on 29019df help sign in
unity8/qml/Greeter/Clock.qml
82 lines 2.4 kB history raw
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17import QtQuick 2.0
18import Ubuntu.Components 0.1
19import Unity.Indicators 0.1 as Indicators
21Item {
22 id: clock
24 implicitWidth: childrenRect.width
25 implicitHeight: childrenRect.height
27 // Allows to set the current Date. Will be overwritten if visible
28 property date currentDate
30 Component.onCompleted: {
31 if (visible) {
32 currentDate = new Date()
33 }
34 }
36 Indicators.CachedUnityMenuModel {
37 id: timeModel
38 objectName: "timeModel"
40 busName: "com.canonical.indicator.datetime"
41 actionsObjectPath: "/com/canonical/indicator/datetime"
42 menuObjectPath: clock.visible ? "/com/canonical/indicator/datetime/phone" : ""
44 Indicators.RootActionState {
45 menu: timeModel.model
46 onUpdated: {
47 if (timeLabel.text != rightLabel) {
48 timeLabel.text = rightLabel;
49 clock.currentDate = new Date();
50 }
51 }
52 }
53 }
55 Column {
56 spacing: units.gu(0.5)
58 Label {
59 id: timeLabel
60 objectName: "timeLabel"
62 anchors.horizontalCenter: parent.horizontalCenter
63 font.pixelSize: units.gu(7.5)
64 color: "white"
65 opacity: 0.5
66 text: Qt.formatTime(clock.currentDate)
67 font.weight: Font.Light
68 }
70 Label {
71 id: dateLabel
72 objectName: "dateLabel"
74 anchors.horizontalCenter: parent.horizontalCenter
75 fontSize: "medium"
76 color: "white"
77 opacity: 0.5
78 text: Qt.formatDate(clock.currentDate, Qt.DefaultLocaleLongDate)
79 font.weight: Font.Light
80 }
81 }