summaryrefslogtreecommitdiffstats
path: root/src/Clock.qml
blob: ecad98b3b291dd0ed0f83a9d769a244e795d8073 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import QtQuick 2.0

Text {
    id: clock

    property real fontSize: parent.height * 0.05
    property real fontScale: 0.5
    property color textColor: parent.textColor != undefined ? parent.textColor : "black"
    property string fontFamily: parent.fontFamily != undefined ? parent.fontFamily : "Helvetica"

    text: currentTime();

    function currentTime() {
        var d = new Date();
        var m = d.getMinutes();
        if (m < 10) m = "0" + m;
        return d.getHours() + ":" + m;
    }

    color: textColor;
    font.family: fontFamily;
    font.pixelSize: fontSize * fontScale;

    anchors.bottom: parent.bottom;
    anchors.left: parent.left;
    anchors.margins: font.pixelSize;

    Timer {
        interval: 60000;
        repeat: true;
        running: true
        onTriggered: clock.text = clock.currentTime();
    }
}