src/hbwidgets/itemviews/hbabstractviewitem.cpp
changeset 3 11d3954df52a
parent 2 06ff229162e9
child 5 627c4a0fd0e7
equal deleted inserted replaced
2:06ff229162e9 3:11d3954df52a
    39 #include <QPersistentModelIndex>
    39 #include <QPersistentModelIndex>
    40 #include <QGraphicsLayout>
    40 #include <QGraphicsLayout>
    41 #include <QVariant>
    41 #include <QVariant>
    42 #include <QCoreApplication>
    42 #include <QCoreApplication>
    43 #include <QEvent>
    43 #include <QEvent>
       
    44 #include <QTimer>
    44 #include <QDebug>
    45 #include <QDebug>
    45 
    46 
    46 #include <QGesture>
    47 #include <QGesture>
    47 #include <QGestureEvent>
    48 #include <QGestureEvent>
    48 
    49 
    49 const QString KDefaultLayoutOption = "default";
    50 const QString KDefaultLayoutOption = "default";
    50 const int HbAbstractViewItemShared::ViewItemDeferredDeleteEvent = QEvent::registerEventType();
    51 const int HbAbstractViewItemShared::ViewItemDeferredDeleteEvent = QEvent::registerEventType();
       
    52 const int HbViewItemPressDelay = 50;
    51 
    53 
    52 /*!
    54 /*!
    53     @alpha
    55     @alpha
    54     @hbwidgets
    56     @hbwidgets
    55     \class HbAbstractViewItem
    57     \class HbAbstractViewItem
   124 
   126 
   125     In most subclasses, createItem should be implemented like this:
   127     In most subclasses, createItem should be implemented like this:
   126 
   128 
   127     \snippet{ultimatecodesnippet/customlistviewitem.cpp,1}
   129     \snippet{ultimatecodesnippet/customlistviewitem.cpp,1}
   128 */
   130 */
       
   131 
       
   132 void HbAbstractViewItemShared::pressStateChangeTimerTriggered()
       
   133 {
       
   134     HbWidgetFeedback::triggered(mPressedItem, Hb::InstantPressed, 0);
       
   135     mPressedItem->pressStateChanged(true, mAnimatePress);
       
   136 }
   129 
   137 
   130 void HbAbstractViewItemPrivate::init()
   138 void HbAbstractViewItemPrivate::init()
   131 {
   139 {
   132     Q_Q(HbAbstractViewItem);
   140     Q_Q(HbAbstractViewItem);
   133 
   141 
   202     QPointF position = event->mapToGraphicsScene(gesture->hotSpot());
   210     QPointF position = event->mapToGraphicsScene(gesture->hotSpot());
   203     position = q->mapFromScene(position);
   211     position = q->mapFromScene(position);
   204 
   212 
   205     switch (gesture->state()) {
   213     switch (gesture->state()) {
   206         case Qt::GestureStarted: {
   214         case Qt::GestureStarted: {
   207             HbWidgetFeedback::triggered(q, Hb::InstantPressed, 0);
       
   208             setPressed(true, true);
   215             setPressed(true, true);
   209             emit q->pressed(position);
   216             emit q->pressed(position);
   210             break;
   217             break;
   211         }
   218         }
   212         case Qt::GestureUpdated: {
   219         case Qt::GestureUpdated: {
   275 {
   282 {
   276     Q_Q(HbAbstractViewItem);
   283     Q_Q(HbAbstractViewItem);
   277 
   284 
   278     if (pressed != mPressed) {
   285     if (pressed != mPressed) {
   279         mPressed = pressed;
   286         mPressed = pressed;
   280         q->pressStateChanged(mPressed, animate);
   287 
       
   288         if (mSharedData->mPressStateChangeTimer) {
       
   289             mSharedData->mPressStateChangeTimer->stop();
       
   290         }
       
   291 
   281         if (mPressed) {
   292         if (mPressed) {
       
   293             if (!mSharedData->mPressStateChangeTimer) {
       
   294                 mSharedData->mPressStateChangeTimer = new QTimer(mSharedData.data());
       
   295                 mSharedData->mPressStateChangeTimer->setSingleShot(true);
       
   296                 QObject::connect(mSharedData->mPressStateChangeTimer, SIGNAL(timeout()), mSharedData.data(), SLOT(pressStateChangeTimerTriggered()));
       
   297             }
       
   298             mSharedData->mPressedItem = q;
       
   299             mSharedData->mAnimatePress = animate;
       
   300             mSharedData->mPressStateChangeTimer->start(HbViewItemPressDelay);
       
   301 
   282             q->setProperty("state", "pressed");
   302             q->setProperty("state", "pressed");
   283         } else {
   303         } else {
       
   304             q->pressStateChanged(mPressed, animate);
       
   305 
   284             q->setProperty("state", "normal");
   306             q->setProperty("state", "normal");
   285         }
   307         }
   286     }
   308     }
   287 }
   309 }
   288 
   310 
   894 
   916 
   895             HbEffect::start(this, sd->mItemType, "released");
   917             HbEffect::start(this, sd->mItemType, "released");
   896             HbEffect::start(d->mFocusItem, sd->mItemType + QString("-focus"), "released", this, "_q_animationFinished");
   918             HbEffect::start(d->mFocusItem, sd->mItemType + QString("-focus"), "released", this, "_q_animationFinished");
   897         } else {
   919         } else {
   898             HbEffect::cancel(this, "pressed");
   920             HbEffect::cancel(this, "pressed");
   899             HbEffect::start(this, sd->mItemType, "released");
   921             HbEffect::cancel(this, "released");
   900             if (d->mFocusItem) {
   922             if (d->mFocusItem) {
   901                 HbEffect::cancel(d->mFocusItem, "pressed");
   923                 HbEffect::cancel(d->mFocusItem, "pressed");
   902                 HbEffect::start(d->mFocusItem, sd->mItemType + QString("-focus"), "released", this, "_q_animationFinished");
   924                 HbEffect::cancel(d->mFocusItem, "released");
   903                 QCoreApplication::postEvent(this, new QEvent((QEvent::Type)HbAbstractViewItemShared::ViewItemDeferredDeleteEvent));
   925                 QCoreApplication::postEvent(this, new QEvent((QEvent::Type)HbAbstractViewItemShared::ViewItemDeferredDeleteEvent));
   904             }
   926             }
   905         }
   927         }
   906     }
   928     }
   907 }
   929 }