Qt 4.8
Public Functions | Properties | List of all members
QOpenKODEWindow Class Reference

#include <qopenkodewindow.h>

Inheritance diagram for QOpenKODEWindow:
QPlatformWindow

Public Functions

QPlatformGLContextglContext () const
 Reimplement to return the glContext associated with the window. More...
 
void lower ()
 Reimplement to be able to let Qt lower windows to the bottom of the desktop. More...
 
void processKeyEvents (const KDEvent *event)
 
void processMouseEvents (const KDEvent *event)
 
 QOpenKODEWindow (QWidget *tlw)
 
void raise ()
 Reimplement to be able to let Qt rais windows to the top of the desktop. More...
 
void setGeometry (const QRect &rect)
 This function is called by Qt whenever a window is moved or the window is resized. More...
 
void setVisible (bool visible)
 Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false. More...
 
WId winId () const
 Reimplement in subclasses to return a handle to the native window. More...
 
 ~QOpenKODEWindow ()
 
- Public Functions inherited from QPlatformWindow
virtual QRect geometry () const
 Returnes the current geometry of a window. More...
 
 QPlatformWindow (QWidget *tlw)
 Constructs a platform window with the given top level widget. More...
 
virtual void requestActivateWindow ()
 Reimplement to let Qt be able to request activation/focus for a window. More...
 
virtual void setOpacity (qreal level)
 Reimplement to be able to let Qt set the opacity level of a window. More...
 
virtual void setParent (const QPlatformWindow *window)
 This function is called to enable native child widgets in QPA. More...
 
virtual Qt::WindowFlags setWindowFlags (Qt::WindowFlags flags)
 Requests setting the window flags of this surface to type. More...
 
virtual void setWindowTitle (const QString &title)
 Reimplement to set the window title to title. More...
 
QWidgetwidget () const
 Returnes the widget which belongs to the QPlatformWindow. More...
 
virtual Qt::WindowFlags windowFlags () const
 Returns the effective window flags for this surface. More...
 
virtual ~QPlatformWindow ()
 Virtual destructor does not delete its top level widget. More...
 

Properties

bool isFullScreen
 
EGLenum m_eglApi
 
EGLConfig m_eglConfig
 
QVector< EGLint > m_eglContextAttrs
 
EGLNativeWindowType m_eglWindow
 
QVector< EGLint > m_eglWindowAttrs
 
struct KDWindow * m_kdWindow
 
QEGLPlatformContextm_platformGlContext
 

Additional Inherited Members

- Protected Variables inherited from QPlatformWindow
QScopedPointer< QPlatformWindowPrivated_ptr
 

Detailed Description

Definition at line 56 of file qopenkodewindow.h.

Constructors and Destructors

◆ QOpenKODEWindow()

QOpenKODEWindow::QOpenKODEWindow ( QWidget tlw)

Definition at line 79 of file qopenkodewindow.cpp.

80  : QPlatformWindow(tlw), isFullScreen(false)
81 {
82  if (tlw->platformWindowFormat().windowApi() == QPlatformWindowFormat::OpenVG) {
83  m_eglApi = EGL_OPENVG_API;
84  } else {
85  m_eglContextAttrs.append(EGL_CONTEXT_CLIENT_VERSION);
87 
88  m_eglApi = EGL_OPENGL_ES_API;
89  }
90  eglBindAPI(m_eglApi);
91 
92  m_eglContextAttrs.append(EGL_NONE);
93  m_eglWindowAttrs.append(EGL_NONE);
94 
95  QList<QPlatformScreen *> screens = QApplicationPrivate::platformIntegration()->screens();
96  //XXXX: jl figure out how to pick the correct screen.
97 // Q_ASSERT(screens.size() > tlw->d_func()->screenNumber);
98 // QOpenKODEScreen *screen = qobject_cast<QOpenKODEScreen *>(screens.at(tlw->d_func()->screenNumber));
99  QOpenKODEScreen *screen = qobject_cast<QOpenKODEScreen *>(screens.at(0));
100  if (!screen) {
101  qErrnoWarning("Could not make QOpenKODEWindow without a screen");
102  }
103 
104  QPlatformWindowFormat format = tlw->platformWindowFormat();
105  format.setRedBufferSize(5);
106  format.setGreenBufferSize(6);
107  format.setBlueBufferSize(5);
108 
110 
111  m_kdWindow = kdCreateWindow(screen->eglDisplay(),
112  m_eglConfig,
113  this);
114  kdInstallCallback(kdProcessMouseEvents,KD_EVENT_INPUT_POINTER,this);
115 #ifdef KD_ATX_keyboard
116  kdInstallCallback(kdProcessKeyEvents, KD_EVENT_INPUT_KEY_ATX,this);
117 #endif //KD_ATX_keyboard
118 
119  if (!m_kdWindow) {
120  qErrnoWarning(kdGetError(), "Error creating native window");
121  return;
122  }
123 
124  KDboolean exclusive(false);
125  if (kdSetWindowPropertybv(m_kdWindow,KD_WINDOWPROPERTY_DESKTOP_EXCLUSIVE_NV, &exclusive)) {
126  isFullScreen = true;
127  }
128 
129  if (isFullScreen) {
130  tlw->setGeometry(screen->geometry());
131  screen->setFullScreen(isFullScreen);
132  }else {
133  const KDint windowSize[2] = { tlw->width(), tlw->height() };
134  if (kdSetWindowPropertyiv(m_kdWindow, KD_WINDOWPROPERTY_SIZE, windowSize)) {
135  qErrnoWarning(kdGetError(), "Could not set native window size");
136  }
137  KDboolean visibillity(false);
138  if (kdSetWindowPropertybv(m_kdWindow, KD_WINDOWPROPERTY_VISIBILITY, &visibillity)) {
139  qErrnoWarning(kdGetError(), "Could not set visibillity to false");
140  }
141 
142  const KDint windowPos[2] = { tlw->x(), tlw->y() };
143  if (kdSetWindowPropertyiv(m_kdWindow, KD_WINDOWPROPERTY_DESKTOP_OFFSET_NV, windowPos)) {
144  qErrnoWarning(kdGetError(), "Could not set native window position");
145  return;
146  }
147  }
148 
149 
150  QOpenKODEIntegration *integration = static_cast<QOpenKODEIntegration *>(QApplicationPrivate::platformIntegration());
151 
152  if (!isFullScreen || (isFullScreen && !integration->mainGLContext())) {
153  if (kdRealizeWindow(m_kdWindow, &m_eglWindow)) {
154  qErrnoWarning(kdGetError(), "Could not realize native window");
155  return;
156  }
157 
158  EGLSurface surface = eglCreateWindowSurface(screen->eglDisplay(),m_eglConfig,m_eglWindow,m_eglWindowAttrs.constData());
160  m_eglContextAttrs.data(), surface, m_eglApi);
161  integration->setMainGLContext(m_platformGLContext);
162  } else {
163  m_platformGlContext = integration->mainGLContext();
164  kdDestroyWindow(m_kdWindow);
165  m_kdWindow = 0;
166  }
167 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
EGLConfig m_eglConfig
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
EGLConfig q_configFromQPlatformWindowFormat(EGLDisplay display, const QPlatformWindowFormat &format, bool highestPixelFormat, int surfaceType)
The QPlatformWindowFormat class specifies the display format of an OpenGL rendering context and if po...
EGLNativeWindowType m_eglWindow
void setBlueBufferSize(int size)
Set the preferred blue buffer size to size.
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qwidget.h:1017
int x
the x coordinate of the widget relative to its parent including any window frame
Definition: qwidget.h:161
QPlatformWindow(QWidget *tlw)
Constructs a platform window with the given top level widget.
QRect geometry() const
Reimplement in subclass to return the pixel geometry of the screen.
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
void setMainGLContext(QEGLPlatformContext *ctx)
struct KDWindow * m_kdWindow
int y
the y coordinate of the widget relative to its parent and including any window frame ...
Definition: qwidget.h:162
QVector< EGLint > m_eglContextAttrs
void setRedBufferSize(int size)
Set the preferred red buffer size to size.
QVector< EGLint > m_eglWindowAttrs
void kdProcessMouseEvents(const KDEvent *event)
T * data()
Returns a pointer to the data stored in the vector.
Definition: qvector.h:152
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154
void setFullScreen(bool fullscreen)
void setGreenBufferSize(int size)
Set the preferred green buffer size to size.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
QEGLPlatformContext * m_platformGlContext
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954
EGLDisplay eglDisplay()

◆ ~QOpenKODEWindow()

QOpenKODEWindow::~QOpenKODEWindow ( )

Definition at line 170 of file qopenkodewindow.cpp.

171 {
172  if (m_platformGlContext != static_cast<QOpenKODEIntegration *>(QApplicationPrivate::platformIntegration())) {
173  delete m_platformGlContext;
174  }
175  if (m_kdWindow)
176  kdDestroyWindow(m_kdWindow);
177 }
struct KDWindow * m_kdWindow
QEGLPlatformContext * m_platformGlContext

Functions

◆ glContext()

QPlatformGLContext * QOpenKODEWindow::glContext ( ) const
virtual

Reimplement to return the glContext associated with the window.

Reimplemented from QPlatformWindow.

Definition at line 238 of file qopenkodewindow.cpp.

239 {
240  return m_platformGlContext;
241 }
QEGLPlatformContext * m_platformGlContext

◆ lower()

void QOpenKODEWindow::lower ( )
virtual

Reimplement to be able to let Qt lower windows to the bottom of the desktop.

Reimplemented from QPlatformWindow.

Definition at line 253 of file qopenkodewindow.cpp.

254 {
255  if (!m_kdWindow)
256  return;
257  KDboolean focus(false);
258  if (kdSetWindowPropertybv(m_kdWindow, KD_WINDOWPROPERTY_FOCUS, &focus)) {
259  qErrnoWarning(kdGetError(), "Could not set focus");
260  }
261 }
struct KDWindow * m_kdWindow
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ processKeyEvents()

void QOpenKODEWindow::processKeyEvents ( const KDEvent *  event)

Definition at line 279 of file qopenkodewindow.cpp.

Referenced by kdProcessMouseEvents().

280 {
281 #ifdef KD_ATX_keyboard
282  //KD_KEY_PRESS_ATX 1
283  QEvent::Type keyPressed = QEvent::KeyRelease;
284  if (event->data.keyboardInputKey.flags)
285  keyPressed = QEvent::KeyPress;
286 //KD_KEY_LOCATION_LEFT_ATX // don't care for now
287 //KD_KEY_LOCATION_RIGHT_ATX
288 //KD_KEY_LOCATION_NUMPAD_ATX
289  Qt::KeyboardModifiers mod = Qt::NoModifier;
290  int openkodeMods = event->data.keyboardInputKey.flags;
291  if (openkodeMods & KD_KEY_MODIFIER_SHIFT_ATX)
292  mod |= Qt::ShiftModifier;
293  if (openkodeMods & KD_KEY_MODIFIER_CTRL_ATX)
294  mod |= Qt::ControlModifier;
295  if (openkodeMods & KD_KEY_MODIFIER_ALT_ATX)
296  mod |= Qt::AltModifier;
297  if (openkodeMods & KD_KEY_MODIFIER_META_ATX)
298  mod |= Qt::MetaModifier;
299 
300  Qt::Key qtKey;
301  QChar keyText;
302  int key = event->data.keyboardInputKey.keycode;
303  if (key >= 0x20 && key <= 0x0ff){ // 8 bit printable Latin1
304  qtKey = Qt::Key(key);
305  keyText = QChar(event->data.keyboardInputKeyChar.character);
306  if (!(mod & Qt::ShiftModifier))
307  keyText = keyText.toLower();
308  } else {
309  qtKey = keyTranslator(key);
310  }
311  QWindowSystemInterface::handleKeyEvent(0,event->timestamp,keyPressed,qtKey,mod,keyText);
312 #endif
313 }
EventRef event
static void handleKeyEvent(QWidget *w, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString &text=QString(), bool autorep=false, ushort count=1)
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
Qt::Key keyTranslator(int key)
Type
This enum type defines the valid event types in Qt.
Definition: qcoreevent.h:62
int key
static QString qtKey(CFStringRef cfkey)
QChar toLower() const
Returns the lowercase equivalent if the character is uppercase or titlecase; otherwise returns the ch...
Definition: qchar.cpp:1239

◆ processMouseEvents()

void QOpenKODEWindow::processMouseEvents ( const KDEvent *  event)

Definition at line 263 of file qopenkodewindow.cpp.

Referenced by kdProcessMouseEvents().

264 {
265  int x = event->data.inputpointer.x;
266  int y = event->data.inputpointer.y;
267  Qt::MouseButtons buttons;
268  switch(event->data.inputpointer.select) {
269  case 1:
270  buttons = Qt::LeftButton;
271  break;
272  default:
273  buttons = Qt::NoButton;
274  }
275  QPoint pos(x,y);
276  QWindowSystemInterface::handleMouseEvent(0,event->timestamp,pos,pos,buttons);
277 }
EventRef event
static Qt::MouseButtons buttons
static void handleMouseEvent(QWidget *w, const QPoint &local, const QPoint &global, Qt::MouseButtons b)
tlw == 0 means that ev is in global coords only
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53

◆ raise()

void QOpenKODEWindow::raise ( )
virtual

Reimplement to be able to let Qt rais windows to the top of the desktop.

Reimplemented from QPlatformWindow.

Definition at line 243 of file qopenkodewindow.cpp.

244 {
245  if (!m_kdWindow)
246  return;
247  KDboolean focus(true);
248  if (kdSetWindowPropertybv(m_kdWindow, KD_WINDOWPROPERTY_FOCUS, &focus)) {
249  qErrnoWarning(kdGetError(), "Could not set focus");
250  }
251 }
struct KDWindow * m_kdWindow
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ setGeometry()

void QOpenKODEWindow::setGeometry ( const QRect rect)
virtual

This function is called by Qt whenever a window is moved or the window is resized.

The resize can happen programatically(from ie. user application) or by the window manager. This means that there is no need to call this function specifically from the window manager callback, instead call QWindowSystemInterface::handleGeometryChange(QWidget *w, const QRect &newRect);

Reimplemented from QPlatformWindow.

Definition at line 178 of file qopenkodewindow.cpp.

179 {
180  if (isFullScreen) {
181  QList<QPlatformScreen *> screens = QApplicationPrivate::platformIntegration()->screens();
182  QOpenKODEScreen *screen = qobject_cast<QOpenKODEScreen *>(screens.at(0));
183  widget()->setGeometry(screen->geometry());
184  return;
185  }
186  bool needToDeleteContext = false;
187  if (!isFullScreen) {
188  const QRect geo = geometry();
189  if (geo.size() != rect.size()) {
190  const KDint windowSize[2] = { rect.width(), rect.height() };
191  if (kdSetWindowPropertyiv(m_kdWindow, KD_WINDOWPROPERTY_SIZE, windowSize)) {
192  qErrnoWarning(kdGetError(), "Could not set native window size");
193  //return;
194  } else {
195  needToDeleteContext = true;
196  }
197  }
198 
199  if (geo.topLeft() != rect.topLeft()) {
200  const KDint windowPos[2] = { rect.x(), rect.y() };
201  if (kdSetWindowPropertyiv(m_kdWindow, KD_WINDOWPROPERTY_DESKTOP_OFFSET_NV, windowPos)) {
202  qErrnoWarning(kdGetError(), "Could not set native window position");
203  //return;
204  } else {
205  needToDeleteContext = true;
206  }
207  }
208  }
209 
210  //need to recreate context
211  if (needToDeleteContext) {
212  delete m_platformGlContext;
213 
214  QList<QPlatformScreen *> screens = QApplicationPrivate::platformIntegration()->screens();
215  QOpenKODEScreen *screen = qobject_cast<QOpenKODEScreen *>(screens.at(0));
216  EGLSurface surface = eglCreateWindowSurface(screen->eglDisplay(),m_eglConfig,m_eglWindow,m_eglWindowAttrs.constData());
218  m_eglContextAttrs.data(),surface,m_eglApi);
219  }
220 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
EGLConfig m_eglConfig
virtual QRect geometry() const
Returnes the current geometry of a window.
EGLNativeWindowType m_eglWindow
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qwidget.h:1017
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QRect geometry() const
Reimplement in subclass to return the pixel geometry of the screen.
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
struct KDWindow * m_kdWindow
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QVector< EGLint > m_eglContextAttrs
QVector< EGLint > m_eglWindowAttrs
T * data()
Returns a pointer to the data stored in the vector.
Definition: qvector.h:152
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
QEGLPlatformContext * m_platformGlContext
QWidget * widget() const
Returnes the widget which belongs to the QPlatformWindow.
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
EGLDisplay eglDisplay()

◆ setVisible()

void QOpenKODEWindow::setVisible ( bool  visible)
virtual

Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false.

Reimplemented from QPlatformWindow.

Definition at line 222 of file qopenkodewindow.cpp.

223 {
224  if (!m_kdWindow)
225  return;
226  KDboolean visibillity(visible);
227  if (kdSetWindowPropertybv(m_kdWindow, KD_WINDOWPROPERTY_VISIBILITY, &visibillity)) {
228  qErrnoWarning(kdGetError(), "Could not set visibillity property");
229  }
230 }
struct KDWindow * m_kdWindow
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ winId()

WId QOpenKODEWindow::winId ( ) const
virtual

Reimplement in subclasses to return a handle to the native window.

Reimplemented from QPlatformWindow.

Definition at line 232 of file qopenkodewindow.cpp.

233 {
234  static int i = 0;
235  return i++;
236 }

Properties

◆ isFullScreen

bool QOpenKODEWindow::isFullScreen
private

Definition at line 83 of file qopenkodewindow.h.

Referenced by QOpenKODEWindow(), and setGeometry().

◆ m_eglApi

EGLenum QOpenKODEWindow::m_eglApi
private

Definition at line 80 of file qopenkodewindow.h.

Referenced by QOpenKODEWindow(), and setGeometry().

◆ m_eglConfig

EGLConfig QOpenKODEWindow::m_eglConfig
private

Definition at line 77 of file qopenkodewindow.h.

Referenced by QOpenKODEWindow(), and setGeometry().

◆ m_eglContextAttrs

QVector<EGLint> QOpenKODEWindow::m_eglContextAttrs
private

Definition at line 79 of file qopenkodewindow.h.

Referenced by QOpenKODEWindow(), and setGeometry().

◆ m_eglWindow

EGLNativeWindowType QOpenKODEWindow::m_eglWindow
private

Definition at line 76 of file qopenkodewindow.h.

Referenced by QOpenKODEWindow(), and setGeometry().

◆ m_eglWindowAttrs

QVector<EGLint> QOpenKODEWindow::m_eglWindowAttrs
private

Definition at line 78 of file qopenkodewindow.h.

Referenced by QOpenKODEWindow(), and setGeometry().

◆ m_kdWindow

struct KDWindow* QOpenKODEWindow::m_kdWindow
private

◆ m_platformGlContext

QEGLPlatformContext* QOpenKODEWindow::m_platformGlContext
private

Definition at line 81 of file qopenkodewindow.h.

Referenced by glContext(), QOpenKODEWindow(), setGeometry(), and ~QOpenKODEWindow().


The documentation for this class was generated from the following files: