Qt 4.8
qdirectfbwindow.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 plugins 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 "qdirectfbwindow.h"
43 #include "qdirectfbwindowsurface.h"
44 #include "qdirectfbinput.h"
45 #include "qdirectfbscreen.h"
46 
47 
48 #include <directfb.h>
49 
51 
53  : QPlatformWindow(tlw), m_inputHandler(inputhandler)
54 {
55  DFBDisplayLayerConfig layerConfig;
56  IDirectFBDisplayLayer *layer;
57 
58  layer = toDfbScreen(tlw)->dfbLayer();
59  toDfbScreen(tlw)->dfbLayer()->GetConfiguration(layer, &layerConfig);
60 
61  DFBWindowDescription description;
62  memset(&description,0,sizeof(DFBWindowDescription));
63  description.flags = DFBWindowDescriptionFlags(DWDESC_WIDTH|DWDESC_HEIGHT|DWDESC_POSX|DWDESC_POSY|DWDESC_SURFACE_CAPS
64 #if DIRECTFB_MINOR_VERSION >= 1
65  |DWDESC_OPTIONS
66 #endif
67  |DWDESC_CAPS);
68  description.width = tlw->width();
69  description.height = tlw->height();
70  description.posx = tlw->x();
71  description.posy = tlw->y();
72 
73  if (layerConfig.surface_caps & DSCAPS_PREMULTIPLIED)
74  description.surface_caps = DSCAPS_PREMULTIPLIED;
75  description.pixelformat = layerConfig.pixelformat;
76 
77 #if DIRECTFB_MINOR_VERSION >= 1
78  description.options = DFBWindowOptions(DWOP_ALPHACHANNEL);
79 #endif
80  description.caps = DFBWindowCapabilities(DWCAPS_DOUBLEBUFFER|DWCAPS_ALPHACHANNEL);
81  description.surface_caps = DSCAPS_PREMULTIPLIED;
82 
83  DFBResult result = layer->CreateWindow(layer, &description, m_dfbWindow.outPtr());
84  if (result != DFB_OK) {
85  DirectFBError("QDirectFbGraphicsSystemScreen: failed to create window",result);
86  }
87 
88  m_dfbWindow->SetOpacity(m_dfbWindow.data(), 0xff);
89 
90  setVisible(widget()->isVisible());
91 
93 }
94 
96 {
98  m_dfbWindow->Destroy(m_dfbWindow.data());
99 }
100 
102 {
103  bool isMoveOnly = (rect.topLeft() != geometry().topLeft()) && (rect.size() == geometry().size());
104 
106  if (widget()->isVisible() && !(widget()->testAttribute(Qt::WA_DontShowOnScreen))) {
107  m_dfbWindow->SetBounds(m_dfbWindow.data(), rect.x(),rect.y(),
108  rect.width(), rect.height());
109  //Hack. When moving since the WindowSurface of a window becomes invalid when moved
110  if (isMoveOnly) { //if resize then windowsurface is updated.
111  widget()->windowSurface()->resize(rect.size());
112  widget()->update();
113  }
114  }
115 }
116 
118 {
119  const quint8 windowOpacity = quint8(level * 0xff);
120  m_dfbWindow->SetOpacity(m_dfbWindow.data(), windowOpacity);
121 }
122 
123 void QDirectFbWindow::setVisible(bool visible)
124 {
125  if (visible) {
126  int x = geometry().x();
127  int y = geometry().y();
128  m_dfbWindow->MoveTo(m_dfbWindow.data(), x, y);
129  } else {
131  QDirectFbConvenience::dfbInterface()->GetDisplayLayer(QDirectFbConvenience::dfbInterface(), DLID_PRIMARY, displayLayer.outPtr());
132 
133  DFBDisplayLayerConfig config;
134  displayLayer->GetConfiguration(displayLayer.data(), &config);
135  m_dfbWindow->MoveTo(m_dfbWindow.data(), config. width + 1, config.height + 1);
136  }
137 }
138 
139 Qt::WindowFlags QDirectFbWindow::setWindowFlags(Qt::WindowFlags flags)
140 {
141  switch (flags & Qt::WindowType_Mask) {
142  case Qt::ToolTip: {
143  DFBWindowOptions options;
144  m_dfbWindow->GetOptions(m_dfbWindow.data(), &options);
145  options = DFBWindowOptions(options | DWOP_GHOST);
146  m_dfbWindow->SetOptions(m_dfbWindow.data(), options);
147  break; }
148  default:
149  break;
150  }
151 
152  m_dfbWindow->SetStackingClass(m_dfbWindow.data(), flags & Qt::WindowStaysOnTopHint ? DWSC_UPPER : DWSC_MIDDLE);
153  return flags;
154 }
155 
157 {
158  m_dfbWindow->RaiseToTop(m_dfbWindow.data());
159 }
160 
162 {
163  m_dfbWindow->LowerToBottom(m_dfbWindow.data());
164 }
165 
167 {
168  DFBWindowID id;
169  m_dfbWindow->GetID(m_dfbWindow.data(), &id);
170  return WId(id);
171 }
172 
174 {
175  DFBResult res;
176 
177  if (grab)
178  res = m_dfbWindow->GrabKeyboard(m_dfbWindow.data());
179  else
180  res = m_dfbWindow->UngrabKeyboard(m_dfbWindow.data());
181 
182  return res == DFB_OK;
183 }
184 
186 {
187  DFBResult res;
188 
189  if (grab)
190  res = m_dfbWindow->GrabPointer(m_dfbWindow.data());
191  else
192  res = m_dfbWindow->UngrabPointer(m_dfbWindow.data());
193 
194  return res == DFB_OK;
195 }
196 
197 IDirectFBWindow *QDirectFbWindow::dfbWindow() const
198 {
199  return m_dfbWindow.data();
200 }
201 
202 IDirectFBSurface *QDirectFbWindow::dfbSurface()
203 {
204  if (!m_dfbSurface) {
205  DFBResult res = m_dfbWindow->GetSurface(m_dfbWindow.data(), m_dfbSurface.outPtr());
206  if (res != DFB_OK)
207  DirectFBError(QDFB_PRETTY, res);
208  }
209 
210  return m_dfbSurface.data();
211 }
212 
Qt::WindowFlags setWindowFlags(Qt::WindowFlags flags)
Requests setting the window flags of this surface to type.
void setOpacity(qreal level)
Reimplement to be able to let Qt set the opacity level of a window.
unsigned long WId
Definition: qwindowdefs.h:119
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
T * data() const
Returns the value of the pointer referenced by this object.
virtual void setGeometry(const QRect &rect)
This function is called by Qt whenever a window is moved or the window is resized.
virtual QRect geometry() const
Returnes the current geometry of a window.
void setGeometry(const QRect &rect)
This function is called by Qt whenever a window is moved or the window is resized.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
unsigned char quint8
Definition: qglobal.h:934
#define QDFB_PRETTY
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
The QPlatformWindow class provides an abstraction for top-level windows.
int x
the x coordinate of the widget relative to its parent including any window frame
Definition: qwidget.h:161
QDirectFbScreen * toDfbScreen(QWidget *window)
QDirectFbWindow(QWidget *tlw, QDirectFbInput *inputhandler)
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
IDirectFBSurface * dfbSurface()
QDirectFBPointer< IDirectFBWindow > m_dfbWindow
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
IDirectFBWindow * dfbWindow() const
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
void addWindow(IDirectFBWindow *window, QWidget *platformWindow)
QWindowSurface * windowSurface() const
Returns the QWindowSurface this widget will be drawn into.
Definition: qwidget.cpp:12819
QDirectFBPointer< IDirectFBSurface > m_dfbSurface
IDirectFBDisplayLayer * dfbLayer() const
bool setMouseGrabEnabled(bool grab)
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int y
the y coordinate of the widget relative to its parent and including any window frame ...
Definition: qwidget.h:162
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
void raise()
Reimplement to be able to let Qt rais windows to the top of the desktop.
void lower()
Reimplement to be able to let Qt lower windows to the bottom of the desktop.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QDirectFbInput * m_inputHandler
static IDirectFB * dfbInterface()
bool setKeyboardGrabEnabled(bool grab)
WId winId() const
Reimplement in subclasses to return a handle to the native window.
void removeWindow(IDirectFBWindow *window)
void setVisible(bool visible)
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false...
QWidget * widget() const
Returnes the widget which belongs to the QPlatformWindow.
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288