Verified Commit 53b86a50 authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

applets/analog-clock: follow Plasma QML style

parent 0df153f3
Pipeline #208072 passed with stage
in 12 minutes and 43 seconds
......@@ -7,18 +7,20 @@
*/
import QtQuick 2.0
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.workspace.calendar 2.0 as PlasmaCalendar
import QtQuick.Layouts 1.1
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.plasma.workspace.calendar 2.0 as PlasmaCalendar
Item {
id: analogclock
width: PlasmaCore.Units.gridUnit * 15
height: PlasmaCore.Units.gridUnit * 15
property int hours
property int minutes
property int seconds
......@@ -33,6 +35,14 @@ Item {
Plasmoid.toolTipSubText: Qt.formatTime(dataSource.data["Local"]["DateTime"], Qt.locale().timeFormat(Locale.LongFormat)) + "\n" +
Qt.formatDate(dataSource.data["Local"]["DateTime"], Qt.locale().dateFormat(Locale.LongFormat).replace(/(^dddd.?\s)|(,?\sdddd$)/, ""))
function dateTimeChanged() {
var currentTZOffset = dataSource.data["Local"]["Offset"] / 60;
if (currentTZOffset !== tzOffset) {
tzOffset = currentTZOffset;
Date.timeZoneUpdated(); // inform the QML JS engine about TZ change
}
}
PlasmaCore.DataSource {
id: dataSource
engine: "time"
......@@ -49,24 +59,6 @@ Item {
}
}
function dateTimeChanged()
{
//console.log("Date/time changed!");
var currentTZOffset = dataSource.data["Local"]["Offset"] / 60;
if (currentTZOffset !== tzOffset) {
tzOffset = currentTZOffset;
//console.log("TZ offset changed: " + tzOffset);
Date.timeZoneUpdated(); // inform the QML JS engine about TZ change
}
}
Component.onCompleted: {
tzOffset = new Date().getTimezoneOffset();
//console.log("Initial TZ offset: " + tzOffset);
dataSource.onDataChanged.connect(dateTimeChanged);
}
Plasmoid.compactRepresentation: MouseArea {
id: representation
......@@ -80,6 +72,10 @@ Item {
PlasmaCore.Svg {
id: clockSvg
property double naturalHorizontalHandShadowOffset: estimateHorizontalHandShadowOffset()
property double naturalVerticalHandShadowOffset: estimateVerticalHandShadowOffset()
imagePath: "widgets/clock"
function estimateHorizontalHandShadowOffset() {
var id = "hint-hands-shadow-offset-to-west";
......@@ -103,8 +99,7 @@ Item {
}
return 0;
}
property double naturalHorizontalHandShadowOffset: estimateHorizontalHandShadowOffset()
property double naturalVerticalHandShadowOffset: estimateVerticalHandShadowOffset()
onRepaintNeeded: {
naturalHorizontalHandShadowOffset = estimateHorizontalHandShadowOffset();
naturalVerticalHandShadowOffset = estimateVerticalHandShadowOffset();
......@@ -113,11 +108,13 @@ Item {
Item {
id: clock
width: parent.width
anchors {
top: parent.top
bottom: showTimezone ? timezoneBg.top : parent.bottom
}
width: parent.width
readonly property double svgScale: face.width / face.naturalSize.width
readonly property double horizontalShadowOffset:
Math.round(clockSvg.naturalHorizontalHandShadowOffset * svgScale) + Math.round(clockSvg.naturalHorizontalHandShadowOffset * svgScale) % 2
......@@ -165,27 +162,27 @@ Item {
}
Hand {
visible: showSecondsHand
elementId: "SecondHandShadow"
rotationCenterHintId: "hint-secondhandshadow-rotation-center-offset"
horizontalRotationOffset: clock.horizontalShadowOffset
verticalRotationOffset: clock.verticalShadowOffset
rotation: 180 + seconds * 6
visible: showSecondsHand
svgScale: clock.svgScale
}
Hand {
visible: showSecondsHand
elementId: "SecondHand"
rotationCenterHintId: "hint-secondhand-rotation-center-offset"
rotation: 180 + seconds * 6
visible: showSecondsHand
svgScale: clock.svgScale
}
PlasmaCore.SvgItem {
id: center
anchors.centerIn: clock
width: naturalSize.width * clock.svgScale
height: naturalSize.height * clock.svgScale
anchors.centerIn: clock
svg: clockSvg
elementId: "HandCenterScrew"
z: 1000
......@@ -193,24 +190,27 @@ Item {
PlasmaCore.SvgItem {
anchors.fill: face
svg: clockSvg
elementId: "Glass"
width: naturalSize.width * clock.svgScale
height: naturalSize.height * clock.svgScale
svg: clockSvg
elementId: "Glass"
}
}
PlasmaCore.FrameSvgItem {
id: timezoneBg
anchors {
horizontalCenter: parent.horizontalCenter
bottom: parent.bottom
bottomMargin: 10
}
imagePath: "widgets/background"
width: childrenRect.width + margins.right + margins.left
height: childrenRect.height + margins.top + margins.bottom
visible: showTimezone
imagePath: "widgets/background"
PlasmaComponents.Label {
id: timezoneText
x: timezoneBg.margins.left
......@@ -221,13 +221,18 @@ Item {
}
Plasmoid.fullRepresentation: PlasmaCalendar.MonthView {
readonly property var appletInterface: Plasmoid.self
Layout.minimumWidth: PlasmaCore.Units.gridUnit * 22
Layout.maximumWidth: PlasmaCore.Units.gridUnit * 80
Layout.minimumHeight: PlasmaCore.Units.gridUnit * 22
Layout.maximumHeight: PlasmaCore.Units.gridUnit * 40
readonly property var appletInterface: Plasmoid.self
today: dataSource.data["Local"]["DateTime"]
}
Component.onCompleted: {
tzOffset = new Date().getTimezoneOffset();
dataSource.onDataChanged.connect(dateTimeChanged);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment