Warning, /plasma/latte-dock/declarativeimports/components/HeaderSwitch.qml is written in an unsupported language. File is not indexed.

0001 /*
0002 *  Copyright 2019  Michail Vourlakos <mvourlakos@gmail.com>
0003 *
0004 *  This file is part of Latte-Dock
0005 *
0006 *  Latte-Dock is free software; you can redistribute it and/or
0007 *  modify it under the terms of the GNU General Public License as
0008 *  published by the Free Software Foundation; either version 2 of
0009 *  the License, or (at your option) any later version.
0010 *
0011 *  Latte-Dock is distributed in the hope that it will be useful,
0012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 *  GNU General Public License for more details.
0015 *
0016 *  You should have received a copy of the GNU General Public License
0017 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018 */
0019 
0020 import QtQuick 2.7
0021 import QtGraphicalEffects 1.0
0022 import QtQuick.Controls 1.4
0023 import QtQuick.Layouts 1.3
0024 
0025 import org.kde.plasma.core 2.0 as PlasmaCore
0026 import org.kde.plasma.components 2.0 as PlasmaComponents
0027 
0028 import org.kde.plasma.plasmoid 2.0
0029 
0030 import org.kde.latte 0.2 as Latte
0031 
0032 import "." as LatteExtraControls
0033 
0034 import "private" as Private
0035 
0036 Item {
0037     id: item
0038 
0039     Layout.rightMargin: {
0040         if (level === 1) {
0041             return Qt.application.layoutDirection === Qt.RightToLeft ? 0 : 2 * units.smallSpacing
0042         }
0043 
0044         return 0;
0045     }
0046     Layout.leftMargin: {
0047         if (level === 1) {
0048             return Qt.application.layoutDirection === Qt.RightToLeft ? 2 * units.smallSpacing : 0
0049         }
0050 
0051         return 0;
0052     }
0053 
0054     property int level:1
0055     property bool checked: false
0056     property bool isFirstSubCategory: false
0057 
0058     readonly property int implicitWidth: row.width
0059 
0060     readonly property int implicitHeight: {
0061         if (level === 1) {
0062             return Math.max(headerText.implicitHeight, itemSwitch.implicitHeight);
0063         } else if (level === 2) {
0064             return Math.max(subHeaderText.implicitHeight, itemSwitch.implicitHeight)
0065         }
0066 
0067         return Math.max(labelText.implicitHeight, itemSwitch.implicitHeight);
0068     }
0069 
0070     property string text:""
0071     property string tooltip:""
0072 
0073     signal pressed();
0074 
0075     Item {
0076         id: row
0077         width: parent.width
0078         height: textElement.height
0079         anchors.verticalCenter: parent.verticalCenter
0080 
0081         RowLayout {
0082             id: textElement
0083             anchors.left: level !== 2 ? parent.left : undefined
0084             anchors.horizontalCenter: level === 2 ? parent.horizontalCenter : undefined
0085             anchors.verticalCenter: parent.verticalCenter
0086 
0087             LatteExtraControls.Header {
0088                 id: headerText
0089                 text: item.text
0090                 enabled: item.checked && item.enabled
0091                 visible: level === 1
0092             }
0093 
0094             LatteExtraControls.SubHeader {
0095                 id: subHeaderText
0096                 text: item.text
0097                 enabled: item.checked && item.enabled
0098                 visible: level === 2
0099                 isFirstSubCategory: item.isFirstSubCategory
0100             }
0101 
0102             PlasmaComponents.Label {
0103                 id: labelText
0104                 text: item.text
0105                 enabled: item.checked && item.enabled
0106                 visible: level > 2
0107             }
0108         }
0109 
0110         PlasmaComponents.Button {
0111             //tooltip ghost
0112             anchors.fill: textElement
0113             tooltip: item.tooltip
0114             opacity: 0
0115             onPressedChanged: {
0116                 if (pressed) {
0117                     item.pressed();
0118                 }
0119             }
0120         }
0121     }
0122 
0123     Switch {
0124         id: itemSwitch
0125         anchors.verticalCenter: row.verticalCenter
0126         anchors.right: row.right
0127         checked: item.checked
0128         enabled: item.enabled
0129 
0130         style: Private.SwitchStyle {}
0131 
0132         PlasmaComponents.Button {
0133             //tooltip ghost
0134             anchors.fill: parent
0135             tooltip: item.tooltip
0136             opacity: 0
0137             onPressedChanged: {
0138                 if (pressed) {
0139                     item.pressed();
0140                 }
0141             }
0142         }
0143     }
0144 }