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: CalenDayContentWidget implementation.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// System includes
|
|
19 |
#include <QGraphicsLinearLayout>
|
63
|
20 |
#include <HbModelIterator>
|
45
|
21 |
|
|
22 |
// User includes
|
|
23 |
#include "calendaymodelmanager.h"
|
|
24 |
#include "calendaycontentwidget.h"
|
|
25 |
#include "calendayitemview.h"
|
|
26 |
#include "calendaycontentscrollarea.h"
|
|
27 |
|
|
28 |
/*!
|
|
29 |
\class CalenDayContentWidget
|
|
30 |
\brief Content widget is a container class for horizontal layouted widgets.
|
|
31 |
*/
|
|
32 |
|
|
33 |
/*!
|
|
34 |
\brief Constructor
|
|
35 |
|
63
|
36 |
\param modelManager Day View model manager
|
45
|
37 |
\param parent The parent of central widget
|
|
38 |
*/
|
|
39 |
CalenDayContentWidget::CalenDayContentWidget(
|
|
40 |
CalenDayModelManager &modelManager,
|
|
41 |
QGraphicsItem *parent) :
|
|
42 |
HbWidget(parent), mLayout(NULL), mModelManager(modelManager)
|
|
43 |
{
|
|
44 |
mWidgets.clear();
|
63
|
45 |
initializeViews();
|
45
|
46 |
}
|
|
47 |
|
|
48 |
/*!
|
|
49 |
\brief Destructor
|
|
50 |
*/
|
|
51 |
CalenDayContentWidget::~CalenDayContentWidget()
|
|
52 |
{
|
|
53 |
// Just clear widget list - parent object will destroy its children
|
|
54 |
mWidgets.clear();
|
|
55 |
}
|
|
56 |
|
|
57 |
/*!
|
|
58 |
\brief Adds the widget to central widget and layouts it horizontally.
|
|
59 |
|
|
60 |
Ownership of item is passed to CalenDayContentWidget.
|
|
61 |
|
|
62 |
\param item Widget to be added
|
|
63 |
\param where Place where widget should be added (as first/last item)
|
|
64 |
*/
|
|
65 |
void CalenDayContentWidget::add(HbWidget* item, CalenWidgetPosition where)
|
|
66 |
{
|
|
67 |
// Create linear, horizontal layout if not exist
|
|
68 |
if (!mLayout) {
|
|
69 |
mLayout = new QGraphicsLinearLayout(Qt::Horizontal, NULL);
|
|
70 |
mLayout->setContentsMargins(0.0, 0.0, 0.0, 0.0);
|
|
71 |
mLayout->setSpacing(0.0);
|
|
72 |
}
|
|
73 |
|
|
74 |
switch (where) {
|
|
75 |
case ECalenFirstWidget: {
|
|
76 |
mLayout->insertItem(0, item);
|
|
77 |
mWidgets.insert(0, item);
|
|
78 |
break;
|
|
79 |
}
|
|
80 |
case ECalenLastWidget:
|
|
81 |
default: {
|
|
82 |
mLayout->addItem(item);
|
|
83 |
mWidgets.append(item);
|
|
84 |
}
|
|
85 |
}
|
|
86 |
|
|
87 |
// If layout has no parent - apply it to central widget
|
|
88 |
if (mLayout && !mLayout->parentLayoutItem()) {
|
|
89 |
setLayout(mLayout);
|
|
90 |
}
|
|
91 |
}
|
|
92 |
|
|
93 |
/*!
|
|
94 |
\brief Takes the widget and removes it from central widget.
|
|
95 |
|
|
96 |
Ownership of item is passed to caller.
|
|
97 |
|
|
98 |
\param which Indicates which widget should be taken (first/last)
|
|
99 |
\return Pointer to HbWidget or NULL if widget was not found
|
|
100 |
*/
|
|
101 |
HbWidget* CalenDayContentWidget::take(CalenWidgetPosition which)
|
|
102 |
{
|
|
103 |
Q_ASSERT(mLayout);
|
|
104 |
|
|
105 |
HbWidget* itemToTake = NULL;
|
|
106 |
switch (which) {
|
|
107 |
case ECalenFirstWidget: {
|
|
108 |
itemToTake = mWidgets.takeFirst();
|
|
109 |
break;
|
|
110 |
}
|
|
111 |
case ECalenLastWidget:
|
|
112 |
default: {
|
|
113 |
itemToTake = mWidgets.takeLast();
|
|
114 |
}
|
|
115 |
}
|
|
116 |
|
|
117 |
if (itemToTake) {
|
|
118 |
mLayout->removeItem(itemToTake);
|
|
119 |
}
|
|
120 |
|
|
121 |
return itemToTake;
|
|
122 |
}
|
|
123 |
|
|
124 |
/*!
|
|
125 |
\brief Removed the widget from central widget.
|
|
126 |
|
|
127 |
Widget is removed and deleted.
|
|
128 |
|
|
129 |
\param which Indicates which widget should be removed (first/last)
|
|
130 |
*/
|
|
131 |
void CalenDayContentWidget::remove(CalenWidgetPosition which)
|
|
132 |
{
|
|
133 |
Q_ASSERT(mLayout);
|
|
134 |
|
|
135 |
HbWidget* itemToRemove = NULL;
|
|
136 |
switch (which) {
|
|
137 |
case ECalenFirstWidget: {
|
|
138 |
itemToRemove = mWidgets.takeFirst();
|
|
139 |
break;
|
|
140 |
}
|
|
141 |
case ECalenLastWidget:
|
|
142 |
default: {
|
|
143 |
itemToRemove = mWidgets.takeLast();
|
|
144 |
}
|
|
145 |
}
|
|
146 |
|
|
147 |
if (itemToRemove) {
|
|
148 |
mLayout->removeItem(itemToRemove);
|
|
149 |
delete itemToRemove;
|
|
150 |
}
|
|
151 |
}
|
|
152 |
|
|
153 |
/*!
|
|
154 |
\brief Performs relayout of widgets when it is needed.
|
|
155 |
|
|
156 |
Relayout is done depending on last scroll move:
|
|
157 |
- if widget was scrolled to next: first widget is taken and added as last
|
|
158 |
- if widget was scrolled to prev: last widget is taken and inserted as first
|
|
159 |
|
|
160 |
Emits widgetsRelayoutFinished SIGNAL when relayout is over.
|
|
161 |
|
|
162 |
\param scrollTo Direction of last movement
|
|
163 |
*/
|
|
164 |
void CalenDayContentWidget::relayoutWidgets(CalenScrollDirection scrollTo)
|
|
165 |
{
|
|
166 |
HbWidget* widget = NULL;
|
|
167 |
switch (scrollTo) {
|
|
168 |
case ECalenScrollToNext: {
|
|
169 |
widget = take(ECalenFirstWidget);
|
|
170 |
add(widget, ECalenLastWidget);
|
|
171 |
break;
|
|
172 |
}
|
|
173 |
case ECalenScrollToPrev:
|
|
174 |
default: {
|
|
175 |
widget = take(ECalenLastWidget);
|
|
176 |
add(widget, ECalenFirstWidget);
|
|
177 |
}
|
|
178 |
}
|
|
179 |
emit widgetsRelayoutFinished(scrollTo);
|
|
180 |
}
|
|
181 |
|
|
182 |
/*!
|
|
183 |
\brief SLOT handles simultanous vertical scrolling of owned widgets.
|
|
184 |
|
|
185 |
\param newPos New scroll position
|
|
186 |
*/
|
|
187 |
void CalenDayContentWidget::widgetScrolled(const QPointF &newPos)
|
|
188 |
{
|
|
189 |
for (int i = 0; i < mWidgets.count(); i++) {
|
|
190 |
CalenDayItemView *view =
|
|
191 |
static_cast<CalenDayItemView *> (mWidgets[i]);
|
|
192 |
view->scrollVertically(newPos);
|
|
193 |
}
|
|
194 |
emit scrollPositionChanged(newPos);
|
|
195 |
}
|
|
196 |
|
|
197 |
/*!
|
|
198 |
\brief Initializes content widgets and adds them to layout.
|
|
199 |
|
|
200 |
\param parent Parent object
|
|
201 |
*/
|
63
|
202 |
void CalenDayContentWidget::initializeViews()
|
45
|
203 |
{
|
|
204 |
// Create item views
|
|
205 |
HbModelIterator *iterator(0);
|
|
206 |
|
|
207 |
iterator = new HbModelIterator(&mModelManager.getModel(
|
|
208 |
CalenDayModelManager::PreviousDay));
|
|
209 |
CalenDayItemView *prevItemView = new CalenDayItemView(
|
|
210 |
mModelManager.getServices(), iterator, 0);
|
|
211 |
|
|
212 |
iterator = new HbModelIterator(&mModelManager.getModel(
|
|
213 |
CalenDayModelManager::CurrentDay));
|
|
214 |
CalenDayItemView *currItemView = new CalenDayItemView(
|
|
215 |
mModelManager.getServices(), iterator, 0);
|
|
216 |
|
|
217 |
iterator = new HbModelIterator(&mModelManager.getModel(
|
|
218 |
CalenDayModelManager::NextDay));
|
|
219 |
CalenDayItemView *nextItemView = new CalenDayItemView(
|
|
220 |
mModelManager.getServices(), iterator, 0);
|
|
221 |
|
|
222 |
// Connecting views with widgetScrolled SLOT
|
|
223 |
// to support simultanous vertical scrolling
|
|
224 |
connect(prevItemView, SIGNAL(scrollPositionChanged(const QPointF&)), this,
|
|
225 |
SLOT(widgetScrolled(const QPointF&)));
|
|
226 |
connect(currItemView, SIGNAL(scrollPositionChanged(const QPointF&)), this,
|
|
227 |
SLOT(widgetScrolled(const QPointF&)));
|
|
228 |
connect(nextItemView, SIGNAL(scrollPositionChanged(const QPointF&)), this,
|
|
229 |
SLOT(widgetScrolled(const QPointF&)));
|
|
230 |
|
63
|
231 |
if (parentItem()) {
|
|
232 |
// Install event filters to receive events necessary for gesture handling
|
|
233 |
CalenDayContentScrollArea* scrollArea =
|
|
234 |
static_cast<CalenDayContentScrollArea*> (parentItem());
|
|
235 |
prevItemView->installEventFilter(scrollArea);
|
|
236 |
currItemView->installEventFilter(scrollArea);
|
|
237 |
nextItemView->installEventFilter(scrollArea);
|
|
238 |
}
|
45
|
239 |
|
|
240 |
// Add views to layout
|
|
241 |
add(prevItemView);
|
|
242 |
add(currItemView);
|
|
243 |
add(nextItemView);
|
|
244 |
}
|
|
245 |
|
|
246 |
// End of File
|