Themeexplorer: sync analog clock code from applet

parent 6e6b8da3
......@@ -24,26 +24,49 @@ import QtQuick 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
PlasmaCore.SvgItem {
id: secondHand
id: handRoot
property alias rotation: rotation.angle
property double svgScale
property double horizontalRotationOffset: 0
property double verticalRotationOffset: 0
property string rotationCenterHintId
readonly property double horizontalRotationCenter: {
if (svg.hasElement(rotationCenterHintId)) {
var hintedCenterRect = svg.elementRect(rotationCenterHintId),
handRect = svg.elementRect(elementId),
hintedX = hintedCenterRect.x - handRect.x + hintedCenterRect.width/2;
return Math.round(hintedX * svgScale) + Math.round(hintedX * svgScale) % 2;
}
return width/2;
}
readonly property double verticalRotationCenter: {
if (svg.hasElement(rotationCenterHintId)) {
var hintedCenterRect = svg.elementRect(rotationCenterHintId),
handRect = svg.elementRect(elementId),
hintedY = hintedCenterRect.y - handRect.y + hintedCenterRect.height/2;
return Math.round(hintedY * svgScale) + width % 2;
}
return width/2;
}
width: naturalSize.width * svgScale
height: naturalSize.height * svgScale
width: Math.round(naturalSize.width * svgScale) + Math.round(naturalSize.width * svgScale) % 2
height: Math.round(naturalSize.height * svgScale) + width % 2
anchors {
top: clock.verticalCenter
topMargin: -width/2
horizontalCenter: clock.horizontalCenter
topMargin: -verticalRotationCenter + verticalRotationOffset
left: clock.horizontalCenter
leftMargin: -horizontalRotationCenter + horizontalRotationOffset
}
svg: clockSvg
smooth: !anim.running
transform: Rotation {
id: rotation
angle: 0
origin {
x: width/2
y: width/2
x: handRoot.horizontalRotationCenter
y: handRoot.verticalRotationCenter
}
Behavior on angle {
RotationAnimation {
......
......@@ -61,6 +61,34 @@ Item {
PlasmaCore.Svg {
id: clockSvg
imagePath: "widgets/clock"
function estimateHorizontalHandShadowOffset() {
var id = "hint-hands-shadow-offset-to-west";
if (hasElement(id)) {
return -elementSize(id).width;
}
id = "hint-hands-shadows-offset-to-east";
if (hasElement(id)) {
return elementSize(id).width;
}
return 0;
}
function estimateVerticalHandShadowOffset() {
var id = "hint-hands-shadow-offset-to-north";
if (hasElement(id)) {
return -elementSize(id).height;
}
id = "hint-hands-shadow-offset-to-south";
if (hasElement(id)) {
return elementSize(id).height;
}
return 0;
}
property double naturalHorizontalHandShadowOffset: estimateHorizontalHandShadowOffset()
property double naturalVerticalHandShadowOffset: estimateVerticalHandShadowOffset()
onRepaintNeeded: {
naturalHorizontalHandShadowOffset = estimateHorizontalHandShadowOffset();
naturalVerticalHandShadowOffset = estimateVerticalHandShadowOffset();
}
}
Item {
......@@ -70,6 +98,11 @@ Item {
top: parent.top
bottom: parent.bottom
}
readonly property double svgScale: face.width / face.naturalSize.width
readonly property double horizontalShadowOffset:
Math.round(clockSvg.naturalHorizontalHandShadowOffset * svgScale) + Math.round(clockSvg.naturalHorizontalHandShadowOffset * svgScale) % 2
readonly property double verticalShadowOffset:
Math.round(clockSvg.naturalVerticalHandShadowOffset * svgScale) + Math.round(clockSvg.naturalVerticalHandShadowOffset * svgScale) % 2
PlasmaCore.SvgItem {
id: face
......@@ -80,61 +113,70 @@ Item {
elementId: "ClockFace"
}
PlasmaCore.SvgItem {
anchors.fill: face
svg: clockSvg
elementId: "Glass"
width: naturalSize.width * face.width / face.naturalSize.width
height: naturalSize.height * face.width / face.naturalSize.width
}
}
Hand {
elementId: "HourHandShadow"
rotationCenterHintId: "hint-hourhandshadow-rotation-center-offset"
horizontalRotationOffset: clock.horizontalShadowOffset
verticalRotationOffset: clock.verticalShadowOffset
rotation: 180 + hours * 30 + (minutes/2)
svgScale: clock.svgScale
Hand {
anchors.topMargin: 3
elementId: "HourHandShdow"
rotation: 180 + hours * 30 + (minutes/2)
svgScale: face.width / face.naturalSize.width
}
Hand {
elementId: "HourHand"
rotationCenterHintId: "hint-hourhand-rotation-center-offset"
rotation: 180 + hours * 30 + (minutes/2)
svgScale: clock.svgScale
}
}
Hand {
elementId: "HourHand"
rotation: 180 + hours * 30 + (minutes/2)
svgScale: face.width / face.naturalSize.width
}
Hand {
elementId: "MinuteHandShadow"
rotationCenterHintId: "hint-minutehandshadow-rotation-center-offset"
horizontalRotationOffset: clock.horizontalShadowOffset
verticalRotationOffset: clock.verticalShadowOffset
rotation: 180 + minutes * 6
svgScale: clock.svgScale
}
Hand {
elementId: "MinuteHand"
rotationCenterHintId: "hint-minutehand-rotation-center-offset"
rotation: 180 + minutes * 6
svgScale: clock.svgScale
}
Hand {
anchors.topMargin: 3
elementId: "MinuteHandShadow"
rotation: 180 + minutes * 6
svgScale: face.width / face.naturalSize.width
}
Hand {
elementId: "MinuteHand"
rotation: 180 + minutes * 6
svgScale: face.width / face.naturalSize.width
}
Hand {
elementId: "SecondHandShadow"
rotationCenterHintId: "hint-secondhandshadow-rotation-center-offset"
horizontalRotationOffset: clock.horizontalShadowOffset
verticalRotationOffset: clock.verticalShadowOffset
rotation: 180 + seconds * 6
visible: showSecondsHand
svgScale: clock.svgScale
}
Hand {
elementId: "SecondHand"
rotationCenterHintId: "hint-secondhand-rotation-center-offset"
rotation: 180 + seconds * 6
visible: showSecondsHand
svgScale: clock.svgScale
}
Hand {
anchors.topMargin: 3
elementId: "SecondHandShadow"
rotation: 180 + seconds * 6
visible: showSecondsHand
svgScale: face.width / face.naturalSize.width
}
Hand {
elementId: "SecondHand"
rotation: 180 + seconds * 6
visible: showSecondsHand
svgScale: face.width / face.naturalSize.width
}
PlasmaCore.SvgItem {
id: center
width: naturalSize.width * clock.svgScale
height: naturalSize.height * clock.svgScale
anchors.centerIn: clock
svg: clockSvg
elementId: "HandCenterScrew"
z: 1000
}
PlasmaCore.SvgItem {
id: center
width: naturalSize.width * face.width / face.naturalSize.width
height: naturalSize.height * face.width / face.naturalSize.width
anchors.centerIn: clock
svg: clockSvg
elementId: "HandCenterScrew"
z: 1000
PlasmaCore.SvgItem {
anchors.fill: face
svg: clockSvg
elementId: "Glass"
width: naturalSize.width * clock.svgScale
height: naturalSize.height * clock.svgScale
}
}
}
Markdown is supported
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