src/video/qtopia/SDL_QWin.cc
author Sam Lantinga <slouken@libsdl.org>
Mon, 20 Jan 2003 01:08:20 +0000
changeset 567 969fbd4dcd4e
parent 481 c96e2137f9eb
child 769 b8d311d90021
permissions -rw-r--r--
From: David Hedbor
Subject: Qtopia patches (input grabbing and iconify)

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