Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 1 |
|
| 2 | /*
|
| 3 | * Copyright (C) 2020 by Savoir-faire Linux
|
| 4 | * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
|
| 5 | *
|
| 6 | * This program is free software; you can redistribute it and/or modify
|
| 7 | * it under the terms of the GNU General Public License as published by
|
| 8 | * the Free Software Foundation; either version 3 of the License, or
|
| 9 | * (at your option) any later version.
|
| 10 | *
|
| 11 | * This program is distributed in the hope that it will be useful,
|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 | * GNU General Public License for more details.
|
| 15 | *
|
| 16 | * You should have received a copy of the GNU General Public License
|
| 17 | * along with this program. If not, see <https://www.gnu.org/licenses/>.
|
| 18 | */
|
| 19 | import QtQuick 2.15
|
| 20 | import QtQuick.Controls 2.14
|
| 21 | import net.jami.Models 1.0
|
| 22 |
|
| 23 |
|
| 24 | /*
|
| 25 | * HoverableButton contains the following configurable properties:
|
| 26 | * 1. Color changes on different button state
|
| 27 | * 2. Radius control (rounded)
|
| 28 | * 3. Text content or image content
|
| 29 | * 4. Can use OnClicked slot to implement some click logic
|
| 30 | */
|
| 31 | Button {
|
| 32 | id: hoverableButton
|
| 33 | property int fontPointSize: 9
|
| 34 | property int buttonImageHeight: hoverableButtonBackground.height - 10
|
| 35 | property int buttonImageWidth: hoverableButtonBackground.width - 10
|
| 36 | property string backgroundColor: JamiTheme.releaseColor
|
| 37 | property string onPressColor: JamiTheme.pressColor
|
| 38 | property string onReleaseColor: backgroundColor
|
| 39 | property string onEnterColor: JamiTheme.hoverColor
|
| 40 | property string onExitColor: backgroundColor
|
| 41 | property alias radius: hoverableButtonBackground.radius
|
| 42 | property alias source: hoverableButtonImage.source
|
Yang Wang | b97bde4 | 2020-08-07 11:24:18 -0400 | [diff] [blame] | 43 | property string toolTipText: ""
|
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 44 | radius: height / 2
|
| 45 | function enterBtn(){
|
| 46 | btnMouseArea.entered()
|
| 47 | }
|
| 48 | function exitBtn(){
|
| 49 | btnMouseArea.exited()
|
| 50 | }
|
| 51 | function pressBtn(){
|
| 52 | btnMouseArea.pressed()
|
| 53 | }
|
| 54 | function releaseBtn(){
|
| 55 | btnMouseArea.released()
|
| 56 | }
|
Yang Wang | b97bde4 | 2020-08-07 11:24:18 -0400 | [diff] [blame] | 57 |
|
| 58 | ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
|
| 59 | ToolTip.visible: hovered && (toolTipText.length > 0)
|
| 60 | ToolTip.text: toolTipText
|
| 61 |
|
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 62 | font.pointSize: fontPointSize
|
| 63 | font.kerning: true
|
| 64 | hoverEnabled: true
|
| 65 | background: Rectangle {
|
| 66 | id: hoverableButtonBackground
|
| 67 | color: backgroundColor
|
| 68 | Image {
|
| 69 | id: hoverableButtonImage
|
| 70 | anchors.centerIn: hoverableButtonBackground
|
| 71 | height: buttonImageHeight
|
| 72 | width: buttonImageWidth
|
| 73 | fillMode: Image.PreserveAspectFit
|
| 74 | mipmap: true
|
| 75 | asynchronous: true
|
| 76 | }
|
| 77 | MouseArea {
|
| 78 | id: btnMouseArea
|
| 79 | anchors.fill: parent
|
| 80 | hoverEnabled: true
|
| 81 | onPressed: {
|
| 82 | hoverableButtonBackground.color = onPressColor
|
| 83 | }
|
| 84 | onReleased: {
|
| 85 | hoverableButtonBackground.color = onReleaseColor
|
| 86 | hoverableButton.clicked()
|
| 87 | }
|
| 88 | onEntered: {
|
| 89 | hoverableButtonBackground.color = onEnterColor
|
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 90 | }
|
| 91 | onExited: {
|
| 92 | hoverableButtonBackground.color = onExitColor
|
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 93 | }
|
| 94 | }
|
| 95 | }
|
| 96 | }
|