2020-10-20 15:32:03 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtGraphicalEffects 1.12
|
|
|
|
import QtQuick.Dialogs 1.3
|
2020-12-28 20:03:57 +00:00
|
|
|
import QtQuick.Layouts 1.13
|
2021-09-28 15:04:06 +00:00
|
|
|
|
2022-07-14 11:03:36 +00:00
|
|
|
import StatusQ.Core 0.1
|
|
|
|
|
2021-09-28 15:04:06 +00:00
|
|
|
import utils 1.0
|
2021-10-27 21:27:49 +00:00
|
|
|
import shared 1.0
|
|
|
|
import shared.panels 1.0
|
|
|
|
import shared.controls 1.0
|
2020-10-20 15:32:03 +00:00
|
|
|
|
|
|
|
Popup {
|
|
|
|
property var modelList
|
|
|
|
property alias listView: listView
|
2020-12-28 20:03:57 +00:00
|
|
|
property var getImageSource
|
|
|
|
property var getImageComponent
|
2020-10-20 15:32:03 +00:00
|
|
|
property var getText: function () {}
|
2022-01-24 17:59:59 +00:00
|
|
|
property var getId: function () {}
|
|
|
|
signal clicked(int index, string id)
|
2020-11-17 03:07:01 +00:00
|
|
|
property int imageWidth: 22
|
|
|
|
property int imageHeight: 22
|
2020-12-28 20:03:57 +00:00
|
|
|
property string title
|
|
|
|
property bool showSearchBox: false
|
2021-12-08 21:20:43 +00:00
|
|
|
property var messageInput
|
2020-10-20 15:32:03 +00:00
|
|
|
|
|
|
|
function openPopup(listParam) {
|
|
|
|
modelList = listParam
|
|
|
|
popup.open()
|
|
|
|
}
|
|
|
|
|
2020-12-28 20:03:57 +00:00
|
|
|
onOpened: {
|
|
|
|
listView.currentIndex = 0
|
|
|
|
if (showSearchBox) {
|
2021-01-05 18:54:17 +00:00
|
|
|
searchBox.text = ""
|
2020-12-28 20:03:57 +00:00
|
|
|
searchBox.textField.forceActiveFocus()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-20 15:32:03 +00:00
|
|
|
id: popup
|
2020-12-28 20:03:57 +00:00
|
|
|
padding: Style.current.smallPadding
|
2020-10-20 15:32:03 +00:00
|
|
|
width: messageInput.width
|
2020-12-28 20:03:57 +00:00
|
|
|
height: {
|
|
|
|
let possibleHeight = listView.contentHeight + Style.current.smallPadding * 2
|
|
|
|
if (popupTitle.visible) {
|
|
|
|
possibleHeight += popupTitle.height + Style.current.smallPadding
|
|
|
|
}
|
|
|
|
if (searchBox.visible) {
|
|
|
|
possibleHeight += searchBox.height + Style.current.smallPadding
|
|
|
|
}
|
|
|
|
|
|
|
|
return Math.min(400, possibleHeight)
|
|
|
|
}
|
|
|
|
x: messageInput.x
|
2020-10-20 15:32:03 +00:00
|
|
|
y: -height
|
|
|
|
background: Rectangle {
|
|
|
|
id: bgRectangle
|
2020-12-28 20:03:57 +00:00
|
|
|
visible: !!popup.title || (!!popup.modelList && popup.modelList.length > 0)
|
2020-10-20 15:32:03 +00:00
|
|
|
color: Style.current.background
|
|
|
|
border.width: 0
|
|
|
|
radius: Style.current.radius
|
|
|
|
layer.enabled: true
|
|
|
|
layer.effect: DropShadow{
|
|
|
|
width: bgRectangle.width
|
|
|
|
height: bgRectangle.height
|
|
|
|
x: bgRectangle.x
|
|
|
|
y: bgRectangle.y + 10
|
|
|
|
visible: bgRectangle.visible
|
|
|
|
source: bgRectangle
|
|
|
|
horizontalOffset: 0
|
|
|
|
verticalOffset: 2
|
|
|
|
radius: 10
|
|
|
|
samples: 15
|
2021-07-29 19:20:15 +00:00
|
|
|
color: Style.current.dropShadow
|
2020-10-20 15:32:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-28 20:03:57 +00:00
|
|
|
StyledText {
|
|
|
|
id: popupTitle
|
|
|
|
visible: !!popup.title
|
|
|
|
height: visible ? implicitHeight : 0
|
|
|
|
text: popup.title
|
|
|
|
font.pixelSize: 17
|
|
|
|
anchors.top: parent.top
|
|
|
|
}
|
|
|
|
|
|
|
|
SearchBox {
|
|
|
|
id: searchBox
|
|
|
|
visible: showSearchBox
|
|
|
|
height: visible ? implicitHeight : 0
|
|
|
|
width: parent.width
|
|
|
|
anchors.top: popupTitle.bottom
|
|
|
|
anchors.topMargin: popupTitle.visible ? Style.current.smallPadding : 0
|
|
|
|
|
|
|
|
function goToNextAvailableIndex(up) {
|
|
|
|
do {
|
|
|
|
if (!up && listView.currentIndex === listView.count - 1) {
|
|
|
|
listView.currentIndex = 0
|
|
|
|
return
|
|
|
|
} else if (up && listView.currentIndex === 0) {
|
|
|
|
listView.currentIndex = listView.count - 1
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (up) {
|
|
|
|
listView.decrementCurrentIndex()
|
|
|
|
} else {
|
|
|
|
listView.incrementCurrentIndex()
|
|
|
|
}
|
|
|
|
} while (!listView.currentItem.visible)
|
|
|
|
}
|
|
|
|
|
2021-12-08 21:20:43 +00:00
|
|
|
Keys.onReleased: {
|
2020-12-28 20:03:57 +00:00
|
|
|
if (event.key === Qt.Key_Down) {
|
|
|
|
searchBox.goToNextAvailableIndex(false)
|
|
|
|
}
|
|
|
|
if (event.key === Qt.Key_Up) {
|
|
|
|
searchBox.goToNextAvailableIndex(true)
|
|
|
|
}
|
|
|
|
if (event.key === Qt.Key_Escape) {
|
|
|
|
return popup.close()
|
|
|
|
}
|
|
|
|
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
|
2022-01-24 17:59:59 +00:00
|
|
|
return popup.clicked(listView.currentIndex, popup.getId(listView.currentItem.myData))
|
2020-12-28 20:03:57 +00:00
|
|
|
}
|
2021-03-29 15:27:38 +00:00
|
|
|
if (!listView.currentItem.visible) {
|
|
|
|
goToNextAvailableIndex(false)
|
|
|
|
}
|
2020-12-28 20:03:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-14 11:03:36 +00:00
|
|
|
StatusListView {
|
2020-10-20 15:32:03 +00:00
|
|
|
id: listView
|
|
|
|
model: popup.modelList || []
|
|
|
|
keyNavigationEnabled: true
|
2020-12-28 20:03:57 +00:00
|
|
|
width: parent.width
|
|
|
|
anchors.top: searchBox.bottom
|
|
|
|
anchors.topMargin: searchBox.visible ? Style.current.smallPadding : 0
|
|
|
|
anchors.bottom: parent.bottom
|
2020-10-20 15:32:03 +00:00
|
|
|
|
|
|
|
delegate: Rectangle {
|
2022-08-17 14:47:06 +00:00
|
|
|
id: rectangle
|
|
|
|
objectName: "inputListRectangle_" + index
|
2022-12-01 10:24:25 +00:00
|
|
|
property var myData: typeof modelData === "undefined" ? model : modelData
|
2022-01-24 17:59:59 +00:00
|
|
|
property string myText: popup.getText(myData)
|
2020-12-28 20:03:57 +00:00
|
|
|
visible: searchBox.text === "" || myText.includes(searchBox.text)
|
2020-10-20 15:32:03 +00:00
|
|
|
color: listView.currentIndex === index ? Style.current.backgroundHover : Style.current.transparent
|
|
|
|
border.width: 0
|
2022-12-01 10:24:25 +00:00
|
|
|
width: ListView.view.width
|
2020-12-28 20:03:57 +00:00
|
|
|
height: visible ? 42 : 0
|
2020-10-20 15:32:03 +00:00
|
|
|
radius: Style.current.radius
|
|
|
|
|
2020-12-28 20:03:57 +00:00
|
|
|
Loader {
|
|
|
|
id: imageLoader
|
|
|
|
active: !!popup.getImageComponent || !!popup.getImageSource
|
2020-11-17 03:07:01 +00:00
|
|
|
width: popup.imageWidth
|
|
|
|
height: popup.imageHeight
|
2020-10-20 15:32:03 +00:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: Style.current.smallPadding
|
2020-12-28 20:03:57 +00:00
|
|
|
sourceComponent: popup.getImageComponent ? customImageComponent : normalImageComponent
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: customImageComponent
|
|
|
|
Item {
|
|
|
|
id: imageComponentContainer
|
|
|
|
children: {
|
|
|
|
if (!popup.getImageComponent) {
|
|
|
|
return ""
|
|
|
|
}
|
2022-01-24 17:59:59 +00:00
|
|
|
return popup.getImageComponent(imageComponentContainer, myData)
|
2020-12-28 20:03:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: normalImageComponent
|
|
|
|
SVGImage {
|
|
|
|
visible: !!source
|
|
|
|
width: popup.imageWidth
|
|
|
|
height: popup.imageHeight
|
|
|
|
source: {
|
|
|
|
if (!popup.getImageSource) {
|
|
|
|
return ""
|
|
|
|
}
|
2022-01-24 17:59:59 +00:00
|
|
|
return popup.getImageSource(myData)
|
2020-12-28 20:03:57 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-20 15:32:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
2020-12-28 20:03:57 +00:00
|
|
|
text: rectangle.myText
|
2020-10-20 15:32:03 +00:00
|
|
|
color: Style.current.textColor
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2020-12-28 20:03:57 +00:00
|
|
|
anchors.left: imageLoader.right
|
2020-10-20 15:32:03 +00:00
|
|
|
anchors.leftMargin: Style.current.smallPadding
|
|
|
|
font.pixelSize: 15
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
anchors.fill: parent
|
|
|
|
hoverEnabled: true
|
|
|
|
onEntered: {
|
|
|
|
listView.currentIndex = index
|
|
|
|
}
|
|
|
|
onClicked: {
|
2022-01-24 17:59:59 +00:00
|
|
|
popup.clicked(index, popup.getId(myData))
|
2020-10-20 15:32:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|