Qt 4.8
qwsembedwidget.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
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 
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 
60 {
62 
63 public:
64  QWSEmbedWidgetPrivate(int winId);
65  void updateWindow();
66  void resize(const QSize &size);
67 
71 };
72 
74  : window(0), windowId(0), embeddedId(winId)
75 {
76 }
77 
79 {
81 
82  QWidget *win = q->window();
83  if (win == window)
84  return;
85 
86  if (window) {
88  QWSEmbedCommand command;
90  QWSDisplay::instance()->d->sendCommand(command);
91  }
92 
93  window = win;
94  if (!window)
95  return;
96  windowId = window->winId();
97 
98  QWSEmbedCommand command;
100  QWSDisplay::instance()->d->sendCommand(command);
102  q->installEventFilter(q);
103 }
104 
106 {
107  if (!window)
108  return;
109 
111 
112  QWSEmbedCommand command;
114  QRect(q->mapToGlobal(QPoint(0, 0)), size));
115  QWSDisplay::instance()->d->sendCommand(command);
116 }
117 
150  : QWidget(*new QWSEmbedWidgetPrivate(id), parent, 0)
151 {
153  d->updateWindow();
154 }
155 
160 {
162  if (!d->window)
163  return;
164 
165  QWSEmbedCommand command;
166  command.setData(d->windowId, d->embeddedId, QWSEmbedEvent::StopEmbed);
167  QWSDisplay::instance()->d->sendCommand(command);
168 }
169 
174 {
176  if (object == d->window && event->type() == QEvent::Move)
177  resizeEvent(0);
178  else if (object == this && event->type() == QEvent::Hide)
179  d->resize(QSize());
180  return QWidget::eventFilter(object, event);
181 }
182 
187 {
189  if (event->type() == QEvent::ParentChange)
190  d->updateWindow();
191 }
192 
197 {
199  d->resize(rect().size());
200 }
201 
206 {
207  resizeEvent(0);
208 }
209 
214 {
216  d->resize(QSize());
217 }
218 
223 {
225  d->resize(rect().size());
226 }
227 
229 
230 #endif // QT_NO_QWSEMBEDWIDGET
double d
Definition: qnumeric_p.h:62
unsigned long WId
Definition: qwindowdefs.h:119
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QSize size() const
Q_DECLARE_PUBLIC(QWSEmbedWidget)
bool eventFilter(QObject *object, QEvent *event)
Reimplemented Function
void removeEventFilter(QObject *)
Removes an event filter object obj from this object.
Definition: qobject.cpp:2099
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
~QWSEmbedWidget()
Destroys this widget.
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
#define Q_Q(Class)
Definition: qglobal.h:2483
void sendCommand(QWSCommand &cmd)
The QWSEmbedWidget class enables embedded top-level widgets in Qt for Embedded Linux.
void hideEvent(QHideEvent *event)
Reimplemented Function
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QMoveEvent class contains event parameters for move events.
Definition: qevent.h:334
void resize(const QSize &size)
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition: qevent.h:388
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:380
QWSEmbedWidget(WId winId, QWidget *parent=0)
Constructs a widget with the given parent, embedding the widget identified by the given window id...
void showEvent(QShowEvent *event)
Reimplemented Function
QRect rect() const
virtual bool eventFilter(QObject *, QEvent *)
Filters events if this object has been installed as an event filter for the watched object...
Definition: qobject.cpp:1375
void setData(const char *d, int len, bool allocateMem=true)
void moveEvent(QMoveEvent *event)
Reimplemented Function
void resizeEvent(QResizeEvent *event)
Reimplemented Function
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void installEventFilter(QObject *)
Installs an event filter filterObj on this object.
Definition: qobject.cpp:2070
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
QObject * parent
Definition: qobject.h:92
void changeEvent(QEvent *event)
Reimplemented Function
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
WId winId() const
Returns the window system identifier of the widget.
Definition: qwidget.cpp:2557
static QWSDisplay * instance()
QWSEmbedWidgetPrivate(int winId)
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303