|
1 /* |
|
2 * Copyright (c) 2009 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 <hbaction.h> |
|
19 #include <hbdialog.h> |
|
20 #include <hbinstance.h> |
|
21 #include <hblabel.h> |
|
22 #include <hblistwidget.h> |
|
23 #include <hbmenu.h> |
|
24 #include <hbscrollbar> |
|
25 #include <QActionGroup> |
|
26 #include <QGraphicsLinearLayout> |
|
27 #include "hgwidgettestview.h" |
|
28 #include "hgtestview.h" |
|
29 #include "hgselectiondialog.h" |
|
30 #include "hgwidgettestdatamodel.h" |
|
31 #include "hgflipwidget.h" |
|
32 #include "trace.h" |
|
33 #include <hgwidgets/hggrid.h> |
|
34 #include <hgwidgets/hgmediawall.h> |
|
35 |
|
36 HgWidgetTestView::HgWidgetTestView(QGraphicsItem *parent) : |
|
37 HbView(parent), |
|
38 mWidget(NULL), |
|
39 mModel(NULL), |
|
40 mListWidget(NULL), |
|
41 mToggleOrientation(false), |
|
42 mTBone(false), |
|
43 mFlipWidget(NULL), |
|
44 mFrontItem(NULL) |
|
45 { |
|
46 mModel = new HgWidgetTestDataModel(this); |
|
47 mModel->setImageDataType(HgWidgetTestDataModel::TypeQImage); |
|
48 mSelectionModel = new QItemSelectionModel(mModel, this); |
|
49 |
|
50 createMenu(); |
|
51 |
|
52 mLayout = new QGraphicsLinearLayout(Qt::Vertical); |
|
53 mLayout->setContentsMargins(0,0,0,0); |
|
54 initWidget( HgWidgetGrid ); |
|
55 setLayout( mLayout ); |
|
56 } |
|
57 |
|
58 HgWidgetTestView::~HgWidgetTestView() |
|
59 { |
|
60 } |
|
61 |
|
62 void HgWidgetTestView::createMenu() |
|
63 { |
|
64 FUNC_LOG; |
|
65 |
|
66 HbMenu* modeMenu = new HbMenu("Change widget type"); |
|
67 menu()->addMenu(modeMenu); |
|
68 |
|
69 HbMenu* scrollBarMenu = new HbMenu("ScrollBar settings"); |
|
70 menu()->addMenu( scrollBarMenu ); |
|
71 |
|
72 HbMenu* imageTypeMenu = new HbMenu("Datamodel image type"); |
|
73 menu()->addMenu( imageTypeMenu ); |
|
74 |
|
75 HbAction* gridAction = modeMenu->addAction( "Use grid" ); |
|
76 HbAction* coverFlowAction = modeMenu->addAction( "Use coverFlow" ); |
|
77 HbAction* TBone = modeMenu->addAction( "Use TBone" ); |
|
78 connect( modeMenu, SIGNAL(triggered(HbAction*)), this, SLOT(switchWidget(HbAction*)) ); |
|
79 |
|
80 QActionGroup* ac1 = new QActionGroup( this ); |
|
81 gridAction->setCheckable( true ); |
|
82 coverFlowAction->setCheckable( true ); |
|
83 TBone->setCheckable(true); |
|
84 gridAction->setChecked( true ); |
|
85 ac1->addAction( gridAction ); |
|
86 ac1->addAction( coverFlowAction ); |
|
87 ac1->addAction( TBone ); |
|
88 |
|
89 HbAction* scrollBarAutoHideAction = scrollBarMenu->addAction( "Autohide ScrollBar" ); |
|
90 HbAction* scrollBarAlwaysOnAction = scrollBarMenu->addAction( "ScrollBar always on" ); |
|
91 HbAction* scrollBarAlwaysOffAction = scrollBarMenu->addAction( "ScrollBar always off" ); |
|
92 scrollBarMenu->addSeparator(); |
|
93 HbAction* interactiveScrollBarAction = scrollBarMenu->addAction( "Interactive scrollbar" ); |
|
94 HbAction* uninteractiveScrollBarAction = scrollBarMenu->addAction( "Uninteractive scrollbar" ); |
|
95 connect( scrollBarAutoHideAction, SIGNAL(triggered()), this, SLOT(autoHideScrollBar()) ); |
|
96 connect( scrollBarAlwaysOnAction, SIGNAL(triggered()), this, SLOT(scrollBarAlwaysOn()) ); |
|
97 connect( scrollBarAlwaysOffAction, SIGNAL(triggered()), this, SLOT(scrollBarAlwaysOff()) ); |
|
98 connect( interactiveScrollBarAction, SIGNAL(triggered()), this, SLOT(interactiveScrollBar()) ); |
|
99 connect( uninteractiveScrollBarAction, SIGNAL(triggered()), this, SLOT(unInteractiveScrollBar()) ); |
|
100 |
|
101 QActionGroup* ac2 = new QActionGroup( this ); |
|
102 scrollBarAutoHideAction->setCheckable( true ); |
|
103 scrollBarAlwaysOnAction->setCheckable( true ); |
|
104 scrollBarAlwaysOffAction->setCheckable(true); |
|
105 scrollBarAutoHideAction->setChecked( true ); |
|
106 ac2->addAction( scrollBarAutoHideAction ); |
|
107 ac2->addAction( scrollBarAlwaysOnAction ); |
|
108 ac2->addAction( scrollBarAlwaysOffAction ); |
|
109 |
|
110 QActionGroup* ac3 = new QActionGroup( this ); |
|
111 interactiveScrollBarAction->setCheckable( true ); |
|
112 uninteractiveScrollBarAction->setCheckable( true ); |
|
113 uninteractiveScrollBarAction->setChecked( true ); |
|
114 ac3->addAction( interactiveScrollBarAction ); |
|
115 ac3->addAction( uninteractiveScrollBarAction ); |
|
116 |
|
117 HbAction* qimageAction = imageTypeMenu->addAction( "feed QImages" ); |
|
118 HbAction* hbiconAction = imageTypeMenu->addAction( "feed HbIcons" ); |
|
119 HbAction* qiconAction = imageTypeMenu->addAction( "feed QIcons" ); |
|
120 connect( qimageAction, SIGNAL(triggered()), this, SLOT(feedqimages()) ); |
|
121 connect( hbiconAction, SIGNAL(triggered()), this, SLOT(feedhbicons()) ); |
|
122 connect( qiconAction, SIGNAL(triggered()), this, SLOT(feedqicons()) ); |
|
123 |
|
124 QActionGroup* ac4 = new QActionGroup( this ); |
|
125 qimageAction->setCheckable( true ); |
|
126 hbiconAction->setCheckable( true ); |
|
127 qiconAction->setCheckable( true ); |
|
128 qimageAction->setChecked( true ); |
|
129 ac4->addAction( qimageAction ); |
|
130 ac4->addAction( hbiconAction ); |
|
131 ac4->addAction( qiconAction ); |
|
132 |
|
133 menu()->addAction("Toggle scrolldirection", this, SLOT(toggleScrollDirection())); |
|
134 menu()->addAction("Simulate orientation switch", this, SLOT(orientationChanged())); |
|
135 |
|
136 mUseLowResAction = menu()->addAction( "Use low res images for coverflow" ); |
|
137 mUseLowResAction->setCheckable(true); |
|
138 mUseLowResAction->setChecked(false); |
|
139 mUseLowResAction->setEnabled(false); |
|
140 connect( mUseLowResAction, SIGNAL(triggered()), this, SLOT(toggleLowResForCoverflow()) ); |
|
141 |
|
142 HbMenu *modelChangeSubMenu = menu()->addMenu("Change model"); |
|
143 modelChangeSubMenu->addAction("Remove items", this, SLOT(openDeleteItemsDialog())); |
|
144 modelChangeSubMenu->addAction("Move items", this, SLOT(openMoveItemsDialog())); |
|
145 modelChangeSubMenu->addAction("Add items", this, SLOT(openAddItemsDialog())); |
|
146 |
|
147 HbMenu *labelChangeSubMenu = menu()->addMenu("Change labels"); |
|
148 HbMenu *titleSubMenu = labelChangeSubMenu->addMenu("Title"); |
|
149 HbAction *aboveAction1 = titleSubMenu->addAction("Above", this, SLOT(setTitleAboveImage())); |
|
150 HbAction *belowAction1 = titleSubMenu->addAction("Below", this, SLOT(setTitleBelowImage())); |
|
151 HbAction *hiddenAction1 = titleSubMenu->addAction("Hide", this, SLOT(setTitleHidden())); |
|
152 QActionGroup* ac5 = new QActionGroup(this); |
|
153 aboveAction1->setCheckable(true); |
|
154 belowAction1->setCheckable(true); |
|
155 hiddenAction1->setCheckable(true); |
|
156 hiddenAction1->setChecked(true); |
|
157 ac5->addAction(aboveAction1); |
|
158 ac5->addAction(belowAction1); |
|
159 ac5->addAction(hiddenAction1); |
|
160 |
|
161 HbMenu *descriptionSubMenu = labelChangeSubMenu->addMenu("Description"); |
|
162 HbAction *aboveAction2 = descriptionSubMenu->addAction("Above", this, SLOT(setDescriptionAboveImage())); |
|
163 HbAction *belowAction2 = descriptionSubMenu->addAction("Below", this, SLOT(setDescriptionBelowImage())); |
|
164 HbAction *hiddenAction2 = descriptionSubMenu->addAction("Hide", this, SLOT(setDescriptionHidden())); |
|
165 QActionGroup* ac6 = new QActionGroup(this); |
|
166 aboveAction2->setCheckable(true); |
|
167 belowAction2->setCheckable(true); |
|
168 hiddenAction2->setCheckable(true); |
|
169 hiddenAction2->setChecked(true); |
|
170 ac6->addAction(aboveAction2); |
|
171 ac6->addAction(belowAction2); |
|
172 ac6->addAction(hiddenAction2); |
|
173 } |
|
174 |
|
175 void HgWidgetTestView::switchWidget(HbAction* action) |
|
176 { |
|
177 FUNC_LOG; |
|
178 |
|
179 mTBone = false; |
|
180 if( action->text() == "Use grid"){ |
|
181 initWidget( HgWidgetGrid ); |
|
182 } |
|
183 else if( action->text() == "Use coverFlow"){ |
|
184 initWidget( HgWidgetCoverflow ); |
|
185 } |
|
186 else if( action->text() == "Use TBone" ){ |
|
187 mTBone = true; |
|
188 initWidget( HgWidgetCoverflow ); |
|
189 } |
|
190 } |
|
191 |
|
192 void HgWidgetTestView::toggleScrollDirection() |
|
193 { |
|
194 FUNC_LOG; |
|
195 |
|
196 mToggleOrientation = !mToggleOrientation; |
|
197 initWidget( mWidgetType ); |
|
198 } |
|
199 |
|
200 void HgWidgetTestView::initWidget( WidgetType type ) |
|
201 { |
|
202 FUNC_LOG; |
|
203 |
|
204 mWidgetType = type; |
|
205 |
|
206 // TODO, disconnecting signals required? |
|
207 |
|
208 if( mWidget ) |
|
209 mLayout->removeItem(mWidget); |
|
210 if( mListWidget ) |
|
211 mLayout->removeItem(mListWidget); |
|
212 |
|
213 delete mWidget; |
|
214 mWidget = NULL; |
|
215 |
|
216 delete mListWidget; |
|
217 mListWidget = NULL; |
|
218 |
|
219 mWidget = createWidget(type); |
|
220 mLayout->addItem(mWidget); |
|
221 |
|
222 switch (type) |
|
223 { |
|
224 case HgWidgetGrid: |
|
225 { |
|
226 mUseLowResAction->setEnabled(false); |
|
227 mModel->enableLowResImages(false); |
|
228 // TODO, init grid different model, |
|
229 mModel->setThumbnailSize(ThumbnailManager::ThumbnailMedium); |
|
230 break; |
|
231 } |
|
232 case HgWidgetCoverflow: |
|
233 { |
|
234 mUseLowResAction->setEnabled(true); |
|
235 mModel->enableLowResImages(mUseLowResAction->isChecked()); |
|
236 mModel->setThumbnailSize(ThumbnailManager::ThumbnailLarge); |
|
237 if (mTBone) { |
|
238 mListWidget = new HbListWidget; |
|
239 mLayout->addItem(mListWidget); |
|
240 mListWidget->addItem( "List item 1"); |
|
241 mListWidget->addItem( "List item 2"); |
|
242 mListWidget->addItem( "List item 3"); |
|
243 } |
|
244 break; |
|
245 } |
|
246 default: |
|
247 break; |
|
248 } |
|
249 |
|
250 HANDLE_ERROR_NULL(mWidget); |
|
251 if (mWidget) |
|
252 { |
|
253 mWidget->setModel( mModel ); |
|
254 connect(mWidget, SIGNAL(activated(QModelIndex)), SLOT(openDialog(QModelIndex))); |
|
255 connect(mWidget, SIGNAL(longPressed(QModelIndex, QPointF)), SLOT(openView(QModelIndex))); |
|
256 QList<HbMainWindow *> mainWindows = hbInstance->allMainWindows(); |
|
257 if (mainWindows.count() > 0) |
|
258 { |
|
259 HbMainWindow *primaryWindow = mainWindows[0]; |
|
260 connect(primaryWindow, SIGNAL(orientationChanged(Qt::Orientation)), mWidget, SLOT(orientationChanged(Qt::Orientation))); |
|
261 } |
|
262 |
|
263 connect(mWidget, SIGNAL(scrollingStarted()), SLOT(onScrollingStarted())); |
|
264 connect(mWidget, SIGNAL(scrollingEnded()), SLOT(onScrollingEnded())); |
|
265 } |
|
266 } |
|
267 |
|
268 void HgWidgetTestView::openDialog(const QModelIndex& index) |
|
269 { |
|
270 FUNC_LOG; |
|
271 |
|
272 QVariant image = mModel->data(index, Qt::DecorationRole); |
|
273 QVariant texts = mModel->data(index, Qt::DisplayRole); |
|
274 |
|
275 if (mWidgetType == HgWidgetCoverflow) |
|
276 { |
|
277 if (image.canConvert<QPixmap>() && texts.canConvert<QStringList>()) |
|
278 { |
|
279 QStringList strList = texts.toStringList(); |
|
280 if (strList.count() > 1) |
|
281 { |
|
282 if (mFrontItem) |
|
283 mFrontItem->setVisible(false); |
|
284 |
|
285 if (mFlipWidget) |
|
286 delete mFlipWidget; |
|
287 |
|
288 QPolygonF poly; |
|
289 if (!mWidget->getItemOutline(index, poly)) |
|
290 return; |
|
291 |
|
292 QRectF itemRect = poly.boundingRect(); |
|
293 |
|
294 mFlipWidget = |
|
295 new HgFlipWidget( |
|
296 strList.at(0), |
|
297 strList.at(1), |
|
298 image.value<QPixmap>(), |
|
299 this); |
|
300 |
|
301 mFlipWidget->setPos(QPointF( |
|
302 itemRect.center().x() - itemRect.width() / 2, |
|
303 itemRect.center().y() - itemRect.height() / 2 |
|
304 )); |
|
305 |
|
306 mFlipWidget->resize(itemRect.width(), itemRect.height()); |
|
307 mFlipWidget->show(); |
|
308 |
|
309 QObject::connect(mFlipWidget, SIGNAL(closed()), this, SLOT(flipClosed())); |
|
310 mModel->setData(index, false, Qt::UserRole+1); |
|
311 mFlippedIndex = index; |
|
312 } |
|
313 } |
|
314 |
|
315 return; |
|
316 } |
|
317 |
|
318 HbDialog dlg; |
|
319 dlg.setTimeout(HbPopup::NoTimeout); |
|
320 dlg.setDismissPolicy(HbPopup::TapInside); |
|
321 dlg.setPrimaryAction(new HbAction("Close")); |
|
322 if (texts.canConvert<QStringList>()) |
|
323 { |
|
324 QStringList strList = texts.toStringList(); |
|
325 if (strList.count() > 0) |
|
326 { |
|
327 dlg.setHeadingWidget(new HbLabel(strList.at(0))); |
|
328 } |
|
329 } |
|
330 if (image.canConvert<QImage>()) |
|
331 { |
|
332 HbLabel *content = new HbLabel; |
|
333 QImage realImage(image.value<QImage>()); |
|
334 QPixmap pixmap = QPixmap::fromImage( realImage ); |
|
335 content->setIcon(HbIcon(pixmap)); |
|
336 dlg.setContentWidget(content); |
|
337 } |
|
338 dlg.exec(); |
|
339 } |
|
340 |
|
341 void HgWidgetTestView::openView(const QModelIndex& index) |
|
342 { |
|
343 FUNC_LOG; |
|
344 |
|
345 QVariant image = mModel->data(index, Qt::DecorationRole); |
|
346 QVariant texts = mModel->data(index, Qt::DisplayRole); |
|
347 |
|
348 if (image.canConvert<QImage>() && texts.canConvert<QStringList>()) |
|
349 { |
|
350 QStringList strList = texts.toStringList(); |
|
351 if (strList.count() > 1) |
|
352 { |
|
353 HgTestView* view = |
|
354 new HgTestView( |
|
355 strList.at(0), |
|
356 strList.at(1), |
|
357 QPixmap::fromImage(image.value<QImage>())); |
|
358 QList<HbMainWindow *> mainWindows = hbInstance->allMainWindows(); |
|
359 if (mainWindows.count() > 0) |
|
360 { |
|
361 HbMainWindow *primaryWindow = mainWindows[0]; |
|
362 primaryWindow->addView(view); |
|
363 primaryWindow->setViewSwitchingEnabled(false); |
|
364 primaryWindow->setCurrentView(view); |
|
365 } |
|
366 } |
|
367 } |
|
368 } |
|
369 |
|
370 void HgWidgetTestView::openDeleteItemsDialog() |
|
371 { |
|
372 FUNC_LOG; |
|
373 HANDLE_ERROR_NULL(mWidget); |
|
374 |
|
375 HgWidget *widget = copyWidget(); |
|
376 HANDLE_ERROR_NULL(widget); |
|
377 |
|
378 HgSelectionDialog *dlg = |
|
379 new HgSelectionDialog("Remove items", "Remove", widget); // Takes ownership of widget |
|
380 HANDLE_ERROR_NULL(dlg); |
|
381 |
|
382 mWidget->hide(); |
|
383 widget->setSelectionMode(HgWidget::MultiSelection); |
|
384 bool removeItems = (dlg->exec() == dlg->primaryAction()); |
|
385 QItemSelection selection = mSelectionModel->selection(); |
|
386 widget->setSelectionMode(HgWidget::NoSelection); // Clears the selection |
|
387 delete dlg; |
|
388 |
|
389 if (removeItems) { |
|
390 mModel->remove(selection); |
|
391 } |
|
392 |
|
393 mWidget->show(); |
|
394 } |
|
395 |
|
396 void HgWidgetTestView::openMoveItemsDialog() |
|
397 { |
|
398 FUNC_LOG; |
|
399 HANDLE_ERROR_NULL(mWidget); |
|
400 |
|
401 HgWidget *widget = copyWidget(); |
|
402 HANDLE_ERROR_NULL(widget); |
|
403 HgSelectionDialog *dlg = |
|
404 new HgSelectionDialog("Select items to move", "Move to...", widget); // Takes ownership of widget |
|
405 HANDLE_ERROR_NULL(dlg); |
|
406 HANDLE_ERROR_NULL(dlg); |
|
407 |
|
408 mWidget->hide(); |
|
409 widget->setSelectionMode(HgWidget::ContiguousSelection); |
|
410 bool moveItems = (dlg->exec() == dlg->primaryAction()); |
|
411 QItemSelection selection = mSelectionModel->selection(); |
|
412 widget->setSelectionMode(HgWidget::NoSelection); // Clears the selection |
|
413 delete dlg; |
|
414 dlg = 0; |
|
415 widget = 0; |
|
416 |
|
417 if (moveItems) { |
|
418 widget = copyWidget(); |
|
419 HANDLE_ERROR_NULL(widget); |
|
420 widget->setPreferredSize(size().width(), 320); |
|
421 dlg = new HgSelectionDialog("Select target location", "Move", widget); // Takes ownership of widget |
|
422 HANDLE_ERROR_NULL(dlg); |
|
423 widget->setSelectionMode(HgWidget::SingleSelection); |
|
424 moveItems = (dlg->exec() == dlg->primaryAction()); |
|
425 QItemSelection target = mSelectionModel->selection(); |
|
426 widget->setSelectionMode(HgWidget::NoSelection); // Clears the selection |
|
427 delete dlg; |
|
428 |
|
429 if (moveItems) { |
|
430 mModel->move(selection, target.indexes().at(0)); |
|
431 } |
|
432 } |
|
433 mWidget->show(); |
|
434 } |
|
435 |
|
436 void HgWidgetTestView::openAddItemsDialog() |
|
437 { |
|
438 FUNC_LOG; |
|
439 HANDLE_ERROR_NULL(mWidget); |
|
440 |
|
441 HgWidget *widget = copyWidget(); |
|
442 HANDLE_ERROR_NULL(widget); |
|
443 HgSelectionDialog *dlg = |
|
444 new HgSelectionDialog("Select position to add items to", "Add", widget); // Takes ownership of widget |
|
445 HANDLE_ERROR_NULL(dlg); |
|
446 |
|
447 mWidget->hide(); |
|
448 widget->setSelectionMode(HgWidget::SingleSelection); |
|
449 bool addItems = (dlg->exec() == dlg->primaryAction()); |
|
450 QItemSelection target = mSelectionModel->selection(); |
|
451 widget->setSelectionMode(HgWidget::NoSelection); // Clears the selection |
|
452 delete dlg; |
|
453 |
|
454 if (addItems) { |
|
455 mModel->add(target.indexes().at(0), 5); |
|
456 } |
|
457 |
|
458 mWidget->show(); |
|
459 } |
|
460 |
|
461 void HgWidgetTestView::autoHideScrollBar() |
|
462 { |
|
463 setScrollBarPolicy(HgWidget::ScrollBarAutoHide); |
|
464 } |
|
465 |
|
466 void HgWidgetTestView::scrollBarAlwaysOn() |
|
467 { |
|
468 setScrollBarPolicy(HgWidget::ScrollBarAlwaysOn); |
|
469 } |
|
470 |
|
471 void HgWidgetTestView::scrollBarAlwaysOff() |
|
472 { |
|
473 setScrollBarPolicy(HgWidget::ScrollBarAlwaysOff); |
|
474 } |
|
475 |
|
476 void HgWidgetTestView::setScrollBarPolicy( HgWidget::ScrollBarPolicy policy ) |
|
477 { |
|
478 mWidget->setScrollBarPolicy( policy ); |
|
479 } |
|
480 |
|
481 void HgWidgetTestView::setScrollBarInteractive( bool value ) |
|
482 { |
|
483 if( value ) |
|
484 setScrollBarPolicy(HgWidget::ScrollBarAlwaysOn); |
|
485 |
|
486 mWidget->scrollBar()->setInteractive(value); |
|
487 |
|
488 if (mWidgetType == HgWidgetCoverflow) { |
|
489 mWidget->setIndexFeedbackPolicy(HgWidget::IndexFeedbackSingleCharacter); |
|
490 } |
|
491 |
|
492 } |
|
493 |
|
494 void HgWidgetTestView::interactiveScrollBar() |
|
495 { |
|
496 setScrollBarInteractive(true); |
|
497 } |
|
498 |
|
499 void HgWidgetTestView::unInteractiveScrollBar() |
|
500 { |
|
501 setScrollBarInteractive(false); |
|
502 } |
|
503 |
|
504 HgWidget *HgWidgetTestView::createWidget(WidgetType type) const |
|
505 { |
|
506 FUNC_LOG; |
|
507 HANDLE_ERROR_NULL(mModel); |
|
508 HANDLE_ERROR_NULL(mSelectionModel); |
|
509 |
|
510 Qt::Orientation scrollDirection = !mToggleOrientation ? Qt::Vertical : Qt::Horizontal ; |
|
511 |
|
512 HgWidget* widget = 0; |
|
513 |
|
514 switch (type) { |
|
515 case HgWidgetGrid: |
|
516 widget = new HgGrid(scrollDirection); |
|
517 break; |
|
518 case HgWidgetCoverflow: |
|
519 widget = new HgMediawall(); |
|
520 break; |
|
521 default: |
|
522 break; |
|
523 } |
|
524 |
|
525 HANDLE_ERROR_NULL(widget); |
|
526 |
|
527 widget->setModel(mModel); |
|
528 widget->setSelectionModel(mSelectionModel); |
|
529 widget->setLongPressEnabled(true); |
|
530 widget->scrollTo(widget->currentIndex()); |
|
531 |
|
532 return widget; |
|
533 } |
|
534 |
|
535 HgWidget *HgWidgetTestView::copyWidget() const |
|
536 { |
|
537 FUNC_LOG; |
|
538 HANDLE_ERROR_NULL(mWidget); |
|
539 |
|
540 HgWidget* widget = createWidget(mWidgetType); |
|
541 widget->setPreferredSize(mWidget->size()); |
|
542 |
|
543 HgMediawall *original = qobject_cast<HgMediawall *>(mWidget); |
|
544 HgMediawall *copy = qobject_cast<HgMediawall *>(widget); |
|
545 if (original && copy) { |
|
546 copy->setTitlePosition(original->titlePosition()); |
|
547 copy->setDescriptionPosition(original->descriptionPosition()); |
|
548 copy->setTitleFontSpec(original->titleFontSpec()); |
|
549 copy->setDescriptionFontSpec(original->descriptionFontSpec()); |
|
550 } |
|
551 |
|
552 return widget; |
|
553 } |
|
554 |
|
555 void HgWidgetTestView::feedqimages() |
|
556 { |
|
557 mModel->setImageDataType(HgWidgetTestDataModel::TypeQImage); |
|
558 } |
|
559 |
|
560 void HgWidgetTestView::feedqicons() |
|
561 { |
|
562 mModel->setImageDataType(HgWidgetTestDataModel::TypeQIcon); |
|
563 } |
|
564 |
|
565 void HgWidgetTestView::feedhbicons() |
|
566 { |
|
567 mModel->setImageDataType(HgWidgetTestDataModel::TypeHbIcon); |
|
568 } |
|
569 |
|
570 void HgWidgetTestView::flipClosed() |
|
571 { |
|
572 delete mFlipWidget; |
|
573 mFlipWidget = 0; |
|
574 mModel->setData(mFlippedIndex, true, Qt::UserRole+1); |
|
575 |
|
576 if (mFrontItem) { |
|
577 mFrontItem->setVisible(true); |
|
578 } |
|
579 |
|
580 } |
|
581 void HgWidgetTestView::orientationChanged() |
|
582 { |
|
583 mWidget->orientationChanged(Qt::Horizontal); |
|
584 } |
|
585 |
|
586 void HgWidgetTestView::onScrollingStarted() |
|
587 { |
|
588 FUNC_LOG; |
|
589 |
|
590 // scrolling started, need to hide |
|
591 // label displaying full resolution image |
|
592 if (mFrontItem) |
|
593 mFrontItem->setVisible(false); |
|
594 |
|
595 } |
|
596 |
|
597 void HgWidgetTestView::onScrollingEnded() |
|
598 { |
|
599 FUNC_LOG; |
|
600 |
|
601 if (mModel->lowResImagesEnabled()) { |
|
602 |
|
603 if (!mWidget) |
|
604 return; |
|
605 |
|
606 // get index to current item |
|
607 QModelIndex index = mWidget->currentIndex(); |
|
608 if (!index.isValid()) |
|
609 return; |
|
610 |
|
611 // get outlines of the item so we know where to render |
|
612 QPolygonF poly; |
|
613 if (!mWidget->getItemOutline(index, poly)) |
|
614 return; |
|
615 |
|
616 // fetch highresolution image from the model |
|
617 QVariant imgVariant = mModel->data(index, Qt::UserRole+2); |
|
618 if (imgVariant.isNull()) |
|
619 return; |
|
620 |
|
621 QRectF itemRect = poly.boundingRect(); |
|
622 |
|
623 // show it using HbLabel |
|
624 QPixmap pixmap = imgVariant.value<QPixmap>().scaled(itemRect.width(), itemRect.height()); |
|
625 |
|
626 if (!mFrontItem) { |
|
627 mFrontItem = new HbLabel(this); |
|
628 } |
|
629 |
|
630 |
|
631 mFrontItem->setVisible(false); |
|
632 mFrontItem->setIcon(HbIcon(pixmap)); |
|
633 mFrontItem->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); |
|
634 mFrontItem->setPos(itemRect.center() - QPointF(itemRect.width()/2, itemRect.height()/2)); |
|
635 mFrontItem->resize(itemRect.width(), itemRect.height()); |
|
636 mFrontItem->setVisible(true); |
|
637 |
|
638 } |
|
639 |
|
640 } |
|
641 |
|
642 void HgWidgetTestView::toggleLowResForCoverflow() |
|
643 { |
|
644 if (mWidgetType == HgWidgetCoverflow) { |
|
645 mModel->enableLowResImages(mUseLowResAction->isChecked()); |
|
646 initWidget(mWidgetType); |
|
647 } |
|
648 } |
|
649 |
|
650 void HgWidgetTestView::setTitleAboveImage() |
|
651 { |
|
652 FUNC_LOG; |
|
653 HgMediawall *mediawall = qobject_cast<HgMediawall *>(mWidget); |
|
654 if (mediawall) { |
|
655 mediawall->setTitlePosition(HgMediawall::PositionAboveImage); |
|
656 } |
|
657 } |
|
658 |
|
659 void HgWidgetTestView::setTitleBelowImage() |
|
660 { |
|
661 FUNC_LOG; |
|
662 HgMediawall *mediawall = qobject_cast<HgMediawall *>(mWidget); |
|
663 if (mediawall) { |
|
664 mediawall->setTitlePosition(HgMediawall::PositionBelowImage); |
|
665 } |
|
666 } |
|
667 |
|
668 void HgWidgetTestView::setTitleHidden() |
|
669 { |
|
670 FUNC_LOG; |
|
671 HgMediawall *mediawall = qobject_cast<HgMediawall *>(mWidget); |
|
672 if (mediawall) { |
|
673 mediawall->setTitlePosition(HgMediawall::PositionNone); |
|
674 } |
|
675 } |
|
676 |
|
677 void HgWidgetTestView::setDescriptionAboveImage() |
|
678 { |
|
679 FUNC_LOG; |
|
680 HgMediawall *mediawall = qobject_cast<HgMediawall *>(mWidget); |
|
681 if (mediawall) { |
|
682 mediawall->setDescriptionPosition(HgMediawall::PositionAboveImage); |
|
683 } |
|
684 } |
|
685 |
|
686 void HgWidgetTestView::setDescriptionBelowImage() |
|
687 { |
|
688 FUNC_LOG; |
|
689 HgMediawall *mediawall = qobject_cast<HgMediawall *>(mWidget); |
|
690 if (mediawall) { |
|
691 mediawall->setDescriptionPosition(HgMediawall::PositionBelowImage); |
|
692 } |
|
693 } |
|
694 |
|
695 void HgWidgetTestView::setDescriptionHidden() |
|
696 { |
|
697 FUNC_LOG; |
|
698 HgMediawall *mediawall = qobject_cast<HgMediawall *>(mWidget); |
|
699 if (mediawall) { |
|
700 mediawall->setDescriptionPosition(HgMediawall::PositionNone); |
|
701 } |
|
702 } |