2020-08-03 13:27:42 -04:00
|
|
|
/*
|
2025-02-06 21:47:26 -04:00
|
|
|
* Copyright (C) 2020-2025 Savoir-faire Linux Inc.
|
2020-08-03 13:27:42 -04:00
|
|
|
*
|
|
|
|
* 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
|
2023-10-18 13:01:22 -04:00
|
|
|
property bool hasIcon: true
|
2021-05-31 14:04:38 -04:00
|
|
|
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
|
2023-10-24 16:35:37 -04:00
|
|
|
property bool isActif: true
|
2020-08-27 12:59:09 -04:00
|
|
|
|
2023-10-18 13:01:22 -04:00
|
|
|
property int itemPreferredWidth: hasIcon ? 50 + contextMenuItemText.contentWidth + contextMenuItemImage.width : 35 + contextMenuItemText.contentWidth
|
|
|
|
property int itemRealWidth: itemPreferredWidth
|
2021-05-31 14:04:38 -04:00
|
|
|
property int itemPreferredHeight: JamiTheme.menuItemsPreferredHeight
|
|
|
|
property int leftBorderWidth: JamiTheme.menuItemsCommonBorderWidth
|
|
|
|
property int rightBorderWidth: JamiTheme.menuItemsCommonBorderWidth
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2023-10-24 16:35:37 -04:00
|
|
|
property int itemImageLeftMargin: 10
|
2023-10-18 13:01:22 -04:00
|
|
|
property int itemTextMargin: 10
|
2021-06-04 13:34:03 -04:00
|
|
|
|
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
|
|
|
|
2023-10-18 13:01:22 -04:00
|
|
|
width: itemRealWidth
|
|
|
|
|
2023-10-24 16:35:37 -04:00
|
|
|
contentItem: PushButton {
|
2020-08-03 13:27:42 -04:00
|
|
|
id: menuItemContentRect
|
|
|
|
|
2023-10-24 16:35:37 -04:00
|
|
|
enabled: isActif
|
|
|
|
hoverEnabled: isActif
|
2021-09-08 10:31:38 -04:00
|
|
|
|
2023-10-24 16:35:37 -04:00
|
|
|
hoveredColor: JamiTheme.hoverColor
|
|
|
|
normalColor: JamiTheme.primaryBackgroundColor
|
|
|
|
circled: false
|
|
|
|
radius: 5
|
2023-10-18 13:01:22 -04:00
|
|
|
|
2023-10-24 16:35:37 -04:00
|
|
|
//duration: 1000
|
|
|
|
anchors.leftMargin: 6
|
|
|
|
anchors.rightMargin: 6
|
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
|
|
|
|
2023-10-18 13:01:22 -04:00
|
|
|
color: menuItemContentRect.hovered ? JamiTheme.textColor : JamiTheme.chatViewFooterImgColor
|
2021-06-01 17:16:40 -04:00
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2023-10-18 13:01:22 -04:00
|
|
|
Item {
|
2021-06-01 17:16:40 -04:00
|
|
|
Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
|
2023-10-18 13:01:22 -04:00
|
|
|
Layout.leftMargin: contextMenuItemImage.status === Image.Ready ? itemTextMargin : itemTextMargin
|
|
|
|
Layout.rightMargin: contextMenuItemImage.status === Image.Ready ? itemImageLeftMargin : itemTextMargin
|
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
|
|
|
|
2023-10-18 13:01:22 -04:00
|
|
|
Text {
|
|
|
|
id: contextMenuItemText
|
2025-03-13 17:11:55 -04:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.left: parent.left
|
2023-10-18 13:01:22 -04:00
|
|
|
height: parent.height
|
|
|
|
text: itemName
|
2023-10-24 16:35:37 -04:00
|
|
|
color: dangerous ? JamiTheme.redColor : isActif ? JamiTheme.textColor : JamiTheme.chatViewFooterImgColor
|
2023-10-18 13:01:22 -04:00
|
|
|
font.pointSize: JamiTheme.textFontSize
|
|
|
|
horizontalAlignment: Text.AlignLeft
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
elide: Text.ElideRight
|
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
|
|
|
|
|
2023-10-18 13:01:22 -04:00
|
|
|
color: JamiTheme.primaryBackgroundColor
|
|
|
|
|
|
|
|
implicitWidth: itemRealWidth
|
2021-05-31 14:04:38 -04:00
|
|
|
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
|
2023-10-18 13:01:22 -04:00
|
|
|
borderColor: JamiTheme.primaryBackgroundColor
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|