src/video/qtopia/SDL_QWin.cc
author Sam Lantinga <slouken@libsdl.org>
Wed, 01 Feb 2006 06:32:25 +0000
changeset 1312 c9b51268668f
parent 769 b8d311d90021
child 1336 3692456e7b0f
permissions -rw-r--r--
Updated copyright information and removed rcs id lines (problematic in branch merges)
I batch edited these files, so please let me know if I've accidentally removed anybody's
credit here.
slouken@371
     1
/*
slouken@371
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@371
     4
slouken@371
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@371
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@371
     9
slouken@371
    10
    This library is distributed in the hope that it will be useful,
slouken@371
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@371
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@371
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@371
    18
slouken@371
    19
    Sam Lantinga
slouken@371
    20
    slouken@libsdl.org
slouken@371
    21
*/
slouken@371
    22
slouken@371
    23
#include "SDL_QWin.h"
slouken@371
    24
#include <qapplication.h>
slouken@371
    25
#include <qdirectpainter_qws.h>
slouken@481
    26
slouken@481
    27
screenRotationT screenRotation = SDL_QT_NO_ROTATION;
slouken@481
    28
slouken@371
    29
SDL_QWin::SDL_QWin(const QSize& size)
slouken@371
    30
  : QWidget(0, "SDL_main"), my_painter(0), my_image(0),
slouken@371
    31
    my_inhibit_resize(false), my_mouse_pos(-1,-1), my_flags(0),
slouken@371
    32
    my_has_fullscreen(false), my_locked(0)
slouken@371
    33
{
slouken@371
    34
  setBackgroundMode(NoBackground);
slouken@371
    35
}
slouken@371
    36
slouken@371
    37
SDL_QWin::~SDL_QWin() {
slouken@371
    38
  // Nothing to do yet.
slouken@371
    39
  if(my_image) {
slouken@371
    40
    delete my_image;
slouken@371
    41
  }
slouken@371
    42
}
slouken@371
    43
slouken@371
    44
void SDL_QWin::setImage(QImage *image) {
slouken@371
    45
  if ( my_image ) {
slouken@371
    46
    delete my_image;
slouken@371
    47
  }
slouken@371
    48
  my_image = image;
slouken@371
    49
  //  setFixedSize(image->size());
slouken@371
    50
}
slouken@371
    51
slouken@371
    52
void SDL_QWin::resizeEvent(QResizeEvent *e) {
slouken@371
    53
  if(size() != qApp->desktop()->size()) {
slouken@371
    54
    // Widget is not the correct size, so do the fullscreen magic
slouken@371
    55
    my_has_fullscreen = false;
slouken@371
    56
    enableFullscreen();
slouken@371
    57
  }
slouken@371
    58
  if(my_inhibit_resize) {
slouken@371
    59
    my_inhibit_resize = false;
slouken@371
    60
  } else {
slouken@371
    61
    SDL_PrivateResize(e->size().width(), e->size().height());
slouken@371
    62
  }
slouken@371
    63
}
slouken@371
    64
slouken@371
    65
void SDL_QWin::focusInEvent(QFocusEvent *) {
slouken@371
    66
  // Always do it here, no matter the size.
slouken@371
    67
  enableFullscreen();
slouken@371
    68
  SDL_PrivateAppActive(true, SDL_APPINPUTFOCUS);
slouken@371
    69
}
slouken@371
    70
slouken@371
    71
void SDL_QWin::focusOutEvent(QFocusEvent *) {
slouken@371
    72
  my_has_fullscreen = false;
slouken@371
    73
  SDL_PrivateAppActive(false, SDL_APPINPUTFOCUS);
slouken@371
    74
}
slouken@371
    75
slouken@371
    76
void SDL_QWin::closeEvent(QCloseEvent *e) {
slouken@371
    77
  SDL_PrivateQuit();
slouken@371
    78
  e->ignore();
slouken@371
    79
}
slouken@371
    80
slouken@379
    81
void SDL_QWin::setMousePos(const QPoint &pos) {
slouken@379
    82
  if(my_image->width() == height()) {
slouken@481
    83
    if (screenRotation == SDL_QT_ROTATION_90)
slouken@481
    84
      my_mouse_pos = QPoint(height()-pos.y(), pos.x());
slouken@481
    85
    else if (screenRotation == SDL_QT_ROTATION_270)
slouken@481
    86
      my_mouse_pos = QPoint(pos.y(), width()-pos.x());
slouken@379
    87
  } else {
slouken@379
    88
    my_mouse_pos = pos;
slouken@379
    89
  }
slouken@379
    90
}
slouken@379
    91
slouken@371
    92
void SDL_QWin::mouseMoveEvent(QMouseEvent *e) {
slouken@371
    93
  Qt::ButtonState button = e->button();
slouken@371
    94
  int sdlstate = 0;
slouken@371
    95
  if( (button & Qt::LeftButton)) {
slouken@371
    96
    sdlstate |= SDL_BUTTON_LMASK;
slouken@371
    97
  }
slouken@371
    98
  if( (button & Qt::RightButton)) {
slouken@371
    99
    sdlstate |= SDL_BUTTON_RMASK;
slouken@371
   100
  }
slouken@371
   101
  if( (button & Qt::MidButton)) {
slouken@371
   102
    sdlstate |= SDL_BUTTON_MMASK;
slouken@371
   103
  }
slouken@379
   104
  setMousePos(e->pos());
slouken@379
   105
  SDL_PrivateMouseMotion(sdlstate, 0, my_mouse_pos.x(), my_mouse_pos.y());
slouken@371
   106
}
slouken@371
   107
slouken@371
   108
void SDL_QWin::mousePressEvent(QMouseEvent *e) {
slouken@481
   109
  mouseMoveEvent(e);
slouken@371
   110
  Qt::ButtonState button = e->button();
slouken@371
   111
  SDL_PrivateMouseButton(SDL_PRESSED,
slouken@371
   112
			 (button & Qt::LeftButton) ? 1 :
slouken@371
   113
			 ((button & Qt::RightButton) ? 2 : 3),
slouken@379
   114
			 my_mouse_pos.x(), my_mouse_pos.y());
slouken@371
   115
}
slouken@371
   116
slouken@371
   117
void SDL_QWin::mouseReleaseEvent(QMouseEvent *e) {
slouken@379
   118
  setMousePos(e->pos());
slouken@371
   119
  Qt::ButtonState button = e->button();
slouken@371
   120
  SDL_PrivateMouseButton(SDL_RELEASED,
slouken@371
   121
			 (button & Qt::LeftButton) ? 1 :
slouken@371
   122
			 ((button & Qt::RightButton) ? 2 : 3),
slouken@379
   123
			 my_mouse_pos.x(), my_mouse_pos.y());
slouken@379
   124
  my_mouse_pos = QPoint(-1, -1);
slouken@371
   125
}
slouken@371
   126
slouken@567
   127
static inline void
slouken@567
   128
gs_fastRotateBlit_3 ( unsigned short *fb,
slouken@567
   129
		      unsigned short *bits,
slouken@567
   130
		      const QRect& rect )
slouken@371
   131
{
slouken@567
   132
  // FIXME: this only works correctly for 240x320 displays
slouken@371
   133
  int startx, starty;
slouken@371
   134
  int width, height;
slouken@371
   135
  
slouken@371
   136
  startx = rect.left() >> 1;
slouken@371
   137
  starty = rect.top() >> 1;
slouken@371
   138
  width  = ((rect.right() - rect.left()) >> 1) + 2;
slouken@371
   139
  height = ((rect.bottom() - rect.top()) >> 1) + 2;
slouken@371
   140
slouken@371
   141
  if((startx+width) > 120) {
slouken@371
   142
    width = 120 - startx; // avoid horizontal overflow
slouken@371
   143
  }
slouken@371
   144
  if((starty+height) > 160) { 
slouken@371
   145
    height = 160 - starty; // avoid vertical overflow
slouken@371
   146
  }
slouken@371
   147
slouken@371
   148
  ulong *sp1, *sp2, *dp1, *dp2;
slouken@371
   149
  ulong stop, sbot, dtop, dbot;    
slouken@371
   150
  
slouken@371
   151
  sp1 = (ulong*)bits + startx + starty*240;
slouken@371
   152
  sp2 = sp1 + 120;
slouken@371
   153
  dp1 = (ulong *)fb + (159 - starty) + startx*320;
slouken@371
   154
  dp2 = dp1 + 160;
slouken@371
   155
  int rowadd = (-320*width) - 1;
slouken@371
   156
  int rowadd2 = 240 - width;
slouken@371
   157
  // transfer in cells of 2x2 pixels in words
slouken@371
   158
  for (int y=0; y<height; y++) {
slouken@371
   159
    for (int x=0; x<width; x++) {
slouken@371
   160
      // read source pixels
slouken@371
   161
      stop = *sp1;
slouken@371
   162
      sbot = *sp2;
slouken@371
   163
      // rotate pixels
slouken@371
   164
      dtop = (sbot & 0xffff) + ((stop & 0xffff)<<16);
slouken@371
   165
      dbot = ((sbot & 0xffff0000)>>16) + (stop & 0xffff0000);
slouken@371
   166
      // write to framebuffer
slouken@371
   167
      *dp1 = dtop;
slouken@371
   168
      *dp2 = dbot;
slouken@371
   169
      // update source ptrs
slouken@371
   170
      sp1++; sp2++;
slouken@371
   171
      // update dest ptrs - 2 pix at a time
slouken@371
   172
      dp1 += 320;
slouken@371
   173
      dp2 += 320;
slouken@371
   174
    }
slouken@371
   175
    // adjust src ptrs - skip a row as we work in pairs
slouken@371
   176
    sp1 += rowadd2;
slouken@371
   177
    sp2 += rowadd2;
slouken@371
   178
    // adjust dest ptrs for rotation
slouken@371
   179
    dp1 += rowadd;
slouken@371
   180
    dp2 += rowadd;
slouken@371
   181
  }
slouken@371
   182
}
slouken@567
   183
slouken@567
   184
static inline void
slouken@567
   185
gs_fastRotateBlit_1 ( unsigned short *fb,
slouken@567
   186
		      unsigned short *bits,
slouken@567
   187
		      const QRect& rect ) {
slouken@567
   188
  // FIXME: this only works correctly for 240x320 displays
slouken@567
   189
  int startx, starty;
slouken@567
   190
  int width, height;
slouken@567
   191
slouken@567
   192
  startx = rect.left() >> 1;
slouken@567
   193
  starty = rect.top() >> 1;
slouken@567
   194
  width  = ((rect.right() - rect.left()) >> 1) + 2;
slouken@567
   195
  height = ((rect.bottom() - rect.top()) >> 1) + 2;
slouken@567
   196
slouken@567
   197
  if((startx+width) > 120) {
slouken@567
   198
    width = 120 - startx; // avoid horizontal overflow
slouken@567
   199
  }
slouken@567
   200
  if((starty+height) > 160) { 
slouken@567
   201
    height = 160 - starty; // avoid vertical overflow
slouken@567
   202
  }
slouken@567
   203
slouken@567
   204
  ulong *sp1, *sp2, *dp1, *dp2;
slouken@567
   205
  ulong stop, sbot, dtop, dbot;    
slouken@567
   206
  fb += 320*239; // Move "fb" to top left corner
slouken@567
   207
  sp1 = (ulong*)bits + startx + starty*240;
slouken@567
   208
  sp2 = sp1 + 120;
slouken@567
   209
  dp1 = (ulong*)fb - startx * 320 - starty;
slouken@567
   210
  dp2 = dp1 - 160;
slouken@567
   211
  int rowadd = (320*width) + 1;
slouken@567
   212
  int rowadd2 = 240 - width;
slouken@567
   213
  // transfer in cells of 2x2 pixels in words
slouken@567
   214
  for (int y=0; y<height; y++) {
slouken@567
   215
    for (int x=0; x<width; x++) {
slouken@567
   216
      // read
slouken@567
   217
      stop = *sp1;
slouken@567
   218
      sbot = *sp2;
slouken@567
   219
      // rotate
slouken@567
   220
      dtop = (stop & 0xffff) + ((sbot & 0xffff)<<16);
slouken@567
   221
      dbot = ((stop & 0xffff0000)>>16) + (sbot & 0xffff0000);
slouken@567
   222
      // write
slouken@567
   223
      *dp1 = dtop;
slouken@567
   224
      *dp2 = dbot;
slouken@567
   225
      // update source ptrs
slouken@567
   226
      sp1++; sp2++;
slouken@567
   227
      // update dest ptrs - 2 pix at a time
slouken@567
   228
      dp1 -= 320;
slouken@567
   229
      dp2 -= 320;
slouken@567
   230
    }
slouken@567
   231
    // adjust src ptrs - skip a row as we work in pairs
slouken@567
   232
    sp1 += rowadd2;
slouken@567
   233
    sp2 += rowadd2;
slouken@567
   234
    // adjust dest ptrs for rotation
slouken@567
   235
    dp1 += rowadd;
slouken@567
   236
    dp2 += rowadd;
slouken@567
   237
  }
slouken@567
   238
}
slouken@567
   239
slouken@567
   240
// desktop, SL-A300 etc
slouken@567
   241
bool SDL_QWin::repaintRotation0(const QRect& rect) {
slouken@567
   242
  if(my_image->width() == width()) {
slouken@567
   243
    uchar *fb = (uchar*)my_painter->frameBuffer();
slouken@567
   244
    uchar *buf = (uchar*)my_image->bits();
slouken@567
   245
    if(rect == my_image->rect()) {
slouken@567
   246
      memcpy(fb, buf, width()*height()*2);
slouken@567
   247
    } else {
slouken@567
   248
      int h = rect.height();
slouken@567
   249
      int wd = rect.width()<<1;
slouken@567
   250
      int fblineadd = my_painter->lineStep();
slouken@567
   251
      int buflineadd = my_image->bytesPerLine();
slouken@567
   252
      fb  += (rect.left()<<1) + rect.top() * my_painter->lineStep();
slouken@567
   253
      buf += (rect.left()<<1) + rect.top() * my_image->bytesPerLine();
slouken@567
   254
      while(h--) {
slouken@567
   255
	memcpy(fb, buf, wd);
slouken@567
   256
	fb += fblineadd;
slouken@567
   257
	buf += buflineadd;
slouken@567
   258
      }
slouken@567
   259
    }
slouken@567
   260
  } else {
slouken@567
   261
    return false; // FIXME: Landscape
slouken@567
   262
  }
slouken@567
   263
#ifdef __i386__
slouken@567
   264
  my_painter->fillRect( rect, QBrush( Qt::NoBrush ) );
slouken@371
   265
#endif
slouken@567
   266
  return true;
slouken@567
   267
}
slouken@567
   268
slouken@567
   269
  
slouken@567
   270
// Sharp Zaurus SL-5500 etc 
slouken@567
   271
bool SDL_QWin::repaintRotation3(const QRect& rect) {
slouken@567
   272
  if(my_image->width() == width()) {
slouken@567
   273
    ushort *fb = (ushort*)my_painter->frameBuffer();
slouken@567
   274
    ushort *buf = (ushort*)my_image->bits();
slouken@567
   275
    gs_fastRotateBlit_3(fb, buf, rect);
slouken@567
   276
  } else {
slouken@567
   277
    // landscape mode
slouken@567
   278
    if (screenRotation == SDL_QT_ROTATION_90) {
slouken@567
   279
      uchar *fb = (uchar*)my_painter->frameBuffer();
slouken@567
   280
      uchar *buf = (uchar*)my_image->bits();
slouken@567
   281
      if(rect == my_image->rect()) {
slouken@567
   282
	memcpy(fb, buf, width()*height()*2);
slouken@567
   283
      } else {
slouken@567
   284
	int h = rect.height();
slouken@567
   285
	int wd = rect.width()<<1;
slouken@567
   286
	int fblineadd = my_painter->lineStep();
slouken@567
   287
	int buflineadd = my_image->bytesPerLine();
slouken@567
   288
	fb  += (rect.left()<<1) + rect.top() * my_painter->lineStep();
slouken@567
   289
	buf += (rect.left()<<1) + rect.top() * my_image->bytesPerLine();
slouken@567
   290
	while(h--) {
slouken@567
   291
	  memcpy(fb, buf, wd);
slouken@567
   292
	  fb += fblineadd;
slouken@567
   293
	  buf += buflineadd;
slouken@567
   294
	}
slouken@567
   295
      }
slouken@567
   296
    } else if (screenRotation == SDL_QT_ROTATION_270) {
slouken@567
   297
      int h = rect.height();
slouken@567
   298
      int wd = rect.width();
slouken@567
   299
      int fblineadd = my_painter->lineStep() - (rect.width() << 1);
slouken@567
   300
      int buflineadd = my_image->bytesPerLine() - (rect.width() << 1);
slouken@567
   301
      int w;
slouken@567
   302
slouken@567
   303
      uchar *fb = (uchar*)my_painter->frameBuffer();
slouken@567
   304
      uchar *buf = (uchar*)my_image->bits();
slouken@567
   305
        
slouken@567
   306
      fb += ((my_painter->width() - (rect.top() + rect.height())) * 
slouken@567
   307
	     my_painter->lineStep()) + ((my_painter->height() - ((rect.left() + 
slouken@567
   308
								  rect.width()))) << 1);
slouken@567
   309
slouken@567
   310
      buf += my_image->bytesPerLine() * (rect.top() + rect.height()) -
slouken@567
   311
	(((my_image->width() - (rect.left() + rect.width())) << 1) + 2);
slouken@567
   312
slouken@567
   313
      while(h--) {
slouken@567
   314
	w = wd;
slouken@567
   315
	while(w--) *((unsigned short*)fb)++ = *((unsigned short*)buf)--;
slouken@567
   316
	fb += fblineadd;
slouken@567
   317
	buf -= buflineadd;
slouken@567
   318
      }
slouken@567
   319
    }
slouken@567
   320
  }
slouken@567
   321
  return true;
slouken@567
   322
}
slouken@567
   323
slouken@567
   324
// ipaq 3800...
slouken@567
   325
bool SDL_QWin::repaintRotation1(const QRect& rect) {
slouken@567
   326
  if(my_image->width() == width()) {
slouken@567
   327
    ushort *fb = (ushort*)my_painter->frameBuffer();
slouken@567
   328
    ushort *buf = (ushort*)my_image->bits();
slouken@567
   329
    gs_fastRotateBlit_1(fb, buf, rect);
slouken@567
   330
  } else {
slouken@567
   331
    return false; // FIXME: landscape mode
slouken@567
   332
  }
slouken@567
   333
  return true;
slouken@567
   334
}
slouken@371
   335
slouken@371
   336
void SDL_QWin::repaintRect(const QRect& rect) {
slouken@371
   337
  if(!my_painter || !rect.width() || !rect.height()) {
slouken@371
   338
    return;
slouken@371
   339
  }
slouken@567
   340
  
slouken@567
   341
  if(QPixmap::defaultDepth() == 16) {
slouken@567
   342
    switch(my_painter->transformOrientation()) {
slouken@567
   343
    case 3:
slouken@567
   344
      if(repaintRotation3(rect)) { return;  }
slouken@567
   345
      break;
slouken@567
   346
    case 1:
slouken@567
   347
      if(repaintRotation1(rect)) { return;  }
slouken@567
   348
      break;
slouken@567
   349
    case 0:
slouken@567
   350
      if(repaintRotation0(rect)) { return;  }
slouken@567
   351
      break;
slouken@371
   352
    }
slouken@567
   353
  } 
slouken@567
   354
  my_painter->drawImage(rect.topLeft(), *my_image, rect);
slouken@371
   355
}
slouken@371
   356
slouken@371
   357
// This paints the current buffer to the screen, when desired. 
slouken@371
   358
void SDL_QWin::paintEvent(QPaintEvent *ev) {  
slouken@567
   359
  if(my_image) {
slouken@567
   360
    lockScreen(true);
slouken@371
   361
    repaintRect(ev->rect());
slouken@371
   362
    unlockScreen();
slouken@371
   363
  }
slouken@371
   364
}  
slouken@371
   365
slouken@567
   366
/* Function to translate a keyboard transition and queue the key event
slouken@567
   367
 * This should probably be a table although this method isn't exactly
slouken@567
   368
 * slow.
slouken@567
   369
 */
slouken@371
   370
void SDL_QWin::QueueKey(QKeyEvent *e, int pressed)
slouken@371
   371
{  
slouken@371
   372
  SDL_keysym keysym;
slouken@371
   373
  int scancode = e->key();
slouken@371
   374
  /* Set the keysym information */
slouken@371
   375
  if(scancode >= 'A' && scancode <= 'Z') {
slouken@371
   376
    // Qt sends uppercase, SDL wants lowercase
slouken@371
   377
    keysym.sym = static_cast<SDLKey>(scancode + 32);
slouken@371
   378
  } else if(scancode  >= 0x1000) {
slouken@371
   379
    // Special keys
slouken@371
   380
    switch(scancode) {
slouken@371
   381
    case Qt::Key_Escape: scancode = SDLK_ESCAPE; break;
slouken@371
   382
    case Qt::Key_Tab: scancode = SDLK_TAB; break;
slouken@371
   383
    case Qt::Key_Backspace: scancode = SDLK_BACKSPACE; break;
slouken@371
   384
    case Qt::Key_Return: scancode = SDLK_RETURN; break;
slouken@371
   385
    case Qt::Key_Enter: scancode = SDLK_KP_ENTER; break;
slouken@371
   386
    case Qt::Key_Insert: scancode = SDLK_INSERT; break;
slouken@371
   387
    case Qt::Key_Delete: scancode = SDLK_DELETE; break;
slouken@371
   388
    case Qt::Key_Pause: scancode = SDLK_PAUSE; break;
slouken@371
   389
    case Qt::Key_Print: scancode = SDLK_PRINT; break;
slouken@371
   390
    case Qt::Key_SysReq: scancode = SDLK_SYSREQ; break;
slouken@371
   391
    case Qt::Key_Home: scancode = SDLK_HOME; break;
slouken@371
   392
    case Qt::Key_End: scancode = SDLK_END; break;
slouken@481
   393
    // We want the control keys to rotate with the screen
slouken@481
   394
    case Qt::Key_Left: 
slouken@481
   395
        if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_UP;
slouken@481
   396
        else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_DOWN;
slouken@481
   397
        else scancode = SDLK_LEFT;
slouken@481
   398
        break;
slouken@481
   399
    case Qt::Key_Up: 
slouken@481
   400
        if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_RIGHT;
slouken@481
   401
        else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_LEFT;
slouken@481
   402
        else scancode = SDLK_UP;
slouken@481
   403
        break;
slouken@481
   404
    case Qt::Key_Right: 
slouken@481
   405
        if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_DOWN;
slouken@481
   406
        else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_UP;
slouken@481
   407
        else scancode = SDLK_RIGHT;
slouken@481
   408
        break;
slouken@481
   409
    case Qt::Key_Down:
slouken@481
   410
        if (screenRotation == SDL_QT_ROTATION_90) scancode = SDLK_LEFT;
slouken@481
   411
        else if (screenRotation == SDL_QT_ROTATION_270) scancode = SDLK_RIGHT;
slouken@481
   412
        else scancode = SDLK_DOWN;
slouken@481
   413
        break;
slouken@371
   414
    case Qt::Key_Prior: scancode = SDLK_PAGEUP; break;
slouken@371
   415
    case Qt::Key_Next: scancode = SDLK_PAGEDOWN; break;
slouken@371
   416
    case Qt::Key_Shift: scancode = SDLK_LSHIFT; break;
slouken@371
   417
    case Qt::Key_Control: scancode = SDLK_LCTRL; break;
slouken@371
   418
    case Qt::Key_Meta: scancode = SDLK_LMETA; break;
slouken@371
   419
    case Qt::Key_Alt: scancode = SDLK_LALT; break;
slouken@371
   420
    case Qt::Key_CapsLock: scancode = SDLK_CAPSLOCK; break;
slouken@371
   421
    case Qt::Key_NumLock: scancode = SDLK_NUMLOCK; break;
slouken@371
   422
    case Qt::Key_ScrollLock: scancode = SDLK_SCROLLOCK; break;
slouken@371
   423
    case Qt::Key_F1: scancode = SDLK_F1; break;
slouken@371
   424
    case Qt::Key_F2: scancode = SDLK_F2; break;
slouken@371
   425
    case Qt::Key_F3: scancode = SDLK_F3; break;
slouken@371
   426
    case Qt::Key_F4: scancode = SDLK_F4; break;
slouken@371
   427
    case Qt::Key_F5: scancode = SDLK_F5; break;
slouken@371
   428
    case Qt::Key_F6: scancode = SDLK_F6; break;
slouken@371
   429
    case Qt::Key_F7: scancode = SDLK_F7; break;
slouken@371
   430
    case Qt::Key_F8: scancode = SDLK_F8; break;
slouken@371
   431
    case Qt::Key_F9: scancode = SDLK_F9; break;
slouken@371
   432
    case Qt::Key_F10: scancode = SDLK_F10; break;
slouken@371
   433
    case Qt::Key_F11: scancode = SDLK_F11; break;
slouken@371
   434
    case Qt::Key_F12: scancode = SDLK_F12; break;
slouken@371
   435
    case Qt::Key_F13: scancode = SDLK_F13; break;
slouken@371
   436
    case Qt::Key_F14: scancode = SDLK_F14; break;
slouken@371
   437
    case Qt::Key_F15: scancode = SDLK_F15; break;
slouken@371
   438
    case Qt::Key_Super_L: scancode = SDLK_LSUPER; break;
slouken@371
   439
    case Qt::Key_Super_R: scancode = SDLK_RSUPER; break;
slouken@371
   440
    case Qt::Key_Menu: scancode = SDLK_MENU; break;
slouken@371
   441
    case Qt::Key_Help: scancode = SDLK_HELP; break;
slouken@567
   442
slouken@567
   443
    case Qt::Key_F33:
slouken@567
   444
      // FIXME: This is a hack to enable the OK key on
slouken@567
   445
      // Zaurii devices. SDLK_RETURN is a suitable key to use
slouken@567
   446
      // since it often is used as such.
slouken@567
   447
      //     david@hedbor.org
slouken@567
   448
      scancode = SDLK_RETURN;
slouken@567
   449
      break;
slouken@371
   450
    default:
slouken@371
   451
      scancode = SDLK_UNKNOWN;
slouken@371
   452
      break;
slouken@371
   453
    }
slouken@371
   454
    keysym.sym = static_cast<SDLKey>(scancode);    
slouken@371
   455
  } else {
slouken@371
   456
    keysym.sym = static_cast<SDLKey>(scancode);    
slouken@371
   457
  }
slouken@371
   458
  keysym.scancode = scancode;
slouken@371
   459
  keysym.mod = KMOD_NONE;
slouken@371
   460
  ButtonState st = e->state();
slouken@371
   461
  if( (st & ShiftButton) )   { keysym.mod = static_cast<SDLMod>(keysym.mod | KMOD_LSHIFT);  }
slouken@371
   462
  if( (st & ControlButton) ) { keysym.mod = static_cast<SDLMod>(keysym.mod | KMOD_LCTRL);  }
slouken@371
   463
  if( (st & AltButton) )     { keysym.mod = static_cast<SDLMod>(keysym.mod | KMOD_LALT);  }
slouken@371
   464
  if ( SDL_TranslateUNICODE ) {
slouken@371
   465
    QChar qchar = e->text()[0];
slouken@371
   466
    keysym.unicode = qchar.unicode();
slouken@371
   467
  } else {
slouken@371
   468
    keysym.unicode = 0;
slouken@371
   469
  }
slouken@371
   470
slouken@371
   471
  /* NUMLOCK and CAPSLOCK are implemented as double-presses in reality */
slouken@371
   472
  //	if ( (keysym.sym == SDLK_NUMLOCK) || (keysym.sym == SDLK_CAPSLOCK) ) {
slouken@371
   473
  //		pressed = 1;
slouken@371
   474
  //	}
slouken@371
   475
slouken@371
   476
  /* Queue the key event */
slouken@371
   477
  if ( pressed ) {
slouken@371
   478
    SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
slouken@371
   479
  } else {
slouken@371
   480
    SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
slouken@371
   481
  }
slouken@371
   482
}
slouken@371
   483
slouken@371
   484
void SDL_QWin::setFullscreen(bool fs_on) {
slouken@371
   485
  my_has_fullscreen = false;
slouken@371
   486
  enableFullscreen();
slouken@371
   487
}
slouken@371
   488
slouken@371
   489
void SDL_QWin::enableFullscreen() {
slouken@371
   490
  // Make sure size is correct
slouken@371
   491
  if(!my_has_fullscreen) {
slouken@371
   492
    setFixedSize(qApp->desktop()->size());
slouken@371
   493
    // This call is needed because showFullScreen won't work
slouken@371
   494
    // correctly if the widget already considers itself to be fullscreen.
slouken@371
   495
    showNormal();
slouken@371
   496
    // This is needed because showNormal() forcefully changes the window
slouken@371
   497
    // style to WSTyle_TopLevel.
slouken@371
   498
    setWFlags(WStyle_Customize | WStyle_NoBorder);
slouken@371
   499
    // Enable fullscreen.
slouken@371
   500
    showFullScreen();
slouken@371
   501
    my_has_fullscreen = true;
slouken@371
   502
  }
slouken@371
   503
}
slouken@567
   504
slouken@567
   505
bool SDL_QWin::lockScreen(bool force) {
slouken@567
   506
  if(!my_painter) {
slouken@567
   507
    if(force || (isVisible() && isActiveWindow())) {
slouken@567
   508
      my_painter = new QDirectPainter(this);
slouken@567
   509
    } else {
slouken@567
   510
      return false;
slouken@567
   511
    }
slouken@567
   512
  }
slouken@567
   513
  my_locked++; // Increate lock refcount
slouken@567
   514
  return true;
slouken@567
   515
}
slouken@567
   516
slouken@567
   517
void SDL_QWin::unlockScreen() {
slouken@567
   518
  if(my_locked > 0) {
slouken@567
   519
    my_locked--; // decrease lock refcount;
slouken@567
   520
  }
slouken@567
   521
  if(!my_locked && my_painter) {
slouken@567
   522
    my_painter->end();
slouken@567
   523
    delete my_painter;
slouken@567
   524
    my_painter = 0;
slouken@567
   525
  }
slouken@567
   526
}