diff --git a/applets/kicker/package/contents/ui/CompactRepresentation.qml b/applets/kicker/package/contents/ui/CompactRepresentation.qml index ed4c4e52a..592ebbe6f 100644 --- a/applets/kicker/package/contents/ui/CompactRepresentation.qml +++ b/applets/kicker/package/contents/ui/CompactRepresentation.qml @@ -1,146 +1,116 @@ /*************************************************************************** * Copyright (C) 2013-2014 by Eike Hein * * * * 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.core 2.0 as PlasmaCore Item { id: root - property bool vertical: (plasmoid.formFactor == PlasmaCore.Types.Vertical) + 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 + onWidthChanged: updateSizeHints() + onHeightChanged: updateSizeHints() + onDashWindowChanged: { if (dashWindow) { dashWindow.visualParent = root; } } - PlasmaCore.IconItem { - id: buttonIcon - - anchors.fill: parent - - visible: !(plasmoid.configuration.useCustomButtonImage && plasmoid.configuration.customButtonImage) - - source: plasmoid.configuration.icon - active: mouseArea.containsMouse && !justOpenedTimer.running - - onWidthChanged: { - if (vertical && visible) { + 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.minimumHeight = parent.width; - } - } - - onHeightChanged: { - if (!vertical && visible) { - root.Layout.minimumWidth = parent.height; + root.Layout.maximumWidth = undefined; + } 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 = undefined; } - } - - onVisibleChanged: { - if (visible) { - if (vertical) { - root.Layout.minimumWidth = units.iconSizes.small; - root.Layout.minimumHeight = units.iconSizes.small; - } else { - root.Layout.minimumWidth = parent.height; - root.Layout.minimumHeight = units.iconSizes.small; - } - } + } else { + root.Layout.minimumWidth = units.iconSizes.small; + root.Layout.maximumWidth = undefined; + root.Layout.minimumHeight = units.iconSizes.small + root.Layout.maximumHeight = undefined; } } - Image { - id: buttonImage + PlasmaCore.IconItem { + id: buttonIcon - width: vertical ? parent.width : undefined - height: vertical ? undefined : parent.height + anchors.fill: parent - onPaintedWidthChanged: { - if (!vertical && visible) { - root.Layout.minimumWidth = paintedWidth; - root.Layout.minimumHeight = units.iconSizes.small; - } - } + readonly property double aspectRatio: (vertical ? implicitHeight / implicitWidth + : implicitWidth / implicitHeight) - onPaintedHeightChanged: { - if (vertical && visible) { - root.Layout.minimumWidth = units.iconSizes.small; - root.Layout.minimumHeight = paintedHeight; - } - } + source: useCustomButtonImage ? plasmoid.configuration.customButtonImage : plasmoid.configuration.icon - onVisibleChanged: { - if (visible) { - if (vertical) { - root.Layout.minimumWidth = units.iconSizes.small; - root.Layout.minimumHeight = paintedHeight; - } else { - root.Layout.minimumWidth = paintedWidth; - root.Layout.minimumHeight = units.iconSizes.small; - } - } - } + active: mouseArea.containsMouse && !justOpenedTimer.running + + roundToIconSize: !useCustomButtonImage - visible: plasmoid.configuration.useCustomButtonImage && (plasmoid.configuration.customButtonImage != "") - source: plasmoid.configuration.customButtonImage - fillMode: Image.PreserveAspectFit - smooth: true + onSourceChanged: updateSizeHints() } MouseArea { id: mouseArea property bool wasExpanded: false; anchors.fill: parent hoverEnabled: !dashWindow || !dashWindow.visible onPressed: { if (!isDash) { wasExpanded = plasmoid.expanded } } onClicked: { if (isDash) { dashWindow.toggle(); justOpenedTimer.start(); } else { plasmoid.expanded = !wasExpanded; } } } Component.onCompleted: { if (isDash) { dashWindow = Qt.createQmlObject("DashboardRepresentation {}", root); plasmoid.activated.connect(function() { dashWindow.toggle() justOpenedTimer.start() }) } } }