chore(TokenItem): component api simplified

This commit is contained in:
Michał Cieślak 2023-04-19 13:55:12 +02:00 committed by Michał
parent 7fbb2cbc5a
commit 70a6327ad4
3 changed files with 14 additions and 22 deletions

View File

@ -412,11 +412,10 @@ Item {
Layout.fillWidth: true Layout.fillWidth: true
key: d.currentItemKey
name: qsTr("Any %1").arg(d.currentItemName) name: qsTr("Any %1").arg(d.currentItemName)
iconSource: d.currentItemSource iconSource: d.currentItemSource
selected: root.checkedKeys.includes(key) selected: root.checkedKeys.includes(d.currentItemKey)
enabled: true enabled: true
onItemClicked: root.itemClicked(d.currentItemKey, onItemClicked: root.itemClicked(d.currentItemKey,
d.currentItemName, d.currentItemName,

View File

@ -89,15 +89,15 @@ StatusListView {
delegate: TokenItem { delegate: TokenItem {
width: ListView.view.width width: ListView.view.width
key: model.key
name: model.name name: model.name
shortName: model.shortName ?? "" shortName: model.shortName ?? ""
iconSource: model.iconSource ?? "" iconSource: model.iconSource ?? ""
subItems: model.subItems showSubItemsIcon: !!model.subItems && model.subItems.count > 0
selected: root.checkedKeys.includes(model.key) selected: root.checkedKeys.includes(model.key)
onItemClicked: root.itemClicked( onItemClicked: root.itemClicked(
key, name, shortName, iconSource, subItems) model.key, name, shortName, iconSource, model.subItems)
} }
section.property: root.searchMode || !root.areSectionsVisible section.property: root.searchMode || !root.areSectionsVisible

View File

@ -1,23 +1,21 @@
import QtQuick 2.13 import QtQuick 2.15
import QtQuick.Layouts 1.14 import QtQuick.Layouts 1.15
import QtQuick.Controls 2.12 import QtQuick.Controls 2.15
import StatusQ.Core 0.1 import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1 import StatusQ.Core.Theme 0.1
import StatusQ.Controls 0.1
import StatusQ.Components 0.1 import StatusQ.Components 0.1
Control { Control {
id: root id: root
property string key
property string name property string name
property string shortName property string shortName
property url iconSource property url iconSource
property var subItems
property bool selected: false property bool selected: false
property bool showSubItemsIcon: false
signal itemClicked(string key, string name, string shortName, url iconSource, var subItems) signal itemClicked
leftPadding: 6 // by design leftPadding: 6 // by design
implicitHeight: 45 // by design implicitHeight: 45 // by design
@ -30,11 +28,7 @@ Control {
anchors.fill: parent anchors.fill: parent
cursorShape: root.enabled ? Qt.PointingHandCursor : Qt.ArrowCursor cursorShape: root.enabled ? Qt.PointingHandCursor : Qt.ArrowCursor
hoverEnabled: true hoverEnabled: true
onClicked: root.itemClicked(root.key, onClicked: root.itemClicked()
root.name,
root.shortName,
root.iconSource,
root.subItems)
} }
} }
contentItem: RowLayout { contentItem: RowLayout {
@ -58,13 +52,14 @@ Control {
text: root.name text: root.name
color: Theme.palette.directColor1 color: Theme.palette.directColor1
font.pixelSize: 13 font.pixelSize: 13
font.weight: Font.Medium
elide: Text.ElideRight elide: Text.ElideRight
} }
StatusBaseText { StatusBaseText {
visible: !!root.shortName visible: !!root.shortName
Layout.fillWidth: true Layout.fillWidth: true
text: !!root.shortName ? root.shortName : "" text: root.shortName
color: Theme.palette.baseColor1 color: Theme.palette.baseColor1
font.pixelSize: 12 font.pixelSize: 12
elide: Text.ElideRight elide: Text.ElideRight
@ -72,10 +67,8 @@ Control {
} }
StatusIcon { StatusIcon {
readonly property bool hasSubItems: !!root.subItems && root.subItems.count > 0 icon: root.selected && !root.showSubItemsIcon ? "checkmark" : "tiny/chevron-right"
visible: root.selected || root.showSubItemsIcon
icon: root.selected && !hasSubItems ? "checkmark" : "tiny/chevron-right"
visible: root.selected || hasSubItems
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
Layout.rightMargin: 16 Layout.rightMargin: 16
color: Theme.palette.baseColor1 color: Theme.palette.baseColor1