src/hbcore/vkbhosts/hbvkbhostcontainerwidget.cpp
author hgs
Mon, 18 Oct 2010 18:23:13 +0300
changeset 34 ed14f46c0e55
permissions -rw-r--r--
201041
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34
hgs
parents:
diff changeset
     1
/****************************************************************************
hgs
parents:
diff changeset
     2
**
hgs
parents:
diff changeset
     3
** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     4
** All rights reserved.
hgs
parents:
diff changeset
     5
** Contact: Nokia Corporation (developer.feedback@nokia.com)
hgs
parents:
diff changeset
     6
**
hgs
parents:
diff changeset
     7
** This file is part of the HbCore module of the UI Extensions for Mobile.
hgs
parents:
diff changeset
     8
**
hgs
parents:
diff changeset
     9
** GNU Lesser General Public License Usage
hgs
parents:
diff changeset
    10
** This file may be used under the terms of the GNU Lesser General Public
hgs
parents:
diff changeset
    11
** License version 2.1 as published by the Free Software Foundation and
hgs
parents:
diff changeset
    12
** appearing in the file LICENSE.LGPL included in the packaging of this file.
hgs
parents:
diff changeset
    13
** Please review the following information to ensure the GNU Lesser General
hgs
parents:
diff changeset
    14
** Public License version 2.1 requirements will be met:
hgs
parents:
diff changeset
    15
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hgs
parents:
diff changeset
    16
**
hgs
parents:
diff changeset
    17
** In addition, as a special exception, Nokia gives you certain additional
hgs
parents:
diff changeset
    18
** rights.  These rights are described in the Nokia Qt LGPL Exception
hgs
parents:
diff changeset
    19
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
hgs
parents:
diff changeset
    20
**
hgs
parents:
diff changeset
    21
** If you have questions regarding the use of this file, please contact
hgs
parents:
diff changeset
    22
** Nokia at developer.feedback@nokia.com.
hgs
parents:
diff changeset
    23
**
hgs
parents:
diff changeset
    24
****************************************************************************/
hgs
parents:
diff changeset
    25
#include "hbvkbhostcontainerwidget_p.h"
hgs
parents:
diff changeset
    26
#include "hbinputfocusobject.h"
hgs
parents:
diff changeset
    27
#include "hbvkbconstants_p.h"
hgs
parents:
diff changeset
    28
#include "hbdeviceprofile.h"
hgs
parents:
diff changeset
    29
#include "hbmainwindow_p.h"
hgs
parents:
diff changeset
    30
#include "hbstatusbar_p.h"
hgs
parents:
diff changeset
    31
#include "hbtitlebar_p.h"
hgs
parents:
diff changeset
    32
#include "hbmainwindow.h"
hgs
parents:
diff changeset
    33
#include "hbpopup.h"
hgs
parents:
diff changeset
    34
#include "hbview.h"
hgs
parents:
diff changeset
    35
hgs
parents:
diff changeset
    36
#include <QWidget>
hgs
parents:
diff changeset
    37
hgs
parents:
diff changeset
    38
/*!
hgs
parents:
diff changeset
    39
\internal
hgs
parents:
diff changeset
    40
\class HbVkbHostContainerWidget
hgs
parents:
diff changeset
    41
Encapsulates editor container widget and knows how the perform certain operations
hgs
parents:
diff changeset
    42
with it, regardless of its base class (QWidget or QGraphicsObject).
hgs
parents:
diff changeset
    43
In case of HbView, takes care of hiding title and status bars by returning suitable
hgs
parents:
diff changeset
    44
fixed movement vector.
hgs
parents:
diff changeset
    45
hgs
parents:
diff changeset
    46
This class is for internal use only.
hgs
parents:
diff changeset
    47
*/
hgs
parents:
diff changeset
    48
hgs
parents:
diff changeset
    49
HbVkbHostContainerWidget::HbVkbHostContainerWidget(QObject *containerWidget) 
hgs
parents:
diff changeset
    50
 : mTopLevelItem(0)
hgs
parents:
diff changeset
    51
{
hgs
parents:
diff changeset
    52
    mGraphicsObject = qobject_cast<QGraphicsObject*>(containerWidget);
hgs
parents:
diff changeset
    53
    if (!mGraphicsObject) {
hgs
parents:
diff changeset
    54
        mWidget = qobject_cast<QWidget*>(containerWidget);
hgs
parents:
diff changeset
    55
    }
hgs
parents:
diff changeset
    56
}
hgs
parents:
diff changeset
    57
hgs
parents:
diff changeset
    58
/*!
hgs
parents:
diff changeset
    59
\internal
hgs
parents:
diff changeset
    60
Sets container widgets position to new position.
hgs
parents:
diff changeset
    61
*/
hgs
parents:
diff changeset
    62
void HbVkbHostContainerWidget::setPos(QPointF newPosition)
hgs
parents:
diff changeset
    63
{
hgs
parents:
diff changeset
    64
    if (mGraphicsObject) {
hgs
parents:
diff changeset
    65
        if (!mTopLevelItem) {
hgs
parents:
diff changeset
    66
            mTopLevelItem = mGraphicsObject->topLevelItem();
hgs
parents:
diff changeset
    67
        }
hgs
parents:
diff changeset
    68
        mTopLevelItem->setPos(newPosition);
hgs
parents:
diff changeset
    69
        return;
hgs
parents:
diff changeset
    70
    }
hgs
parents:
diff changeset
    71
hgs
parents:
diff changeset
    72
    if (mWidget) {
hgs
parents:
diff changeset
    73
#ifdef Q_WS_WIN
hgs
parents:
diff changeset
    74
        QPoint finalPosition = newPosition.toPoint();
hgs
parents:
diff changeset
    75
        finalPosition -= mWidget->geometry().topLeft() - mWidget->frameGeometry().topLeft();
hgs
parents:
diff changeset
    76
        mWidget->move(finalPosition);
hgs
parents:
diff changeset
    77
#else
hgs
parents:
diff changeset
    78
        mWidget->move(newPosition.toPoint());
hgs
parents:
diff changeset
    79
#endif
hgs
parents:
diff changeset
    80
        return;
hgs
parents:
diff changeset
    81
    }
hgs
parents:
diff changeset
    82
}
hgs
parents:
diff changeset
    83
hgs
parents:
diff changeset
    84
/*!
hgs
parents:
diff changeset
    85
\internal
hgs
parents:
diff changeset
    86
Returns the global position, if container widget is a QGraphicsObject, it returns
hgs
parents:
diff changeset
    87
scene position. In case the widget is QWidget it returns global co-ordinates
hgs
parents:
diff changeset
    88
*/
hgs
parents:
diff changeset
    89
QPointF HbVkbHostContainerWidget::pos() const
hgs
parents:
diff changeset
    90
{
hgs
parents:
diff changeset
    91
    if (mGraphicsObject) {
hgs
parents:
diff changeset
    92
        if (!mTopLevelItem) {
hgs
parents:
diff changeset
    93
            mTopLevelItem = mGraphicsObject->topLevelItem();
hgs
parents:
diff changeset
    94
        }
hgs
parents:
diff changeset
    95
        return mTopLevelItem->pos();
hgs
parents:
diff changeset
    96
    }
hgs
parents:
diff changeset
    97
hgs
parents:
diff changeset
    98
    if (mWidget) {
hgs
parents:
diff changeset
    99
        return mWidget->mapToGlobal(QPoint(0, 0));
hgs
parents:
diff changeset
   100
    }
hgs
parents:
diff changeset
   101
hgs
parents:
diff changeset
   102
    return QPointF(0, 0);
hgs
parents:
diff changeset
   103
}
hgs
parents:
diff changeset
   104
hgs
parents:
diff changeset
   105
/*!
hgs
parents:
diff changeset
   106
\internal
hgs
parents:
diff changeset
   107
Returns the bounding rect in global co-ordinate, if container widget is a QGraphicsObject
hgs
parents:
diff changeset
   108
it returns in scene co-ordinate, incase widget is QWidget it returns in global co-ordinate
hgs
parents:
diff changeset
   109
*/
hgs
parents:
diff changeset
   110
QRectF HbVkbHostContainerWidget::sceneBoundingRect() const
hgs
parents:
diff changeset
   111
{
hgs
parents:
diff changeset
   112
    if (mGraphicsObject) {
hgs
parents:
diff changeset
   113
        return mGraphicsObject->sceneBoundingRect();
hgs
parents:
diff changeset
   114
    }
hgs
parents:
diff changeset
   115
hgs
parents:
diff changeset
   116
    if (mWidget) {
hgs
parents:
diff changeset
   117
        return QRectF(mWidget->mapToGlobal(QPoint(0, 0)), mWidget->size());
hgs
parents:
diff changeset
   118
    }
hgs
parents:
diff changeset
   119
hgs
parents:
diff changeset
   120
    return QRectF(0, 0, 0, 0);
hgs
parents:
diff changeset
   121
}
hgs
parents:
diff changeset
   122
hgs
parents:
diff changeset
   123
/*!
hgs
parents:
diff changeset
   124
\internal
hgs
parents:
diff changeset
   125
Connects container specific signals.
hgs
parents:
diff changeset
   126
*/
hgs
parents:
diff changeset
   127
void HbVkbHostContainerWidget::connectSignals(QObject *receiver)
hgs
parents:
diff changeset
   128
{
hgs
parents:
diff changeset
   129
    if (mGraphicsObject) {
hgs
parents:
diff changeset
   130
        QObject::connect(mGraphicsObject, SIGNAL(yChanged()),
hgs
parents:
diff changeset
   131
                         receiver, SLOT(ensureCursorVisibility()));
hgs
parents:
diff changeset
   132
    }
hgs
parents:
diff changeset
   133
hgs
parents:
diff changeset
   134
    HbPopup *popup = qobject_cast<HbPopup *>(mGraphicsObject);
hgs
parents:
diff changeset
   135
    if (popup) {
hgs
parents:
diff changeset
   136
        QObject::connect(popup, SIGNAL(aboutToHide()), receiver, SLOT(_q_containerAboutToClose()));
hgs
parents:
diff changeset
   137
    }
hgs
parents:
diff changeset
   138
hgs
parents:
diff changeset
   139
    HbView *view = qobject_cast<HbView *>(mGraphicsObject);
hgs
parents:
diff changeset
   140
    if (view) {
hgs
parents:
diff changeset
   141
        QObject::connect(view->mainWindow(), SIGNAL(currentViewChanged(HbView *)),
hgs
parents:
diff changeset
   142
                         receiver, SLOT(_q_containerAboutToClose()));
hgs
parents:
diff changeset
   143
    }
hgs
parents:
diff changeset
   144
}
hgs
parents:
diff changeset
   145
hgs
parents:
diff changeset
   146
/*!
hgs
parents:
diff changeset
   147
\internal
hgs
parents:
diff changeset
   148
Disconnects container specific signals.
hgs
parents:
diff changeset
   149
*/
hgs
parents:
diff changeset
   150
void HbVkbHostContainerWidget::disconnectSignals(QObject *receiver)
hgs
parents:
diff changeset
   151
{
hgs
parents:
diff changeset
   152
    if (mGraphicsObject) {
hgs
parents:
diff changeset
   153
        QObject::disconnect(mGraphicsObject, SIGNAL(yChanged()),
hgs
parents:
diff changeset
   154
                            receiver, SLOT(ensureCursorVisibility()));
hgs
parents:
diff changeset
   155
    }
hgs
parents:
diff changeset
   156
hgs
parents:
diff changeset
   157
    HbPopup *popup = qobject_cast<HbPopup *>(mGraphicsObject);
hgs
parents:
diff changeset
   158
    if (popup) {
hgs
parents:
diff changeset
   159
        QObject::disconnect(popup, SIGNAL(aboutToHide()), receiver, SLOT(_q_containerAboutToClose()));
hgs
parents:
diff changeset
   160
    }
hgs
parents:
diff changeset
   161
hgs
parents:
diff changeset
   162
    HbPopup *view = qobject_cast<HbPopup *>(mGraphicsObject);
hgs
parents:
diff changeset
   163
    if (view) {
hgs
parents:
diff changeset
   164
        QObject::disconnect(view->mainWindow(), SIGNAL(currentViewChanged(HbView *)),
hgs
parents:
diff changeset
   165
                            receiver, SLOT(_q_containerAboutToClose()));
hgs
parents:
diff changeset
   166
    }
hgs
parents:
diff changeset
   167
}
hgs
parents:
diff changeset
   168
hgs
parents:
diff changeset
   169
/*!
hgs
parents:
diff changeset
   170
\internal
hgs
parents:
diff changeset
   171
Returns fixed container movement vector. This vector is the minimum amount
hgs
parents:
diff changeset
   172
the container always needs to be moved when the keypad opens.
hgs
parents:
diff changeset
   173
In case of HbView, it is used for hiding status and title bars.
hgs
parents:
diff changeset
   174
*/
hgs
parents:
diff changeset
   175
QPointF HbVkbHostContainerWidget::fixedContainerMovement() const
hgs
parents:
diff changeset
   176
{
hgs
parents:
diff changeset
   177
    // Find out if the editor is inside a view and if it is, eliminate possible
hgs
parents:
diff changeset
   178
    // status and title bars with suitable fixed movement vector.
hgs
parents:
diff changeset
   179
    HbView *view = qobject_cast<HbView*>(mGraphicsObject);
hgs
parents:
diff changeset
   180
    qreal yComponent = 0.0;
hgs
parents:
diff changeset
   181
    if (view) {
hgs
parents:
diff changeset
   182
        HbMainWindow *mainWindow = view->mainWindow();
hgs
parents:
diff changeset
   183
        if (mainWindow) {
hgs
parents:
diff changeset
   184
            if (view->isItemVisible(Hb::TitleBarItem)) {
hgs
parents:
diff changeset
   185
                 yComponent += HbMainWindowPrivate::d_ptr(mainWindow)->mTitleBar->sceneBoundingRect().height();
hgs
parents:
diff changeset
   186
            }
hgs
parents:
diff changeset
   187
            if (view->isItemVisible(Hb::StatusBarItem)) {
hgs
parents:
diff changeset
   188
                 yComponent += HbMainWindowPrivate::d_ptr(mainWindow)->mStatusBar->sceneBoundingRect().height();
hgs
parents:
diff changeset
   189
            }
hgs
parents:
diff changeset
   190
            return QPointF(0, -yComponent);
hgs
parents:
diff changeset
   191
        }    
hgs
parents:
diff changeset
   192
    }
hgs
parents:
diff changeset
   193
hgs
parents:
diff changeset
   194
    return QPointF(0, 0);
hgs
parents:
diff changeset
   195
}
hgs
parents:
diff changeset
   196
hgs
parents:
diff changeset
   197
// End of file