src/hbcore/vkbhosts/hbshrinkingvkbhost.cpp
changeset 34 ed14f46c0e55
parent 6 c3690ec91ef8
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    22 ** Nokia at developer.feedback@nokia.com.
    22 ** Nokia at developer.feedback@nokia.com.
    23 **
    23 **
    24 ****************************************************************************/
    24 ****************************************************************************/
    25 #include "hbshrinkingvkbhost.h"
    25 #include "hbshrinkingvkbhost.h"
    26 #include "hbabstractvkbhost_p.h"
    26 #include "hbabstractvkbhost_p.h"
    27 
    27 #include "hbvkbhostcontainerwidget_p.h"
    28 #include <hbinputvirtualkeyboard.h>
    28 
    29 #include <hbinputmethod.h>
    29 #include "hbinputvirtualkeyboard.h"
       
    30 #include "hbinputmethod.h"
    30 
    31 
    31 #include "hbwidget.h"
    32 #include "hbwidget.h"
    32 #include "hbmainwindow.h"
    33 #include "hbmainwindow.h"
    33 #include "hbmainwindow_p.h"
    34 #include "hbmainwindow_p.h"
    34 
    35 
    35 /*!
    36 /*!
    36 \proto
    37 \proto
       
    38 @hbcore
    37 \class HbShrinkingVkbHost
    39 \class HbShrinkingVkbHost
    38 \brief A virtual keyboard host that doesn't move the active mainwindow view but shrinks it.
    40 \brief A virtual keyboard host that doesn't move the active mainwindow view but shrinks it.
    39 
    41 
    40 The default virtual keyboard host moves the editor container widget in order to keep the
    42 The default virtual keyboard host moves the editor container widget in order to keep the
    41 cursor line visible. In some situations that doesn't work and the container should be shrunk
    43 cursor line visible. In some situations that doesn't work and the container should be shrunk
    42 and relayouted instead.
    44 and relayouted instead.
    43 
    45 
    44 This virtual keyboard host does that. It works with editors that live inside in main window's
    46 The shrinking virtual keyboard host does that. It works with editors that live inside in main window's
    45 active view and shrinks the view instead of moving it around when the virtual keyboard comes up.
    47 active view and shrinks the view instead of moving it around when the virtual keyboard comes up.
    46 */
    48 
    47 
    49 See \ref vkbHandling "virtual keyboard handling guide" for more information
    48 /// @cond
    50 
       
    51 \sa HbVkbHost
       
    52 \sa HbAbstractVkbHost
       
    53 \sa HbStaticVkbHost
       
    54 */
    49 
    55 
    50 class HbShrinkingVkbHostPrivate : public HbAbstractVkbHostPrivate
    56 class HbShrinkingVkbHostPrivate : public HbAbstractVkbHostPrivate
    51 {
    57 {
    52     Q_DECLARE_PUBLIC(HbShrinkingVkbHost)
    58     Q_DECLARE_PUBLIC(HbShrinkingVkbHost)
    53 
    59 
    54 public:
    60 public:
    55     HbShrinkingVkbHostPrivate(HbAbstractVkbHost *myHost, HbWidget *widget);
    61     HbShrinkingVkbHostPrivate(HbAbstractVkbHost *myHost, HbWidget *widget);
       
    62     ~HbShrinkingVkbHostPrivate();
    56     bool prepareContainerAnimation(HbVkbHost::HbVkbStatus status);
    63     bool prepareContainerAnimation(HbVkbHost::HbVkbStatus status);
    57     void closeKeypad();
    64     void closeKeypad();
    58     void closeKeypadWithoutAnimation();
    65     void closeKeypadWithoutAnimation();
    59     void openKeypadWithoutAnimation();
    66     void openKeypadWithoutAnimation();
    60     void minimizeKeypadWithoutAnimation();
    67     void cancelAnimationAndHideVkbWidget();
    61 
    68 
    62     void shrinkView();
    69     void shrinkView();
    63     void resetViewSize();
    70     void resetViewSize();
    64 
    71 
    65 public:
    72 public:
    66     QSizeF mContainerOriginalSize;
    73     QSizeF mContainerOriginalSize;
       
    74     QSizeF mKeyboardSize;
       
    75     QSizeF mActiveViewSize;
    67 };
    76 };
    68 
    77 
    69 HbShrinkingVkbHostPrivate::HbShrinkingVkbHostPrivate(HbAbstractVkbHost *myHost, HbWidget *widget)
    78 HbShrinkingVkbHostPrivate::HbShrinkingVkbHostPrivate(HbAbstractVkbHost *myHost, HbWidget *widget)
    70     : HbAbstractVkbHostPrivate(myHost, widget)
    79     : HbAbstractVkbHostPrivate(myHost, widget)
    71 {
    80 {
    72 }
    81 }
    73 
    82 
       
    83 HbShrinkingVkbHostPrivate::~HbShrinkingVkbHostPrivate()
       
    84 {
       
    85     resetViewSize();
       
    86 }
       
    87 
    74 bool HbShrinkingVkbHostPrivate::prepareContainerAnimation(HbVkbHost::HbVkbStatus status)
    88 bool HbShrinkingVkbHostPrivate::prepareContainerAnimation(HbVkbHost::HbVkbStatus status)
    75 {
    89 {
    76     Q_UNUSED(status);
    90     if (status == HbVkbHost::HbVkbStatusOpened) {
    77 
    91         if (mContainerWidget &&
    78     // This host doesn't move the container, only the keypad.
    92             (mKeypadStatus == HbVkbHost::HbVkbStatusClosed)) {
       
    93             mContainerMovementVector = mContainerWidget->fixedContainerMovement();
       
    94             return true;
       
    95         }
       
    96     } else if (status == HbVkbHost::HbVkbStatusClosed) {
       
    97         if (mContainerMovementStartingPoint != mOriginalContainerPosition) {
       
    98            mContainerMovementVector = mOriginalContainerPosition - mContainerMovementStartingPoint;
       
    99            return true;
       
   100         }
       
   101     }
       
   102 
    79     return false;
   103     return false;
    80 }
   104 }
    81 
   105 
    82 void HbShrinkingVkbHostPrivate::closeKeypad()
   106 void HbShrinkingVkbHostPrivate::closeKeypad()
    83 {
   107 {
    84     resetViewSize();
       
    85     HbAbstractVkbHostPrivate::closeKeypad();
   108     HbAbstractVkbHostPrivate::closeKeypad();
    86 }
   109 }
    87 
   110 
    88 void HbShrinkingVkbHostPrivate::closeKeypadWithoutAnimation()
   111 void HbShrinkingVkbHostPrivate::closeKeypadWithoutAnimation()
    89 {
   112 {
    95 {
   118 {
    96     HbAbstractVkbHostPrivate::openKeypadWithoutAnimation();
   119     HbAbstractVkbHostPrivate::openKeypadWithoutAnimation();
    97     shrinkView();
   120     shrinkView();
    98 }
   121 }
    99 
   122 
   100 void HbShrinkingVkbHostPrivate::minimizeKeypadWithoutAnimation()
   123 void HbShrinkingVkbHostPrivate::cancelAnimationAndHideVkbWidget()
   101 {
   124 {
   102     HbAbstractVkbHostPrivate::minimizeKeypadWithoutAnimation();
   125     resetViewSize();
   103     shrinkView();
   126     HbAbstractVkbHostPrivate::cancelAnimationAndHideVkbWidget();
   104 }
   127 }
   105 
   128 
   106 void HbShrinkingVkbHostPrivate::resetViewSize()
   129 void HbShrinkingVkbHostPrivate::resetViewSize()
   107 {
   130 {
   108     HbMainWindow *mainWin = mainWindow();
   131     HbMainWindow *mainWin = mainWindow();
   119     HbMainWindow *mainWin = mainWindow();
   142     HbMainWindow *mainWin = mainWindow();
   120     if (mainWin) {
   143     if (mainWin) {
   121         if (!mContainerOriginalSize.isValid()) {
   144         if (!mContainerOriginalSize.isValid()) {
   122             mContainerOriginalSize = HbMainWindowPrivate::d_ptr(mainWin)->viewPortSize();
   145             mContainerOriginalSize = HbMainWindowPrivate::d_ptr(mainWin)->viewPortSize();
   123         }
   146         }
   124         HbMainWindowPrivate::d_ptr(mainWin)->setViewportSize(q->applicationArea().size());
   147         if (mTimeLine.state() != QTimeLine::Running) {
   125     }
   148             QSizeF newViewportSize = q->applicationArea().size();
   126 }
   149             newViewportSize.setHeight(newViewportSize.height() - mContainerWidget->fixedContainerMovement().y());
   127 
   150             HbMainWindowPrivate::d_ptr(mainWin)->setViewportSize(newViewportSize);
   128 /// @endcond
   151         } else {
       
   152             HbMainWindowPrivate::d_ptr(mainWin)->setViewportSize(mActiveViewSize);
       
   153         }
       
   154     }
       
   155 }
   129 
   156 
   130 /*!
   157 /*!
   131 Constructs the object.
   158 Constructs the object.
   132 */
   159 */
   133 HbShrinkingVkbHost::HbShrinkingVkbHost(HbWidget *widget) : HbAbstractVkbHost(new HbShrinkingVkbHostPrivate(this, widget))
   160 HbShrinkingVkbHost::HbShrinkingVkbHost(HbWidget *widget) : HbAbstractVkbHost(new HbShrinkingVkbHostPrivate(this, widget))
   143 }
   170 }
   144 
   171 
   145 /*!
   172 /*!
   146 \reimp
   173 \reimp
   147 */
   174 */
   148 int HbShrinkingVkbHost::priority() const
   175 void HbShrinkingVkbHost::animValueChanged(qreal value)
   149 {
   176 {
   150     return 0;
   177     Q_D(HbShrinkingVkbHost);
       
   178 
       
   179     HbAbstractVkbHost::animValueChanged(value);
       
   180 
       
   181     QSizeF vpSize = d->screenSize();
       
   182     QRectF viewport = QRectF(QPointF(0.0, 0.0), QPointF(vpSize.width(), vpSize.height()));
       
   183 
       
   184     if (!d->mKeyboardSize.isValid()) {
       
   185         d->mKeyboardSize = confirmedKeyboardSize();
       
   186     }
       
   187     
       
   188     // Calculate available space above the keyboard
       
   189     if (d->mKeypadStatus == HbVkbHost::HbVkbStatusOpened) {
       
   190         viewport.setHeight(viewport.height() - d->mKeyboardSize.height() * value);
       
   191     } else {
       
   192         viewport.setHeight(viewport.height() - d->mKeyboardSize.height() * (1 - value));
       
   193     }
       
   194 
       
   195     if (d->mContainerWidget) {
       
   196         viewport.setHeight(viewport.height() - d->mContainerWidget->fixedContainerMovement().y());
       
   197     }
       
   198 
       
   199     d->mActiveViewSize = viewport.size();
       
   200 
       
   201     d->shrinkView();
       
   202     d->ensureVisibilityInsideScrollArea();
   151 }
   203 }
   152 
   204 
   153 /*!
   205 /*!
   154 \reimp
   206 \reimp
   155 */
   207 */
   156 void HbShrinkingVkbHost::animationFinished()
   208 void HbShrinkingVkbHost::animationFinished()
   157 {
   209 {
   158     Q_D(HbShrinkingVkbHost);
   210     Q_D(HbShrinkingVkbHost);
   159 
   211 
   160 
       
   161     HbAbstractVkbHost::animationFinished();
   212     HbAbstractVkbHost::animationFinished();
   162 
   213 
   163     if (d->mKeypadStatus == HbVkbHost::HbVkbStatusOpened ||
   214     if (d->mKeypadStatus == HbVkbHost::HbVkbStatusOpened) {
   164         d->mKeypadStatus == HbVkbHost::HbVkbStatusMinimized) {
       
   165         d->shrinkView();
   215         d->shrinkView();
   166     }
   216     } else {
       
   217         d->resetViewSize();
       
   218     }
       
   219 
       
   220     d->mKeyboardSize = QSizeF();
       
   221     d->ensureVisibilityInsideScrollArea();
   167 }
   222 }
   168 
   223 
   169 // End of file
   224 // End of file
   170