Warning, /plasma/plasma-sdk/themeexplorer/package/contents/ui/delegates/clock.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *   SPDX-FileCopyrightText: 2012 Viranch Mehta <viranch.mehta@gmail.com>
0003  *   SPDX-FileCopyrightText: 2012 Marco Martin <mart@kde.org>
0004  *   SPDX-FileCopyrightText: 2013 David Edmundson <davidedmundson@kde.org>
0005  *
0006  *   SPDX-License-Identifier: LGPL-2.0-or-later
0007  */
0008 
0009 import QtQuick 2.0
0010 import QtQuick.Layouts 1.1
0011 
0012 import org.kde.plasma.core as PlasmaCore
0013 import org.kde.ksvg 1.0 as KSvg
0014 
0015 Item {
0016     id: analogclock
0017 
0018     width: units.gridUnit * 15
0019     height: units.gridUnit * 15
0020     property int hours
0021     property int minutes
0022     property int seconds
0023     property bool showSecondsHand: true
0024 
0025  
0026     PlasmaCore.DataSource {
0027         id: dataSource
0028         engine: "time"
0029         connectedSources: "Local"
0030         interval: showSecondsHand ? 1000 : 30000
0031         onDataChanged: {
0032             var date = new Date(data["Local"]["DateTime"]);
0033             hours = date.getHours();
0034             minutes = date.getMinutes();
0035             seconds = date.getSeconds();
0036         }
0037         Component.onCompleted: {
0038             onDataChanged();
0039         }
0040     }
0041 
0042 
0043     Component.onCompleted: {
0044         dataSource.onDataChanged.connect(dateTimeChanged);
0045     }
0046 
0047 
0048     KSvg.Svg {
0049         id: clockSvg
0050         imagePath: "widgets/clock"
0051         function estimateHorizontalHandShadowOffset() {
0052             var id = "hint-hands-shadow-offset-to-west";
0053             if (hasElement(id)) {
0054                 return -elementSize(id).width;
0055             }
0056             id = "hint-hands-shadows-offset-to-east";
0057             if (hasElement(id)) {
0058                 return elementSize(id).width;
0059             }
0060             return 0;
0061         }
0062         function estimateVerticalHandShadowOffset() {
0063             var id = "hint-hands-shadow-offset-to-north";
0064             if (hasElement(id)) {
0065                 return -elementSize(id).height;
0066             }
0067             id = "hint-hands-shadow-offset-to-south";
0068             if (hasElement(id)) {
0069                 return elementSize(id).height;
0070             }
0071             return 0;
0072         }
0073         property double naturalHorizontalHandShadowOffset: estimateHorizontalHandShadowOffset()
0074         property double naturalVerticalHandShadowOffset: estimateVerticalHandShadowOffset()
0075         onRepaintNeeded: {
0076             naturalHorizontalHandShadowOffset = estimateHorizontalHandShadowOffset();
0077             naturalVerticalHandShadowOffset = estimateVerticalHandShadowOffset();
0078         }
0079     }
0080 
0081     Item {
0082         id: clock
0083         width: parent.width
0084         anchors {
0085             top: parent.top
0086             bottom: parent.bottom
0087         }
0088         readonly property double svgScale: face.width / face.naturalSize.width
0089         readonly property double horizontalShadowOffset:
0090             Math.round(clockSvg.naturalHorizontalHandShadowOffset * svgScale) + Math.round(clockSvg.naturalHorizontalHandShadowOffset * svgScale) % 2
0091         readonly property double verticalShadowOffset:
0092             Math.round(clockSvg.naturalVerticalHandShadowOffset * svgScale) + Math.round(clockSvg.naturalVerticalHandShadowOffset * svgScale) % 2
0093 
0094         KSvg.SvgItem {
0095             id: face
0096             anchors.centerIn: parent
0097             width: Math.min(parent.width, parent.height)
0098             height: Math.min(parent.width, parent.height)
0099             svg: clockSvg
0100             elementId: "ClockFace"
0101         }
0102 
0103         Hand {
0104             elementId: "HourHandShadow"
0105             rotationCenterHintId: "hint-hourhandshadow-rotation-center-offset"
0106             horizontalRotationOffset: clock.horizontalShadowOffset
0107             verticalRotationOffset: clock.verticalShadowOffset
0108             rotation: 180 + hours * 30 + (minutes/2)
0109             svgScale: clock.svgScale
0110 
0111         }
0112         Hand {
0113             elementId: "HourHand"
0114             rotationCenterHintId: "hint-hourhand-rotation-center-offset"
0115             rotation: 180 + hours * 30 + (minutes/2)
0116             svgScale: clock.svgScale
0117         }
0118 
0119         Hand {
0120             elementId: "MinuteHandShadow"
0121             rotationCenterHintId: "hint-minutehandshadow-rotation-center-offset"
0122             horizontalRotationOffset: clock.horizontalShadowOffset
0123             verticalRotationOffset: clock.verticalShadowOffset
0124             rotation: 180 + minutes * 6
0125             svgScale: clock.svgScale
0126         }
0127         Hand {
0128             elementId: "MinuteHand"
0129             rotationCenterHintId: "hint-minutehand-rotation-center-offset"
0130             rotation: 180 + minutes * 6
0131             svgScale: clock.svgScale
0132         }
0133 
0134         Hand {
0135             elementId: "SecondHandShadow"
0136             rotationCenterHintId: "hint-secondhandshadow-rotation-center-offset"
0137             horizontalRotationOffset: clock.horizontalShadowOffset
0138             verticalRotationOffset: clock.verticalShadowOffset
0139             rotation: 180 + seconds * 6
0140             visible: showSecondsHand
0141             svgScale: clock.svgScale
0142         }
0143         Hand {
0144             elementId: "SecondHand"
0145             rotationCenterHintId: "hint-secondhand-rotation-center-offset"
0146             rotation: 180 + seconds * 6
0147             visible: showSecondsHand
0148             svgScale: clock.svgScale
0149         }
0150 
0151         KSvg.SvgItem {
0152             id: center
0153             width: naturalSize.width * clock.svgScale
0154             height: naturalSize.height * clock.svgScale
0155             anchors.centerIn: clock
0156             svg: clockSvg
0157             elementId: "HandCenterScrew"
0158             z: 1000
0159         }
0160 
0161         KSvg.SvgItem {
0162             anchors.fill: face
0163             svg: clockSvg
0164             elementId: "Glass"
0165             width: naturalSize.width * clock.svgScale
0166             height: naturalSize.height * clock.svgScale
0167         }
0168     }
0169 }