VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIComboBox.h

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 KB
Line 
1/* $Id: QIComboBox.h 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - Qt extensions: QIComboBox class declaration.
4 */
5
6/*
7 * Copyright (C) 2016-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_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. */
41class 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
50signals:
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
70public:
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 = QString());
133
134 /** Inserts separator at position with specified @a iIndex. */
135 void insertSeparator(int iIndex);
136
137public slots:
138
139 /** Clears the combobox, removing all items. */
140 void clear();
141
142 /** Defines the @a size of the icons shown in the combo-box. */
143 void setIconSize(const QSize &size) const;
144 /** Defines the combo-box insert @a policy. */
145 void setInsertPolicy(QComboBox::InsertPolicy policy) const;
146 /** Defines whether the combo-box is @a fEditable. */
147 void setEditable(bool fEditable) const;
148
149 /** Defines the @a iIndex of the current item in the combo-box. */
150 void setCurrentIndex(int iIndex) const;
151
152 /** Defines the @a data for the item with the given @a iIndex and specified @a iRole. */
153 void setItemData(int iIndex, const QVariant &value, int iRole = Qt::UserRole) const;
154 /** Defines the @a icon for the item with the given @a iIndex. */
155 void setItemIcon(int iIndex, const QIcon &icon) const;
156 /** Defines the @a strText for the item with the given @a iIndex. */
157 void setItemText(int iIndex, const QString &strText) const;
158
159protected:
160
161 /** Returns the embedded combo-box reference. */
162 QComboBox *comboBox() const;
163
164private:
165
166 /** Prepares all. */
167 void prepare();
168
169 /** Holds the original combo-box instance. */
170 QComboBox *m_pComboBox;
171};
172
173#endif /* !FEQT_INCLUDED_SRC_extensions_QIComboBox_h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use