Changeset View
Changeset View
Standalone View
Standalone View
kcms/desktoptheme/package/contents/ui/Hand.qml
Show All 18 Lines | |||||
19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | import QtQuick 2.0 | 22 | import QtQuick 2.0 | ||
23 | 23 | | |||
24 | import org.kde.plasma.core 2.0 as PlasmaCore | 24 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
25 | 25 | | |||
26 | PlasmaCore.SvgItem { | 26 | PlasmaCore.SvgItem { | ||
27 | id: secondHand | 27 | id: handRoot | ||
28 | 28 | | |||
29 | property alias rotation: rotation.angle | 29 | property alias rotation: rotation.angle | ||
30 | property double svgScale | 30 | property double svgScale | ||
31 | property double horizontalRotationOffset: 0 | ||||
32 | property double verticalRotationOffset: 0 | ||||
33 | property string rotationCenterHintId | ||||
34 | readonly property double horizontalRotationCenter: { | ||||
35 | if (svg.hasElement(rotationCenterHintId)) { | ||||
36 | var hintedCenterRect = svg.elementRect(rotationCenterHintId), | ||||
37 | handRect = svg.elementRect(elementId), | ||||
38 | hintedX = hintedCenterRect.x - handRect.x + hintedCenterRect.width/2; | ||||
39 | return Math.round(hintedX * svgScale) + Math.round(hintedX * svgScale) % 2; | ||||
40 | } | ||||
41 | return width/2; | ||||
42 | } | ||||
43 | readonly property double verticalRotationCenter: { | ||||
44 | if (svg.hasElement(rotationCenterHintId)) { | ||||
45 | var hintedCenterRect = svg.elementRect(rotationCenterHintId), | ||||
46 | handRect = svg.elementRect(elementId), | ||||
47 | hintedY = hintedCenterRect.y - handRect.y + hintedCenterRect.height/2; | ||||
48 | return Math.round(hintedY * svgScale) + width % 2; | ||||
49 | } | ||||
50 | return width/2; | ||||
51 | } | ||||
31 | 52 | | |||
32 | width: Math.round(naturalSize.width * svgScale) + Math.round(naturalSize.width * svgScale) % 2 | 53 | width: Math.round(naturalSize.width * svgScale) + Math.round(naturalSize.width * svgScale) % 2 | ||
33 | height: Math.round(naturalSize.height * svgScale) + width % 2 | 54 | height: Math.round(naturalSize.height * svgScale) + width % 2 | ||
34 | anchors { | 55 | anchors { | ||
35 | top: clock.verticalCenter | 56 | top: clock.verticalCenter | ||
36 | topMargin: -width / 2 | 57 | topMargin: -verticalRotationCenter + verticalRotationOffset | ||
37 | horizontalCenter: clock.horizontalCenter | 58 | left: clock.horizontalCenter | ||
59 | leftMargin: -horizontalRotationCenter + horizontalRotationOffset | ||||
38 | } | 60 | } | ||
61 | | ||||
39 | svg: clockSvg | 62 | svg: clockSvg | ||
40 | smooth: !anim.running | 63 | smooth: !anim.running | ||
41 | transform: Rotation { | 64 | transform: Rotation { | ||
42 | id: rotation | 65 | id: rotation | ||
43 | angle: 0 | 66 | angle: 0 | ||
44 | origin { | 67 | origin { | ||
45 | x: width / 2 | 68 | x: handRoot.horizontalRotationCenter | ||
46 | y: width / 2 | 69 | y: handRoot.verticalRotationCenter | ||
47 | } | 70 | } | ||
48 | Behavior on angle { | 71 | Behavior on angle { | ||
49 | RotationAnimation { | 72 | RotationAnimation { | ||
50 | id: anim | 73 | id: anim | ||
51 | duration: 200 | 74 | duration: 200 | ||
52 | direction: RotationAnimation.Clockwise | 75 | direction: RotationAnimation.Clockwise | ||
53 | easing.type: Easing.OutElastic | 76 | easing.type: Easing.OutElastic | ||
54 | easing.overshoot: 0.5 | 77 | easing.overshoot: 0.5 | ||
55 | } | 78 | } | ||
56 | } | 79 | } | ||
57 | } | 80 | } | ||
58 | } | 81 | } |