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
|
|
19 |
#include <hbdeviceprofile.h>
|
|
20 |
#include <hbstyle.h>
|
|
21 |
#include <hbinstance.h>
|
|
22 |
#include <qdatetime.h>
|
|
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 |
/*!
|
|
100 |
\brief contentWidth
|
|
101 |
|
|
102 |
\return Width of content area
|
|
103 |
*/
|
|
104 |
qreal CalenDayUtils::contentWidth() const
|
|
105 |
{
|
|
106 |
return (screenWidth() - mHourElementWidth);
|
|
107 |
}
|
|
108 |
|
|
109 |
/*!
|
|
110 |
\brief orientation
|
|
111 |
|
|
112 |
\return Orientation of main window
|
|
113 |
*/
|
|
114 |
Qt::Orientation CalenDayUtils::orientation() const
|
|
115 |
{
|
|
116 |
ASSERT(mMainWindow);
|
|
117 |
|
|
118 |
return mMainWindow->orientation();
|
|
119 |
}
|
|
120 |
|
|
121 |
/*!
|
|
122 |
\brief mainWindow
|
|
123 |
|
|
124 |
\return Pointer to main window of application
|
|
125 |
*/
|
|
126 |
HbMainWindow* CalenDayUtils::mainWindow()
|
|
127 |
{
|
|
128 |
ASSERT(mMainWindow);
|
|
129 |
|
|
130 |
return mMainWindow;
|
|
131 |
}
|
|
132 |
|
|
133 |
/*!
|
|
134 |
\brief getEventValidStartEndTime
|
|
135 |
\brief Get event's valid start/end time from agenda entry.
|
|
136 |
*/
|
|
137 |
void CalenDayUtils::getEventValidStartEndTime( QDateTime& start, QDateTime& end,
|
55
|
138 |
const AgendaEntry& entry, QDateTime& currentDate )
|
45
|
139 |
{
|
|
140 |
start = entry.startTime();
|
|
141 |
end = entry.endTime();
|
|
142 |
|
|
143 |
if ( !CalenDateUtils::onSameDay( start, currentDate ) ) {
|
|
144 |
start = CalenDateUtils::beginningOfDay( currentDate );
|
|
145 |
}
|
|
146 |
|
|
147 |
if ( !CalenDateUtils::onSameDay( end, currentDate ) ) {
|
|
148 |
QDateTime tommorrow( currentDate.addDays( 1 ));
|
|
149 |
end = CalenDateUtils::beginningOfDay( tommorrow ).addSecs( -60 );
|
|
150 |
}
|
|
151 |
}
|
|
152 |
|
|
153 |
/*!
|
|
154 |
\brief Constructor
|
|
155 |
*/
|
|
156 |
CalenDayUtils::CalenDayUtils() : mMainWindow(NULL)
|
|
157 |
{
|
|
158 |
if (HbInstance::instance()->allMainWindows().count() > 0) {
|
|
159 |
mMainWindow = HbInstance::instance()->allMainWindows().first();
|
|
160 |
}
|
|
161 |
mHourElementWidth = calculateHourElementWidth();
|
|
162 |
mHourElementHeight = calculateHourElementHeight();
|
|
163 |
}
|
|
164 |
|
|
165 |
/*!
|
|
166 |
\brief Calculates the width of hour element according to UI spec.
|
|
167 |
|
|
168 |
\return Calculated width of hour element
|
|
169 |
*/
|
|
170 |
qreal CalenDayUtils::calculateHourElementWidth() const
|
|
171 |
{
|
|
172 |
HbStyle style;
|
|
173 |
HbDeviceProfile deviceProfile;
|
|
174 |
qreal unitInPixels = deviceProfile.unitValue();
|
|
175 |
|
|
176 |
// Calculate element's preferred width
|
|
177 |
qreal prefWidth = 0.0;
|
|
178 |
qreal textWidth = 0.0;
|
|
179 |
qreal horizontalSpacing = 0.0;
|
|
180 |
|
|
181 |
textWidth = 8.04 * unitInPixels; // pix (according to UI spec)
|
|
182 |
style.parameter(QString("hb-param-margin-gene-middle-horizontal"),
|
|
183 |
horizontalSpacing, deviceProfile);
|
|
184 |
prefWidth = horizontalSpacing * 2 + textWidth;
|
|
185 |
|
|
186 |
return prefWidth;
|
|
187 |
}
|
|
188 |
|
|
189 |
/*!
|
|
190 |
\brief Calculates the height of hour element according to UI spec.
|
|
191 |
|
|
192 |
\return Calculated height of hour element
|
|
193 |
*/
|
|
194 |
qreal CalenDayUtils::calculateHourElementHeight() const
|
|
195 |
{
|
|
196 |
HbStyle style;
|
|
197 |
HbDeviceProfile deviceProfile;
|
|
198 |
|
|
199 |
qreal unitInPixels = deviceProfile.unitValue();
|
|
200 |
|
|
201 |
// Calculate element's preferred height
|
|
202 |
qreal prefHeight = 0.0;
|
|
203 |
qreal textHeight = 0.0;
|
|
204 |
qreal verticalSpacing = 0.0;
|
|
205 |
|
|
206 |
qreal bottomSpacer = 3.0 * unitInPixels;
|
|
207 |
style.parameter(QString("hb-param-text-height-secondary"), textHeight,
|
|
208 |
deviceProfile);
|
|
209 |
style.parameter(QString("hb-param-margin-gene-middle-vertical"),
|
|
210 |
verticalSpacing, deviceProfile);
|
|
211 |
|
|
212 |
prefHeight = textHeight * 2; //time + ampm
|
|
213 |
prefHeight += verticalSpacing * 2;
|
|
214 |
prefHeight += bottomSpacer;
|
|
215 |
|
|
216 |
return prefHeight;
|
|
217 |
}
|