2019-02-11 17:53:50 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
import QtQuick 2.11
|
|
|
|
import QtQuick.Controls 2.4
|
|
|
|
import QtQuick.Layouts 1.11
|
2020-01-14 20:29:08 +00:00
|
|
|
import org.kde.kirigami 2.4 as Kirigami
|
2019-02-11 17:53:50 +00:00
|
|
|
|
|
|
|
ComboBox {
|
2020-12-19 23:19:19 +00:00
|
|
|
id: cb
|
2019-02-11 17:53:50 +00:00
|
|
|
Layout.fillWidth: true
|
2020-01-14 20:29:08 +00:00
|
|
|
Layout.preferredHeight: Kirigami.Units.gridUnit * 2.5
|
|
|
|
inputMethodHints: Qt.ImhNoPredictiveText
|
2020-01-09 10:31:30 +00:00
|
|
|
font.pointSize: subsurfaceTheme.regularPointSize
|
2020-12-19 23:19:19 +00:00
|
|
|
delegate: ItemDelegate {
|
|
|
|
width: cb.width
|
|
|
|
contentItem: Text {
|
|
|
|
text: modelData
|
|
|
|
color: subsurfaceTheme.textColor
|
|
|
|
font: cb.font
|
|
|
|
elide: Text.ElideRight
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
}
|
|
|
|
highlighted: cb.highlightedIndex === index
|
|
|
|
}
|
|
|
|
|
|
|
|
indicator: Canvas {
|
|
|
|
id: canvas
|
|
|
|
x: cb.width - width - cb.rightPadding
|
|
|
|
y: cb.topPadding + (cb.availableHeight - height) / 2
|
|
|
|
width: Kirigami.Units.gridUnit
|
|
|
|
height: width * 0.66
|
|
|
|
contextType: "2d"
|
|
|
|
Connections {
|
|
|
|
target: cb
|
|
|
|
function onPressedChanged() { canvas.requestPaint(); }
|
|
|
|
}
|
2020-12-23 00:10:07 +00:00
|
|
|
// if the theme changes, we need to force a repaint of the indicator
|
|
|
|
property color sttc: subsurfaceTheme.textColor
|
|
|
|
onSttcChanged: { requestPaint() }
|
2020-12-19 23:19:19 +00:00
|
|
|
onPaint: {
|
|
|
|
context.reset();
|
|
|
|
context.moveTo(0, 0);
|
|
|
|
context.lineTo(width, 0);
|
|
|
|
context.lineTo(width / 2, height);
|
|
|
|
context.closePath();
|
|
|
|
context.fillStyle = subsurfaceTheme.textColor;
|
|
|
|
context.fill();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-22 22:12:58 +00:00
|
|
|
contentItem: TextField {
|
|
|
|
readOnly: !cb.editable
|
|
|
|
anchors.right: indicator.left
|
|
|
|
anchors.left: cb.left
|
2020-12-19 23:19:19 +00:00
|
|
|
leftPadding: Kirigami.Units.smallSpacing
|
2020-12-22 22:12:58 +00:00
|
|
|
rightPadding: Kirigami.Units.smallSpacing
|
2020-12-30 22:01:07 +00:00
|
|
|
text: readOnly ? cb.displayText : cb.editText
|
2020-12-19 23:19:19 +00:00
|
|
|
font: cb.font
|
|
|
|
color: subsurfaceTheme.textColor
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
2020-12-23 00:23:12 +00:00
|
|
|
onPressed: {
|
|
|
|
if (readOnly) {
|
|
|
|
if (cb.popup.opened) {
|
|
|
|
cb.popup.close()
|
|
|
|
} else {
|
|
|
|
cb.popup.open()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-19 23:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
background: Rectangle {
|
2020-12-23 00:17:57 +00:00
|
|
|
border.color: cb.focus ? subsurfaceTheme.darkerPrimaryColor : subsurfaceTheme.backgroundColor
|
2020-12-19 23:19:19 +00:00
|
|
|
border.width: cb.visualFocus ? 2 : 1
|
2020-12-23 00:17:57 +00:00
|
|
|
color: Qt.darker(subsurfaceTheme.backgroundColor, 1.1)
|
2020-12-19 23:19:19 +00:00
|
|
|
radius: 2
|
|
|
|
}
|
|
|
|
|
|
|
|
popup: Popup {
|
|
|
|
y: cb.height - 1
|
|
|
|
width: cb.width
|
|
|
|
implicitHeight: contentItem.implicitHeight
|
|
|
|
padding: 1
|
|
|
|
|
|
|
|
contentItem: ListView {
|
|
|
|
clip: true
|
|
|
|
implicitHeight: contentHeight
|
|
|
|
model: cb.popup.visible ? cb.delegateModel : null
|
|
|
|
currentIndex: cb.highlightedIndex
|
|
|
|
|
|
|
|
ScrollIndicator.vertical: ScrollIndicator { }
|
|
|
|
}
|
|
|
|
|
|
|
|
background: Rectangle {
|
|
|
|
border.color: subsurfaceTheme.darkerPrimaryColor
|
|
|
|
color: subsurfaceTheme.backgroundColor
|
|
|
|
radius: 2
|
|
|
|
}
|
|
|
|
}
|
2019-02-11 17:53:50 +00:00
|
|
|
}
|