File indexing completed on 2024-05-05 04:19:19
0001 /* 0002 Gwenview: an image viewer 0003 Copyright 2007 Aurélien Gâteau <agateau@kde.org> 0004 0005 This program is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU General Public License 0007 as published by the Free Software Foundation; either version 2 0008 of the License, or (at your option) any later version. 0009 0010 This program is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 GNU General Public License for more details. 0014 0015 You should have received a copy of the GNU General Public License 0016 along with this program; if not, write to the Free Software 0017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0018 0019 */ 0020 #ifndef SIDEBAR_H 0021 #define SIDEBAR_H 0022 0023 // Qt 0024 #include <QFrame> 0025 #include <QStylePainter> 0026 #include <QTabBar> 0027 #include <QTabWidget> 0028 0029 namespace Gwenview 0030 { 0031 class SideBar; 0032 0033 struct SideBarGroupPrivate; 0034 class SideBarGroup : public QFrame 0035 { 0036 Q_OBJECT 0037 public: 0038 SideBarGroup(const QString &title = ""); 0039 ~SideBarGroup() override; 0040 0041 void addWidget(QWidget *); 0042 void addAction(QAction *); 0043 void clear(); 0044 0045 private: 0046 SideBarGroupPrivate *const d; 0047 }; 0048 0049 struct SideBarPagePrivate; 0050 class SideBarPage : public QWidget 0051 { 0052 Q_OBJECT 0053 public: 0054 SideBarPage(const QIcon &icon, const QString &title); 0055 ~SideBarPage() override; 0056 void addWidget(QWidget *); 0057 void addStretch(); 0058 0059 const QIcon &icon() const; 0060 const QString &title() const; 0061 0062 private: 0063 SideBarPagePrivate *const d; 0064 }; 0065 0066 struct SideBarTabBarPrivate; 0067 class SideBarTabBar : public QTabBar 0068 { 0069 Q_OBJECT 0070 public: 0071 explicit SideBarTabBar(QWidget *parent); 0072 ~SideBarTabBar() override; 0073 0074 enum TabButtonStyle { 0075 TabButtonIconOnly, 0076 TabButtonTextOnly, 0077 TabButtonTextBesideIcon, 0078 }; 0079 Q_ENUM(TabButtonStyle) 0080 0081 TabButtonStyle tabButtonStyle() const; 0082 0083 QSize sizeHint() const override; 0084 0085 QSize minimumSizeHint() const override; 0086 0087 protected: 0088 QSize tabSizeHint(const int index) const override; 0089 QSize minimumTabSizeHint(int index) const override; 0090 // Switches the TabButtonStyle based on the width 0091 void tabLayoutChange() override; 0092 void paintEvent(QPaintEvent *event) override; 0093 0094 private: 0095 // Like sizeHint, but just for content size 0096 QSize tabContentSize(const int index, const TabButtonStyle tabButtonStyle, const QStyleOptionTab &opt) const; 0097 // Gets the tab size hint for the given TabButtonStyle 0098 QSize tabSizeHint(const int index, const TabButtonStyle tabButtonStyle) const; 0099 // Gets the size hint for the given TabButtonStyle 0100 QSize sizeHint(const TabButtonStyle tabButtonStyle) const; 0101 void drawTab(int index, QStylePainter &painter) const; 0102 const std::unique_ptr<SideBarTabBarPrivate> d; 0103 }; 0104 0105 struct SideBarPrivate; 0106 class SideBar : public QTabWidget 0107 { 0108 Q_OBJECT 0109 public: 0110 explicit SideBar(QWidget *parent); 0111 ~SideBar() override; 0112 0113 void addPage(SideBarPage *); 0114 0115 QString currentPage() const; 0116 void setCurrentPage(const QString &name); 0117 0118 void loadConfig(); 0119 0120 QSize sizeHint() const override; 0121 0122 private: 0123 SideBarPrivate *const d; 0124 }; 0125 0126 } // namespace 0127 0128 #endif /* SIDEBAR_H */