feat(StatusMenuItem): add support for "checked" indicator

- it is displayed on the trailing edge, next to the main text, iff the
item/action is `checked`
- fix the text elide (must have a width set)
- fix for setting the icon name/source/color if we directly use a
(Status)MenuItem (as opposed to going via (Status)Action)
This commit is contained in:
Lukáš Tinkl 2023-03-20 13:25:56 +01:00 committed by Lukáš Tinkl
parent b4459c5858
commit d180001f84
1 changed files with 29 additions and 19 deletions

View File

@ -1,5 +1,6 @@
import QtQuick 2.13 import QtQuick 2.13
import QtQuick.Controls 2.13 import QtQuick.Controls 2.13
import QtQuick.Layouts 1.15
import StatusQ.Core 0.1 import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1 import StatusQ.Core.Theme 0.1
@ -83,9 +84,9 @@ MenuItem {
rotation: 0 rotation: 0
// Link to standard Qt properties. Not because it's a good idea, // Link to standard Qt properties. Not because it's a good idea,
// but because it we use it in some places and it will make refactor easier. // but because it we use it in some places and it will make refactor easier.
name: d.isSubMenu ? "" : root.action.icon.name name: d.isSubMenu ? "" : (d.hasAction ? root.action.icon.name : root.icon.name)
source: d.isSubMenu ? "" : root.action.icon.source source: d.isSubMenu ? "" : (d.hasAction ? root.action.icon.source : root.icon.source)
color: d.isSubMenu ? "" : root.action.icon.color color: d.isSubMenu ? "" : (d.hasAction ? root.action.icon.color : root.icon.color)
} }
readonly property StatusFontSettings defaultFontSettings: StatusFontSettings { readonly property StatusFontSettings defaultFontSettings: StatusFontSettings {
@ -119,7 +120,9 @@ MenuItem {
} }
} }
contentItem: StatusBaseText { contentItem: RowLayout {
StatusBaseText {
Layout.fillWidth: true
readonly property real arrowPadding: root.spacing + (root.subMenu && root.arrow ? root.arrow.width : 0) readonly property real arrowPadding: root.spacing + (root.subMenu && root.arrow ? root.arrow.width : 0)
readonly property real indicatorPadding: root.spacing + (root.indicator.visible ? root.indicator.width : 0) readonly property real indicatorPadding: root.spacing + (root.indicator.visible ? root.indicator.width : 0)
@ -132,14 +135,21 @@ MenuItem {
text: root.text text: root.text
color: !root.enabled ? Theme.palette.baseColor1 color: !root.enabled ? Theme.palette.baseColor1
: d.isStatusDangerAction ? Theme.palette.dangerColor1 : d.isStatusDangerAction ? Theme.palette.dangerColor1
: d.isStatusSuccessAction? : d.isStatusSuccessAction ? Theme.palette.successColor1 : Theme.palette.directColor1
Theme.palette.successColor1 : Theme.palette.directColor1
font.pixelSize: d.fontSettings ? d.fontSettings.pixelSize : d.defaultFontSettings.pixelSize font.pixelSize: d.fontSettings ? d.fontSettings.pixelSize : d.defaultFontSettings.pixelSize
font.bold: d.fontSettings ? d.fontSettings.bold : d.defaultFontSettings.bold font.bold: d.fontSettings ? d.fontSettings.bold : d.defaultFontSettings.bold
font.italic: d.fontSettings ? d.fontSettings.italic : d.defaultFontSettings.italic font.italic: d.fontSettings ? d.fontSettings.italic : d.defaultFontSettings.italic
elide: Text.ElideRight elide: Text.ElideRight
} }
StatusIcon {
Layout.preferredHeight: 16
Layout.alignment: Qt.AlignRight
visible: root.checkable && root.checked
icon: "checkmark"
color: Theme.palette.primaryColor1
}
}
arrow: StatusIcon { arrow: StatusIcon {
id: arrowIcon id: arrowIcon