feature parity of Menu with the Desktop style

This commit is contained in:
Marco Martin 2018-11-28 16:35:43 +01:00
parent 2880333aab
commit e4c2f65c95
2 changed files with 80 additions and 16 deletions

View File

@ -17,19 +17,23 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import QtQuick 2.6
import QtQuick 2.7
import QtQuick.Controls @QQC2_VERSION@
import QtQuick.Templates @QQC2_VERSION@ as T
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.kirigami 2.5 as Kirigami
T.Menu {
id: control
@DISABLE_UNDER_QQC2_2_4@ palette: Kirigami.Theme.palette
implicitWidth: Math.max(background ? background.implicitWidth : 0,
contentItem ? contentItem.implicitWidth + leftPadding + rightPadding : 0)
implicitHeight: Math.max(background ? background.implicitHeight : 0,
contentItem ? contentItem.implicitHeight : 0) + topPadding + bottomPadding
@DISABLE_UNDER_QQC2_2_3@ delegate: MenuItem { width: parent.width; onImplicitWidthChanged: control.contentItem.contentItem.childrenChanged() }
margins: 0
leftPadding: background.margins.left
topPadding: background.margins.top
@ -38,10 +42,23 @@ T.Menu {
contentItem: ListView {
implicitHeight: contentHeight
property bool hasCheckables: false
property bool hasIcons: false
model: control.contentModel
implicitWidth: {
var maxWidth = 0;
for (var i = 0; i < contentItem.children.length; ++i) {
maxWidth = Math.max(maxWidth, contentItem.children[i].implicitWidth);
}
return maxWidth;
}
interactive: ApplicationWindow.window ? contentHeight > ApplicationWindow.window.height : false
clip: true
keyNavigationWraps: false
currentIndex: -1
currentIndex: control.currentIndex || 0
keyNavigationEnabled: true
keyNavigationWraps: true
T.ScrollBar.vertical: ScrollBar {}
}

View File

@ -18,14 +18,17 @@
*/
import QtQuick 2.6
import QtQuick.Layouts 1.2
import QtQuick.Templates @QQC2_VERSION@ as T
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.kirigami 2.5 as Kirigami
T.MenuItem {
id: controlRoot
@DISABLE_UNDER_QQC2_2_4@ palette: Kirigami.Theme.palette
implicitWidth: Math.max(background ? background.implicitWidth : 0,
contentItem.implicitWidth + leftPadding + rightPadding)
contentItem.implicitWidth + leftPadding + rightPadding + (arrow ? arrow.implicitWidth : 0))
implicitHeight: Math.max(background ? background.implicitHeight : 0,
Math.max(contentItem.implicitHeight,
indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding)
@ -38,19 +41,63 @@ T.MenuItem {
spacing: units.smallSpacing
hoverEnabled: true
contentItem: Label {
leftPadding: !controlRoot.mirrored ? (controlRoot.indicator ? controlRoot.indicator.width : 0) + controlRoot.spacing : 0
rightPadding: controlRoot.mirrored ? (controlRoot.indicator ? controlRoot.indicator.width : 0) + controlRoot.spacing : 0
text: controlRoot.text
font: controlRoot.font
color: theme.textColor
elide: Text.ElideRight
visible: controlRoot.text
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
Kirigami.MnemonicData.enabled: controlRoot.enabled && controlRoot.visible
Kirigami.MnemonicData.controlType: Kirigami.MnemonicData.MenuItem
Kirigami.MnemonicData.label: controlRoot.text
Shortcut {
//in case of explicit & the button manages it by itself
enabled: !(RegExp(/\&[^\&]/).test(controlRoot.text))
sequence: controlRoot.Kirigami.MnemonicData.sequence
onActivated: {
if (controlRoot.checkable) {
controlRoot.toggle();
} else {
controlRoot.clicked();
}
}
}
contentItem: RowLayout {
Item {
Layout.preferredWidth: (controlRoot.ListView.view && controlRoot.ListView.view.hasCheckables) || controlRoot.checkable ? controlRoot.indicator.width : Kirigami.Units.smallSpacing
}
PlasmaCore.IconItem {
Layout.alignment: Qt.AlignVCenter
visible: (controlRoot.ListView.view && controlRoot.ListView.view.hasIcons) || (controlRoot.icon != undefined && (controlRoot.icon.name.length > 0 || controlRoot.icon.source.length > 0))
source: controlRoot.icon ? (controlRoot.icon.name || controlRoot.icon.source) : ""
//FIXME: either migrate to Kirigami icon or add color to IconItem
// color: controlRoot.icon ? controlRoot.icon.color : "transparent"
//hovered is for retrocompatibility
status: (controlRoot.highlighted || controlRoot.hovered) ? PlasmaCore.Svg.Selected : PlasmaCore.Svg.Normal
Layout.preferredHeight: Math.max(label.height, Kirigami.Units.iconSizes.small)
Layout.preferredWidth: Layout.preferredHeight
}
Label {
id: label
Layout.alignment: Qt.AlignVCenter
Layout.fillWidth: true
text: controlRoot.Kirigami.MnemonicData.richTextLabel
font: controlRoot.font
color: (controlRoot.highlighted || controlRoot.hovered) ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor
elide: Text.ElideRight
visible: controlRoot.text
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
}
}
//we can't use arrow: on old qqc2 releases
@DISABLE_UNDER_QQC2_2_3@ arrow: PlasmaCore.IconItem {
@DISABLE_UNDER_QQC2_2_3@ x: controlRoot.mirrored ? controlRoot.padding : controlRoot.width - width - controlRoot.padding
@DISABLE_UNDER_QQC2_2_3@ y: controlRoot.topPadding + (controlRoot.availableHeight - height) / 2
@DISABLE_UNDER_QQC2_2_3@ source: controlRoot.mirrored ? "go-next-symbolic-rtl" : "go-next-symbolic"
@DISABLE_UNDER_QQC2_2_3@ status: controlRoot.highlighted ? PlasmaCore.Svg.Selected : PlasmaCore.Svg.Normal
@DISABLE_UNDER_QQC2_2_3@ width: Math.max(label.height, Kirigami.Units.iconSizes.small)
@DISABLE_UNDER_QQC2_2_3@ height: width
@DISABLE_UNDER_QQC2_2_3@ visible: controlRoot.subMenu
@DISABLE_UNDER_QQC2_2_3@ }
indicator: CheckIndicator {
x: controlRoot.mirrored ? controlRoot.width - width - controlRoot.rightPadding : controlRoot.leftPadding
y: controlRoot.topPadding + (controlRoot.availableHeight - height) / 2
@ -68,7 +115,7 @@ T.MenuItem {
prefix: "hover"
colorGroup: PlasmaCore.ColorScope.colorGroup
anchors.fill: parent
opacity: controlRoot.hovered && !controlRoot.pressed ? 1 : 0
opacity: (controlRoot.highlighted || controlRoot.hovered) && !controlRoot.pressed ? 1 : 0
Behavior on opacity {
NumberAnimation {
duration: units.longDuration