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: CalenDayHourScrollArea implementation.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// System includes
|
|
19 |
#include <QGraphicsLinearLayout>
|
|
20 |
|
|
21 |
// User includes
|
|
22 |
#include "calendayhourscrollarea.h"
|
|
23 |
#include "calendayhourelement.h"
|
|
24 |
#include "calendayutils.h"
|
|
25 |
|
|
26 |
/*!
|
|
27 |
\class CalenDayHourScrollArea
|
|
28 |
\brief Scrollable container class for hour elements.
|
|
29 |
|
|
30 |
It handles vertical scrolling.
|
|
31 |
*/
|
|
32 |
|
|
33 |
/*!
|
|
34 |
\brief Constructor
|
|
35 |
|
|
36 |
Configures scroll area settings and resets internal stares of widget.
|
|
37 |
Gets the width of device.
|
|
38 |
|
|
39 |
\param parent The parent of scroll area widget
|
|
40 |
*/
|
|
41 |
CalenDayHourScrollArea::CalenDayHourScrollArea(QGraphicsItem *parent) :
|
57
|
42 |
HbScrollArea(parent), mDateTime(QDateTime())
|
45
|
43 |
{
|
57
|
44 |
// Grab pan gestures
|
55
|
45 |
grabGesture(Qt::PanGesture);
|
45
|
46 |
|
|
47 |
// Create widget for hour elements
|
|
48 |
HbWidget *hourWidget = new HbWidget();
|
|
49 |
|
|
50 |
// Create and insert hour elements into vertical layout
|
|
51 |
QGraphicsLinearLayout* hourLayout = new QGraphicsLinearLayout(Qt::Vertical,
|
|
52 |
NULL);
|
57
|
53 |
for (int i = 0; i < KCalenHoursInDay; i++) {
|
45
|
54 |
CalenDayHourElement* element = new CalenDayHourElement(QTime(i, 0),
|
|
55 |
this);
|
|
56 |
hourLayout->addItem(element);
|
|
57 |
mHourElements.append(element);
|
|
58 |
}
|
|
59 |
hourLayout->setContentsMargins(0.0, 0.0, 0.0, 0.0);
|
|
60 |
hourLayout->setSpacing(0.0);
|
|
61 |
|
|
62 |
// Apply hour layout for new widget and set content widget to scroll area
|
|
63 |
hourWidget->setLayout(hourLayout);
|
|
64 |
setContentWidget(hourWidget);
|
|
65 |
}
|
|
66 |
|
|
67 |
/*!
|
|
68 |
\brief Destructor
|
|
69 |
*/
|
|
70 |
CalenDayHourScrollArea::~CalenDayHourScrollArea()
|
|
71 |
{
|
55
|
72 |
mHourElements.clear();
|
45
|
73 |
}
|
|
74 |
|
|
75 |
/*!
|
|
76 |
\brief Sets date and time for this container.
|
|
77 |
|
|
78 |
\param dateTime new date and time
|
|
79 |
*/
|
|
80 |
void CalenDayHourScrollArea::setDateTime(const QDateTime &dateTime)
|
|
81 |
{
|
|
82 |
mDateTime = dateTime;
|
|
83 |
}
|
81
|
84 |
|
45
|
85 |
/*!
|
|
86 |
\brief Returns date and time assigned to current view.
|
|
87 |
*/
|
|
88 |
QDateTime CalenDayHourScrollArea::dateTime() const
|
|
89 |
{
|
|
90 |
return mDateTime;
|
|
91 |
}
|
|
92 |
|
|
93 |
/*!
|
|
94 |
\brief Scroll view to given hour.
|
|
95 |
|
57
|
96 |
\param An hour in 24 hour format (0 - 23)
|
45
|
97 |
*/
|
|
98 |
void CalenDayHourScrollArea::scrollToHour(int hour)
|
|
99 |
{
|
57
|
100 |
Q_ASSERT((hour > -1) && (hour < KCalenHoursInDay));
|
|
101 |
|
45
|
102 |
CalenDayHourElement *hourElement = mHourElements.at(hour);
|
|
103 |
QRectF hourElementRect = hourElement->rect();
|
|
104 |
hourElementRect = hourElement->mapRectToParent(hourElementRect);
|
|
105 |
QPointF newPos = hourElementRect.topLeft();
|
|
106 |
|
57
|
107 |
// Ensure that we won't scroll out of bound
|
45
|
108 |
CalenDayHourElement *lastElement = mHourElements.last();
|
|
109 |
qreal bottomEdge = lastElement->mapRectToParent(lastElement->rect()).bottom();
|
|
110 |
qreal viewHeight = rect().height();
|
|
111 |
|
57
|
112 |
if (bottomEdge - newPos.y() < viewHeight) {
|
45
|
113 |
newPos.setY(bottomEdge - viewHeight);
|
|
114 |
}
|
|
115 |
|
|
116 |
scrollContentsTo(newPos);
|
|
117 |
}
|
|
118 |
|
81
|
119 |
/*!
|
|
120 |
\brief SLOT scrolls the view vertically to new position.
|
|
121 |
|
|
122 |
\param newPosition New position
|
|
123 |
*/
|
|
124 |
void CalenDayHourScrollArea::scrollVertically(const QPointF &newPosition)
|
|
125 |
{
|
|
126 |
QPointF currentPos = contentWidget()->pos();
|
|
127 |
if (abs(newPosition.y()) != abs(currentPos.y())) {
|
|
128 |
currentPos.setY(newPosition.y());
|
|
129 |
scrollContentsTo(currentPos, 0);
|
|
130 |
}
|
|
131 |
}
|
|
132 |
|
|
133 |
/*!
|
|
134 |
\brief SLOT updates time/date representation when system locale are changed.
|
|
135 |
*/
|
|
136 |
void CalenDayHourScrollArea::localeChanged()
|
|
137 |
{
|
|
138 |
for (int i = 0; i < mHourElements.count(); i++) {
|
|
139 |
mHourElements.at(i)->localeChanged();
|
|
140 |
mHourElements.at(i)->update(mHourElements.at(i)->rect());
|
|
141 |
}
|
|
142 |
}
|
|
143 |
|
|
144 |
/*!
|
|
145 |
\brief SLOT refreshes time indicator if current day is displayed.
|
|
146 |
|
|
147 |
Time indicator should also be updated if transition between prev/next
|
|
148 |
day was done previously: failure ou1cimx1#565650 fixed
|
|
149 |
*/
|
|
150 |
void CalenDayHourScrollArea::updateTimeIndicator()
|
|
151 |
{
|
|
152 |
QDateTime currentDateTime = QDateTime::currentDateTime();
|
|
153 |
|
|
154 |
bool updateNeeded = mDateTime.date() >= currentDateTime.date().addDays(-1);
|
|
155 |
updateNeeded = updateNeeded && mDateTime.date() <= currentDateTime.date().addDays(1);
|
|
156 |
|
|
157 |
if (updateNeeded) {
|
|
158 |
for (int i = 0; i < mHourElements.count(); i++) {
|
|
159 |
mHourElements.at(i)->update(mHourElements.at(i)->rect());
|
|
160 |
}
|
|
161 |
}
|
|
162 |
}
|
|
163 |
|
45
|
164 |
// End of File
|