2018-12-31 18:45:40 +03:00
/ *
* Copyright 2019 Michail Vourlakos < mvourlakos @ gmail . com >
*
* This file is part of Latte - Dock
*
* Latte - Dock is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation ; either version 2 of
* the License , or ( at your option ) any later version .
*
* Latte - Dock is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http: //www.gnu.org/licenses/>.
* /
import QtQuick 2.7
import QtGraphicalEffects 1.0
import QtQuick . Controls 1.4
import QtQuick . Layouts 1.3
import org . kde . plasma . core 2.0 as PlasmaCore
import org . kde . plasma . components 2.0 as PlasmaComponents
import org . kde . plasma . plasmoid 2.0
import "." as LatteExtraControls
import "private" as Private
Item {
id: item
2019-03-27 02:50:55 +03:00
Layout.rightMargin: {
if ( level === 1 ) {
return Qt . application . layoutDirection === Qt . RightToLeft ? 0 : 2 * units . smallSpacing
}
return 0 ;
}
Layout.leftMargin: {
if ( level === 1 ) {
return Qt . application . layoutDirection === Qt . RightToLeft ? 2 * units.smallSpacing : 0
}
return 0 ;
}
2019-02-17 20:25:58 +03:00
property int level: 1
2018-12-31 18:45:40 +03:00
property bool checked: false
2019-03-27 02:50:55 +03:00
property bool isFirstSubCategory: false
2018-12-31 18:45:40 +03:00
2019-02-17 20:25:58 +03:00
readonly property int implicitWidth: row . width
readonly property int implicitHeight: {
if ( level === 1 ) {
return Math . max ( headerText . implicitHeight , itemSwitch . implicitHeight ) ;
} else if ( level === 2 ) {
return Math . max ( subHeaderText . implicitHeight , itemSwitch . implicitHeight )
}
return Math . max ( labelText . implicitHeight , itemSwitch . implicitHeight ) ;
}
2018-12-31 18:45:40 +03:00
property string text: ""
property string tooltip: ""
signal pressed ( ) ;
2019-04-04 14:41:16 +03:00
Item {
2018-12-31 18:45:40 +03:00
id: row
2019-01-01 15:14:24 +03:00
width: parent . width
2019-04-04 14:41:16 +03:00
height: textElement . height
2019-01-01 15:14:24 +03:00
anchors.verticalCenter: parent . verticalCenter
2018-12-31 18:45:40 +03:00
2019-04-04 14:41:16 +03:00
RowLayout {
id: textElement
anchors.left: level !== 2 ? parent.left : undefined
anchors.horizontalCenter: level === 2 ? parent.horizontalCenter : undefined
anchors.verticalCenter: parent . verticalCenter
LatteExtraControls . Header {
id: headerText
text: item . text
2019-05-01 19:22:39 +03:00
enabled: item . checked && item . enabled
2019-04-04 14:41:16 +03:00
visible: level === 1
}
LatteExtraControls . SubHeader {
id: subHeaderText
text: item . text
2019-05-01 19:22:39 +03:00
enabled: item . checked && item . enabled
2019-04-04 14:41:16 +03:00
visible: level === 2
isFirstSubCategory: item . isFirstSubCategory
}
PlasmaComponents . Label {
id: labelText
text: item . text
2019-05-01 19:22:39 +03:00
enabled: item . checked && item . enabled
2019-04-04 14:41:16 +03:00
visible: level > 2
}
2019-02-17 20:25:58 +03:00
}
2019-04-10 02:54:14 +03:00
PlasmaComponents . Button {
//tooltip ghost
2019-04-12 00:08:09 +03:00
anchors.fill: textElement
2019-04-10 02:54:14 +03:00
tooltip: item . tooltip
opacity: 0
2019-04-12 00:08:09 +03:00
onPressedChanged: {
if ( pressed ) {
item . pressed ( ) ;
}
}
2018-12-31 18:45:40 +03:00
}
2019-02-17 20:25:58 +03:00
}
2018-12-31 18:45:40 +03:00
2019-02-17 20:25:58 +03:00
Switch {
id: itemSwitch
anchors.verticalCenter: row . verticalCenter
anchors.right: row . right
checked: item . checked
2019-05-01 19:22:39 +03:00
enabled: item . enabled
2018-12-31 18:45:40 +03:00
2019-02-17 20:25:58 +03:00
style: Private . SwitchStyle { }
2018-12-31 18:45:40 +03:00
2019-04-10 02:54:14 +03:00
PlasmaComponents . Button {
//tooltip ghost
2019-04-04 14:41:16 +03:00
anchors.fill: parent
2019-04-10 02:54:14 +03:00
tooltip: item . tooltip
opacity: 0
2019-04-12 00:08:09 +03:00
onPressedChanged: {
if ( pressed ) {
item . pressed ( ) ;
}
}
2019-04-04 14:41:16 +03:00
}
2018-12-31 18:45:40 +03:00
}
}