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