2020-08-03 13:27:42 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 by Savoir-faire Linux
|
|
|
|
* Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-10-06 13:58:44 +02:00
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
import QtQuick 2.14
|
|
|
|
import QtQuick.Controls 2.14
|
|
|
|
import QtQuick.Layouts 1.14
|
2020-10-06 13:58:44 +02:00
|
|
|
import QtGraphicalEffects 1.14
|
2021-03-17 14:23:21 -04:00
|
|
|
|
2020-12-05 14:05:57 +01:00
|
|
|
import net.jami.Constants 1.0
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-05-31 14:04:38 -04:00
|
|
|
import "../../commoncomponents"
|
|
|
|
|
2020-09-03 21:19:10 -04:00
|
|
|
// General menu item.
|
|
|
|
// Can control top, bottom, left, right border width.
|
|
|
|
// Use onClicked slot to simulate item click event.
|
|
|
|
// Can have image icon at the left of the text.
|
2020-08-03 13:27:42 -04:00
|
|
|
MenuItem {
|
|
|
|
id: menuItem
|
|
|
|
|
|
|
|
property string itemName: ""
|
2021-05-31 14:04:38 -04:00
|
|
|
property alias iconSource: contextMenuItemImage.source
|
2020-11-28 16:14:25 -05:00
|
|
|
property string iconColor: ""
|
2021-05-31 14:04:38 -04:00
|
|
|
property bool canTrigger: true
|
|
|
|
property bool addMenuSeparatorAfter: false
|
2021-06-01 17:16:40 -04:00
|
|
|
property bool autoTextSizeAdjustment: true
|
2021-05-31 14:04:38 -04:00
|
|
|
property BaseContextMenu parentMenu
|
2020-08-27 12:59:09 -04:00
|
|
|
|
2021-05-31 14:04:38 -04:00
|
|
|
property int itemPreferredWidth: JamiTheme.menuItemsPreferredWidth
|
|
|
|
property int itemPreferredHeight: JamiTheme.menuItemsPreferredHeight
|
|
|
|
property int leftBorderWidth: JamiTheme.menuItemsCommonBorderWidth
|
|
|
|
property int rightBorderWidth: JamiTheme.menuItemsCommonBorderWidth
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
signal clicked
|
|
|
|
|
2020-10-09 17:59:07 -04:00
|
|
|
contentItem: AbstractButton {
|
2020-08-03 13:27:42 -04:00
|
|
|
id: menuItemContentRect
|
|
|
|
|
2020-10-09 17:59:07 -04:00
|
|
|
background: Rectangle {
|
|
|
|
id: background
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.leftMargin: 1
|
|
|
|
anchors.rightMargin: 1
|
|
|
|
color: "transparent"
|
|
|
|
}
|
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
anchors.fill: parent
|
2021-04-02 10:24:46 -04:00
|
|
|
|
2021-06-01 17:16:40 -04:00
|
|
|
RowLayout {
|
|
|
|
spacing: 0
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-06-01 17:16:40 -04:00
|
|
|
anchors.fill: menuItemContentRect
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-06-01 17:16:40 -04:00
|
|
|
ResponsiveImage {
|
|
|
|
id: contextMenuItemImage
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-06-01 17:16:40 -04:00
|
|
|
Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
|
|
|
|
Layout.leftMargin: status === Image.Ready ? 24 : 0
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-06-01 17:16:40 -04:00
|
|
|
visible: status === Image.Ready
|
2021-04-02 10:24:46 -04:00
|
|
|
|
2021-06-01 17:16:40 -04:00
|
|
|
color: iconColor !== "" ? iconColor : JamiTheme.textColor
|
|
|
|
opacity: 0.7
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-06-01 17:16:40 -04:00
|
|
|
Text {
|
|
|
|
id: contextMenuItemText
|
|
|
|
|
|
|
|
Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
|
|
|
|
Layout.leftMargin: contextMenuItemImage.status === Image.Ready ? 20 : 10
|
|
|
|
Layout.rightMargin: contextMenuItemImage.status === Image.Ready ? 20 : 10
|
|
|
|
Layout.preferredHeight: itemPreferredHeight
|
|
|
|
Layout.preferredWidth: JamiTheme.contextMenuItemTextPreferredWidth
|
|
|
|
|
|
|
|
text: itemName
|
|
|
|
color: JamiTheme.textColor
|
|
|
|
font.pointSize: JamiTheme.textFontSize
|
|
|
|
horizontalAlignment: Text.AlignLeft
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
elide: Text.ElideRight
|
|
|
|
|
|
|
|
onWidthChanged: {
|
|
|
|
if (autoTextSizeAdjustment
|
|
|
|
&& width > contextMenuItemText.Layout.preferredWidth) {
|
|
|
|
if (width > JamiTheme.contextMenuItemTextMaxWidth)
|
|
|
|
contextMenuItemText.Layout.preferredWidth
|
|
|
|
= JamiTheme.contextMenuItemTextMaxWidth
|
|
|
|
else
|
|
|
|
contextMenuItemText.Layout.preferredWidth = width
|
|
|
|
itemPreferredWidth += contextMenuItemText.Layout.preferredWidth
|
|
|
|
- JamiTheme.contextMenuItemTextPreferredWidth
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
2021-05-31 14:04:38 -04:00
|
|
|
onReleased: {
|
|
|
|
menuItem.clicked()
|
|
|
|
parentMenu.close()
|
|
|
|
}
|
2020-10-09 17:59:07 -04:00
|
|
|
|
|
|
|
states: [
|
|
|
|
State {
|
2021-06-01 17:16:40 -04:00
|
|
|
name: "hovered"
|
|
|
|
when: hovered
|
|
|
|
PropertyChanges {
|
|
|
|
target: background
|
|
|
|
color: JamiTheme.hoverColor
|
|
|
|
}
|
2020-10-09 17:59:07 -04:00
|
|
|
},
|
|
|
|
State {
|
2021-06-01 17:16:40 -04:00
|
|
|
name: "normal"
|
|
|
|
when: !hovered
|
|
|
|
PropertyChanges {
|
|
|
|
target: background
|
|
|
|
color: JamiTheme.backgroundColor
|
|
|
|
}
|
2020-10-09 17:59:07 -04:00
|
|
|
}
|
|
|
|
]
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
2020-10-09 17:59:07 -04:00
|
|
|
highlighted: true
|
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
background: Rectangle {
|
|
|
|
id: contextMenuBackgroundRect
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.leftMargin: leftBorderWidth
|
|
|
|
anchors.rightMargin: rightBorderWidth
|
|
|
|
|
2021-05-31 14:04:38 -04:00
|
|
|
implicitWidth: itemPreferredWidth
|
|
|
|
implicitHeight: itemPreferredHeight
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
border.width: 0
|
|
|
|
|
|
|
|
CustomBorder {
|
|
|
|
commonBorder: false
|
|
|
|
lBorderwidth: leftBorderWidth
|
|
|
|
rBorderwidth: rightBorderWidth
|
2020-08-27 12:59:09 -04:00
|
|
|
tBorderwidth: 0
|
|
|
|
bBorderwidth: 0
|
2020-08-03 13:27:42 -04:00
|
|
|
borderColor: JamiTheme.tabbarBorderColor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|