linphone-desktop/linphone-app/ui/modules/Common/Menus/MenuItem.qml
2021-10-29 17:46:01 +02:00

102 lines
2.8 KiB
QML

import QtQuick 2.7
import QtQuick.Controls 2.3 as Controls //2.3 for menu property (Qt 5.10)
import QtQuick.Layouts 1.3
import Common 1.0
import Common.Styles 1.0
// =============================================================================
// Using MenuItem.icon doesn't seem to work as of 07/2021
// Workaround : Implement own Icon
Controls.MenuItem {
id: button
property alias iconMenu : iconArea.icon
property alias iconSizeMenu : iconArea.iconSize
property alias iconOverwriteColorMenu: iconArea.overwriteColor
property alias iconLayoutDirection : rowArea.layoutDirection
property var menuItemStyle : MenuItemStyle.normal
property alias textWeight : rowText.font.bold
property int offsetTopMargin : 0
property int offsetBottomMargin : 0
height:visible?undefined:0
Component.onCompleted: menu.width = Math.max(menu.width, implicitWidth)
background: Rectangle {
color: button.down
? menuItemStyle.background.color.pressed
: (
button.hovered
? menuItemStyle.background.color.hovered
: menuItemStyle.background.color.normal
)
implicitHeight: button.menuItemStyle.background.height
}
contentItem:RowLayout{
id:rowArea
spacing:15
Icon{
id: iconArea
visible: icon
width: icon?iconSize:0
Layout.leftMargin:(iconLayoutDirection == Qt.LeftToRight ? menuItemStyle.leftMargin : 0)
Layout.rightMargin:(iconLayoutDirection == Qt.LeftToRight ? 0 : menuItemStyle.rightMargin)
overwriteColor: button.enabled
? (button.down
? menuItemStyle.text.color.pressed
: (
button.hovered
? menuItemStyle.text.color.hovered
: menuItemStyle.text.color.normal
))
: menuItemStyle.text.color.disabled
}
Text {
id:rowText
Layout.fillWidth: true
Layout.fillHeight: true
Layout.leftMargin:(iconLayoutDirection == Qt.LeftToRight ? 0 : menuItemStyle.leftMargin)
Layout.rightMargin:(iconLayoutDirection == Qt.LeftToRight ? menuItemStyle.rightMargin : 0)
color: button.enabled
? (button.down
? menuItemStyle.text.color.pressed
: (
button.hovered
? menuItemStyle.text.color.hovered
: menuItemStyle.text.color.normal
))
: menuItemStyle.text.color.disabled
elide: Text.ElideRight
font {
weight: menuItemStyle.text.weight
pointSize: menuItemStyle.text.pointSize
}
text: button.text
//leftPadding: menuItemStyle.leftPadding
//rightPadding: menuItemStyle.rightPadding
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
//anchors.top: parent.top
//anchors.bottom : parent.bottom
}
}
hoverEnabled: true
MouseArea{
anchors.fill:parent
propagateComposedEvents:true
acceptedButtons: Qt.NoButton
cursorShape: parent.hovered
? Qt.PointingHandCursor
: Qt.ArrowCursor
}
}