1 /* 2 * Strawberry Music Player 3 * This file was part of Clementine. 4 * Copyright 2018, Vikram Ambrose <ambroseworks@gmail.com> 5 * Copyright 2018, Jonas Kvinge <jonas@jkvinge.net> 6 * 7 * Strawberry is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * Strawberry is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with Strawberry. If not, see <http://www.gnu.org/licenses/>. 19 * 20 */ 21 22 #ifndef FANCYTABWIDGET_H 23 #define FANCYTABWIDGET_H 24 25 #include "config.h" 26 27 #include <QObject> 28 #include <QTabWidget> 29 #include <QHash> 30 #include <QString> 31 #include <QIcon> 32 #include <QPixmap> 33 #include <QSize> 34 #include <QColor> 35 36 class QMenu; 37 class QActionGroup; 38 class QContextMenuEvent; 39 class QPaintEvent; 40 class QProxyStyle; 41 class TabData; 42 43 namespace Core { 44 namespace Internal { 45 46 class FancyTabWidget : public QTabWidget { 47 Q_OBJECT 48 49 public: 50 explicit FancyTabWidget(QWidget *parent = nullptr); 51 ~FancyTabWidget() override; 52 53 void AddTab(QWidget *widget_view, const QString &name, const QIcon &icon, const QString &label); 54 bool EnableTab(QWidget *widget_view); 55 bool DisableTab(QWidget *widget_view); 56 int insertTab(const int idx, QWidget *page, const QIcon &icon, const QString &label); 57 void addBottomWidget(QWidget *widget_view); 58 int IndexOfTab(QWidget *widget); 59 60 void setBackgroundPixmap(const QPixmap &pixmap); 61 void addSpacer(); 62 63 void Load(const QString &kSettingsGroup); 64 void SaveSettings(const QString &kSettingsGroup); 65 void ReloadSettings(); 66 67 // Values are persisted - only add to the end 68 enum Mode { 69 Mode_None = 0, 70 Mode_LargeSidebar, 71 Mode_SmallSidebar, 72 Mode_Tabs, 73 Mode_IconOnlyTabs, 74 Mode_PlainSidebar, 75 }; 76 77 static const int TabSize_LargeSidebarMinWidth; 78 static const int IconSize_LargeSidebar; 79 static const int IconSize_SmallSidebar; 80 mode()81 Mode mode() const { return mode_; } iconsize_smallsidebar()82 int iconsize_smallsidebar() const { return iconsize_smallsidebar_; } iconsize_largesidebar()83 int iconsize_largesidebar() const { return iconsize_largesidebar_; } 84 85 signals: 86 void ModeChanged(FancyTabWidget::Mode mode); 87 void CurrentChanged(int); 88 89 public slots: 90 void setCurrentIndex(int idx); 91 void SetMode(Core::Internal::FancyTabWidget::Mode mode); 92 // Mapper mapped signal needs this convenience function SetMode(int mode)93 void SetMode(int mode) { SetMode(Mode(mode)); } 94 95 private slots: 96 void tabBarUpdateGeometry(); 97 void currentTabChanged(int); 98 99 protected: 100 void paintEvent(QPaintEvent*) override; 101 void contextMenuEvent(QContextMenuEvent *e) override; 102 103 private: 104 void addMenuItem(QActionGroup *group, const QString &text, Mode mode); 105 106 QProxyStyle *style_; 107 QPixmap background_pixmap_; 108 QMenu *menu_; 109 Mode mode_; 110 QWidget *bottom_widget_; 111 112 QHash<QWidget*, TabData*> tabs_; 113 114 bool bg_color_system_; 115 bool bg_gradient_; 116 QColor bg_color_; 117 int iconsize_smallsidebar_; 118 int iconsize_largesidebar_; 119 120 }; 121 122 } // namespace Internal 123 } // namespace Core 124 125 using Core::Internal::FancyTabWidget; 126 127 #endif // FANCYTABWIDGET_H 128