2024-07-03 11:47:05 +00:00
|
|
|
|
import QtQuick 2.15
|
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
|
|
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
|
import StatusQ.Core.Utils 0.1
|
|
|
|
|
|
|
|
|
|
import AppLayouts.Wallet.panels 1.0
|
|
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
|
|
Control {
|
|
|
|
|
id: root
|
|
|
|
|
|
2024-08-30 15:31:53 +00:00
|
|
|
|
/** Expected model structure: see SearchableAssetsPanel::model **/
|
2024-07-03 11:47:05 +00:00
|
|
|
|
property alias assetsModel: tokenSelectorPanel.assetsModel
|
|
|
|
|
|
2024-08-30 15:31:53 +00:00
|
|
|
|
/** Expected model structure: see SearchableCollectiblesPanel::model **/
|
2024-07-03 11:47:05 +00:00
|
|
|
|
property alias collectiblesModel: tokenSelectorPanel.collectiblesModel
|
|
|
|
|
|
2024-09-23 08:15:01 +00:00
|
|
|
|
readonly property bool isTokenSelected: tokenSelectorButton.selected
|
2024-07-31 04:53:43 +00:00
|
|
|
|
|
2024-07-03 11:47:05 +00:00
|
|
|
|
signal assetSelected(string key)
|
|
|
|
|
signal collectionSelected(string key)
|
|
|
|
|
signal collectibleSelected(string key)
|
|
|
|
|
|
|
|
|
|
// Index of the current tab, indexes correspond to the
|
|
|
|
|
// TokensSelectorPanel.Tabs enum values.
|
|
|
|
|
property alias currentTab: tokenSelectorPanel.currentTab
|
|
|
|
|
|
2024-09-23 08:15:01 +00:00
|
|
|
|
function setSelection(name: string, icon: url, key: string) {
|
|
|
|
|
tokenSelectorButton.selected = true
|
2024-09-02 09:35:18 +00:00
|
|
|
|
tokenSelectorButton.name = name
|
|
|
|
|
tokenSelectorButton.icon = icon
|
2024-07-03 11:47:05 +00:00
|
|
|
|
tokenSelectorPanel.highlightedKey = key ?? ""
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-08 11:22:13 +00:00
|
|
|
|
QObject {
|
|
|
|
|
id: d
|
|
|
|
|
|
|
|
|
|
readonly property int maxPopupHeight: 330
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-30 12:24:16 +00:00
|
|
|
|
contentItem: TokenSelectorButton {
|
2024-09-02 09:35:18 +00:00
|
|
|
|
id: tokenSelectorButton
|
|
|
|
|
|
2024-08-30 12:24:16 +00:00
|
|
|
|
forceHovered: dropdown.opened
|
2024-07-03 11:47:05 +00:00
|
|
|
|
|
2024-08-30 12:24:16 +00:00
|
|
|
|
onClicked: dropdown.opened ? dropdown.close() : dropdown.open()
|
2024-07-03 11:47:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StatusDropdown {
|
|
|
|
|
id: dropdown
|
|
|
|
|
|
|
|
|
|
y: parent.height + 4
|
2024-09-18 11:03:36 +00:00
|
|
|
|
width: 448
|
2024-07-03 11:47:05 +00:00
|
|
|
|
|
|
|
|
|
closePolicy: Popup.CloseOnPressOutsideParent
|
2024-09-02 09:35:18 +00:00
|
|
|
|
horizontalPadding: 0
|
2024-07-03 11:47:05 +00:00
|
|
|
|
bottomPadding: 0
|
|
|
|
|
|
2024-11-08 11:22:13 +00:00
|
|
|
|
onClosed: tokenSelectorPanel.clear()
|
|
|
|
|
|
|
|
|
|
contentItem: Item {
|
|
|
|
|
implicitHeight: Math.min(tokenSelectorPanel.implicitHeight, d.maxPopupHeight)
|
2024-07-03 11:47:05 +00:00
|
|
|
|
|
2024-11-08 11:22:13 +00:00
|
|
|
|
TokenSelectorPanel {
|
|
|
|
|
id: tokenSelectorPanel
|
2024-09-03 14:29:22 +00:00
|
|
|
|
|
2024-11-08 11:22:13 +00:00
|
|
|
|
objectName: "tokenSelectorPanel"
|
2024-07-03 11:47:05 +00:00
|
|
|
|
|
2024-11-08 11:22:13 +00:00
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
|
|
function findSubitem(key) {
|
|
|
|
|
const count = collectiblesModel.rowCount()
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < count; i++) {
|
|
|
|
|
const entry = ModelUtils.get(collectiblesModel, i)
|
|
|
|
|
const subitem = ModelUtils.getByKey(
|
|
|
|
|
entry.subitems, "key", key)
|
|
|
|
|
if (subitem)
|
|
|
|
|
return subitem
|
|
|
|
|
}
|
2024-07-03 11:47:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-08 11:22:13 +00:00
|
|
|
|
function setCurrentAndClose(name, icon) {
|
|
|
|
|
tokenSelectorButton.name = name
|
|
|
|
|
tokenSelectorButton.icon = icon
|
|
|
|
|
tokenSelectorButton.selected = true
|
|
|
|
|
dropdown.close()
|
|
|
|
|
}
|
2024-07-03 11:47:05 +00:00
|
|
|
|
|
2024-11-08 11:22:13 +00:00
|
|
|
|
onAssetSelected: {
|
|
|
|
|
const entry = ModelUtils.getByKey(assetsModel, "tokensKey", key)
|
|
|
|
|
highlightedKey = key
|
2024-07-03 11:47:05 +00:00
|
|
|
|
|
2024-11-08 11:22:13 +00:00
|
|
|
|
setCurrentAndClose(entry.symbol, entry.iconSource)
|
|
|
|
|
root.assetSelected(key)
|
|
|
|
|
}
|
2024-07-03 11:47:05 +00:00
|
|
|
|
|
2024-11-08 11:22:13 +00:00
|
|
|
|
onCollectibleSelected: {
|
|
|
|
|
highlightedKey = key
|
2024-07-03 11:47:05 +00:00
|
|
|
|
|
2024-11-08 11:22:13 +00:00
|
|
|
|
const subitem = findSubitem(key)
|
|
|
|
|
setCurrentAndClose(subitem.name, subitem.icon)
|
2024-07-03 11:47:05 +00:00
|
|
|
|
|
2024-11-08 11:22:13 +00:00
|
|
|
|
root.collectibleSelected(key)
|
|
|
|
|
}
|
2024-07-03 11:47:05 +00:00
|
|
|
|
|
2024-11-08 11:22:13 +00:00
|
|
|
|
onCollectionSelected: {
|
|
|
|
|
highlightedKey = key
|
2024-07-03 11:47:05 +00:00
|
|
|
|
|
2024-11-08 11:22:13 +00:00
|
|
|
|
const subitem = findSubitem(key)
|
|
|
|
|
setCurrentAndClose(subitem.name, subitem.icon)
|
2024-07-03 11:47:05 +00:00
|
|
|
|
|
2024-11-08 11:22:13 +00:00
|
|
|
|
root.collectionSelected(key)
|
|
|
|
|
}
|
2024-07-03 11:47:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|