src/hbcore/vkbhosts/hbshrinkingvkbhost.cpp
changeset 5 627c4a0fd0e7
child 6 c3690ec91ef8
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
       
     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 HbCore 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 "hbshrinkingvkbhost.h"
       
    26 #include "hbabstractvkbhost_p.h"
       
    27 
       
    28 #include <hbinputvirtualkeyboard.h>
       
    29 #include <hbinputmethod.h>
       
    30 
       
    31 #include "hbwidget.h"
       
    32 #include "hbmainwindow.h"
       
    33 #include "hbmainwindow_p.h"
       
    34 
       
    35 /*!
       
    36 \proto
       
    37 \class HbShrinkingVkbHost
       
    38 \brief A virtual keyboard host that doesn't move the active mainwindow view but shrinks it.
       
    39 
       
    40 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
       
    42 and relayouted instead.
       
    43 
       
    44 This 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.
       
    46 */
       
    47 
       
    48 /// @cond
       
    49 
       
    50 class HbShrinkingVkbHostPrivate : public HbAbstractVkbHostPrivate
       
    51 {
       
    52     Q_DECLARE_PUBLIC(HbShrinkingVkbHost)
       
    53 
       
    54 public:
       
    55     HbShrinkingVkbHostPrivate(HbAbstractVkbHost *myHost, HbWidget *widget);
       
    56     bool prepareContainerAnimation(HbVkbHost::HbVkbStatus status);
       
    57     void closeKeypad();
       
    58     void closeKeypadWithoutAnimation();
       
    59     void openKeypadWithoutAnimation();
       
    60     void minimizeKeypadWithoutAnimation();
       
    61 
       
    62     void shrinkView();
       
    63     void resetViewSize();
       
    64 
       
    65 public:
       
    66     QSizeF mContainerOriginalSize;
       
    67 };
       
    68 
       
    69 HbShrinkingVkbHostPrivate::HbShrinkingVkbHostPrivate(HbAbstractVkbHost *myHost, HbWidget *widget)
       
    70 : HbAbstractVkbHostPrivate(myHost, widget)
       
    71 {
       
    72 }
       
    73 
       
    74 bool HbShrinkingVkbHostPrivate::prepareContainerAnimation(HbVkbHost::HbVkbStatus status)
       
    75 {
       
    76     Q_UNUSED(status);
       
    77 
       
    78     // This host doesn't move the container, only the keypad.
       
    79     return false;
       
    80 }
       
    81 
       
    82 void HbShrinkingVkbHostPrivate::closeKeypad()
       
    83 { 
       
    84     resetViewSize();
       
    85     HbAbstractVkbHostPrivate::closeKeypad();
       
    86 }
       
    87 
       
    88 void HbShrinkingVkbHostPrivate::closeKeypadWithoutAnimation()
       
    89 {  
       
    90     resetViewSize();
       
    91     HbAbstractVkbHostPrivate::closeKeypadWithoutAnimation();
       
    92 }
       
    93 
       
    94 void HbShrinkingVkbHostPrivate::openKeypadWithoutAnimation()
       
    95 {
       
    96     HbAbstractVkbHostPrivate::openKeypadWithoutAnimation();
       
    97     shrinkView();
       
    98 }
       
    99 
       
   100 void HbShrinkingVkbHostPrivate::minimizeKeypadWithoutAnimation()
       
   101 {
       
   102     HbAbstractVkbHostPrivate::minimizeKeypadWithoutAnimation();
       
   103     shrinkView();
       
   104 }
       
   105 
       
   106 void HbShrinkingVkbHostPrivate::resetViewSize()
       
   107 {    
       
   108     HbMainWindow *mainWin = mainWindow();
       
   109     if (mainWin && mContainerOriginalSize.isValid()) {
       
   110         HbMainWindowPrivate::d_ptr(mainWin)->setViewportSize(mContainerOriginalSize);
       
   111         mContainerOriginalSize = QSizeF();
       
   112     }
       
   113 }
       
   114 
       
   115 void HbShrinkingVkbHostPrivate::shrinkView()
       
   116 {
       
   117     Q_Q(HbShrinkingVkbHost);
       
   118 
       
   119     HbMainWindow *mainWin = mainWindow();
       
   120     if (mainWin) {
       
   121         if (!mContainerOriginalSize.isValid()) {
       
   122             mContainerOriginalSize = HbMainWindowPrivate::d_ptr(mainWin)->viewPortSize();
       
   123         }
       
   124         HbMainWindowPrivate::d_ptr(mainWin)->setViewportSize(q->applicationArea().size());
       
   125     }
       
   126 }
       
   127 
       
   128 /// @endcond
       
   129 
       
   130 /*!
       
   131 Constructs the object.
       
   132 */
       
   133 HbShrinkingVkbHost::HbShrinkingVkbHost(HbWidget *widget) : HbAbstractVkbHost(new HbShrinkingVkbHostPrivate(this, widget))
       
   134 {  
       
   135     setParent(widget);   
       
   136 }
       
   137 
       
   138 /*!
       
   139 Destructs the object.
       
   140 */
       
   141 HbShrinkingVkbHost::~HbShrinkingVkbHost()
       
   142 {
       
   143 }
       
   144 
       
   145 /*!
       
   146 \reimp
       
   147 */
       
   148 int HbShrinkingVkbHost::priority() const
       
   149 {   
       
   150     return 0;
       
   151 }
       
   152 
       
   153 /*!
       
   154 \reimp
       
   155 */
       
   156 void HbShrinkingVkbHost::animationFinished()
       
   157 {
       
   158     Q_D(HbShrinkingVkbHost);
       
   159 
       
   160 
       
   161     HbAbstractVkbHost::animationFinished();
       
   162 
       
   163     if (d->mKeypadStatus == HbVkbHost::HbVkbStatusOpened ||
       
   164         d->mKeypadStatus == HbVkbHost::HbVkbStatusMinimized) {
       
   165         d->shrinkView();
       
   166     }
       
   167 }
       
   168 
       
   169 // End of file
       
   170