diff --git a/src/gui/Base/HComboBox.qml b/src/gui/Base/HComboBox.qml new file mode 100644 index 00000000..2a55b976 --- /dev/null +++ b/src/gui/Base/HComboBox.qml @@ -0,0 +1,89 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.12 + +ComboBox { + id: root + + property bool error: false + property bool bordered: true + property color backgroundColor: theme.controls.textField.background + property color borderColor: theme.controls.textField.border + property color errorBorder: theme.controls.textField.errorBorder + property color focusedBorderColor: theme.controls.textField.focusedBorder + property color focusedBackgroundColor: + theme.controls.textField.focusedBackground + + spacing: 0 + + background: Rectangle { + radius: theme.radius + color: field.activeFocus ? focusedBackgroundColor : backgroundColor + + border.width: bordered ? theme.controls.textField.borderWidth : 0 + border.color: borderColor + + HBottomFocusLine { + show: field.activeFocus + borderHeight: theme.controls.textField.borderWidth + color: error ? errorBorder : focusedBorderColor + } + } + + contentItem: HTextField { + id: field + background: null + text: root.displayText + readOnly: ! root.editable + rightPadding: root.indicator.width + theme.spacing + + TapHandler { + enabled: field.readOnly + onTapped: + root.popup.visible ? root.popup.close() : root.popup.open() + } + } + + indicator: HButton { + x: root.width - root.rightPadding + height: root.availableHeight + backgroundColor: "transparent" + icon.name: "combo-box-" + (root.popup.visible ? "close" : "open") + iconItem.small: true + onClicked: root.popup.visible ? root.popup.close() : root.popup.open() + } + + popup: HMenu { + id: menu + y: root.height + width: root.width + modal: false + onOpened: currentIndex = root.currentIndex + + enter: Transition { + HNumberAnimation { + property: "height" + from: 0 + to: menu.implicitHeight + easing.type: Easing.OutQuad + } + } + + exit: Transition { + HNumberAnimation { + property: "height" + to: 0 + easing.type: Easing.InQuad + } + } + + Repeater { + model: root.popup.visible ? root.model : null + delegate: root.delegate + } + } + + delegate: HMenuItem { + text: modelData + onTriggered: root.currentIndex = model.index + } +} diff --git a/src/icons/thin/combo-box-close.svg b/src/icons/thin/combo-box-close.svg new file mode 100644 index 00000000..3ecee689 --- /dev/null +++ b/src/icons/thin/combo-box-close.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/icons/thin/combo-box-open.svg b/src/icons/thin/combo-box-open.svg new file mode 100644 index 00000000..1bd759eb --- /dev/null +++ b/src/icons/thin/combo-box-open.svg @@ -0,0 +1,3 @@ + + +