blob: cd4f5a4496e27af3f63be25e2e49bc707ac34685 [file] [log] [blame]
Sébastien Blin1f915762020-08-03 13:27:42 -04001/*
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
19import QtQuick 2.15
20import QtQuick.Window 2.14
21import QtQuick.Controls 2.14
22import QtQuick.Controls.Universal 2.12
23import QtQuick.Layouts 1.3
24import QtGraphicalEffects 1.14
25import QtQuick.Controls.Styles 1.4
ababi6fa08612020-08-10 19:13:28 +020026import "../../commoncomponents"
Sébastien Blin1f915762020-08-03 13:27:42 -040027
28RowLayout {
ababi6fa08612020-08-10 19:13:28 +020029 property string labelText: ""
Sébastien Blin1f915762020-08-03 13:27:42 -040030 property int widthOfSwitch: 50
31 property int heightOfSwitch: 10
32 property int heightOfLayout: 30
33 property int fontPointSize: 13
34
Yang Wangb97bde42020-08-07 11:24:18 -040035 property string tooltipText: ""
36
Sébastien Blin1f915762020-08-03 13:27:42 -040037 property alias toggleSwitch: switchOfLayout
38 property alias checked: switchOfLayout.checked
39
40 signal switchToggled
41
ababi6fa08612020-08-10 19:13:28 +020042 spacing: 8
Sébastien Blin1f915762020-08-03 13:27:42 -040043 Layout.fillWidth: true
ababi6fa08612020-08-10 19:13:28 +020044 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 Blin1f915762020-08-03 13:27:42 -040058
59 Switch {
60 id: switchOfLayout
ababi6fa08612020-08-10 19:13:28 +020061 Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
Sébastien Blin1f915762020-08-03 13:27:42 -040062
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 Wangb97bde42020-08-07 11:24:18 -040071 hoverEnabled: true
72 ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
73 ToolTip.visible: hovered && (tooltipText.length > 0)
74 ToolTip.text: tooltipText
75
Sébastien Blin1f915762020-08-03 13:27:42 -040076 onToggled: {
77 switchToggled()
78 }
79 }
Sébastien Blin1f915762020-08-03 13:27:42 -040080}