| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #ifndef TABWIDGET_H |
| 4 | #define TABWIDGET_H |
| 5 | |
| 6 | #include "core/message.h" |
| 7 | #include "gui/tabbar.h" |
| 8 | #include "gui/tabcontent.h" |
| 9 | |
| 10 | #include <QTabWidget> |
| 11 | #include <QUrl> |
| 12 | |
| 13 | class QMenu; |
| 14 | class PlainToolButton; |
| 15 | class RootItem; |
| 16 | class FeedMessageViewer; |
| 17 | |
| 18 | class TabWidget : public QTabWidget { |
| 19 | Q_OBJECT |
| 20 | |
| 21 | public: |
| 22 | // Constructors and destructors. |
| 23 | explicit TabWidget(QWidget* parent = nullptr); |
| 24 | virtual ~TabWidget(); |
| 25 | |
| 26 | // Manimulators for tabs. |
| 27 | int addTab(TabContent* widget, const QString&, TabBar::TabType type = TabBar::TabType::NonClosable); |
| 28 | int addTab(TabContent* widget, |
| 29 | const QIcon& icon, |
| 30 | const QString& label, |
| 31 | TabBar::TabType type = TabBar::TabType::NonClosable); |
| 32 | int insertTab(int index, QWidget* widget, const QString& label, TabBar::TabType type = TabBar::TabType::Closable); |
| 33 | int insertTab(int index, |
| 34 | QWidget* widget, |
| 35 | const QIcon& icon, |
| 36 | const QString& label, |
| 37 | TabBar::TabType type = TabBar::TabType::NonClosable); |
| 38 | void removeTab(int index, bool clear_from_memory); |
| 39 | |
| 40 | // Returns tab bar. |
| 41 | TabBar* tabBar() const; |
| 42 | |
| 43 | // Returns the central widget of this tab. |
| 44 | TabContent* widget(int index) const; |
| 45 | |
| 46 | TabContent* currentWidget() const; |
| 47 | |
| 48 | // Initializes TabWidget with tabs, this includes initialization |
| 49 | // of main "Feeds" widget. |
| 50 | void initializeTabs(); |
| 51 | |
| 52 | // Sets up icons for this TabWidget. |
| 53 | void setupIcons(); |
| 54 | |
| 55 | // Accessor to feed/message viewer. |
| 56 | FeedMessageViewer* feedMessageViewer() const; |
| 57 | |
| 58 | public slots: |
| 59 | void scrollUpCurrentBrowser(); |
| 60 | void scrollDownCurrentBrowser(); |
| 61 | |
| 62 | // Called when number of tab pages changes. |
| 63 | void checkCornerButtonVisibility(); |
| 64 | void updateAppearance(); |
| 65 | |
| 66 | // Tab closing. |
| 67 | bool closeTab(int index); |
| 68 | void closeTabWithSender(); |
| 69 | void closeAllTabsExceptCurrent(); |
| 70 | void closeAllTabs(); |
| 71 | void closeCurrentTab(); |
| 72 | |
| 73 | // Displays download manager. |
| 74 | void showDownloadManager(); |
| 75 | |
| 76 | int addSingleMessageView(RootItem* root, const Message& message); |
| 77 | |
| 78 | // Adds new WebBrowser tab to global TabWidget. |
| 79 | int addEmptyBrowser(); |
| 80 | |
| 81 | #if defined(ENABLE_MEDIAPLAYER) |
| 82 | int addMediaPlayer(const QString& url, bool make_active); |
| 83 | #endif |
| 84 | |
| 85 | // Adds new WebBrowser with link. This is used when user |
| 86 | // selects to "Open link in new tab.". |
| 87 | int addLinkedBrowser(const QUrl& initial_url = QUrl()); |
| 88 | int addLinkedBrowser(const QString& initial_url); |
| 89 | |
| 90 | // General method for adding WebBrowsers. |
| 91 | int addBrowser(bool move_after_current, bool make_active, const QUrl& initial_url = QUrl()); |
| 92 | int addBrowser(bool move_after_current, bool make_active, WebBrowser* browser); |
| 93 | |
| 94 | void gotoNextTab(); |
| 95 | void gotoPreviousTab(); |
| 96 | |
| 97 | private slots: |
| 98 | |
| 99 | // Fixes tabs indexes. |
| 100 | void fixContentsAfterMove(int from, int to); |
| 101 | |
| 102 | // Changes icon/text of the tab. |
| 103 | void changeTitle(int index, const QString& new_title); |
| 104 | void changeIcon(int index, const QIcon& new_icon); |
| 105 | |
| 106 | // Opens main menu. |
| 107 | void openMainMenu(); |
| 108 | |
| 109 | private: |
| 110 | void indentTabText(int index); |
| 111 | void createConnections(); |
| 112 | void setupMainMenuButton(); |
| 113 | |
| 114 | void tabInserted(int index); |
| 115 | void tabRemoved(int index); |
| 116 | |
| 117 | PlainToolButton* m_btnMainMenu; |
| 118 | QMenu* m_menuMain; |
| 119 | FeedMessageViewer* m_feedMessageViewer; |
| 120 | }; |
| 121 | |
| 122 | inline TabBar* TabWidget::tabBar() const { |
| 123 | return static_cast<TabBar*>(QTabWidget::tabBar()); |
| 124 | } |
| 125 | |
| 126 | inline TabContent* TabWidget::widget(int index) const { |
| 127 | return static_cast<TabContent*>(QTabWidget::widget(index)); |
| 128 | } |
| 129 | |
| 130 | inline TabContent* TabWidget::currentWidget() const { |
| 131 | return static_cast<TabContent*>(QTabWidget::currentWidget()); |
| 132 | } |
| 133 | |
| 134 | inline FeedMessageViewer* TabWidget::feedMessageViewer() const { |
| 135 | return m_feedMessageViewer; |
| 136 | } |
| 137 | |
| 138 | #endif // TABWIDGET_H |