40 #include <QTextEdit> |
41 #include <QTextEdit> |
41 |
42 |
42 const int HbAnimationTime = 200; |
43 const int HbAnimationTime = 200; |
43 const qreal HbHeightVerticalFactor = 0.5; |
44 const qreal HbHeightVerticalFactor = 0.5; |
44 const qreal HbHeightHorizFactor = 0.7; |
45 const qreal HbHeightHorizFactor = 0.7; |
|
46 const qreal HbEditorExtraMargin = 17.0; |
45 |
47 |
46 const QString KHandWritingName("Handwriting"); |
48 const QString KHandWritingName("Handwriting"); |
47 // see hbpopup.cpp for this |
49 // see hbpopup.cpp for this |
48 extern const char* KPositionManagedByVKB; |
50 extern const char* KPositionManagedByVKB; |
49 |
51 |
50 /// @cond |
52 /// @cond |
51 |
53 |
52 HbVkbHostContainerWidget::HbVkbHostContainerWidget(QObject *containterWidget) |
54 HbVkbHostContainerWidget::HbVkbHostContainerWidget(QObject *containerWidget) |
53 : mContainerWidget(containterWidget) |
55 { |
54 { |
56 mGraphicsObject = qobject_cast<QGraphicsObject*>(containerWidget); |
55 } |
57 if (!mGraphicsObject) { |
56 |
58 mWidget = qobject_cast<QWidget*>(containerWidget); |
57 // sets container widgets position to new position. |
59 } |
|
60 } |
|
61 |
|
62 /*! |
|
63 \internal |
|
64 Sets container widgets position to new position. |
|
65 */ |
58 void HbVkbHostContainerWidget::setPos(QPointF newPosition) |
66 void HbVkbHostContainerWidget::setPos(QPointF newPosition) |
59 { |
67 { |
60 if (mContainerWidget) { |
68 if (mGraphicsObject) { |
61 QGraphicsObject *graphicsObject = qobject_cast<QGraphicsObject *>(mContainerWidget); |
69 mGraphicsObject->setPos(newPosition); |
62 if (graphicsObject) { |
70 return; |
63 graphicsObject->setPos(newPosition); |
71 } |
64 return; |
72 |
65 } |
73 if (mWidget) { |
66 |
|
67 QWidget *qWidget = qobject_cast<QWidget *>(mContainerWidget); |
|
68 if (qWidget) { |
|
69 #ifdef Q_WS_WIN |
74 #ifdef Q_WS_WIN |
70 QPoint finalPosition = newPosition.toPoint(); |
75 QPoint finalPosition = newPosition.toPoint(); |
71 finalPosition -= qWidget->geometry().topLeft() - qWidget->frameGeometry().topLeft(); |
76 finalPosition -= mWidget->geometry().topLeft() - mWidget->frameGeometry().topLeft(); |
72 qWidget->move(finalPosition); |
77 mWidget->move(finalPosition); |
73 #else |
78 #else |
74 qWidget->move(newPosition.toPoint()); |
79 mWidget->move(newPosition.toPoint()); |
75 #endif |
80 #endif |
76 return; |
81 return; |
77 } |
82 } |
78 } |
83 } |
79 } |
84 |
80 |
85 /*! |
81 // returns the global position, if container widget is a QGraphicsObject, it returns |
86 \internal |
82 // scene position. In case the widget is QWidget it returns global co-ordinates |
87 Returns the global position, if container widget is a QGraphicsObject, it returns |
|
88 scene position. In case the widget is QWidget it returns global co-ordinates |
|
89 */ |
83 QPointF HbVkbHostContainerWidget::pos() |
90 QPointF HbVkbHostContainerWidget::pos() |
84 { |
91 { |
85 if (mContainerWidget) { |
92 if (mGraphicsObject) { |
86 QGraphicsObject *graphicsObject = qobject_cast<QGraphicsObject *>(mContainerWidget); |
93 return mGraphicsObject->pos(); |
87 if (graphicsObject) { |
94 } |
88 return graphicsObject->pos();; |
95 |
89 } |
96 if (mWidget) { |
90 |
97 return mWidget->mapToGlobal(QPoint(0, 0)); |
91 QWidget *qWidget = qobject_cast<QWidget *>(mContainerWidget); |
|
92 if (qWidget) { |
|
93 return qWidget->mapToGlobal(QPoint(0, 0)); |
|
94 } |
|
95 } |
98 } |
96 |
99 |
97 return QPointF(0, 0); |
100 return QPointF(0, 0); |
98 } |
101 } |
99 |
102 |
100 // returns the bounding rect in global co-ordinate, if container widget is a QGraphicsObject |
103 /*! |
101 // it returns in scene co-ordinate, incase widget is QWidget it returns in global co-ordinate |
104 \internal |
|
105 Returns the bounding rect in global co-ordinate, if container widget is a QGraphicsObject |
|
106 it returns in scene co-ordinate, incase widget is QWidget it returns in global co-ordinate |
|
107 */ |
102 QRectF HbVkbHostContainerWidget::sceneBoundingRect() |
108 QRectF HbVkbHostContainerWidget::sceneBoundingRect() |
103 { |
109 { |
104 if (mContainerWidget) { |
110 if (mGraphicsObject) { |
105 QGraphicsObject *graphicsObject = qobject_cast<QGraphicsObject *>(mContainerWidget); |
111 return mGraphicsObject->sceneBoundingRect(); |
106 if (graphicsObject) { |
112 } |
107 return graphicsObject->sceneBoundingRect();; |
113 |
108 } |
114 if (mWidget) { |
109 |
115 return QRectF(mWidget->mapToGlobal(QPoint(0, 0)), mWidget->size()); |
110 QWidget *qWidget = qobject_cast<QWidget *>(mContainerWidget); |
|
111 if (qWidget) { |
|
112 return QRectF(qWidget->mapToGlobal(QPoint(0, 0)), qWidget->size()); |
|
113 } |
|
114 } |
116 } |
115 |
117 |
116 return QRectF(0, 0, 0, 0); |
118 return QRectF(0, 0, 0, 0); |
117 } |
119 } |
118 |
120 |
119 // connect container specific signals here. |
121 /*! |
|
122 \internal |
|
123 Connects ontainer specific signals. |
|
124 */ |
120 void HbVkbHostContainerWidget::connectSignals(QObject *receiver) |
125 void HbVkbHostContainerWidget::connectSignals(QObject *receiver) |
121 { |
126 { |
122 if (qobject_cast<QGraphicsObject *> (mContainerWidget)) { |
127 if (mGraphicsObject) { |
123 QObject::connect(mContainerWidget, SIGNAL(yChanged()), |
128 QObject::connect(mGraphicsObject, SIGNAL(yChanged()), |
124 receiver, SLOT(ensureCursorVisibility())); |
129 receiver, SLOT(ensureCursorVisibility())); |
125 } |
130 } |
126 |
131 |
127 HbPopup *popup = qobject_cast<HbPopup *>(mContainerWidget); |
132 HbPopup *popup = qobject_cast<HbPopup *>(mGraphicsObject); |
128 if (popup) { |
133 if (popup) { |
129 QObject::connect(popup, SIGNAL(aboutToHide()), receiver, SLOT(containerAboutToClose())); |
134 QObject::connect(popup, SIGNAL(aboutToHide()), receiver, SLOT(_q_containerAboutToClose())); |
130 } |
135 } |
131 |
136 |
132 HbView *view = qobject_cast<HbView *>(mContainerWidget); |
137 HbView *view = qobject_cast<HbView *>(mGraphicsObject); |
133 if (view) { |
138 if (view) { |
134 QObject::connect(view->mainWindow(), SIGNAL(currentViewChanged(HbView *)), |
139 QObject::connect(view->mainWindow(), SIGNAL(currentViewChanged(HbView *)), |
135 receiver, SLOT(currentViewChanged(HbView *))); |
140 receiver, SLOT(_q_containerAboutToClose())); |
136 } |
141 } |
137 } |
142 } |
138 |
143 |
139 // disconnect container specific signals here. |
144 /*! |
|
145 \internal |
|
146 Disconnects container specific signals. |
|
147 */ |
140 void HbVkbHostContainerWidget::disconnectSignals(QObject *receiver) |
148 void HbVkbHostContainerWidget::disconnectSignals(QObject *receiver) |
141 { |
149 { |
142 if (qobject_cast<QGraphicsObject *> (mContainerWidget)) { |
150 if (mGraphicsObject) { |
143 QObject::disconnect(mContainerWidget, SIGNAL(yChanged()), |
151 QObject::disconnect(mGraphicsObject, SIGNAL(yChanged()), |
144 receiver, SLOT(ensureCursorVisibility())); |
152 receiver, SLOT(ensureCursorVisibility())); |
145 } |
153 } |
146 |
154 |
147 HbPopup *popup = qobject_cast<HbPopup *>(mContainerWidget); |
155 HbPopup *popup = qobject_cast<HbPopup *>(mGraphicsObject); |
148 if (popup) { |
156 if (popup) { |
149 QObject::disconnect(popup, SIGNAL(aboutToHide()), receiver, SLOT(containerAboutToClose())); |
157 QObject::disconnect(popup, SIGNAL(aboutToHide()), receiver, SLOT(_q_containerAboutToClose())); |
150 } |
158 } |
151 |
159 |
152 HbPopup *view = qobject_cast<HbPopup *>(mContainerWidget); |
160 HbPopup *view = qobject_cast<HbPopup *>(mGraphicsObject); |
153 if (view) { |
161 if (view) { |
154 QObject::disconnect(view->mainWindow(), SIGNAL(currentViewChanged(HbView *)), |
162 QObject::disconnect(view->mainWindow(), SIGNAL(currentViewChanged(HbView *)), |
155 receiver, SLOT(currentViewChanged(HbView *))); |
163 receiver, SLOT(_q_containerAboutToClose())); |
156 } |
164 } |
157 } |
165 } |
158 |
166 |
159 /// @endcond |
167 /// @endcond |
160 |
168 |
161 /*! |
169 /*! |
162 \proto |
170 \proto |
|
171 @hbcore |
163 \class HbAbstractVkbHost |
172 \class HbAbstractVkbHost |
164 \brief Base class for HbCore's virtual keyboard hosts. |
173 \brief Base class for HbCore's virtual keyboard hosts. |
165 |
174 |
166 This class contains common code for HbCore's virtual keyboard hosts. |
175 This class contains common code for HbCore's virtual keyboard hosts. |
167 */ |
176 */ |
237 } |
257 } |
238 |
258 |
239 return true; |
259 return true; |
240 } |
260 } |
241 |
261 |
|
262 /*! |
|
263 \internal |
|
264 Sets up the container widget animation effect. |
|
265 */ |
242 bool HbAbstractVkbHostPrivate::prepareContainerAnimation(HbVkbHost::HbVkbStatus status) |
266 bool HbAbstractVkbHostPrivate::prepareContainerAnimation(HbVkbHost::HbVkbStatus status) |
243 { |
267 { |
244 // Init and check main objects |
268 // Init and check main objects |
245 HbView* currentView = NULL; |
269 HbView* currentView = 0; |
246 HbInputFocusObject* focusObject = NULL; |
270 HbInputFocusObject* focusObject = 0; |
247 if (!getViewAndFocusObjects(currentView, focusObject)) { |
271 if (!getViewAndFocusObjects(currentView, focusObject)) { |
248 return false; |
272 return false; |
249 } |
273 } |
250 |
274 |
251 // Init parameters before calling... |
275 // Init parameters before calling... |
252 QSizeF keypadSize = mKeypad->size(); |
276 QSizeF keypadSize = mKeypad->size(); |
253 QRectF viewRect = currentView->sceneBoundingRect(); |
277 QRectF viewRect = currentView->sceneBoundingRect(); |
|
278 bool isPopupType = qobject_cast<HbPopup *>(mContainerWidget->widgetObject()) != NULL; |
254 bool vkbOpen = mKeypadStatus == HbVkbHost::HbVkbStatusOpened; |
279 bool vkbOpen = mKeypadStatus == HbVkbHost::HbVkbStatusOpened; |
255 bool titlebarVisible = currentView->isItemVisible(Hb::TitleBarItem); |
280 bool titlebarVisible = currentView->isItemVisible(Hb::TitleBarItem); |
256 bool statusbarVisible = currentView->isItemVisible(Hb::StatusBarItem); |
281 bool statusbarVisible = currentView->isItemVisible(Hb::StatusBarItem); |
257 QRectF containerRect = mContainerWidget->sceneBoundingRect(); |
282 QRectF containerRect = mContainerWidget->sceneBoundingRect(); |
258 QRectF editorRect = focusObject->editorGeometry(); |
283 QRectF editorRect = focusObject->editorGeometry(); |
275 } |
301 } |
276 |
302 |
277 return false; |
303 return false; |
278 } |
304 } |
279 |
305 |
|
306 /*! |
|
307 \internal |
|
308 Sets up the keypad widget animation effect. |
|
309 */ |
280 bool HbAbstractVkbHostPrivate::prepareKeypadAnimation(HbVkbHost::HbVkbStatus status) |
310 bool HbAbstractVkbHostPrivate::prepareKeypadAnimation(HbVkbHost::HbVkbStatus status) |
281 { |
311 { |
282 if (status == HbVkbHost::HbVkbStatusOpened) { |
312 if (mKeypad) { |
283 if (mKeypadStatus == HbVkbHost::HbVkbStatusClosed) { |
313 if (status == HbVkbHost::HbVkbStatusOpened) { |
284 // Set up keyboard open animation. |
314 if (mKeypadStatus == HbVkbHost::HbVkbStatusClosed) { |
285 mKeypadMovementStartingPoint.setY(mScreenSize.height()); |
315 // Set up keyboard open animation. |
286 mKeypadMovementVector.setY(-mKeypad->size().height()); |
316 mKeypadMovementStartingPoint.setY(mScreenSize.height()); |
287 if (!disableCursorShift()) { |
317 mKeypadMovementVector.setY(-mKeypad->size().height()); |
288 // Initialize keypad position |
318 if (!disableCursorShift()) { |
289 mKeypad->setPos(mKeypadMovementStartingPoint); |
319 // Initialize keypad position |
|
320 mKeypad->setPos(mKeypadMovementStartingPoint); |
|
321 } |
|
322 return true; |
|
323 } else if (mKeypadStatus == HbVkbHost::HbVkbStatusMinimized && mCallback) { |
|
324 mKeypadMovementVector.setY(-(mKeypad->size().height() - mCallback->minimizedKeyboardSize().height())); |
|
325 return true; |
290 } |
326 } |
|
327 } else { |
|
328 // It is going to be closed. |
|
329 mKeypadMovementVector = QPointF(0, mKeypad->size().height()); |
291 return true; |
330 return true; |
292 } else if (mKeypadStatus == HbVkbHost::HbVkbStatusMinimized && mCallback) { |
331 } |
293 mKeypadMovementVector.setY(-(mKeypad->size().height() - mCallback->minimizedKeyboardSize().height())); |
|
294 return true; |
|
295 } |
|
296 } else if (status == HbVkbHost::HbVkbStatusMinimized && mCallback) { |
|
297 mKeypadMovementVector = QPointF(0, mKeypad->size().height() - mCallback->minimizedKeyboardSize().height()); |
|
298 return true; |
|
299 } else { |
|
300 // It is going to be closed. |
|
301 mKeypadMovementVector = QPointF(0, mKeypad->size().height()); |
|
302 return true; |
|
303 } |
332 } |
304 |
333 |
305 return false; |
334 return false; |
306 } |
335 } |
307 |
336 |
|
337 /*! |
|
338 \internal |
|
339 Sets up all the animation effects. |
|
340 */ |
308 bool HbAbstractVkbHostPrivate::prepareAnimations(HbVkbHost::HbVkbStatus status) |
341 bool HbAbstractVkbHostPrivate::prepareAnimations(HbVkbHost::HbVkbStatus status) |
309 { |
342 { |
310 prepareAnimationsCommon(); |
343 prepareAnimationsCommon(); |
311 |
344 |
312 bool containerResult = prepareContainerAnimation(status); |
345 bool containerResult = prepareContainerAnimation(status); |
394 mTimeLine.start(); |
442 mTimeLine.start(); |
395 } |
443 } |
396 } |
444 } |
397 } |
445 } |
398 |
446 |
399 void HbAbstractVkbHostPrivate::minimizeKeypad() |
447 /*! |
400 { |
448 \internal |
401 if (mCallback && mKeypadStatus != HbVkbHost::HbVkbStatusMinimized) { |
449 Opens the keypad widget without animation effect. |
402 mCallback->aboutToClose(q_ptr); |
450 */ |
403 if (mContainerWidget->widgetObject()) { |
|
404 if (prepareAnimations(HbVkbHost::HbVkbStatusMinimized)) { |
|
405 //show the title bar and status bar when minimizing the vkb |
|
406 setTitleAndStatusBarVisible(true); |
|
407 |
|
408 mKeypadStatus = HbVkbHost::HbVkbStatusMinimized; |
|
409 mTimeLine.start(); |
|
410 } |
|
411 } |
|
412 } |
|
413 } |
|
414 |
|
415 void HbAbstractVkbHostPrivate::openKeypadWithoutAnimation() |
451 void HbAbstractVkbHostPrivate::openKeypadWithoutAnimation() |
416 { |
452 { |
417 HbMainWindow *mainWin = mainWindow(); |
453 HbMainWindow *mainWin = mainWindow(); |
418 if (mKeypadStatus != HbVkbHost::HbVkbStatusOpened && mKeypad && mContainerWidget->widgetObject() && mainWin) { |
454 if (mKeypadStatus != HbVkbHost::HbVkbStatusOpened && mKeypad && mContainerWidget->widgetObject() && mainWin) { |
419 if (mKeypad->scene() != mainWin->scene()) { |
455 if (mKeypad->scene() != mainWin->scene()) { |
420 // Add item to scene if it is not already in there. |
456 // Add item to scene if it is not already in there. |
421 mainWin->scene()->addItem(mKeypad); |
457 mainWin->scene()->addItem(mKeypad); |
422 } |
458 } |
423 |
459 |
424 if (mKeypadStatus != HbVkbHost::HbVkbStatusOpened) { |
460 if (mKeypadStatus != HbVkbHost::HbVkbStatusOpened) { |
425 mCallback->aboutToOpen(q_ptr); |
461 if (mCallback) { |
|
462 mCallback->aboutToOpen(q_ptr); |
|
463 } |
426 q_ptr->resizeKeyboard(); // Make sure that the keyboard doesn't exceed given boundaries. |
464 q_ptr->resizeKeyboard(); // Make sure that the keyboard doesn't exceed given boundaries. |
427 } |
465 } |
428 if (prepareAnimations(HbVkbHost::HbVkbStatusOpened)) { |
466 if (prepareAnimations(HbVkbHost::HbVkbStatusOpened)) { |
429 // hide the title bar and status bar when opening the vkb |
467 // hide the title bar and status bar when opening the vkb |
430 setTitleAndStatusBarVisible(false); |
468 setTitleAndStatusBarVisible(false); |
436 // Move the keypad |
474 // Move the keypad |
437 mKeypad->setPos(mKeypadMovementStartingPoint + mKeypadMovementVector); |
475 mKeypad->setPos(mKeypadMovementStartingPoint + mKeypadMovementVector); |
438 } |
476 } |
439 |
477 |
440 mKeypadStatus = HbVkbHost::HbVkbStatusOpened; |
478 mKeypadStatus = HbVkbHost::HbVkbStatusOpened; |
441 mCallback->keyboardOpened(q_ptr); |
479 if (mCallback) { |
442 } |
480 mCallback->keyboardOpened(q_ptr); |
443 } |
|
444 } |
|
445 |
|
446 void HbAbstractVkbHostPrivate::openMinimizedKeypad() |
|
447 { |
|
448 // No need of any animation as this minimized keypad is very small to be a candidate for an |
|
449 // animation. |
|
450 HbMainWindow *mainWin = mainWindow(); |
|
451 if (mainWin && mKeypad && mContainerWidget->widgetObject()) { |
|
452 if (mKeypad->scene() != mainWin->scene()) { |
|
453 // Add item to scene if it is not already in there. |
|
454 mainWin->scene()->addItem(mKeypad); |
|
455 } |
|
456 |
|
457 if (mKeypadStatus != HbVkbHost::HbVkbStatusMinimized) { |
|
458 mCallback->aboutToOpen(q_ptr); |
|
459 q_ptr->resizeKeyboard(); // Make sure that the keyboard doesn't exceed given boundaries. |
|
460 } |
|
461 |
|
462 if (prepareAnimations(HbVkbHost::HbVkbStatusMinimized)) { |
|
463 if (!disableCursorShift()) { |
|
464 mKeypad->setPos(0.0, mScreenSize.height() - mCallback->minimizedKeyboardSize().height()); |
|
465 } |
481 } |
466 mKeypadStatus = HbVkbHost::HbVkbStatusMinimized; |
482 } |
467 mCallback->keyboardMinimized(q_ptr); |
483 } |
468 } |
484 } |
469 } |
485 |
470 } |
486 /*! |
471 |
487 \internal |
|
488 Closes the keypad widget without animating it. |
|
489 */ |
472 void HbAbstractVkbHostPrivate::closeKeypadWithoutAnimation() |
490 void HbAbstractVkbHostPrivate::closeKeypadWithoutAnimation() |
473 { |
491 { |
474 if (mKeypadStatus != HbVkbHost::HbVkbStatusClosed && mKeypad) { |
492 if (mKeypadStatus != HbVkbHost::HbVkbStatusClosed && mKeypad && mCallback) { |
475 mCallback->aboutToClose(q_ptr); |
493 mCallback->aboutToClose(q_ptr); |
|
494 |
476 // show the title bar and status bar when closing the vkb |
495 // show the title bar and status bar when closing the vkb |
477 setTitleAndStatusBarVisible(true); |
496 setTitleAndStatusBarVisible(true); |
478 |
497 |
479 // Set original content widget position |
498 // Set original content widget position |
480 mKeypadStatus = HbVkbHost::HbVkbStatusClosed; |
499 mKeypadStatus = HbVkbHost::HbVkbStatusClosed; |
484 mContainerWidget->setPos(mOriginalContainerPosition); |
503 mContainerWidget->setPos(mOriginalContainerPosition); |
485 mContainerWidget->widgetObject()->setProperty(KPositionManagedByVKB, false ); |
504 mContainerWidget->widgetObject()->setProperty(KPositionManagedByVKB, false ); |
486 } |
505 } |
487 |
506 |
488 // Hide the keypad |
507 // Hide the keypad |
489 mKeypad->hide(); |
508 mKeypad->hide(); |
490 mCallback->keyboardClosed(q_ptr); |
509 mCallback->keyboardClosed(q_ptr); |
491 mCallback = 0; |
510 mCallback = 0; |
492 } |
511 } |
493 } |
512 } |
494 |
513 |
495 void HbAbstractVkbHostPrivate::minimizeKeypadWithoutAnimation() |
514 /*! |
496 { |
515 \internal |
497 HbMainWindow *mainWin = mainWindow(); |
516 Cancels the ongoing keypad animation and resets the timeline timer. |
498 if (mKeypadStatus != HbVkbHost::HbVkbStatusMinimized && mKeypad && mainWin) { |
517 */ |
499 mCallback->aboutToClose(q_ptr); |
|
500 if (mKeypad->scene() != mainWin->scene()) { |
|
501 // Add item to scene if it is not already in there. |
|
502 mainWin->scene()->addItem(mKeypad); |
|
503 } |
|
504 // show the title bar and status bar when minimizing the vkb |
|
505 setTitleAndStatusBarVisible(true); |
|
506 |
|
507 mKeypadStatus = HbVkbHost::HbVkbStatusMinimized; |
|
508 if (!disableCursorShift()) { |
|
509 // Return the container widget to original position. |
|
510 mContainerWidget->setPos(mOriginalContainerPosition); |
|
511 |
|
512 // Set the keypad to minimized position. |
|
513 mKeypad->setPos(QPointF(0.0, mScreenSize.height() - mCallback->minimizedKeyboardSize().height())); |
|
514 } |
|
515 } |
|
516 } |
|
517 |
|
518 void HbAbstractVkbHostPrivate::cancelAnimationAndHideVkbWidget() |
518 void HbAbstractVkbHostPrivate::cancelAnimationAndHideVkbWidget() |
519 { |
519 { |
520 if (mTimeLine.state() == QTimeLine::Running) { |
520 if (mTimeLine.state() == QTimeLine::Running) { |
521 mTimeLine.stop(); |
521 mTimeLine.stop(); |
522 |
522 |
523 if (!disableCursorShift()) { |
523 if (!disableCursorShift() && mContainerWidget && mContainerWidget->widgetObject()) { |
524 mContainerWidget->setPos(mOriginalContainerPosition); |
524 mContainerWidget->setPos(mOriginalContainerPosition); |
525 mContainerWidget->widgetObject()->setProperty(KPositionManagedByVKB, false ); |
525 mContainerWidget->widgetObject()->setProperty(KPositionManagedByVKB, false ); |
526 } |
526 } |
527 |
527 |
528 if (mKeypad) { |
528 if (mKeypad) { |
591 if (mainWindow() && mainWindow()->orientation() == Qt::Horizontal && imName == KHandWritingName) { |
599 if (mainWindow() && mainWindow()->orientation() == Qt::Horizontal && imName == KHandWritingName) { |
592 return true; |
600 return true; |
593 } |
601 } |
594 return false; |
602 return false; |
595 } |
603 } |
|
604 |
|
605 /*! |
|
606 \internal |
|
607 Sets title and status bar visibility. |
|
608 */ |
596 void HbAbstractVkbHostPrivate::setTitleAndStatusBarVisible(bool visible) |
609 void HbAbstractVkbHostPrivate::setTitleAndStatusBarVisible(bool visible) |
597 { |
610 { |
598 // should not change the title bar and status bar visibility when the keypad is opened from a popup |
611 // should not change the title bar and status bar visibility when the keypad is opened from a popup |
599 HbPopup *popup = qobject_cast<HbPopup *>(mContainerWidget->widgetObject()); |
612 HbPopup *popup = qobject_cast<HbPopup *>(mContainerWidget->widgetObject()); |
600 if (popup) { |
613 if (popup) { |
601 return; |
614 return; |
602 } |
615 } |
603 |
616 |
|
617 // Set flags to control view behaviour when visibility is changed |
604 HbMainWindow *mainWin = mainWindow(); |
618 HbMainWindow *mainWin = mainWindow(); |
605 if (!mainWin) { |
619 HbView *currentView; |
|
620 |
|
621 if (mainWin && (currentView = mainWin->currentView())) { |
|
622 // Get view flags to use |
|
623 HbView::HbViewFlags viewFlags = HbView::ViewFlagNone; |
|
624 getViewFlagsForVisibilityChange(viewFlags, visible, currentView); |
|
625 // Set the flags |
|
626 currentView->setViewFlags(viewFlags); |
|
627 } |
|
628 } |
|
629 |
|
630 /*! |
|
631 \internal |
|
632 Specifies view flags to use when Title/Statusbar visibility changes. |
|
633 Derived classes should override as appropriate |
|
634 */ |
|
635 void HbAbstractVkbHostPrivate::getViewFlagsForVisibilityChange(HbView::HbViewFlags &viewFlags, bool visible, HbView *view) |
|
636 { |
|
637 if (!view) { |
606 return; |
638 return; |
607 } |
639 } |
608 |
640 |
609 HbView *currentView = mainWin->currentView(); |
641 HbView::HbViewFlags flags = view->viewFlags(); |
610 if (currentView) { |
642 HbView::HbViewFlags setFlags = HbView::ViewFlagNone; |
611 HbView::HbViewFlags flags = currentView->viewFlags(); |
643 |
612 |
644 if (!visible) { |
613 HbView::HbViewFlags setFlags = HbView::ViewFlagNone; |
645 // Should set title and statur bar to not visible. |
614 if (!visible) { |
646 // Check if they were visible before, and set a variable |
615 if (!(flags & HbView::ViewTitleBarHidden)) { |
647 // to remember it was us who hid them. |
616 setFlags |= HbView::ViewTitleBarHidden; |
648 if (!(flags & HbView::ViewTitleBarHidden)) { |
617 mTitleBarHiddenByVkbHost = true; |
649 setFlags |= HbView::ViewTitleBarHidden; |
|
650 mTitleBarHiddenByVkbHost = true; |
|
651 } |
|
652 if (!(flags & HbView::ViewStatusBarHidden)) { |
|
653 setFlags |= HbView::ViewStatusBarHidden; |
|
654 mStatusBarHiddenByVkbHost = true; |
|
655 } |
|
656 if (mTitleBarHiddenByVkbHost || mStatusBarHiddenByVkbHost) { |
|
657 setFlags |= HbView::ViewDisableRelayout; |
|
658 } |
|
659 // Return the original flags plus the ones we may have set |
|
660 viewFlags = (flags | setFlags); |
|
661 } else { |
|
662 // Title and status bar should become visible. |
|
663 // Check if we hid them and clear any flags we might have set before. |
|
664 if ((flags & HbView::ViewDisableRelayout) && |
|
665 (mTitleBarHiddenByVkbHost || mStatusBarHiddenByVkbHost)) { |
|
666 setFlags |= HbView::ViewDisableRelayout; |
|
667 } |
|
668 if ((flags & HbView::ViewTitleBarHidden) && mTitleBarHiddenByVkbHost) { |
|
669 setFlags |= HbView::ViewTitleBarHidden; |
|
670 mTitleBarHiddenByVkbHost = false; |
|
671 } |
|
672 if ((flags & HbView::ViewStatusBarHidden) && mStatusBarHiddenByVkbHost) { |
|
673 setFlags |= HbView::ViewStatusBarHidden; |
|
674 mStatusBarHiddenByVkbHost = false; |
|
675 } |
|
676 // Return the original flags, clear the ones we have set before |
|
677 viewFlags = (flags & ~setFlags); |
|
678 } |
|
679 } |
|
680 |
|
681 /*! |
|
682 \internal |
|
683 Closes the keypad. This slot is connected to various signals from |
|
684 different container classes. |
|
685 */ |
|
686 void HbAbstractVkbHostPrivate::_q_containerAboutToClose() |
|
687 { |
|
688 Q_Q(HbAbstractVkbHost); |
|
689 |
|
690 q->closeKeypad(); |
|
691 } |
|
692 |
|
693 /*! |
|
694 \internal |
|
695 Finds out if given editor is inside a scroll area and makes sure the cursor position is visible inside the |
|
696 scroll area. |
|
697 */ |
|
698 void HbAbstractVkbHostPrivate::ensureVisibilityInsideScrollArea() const |
|
699 { |
|
700 if (mInputMethod && mInputMethod->focusObject()) { |
|
701 HbInputFocusObject *fo = mInputMethod->focusObject(); |
|
702 HbScrollArea *scrollArea = 0; |
|
703 |
|
704 QGraphicsObject *graphicsObject = qobject_cast<QGraphicsObject *>(fo->object()); |
|
705 if (graphicsObject) { |
|
706 for (QGraphicsWidget *parent = graphicsObject->parentWidget(); parent; parent = parent->parentWidget()) { |
|
707 scrollArea = qobject_cast<HbScrollArea*>(parent); |
|
708 if (scrollArea) { |
|
709 break; |
|
710 } |
618 } |
711 } |
619 if (!(flags & HbView::ViewStatusBarHidden)) { |
712 } |
620 setFlags |= HbView::ViewStatusBarHidden; |
713 |
621 mStatusBarHiddenByVkbHost = true; |
714 if (scrollArea && scrollArea->contentWidget()) { |
622 } |
715 QRectF scrollRect = scrollArea->sceneBoundingRect(); |
623 if (mTitleBarHiddenByVkbHost || mStatusBarHiddenByVkbHost) { |
716 QRectF editorRect = fo->editorGeometry(); |
624 setFlags |= HbView::ViewDisableRelayout; |
717 if (!scrollRect.contains(editorRect) && |
625 } |
718 scrollRect.intersects(editorRect)) { |
626 currentView->setViewFlags(flags | setFlags); |
719 // The editor is half visible inside a scroll area. |
627 } else { |
720 // Calculate how much the area needs to be scrolled |
628 if ((flags & HbView::ViewDisableRelayout) && (mTitleBarHiddenByVkbHost || |
721 // to make the cursor line visible inside the scroll |
629 mStatusBarHiddenByVkbHost)) { |
722 // area. The call scroll area's ensure visibility and |
630 setFlags |= HbView::ViewDisableRelayout; |
723 // return the calculated value (it needs to be factored in |
631 } |
724 // to container animation calculations). |
632 if ((flags & HbView::ViewTitleBarHidden) && mTitleBarHiddenByVkbHost) { |
725 if (editorRect.height() < scrollRect.height()) { |
633 setFlags |= HbView::ViewTitleBarHidden; |
726 // Whole editor rect fits into scroll area. Move it there. |
634 mTitleBarHiddenByVkbHost = false; |
727 if (editorRect.bottom() > scrollRect.bottom()) { |
635 } |
728 // Scroll upwards. |
636 if ((flags & HbView::ViewStatusBarHidden) && mStatusBarHiddenByVkbHost) { |
729 scrollArea->ensureVisible(scrollArea->contentWidget()->mapFromScene(editorRect.bottomLeft()), 0.0, HbEditorExtraMargin); |
637 setFlags |= HbView::ViewStatusBarHidden; |
730 } else { |
638 mStatusBarHiddenByVkbHost = false; |
731 // Scroll downwards. |
639 } |
732 scrollArea->ensureVisible(scrollArea->contentWidget()->mapFromScene(editorRect.topLeft()), 0.0, HbEditorExtraMargin); |
640 currentView->setViewFlags(flags & ~setFlags); |
733 } |
641 } |
734 } else { |
|
735 // Whole editor doesn't fit into scroll area. Used micro focus position instead. |
|
736 QRectF microFocus = fo->microFocus(); |
|
737 if (microFocus.bottom() > scrollRect.bottom()) { |
|
738 // Scroll upwards. |
|
739 scrollArea->ensureVisible(scrollArea->contentWidget()->mapFromScene(microFocus.bottomLeft()), 0.0, HbEditorExtraMargin); |
|
740 } else { |
|
741 // Scroll downwards. |
|
742 scrollArea->ensureVisible(scrollArea->contentWidget()->mapFromScene(microFocus.topLeft()), 0.0, HbEditorExtraMargin); |
|
743 } |
|
744 } |
|
745 } |
|
746 } |
642 } |
747 } |
643 } |
748 } |
644 |
749 |
645 /// @endcond |
750 /// @endcond |
646 |
751 |