Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2020 by Savoir-faire Linux |
| 3 | * Author: Sébastien blin <sebastien.blin@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 <https://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | import QtQuick 2.14 |
| 20 | import QtQuick.Layouts 1.3 |
| 21 | import QtQuick.Controls 2.14 |
| 22 | import QtGraphicalEffects 1.15 |
| 23 | |
| 24 | Button { |
| 25 | id: root |
| 26 | |
| 27 | property alias source: root.icon.source |
| 28 | property string toolTipText: "" |
| 29 | property var color: "transparent" |
| 30 | property var outlined: false |
| 31 | |
| 32 | Layout.alignment: Qt.AlignCenter |
| 33 | Layout.preferredWidth: 400 |
| 34 | Layout.preferredHeight: 36 |
| 35 | |
| 36 | font.kerning: true |
| 37 | |
| 38 | icon.source: "" |
| 39 | icon.height: 18 |
| 40 | icon.width: 18 |
| 41 | |
| 42 | contentItem: Item { |
| 43 | Rectangle { |
| 44 | anchors.fill: parent |
| 45 | color: "transparent" |
| 46 | Image { |
| 47 | source: root.icon.source |
| 48 | width: root.icon.width |
| 49 | height: root.icon.height |
| 50 | anchors.verticalCenter: parent.verticalCenter |
| 51 | anchors.left: parent.left |
| 52 | anchors.leftMargin: 16 |
| 53 | layer { |
| 54 | enabled: true |
| 55 | effect: ColorOverlay { |
| 56 | id: overlay |
| 57 | color: outlined ? root.color : "white" |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | Text { |
| 62 | text: root.text |
| 63 | color: outlined? root.color : "white" |
| 64 | font: root.font |
| 65 | anchors.centerIn: parent |
| 66 | horizontalAlignment: Text.AlignHCenter |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval |
| 72 | ToolTip.visible: hovered && (toolTipText.length > 0) |
| 73 | ToolTip.text: toolTipText |
| 74 | |
| 75 | background: Rectangle { |
| 76 | id: backgroundRect |
| 77 | anchors.fill: parent |
| 78 | color: !outlined ? root.color : "transparent" |
| 79 | border.color: outlined ? root.color : "transparent" |
| 80 | radius: 4 |
| 81 | } |
| 82 | } |