45
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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: CalenDayUtils utility class implementation.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// System includes
|
63
|
19 |
#include <QDateTime>
|
|
20 |
#include <HbDeviceProfile>
|
|
21 |
#include <HbStyle>
|
|
22 |
#include <HbInstance>
|
45
|
23 |
|
|
24 |
// User includes
|
|
25 |
#include "calendayutils.h"
|
|
26 |
#include "calendaycommonheaders.h"
|
|
27 |
#include "agendaentry.h"
|
|
28 |
#include "calendateutils.h"
|
|
29 |
|
|
30 |
// Initialization of static member
|
|
31 |
CalenDayUtils* CalenDayUtils::mInstance = 0;
|
|
32 |
|
|
33 |
/*!
|
|
34 |
\class CalenDayUtils
|
|
35 |
\brief Singleton utility class.
|
|
36 |
|
|
37 |
Class cannot be used in console applications.
|
|
38 |
|
|
39 |
Provided functionalities (getters):
|
|
40 |
- screen width of device
|
|
41 |
- default width of hour element
|
|
42 |
- default height of hour element
|
|
43 |
- default width of content area
|
|
44 |
- current orientation of screen
|
|
45 |
- pointer to the main window of application
|
|
46 |
*/
|
|
47 |
|
|
48 |
/*!
|
|
49 |
\brief Returns the instance of CalenDayUtils class
|
|
50 |
*/
|
|
51 |
CalenDayUtils *CalenDayUtils::instance()
|
|
52 |
{
|
|
53 |
if (!mInstance) {
|
|
54 |
mInstance = new CalenDayUtils();
|
|
55 |
}
|
|
56 |
return mInstance;
|
|
57 |
}
|
|
58 |
|
|
59 |
/*!
|
|
60 |
\brief Destructor
|
|
61 |
*/
|
|
62 |
CalenDayUtils::~CalenDayUtils()
|
|
63 |
{
|
|
64 |
|
|
65 |
}
|
|
66 |
|
|
67 |
/*!
|
|
68 |
\brief screenWidth
|
|
69 |
|
|
70 |
\return Width of main window's screen
|
|
71 |
*/
|
|
72 |
qreal CalenDayUtils::screenWidth() const
|
|
73 |
{
|
|
74 |
ASSERT(mMainWindow);
|
|
75 |
|
|
76 |
return mMainWindow->layoutRect().width();
|
|
77 |
}
|
|
78 |
|
|
79 |
/*!
|
|
80 |
\brief hourElementWidth
|
|
81 |
|
|
82 |
\return Width of hour element
|
|
83 |
*/
|
|
84 |
qreal CalenDayUtils::hourElementWidth() const
|
|
85 |
{
|
|
86 |
return mHourElementWidth;
|
|
87 |
}
|
|
88 |
|
|
89 |
/*!
|
|
90 |
\brief hourElementHeight
|
|
91 |
|
|
92 |
\return Height of hour element
|
|
93 |
*/
|
|
94 |
qreal CalenDayUtils::hourElementHeight() const
|
|
95 |
{
|
|
96 |
return mHourElementHeight;
|
|
97 |
}
|
|
98 |
|
|
99 |
/*!
|
70
|
100 |
\brief minEventHeight
|
|
101 |
|
|
102 |
\return Minimum height of event bubble
|
|
103 |
*/
|
|
104 |
qreal CalenDayUtils::minEventHeight() const
|
|
105 |
{
|
|
106 |
return mMinEventHeight;
|
|
107 |
}
|
|
108 |
|
|
109 |
/*!
|
45
|
110 |
\brief contentWidth
|
|
111 |
|
|
112 |
\return Width of content area
|
|
113 |
*/
|
|
114 |
qreal CalenDayUtils::contentWidth() const
|
|
115 |
{
|
|
116 |
return (screenWidth() - mHourElementWidth);
|
|
117 |
}
|
|
118 |
|
|
119 |
/*!
|
|
120 |
\brief orientation
|
|
121 |
|
|
122 |
\return Orientation of main window
|
|
123 |
*/
|
|
124 |
Qt::Orientation CalenDayUtils::orientation() const
|
|
125 |
{
|
|
126 |
ASSERT(mMainWindow);
|
|
127 |
|
|
128 |
return mMainWindow->orientation();
|
|
129 |
}
|
|
130 |
|
|
131 |
/*!
|
|
132 |
\brief mainWindow
|
|
133 |
|
|
134 |
\return Pointer to main window of application
|
|
135 |
*/
|
|
136 |
HbMainWindow* CalenDayUtils::mainWindow()
|
|
137 |
{
|
|
138 |
ASSERT(mMainWindow);
|
|
139 |
|
|
140 |
return mMainWindow;
|
|
141 |
}
|
|
142 |
|
81
|
143 |
/*
|
|
144 |
* Get event's start/end time fromm agenda entry.
|
|
145 |
* Start/end time are validated to be within the current day (the case of
|
|
146 |
* multi-day events)
|
|
147 |
* @param start [out] valid start time
|
|
148 |
* @param end [out] valid end time
|
|
149 |
* @param entry [in] agenda entry asociated with the event.
|
|
150 |
* @param currentDate [in] current date
|
45
|
151 |
*/
|
81
|
152 |
void CalenDayUtils::getEventValidStartEndTime(
|
|
153 |
QDateTime& start,
|
|
154 |
QDateTime& end,
|
|
155 |
const AgendaEntry& entry,
|
|
156 |
QDateTime& currentDate)
|
45
|
157 |
{
|
|
158 |
start = entry.startTime();
|
|
159 |
end = entry.endTime();
|
81
|
160 |
|
|
161 |
if (!CalenDateUtils::onSameDay(start, currentDate)) {
|
|
162 |
start = CalenDateUtils::beginningOfDay(currentDate);
|
45
|
163 |
}
|
81
|
164 |
|
|
165 |
if (!CalenDateUtils::onSameDay(end, currentDate)) {
|
|
166 |
QDateTime tommorrow(currentDate.addDays(1));
|
|
167 |
end = CalenDateUtils::beginningOfDay(tommorrow).addSecs(-60);
|
45
|
168 |
}
|
|
169 |
}
|
|
170 |
|
|
171 |
/*!
|
|
172 |
\brief Constructor
|
|
173 |
*/
|
|
174 |
CalenDayUtils::CalenDayUtils() : mMainWindow(NULL)
|
|
175 |
{
|
|
176 |
if (HbInstance::instance()->allMainWindows().count() > 0) {
|
|
177 |
mMainWindow = HbInstance::instance()->allMainWindows().first();
|
|
178 |
}
|
|
179 |
mHourElementWidth = calculateHourElementWidth();
|
|
180 |
mHourElementHeight = calculateHourElementHeight();
|
70
|
181 |
mMinEventHeight = calculateMinEventHeight();
|
45
|
182 |
}
|
|
183 |
|
|
184 |
/*!
|
|
185 |
\brief Calculates the width of hour element according to UI spec.
|
|
186 |
|
|
187 |
\return Calculated width of hour element
|
|
188 |
*/
|
|
189 |
qreal CalenDayUtils::calculateHourElementWidth() const
|
|
190 |
{
|
|
191 |
HbStyle style;
|
|
192 |
HbDeviceProfile deviceProfile;
|
|
193 |
qreal unitInPixels = deviceProfile.unitValue();
|
|
194 |
|
|
195 |
// Calculate element's preferred width
|
|
196 |
qreal prefWidth = 0.0;
|
|
197 |
qreal textWidth = 0.0;
|
|
198 |
qreal horizontalSpacing = 0.0;
|
|
199 |
|
|
200 |
textWidth = 8.04 * unitInPixels; // pix (according to UI spec)
|
|
201 |
style.parameter(QString("hb-param-margin-gene-middle-horizontal"),
|
|
202 |
horizontalSpacing, deviceProfile);
|
|
203 |
prefWidth = horizontalSpacing * 2 + textWidth;
|
|
204 |
|
|
205 |
return prefWidth;
|
|
206 |
}
|
|
207 |
|
|
208 |
/*!
|
|
209 |
\brief Calculates the height of hour element according to UI spec.
|
|
210 |
|
|
211 |
\return Calculated height of hour element
|
|
212 |
*/
|
|
213 |
qreal CalenDayUtils::calculateHourElementHeight() const
|
|
214 |
{
|
|
215 |
HbStyle style;
|
|
216 |
HbDeviceProfile deviceProfile;
|
|
217 |
|
|
218 |
qreal unitInPixels = deviceProfile.unitValue();
|
|
219 |
|
|
220 |
// Calculate element's preferred height
|
|
221 |
qreal prefHeight = 0.0;
|
|
222 |
qreal textHeight = 0.0;
|
|
223 |
qreal verticalSpacing = 0.0;
|
|
224 |
|
64
|
225 |
qreal bottomSpacer = 4.1 * unitInPixels;
|
45
|
226 |
style.parameter(QString("hb-param-text-height-secondary"), textHeight,
|
|
227 |
deviceProfile);
|
|
228 |
style.parameter(QString("hb-param-margin-gene-middle-vertical"),
|
|
229 |
verticalSpacing, deviceProfile);
|
|
230 |
|
|
231 |
prefHeight = textHeight * 2; //time + ampm
|
|
232 |
prefHeight += verticalSpacing * 2;
|
|
233 |
prefHeight += bottomSpacer;
|
|
234 |
|
|
235 |
return prefHeight;
|
|
236 |
}
|
70
|
237 |
|
|
238 |
/*!
|
|
239 |
\brief Calculates the height of hour element according to UI spec.
|
|
240 |
|
|
241 |
\return Calculated minimum height of event bubble
|
|
242 |
*/
|
|
243 |
qreal CalenDayUtils::calculateMinEventHeight() const
|
|
244 |
{
|
|
245 |
HbStyle style;
|
|
246 |
HbDeviceProfile deviceProfile;
|
|
247 |
|
|
248 |
// Calculate minimum height of event bubble
|
|
249 |
qreal textHeight = 0.0;
|
|
250 |
qreal topSpacing = 0.0;
|
|
251 |
qreal bottomSpacing = 0.0;
|
|
252 |
style.parameter(QString("hb-param-text-height-secondary"), textHeight,
|
|
253 |
deviceProfile);
|
|
254 |
style.parameter(QString("hb-param-margin-gene-top"), topSpacing,
|
|
255 |
deviceProfile);
|
|
256 |
style.parameter(QString("hb-param-margin-gene-bottom"), bottomSpacing,
|
|
257 |
deviceProfile);
|
|
258 |
|
|
259 |
return (topSpacing + textHeight + bottomSpacing);
|
|
260 |
}
|