1/* 2 * SPDX-FileCopyrightText: 2018 Friedrich W. H. Kossebau <kossebau@kde.org> 3 * 4 * SPDX-License-Identifier: GPL-2.0-or-later 5 */ 6 7import QtQuick 2.9 8 9import QtQuick.Layouts 1.3 10 11import org.kde.plasma.plasmoid 2.0 12import org.kde.plasma.core 2.0 as PlasmaCore 13 14ColumnLayout { 15 id: compactRoot 16 17 property var generalModel 18 property var observationModel 19 20 readonly property bool vertical: (plasmoid.formFactor == PlasmaCore.Types.Vertical) 21 readonly property bool showTemperature: plasmoid.nativeInterface.temperatureShownInCompactMode && 22 !plasmoid.nativeInterface.needsToBeSquare 23 24 Loader { 25 id: loader 26 27 sourceComponent: showTemperature ? iconAndTextComponent : iconComponent 28 Layout.fillWidth: compactRoot.vertical 29 Layout.fillHeight: !compactRoot.vertical 30 Layout.minimumWidth: item.Layout.minimumWidth 31 Layout.minimumHeight: item.Layout.minimumHeight 32 33 MouseArea { 34 id: compactMouseArea 35 anchors.fill: parent 36 37 hoverEnabled: true 38 39 onClicked: { 40 plasmoid.expanded = !plasmoid.expanded; 41 } 42 } 43 } 44 45 Component { 46 id: iconComponent 47 48 PlasmaCore.IconItem { 49 readonly property int minIconSize: Math.max((compactRoot.vertical ? compactRoot.width : compactRoot.height), PlasmaCore.Units.iconSizes.small) 50 51 source: generalModel.currentConditionIconName 52 active: compactMouseArea.containsMouse 53 // reset implicit size, so layout in free dimension does not stop at the default one 54 implicitWidth: PlasmaCore.Units.iconSizes.small 55 implicitHeight: PlasmaCore.Units.iconSizes.small 56 Layout.minimumWidth: compactRoot.vertical ? PlasmaCore.Units.iconSizes.small : minIconSize 57 Layout.minimumHeight: compactRoot.vertical ? minIconSize : PlasmaCore.Units.iconSizes.small 58 } 59 } 60 61 Component { 62 id: iconAndTextComponent 63 64 IconAndTextItem { 65 vertical: compactRoot.vertical 66 iconSource: generalModel.currentConditionIconName 67 active: compactMouseArea.containsMouse 68 text: observationModel.temperature 69 } 70 } 71} 72