Unity 8
 All Classes Functions
Clock.qml
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  */
16 
17 import QtQuick 2.0
18 import Ubuntu.Components 0.1
19 import "../Panel/Indicators"
20 import Unity.Indicators 0.1 as Indicators
21 
22 Item {
23  id: clock
24 
25  implicitWidth: childrenRect.width
26  implicitHeight: childrenRect.height
27 
28  // Allows to set the current Date. Will be overwritten if visible
29  property date currentDate
30 
31  Component.onCompleted: {
32  if (visible) {
33  currentDate = new Date()
34  }
35  }
36 
37  CachedUnityMenuModel {
38  id: timeModel
39  objectName: "timeModel"
40 
41  busName: "com.canonical.indicator.datetime"
42  actionsObjectPath: "/com/canonical/indicator/datetime"
43  menuObjectPath: clock.visible ? "/com/canonical/indicator/datetime/phone" : ""
44 
45  Indicators.RootActionState {
46  menu: timeModel.model
47  onUpdated: {
48  if (timeLabel.text != rightLabel) {
49  timeLabel.text = rightLabel;
50  clock.currentDate = new Date();
51  }
52  }
53  }
54  }
55 
56  Column {
57  spacing: units.gu(0.5)
58 
59  Label {
60  id: timeLabel
61  objectName: "timeLabel"
62 
63  anchors.horizontalCenter: parent.horizontalCenter
64  font.pixelSize: units.gu(7.5)
65  color: "white"
66  opacity: 0.5
67  text: Qt.formatTime(clock.currentDate)
68  font.weight: Font.Light
69  }
70 
71  Label {
72  id: dateLabel
73  objectName: "dateLabel"
74 
75  anchors.horizontalCenter: parent.horizontalCenter
76  fontSize: "medium"
77  color: "white"
78  opacity: 0.5
79  text: Qt.formatDate(clock.currentDate, Qt.DefaultLocaleLongDate)
80  font.weight: Font.Light
81  }
82  }
83 }