2020-06-17 19:31:01 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtGraphicalEffects 1.13
|
2020-05-27 21:09:12 +00:00
|
|
|
import "../imports"
|
2020-06-25 13:23:17 +00:00
|
|
|
import "../shared"
|
2020-05-27 20:42:24 +00:00
|
|
|
|
|
|
|
Menu {
|
2020-08-04 21:09:24 +00:00
|
|
|
// This is to add icons to submenu items. QML doesn't have a way to add icons to those sadly so this is a workaround
|
|
|
|
property var subMenuIcons: []
|
2020-07-09 18:26:50 +00:00
|
|
|
property int paddingSize: 8
|
2020-07-24 11:27:26 +00:00
|
|
|
property bool hasArrow: true
|
2020-07-09 17:47:36 +00:00
|
|
|
closePolicy: Popup.CloseOnPressOutside | Popup.CloseOnReleaseOutside | Popup.CloseOnEscape
|
2020-05-27 20:42:24 +00:00
|
|
|
id: popupMenu
|
2020-10-09 17:56:42 +00:00
|
|
|
topPadding: paddingSize
|
2020-07-09 18:26:50 +00:00
|
|
|
bottomPadding: paddingSize
|
|
|
|
|
2020-05-27 20:42:24 +00:00
|
|
|
delegate: MenuItem {
|
2021-02-18 19:07:23 +00:00
|
|
|
property color textColor: this.action.icon.color.toString() !== "#00000000" ? this.action.icon.color : Style.current.textColor
|
2020-08-04 21:09:24 +00:00
|
|
|
property int subMenuIndex: {
|
|
|
|
if (!this.subMenu) {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
let child;
|
|
|
|
let index = 0;
|
|
|
|
for (let i = 0; i < popupMenu.count; i++) {
|
|
|
|
child = popupMenu.itemAt(i)
|
|
|
|
if (child.subMenu) {
|
|
|
|
if (child === this) {
|
|
|
|
return index
|
|
|
|
} else {
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return index
|
|
|
|
}
|
|
|
|
|
2021-02-23 10:18:09 +00:00
|
|
|
enabled: {
|
|
|
|
if (this.subMenu) {
|
|
|
|
return this.subMenu.enabled
|
|
|
|
}
|
|
|
|
return this.action.enabled
|
|
|
|
}
|
2020-08-04 21:09:24 +00:00
|
|
|
action: Action{} // Meant to be overwritten
|
2020-05-27 20:42:24 +00:00
|
|
|
id: popupMenuItem
|
|
|
|
implicitWidth: 200
|
2020-07-09 18:26:50 +00:00
|
|
|
implicitHeight: 34
|
|
|
|
font.pixelSize: 13
|
2020-10-09 17:56:42 +00:00
|
|
|
font.weight: checked ? Font.Medium : Font.Normal
|
2020-07-02 15:14:31 +00:00
|
|
|
icon.color: popupMenuItem.action.icon.color != "#00000000" ? popupMenuItem.action.icon.color : Style.current.blue
|
2020-08-04 21:09:24 +00:00
|
|
|
icon.source: this.subMenu ? subMenuIcons[subMenuIndex].source : popupMenuItem.action.icon.source
|
|
|
|
icon.width: this.subMenu ? subMenuIcons[subMenuIndex].width : popupMenuItem.action.icon.width
|
|
|
|
icon.height: this.subMenu ? subMenuIcons[subMenuIndex].height : popupMenuItem.action.icon.height
|
2021-02-23 10:18:09 +00:00
|
|
|
visible: enabled
|
2020-10-09 17:56:42 +00:00
|
|
|
height: visible ? popupMenuItem.implicitHeight : 0
|
2020-07-09 18:26:50 +00:00
|
|
|
|
2020-08-04 21:09:24 +00:00
|
|
|
arrow: SVGImage {
|
|
|
|
source: "../app/img/caret.svg"
|
|
|
|
rotation: -90
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: 12
|
|
|
|
width: 9
|
|
|
|
fillMode: Image.PreserveAspectFit
|
2021-02-23 10:18:09 +00:00
|
|
|
visible: popupMenuItem.subMenu && popupMenuItem.subMenu.enabled
|
2020-12-01 18:21:44 +00:00
|
|
|
|
2020-08-04 21:09:24 +00:00
|
|
|
ColorOverlay {
|
|
|
|
anchors.fill: parent
|
|
|
|
source: parent
|
2021-02-18 19:07:23 +00:00
|
|
|
color: popupMenuItem.textColor
|
2020-07-09 18:26:50 +00:00
|
|
|
}
|
2020-08-04 21:09:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME the icons looks very pixelated on Linux for some reason. Using smooth, mipmap, etc doesn't fix it
|
2020-12-01 18:21:44 +00:00
|
|
|
indicator: Item {
|
2020-08-04 21:09:24 +00:00
|
|
|
visible: !!popupMenuItem.icon.source.toString()
|
|
|
|
width: !isNaN(popupMenuItem.icon.width) ? popupMenuItem.icon.width : 25
|
|
|
|
height: !isNaN(popupMenuItem.icon.height) ? popupMenuItem.icon.height : 25
|
2020-12-01 18:21:44 +00:00
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: Style.current.padding
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
|
|
|
Image {
|
|
|
|
id: menuIcon
|
|
|
|
source: popupMenuItem.icon.source
|
|
|
|
visible: false
|
|
|
|
width: parent.width
|
|
|
|
height: parent.width
|
|
|
|
sourceSize.width: width
|
|
|
|
sourceSize.height: height
|
|
|
|
}
|
2020-05-27 20:42:24 +00:00
|
|
|
|
2020-07-09 18:26:50 +00:00
|
|
|
ColorOverlay {
|
2020-12-01 18:21:44 +00:00
|
|
|
anchors.fill: menuIcon
|
|
|
|
source: menuIcon
|
|
|
|
smooth: true
|
2021-02-18 19:07:23 +00:00
|
|
|
color: (popupMenuItem.action.icon.color != "#00000000" ? popupMenuItem.action.icon.color : Style.current.primaryMenuItemHover)
|
2020-05-27 20:42:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-04 21:09:24 +00:00
|
|
|
contentItem: StyledText {
|
|
|
|
anchors.left: popupMenuItem.indicator.right
|
|
|
|
anchors.leftMargin: popupMenu.paddingSize
|
|
|
|
text: popupMenuItem.text
|
|
|
|
font: popupMenuItem.font
|
2021-02-18 19:07:23 +00:00
|
|
|
color: popupMenuItem.textColor
|
2020-08-04 21:09:24 +00:00
|
|
|
horizontalAlignment: Text.AlignLeft
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
opacity: enabled ? 1.0 : 0.3
|
|
|
|
elide: Text.ElideRight
|
|
|
|
}
|
|
|
|
|
2020-05-27 20:42:24 +00:00
|
|
|
background: Rectangle {
|
|
|
|
implicitWidth: 220
|
2021-02-23 10:18:09 +00:00
|
|
|
implicitHeight: enabled ? 24 : 0
|
2021-02-18 19:07:23 +00:00
|
|
|
color: popupMenuItem.highlighted ? Style.current.backgroundHover : "transparent"
|
2020-05-27 20:42:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-04 21:09:24 +00:00
|
|
|
background: Item {
|
2020-05-27 20:42:24 +00:00
|
|
|
id: bgPopupMenu
|
|
|
|
implicitWidth: 220
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: bgPopupMenuContent
|
|
|
|
implicitWidth: bgPopupMenu.width
|
|
|
|
implicitHeight: bgPopupMenu.height
|
2020-07-13 18:45:54 +00:00
|
|
|
color: Style.current.modalBackground
|
2020-11-11 10:49:57 +00:00
|
|
|
radius: 8
|
2020-05-27 20:42:24 +00:00
|
|
|
layer.enabled: true
|
|
|
|
layer.effect: DropShadow{
|
|
|
|
width: bgPopupMenuContent.width
|
|
|
|
height: bgPopupMenuContent.height
|
|
|
|
x: bgPopupMenuContent.x
|
|
|
|
visible: bgPopupMenuContent.visible
|
|
|
|
source: bgPopupMenuContent
|
|
|
|
horizontalOffset: 0
|
2020-11-11 10:49:57 +00:00
|
|
|
verticalOffset: 4
|
|
|
|
radius: 12
|
|
|
|
samples: 25
|
|
|
|
spread: 0.2
|
2020-05-27 20:42:24 +00:00
|
|
|
color: "#22000000"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-04 14:53:10 +00:00
|
|
|
|
|
|
|
/*##^##
|
|
|
|
Designer {
|
|
|
|
D{i:0;autoSize:true;height:480;width:640}
|
|
|
|
}
|
|
|
|
##^##*/
|