src/hbinput/inputwidgets/hbinputvkbwidget.cpp
changeset 0 16d8024aca5e
child 1 f7ac710697a9
equal deleted inserted replaced
-1:000000000000 0:16d8024aca5e
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbInput module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 #include <QPixmap>
       
    26 #include <QBitmap>
       
    27 #include <QPainter>
       
    28 #include <QGraphicsItemAnimation>
       
    29 #include <QGraphicsSceneMouseEvent>
       
    30 #include <QGraphicsProxyWidget>
       
    31 #include <QTimeLine>
       
    32 #include <QGraphicsGridLayout>
       
    33 #include <QGraphicsScene>
       
    34 #include <QGraphicsLinearLayout>
       
    35 
       
    36 #include <hbapplication.h>
       
    37 #include <hbmainwindow.h>
       
    38 #include <hbaction.h>
       
    39 #include <hbview.h>
       
    40 #include <hbwidget.h>
       
    41 #include <hbpushbutton.h>
       
    42 #include <hbinputsettingproxy.h>
       
    43 #include <hbdialog.h>
       
    44 #include <hbeffect.h>
       
    45 #include <hbstackedwidget.h>
       
    46 #include <hbframedrawer.h>
       
    47 #include <hbevent.h>
       
    48 
       
    49 #include <hbinputmethod.h>
       
    50 #include <hbinputsettingproxy.h>
       
    51 #include <hbinpututils.h>
       
    52 #include <hbinputdef.h>
       
    53 #include <hbinputvkbhost.h>
       
    54 #include <hbinputsettingdialog.h>
       
    55 #include <hbinputcommondialogs.h>
       
    56 #include <hbinputkeymap.h>
       
    57 #include <hbinputkeymapfactory.h>
       
    58 #include <hbwidgetfeedback.h>
       
    59 #include <hbsmileyengine.h>
       
    60 #include <hbinputpredictionfactory.h>
       
    61 
       
    62 #include "hbinputvirtualrocker.h"
       
    63 #include "hbinputvkbwidget.h"
       
    64 #include "hbinputvkbwidget_p.h"
       
    65 #include "hbinputtouchkeypadbutton.h"
       
    66 #include "hbinputsettinglist.h"
       
    67 #include "hbinputmodeindicator.h"
       
    68 #include <hbfeedbackmanager.h>
       
    69 #include "hbinputsmileypicker.h"
       
    70 #include "hbinputscreenshotwidget.h"
       
    71 const qreal HbMouseDragDelta = 0.4;
       
    72 const qreal HbRockerWidth = 50.0;
       
    73 
       
    74 const int MaxSweepTime = 500;
       
    75 const int SweepLength = 150;
       
    76 
       
    77 
       
    78 /*!
       
    79 @proto
       
    80 @hbinput
       
    81 \class HbInputVkbWidget
       
    82 \brief A base class for touch keypads.
       
    83 
       
    84 This class implements default mechanisms for opening and closing touch keypads.
       
    85 It know how to operate in landscape and in portait modes and it know how
       
    86 implement split view -mechasnism for S60 QT UI's Hb library. It also implements
       
    87 closing mechansim, where used is able to close the touch keypad by sliding it downwards
       
    88 with a finger. This class also implements background drawing for touch keypads.
       
    89 */
       
    90 
       
    91 /// @cond
       
    92 
       
    93 inline HbWidget* hbwidget_cast(QGraphicsItem *item)
       
    94 {
       
    95     if( item->isWidget() && static_cast<QGraphicsWidget*>(item)->inherits("HbWidget") ) {
       
    96         return static_cast<HbWidget*>(item);
       
    97     }
       
    98     return 0;
       
    99 }
       
   100 
       
   101 HbInputVkbWidgetPrivate::HbInputVkbWidgetPrivate()
       
   102 : mOwner(0),
       
   103 mMode(EModeAbc),
       
   104 mKeymap(0),
       
   105 mModifiers(0),
       
   106 mInputModeIndicator(0),
       
   107 mApplicationButton(0),
       
   108 mSettingsButton(0),
       
   109 mSettingList(0),
       
   110 mButtonLayout(0),
       
   111 mRocker(0),
       
   112 mBackgroundDrawer(0),
       
   113 mIconDrawer(0),
       
   114 mMainWinConnected(false),
       
   115 mShowRocker(false),
       
   116 mLayout(0),
       
   117 mCurrentHost(0),
       
   118 mDrawbackground(true),
       
   119 mMouseButtonPressedDown(false),
       
   120 mFlickDirection(HbInputVkbWidget::HbFlickDirectionNone),
       
   121 mSmileyPicker(0),
       
   122 mScreenshotWidget(0),
       
   123 mScreenshotTimeLine(250),
       
   124 mMostRecentlyAccessedButton(0),
       
   125 mMostRecentlyClickedLocation(0.0,0.0),
       
   126 mFocusedObject(0),
       
   127 mFlickAnimation(false),
       
   128 mSettingsListOpen(false),
       
   129 mAnimateWhenDialogCloses(false),
       
   130 mKeyboardSize(HbQwerty4x10),
       
   131 mCloseHandleHeight(0),
       
   132 mCloseHandle(NULL),
       
   133 mKeyboardDimmed(false)
       
   134 {
       
   135 }
       
   136 
       
   137 
       
   138 HbInputVkbWidgetPrivate::~HbInputVkbWidgetPrivate()
       
   139 {
       
   140     delete mSettingList;
       
   141     delete mBackgroundDrawer;
       
   142     delete mIconDrawer;
       
   143     delete mSmileyPicker;
       
   144     delete mScreenshotWidget;
       
   145 }
       
   146 
       
   147 void HbInputVkbWidgetPrivate::init()
       
   148 {
       
   149     Q_Q(HbInputVkbWidget);
       
   150 
       
   151     mRocker = new HbInputVirtualRocker(q);
       
   152     mRocker->setObjectName("VirtualRocker");
       
   153     QSizeF rockerSize(HbRockerWidth, HbRockerWidth);
       
   154     mRocker->resize(rockerSize);
       
   155     mRocker->setMinimumSize(HbRockerWidth, HbRockerWidth);
       
   156     mRocker->setMaximumSize(HbRockerWidth*20, HbRockerWidth*20);
       
   157 
       
   158     QObject::connect(mRocker, SIGNAL(rockerDirection(int, HbInputVirtualRocker::RockerSelectionMode)),
       
   159         q, SIGNAL(rockerDirection(int, HbInputVirtualRocker::RockerSelectionMode)));
       
   160 
       
   161     mRocker->setVisible(false);
       
   162 
       
   163     mBackgroundDrawer = new HbFrameDrawer();
       
   164     mBackgroundDrawer->setFrameGraphicsName(backgroundGraphics);
       
   165     mBackgroundDrawer->setFrameType(HbFrameDrawer::ThreePiecesVertical);
       
   166     mBackgroundDrawer->setFillWholeRect(true);
       
   167     mBackgroundDrawer->setBorderWidths(0.0, HbCloseHandleHeight, 0.0, HbCloseHandleHeight);
       
   168 
       
   169     mIconDrawer = new HbFrameDrawer();
       
   170     mIconDrawer->setFrameType(HbFrameDrawer::OnePiece);
       
   171     mIconDrawer->setFrameGraphicsName(HbInputVkbHandleIcon);
       
   172 
       
   173     mReleaseMapper = new QSignalMapper(q);
       
   174     mPressMapper = new QSignalMapper(q);
       
   175     mActionMapper = new QSignalMapper(q);
       
   176 }
       
   177 
       
   178 // re-implemented by inherited keyboards
       
   179 int HbInputVkbWidgetPrivate::keyCode(int buttonId)
       
   180 {
       
   181     Q_UNUSED(buttonId);
       
   182     return -1;
       
   183 }
       
   184 
       
   185 // re-implemented by inherited keyboards
       
   186 int HbInputVkbWidgetPrivate::keyCode(HbTouchKeypadButton *button)
       
   187 {
       
   188     Q_UNUSED(button);
       
   189     return -1;
       
   190 }
       
   191 
       
   192 void HbInputVkbWidgetPrivate::handleStandardButtonPress(int buttonid)
       
   193 {
       
   194     int keycode = buttonid;
       
   195     if (buttonid >= 0) {
       
   196         keycode = keyCode(buttonid);
       
   197     }
       
   198 
       
   199     QKeyEvent event(QEvent::KeyPress, keycode, Qt::NoModifier);
       
   200     if (mOwner) {
       
   201         mOwner->filterEvent(&event);
       
   202     }
       
   203 }
       
   204 
       
   205 void HbInputVkbWidgetPrivate::handleStandardButtonRelease(int buttonid)
       
   206 {
       
   207     int keycode = buttonid;
       
   208     if (buttonid >= 0) {
       
   209         keycode = keyCode(buttonid);
       
   210     }
       
   211 
       
   212     QKeyEvent event(QEvent::KeyRelease, keycode, Qt::NoModifier);
       
   213     if (mOwner) {
       
   214         mOwner->filterEvent(&event);
       
   215     }
       
   216 }
       
   217 
       
   218 void HbInputVkbWidgetPrivate::addCustomButtonToLayout( HbTouchKeypadButton* button,
       
   219                                                        int index)
       
   220 {
       
   221     Q_UNUSED(button);
       
   222     Q_UNUSED(index);
       
   223 }
       
   224 
       
   225 void HbInputVkbWidgetPrivate::redirectMousePressEvent(QGraphicsSceneMouseEvent *aEvent)
       
   226 {
       
   227     q_ptr->mousePressEvent(aEvent);
       
   228 }
       
   229 
       
   230 void HbInputVkbWidgetPrivate::redirectMouseReleaseEvent(QGraphicsSceneMouseEvent *aEvent)
       
   231 {
       
   232     q_ptr->mouseReleaseEvent(aEvent);
       
   233 }
       
   234 
       
   235 void HbInputVkbWidgetPrivate::applyEditorConstraints() {
       
   236     // no default implementaiton as of now.
       
   237 }
       
   238 
       
   239 void HbInputVkbWidgetPrivate::setRockerPosition()
       
   240 {
       
   241     Q_Q(HbInputVkbWidget);
       
   242 
       
   243     // Set rocker position.
       
   244     QSizeF padArea = q->keypadButtonAreaSize();
       
   245     QPointF point((padArea.width() * 0.5) - (mRocker->size().width() * 0.5),
       
   246         (padArea.height() * 0.5) - (mRocker->size().height() * 0.5));
       
   247     point.setY(point.y() + mCloseHandleHeight);
       
   248 
       
   249     if (q->keypadLayout() && q->keypadLayout()->geometry().height()) {
       
   250         point.setX(((padArea.width() * 0.5) - (mRocker->size().width() * 0.5)));
       
   251         point.setY(((q->keypadLayout()->geometry().height() * 0.5) - (mRocker->size().height() * 0.5) + mCloseHandleHeight));
       
   252     }
       
   253     mRocker->setPos(point);
       
   254 }
       
   255 
       
   256 void HbInputVkbWidgetPrivate::captureScreenshot()
       
   257 {
       
   258     Q_Q(HbInputVkbWidget);
       
   259 
       
   260     if (!mScreenshotWidget) {
       
   261         mScreenshotWidget = new HbInputScreenshotWidget();
       
   262         mScreenshotWidget->setGeometry(q->geometry());
       
   263         q->mainWindow()->scene()->addItem(mScreenshotWidget);
       
   264     }
       
   265 
       
   266     QPointF position = q->pos();
       
   267     QRectF rect = QRectF(position.x(), position.y()+ mCloseHandleHeight, q->boundingRect().width(), q->boundingRect().height()- mCloseHandleHeight);
       
   268     QTransform rotateTrans;
       
   269     rotateTrans = q->mainWindow()->viewportTransform();
       
   270     QRectF transRect = rotateTrans.mapRect(rect);
       
   271     QPixmap pixmap;
       
   272     pixmap = QPixmap::grabWidget(q->mainWindow(), (int)transRect.x(), (int)transRect.y(), (int)transRect.width(), (int)transRect.height());
       
   273     pixmap = pixmap.transformed(rotateTrans.inverted());
       
   274     mScreenshotWidget->setScreenshot(pixmap);
       
   275 }
       
   276 
       
   277 
       
   278 void HbInputVkbWidgetPrivate::updateMouseHitItem(HbTouchKeypadButton *button, QPointF position)
       
   279 {
       
   280     mMostRecentlyAccessedButton = button;
       
   281     mMostRecentlyClickedLocation = position;
       
   282 }
       
   283 
       
   284 void HbInputVkbWidgetPrivate::normalizeProbabilities(QList<HbKeyPressProbability> &allProbableKeys)
       
   285 {
       
   286     qreal sum = 0.0;
       
   287     foreach (HbKeyPressProbability key, allProbableKeys) {
       
   288         sum += key.probability;
       
   289     }
       
   290 
       
   291     for (int count=0;count<allProbableKeys.size();count++) {
       
   292         allProbableKeys[count].probability = allProbableKeys[count].probability / sum;
       
   293     }
       
   294 }
       
   295 
       
   296 bool HbInputVkbWidgetPrivate::isKeyboardDimmed()
       
   297 {
       
   298     return mKeyboardDimmed;
       
   299 }
       
   300 
       
   301 bool HbInputVkbWidgetPrivate::isSmileysEnabled()
       
   302 {
       
   303     bool ret = false;
       
   304     if (!mOwner || !mOwner->focusObject()) {
       
   305         return ret;
       
   306     }
       
   307     if (mOwner->focusObject()->editorInterface().editor()->inherits("HbAbstractEdit")) {
       
   308         if (!mOwner->focusObject()->editorInterface().smileyTheme().isNull()) {
       
   309             ret = true;
       
   310         }		
       
   311     }	else {
       
   312         HbSmileyEngine smileyEngine;
       
   313         if (!smileyEngine.defaultTheme().isNull()) {
       
   314             ret = true;
       
   315         }	
       
   316     }	
       
   317     return ret;	
       
   318 }
       
   319 /// @endcond
       
   320 
       
   321 /*!
       
   322 Costructs the object.
       
   323 */
       
   324 HbInputVkbWidget::HbInputVkbWidget(QGraphicsItem* parent)
       
   325     : HbWidget(*new HbInputVkbWidgetPrivate, parent)
       
   326 {
       
   327     Q_D(HbInputVkbWidget);
       
   328     d->q_ptr = this;
       
   329     d->init();
       
   330 
       
   331     setFocusPolicy(Qt::ClickFocus);
       
   332     setPos(QPointF(0,0));
       
   333 
       
   334 #ifdef HB_EFFECTS
       
   335     HbEffect::disable(this);
       
   336 #endif // HB_EFFECTS
       
   337 
       
   338 #if QT_VERSION >= 0x040600
       
   339     // Make sure the keypad never steals focus.
       
   340     setFlag(QGraphicsItem::ItemIsPanel, true);
       
   341     setActive(false);
       
   342 #endif
       
   343 }
       
   344 
       
   345 /*!
       
   346 Constructs the object.
       
   347 */
       
   348 HbInputVkbWidget::HbInputVkbWidget(HbInputVkbWidgetPrivate& dd, QGraphicsItem* parent)
       
   349   : HbWidget(dd, parent)
       
   350 {
       
   351     Q_D(HbInputVkbWidget);
       
   352     d->q_ptr = this;
       
   353     d->init();
       
   354 
       
   355     setFocusPolicy(Qt::ClickFocus);
       
   356     setPos(QPointF(0,0));
       
   357 
       
   358 #ifdef HB_EFFECTS
       
   359     HbEffect::disable(this);
       
   360 #endif // HB_EFFECTS
       
   361 
       
   362 #if QT_VERSION >= 0x040600
       
   363     // Make sure the keypad never steals focus.
       
   364     setFlag(QGraphicsItem::ItemIsPanel, true);
       
   365     setActive(false);
       
   366 #endif
       
   367 }
       
   368 
       
   369 /*!
       
   370 Destructs the object.
       
   371 */
       
   372 HbInputVkbWidget::~HbInputVkbWidget()
       
   373 {
       
   374 }
       
   375 
       
   376 /*!
       
   377 Vkb host calls this handler when the keypad open animation finishes.
       
   378 */
       
   379 void HbInputVkbWidget::keyboardOpened(HbVkbHost *host)
       
   380 {
       
   381     Q_D(HbInputVkbWidget);
       
   382 
       
   383     d->mCurrentHost = host;
       
   384     d->mRocker->setVisible(d->mShowRocker);
       
   385     d->setRockerPosition();
       
   386 }
       
   387 
       
   388 /*!
       
   389 Vkb host calls this handler when the keyboard close animation has finished.
       
   390 
       
   391 \sa HbVkbHost
       
   392 */
       
   393 void HbInputVkbWidget::keyboardClosed(HbVkbHost *host)
       
   394 {
       
   395     Q_UNUSED(host);
       
   396     Q_D(HbInputVkbWidget);
       
   397 
       
   398     d->mRocker->setVisible(false);
       
   399 }
       
   400 
       
   401 /*!
       
   402 Vkb host calls this handler when the keyboard minimize animation has finished.
       
   403 
       
   404 \sa HbVkbHost
       
   405 */
       
   406 void HbInputVkbWidget::keyboardMinimized(HbVkbHost *host)
       
   407 {
       
   408     Q_UNUSED(host);
       
   409 }
       
   410 
       
   411 /*!
       
   412 handles mouse press event.
       
   413 */
       
   414 void HbInputVkbWidget::mousePressEvent(QGraphicsSceneMouseEvent* event)
       
   415 {
       
   416     Q_D(HbInputVkbWidget);
       
   417     Q_UNUSED(event);
       
   418     if (!d->mMouseButtonPressedDown) {
       
   419         d->mMouseButtonPressedDown = true;
       
   420         d->mMousePressTime.start();
       
   421     }
       
   422 }
       
   423 
       
   424 /*!
       
   425 Handles mouse release event.
       
   426 */
       
   427 void HbInputVkbWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
       
   428 {
       
   429     Q_D(HbInputVkbWidget);
       
   430     d->mFlickDirection = HbFlickDirectionNone;
       
   431     d->mMouseButtonPressedDown = false;
       
   432 
       
   433     QPointF mouseDownpoint = event->buttonDownScenePos(Qt::LeftButton);
       
   434 
       
   435     if (d->mCurrentHost && d->mCurrentHost->keypadStatus() != HbVkbHost::HbVkbStatusOpened &&
       
   436         d->mCurrentHost->activeKeypad() && d->mOwner) {
       
   437         HbWidgetFeedback::triggered(this, Hb::InstantFlicked);
       
   438         d->mCurrentHost->openKeypad(d->mCurrentHost->activeKeypad(), d->mOwner);
       
   439     } else if (d->mMousePressTime.elapsed() < MaxSweepTime || mouseDownpoint.y() <= scenePos().y() + d->mCloseHandleHeight) {
       
   440         QPointF delta = event->scenePos() - mouseDownpoint;
       
   441 
       
   442         qreal height;
       
   443         if (HbInputSettingProxy::instance()->screenOrientation() == Qt::Horizontal) {
       
   444             height = geometry().height() * 0.5;
       
   445         } else {
       
   446             // For ITU-T, 40% of the scene height is considered.
       
   447             height = 0.4 * geometry().height();
       
   448         }
       
   449         // If the user drags the mouse on keypad and the
       
   450         // delta is greater than 10% of the height, keypad is closed
       
   451         height = HbMouseDragDelta * height;
       
   452 
       
   453         if (delta.y() > height) {
       
   454             HbWidgetFeedback::triggered(this, Hb::InstantFlicked);
       
   455             d->mFlickDirection = HbFlickDirectionDown;
       
   456             emit keypadCloseEventDetected(HbVkbCloseMethodButtonDrag);
       
   457         }
       
   458 
       
   459         if (qAbs(delta.x()) > SweepLength) {
       
   460 
       
   461             d->mFlickDirection = delta.x()>0 ? HbFlickDirectionRight : HbFlickDirectionLeft;
       
   462 
       
   463             if (d->mFlickAnimation){
       
   464                 HbWidgetFeedback::triggered(this, Hb::InstantFlicked);
       
   465                 animKeyboardChange();
       
   466             }
       
   467             emit flickEvent(d->mFlickDirection);
       
   468         }
       
   469     }
       
   470 }
       
   471 
       
   472 /*!
       
   473 Handles virtual key press
       
   474 */
       
   475 void HbInputVkbWidget::mappedKeyPress(int buttonid)
       
   476 {
       
   477     Q_D(HbInputVkbWidget);
       
   478     d->handleStandardButtonPress(buttonid);
       
   479 }
       
   480 
       
   481 /*!
       
   482 Handles virtual key release
       
   483 */
       
   484 void HbInputVkbWidget::mappedKeyRelease(int buttonid)
       
   485 {
       
   486     Q_D(HbInputVkbWidget);
       
   487     d->handleStandardButtonRelease(buttonid);
       
   488 }
       
   489 
       
   490 
       
   491 /*!
       
   492 The paint method. Draws the widget.
       
   493 */
       
   494 void HbInputVkbWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
       
   495 {
       
   496     Q_UNUSED(option);
       
   497     Q_UNUSED(widget);
       
   498 
       
   499     Q_D(HbInputVkbWidget);
       
   500 
       
   501     QRectF rect = boundingRect();
       
   502     if (d->mDrawbackground) {
       
   503         d->mBackgroundDrawer->paint(painter, rect);
       
   504     }
       
   505 
       
   506     rect.setLeft(rect.width()/2 - d->mCloseHandleHeight*3);
       
   507     rect.setWidth(d->mCloseHandleHeight*6);
       
   508     rect.setHeight(d->mCloseHandleHeight);
       
   509     d->mIconDrawer->paint(painter, rect);
       
   510 }
       
   511 
       
   512 /*!
       
   513 Sets virtual rocker visibility.
       
   514 */
       
   515 void HbInputVkbWidget::setRockerVisible(bool visible)
       
   516 {
       
   517     Q_D(HbInputVkbWidget);
       
   518     d->mShowRocker = visible;
       
   519 }
       
   520 
       
   521 /*!
       
   522 Returns true if virtual rocker is allowed to be visible.
       
   523 */
       
   524 bool HbInputVkbWidget::isRockerVisible() const
       
   525 {
       
   526     Q_D(const HbInputVkbWidget);
       
   527     if (d->mShowRocker) {
       
   528         return d->mRocker->isVisible();
       
   529     } else {
       
   530         return false;
       
   531     }
       
   532 }
       
   533 
       
   534 /*!
       
   535 Returns active keypad mode. Possible values are EModeAbc, EModeNumeric and EModeSct.
       
   536 */
       
   537 HbKeypadMode HbInputVkbWidget::mode() const
       
   538 {
       
   539     Q_D(const HbInputVkbWidget);
       
   540     return d->mMode;
       
   541 }
       
   542 
       
   543 /*!
       
   544 Returns active keypad modifiers.
       
   545 */
       
   546 HbModifiers HbInputVkbWidget::modifiers() const
       
   547 {
       
   548     Q_D(const HbInputVkbWidget);
       
   549     return d->mModifiers;
       
   550 }
       
   551 
       
   552 /*!
       
   553 Sets the keypad to given mode. Possible values are EModeAbc, EModeNumeric and EModeSct.
       
   554 */
       
   555 void HbInputVkbWidget::setMode(HbKeypadMode mode, HbModifiers modifiers)
       
   556 {
       
   557     Q_D(HbInputVkbWidget);
       
   558     d->mModifiers = modifiers;
       
   559     d->mMode = mode;
       
   560 }
       
   561 
       
   562 /*!
       
   563 Sets key map data object. Given key map data will be used as a source for button titles.
       
   564 Usually the key map data for active input language is used.
       
   565 */
       
   566 void HbInputVkbWidget::setKeymap(const HbKeymap* keymap)
       
   567 {
       
   568     Q_D(HbInputVkbWidget);
       
   569     if (keymap) {
       
   570         d->mKeymap = keymap;
       
   571     }
       
   572 }
       
   573 
       
   574 /*!
       
   575 This is called right before the keypad is about to open. This gives inheriting classes opportunity
       
   576 to do whatever initialization they need to do at this point.
       
   577 */
       
   578 void HbInputVkbWidget::aboutToOpen(HbVkbHost *host)
       
   579 {
       
   580     Q_D(HbInputVkbWidget);
       
   581 
       
   582     d->mCurrentHost = host;
       
   583 
       
   584     if (!d->mLayout) {
       
   585         // get preferred size from vkbhost and set it to vkb.
       
   586         // Keypad buttons will flicker while vkb opening (when we open keypad for first time )
       
   587         // if we dont set size to vkb before seting layout to vkb.
       
   588         resize(preferredKeyboardSize());
       
   589         d->mLayout = new QGraphicsLinearLayout(Qt::Vertical);
       
   590         d->mLayout->setContentsMargins(0.0, 0.0, 0.0, 0.0);
       
   591         d->mLayout->setSpacing(0.0);
       
   592 
       
   593         setLayout(d->mLayout);
       
   594 
       
   595         d->mCloseHandle = new QGraphicsWidget();
       
   596         d->mCloseHandle->setObjectName("vkbHandle");
       
   597         d->mCloseHandleHeight = HbCloseHandleHeight;
       
   598         d->mCloseHandle->setMinimumHeight(d->mCloseHandleHeight);
       
   599         d->mCloseHandle->setMaximumHeight(d->mCloseHandleHeight);
       
   600 
       
   601         d->mLayout->addItem(d->mCloseHandle);
       
   602         d->mLayout->addItem(keypadLayout());
       
   603     }
       
   604 
       
   605 
       
   606     if (d->mOwner && d->mOwner->focusObject()) {
       
   607         qreal vkbZValue = d->mOwner->focusObject()->findVkbZValue();
       
   608         setZValue(vkbZValue);
       
   609         d->mRocker->setZValue(vkbZValue+0.5);
       
   610     }
       
   611 
       
   612     show();
       
   613 }
       
   614 
       
   615 /*!
       
   616 This is called right before the keypad is about to close.
       
   617 */
       
   618 void HbInputVkbWidget::aboutToClose(HbVkbHost *host)
       
   619 {
       
   620     Q_D(HbInputVkbWidget);
       
   621 
       
   622     d->mCurrentHost = host;
       
   623 
       
   624     d->mRocker->setVisible(false);
       
   625     if (d->mSettingList) {
       
   626         d->mSettingList->close();
       
   627     }
       
   628 }
       
   629 
       
   630 /*!
       
   631 Enables or disabled all buttons in the keyboard that have not been disabled directly.
       
   632 */
       
   633 void HbInputVkbWidget::setKeyboardDimmed(bool dimmed)
       
   634 {
       
   635     Q_D(HbInputVkbWidget);
       
   636     d->mKeyboardDimmed = dimmed;
       
   637     if (keypadLayout()) {
       
   638         int itemCount = keypadLayout()->count();
       
   639         for (int i=0; i<itemCount; i++) {
       
   640             HbTouchKeypadButton* button = static_cast<HbTouchKeypadButton*>(keypadLayout()->itemAt(i));
       
   641             button->setFade(dimmed);
       
   642         }
       
   643     }
       
   644     if (!dimmed) {
       
   645         // when we undimmed the keyboard, all the buttons will be enabled by default.
       
   646         // we need to call applyEditorConstraints on the keyboard to apply constraints
       
   647         d->applyEditorConstraints();
       
   648     }
       
   649 
       
   650 }
       
   651 
       
   652 /*!
       
   653 Shows settings list
       
   654 */
       
   655 void HbInputVkbWidget::showSettingList()
       
   656 {
       
   657     Q_D(HbInputVkbWidget);
       
   658     HbPredictionFactory *predFactory = HbPredictionFactory::instance();
       
   659 
       
   660     d->mSettingsListOpen = true;
       
   661     d->captureScreenshot();
       
   662 
       
   663     if (!d->mSettingList) {
       
   664         d->mSettingList = new HbInputSettingList();
       
   665         connect(d->mSettingList, SIGNAL(aboutToClose()), this, SLOT(settingsClosed()));
       
   666         connect(d->mSettingList, SIGNAL(inputSettingsButtonClicked()), this, SLOT(executeSettingsDialog()));
       
   667         connect(d->mSettingList, SIGNAL(inputMethodsButtonClicked()), this, SLOT(executeMethodDialog()));
       
   668     }
       
   669 
       
   670 #if QT_VERSION >= 0x040600
       
   671     HbInputFocusObject *focusObject = d->mOwner->focusObject();
       
   672     if (focusObject &&
       
   673         focusObject->editorInterface().isPredictionAllowed() &&
       
   674         !focusObject->editorInterface().isNumericEditor() &&
       
   675         predFactory->predictionEngineForLanguage(HbInputSettingProxy::instance()->globalInputLanguage())) {
       
   676         d->mSettingList->setPredictionSelectionEnabled(true);
       
   677     } else {
       
   678         d->mSettingList->setPredictionSelectionEnabled(false);
       
   679     }
       
   680 #endif
       
   681 
       
   682     d->mSettingsButton->setBackgroundAttributes(HbTouchKeypadButton::HbTouchButtonLatched);
       
   683     qreal x = d->mSettingsButton->scenePos().x() + d->mSettingsButton->rect().width();
       
   684     qreal y = d->mSettingsButton->scenePos().y();
       
   685     d->mSettingList->setPreferredPos(QPointF(x, y), HbPopup::BottomRightCorner);
       
   686     d->mSettingList->showSettingList();
       
   687     d->mSettingsListOpen = false;
       
   688     if ( d->mAnimateWhenDialogCloses ) {
       
   689         animKeyboardChange();
       
   690         d->mAnimateWhenDialogCloses = false;
       
   691     } else if(d->mScreenshotTimeLine.state() != QTimeLine::Running) {
       
   692         keypadLanguageChangeFinished();
       
   693     }
       
   694 }
       
   695 
       
   696 /*!
       
   697 Slot to connect aboutToClose of settings list to update keyboard graphics.
       
   698 */
       
   699 void HbInputVkbWidget::settingsClosed()
       
   700 {
       
   701     Q_D(HbInputVkbWidget);
       
   702     d->mSettingsButton->setBackgroundAttributes(HbTouchKeypadButton::HbTouchButtonReleased);
       
   703 }
       
   704 
       
   705 /*!
       
   706 Closes settings list
       
   707 */
       
   708 void HbInputVkbWidget::closeSettingList()
       
   709 {
       
   710     Q_D(HbInputVkbWidget);
       
   711     d->mSettingList->close();
       
   712     d->mSettingsButton->setBackgroundAttributes(HbTouchKeypadButton::HbTouchButtonReleased);
       
   713 }
       
   714 
       
   715 /*!
       
   716 Toggles prediction status.
       
   717 */
       
   718 void HbInputVkbWidget::togglePredictionStatus()
       
   719 {
       
   720     closeSettingList();
       
   721     bool predictionStatus = HbInputSettingProxy::instance()->predictiveInputStatus();
       
   722     HbInputSettingProxy::instance()->setPredictiveInputStatus(!predictionStatus);
       
   723     update();
       
   724 }
       
   725 
       
   726 /*!
       
   727 Executes settingsDialog
       
   728 */
       
   729 void HbInputVkbWidget::executeSettingsDialog()
       
   730 {
       
   731     Q_D(HbInputVkbWidget);
       
   732 
       
   733     closeSettingList();
       
   734     HbInputSettingDialog::HbSettingItems items = HbInputSettingDialog::HbSettingItemAll;
       
   735     if (d->mOwner->focusObject()->editorInterface().isNumericEditor()) {
       
   736         items &=  (~HbInputSettingDialog::HbSettingItemPrediction);
       
   737     }
       
   738     HbInputSettingDialog* settings = new HbInputSettingDialog(items);
       
   739     d->mSettingsListOpen = true;
       
   740     settings->exec();
       
   741     delete settings;
       
   742     d->mSettingsListOpen = false;
       
   743     if ( d->mAnimateWhenDialogCloses ) {
       
   744         animKeyboardChange();
       
   745         d->mAnimateWhenDialogCloses = false;
       
   746     } else {
       
   747         keypadLanguageChangeFinished();
       
   748     }
       
   749 }
       
   750 
       
   751 /*!
       
   752 Executes input method selection dialog
       
   753 */
       
   754 void HbInputVkbWidget::executeMethodDialog()
       
   755 {
       
   756     Q_D(HbInputVkbWidget);
       
   757 
       
   758     closeSettingList();
       
   759     HbInputMethodDescriptor method
       
   760         = HbInputCommonDialogs::showCustomInputMethodSelectionDialog(HbInputSettingProxy::instance()->globalInputLanguage());
       
   761     if (!method.isEmpty() && d->mOwner) {
       
   762         d->mOwner->activateInputMethod(method);
       
   763     }
       
   764 }
       
   765 
       
   766 /*!
       
   767 Virtual function, each derived keypads should calculate and provide the
       
   768 layout information through this functions. This layout information is used
       
   769 by HbInputVkbWidget for layouting different components of vkb.
       
   770 */
       
   771 QGraphicsLayout *HbInputVkbWidget::keypadLayout()
       
   772 {
       
   773     Q_D(HbInputVkbWidget);
       
   774     return d->mButtonLayout;
       
   775 }
       
   776 
       
   777 /*!
       
   778 Returns the keypad in QWidget form.
       
   779 */
       
   780 QWidget* HbInputVkbWidget::asWidget()
       
   781 {
       
   782     return HbInputUtils::createWrapperWidget(this);
       
   783 }
       
   784 
       
   785 /*!
       
   786 Returns the keypad in QGraphicsWidget form.
       
   787 */
       
   788 QGraphicsWidget* HbInputVkbWidget::asGraphicsWidget()
       
   789 {
       
   790     return this;
       
   791 }
       
   792 
       
   793 /*!
       
   794 Returns preferred keyboard size. HbVkbHost uses this information when it opens the keyboard.
       
   795 */
       
   796 QSizeF HbInputVkbWidget::preferredKeyboardSize()
       
   797 {
       
   798     Q_D(HbInputVkbWidget);
       
   799 
       
   800     if (d->mCurrentHost) {
       
   801         // Just rely on the host and return what it suggests.
       
   802         QSizeF rect = d->mCurrentHost->keyboardArea();
       
   803         return rect;
       
   804     }
       
   805 
       
   806     return QSizeF(0.0, 0.0);
       
   807 }
       
   808 
       
   809 /*!
       
   810 This method is called every time vkb host draws an opening animation frame.
       
   811 */
       
   812 void HbInputVkbWidget::keyboardAnimationFrame(HbVkbAnimationType type, qreal x)
       
   813 {
       
   814     Q_UNUSED(type);
       
   815     Q_UNUSED(x);
       
   816 
       
   817     Q_D(HbInputVkbWidget);
       
   818     d->setRockerPosition();
       
   819 }
       
   820 
       
   821 /*!
       
   822 Returns the size of the keypad button area.
       
   823 */
       
   824 QSizeF HbInputVkbWidget::keypadButtonAreaSize()
       
   825 {
       
   826     Q_D(HbInputVkbWidget);
       
   827     QSizeF ret = preferredKeyboardSize();
       
   828     if (ret.height() >  d->mCloseHandleHeight) {
       
   829         ret.setHeight(ret.height() - d->mCloseHandleHeight);
       
   830 	}
       
   831 
       
   832     return ret;
       
   833 }
       
   834 
       
   835 /*!
       
   836 Sets the status of the background drawing. This method can be used to
       
   837 optimize vkb widget drawing. If it is known that the widget will cover whole
       
   838 vkb area and there are no places where the background shows through, then the background
       
   839 drawing can be turned off to speed up paint method.
       
   840 */
       
   841 void HbInputVkbWidget::setBackgroundDrawing(bool backgroundEnabled)
       
   842 {
       
   843     Q_D(HbInputVkbWidget);
       
   844     d->mDrawbackground = backgroundEnabled;
       
   845 }
       
   846 
       
   847 
       
   848 /*!
       
   849 Returns all possible keys those the user could have intended to press
       
   850 for the last registered touch along with their corresponding probability.
       
   851 One issue of thecurrent API implementation is that it does not always
       
   852 sum up the probabilities to 1.0, but sometimes it returns.999999899 etc.
       
   853 Need to be careful about it!
       
   854 */
       
   855 QList<HbKeyPressProbability> HbInputVkbWidget::probableKeypresses()
       
   856 {
       
   857     Q_D(HbInputVkbWidget);
       
   858 
       
   859     QList<HbKeyPressProbability> probableKeys;
       
   860     int totalItems = d->mButtonLayout->count();
       
   861     QRectF buttonRect = d->mMostRecentlyAccessedButton->geometry();
       
   862     //The overlaying rectangle is the test rectangle that is used for finding
       
   863     //intersactions with other buttons.
       
   864     QRectF overlayingRect(d->mMostRecentlyClickedLocation.x()-buttonRect.width()/2,d->mMostRecentlyClickedLocation.y()-buttonRect.height()/2, buttonRect.width(), buttonRect.height());
       
   865     QPainterPath path(overlayingRect.topLeft());
       
   866     path.addRect(overlayingRect);
       
   867     for(int count=0; count < totalItems; count++) {
       
   868         QGraphicsItem *item = d->mButtonLayout->itemAt(count)->graphicsItem();
       
   869         QPainterPath testPath = item->mapFromScene(path);
       
   870         HbTouchKeypadButton *buttonItem = 0;
       
   871         if(item->isWidget()){
       
   872             buttonItem =  qobject_cast<HbTouchKeypadButton *>(static_cast<QGraphicsWidget *>(item));
       
   873         }
       
   874         if(!buttonItem) {
       
   875             continue;
       
   876         }
       
   877 
       
   878         //Checkif the button collides with the path, if yes,it means that the colliding
       
   879         //key also could have been clicked by the user. The probability of the button being
       
   880         //clickedin that case willdependon the area of the intersaction rectangle.
       
   881         if(buttonItem->collidesWithPath(testPath)) {
       
   882             //Initiallylet the intersaction be same as the overlaying rectangle,later we will
       
   883             //shrink the rectangle and find the actual intersected rectangle.
       
   884             QRectF intersactionRect = overlayingRect;
       
   885             //The overlaying rectangle is in scene coordinates, map it to the item coordinates.
       
   886             intersactionRect.moveTopLeft(buttonItem->mapFromScene(overlayingRect.topLeft()));
       
   887             int width = (int)intersactionRect.width();
       
   888             int height = (int)intersactionRect.height();
       
   889             qreal probability = 0.0;
       
   890             //Shrink based on the size of the intersaction
       
   891             if (intersactionRect.topLeft().x() > 0) {
       
   892                 width -= (int)intersactionRect.topLeft().x();
       
   893             } else {
       
   894                 width += (int)intersactionRect.topLeft().x();
       
   895             }
       
   896             if (intersactionRect.topLeft().y() > 0) {
       
   897                 height -= (int)intersactionRect.topLeft().y();
       
   898             } else {
       
   899                 height += (int)intersactionRect.topLeft().y();
       
   900             }
       
   901             //The probabilty of the key is based on the intersaction area.
       
   902             probability = (height * width) / (intersactionRect.width()* intersactionRect.height());
       
   903             HbKeyPressProbability probablekey;
       
   904             probablekey.keycode = d->keyCode(buttonItem);
       
   905             probablekey.probability = probability;
       
   906 
       
   907             if(probablekey.keycode && (probablekey.probability>0)) {
       
   908                 probableKeys.append(probablekey);
       
   909             }
       
   910         }
       
   911     }
       
   912     //Normalize makes sure that all probability summation is 1.0.
       
   913     d->normalizeProbabilities(probableKeys);
       
   914     return probableKeys;
       
   915 }
       
   916 
       
   917 /*!
       
   918 Sets up the common buttons in the tool cluster (settings and application buttons).
       
   919 */
       
   920 void HbInputVkbWidget::setupToolCluster()
       
   921 {
       
   922     Q_D(HbInputVkbWidget);
       
   923     if(!d->mOwner || !d->mOwner->focusObject()) {
       
   924         return;
       
   925     }
       
   926 
       
   927     // Create settings button if it does not exist
       
   928     if (!d->mSettingsButton) {
       
   929         d->mSettingsButton = new HbTouchKeypadButton(this, QString(""));
       
   930         d->mInputModeIndicator = new HbInputModeIndicator(*d->mSettingsButton, this);
       
   931         d->mSettingsButton->setButtonType(HbTouchKeypadButton::HbTouchButtonFunction);
       
   932         d->mSettingsButton->setBackgroundAttributes(HbTouchKeypadButton::HbTouchButtonReleased);
       
   933 
       
   934         connect(d->mSettingsButton, SIGNAL(clicked()), this, SLOT(showSettingList()));
       
   935 
       
   936         connect(d->mSettingsButton, SIGNAL(pressed()), d->mPressMapper, SLOT(map()));
       
   937         connect(d->mSettingsButton, SIGNAL(released()), d->mReleaseMapper, SLOT(map()));
       
   938         d->mPressMapper->setMapping(d->mSettingsButton, -1);
       
   939         d->mReleaseMapper->setMapping(d->mSettingsButton, -1);
       
   940     } else {
       
   941         d->mInputModeIndicator->updateIndicator();
       
   942     }
       
   943 
       
   944     // If there's a application specific button defined, create new button with the properties
       
   945     // or update the existing one. Otherwise create an empty button or clean the properties of an existing one.
       
   946     if (!d->mOwner->focusObject()->editorInterface().actions().isEmpty()) {
       
   947         QList<HbAction*> actions = d->mOwner->focusObject()->editorInterface().actions();
       
   948         if (d->mApplicationButtonAction != actions.first()) {
       
   949             if (d->mApplicationButton) {
       
   950                 d->mApplicationButton->setText(actions.first()->text());
       
   951                 d->mApplicationButton->setIcon(actions.first()->icon());
       
   952                 d->mApplicationButton->disconnect(SIGNAL(clicked()));
       
   953                 d->mApplicationButton->disconnect(SIGNAL(pressed()));
       
   954                 d->mApplicationButton->disconnect(SIGNAL(released()));
       
   955 
       
   956                 // disconnects old signal
       
   957                 disconnect(d->mApplicationButtonAction, SIGNAL(changed()), this, SLOT(refreshApplicationButton()));
       
   958                 disconnect(d->mApplicationButton, SIGNAL(clicked()), d->mApplicationButtonAction, SLOT(trigger()));
       
   959             } else {
       
   960                 d->mApplicationButton = new HbTouchKeypadButton(this, actions.first()->icon(), actions.first()->text());
       
   961             }
       
   962             d->mApplicationButtonAction = actions.first();
       
   963             // Connect to enabling signal and check its value
       
   964             connect(actions.first(), SIGNAL(changed()), this, SLOT(refreshApplicationButton()));
       
   965 
       
   966             if (actions.first()->isEnabled()) {
       
   967                 // action is enabled
       
   968                 connect(d->mApplicationButton, SIGNAL(clicked()), d->mApplicationButtonAction, SLOT(trigger()));
       
   969 
       
   970                 connect(d->mApplicationButton, SIGNAL(pressed()), d->mPressMapper, SLOT(map()));
       
   971                 connect(d->mApplicationButton, SIGNAL(released()), d->mReleaseMapper, SLOT(map()));
       
   972                 d->mPressMapper->setMapping(d->mApplicationButton, -1);
       
   973                 d->mReleaseMapper->setMapping(d->mApplicationButton, -1);
       
   974 
       
   975                 d->mApplicationButton->setToolTip(actions.first()->toolTip());
       
   976                 d->mApplicationButton->setButtonType(HbTouchKeypadButton::HbTouchButtonFunction);
       
   977                 d->mApplicationButton->setBackgroundAttributes(HbTouchKeypadButton::HbTouchButtonReleased);
       
   978             } else {
       
   979                 // action is disabled
       
   980                 d->mApplicationButton->setButtonType(HbTouchKeypadButton::HbTouchButtonFnInActive);
       
   981                 d->mApplicationButton->setBackgroundAttributes(HbTouchKeypadButton::HbTouchButtonPressed);
       
   982             }
       
   983             d->mApplicationButton->setToolTip(actions.first()->toolTip());
       
   984         }
       
   985     } else {
       
   986         if (d->mApplicationButton) {
       
   987             if (d->mApplicationButtonAction) {
       
   988                 disconnect(d->mApplicationButtonAction, SIGNAL(changed()), this, SLOT(refreshApplicationButton()));
       
   989             }
       
   990             d->mApplicationButton->disconnect(SIGNAL(clicked()));
       
   991             d->mApplicationButton->disconnect(SIGNAL(pressed()));
       
   992             d->mApplicationButton->disconnect(SIGNAL(released()));
       
   993             d->mApplicationButton->setText(QString());
       
   994             d->mApplicationButton->setIcon(HbIcon());
       
   995             d->mApplicationButton->setToolTip(QString());
       
   996 			d->mApplicationButtonAction = 0;
       
   997         } else {
       
   998             d->mApplicationButton = new HbTouchKeypadButton(this, QString());
       
   999             d->mApplicationButton->setButtonType(HbTouchKeypadButton::HbTouchButtonFunction);
       
  1000             d->mApplicationButton->setBackgroundAttributes(HbTouchKeypadButton::HbTouchButtonReleased);
       
  1001         }
       
  1002         d->mApplicationButtonAction = NULL;
       
  1003     }
       
  1004 }
       
  1005 
       
  1006 /*!
       
  1007 shape function actually refines the bounding rect. This function is used for collision detection
       
  1008 and hit test.
       
  1009 */
       
  1010 QPainterPath HbInputVkbWidget::shape() const
       
  1011 {
       
  1012     QRectF rect = boundingRect();
       
  1013     QPainterPath path;
       
  1014     path.addRect(rect);
       
  1015     return path;
       
  1016 }
       
  1017 
       
  1018 QSizeF HbInputVkbWidget::minimizedKeyboardSize()
       
  1019 {
       
  1020     Q_D(HbInputVkbWidget);
       
  1021     return QSizeF(0.0, d->mCloseHandleHeight);
       
  1022 }
       
  1023 
       
  1024 void HbInputVkbWidget::showSmileyPicker(int rows, int columns)
       
  1025 {
       
  1026     Q_D(HbInputVkbWidget);
       
  1027     if (!d->mOwner || !d->mOwner->focusObject()) {
       
  1028         return;
       
  1029     }
       
  1030     // check whether the smiley recognition is enabled 	in the currently focused editor.
       
  1031     if (!d->isSmileysEnabled()) {
       
  1032         return;
       
  1033     }
       
  1034     HbInputFocusObject *focusObject = d->mOwner->focusObject();
       
  1035 	
       
  1036     if (!d->mSmileyPicker || d->mFocusedObject != focusObject) {
       
  1037         d->mFocusedObject = focusObject;
       
  1038         if (d->mSmileyPicker) {
       
  1039             delete d->mSmileyPicker;
       
  1040         }
       
  1041         // get the smiley list from editor interface smiley theme.
       
  1042         QStringList smileys = focusObject->editorInterface().smileyTheme().smileys();
       
  1043         // if the smiley list is empty and the editor is not a Hb editor, 
       
  1044         // then get the default smiley list from smiley engine.
       
  1045         if (smileys.isEmpty() && !focusObject->editorInterface().editor()->inherits("HbAbstractEdit")) {
       
  1046             HbSmileyEngine smileyEngine;
       
  1047             smileys = smileyEngine.defaultTheme().smileys();
       
  1048         }
       
  1049 
       
  1050         if (!smileys.isEmpty()) {
       
  1051             d->mSmileyPicker = new HbInputSmileyPicker(rows, columns, 0, smileys);
       
  1052             d->mSmileyPicker->setObjectName("vkbwidget_smiley_picker");
       
  1053             connect(d->mSmileyPicker, SIGNAL(selected(QString)), this, SIGNAL(smileySelected(QString)));
       
  1054         }			
       
  1055     }
       
  1056 
       
  1057     if (d->mSmileyPicker) {
       
  1058         d->mSmileyPicker->setGeometry(QRectF(0, pos().y(), geometry().width(),
       
  1059             geometry().height()));
       
  1060         d->mSmileyPicker->show();
       
  1061     }		
       
  1062 }
       
  1063 
       
  1064 HbInputVkbWidget::HbFlickDirection HbInputVkbWidget::flickDirection()
       
  1065 {
       
  1066     Q_D(HbInputVkbWidget);
       
  1067     return d->mFlickDirection;
       
  1068 }
       
  1069 
       
  1070 /*!
       
  1071     Intended for internal use only
       
  1072 */
       
  1073 void HbInputVkbWidget::refreshApplicationButton()
       
  1074 {
       
  1075     Q_D(HbInputVkbWidget);
       
  1076 
       
  1077     d->mApplicationButton->setText(d->mApplicationButtonAction->text());
       
  1078     d->mApplicationButton->setIcon(d->mApplicationButtonAction->icon());
       
  1079 
       
  1080     if (d->mApplicationButton->getButtonType() == HbTouchKeypadButton::HbTouchButtonFnInActive
       
  1081         && d->mApplicationButtonAction->isEnabled()) {
       
  1082         // action has been enabled
       
  1083         connect(d->mApplicationButton, SIGNAL(clicked()), d->mApplicationButtonAction, SLOT(trigger()));
       
  1084         d->mApplicationButton->setToolTip(d->mApplicationButtonAction->toolTip());
       
  1085         d->mApplicationButton->setFade(false);
       
  1086     } else if (d->mApplicationButton->getButtonType() == HbTouchKeypadButton::HbTouchButtonFunction
       
  1087         && !d->mApplicationButtonAction->isEnabled()) {
       
  1088         // action has been disabled
       
  1089         d->mApplicationButton->disconnect(SIGNAL(clicked()));
       
  1090         d->mApplicationButton->setFade(true);
       
  1091     }
       
  1092 }
       
  1093 
       
  1094 void HbInputVkbWidget::keypadLanguageChangeAnimationUpdate(qreal aValue)
       
  1095 {
       
  1096     Q_D(HbInputVkbWidget);
       
  1097 
       
  1098     int direction = 1;
       
  1099     if (flickDirection() == HbFlickDirectionLeft) {
       
  1100         direction = -1;
       
  1101     }
       
  1102 
       
  1103     QRectF rect = boundingRect();
       
  1104     QPointF position = pos();
       
  1105     position.setX(direction * (-rect.width() + rect.width() * aValue));
       
  1106     if (d->mScreenshotWidget) {
       
  1107        d->mScreenshotWidget->setPos(position.x() + direction * rect.width(), position.y());
       
  1108        setPos(position);
       
  1109     }
       
  1110 }
       
  1111 
       
  1112 void HbInputVkbWidget::keypadLanguageChangeFinished()
       
  1113 {
       
  1114     Q_D(HbInputVkbWidget);
       
  1115     delete d->mScreenshotWidget;
       
  1116     d->mScreenshotWidget = NULL;
       
  1117 }
       
  1118 
       
  1119 void HbInputVkbWidget::animKeyboardChange()
       
  1120 {
       
  1121     Q_D(HbInputVkbWidget);
       
  1122     if (mainWindow()) {
       
  1123         if (d->mSettingsListOpen){
       
  1124             d->mAnimateWhenDialogCloses = true;
       
  1125         } else {
       
  1126             if (!d->mAnimateWhenDialogCloses) {
       
  1127                 d->captureScreenshot();
       
  1128             }
       
  1129             connect(&d->mScreenshotTimeLine, SIGNAL(valueChanged(qreal)), this, SLOT(keypadLanguageChangeAnimationUpdate(qreal)));
       
  1130             connect(&d->mScreenshotTimeLine, SIGNAL(finished()), this, SLOT(keypadLanguageChangeFinished()));
       
  1131             d->mScreenshotTimeLine.start();
       
  1132         }
       
  1133     }
       
  1134 }
       
  1135 
       
  1136 QSizeF HbInputVkbWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
       
  1137 {
       
  1138     Q_UNUSED(constraint);
       
  1139     Q_D(const HbInputVkbWidget);
       
  1140 
       
  1141     QSizeF sh;
       
  1142     switch (which) {
       
  1143         case Qt::MinimumSize:
       
  1144             sh = QSizeF(0, 0);
       
  1145             break;
       
  1146         case Qt::PreferredSize:
       
  1147             if (d->mCurrentHost) {
       
  1148                 sh = d->mCurrentHost->keyboardArea();
       
  1149             }
       
  1150             break;
       
  1151         case Qt::MaximumSize:
       
  1152             sh = QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
       
  1153             break;
       
  1154         default:
       
  1155             qWarning("HbInputVkbWidget::sizeHint(): Don't know how to handle the value of 'which'");
       
  1156             break;
       
  1157     }
       
  1158     return sh;
       
  1159 }
       
  1160 
       
  1161 /*!
       
  1162     \reimp
       
  1163  */
       
  1164 void HbInputVkbWidget::changeEvent(QEvent *event)
       
  1165 {
       
  1166     Q_D(HbInputVkbWidget);
       
  1167     if (event->type() == HbEvent::ThemeChanged) {
       
  1168         d->mBackgroundDrawer->themeChanged();
       
  1169         d->mIconDrawer->themeChanged();
       
  1170     }
       
  1171     HbWidget::changeEvent(event);
       
  1172 }
       
  1173 
       
  1174 // End of file