src/hbinput/inputwidgets/hbinputvirtualrocker.cpp
changeset 6 c3690ec91ef8
parent 1 f7ac710697a9
child 7 923ff622b8b9
--- a/src/hbinput/inputwidgets/hbinputvirtualrocker.cpp	Fri Jun 11 13:58:22 2010 +0300
+++ b/src/hbinput/inputwidgets/hbinputvirtualrocker.cpp	Wed Jun 23 18:33:25 2010 +0300
@@ -22,6 +22,8 @@
 ** Nokia at developer.feedback@nokia.com.
 **
 ****************************************************************************/
+#include "hbinputvirtualrocker.h"
+
 #include <QGraphicsSceneMouseEvent>
 #include <QPixmap>
 #include <QBitmap>
@@ -33,7 +35,6 @@
 #include <hbwidgetfeedback.h>
 
 #include "hbinputvkbwidget.h"
-#include "hbinputvirtualrocker.h"
 
 /// @cond
 
@@ -49,37 +50,35 @@
 class HbInputVirtualRockerPrivate
 {
 public:
-    explicit HbInputVirtualRockerPrivate(HbInputVirtualRocker *rocker, HbInputVkbWidget* parent = 0);
+    explicit HbInputVirtualRockerPrivate(HbInputVirtualRocker *rocker);
     ~HbInputVirtualRockerPrivate();
     int rockerEventRepeats(qreal distance);
     void setCenter();
 
 public:
     HbInputVirtualRocker *q_ptr;
-    HbIcon* mIconNormal;
+    HbIcon *mIconNormal;
     HbInputVirtualRocker::RockerSelectionMode mShifted;
     QPointF mLastPoint;
     QPointF mCenterPosition;
     QPointF mPointerPosition;
     QPointF mMousePressPoint;
-    HbInputVkbWidget* mKeyboard;
     bool mPressed;
 };
 
-HbInputVirtualRockerPrivate::HbInputVirtualRockerPrivate(HbInputVirtualRocker *rocker, HbInputVkbWidget* parent)
-        : q_ptr(rocker),
-          mIconNormal(0),
-          mShifted(HbInputVirtualRocker::RockerSelectionModeOff),
-          mLastPoint(0.0,0.0),
-          mCenterPosition(0.0,0.0),
-          mMousePressPoint(0.0,0.0),
-          mKeyboard(parent),
-          mPressed(false)
-{    
-    mIconNormal = new HbIcon("qtg_graf_trackpoint_normal" );
-    mIconNormal->setSize( QSizeF( HbIconWidth, HbIconWidth ));
+HbInputVirtualRockerPrivate::HbInputVirtualRockerPrivate(HbInputVirtualRocker *rocker)
+    : q_ptr(rocker),
+      mIconNormal(0),
+      mShifted(HbInputVirtualRocker::RockerSelectionModeOff),
+      mLastPoint(0.0, 0.0),
+      mCenterPosition(0.0, 0.0),
+      mMousePressPoint(0.0, 0.0),
+      mPressed(false)
+{
+    mIconNormal = new HbIcon("qtg_graf_trackpoint_normal");
+    mIconNormal->setSize(QSizeF(HbIconWidth, HbIconWidth));
 
-    q_ptr->grabGesture(Qt::SwipeGesture);    
+    q_ptr->grabGesture(Qt::SwipeGesture);
     q_ptr->grabGesture(Qt::TapGesture);
     q_ptr->grabGesture(Qt::PanGesture);
 }
@@ -93,11 +92,11 @@
 {
     // cursor move multiplier for cursor moving signals, depending on the rocker move speed
     int repeats = 1;
-    if (distance > 30){
+    if (distance > 30) {
         repeats = 30;
     } else if (distance > 20) {
         repeats = 10;
-    } else if(distance > 10) {
+    } else if (distance > 10) {
         repeats = 2;
     }
     return repeats;
@@ -105,12 +104,12 @@
 
 void HbInputVirtualRockerPrivate::setCenter()
 {
-    if(mCenterPosition.isNull()){
-        mCenterPosition.setX(q_ptr->pos().x()+HbRockerWidth/2);
-        mCenterPosition.setY(q_ptr->pos().y()+HbRockerWidth/2);
+    if (mCenterPosition.isNull()) {
+        mCenterPosition.setX(q_ptr->pos().x() + HbRockerWidth / 2);
+        mCenterPosition.setY(q_ptr->pos().y() + HbRockerWidth / 2);
     }
-    mPointerPosition.setX((HbRockerWidth - HbPointerWidth)/2);
-    mPointerPosition.setY((HbRockerWidth - HbPointerWidth)/2);
+    mPointerPosition.setX((HbRockerWidth - HbPointerWidth) / 2);
+    mPointerPosition.setY((HbRockerWidth - HbPointerWidth) / 2);
 }
 
 /// @endcond
@@ -148,19 +147,21 @@
 /*!
 Constructs the object.
 */
-HbInputVirtualRocker::HbInputVirtualRocker(HbInputVkbWidget* parent)
-    : HbWidget(parent), d_ptr(new HbInputVirtualRockerPrivate(this, parent))
+HbInputVirtualRocker::HbInputVirtualRocker(HbInputVkbWidget *parent)
+    : HbWidget(parent), d_ptr(new HbInputVirtualRockerPrivate(this))
 {
     setOpacity(HbRockerDimOpacity);
+    setFlag(QGraphicsItem::ItemHasNoContents, false);
 }
 
 /*!
 Constructs the object.
 */
-HbInputVirtualRocker::HbInputVirtualRocker(HbInputVirtualRockerPrivate &dd, QGraphicsWidget* parent)
+HbInputVirtualRocker::HbInputVirtualRocker(HbInputVirtualRockerPrivate &dd, QGraphicsWidget *parent)
     : HbWidget(parent), d_ptr(&dd)
 {
     setOpacity(HbRockerDimOpacity);
+    setFlag(QGraphicsItem::ItemHasNoContents, false);
 }
 
 /*!
@@ -175,23 +176,21 @@
     \reimp
     \sa QGraphicsWidget.
 */
-void HbInputVirtualRocker::mousePressEvent(QGraphicsSceneMouseEvent* event)
+void HbInputVirtualRocker::mousePressEvent(QGraphicsSceneMouseEvent *event)
 {
     Q_D(HbInputVirtualRocker);
 
     QPointF position = event->pos();
-    QPointF delta = position - QPointF(HbRockerWidth/2, HbRockerWidth/2);
+    QPointF delta = position - QPointF(HbRockerWidth / 2, HbRockerWidth / 2);
 
-    qreal squareDistance = delta.y()*delta.y() + delta.x()*delta.x();
-    qreal squareRadius = HbRockerWidth*HbRockerWidth/4;
+    qreal squareDistance = delta.y() * delta.y() + delta.x() * delta.x();
+    qreal squareRadius = HbRockerWidth * HbRockerWidth / 4;
     if (squareRadius > squareDistance) {
         // the touch point is inside circle which diameter is HbRockerWidth
         d->setCenter();
         d->mLastPoint = position;
         d->mMousePressPoint = position;
-        if (d->mKeyboard) {
-            d->mKeyboard->setKeyboardDimmed(true);
-        }
+        emit rockerDirection(HbRockerDirectionPress, d->mShifted);
         HbWidgetFeedback::triggered(this, Hb::InstantPressed);
         setOpacity(HbRockerNormalOpacity);
         d->mPressed = true;
@@ -205,15 +204,13 @@
     \reimp
     \sa QGraphicsWidget.
 */
-void HbInputVirtualRocker::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
+void HbInputVirtualRocker::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
 {
     Q_UNUSED(event)
     Q_D(HbInputVirtualRocker);
 
-    if (d->mKeyboard) {
-        d->mKeyboard->setKeyboardDimmed(false);
-        setOpacity(HbRockerDimOpacity);
-    }
+    emit rockerDirection(HbRockerDirectionRelease, d->mShifted);
+    setOpacity(HbRockerDimOpacity);
     d->mPressed = false;
     update();
     d->setCenter();
@@ -225,7 +222,7 @@
     \reimp
     \sa QGraphicsWidget.
 */
-void HbInputVirtualRocker::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
+void HbInputVirtualRocker::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
 {
     Q_D(HbInputVirtualRocker);
 
@@ -237,13 +234,13 @@
         HbWidgetFeedback::triggered(this, Hb::InstantDraggedOver);
 
         if (delta.x() > HbRockerXThreshold) {
-            repeats = d->rockerEventRepeats( delta.x() );
+            repeats = d->rockerEventRepeats(delta.x());
             for (int i = 0; i < repeats; i++) {
                 emit rockerDirection(HbRockerDirectionRight, d->mShifted);
             }
             d->mLastPoint = event->pos();
         } else if (delta.x() < -HbRockerXThreshold) {
-            repeats = d->rockerEventRepeats( -delta.x() );
+            repeats = d->rockerEventRepeats(-delta.x());
             for (int i = 0; i < repeats; i++) {
                 emit rockerDirection(HbRockerDirectionLeft, d->mShifted);
             }
@@ -260,7 +257,7 @@
         }
 
         d->mPointerPosition = HbIconWidth * deltaPressLoc / d->mCenterPosition.x() / 2
-            + QPointF((HbRockerWidth-HbPointerWidth)/2, (HbRockerWidth-HbPointerWidth)/2);
+                              + QPointF((HbRockerWidth - HbPointerWidth) / 2, (HbRockerWidth - HbPointerWidth) / 2);
 
         update();
 
@@ -271,7 +268,7 @@
     \reimp
     \sa QGraphicsWidget.
 */
-void HbInputVirtualRocker::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
+void HbInputVirtualRocker::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
 {
     Q_UNUSED(event)
     Q_D(HbInputVirtualRocker);
@@ -282,10 +279,7 @@
         d->mShifted = RockerSelectionModeOff;
     }
 
-    // dim the keypad.
-    if (d->mKeyboard) {
-        d->mKeyboard->setKeyboardDimmed(true);
-    }
+    emit rockerDirection(HbRockerDirectionDoubleClick, d->mShifted);
     setOpacity(HbRockerNormalOpacity);
 }
 
@@ -293,7 +287,7 @@
     \reimp
     \sa QGraphicsWidget.
 */
-void HbInputVirtualRocker::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
+void HbInputVirtualRocker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
 {
     Q_UNUSED(option)
     Q_UNUSED(widget)
@@ -334,7 +328,7 @@
 
 void HbInputVirtualRocker::gestureEvent(QGestureEvent *event)
 {
-    Q_UNUSED (event);
+    Q_UNUSED(event);
 }
 
 // End of file