forked from openkylin/qt5-ukui-platformtheme
98 lines
2.8 KiB
QML
98 lines
2.8 KiB
QML
|
|
import QtQuick 2.7
|
|
import QtQuick.Layouts 1.2
|
|
import QtGraphicalEffects 1.0
|
|
import QtQuick.Controls 2.5
|
|
import QtQuick.Templates 2.5 as T
|
|
import org.ukui.qqc2style.private 1.0 as StylePrivate
|
|
|
|
T.Menu {
|
|
id: control
|
|
|
|
palette: StylePrivate.StyleHelper.palette
|
|
font: StylePrivate.StyleHelper.font
|
|
|
|
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
|
|
|
|
margins: 0
|
|
|
|
delegate: MenuItem { onImplicitWidthChanged: control.contentItem.contentItem.childrenChanged() }
|
|
|
|
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
|
|
currentIndex: control.currentIndex || 0
|
|
keyNavigationEnabled: true
|
|
keyNavigationWraps: true
|
|
|
|
ScrollBar.vertical: ScrollBar {}
|
|
}
|
|
|
|
Connections {
|
|
target: control.contentItem.contentItem
|
|
onChildrenChanged: {
|
|
for (var i in control.contentItem.contentItem.children) {
|
|
var child = control.contentItem.contentItem.children[i];
|
|
if (child.checkable) {
|
|
control.contentItem.hasCheckables = true;
|
|
}
|
|
if (child.icon && child.icon.hasOwnProperty("name") && (child.icon.name.length > 0 || child.icon.source.length > 0)) {
|
|
control.contentItem.hasIcons = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
enter: Transition {
|
|
NumberAnimation {
|
|
property: "opacity"
|
|
from: 0
|
|
to: 1
|
|
easing.type: Easing.InOutQuad
|
|
duration: 150
|
|
}
|
|
}
|
|
|
|
exit: Transition {
|
|
NumberAnimation {
|
|
property: "opacity"
|
|
from: 1
|
|
to: 0
|
|
easing.type: Easing.InOutQuad
|
|
duration: 150
|
|
}
|
|
}
|
|
|
|
background: Rectangle {
|
|
radius: 2
|
|
|
|
color: control.palette.window
|
|
|
|
layer.enabled: true
|
|
|
|
layer.effect: DropShadow {
|
|
transparentBorder: true
|
|
radius: 8
|
|
samples: 8
|
|
horizontalOffset: 0
|
|
verticalOffset: 2
|
|
color: Qt.rgba(0, 0, 0, 0.3)
|
|
}
|
|
}
|
|
}
|