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