src/hbwidgets/itemviews/hbabstractviewitem.cpp
changeset 7 923ff622b8b9
parent 6 c3690ec91ef8
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
6:c3690ec91ef8 7:923ff622b8b9
    33 #include <hbiconitem.h>
    33 #include <hbiconitem.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 
    39 
    39 #include <QPersistentModelIndex>
    40 #include <QPersistentModelIndex>
    40 #include <QGraphicsLayout>
    41 #include <QGraphicsLayout>
    41 #include <QVariant>
    42 #include <QVariant>
    42 #include <QCoreApplication>
    43 #include <QCoreApplication>
    43 #include <QEvent>
    44 #include <QEvent>
    44 #include <QTimer>
    45 #include <QTimer>
       
    46 #include <QGraphicsScene>
    45 #include <QDebug>
    47 #include <QDebug>
    46 
    48 
    47 #include <QGesture>
    49 #include <QGesture>
    48 #include <QGestureEvent>
    50 #include <QGestureEvent>
    49 
    51 
   261     QPointF position = event->mapToGraphicsScene(gesture->hotSpot());
   263     QPointF position = event->mapToGraphicsScene(gesture->hotSpot());
   262     position = q->mapFromScene(position);
   264     position = q->mapFromScene(position);
   263 
   265 
   264     switch (gesture->state()) {
   266     switch (gesture->state()) {
   265         case Qt::GestureStarted: {
   267         case Qt::GestureStarted: {
       
   268             q->scene()->setProperty(HbPrivate::OverridingGesture.latin1(),Qt::TapGesture);
       
   269             if (!gesture->property(HbPrivate::ThresholdRect.latin1()).toRect().isValid()) {
       
   270                 gesture->setProperty(HbPrivate::ThresholdRect.latin1(), q->mapRectToScene(q->boundingRect()).toRect());
       
   271             }
       
   272 
   266             setPressed(true, true);
   273             setPressed(true, true);
   267             emit q->pressed(position);
   274             emit q->pressed(position);
   268             break;
   275             break;
   269         }
   276         }
   270         case Qt::GestureUpdated: {
   277         case Qt::GestureUpdated: {
   279                 }
   286                 }
   280             }
   287             }
   281             break;
   288             break;
   282         }
   289         }
   283         case Qt::GestureFinished: {
   290         case Qt::GestureFinished: {
       
   291             q->scene()->setProperty(HbPrivate::OverridingGesture.latin1(),QVariant());
       
   292 
   284             if (gesture->tapStyleHint() == HbTapGesture::Tap 
   293             if (gesture->tapStyleHint() == HbTapGesture::Tap 
   285                 || (mSharedData->mItemView
   294                 || (mSharedData->mItemView
   286                 && !mSharedData->mItemView->longPressEnabled())) {
   295                 && !mSharedData->mItemView->longPressEnabled())) {
   287                 setPressed(false, true);
   296                 setPressed(false, true);
   288 
   297 
   304             }
   313             }
   305 
   314 
   306             break;
   315             break;
   307         }
   316         }
   308         case Qt::GestureCanceled: {
   317         case Qt::GestureCanceled: {
       
   318             q->scene()->setProperty(HbPrivate::OverridingGesture.latin1(),QVariant());
   309             // hides focus immediately
   319             // hides focus immediately
   310             setPressed(false, false);
   320             setPressed(false, false);
   311 
   321 
   312             emit q->released(position);
   322             emit q->released(position);
   313             break;
   323             break;
   892         delete d->mMultiSelectionTouchArea;
   902         delete d->mMultiSelectionTouchArea;
   893         d->mMultiSelectionTouchArea = 0;
   903         d->mMultiSelectionTouchArea = 0;
   894     }
   904     }
   895 
   905 
   896     // items visibility or items content has really changed
   906     // items visibility or items content has really changed
   897     d->mSizeHintPolish = false;
       
   898     updatePrimitives();
   907     updatePrimitives();
   899     if (!d->mContentChangedSupported
   908     if (!d->mContentChangedSupported
   900         || d->mItemsChanged) {
   909         || d->mItemsChanged) {
   901         updateGeometry();   // ensures that sizehint is calculated again in case items have been created or deleted
   910         updateGeometry();   // ensures that sizehint is calculated again in case items have been created or deleted
   902         d->mRepolishRequested = true;
   911         d->mRepolishRequested = true;
       
   912         // handle QEvent::Polish & QEvent::LayoutRequest event itself in ::sizeHint() as our performance is slightly better
       
   913         // (saving a layoutrequest and going event loop through twice)
       
   914         if (sd->mItemView && sd->mItemView->isScrolling()) {
       
   915             d->mHandlingRepolishSynchronously = true;
       
   916         }
   903         repolish();
   917         repolish();
       
   918         d->mHandlingRepolishSynchronously = false;
   904     }
   919     }
   905     d->mItemsChanged = false;
   920     d->mItemsChanged = false;
   906 }
   921 }
   907 
   922 
   908 /*!
   923 /*!
   952     }
   967     }
   953     if (pressed) {
   968     if (pressed) {
   954         if (!d->mFocusItem) {
   969         if (!d->mFocusItem) {
   955             d->mFocusItem = style()->createPrimitive(HbStyle::P_ItemViewItem_focus, this);
   970             d->mFocusItem = style()->createPrimitive(HbStyle::P_ItemViewItem_focus, this);
   956         }
   971         }
   957             
   972 
   958         HbStyleOptionAbstractViewItem styleOption;
   973         HbStyleOptionAbstractViewItem styleOption;
   959         initStyleOption(&styleOption);
   974         initStyleOption(&styleOption);
   960 
   975 
   961         if (d->mFocusItem) {
   976         if (d->mFocusItem) {
   962             style()->updatePrimitive(d->mFocusItem, HbStyle::P_ItemViewItem_focus, &styleOption);
   977             style()->updatePrimitive(d->mFocusItem, HbStyle::P_ItemViewItem_focus, &styleOption);
  1002 */
  1017 */
  1003 void HbAbstractViewItem::polish(HbStyleParameters& params)
  1018 void HbAbstractViewItem::polish(HbStyleParameters& params)
  1004 {
  1019 {
  1005     HB_SDD(HbAbstractViewItem);
  1020     HB_SDD(HbAbstractViewItem);
  1006 
  1021 
  1007 	if (!d->polished && layout()) {
  1022     if (!d->polished && layout()) {
  1008 		return;
  1023     return;
  1009 	}
       
  1010 	
       
  1011     if (d->mSizeHintPolish) {
       
  1012         d->mSizeHintPolish = false;
       
  1013         return;
       
  1014     }
  1024     }
  1015 
  1025 
  1016     if (sd->mItemView) {
  1026     if (sd->mItemView) {
  1017         setProperty("layoutName", sd->mItemView->layoutName());
  1027         setProperty("layoutName", sd->mItemView->layoutName());
  1018     }
  1028     }
  1038 */
  1048 */
  1039 QSizeF HbAbstractViewItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
  1049 QSizeF HbAbstractViewItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
  1040 {
  1050 {
  1041     Q_D(const HbAbstractViewItem);
  1051     Q_D(const HbAbstractViewItem);
  1042     if (d->mRepolishRequested) {
  1052     if (d->mRepolishRequested) {
  1043         // force the polish event in order to get the real size
  1053         if (d->repolishOutstanding) {
  1044         const_cast<HbAbstractViewItemPrivate *>(d)->mRepolishRequested = false;
  1054             // force the polish event in order to get the real size
  1045         QEvent polishEvent(QEvent::Polish);
  1055             // updateGeometry() in ::updateChildItems() causes this function to be called
  1046         QCoreApplication::sendEvent(const_cast<HbAbstractViewItem *>(this), &polishEvent);
  1056             // before QEvent::Polish of repolish() is handled from the event loop
  1047         // HbAbstractItemView::scrollByAmount() [recycleItems()]
  1057             QCoreApplication::sendPostedEvents(const_cast<HbAbstractViewItem*>(this), QEvent::Polish);
  1048         // causes updateChildItems() to be called, which posts Polish to be posted via repolish().
  1058         } else {
  1049         // Next statement in the scrollByAmount() [refreshContainerGeometry()]
  1059             // needed for pure widget or at startup phase, if first polish has not yet been done
  1050         // causes synchronous call of this method. This is a quick way to disable another
  1060             QEvent polishEvent(QEvent::Polish);
  1051         // ::polish() to be called.
  1061             QCoreApplication::sendEvent(const_cast<HbAbstractViewItem *>(this), &polishEvent);
  1052         d->mSizeHintPolish = true;
  1062         }
       
  1063         QCoreApplication::sendPostedEvents(const_cast<HbAbstractViewItem *>(this), QEvent::LayoutRequest);
  1053     }
  1064     }
  1054     return HbWidget::sizeHint(which, constraint);
  1065     return HbWidget::sizeHint(which, constraint);
  1055 }
  1066 }
  1056 
  1067 
  1057 /*!
  1068 /*!