1 | /* $Id: QIComboBox.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Qt extensions: QIComboBox class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2016-2024 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_extensions_QIComboBox_h
|
---|
29 | #define FEQT_INCLUDED_SRC_extensions_QIComboBox_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QComboBox>
|
---|
36 |
|
---|
37 | /* GUI includes: */
|
---|
38 | #include "UILibraryDefs.h"
|
---|
39 |
|
---|
40 | /** QWidget subclass extending standard functionality of QComboBox. */
|
---|
41 | class SHARED_LIBRARY_STUFF QIComboBox : public QWidget
|
---|
42 | {
|
---|
43 | Q_OBJECT;
|
---|
44 |
|
---|
45 | /** Enumerates sub-element indexes for basic case. */
|
---|
46 | enum { SubElement_Selector, SubElement_Max };
|
---|
47 | /** Enumerates sub-element indexes for editable case. */
|
---|
48 | enum { SubElementEditable_Editor, SubElementEditable_Selector, SubElementEditable_Max };
|
---|
49 |
|
---|
50 | signals:
|
---|
51 |
|
---|
52 | /** Notifies listeners about user chooses an item with @a iIndex in the combo-box. */
|
---|
53 | void activated(int iIndex);
|
---|
54 | /** Notifies listeners about user chooses an item with @a strText in the combo-box. */
|
---|
55 | void textActivated(const QString &strText);
|
---|
56 |
|
---|
57 | /** Notifies listeners about current item changed to item with @a iIndex. */
|
---|
58 | void currentIndexChanged(int iIndex);
|
---|
59 |
|
---|
60 | /** Notifies listeners about current combo-box text is changed to @a strText. */
|
---|
61 | void currentTextChanged(const QString &strText);
|
---|
62 | /** Notifies listeners about current combo-box editable text is changed to @a strText. */
|
---|
63 | void editTextChanged(const QString &strText);
|
---|
64 |
|
---|
65 | /** Notifies listeners about user highlighted an item with @a iIndex in the popup list-view. */
|
---|
66 | void highlighted(int iIndex);
|
---|
67 | /** Notifies listeners about user highlighted an item with @a strText in the popup list-view. */
|
---|
68 | void textHighlighted(const QString &strText);
|
---|
69 |
|
---|
70 | public:
|
---|
71 |
|
---|
72 | /** Constructs combo-box passing @a pParent to the base-class. */
|
---|
73 | QIComboBox(QWidget *pParent = 0);
|
---|
74 |
|
---|
75 | /** Returns sub-element count. */
|
---|
76 | int subElementCount() const;
|
---|
77 | /** Returns sub-element with passed @a iIndex. */
|
---|
78 | QWidget *subElement(int iIndex) const;
|
---|
79 |
|
---|
80 | /** Returns the embedded line-editor reference. */
|
---|
81 | QLineEdit *lineEdit() const;
|
---|
82 | /** Returns the embedded list-view reference. */
|
---|
83 | QAbstractItemView *view() const;
|
---|
84 |
|
---|
85 | /** Returns the size of the icons shown in the combo-box. */
|
---|
86 | QSize iconSize() const;
|
---|
87 | /** Returns the combo-box insert policy. */
|
---|
88 | QComboBox::InsertPolicy insertPolicy() const;
|
---|
89 | /** Returns whether the combo-box is editable. */
|
---|
90 | bool isEditable() const;
|
---|
91 |
|
---|
92 | /** Returns the number of items in the combo-box. */
|
---|
93 | int count() const;
|
---|
94 | /** Returns the index of the current item in the combo-box. */
|
---|
95 | int currentIndex() const;
|
---|
96 | /** Returns the text of the current item in the combo-box. */
|
---|
97 | QString currentText() const;
|
---|
98 | /** Returns the data of the current item in the combo-box. */
|
---|
99 | QVariant currentData(int iRole = Qt::UserRole) const;
|
---|
100 |
|
---|
101 | /** Adds the @a items into the combo-box. */
|
---|
102 | void addItems(const QStringList &items) const;
|
---|
103 | /** Adds the @a strText and userData (stored in the Qt::UserRole) into the combo-box. */
|
---|
104 | void addItem(const QString &strText, const QVariant &userData = QVariant()) const;
|
---|
105 | /** Inserts the @a items into the combo-box at the given @a iIndex. */
|
---|
106 | void insertItems(int iIndex, const QStringList &items);
|
---|
107 | /** Inserts the @a strText and userData (stored in the Qt::UserRole) into the combo-box at the given @a iIndex. */
|
---|
108 | void insertItem(int iIndex, const QString &strText, const QVariant &userData = QVariant()) const;
|
---|
109 | /** Removes the item from the combo-box at the given @a iIndex. */
|
---|
110 | void removeItem(int iIndex) const;
|
---|
111 |
|
---|
112 | /** Returns the data for the item with the given @a iIndex and specified @a iRole. */
|
---|
113 | QVariant itemData(int iIndex, int iRole = Qt::UserRole) const;
|
---|
114 | /** Returns the icon for the item with the given @a iIndex. */
|
---|
115 | QIcon itemIcon(int iIndex) const;
|
---|
116 | /** Returns the text for the item with the given @a iIndex. */
|
---|
117 | QString itemText(int iIndex) const;
|
---|
118 |
|
---|
119 | /** Returns the index of the item containing the given @a data for the given @a iRole; otherwise returns -1.
|
---|
120 | * @param flags Specifies how the items in the combobox are searched. */
|
---|
121 | int findData(const QVariant &data, int iRole = Qt::UserRole,
|
---|
122 | Qt::MatchFlags flags = static_cast<Qt::MatchFlags>(Qt::MatchExactly | Qt::MatchCaseSensitive)) const;
|
---|
123 | /** Returns the index of the item containing the given @a strText; otherwise returns -1.
|
---|
124 | * @param flags Specifies how the items in the combobox are searched. */
|
---|
125 | int findText(const QString &strText, Qt::MatchFlags flags = static_cast<Qt::MatchFlags>(Qt::MatchExactly | Qt::MatchCaseSensitive)) const;
|
---|
126 |
|
---|
127 | /** Returns size adjust policy. */
|
---|
128 | QComboBox::SizeAdjustPolicy sizeAdjustPolicy() const;
|
---|
129 | /** Defines size adjust @a enmPolicy. */
|
---|
130 | void setSizeAdjustPolicy(QComboBox::SizeAdjustPolicy enmPolicy);
|
---|
131 | /** Marks the line edit of the combobox. Refer to QILineEdit::mark(..). */
|
---|
132 | void mark(bool fError, const QString &strErrorMessage, const QString &strNoErrorMessage);
|
---|
133 |
|
---|
134 | /** Inserts separator at position with specified @a iIndex. */
|
---|
135 | void insertSeparator(int iIndex);
|
---|
136 |
|
---|
137 | /** Calls QILineEdit member's setMarkable API. */
|
---|
138 | void setMarkable(bool fMarkable);
|
---|
139 |
|
---|
140 | public slots:
|
---|
141 |
|
---|
142 | /** Clears the combobox, removing all items. */
|
---|
143 | void clear();
|
---|
144 |
|
---|
145 | /** Defines the @a size of the icons shown in the combo-box. */
|
---|
146 | void setIconSize(const QSize &size) const;
|
---|
147 | /** Defines the combo-box insert @a policy. */
|
---|
148 | void setInsertPolicy(QComboBox::InsertPolicy policy) const;
|
---|
149 | /** Defines whether the combo-box is @a fEditable. */
|
---|
150 | void setEditable(bool fEditable) const;
|
---|
151 |
|
---|
152 | /** Defines the @a iIndex of the current item in the combo-box. */
|
---|
153 | void setCurrentIndex(int iIndex) const;
|
---|
154 |
|
---|
155 | /** Defines the @a data for the item with the given @a iIndex and specified @a iRole. */
|
---|
156 | void setItemData(int iIndex, const QVariant &value, int iRole = Qt::UserRole) const;
|
---|
157 | /** Defines the @a icon for the item with the given @a iIndex. */
|
---|
158 | void setItemIcon(int iIndex, const QIcon &icon) const;
|
---|
159 | /** Defines the @a strText for the item with the given @a iIndex. */
|
---|
160 | void setItemText(int iIndex, const QString &strText) const;
|
---|
161 |
|
---|
162 | protected:
|
---|
163 |
|
---|
164 | /** Returns the embedded combo-box reference. */
|
---|
165 | QComboBox *comboBox() const;
|
---|
166 |
|
---|
167 | private:
|
---|
168 |
|
---|
169 | /** Prepares all. */
|
---|
170 | void prepare();
|
---|
171 |
|
---|
172 | /** Holds the original combo-box instance. */
|
---|
173 | QComboBox *m_pComboBox;
|
---|
174 | };
|
---|
175 |
|
---|
176 | #endif /* !FEQT_INCLUDED_SRC_extensions_QIComboBox_h */
|
---|