summaryrefslogtreecommitdiff
path: root/src/VBox/Frontends/VirtualBox/src/settings/UISettingsSelector.h
blob: 3e3f0c29093e0765384d863128188a35e104950a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/* $Id$ */
/** @file
 * VBox Qt GUI - UISettingsSelector class declaration.
 */

/*
 * Copyright (C) 2008-2022 Oracle and/or its affiliates.
 *
 * This file is part of VirtualBox base platform packages, as
 * available from https://www.virtualbox.org.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, in version 3 of the
 * License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <https://www.gnu.org/licenses>.
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#ifndef FEQT_INCLUDED_SRC_settings_UISettingsSelector_h
#define FEQT_INCLUDED_SRC_settings_UISettingsSelector_h
#ifndef RT_WITHOUT_PRAGMA_ONCE
# pragma once
#endif

/* Qt includes: */
#include <QObject>

/* GUI includes: */
#include "UILibraryDefs.h"

/* Forward declarations: */
class QAction;
class QActionGroup;
class QTabWidget;
class QTreeWidget;
class QTreeWidgetItem;
class QITreeWidget;
class UISelectorActionItem;
class UISelectorItem;
class UISettingsPage;
class QIToolBar;


/** QObject subclass providing settings dialog
  * with the means to switch between settings pages. */
class SHARED_LIBRARY_STUFF UISettingsSelector : public QObject
{
    Q_OBJECT;

signals:

    /** Notifies listeners about selector @a iCategory changed. */
    void sigCategoryChanged(int iCategory);

public:

    /** Constructs settings selector passing @a pParent to the base-class. */
    UISettingsSelector(QWidget *pParent = 0);
    /** Destructs settings selector. */
    virtual ~UISettingsSelector() RT_OVERRIDE;

    /** Returns the widget selector operates on. */
    virtual QWidget *widget() const = 0;

    /** Adds a new selector item.
      * @param  strBigIcon     Brings the big icon reference.
      * @param  strMediumIcon  Brings the medium icon reference.
      * @param  strSmallIcon   Brings the small icon reference.
      * @param  iID            Brings the selector section ID.
      * @param  strLink        Brings the selector section link.
      * @param  pPage          Brings the selector section page reference.
      * @param  iParentID      Brings the parent section ID or -1 if there is no parent. */
    virtual QWidget *addItem(const QString &strBigIcon, const QString &strMediumIcon, const QString &strSmallIcon,
                             int iID, const QString &strLink, UISettingsPage *pPage = 0, int iParentID = -1) = 0;

    /** Defines the @a strText for section with @a iID. */
    virtual void setItemText(int iID, const QString &strText);
    /** Returns the text for section with @a iID. */
    virtual QString itemText(int iID) const = 0;
    /** Returns the text for section with @a pPage. */
    virtual QString itemTextByPage(UISettingsPage *pPage) const;

    /** Returns the current selector ID. */
    virtual int currentId() const = 0;

    /** Returns the section ID for passed @a strLink. */
    virtual int linkToId(const QString &strLink) const = 0;

    /** Returns the section page for passed @a iID. */
    virtual QWidget *idToPage(int iID) const;
    /** Returns the section root-page for passed @a iID. */
    virtual QWidget *rootPage(int iID) const { return idToPage(iID); }

    /** Make the section with @a iID current. */
    virtual void selectById(int iID) = 0;
    /** Make the section with @a strLink current. */
    virtual void selectByLink(const QString &strLink) { selectById(linkToId(strLink)); }

    /** Make the section with @a iID @a fVisible. */
    virtual void setVisibleById(int iID, bool fVisible) = 0;

    /** Returns the list of all selector pages. */
    virtual QList<UISettingsPage*> settingPages() const;
    /** Returns the list of all root pages. */
    virtual QList<QWidget*> rootPages() const;

    /** Performs selector polishing. */
    virtual void polish() {}

    /** Returns minimum selector width. */
    virtual int minWidth() const { return 0; }

protected:

    /** Clears selector of all the items. */
    virtual void clear() = 0;

    /** Searches for item with passed @a iID. */
    UISelectorItem *findItem(int iID) const;
    /** Searches for item with passed @a strLink. */
    UISelectorItem *findItemByLink(const QString &strLink) const;
    /** Searches for item with passed @a pPage. */
    UISelectorItem *findItemByPage(UISettingsPage *pPage) const;

    /** Holds the selector item instances. */
    QList<UISelectorItem*> m_list;
};


/** UISettingsSelector subclass providing settings dialog
  * with the means to switch between settings pages.
  * This one represented as tree-widget. */
class SHARED_LIBRARY_STUFF UISettingsSelectorTreeView : public UISettingsSelector
{
    Q_OBJECT;

public:

    /** Constructs settings selector passing @a pParent to the base-class. */
    UISettingsSelectorTreeView(QWidget *pParent = 0);
    /** Destructs settings selector. */
    virtual ~UISettingsSelectorTreeView() RT_OVERRIDE;

    /** Returns the widget selector operates on. */
    virtual QWidget *widget() const RT_OVERRIDE;

    /** Adds a new selector item.
      * @param  strBigIcon     Brings the big icon reference.
      * @param  strMediumIcon  Brings the medium icon reference.
      * @param  strSmallIcon   Brings the small icon reference.
      * @param  iID            Brings the selector section ID.
      * @param  strLink        Brings the selector section link.
      * @param  pPage          Brings the selector section page reference.
      * @param  iParentID      Brings the parent section ID or -1 if there is no parent. */
    virtual QWidget *addItem(const QString &strBigIcon, const QString &strMediumIcon, const QString &strSmallIcon,
                             int iID, const QString &strLink, UISettingsPage *pPage = 0, int iParentID = -1) RT_OVERRIDE;

    /** Defines the @a strText for section with @a iID. */
    virtual void setItemText(int iID, const QString &strText) RT_OVERRIDE;
    /** Returns the text for section with @a iID. */
    virtual QString itemText(int iID) const RT_OVERRIDE;

    /** Returns the current selector ID. */
    virtual int currentId() const RT_OVERRIDE;

    /** Returns the section ID for passed @a strLink. */
    virtual int linkToId(const QString &strLink) const RT_OVERRIDE;

    /** Make the section with @a iID current. */
    virtual void selectById(int iID) RT_OVERRIDE;

    /** Make the section with @a iID @a fVisible. */
    virtual void setVisibleById(int iID, bool fVisible) RT_OVERRIDE;

    /** Performs selector polishing. */
    virtual void polish() RT_OVERRIDE;

private slots:

    /** Handles selector section change from @a pPrevItem to @a pItem. */
    void sltSettingsGroupChanged(QTreeWidgetItem *pItem, QTreeWidgetItem *pPrevItem);

private:

    /** Clears selector of all the items. */
    virtual void clear() RT_OVERRIDE;

    /** Returns page path for passed @a strMatch. */
    QString pagePath(const QString &strMatch) const;
    /** Find item within the passed @a pView and @a iColumn matching @a strMatch. */
    QTreeWidgetItem *findItem(QTreeWidget *pView, const QString &strMatch, int iColumn) const;
    /** Performs @a iID to QString serialization. */
    QString idToString(int iID) const;

    /** Forges the full path for passed @a pItem. */
    static QString path(const QTreeWidgetItem *pItem);

    /** Holds the tree-widget instance. */
    QITreeWidget *m_pTreeWidget;
};


/** UISettingsSelector subclass providing settings dialog
  * with the means to switch between settings pages.
  * This one represented as tab-widget. */
class SHARED_LIBRARY_STUFF UISettingsSelectorToolBar : public UISettingsSelector
{
    Q_OBJECT;

public:

    /** Constructs settings selector passing @a pParent to the base-class. */
    UISettingsSelectorToolBar(QWidget *pParent = 0);
    /** Destructs settings selector. */
    virtual ~UISettingsSelectorToolBar() RT_OVERRIDE;

    /** Returns the widget selector operates on. */
    virtual QWidget *widget() const RT_OVERRIDE;

    /** Adds a new selector item.
      * @param  strBigIcon     Brings the big icon reference.
      * @param  strMediumIcon  Brings the medium icon reference.
      * @param  strSmallIcon   Brings the small icon reference.
      * @param  iID            Brings the selector section ID.
      * @param  strLink        Brings the selector section link.
      * @param  pPage          Brings the selector section page reference.
      * @param  iParentID      Brings the parent section ID or -1 if there is no parent. */
    virtual QWidget *addItem(const QString &strBigIcon, const QString &strMediumIcon, const QString &strSmallIcon,
                             int iID, const QString &strLink, UISettingsPage *pPage = 0, int iParentID = -1) RT_OVERRIDE;

    /** Defines the @a strText for section with @a iID. */
    virtual void setItemText(int iID, const QString &strText) RT_OVERRIDE;
    /** Returns the text for section with @a iID. */
    virtual QString itemText(int iID) const RT_OVERRIDE;

    /** Returns the current selector ID. */
    virtual int currentId() const RT_OVERRIDE;

    /** Returns the section ID for passed @a strLink. */
    virtual int linkToId(const QString &strLink) const RT_OVERRIDE;

    /** Returns the section page for passed @a iID. */
    virtual QWidget *idToPage(int iID) const RT_OVERRIDE;
    /** Returns the section root-page for passed @a iID. */
    virtual QWidget *rootPage(int iID) const RT_OVERRIDE;

    /** Make the section with @a iID current. */
    virtual void selectById(int iID) RT_OVERRIDE;

    /** Make the section with @a iID @a fVisible. */
    virtual void setVisibleById(int iID, bool fVisible) RT_OVERRIDE;

    /** Returns the list of all root pages. */
    virtual QList<QWidget*> rootPages() const RT_OVERRIDE;

    /** Returns minimum selector width. */
    virtual int minWidth() const RT_OVERRIDE;

private slots:

    /** Handles selector section change to @a pAction. */
    void sltSettingsGroupChanged(QAction *pAction);
    /** Handles selector section change to @a iIndex. */
    void sltSettingsGroupChanged(int iIndex);

private:

    /** Clears selector of all the items. */
    virtual void clear() RT_OVERRIDE;

    /** Searches for action item with passed @a iID. */
    UISelectorActionItem *findActionItem(int iID) const;
    /** Searches for action item with passed @a pAction. */
    UISelectorActionItem *findActionItemByAction(QAction *pAction) const;
    /** Searches for action item with passed @a pTabWidget and @a iIndex. */
    UISelectorActionItem *findActionItemByTabWidget(QTabWidget *pTabWidget, int iIndex) const;

    /** Holds the toolbar instance. */
    QIToolBar *m_pToolBar;
    /** Holds the action group instance. */
    QActionGroup *m_pActionGroup;
};


#endif /* !FEQT_INCLUDED_SRC_settings_UISettingsSelector_h */