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