source: trunk/src/gui/embedded/qwsembedwidget.cpp@ 1054

Last change on this file since 1054 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 5.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation (qt-info@nokia.com)
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at qt-info@nokia.com.
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qwsembedwidget.h"
43
44#ifndef QT_NO_QWSEMBEDWIDGET
45
46#include <qwsdisplay_qws.h>
47#include <private/qwidget_p.h>
48#include <private/qwsdisplay_qws_p.h>
49#include <private/qwscommand_qws_p.h>
50
51QT_BEGIN_NAMESPACE
52
53// TODO:
54// Must remove window decorations from the embedded window
55// Focus In/Out, Keyboard/Mouse...
56//
57// BUG: what if my parent change parent?
58
59class QWSEmbedWidgetPrivate : public QWidgetPrivate
60{
61 Q_DECLARE_PUBLIC(QWSEmbedWidget);
62
63public:
64 QWSEmbedWidgetPrivate(int winId);
65 void updateWindow();
66 void resize(const QSize &size);
67
68 QWidget *window;
69 WId windowId;
70 WId embeddedId;
71};
72
73QWSEmbedWidgetPrivate::QWSEmbedWidgetPrivate(int winId)
74 : window(0), windowId(0), embeddedId(winId)
75{
76}
77
78void QWSEmbedWidgetPrivate::updateWindow()
79{
80 Q_Q(QWSEmbedWidget);
81
82 QWidget *win = q->window();
83 if (win == window)
84 return;
85
86 if (window) {
87 window->removeEventFilter(q);
88 QWSEmbedCommand command;
89 command.setData(windowId, embeddedId, QWSEmbedEvent::StopEmbed);
90 QWSDisplay::instance()->d->sendCommand(command);
91 }
92
93 window = win;
94 if (!window)
95 return;
96 windowId = window->winId();
97
98 QWSEmbedCommand command;
99 command.setData(windowId, embeddedId, QWSEmbedEvent::StartEmbed);
100 QWSDisplay::instance()->d->sendCommand(command);
101 window->installEventFilter(q);
102 q->installEventFilter(q);
103}
104
105void QWSEmbedWidgetPrivate::resize(const QSize &size)
106{
107 if (!window)
108 return;
109
110 Q_Q(QWSEmbedWidget);
111
112 QWSEmbedCommand command;
113 command.setData(windowId, embeddedId, QWSEmbedEvent::Region,
114 QRect(q->mapToGlobal(QPoint(0, 0)), size));
115 QWSDisplay::instance()->d->sendCommand(command);
116}
117
118/*!
119 \class QWSEmbedWidget
120 \since 4.2
121 \ingroup qws
122 \ingroup advanced
123
124 \brief The QWSEmbedWidget class enables embedded top-level widgets
125 in Qt for Embedded Linux.
126
127 Note that this class is only available in \l{Qt for Embedded Linux}.
128
129 QWSEmbedWidget inherits QWidget and acts as any other widget, but
130 in addition it is capable of embedding another top-level widget.
131
132 An example of use is when painting directly onto the screen using
133 the QDirectPainter class. Then the reserved region can be embedded
134 into an instance of the QWSEmbedWidget class, providing for
135 example event handling and size policies for the reserved region.
136
137 All that is required to embed a top-level widget is its window ID.
138
139 \sa {Qt for Embedded Linux Architecture}
140*/
141
142/*!
143 Constructs a widget with the given \a parent, embedding the widget
144 identified by the given window \a id.
145*/
146QWSEmbedWidget::QWSEmbedWidget(WId id, QWidget *parent)
147 : QWidget(*new QWSEmbedWidgetPrivate(id), parent, 0)
148{
149 Q_D(QWSEmbedWidget);
150 d->updateWindow();
151}
152
153/*!
154 Destroys this widget.
155*/
156QWSEmbedWidget::~QWSEmbedWidget()
157{
158 Q_D(QWSEmbedWidget);
159 if (!d->window)
160 return;
161
162 QWSEmbedCommand command;
163 command.setData(d->windowId, d->embeddedId, QWSEmbedEvent::StopEmbed);
164 QWSDisplay::instance()->d->sendCommand(command);
165}
166
167/*!
168 \reimp
169*/
170bool QWSEmbedWidget::eventFilter(QObject *object, QEvent *event)
171{
172 Q_D(QWSEmbedWidget);
173 if (object == d->window && event->type() == QEvent::Move)
174 resizeEvent(0);
175 else if (object == this && event->type() == QEvent::Hide)
176 d->resize(QSize());
177 return QWidget::eventFilter(object, event);
178}
179
180/*!
181 \reimp
182*/
183void QWSEmbedWidget::changeEvent(QEvent *event)
184{
185 Q_D(QWSEmbedWidget);
186 if (event->type() == QEvent::ParentChange)
187 d->updateWindow();
188}
189
190/*!
191 \reimp
192*/
193void QWSEmbedWidget::resizeEvent(QResizeEvent*)
194{
195 Q_D(QWSEmbedWidget);
196 d->resize(rect().size());
197}
198
199/*!
200 \reimp
201*/
202void QWSEmbedWidget::moveEvent(QMoveEvent*)
203{
204 resizeEvent(0);
205}
206
207/*!
208 \reimp
209*/
210void QWSEmbedWidget::hideEvent(QHideEvent*)
211{
212 Q_D(QWSEmbedWidget);
213 d->resize(QSize());
214}
215
216/*!
217 \reimp
218*/
219void QWSEmbedWidget::showEvent(QShowEvent*)
220{
221 Q_D(QWSEmbedWidget);
222 d->resize(rect().size());
223}
224
225QT_END_NAMESPACE
226
227#endif // QT_NO_QWSEMBEDWIDGET
Note: See TracBrowser for help on using the repository browser.