File indexing completed on 2024-05-12 04:57:48
0001 /************************************************************************** 0002 ** 0003 ** This file is part of Qt Creator 0004 ** 0005 ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). 0006 ** 0007 ** Contact: Nokia Corporation (qt-info@nokia.com) 0008 ** 0009 ** Commercial Usage 0010 ** 0011 ** Licensees holding valid Qt Commercial licenses may use this file in 0012 ** accordance with the Qt Commercial License Agreement provided with the 0013 ** Software or, alternatively, in accordance with the terms contained in 0014 ** a written agreement between you and Nokia. 0015 ** 0016 ** GNU Lesser General Public License Usage 0017 ** 0018 ** Alternatively, this file may be used under the terms of the GNU Lesser 0019 ** General Public License version 2.1 as published by the Free Software 0020 ** Foundation and appearing in the file LICENSE.LGPL included in the 0021 ** packaging of this file. Please review the following information to 0022 ** ensure the GNU Lesser General Public License version 2.1 requirements 0023 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 0024 ** 0025 ** If you are unsure which license is appropriate for your use, please 0026 ** contact the sales department at http://qt.nokia.com/contact. 0027 ** 0028 **************************************************************************/ 0029 0030 #ifndef FANCYTABWIDGET_H 0031 #define FANCYTABWIDGET_H 0032 0033 #include "qzcommon.h" 0034 0035 #include <QIcon> 0036 #include <QProxyStyle> 0037 #include <QTabBar> 0038 #include <QTimer> 0039 #include <QWidget> 0040 #include <QPropertyAnimation> 0041 0042 class QActionGroup; 0043 class QMenu; 0044 class QPainter; 0045 class QSignalMapper; 0046 class QStackedLayout; 0047 class QStatusBar; 0048 class QVBoxLayout; 0049 0050 namespace Core 0051 { 0052 namespace Internal 0053 { 0054 0055 class FALKON_EXPORT FancyTabProxyStyle : public QProxyStyle 0056 { 0057 Q_OBJECT 0058 0059 public: 0060 void drawControl(ControlElement element, const QStyleOption* option, 0061 QPainter* painter, const QWidget* widget) const override; 0062 void polish(QWidget* widget) override; 0063 void polish(QApplication* app) override; 0064 void polish(QPalette &palette) override; 0065 0066 protected: 0067 bool eventFilter(QObject* o, QEvent* e) override; 0068 }; 0069 0070 class FALKON_EXPORT FancyTab : public QWidget 0071 { 0072 Q_OBJECT 0073 0074 Q_PROPERTY(float fader READ fader WRITE setFader) 0075 public: 0076 FancyTab(QWidget* tabbar); 0077 float fader() { return m_fader; } 0078 void setFader(float value); 0079 0080 QSize sizeHint() const override; 0081 0082 void fadeIn(); 0083 void fadeOut(); 0084 0085 QIcon icon; 0086 QString text; 0087 0088 protected: 0089 void enterEvent(QEnterEvent *event) override; 0090 void leaveEvent(QEvent*) override; 0091 0092 private: 0093 QPropertyAnimation animator; 0094 QWidget* tabbar; 0095 float m_fader; 0096 }; 0097 0098 class FALKON_EXPORT FancyTabBar : public QWidget 0099 { 0100 Q_OBJECT 0101 0102 public: 0103 explicit FancyTabBar(QWidget* parent = nullptr); 0104 ~FancyTabBar() override; 0105 0106 void paintEvent(QPaintEvent* event) override; 0107 void paintTab(QPainter* painter, int tabIndex) const; 0108 void mousePressEvent(QMouseEvent*) override; 0109 bool validIndex(int index) const { return index >= 0 && index < m_tabs.count(); } 0110 0111 QSize sizeHint() const override; 0112 QSize minimumSizeHint() const override; 0113 0114 void addTab(const QIcon &icon, const QString &label); 0115 void addSpacer(int size = 40); 0116 void removeTab(int index) { 0117 FancyTab* tab = m_tabs.takeAt(index); 0118 delete tab; 0119 } 0120 void setCurrentIndex(int index); 0121 int currentIndex() const { return m_currentIndex; } 0122 0123 void setTabToolTip(int index, const QString &toolTip); 0124 QString tabToolTip(int index) const; 0125 0126 QIcon tabIcon(int index) const {return m_tabs.at(index)->icon; } 0127 QString tabText(int index) const { return m_tabs.at(index)->text; } 0128 int count() const {return m_tabs.count(); } 0129 QRect tabRect(int index) const; 0130 0131 Q_SIGNALS: 0132 void currentChanged(int); 0133 0134 public Q_SLOTS: 0135 void emitCurrentIndex(); 0136 0137 private: 0138 static const int m_rounding; 0139 static const int m_textPadding; 0140 int m_currentIndex; 0141 QList<FancyTab*> m_tabs; 0142 QTimer m_triggerTimer; 0143 QSize tabSizeHint(bool minimum = false) const; 0144 0145 }; 0146 0147 class FALKON_EXPORT FancyTabWidget : public QWidget 0148 { 0149 Q_OBJECT 0150 0151 Q_PROPERTY(QPixmap bgPixmap READ bgPixmap WRITE SetBackgroundPixmap) 0152 0153 public: 0154 explicit FancyTabWidget(QWidget* parent = nullptr); 0155 0156 // Values are persisted - only add to the end 0157 enum Mode { 0158 Mode_None = 0, 0159 0160 Mode_LargeSidebar = 1, 0161 Mode_SmallSidebar = 2, 0162 Mode_Tabs = 3, 0163 Mode_IconOnlyTabs = 4, 0164 Mode_PlainSidebar = 5, 0165 }; 0166 0167 struct Item { 0168 Item(const QIcon &icon, const QString &label) 0169 : type_(Type_Tab), tab_label_(label), tab_icon_(icon), spacer_size_(0) {} 0170 Item(int size) : type_(Type_Spacer), spacer_size_(size) {} 0171 0172 enum Type { 0173 Type_Tab, 0174 Type_Spacer, 0175 }; 0176 0177 Type type_; 0178 QString tab_label_; 0179 QIcon tab_icon_; 0180 int spacer_size_; 0181 }; 0182 0183 void AddTab(QWidget* tab, const QIcon &icon, const QString &label); 0184 void AddSpacer(int size = 40); 0185 void SetBackgroundPixmap(const QPixmap &pixmap); 0186 0187 void AddBottomWidget(QWidget* widget); 0188 0189 int current_index() const; 0190 Mode mode() const { return mode_; } 0191 QPixmap bgPixmap() { return background_pixmap_; } 0192 0193 public Q_SLOTS: 0194 void SetCurrentIndex(int index); 0195 void SetMode(FancyTabWidget::Mode mode); 0196 void SetMode(int mode) { SetMode(Mode(mode)); } 0197 0198 Q_SIGNALS: 0199 void CurrentChanged(int index); 0200 void ModeChanged(FancyTabWidget::Mode mode); 0201 0202 protected: 0203 void paintEvent(QPaintEvent* event) override; 0204 void contextMenuEvent(QContextMenuEvent* e) override; 0205 0206 private Q_SLOTS: 0207 void ShowWidget(int index); 0208 0209 private: 0210 void MakeTabBar(QTabBar::Shape shape, bool text, bool icons, bool fancy); 0211 void AddMenuItem(QSignalMapper* mapper, QActionGroup* group, 0212 const QString &text, Mode mode); 0213 0214 Mode mode_; 0215 QList<Item> items_; 0216 0217 QWidget* tab_bar_; 0218 QStackedLayout* stack_; 0219 QPixmap background_pixmap_; 0220 QWidget* side_widget_; 0221 QVBoxLayout* side_layout_; 0222 QVBoxLayout* top_layout_; 0223 0224 bool use_background_; 0225 0226 QMenu* menu_; 0227 0228 FancyTabProxyStyle* proxy_style_; 0229 }; 0230 0231 } // namespace Internal 0232 } // namespace Core 0233 0234 using Core::Internal::FancyTab; 0235 using Core::Internal::FancyTabBar; 0236 using Core::Internal::FancyTabWidget; 0237 0238 #endif // FANCYTABWIDGET_H