2020-08-03 13:27:42 -04:00
|
|
|
/*
|
2023-02-06 01:47:15 -05:00
|
|
|
* Copyright (C) 2020-2023 Savoir-faire Linux Inc.
|
2020-08-03 13:27:42 -04:00
|
|
|
* 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/>.
|
|
|
|
*/
|
2021-09-08 10:31:38 -04:00
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Controls
|
|
|
|
import QtQuick.Layouts
|
2021-08-23 13:24:08 -04:00
|
|
|
import net.jami.Constants 1.1
|
2023-04-13 16:18:26 -04:00
|
|
|
import "../"
|
2021-05-31 14:04:38 -04:00
|
|
|
|
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
|
2022-10-11 16:24:04 -04:00
|
|
|
property bool dangerous: false
|
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
|
|
|
|
2021-06-04 13:34:03 -04:00
|
|
|
property int itemImageLeftMargin: 24
|
|
|
|
property int itemTextMargin: 20
|
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
signal clicked
|
2023-01-10 16:47:18 -05:00
|
|
|
property bool itemHovered: menuItemContentRect.hovered
|
2020-08-03 13:27:42 -04:00
|
|
|
|
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
|
2021-09-08 10:31:38 -04:00
|
|
|
|
2020-10-09 17:59:07 -04:00
|
|
|
anchors.fill: parent
|
|
|
|
anchors.leftMargin: 1
|
|
|
|
anchors.rightMargin: 1
|
2021-09-08 10:31:38 -04:00
|
|
|
|
2023-04-13 16:18:26 -04:00
|
|
|
color: menuItemContentRect.hovered ? JamiTheme.hoverColor : JamiTheme.backgroundColor
|
2020-10-09 17:59:07 -04:00
|
|
|
}
|
|
|
|
|
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
|
2021-06-04 13:34:03 -04:00
|
|
|
Layout.leftMargin: status === Image.Ready ? itemImageLeftMargin : 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
|
2023-04-13 16:18:26 -04:00
|
|
|
Layout.leftMargin: contextMenuItemImage.status === Image.Ready ? itemTextMargin : itemTextMargin / 2
|
|
|
|
Layout.rightMargin: contextMenuItemImage.status === Image.Ready ? itemTextMargin : itemTextMargin / 2
|
2021-06-01 17:16:40 -04:00
|
|
|
Layout.preferredHeight: itemPreferredHeight
|
2021-06-04 13:34:03 -04:00
|
|
|
Layout.fillWidth: true
|
2021-06-01 17:16:40 -04:00
|
|
|
|
|
|
|
text: itemName
|
2022-10-11 16:24:04 -04:00
|
|
|
color: dangerous ? JamiTheme.redColor : JamiTheme.textColor
|
2021-06-01 17:16:40 -04:00
|
|
|
font.pointSize: JamiTheme.textFontSize
|
|
|
|
horizontalAlignment: Text.AlignLeft
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
2021-06-04 13:34:03 -04:00
|
|
|
|
|
|
|
TextMetrics {
|
|
|
|
id: contextMenuItemTextMetrics
|
|
|
|
|
|
|
|
font: contextMenuItemText.font
|
|
|
|
text: contextMenuItemText.text
|
|
|
|
|
|
|
|
onBoundingRectChanged: {
|
2023-04-13 16:18:26 -04:00
|
|
|
var sizeToCompare = itemPreferredWidth - (contextMenuItemImage.source.toString().length > 0 ? itemTextMargin + itemImageLeftMargin + contextMenuItemImage.width : itemTextMargin / 2);
|
|
|
|
if (autoTextSizeAdjustment && boundingRect.width > sizeToCompare) {
|
2021-06-04 13:34:03 -04:00
|
|
|
if (boundingRect.width > JamiTheme.contextMenuItemTextMaxWidth) {
|
2023-04-13 16:18:26 -04:00
|
|
|
itemPreferredWidth += JamiTheme.contextMenuItemTextMaxWidth - JamiTheme.contextMenuItemTextPreferredWidth + itemTextMargin;
|
|
|
|
contextMenuItemText.elide = Text.ElideRight;
|
2021-06-04 13:34:03 -04:00
|
|
|
} else
|
2023-04-13 16:18:26 -04:00
|
|
|
itemPreferredWidth += boundingRect.width + itemTextMargin - sizeToCompare;
|
2021-06-04 13:34:03 -04:00
|
|
|
}
|
2021-06-01 17:16:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
2021-05-31 14:04:38 -04:00
|
|
|
onReleased: {
|
2023-04-13 16:18:26 -04:00
|
|
|
menuItem.clicked();
|
|
|
|
parentMenu.close();
|
2021-05-31 14:04:38 -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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|