From 55532aad73e1aba36a15524207df2a6e0931260a Mon Sep 17 00:00:00 2001 From: ivan tkachenko Date: Wed, 13 Jul 2022 11:22:04 +0300 Subject: [PATCH] [applet/{analog,digital}-clock] Merge roots of full representations with MouseArea --- .../analog-clock/contents/ui/analogclock.qml | 13 ++-- .../package/contents/ui/DigitalClock.qml | 70 +++++++++---------- 2 files changed, 37 insertions(+), 46 deletions(-) diff --git a/applets/analog-clock/contents/ui/analogclock.qml b/applets/analog-clock/contents/ui/analogclock.qml index 3ff2a9d8e..6603b7918 100644 --- a/applets/analog-clock/contents/ui/analogclock.qml +++ b/applets/analog-clock/contents/ui/analogclock.qml @@ -67,20 +67,15 @@ Item { dataSource.onDataChanged.connect(dateTimeChanged); } - Plasmoid.compactRepresentation: Item { + Plasmoid.compactRepresentation: MouseArea { id: representation Layout.minimumWidth: Plasmoid.formFactor !== PlasmaCore.Types.Vertical ? representation.height : PlasmaCore.Units.gridUnit Layout.minimumHeight: Plasmoid.formFactor === PlasmaCore.Types.Vertical ? representation.width : PlasmaCore.Units.gridUnit - MouseArea { - anchors.fill: parent - - property bool wasExpanded - - onPressed: wasExpanded = Plasmoid.expanded - onClicked: Plasmoid.expanded = !wasExpanded - } + property bool wasExpanded + onPressed: wasExpanded = Plasmoid.expanded + onClicked: Plasmoid.expanded = !wasExpanded PlasmaCore.Svg { id: clockSvg diff --git a/applets/digital-clock/package/contents/ui/DigitalClock.qml b/applets/digital-clock/package/contents/ui/DigitalClock.qml index bf611b546..9ab4a6670 100644 --- a/applets/digital-clock/package/contents/ui/DigitalClock.qml +++ b/applets/digital-clock/package/contents/ui/DigitalClock.qml @@ -14,7 +14,7 @@ import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as Components // Date label height breaks on vertical panel with PC3 version import org.kde.plasma.private.digitalclock 1.0 -Item { +MouseArea { id: main property string timeFormat @@ -61,6 +61,9 @@ Item { } } + property bool wasExpanded + property int wheelDelta: 0 + onDateFormatChanged: { setupLabels(); } @@ -433,46 +436,39 @@ Item { } ] - MouseArea { - anchors.fill: parent - - property bool wasExpanded - property int wheelDelta: 0 - - onPressed: wasExpanded = Plasmoid.expanded - onClicked: Plasmoid.expanded = !wasExpanded - onWheel: { - if (!Plasmoid.configuration.wheelChangesTimezone) { - return; - } + onPressed: wasExpanded = Plasmoid.expanded + onClicked: Plasmoid.expanded = !wasExpanded + onWheel: { + if (!Plasmoid.configuration.wheelChangesTimezone) { + return; + } - var delta = wheel.angleDelta.y || wheel.angleDelta.x - var newIndex = main.tzIndex; - wheelDelta += delta; - // magic number 120 for common "one click" - // See: https://doc.qt.io/qt-5/qml-qtquick-wheelevent.html#angleDelta-prop - while (wheelDelta >= 120) { - wheelDelta -= 120; - newIndex--; - } - while (wheelDelta <= -120) { - wheelDelta += 120; - newIndex++; - } + var delta = wheel.angleDelta.y || wheel.angleDelta.x + var newIndex = main.tzIndex; + wheelDelta += delta; + // magic number 120 for common "one click" + // See: https://doc.qt.io/qt-5/qml-qtquick-wheelevent.html#angleDelta-prop + while (wheelDelta >= 120) { + wheelDelta -= 120; + newIndex--; + } + while (wheelDelta <= -120) { + wheelDelta += 120; + newIndex++; + } - if (newIndex >= Plasmoid.configuration.selectedTimeZones.length) { - newIndex = 0; - } else if (newIndex < 0) { - newIndex = Plasmoid.configuration.selectedTimeZones.length - 1; - } + if (newIndex >= Plasmoid.configuration.selectedTimeZones.length) { + newIndex = 0; + } else if (newIndex < 0) { + newIndex = Plasmoid.configuration.selectedTimeZones.length - 1; + } - if (newIndex !== main.tzIndex) { - Plasmoid.configuration.lastSelectedTimezone = Plasmoid.configuration.selectedTimeZones[newIndex]; - main.tzIndex = newIndex; + if (newIndex !== main.tzIndex) { + Plasmoid.configuration.lastSelectedTimezone = Plasmoid.configuration.selectedTimeZones[newIndex]; + main.tzIndex = newIndex; - dataSource.dataChanged(); - setupLabels(); - } + dataSource.dataChanged(); + setupLabels(); } }