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