26 #include "hbabstractviewitem_p.h" |
26 #include "hbabstractviewitem_p.h" |
27 |
27 |
28 #include <hbabstractviewitem.h> |
28 #include <hbabstractviewitem.h> |
29 #include <hbabstractitemview.h> |
29 #include <hbabstractitemview.h> |
30 #include <hbnamespace.h> |
30 #include <hbnamespace.h> |
31 #include <hbstyleoptionabstractviewitem_p.h> |
|
32 #include <hbstyle.h> |
31 #include <hbstyle.h> |
33 #include <hbiconitem.h> |
32 #include <hbiconitem.h> |
|
33 #include <hbiconitem_p.h> |
34 #include <hbframebackground.h> |
34 #include <hbframebackground.h> |
35 #include <hbabstractitemview_p.h> |
35 #include <hbabstractitemview_p.h> |
36 #include <hbwidgetfeedback.h> |
36 #include <hbwidgetfeedback.h> |
37 #include <hbtapgesture.h> |
37 #include <hbtapgesture.h> |
38 #include <hbnamespace_p.h> |
38 #include <hbnamespace_p.h> |
39 #include <hbevent.h> |
39 #include <hbevent.h> |
|
40 #include <hbtextitem.h> |
|
41 #include <hbiconitem.h> |
|
42 #include <hbstyletextprimitivedata.h> |
|
43 #include <hbstyleframeprimitivedata.h> |
|
44 #include <hbstyleiconprimitivedata.h> |
|
45 #include <hbstyletouchareaprimitivedata.h> |
40 |
46 |
41 #include <QPersistentModelIndex> |
47 #include <QPersistentModelIndex> |
42 #include <QGraphicsLayout> |
48 #include <QGraphicsLayout> |
43 #include <QVariant> |
49 #include <QVariant> |
44 #include <QCoreApplication> |
50 #include <QCoreApplication> |
45 #include <QEvent> |
51 #include <QEvent> |
46 #include <QTimer> |
52 #include <QTimer> |
47 #include <QGraphicsScene> |
53 #include <QGraphicsScene> |
48 |
54 |
49 #include <QPixmap> |
55 #include <QPixmap> |
50 #include <QPainter> |
|
51 #include <QDebug> |
|
52 #include <QChildEvent> |
56 #include <QChildEvent> |
53 |
57 |
54 #include <QGesture> |
58 #include <QGesture> |
55 #include <QGestureEvent> |
59 #include <QGestureEvent> |
56 #include <QGraphicsSceneEvent> |
60 #include <QGraphicsSceneEvent> |
|
61 |
|
62 #include <QDebug> |
57 |
63 |
58 const QString KDefaultLayoutOption = "default"; |
64 const QString KDefaultLayoutOption = "default"; |
59 const int HbAbstractViewItemShared::ViewItemDeferredDeleteEvent = QEvent::registerEventType(); |
65 const int HbAbstractViewItemShared::ViewItemDeferredDeleteEvent = QEvent::registerEventType(); |
60 const int HbViewItemPressDelay = 100; |
66 const int HbViewItemPressDelay = 100; |
61 |
67 |
183 In most subclasses, createItem should be implemented like this: |
190 In most subclasses, createItem should be implemented like this: |
184 |
191 |
185 \snippet{ultimatecodesnippet/customlistviewitem.cpp,1} |
192 \snippet{ultimatecodesnippet/customlistviewitem.cpp,1} |
186 */ |
193 */ |
187 |
194 |
|
195 void HbAbstractViewItemShared::updateIconItemsAsyncMode() |
|
196 { |
|
197 foreach (HbAbstractViewItem *item, mCloneItems) { |
|
198 QList<QGraphicsItem *> childItems = item->childItems(); |
|
199 foreach (QGraphicsItem *child, childItems) { |
|
200 item->d_func()->updateIconItemsAsyncMode(child); |
|
201 } |
|
202 } |
|
203 } |
|
204 |
|
205 void HbAbstractViewItemShared::setItemView(HbAbstractItemView *view) |
|
206 { |
|
207 if (view != mItemView) { |
|
208 if (mItemView) { |
|
209 disconnect(mItemView, SIGNAL(scrollingStarted()), this, SLOT(scrollingStarted())); |
|
210 } |
|
211 mItemView = view; |
|
212 if (mItemView) { |
|
213 connect(mItemView, SIGNAL(scrollingStarted()), this, SLOT(scrollingStarted())); |
|
214 } |
|
215 } |
|
216 } |
|
217 |
188 void HbAbstractViewItemShared::pressStateChangeTimerTriggered() |
218 void HbAbstractViewItemShared::pressStateChangeTimerTriggered() |
189 { |
219 { |
190 HbWidgetFeedback::triggered(mPressedItem, Hb::InstantPressed, 0); |
220 HbWidgetFeedback::triggered(mPressedItem, Hb::InstantPressed, 0); |
191 mPressedItem->pressStateChanged(true, mAnimatePress); |
221 mPressedItem->pressStateChanged(true, mAnimatePress); |
192 } |
222 } |
247 |
289 |
248 if (mFocusItem) { |
290 if (mFocusItem) { |
249 QCoreApplication::postEvent(q, new QEvent((QEvent::Type)HbAbstractViewItemShared::ViewItemDeferredDeleteEvent)); |
291 QCoreApplication::postEvent(q, new QEvent((QEvent::Type)HbAbstractViewItemShared::ViewItemDeferredDeleteEvent)); |
250 } |
292 } |
251 } |
293 } |
|
294 |
|
295 void HbAbstractViewItemPrivate::_q_childrenChanged() |
|
296 { |
|
297 Q_Q(HbAbstractViewItem); |
|
298 |
|
299 QList<QGraphicsItem *> childList = q->childItems(); |
|
300 int currentCount = childList.count(); |
|
301 int previousCount = mChildren.count(); |
|
302 |
|
303 if (currentCount > previousCount) { |
|
304 QGraphicsItem *addedItem = 0; |
|
305 for (int i = 0; i < currentCount; ++i) { |
|
306 QGraphicsItem *item = childList.at(i); |
|
307 if (item != mChildren.value(i)) { |
|
308 addedItem = item; |
|
309 break; |
|
310 } |
|
311 } |
|
312 |
|
313 if (usePixmapCache()) { |
|
314 setChildFlags(addedItem, true); |
|
315 } |
|
316 |
|
317 updateIconItemsAsyncMode(addedItem); |
|
318 } else { |
|
319 if (mUpdateItems.count()) { |
|
320 int itemCount = mUpdateItems.count(); |
|
321 for (int i = 0; i < itemCount; ++i) { |
|
322 QGraphicsItem *item = mUpdateItems.at(i); |
|
323 int index = childList.indexOf(item); |
|
324 if (index == -1) { |
|
325 mUpdateItems.remove(i); |
|
326 mUpdateItems.squeeze(); |
|
327 } |
|
328 } |
|
329 } |
|
330 } |
|
331 |
|
332 mChildren = childList; |
|
333 } |
|
334 |
252 |
335 |
253 void HbAbstractViewItemPrivate::repolishCloneItems() |
336 void HbAbstractViewItemPrivate::repolishCloneItems() |
254 { |
337 { |
255 int count(mSharedData->mCloneItems.count()); |
338 int count(mSharedData->mCloneItems.count()); |
256 for (int i = 0; i < count; ++i) { |
339 for (int i = 0; i < count; ++i) { |
443 child->paint(painter, option, 0); |
526 child->paint(painter, option, 0); |
444 painter->setCompositionMode(mode); |
527 painter->setCompositionMode(mode); |
445 painter->translate(-child->pos()); |
528 painter->translate(-child->pos()); |
446 continue; |
529 continue; |
447 } |
530 } |
448 paintChildItemsRecursively(child,painter,option); |
531 paintChildItemsRecursively(child,painter,option, child->pos()); |
449 } |
532 } |
450 mInPaintItems = false; |
533 mInPaintItems = false; |
451 } |
534 } |
452 |
535 |
453 void HbAbstractViewItemPrivate::paintChildItemsRecursively(QGraphicsItem *child, QPainter *painter,QStyleOptionGraphicsItem *option) |
536 void HbAbstractViewItemPrivate::paintChildItemsRecursively(QGraphicsItem *child, |
|
537 QPainter *painter, |
|
538 QStyleOptionGraphicsItem *option, |
|
539 const QPointF &translatePosition) |
454 { |
540 { |
455 if (!child->isVisible()) |
541 if (!child->isVisible()) |
456 return; |
542 return; |
457 int i = 0; |
543 int i = 0; |
458 QList<QGraphicsItem *> children = child->childItems(); |
544 QList<QGraphicsItem *> children = child->childItems(); |
459 int count(children.size()); |
545 int count(children.size()); |
460 painter->translate(child->pos()); |
546 if (!translatePosition.isNull()) { |
|
547 painter->translate(translatePosition); |
|
548 } |
461 // Draw children behind |
549 // Draw children behind |
462 for (i = 0; i < count; ++i) { |
550 for (i = 0; i < count; ++i) { |
463 QGraphicsItem *subChild = children.at(i); |
551 QGraphicsItem *subChild = children.at(i); |
464 if (!(subChild->flags() & QGraphicsItem::ItemStacksBehindParent)) |
552 if (!(subChild->flags() & QGraphicsItem::ItemStacksBehindParent)) |
465 break; |
553 break; |
466 paintChildItemsRecursively(subChild, painter,option); |
554 paintChildItemsRecursively(subChild, painter,option, subChild->pos()); |
467 } |
555 } |
468 option->exposedRect = child->boundingRect(); |
556 option->exposedRect = child->boundingRect(); |
469 |
557 |
470 bool restorePainter = false; |
558 bool restorePainter = false; |
471 if (child->flags() & QGraphicsItem::ItemClipsToShape) { |
559 if (child->flags() & QGraphicsItem::ItemClipsToShape) { |
514 subChild == mBackPixmapPainter) { |
605 subChild == mBackPixmapPainter) { |
515 continue; |
606 continue; |
516 } |
607 } |
517 setChildFlags(subChild, pixmapCacheEnabled); |
608 setChildFlags(subChild, pixmapCacheEnabled); |
518 } |
609 } |
|
610 } |
|
611 |
|
612 void HbAbstractViewItemPrivate::drawSubPixmap(QPixmap *pixmap, |
|
613 QPainter *painter, |
|
614 const QTransform &itemToPixmapTransform, |
|
615 const QStyleOptionGraphicsItem *option) |
|
616 { |
|
617 Q_Q(HbAbstractViewItem); |
|
618 |
|
619 QPixmap subPix; |
|
620 QPainter pixmapPainter; |
|
621 QStyleOptionGraphicsItem pixmapOption(*option); |
|
622 |
|
623 QList<QGraphicsItem *> childList = q->childItems(); |
|
624 |
|
625 foreach (QGraphicsItem *subChild, mUpdateItems) { |
|
626 pixmapOption.exposedRect = subChild->boundingRect(); |
|
627 |
|
628 subPix = QPixmap(pixmapOption.exposedRect.toRect().size()); |
|
629 subPix.fill(Qt::transparent); |
|
630 |
|
631 pixmapPainter.begin(&subPix); |
|
632 pixmapPainter.setRenderHints(pixmapPainter.renderHints(), false); |
|
633 pixmapPainter.setRenderHints(painter->renderHints(), true); |
|
634 |
|
635 // Draw items on the pixmap |
|
636 paintChildItemsRecursively(subChild, &pixmapPainter, &pixmapOption, QPointF()); |
|
637 |
|
638 // Search & paint overlapping child items. |
|
639 QRectF subChildRectRelativeToParent(subChild->pos(), subChild->boundingRect().size()); |
|
640 |
|
641 int currentIndex = childList.indexOf(subChild) + 1; |
|
642 int childCount = childList.count(); |
|
643 while (currentIndex < childCount) { |
|
644 QGraphicsItem *item = childList.at(currentIndex); |
|
645 if (item != mNonCachableItem |
|
646 && item != mFrontPixmapPainter |
|
647 && item != mBackPixmapPainter) { |
|
648 QRectF itemRectRelativeToParent(item->pos(), item->boundingRect().size()); |
|
649 |
|
650 QRectF intersectionRect(itemRectRelativeToParent.intersected(subChildRectRelativeToParent)); |
|
651 if (!intersectionRect.isNull()) { |
|
652 QStyleOptionGraphicsItem itemPixmapOption(*option); |
|
653 itemPixmapOption.exposedRect = intersectionRect.translated(-item->pos()); |
|
654 |
|
655 paintChildItemsRecursively(item, &pixmapPainter, &itemPixmapOption, subChild->mapFromParent(itemRectRelativeToParent.topLeft())); |
|
656 } |
|
657 } |
|
658 ++currentIndex; |
|
659 } |
|
660 |
|
661 pixmapPainter.end(); |
|
662 |
|
663 if (!subPix.isNull()) { |
|
664 // Blit the subpixmap into the main pixmap. |
|
665 pixmapPainter.begin(pixmap); |
|
666 pixmapPainter.setWorldTransform(itemToPixmapTransform, true); |
|
667 pixmapPainter.translate(subChild->pos()); |
|
668 pixmapPainter.setCompositionMode(QPainter::CompositionMode_Source); |
|
669 pixmapPainter.setClipRect(pixmapOption.exposedRect); |
|
670 pixmapPainter.drawPixmap(pixmapOption.exposedRect.topLeft(), subPix); |
|
671 pixmapPainter.end(); |
|
672 } |
|
673 } |
|
674 mUpdateItems.clear(); |
519 } |
675 } |
520 |
676 |
521 void HbAbstractViewItemPrivate::updatePixmap(QPixmap *pixmap, |
677 void HbAbstractViewItemPrivate::updatePixmap(QPixmap *pixmap, |
522 QPainter *painter, |
678 QPainter *painter, |
523 const QTransform &itemToPixmapTransform, |
679 const QTransform &itemToPixmapTransform, |
546 mFrontPixmapPainter->setPixmap(0); |
702 mFrontPixmapPainter->setPixmap(0); |
547 } |
703 } |
548 |
704 |
549 if (mBackPixmapPainter) { |
705 if (mBackPixmapPainter) { |
550 mBackPixmapPainter->setPixmap(0); |
706 mBackPixmapPainter->setPixmap(0); |
|
707 } |
|
708 } |
|
709 |
|
710 bool HbAbstractViewItemPrivate::iconLoadedCallback(HbIconItem *target, void *param) |
|
711 { |
|
712 HbAbstractViewItemPrivate* d_ptr = (HbAbstractViewItemPrivate*)param; |
|
713 return d_ptr->iconLoaded(target); |
|
714 } |
|
715 |
|
716 bool HbAbstractViewItemPrivate::iconLoaded(HbIconItem *target) |
|
717 { |
|
718 Q_Q(HbAbstractViewItem); |
|
719 |
|
720 bool result = false; |
|
721 |
|
722 if (usePixmapCache()) { |
|
723 mUpdateItems.append(target); |
|
724 if (mSharedData->mItemView && !mSharedData->mItemView->isScrolling()) { |
|
725 q->update(); |
|
726 } |
|
727 |
|
728 result = true; |
|
729 } |
|
730 |
|
731 return result; |
|
732 } |
|
733 |
|
734 void HbAbstractViewItemPrivate::updateIconItemsAsyncMode(QGraphicsItem *item) |
|
735 { |
|
736 if (mSharedData->mItemView) { |
|
737 HbIconItem *iconItem = qgraphicsitem_cast<HbIconItem *>(item); |
|
738 if (iconItem) { |
|
739 HbAbstractItemView::IconLoadPolicy loadPolicy = mSharedData->mItemView->iconLoadPolicy(); |
|
740 if (loadPolicy == HbAbstractItemView::LoadAsynchronouslyAlways |
|
741 || (loadPolicy == HbAbstractItemView::LoadAsynchronouslyWhenScrolling |
|
742 && mSharedData->mItemView->isScrolling())) { |
|
743 HbIconItemPrivate::d_ptr(iconItem)->setAsyncCallbackFilter(&HbAbstractViewItemPrivate::iconLoadedCallback, this); |
|
744 iconItem->setAsync(true); |
|
745 } else { |
|
746 iconItem->setAsync(false); |
|
747 } |
|
748 } |
551 } |
749 } |
552 } |
750 } |
553 |
751 |
554 /*! |
752 /*! |
555 Constructs an abstract view item with the given parent. |
753 Constructs an abstract view item with the given parent. |
712 { |
910 { |
713 HB_SDD( const HbAbstractViewItem ); |
911 HB_SDD( const HbAbstractViewItem ); |
714 return sd->mItemView; |
912 return sd->mItemView; |
715 } |
913 } |
716 |
914 |
717 /*! |
|
718 Populates a style option object for this widget based on its current state, and stores the output in \a option. |
|
719 */ |
|
720 void HbAbstractViewItem::initStyleOption(HbStyleOptionAbstractViewItem *option) const |
|
721 { |
|
722 HB_SDD( const HbAbstractViewItem ); |
|
723 |
|
724 HbWidget::initStyleOption(option); |
|
725 |
|
726 option->modelItemType = d->mModelItemType; |
|
727 option->index = d->mIndex; |
|
728 |
|
729 option->viewItemType = type(); |
|
730 option->checkState = d->mCheckState; |
|
731 option->background = d->mBackground; |
|
732 if (!option->background.isValid()) { |
|
733 if (option->modelItemType == Hb::StandardItem |
|
734 && !sd->mDefaultFrame.isNull()) { |
|
735 option->background = sd->mDefaultFrame; |
|
736 } |
|
737 } |
|
738 |
|
739 if ( sd->mItemView |
|
740 && sd->mItemView->selectionMode() == HbAbstractItemView::SingleSelection){ |
|
741 option->singleSelectionMode = true; |
|
742 } else { |
|
743 option->singleSelectionMode = false; |
|
744 } |
|
745 |
|
746 option->insidePopup = testAttribute(Hb::InsidePopup); |
|
747 } |
|
748 |
915 |
749 /*! |
916 /*! |
750 Check whether \a position is inside the selection area of the given selectionAreaType in the view item. |
917 Check whether \a position is inside the selection area of the given selectionAreaType in the view item. |
751 |
918 |
752 Default selection areas are for |
919 Default selection areas are for |
753 \li HbAbstractViewItem::SingleSelection mode: whole item |
920 \li HbAbstractViewItem::SingleSelection mode: whole item |
754 \li HbAbstractViewItem::MultiSelection mode: whole item. |
921 \li HbAbstractViewItem::MultiSelection mode: whole item. |
755 \li HbAbstractViewItem::ContiguousSelection mode: area of HbStylePrivate::P_ItemViewItem_touchmultiselection icon. |
922 \li HbAbstractViewItem::ContiguousSelection mode: area of icon of primitive with item name "multiselection-toucharea". |
756 |
923 |
757 The \a selectionAreaType tells what kind of selection area is requested. The parameter value ContiguousSelection returns |
924 The \a selectionAreaType tells what kind of selection area is requested. The parameter value ContiguousSelection returns |
758 the area where mouse movement will extend the selection to new items. By default this contiguous selection area is |
925 the area where mouse movement will extend the selection to new items. By default this contiguous selection is area of |
759 the HbStylePrivate::P_ItemViewItem_touchmultiselection. |
926 "multiselection-toucharea" primitive. |
760 |
927 |
761 */ |
928 */ |
762 bool HbAbstractViewItem::selectionAreaContains(const QPointF &position, SelectionAreaType selectionAreaType) const |
929 bool HbAbstractViewItem::selectionAreaContains(const QPointF &position, SelectionAreaType selectionAreaType) const |
763 { |
930 { |
764 Q_D(const HbAbstractViewItem); |
931 Q_D(const HbAbstractViewItem); |
802 if (d->mBackPixmapPainter) { |
969 if (d->mBackPixmapPainter) { |
803 d->mBackPixmapPainter->setSize(resizeEvent->newSize()); |
970 d->mBackPixmapPainter->setSize(resizeEvent->newSize()); |
804 } |
971 } |
805 |
972 |
806 if (d->mBackgroundItem || d->mFrame || d->mFocusItem) { |
973 if (d->mBackgroundItem || d->mFrame || d->mFocusItem) { |
807 initStyleOption(d->mSharedData->mStyleOption); |
|
808 if (d->mFocusItem) { |
974 if (d->mFocusItem) { |
809 HbStylePrivate::updatePrimitive(d->mFocusItem, HbStylePrivate::P_ItemViewItem_focus, d->mSharedData->mStyleOption); |
975 // HbFrameItem |
|
976 HbStyleFramePrimitiveData primitiveData; |
|
977 initPrimitiveData(&primitiveData, d->mFocusItem); |
|
978 style()->updatePrimitive(d->mFocusItem, &primitiveData, this); |
810 } |
979 } |
811 |
980 |
812 if (d->mFrame) { |
981 if (d->mFrame) { |
813 HbStylePrivate::updatePrimitive(d->mFrame, HbStylePrivate::P_ItemViewItem_frame, d->mSharedData->mStyleOption); |
982 // HbFrameItem |
|
983 HbStyleFramePrimitiveData primitiveData; |
|
984 initPrimitiveData(&primitiveData, d->mFrame); |
|
985 style()->updatePrimitive(d->mFrame, &primitiveData, this); |
814 } |
986 } |
815 |
987 |
816 if (d->mBackgroundItem) { |
988 if (d->mBackgroundItem) { |
817 HbStylePrivate::updatePrimitive(d->mBackgroundItem, HbStylePrivate::P_ItemViewItem_background, d->mSharedData->mStyleOption); |
989 // HbIconItem |
|
990 HbStyleIconPrimitiveData primitiveData; |
|
991 initPrimitiveData(&primitiveData, d->mBackgroundItem); |
|
992 style()->updatePrimitive(d->mBackgroundItem, &primitiveData, this); |
818 } |
993 } |
819 } |
994 } |
820 break; |
995 break; |
821 } |
996 } |
822 case QEvent::LayoutDirectionChange: { |
997 case QEvent::LayoutDirectionChange: { |
885 d->releasePixmaps(); |
1060 d->releasePixmaps(); |
886 d->mResetPixmapCache = true; |
1061 d->mResetPixmapCache = true; |
887 } |
1062 } |
888 break; |
1063 break; |
889 } |
1064 } |
890 case ItemChildAddedChange: { |
|
891 Q_D(HbAbstractViewItem); |
|
892 if (d->usePixmapCache()) { |
|
893 d->setChildFlags(qvariant_cast<QGraphicsItem *>(value), true); |
|
894 } |
|
895 break; |
|
896 } |
|
897 default: |
1065 default: |
898 break; |
1066 break; |
899 } |
1067 } |
900 |
1068 |
901 return HbWidget::itemChange(change, value); |
1069 return HbWidget::itemChange(change, value); |
902 } |
1070 } |
|
1071 |
|
1072 /*! |
|
1073 Initializes the HbAbstractViewItem primitive data. |
|
1074 |
|
1075 This function calls HbWidgetBase::initPrimitiveData(). |
|
1076 \a primitiveData is data object, which is populated with data. \a primitive is the primitive. |
|
1077 */ |
|
1078 void HbAbstractViewItem::initPrimitiveData( HbStylePrimitiveData *primitiveData, |
|
1079 const QGraphicsObject *primitive) |
|
1080 { |
|
1081 Q_ASSERT_X(primitive && primitiveData, "HbAbstractViewItem::initPrimitiveData" , "NULL data not permitted"); |
|
1082 HB_SDD(HbAbstractViewItem); |
|
1083 |
|
1084 HbWidgetBase::initPrimitiveData(primitiveData, primitive); |
|
1085 if (primitiveData->type == HbStylePrimitiveData::SPD_Icon) { |
|
1086 HbStyleIconPrimitiveData *iconPrimitiveData = hbstyleprimitivedata_cast<HbStyleIconPrimitiveData*>(primitiveData); |
|
1087 |
|
1088 if (primitive ==d-> mBackgroundItem) { |
|
1089 iconPrimitiveData->geometry = boundingRect(); |
|
1090 |
|
1091 QVariant background = d->mBackground; |
|
1092 if (!background.isValid()) { |
|
1093 if ( d->mModelItemType == Hb::StandardItem |
|
1094 && !sd->mDefaultFrame.isNull()) { |
|
1095 background = sd->mDefaultFrame; |
|
1096 } |
|
1097 } |
|
1098 |
|
1099 if (background.canConvert<HbIcon>()){ |
|
1100 iconPrimitiveData->icon = background.value<HbIcon>(); |
|
1101 iconPrimitiveData->brush = QBrush(); |
|
1102 } else if (background.canConvert<QBrush>()){ |
|
1103 iconPrimitiveData->icon = HbIcon(); |
|
1104 iconPrimitiveData->brush = background.value<QBrush>(); |
|
1105 } else { |
|
1106 iconPrimitiveData->icon = HbIcon(); |
|
1107 iconPrimitiveData->brush = QBrush(); |
|
1108 } |
|
1109 } else if (primitive == d->mSelectionItem) { |
|
1110 int viewItemType = type(); |
|
1111 bool singleSelectionMode = false; |
|
1112 if (sd->mItemView |
|
1113 && sd->mItemView->selectionMode() == HbAbstractItemView::SingleSelection){ |
|
1114 singleSelectionMode = true; |
|
1115 } |
|
1116 |
|
1117 if (viewItemType == Hb::ItemType_RadioButtonListViewItem) { |
|
1118 if (d->mCheckState == Qt::Checked) { |
|
1119 iconPrimitiveData->iconState = QIcon::On; |
|
1120 iconPrimitiveData->iconName = QLatin1String("qtg_small_radio_selected"); |
|
1121 } else { |
|
1122 iconPrimitiveData->iconState = QIcon::Off; |
|
1123 iconPrimitiveData->iconName = QLatin1String("qtg_small_radio_unselected"); |
|
1124 } |
|
1125 } else { |
|
1126 if (d->mCheckState == Qt::Checked) { |
|
1127 iconPrimitiveData->iconState = QIcon::On; |
|
1128 if (singleSelectionMode) { |
|
1129 iconPrimitiveData->iconName = QLatin1String("qtg_small_tick"); |
|
1130 } else { |
|
1131 iconPrimitiveData->iconName = QLatin1String("qtg_small_selected"); |
|
1132 } |
|
1133 } else if (d->mCheckState == Qt::PartiallyChecked) { |
|
1134 iconPrimitiveData->iconState = QIcon::On; |
|
1135 iconPrimitiveData->iconName = QLatin1String("qtg_small_selected_partial"); |
|
1136 } else { |
|
1137 iconPrimitiveData->iconState = QIcon::Off; |
|
1138 if (singleSelectionMode) { |
|
1139 iconPrimitiveData->iconName = QLatin1String(""); |
|
1140 } else { |
|
1141 iconPrimitiveData->iconName = QLatin1String("qtg_small_unselected"); |
|
1142 } |
|
1143 } |
|
1144 } |
|
1145 } |
|
1146 } else if (primitiveData->type == HbStylePrimitiveData::SPD_Frame) { |
|
1147 HbStyleFramePrimitiveData *framePrimitiveData = hbstyleprimitivedata_cast<HbStyleFramePrimitiveData*>(primitiveData); |
|
1148 |
|
1149 if (primitive == d->mFrame ) { |
|
1150 framePrimitiveData->geometry = boundingRect(); |
|
1151 |
|
1152 QVariant background = d->mBackground; |
|
1153 if (!background.isValid()) { |
|
1154 if ( d->mModelItemType == Hb::StandardItem |
|
1155 && !sd->mDefaultFrame.isNull()) { |
|
1156 background = sd->mDefaultFrame; |
|
1157 } |
|
1158 } |
|
1159 |
|
1160 if (background.canConvert<HbFrameBackground>()) { |
|
1161 HbFrameBackground frame = background.value<HbFrameBackground>(); |
|
1162 framePrimitiveData->frameType = frame.frameType(); |
|
1163 framePrimitiveData->frameGraphicsName = frame.frameGraphicsName(); |
|
1164 } else { |
|
1165 int viewItemType = type(); |
|
1166 bool insidePopup = testAttribute(Hb::InsidePopup); |
|
1167 if (viewItemType == Hb::ItemType_TreeViewItem) { |
|
1168 if (d->mModelItemType == Hb::ParentItem) { |
|
1169 framePrimitiveData->frameType = HbFrameDrawer::NinePieces; |
|
1170 framePrimitiveData->frameGraphicsName = insidePopup ? |
|
1171 QLatin1String("qtg_fr_popup_list_parent_normal") : QLatin1String("qtg_fr_list_parent_normal"); |
|
1172 } else if (d->mModelItemType == Hb::SeparatorItem) { |
|
1173 framePrimitiveData->frameType = HbFrameDrawer::NinePieces; |
|
1174 framePrimitiveData->frameGraphicsName = QLatin1String("qtg_fr_list_separator"); |
|
1175 } else { |
|
1176 framePrimitiveData->frameType = HbFrameDrawer::NinePieces; |
|
1177 framePrimitiveData->frameGraphicsName = insidePopup ? |
|
1178 QLatin1String("qtg_fr_popup_list_normal") : QLatin1String("qtg_fr_list_normal"); |
|
1179 } |
|
1180 } else if (viewItemType == Hb::ItemType_ListViewItem |
|
1181 || viewItemType == Hb::ItemType_RadioButtonListViewItem) { |
|
1182 if (d->mModelItemType == Hb::SeparatorItem) { |
|
1183 framePrimitiveData->frameType = HbFrameDrawer::NinePieces; |
|
1184 framePrimitiveData->frameGraphicsName = QLatin1String("qtg_fr_list_separator"); |
|
1185 } else { |
|
1186 framePrimitiveData->frameType = HbFrameDrawer::NinePieces; |
|
1187 framePrimitiveData->frameGraphicsName = insidePopup ? |
|
1188 QLatin1String("qtg_fr_popup_list_normal") : QLatin1String("qtg_fr_list_normal"); |
|
1189 } |
|
1190 } else if (viewItemType == Hb::ItemType_GridViewItem |
|
1191 || viewItemType == HbPrivate::ItemType_ColorGridViewItem) { |
|
1192 framePrimitiveData->frameType = HbFrameDrawer::NinePieces; |
|
1193 framePrimitiveData->frameGraphicsName = insidePopup ? |
|
1194 QLatin1String("qtg_fr_popup_grid_normal") : QLatin1String("qtg_fr_grid_normal"); |
|
1195 } else{ |
|
1196 framePrimitiveData->frameGraphicsName = QString(); |
|
1197 } |
|
1198 } |
|
1199 } else if (primitive == d->mFocusItem) { |
|
1200 framePrimitiveData->geometry = boundingRect(); |
|
1201 |
|
1202 int viewItemType = type(); |
|
1203 bool insidePopup = testAttribute(Hb::InsidePopup); |
|
1204 if (viewItemType == Hb::ItemType_TreeViewItem |
|
1205 || viewItemType == Hb::ItemType_ListViewItem |
|
1206 || viewItemType == Hb::ItemType_RadioButtonListViewItem) { |
|
1207 framePrimitiveData->frameType = HbFrameDrawer::NinePieces; |
|
1208 framePrimitiveData->frameGraphicsName = insidePopup ? |
|
1209 QLatin1String("qtg_fr_popup_list_pressed") : QLatin1String("qtg_fr_list_pressed"); |
|
1210 } else if ( viewItemType == Hb::ItemType_GridViewItem |
|
1211 || viewItemType == HbPrivate::ItemType_ColorGridViewItem) { |
|
1212 framePrimitiveData->frameType = HbFrameDrawer::NinePieces; |
|
1213 framePrimitiveData->frameGraphicsName = insidePopup ? |
|
1214 QLatin1String("qtg_fr_popup_grid_pressed") : QLatin1String("qtg_fr_grid_pressed"); |
|
1215 } else{ |
|
1216 framePrimitiveData->frameGraphicsName = QString(); |
|
1217 } |
|
1218 } |
|
1219 |
|
1220 } // else if (primitiveData->type == HbStylePrimitiveData::SPD_TouchArea) { |
|
1221 // mMultiSelectionTouchArea: no data provided |
|
1222 } |
|
1223 |
|
1224 |
903 |
1225 |
904 /*! |
1226 /*! |
905 \reimp |
1227 \reimp |
906 |
1228 |
907 To optimize loading css/xml definitions to take place only once, this function should be |
1229 To optimize loading css/xml definitions to take place only once, this function should be |
941 } |
1263 } |
942 } |
1264 } |
943 } |
1265 } |
944 #endif |
1266 #endif |
945 |
1267 |
946 |
|
947 initStyleOption(d->mSharedData->mStyleOption); |
|
948 |
|
949 if (d->mBackgroundItem) { |
1268 if (d->mBackgroundItem) { |
950 HbStylePrivate::updatePrimitive(d->mBackgroundItem, HbStylePrivate::P_ItemViewItem_background, d->mSharedData->mStyleOption); |
1269 // HbIconItem |
|
1270 HbStyleIconPrimitiveData primitiveData; |
|
1271 initPrimitiveData(&primitiveData, d->mBackgroundItem); |
|
1272 style()->updatePrimitive(d->mBackgroundItem, &primitiveData, this); |
951 } |
1273 } |
952 |
1274 |
953 if (d->mFrame) { |
1275 if (d->mFrame) { |
954 HbStylePrivate::updatePrimitive(d->mFrame, HbStylePrivate::P_ItemViewItem_frame, d->mSharedData->mStyleOption); |
1276 // HbFrameItem |
|
1277 HbStyleFramePrimitiveData primitiveData; |
|
1278 initPrimitiveData(&primitiveData, d->mFrame); |
|
1279 style()->updatePrimitive(d->mFrame, &primitiveData, this); |
955 } |
1280 } |
956 |
1281 |
957 if (d->mSelectionItem) { |
1282 if (d->mSelectionItem) { |
958 HbStylePrivate::updatePrimitive(d->mSelectionItem, HbStylePrivate::P_ItemViewItem_selection, d->mSharedData->mStyleOption); |
1283 // HbIconItem |
|
1284 HbStyleIconPrimitiveData primitiveData; |
|
1285 initPrimitiveData(&primitiveData, d->mSelectionItem); |
|
1286 style()->updatePrimitive(d->mSelectionItem, &primitiveData, this); |
959 } |
1287 } |
960 |
1288 |
961 if (d->mMultiSelectionTouchArea) { |
1289 if (d->mMultiSelectionTouchArea) { |
962 HbStylePrivate::updatePrimitive(d->mMultiSelectionTouchArea, HbStylePrivate::P_ItemViewItem_touchmultiselection, d->mSharedData->mStyleOption); |
1290 // HbTouchArea |
|
1291 HbStyleTouchAreaPrimitiveData primitiveData; |
|
1292 initPrimitiveData(&primitiveData, d->mMultiSelectionTouchArea); |
|
1293 style()->updatePrimitive(d->mMultiSelectionTouchArea, &primitiveData, this); |
963 } |
1294 } |
964 |
1295 |
965 if (d->mFocusItem) { |
1296 if (d->mFocusItem) { |
966 HbStylePrivate::updatePrimitive(d->mFocusItem, HbStylePrivate::P_ItemViewItem_focus, d->mSharedData->mStyleOption); |
1297 // HbFrameItem |
|
1298 HbStyleFramePrimitiveData primitiveData; |
|
1299 initPrimitiveData(&primitiveData, d->mFocusItem); |
|
1300 style()->updatePrimitive(d->mFocusItem, &primitiveData, this); |
967 } |
1301 } |
968 |
1302 |
969 updatePixmapCache(); |
1303 updatePixmapCache(); |
970 } |
1304 } |
971 |
1305 |
1016 d->mBackground = currentBackground; |
1350 d->mBackground = currentBackground; |
1017 if (currentBackground.canConvert<HbIcon>() |
1351 if (currentBackground.canConvert<HbIcon>() |
1018 || currentBackground.canConvert<QBrush>()) { |
1352 || currentBackground.canConvert<QBrush>()) { |
1019 if (!d->mBackgroundItem) { |
1353 if (!d->mBackgroundItem) { |
1020 d->mItemsChanged = true; |
1354 d->mItemsChanged = true; |
1021 d->mBackgroundItem = HbStylePrivate::createPrimitive(HbStylePrivate::P_ItemViewItem_background, this); |
1355 d->mBackgroundItem = style()->createPrimitive(HbStyle::PT_IconItem, QLatin1String("background"), 0); |
|
1356 d->mBackgroundItem->setParentItem(this); // To enable asynchronous icon loading. |
|
1357 d->mBackgroundItem->setZValue(-3.0); |
|
1358 HbIconItem *iconItem = qobject_cast<HbIconItem*>(d->mBackgroundItem); |
|
1359 if (iconItem) { |
|
1360 iconItem->setAspectRatioMode(Qt::IgnoreAspectRatio); |
|
1361 } |
1022 delete d->mFrame; |
1362 delete d->mFrame; |
1023 d->mFrame = 0; |
1363 d->mFrame = 0; |
1024 } |
1364 } |
1025 } else if (currentBackground.canConvert<HbFrameBackground>()) { |
1365 } else if (currentBackground.canConvert<HbFrameBackground>()) { |
1026 if (!d->mFrame) { |
1366 if (!d->mFrame) { |
1027 d->mItemsChanged = true; |
1367 d->mItemsChanged = true; |
1028 d->mFrame = HbStylePrivate::createPrimitive(HbStylePrivate::P_ItemViewItem_frame, this); |
1368 d->mFrame = style()->createPrimitive(HbStyle::PT_FrameItem, QLatin1String("frame"), this); |
|
1369 d->mFrame->setZValue(-4.0); |
|
1370 |
1029 delete d->mBackgroundItem; |
1371 delete d->mBackgroundItem; |
1030 d->mBackgroundItem = 0; |
1372 d->mBackgroundItem = 0; |
1031 } |
1373 } |
1032 } else if (d->mBackgroundItem) { |
1374 } else if (d->mBackgroundItem) { |
1033 d->mItemsChanged = true; |
1375 d->mItemsChanged = true; |
1183 doAnimate = false; |
1531 doAnimate = false; |
1184 } |
1532 } |
1185 |
1533 |
1186 if (pressed) { |
1534 if (pressed) { |
1187 if (!d->mFocusItem) { |
1535 if (!d->mFocusItem) { |
1188 d->mFocusItem = HbStylePrivate::createPrimitive(HbStylePrivate::P_ItemViewItem_focus, this); |
1536 d->mFocusItem = style()->createPrimitive(HbStyle::PT_FrameItem, QLatin1String("focus") , this); |
|
1537 d->mFocusItem->setZValue(-1.0); |
|
1538 // setChildFlags gets called in the construction phase, but the values are wrong. |
|
1539 // Here we set the flags to force focusItem to be painted even when itemPixmapCache is on |
1189 d->setChildFlags(d->mFocusItem, false); |
1540 d->setChildFlags(d->mFocusItem, false); |
1190 } |
1541 } |
1191 |
1542 |
1192 initStyleOption(d->mSharedData->mStyleOption); |
|
1193 |
|
1194 if (d->mFocusItem) { |
1543 if (d->mFocusItem) { |
1195 HbStylePrivate::updatePrimitive(d->mFocusItem, HbStylePrivate::P_ItemViewItem_focus, d->mSharedData->mStyleOption); |
1544 HbStyleFramePrimitiveData primitiveData; |
|
1545 initPrimitiveData(&primitiveData, d->mFocusItem); |
|
1546 style()->updatePrimitive(d->mFocusItem, &primitiveData, this); |
1196 } |
1547 } |
1197 |
1548 |
1198 if (doAnimate) { |
1549 if (doAnimate) { |
1199 HbEffect::cancel(this, "released"); |
1550 HbEffect::cancel(this, "released"); |
1200 HbEffect::cancel(d->mFocusItem, "released"); |
1551 HbEffect::cancel(d->mFocusItem, "released"); |
1362 if (deviceRect.size() != d->mFrontPixmapPainter->pixmapSize()) { |
1716 if (deviceRect.size() != d->mFrontPixmapPainter->pixmapSize()) { |
1363 d->mResetPixmapCache = true; |
1717 d->mResetPixmapCache = true; |
1364 d->releasePixmaps(); |
1718 d->releasePixmaps(); |
1365 } |
1719 } |
1366 |
1720 |
|
1721 if (!d->mResetPixmapCache && d->mUpdateItems.count() && d->mFrontPixmapPainter->pixmap()) { |
|
1722 // Construct an item-to-pixmap transform. |
|
1723 QPointF point = deviceRect.topLeft(); |
|
1724 QTransform itemToPixmap = painter->worldTransform(); |
|
1725 if (!point.isNull()) { |
|
1726 itemToPixmap *= QTransform::fromTranslate(-point.x(), -point.y()); |
|
1727 } |
|
1728 d->drawSubPixmap(d->mFrontPixmapPainter->pixmap(), painter, itemToPixmap, option); |
|
1729 } |
|
1730 |
1367 if (d->mResetPixmapCache) { |
1731 if (d->mResetPixmapCache) { |
1368 if (!d->mFrontPixmapPainter->pixmap()) { |
1732 if (!d->mFrontPixmapPainter->pixmap()) { |
1369 d->setChildFlagRecursively(true); |
1733 d->setChildFlagRecursively(true); |
1370 QPixmap *pixmap = new QPixmap(deviceRect.size()); |
1734 QPixmap *pixmap = new QPixmap(deviceRect.size()); |
1371 d->mFrontPixmapPainter->setPixmap(pixmap); |
1735 d->mFrontPixmapPainter->setPixmap(pixmap); |
1372 } |
1736 } |
1373 |
1737 |
1374 // Construct an item-to-pixmap transform. |
1738 // Construct an item-to-pixmap transform. |
1375 QPointF p = deviceRect.topLeft(); |
1739 QPointF point = deviceRect.topLeft(); |
1376 QTransform itemToPixmap = painter->worldTransform(); |
1740 QTransform itemToPixmap = painter->worldTransform(); |
1377 if (!p.isNull()) |
1741 if (!point.isNull()) { |
1378 itemToPixmap *= QTransform::fromTranslate(-p.x(), -p.y()); |
1742 itemToPixmap *= QTransform::fromTranslate(-point.x(), -point.y()); |
|
1743 } |
|
1744 d->mUpdateItems.clear(); |
1379 |
1745 |
1380 d->updatePixmap(d->mFrontPixmapPainter->pixmap(), painter, itemToPixmap, option, d->mNonCachableItem, 0); |
1746 d->updatePixmap(d->mFrontPixmapPainter->pixmap(), painter, itemToPixmap, option, d->mNonCachableItem, 0); |
1381 |
1747 |
1382 if (d->mNonCachableItem) { |
1748 if (d->mNonCachableItem) { |
1383 if (!d->mBackPixmapPainter->pixmap()) { |
1749 if (!d->mBackPixmapPainter->pixmap()) { |