2022-09-06 13:19:50 +00:00
|
|
|
import QtQuick 2.14
|
|
|
|
import QtQuick.Controls 2.14
|
|
|
|
import QtQuick.Layouts 1.14
|
|
|
|
import QtGraphicalEffects 1.0
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Core.Utils 0.1
|
|
|
|
import StatusQ.Popups.Dialog 0.1
|
|
|
|
|
2022-09-20 10:54:28 +00:00
|
|
|
import utils 1.0
|
|
|
|
|
2022-09-06 13:19:50 +00:00
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
property alias model: listView.model
|
|
|
|
property alias delegate: listView.delegate
|
|
|
|
|
|
|
|
property alias suggestionsModel: suggestionsListView.model
|
|
|
|
property alias suggestionsDelegate: suggestionsListView.delegate
|
2022-11-08 08:36:08 +00:00
|
|
|
property size suggestionsDelegateSize: Qt.size(344, 64)
|
2022-09-06 13:19:50 +00:00
|
|
|
|
|
|
|
readonly property alias label: label
|
|
|
|
readonly property alias warningLabel: warningLabel
|
|
|
|
readonly property alias edit: edit
|
|
|
|
|
|
|
|
signal confirmed()
|
|
|
|
signal rejected()
|
|
|
|
|
2022-09-29 15:18:29 +00:00
|
|
|
signal enterKeyPressed()
|
|
|
|
signal upKeyPressed()
|
|
|
|
signal downKeyPressed()
|
|
|
|
|
2022-09-06 13:19:50 +00:00
|
|
|
signal entryAccepted(var suggestionsDelegate)
|
|
|
|
signal entryRemoved(var delegate)
|
2022-09-16 19:25:10 +00:00
|
|
|
signal textPasted(string text)
|
2022-09-06 13:19:50 +00:00
|
|
|
|
|
|
|
implicitWidth: mainLayout.implicitWidth
|
|
|
|
implicitHeight: mainLayout.implicitHeight
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
id: mainLayout
|
|
|
|
anchors.fill: parent
|
2022-09-20 10:54:28 +00:00
|
|
|
spacing: Style.current.padding
|
2022-09-06 13:19:50 +00:00
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: 44
|
2022-09-20 10:54:28 +00:00
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
Layout.leftMargin: Style.current.halfPadding
|
2022-09-06 13:19:50 +00:00
|
|
|
color: Theme.palette.baseColor2
|
2022-09-20 10:54:28 +00:00
|
|
|
radius: Style.current.radius
|
2022-09-06 13:19:50 +00:00
|
|
|
RowLayout {
|
2022-09-20 10:54:28 +00:00
|
|
|
anchors.fill: parent
|
|
|
|
spacing: Style.current.halfPadding
|
2022-09-06 13:19:50 +00:00
|
|
|
StatusBaseText {
|
|
|
|
id: label
|
2022-09-20 10:54:28 +00:00
|
|
|
Layout.leftMargin: Style.current.padding
|
2022-09-06 13:19:50 +00:00
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
visible: text !== ""
|
|
|
|
font.pixelSize: 15
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
}
|
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
2022-11-08 08:36:08 +00:00
|
|
|
StatusScrollView {
|
|
|
|
id: scrollView
|
|
|
|
|
|
|
|
function positionViewAtEnd() {
|
|
|
|
if (scrollView.contentWidth > scrollView.width) {
|
|
|
|
scrollView.contentX = scrollView.contentWidth - scrollView.width
|
|
|
|
} else {
|
|
|
|
scrollView.contentX = 0
|
|
|
|
}
|
|
|
|
}
|
2022-09-06 13:19:50 +00:00
|
|
|
|
2022-09-29 15:18:29 +00:00
|
|
|
anchors.fill: parent
|
2022-11-08 08:36:08 +00:00
|
|
|
padding: 0
|
|
|
|
|
|
|
|
onContentWidthChanged: positionViewAtEnd()
|
|
|
|
onWidthChanged: positionViewAtEnd()
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
height: scrollView.height
|
2022-09-06 13:19:50 +00:00
|
|
|
StatusListView {
|
|
|
|
id: listView
|
2022-11-08 08:36:08 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: 30
|
|
|
|
implicitWidth: contentWidth
|
2022-09-06 13:19:50 +00:00
|
|
|
orientation: ListView.Horizontal
|
2022-09-20 10:54:28 +00:00
|
|
|
spacing: Style.current.halfPadding
|
2022-09-06 13:19:50 +00:00
|
|
|
}
|
|
|
|
|
2022-11-08 08:36:08 +00:00
|
|
|
TextInput {
|
|
|
|
id: edit
|
|
|
|
Layout.minimumWidth: 4
|
|
|
|
Layout.fillHeight: true
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
font.pixelSize: 15
|
|
|
|
color: Theme.palette.directColor1
|
|
|
|
|
|
|
|
selectByMouse: true
|
|
|
|
selectionColor: Theme.palette.primaryColor2
|
|
|
|
selectedTextColor: color
|
|
|
|
|
|
|
|
cursorDelegate: Rectangle {
|
|
|
|
color: Theme.palette.primaryColor1
|
|
|
|
implicitWidth: 2
|
|
|
|
radius: 1
|
|
|
|
visible: edit.cursorVisible
|
|
|
|
SequentialAnimation on visible {
|
|
|
|
loops: Animation.Infinite
|
|
|
|
running: edit.cursorVisible
|
|
|
|
PropertyAnimation { to: false; duration: 600; }
|
|
|
|
PropertyAnimation { to: true; duration: 600; }
|
|
|
|
}
|
2022-09-06 13:19:50 +00:00
|
|
|
}
|
|
|
|
|
2022-11-08 08:36:08 +00:00
|
|
|
Keys.onPressed: {
|
|
|
|
if (event.matches(StandardKey.Paste)) {
|
|
|
|
event.accepted = true
|
|
|
|
const previousText = text;
|
|
|
|
const previousSelectedText = selectedText;
|
|
|
|
paste()
|
|
|
|
if (previousText === "" || previousSelectedText.length === previousText.length)
|
|
|
|
root.textPasted(text)
|
|
|
|
return;
|
2022-09-16 19:25:10 +00:00
|
|
|
}
|
2022-11-08 08:36:08 +00:00
|
|
|
|
|
|
|
if (suggestionsDialog.visible) {
|
|
|
|
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
|
|
|
|
root.entryAccepted(suggestionsListView.itemAtIndex(suggestionsListView.currentIndex))
|
|
|
|
} else if (event.key === Qt.Key_Up) {
|
|
|
|
suggestionsListView.decrementCurrentIndex()
|
|
|
|
} else if (event.key === Qt.Key_Down) {
|
|
|
|
suggestionsListView.incrementCurrentIndex()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (event.key === Qt.Key_Backspace && edit.text === "") {
|
|
|
|
root.entryRemoved(listView.itemAtIndex(listView.count - 1))
|
|
|
|
} else if (event.key === Qt.Key_Return || event.key === Qt.Enter) {
|
|
|
|
root.enterKeyPressed()
|
|
|
|
} else if (event.key === Qt.Key_Escape) {
|
|
|
|
root.rejected()
|
|
|
|
} else if (event.key === Qt.Key_Up) {
|
|
|
|
root.upKeyPressed()
|
|
|
|
} else if (event.key === Qt.Key_Down) {
|
|
|
|
root.downKeyPressed()
|
|
|
|
}
|
2022-09-06 13:19:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-08 08:36:08 +00:00
|
|
|
|
|
|
|
// ensure edit cursor is visible
|
|
|
|
Item {
|
|
|
|
Layout.fillHeight: true
|
|
|
|
implicitWidth: 1
|
|
|
|
}
|
2022-09-06 13:19:50 +00:00
|
|
|
}
|
|
|
|
|
2022-11-08 08:36:08 +00:00
|
|
|
ScrollBar.horizontal: StatusScrollBar {
|
|
|
|
id: scrollBar
|
|
|
|
parent: scrollView.parent
|
|
|
|
anchors.top: scrollView.bottom
|
|
|
|
anchors.left: scrollView.left
|
|
|
|
anchors.right: scrollView.right
|
|
|
|
policy: ScrollBar.AsNeeded
|
|
|
|
visible: resolveVisibility(policy, scrollView.width, scrollView.contentWidth)
|
2022-09-06 13:19:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
id: warningLabel
|
2022-09-20 10:54:28 +00:00
|
|
|
Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
|
|
|
|
Layout.rightMargin: Style.current.padding
|
2022-09-06 13:19:50 +00:00
|
|
|
visible: text !== ""
|
|
|
|
font.pixelSize: 10
|
|
|
|
color: Theme.palette.dangerColor1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
propagateComposedEvents: true
|
|
|
|
onPressed: {
|
|
|
|
edit.forceActiveFocus()
|
|
|
|
mouse.accepted = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusButton {
|
2022-09-29 14:33:47 +00:00
|
|
|
objectName: "inlineSelectorConfirmButton"
|
2022-09-20 10:54:28 +00:00
|
|
|
Layout.alignment: Qt.AlignVCenter
|
2022-11-08 08:36:08 +00:00
|
|
|
enabled: (listView.count > 0)
|
2022-09-06 13:19:50 +00:00
|
|
|
text: qsTr("Confirm")
|
|
|
|
onClicked: root.confirmed()
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusButton {
|
2022-09-20 10:54:28 +00:00
|
|
|
Layout.alignment: Qt.AlignVCenter
|
2022-11-15 14:17:58 +00:00
|
|
|
text: qsTr("Cancel")
|
2022-09-06 13:19:50 +00:00
|
|
|
type: StatusBaseButton.Type.Danger
|
|
|
|
onClicked: root.rejected()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Popup {
|
|
|
|
id: suggestionsDialog
|
2022-11-08 08:36:08 +00:00
|
|
|
parent: scrollView
|
|
|
|
x: Math.min(parent.width, parent.contentWidth)
|
|
|
|
y: parent.height + Style.current.halfPadding
|
2022-11-07 09:51:51 +00:00
|
|
|
visible: edit.text !== ""
|
2022-09-20 10:54:28 +00:00
|
|
|
padding: Style.current.halfPadding
|
2022-09-06 13:19:50 +00:00
|
|
|
background: StatusDialogBackground {
|
|
|
|
id: bg
|
|
|
|
layer.enabled: true
|
|
|
|
layer.effect: DropShadow {
|
|
|
|
source: bg
|
|
|
|
horizontalOffset: 0
|
|
|
|
verticalOffset: 4
|
|
|
|
radius: 12
|
|
|
|
samples: 25
|
|
|
|
spread: 0.2
|
|
|
|
color: Theme.palette.dropShadow
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-08 08:36:08 +00:00
|
|
|
height: suggestionsListView.count ?
|
|
|
|
Math.min(400, suggestionsListView.count * suggestionsDelegateSize.height + 2 * padding) :
|
|
|
|
noResultsFoundText.height + 2 * padding
|
|
|
|
width: suggestionsDelegateSize.width
|
|
|
|
|
2022-11-07 09:51:51 +00:00
|
|
|
ColumnLayout {
|
2022-09-06 13:19:50 +00:00
|
|
|
anchors.fill: parent
|
2022-11-07 09:51:51 +00:00
|
|
|
|
|
|
|
StatusBaseText {
|
2022-11-08 08:36:08 +00:00
|
|
|
id: noResultsFoundText
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
2022-11-07 09:51:51 +00:00
|
|
|
visible: root.suggestionsModel.count === 0
|
|
|
|
text: qsTr("No results found")
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusListView {
|
|
|
|
id: suggestionsListView
|
2022-11-08 08:36:08 +00:00
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
|
2022-11-07 09:51:51 +00:00
|
|
|
visible: root.suggestionsModel.count
|
|
|
|
|
2022-11-08 08:36:08 +00:00
|
|
|
highlightMoveDuration: 0
|
|
|
|
highlightMoveVelocity: -1
|
|
|
|
|
|
|
|
verticalScrollBar {
|
|
|
|
visible: contentHeight > height
|
|
|
|
policy: ScrollBar.AlwaysOn
|
|
|
|
}
|
|
|
|
|
2022-11-07 09:51:51 +00:00
|
|
|
onVisibleChanged: currentIndex = 0
|
2022-11-08 08:36:08 +00:00
|
|
|
onCountChanged: currentIndex = 0
|
2022-11-07 09:51:51 +00:00
|
|
|
}
|
2022-09-06 13:19:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|