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