1 | /* $Id: UISettingsSelector.h 102261 2023-11-22 15:12:38Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UISettingsSelector class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef FEQT_INCLUDED_SRC_settings_UISettingsSelector_h
|
---|
29 | #define FEQT_INCLUDED_SRC_settings_UISettingsSelector_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QObject>
|
---|
36 |
|
---|
37 | /* GUI includes: */
|
---|
38 | #include "UILibraryDefs.h"
|
---|
39 |
|
---|
40 | /* Forward declarations: */
|
---|
41 | class QAction;
|
---|
42 | class QActionGroup;
|
---|
43 | class QSortFilterProxyModel;
|
---|
44 | class QTabWidget;
|
---|
45 | class QTreeWidget;
|
---|
46 | class QTreeWidgetItem;
|
---|
47 | class QITreeWidget;
|
---|
48 | class UISelectorActionItem;
|
---|
49 | class UISelectorItem;
|
---|
50 | class UISelectorModel;
|
---|
51 | class UISelectorTreeView;
|
---|
52 | class UISettingsPage;
|
---|
53 | class QIToolBar;
|
---|
54 |
|
---|
55 |
|
---|
56 | /** QObject subclass providing settings dialog
|
---|
57 | * with the means to switch between settings pages. */
|
---|
58 | class SHARED_LIBRARY_STUFF UISettingsSelector : public QObject
|
---|
59 | {
|
---|
60 | Q_OBJECT;
|
---|
61 |
|
---|
62 | signals:
|
---|
63 |
|
---|
64 | /** Notifies listeners about selector @a iCategory changed. */
|
---|
65 | void sigCategoryChanged(int iCategory);
|
---|
66 |
|
---|
67 | public:
|
---|
68 |
|
---|
69 | /** Constructs settings selector passing @a pParent to the base-class. */
|
---|
70 | UISettingsSelector(QWidget *pParent = 0);
|
---|
71 | /** Destructs settings selector. */
|
---|
72 | virtual ~UISettingsSelector() RT_OVERRIDE;
|
---|
73 |
|
---|
74 | /** Returns the widget selector operates on. */
|
---|
75 | virtual QWidget *widget() const = 0;
|
---|
76 |
|
---|
77 | /** Adds a new selector item.
|
---|
78 | * @param strBigIcon Brings the big icon reference.
|
---|
79 | * @param strMediumIcon Brings the medium icon reference.
|
---|
80 | * @param strSmallIcon Brings the small icon reference.
|
---|
81 | * @param iID Brings the selector section ID.
|
---|
82 | * @param strLink Brings the selector section link.
|
---|
83 | * @param pPage Brings the selector section page reference.
|
---|
84 | * @param iParentID Brings the parent section ID or -1 if there is no parent. */
|
---|
85 | virtual QWidget *addItem(const QString &strBigIcon, const QString &strMediumIcon, const QString &strSmallIcon,
|
---|
86 | int iID, const QString &strLink, UISettingsPage *pPage = 0, int iParentID = -1) = 0;
|
---|
87 |
|
---|
88 | /** Defines whether section with @a iID is @a fVisible. */
|
---|
89 | virtual void setItemVisible(int iID, bool fVisible) { Q_UNUSED(iID); Q_UNUSED(fVisible); }
|
---|
90 |
|
---|
91 | /** Defines the @a strText for section with @a iID. */
|
---|
92 | virtual void setItemText(int iID, const QString &strText);
|
---|
93 | /** Returns the text for section with @a iID. */
|
---|
94 | virtual QString itemText(int iID) const = 0;
|
---|
95 | /** Returns the text for section with @a pPage. */
|
---|
96 | virtual QString itemTextByPage(UISettingsPage *pPage) const;
|
---|
97 |
|
---|
98 | /** Returns the current selector ID. */
|
---|
99 | virtual int currentId() const = 0;
|
---|
100 |
|
---|
101 | /** Returns the section ID for passed @a strLink. */
|
---|
102 | virtual int linkToId(const QString &strLink) const = 0;
|
---|
103 |
|
---|
104 | /** Returns the section page for passed @a iID. */
|
---|
105 | virtual QWidget *idToPage(int iID) const;
|
---|
106 |
|
---|
107 | /** Make the section with @a iID current. */
|
---|
108 | virtual void selectById(int iID, bool fSilently = false) = 0;
|
---|
109 | /** Make the section with @a strLink current. */
|
---|
110 | virtual void selectByLink(const QString &strLink) { selectById(linkToId(strLink)); }
|
---|
111 |
|
---|
112 | /** Returns the list of all selector pages. */
|
---|
113 | virtual QList<UISettingsPage*> settingPages() const;
|
---|
114 |
|
---|
115 | /** Performs selector polishing. */
|
---|
116 | virtual void polish() {}
|
---|
117 |
|
---|
118 | /** Returns minimum selector width. */
|
---|
119 | virtual int minWidth() const { return 0; }
|
---|
120 |
|
---|
121 | protected:
|
---|
122 |
|
---|
123 | /** Searches for item with passed @a iID. */
|
---|
124 | UISelectorItem *findItem(int iID) const;
|
---|
125 | /** Searches for item with passed @a strLink. */
|
---|
126 | UISelectorItem *findItemByLink(const QString &strLink) const;
|
---|
127 | /** Searches for item with passed @a pPage. */
|
---|
128 | UISelectorItem *findItemByPage(UISettingsPage *pPage) const;
|
---|
129 |
|
---|
130 | /** Holds the selector item instances. */
|
---|
131 | QList<UISelectorItem*> m_list;
|
---|
132 | };
|
---|
133 |
|
---|
134 |
|
---|
135 | /** UISettingsSelector subclass providing settings dialog
|
---|
136 | * with the means to switch between settings pages.
|
---|
137 | * This one represented as tree-view. */
|
---|
138 | class SHARED_LIBRARY_STUFF UISettingsSelectorTreeView : public UISettingsSelector
|
---|
139 | {
|
---|
140 | Q_OBJECT;
|
---|
141 |
|
---|
142 | public:
|
---|
143 |
|
---|
144 | /** Constructs settings selector passing @a pParent to the base-class. */
|
---|
145 | UISettingsSelectorTreeView(QWidget *pParent);
|
---|
146 | /** Destructs settings selector. */
|
---|
147 | virtual ~UISettingsSelectorTreeView() RT_OVERRIDE;
|
---|
148 |
|
---|
149 | /** Returns the widget selector operates on. */
|
---|
150 | virtual QWidget *widget() const RT_OVERRIDE;
|
---|
151 |
|
---|
152 | /** Adds a new selector item.
|
---|
153 | * @param strBigIcon Brings the big icon reference.
|
---|
154 | * @param strMediumIcon Brings the medium icon reference.
|
---|
155 | * @param strSmallIcon Brings the small icon reference.
|
---|
156 | * @param iID Brings the selector section ID.
|
---|
157 | * @param strLink Brings the selector section link.
|
---|
158 | * @param pPage Brings the selector section page reference.
|
---|
159 | * @param iParentID Brings the parent section ID or -1 if there is no parent. */
|
---|
160 | virtual QWidget *addItem(const QString &strBigIcon, const QString &strMediumIcon, const QString &strSmallIcon,
|
---|
161 | int iID, const QString &strLink, UISettingsPage *pPage = 0, int iParentID = -1) RT_OVERRIDE;
|
---|
162 |
|
---|
163 | /** Defines whether section with @a iID is @a fVisible. */
|
---|
164 | virtual void setItemVisible(int iID, bool fVisible) RT_OVERRIDE;
|
---|
165 |
|
---|
166 | /** Defines the @a strText for section with @a iID. */
|
---|
167 | virtual void setItemText(int iID, const QString &strText) RT_OVERRIDE;
|
---|
168 | /** Returns the text for section with @a iID. */
|
---|
169 | virtual QString itemText(int iID) const RT_OVERRIDE;
|
---|
170 |
|
---|
171 | /** Returns the current selector ID. */
|
---|
172 | virtual int currentId() const RT_OVERRIDE;
|
---|
173 |
|
---|
174 | /** Returns the section ID for passed @a strLink. */
|
---|
175 | virtual int linkToId(const QString &strLink) const RT_OVERRIDE;
|
---|
176 |
|
---|
177 | /** Make the section with @a iID current. */
|
---|
178 | virtual void selectById(int iID, bool fSilently) RT_OVERRIDE;
|
---|
179 |
|
---|
180 | private slots:
|
---|
181 |
|
---|
182 | /** Handles selector section change from @a pPrevItem to @a pItem. */
|
---|
183 | void sltHandleCurrentChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
---|
184 |
|
---|
185 | private:
|
---|
186 |
|
---|
187 | /** Prepares all. */
|
---|
188 | void prepare();
|
---|
189 | /** Cleanups all. */
|
---|
190 | void cleanup();
|
---|
191 |
|
---|
192 | /** Holds the tree-view instance. */
|
---|
193 | UISelectorTreeView *m_pTreeView;
|
---|
194 | /** Holds the model instance. */
|
---|
195 | UISelectorModel *m_pModel;
|
---|
196 | /** Holds the proxy-model instance. */
|
---|
197 | QSortFilterProxyModel *m_pModelProxy;
|
---|
198 | };
|
---|
199 |
|
---|
200 |
|
---|
201 | /** UISettingsSelector subclass providing settings dialog
|
---|
202 | * with the means to switch between settings pages.
|
---|
203 | * This one represented as tree-widget. */
|
---|
204 | class SHARED_LIBRARY_STUFF UISettingsSelectorTreeWidget : public UISettingsSelector
|
---|
205 | {
|
---|
206 | Q_OBJECT;
|
---|
207 |
|
---|
208 | public:
|
---|
209 |
|
---|
210 | /** Constructs settings selector passing @a pParent to the base-class. */
|
---|
211 | UISettingsSelectorTreeWidget(QWidget *pParent = 0);
|
---|
212 | /** Destructs settings selector. */
|
---|
213 | virtual ~UISettingsSelectorTreeWidget() RT_OVERRIDE;
|
---|
214 |
|
---|
215 | /** Returns the widget selector operates on. */
|
---|
216 | virtual QWidget *widget() const RT_OVERRIDE;
|
---|
217 |
|
---|
218 | /** Adds a new selector item.
|
---|
219 | * @param strBigIcon Brings the big icon reference.
|
---|
220 | * @param strMediumIcon Brings the medium icon reference.
|
---|
221 | * @param strSmallIcon Brings the small icon reference.
|
---|
222 | * @param iID Brings the selector section ID.
|
---|
223 | * @param strLink Brings the selector section link.
|
---|
224 | * @param pPage Brings the selector section page reference.
|
---|
225 | * @param iParentID Brings the parent section ID or -1 if there is no parent. */
|
---|
226 | virtual QWidget *addItem(const QString &strBigIcon, const QString &strMediumIcon, const QString &strSmallIcon,
|
---|
227 | int iID, const QString &strLink, UISettingsPage *pPage = 0, int iParentID = -1) RT_OVERRIDE;
|
---|
228 |
|
---|
229 | /** Defines the @a strText for section with @a iID. */
|
---|
230 | virtual void setItemText(int iID, const QString &strText) RT_OVERRIDE;
|
---|
231 | /** Returns the text for section with @a iID. */
|
---|
232 | virtual QString itemText(int iID) const RT_OVERRIDE;
|
---|
233 |
|
---|
234 | /** Returns the current selector ID. */
|
---|
235 | virtual int currentId() const RT_OVERRIDE;
|
---|
236 |
|
---|
237 | /** Returns the section ID for passed @a strLink. */
|
---|
238 | virtual int linkToId(const QString &strLink) const RT_OVERRIDE;
|
---|
239 |
|
---|
240 | /** Make the section with @a iID current. */
|
---|
241 | virtual void selectById(int iID, bool fSilently) RT_OVERRIDE;
|
---|
242 |
|
---|
243 | /** Performs selector polishing. */
|
---|
244 | virtual void polish() RT_OVERRIDE;
|
---|
245 |
|
---|
246 | private slots:
|
---|
247 |
|
---|
248 | /** Handles selector section change from @a pPrevItem to @a pItem. */
|
---|
249 | void sltSettingsGroupChanged(QTreeWidgetItem *pItem, QTreeWidgetItem *pPrevItem);
|
---|
250 |
|
---|
251 | private:
|
---|
252 |
|
---|
253 | /** Prepares all. */
|
---|
254 | void prepare();
|
---|
255 |
|
---|
256 | /** Returns page path for passed @a strMatch. */
|
---|
257 | QString pagePath(const QString &strMatch) const;
|
---|
258 | /** Find item within the passed @a pView and @a iColumn matching @a strMatch. */
|
---|
259 | QTreeWidgetItem *findItem(QTreeWidget *pView, const QString &strMatch, int iColumn) const;
|
---|
260 | /** Performs @a iID to QString serialization. */
|
---|
261 | QString idToString(int iID) const;
|
---|
262 |
|
---|
263 | /** Forges the full path for passed @a pItem. */
|
---|
264 | static QString path(const QTreeWidgetItem *pItem);
|
---|
265 |
|
---|
266 | /** Holds the tree-widget instance. */
|
---|
267 | QITreeWidget *m_pTreeWidget;
|
---|
268 | };
|
---|
269 |
|
---|
270 |
|
---|
271 | /** UISettingsSelector subclass providing settings dialog
|
---|
272 | * with the means to switch between settings pages.
|
---|
273 | * This one represented as tool-bar. */
|
---|
274 | class SHARED_LIBRARY_STUFF UISettingsSelectorToolBar : public UISettingsSelector
|
---|
275 | {
|
---|
276 | Q_OBJECT;
|
---|
277 |
|
---|
278 | public:
|
---|
279 |
|
---|
280 | /** Constructs settings selector passing @a pParent to the base-class. */
|
---|
281 | UISettingsSelectorToolBar(QWidget *pParent = 0);
|
---|
282 | /** Destructs settings selector. */
|
---|
283 | virtual ~UISettingsSelectorToolBar() RT_OVERRIDE;
|
---|
284 |
|
---|
285 | /** Returns the widget selector operates on. */
|
---|
286 | virtual QWidget *widget() const RT_OVERRIDE;
|
---|
287 |
|
---|
288 | /** Adds a new selector item.
|
---|
289 | * @param strBigIcon Brings the big icon reference.
|
---|
290 | * @param strMediumIcon Brings the medium icon reference.
|
---|
291 | * @param strSmallIcon Brings the small icon reference.
|
---|
292 | * @param iID Brings the selector section ID.
|
---|
293 | * @param strLink Brings the selector section link.
|
---|
294 | * @param pPage Brings the selector section page reference.
|
---|
295 | * @param iParentID Brings the parent section ID or -1 if there is no parent. */
|
---|
296 | virtual QWidget *addItem(const QString &strBigIcon, const QString &strMediumIcon, const QString &strSmallIcon,
|
---|
297 | int iID, const QString &strLink, UISettingsPage *pPage = 0, int iParentID = -1) RT_OVERRIDE;
|
---|
298 |
|
---|
299 | /** Defines the @a strText for section with @a iID. */
|
---|
300 | virtual void setItemText(int iID, const QString &strText) RT_OVERRIDE;
|
---|
301 | /** Returns the text for section with @a iID. */
|
---|
302 | virtual QString itemText(int iID) const RT_OVERRIDE;
|
---|
303 |
|
---|
304 | /** Returns the current selector ID. */
|
---|
305 | virtual int currentId() const RT_OVERRIDE;
|
---|
306 |
|
---|
307 | /** Returns the section ID for passed @a strLink. */
|
---|
308 | virtual int linkToId(const QString &strLink) const RT_OVERRIDE;
|
---|
309 |
|
---|
310 | /** Returns the section page for passed @a iID. */
|
---|
311 | virtual QWidget *idToPage(int iID) const RT_OVERRIDE;
|
---|
312 |
|
---|
313 | /** Make the section with @a iID current. */
|
---|
314 | virtual void selectById(int iID, bool fSilently) RT_OVERRIDE;
|
---|
315 |
|
---|
316 | /** Returns minimum selector width. */
|
---|
317 | virtual int minWidth() const RT_OVERRIDE;
|
---|
318 |
|
---|
319 | private slots:
|
---|
320 |
|
---|
321 | /** Handles selector section change to @a pAction. */
|
---|
322 | void sltSettingsGroupChanged(QAction *pAction);
|
---|
323 |
|
---|
324 | private:
|
---|
325 |
|
---|
326 | /** Prepares all. */
|
---|
327 | void prepare();
|
---|
328 |
|
---|
329 | /** Searches for action item with passed @a iID. */
|
---|
330 | UISelectorActionItem *findActionItem(int iID) const;
|
---|
331 | /** Searches for action item with passed @a pAction. */
|
---|
332 | UISelectorActionItem *findActionItemByAction(QAction *pAction) const;
|
---|
333 | /** Searches for action item with passed @a pTabWidget and @a iIndex. */
|
---|
334 | UISelectorActionItem *findActionItemByTabWidget(QTabWidget *pTabWidget, int iIndex) const;
|
---|
335 |
|
---|
336 | /** Holds the toolbar instance. */
|
---|
337 | QIToolBar *m_pToolBar;
|
---|
338 | /** Holds the action group instance. */
|
---|
339 | QActionGroup *m_pActionGroup;
|
---|
340 | };
|
---|
341 |
|
---|
342 |
|
---|
343 | #endif /* !FEQT_INCLUDED_SRC_settings_UISettingsSelector_h */
|
---|