aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols2/material/ComboBox.qml
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2021-07-28 11:21:25 +0200
committerMitch Curtis <mitch.curtis@qt.io>2021-07-28 11:21:25 +0200
commit16436239cd35ba7346b89a1f57d5b29dc786f4c6 (patch)
tree7e9011d0dfdda5ef9ccc302dae69ab3e5ba4b8cc /src/quickcontrols2/material/ComboBox.qml
parent5a5b9c2344b961e984a2c860bb0c33022d641f32 (diff)
parent89d3486ad18d782a8141037a2bffb7992118cc78 (diff)
Merge qtquickcontrols2 into qtdeclarative
Diffstat (limited to 'src/quickcontrols2/material/ComboBox.qml')
-rw-r--r--src/quickcontrols2/material/ComboBox.qml179
1 files changed, 179 insertions, 0 deletions
diff --git a/src/quickcontrols2/material/ComboBox.qml b/src/quickcontrols2/material/ComboBox.qml
new file mode 100644
index 0000000000..15f4c1addf
--- /dev/null
+++ b/src/quickcontrols2/material/ComboBox.qml
@@ -0,0 +1,179 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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
+import QtQuick.Window
+import QtQuick.Controls.impl
+import QtQuick.Templates as T
+import QtQuick.Controls.Material
+import QtQuick.Controls.Material.impl
+
+T.ComboBox {
+ id: control
+
+ implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
+ implicitContentWidth + leftPadding + rightPadding)
+ implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
+ implicitContentHeight + topPadding + bottomPadding,
+ implicitIndicatorHeight + topPadding + bottomPadding)
+
+ topInset: 6
+ bottomInset: 6
+
+ leftPadding: padding + (!control.mirrored || !indicator || !indicator.visible ? 0 : indicator.width + spacing)
+ rightPadding: padding + (control.mirrored || !indicator || !indicator.visible ? 0 : indicator.width + spacing)
+
+ Material.elevation: flat ? control.pressed || control.hovered ? 2 : 0
+ : control.pressed ? 8 : 2
+ Material.background: flat ? "transparent" : undefined
+ Material.foreground: flat ? undefined : Material.primaryTextColor
+
+ delegate: MenuItem {
+ width: ListView.view.width
+ text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData
+ Material.foreground: control.currentIndex === index ? ListView.view.contentItem.Material.accent : ListView.view.contentItem.Material.foreground
+ highlighted: control.highlightedIndex === index
+ hoverEnabled: control.hoverEnabled
+ }
+
+ indicator: ColorImage {
+ x: control.mirrored ? control.padding : control.width - width - control.padding
+ y: control.topPadding + (control.availableHeight - height) / 2
+ color: control.enabled ? control.Material.foreground : control.Material.hintTextColor
+ source: "qrc:/qt-project.org/imports/QtQuick/Controls/Material/images/drop-indicator.png"
+ }
+
+ contentItem: T.TextField {
+ padding: 6
+ leftPadding: control.editable ? 2 : control.mirrored ? 0 : 12
+ rightPadding: control.editable ? 2 : control.mirrored ? 12 : 0
+
+ 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.enabled ? control.Material.foreground : control.Material.hintTextColor
+ selectionColor: control.Material.accentColor
+ selectedTextColor: control.Material.primaryHighlightedTextColor
+ verticalAlignment: Text.AlignVCenter
+
+ cursorDelegate: CursorDelegate { }
+ }
+
+ background: Rectangle {
+ implicitWidth: 120
+ implicitHeight: control.Material.buttonHeight
+
+ radius: control.flat ? 0 : 2
+ color: !control.editable ? control.Material.dialogColor : "transparent"
+
+ layer.enabled: control.enabled && !control.editable && control.Material.background.a > 0
+ layer.effect: ElevationEffect {
+ elevation: control.Material.elevation
+ }
+
+ Rectangle {
+ visible: control.editable
+ y: parent.y + control.baselineOffset
+ width: parent.width
+ height: control.activeFocus ? 2 : 1
+ color: control.editable && control.activeFocus ? control.Material.accentColor : control.Material.hintTextColor
+ }
+
+ Ripple {
+ clip: control.flat
+ clipRadius: control.flat ? 0 : 2
+ x: control.editable && control.indicator ? control.indicator.x : 0
+ width: control.editable && control.indicator ? control.indicator.width : parent.width
+ height: parent.height
+ pressed: control.pressed
+ anchor: control.editable && control.indicator ? control.indicator : control
+ active: control.pressed || control.visualFocus || control.hovered
+ color: control.Material.rippleColor
+ }
+ }
+
+ popup: T.Popup {
+ y: control.editable ? control.height - 5 : 0
+ width: control.width
+ height: Math.min(contentItem.implicitHeight, control.Window.height - topMargin - bottomMargin)
+ transformOrigin: Item.Top
+ topMargin: 12
+ bottomMargin: 12
+
+ Material.theme: control.Material.theme
+ Material.accent: control.Material.accent
+ Material.primary: control.Material.primary
+
+ enter: Transition {
+ // grow_fade_in
+ NumberAnimation { property: "scale"; from: 0.9; easing.type: Easing.OutQuint; duration: 220 }
+ NumberAnimation { property: "opacity"; from: 0.0; easing.type: Easing.OutCubic; duration: 150 }
+ }
+
+ exit: Transition {
+ // shrink_fade_out
+ NumberAnimation { property: "scale"; to: 0.9; easing.type: Easing.OutQuint; duration: 220 }
+ NumberAnimation { property: "opacity"; to: 0.0; easing.type: Easing.OutCubic; duration: 150 }
+ }
+
+ contentItem: ListView {
+ clip: true
+ implicitHeight: contentHeight
+ model: control.delegateModel
+ currentIndex: control.highlightedIndex
+ highlightMoveDuration: 0
+
+ T.ScrollIndicator.vertical: ScrollIndicator { }
+ }
+
+ background: Rectangle {
+ radius: 2
+ color: parent.Material.dialogColor
+
+ layer.enabled: control.enabled
+ layer.effect: ElevationEffect {
+ elevation: 8
+ }
+ }
+ }
+}