aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/nativestyle/items
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-05-29 10:24:09 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-06-09 08:02:56 +0000
commit4048645d204173a5d7ae5c1548611f2d6b003c97 (patch)
tree0c4d9e0a9e99c4a1742489e0a2111480665a3e2b /src/imports/nativestyle/items
parent62fa08d89eadfcd79cd4a51b997223eb6ec24d5e (diff)
NativeStyle: add ComboBox
Change-Id: Ia6387857ba012ba7f6df453e64dd9419f7979db8 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'src/imports/nativestyle/items')
-rw-r--r--src/imports/nativestyle/items/items.pri2
-rw-r--r--src/imports/nativestyle/items/qquickstyleitemcombobox.cpp88
-rw-r--r--src/imports/nativestyle/items/qquickstyleitemcombobox.h60
3 files changed, 150 insertions, 0 deletions
diff --git a/src/imports/nativestyle/items/items.pri b/src/imports/nativestyle/items/items.pri
index 1816033f..1bb311fd 100644
--- a/src/imports/nativestyle/items/items.pri
+++ b/src/imports/nativestyle/items/items.pri
@@ -11,6 +11,7 @@ HEADERS += \
$$PWD/qquickstyleitemtextfield.h \
$$PWD/qquickstyleitemframe.h \
$$PWD/qquickstyleitemtextarea.h \
+ $$PWD/qquickstyleitemcombobox.h \
SOURCES += \
$$PWD/qquickstyleitem.cpp \
@@ -23,3 +24,4 @@ SOURCES += \
$$PWD/qquickstyleitemtextfield.cpp \
$$PWD/qquickstyleitemframe.cpp \
$$PWD/qquickstyleitemtextarea.cpp \
+ $$PWD/qquickstyleitemcombobox.cpp \
diff --git a/src/imports/nativestyle/items/qquickstyleitemcombobox.cpp b/src/imports/nativestyle/items/qquickstyleitemcombobox.cpp
new file mode 100644
index 00000000..c9b7fca1
--- /dev/null
+++ b/src/imports/nativestyle/items/qquickstyleitemcombobox.cpp
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquickstyleitemcombobox.h"
+
+QFont QQuickStyleItemComboBox::styleFont(QQuickItem *control)
+{
+ return style()->font(QStyle::CE_PushButtonLabel, controlSize(control));
+}
+
+void QQuickStyleItemComboBox::connectToControl()
+{
+ QQuickStyleItem::connectToControl();
+ auto comboBox = control<QQuickComboBox>();
+ connect(comboBox, &QQuickComboBox::downChanged, this, &QQuickStyleItem::markImageDirty);
+}
+
+StyleItemGeometry QQuickStyleItemComboBox::calculateGeometry()
+{
+ QStyleOptionComboBox styleOption;
+ initStyleOption(styleOption);
+ StyleItemGeometry geometry;
+
+ geometry.minimumSize = style()->sizeFromContents(QStyle::CT_ComboBox, &styleOption, QSize(0, 0));
+ geometry.implicitSize = style()->sizeFromContents(QStyle::CT_ComboBox, &styleOption, contentSize());
+ styleOption.rect = QRect(QPoint(0, 0), geometry.implicitSize);
+ geometry.contentRect = style()->subControlRect(QStyle::CC_ComboBox, &styleOption, QStyle::SC_ComboBoxEditField);
+ geometry.layoutRect = style()->subElementRect(QStyle::SE_ComboBoxLayoutItem, &styleOption);
+ geometry.ninePatchMargins = style()->ninePatchMargins(QStyle::CC_ComboBox, &styleOption, geometry.minimumSize);
+
+ return geometry;
+}
+
+void QQuickStyleItemComboBox::paintEvent(QPainter *painter)
+{
+ QStyleOptionComboBox styleOption;
+ initStyleOption(styleOption);
+ style()->drawComplexControl(QStyle::CC_ComboBox, &styleOption, painter);
+}
+
+void QQuickStyleItemComboBox::initStyleOption(QStyleOptionComboBox &styleOption)
+{
+ initStyleOptionBase(styleOption);
+ auto comboBox = control<QQuickComboBox>();
+
+ styleOption.subControls = QStyle::SC_ComboBoxFrame | QStyle::SC_ComboBoxArrow;// | QStyle::SC_ComboBoxEditField | QStyle::SC_ComboBoxArrow;
+ styleOption.frame = true;
+ styleOption.state |= QStyle::State_Selected;
+ styleOption.editable = comboBox->isEditable();
+
+ if (comboBox->isDown())
+ styleOption.state |= QStyle::State_Sunken;
+ if (!comboBox->isFlat() && !comboBox->isDown())
+ styleOption.state |= QStyle::State_Raised;
+}
diff --git a/src/imports/nativestyle/items/qquickstyleitemcombobox.h b/src/imports/nativestyle/items/qquickstyleitemcombobox.h
new file mode 100644
index 00000000..f446b191
--- /dev/null
+++ b/src/imports/nativestyle/items/qquickstyleitemcombobox.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKSTYLEITEMCOMBOBOX_H
+#define QQUICKSTYLEITEMCOMBOBOX_H
+
+#include "qquickstyleitem.h"
+#include <QtQuickTemplates2/private/qquickcombobox_p.h>
+
+class QQuickStyleItemComboBox : public QQuickStyleItem
+{
+ Q_OBJECT
+ QML_NAMED_ELEMENT(ComboBox)
+
+public:
+ QFont styleFont(QQuickItem *control) override;
+
+protected:
+ void connectToControl() override;
+ void paintEvent(QPainter *painter) override;
+ StyleItemGeometry calculateGeometry() override;
+
+private:
+ void initStyleOption(QStyleOptionComboBox &styleOption);
+};
+
+#endif // QQUICKSTYLEITEMCOMBOBOX_H