1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #include "qwsembedwidget.h"
44 #ifndef QT_NO_QWSEMBEDWIDGET
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>
54 // Must remove window decorations from the embedded window
55 // Focus In/Out, Keyboard/Mouse...
57 // BUG: what if my parent change parent?
59 class QWSEmbedWidgetPrivate : public QWidgetPrivate
61 Q_DECLARE_PUBLIC(QWSEmbedWidget);
64 QWSEmbedWidgetPrivate(int winId);
66 void resize(const QSize &size);
73 QWSEmbedWidgetPrivate::QWSEmbedWidgetPrivate(int winId)
74 : window(0), windowId(0), embeddedId(winId)
78 void QWSEmbedWidgetPrivate::updateWindow()
82 QWidget *win = q->window();
87 window->removeEventFilter(q);
88 QWSEmbedCommand command;
89 command.setData(windowId, embeddedId, QWSEmbedEvent::StopEmbed);
90 QWSDisplay::instance()->d->sendCommand(command);
96 windowId = window->winId();
98 QWSEmbedCommand command;
99 command.setData(windowId, embeddedId, QWSEmbedEvent::StartEmbed);
100 QWSDisplay::instance()->d->sendCommand(command);
101 window->installEventFilter(q);
102 q->installEventFilter(q);
105 void QWSEmbedWidgetPrivate::resize(const QSize &size)
112 QWSEmbedCommand command;
113 command.setData(windowId, embeddedId, QWSEmbedEvent::Region,
114 QRect(q->mapToGlobal(QPoint(0, 0)), size));
115 QWSDisplay::instance()->d->sendCommand(command);
119 \class QWSEmbedWidget
124 \brief The QWSEmbedWidget class enables embedded top-level widgets
125 in Qt for Embedded Linux.
127 Note that this class is only available in \l{Qt for Embedded Linux}.
129 QWSEmbedWidget inherits QWidget and acts as any other widget, but
130 in addition it is capable of embedding another top-level widget.
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.
137 All that is required to embed a top-level widget is its window ID.
139 \sa {Qt for Embedded Linux Architecture}
143 Constructs a widget with the given \a parent, embedding the widget
144 identified by the given window \a id.
146 QWSEmbedWidget::QWSEmbedWidget(WId id, QWidget *parent)
147 : QWidget(*new QWSEmbedWidgetPrivate(id), parent, 0)
154 Destroys this widget.
156 QWSEmbedWidget::~QWSEmbedWidget()
162 QWSEmbedCommand command;
163 command.setData(d->windowId, d->embeddedId, QWSEmbedEvent::StopEmbed);
164 QWSDisplay::instance()->d->sendCommand(command);
170 bool QWSEmbedWidget::eventFilter(QObject *object, QEvent *event)
173 if (object == d->window && event->type() == QEvent::Move)
175 else if (object == this && event->type() == QEvent::Hide)
177 return QWidget::eventFilter(object, event);
183 void QWSEmbedWidget::changeEvent(QEvent *event)
186 if (event->type() == QEvent::ParentChange)
193 void QWSEmbedWidget::resizeEvent(QResizeEvent*)
196 d->resize(rect().size());
202 void QWSEmbedWidget::moveEvent(QMoveEvent*)
210 void QWSEmbedWidget::hideEvent(QHideEvent*)
219 void QWSEmbedWidget::showEvent(QShowEvent*)
222 d->resize(rect().size());
227 #endif // QT_NO_QWSEMBEDWIDGET