diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-05-29 10:24:09 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-06-09 08:02:56 +0000 |
commit | 4048645d204173a5d7ae5c1548611f2d6b003c97 (patch) | |
tree | 0c4d9e0a9e99c4a1742489e0a2111480665a3e2b /src/imports/nativestyle/controls | |
parent | 62fa08d89eadfcd79cd4a51b997223eb6ec24d5e (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/controls')
-rw-r--r-- | src/imports/nativestyle/controls/DefaultComboBox.qml | 134 | ||||
-rw-r--r-- | src/imports/nativestyle/controls/controls.pri | 1 |
2 files changed, 135 insertions, 0 deletions
diff --git a/src/imports/nativestyle/controls/DefaultComboBox.qml b/src/imports/nativestyle/controls/DefaultComboBox.qml new file mode 100644 index 00000000..0ae111fe --- /dev/null +++ b/src/imports/nativestyle/controls/DefaultComboBox.qml @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.15 +import QtQuick.Window 2.15 +import QtQuick.Controls 2.15 +import QtQuick.Controls.impl 2.15 +import QtQuick.Templates 2.15 as T +import QtQuick.NativeStyle 6.0 as NativeStyle + +T.ComboBox { + id: control + + readonly property bool nativeBackground: background instanceof NativeStyle.StyleItem + + implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, + implicitContentWidth + leftPadding + rightPadding) + implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, + implicitContentHeight + topPadding + bottomPadding, + implicitIndicatorHeight + topPadding + bottomPadding) + + font.pixelSize: nativeBackground ? background.styleFont(control).pixelSize : undefined + + leftPadding: nativeBackground ? background.contentPadding.left : 5 + rightPadding: nativeBackground ? background.contentPadding.right : 5 + topPadding: nativeBackground ? background.contentPadding.top : 5 + bottomPadding: nativeBackground ? background.contentPadding.bottom : 5 + + topInset: nativeBackground ? background.insets.top : 0 + bottomInset: nativeBackground ? background.insets.bottom : 0 + leftInset: nativeBackground ? background.insets.left : 0 + rightInset: nativeBackground ? background.insets.right : 0 + + contentItem: T.TextField { + id: textField + + implicitWidth: textField.contentWidth + implicitHeight: textField.contentHeight + text: control.editable ? control.editText : control.displayText + + enabled: control.editable + autoScroll: control.editable + readOnly: control.down + inputMethodHints: control.inputMethodHints + validator: control.validator + selectByMouse: control.selectTextByMouse + + font: control.font + color: control.editable ? control.palette.text : control.palette.buttonText + selectionColor: control.palette.highlight + selectedTextColor: control.palette.highlightedText + verticalAlignment: Text.AlignVCenter + } + + background: NativeStyle.ComboBox { + control: control + contentWidth: contentItem.implicitWidth + contentHeight: contentItem.implicitHeight + } + + delegate: ItemDelegate { + width: ListView.view.width + text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData + palette.text: control.palette.text + palette.highlightedText: control.palette.highlightedText + font.weight: control.currentIndex === index ? Font.DemiBold : Font.Normal + highlighted: control.highlightedIndex === index + hoverEnabled: control.hoverEnabled + } + + popup: T.Popup { + x: control.nativeBackground ? control.background.layoutRect.x : 0 + y: control.nativeBackground ? control.background.layoutRect.y + control.background.layoutRect.height : control.height + width: control.nativeBackground ? control.background.layoutRect.width : control.width + height: Math.min(contentItem.implicitHeight, control.Window.height - topMargin - bottomMargin) + topMargin: 6 + bottomMargin: 6 + + contentItem: ListView { + clip: true + implicitHeight: contentHeight + model: control.delegateModel + currentIndex: control.highlightedIndex + highlightMoveDuration: 0 + + Rectangle { + z: 10 + width: parent.width + height: parent.height + color: "transparent" + border.color: control.palette.mid + } + + T.ScrollIndicator.vertical: ScrollIndicator { } + } + + background: Rectangle { + color: control.palette.window + } + } +} diff --git a/src/imports/nativestyle/controls/controls.pri b/src/imports/nativestyle/controls/controls.pri index 493b8956..3e175c83 100644 --- a/src/imports/nativestyle/controls/controls.pri +++ b/src/imports/nativestyle/controls/controls.pri @@ -8,3 +8,4 @@ QML_FILES += \ $$PWD/DefaultTextField.qml \ $$PWD/DefaultFrame.qml \ $$PWD/DefaultTextArea.qml \ + $$PWD/DefaultComboBox.qml \ |