src/hbinput/inputwidgets/hbinputvirtualrocker.cpp
changeset 7 923ff622b8b9
parent 6 c3690ec91ef8
equal deleted inserted replaced
6:c3690ec91ef8 7:923ff622b8b9
    41 const qreal HbRockerXThreshold = 5.0;
    41 const qreal HbRockerXThreshold = 5.0;
    42 const qreal HbRockerYThreshold = 50.0;
    42 const qreal HbRockerYThreshold = 50.0;
    43 const qreal HbRockerDimOpacity = 1.0;
    43 const qreal HbRockerDimOpacity = 1.0;
    44 const qreal HbRockerNormalOpacity = 1.0;
    44 const qreal HbRockerNormalOpacity = 1.0;
    45 const qreal HbRockerWidth = 50.0;
    45 const qreal HbRockerWidth = 50.0;
    46 const int HbIconWidth = 30;
    46 const qreal HbNormalSizeInUnits = 5;
    47 const int HbPointerWidth = 15;
    47 const qreal HbPressedSizeInUnits = 9.5;
    48 
    48 const qreal HbActivatedSizeInUnits = 9.5;
    49 
    49 
    50 class HbInputVirtualRockerPrivate
    50 class HbInputVirtualRockerPrivate
    51 {
    51 {
    52 public:
    52 public:
    53     explicit HbInputVirtualRockerPrivate(HbInputVirtualRocker *rocker);
    53     explicit HbInputVirtualRockerPrivate(HbInputVirtualRocker *rocker);
    54     ~HbInputVirtualRockerPrivate();
    54     ~HbInputVirtualRockerPrivate();
    55     int rockerEventRepeats(qreal distance);
    55     int rockerEventRepeats(qreal distance);
    56     void setCenter();
       
    57 
    56 
    58 public:
    57 public:
    59     HbInputVirtualRocker *q_ptr;
    58     HbInputVirtualRocker *q_ptr;
    60     HbIcon *mIconNormal;
    59     HbIcon mIconNormal;
       
    60     HbIcon mIconPressed;
       
    61     HbIcon mIconActivated;
    61     HbInputVirtualRocker::RockerSelectionMode mShifted;
    62     HbInputVirtualRocker::RockerSelectionMode mShifted;
    62     QPointF mLastPoint;
    63     QPointF mLastPoint;
    63     QPointF mCenterPosition;
       
    64     QPointF mPointerPosition;
       
    65     QPointF mMousePressPoint;
    64     QPointF mMousePressPoint;
    66     bool mPressed;
    65     bool mPressed;
    67 };
    66 };
    68 
    67 
    69 HbInputVirtualRockerPrivate::HbInputVirtualRockerPrivate(HbInputVirtualRocker *rocker)
    68 HbInputVirtualRockerPrivate::HbInputVirtualRockerPrivate(HbInputVirtualRocker *rocker)
    70     : q_ptr(rocker),
    69     : q_ptr(rocker),
    71       mIconNormal(0),
       
    72       mShifted(HbInputVirtualRocker::RockerSelectionModeOff),
    70       mShifted(HbInputVirtualRocker::RockerSelectionModeOff),
    73       mLastPoint(0.0, 0.0),
    71       mLastPoint(0.0, 0.0),
    74       mCenterPosition(0.0, 0.0),
       
    75       mMousePressPoint(0.0, 0.0),
    72       mMousePressPoint(0.0, 0.0),
    76       mPressed(false)
    73       mPressed(false)
    77 {
    74 {
    78     mIconNormal = new HbIcon("qtg_graf_trackpoint_normal");
    75     mIconNormal = HbIcon("qtg_graf_trackpoint_normal" );
    79     mIconNormal->setSize(QSizeF(HbIconWidth, HbIconWidth));
    76     mIconPressed = HbIcon("qtg_graf_trackpoint_pressed" );
       
    77     mIconActivated = HbIcon("qtg_graf_trackpoint_activated" );
    80 
    78 
    81     q_ptr->grabGesture(Qt::SwipeGesture);
    79     q_ptr->grabGesture(Qt::SwipeGesture);
    82     q_ptr->grabGesture(Qt::TapGesture);
    80     q_ptr->grabGesture(Qt::TapGesture);
    83     q_ptr->grabGesture(Qt::PanGesture);
    81     q_ptr->grabGesture(Qt::PanGesture);
    84 }
    82 }
    85 
    83 
    86 HbInputVirtualRockerPrivate::~HbInputVirtualRockerPrivate()
    84 HbInputVirtualRockerPrivate::~HbInputVirtualRockerPrivate()
    87 {
    85 {
    88     delete mIconNormal;
       
    89 }
    86 }
    90 
    87 
    91 int HbInputVirtualRockerPrivate::rockerEventRepeats(qreal distance)
    88 int HbInputVirtualRockerPrivate::rockerEventRepeats(qreal distance)
    92 {
    89 {
    93     // cursor move multiplier for cursor moving signals, depending on the rocker move speed
    90     // cursor move multiplier for cursor moving signals, depending on the rocker move speed
   100         repeats = 2;
    97         repeats = 2;
   101     }
    98     }
   102     return repeats;
    99     return repeats;
   103 }
   100 }
   104 
   101 
   105 void HbInputVirtualRockerPrivate::setCenter()
       
   106 {
       
   107     if (mCenterPosition.isNull()) {
       
   108         mCenterPosition.setX(q_ptr->pos().x() + HbRockerWidth / 2);
       
   109         mCenterPosition.setY(q_ptr->pos().y() + HbRockerWidth / 2);
       
   110     }
       
   111     mPointerPosition.setX((HbRockerWidth - HbPointerWidth) / 2);
       
   112     mPointerPosition.setY((HbRockerWidth - HbPointerWidth) / 2);
       
   113 }
       
   114 
       
   115 /// @endcond
   102 /// @endcond
   116 
   103 
   117 /*!
   104 /*!
   118 @alpha
   105 @alpha
   119 @hbinput
   106 @hbinput
   143 
   130 
   144 This enum defines virtual rocker selection modes.
   131 This enum defines virtual rocker selection modes.
   145 */
   132 */
   146 
   133 
   147 /*!
   134 /*!
       
   135 \deprecated HbInputVirtualRocker::HbInputVirtualRocker(HbInputVkbWidget*)
       
   136     is deprecated.
       
   137 
   148 Constructs the object.
   138 Constructs the object.
   149 */
   139 */
   150 HbInputVirtualRocker::HbInputVirtualRocker(HbInputVkbWidget *parent)
   140 HbInputVirtualRocker::HbInputVirtualRocker(HbInputVkbWidget *parent)
   151     : HbWidget(parent), d_ptr(new HbInputVirtualRockerPrivate(this))
   141     : HbWidget(parent), d_ptr(new HbInputVirtualRockerPrivate(this))
   152 {
   142 {
   153     setOpacity(HbRockerDimOpacity);
   143     setOpacity(HbRockerDimOpacity);
   154     setFlag(QGraphicsItem::ItemHasNoContents, false);
   144 }
   155 }
   145 
   156 
   146 /*!
   157 /*!
   147 \deprecated HbInputVirtualRocker::HbInputVirtualRocker(HbInputVirtualRockerPrivate&, QGraphicsWidget*)
       
   148     is deprecated.
       
   149 
   158 Constructs the object.
   150 Constructs the object.
   159 */
   151 */
   160 HbInputVirtualRocker::HbInputVirtualRocker(HbInputVirtualRockerPrivate &dd, QGraphicsWidget *parent)
   152 HbInputVirtualRocker::HbInputVirtualRocker(HbInputVirtualRockerPrivate &dd, QGraphicsWidget *parent)
   161     : HbWidget(parent), d_ptr(&dd)
   153     : HbWidget(parent), d_ptr(&dd)
   162 {
   154 {
   163     setOpacity(HbRockerDimOpacity);
   155     setOpacity(HbRockerDimOpacity);
   164     setFlag(QGraphicsItem::ItemHasNoContents, false);
   156 }
   165 }
   157 
   166 
   158 /*!
   167 /*!
   159 \deprecated HbInputVirtualRocker::~HbInputVirtualRocker()
       
   160     is deprecated.
       
   161 
   168 Destroys the widget.
   162 Destroys the widget.
   169 */
   163 */
   170 HbInputVirtualRocker::~HbInputVirtualRocker()
   164 HbInputVirtualRocker::~HbInputVirtualRocker()
   171 {
   165 {
   172     delete d_ptr;
   166     delete d_ptr;
   173 }
   167 }
   174 
   168 
   175 /*!
   169 /*!
   176     \reimp
   170 \deprecated HbInputVirtualRocker::mousePressEvent(QGraphicsSceneMouseEvent*)
   177     \sa QGraphicsWidget.
   171     is deprecated.
   178 */
   172 */
   179 void HbInputVirtualRocker::mousePressEvent(QGraphicsSceneMouseEvent *event)
   173 void HbInputVirtualRocker::mousePressEvent(QGraphicsSceneMouseEvent *event)
   180 {
   174 {
   181     Q_D(HbInputVirtualRocker);
   175     Q_D(HbInputVirtualRocker);
   182 
   176 
   185 
   179 
   186     qreal squareDistance = delta.y() * delta.y() + delta.x() * delta.x();
   180     qreal squareDistance = delta.y() * delta.y() + delta.x() * delta.x();
   187     qreal squareRadius = HbRockerWidth * HbRockerWidth / 4;
   181     qreal squareRadius = HbRockerWidth * HbRockerWidth / 4;
   188     if (squareRadius > squareDistance) {
   182     if (squareRadius > squareDistance) {
   189         // the touch point is inside circle which diameter is HbRockerWidth
   183         // the touch point is inside circle which diameter is HbRockerWidth
   190         d->setCenter();
       
   191         d->mLastPoint = position;
   184         d->mLastPoint = position;
   192         d->mMousePressPoint = position;
   185         d->mMousePressPoint = position;
   193         emit rockerDirection(HbRockerDirectionPress, d->mShifted);
   186         emit rockerDirection(HbRockerDirectionPress, d->mShifted);
   194         HbWidgetFeedback::triggered(this, Hb::InstantPressed);
   187         HbWidgetFeedback::triggered(this, Hb::InstantPressed);
   195         setOpacity(HbRockerNormalOpacity);
   188         setOpacity(HbRockerNormalOpacity);
   199         event->ignore();
   192         event->ignore();
   200     }
   193     }
   201 }
   194 }
   202 
   195 
   203 /*!
   196 /*!
   204     \reimp
   197 \deprecated HbInputVirtualRocker::mouseReleaseEvent(QGraphicsSceneMouseEvent*)
   205     \sa QGraphicsWidget.
   198     is deprecated.
   206 */
   199 */
   207 void HbInputVirtualRocker::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
   200 void HbInputVirtualRocker::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
   208 {
   201 {
   209     Q_UNUSED(event)
   202     Q_UNUSED(event)
   210     Q_D(HbInputVirtualRocker);
   203     Q_D(HbInputVirtualRocker);
   211 
   204 
   212     emit rockerDirection(HbRockerDirectionRelease, d->mShifted);
   205     emit rockerDirection(HbRockerDirectionRelease, d->mShifted);
   213     setOpacity(HbRockerDimOpacity);
   206     setOpacity(HbRockerDimOpacity);
   214     d->mPressed = false;
   207     d->mPressed = false;
   215     update();
   208     update();
   216     d->setCenter();
       
   217     d->mShifted = RockerSelectionModeOff;
   209     d->mShifted = RockerSelectionModeOff;
   218     HbWidgetFeedback::triggered(this, Hb::InstantReleased);
   210     HbWidgetFeedback::triggered(this, Hb::InstantReleased);
   219 }
   211 }
   220 
   212 
   221 /*!
   213 /*!
   222     \reimp
   214 \deprecated HbInputVirtualRocker::mouseMoveEvent(QGraphicsSceneMouseEvent*)
   223     \sa QGraphicsWidget.
   215     is deprecated.
   224 */
   216 */
   225 void HbInputVirtualRocker::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
   217 void HbInputVirtualRocker::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
   226 {
   218 {
   227     Q_D(HbInputVirtualRocker);
   219     Q_D(HbInputVirtualRocker);
   228 
   220 
   253             d->mLastPoint = event->pos();
   245             d->mLastPoint = event->pos();
   254         } else if (delta.y() < -HbRockerYThreshold) {
   246         } else if (delta.y() < -HbRockerYThreshold) {
   255             emit rockerDirection(HbRockerDirectionUp, d->mShifted);
   247             emit rockerDirection(HbRockerDirectionUp, d->mShifted);
   256             d->mLastPoint = event->pos();
   248             d->mLastPoint = event->pos();
   257         }
   249         }
   258 
       
   259         d->mPointerPosition = HbIconWidth * deltaPressLoc / d->mCenterPosition.x() / 2
       
   260                               + QPointF((HbRockerWidth - HbPointerWidth) / 2, (HbRockerWidth - HbPointerWidth) / 2);
       
   261 
       
   262         update();
   250         update();
   263 
   251     }
   264     }
   252 }
   265 }
   253 
   266 
   254 /*!
   267 /*!
   255 \deprecated HbInputVirtualRocker::mouseDoubleClickEvent(QGraphicsSceneMouseEvent*)
   268     \reimp
   256     is deprecated.
   269     \sa QGraphicsWidget.
       
   270 */
   257 */
   271 void HbInputVirtualRocker::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
   258 void HbInputVirtualRocker::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
   272 {
   259 {
   273     Q_UNUSED(event)
   260     Q_UNUSED(event)
   274     Q_D(HbInputVirtualRocker);
   261     Q_D(HbInputVirtualRocker);
   282     emit rockerDirection(HbRockerDirectionDoubleClick, d->mShifted);
   269     emit rockerDirection(HbRockerDirectionDoubleClick, d->mShifted);
   283     setOpacity(HbRockerNormalOpacity);
   270     setOpacity(HbRockerNormalOpacity);
   284 }
   271 }
   285 
   272 
   286 /*!
   273 /*!
   287     \reimp
   274 \deprecated HbInputVirtualRocker::paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*)
   288     \sa QGraphicsWidget.
   275     is deprecated.
   289 */
   276 */
   290 void HbInputVirtualRocker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
   277 void HbInputVirtualRocker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
   291 {
   278 {
   292     Q_UNUSED(option)
   279     Q_UNUSED(option)
   293     Q_UNUSED(widget)
   280     Q_UNUSED(widget)
   294     Q_D(HbInputVirtualRocker);
   281     Q_D(HbInputVirtualRocker);
   295 
   282 
   296     painter->setRenderHint(QPainter::Antialiasing, true);
   283     painter->setRenderHint(QPainter::Antialiasing, true);
   297 
   284 
   298     if (d->mIconNormal &&
   285     qreal unitValue = HbDeviceProfile::profile(mainWindow()).unitValue();
   299         !d->mIconNormal->isNull()) {
   286     if (selectionMode() == RockerSelectionModeOn) {
   300         // We have icon, lets draw it.
   287         d->mIconActivated.setSize(QSizeF(HbActivatedSizeInUnits * unitValue, HbActivatedSizeInUnits * unitValue));
   301 
   288         d->mIconActivated.paint(painter, rect());
   302         d->mIconNormal->paint(painter, rect(), Qt::IgnoreAspectRatio);
   289     } else if (d->mPressed) {
   303         if (d->mPressed) {
   290         d->mIconPressed.setSize(QSizeF(HbPressedSizeInUnits * unitValue, HbPressedSizeInUnits * unitValue));
   304             painter->setBrush(Qt::blue);
   291         d->mIconPressed.paint(painter, rect());
   305             painter->setPen(Qt::blue);
       
   306             painter->drawEllipse(static_cast<int>(d->mPointerPosition.x()),
       
   307                                  static_cast<int>(d->mPointerPosition.y()),
       
   308                                  HbPointerWidth, HbPointerWidth);
       
   309         }
       
   310 
       
   311     } else {
   292     } else {
   312         // Otherwise just draw a white ellipse as a fallback.
   293         d->mIconNormal.setSize(QSizeF(HbNormalSizeInUnits * unitValue, HbNormalSizeInUnits * unitValue));
   313         painter->setBrush(Qt::white);
   294         d->mIconNormal.paint(painter, rect());
   314         painter->setPen(Qt::white);
   295     }
   315         painter->drawEllipse(boundingRect());
   296 }
   316     }
   297 
   317 }
   298 /*!
   318 
   299 \deprecated HbInputVirtualRocker::selectionMode() const
   319 /*!
   300     is deprecated.
   320 Returns true if virtual rocker is in selection state, ie. it sends event with shift modifier
       
   321 on.
       
   322 */
   301 */
   323 HbInputVirtualRocker::RockerSelectionMode HbInputVirtualRocker::selectionMode() const
   302 HbInputVirtualRocker::RockerSelectionMode HbInputVirtualRocker::selectionMode() const
   324 {
   303 {
   325     Q_D(const HbInputVirtualRocker);
   304     Q_D(const HbInputVirtualRocker);
   326     return d->mShifted;
   305     return d->mShifted;
   327 }
   306 }
   328 
   307 
       
   308 /*!
       
   309 \deprecated HbInputVirtualRocker::gestureEvent(QGestureEvent*)
       
   310     is deprecated.
       
   311 */
   329 void HbInputVirtualRocker::gestureEvent(QGestureEvent *event)
   312 void HbInputVirtualRocker::gestureEvent(QGestureEvent *event)
   330 {
   313 {
   331     Q_UNUSED(event);
   314     Q_UNUSED(event);
   332 }
   315 }
   333 
   316