Qt 4.8
qdirectfbconvenience.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 "qdirectfbconvenience.h"
43 #include "qdirectfbblitter.h"
44 #include "qdirectfbscreen.h"
45 
46 #include <private/qpixmap_blitter_p.h>
47 
48 #include <QtGui/QWidget>
49 #include <QtGui/QScreen>
50 
52 
54 {
55  static IDirectFB *dfb = 0;
56  if (!dfb) {
57  DFBResult result = DirectFBCreate(&dfb);
58  if (result != DFB_OK) {
59  DirectFBErrorFatal("QDirectFBConvenience: error creating DirectFB interface", result);
60  return 0;
61  }
62  }
63  return dfb;
64 }
65 
67 {
68  IDirectFBDisplayLayer *layer;
69  DFBResult result = QDirectFbConvenience::dfbInterface()->GetDisplayLayer(QDirectFbConvenience::dfbInterface(),display,&layer);
70  if (result != DFB_OK)
71  DirectFBErrorFatal("QDirectFbConvenience: "
72  "Unable to get primary display layer!", result);
73  return layer;
74 }
75 
76 QImage::Format QDirectFbConvenience::imageFormatFromSurfaceFormat(const DFBSurfacePixelFormat format, const DFBSurfaceCapabilities caps)
77 {
78  switch (format) {
79  case DSPF_LUT8:
81  case DSPF_RGB24:
82  return QImage::Format_RGB888;
83  case DSPF_ARGB4444:
85  case DSPF_RGB444:
86  return QImage::Format_RGB444;
87  case DSPF_RGB555:
88  case DSPF_ARGB1555:
89  return QImage::Format_RGB555;
90  case DSPF_RGB16:
91  return QImage::Format_RGB16;
92  case DSPF_ARGB6666:
94  case DSPF_RGB18:
95  return QImage::Format_RGB666;
96  case DSPF_RGB32:
97  return QImage::Format_RGB32;
98  case DSPF_ARGB: {
99  if (caps & DSCAPS_PREMULTIPLIED)
101  else return QImage::Format_ARGB32; }
102  default:
103  break;
104  }
105  return QImage::Format_Invalid;
106 
107 }
108 
109 int QDirectFbConvenience::colorDepthForSurface(const DFBSurfacePixelFormat format)
110 {
111  return ((0x1f << 7) & format) >> 7;
112 }
113 
119 {
120  QBlittablePixmapData *blittablePmData = static_cast<QBlittablePixmapData *>(handle);
121  if (blittablePmData) {
122  QBlittable *blittable = blittablePmData->blittable();
123  QDirectFbBlitter *dfbBlitter = static_cast<QDirectFbBlitter *>(blittable);
124  return dfbBlitter->m_surface.data();
125  }
126  return 0;
127 }
128 
129 Qt::MouseButton QDirectFbConvenience::mouseButton(DFBInputDeviceButtonIdentifier identifier)
130 {
131  switch (identifier){
132  case DIBI_LEFT:
133  return Qt::LeftButton;
134  case DIBI_MIDDLE:
135  return Qt::MidButton;
136  case DIBI_RIGHT:
137  return Qt::RightButton;
138  default:
139  return Qt::NoButton;
140  }
141 }
142 
143 Qt::MouseButtons QDirectFbConvenience::mouseButtons(DFBInputDeviceButtonMask mask)
144 {
145  Qt::MouseButtons buttons = Qt::NoButton;
146 
147  if (mask & DIBM_LEFT) {
148  buttons |= Qt::LeftButton;
149  }
150  if (mask & DIBM_MIDDLE) {
151  buttons |= Qt::MidButton;
152  }
153  if (mask & DIBM_RIGHT) {
154  buttons |= Qt::RightButton;
155  }
156  return buttons;
157 }
158 
159 Qt::KeyboardModifiers QDirectFbConvenience::keyboardModifiers(DFBInputDeviceModifierMask mask)
160 {
161  Qt::KeyboardModifiers modifiers = Qt::NoModifier;
162 
163  if (mask & DIMM_SHIFT) {
164  modifiers |= Qt::ShiftModifier;
165  }
166  if (mask & DIMM_ALT) {
167  modifiers |= Qt::AltModifier;
168  }
169  if (mask & DIMM_ALTGR) {
170  modifiers |= Qt::MetaModifier;
171  }
172  if (mask & DIMM_CONTROL) {
173  modifiers |= Qt::ControlModifier;
174  }
175  if (mask & DIMM_META) {
176  modifiers | Qt::MetaModifier;
177  }
178  return modifiers;
179 }
180 
182 {
183  switch(type) {
184  case DWET_BUTTONDOWN:
186  case DWET_BUTTONUP:
188  case DWET_MOTION:
189  return QEvent::MouseMove;
190  case DWET_WHEEL:
191  return QEvent::Wheel;
192  case DWET_KEYDOWN:
193  return QEvent::KeyPress;
194  case DWET_KEYUP:
195  return QEvent::KeyRelease;
196  default:
197  return QEvent::None;
198  }
199 }
202 {
203  if (!dfbKeymap)
204  dfbKeymap = new QDirectFbKeyMap();
205  return dfbKeymap;
206 }
207 
209 {
210  insert(DIKS_BACKSPACE , Qt::Key_Backspace);
211  insert(DIKS_TAB , Qt::Key_Tab);
212  insert(DIKS_RETURN , Qt::Key_Return);
213  insert(DIKS_ESCAPE , Qt::Key_Escape);
214  insert(DIKS_DELETE , Qt::Key_Delete);
215 
216  insert(DIKS_CURSOR_LEFT , Qt::Key_Left);
217  insert(DIKS_CURSOR_RIGHT , Qt::Key_Right);
218  insert(DIKS_CURSOR_UP , Qt::Key_Up);
219  insert(DIKS_CURSOR_DOWN , Qt::Key_Down);
220  insert(DIKS_INSERT , Qt::Key_Insert);
221  insert(DIKS_HOME , Qt::Key_Home);
222  insert(DIKS_END , Qt::Key_End);
223  insert(DIKS_PAGE_UP , Qt::Key_PageUp);
224  insert(DIKS_PAGE_DOWN , Qt::Key_PageDown);
225  insert(DIKS_PRINT , Qt::Key_Print);
226  insert(DIKS_PAUSE , Qt::Key_Pause);
227  insert(DIKS_SELECT , Qt::Key_Select);
228  insert(DIKS_GOTO , Qt::Key_OpenUrl);
229  insert(DIKS_CLEAR , Qt::Key_Clear);
230  insert(DIKS_MENU , Qt::Key_Menu);
231  insert(DIKS_HELP , Qt::Key_Help);
232 
233  insert(DIKS_INTERNET , Qt::Key_HomePage);
234  insert(DIKS_MAIL , Qt::Key_LaunchMail);
235  insert(DIKS_FAVORITES , Qt::Key_Favorites);
236 
237  insert(DIKS_BACK , Qt::Key_Back);
238  insert(DIKS_FORWARD , Qt::Key_Forward);
239  insert(DIKS_VOLUME_UP , Qt::Key_VolumeUp);
240  insert(DIKS_VOLUME_DOWN , Qt::Key_VolumeDown);
241  insert(DIKS_MUTE , Qt::Key_VolumeMute);
242  insert(DIKS_PLAYPAUSE , Qt::Key_Pause);
243  insert(DIKS_PLAY , Qt::Key_MediaPlay);
244  insert(DIKS_STOP , Qt::Key_MediaStop);
245  insert(DIKS_RECORD , Qt::Key_MediaRecord);
246  insert(DIKS_PREVIOUS , Qt::Key_MediaPrevious);
247  insert(DIKS_NEXT , Qt::Key_MediaNext);
248 
249  insert(DIKS_F1 , Qt::Key_F1);
250  insert(DIKS_F2 , Qt::Key_F2);
251  insert(DIKS_F3 , Qt::Key_F3);
252  insert(DIKS_F4 , Qt::Key_F4);
253  insert(DIKS_F5 , Qt::Key_F5);
254  insert(DIKS_F6 , Qt::Key_F6);
255  insert(DIKS_F7 , Qt::Key_F7);
256  insert(DIKS_F8 , Qt::Key_F8);
257  insert(DIKS_F9 , Qt::Key_F9);
258  insert(DIKS_F10 , Qt::Key_F10);
259  insert(DIKS_F11 , Qt::Key_F11);
260  insert(DIKS_F12 , Qt::Key_F12);
261 
262  insert(DIKS_SHIFT , Qt::Key_Shift);
263  insert(DIKS_CONTROL , Qt::Key_Control);
264  insert(DIKS_ALT , Qt::Key_Alt);
265  insert(DIKS_ALTGR , Qt::Key_AltGr);
266 
267  insert(DIKS_META , Qt::Key_Meta);
268  insert(DIKS_SUPER , Qt::Key_Super_L); // ???
269  insert(DIKS_HYPER , Qt::Key_Hyper_L); // ???
270 
271  insert(DIKS_CAPS_LOCK , Qt::Key_CapsLock);
272  insert(DIKS_NUM_LOCK , Qt::Key_NumLock);
273  insert(DIKS_SCROLL_LOCK , Qt::Key_ScrollLock);
274 
275  insert(DIKS_DEAD_ABOVEDOT , Qt::Key_Dead_Abovedot);
276  insert(DIKS_DEAD_ABOVERING , Qt::Key_Dead_Abovering);
277  insert(DIKS_DEAD_ACUTE , Qt::Key_Dead_Acute);
278  insert(DIKS_DEAD_BREVE , Qt::Key_Dead_Breve);
279  insert(DIKS_DEAD_CARON , Qt::Key_Dead_Caron);
280  insert(DIKS_DEAD_CEDILLA , Qt::Key_Dead_Cedilla);
281  insert(DIKS_DEAD_CIRCUMFLEX , Qt::Key_Dead_Circumflex);
282  insert(DIKS_DEAD_DIAERESIS , Qt::Key_Dead_Diaeresis);
283  insert(DIKS_DEAD_DOUBLEACUTE , Qt::Key_Dead_Doubleacute);
284  insert(DIKS_DEAD_GRAVE , Qt::Key_Dead_Grave);
285  insert(DIKS_DEAD_IOTA , Qt::Key_Dead_Iota);
286  insert(DIKS_DEAD_MACRON , Qt::Key_Dead_Macron);
287  insert(DIKS_DEAD_OGONEK , Qt::Key_Dead_Ogonek);
288  insert(DIKS_DEAD_SEMIVOICED_SOUND , Qt::Key_Dead_Semivoiced_Sound);
289  insert(DIKS_DEAD_TILDE , Qt::Key_Dead_Tilde);
290  insert(DIKS_DEAD_VOICED_SOUND , Qt::Key_Dead_Voiced_Sound);
291  insert(DIKS_SPACE , Qt::Key_Space);
292  insert(DIKS_EXCLAMATION_MARK , Qt::Key_Exclam);
293  insert(DIKS_QUOTATION , Qt::Key_QuoteDbl);
294  insert(DIKS_NUMBER_SIGN , Qt::Key_NumberSign);
295  insert(DIKS_DOLLAR_SIGN , Qt::Key_Dollar);
296  insert(DIKS_PERCENT_SIGN , Qt::Key_Percent);
297  insert(DIKS_AMPERSAND , Qt::Key_Ampersand);
298  insert(DIKS_APOSTROPHE , Qt::Key_Apostrophe);
299  insert(DIKS_PARENTHESIS_LEFT , Qt::Key_ParenLeft);
300  insert(DIKS_PARENTHESIS_RIGHT , Qt::Key_ParenRight);
301  insert(DIKS_ASTERISK , Qt::Key_Asterisk);
302  insert(DIKS_PLUS_SIGN , Qt::Key_Plus);
303  insert(DIKS_COMMA , Qt::Key_Comma);
304  insert(DIKS_MINUS_SIGN , Qt::Key_Minus);
305  insert(DIKS_PERIOD , Qt::Key_Period);
306  insert(DIKS_SLASH , Qt::Key_Slash);
307  insert(DIKS_0 , Qt::Key_0);
308  insert(DIKS_1 , Qt::Key_1);
309  insert(DIKS_2 , Qt::Key_2);
310  insert(DIKS_3 , Qt::Key_3);
311  insert(DIKS_4 , Qt::Key_4);
312  insert(DIKS_5 , Qt::Key_5);
313  insert(DIKS_6 , Qt::Key_6);
314  insert(DIKS_7 , Qt::Key_7);
315  insert(DIKS_8 , Qt::Key_8);
316  insert(DIKS_9 , Qt::Key_9);
317  insert(DIKS_COLON , Qt::Key_Colon);
318  insert(DIKS_SEMICOLON , Qt::Key_Semicolon);
319  insert(DIKS_LESS_THAN_SIGN , Qt::Key_Less);
320  insert(DIKS_EQUALS_SIGN , Qt::Key_Equal);
321  insert(DIKS_GREATER_THAN_SIGN , Qt::Key_Greater);
322  insert(DIKS_QUESTION_MARK , Qt::Key_Question);
323  insert(DIKS_AT , Qt::Key_At);
324  insert(DIKS_CAPITAL_A , Qt::Key_A);
325  insert(DIKS_CAPITAL_B , Qt::Key_B);
326  insert(DIKS_CAPITAL_C , Qt::Key_C);
327  insert(DIKS_CAPITAL_D , Qt::Key_D);
328  insert(DIKS_CAPITAL_E , Qt::Key_E);
329  insert(DIKS_CAPITAL_F , Qt::Key_F);
330  insert(DIKS_CAPITAL_G , Qt::Key_G);
331  insert(DIKS_CAPITAL_H , Qt::Key_H);
332  insert(DIKS_CAPITAL_I , Qt::Key_I);
333  insert(DIKS_CAPITAL_J , Qt::Key_J);
334  insert(DIKS_CAPITAL_K , Qt::Key_K);
335  insert(DIKS_CAPITAL_L , Qt::Key_L);
336  insert(DIKS_CAPITAL_M , Qt::Key_M);
337  insert(DIKS_CAPITAL_N , Qt::Key_N);
338  insert(DIKS_CAPITAL_O , Qt::Key_O);
339  insert(DIKS_CAPITAL_P , Qt::Key_P);
340  insert(DIKS_CAPITAL_Q , Qt::Key_Q);
341  insert(DIKS_CAPITAL_R , Qt::Key_R);
342  insert(DIKS_CAPITAL_S , Qt::Key_S);
343  insert(DIKS_CAPITAL_T , Qt::Key_T);
344  insert(DIKS_CAPITAL_U , Qt::Key_U);
345  insert(DIKS_CAPITAL_V , Qt::Key_V);
346  insert(DIKS_CAPITAL_W , Qt::Key_W);
347  insert(DIKS_CAPITAL_X , Qt::Key_X);
348  insert(DIKS_CAPITAL_Y , Qt::Key_Y);
349  insert(DIKS_CAPITAL_Z , Qt::Key_Z);
350  insert(DIKS_SQUARE_BRACKET_LEFT , Qt::Key_BracketLeft);
351  insert(DIKS_BACKSLASH , Qt::Key_Backslash);
352  insert(DIKS_SQUARE_BRACKET_RIGHT , Qt::Key_BracketRight);
353  insert(DIKS_CIRCUMFLEX_ACCENT , Qt::Key_AsciiCircum);
354  insert(DIKS_UNDERSCORE , Qt::Key_Underscore);
355  insert(DIKS_SMALL_A , Qt::Key_A);
356  insert(DIKS_SMALL_B , Qt::Key_B);
357  insert(DIKS_SMALL_C , Qt::Key_C);
358  insert(DIKS_SMALL_D , Qt::Key_D);
359  insert(DIKS_SMALL_E , Qt::Key_E);
360  insert(DIKS_SMALL_F , Qt::Key_F);
361  insert(DIKS_SMALL_G , Qt::Key_G);
362  insert(DIKS_SMALL_H , Qt::Key_H);
363  insert(DIKS_SMALL_I , Qt::Key_I);
364  insert(DIKS_SMALL_J , Qt::Key_J);
365  insert(DIKS_SMALL_K , Qt::Key_K);
366  insert(DIKS_SMALL_L , Qt::Key_L);
367  insert(DIKS_SMALL_M , Qt::Key_M);
368  insert(DIKS_SMALL_N , Qt::Key_N);
369  insert(DIKS_SMALL_O , Qt::Key_O);
370  insert(DIKS_SMALL_P , Qt::Key_P);
371  insert(DIKS_SMALL_Q , Qt::Key_Q);
372  insert(DIKS_SMALL_R , Qt::Key_R);
373  insert(DIKS_SMALL_S , Qt::Key_S);
374  insert(DIKS_SMALL_T , Qt::Key_T);
375  insert(DIKS_SMALL_U , Qt::Key_U);
376  insert(DIKS_SMALL_V , Qt::Key_V);
377  insert(DIKS_SMALL_W , Qt::Key_W);
378  insert(DIKS_SMALL_X , Qt::Key_X);
379  insert(DIKS_SMALL_Y , Qt::Key_Y);
380  insert(DIKS_SMALL_Z , Qt::Key_Z);
381  insert(DIKS_CURLY_BRACKET_LEFT , Qt::Key_BraceLeft);
382  insert(DIKS_VERTICAL_BAR , Qt::Key_Bar);
383  insert(DIKS_CURLY_BRACKET_RIGHT , Qt::Key_BraceRight);
384  insert(DIKS_TILDE , Qt::Key_AsciiTilde);
385 }
386 
388 {
389  return static_cast<QDirectFbScreen*>(QPlatformScreen::platformScreenForWidget(window));
390 }
391 
392 IDirectFBDisplayLayer *toDfbLayer(QPlatformScreen *screen)
393 {
394  return static_cast<QDirectFbScreen*>(screen)->dfbLayer();
395 }
396 
Format
The following image formats are available in Qt.
Definition: qimage.h:91
int type
Definition: qmetatype.cpp:239
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static IDirectFBDisplayLayer * dfbDisplayLayer(int display=DLID_PRIMARY)
The QPlatformScreen class provides an abstraction for visual displays.
T * data() const
Returns the value of the pointer referenced by this object.
static QDirectFbKeyMap * keyMap()
static Qt::MouseButtons buttons
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static QImage::Format imageFormatFromSurfaceFormat(const DFBSurfacePixelFormat format, const DFBSurfaceCapabilities caps)
IDirectFBDisplayLayer * toDfbLayer(QPlatformScreen *screen)
static QEvent::Type eventType(DFBWindowEventType type)
static IDirectFBSurface * dfbSurfaceForPlatformPixmap(QPixmapData *)
static int colorDepthForSurface(const DFBSurfacePixelFormat format)
QDirectFbScreen * toDfbScreen(QWidget *window)
static Qt::KeyboardModifiers keyboardModifiers(DFBInputDeviceModifierMask mask)
NSWindow * window
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
static Qt::MouseButton mouseButton(DFBInputDeviceButtonIdentifier identifier)
static QPlatformScreen * platformScreenForWidget(const QWidget *widget)
Type
This enum type defines the valid event types in Qt.
Definition: qcoreevent.h:62
static IDirectFB * dfbInterface()
QBlittable * blittable() const
static Qt::MouseButtons mouseButtons(DFBInputDeviceButtonMask mask)
static QDirectFbKeyMap * dfbKeymap
QDirectFBPointer< IDirectFBSurface > m_surface
MouseButton
Definition: qnamespace.h:150