Skip to content

Commit

Permalink
fix(StatusMenu): StatusSuccessAction is not taken into account for Me…
Browse files Browse the repository at this point in the history
…nu width

- StatusSuccessAction, despite its name, is a visual item (`MenuItem` ->
`AbstractButton`) which is not part of the `contentModel` but just added
to the menu container
- therefore we don't use a ListView but a ScrollView/Repeater instead
and set the width/maxWidth manually after the menu items have been added
to the layout

Fixes #14037
  • Loading branch information
caybro committed Sep 19, 2024
1 parent ea8827e commit 091d8a3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 37 deletions.
41 changes: 14 additions & 27 deletions ui/StatusQ/src/StatusQ/Popups/StatusMenu.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import QtQuick 2.15
import QtQml 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import QtGraphicalEffects 1.15

import StatusQ.Core 0.1
Expand Down Expand Up @@ -67,22 +68,11 @@ Menu {
property var openHandler
property var closeHandler

function checkIfEmpty() {
for (let i = 0; i < root.contentItem.count; ++i) {
const menuItem = root.contentItem.itemAtIndex(i)
if (menuItem.text !== undefined && menuItem.enabled) { // skip menu separators
return false
}
}
return true
}

dim: false
closePolicy: Popup.CloseOnPressOutside | Popup.CloseOnEscape
topPadding: 8
bottomPadding: 8
margins: 16
width: Math.min(implicitWidth, root.maxImplicitWidth)

onOpened: {
if (typeof openHandler === "function") {
Expand All @@ -96,27 +86,24 @@ Menu {
}
}

QtObject {
id: d
//helper property to get the max implicit width of the delegate
property real maxDelegateImplWidth: 0
}

delegate: StatusMenuItem {
visible: root.hideDisabledItems && !visibleOnDisabled ? enabled : true
height: visible ? implicitHeight : 0
onImplicitWidthChanged: {
if (visible)
d.maxDelegateImplWidth = Math.max(d.maxDelegateImplWidth, implicitWidth)
}
}

contentItem: StatusListView {
currentIndex: root.currentIndex
implicitHeight: contentHeight
implicitWidth: d.maxDelegateImplWidth
interactive: contentHeight > availableHeight
model: root.contentModel
contentItem: StatusScrollView {
padding: 0

ColumnLayout {
Repeater {
model: root.contentModel

onItemAdded: {
item.Layout.fillWidth = true
item.Layout.maximumWidth = root.maxImplicitWidth
}
}
}
}

background: Rectangle {
Expand Down
4 changes: 2 additions & 2 deletions ui/StatusQ/src/StatusQ/Popups/StatusMenuItem.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15

import StatusQ.Core 0.1
Expand Down
16 changes: 8 additions & 8 deletions ui/StatusQ/src/StatusQ/Popups/StatusSuccessAction.qml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import QtQuick 2.14
import QtQuick 2.15

import StatusQ.Popups 0.1

Expand All @@ -9,7 +9,7 @@ import StatusQ.Popups 0.1
\since StatusQ.Popups 0.1
\brief Menu action displaying success state.
The \c StatusSuccessAction visually indicate a success state after being triggered.
The \c StatusSuccessAction visually indicates a success state after being triggered.
Success state is showed by changing action type to \c{Success}.
\qml
Expand All @@ -27,31 +27,31 @@ StatusMenuItem {
id: root

/*!
\qmlproperty bool StatusSuccessAction.qml::success
\qmlproperty bool StatusSuccessAction::success
This property holds state of the action.
*/
property bool success: false
/*!
\qmlproperty string StatusSuccessAction.qml::successText
\qmlproperty string StatusSuccessAction::successText
This property holds success text displayed on success state.
Default value is binded to \c{text}.
Default value is bound to \c{text}.
*/
property string successText: text
/*!
\qmlproperty string StatusSuccessAction.qml::successIconName
\qmlproperty string StatusSuccessAction::successIconName
This property holds icon name displayed on success state.
Default value is \c{tiny/checkmark}.
*/
property string successIconName: "tiny/checkmark"
/*!
\qmlproperty bool StatusSuccessAction.qml::autoDismissMenu
\qmlproperty bool StatusSuccessAction::autoDismissMenu
This property enable menu closing on click.
*/
property bool autoDismissMenu: false
/*!
\qmlproperty int StatusSuccessAction.qml::timeout
\qmlproperty int StatusSuccessAction::timeout
This property controls how long success state is showed.
*/
property int timeout: 2000
Expand Down

0 comments on commit 091d8a3

Please sign in to comment.