34
|
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 "hbvkbhostcontainerwidget_p.h"
|
|
26 |
#include "hbinputfocusobject.h"
|
|
27 |
#include "hbvkbconstants_p.h"
|
|
28 |
#include "hbdeviceprofile.h"
|
|
29 |
#include "hbmainwindow_p.h"
|
|
30 |
#include "hbstatusbar_p.h"
|
|
31 |
#include "hbtitlebar_p.h"
|
|
32 |
#include "hbmainwindow.h"
|
|
33 |
#include "hbpopup.h"
|
|
34 |
#include "hbview.h"
|
|
35 |
|
|
36 |
#include <QWidget>
|
|
37 |
|
|
38 |
/*!
|
|
39 |
\internal
|
|
40 |
\class HbVkbHostContainerWidget
|
|
41 |
Encapsulates editor container widget and knows how the perform certain operations
|
|
42 |
with it, regardless of its base class (QWidget or QGraphicsObject).
|
|
43 |
In case of HbView, takes care of hiding title and status bars by returning suitable
|
|
44 |
fixed movement vector.
|
|
45 |
|
|
46 |
This class is for internal use only.
|
|
47 |
*/
|
|
48 |
|
|
49 |
HbVkbHostContainerWidget::HbVkbHostContainerWidget(QObject *containerWidget)
|
|
50 |
: mTopLevelItem(0)
|
|
51 |
{
|
|
52 |
mGraphicsObject = qobject_cast<QGraphicsObject*>(containerWidget);
|
|
53 |
if (!mGraphicsObject) {
|
|
54 |
mWidget = qobject_cast<QWidget*>(containerWidget);
|
|
55 |
}
|
|
56 |
}
|
|
57 |
|
|
58 |
/*!
|
|
59 |
\internal
|
|
60 |
Sets container widgets position to new position.
|
|
61 |
*/
|
|
62 |
void HbVkbHostContainerWidget::setPos(QPointF newPosition)
|
|
63 |
{
|
|
64 |
if (mGraphicsObject) {
|
|
65 |
if (!mTopLevelItem) {
|
|
66 |
mTopLevelItem = mGraphicsObject->topLevelItem();
|
|
67 |
}
|
|
68 |
mTopLevelItem->setPos(newPosition);
|
|
69 |
return;
|
|
70 |
}
|
|
71 |
|
|
72 |
if (mWidget) {
|
|
73 |
#ifdef Q_WS_WIN
|
|
74 |
QPoint finalPosition = newPosition.toPoint();
|
|
75 |
finalPosition -= mWidget->geometry().topLeft() - mWidget->frameGeometry().topLeft();
|
|
76 |
mWidget->move(finalPosition);
|
|
77 |
#else
|
|
78 |
mWidget->move(newPosition.toPoint());
|
|
79 |
#endif
|
|
80 |
return;
|
|
81 |
}
|
|
82 |
}
|
|
83 |
|
|
84 |
/*!
|
|
85 |
\internal
|
|
86 |
Returns the global position, if container widget is a QGraphicsObject, it returns
|
|
87 |
scene position. In case the widget is QWidget it returns global co-ordinates
|
|
88 |
*/
|
|
89 |
QPointF HbVkbHostContainerWidget::pos() const
|
|
90 |
{
|
|
91 |
if (mGraphicsObject) {
|
|
92 |
if (!mTopLevelItem) {
|
|
93 |
mTopLevelItem = mGraphicsObject->topLevelItem();
|
|
94 |
}
|
|
95 |
return mTopLevelItem->pos();
|
|
96 |
}
|
|
97 |
|
|
98 |
if (mWidget) {
|
|
99 |
return mWidget->mapToGlobal(QPoint(0, 0));
|
|
100 |
}
|
|
101 |
|
|
102 |
return QPointF(0, 0);
|
|
103 |
}
|
|
104 |
|
|
105 |
/*!
|
|
106 |
\internal
|
|
107 |
Returns the bounding rect in global co-ordinate, if container widget is a QGraphicsObject
|
|
108 |
it returns in scene co-ordinate, incase widget is QWidget it returns in global co-ordinate
|
|
109 |
*/
|
|
110 |
QRectF HbVkbHostContainerWidget::sceneBoundingRect() const
|
|
111 |
{
|
|
112 |
if (mGraphicsObject) {
|
|
113 |
return mGraphicsObject->sceneBoundingRect();
|
|
114 |
}
|
|
115 |
|
|
116 |
if (mWidget) {
|
|
117 |
return QRectF(mWidget->mapToGlobal(QPoint(0, 0)), mWidget->size());
|
|
118 |
}
|
|
119 |
|
|
120 |
return QRectF(0, 0, 0, 0);
|
|
121 |
}
|
|
122 |
|
|
123 |
/*!
|
|
124 |
\internal
|
|
125 |
Connects container specific signals.
|
|
126 |
*/
|
|
127 |
void HbVkbHostContainerWidget::connectSignals(QObject *receiver)
|
|
128 |
{
|
|
129 |
if (mGraphicsObject) {
|
|
130 |
QObject::connect(mGraphicsObject, SIGNAL(yChanged()),
|
|
131 |
receiver, SLOT(ensureCursorVisibility()));
|
|
132 |
}
|
|
133 |
|
|
134 |
HbPopup *popup = qobject_cast<HbPopup *>(mGraphicsObject);
|
|
135 |
if (popup) {
|
|
136 |
QObject::connect(popup, SIGNAL(aboutToHide()), receiver, SLOT(_q_containerAboutToClose()));
|
|
137 |
}
|
|
138 |
|
|
139 |
HbView *view = qobject_cast<HbView *>(mGraphicsObject);
|
|
140 |
if (view) {
|
|
141 |
QObject::connect(view->mainWindow(), SIGNAL(currentViewChanged(HbView *)),
|
|
142 |
receiver, SLOT(_q_containerAboutToClose()));
|
|
143 |
}
|
|
144 |
}
|
|
145 |
|
|
146 |
/*!
|
|
147 |
\internal
|
|
148 |
Disconnects container specific signals.
|
|
149 |
*/
|
|
150 |
void HbVkbHostContainerWidget::disconnectSignals(QObject *receiver)
|
|
151 |
{
|
|
152 |
if (mGraphicsObject) {
|
|
153 |
QObject::disconnect(mGraphicsObject, SIGNAL(yChanged()),
|
|
154 |
receiver, SLOT(ensureCursorVisibility()));
|
|
155 |
}
|
|
156 |
|
|
157 |
HbPopup *popup = qobject_cast<HbPopup *>(mGraphicsObject);
|
|
158 |
if (popup) {
|
|
159 |
QObject::disconnect(popup, SIGNAL(aboutToHide()), receiver, SLOT(_q_containerAboutToClose()));
|
|
160 |
}
|
|
161 |
|
|
162 |
HbPopup *view = qobject_cast<HbPopup *>(mGraphicsObject);
|
|
163 |
if (view) {
|
|
164 |
QObject::disconnect(view->mainWindow(), SIGNAL(currentViewChanged(HbView *)),
|
|
165 |
receiver, SLOT(_q_containerAboutToClose()));
|
|
166 |
}
|
|
167 |
}
|
|
168 |
|
|
169 |
/*!
|
|
170 |
\internal
|
|
171 |
Returns fixed container movement vector. This vector is the minimum amount
|
|
172 |
the container always needs to be moved when the keypad opens.
|
|
173 |
In case of HbView, it is used for hiding status and title bars.
|
|
174 |
*/
|
|
175 |
QPointF HbVkbHostContainerWidget::fixedContainerMovement() const
|
|
176 |
{
|
|
177 |
// Find out if the editor is inside a view and if it is, eliminate possible
|
|
178 |
// status and title bars with suitable fixed movement vector.
|
|
179 |
HbView *view = qobject_cast<HbView*>(mGraphicsObject);
|
|
180 |
qreal yComponent = 0.0;
|
|
181 |
if (view) {
|
|
182 |
HbMainWindow *mainWindow = view->mainWindow();
|
|
183 |
if (mainWindow) {
|
|
184 |
if (view->isItemVisible(Hb::TitleBarItem)) {
|
|
185 |
yComponent += HbMainWindowPrivate::d_ptr(mainWindow)->mTitleBar->sceneBoundingRect().height();
|
|
186 |
}
|
|
187 |
if (view->isItemVisible(Hb::StatusBarItem)) {
|
|
188 |
yComponent += HbMainWindowPrivate::d_ptr(mainWindow)->mStatusBar->sceneBoundingRect().height();
|
|
189 |
}
|
|
190 |
return QPointF(0, -yComponent);
|
|
191 |
}
|
|
192 |
}
|
|
193 |
|
|
194 |
return QPointF(0, 0);
|
|
195 |
}
|
|
196 |
|
|
197 |
// End of file
|