| 1 | // Copyright (C) 2017 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QQUICKCOMBOBOX_P_H |
| 5 | #define QQUICKCOMBOBOX_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtCore/qloggingcategory.h> |
| 19 | #include <QtQmlModels/private/qtqmlmodels-config_p.h> |
| 20 | #include <QtQuickTemplates2/private/qquickcontrol_p.h> |
| 21 | |
| 22 | QT_REQUIRE_CONFIG(qml_delegate_model); |
| 23 | |
| 24 | QT_BEGIN_NAMESPACE |
| 25 | |
| 26 | Q_DECLARE_LOGGING_CATEGORY(lcItemManagement) |
| 27 | |
| 28 | class QValidator; |
| 29 | class ; |
| 30 | class QQmlInstanceModel; |
| 31 | class QQuickComboBoxPrivate; |
| 32 | |
| 33 | class Q_QUICKTEMPLATES2_EXPORT QQuickComboBox : public QQuickControl |
| 34 | { |
| 35 | Q_OBJECT |
| 36 | Q_PROPERTY(int count READ count NOTIFY countChanged FINAL) |
| 37 | Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged FINAL) |
| 38 | Q_PROPERTY(QQmlInstanceModel *delegateModel READ delegateModel NOTIFY delegateModelChanged FINAL) |
| 39 | Q_PROPERTY(bool pressed READ isPressed NOTIFY pressedChanged FINAL) |
| 40 | Q_PROPERTY(int highlightedIndex READ highlightedIndex NOTIFY highlightedIndexChanged FINAL) |
| 41 | Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL) |
| 42 | Q_PROPERTY(QString currentText READ currentText NOTIFY currentTextChanged FINAL) |
| 43 | Q_PROPERTY(QString displayText READ displayText WRITE setDisplayText RESET resetDisplayText NOTIFY displayTextChanged FINAL) |
| 44 | Q_PROPERTY(QString textRole READ textRole WRITE setTextRole NOTIFY textRoleChanged FINAL) |
| 45 | Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL) |
| 46 | Q_PROPERTY(QQuickItem *indicator READ indicator WRITE setIndicator NOTIFY indicatorChanged FINAL) |
| 47 | Q_PROPERTY(QQuickPopup *popup READ popup WRITE setPopup NOTIFY popupChanged FINAL) |
| 48 | // 2.1 (Qt 5.8) |
| 49 | Q_PROPERTY(bool flat READ isFlat WRITE setFlat NOTIFY flatChanged FINAL REVISION(2, 1)) |
| 50 | // 2.2 (Qt 5.9) |
| 51 | Q_PROPERTY(bool down READ isDown WRITE setDown RESET resetDown NOTIFY downChanged FINAL REVISION(2, 2)) |
| 52 | Q_PROPERTY(bool editable READ isEditable WRITE setEditable NOTIFY editableChanged FINAL REVISION(2, 2)) |
| 53 | Q_PROPERTY(QString editText READ editText WRITE setEditText RESET resetEditText NOTIFY editTextChanged FINAL REVISION(2, 2)) |
| 54 | #if QT_CONFIG(validator) |
| 55 | Q_PROPERTY(QValidator *validator READ validator WRITE setValidator NOTIFY validatorChanged FINAL REVISION(2, 2)) |
| 56 | #endif |
| 57 | Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged FINAL REVISION(2, 2)) |
| 58 | Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged FINAL REVISION(2, 2)) |
| 59 | Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged FINAL REVISION(2, 2)) |
| 60 | // 2.5 (Qt 5.12) |
| 61 | Q_PROPERTY(qreal implicitIndicatorWidth READ implicitIndicatorWidth NOTIFY implicitIndicatorWidthChanged FINAL REVISION(2, 5)) |
| 62 | Q_PROPERTY(qreal implicitIndicatorHeight READ implicitIndicatorHeight NOTIFY implicitIndicatorHeightChanged FINAL REVISION(2, 5)) |
| 63 | Q_CLASSINFO("DeferredPropertyNames" , "background,contentItem,indicator,popup" ) |
| 64 | // 2.14 (Qt 5.14) |
| 65 | Q_PROPERTY(QVariant currentValue READ currentValue NOTIFY currentValueChanged FINAL REVISION(2, 14)) |
| 66 | Q_PROPERTY(QString valueRole READ valueRole WRITE setValueRole NOTIFY valueRoleChanged FINAL REVISION(2, 14)) |
| 67 | // 2.15 (Qt 5.15) |
| 68 | Q_PROPERTY(bool selectTextByMouse READ selectTextByMouse WRITE setSelectTextByMouse NOTIFY selectTextByMouseChanged FINAL REVISION(2, 15)) |
| 69 | // 6.0 (Qt 6.0) |
| 70 | Q_PROPERTY(ImplicitContentWidthPolicy implicitContentWidthPolicy READ implicitContentWidthPolicy |
| 71 | WRITE setImplicitContentWidthPolicy NOTIFY implicitContentWidthPolicyChanged FINAL REVISION(6, 0)) |
| 72 | QML_NAMED_ELEMENT(ComboBox) |
| 73 | QML_ADDED_IN_VERSION(2, 0) |
| 74 | |
| 75 | public: |
| 76 | explicit QQuickComboBox(QQuickItem *parent = nullptr); |
| 77 | ~QQuickComboBox(); |
| 78 | |
| 79 | int count() const; |
| 80 | |
| 81 | QVariant model() const; |
| 82 | void setModel(const QVariant &model); |
| 83 | QQmlInstanceModel *delegateModel() const; |
| 84 | |
| 85 | bool isPressed() const; |
| 86 | void setPressed(bool pressed); |
| 87 | |
| 88 | int highlightedIndex() const; |
| 89 | |
| 90 | int currentIndex() const; |
| 91 | void setCurrentIndex(int index); |
| 92 | |
| 93 | QString currentText() const; |
| 94 | |
| 95 | QString displayText() const; |
| 96 | void setDisplayText(const QString &text); |
| 97 | void resetDisplayText(); |
| 98 | |
| 99 | QString textRole() const; |
| 100 | void setTextRole(const QString &role); |
| 101 | |
| 102 | QString valueRole() const; |
| 103 | void setValueRole(const QString &role); |
| 104 | |
| 105 | QQmlComponent *delegate() const; |
| 106 | void setDelegate(QQmlComponent *delegate); |
| 107 | |
| 108 | QQuickItem *indicator() const; |
| 109 | void setIndicator(QQuickItem *indicator); |
| 110 | |
| 111 | QQuickPopup *() const; |
| 112 | void (QQuickPopup *); |
| 113 | |
| 114 | Q_INVOKABLE QString textAt(int index) const; |
| 115 | Q_INVOKABLE int find(const QString &text, Qt::MatchFlags flags = Qt::MatchExactly) const; |
| 116 | |
| 117 | // 2.1 (Qt 5.8) |
| 118 | bool isFlat() const; |
| 119 | void setFlat(bool flat); |
| 120 | |
| 121 | // 2.2 (Qt 5.9) |
| 122 | bool isDown() const; |
| 123 | void setDown(bool down); |
| 124 | void resetDown(); |
| 125 | |
| 126 | bool isEditable() const; |
| 127 | void setEditable(bool editable); |
| 128 | |
| 129 | QString editText() const; |
| 130 | void setEditText(const QString &text); |
| 131 | void resetEditText(); |
| 132 | |
| 133 | #if QT_CONFIG(validator) |
| 134 | QValidator *validator() const; |
| 135 | void setValidator(QValidator *validator); |
| 136 | #endif |
| 137 | |
| 138 | Qt::InputMethodHints inputMethodHints() const; |
| 139 | void setInputMethodHints(Qt::InputMethodHints hints); |
| 140 | |
| 141 | bool isInputMethodComposing() const; |
| 142 | bool hasAcceptableInput() const; |
| 143 | |
| 144 | // 2.5 (Qt 5.12) |
| 145 | qreal implicitIndicatorWidth() const; |
| 146 | qreal implicitIndicatorHeight() const; |
| 147 | |
| 148 | // 2.14 (Qt 5.14) |
| 149 | QVariant currentValue() const; |
| 150 | Q_REVISION(2, 14) Q_INVOKABLE QVariant valueAt(int index) const; |
| 151 | Q_REVISION(2, 14) Q_INVOKABLE int indexOfValue(const QVariant &value) const; |
| 152 | |
| 153 | // 2.15 (Qt 5.15) |
| 154 | bool selectTextByMouse() const; |
| 155 | void setSelectTextByMouse(bool canSelect); |
| 156 | |
| 157 | // 6.0 (Qt 6.0) |
| 158 | enum ImplicitContentWidthPolicy { |
| 159 | ContentItemImplicitWidth, |
| 160 | WidestText, |
| 161 | WidestTextWhenCompleted |
| 162 | }; |
| 163 | Q_ENUM(ImplicitContentWidthPolicy) |
| 164 | |
| 165 | ImplicitContentWidthPolicy implicitContentWidthPolicy() const; |
| 166 | void setImplicitContentWidthPolicy(ImplicitContentWidthPolicy policy); |
| 167 | |
| 168 | public Q_SLOTS: |
| 169 | void incrementCurrentIndex(); |
| 170 | void decrementCurrentIndex(); |
| 171 | Q_REVISION(2, 2) void selectAll(); |
| 172 | |
| 173 | Q_SIGNALS: |
| 174 | void activated(int index); |
| 175 | void highlighted(int index); |
| 176 | void countChanged(); |
| 177 | void modelChanged(); |
| 178 | void delegateModelChanged(); |
| 179 | void pressedChanged(); |
| 180 | void highlightedIndexChanged(); |
| 181 | void currentIndexChanged(); |
| 182 | void currentTextChanged(); |
| 183 | void displayTextChanged(); |
| 184 | void textRoleChanged(); |
| 185 | void delegateChanged(); |
| 186 | void indicatorChanged(); |
| 187 | void (); |
| 188 | // 2.1 (Qt 5.8) |
| 189 | Q_REVISION(2, 1) void flatChanged(); |
| 190 | // 2.2 (Qt 5.9) |
| 191 | Q_REVISION(2, 2) void accepted(); |
| 192 | Q_REVISION(2, 2) void downChanged(); |
| 193 | Q_REVISION(2, 2) void editableChanged(); |
| 194 | Q_REVISION(2, 2) void editTextChanged(); |
| 195 | #if QT_CONFIG(validator) |
| 196 | Q_REVISION(2, 2) void validatorChanged(); |
| 197 | #endif |
| 198 | Q_REVISION(2, 2) void inputMethodHintsChanged(); |
| 199 | Q_REVISION(2, 2) void inputMethodComposingChanged(); |
| 200 | Q_REVISION(2, 2) void acceptableInputChanged(); |
| 201 | // 2.5 (Qt 5.12) |
| 202 | Q_REVISION(2, 5) void implicitIndicatorWidthChanged(); |
| 203 | Q_REVISION(2, 5) void implicitIndicatorHeightChanged(); |
| 204 | // 2.14 (Qt 5.14) |
| 205 | Q_REVISION(2, 14) void valueRoleChanged(); |
| 206 | Q_REVISION(2, 14) void currentValueChanged(); |
| 207 | // 2.15 (Qt 5.15) |
| 208 | Q_REVISION(2, 15) void selectTextByMouseChanged(); |
| 209 | // 6.0 (Qt 6.0) |
| 210 | Q_REVISION(6, 0) void implicitContentWidthPolicyChanged(); |
| 211 | |
| 212 | protected: |
| 213 | bool eventFilter(QObject *object, QEvent *event) override; |
| 214 | void focusInEvent(QFocusEvent *event) override; |
| 215 | void focusOutEvent(QFocusEvent *event) override; |
| 216 | #if QT_CONFIG(im) |
| 217 | void inputMethodEvent(QInputMethodEvent *event) override; |
| 218 | #endif |
| 219 | void keyPressEvent(QKeyEvent *event) override; |
| 220 | void keyReleaseEvent(QKeyEvent *event) override; |
| 221 | #if QT_CONFIG(wheelevent) |
| 222 | void wheelEvent(QWheelEvent *event) override; |
| 223 | #endif |
| 224 | bool event(QEvent *e) override; |
| 225 | |
| 226 | void componentComplete() override; |
| 227 | void itemChange(ItemChange change, const ItemChangeData &value) override; |
| 228 | void fontChange(const QFont &newFont, const QFont &oldFont) override; |
| 229 | void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) override; |
| 230 | void localeChange(const QLocale &newLocale, const QLocale &oldLocale) override; |
| 231 | |
| 232 | QFont defaultFont() const override; |
| 233 | |
| 234 | #if QT_CONFIG(accessibility) |
| 235 | QAccessible::Role accessibleRole() const override; |
| 236 | void accessibilityActiveChanged(bool active) override; |
| 237 | #endif |
| 238 | |
| 239 | private: |
| 240 | Q_DISABLE_COPY(QQuickComboBox) |
| 241 | Q_DECLARE_PRIVATE(QQuickComboBox) |
| 242 | }; |
| 243 | |
| 244 | QT_END_NAMESPACE |
| 245 | |
| 246 | #endif // QQUICKCOMBOBOX_P_H |
| 247 | |