16 */ |
16 */ |
17 |
17 |
18 #include <QGesture> |
18 #include <QGesture> |
19 #include <QPainter> |
19 #include <QPainter> |
20 #include <QTimer> |
20 #include <QTimer> |
21 #include <hbgridviewitem> |
21 #include <HbMainWindow> |
22 #include <hbmainwindow> |
22 #include "HgContainer.h" |
23 #include "hgcontainer.h" |
|
24 #include "hgmediawallrenderer.h" |
23 #include "hgmediawallrenderer.h" |
25 #include "hgquad.h" |
24 #include "hgquad.h" |
26 #include "hgvgquadrenderer.h" |
25 #include "hgvgquadrenderer.h" |
27 #include "hgvgimage.h" |
26 #include "hgvgimage.h" |
28 #include "hgwidgetitem.h" |
27 #include "hgwidgetitem.h" |
29 #include "trace.h" |
28 #include "trace.h" |
30 |
29 |
31 //#include <hbstyleoptioncheckbox.h> |
30 #include <HbCheckBox> |
32 //#include <hbcheckbox> |
31 #include <HbGridViewItem> |
33 #include <hbgridviewitem> |
32 #include <HbGridView> |
34 #include <hbgridview> |
33 #include <HbIconItem> |
35 #include <hbiconitem> |
34 #include <QAbstractItemModel> |
36 #include <qabstractitemmodel> |
35 #include <HbTapGesture> |
37 #include <hbtapgesture> |
|
38 #include "hglongpressvisualizer.h" |
36 #include "hglongpressvisualizer.h" |
39 |
37 |
40 static const qreal KSpringKScrolling(50.0); |
38 static const qreal KSpringKScrolling(50.0); |
41 static const qreal KSpringKScrollBar(10.0); |
39 static const qreal KSpringKScrollBar(10.0); |
42 static const qreal KSpringDampingScrolling(20.0); |
40 static const qreal KSpringDampingScrolling(20.0); |
503 |
501 |
504 void HgContainer::gestureEvent(QGestureEvent *event) |
502 void HgContainer::gestureEvent(QGestureEvent *event) |
505 { |
503 { |
506 FUNC_LOG; |
504 FUNC_LOG; |
507 |
505 |
|
506 if (mItems.count() == 0) { |
|
507 // we have no items so no need to handle the gesture. |
|
508 event->ignore(); |
|
509 return; |
|
510 } |
|
511 |
508 bool eventHandled(false); |
512 bool eventHandled(false); |
509 // Event may contain more than one gesture type |
513 // Event may contain more than one gesture type |
510 HbTapGesture *tap = 0; |
514 HbTapGesture *tap = 0; |
511 if (QGesture *gesture = event->gesture(Qt::TapGesture)) { |
515 if (QGesture *gesture = event->gesture(Qt::TapGesture)) { |
512 tap = static_cast<HbTapGesture *>(event->gesture(Qt::TapGesture)); |
516 tap = static_cast<HbTapGesture *>(event->gesture(Qt::TapGesture)); |
539 mRenderer = createRenderer(scrollDirection); |
543 mRenderer = createRenderer(scrollDirection); |
540 mOrientation = scrollDirection; |
544 mOrientation = scrollDirection; |
541 |
545 |
542 mQuadRenderer = mRenderer->getRenderer(); |
546 mQuadRenderer = mRenderer->getRenderer(); |
543 |
547 |
544 QImage markImage(":/images/mark.svg"); |
548 // Fetch icons for marking mode (on and off states). |
545 if (markImage.isNull()) { |
549 |
546 ERROR("Failed to load :/images/mark.svg"); |
|
547 } |
|
548 mMarkImageOn = mQuadRenderer->createNativeImage(); |
550 mMarkImageOn = mQuadRenderer->createNativeImage(); |
549 HANDLE_ERROR_NULL(mMarkImageOn); |
|
550 if (mMarkImageOn) { |
|
551 mMarkImageOn->setImage(markImage); |
|
552 } |
|
553 |
|
554 /* mMarkImageOn = mQuadRenderer->createNativeImage(); |
|
555 HANDLE_ERROR_NULL(mMarkImageOn); |
551 HANDLE_ERROR_NULL(mMarkImageOn); |
556 mMarkImageOff = mQuadRenderer->createNativeImage(); |
552 mMarkImageOff = mQuadRenderer->createNativeImage(); |
557 HANDLE_ERROR_NULL(mMarkImageOff); |
553 HANDLE_ERROR_NULL(mMarkImageOff); |
558 |
554 |
559 // Fetch icons for marking mode (on and off states). |
555 // Since there is no way to create the icons directly currently |
560 QGraphicsItem* checkBox = style()->createPrimitive(HbStyle::P_CheckBox_icon, this); |
556 // lets create HbCheckBox and ask primitives from it. |
561 HbIconItem* iconItem = static_cast<HbIconItem*>(checkBox); |
557 HbCheckBox* checkBox = new HbCheckBox(); |
562 HbStyleOptionCheckBox checkBoxOption; |
558 checkBox->setCheckState(Qt::Checked); |
563 checkBoxOption.state = QStyle::State_On; |
559 QGraphicsItem *icon = checkBox->HbWidget::primitive("icon"); |
564 style()->updatePrimitive(iconItem, HbStyle::P_CheckBox_icon, &checkBoxOption); |
560 HbIconItem *iconItem = 0; |
565 |
561 if (icon) { |
566 if (mMarkImageOn) { |
562 iconItem = static_cast<HbIconItem*>(icon); |
567 mMarkImageOn->setPixmap(iconItem->icon().pixmap()); |
563 if (mMarkImageOn) { |
568 } |
564 mMarkImageOn->setPixmap(iconItem->icon().pixmap()); |
569 |
565 } |
570 checkBoxOption.state = QStyle::State_Off; |
566 } |
571 style()->updatePrimitive(iconItem, HbStyle::P_CheckBox_icon, &checkBoxOption); |
567 checkBox->setCheckState(Qt::Unchecked); |
572 if (mMarkImageOff) { |
568 icon = checkBox->HbWidget::primitive("icon"); |
573 mMarkImageOff->setPixmap(iconItem->icon().pixmap()); |
569 if (icon) { |
574 } |
570 iconItem = static_cast<HbIconItem*>(icon); |
575 |
571 if (mMarkImageOff) { |
|
572 mMarkImageOff->setPixmap(iconItem->icon().pixmap()); |
|
573 } |
|
574 } |
576 delete checkBox; |
575 delete checkBox; |
577 */ |
576 |
578 connect(&mSpring, SIGNAL(updated()), SLOT(updateBySpringPosition())); |
577 connect(&mSpring, SIGNAL(updated()), SLOT(updateBySpringPosition())); |
579 connect(&mSpring, SIGNAL(started()), SIGNAL(scrollingStarted())); |
578 connect(&mSpring, SIGNAL(started()), SIGNAL(scrollingStarted())); |
580 connect(&mSpring, SIGNAL(started()), SLOT(onScrollingStarted())); |
579 connect(&mSpring, SIGNAL(started()), SLOT(onScrollingStarted())); |
581 connect(&mSpring, SIGNAL(ended()), SIGNAL(scrollingEnded())); |
580 connect(&mSpring, SIGNAL(ended()), SIGNAL(scrollingEnded())); |
582 connect(&mSpring, SIGNAL(ended()), SLOT(onScrollingEnded())); |
581 connect(&mSpring, SIGNAL(ended()), SLOT(onScrollingEnded())); |
881 QList<HgQuad*> quads = mRenderer->getVisibleQuads(); |
880 QList<HgQuad*> quads = mRenderer->getVisibleQuads(); |
882 QList<QModelIndex> result; |
881 QList<QModelIndex> result; |
883 for (int i = 0; i < quads.count(); i++) { |
882 for (int i = 0; i < quads.count(); i++) { |
884 bool ok; |
883 bool ok; |
885 int index = quads.at(i)->userData().toInt(&ok); |
884 int index = quads.at(i)->userData().toInt(&ok); |
886 result.append(itemByIndex(index)->modelIndex()); |
885 HgWidgetItem *item = itemByIndex(index); |
|
886 if (item) |
|
887 result.append(item->modelIndex()); |
887 } |
888 } |
888 qSort(result); |
889 qSort(result); |
889 return result; |
890 return result; |
890 } |
891 } |
891 |
892 |
892 void HgContainer::itemDataChanged(const int &firstIndex, const int &lastIndex) |
893 void HgContainer::itemDataChanged(const int &firstIndex, const int &lastIndex) |
893 { |
894 { |
894 FUNC_LOG; |
895 FUNC_LOG; |
895 |
896 |
896 int firstItemOnScreen = 0, lastItemOnScreen = 0; |
897 int firstItemOnScreen = 0, lastItemOnScreen = 0; |
897 firstItemOnScreen = mSpring.pos().x(); |
898 firstItemOnScreen = mSpring.pos().x(); |
898 firstItemOnScreen *= rowCount(); |
899 firstItemOnScreen *= rowCount(); |
899 |
900 |
900 int itemsOnScreen = mRenderer->getVisibleQuads().count(); |
901 int itemsOnScreen = mRenderer->getVisibleQuads().count(); |
901 lastItemOnScreen = firstItemOnScreen+itemsOnScreen; |
902 lastItemOnScreen = firstItemOnScreen+itemsOnScreen; |
902 |
903 |
903 if ((firstIndex >= firstItemOnScreen && firstIndex < lastItemOnScreen) || |
904 if ( itemsOnScreen == 0 || (firstIndex >= firstItemOnScreen && firstIndex < lastItemOnScreen) || |
904 (lastIndex >= firstItemOnScreen && lastIndex < lastItemOnScreen)) { |
905 (lastIndex >= firstItemOnScreen && lastIndex < lastItemOnScreen)) { |
905 update(); |
906 update(); |
906 } |
907 } |
907 } |
908 } |
908 |
909 |
909 void HgContainer::selectItem(int index) |
910 void HgContainer::selectItem(int index) |
910 { |
911 { |
|
912 Q_UNUSED(index) |
911 // TODO: replace this with own selection implementation |
913 // TODO: replace this with own selection implementation |
912 /* if (index < 0 && index >= mItems.count()) |
914 /* if (index < 0 && index >= mItems.count()) |
913 return; |
915 return; |
914 |
916 |
915 mHitItemIndex = index; |
917 mHitItemIndex = index; |