20 ** |
20 ** |
21 ** If you have questions regarding the use of this file, please contact |
21 ** If you have questions regarding the use of this file, please contact |
22 ** Nokia at developer.feedback@nokia.com. |
22 ** Nokia at developer.feedback@nokia.com. |
23 ** |
23 ** |
24 ****************************************************************************/ |
24 ****************************************************************************/ |
|
25 #include "hbinputvirtualrocker.h" |
|
26 |
25 #include <QGraphicsSceneMouseEvent> |
27 #include <QGraphicsSceneMouseEvent> |
26 #include <QPixmap> |
28 #include <QPixmap> |
27 #include <QBitmap> |
29 #include <QBitmap> |
28 #include <QPainter> |
30 #include <QPainter> |
29 #include <QCoreApplication> |
31 #include <QCoreApplication> |
31 #include <hbicon.h> |
33 #include <hbicon.h> |
32 #include <hbinputsettingproxy.h> |
34 #include <hbinputsettingproxy.h> |
33 #include <hbwidgetfeedback.h> |
35 #include <hbwidgetfeedback.h> |
34 |
36 |
35 #include "hbinputvkbwidget.h" |
37 #include "hbinputvkbwidget.h" |
36 #include "hbinputvirtualrocker.h" |
|
37 |
38 |
38 /// @cond |
39 /// @cond |
39 |
40 |
40 const qreal HbRockerXThreshold = 5.0; |
41 const qreal HbRockerXThreshold = 5.0; |
41 const qreal HbRockerYThreshold = 50.0; |
42 const qreal HbRockerYThreshold = 50.0; |
47 |
48 |
48 |
49 |
49 class HbInputVirtualRockerPrivate |
50 class HbInputVirtualRockerPrivate |
50 { |
51 { |
51 public: |
52 public: |
52 explicit HbInputVirtualRockerPrivate(HbInputVirtualRocker *rocker, HbInputVkbWidget* parent = 0); |
53 explicit HbInputVirtualRockerPrivate(HbInputVirtualRocker *rocker); |
53 ~HbInputVirtualRockerPrivate(); |
54 ~HbInputVirtualRockerPrivate(); |
54 int rockerEventRepeats(qreal distance); |
55 int rockerEventRepeats(qreal distance); |
55 void setCenter(); |
56 void setCenter(); |
56 |
57 |
57 public: |
58 public: |
58 HbInputVirtualRocker *q_ptr; |
59 HbInputVirtualRocker *q_ptr; |
59 HbIcon* mIconNormal; |
60 HbIcon *mIconNormal; |
60 HbInputVirtualRocker::RockerSelectionMode mShifted; |
61 HbInputVirtualRocker::RockerSelectionMode mShifted; |
61 QPointF mLastPoint; |
62 QPointF mLastPoint; |
62 QPointF mCenterPosition; |
63 QPointF mCenterPosition; |
63 QPointF mPointerPosition; |
64 QPointF mPointerPosition; |
64 QPointF mMousePressPoint; |
65 QPointF mMousePressPoint; |
65 HbInputVkbWidget* mKeyboard; |
|
66 bool mPressed; |
66 bool mPressed; |
67 }; |
67 }; |
68 |
68 |
69 HbInputVirtualRockerPrivate::HbInputVirtualRockerPrivate(HbInputVirtualRocker *rocker, HbInputVkbWidget* parent) |
69 HbInputVirtualRockerPrivate::HbInputVirtualRockerPrivate(HbInputVirtualRocker *rocker) |
70 : q_ptr(rocker), |
70 : q_ptr(rocker), |
71 mIconNormal(0), |
71 mIconNormal(0), |
72 mShifted(HbInputVirtualRocker::RockerSelectionModeOff), |
72 mShifted(HbInputVirtualRocker::RockerSelectionModeOff), |
73 mLastPoint(0.0,0.0), |
73 mLastPoint(0.0, 0.0), |
74 mCenterPosition(0.0,0.0), |
74 mCenterPosition(0.0, 0.0), |
75 mMousePressPoint(0.0,0.0), |
75 mMousePressPoint(0.0, 0.0), |
76 mKeyboard(parent), |
76 mPressed(false) |
77 mPressed(false) |
77 { |
78 { |
78 mIconNormal = new HbIcon("qtg_graf_trackpoint_normal"); |
79 mIconNormal = new HbIcon("qtg_graf_trackpoint_normal" ); |
79 mIconNormal->setSize(QSizeF(HbIconWidth, HbIconWidth)); |
80 mIconNormal->setSize( QSizeF( HbIconWidth, HbIconWidth )); |
80 |
81 |
81 q_ptr->grabGesture(Qt::SwipeGesture); |
82 q_ptr->grabGesture(Qt::SwipeGesture); |
|
83 q_ptr->grabGesture(Qt::TapGesture); |
82 q_ptr->grabGesture(Qt::TapGesture); |
84 q_ptr->grabGesture(Qt::PanGesture); |
83 q_ptr->grabGesture(Qt::PanGesture); |
85 } |
84 } |
86 |
85 |
87 HbInputVirtualRockerPrivate::~HbInputVirtualRockerPrivate() |
86 HbInputVirtualRockerPrivate::~HbInputVirtualRockerPrivate() |
91 |
90 |
92 int HbInputVirtualRockerPrivate::rockerEventRepeats(qreal distance) |
91 int HbInputVirtualRockerPrivate::rockerEventRepeats(qreal distance) |
93 { |
92 { |
94 // cursor move multiplier for cursor moving signals, depending on the rocker move speed |
93 // cursor move multiplier for cursor moving signals, depending on the rocker move speed |
95 int repeats = 1; |
94 int repeats = 1; |
96 if (distance > 30){ |
95 if (distance > 30) { |
97 repeats = 30; |
96 repeats = 30; |
98 } else if (distance > 20) { |
97 } else if (distance > 20) { |
99 repeats = 10; |
98 repeats = 10; |
100 } else if(distance > 10) { |
99 } else if (distance > 10) { |
101 repeats = 2; |
100 repeats = 2; |
102 } |
101 } |
103 return repeats; |
102 return repeats; |
104 } |
103 } |
105 |
104 |
106 void HbInputVirtualRockerPrivate::setCenter() |
105 void HbInputVirtualRockerPrivate::setCenter() |
107 { |
106 { |
108 if(mCenterPosition.isNull()){ |
107 if (mCenterPosition.isNull()) { |
109 mCenterPosition.setX(q_ptr->pos().x()+HbRockerWidth/2); |
108 mCenterPosition.setX(q_ptr->pos().x() + HbRockerWidth / 2); |
110 mCenterPosition.setY(q_ptr->pos().y()+HbRockerWidth/2); |
109 mCenterPosition.setY(q_ptr->pos().y() + HbRockerWidth / 2); |
111 } |
110 } |
112 mPointerPosition.setX((HbRockerWidth - HbPointerWidth)/2); |
111 mPointerPosition.setX((HbRockerWidth - HbPointerWidth) / 2); |
113 mPointerPosition.setY((HbRockerWidth - HbPointerWidth)/2); |
112 mPointerPosition.setY((HbRockerWidth - HbPointerWidth) / 2); |
114 } |
113 } |
115 |
114 |
116 /// @endcond |
115 /// @endcond |
117 |
116 |
118 /*! |
117 /*! |
146 */ |
145 */ |
147 |
146 |
148 /*! |
147 /*! |
149 Constructs the object. |
148 Constructs the object. |
150 */ |
149 */ |
151 HbInputVirtualRocker::HbInputVirtualRocker(HbInputVkbWidget* parent) |
150 HbInputVirtualRocker::HbInputVirtualRocker(HbInputVkbWidget *parent) |
152 : HbWidget(parent), d_ptr(new HbInputVirtualRockerPrivate(this, parent)) |
151 : HbWidget(parent), d_ptr(new HbInputVirtualRockerPrivate(this)) |
153 { |
152 { |
154 setOpacity(HbRockerDimOpacity); |
153 setOpacity(HbRockerDimOpacity); |
|
154 setFlag(QGraphicsItem::ItemHasNoContents, false); |
155 } |
155 } |
156 |
156 |
157 /*! |
157 /*! |
158 Constructs the object. |
158 Constructs the object. |
159 */ |
159 */ |
160 HbInputVirtualRocker::HbInputVirtualRocker(HbInputVirtualRockerPrivate &dd, QGraphicsWidget* parent) |
160 HbInputVirtualRocker::HbInputVirtualRocker(HbInputVirtualRockerPrivate &dd, QGraphicsWidget *parent) |
161 : HbWidget(parent), d_ptr(&dd) |
161 : HbWidget(parent), d_ptr(&dd) |
162 { |
162 { |
163 setOpacity(HbRockerDimOpacity); |
163 setOpacity(HbRockerDimOpacity); |
|
164 setFlag(QGraphicsItem::ItemHasNoContents, false); |
164 } |
165 } |
165 |
166 |
166 /*! |
167 /*! |
167 Destroys the widget. |
168 Destroys the widget. |
168 */ |
169 */ |
173 |
174 |
174 /*! |
175 /*! |
175 \reimp |
176 \reimp |
176 \sa QGraphicsWidget. |
177 \sa QGraphicsWidget. |
177 */ |
178 */ |
178 void HbInputVirtualRocker::mousePressEvent(QGraphicsSceneMouseEvent* event) |
179 void HbInputVirtualRocker::mousePressEvent(QGraphicsSceneMouseEvent *event) |
179 { |
180 { |
180 Q_D(HbInputVirtualRocker); |
181 Q_D(HbInputVirtualRocker); |
181 |
182 |
182 QPointF position = event->pos(); |
183 QPointF position = event->pos(); |
183 QPointF delta = position - QPointF(HbRockerWidth/2, HbRockerWidth/2); |
184 QPointF delta = position - QPointF(HbRockerWidth / 2, HbRockerWidth / 2); |
184 |
185 |
185 qreal squareDistance = delta.y()*delta.y() + delta.x()*delta.x(); |
186 qreal squareDistance = delta.y() * delta.y() + delta.x() * delta.x(); |
186 qreal squareRadius = HbRockerWidth*HbRockerWidth/4; |
187 qreal squareRadius = HbRockerWidth * HbRockerWidth / 4; |
187 if (squareRadius > squareDistance) { |
188 if (squareRadius > squareDistance) { |
188 // the touch point is inside circle which diameter is HbRockerWidth |
189 // the touch point is inside circle which diameter is HbRockerWidth |
189 d->setCenter(); |
190 d->setCenter(); |
190 d->mLastPoint = position; |
191 d->mLastPoint = position; |
191 d->mMousePressPoint = position; |
192 d->mMousePressPoint = position; |
192 if (d->mKeyboard) { |
193 emit rockerDirection(HbRockerDirectionPress, d->mShifted); |
193 d->mKeyboard->setKeyboardDimmed(true); |
|
194 } |
|
195 HbWidgetFeedback::triggered(this, Hb::InstantPressed); |
194 HbWidgetFeedback::triggered(this, Hb::InstantPressed); |
196 setOpacity(HbRockerNormalOpacity); |
195 setOpacity(HbRockerNormalOpacity); |
197 d->mPressed = true; |
196 d->mPressed = true; |
198 } else { |
197 } else { |
199 // outside of circle: give event to a push button |
198 // outside of circle: give event to a push button |
203 |
202 |
204 /*! |
203 /*! |
205 \reimp |
204 \reimp |
206 \sa QGraphicsWidget. |
205 \sa QGraphicsWidget. |
207 */ |
206 */ |
208 void HbInputVirtualRocker::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) |
207 void HbInputVirtualRocker::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
209 { |
208 { |
210 Q_UNUSED(event) |
209 Q_UNUSED(event) |
211 Q_D(HbInputVirtualRocker); |
210 Q_D(HbInputVirtualRocker); |
212 |
211 |
213 if (d->mKeyboard) { |
212 emit rockerDirection(HbRockerDirectionRelease, d->mShifted); |
214 d->mKeyboard->setKeyboardDimmed(false); |
213 setOpacity(HbRockerDimOpacity); |
215 setOpacity(HbRockerDimOpacity); |
|
216 } |
|
217 d->mPressed = false; |
214 d->mPressed = false; |
218 update(); |
215 update(); |
219 d->setCenter(); |
216 d->setCenter(); |
220 d->mShifted = RockerSelectionModeOff; |
217 d->mShifted = RockerSelectionModeOff; |
221 HbWidgetFeedback::triggered(this, Hb::InstantReleased); |
218 HbWidgetFeedback::triggered(this, Hb::InstantReleased); |
235 int repeats = 1; |
232 int repeats = 1; |
236 |
233 |
237 HbWidgetFeedback::triggered(this, Hb::InstantDraggedOver); |
234 HbWidgetFeedback::triggered(this, Hb::InstantDraggedOver); |
238 |
235 |
239 if (delta.x() > HbRockerXThreshold) { |
236 if (delta.x() > HbRockerXThreshold) { |
240 repeats = d->rockerEventRepeats( delta.x() ); |
237 repeats = d->rockerEventRepeats(delta.x()); |
241 for (int i = 0; i < repeats; i++) { |
238 for (int i = 0; i < repeats; i++) { |
242 emit rockerDirection(HbRockerDirectionRight, d->mShifted); |
239 emit rockerDirection(HbRockerDirectionRight, d->mShifted); |
243 } |
240 } |
244 d->mLastPoint = event->pos(); |
241 d->mLastPoint = event->pos(); |
245 } else if (delta.x() < -HbRockerXThreshold) { |
242 } else if (delta.x() < -HbRockerXThreshold) { |
246 repeats = d->rockerEventRepeats( -delta.x() ); |
243 repeats = d->rockerEventRepeats(-delta.x()); |
247 for (int i = 0; i < repeats; i++) { |
244 for (int i = 0; i < repeats; i++) { |
248 emit rockerDirection(HbRockerDirectionLeft, d->mShifted); |
245 emit rockerDirection(HbRockerDirectionLeft, d->mShifted); |
249 } |
246 } |
250 d->mLastPoint = event->pos(); |
247 d->mLastPoint = event->pos(); |
251 } |
248 } |
258 emit rockerDirection(HbRockerDirectionUp, d->mShifted); |
255 emit rockerDirection(HbRockerDirectionUp, d->mShifted); |
259 d->mLastPoint = event->pos(); |
256 d->mLastPoint = event->pos(); |
260 } |
257 } |
261 |
258 |
262 d->mPointerPosition = HbIconWidth * deltaPressLoc / d->mCenterPosition.x() / 2 |
259 d->mPointerPosition = HbIconWidth * deltaPressLoc / d->mCenterPosition.x() / 2 |
263 + QPointF((HbRockerWidth-HbPointerWidth)/2, (HbRockerWidth-HbPointerWidth)/2); |
260 + QPointF((HbRockerWidth - HbPointerWidth) / 2, (HbRockerWidth - HbPointerWidth) / 2); |
264 |
261 |
265 update(); |
262 update(); |
266 |
263 |
267 } |
264 } |
268 } |
265 } |
269 |
266 |
270 /*! |
267 /*! |
271 \reimp |
268 \reimp |
272 \sa QGraphicsWidget. |
269 \sa QGraphicsWidget. |
273 */ |
270 */ |
274 void HbInputVirtualRocker::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) |
271 void HbInputVirtualRocker::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) |
275 { |
272 { |
276 Q_UNUSED(event) |
273 Q_UNUSED(event) |
277 Q_D(HbInputVirtualRocker); |
274 Q_D(HbInputVirtualRocker); |
278 |
275 |
279 if (d->mShifted == RockerSelectionModeOff) { |
276 if (d->mShifted == RockerSelectionModeOff) { |
280 d->mShifted = RockerSelectionModeOn; |
277 d->mShifted = RockerSelectionModeOn; |
281 } else { |
278 } else { |
282 d->mShifted = RockerSelectionModeOff; |
279 d->mShifted = RockerSelectionModeOff; |
283 } |
280 } |
284 |
281 |
285 // dim the keypad. |
282 emit rockerDirection(HbRockerDirectionDoubleClick, d->mShifted); |
286 if (d->mKeyboard) { |
|
287 d->mKeyboard->setKeyboardDimmed(true); |
|
288 } |
|
289 setOpacity(HbRockerNormalOpacity); |
283 setOpacity(HbRockerNormalOpacity); |
290 } |
284 } |
291 |
285 |
292 /*! |
286 /*! |
293 \reimp |
287 \reimp |
294 \sa QGraphicsWidget. |
288 \sa QGraphicsWidget. |
295 */ |
289 */ |
296 void HbInputVirtualRocker::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) |
290 void HbInputVirtualRocker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
297 { |
291 { |
298 Q_UNUSED(option) |
292 Q_UNUSED(option) |
299 Q_UNUSED(widget) |
293 Q_UNUSED(widget) |
300 Q_D(HbInputVirtualRocker); |
294 Q_D(HbInputVirtualRocker); |
301 |
295 |