1 /* 2 SPDX-FileCopyrightText: 2012 Joris Guisson <joris.guisson@gmail.com> 3 SPDX-License-Identifier: GPL-2.0-or-later 4 */ 5 6 #ifndef KT_GROUPSWITCHER_H 7 #define KT_GROUPSWITCHER_H 8 9 #include <QActionGroup> 10 11 #include <KSharedConfig> 12 #include <KToolBar> 13 14 #include <groups/groupmanager.h> 15 16 class QToolButton; 17 18 namespace kt 19 { 20 class View; 21 22 /** 23 * toolbar to switch between groups 24 */ 25 class GroupSwitcher : public QWidget 26 { 27 Q_OBJECT 28 public: 29 GroupSwitcher(View *view, GroupManager *gman, QWidget *parent); 30 ~GroupSwitcher() override; 31 32 /** 33 * Load state of widget from config 34 * @param cfg The config 35 **/ 36 void loadState(KSharedConfig::Ptr cfg); 37 38 /** 39 * Save state of widget to config 40 * @param cfg The config 41 **/ 42 void saveState(KSharedConfig::Ptr cfg); 43 44 public Q_SLOTS: 45 /** 46 * Add a tab 47 * @param group The group of the tab 48 **/ 49 void addTab(Group *group); 50 51 /** 52 * Add a new tab showing the all group. 53 **/ 54 void newTab(); 55 56 /** 57 * Close the current tab 58 **/ 59 void closeTab(); 60 61 /** 62 * An action was activated 63 * @param action The action 64 **/ 65 void onActivated(QAction *action); 66 67 /** 68 * The current group has changed 69 * @param group The new group 70 **/ 71 void currentGroupChanged(kt::Group *group); 72 73 /** 74 * Update the group count 75 */ 76 void updateGroupCount(); 77 78 /** 79 * A group has been removed 80 * @param group The group 81 **/ 82 void groupRemoved(Group *group); 83 84 /** 85 * Edit the group policy 86 **/ 87 void editGroupPolicy(); 88 89 private: 90 struct Tab { 91 Group *group; 92 QAction *action; 93 QByteArray view_settings; 94 TabTab95 Tab(Group *group, QAction *action) 96 : group(group) 97 , action(action) 98 { 99 } 100 }; 101 102 typedef QList<Tab> TabList; 103 104 TabList::iterator closeTab(TabList::iterator i); 105 106 private: 107 QToolButton *new_tab; 108 QToolButton *close_tab; 109 QToolButton *edit_group_policy; 110 KToolBar *tool_bar; 111 QActionGroup *action_group; 112 GroupManager *gman; 113 View *view; 114 TabList tabs; 115 int current_tab; 116 }; 117 118 } 119 120 #endif // KT_GROUPSWITCHER_H 121