1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Calendar widget's date icon layout handler |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <QObject> |
|
20 #include <HbLabel> |
|
21 #include <HbColorScheme> |
|
22 #include <HbFrameDrawer> |
|
23 #include <HbFrameItem> |
|
24 #include <HbDocumentLoader> |
|
25 #include <QDateTime> |
|
26 #include <QTimer> |
|
27 #include <QPointF> |
|
28 #include <QGraphicsLayout> |
|
29 #include <xqaiwrequest.h> |
|
30 #include <xqappmgr.h> |
|
31 |
|
32 // User includes |
|
33 #include "dateiconlayouthandler.h" |
|
34 #include "calendarwidgetdebug.h" |
|
35 #include "datetimeobserver.h" |
|
36 |
|
37 // Local constants |
|
38 namespace |
|
39 { |
|
40 const HbFrameDrawer::FrameType BACKGROUND_FRAME_TYPE = HbFrameDrawer::OnePiece; |
|
41 const char *DAY_CONTAINER = "dayContainer"; |
|
42 const char *DATE_ICON_DAYNUMBER = "dayNumber"; |
|
43 const char *DATE_ICON_MONTHLABEL = "month"; |
|
44 const char *NUMBER_LABEL_COLOR = "qtc_hs_cal"; |
|
45 const char *MONTH_LABEL_COLOR = "qtc_hs_list_item_title_normal"; |
|
46 const char *DATE_BACKGROUND = "qtg_large_calendar_dynamic"; |
|
47 } // namespace |
|
48 |
|
49 // ======== MEMBER FUNCTIONS ======== |
|
50 |
|
51 /* |
|
52 * DateIconLayoutHandler::DateIconLayoutHandler() |
|
53 */ |
|
54 DateIconLayoutHandler::DateIconLayoutHandler() |
|
55 : mWidget(0), |
|
56 mNumberLabel(0), |
|
57 mMonthLabel(0), |
|
58 mFrameDrawer(0), |
|
59 mDateObserver(0) |
|
60 { |
|
61 LOGS("DateIconLayoutHandler::DateIconLayoutHandler"); |
|
62 } |
|
63 |
|
64 /* |
|
65 * DateIconLayoutHandler::~DateIconLayoutHandler() |
|
66 */ |
|
67 DateIconLayoutHandler::~DateIconLayoutHandler() |
|
68 { |
|
69 LOGS("DateIconLayoutHandler::~DateIconLayoutHandler()"); |
|
70 delete mDateObserver; |
|
71 } |
|
72 |
|
73 /* |
|
74 * DateIconLayoutHandler::initializeLayout() |
|
75 */ |
|
76 void DateIconLayoutHandler::initializeLayout(const HbDocumentLoader &layoutLoader, QObject *owner) |
|
77 { |
|
78 this->setParent(owner); |
|
79 mWidget = qobject_cast<HbWidget*>(layoutLoader.findWidget(QString(DAY_CONTAINER))); |
|
80 mNumberLabel = qobject_cast<HbLabel*>(layoutLoader.findWidget(QString(DATE_ICON_DAYNUMBER))); |
|
81 mMonthLabel = qobject_cast<HbLabel*>(layoutLoader.findWidget(QString(DATE_ICON_MONTHLABEL))); |
|
82 |
|
83 // Create background drawer only if day container loading succeeded |
|
84 if (mWidget) { |
|
85 mFrameDrawer = new HbFrameDrawer(DATE_BACKGROUND, BACKGROUND_FRAME_TYPE); |
|
86 HbFrameItem* frameItem = new HbFrameItem(mFrameDrawer); |
|
87 mWidget->setBackgroundItem(frameItem); |
|
88 } |
|
89 |
|
90 setCalendarIconContent(); |
|
91 setLabelsColor(); |
|
92 |
|
93 mDateObserver = new DateTimeObserver(); |
|
94 connect(mDateObserver, SIGNAL(completed()), this, SIGNAL(dateChanged())); |
|
95 connect(this, SIGNAL( dateChanged() ), owner, SIGNAL( updateLayout() )); |
|
96 } |
|
97 |
|
98 /* |
|
99 * DateIconLayoutHandler::updateLayout() |
|
100 */ |
|
101 void DateIconLayoutHandler::updateLayout() |
|
102 { |
|
103 LOGS("DateIconLayoutHandler::updateLayout"); |
|
104 setCalendarIconContent(); |
|
105 } |
|
106 |
|
107 /* |
|
108 * DateIconLayoutHandler::onTap() |
|
109 */ |
|
110 void DateIconLayoutHandler::onTap(QPointF &point) |
|
111 { |
|
112 if (mWidget) { |
|
113 if (mWidget->sceneBoundingRect().contains(point)) { |
|
114 LOGS("[[[onTap in DateIcon area]]]"); |
|
115 launchCalendarMonthView(); |
|
116 } |
|
117 } |
|
118 } |
|
119 |
|
120 /* |
|
121 * DateIconLayoutHandler::onThemeChange() |
|
122 */ |
|
123 void DateIconLayoutHandler::onThemeChange() |
|
124 { |
|
125 LOGS("DateIconLayoutHandler::onThemeChange"); |
|
126 if (mFrameDrawer) { |
|
127 mFrameDrawer->themeChanged(); |
|
128 } |
|
129 setLabelsColor(); |
|
130 } |
|
131 |
|
132 void DateIconLayoutHandler::setLabelsColor() |
|
133 { |
|
134 LOGS("CalendarWidget::CalendarWidget"); |
|
135 |
|
136 const QString dayLabelColorAttribute(NUMBER_LABEL_COLOR); |
|
137 QColor numberLabelColor(HbColorScheme::color(dayLabelColorAttribute)); |
|
138 if (numberLabelColor.isValid() && mNumberLabel) { |
|
139 mNumberLabel->setTextColor(numberLabelColor); |
|
140 } |
|
141 |
|
142 const QString monthLabelColorAttribute(MONTH_LABEL_COLOR); |
|
143 QColor monthLabelColor(HbColorScheme::color(monthLabelColorAttribute)); |
|
144 if (monthLabelColor.isValid() && mMonthLabel) { |
|
145 mMonthLabel->setTextColor(monthLabelColor); |
|
146 } |
|
147 } |
|
148 |
|
149 /* |
|
150 * DateIconLayoutHandler::setCalendarIconContent() |
|
151 */ |
|
152 void DateIconLayoutHandler::setCalendarIconContent() |
|
153 { |
|
154 LOGS("DateIconLayoutHandler::setCalendarIconContent"); |
|
155 if (mNumberLabel) { |
|
156 mNumberLabel->setPlainText(QString::number(QDateTime::currentDateTime().date().day(), 10)); |
|
157 } |
|
158 if (mMonthLabel) { |
|
159 mMonthLabel->setPlainText(QLocale::system().monthName( |
|
160 QDateTime::currentDateTime().date().month())); |
|
161 } |
|
162 } |
|
163 |
|
164 /* |
|
165 * DateIconLayoutHandler::launchCalendarMonthView() |
|
166 */ |
|
167 void DateIconLayoutHandler::launchCalendarMonthView() |
|
168 { |
|
169 LOGS("DateIconLayoutHandler::launchCalendarMonthView"); |
|
170 |
|
171 QString interface("calendar.Launch"); |
|
172 QString service("com.nokia.services"); |
|
173 QString method("launchCalendarApp(QDateTime,int)"); |
|
174 |
|
175 XQApplicationManager aiwMgr; |
|
176 XQAiwRequest* request = aiwMgr.create(service, interface, method, false); |
|
177 if (request == NULL) |
|
178 { |
|
179 return; |
|
180 } |
|
181 |
|
182 // Connect result handling signal |
|
183 connect(request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&))); |
|
184 // Connect error handling signal or apply lastError function instead. |
|
185 connect(request, SIGNAL(requestError(int,const QString&)), this, SLOT(handleError(int,const QString&))); |
|
186 |
|
187 QList<QVariant> args; |
|
188 //if there are no elements in the calendar open the current day view |
|
189 QDateTime currentDate = QDateTime::currentDateTime(); |
|
190 args << currentDate; |
|
191 |
|
192 int viewId = 0; |
|
193 args << viewId; |
|
194 |
|
195 // Set function parameters |
|
196 request->setArguments(args); |
|
197 |
|
198 // Send the request |
|
199 bool res = request->send(); |
|
200 if (!res) { |
|
201 // Request failed. |
|
202 int error = request->lastError(); |
|
203 // Handle error |
|
204 } |
|
205 |
|
206 // All done. |
|
207 delete request; |
|
208 } |
|
209 |
|
210 /* |
|
211 * DateIconLayoutHandler::handleOk() |
|
212 */ |
|
213 void DateIconLayoutHandler::handleOk(const QVariant& var) |
|
214 { |
|
215 Q_UNUSED(var); |
|
216 LOGS("DateIconLayoutHandler::handleOk"); |
|
217 mTestResult = 0; |
|
218 emit requestComplete(); |
|
219 } |
|
220 |
|
221 /* |
|
222 * DateIconLayoutHandler::handleError() |
|
223 */ |
|
224 void DateIconLayoutHandler::handleError(int err, const QString& str) |
|
225 { |
|
226 Q_UNUSED(str); |
|
227 LOGS("ContentLayoutHandler::handleError"); |
|
228 mTestResult = err; |
|
229 emit requestError(); |
|
230 } |
|
231 |
|
232 /* |
|
233 * TEST Functions |
|
234 */ |
|
235 |
|
236 /* |
|
237 * DateIconLayoutHandler::testId() |
|
238 */ |
|
239 int DateIconLayoutHandler::testId() |
|
240 { |
|
241 return mTestID; |
|
242 } |
|
243 |
|
244 /* |
|
245 * DateIconLayoutHandler::setTestId() |
|
246 */ |
|
247 void DateIconLayoutHandler::setTestId(int testID) |
|
248 { |
|
249 mTestID = testID; |
|
250 } |
|
251 |
|
252 int DateIconLayoutHandler::testResult() |
|
253 { |
|
254 return mTestResult; |
|
255 } |
|
256 |
|
257 void DateIconLayoutHandler::setTestResult(int testResult) |
|
258 { |
|
259 mTestResult = testResult; |
|
260 } |
|
261 |
|
262 //End of file |
|
263 |
|