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.Controls.Universal 2.12 |
| 23 | import QtQuick.Layouts 1.3 |
| 24 | import QtGraphicalEffects 1.14 |
| 25 | import QtQuick.Controls.Styles 1.4 |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 26 | import "../../commoncomponents" |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 27 | |
| 28 | RowLayout { |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 29 | property string labelText: "" |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 30 | property int widthOfSwitch: 50 |
| 31 | property int heightOfSwitch: 10 |
| 32 | property int heightOfLayout: 30 |
| 33 | property int fontPointSize: 13 |
| 34 | |
Yang Wang | b97bde4 | 2020-08-07 11:24:18 -0400 | [diff] [blame^] | 35 | property string tooltipText: "" |
| 36 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 37 | property alias toggleSwitch: switchOfLayout |
| 38 | property alias checked: switchOfLayout.checked |
| 39 | |
| 40 | signal switchToggled |
| 41 | |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 42 | spacing: 8 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 43 | Layout.fillWidth: true |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 44 | Layout.maximumHeight: 32 |
| 45 | |
| 46 | ElidedTextLabel { |
| 47 | Layout.fillWidth: true |
| 48 | |
| 49 | Layout.minimumHeight: heightOfLayout |
| 50 | Layout.preferredHeight: heightOfLayout |
| 51 | Layout.maximumHeight: heightOfLayout |
| 52 | |
| 53 | eText: qsTr(labelText) |
| 54 | fontSize: fontPointSize |
| 55 | maxWidth: parent.width - widthOfSwitch |
| 56 | |
| 57 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 58 | |
| 59 | Switch { |
| 60 | id: switchOfLayout |
ababi | 6fa0861 | 2020-08-10 19:13:28 +0200 | [diff] [blame] | 61 | Layout.alignment: Qt.AlignVCenter | Qt.AlignRight |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 62 | |
| 63 | Layout.maximumWidth: widthOfSwitch |
| 64 | Layout.preferredWidth: widthOfSwitch |
| 65 | Layout.minimumWidth: widthOfSwitch |
| 66 | |
| 67 | Layout.minimumHeight: heightOfSwitch |
| 68 | Layout.preferredHeight: heightOfSwitch |
| 69 | Layout.maximumHeight: heightOfSwitch |
| 70 | |
Yang Wang | b97bde4 | 2020-08-07 11:24:18 -0400 | [diff] [blame^] | 71 | hoverEnabled: true |
| 72 | ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval |
| 73 | ToolTip.visible: hovered && (tooltipText.length > 0) |
| 74 | ToolTip.text: tooltipText |
| 75 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 76 | onToggled: { |
| 77 | switchToggled() |
| 78 | } |
| 79 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 80 | } |