2022-06-09 15:27:14 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Layouts 1.14
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtGraphicalEffects 1.13
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Controls.Validators 0.1
|
|
|
|
import StatusQ.Core.Utils 0.1 as SQ
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
StatusDropdown {
|
|
|
|
id: root
|
|
|
|
|
2022-08-23 08:46:37 +00:00
|
|
|
property var store
|
|
|
|
|
|
|
|
property var itemKey
|
|
|
|
property real tokenAmount: 0
|
2022-06-09 15:27:14 +00:00
|
|
|
property string tokenName: d.defaultTokenNameText
|
|
|
|
property url tokenImage: ""
|
2022-08-23 08:46:37 +00:00
|
|
|
property real collectibleAmount: 1
|
|
|
|
property string collectibleName: d.defaultCollectibleNameText
|
|
|
|
property url collectibleImage: ""
|
2022-06-09 15:27:14 +00:00
|
|
|
property int operator: SQ.Utils.Operators.None
|
|
|
|
property bool withOperatorSelector: true
|
|
|
|
|
2022-08-23 08:46:37 +00:00
|
|
|
signal addItem(var itemKey, string itemText, url itemImage, int operator)
|
2022-06-09 15:27:14 +00:00
|
|
|
|
|
|
|
function reset() {
|
2022-08-23 08:46:37 +00:00
|
|
|
d.currentTabIndex = 0
|
|
|
|
root.itemKey = undefined
|
|
|
|
root.tokenAmount = 0
|
2022-06-09 15:27:14 +00:00
|
|
|
root.tokenName = d.defaultTokenNameText
|
|
|
|
root.tokenImage = ""
|
2022-08-23 08:46:37 +00:00
|
|
|
root.collectibleAmount = 1
|
|
|
|
root.collectibleName = d.defaultCollectibleNameText
|
|
|
|
root.collectibleImage = ""
|
2022-06-09 15:27:14 +00:00
|
|
|
root.operator = SQ.Utils.Operators.None
|
|
|
|
}
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
2022-08-23 08:46:37 +00:00
|
|
|
// Internal management properties:
|
|
|
|
readonly property bool tokensReady: root.tokenAmount > 0 && root.tokenName !== d.defaultTokenNameText
|
|
|
|
readonly property bool collectiblesReady: root.collectibleAmount > 0 && root.collectibleName !== d.defaultCollectibleNameText
|
|
|
|
readonly property string tokensState: "TOKENS"
|
|
|
|
readonly property string collectiblesState: "COLLECTIBLES"
|
|
|
|
readonly property string ensState: "ENS"
|
|
|
|
property bool isTokensLayout: true
|
|
|
|
property int currentTabIndex: 0
|
2022-06-09 15:27:14 +00:00
|
|
|
|
|
|
|
// By design values:
|
|
|
|
readonly property int initialHeight: 232
|
|
|
|
readonly property int mainHeight: 256
|
2022-08-23 08:46:37 +00:00
|
|
|
readonly property int mainExtendedHeight: 276
|
2022-06-09 15:27:14 +00:00
|
|
|
readonly property int operatorsHeight: 96
|
|
|
|
readonly property int extendedHeight: 417
|
|
|
|
readonly property int defaultWidth: 289
|
|
|
|
readonly property int operatorsWidth: 159
|
|
|
|
|
|
|
|
property string defaultTokenNameText: qsTr("Choose token")
|
2022-08-23 08:46:37 +00:00
|
|
|
property string defaultCollectibleNameText: qsTr("Choose collectible")
|
2022-06-09 15:27:14 +00:00
|
|
|
|
|
|
|
function selectInitState() {
|
|
|
|
if(root.withOperatorSelector)
|
|
|
|
loader.sourceComponent = operatorsSelectorView
|
|
|
|
else
|
|
|
|
loader.sourceComponent = tabsView
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-23 08:46:37 +00:00
|
|
|
implicitWidth: d.defaultWidth
|
|
|
|
implicitHeight: loader.implicitHeight
|
2022-06-09 15:27:14 +00:00
|
|
|
|
|
|
|
contentItem: Loader {
|
|
|
|
id: loader
|
2022-08-23 08:46:37 +00:00
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.left: parent.left
|
|
|
|
width: parent.width
|
|
|
|
height: (item != null && typeof(item) !== 'undefined') ? item.implicitHeight : 0
|
2022-06-09 15:27:14 +00:00
|
|
|
sourceComponent: root.withOperatorSelector ? operatorsSelectorView : tabsView
|
|
|
|
onSourceComponentChanged: {
|
2022-08-23 08:46:37 +00:00
|
|
|
if(sourceComponent == operatorsSelectorView) {
|
2022-06-09 15:27:14 +00:00
|
|
|
root.width = d.operatorsWidth
|
|
|
|
}
|
2022-08-23 08:46:37 +00:00
|
|
|
else {
|
2022-06-09 15:27:14 +00:00
|
|
|
root.width = d.defaultWidth
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onOpened: d.selectInitState()
|
|
|
|
onClosed: root.reset()
|
|
|
|
onWithOperatorSelectorChanged: d.selectInitState()
|
|
|
|
|
2022-08-23 08:46:37 +00:00
|
|
|
Component {
|
|
|
|
id: operatorsSelectorView
|
|
|
|
ColumnLayout {
|
|
|
|
StatusPickerButton {
|
|
|
|
Layout.margins: 8
|
|
|
|
Layout.bottomMargin: 0
|
|
|
|
Layout.preferredWidth: 143 // by design
|
|
|
|
Layout.preferredHeight: 36
|
|
|
|
horizontalPadding: 12
|
|
|
|
spacing: 10
|
|
|
|
bgColor: Theme.palette.primaryColor3
|
|
|
|
contentColor: Theme.palette.primaryColor1
|
2022-08-11 11:55:08 +00:00
|
|
|
asset.name: Style.svg("add")
|
|
|
|
asset.isImage: true
|
2022-08-23 08:46:37 +00:00
|
|
|
text: qsTr("And...")
|
2022-08-11 11:55:08 +00:00
|
|
|
asset.height: 12
|
|
|
|
asset.width: 12
|
2022-08-23 08:46:37 +00:00
|
|
|
font.pixelSize: 13
|
|
|
|
onClicked: {
|
|
|
|
root.operator = SQ.Utils.Operators.And
|
|
|
|
loader.sourceComponent = tabsView
|
|
|
|
}
|
|
|
|
}
|
|
|
|
StatusPickerButton {
|
|
|
|
Layout.margins: 8
|
|
|
|
Layout.topMargin: 0
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: 36
|
|
|
|
horizontalPadding: 12
|
|
|
|
spacing: 10
|
|
|
|
bgColor: Theme.palette.primaryColor3
|
|
|
|
contentColor: Theme.palette.primaryColor1
|
2022-08-11 11:55:08 +00:00
|
|
|
asset.name: Style.svg("condition-Or")
|
|
|
|
asset.isImage: true
|
|
|
|
asset.height: 12
|
|
|
|
asset.width: 12
|
2022-08-23 08:46:37 +00:00
|
|
|
text: qsTr("Or...")
|
|
|
|
font.pixelSize: 13
|
|
|
|
onClicked: {
|
|
|
|
root.operator = SQ.Utils.Operators.Or
|
|
|
|
loader.sourceComponent = tabsView
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
Component {
|
|
|
|
id: tabsView
|
|
|
|
|
|
|
|
ColumnLayout {
|
2022-08-23 08:46:37 +00:00
|
|
|
spacing: 0
|
|
|
|
state: d.currentTabIndex === 0 ? d.tokensState : (d.currentTabIndex === 1 ? d.collectiblesState : d.ensState)
|
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: d.tokensState
|
|
|
|
PropertyChanges {target: tabsLoader; sourceComponent: tokensCollectiblesLayout}
|
|
|
|
PropertyChanges {target: d; isTokensLayout: true}
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: d.collectiblesState
|
|
|
|
PropertyChanges {target: tabsLoader; sourceComponent: tokensCollectiblesLayout}
|
|
|
|
PropertyChanges {target: d; isTokensLayout: false}
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: d.ensState
|
|
|
|
PropertyChanges {target: tabsLoader; sourceComponent: ensLayout}
|
|
|
|
}
|
|
|
|
]
|
2022-06-09 15:27:14 +00:00
|
|
|
StatusIconTextButton {
|
|
|
|
visible: root.withOperatorSelector
|
2022-08-23 08:46:37 +00:00
|
|
|
Layout.leftMargin: 16
|
|
|
|
Layout.topMargin: 12
|
2022-06-09 15:27:14 +00:00
|
|
|
spacing: 0
|
|
|
|
statusIcon: "next"
|
|
|
|
icon.width: 12
|
|
|
|
icon.height: 12
|
|
|
|
iconRotation: 180
|
|
|
|
text: qsTr("Back")
|
|
|
|
onClicked: loader.sourceComponent = operatorsSelectorView
|
|
|
|
}
|
|
|
|
StatusSwitchTabBar {
|
|
|
|
id: tabBar
|
|
|
|
Layout.preferredWidth: 273 // by design
|
2022-08-23 08:46:37 +00:00
|
|
|
Layout.margins: 8
|
|
|
|
Layout.topMargin: root.withOperatorSelector ? 12 : 16
|
2022-06-09 15:27:14 +00:00
|
|
|
Layout.preferredHeight: 36 // by design
|
2022-08-23 08:46:37 +00:00
|
|
|
currentIndex: d.currentTabIndex
|
|
|
|
onCurrentIndexChanged: d.currentTabIndex = currentIndex
|
2022-06-09 15:27:14 +00:00
|
|
|
StatusSwitchTabButton {
|
|
|
|
text: qsTr("Token")
|
|
|
|
fontPixelSize: 13
|
|
|
|
}
|
|
|
|
StatusSwitchTabButton {
|
2022-08-23 08:46:37 +00:00
|
|
|
text: qsTr("Collectible")
|
2022-06-09 15:27:14 +00:00
|
|
|
fontPixelSize: 13
|
|
|
|
}
|
|
|
|
StatusSwitchTabButton {
|
|
|
|
text: qsTr("ENS")
|
|
|
|
fontPixelSize: 13
|
|
|
|
enabled: false // TODO
|
|
|
|
}
|
|
|
|
}
|
2022-08-23 08:46:37 +00:00
|
|
|
Loader {
|
|
|
|
id: tabsLoader
|
2022-06-09 15:27:14 +00:00
|
|
|
Layout.fillWidth: true
|
2022-08-23 08:46:37 +00:00
|
|
|
Layout.margins: 8
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
2022-08-23 08:46:37 +00:00
|
|
|
id: tokensCollectiblesLayout
|
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
ColumnLayout {
|
2022-08-23 08:46:37 +00:00
|
|
|
spacing: 0
|
2022-06-09 15:27:14 +00:00
|
|
|
StatusPickerButton {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: 36
|
2022-08-23 08:46:37 +00:00
|
|
|
bgColor: Theme.palette.baseColor5
|
|
|
|
contentColor: Theme.palette.directColor1
|
|
|
|
text: d.isTokensLayout ? root.tokenName : root.collectibleName
|
2022-06-09 15:27:14 +00:00
|
|
|
font.pixelSize: 13
|
2022-08-11 11:55:08 +00:00
|
|
|
asset.name: d.isTokensLayout ? root.tokenImage : root.collectibleImage
|
2022-08-23 08:46:37 +00:00
|
|
|
onClicked: loader.sourceComponent = extendedView
|
|
|
|
}
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
visible: !d.isTokensLayout
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
Layout.leftMargin: 16
|
|
|
|
Layout.rightMargin: 6
|
|
|
|
Layout.topMargin: 8
|
|
|
|
StatusBaseText {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
text: qsTr("Specific amount")
|
|
|
|
font.pixelSize: 13
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
elide: Text.ElideRight
|
|
|
|
clip: true
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
2022-08-23 08:46:37 +00:00
|
|
|
StatusSwitch { id: specificAmountSwitch }
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
2022-08-23 08:46:37 +00:00
|
|
|
|
|
|
|
StatusInput {
|
2022-06-09 15:27:14 +00:00
|
|
|
Layout.fillWidth: true
|
2022-08-23 08:46:37 +00:00
|
|
|
Layout.topMargin: 8
|
|
|
|
visible: d.isTokensLayout ? true : specificAmountSwitch.checked
|
|
|
|
minimumHeight: 36
|
|
|
|
maximumHeight: 36
|
|
|
|
topPadding: 0
|
|
|
|
bottomPadding: 0
|
|
|
|
text: d.isTokensLayout ? (root.tokenAmount === 0 ? "" : root.tokenAmount.toString()) :
|
|
|
|
(root.collectibleAmount === 0 ? "" : root.collectibleAmount.toString())
|
2022-06-09 15:27:14 +00:00
|
|
|
font.pixelSize: 13
|
2022-08-23 08:46:37 +00:00
|
|
|
rightPadding: amountText.implicitWidth + amountText.anchors.rightMargin + leftPadding
|
|
|
|
input.placeholderText: "0"
|
|
|
|
validationMode: StatusInput.ValidationMode.IgnoreInvalidInput
|
|
|
|
validators: StatusFloatValidator { bottom: 0 }
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
id: amountText
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: 13
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
text: qsTr("Amount")
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
font.pixelSize: 13
|
|
|
|
}
|
|
|
|
onTextChanged: {
|
|
|
|
if(d.isTokensLayout)
|
|
|
|
root.tokenAmount = Number(text)
|
|
|
|
else
|
|
|
|
root.collectibleAmount = Number(text)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusButton {
|
|
|
|
enabled: d.isTokensLayout ? d.tokensReady : d.collectiblesReady
|
|
|
|
text: qsTr("Add")
|
|
|
|
height: 44
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.topMargin: 32
|
2022-06-09 15:27:14 +00:00
|
|
|
onClicked: {
|
2022-08-23 08:46:37 +00:00
|
|
|
if(d.isTokensLayout)
|
|
|
|
root.addItem(root.itemKey, root.tokenAmount.toString() + " " + root.tokenName, root.tokenImage, root.operator)
|
|
|
|
else
|
|
|
|
root.addItem(root.itemKey, root.collectibleAmount.toString() + " " + root.collectibleName, root.collectibleImage, root.operator)
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-23 08:46:37 +00:00
|
|
|
// TODO
|
2022-06-09 15:27:14 +00:00
|
|
|
Component {
|
2022-08-23 08:46:37 +00:00
|
|
|
id: ensLayout
|
|
|
|
Item {}
|
|
|
|
}
|
2022-06-09 15:27:14 +00:00
|
|
|
|
2022-08-23 08:46:37 +00:00
|
|
|
Component {
|
|
|
|
id: extendedView
|
|
|
|
|
|
|
|
ExtendedDropdownContent {
|
|
|
|
store: root.store
|
|
|
|
type: d.isTokensLayout ? ExtendedDropdownContent.Type.Tokens : ExtendedDropdownContent.Type.Collectibles
|
|
|
|
onGoBack: loader.sourceComponent = tabsView
|
2022-06-09 15:27:14 +00:00
|
|
|
onItemClicked: {
|
|
|
|
// Go back
|
|
|
|
loader.sourceComponent = tabsView
|
|
|
|
|
2022-08-23 08:46:37 +00:00
|
|
|
if(d.isTokensLayout) {
|
|
|
|
// Update new token item info
|
|
|
|
root.tokenName = name
|
|
|
|
root.tokenImage = iconSource
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Update new collectible item info
|
|
|
|
root.collectibleName = name
|
|
|
|
root.collectibleImage = iconSource
|
|
|
|
}
|
|
|
|
root.itemKey = key
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-23 08:46:37 +00:00
|
|
|
}
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|