Falkon Develop
Cross-platform Qt-based web browser
fancytabwidget.h
Go to the documentation of this file.
1/**************************************************************************
2**
3** This file is part of Qt Creator
4**
5** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
6**
7** Contact: Nokia Corporation (qt-info@nokia.com)
8**
9** Commercial Usage
10**
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17**
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** If you are unsure which license is appropriate for your use, please
26** contact the sales department at http://qt.nokia.com/contact.
27**
28**************************************************************************/
29
30#ifndef FANCYTABWIDGET_H
31#define FANCYTABWIDGET_H
32
33#include "qzcommon.h"
34
35#include <QIcon>
36#include <QProxyStyle>
37#include <QTabBar>
38#include <QTimer>
39#include <QWidget>
40#include <QPropertyAnimation>
41
42class QActionGroup;
43class QMenu;
44class QPainter;
45class QSignalMapper;
46class QStackedLayout;
47class QStatusBar;
48class QVBoxLayout;
49
50namespace Core
51{
52namespace Internal
53{
54
55class FALKON_EXPORT FancyTabProxyStyle : public QProxyStyle
56{
57 Q_OBJECT
58
59public:
60 void drawControl(ControlElement element, const QStyleOption* option,
61 QPainter* painter, const QWidget* widget) const override;
62 void polish(QWidget* widget) override;
63 void polish(QApplication* app) override;
64 void polish(QPalette &palette) override;
65
66protected:
67 bool eventFilter(QObject* o, QEvent* e) override;
68};
69
70class FALKON_EXPORT FancyTab : public QWidget
71{
72 Q_OBJECT
73
74 Q_PROPERTY(float fader READ fader WRITE setFader)
75public:
76 FancyTab(QWidget* tabbar);
77 float fader() { return m_fader; }
78 void setFader(float value);
79
80 QSize sizeHint() const override;
81
82 void fadeIn();
83 void fadeOut();
84
85 QIcon icon;
86 QString text;
87
88protected:
89 void enterEvent(QEnterEvent *event) override;
90 void leaveEvent(QEvent*) override;
91
92private:
93 QPropertyAnimation animator;
94 QWidget* tabbar;
95 float m_fader;
96};
97
98class FALKON_EXPORT FancyTabBar : public QWidget
99{
100 Q_OBJECT
101
102public:
103 explicit FancyTabBar(QWidget* parent = nullptr);
104 ~FancyTabBar() override;
105
106 void paintEvent(QPaintEvent* event) override;
107 void paintTab(QPainter* painter, int tabIndex) const;
108 void mousePressEvent(QMouseEvent*) override;
109 bool validIndex(int index) const { return index >= 0 && index < m_tabs.count(); }
110
111 QSize sizeHint() const override;
112 QSize minimumSizeHint() const override;
113
114 void addTab(const QIcon &icon, const QString &label);
115 void addSpacer(int size = 40);
116 void removeTab(int index) {
117 FancyTab* tab = m_tabs.takeAt(index);
118 delete tab;
119 }
120 void setCurrentIndex(int index);
121 int currentIndex() const { return m_currentIndex; }
122
123 void setTabToolTip(int index, const QString &toolTip);
124 QString tabToolTip(int index) const;
125
126 QIcon tabIcon(int index) const {return m_tabs.at(index)->icon; }
127 QString tabText(int index) const { return m_tabs.at(index)->text; }
128 int count() const {return m_tabs.count(); }
129 QRect tabRect(int index) const;
130
131Q_SIGNALS:
132 void currentChanged(int);
133
134public Q_SLOTS:
135 void emitCurrentIndex();
136
137private:
138 static const int m_rounding;
139 static const int m_textPadding;
140 int m_currentIndex;
141 QList<FancyTab*> m_tabs;
142 QTimer m_triggerTimer;
143 QSize tabSizeHint(bool minimum = false) const;
144
145};
146
147class FALKON_EXPORT FancyTabWidget : public QWidget
148{
149 Q_OBJECT
150
151 Q_PROPERTY(QPixmap bgPixmap READ bgPixmap WRITE SetBackgroundPixmap)
152
153public:
154 explicit FancyTabWidget(QWidget* parent = nullptr);
155
156 // Values are persisted - only add to the end
157 enum Mode {
158 Mode_None = 0,
159
160 Mode_LargeSidebar = 1,
161 Mode_SmallSidebar = 2,
162 Mode_Tabs = 3,
163 Mode_IconOnlyTabs = 4,
164 Mode_PlainSidebar = 5,
165 };
166
167 struct Item {
168 Item(const QIcon &icon, const QString &label)
169 : type_(Type_Tab), tab_label_(label), tab_icon_(icon), spacer_size_(0) {}
170 Item(int size) : type_(Type_Spacer), spacer_size_(size) {}
171
172 enum Type {
175 };
176
178 QString tab_label_;
181 };
182
183 void AddTab(QWidget* tab, const QIcon &icon, const QString &label);
184 void AddSpacer(int size = 40);
185 void SetBackgroundPixmap(const QPixmap &pixmap);
186
187 void AddBottomWidget(QWidget* widget);
188
189 int current_index() const;
190 Mode mode() const { return mode_; }
191 QPixmap bgPixmap() { return background_pixmap_; }
192
193public Q_SLOTS:
194 void SetCurrentIndex(int index);
195 void SetMode(FancyTabWidget::Mode mode);
196 void SetMode(int mode) { SetMode(Mode(mode)); }
197
198Q_SIGNALS:
199 void CurrentChanged(int index);
201
202protected:
203 void paintEvent(QPaintEvent* event) override;
204 void contextMenuEvent(QContextMenuEvent* e) override;
205
206private Q_SLOTS:
207 void ShowWidget(int index);
208
209private:
210 void MakeTabBar(QTabBar::Shape shape, bool text, bool icons, bool fancy);
211 void AddMenuItem(QSignalMapper* mapper, QActionGroup* group,
212 const QString &text, Mode mode);
213
214 Mode mode_;
215 QList<Item> items_;
216
217 QWidget* tab_bar_;
218 QStackedLayout* stack_;
219 QPixmap background_pixmap_;
220 QWidget* side_widget_;
221 QVBoxLayout* side_layout_;
222 QVBoxLayout* top_layout_;
223
224 bool use_background_;
225
226 QMenu* menu_;
227
228 FancyTabProxyStyle* proxy_style_;
229};
230
231} // namespace Internal
232} // namespace Core
233
237
238#endif // FANCYTABWIDGET_H
QIcon tabIcon(int index) const
bool validIndex(int index) const
QString tabText(int index) const
void ModeChanged(FancyTabWidget::Mode mode)
int value(const QColor &c)
Definition: colors.cpp:238
#define FALKON_EXPORT
Definition: qzcommon.h:28
Item(const QIcon &icon, const QString &label)