Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019-2020 by Savoir-faire Linux |
| 3 | * Author: Yang Wang <yang.wang@savoirfairelinux.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | import QtQuick 2.15 |
| 20 | import QtQuick.Window 2.14 |
| 21 | import QtQuick.Controls 2.14 |
| 22 | import QtQuick.Layouts 1.14 |
| 23 | import QtQuick.Controls.Universal 2.12 |
| 24 | import QtGraphicalEffects 1.14 |
| 25 | |
| 26 | import "../../constant" |
| 27 | |
| 28 | Button { |
| 29 | id: button |
| 30 | checkable: true |
| 31 | hoverEnabled: true |
| 32 | |
| 33 | property alias imageSource: buttonPix.source |
| 34 | property alias buttonText: buttonText.text |
| 35 | |
| 36 | property string backgroundColor: JamiTheme.releaseColor |
| 37 | property string onPressColor: JamiTheme.pressColor |
| 38 | property string onReleaseColor: JamiTheme.releaseColor |
| 39 | property string onEnterColor: JamiTheme.hoverColor |
| 40 | property string onExitColor: JamiTheme.transparentColor |
| 41 | property string checkedColor: JamiTheme.releaseColor |
| 42 | |
| 43 | signal checkedToggledForLeftPanel(var checked) |
| 44 | signal checkedToggledForRightPanel(var checked) |
| 45 | |
| 46 | function setCheckedState(check, triggerSignal) { |
| 47 | button.checked = check |
| 48 | if (triggerSignal) { |
| 49 | checkedToggledForLeftPanel(check) |
| 50 | checkedToggledForRightPanel(check) |
| 51 | } |
| 52 | button.background.color = check ? button.checkedColor : button.onExitColor |
| 53 | } |
| 54 | |
| 55 | onClicked: { |
| 56 | setCheckedState(true, true) |
| 57 | } |
| 58 | |
| 59 | Layout.minimumHeight: 60 |
| 60 | Layout.preferredHeight: 60 |
| 61 | Layout.maximumHeight: 60 |
| 62 | |
| 63 | Layout.fillWidth: true |
| 64 | |
| 65 | background: Rectangle { |
| 66 | anchors.fill: parent |
| 67 | color: parent.checked ? button.checkedColor : button.onExitColor |
| 68 | |
| 69 | RowLayout { |
| 70 | anchors.fill: parent |
| 71 | spacing: 24 |
| 72 | Image { |
| 73 | id: buttonPix |
| 74 | Layout.minimumHeight: 24 |
| 75 | Layout.preferredHeight: 24 |
| 76 | Layout.maximumHeight: 24 |
| 77 | |
| 78 | Layout.minimumWidth: 24 |
| 79 | Layout.preferredWidth: 24 |
| 80 | Layout.maximumWidth: 24 |
| 81 | |
| 82 | Layout.leftMargin: 24 |
| 83 | |
| 84 | Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter |
| 85 | } |
| 86 | |
| 87 | Label { |
| 88 | id: buttonText |
| 89 | |
| 90 | Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter |
| 91 | |
| 92 | Layout.fillHeight: true |
| 93 | Layout.fillWidth: true |
| 94 | |
| 95 | font.pointSize: 11 |
| 96 | font.kerning: true |
| 97 | |
| 98 | horizontalAlignment: Text.AlignLeft |
| 99 | verticalAlignment: Text.AlignVCenter |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | MouseArea { |
| 104 | anchors.fill: parent |
| 105 | |
| 106 | hoverEnabled: true |
| 107 | |
| 108 | onPressed: { |
| 109 | if (!button.checked) { |
| 110 | parent.color = button.onPressColor |
| 111 | } |
| 112 | } |
| 113 | onReleased: { |
| 114 | button.clicked() |
| 115 | if (!button.checked) { |
| 116 | parent.color = button.onExitColor |
| 117 | } |
| 118 | } |
| 119 | onEntered: { |
| 120 | if (!button.checked) { |
| 121 | parent.color = button.onEnterColor |
| 122 | } |
| 123 | } |
| 124 | onExited: { |
| 125 | if (!button.checked) { |
| 126 | parent.color = button.onExitColor |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | } |