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
|
2020-08-03 13:27:42 -04:00
|
|
|
import net.jami.Models 1.0
|
|
|
|
|
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: ""
|
|
|
|
property string iconSource: ""
|
2020-07-30 13:38:57 +02:00
|
|
|
property int preferredWidth: 220
|
|
|
|
property int preferredHeight: 48
|
2020-08-27 12:59:09 -04:00
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
property int leftBorderWidth: 0
|
|
|
|
property int rightBorderWidth: 0
|
|
|
|
|
|
|
|
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
|
2020-10-08 18:44:10 -04:00
|
|
|
ResponsiveImage {
|
2020-08-03 13:27:42 -04:00
|
|
|
id: contextMenuItemImage
|
|
|
|
|
|
|
|
anchors.left: menuItemContentRect.left
|
2020-07-30 13:38:57 +02:00
|
|
|
anchors.leftMargin: (visible ? 24 : 0)
|
2020-08-03 13:27:42 -04:00
|
|
|
anchors.verticalCenter: menuItemContentRect.verticalCenter
|
|
|
|
|
2020-07-30 13:38:57 +02:00
|
|
|
width: (visible ? 24 : 0)
|
|
|
|
height: (visible ? 24 : 0)
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
visible: false
|
2020-07-30 13:38:57 +02:00
|
|
|
opacity: 0.7
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Text {
|
|
|
|
id: contextMenuItemText
|
|
|
|
|
|
|
|
anchors.left: contextMenuItemImage.right
|
2020-07-30 13:38:57 +02:00
|
|
|
anchors.leftMargin: 20
|
2020-08-03 13:27:42 -04:00
|
|
|
anchors.verticalCenter: menuItemContentRect.verticalCenter
|
2020-09-24 16:50:00 +02:00
|
|
|
width: contextMenuItemImage.visible ?
|
|
|
|
(preferredWidth - contextMenuItemImage.width - 58) :
|
|
|
|
preferredWidth - 24
|
2020-08-03 13:27:42 -04:00
|
|
|
height: 30
|
|
|
|
|
2020-09-24 16:50:00 +02:00
|
|
|
text: itemName
|
|
|
|
wrapMode: Text.WordWrap
|
2020-07-30 13:38:57 +02:00
|
|
|
font.pointSize: JamiTheme.textFontSize
|
2020-08-03 13:27:42 -04:00
|
|
|
horizontalAlignment: Text.AlignLeft
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
}
|
|
|
|
|
2020-10-09 17:59:07 -04:00
|
|
|
onReleased: menuItem.clicked()
|
|
|
|
|
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: "hovered"; when: hovered
|
|
|
|
PropertyChanges { target: background; color: JamiTheme.hoverColor }
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "normal"; when: !hovered
|
|
|
|
PropertyChanges { target: background; color: "white" }
|
|
|
|
}
|
|
|
|
]
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
onIconSourceChanged: {
|
|
|
|
if (iconSource !== "") {
|
|
|
|
contextMenuItemImage.source = iconSource
|
|
|
|
contextMenuItemImage.visible = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
|
implicitWidth: preferredWidth
|
|
|
|
implicitHeight: preferredHeight
|
|
|
|
|
|
|
|
border.width: 0
|
2020-09-28 18:59:40 -04:00
|
|
|
color: menuItem.down ? JamiTheme.normalButtonColor : "white"
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|