aerothemeplasma/Plasma Widgets/SevenStart/contents/ui/CompactRepresentation.qml

141 lines
6 KiB
QML
Raw Normal View History

2021-07-16 19:33:52 +00:00
/***************************************************************************
* Copyright (C) 2013-2014 by Eike Hein <hein@kde.org> *
* *
* This program 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. *
* *
* This program 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, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
import QtQuick 2.0
import QtQuick.Layouts 1.1
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
Item {
id: root
readonly property var screenGeometry: plasmoid.screenGeometry
readonly property bool inPanel: (plasmoid.location == PlasmaCore.Types.TopEdge
|| plasmoid.location == PlasmaCore.Types.RightEdge
|| plasmoid.location == PlasmaCore.Types.BottomEdge
|| plasmoid.location == PlasmaCore.Types.LeftEdge)
readonly property bool vertical: (plasmoid.formFactor == PlasmaCore.Types.Vertical)
readonly property bool useCustomButtonImage: (plasmoid.configuration.useCustomButtonImage
&& plasmoid.configuration.customButtonImage.length != 0)
property QtObject dashWindow: null
Plasmoid.status: dashWindow && dashWindow.visible ? PlasmaCore.Types.RequiresAttentionStatus : PlasmaCore.Types.PassiveStatus
onWidthChanged: updateSizeHints()
onHeightChanged: updateSizeHints()
function updateSizeHints() {
if (useCustomButtonImage) {
if (vertical) {
var scaledHeight = Math.floor(parent.width * (buttonIcon.implicitHeight / buttonIcon.implicitWidth));
root.Layout.minimumHeight = scaledHeight;
root.Layout.maximumHeight = scaledHeight;
root.Layout.minimumWidth = units.iconSizes.small;
root.Layout.maximumWidth = inPanel ? units.iconSizeHints.panel : -1;
} else {
var scaledWidth = Math.floor(parent.height * (buttonIcon.implicitWidth / buttonIcon.implicitHeight));
root.Layout.minimumWidth = scaledWidth;
root.Layout.maximumWidth = scaledWidth;
root.Layout.minimumHeight = units.iconSizes.small;
root.Layout.maximumHeight = inPanel ? units.iconSizeHints.panel : -1;
}
} else {
root.Layout.minimumWidth = units.iconSizes.small;
root.Layout.maximumWidth = inPanel ? units.iconSizeHints.panel : -1;
root.Layout.minimumHeight = units.iconSizes.small
root.Layout.maximumHeight = inPanel ? units.iconSizeHints.panel : -1;
}
}
Connections {
target: units.iconSizeHints
onPanelChanged: updateSizeHints()
}
PlasmaCore.IconItem {
2021-07-25 11:04:28 +00:00
id: buttonIconHovered
z: 1
source: plasmoid.configuration.customButtonImageHover
2021-07-25 11:04:28 +00:00
opacity: 0
2021-07-16 19:33:52 +00:00
anchors.fill: parent
2021-07-25 11:04:28 +00:00
readonly property double aspectRatio: (vertical ? implicitHeight / implicitWidth
: implicitWidth / implicitHeight)
smooth: true
// A custom icon could also be rectangular. However, if a square, custom, icon is given, assume it
// to be an icon and round it to the nearest icon size again to avoid scaling artefacts.
roundToIconSize: !useCustomButtonImage || aspectRatio === 1
2021-07-16 19:33:52 +00:00
2021-07-25 11:04:28 +00:00
onSourceChanged: updateSizeHints()
}
PlasmaCore.IconItem {
id: buttonIcon
anchors.fill: parent
opacity: 1
2021-07-16 19:33:52 +00:00
readonly property double aspectRatio: (vertical ? implicitHeight / implicitWidth
: implicitWidth / implicitHeight)
2021-07-25 11:04:28 +00:00
//source: useCustomButtonImage ? plasmoid.configuration.customButtonImage : plasmoid.configuration.icon
source: dashWindow.visible ? plasmoid.configuration.customButtonImageActive : plasmoid.configuration.customButtonImage
2021-07-25 11:04:28 +00:00
states: State {
name: "mouse-over"; when: mouseArea.containsMouse && !dashWindow.visible
//PropertyChanges { target: buttonIcon; opacity: dashWindow.visible ? 1 : 0}
PropertyChanges { target: buttonIconHovered; opacity: dashWindow.visible ? 0 : 1}
}
2021-07-16 19:33:52 +00:00
2021-07-25 11:04:28 +00:00
transitions: Transition {
NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad; duration: 250 }
}
2021-07-16 19:33:52 +00:00
2021-07-25 11:04:28 +00:00
//active: mouseArea.containsMouse
2021-07-16 19:33:52 +00:00
smooth: true
// A custom icon could also be rectangular. However, if a square, custom, icon is given, assume it
// to be an icon and round it to the nearest icon size again to avoid scaling artefacts.
roundToIconSize: !useCustomButtonImage || aspectRatio === 1
onSourceChanged: updateSizeHints()
}
MouseArea
{
id: mouseArea
anchors.fill: parent
hoverEnabled: true
onClicked: {
dashWindow.visible = !dashWindow.visible;
}
}
Component.onCompleted: {
dashWindow = Qt.createQmlObject("MenuRepresentation {}", root);
plasmoid.activated.connect(function() {
dashWindow.visible = !dashWindow.visible;
});
}
}