diff -r e6ad4ef83b23 -r b7da29130b0e src/hbwidgets/dataform/hbdataform.cpp --- a/src/hbwidgets/dataform/hbdataform.cpp Thu Sep 02 20:44:51 2010 +0300 +++ b/src/hbwidgets/dataform/hbdataform.cpp Fri Sep 17 08:32:10 2010 +0300 @@ -39,7 +39,156 @@ #include #include +#include +#include +#include +class HbTapDelayGesture:public HbTapGesture +{ +public: + using HbTapGesture::d_ptr; + + Q_DECLARE_PRIVATE_D(d_ptr, HbTapGesture); +}; +class HbTapDelayGestureRecognizer : public HbTapGestureRecognizer +{ +public: + explicit HbTapDelayGestureRecognizer(){}; + virtual ~HbTapDelayGestureRecognizer() + { + int i = 0; + i++; + }; + + QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event) + { + HbTapDelayGesture* gesture = static_cast(state); + QMouseEvent* me = toMouseEvent(event); + Qt::GestureState gestureState = state->state(); + switch(event->type()) + { + case QEvent::MouseButtonDblClick: + case QEvent::MouseButtonPress: + if ( state->state() == Qt::NoGesture && me->button() == Qt::LeftButton){ + + gesture->setPosition(me->globalPos()); + gesture->setHotSpot(me->globalPos()); + gesture->setStartPos(me->globalPos()); + gesture->setScenePosition(HbGestureUtils::mapToScene(watched, me->globalPos())); + gesture->setSceneStartPos(HbGestureUtils::mapToScene(watched, me->globalPos())); + mTapRadius = (int)(HbDefaultTapRadius * HbDeviceProfile::current().ppmValue()); + + HbTapGesturePrivate* d_ptr = gesture->d_func(); + d_ptr->mTapStyleHint = HbTapGesture::Tap; + if ( d_ptr->mTimerId ) { + gesture->killTimer(d_ptr->mTimerId); + } + d_ptr->mTimerId = gesture->startTimer(50); + return QGestureRecognizer::MayBeGesture; + + } + else { + return QGestureRecognizer::Ignore; + } + + + case QEvent::MouseMove: + if(gestureState != Qt::NoGesture && gestureState != Qt::GestureCanceled) { + return handleMouseMove(gestureState, gesture, watched, toMouseEvent(event)); + } + else{ + if (gesture->d_func()->mTimerId) { + gesture->setPosition(me->globalPos()); + gesture->setScenePosition(HbGestureUtils::mapToScene(watched, me->globalPos())); + gesture->setHotSpot(me->globalPos()); + + int tapRadiusSquare(mTapRadius * mTapRadius); + if(gesture->property(HbPrivate::TapRadius.latin1()).isValid()) { + qWarning("WARNING using widget specific properties in HbTapGestureRecognizer"); + int tapRadius = gesture->property(HbPrivate::TapRadius.latin1()).toInt(); + tapRadiusSquare = tapRadius * tapRadius; + } + QPointF delta = me->globalPos() - gesture->startPos(); + + // cancel long press with radius + if((delta.x() * delta.x() + delta.y() * delta.y()) > tapRadiusSquare) { + gesture->killTimer(gesture->d_func()->mTimerId); + gesture->d_func()->mTimerId = 0; + } + + } + return QGestureRecognizer::Ignore; + } + + case QEvent::MouseButtonRelease: + if(gestureState != Qt::NoGesture) { + return handleMouseRelease(gestureState, gesture, watched, toMouseEvent(event)); + } + else{ + + if (gesture->d_func()->mTimerId) { + gesture->killTimer(gesture->d_func()->mTimerId); + gesture->d_func()->mTimerId = 0; + return QGestureRecognizer::FinishGesture; + } else { + return QGestureRecognizer::Ignore; + } + } + + case QEvent::Timer: + { + QGestureRecognizer::Result result; + gesture->killTimer(gesture->d_func()->mTimerId); + gesture->d_func()->mTimerId = 0; + if(gestureState == Qt::NoGesture) { + result = QGestureRecognizer::TriggerGesture; + gesture->d_func()->mTimerId = gesture->startTimer(HbTapAndHoldTimeout); + + } + else { + result = handleTimerEvent(gesture->state(),gesture,watched); + } + + return result; + } + break; + + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + return HbTapGestureRecognizer::recognize(state, watched, event); + + default: break; + } + + return QGestureRecognizer::Ignore; + + } +}; + +class DelayGestureInstaller +{ +public: + DelayGestureInstaller():count(0){} + void install() + { + if(count <=0){ + QGestureRecognizer::unregisterRecognizer(Qt::TapGesture); + QGestureRecognizer::registerRecognizer(new HbTapDelayGestureRecognizer); + + } + count++; + } + void unInstall() + { + count--; + if(count <1){ + QGestureRecognizer::unregisterRecognizer(Qt::TapGesture); + QGestureRecognizer::registerRecognizer(new HbTapGestureRecognizer); + } + } + int count; +}; +static DelayGestureInstaller delayGestureInstaller; /*! @beta @hbwidgets @@ -233,7 +382,7 @@ Q_D( HbDataForm ); d->q_ptr = this; d->init(); - setVerticalScrollBarPolicy(ScrollBarAlwaysOff); + //setVerticalScrollBarPolicy(ScrollBarAlwaysOff); } /*! @@ -513,13 +662,14 @@ HbDataFormModelItemPrivate *modelItem_priv = HbDataFormModelItemPrivate::d_ptr(modelItem); if(item){ - HbDataFormViewItemPrivate::d_ptr(item)->setEnabled( modelItem->isEnabled() ); if( modelItem_priv->dirtyProperty() == "LabelRole" || modelItem_priv->dirtyProperty() == "DecorationRole" || modelItem_priv->dirtyProperty() == "DescriptionRole" ) { HbDataFormViewItemPrivate::d_ptr(item)->updateData(); return; + } else if(modelItem_priv->dirtyProperty() == "enabled") { + HbDataFormViewItemPrivate::d_ptr(item)->setEnabled( modelItem->isEnabled() ); } item->restore(); } @@ -654,6 +804,66 @@ d->removeAllConnection(item); } + +/*! + \reimp + + This slot is called when orientation is changed. + \a newOrientation has the currentOrientation mode. + Note: Currently platform dependent orientation support is not available +*/ +void HbDataForm::orientationChanged(Qt::Orientation newOrientation) +{ + Q_UNUSED(newOrientation); + Q_D(HbDataForm); + + //Setting the uniform ites sizes to container again resets size caches. + d->mContainer->setUniformItemSizes(d->mContainer->uniformItemSizes()); + d->mContainer->setPos(0,0); + d->mContainer->resizeContainer(); + + d->updateScrollMetrics(); + + d->stopAnimating(); + scrollTo(d->mVisibleIndex, HbAbstractItemView::PositionAtCenter); + d->mVisibleIndex = QModelIndex(); +} + +void HbDataForm::orientationAboutToBeChanged() +{ + Q_D(HbDataForm); + QRectF rect = mapToScene(boundingRect()).boundingRect(); + HbAbstractViewItem * item = d->itemAt((rect.center())); + if(item){ + d->mVisibleIndex = item->modelIndex(); + } else{ + HbAbstractItemView::orientationAboutToBeChanged(); + } +} + +/*! + \reimp +*/ + +void HbDataForm::showEvent(QShowEvent * event) +{ + if(!isVisible() ){ + delayGestureInstaller.install(); + } + HbAbstractItemView::showEvent( event ); +} + +/*! + \reimp +*/ +void HbDataForm::hideEvent ( QHideEvent * event ) +{ + delayGestureInstaller.unInstall(); + HbAbstractItemView::hideEvent( event ); + +} + + #include "moc_hbdataform.cpp"