src/hbwidgets/sliders/hbprogresssliderhandle_p.cpp
changeset 23 e6ad4ef83b23
parent 21 4633027730f5
child 28 b7da29130b0e
--- a/src/hbwidgets/sliders/hbprogresssliderhandle_p.cpp	Wed Aug 18 10:05:37 2010 +0300
+++ b/src/hbwidgets/sliders/hbprogresssliderhandle_p.cpp	Thu Sep 02 20:44:51 2010 +0300
@@ -60,6 +60,7 @@
     q(parent),
     mHandleIcon()
 {
+    HbEffect::disable(this);
     mFlags = 0;
     mFlags |= TextVisible;
 
@@ -102,14 +103,10 @@
 }
 
 
-void HbProgressSliderHandle::gestureEvent(QGestureEvent *event)
-{
-    Q_UNUSED(event);
-    // HbWidgetBase::gestureEvent() ignores, overriding to accept
-}
 
 void HbProgressSliderHandle::mousePressEvent(QGraphicsSceneMouseEvent *event) 
 {
+#ifndef HB_GESTURE_FW
     HbWidget::mousePressEvent(event);
 
 #ifdef HB_EFFECTS
@@ -144,10 +141,14 @@
          HbToolTip::showText(locale.toString(slider->sliderValue()),this, QRectF(mItemCurPos,QSize(0,0)),q->textAlignment());
 
      }
+#else
+    Q_UNUSED(event)
+#endif 
 }
 
 void HbProgressSliderHandle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) 
 {
+#ifndef HB_GESTURE_FW
     HbWidget::mouseReleaseEvent(event);
 
     HbStyleOptionProgressSliderHandle option;
@@ -170,33 +171,14 @@
     event->accept();
     setHandlePosForValue(q->progressValue());   
     q->emitSliderReleased();
-}
-
-void HbProgressSliderHandle::handleTrackRelease(QGraphicsSceneMouseEvent * event)
-{
-    Q_UNUSED(event);
-    setHandlePosForValue(q->progressValue());   
-}
-
-void HbProgressSliderHandle::handleTrackPress(QGraphicsSceneMouseEvent * event)
-{
-    QPointF newPos = q->parentGraphicsItem()->mapFromScene(event->scenePos());
-    if((newPos.x() >=  q->boundingRect().x()) && (newPos.x() <=  q->boundingRect().width())) {   
-        if(q->orientation() == Qt::Horizontal){
-            mItemCurPos = QPointF(newPos.x() - boundingRect().width()/2, pos().y());
-        }
-        else{
-            mItemCurPos = QPointF(pos().x(), newPos.y()-boundingRect().height()/2);
-        }
-
-        mItemCurPos = normalizedPos(mItemCurPos,false);
-        setPos(mItemCurPos);
-        processItemChange(mItemCurPos);
-    }
+#else
+    Q_UNUSED(event)
+#endif 
 }
 
 void HbProgressSliderHandle::mouseMoveEvent ( QGraphicsSceneMouseEvent * event ) 
 {
+#ifndef HB_GESTURE_FW
     HbWidget::mouseMoveEvent(event);
     mFlags |=HandleMoving;
     QPointF scenePos = event->scenePos();
@@ -241,6 +223,171 @@
          HbToolTip::showText(locale.toString(slider->sliderValue()),this, QRectF(mItemCurPos,QSize(0,0)),q->textAlignment());
 
      }
+#else
+    Q_UNUSED(event)
+#endif 
+}
+
+void HbProgressSliderHandle::handleTrackRelease(QGestureEvent *event)
+{
+    Q_UNUSED(event);
+    setHandlePosForValue(q->progressValue());   
+}
+
+void HbProgressSliderHandle::handleTrackPress(QGestureEvent *event)
+{
+    HbTapGesture *gesture = static_cast<HbTapGesture *>(event->gesture(Qt::TapGesture));
+    QPointF newPos = q->parentGraphicsItem()->mapFromScene(event->mapToGraphicsScene(gesture->position()));
+
+    //QPointF newPos = q->parentGraphicsItem()->mapFromScene(event->scenePos());
+    if((newPos.x() >=  q->boundingRect().x()) && (newPos.x() <=  q->boundingRect().width())) {   
+        if(q->orientation() == Qt::Horizontal){
+            mItemCurPos = QPointF(newPos.x() - boundingRect().width()/2, pos().y());
+        }
+        else{
+            mItemCurPos = QPointF(pos().x(), newPos.y()-boundingRect().height()/2);
+        }
+
+        mItemCurPos = normalizedPos(mItemCurPos,false);
+        setPos(mItemCurPos);
+        processItemChange(mItemCurPos);
+    }
+}
+
+
+/*!
+  reimp
+
+*/
+void HbProgressSliderHandle::gestureEvent(QGestureEvent *event)
+{ 
+    if(HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
+        switch(tap->state()) {
+            case Qt::GestureStarted: {
+                mMousePressPos = mapFromScene(event->mapToGraphicsScene(tap->position( )));                
+                if(q->textVisible()) {  // User called it 
+                    if(!q->toolTipText().isNull()) {
+                        HbToolTip::showText(q->toolTipText(),this, QRectF(mMousePressPos,QSize(0,0)),q->textAlignment());            
+                    }        
+                }
+                else {  // show default
+                    HbExtendedLocale locale;
+                    HbProgressSlider *slider = (HbProgressSlider*)q->parentGraphicsWidget();
+                    HbToolTip::showText(locale.toString(slider->sliderValue()),this, QRectF(mMousePressPos,QSize(0,0)),q->textAlignment());
+                }
+                #ifdef HB_EFFECTS
+                    HbEffect::start(this, HB_PRGRESSSLIDERHANDLE_ITEM_TYPE, "progressslider_handlepress");
+                #endif
+                mFlags |= HbProgressSliderHandle::MousePressed;
+                HbStyleOptionProgressSliderHandle option;
+                initStyleOption(&option);
+                option.pressedState = true;
+                if (mHandleIconItem) {
+                    HbStylePrivate::updatePrimitive(mHandleIconItem, HbStylePrivate::P_ProgressSliderHandle_icon, &option);
+                }
+                mMousePressPos = mapFromScene(event->mapToGraphicsScene(tap->position( )));
+                HbWidgetFeedback::triggered(q->parentGraphicsWidget(), Hb::InstantPressed, Hb::ModifierSliderHandle);
+                event->accept();
+
+                q->emitSliderPressed();  
+            }
+            break;
+            case Qt::GestureFinished:{
+                HbStyleOptionProgressSliderHandle option;
+                initStyleOption(&option);
+                option.pressedState = false;
+                if (mHandleIconItem) {
+                HbStylePrivate::updatePrimitive(mHandleIconItem, HbStylePrivate::P_ProgressSliderHandle_icon, &option);
+                }
+                if (isHandleMoving()) {
+                    HbWidgetFeedback::continuousStopped(q->parentGraphicsWidget(), Hb::ContinuousDragged);
+                }
+                HbWidgetFeedback::triggered(q->parentGraphicsWidget(), Hb::InstantReleased, Hb::ModifierSliderHandle);
+                #ifdef HB_EFFECTS
+                HbEffect::start(this, HB_PRGRESSSLIDERHANDLE_ITEM_TYPE, "progressslider_handlerelease");
+                #endif
+                mFlags &= ~HbProgressSliderHandle::MousePressed;
+                mFlags &=~HandleMoving;
+                event->accept();
+                setHandlePosForValue(q->progressValue());   
+                q->emitSliderReleased();
+            }
+            break;
+            default:
+                break;                                  
+        }
+    }
+    if (HbPanGesture *panGesture = qobject_cast<HbPanGesture*>(event->gesture(Qt::PanGesture))) {
+        switch(panGesture->state( )) {
+            case Qt::GestureStarted: 
+            case Qt::GestureUpdated:{
+                    mFlags |=HandleMoving;
+                    QPointF scenePos =mapToParent( mapFromScene(panGesture->sceneOffset( )+panGesture->sceneStartPos( )));
+                    if(scenePos.x() == oldCord.x()) {
+                        return;
+                    }
+                    oldCord = scenePos;
+                    //if(q->orientation() == Qt::Horizontal){
+                        mItemCurPos = QPointF((scenePos.x() - mMousePressPos.x()), pos().y());
+                        HbWidgetFeedback::continuousTriggered(qobject_cast<HbWidget*>(q->parentGraphicsWidget()), Hb::ContinuousDragged);
+                        if(mItemCurPos.x()+boundingRect().width() < q->boundingRect().width() && mItemCurPos.x()>q->boundingRect().topLeft().x() ){
+                        setPos(mItemCurPos);
+                    //}
+                    //else{
+                    //    processItemChange(mItemCurPos);
+                    //}
+                }
+                if (!mTouchItem->boundingRect().contains(parentItem()->mapFromScene(scenePos))) {
+                    #ifdef HB_EFFECTS
+                    HbEffect::start(this, HB_PRGRESSSLIDERHANDLE_ITEM_TYPE, "progressslider_handleoutofbound");
+                    #endif
+                }
+                event->accept();
+                if(q->textVisible()) {  // User called it 
+                     if(q->toolTipText().isNull()) {
+                         // Dont show any tooltip.                     
+                     }
+                     else { 
+                         HbToolTip::showText(q->toolTipText(),this, QRectF(mItemCurPos,QSize(0,0)),q->textAlignment());                    
+                     }        
+                 }
+                 else {  // show default
+                     HbExtendedLocale locale;
+                     HbProgressSlider *slider = (HbProgressSlider*)q->parentGraphicsWidget();
+                     HbToolTip::showText(locale.toString(slider->sliderValue()),this, QRectF(mItemCurPos,QSize(0,0)),q->textAlignment());
+                 } 
+                 q->emitSliderMoved(pointToValue(mItemCurPos));
+            }
+            break;
+            case Qt::GestureFinished:
+            case Qt::GestureCanceled: {
+                HbStyleOptionProgressSliderHandle option;
+                option.pressedState = false;
+                initStyleOption(&option);
+                if (mHandleIconItem) {
+                    HbStylePrivate::updatePrimitive(mHandleIconItem, HbStylePrivate::P_ProgressSliderHandle_icon, &option);
+                }
+                if (isHandleMoving()) {
+                  HbWidgetFeedback::continuousStopped(q->parentGraphicsWidget(), Hb::ContinuousDragged);
+                }
+                else {
+                    HbWidgetFeedback::triggered(q->parentGraphicsWidget(), Hb::InstantReleased, Hb::ModifierSliderHandle);
+                }
+                #ifdef HB_EFFECTS
+                HbEffect::start(this, HB_PRGRESSSLIDERHANDLE_ITEM_TYPE, "progressslider_handlerelease");
+                #endif
+                mFlags &= ~HbProgressSliderHandle::MousePressed;
+                mFlags &=~HandleMoving;
+                event->accept();
+                setHandlePosForValue(q->progressValue());   
+                q->emitSliderReleased();
+            }
+            break;
+            default:
+                break;
+        }
+    }
+
 }
 
 int HbProgressSliderHandle::pointToValue(QPointF point) const
@@ -249,15 +396,10 @@
     qreal effectiveWidth;
     point = normalizedPos(point,q->invertedAppearance());
     qreal givenPixel;
-    if(q->orientation() == Qt::Horizontal){
-        effectiveWidth = rect.width() - boundingRect().width();
-        givenPixel = point.x();
-    }
-    else{
-        effectiveWidth = rect.height() - boundingRect().height();
-        givenPixel = effectiveWidth-point.y();
-    }
-
+ 
+    effectiveWidth = rect.width() - boundingRect().width();
+    givenPixel = point.x();
+    
     qreal tickPerPixel = (qreal)(q->maximum()-q->minimum())/effectiveWidth;
     qreal tickForGivenPixel = givenPixel * tickPerPixel;
     tickForGivenPixel = qRound(tickForGivenPixel);
@@ -285,24 +427,12 @@
     QRectF r2 = boundingRect();
 
     qreal width;
-    if(q->orientation()== Qt::Horizontal){
-        width = r1.width() - r2.width();
-        
-    }
-    else{
-        width = r1.height() - r2.height();
-       
-    }
+    width = r1.width() - r2.width();
     if(q->maximum() != q->minimum()){
         qreal pixelpertick = width/(qreal)(q->maximum()-q->minimum());
         qreal noOfTicks = qreal(value - q->minimum());
         qreal xpos =  noOfTicks * pixelpertick;
-        if(q->orientation() == Qt::Horizontal){
-            return QPointF(xpos, r1.top());
-        }
-        else{
-            return QPointF(r1.left(),width-xpos);
-        }
+        return QPointF(xpos, r1.top());
     }
     else{
         return QPointF(0,0);
@@ -312,25 +442,17 @@
 QPointF HbProgressSliderHandle::normalizedPos(const QPointF&  pos,bool inverted) const 
 {
     Q_UNUSED(inverted);
+    
     QPointF newPos = pos;
-    if(q->orientation() == Qt::Horizontal){
-        if (newPos.x() < HandleMargin) {
+    
+    if (newPos.x() < HandleMargin) {
             newPos.setX( HandleMargin );
-        }
-
-        if (newPos.x() > q->boundingRect().width() - boundingRect().width() - HandleMargin) {
-            newPos.setX(q->boundingRect().width() - boundingRect().width() - HandleMargin);
-        }
     }
-    else{
-        if (newPos.y() < HandleMargin) {
-            newPos.setY( HandleMargin );
-        }
 
-        if (newPos.y() > q->boundingRect().height() - boundingRect().height() - HandleMargin) {
-            newPos.setY(q->boundingRect().height() - boundingRect().height() - HandleMargin);
-        }
+    if (newPos.x() > q->boundingRect().width() - boundingRect().width() - HandleMargin) {
+            newPos.setX(q->boundingRect().width() - boundingRect().width() - HandleMargin);
     }
+    
     return newPos;
 }
 
@@ -350,12 +472,7 @@
         // value is the new position
         QPointF pt = value.toPointF();
         int newValue = pointToValue(pt);
-        if(q->orientation() == Qt::Horizontal){
-            pt.setY(q->boundingRect().top());
-        }
-        else{
-            pt.setX(q->boundingRect().left());
-        }
+        pt.setY(q->boundingRect().top());
         q->emitSliderMoved(newValue);
         QPointF newPos = pt;
         return normalizedPos(newPos,false);
@@ -368,21 +485,12 @@
         QPointF newPos = valueToHandlePos(progressValue);
         QPointF pos = normalizedPos(newPos,q->invertedAppearance());
         if(q->invertedAppearance()) {
-            if(q->orientation() == Qt::Horizontal){
                 qreal xVal = q->boundingRect().width() - pos.x() - boundingRect().width();
                 pos.setX(xVal);
-            }
-            else{
-                qreal yVal = q->boundingRect().height() - pos.y() - boundingRect().height();
-                pos.setY(yVal);
-            }
-           
         }
-
         qreal yPos = qreal (q->boundingRect().height()-boundingRect().height()) /2 ;
         setPos(pos.x(),yPos);
-    }   
-   
+    }    
 }
 
 
@@ -424,4 +532,22 @@
     option->handleIcon = mHandleIcon;
     option->pressedState = false;
 }
+void HbProgressSliderHandle::setPressedState()
+{
+   HbStyleOptionProgressSliderHandle option;
+   initStyleOption(&option);
+   option.pressedState = true;
+   if (mHandleIconItem) {
+         HbStylePrivate::updatePrimitive(mHandleIconItem, HbStylePrivate::P_ProgressSliderHandle_icon, &option);
+   }
+}
+void HbProgressSliderHandle::setReleasedState()
+{
+   HbStyleOptionProgressSliderHandle option;
+   initStyleOption(&option);
+   option.pressedState = false;
+   if (mHandleIconItem) {
+         HbStylePrivate::updatePrimitive(mHandleIconItem, HbStylePrivate::P_ProgressSliderHandle_icon, &option);
+   }
+}