6
|
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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <QGesture>
|
|
19 |
#include <QPainter>
|
|
20 |
#include <QTimer>
|
|
21 |
#include <HbMainWindow>
|
|
22 |
#include <HbCheckBox>
|
|
23 |
#include <HbGridViewItem>
|
|
24 |
#include <HbGridView>
|
|
25 |
#include <HbIconItem>
|
|
26 |
#include <QAbstractItemModel>
|
|
27 |
#include <HbTapGesture>
|
17
|
28 |
|
|
29 |
#include "hgcontainer.h"
|
|
30 |
#include "hgmediawallrenderer.h"
|
|
31 |
#include "hgquad.h"
|
|
32 |
#include "hgimage.h"
|
|
33 |
#include "hgwidgetitem.h"
|
|
34 |
#include "trace.h"
|
|
35 |
#include "hgquadrenderer.h"
|
6
|
36 |
#include "hglongpressvisualizer.h"
|
|
37 |
|
17
|
38 |
|
6
|
39 |
static const qreal KSpringKScrolling(50.0);
|
17
|
40 |
static const qreal KSpringKScrollBar(50.0);
|
6
|
41 |
static const qreal KSpringDampingScrolling(20.0);
|
17
|
42 |
static const qreal KSpringDampingScrollBar(20.0);
|
6
|
43 |
static const qreal KFramesToZeroVelocity(60.0);
|
|
44 |
static const int KLongTapDuration(400);
|
|
45 |
|
|
46 |
|
|
47 |
HgContainer::HgContainer(QGraphicsItem* parent) :
|
|
48 |
HbWidget(parent),
|
|
49 |
mQuadRenderer(0),
|
|
50 |
mRenderer(0),
|
|
51 |
mTapCount(0),
|
|
52 |
mAnimateUsingScrollBar(false),
|
|
53 |
mSelectionMode(HgWidget::NoSelection),
|
|
54 |
mSelectionModel(0),
|
|
55 |
mMarkImageOn(0),
|
|
56 |
mMarkImageOff(0),
|
|
57 |
mSpringVelAtDragStart(0),
|
|
58 |
mDragged(false),
|
|
59 |
mFramesDragged(0),
|
|
60 |
mHitItemView(NULL),
|
|
61 |
mLongPressVisualizer(NULL),
|
|
62 |
mLongPressTimer(NULL),
|
|
63 |
mHitItemIndex(-1),
|
|
64 |
mItemSizePolicy(HgWidget::ItemSizeAutomatic),
|
|
65 |
mOrientation(Qt::Vertical),
|
|
66 |
mDelayedScrollToIndex(),
|
12
|
67 |
mIgnoreGestureAction(false),
|
|
68 |
mHandleLongPress(false)
|
6
|
69 |
{
|
|
70 |
FUNC_LOG;
|
|
71 |
|
|
72 |
setFlag(QGraphicsItem::ItemHasNoContents, false);
|
|
73 |
|
|
74 |
grabGesture(Qt::PanGesture);
|
|
75 |
grabGesture(Qt::TapGesture);
|
|
76 |
}
|
|
77 |
|
|
78 |
HgContainer::~HgContainer()
|
|
79 |
{
|
|
80 |
FUNC_LOG;
|
|
81 |
|
|
82 |
qDeleteAll(mItems);
|
|
83 |
mItems.clear();
|
|
84 |
delete mMarkImageOn;
|
|
85 |
delete mMarkImageOff;
|
|
86 |
delete mRenderer;
|
|
87 |
}
|
|
88 |
|
|
89 |
void HgContainer::setItemCount(int itemCount)
|
|
90 |
{
|
|
91 |
FUNC_LOG;
|
|
92 |
|
|
93 |
qDeleteAll(mItems);
|
|
94 |
mItems.clear();
|
|
95 |
for (int i=0; i<itemCount; i++) {
|
|
96 |
HgWidgetItem* item = new HgWidgetItem(mQuadRenderer);
|
|
97 |
mItems.append(item);
|
|
98 |
}
|
|
99 |
}
|
|
100 |
|
11
|
101 |
// TODO: This does exactly the same as HgContainer::imageCount(), should this be thus removed?
|
6
|
102 |
int HgContainer::itemCount() const
|
|
103 |
{
|
|
104 |
return mItems.count();
|
|
105 |
}
|
|
106 |
|
17
|
107 |
int HgContainer::currentRowCount() const
|
6
|
108 |
{
|
|
109 |
return mRenderer ? mRenderer->getRowCount() : 0;
|
|
110 |
}
|
|
111 |
|
|
112 |
QList<HgWidgetItem*> HgContainer::items() const
|
|
113 |
{
|
|
114 |
return mItems;
|
|
115 |
}
|
|
116 |
|
|
117 |
HgWidgetItem* HgContainer::itemByIndex(const QModelIndex& index) const
|
|
118 |
{
|
|
119 |
foreach (HgWidgetItem* item, mItems) {
|
|
120 |
if (item->modelIndex() == index)
|
|
121 |
return item;
|
|
122 |
}
|
|
123 |
|
|
124 |
return 0;
|
|
125 |
}
|
|
126 |
|
|
127 |
HgWidgetItem* HgContainer::itemByIndex(const int& index) const
|
|
128 |
{
|
|
129 |
if (mItems.count() > index && index >= 0)
|
|
130 |
return mItems.at(index);
|
|
131 |
else
|
|
132 |
return 0;
|
|
133 |
}
|
|
134 |
|
|
135 |
/*!
|
|
136 |
Changes the selection model of the container.
|
|
137 |
Ownership is not transferred.
|
|
138 |
Widget is redrawn to make new selection visible.
|
|
139 |
*/
|
|
140 |
void HgContainer::setSelectionModel(QItemSelectionModel *selectionModel, const QModelIndex &defaultItem)
|
|
141 |
{
|
|
142 |
FUNC_LOG;
|
|
143 |
HANDLE_ERROR_NULL(selectionModel); // Parameter is always a valid QItemSelectionModel
|
|
144 |
|
|
145 |
if (mSelectionModel == selectionModel) return;
|
|
146 |
|
|
147 |
bool defaultCurrentSet(false);
|
|
148 |
|
|
149 |
if (!selectionModel->currentIndex().isValid()) { // If there is valid current item, do not change it
|
|
150 |
if (!mSelectionModel && defaultItem.isValid()) { // mSelectionModel is 0 when called first time
|
|
151 |
selectionModel->setCurrentIndex(defaultItem, QItemSelectionModel::Current);
|
|
152 |
defaultCurrentSet = true;
|
|
153 |
}
|
|
154 |
else if (mSelectionModel && mSelectionModel->currentIndex().isValid()) {
|
|
155 |
selectionModel->setCurrentIndex(mSelectionModel->currentIndex(),
|
|
156 |
QItemSelectionModel::Current);
|
|
157 |
}
|
|
158 |
}
|
|
159 |
|
|
160 |
mSelectionModel = selectionModel;
|
|
161 |
|
|
162 |
if (mSelectionModel->currentIndex().isValid() && !defaultCurrentSet) {
|
|
163 |
scrollTo(mSelectionModel->currentIndex());
|
|
164 |
}
|
|
165 |
else {
|
|
166 |
update();
|
|
167 |
}
|
|
168 |
}
|
|
169 |
|
|
170 |
/*!
|
|
171 |
Returns the selection model of the container.
|
|
172 |
Ownership is not transferred.
|
|
173 |
*/
|
|
174 |
QItemSelectionModel *HgContainer::selectionModel() const
|
|
175 |
{
|
|
176 |
FUNC_LOG;
|
|
177 |
|
|
178 |
return mSelectionModel;
|
|
179 |
}
|
|
180 |
|
|
181 |
/*!
|
|
182 |
Changes the selection mode of the container (no selection/multiselection).
|
|
183 |
*/
|
|
184 |
void HgContainer::setSelectionMode(HgWidget::SelectionMode mode, bool resetSelection)
|
|
185 |
{
|
|
186 |
FUNC_LOG;
|
|
187 |
|
|
188 |
if (mSelectionMode != mode) {
|
|
189 |
mSelectionMode = mode;
|
|
190 |
|
|
191 |
if (mSelectionModel && resetSelection) {
|
|
192 |
mSelectionModel->clearSelection();
|
|
193 |
update();
|
|
194 |
}
|
|
195 |
}
|
|
196 |
}
|
|
197 |
|
|
198 |
/*!
|
|
199 |
Returns the selection mode of the container (no selection/multiselection).
|
|
200 |
*/
|
|
201 |
HgWidget::SelectionMode HgContainer::selectionMode() const
|
|
202 |
{
|
|
203 |
FUNC_LOG;
|
|
204 |
|
|
205 |
return mSelectionMode;
|
|
206 |
}
|
|
207 |
|
|
208 |
void HgContainer::dimensions(qreal &screenSize, qreal &worldSize)
|
|
209 |
{
|
|
210 |
const QRectF containerRect(rect());
|
|
211 |
|
|
212 |
if (scrollDirection()== Qt::Vertical) {
|
|
213 |
// assume we are in portrait mode, ofcource this might not be the case
|
|
214 |
screenSize = containerRect.height()/(mRenderer->getImageSize().height() + mRenderer->getSpacing().height());
|
|
215 |
worldSize = worldWidth();
|
|
216 |
}
|
|
217 |
else{
|
|
218 |
screenSize = containerRect.width()/(mRenderer->getImageSize().width() + mRenderer->getSpacing().width());
|
|
219 |
worldSize = worldWidth();
|
|
220 |
}
|
|
221 |
}
|
|
222 |
|
|
223 |
Qt::Orientation HgContainer::orientation() const
|
|
224 |
{
|
|
225 |
FUNC_LOG;
|
|
226 |
|
|
227 |
return mOrientation;
|
|
228 |
}
|
|
229 |
|
|
230 |
void HgContainer::setOrientation(Qt::Orientation orientation, bool animate)
|
|
231 |
{
|
|
232 |
FUNC_LOG;
|
|
233 |
|
|
234 |
mOrientation = orientation;
|
|
235 |
mRenderer->setOrientation(orientation);
|
|
236 |
mRenderer->setScrollDirection(orientation, animate);
|
|
237 |
if (mSpring.isActive()) {
|
|
238 |
// Need to stop scrolling.
|
|
239 |
mSpring.cancel();
|
|
240 |
}
|
|
241 |
}
|
|
242 |
|
|
243 |
void HgContainer::scrollToPosition(qreal value, bool animate)
|
|
244 |
{
|
|
245 |
FUNC_LOG;
|
|
246 |
|
|
247 |
scrollToPosition(QPointF(value*worldWidth(), 0), animate);
|
|
248 |
}
|
|
249 |
|
|
250 |
void HgContainer::scrollToPosition(const QPointF& pos, bool animate)
|
|
251 |
{
|
|
252 |
FUNC_LOG;
|
|
253 |
|
|
254 |
mAnimateUsingScrollBar = animate;
|
|
255 |
initSpringForScrollBar();
|
|
256 |
|
|
257 |
if (animate)
|
|
258 |
mSpring.animateToPos(pos);
|
|
259 |
else
|
|
260 |
mSpring.gotoPos(pos);
|
|
261 |
}
|
|
262 |
|
|
263 |
void HgContainer::scrollTo(const QModelIndex &index)
|
|
264 |
{
|
|
265 |
FUNC_LOG;
|
|
266 |
INFO("Scrolling to" << index);
|
|
267 |
|
|
268 |
if (index.isValid() && mRenderer->getRowCount() > 0 ) {
|
|
269 |
|
|
270 |
QRectF containerRect(rect());
|
|
271 |
if (containerRect.isNull()) {
|
|
272 |
// Container hasn't been resized yet. We need to know the container
|
|
273 |
// size before we can calculate if index we are scrolling to is valid.
|
|
274 |
// Store scrollTo index and scrolling is performed when container is resized.
|
|
275 |
mDelayedScrollToIndex = index;
|
|
276 |
return;
|
|
277 |
}
|
|
278 |
|
|
279 |
// Container has some size. We can try to calculate if scrollto index is valid.
|
|
280 |
// ScrollTo index will be the top item in grid and left item on coverflow.
|
|
281 |
|
|
282 |
if (!mRenderer->coverflowModeEnabled()) {
|
|
283 |
// Grid case
|
|
284 |
int itemsOnScreen = 0;
|
|
285 |
if (scrollDirection()== Qt::Vertical) {
|
|
286 |
const int rowHeight = mRenderer->getImageSize().height() + mRenderer->getSpacing().height();
|
|
287 |
itemsOnScreen = containerRect.height()/rowHeight;
|
|
288 |
if ((int)containerRect.height()%rowHeight) {
|
|
289 |
itemsOnScreen++;
|
|
290 |
}
|
17
|
291 |
itemsOnScreen *= currentRowCount();
|
6
|
292 |
if (itemsOnScreen + index.row() > mItems.count()) {
|
|
293 |
int newItem = mItems.count()-itemsOnScreen;
|
|
294 |
|
17
|
295 |
if (mItems.count()%currentRowCount())
|
|
296 |
newItem += currentRowCount() - (mItems.count()%currentRowCount());
|
6
|
297 |
if (newItem < 0)
|
|
298 |
newItem = 0;
|
|
299 |
|
|
300 |
scrollToPosition(QPointF(newItem/mRenderer->getRowCount(),0), false);
|
|
301 |
} else {
|
|
302 |
scrollToPosition(QPointF(index.row()/mRenderer->getRowCount(), 0), false);
|
|
303 |
}
|
|
304 |
} else {
|
|
305 |
// Scrolldirection is horizontal
|
|
306 |
const int rowWidth = mRenderer->getImageSize().width() + mRenderer->getSpacing().width();
|
|
307 |
itemsOnScreen = containerRect.width()/rowWidth;
|
|
308 |
if ((int)containerRect.height()%rowWidth) {
|
|
309 |
itemsOnScreen++;
|
|
310 |
}
|
17
|
311 |
itemsOnScreen *= currentRowCount();
|
6
|
312 |
if (itemsOnScreen + index.row() > mItems.count()) {
|
|
313 |
int newItem = mItems.count()-itemsOnScreen;
|
|
314 |
|
17
|
315 |
if (mItems.count()%currentRowCount())
|
|
316 |
newItem += currentRowCount() - (mItems.count()%currentRowCount());
|
6
|
317 |
if (newItem < 0) newItem = 0;
|
|
318 |
|
|
319 |
scrollToPosition(QPointF(newItem/mRenderer->getRowCount(),0), false);
|
|
320 |
} else {
|
|
321 |
scrollToPosition(QPointF(index.row()/mRenderer->getRowCount(), 0), false);
|
|
322 |
}
|
|
323 |
}
|
|
324 |
updateBySpringPosition();
|
|
325 |
} else {
|
|
326 |
// Coverflow case. TODO, this will need some finetuning.
|
|
327 |
scrollToPosition(QPointF(index.row()/mRenderer->getRowCount(), 0), false);
|
|
328 |
updateBySpringPosition();
|
|
329 |
}
|
|
330 |
}
|
|
331 |
}
|
|
332 |
|
|
333 |
void HgContainer::itemDataChanged(const QModelIndex &firstIndex, const QModelIndex &lastIndex)
|
|
334 |
{
|
|
335 |
FUNC_LOG;
|
|
336 |
|
|
337 |
// TODO, fix this
|
|
338 |
int columns = firstIndex.model()->columnCount(QModelIndex());
|
|
339 |
|
|
340 |
// Check this!!
|
|
341 |
int index = columns*firstIndex.row()+firstIndex.column();
|
|
342 |
int index2 = columns*lastIndex.row()+lastIndex.column();
|
|
343 |
|
|
344 |
// convert indeces to match one dimensional item array
|
|
345 |
itemDataChanged( index, index2 );
|
|
346 |
}
|
|
347 |
|
|
348 |
void HgContainer::addItems(int start, int end)
|
|
349 |
{
|
|
350 |
FUNC_LOG;
|
|
351 |
HANDLE_ERROR_NULL(mSelectionModel);
|
|
352 |
|
|
353 |
int first = qBound(0, start, mItems.count()-1);
|
|
354 |
int last = qBound(0, end, mItems.count()-1);
|
|
355 |
for (int i = 0; i <= end-start; i++) {
|
|
356 |
HgWidgetItem* item = new HgWidgetItem(mQuadRenderer);
|
|
357 |
mItems.insert(start, item);
|
|
358 |
}
|
|
359 |
scrollTo(mSelectionModel->currentIndex());
|
|
360 |
}
|
|
361 |
|
|
362 |
void HgContainer::removeItems(int start, int end)
|
|
363 |
{
|
|
364 |
FUNC_LOG;
|
|
365 |
HANDLE_ERROR_NULL(mSelectionModel);
|
|
366 |
|
|
367 |
int first = qBound(0, start, mItems.count()-1);
|
|
368 |
int last = qBound(0, end, mItems.count()-1);
|
|
369 |
for (int i = last; i >= first; i--) {
|
|
370 |
delete mItems.at(i);
|
|
371 |
mItems.removeAt(i);
|
|
372 |
}
|
|
373 |
scrollTo(mSelectionModel->currentIndex());
|
|
374 |
}
|
|
375 |
|
|
376 |
void HgContainer::moveItems(int start, int end, int destination)
|
|
377 |
{
|
|
378 |
FUNC_LOG;
|
|
379 |
HANDLE_ERROR_NULL(mSelectionModel);
|
|
380 |
|
|
381 |
int first = qBound(0, start, mItems.count()-1);
|
|
382 |
int last = qBound(0, end, mItems.count()-1);
|
|
383 |
int target = qBound(0, destination, mItems.count()-1);
|
|
384 |
|
|
385 |
if (target < first) {
|
|
386 |
for (int i = 0; i <= last-first; i++) {
|
|
387 |
mItems.move(first+i, target+i);
|
|
388 |
}
|
|
389 |
}
|
|
390 |
else if (target > last) {
|
|
391 |
for (int i = 0; i <= last-first; i++) {
|
|
392 |
mItems.move(last-i, target);
|
|
393 |
}
|
|
394 |
}
|
|
395 |
// else do nothing
|
|
396 |
scrollTo(mSelectionModel->currentIndex());
|
|
397 |
}
|
|
398 |
|
11
|
399 |
// TODO: This does exactly the same as HgContainer::itemCount(), should this be thus removed?
|
6
|
400 |
int HgContainer::imageCount() const
|
|
401 |
{
|
|
402 |
return mItems.count();
|
|
403 |
}
|
|
404 |
|
|
405 |
const HgImage *HgContainer::image(int index) const
|
|
406 |
{
|
|
407 |
return mItems[index]->image();
|
|
408 |
}
|
|
409 |
|
|
410 |
int HgContainer::flags(int index) const
|
|
411 |
{
|
|
412 |
if (index >= 0 && index < itemCount()) {
|
|
413 |
if (mSelectionMode != HgWidget::NoSelection) {
|
17
|
414 |
if (mSelectionModel &&
|
|
415 |
mSelectionModel->model() &&
|
|
416 |
mSelectionModel->isSelected(mSelectionModel->model()->index(index, 0))) {
|
6
|
417 |
return 1; // TODO: Assign flag to mark indicator
|
|
418 |
} else
|
|
419 |
return 2;
|
|
420 |
}
|
|
421 |
}
|
|
422 |
return 0;
|
|
423 |
}
|
|
424 |
|
12
|
425 |
const HgImage *HgContainer::indicator(int flags)
|
6
|
426 |
{
|
12
|
427 |
if (flags != 0 && (!mMarkImageOff || !mMarkImageOn)) {
|
|
428 |
// indicators haven't been loaded yet.
|
|
429 |
loadIndicatorGraphics();
|
|
430 |
}
|
|
431 |
|
6
|
432 |
if (flags & 1) {
|
|
433 |
return mMarkImageOn;
|
|
434 |
}
|
|
435 |
else if (flags & 2) {
|
|
436 |
return mMarkImageOff;
|
|
437 |
}
|
|
438 |
|
|
439 |
return 0;
|
|
440 |
}
|
|
441 |
|
|
442 |
void HgContainer::updateBySpringPosition()
|
|
443 |
{
|
|
444 |
// spring works always in one dimension, that is, x coord.
|
|
445 |
qreal pos = mSpring.pos().x();
|
|
446 |
|
|
447 |
onScrollPositionChanged(pos);
|
|
448 |
|
|
449 |
emit scrollPositionChanged(pos, mAnimateUsingScrollBar);
|
|
450 |
update();
|
|
451 |
}
|
|
452 |
|
|
453 |
void HgContainer::redraw()
|
|
454 |
{
|
|
455 |
update();
|
|
456 |
}
|
|
457 |
|
|
458 |
void HgContainer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
459 |
{
|
|
460 |
Q_UNUSED(option)
|
|
461 |
Q_UNUSED(widget)
|
14
|
462 |
|
6
|
463 |
// update spring position at paint if needed,
|
|
464 |
// this is hack for scrollbar, since dragging it
|
|
465 |
// causes also paint events in here
|
|
466 |
if (mSpring.updatePositionIfNeeded())
|
|
467 |
{
|
|
468 |
qreal pos = mSpring.pos().x();
|
|
469 |
onScrollPositionChanged(pos);
|
|
470 |
emit scrollPositionChanged(pos, true);
|
|
471 |
}
|
|
472 |
|
|
473 |
QPainter::RenderHints hints = painter->renderHints();
|
|
474 |
painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
|
|
475 |
|
|
476 |
// interpolate spring velocity towards zero, this is done
|
|
477 |
// so that spring velocity for rendering doesn't drop directly to
|
|
478 |
// zero when dragging starts
|
|
479 |
qreal springVel = mSpring.velocity().x();
|
|
480 |
if (mDragged) {
|
|
481 |
qreal t = qBound(mFramesDragged / KFramesToZeroVelocity, 0.0f, 1.0f);
|
|
482 |
springVel = mSpringVelAtDragStart * (1.0f - t);
|
|
483 |
mFramesDragged++;
|
|
484 |
}
|
|
485 |
|
|
486 |
// setup rendering and draw the current view
|
|
487 |
mRenderer->setCameraDistance(getCameraDistance(springVel));
|
|
488 |
mRenderer->setCameraRotationY(getCameraRotationY(springVel));
|
|
489 |
mRenderer->draw(mSpring.startPos(), mSpring.pos(), mSpring.endPos(),
|
|
490 |
springVel, painter, sceneTransform(), rect());
|
|
491 |
|
|
492 |
painter->setRenderHint(QPainter::SmoothPixmapTransform, (hints.testFlag(QPainter::SmoothPixmapTransform)) );
|
|
493 |
}
|
|
494 |
|
|
495 |
void HgContainer::resizeEvent(QGraphicsSceneResizeEvent *event)
|
|
496 |
{
|
|
497 |
FUNC_LOG;
|
|
498 |
|
|
499 |
HbWidget::resizeEvent(event);
|
|
500 |
|
|
501 |
if (mDelayedScrollToIndex.isValid()) {
|
|
502 |
scrollTo(mDelayedScrollToIndex);
|
|
503 |
// set scrollto index to invalid value.
|
|
504 |
mDelayedScrollToIndex = QModelIndex();
|
|
505 |
}
|
12
|
506 |
// Indicator size depends from the item size so
|
|
507 |
// indicators need to be updated. Indicators are created
|
|
508 |
// in runtime only for need so if they dont exists they aren't created.
|
|
509 |
loadIndicatorGraphics(true);
|
6
|
510 |
}
|
|
511 |
|
|
512 |
// this needs to be implemented for gesture framework to work
|
|
513 |
void HgContainer::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
514 |
{
|
|
515 |
Q_UNUSED(event);
|
|
516 |
}
|
|
517 |
|
|
518 |
void HgContainer::gestureEvent(QGestureEvent *event)
|
|
519 |
{
|
|
520 |
FUNC_LOG;
|
|
521 |
|
|
522 |
if (mItems.count() == 0) {
|
|
523 |
// we have no items so no need to handle the gesture.
|
|
524 |
event->ignore();
|
|
525 |
return;
|
|
526 |
}
|
|
527 |
|
|
528 |
bool eventHandled(false);
|
|
529 |
// Event may contain more than one gesture type
|
|
530 |
HbTapGesture *tap = 0;
|
|
531 |
if (QGesture *gesture = event->gesture(Qt::TapGesture)) {
|
|
532 |
tap = static_cast<HbTapGesture *>(event->gesture(Qt::TapGesture));
|
12
|
533 |
if (mHandleLongPress && tap->tapStyleHint() == HbTapGesture::TapAndHold) {
|
6
|
534 |
eventHandled = handleLongTap(tap->state(),
|
|
535 |
mapFromScene(event->mapToGraphicsScene(tap->hotSpot())));
|
|
536 |
|
|
537 |
} else {
|
|
538 |
eventHandled = handleTap(tap->state(),
|
|
539 |
mapFromScene(event->mapToGraphicsScene(tap->hotSpot())));
|
|
540 |
}
|
|
541 |
}
|
|
542 |
if (QGesture *pan = event->gesture(Qt::PanGesture)) {
|
|
543 |
eventHandled = handlePanning(static_cast<QPanGesture*>(pan));
|
|
544 |
} else if( mIgnoreGestureAction && tap && tap->state() == Qt::GestureCanceled ) {
|
|
545 |
// user has tapped or long pressed in grid while scrolling so we need to
|
|
546 |
// stop the 3d effect.
|
|
547 |
mSpring.resetVelocity();
|
|
548 |
update();
|
|
549 |
mIgnoreGestureAction = false;
|
|
550 |
}
|
|
551 |
|
|
552 |
eventHandled ? event->accept() : event->ignore();
|
|
553 |
}
|
|
554 |
|
|
555 |
void HgContainer::init(Qt::Orientation scrollDirection)
|
|
556 |
{
|
|
557 |
FUNC_LOG;
|
|
558 |
|
14
|
559 |
setFlag( QGraphicsItem::ItemClipsToShape, true );
|
|
560 |
|
6
|
561 |
mRenderer = createRenderer(scrollDirection);
|
|
562 |
mOrientation = scrollDirection;
|
|
563 |
|
|
564 |
mQuadRenderer = mRenderer->getRenderer();
|
|
565 |
|
|
566 |
connect(&mSpring, SIGNAL(updated()), SLOT(updateBySpringPosition()));
|
|
567 |
connect(&mSpring, SIGNAL(started()), SIGNAL(scrollingStarted()));
|
|
568 |
connect(&mSpring, SIGNAL(started()), SLOT(onScrollingStarted()));
|
|
569 |
connect(&mSpring, SIGNAL(ended()), SIGNAL(scrollingEnded()));
|
|
570 |
connect(&mSpring, SIGNAL(ended()), SLOT(onScrollingEnded()));
|
|
571 |
connect(mRenderer, SIGNAL(renderingNeeded()), SLOT(redraw()));
|
|
572 |
|
|
573 |
}
|
|
574 |
|
|
575 |
qreal HgContainer::worldWidth() const
|
|
576 |
{
|
|
577 |
return (qreal)mRenderer->getWorldWidth();
|
|
578 |
}
|
|
579 |
|
|
580 |
void HgContainer::initSpringForScrollBar()
|
|
581 |
{
|
|
582 |
FUNC_LOG;
|
|
583 |
|
|
584 |
mSpring.setDamping(KSpringDampingScrollBar);
|
|
585 |
mSpring.setK(KSpringKScrollBar);
|
|
586 |
}
|
|
587 |
|
|
588 |
void HgContainer::initSpringForScrolling()
|
|
589 |
{
|
|
590 |
FUNC_LOG;
|
|
591 |
|
|
592 |
mSpring.setDamping(KSpringDampingScrolling);
|
|
593 |
mSpring.setK(KSpringKScrolling);
|
|
594 |
}
|
|
595 |
|
|
596 |
void HgContainer::boundSpring()
|
|
597 |
{
|
|
598 |
FUNC_LOG;
|
|
599 |
|
|
600 |
qreal x = mSpring.endPos().x();
|
|
601 |
if (mRenderer->coverflowModeEnabled()) {
|
|
602 |
qreal i = floorf(x);
|
|
603 |
x = (x - i > 0.5f) ? ceilf(x) : i;
|
|
604 |
}
|
|
605 |
|
11
|
606 |
mSpring.animateToPosAfterPanning(QPointF(x, 0), worldWidth());
|
6
|
607 |
|
|
608 |
}
|
|
609 |
|
|
610 |
bool HgContainer::handlePanning(QPanGesture *gesture)
|
|
611 |
{
|
|
612 |
mAnimateUsingScrollBar = false;
|
|
613 |
initSpringForScrolling();
|
|
614 |
|
|
615 |
qreal pos = mSpring.pos().x();
|
|
616 |
qreal delta(0);
|
|
617 |
qreal itemSide(0);
|
|
618 |
|
|
619 |
if (mOrientation == mRenderer->getScrollDirection()) {
|
|
620 |
delta = gesture->delta().y();
|
|
621 |
}
|
|
622 |
else {
|
|
623 |
delta = gesture->delta().x();
|
|
624 |
}
|
|
625 |
|
|
626 |
if (mRenderer->getScrollDirection() == Qt::Vertical)
|
|
627 |
itemSide = mRenderer->getImageSize().height()+mRenderer->getSpacing().height();
|
|
628 |
else
|
|
629 |
itemSide = mRenderer->getImageSize().width()+mRenderer->getSpacing().width();
|
|
630 |
|
|
631 |
if (gesture->state() == Qt::GestureStarted) {
|
|
632 |
mOffsetAtDragStart = gesture->offset();
|
|
633 |
}
|
|
634 |
else if (gesture->state() == Qt::GestureUpdated) {
|
|
635 |
QPointF offset = gesture->offset();
|
|
636 |
QPointF offsetDelta = offset - mOffsetAtDragStart;
|
|
637 |
if (!mDragged && (qAbs(offsetDelta.x()) > 8 ||
|
|
638 |
qAbs(offsetDelta.y()) > 8)) {
|
|
639 |
mDragged = true;
|
|
640 |
mDrag.reset(delta, mSpring.pos().x());
|
|
641 |
mDragged = true;
|
|
642 |
mSpringVelAtDragStart = mSpring.velocity().x();
|
|
643 |
mFramesDragged = 0;
|
|
644 |
}
|
|
645 |
|
|
646 |
if (mDragged)
|
|
647 |
{
|
|
648 |
emit scrollingStarted();
|
|
649 |
|
|
650 |
qreal newPosition = mDrag.update(delta, pos, itemSide);
|
|
651 |
if (qAbs(newPosition - mSpring.pos().x()) > 0.01f) {
|
|
652 |
mSpring.gotoPos(QPointF(newPosition, 0));
|
|
653 |
if (mRenderer->coverflowModeEnabled()) {
|
|
654 |
emit scrollPositionChanged(newPosition,true);
|
|
655 |
update();
|
|
656 |
} else {
|
|
657 |
updateBySpringPosition();
|
|
658 |
}
|
|
659 |
}
|
|
660 |
}
|
|
661 |
}
|
|
662 |
else if (mDragged && gesture->state() == Qt::GestureFinished) {
|
|
663 |
mDrag.update(delta, pos, itemSide);
|
|
664 |
mDragged = false;
|
|
665 |
qreal newPos(0);
|
|
666 |
if (mDrag.finish(pos, mRenderer->coverflowModeEnabled(), newPos)) {
|
11
|
667 |
|
|
668 |
mSpring.animateToPosAfterPanning(QPointF(newPos, 0), worldWidth());
|
|
669 |
|
6
|
670 |
HgWidgetItem* item = itemByIndex(newPos);
|
|
671 |
if (item && item->modelIndex() != mSelectionModel->currentIndex()) {
|
|
672 |
// mSelectionModel->setCurrentIndex(item->modelIndex(), QItemSelectionModel::Current);
|
|
673 |
}
|
|
674 |
}
|
|
675 |
else {
|
|
676 |
boundSpring();
|
|
677 |
}
|
|
678 |
}
|
|
679 |
else if(!mDragged && gesture->state() == Qt::GestureFinished) {
|
|
680 |
if (!mRenderer->coverflowModeEnabled()) {
|
|
681 |
mSpring.resetVelocity();
|
|
682 |
update();
|
|
683 |
}
|
|
684 |
}
|
|
685 |
else if (gesture->state() == Qt::GestureCanceled) {
|
|
686 |
boundSpring();
|
|
687 |
}
|
|
688 |
|
|
689 |
return true;
|
|
690 |
}
|
|
691 |
|
|
692 |
bool HgContainer::handleLongTap(Qt::GestureState state, const QPointF &pos)
|
|
693 |
{
|
|
694 |
FUNC_LOG;
|
|
695 |
|
|
696 |
bool handleGesture = false;
|
|
697 |
|
|
698 |
if (hasItemAt(pos)) {
|
|
699 |
|
|
700 |
switch (state)
|
|
701 |
{
|
|
702 |
case Qt::GestureUpdated:
|
17
|
703 |
{
|
|
704 |
int hitItemIndex = -1;
|
|
705 |
HgWidgetItem* hitItem = getItemAt(pos,hitItemIndex);
|
|
706 |
handleLongTapAction(pos,hitItem, hitItemIndex);
|
|
707 |
}
|
6
|
708 |
case Qt::GestureStarted:
|
|
709 |
case Qt::GestureCanceled:
|
|
710 |
case Qt::GestureFinished:
|
|
711 |
default:
|
|
712 |
stopLongPressWatcher();
|
|
713 |
break;
|
|
714 |
}
|
|
715 |
handleGesture = true;
|
|
716 |
} else {
|
|
717 |
mIgnoreGestureAction = true;
|
|
718 |
}
|
|
719 |
|
|
720 |
return handleGesture;
|
|
721 |
}
|
|
722 |
|
|
723 |
|
|
724 |
bool HgContainer::getItemPoints(int index, QPolygonF& points)
|
|
725 |
{
|
|
726 |
return mRenderer->getItemPoints(index, points);
|
|
727 |
}
|
|
728 |
|
|
729 |
QList<QModelIndex> HgContainer::getVisibleItemIndices() const
|
|
730 |
{
|
|
731 |
QList<HgQuad*> quads = mRenderer->getVisibleQuads();
|
|
732 |
QList<QModelIndex> result;
|
|
733 |
for (int i = 0; i < quads.count(); i++) {
|
|
734 |
bool ok;
|
|
735 |
int index = quads.at(i)->userData().toInt(&ok);
|
|
736 |
HgWidgetItem *item = itemByIndex(index);
|
|
737 |
if (item)
|
|
738 |
result.append(item->modelIndex());
|
|
739 |
}
|
|
740 |
qSort(result);
|
|
741 |
return result;
|
|
742 |
}
|
|
743 |
|
|
744 |
void HgContainer::itemDataChanged(const int &firstIndex, const int &lastIndex)
|
|
745 |
{
|
|
746 |
FUNC_LOG;
|
|
747 |
|
|
748 |
int firstItemOnScreen = 0, lastItemOnScreen = 0;
|
|
749 |
firstItemOnScreen = mSpring.pos().x();
|
17
|
750 |
firstItemOnScreen *= currentRowCount();
|
6
|
751 |
|
|
752 |
int itemsOnScreen = mRenderer->getVisibleQuads().count();
|
|
753 |
lastItemOnScreen = firstItemOnScreen+itemsOnScreen;
|
|
754 |
|
|
755 |
if ( itemsOnScreen == 0 || (firstIndex >= firstItemOnScreen && firstIndex < lastItemOnScreen) ||
|
|
756 |
(lastIndex >= firstItemOnScreen && lastIndex < lastItemOnScreen)) {
|
|
757 |
update();
|
|
758 |
}
|
|
759 |
}
|
|
760 |
|
|
761 |
void HgContainer::selectItem(int index)
|
|
762 |
{
|
|
763 |
Q_UNUSED(index)
|
|
764 |
// TODO: replace this with own selection implementation
|
|
765 |
/* if (index < 0 && index >= mItems.count())
|
|
766 |
return;
|
|
767 |
|
|
768 |
mHitItemIndex = index;
|
|
769 |
|
|
770 |
if (mHitItemView)
|
|
771 |
{
|
|
772 |
delete mHitItemView;
|
|
773 |
mHitItemView = NULL;
|
|
774 |
}
|
|
775 |
|
|
776 |
mHitItemView = new HbGridViewItem(this);
|
|
777 |
mHitItemView->setVisible(false);
|
|
778 |
mHitItemView->setPos(QPointF(0,0));
|
|
779 |
mHitItemView->setPressed(true, false);
|
|
780 |
|
|
781 |
const QImage& image = mItems[mHitItemIndex]->image()->getQImage();
|
|
782 |
if (image.isNull())
|
|
783 |
{
|
|
784 |
mHitItemView->setVisible(false);
|
|
785 |
return;
|
|
786 |
}
|
|
787 |
|
|
788 |
QPixmap pixmap = QPixmap::fromImage(image);
|
|
789 |
HbIcon icon(pixmap.scaled(mRenderer->getImageSize().toSize(), Qt::IgnoreAspectRatio));
|
|
790 |
QGraphicsItem* item = mHitItemView->style()->createPrimitive(HbStyle::P_GridViewItem_icon, mHitItemView);
|
|
791 |
HbIconItem *iconItem = static_cast<HbIconItem*>(item);
|
|
792 |
iconItem->setAlignment(Qt::AlignCenter);
|
|
793 |
iconItem->setAspectRatioMode(Qt::IgnoreAspectRatio);
|
|
794 |
iconItem->setIcon(icon);
|
|
795 |
|
|
796 |
mHitItemView->resize(mRenderer->getImageSize().width(),
|
|
797 |
mRenderer->getImageSize().height());
|
|
798 |
*/
|
|
799 |
}
|
|
800 |
|
|
801 |
void HgContainer::updateSelectedItem()
|
|
802 |
{
|
|
803 |
if (!mHitItemView || mHitItemIndex == -1)
|
|
804 |
return;
|
|
805 |
|
|
806 |
QPolygonF points;
|
|
807 |
if (!getItemPoints(mHitItemIndex, points))
|
|
808 |
{
|
|
809 |
// the item was not rendered, we must hide
|
|
810 |
// our qt item
|
|
811 |
mHitItemView->setVisible(false);
|
|
812 |
return;
|
|
813 |
}
|
|
814 |
|
|
815 |
QRectF bounds = points.boundingRect();
|
|
816 |
if (!(rect().contains(bounds) || rect().intersects(bounds)))
|
|
817 |
{
|
|
818 |
mHitItemView->setVisible(false);
|
|
819 |
return;
|
|
820 |
}
|
|
821 |
|
|
822 |
QPolygonF img;
|
|
823 |
img.append(QPointF(3,mHitItemView->boundingRect().height()-3));
|
|
824 |
img.append(QPointF(mHitItemView->boundingRect().width()-3,mHitItemView->boundingRect().height()-3));
|
|
825 |
img.append(QPointF(mHitItemView->boundingRect().width()-3,3));
|
|
826 |
img.append(QPointF(3,3));
|
|
827 |
|
|
828 |
QTransform t;
|
|
829 |
QTransform::quadToQuad(img, points, t);
|
|
830 |
|
|
831 |
//t.translate(50,50);
|
|
832 |
bool bOk;
|
|
833 |
mHitItemView->setTransform(t * this->transform().inverted(&bOk));
|
|
834 |
mHitItemView->setVisible(true);
|
|
835 |
}
|
|
836 |
|
|
837 |
void HgContainer::unselectItem()
|
|
838 |
{
|
|
839 |
mHitItemIndex = -1;
|
|
840 |
if (mHitItemView)
|
|
841 |
{
|
|
842 |
mHitItemView->setVisible(false);
|
|
843 |
}
|
|
844 |
}
|
|
845 |
|
|
846 |
void HgContainer::updateLongPressVisualizer()
|
|
847 |
{
|
|
848 |
int elapsed = mLongTapDuration.elapsed();
|
|
849 |
|
|
850 |
if (elapsed > 80)
|
|
851 |
{
|
|
852 |
int frame = 100.0f * qreal(elapsed - 80) / qreal(KLongTapDuration - 80);
|
|
853 |
mLongPressVisualizer->setFrame(frame);
|
|
854 |
}
|
|
855 |
}
|
|
856 |
|
|
857 |
bool HgContainer::hasItemAt(const QPointF& pos)
|
|
858 |
{
|
|
859 |
int dummy;
|
|
860 |
HgWidgetItem *item = getItemAt(pos, dummy);
|
|
861 |
if (item) {
|
|
862 |
return item->modelIndex().isValid();
|
|
863 |
}
|
|
864 |
return false;
|
|
865 |
}
|
|
866 |
|
|
867 |
HgWidgetItem* HgContainer::getItemAt(const QPointF& pos, int& index)
|
|
868 |
{
|
|
869 |
HgQuad* quad = mRenderer->getQuadAt(pos);
|
|
870 |
if (quad)
|
|
871 |
{
|
|
872 |
bool ok;
|
|
873 |
index = quad->userData().toInt(&ok);
|
|
874 |
|
|
875 |
HgWidgetItem* item = itemByIndex(index);
|
|
876 |
return item;
|
|
877 |
}
|
|
878 |
return NULL;
|
|
879 |
}
|
|
880 |
|
|
881 |
void HgContainer::startLongPressWatcher(const QPointF& pos)
|
|
882 |
{
|
|
883 |
if (!mLongPressVisualizer)
|
|
884 |
{
|
|
885 |
mLongPressVisualizer = new HgLongPressVisualizer(this);
|
|
886 |
mLongPressVisualizer->setZValue(zValue()+1);
|
|
887 |
}
|
|
888 |
|
|
889 |
mLongPressVisualizer->start(pos);
|
|
890 |
|
|
891 |
if (!mLongPressTimer)
|
|
892 |
{
|
|
893 |
mLongPressTimer = new QTimer(this);
|
|
894 |
QObject::connect(mLongPressTimer, SIGNAL(timeout()), this, SLOT(updateLongPressVisualizer()));
|
|
895 |
}
|
|
896 |
|
|
897 |
mLongPressTimer->start(20);
|
|
898 |
|
|
899 |
mLongTapDuration.start();
|
|
900 |
}
|
|
901 |
|
|
902 |
void HgContainer::stopLongPressWatcher()
|
|
903 |
{
|
|
904 |
if (mLongPressTimer && mLongPressVisualizer)
|
|
905 |
{
|
|
906 |
mLongPressTimer->stop();
|
|
907 |
mLongPressVisualizer->stop();
|
|
908 |
}
|
|
909 |
}
|
|
910 |
|
|
911 |
qreal HgContainer::getCameraDistance(qreal springVelocity)
|
|
912 |
{
|
|
913 |
Q_UNUSED(springVelocity)
|
|
914 |
return 0;
|
|
915 |
}
|
|
916 |
|
|
917 |
qreal HgContainer::getCameraRotationY(qreal springVelocity)
|
|
918 |
{
|
|
919 |
Q_UNUSED(springVelocity)
|
|
920 |
return 0;
|
|
921 |
}
|
|
922 |
|
17
|
923 |
bool HgContainer::handleTapAction(const QPointF& pos, HgWidgetItem* hitItem, int hitItemIndex)
|
6
|
924 |
{
|
|
925 |
Q_UNUSED(pos)
|
|
926 |
Q_UNUSED(hitItem)
|
|
927 |
Q_UNUSED(hitItemIndex)
|
17
|
928 |
return false;
|
6
|
929 |
}
|
|
930 |
|
17
|
931 |
bool HgContainer::handleLongTapAction(const QPointF& pos, HgWidgetItem* hitItem, int hitItemIndex)
|
6
|
932 |
{
|
|
933 |
Q_UNUSED(pos)
|
|
934 |
Q_UNUSED(hitItem)
|
|
935 |
Q_UNUSED(hitItemIndex)
|
17
|
936 |
return false;
|
6
|
937 |
}
|
|
938 |
|
|
939 |
void HgContainer::onScrollPositionChanged(qreal pos)
|
|
940 |
{
|
|
941 |
Q_UNUSED(pos)
|
|
942 |
}
|
|
943 |
|
|
944 |
void HgContainer::onScrollingStarted()
|
|
945 |
{
|
|
946 |
// By default do nothing
|
|
947 |
}
|
|
948 |
|
|
949 |
void HgContainer::onScrollingEnded()
|
|
950 |
{
|
|
951 |
// By default do nothing
|
|
952 |
}
|
|
953 |
|
|
954 |
void HgContainer::setDefaultImage(QImage defaultImage)
|
|
955 |
{
|
|
956 |
HgQuadRenderer *renderer = mRenderer->getRenderer();
|
|
957 |
if (renderer) {
|
|
958 |
QImage scaled = defaultImage.scaled(mRenderer->getImageSize().toSize());
|
|
959 |
renderer->setDefaultImage(scaled);
|
|
960 |
}
|
|
961 |
}
|
|
962 |
|
|
963 |
void HgContainer::setItemSizePolicy(HgWidget::ItemSizePolicy policy)
|
|
964 |
{
|
|
965 |
if (policy != mItemSizePolicy)
|
|
966 |
{
|
|
967 |
mItemSizePolicy = policy;
|
|
968 |
|
|
969 |
updateItemSizeAndSpacing();
|
|
970 |
}
|
|
971 |
}
|
|
972 |
|
|
973 |
HgWidget::ItemSizePolicy HgContainer::itemSizePolicy() const
|
|
974 |
{
|
|
975 |
return mItemSizePolicy;
|
|
976 |
}
|
|
977 |
|
|
978 |
void HgContainer::setItemSize(const QSizeF& size)
|
|
979 |
{
|
|
980 |
mUserItemSize = size;
|
|
981 |
updateItemSizeAndSpacing();
|
|
982 |
}
|
|
983 |
|
|
984 |
QSizeF HgContainer::itemSize() const
|
|
985 |
{
|
|
986 |
return mRenderer->getImageSize();
|
|
987 |
}
|
|
988 |
|
|
989 |
void HgContainer::setItemSpacing(const QSizeF& spacing)
|
|
990 |
{
|
|
991 |
mUserItemSpacing = spacing;
|
|
992 |
updateItemSizeAndSpacing();
|
|
993 |
}
|
|
994 |
|
|
995 |
QSizeF HgContainer::itemSpacing() const
|
|
996 |
{
|
|
997 |
return mRenderer->getSpacing();
|
|
998 |
}
|
|
999 |
|
|
1000 |
void HgContainer::updateItemSizeAndSpacing()
|
|
1001 |
{
|
|
1002 |
if (mItemSizePolicy == HgWidget::ItemSizeUserDefined)
|
|
1003 |
{
|
|
1004 |
mRenderer->setImageSize(mUserItemSize);
|
|
1005 |
mRenderer->setSpacing(mUserItemSpacing);
|
|
1006 |
}
|
12
|
1007 |
// Indicator size depends from the item size so
|
|
1008 |
// indicators need to be updated. Indicators are created
|
|
1009 |
// in runtime only for need so if they dont exists they aren't created.
|
|
1010 |
loadIndicatorGraphics(true);
|
6
|
1011 |
}
|
|
1012 |
|
|
1013 |
QSizeF HgContainer::getAutoItemSize() const
|
|
1014 |
{
|
|
1015 |
return mUserItemSize;
|
|
1016 |
}
|
|
1017 |
|
|
1018 |
QSizeF HgContainer::getAutoItemSpacing() const
|
|
1019 |
{
|
|
1020 |
return mUserItemSpacing;
|
|
1021 |
}
|
|
1022 |
|
|
1023 |
Qt::Orientation HgContainer::scrollDirection() const
|
|
1024 |
{
|
|
1025 |
return mRenderer->getScrollDirection();
|
|
1026 |
}
|
|
1027 |
|
|
1028 |
qreal HgContainer::scrollPosition() const
|
|
1029 |
{
|
|
1030 |
return mSpring.pos().x();
|
|
1031 |
}
|
|
1032 |
|
12
|
1033 |
void HgContainer::loadIndicatorGraphics(bool loadIfExists)
|
|
1034 |
{
|
|
1035 |
if (loadIfExists && !mMarkImageOn && !mMarkImageOff) return;
|
|
1036 |
|
|
1037 |
if (!mMarkImageOn) {
|
|
1038 |
mMarkImageOn = mQuadRenderer->createNativeImage();
|
|
1039 |
}
|
|
1040 |
HANDLE_ERROR_NULL(mMarkImageOn);
|
|
1041 |
if (!mMarkImageOff) {
|
|
1042 |
mMarkImageOff = mQuadRenderer->createNativeImage();
|
|
1043 |
}
|
|
1044 |
|
|
1045 |
const QSizeF newIndicatorSize = itemSize()/2;
|
|
1046 |
|
|
1047 |
// Validate if loading marking icons is really needed by comparing the sizes.
|
|
1048 |
// Both marking icons have the same size so its enough to check one.
|
|
1049 |
if (mMarkImageOn && mMarkImageOn->width() == newIndicatorSize.width() &&
|
|
1050 |
mMarkImageOn->height() == newIndicatorSize.height() ) return;
|
|
1051 |
|
|
1052 |
HANDLE_ERROR_NULL(mMarkImageOff);
|
|
1053 |
HbIcon selectedIcon(QLatin1String("qtg_small_selected"));
|
|
1054 |
HbIcon unselectedIcon(QLatin1String("qtg_small_unselected"));
|
|
1055 |
selectedIcon.setSize(newIndicatorSize);
|
|
1056 |
unselectedIcon.setSize(newIndicatorSize);
|
|
1057 |
|
|
1058 |
QPixmap selectedPixmap = selectedIcon.pixmap();
|
|
1059 |
QPixmap unselectedPixmap = unselectedIcon.pixmap();
|
|
1060 |
|
|
1061 |
if (!selectedPixmap.isNull() && !unselectedPixmap.isNull()) {
|
|
1062 |
if (mMarkImageOn) {
|
|
1063 |
mMarkImageOn->setPixmap(selectedPixmap);
|
|
1064 |
}
|
|
1065 |
if (mMarkImageOff) {
|
|
1066 |
mMarkImageOff->setPixmap(unselectedPixmap);
|
|
1067 |
}
|
|
1068 |
}
|
|
1069 |
}
|
|
1070 |
|
|
1071 |
void HgContainer::setHandleLongPress(bool handheLongPress)
|
|
1072 |
{
|
|
1073 |
// this is just a flag that is used in gesturehandling logic.
|
|
1074 |
mHandleLongPress = handheLongPress;
|
|
1075 |
}
|
17
|
1076 |
|
|
1077 |
bool HgContainer::handleItemSelection(HgWidgetItem* item)
|
|
1078 |
{
|
|
1079 |
bool handled = true;
|
|
1080 |
switch(mSelectionMode)
|
|
1081 |
{
|
|
1082 |
case HgWidget::MultiSelection:
|
|
1083 |
{
|
|
1084 |
mSelectionModel->setCurrentIndex(item->modelIndex(), QItemSelectionModel::Current);
|
|
1085 |
INFO("Select:" << item->modelIndex().row());
|
|
1086 |
mSelectionModel->select(item->modelIndex(), QItemSelectionModel::Toggle);
|
|
1087 |
update(); // It would be enough to update the item
|
|
1088 |
break;
|
|
1089 |
}
|
|
1090 |
case HgWidget::SingleSelection:
|
|
1091 |
{
|
|
1092 |
mSelectionModel->setCurrentIndex(item->modelIndex(), QItemSelectionModel::Current);
|
|
1093 |
INFO("Select:" << item->modelIndex().row());
|
|
1094 |
mSelectionModel->select(item->modelIndex(), QItemSelectionModel::ClearAndSelect);
|
|
1095 |
update(); // It would be enough to update the item
|
|
1096 |
break;
|
|
1097 |
}
|
|
1098 |
case HgWidget::ContiguousSelection:
|
|
1099 |
{
|
|
1100 |
mSelectionModel->setCurrentIndex(item->modelIndex(), QItemSelectionModel::Current);
|
|
1101 |
QModelIndex newSelected = item->modelIndex();
|
|
1102 |
QModelIndexList oldSelection = mSelectionModel->selectedIndexes();
|
|
1103 |
INFO("Select:" << newSelected.row());
|
|
1104 |
if (oldSelection.count() > 0 && !mSelectionModel->isSelected(newSelected)) {
|
|
1105 |
if (newSelected.row() < oldSelection.front().row()) {
|
|
1106 |
mSelectionModel->select(QItemSelection(newSelected, oldSelection.back()),
|
|
1107 |
QItemSelectionModel::Select);
|
|
1108 |
}
|
|
1109 |
else { // newSelected.row() > oldSelection.back().row()
|
|
1110 |
mSelectionModel->select(QItemSelection(oldSelection.front(), newSelected),
|
|
1111 |
QItemSelectionModel::Select);
|
|
1112 |
}
|
|
1113 |
}
|
|
1114 |
else {
|
|
1115 |
mSelectionModel->select(newSelected, QItemSelectionModel::Select);
|
|
1116 |
}
|
|
1117 |
update(); // It would be enough to update the item
|
|
1118 |
break;
|
|
1119 |
}
|
|
1120 |
default:
|
|
1121 |
handled = false;
|
|
1122 |
break;
|
|
1123 |
}
|
|
1124 |
|
|
1125 |
return handled;
|
|
1126 |
}
|
|
1127 |
|
6
|
1128 |
// EOF
|