2024-05-28 17:39:41 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
2023-09-11 10:20:36 +00:00
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
property var comboBoxModel
|
|
|
|
|
|
|
|
property var selectedItem
|
|
|
|
property var hoveredItem
|
|
|
|
property string defaultIconSource
|
|
|
|
property string placeholderText
|
|
|
|
|
|
|
|
property var itemIconSourceFn: function (item) {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
property var itemTextFn: function (item) {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
property alias comboBoxControl: comboBox.control
|
|
|
|
property alias comboBoxDelegate: comboBox.delegate
|
2024-01-30 13:15:58 +00:00
|
|
|
property alias comboBoxListViewSection: comboBox.comboBoxListViewSection
|
2023-09-11 10:20:36 +00:00
|
|
|
property var comboBoxPopupHeader
|
|
|
|
|
|
|
|
property int contentIconSize: 21
|
|
|
|
property int contentTextSize: 28
|
|
|
|
|
|
|
|
function openPopup() {
|
|
|
|
root.comboBoxControl.popup.open()
|
|
|
|
}
|
|
|
|
|
|
|
|
implicitWidth: comboBox.width
|
|
|
|
implicitHeight: comboBox.implicitHeight
|
|
|
|
|
|
|
|
onSelectedItemChanged: {
|
2024-06-18 17:24:07 +00:00
|
|
|
let iconSource = itemIconSourceFn(selectedItem)
|
|
|
|
d.iconSource = !selectedItem ? "" : !!iconSource ? iconSource : defaultIconSource
|
|
|
|
let itemText = itemTextFn(selectedItem)
|
|
|
|
d.text = !!itemText ? itemText : placeholderText
|
2023-09-11 10:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onHoveredItemChanged: {
|
2024-06-18 17:24:07 +00:00
|
|
|
let iconSource = itemIconSourceFn(hoveredItem)
|
|
|
|
d.iconSource = !!iconSource ? iconSource : defaultIconSource
|
|
|
|
let itemText = itemTextFn(hoveredItem)
|
|
|
|
d.text = !!itemText ? itemText : placeholderText
|
2023-09-11 10:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
property string iconSource: ""
|
2023-09-12 14:26:38 +00:00
|
|
|
onIconSourceChanged: tokenIcon.image.source = iconSource
|
2024-05-28 17:39:41 +00:00
|
|
|
property string text: qsTr("Select asset")
|
2023-09-11 10:20:36 +00:00
|
|
|
readonly property bool isItemSelected: !!root.selectedItem || !!root.hoveredItem
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusComboBox {
|
|
|
|
id: comboBox
|
|
|
|
objectName: "assetSelectorButton"
|
|
|
|
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
2024-05-28 17:39:41 +00:00
|
|
|
control.padding: 12
|
2023-09-11 10:20:36 +00:00
|
|
|
control.popup.width: 492
|
|
|
|
control.popup.x: -root.x
|
|
|
|
control.popup.verticalPadding: 0
|
|
|
|
|
|
|
|
popupContentItemObjectName: "assetSelectorList"
|
|
|
|
|
|
|
|
model: root.comboBoxModel
|
|
|
|
|
|
|
|
control.background: Rectangle {
|
2024-05-28 17:39:41 +00:00
|
|
|
color: !d.isItemSelected ? Theme.palette.primaryColor3 : "transparent"
|
2023-09-11 10:20:36 +00:00
|
|
|
border.width: d.isItemSelected ? 0 : 1
|
|
|
|
border.color: Theme.palette.directColor7
|
2024-05-28 17:39:41 +00:00
|
|
|
radius: 8
|
|
|
|
|
|
|
|
HoverHandler {
|
|
|
|
cursorShape: root.enabled ? Qt.PointingHandCursor : undefined
|
|
|
|
}
|
2023-09-11 10:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
contentItem: RowLayout {
|
|
|
|
StatusRoundedImage {
|
2023-09-12 14:26:38 +00:00
|
|
|
id: tokenIcon
|
2024-06-13 00:45:33 +00:00
|
|
|
objectName: "holdingSelectorsTokenIcon"
|
2023-09-11 10:20:36 +00:00
|
|
|
Layout.preferredWidth: root.contentIconSize
|
|
|
|
Layout.preferredHeight: root.contentIconSize
|
|
|
|
visible: !!d.iconSource
|
|
|
|
image.source: d.iconSource
|
|
|
|
image.onStatusChanged: {
|
|
|
|
if (image.status === Image.Error) {
|
|
|
|
image.source = root.defaultIconSource
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
StatusBaseText {
|
2024-06-13 00:45:33 +00:00
|
|
|
objectName: "holdingSelectorsContentItemText"
|
2023-10-03 21:10:02 +00:00
|
|
|
Layout.fillWidth: true
|
2024-06-18 17:24:07 +00:00
|
|
|
font.pixelSize: !selectedItem && !hoveredItem ? Theme.primaryTextFontSize : root.contentTextSize
|
2023-09-11 10:20:36 +00:00
|
|
|
elide: Text.ElideRight
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
2024-05-28 17:39:41 +00:00
|
|
|
color: Theme.palette.primaryColor1
|
2023-09-11 10:20:36 +00:00
|
|
|
text: d.text
|
|
|
|
}
|
|
|
|
StatusIcon {
|
|
|
|
Layout.preferredWidth: 16
|
|
|
|
Layout.preferredHeight: 16
|
|
|
|
icon: "chevron-down"
|
2024-05-28 17:39:41 +00:00
|
|
|
color: Theme.palette.primaryColor1
|
2023-09-11 10:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
control.indicator: null
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
control.currentIndex = -1
|
|
|
|
control.popup.contentItem.header = root.comboBoxPopupHeader
|
|
|
|
}
|
|
|
|
|
|
|
|
control.popup.onOpened: {
|
|
|
|
control.currentIndex = -1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|