Changeset 479 for trunk/src/gui/kernel


Ignore:
Timestamp:
Jan 27, 2010, 8:49:14 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

gui: QCursor: Added missing cursor shapes and implemented support for custom cursor shapes (#73).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gui/kernel/qcursor_pm.cpp

    r182 r479  
    4848#ifndef QT_NO_CURSOR
    4949
    50 #include <qimage.h>
     50#include <qicon.h>
    5151#include <qapplication.h>
    5252#include <qdesktopwidget.h>
     
    131131#ifndef QT_NO_CURSOR
    132132
     133enum { cursor_uparrow_x = 11, cursor_uparrow_y = 1 };
     134static char const * const cursor_uparrow_xpm[] = {
     135"24 24 3 1",
     136"       c None",
     137".      c #000000",
     138"+      c #FFFFFF",
     139"                        ",
     140"           ++           ",
     141"          +..+          ",
     142"         +....+         ",
     143"        +......+        ",
     144"       +........+       ",
     145"        +++..+++        ",
     146"          +..+          ",
     147"          +..+          ",
     148"          +..+          ",
     149"          +..+          ",
     150"          +..+          ",
     151"          +..+          ",
     152"          +..+          ",
     153"          +..+          ",
     154"          +..+          ",
     155"          +..+          ",
     156"          +..+          ",
     157"          +..+          ",
     158"          +..+          ",
     159"          +..+          ",
     160"           ++           ",
     161"                        ",
     162"                        "};
     163
     164enum { cursor_cross_x = 11, cursor_cross_y = 11 };
     165static char const * const cursor_cross_xpm[] = {
     166"24 24 3 1",
     167"       c None",
     168".      c #FFFFFF",
     169"+      c #000000",
     170"                        ",
     171"           ..           ",
     172"          .++.          ",
     173"          .++.          ",
     174"          .++.          ",
     175"          .++.          ",
     176"          .++.          ",
     177"          .++.          ",
     178"          .++.          ",
     179"          .++.          ",
     180"  ........   ........   ",
     181" .++++++++   ++++++++.  ",
     182" .++++++++   ++++++++.  ",
     183"  ........   ........   ",
     184"          .++.          ",
     185"          .++.          ",
     186"          .++.          ",
     187"          .++.          ",
     188"          .++.          ",
     189"          .++.          ",
     190"          .++.          ",
     191"          .++.          ",
     192"           ..           ",
     193"                        "};
     194
     195enum { cursor_vsplit_x = 11, cursor_vsplit_y = 11 };
     196static char const * const cursor_vsplit_xpm[] = {
     197"24 24 3 1",
     198"       c None",
     199".      c #000000",
     200"+      c #FFFFFF",
     201"                        ",
     202"           ++           ",
     203"          +..+          ",
     204"         +....+         ",
     205"        +......+        ",
     206"       +........+       ",
     207"        +++..+++        ",
     208"          +..+          ",
     209"  +++++++++..+++++++++  ",
     210" +....................+ ",
     211" +....................+ ",
     212"  ++++++++++++++++++++  ",
     213"  ++++++++++++++++++++  ",
     214" +....................+ ",
     215" +....................+ ",
     216"  +++++++++..+++++++++  ",
     217"          +..+          ",
     218"        +++..+++        ",
     219"       +........+       ",
     220"        +......+        ",
     221"         +....+         ",
     222"          +..+          ",
     223"           ++           ",
     224"                        "};
     225
     226enum { cursor_hsplit_x = 11, cursor_hsplit_y = 11 };
     227static char const * const cursor_hsplit_xpm[] = {
     228"24 24 3 1",
     229"       c None",
     230".      c #000000",
     231"+      c #FFFFFF",
     232"                        ",
     233"         ++++++         ",
     234"        +..++..+        ",
     235"        +..++..+        ",
     236"        +..++..+        ",
     237"        +..++..+        ",
     238"        +..++..+        ",
     239"     +  +..++..+  +     ",
     240"    +.+ +..++..+ +.+    ",
     241"   +..+ +..++..+ +..+   ",
     242"  +...+++..++..+++...+  ",
     243" +.........++.........+ ",
     244" +.........++.........+ ",
     245"  +...+++..++..+++...+  ",
     246"   +..+ +..++..+ +..+   ",
     247"    +.+ +..++..+ +.+    ",
     248"     +  +..++..+  +     ",
     249"        +..++..+        ",
     250"        +..++..+        ",
     251"        +..++..+        ",
     252"        +..++..+        ",
     253"        +..++..+        ",
     254"         ++++++         ",
     255"                        "};
     256
     257enum { cursor_blank_x = 0, cursor_blank_y = 0 };
     258static char const * const cursor_blank_xpm[] = {
     259"1 1 1 1",
     260"       c None",
     261" "};
     262
     263enum { cursor_hand_x = 9, cursor_hand_y = 0 };
     264static char const * const cursor_hand_xpm[] = {
     265"24 24 3 1",
     266"       c None",
     267".      c #FFFFFF",
     268"+      c #000000",
     269"         ++             ",
     270"        +..+            ",
     271"        +..+            ",
     272"        +..+            ",
     273"        +..+            ",
     274"        +..+            ",
     275"        +..+++          ",
     276"        +..+..+++       ",
     277"        +..+..+..++     ",
     278"     ++ +..+..+..+.+    ",
     279"    +..++..+..+..+.+    ",
     280"    +...+..........+    ",
     281"     +.............+    ",
     282"      +............+    ",
     283"      +............+    ",
     284"       +..........+     ",
     285"       +..........+     ",
     286"        +........+      ",
     287"        +........+      ",
     288"        ++++++++++      ",
     289"        ++++++++++      ",
     290"        ++++++++++      ",
     291"                        ",
     292"                        "};
     293
     294enum { cursor_whatsthis_x = 9, cursor_whatsthis_y = 0 };
     295static char const * const cursor_whatsthis_xpm[] = {
     296"24 24 3 1",
     297"       c None",
     298".      c #000000",
     299"+      c #FFFFFF",
     300".                       ",
     301"..          ++++++      ",
     302".+.        +......+     ",
     303".++.      +........+    ",
     304".+++.    +....++....+   ",
     305".++++.   +...+  +...+   ",
     306".+++++.  +...+  +...+   ",
     307".++++++.  +.+  +....+   ",
     308".+++++++.  +  +....+    ",
     309".++++++++.   +....+     ",
     310".+++++.....  +...+      ",
     311".++.++.      +...+      ",
     312".+. .++.     +...+      ",
     313"..  .++.      +++       ",
     314".    .++.    +...+      ",
     315"     .++.    +...+      ",
     316"      .++.   +...+      ",
     317"      .++.    +++       ",
     318"       ..               ",
     319"                        ",
     320"                        ",
     321"                        ",
     322"                        ",
     323"                        "};
     324
     325enum { cursor_openhand_x = 7, cursor_openhand_y = 7 };
     326static char const * const cursor_openhand_xpm[] = {
     327"16 16 3 1",
     328"       g None",
     329".      g #000000",
     330"+      g #FFFFFF",
     331"       ..       ",
     332"   .. .++...    ",
     333"  .++..++.++.   ",
     334"  .++..++.++. . ",
     335"   .++.++.++..+.",
     336"   .++.++.++.++.",
     337" ..+.+++++++.++.",
     338".++..++++++++++.",
     339".+++.+++++++++. ",
     340" .++++++++++++. ",
     341"  .+++++++++++. ",
     342"  .++++++++++.  ",
     343"   .+++++++++.  ",
     344"    .+++++++.   ",
     345"     .++++++.   ",
     346"                "};
     347
     348enum { cursor_closedhand_x = 7, cursor_closedhand_y = 7 };
     349static char const * const cursor_closedhand_xpm[] = {
     350"16 16 3 1",
     351"       g None",
     352".      g #000000",
     353"+      g #FFFFFF",
     354"                ",
     355"                ",
     356"                ",
     357"    .. .. ..    ",
     358"   .++.++.++..  ",
     359"   .++++++++.+. ",
     360"    .+++++++++. ",
     361"   ..+++++++++. ",
     362"  .+++++++++++. ",
     363"  .++++++++++.  ",
     364"   .+++++++++.  ",
     365"    .+++++++.   ",
     366"     .++++++.   ",
     367"     .++++++.   ",
     368"                ",
     369"                "};
     370
    133371void QCursorData::update()
    134372{
    135373    if (!QCursorData::initialized)
    136374        QCursorData::initialize();
    137     // @todo we depend on QPixmap vs HBITMAP integration here
     375
     376    if (cshape == Qt::BitmapCursor) {
     377        QPixmap pm = pixmap;
     378        if (pm.isNull()) {
     379            Q_ASSERT(bm && bmm);
     380            pm = *bm;
     381            pm.setMask(*bmm);
     382        }
     383        hptr = QPixmap::toPmHPOINTER(QIcon(pm), true, hx, hy);
     384        Q_ASSERT(hptr);
     385        isSysPtr = false;
     386        return;
     387    }
    138388
    139389    LONG id = 0;
    140     const uchar *bits = 0;
    141     const uchar *mask = 0;
    142     bool isbitmap = false;
     390    char const * const * xpm = 0;
     391    int xpm_hx = 0;
     392    int xpm_hy = 0;
    143393
    144394    switch (cshape) { // map to OS/2 cursor
    145395    case Qt::ArrowCursor:
    146     case Qt::UpArrowCursor: // @todo what's this?
    147     case Qt::CrossCursor: // @todo what's this?
    148396        id = SPTR_ARROW;
     397        break;
     398    case Qt::UpArrowCursor:
     399        xpm = cursor_uparrow_xpm;
     400        xpm_hx = cursor_uparrow_x;
     401        xpm_hy = cursor_uparrow_y;
     402        break;
     403    case Qt::CrossCursor:
     404        xpm = cursor_cross_xpm;
     405        xpm_hx = cursor_cross_x;
     406        xpm_hy = cursor_cross_y;
    149407            break;
    150408    case Qt::WaitCursor:
     
    169427        id = SPTR_MOVE;
    170428        break;
     429    case Qt::BlankCursor:
     430        xpm = cursor_blank_xpm;
     431        xpm_hx = cursor_blank_x;
     432        xpm_hy = cursor_blank_y;
     433        break;
     434    case Qt::SplitVCursor:
     435        xpm = cursor_vsplit_xpm;
     436        xpm_hx = cursor_vsplit_x;
     437        xpm_hy = cursor_vsplit_y;
     438        break;
     439    case Qt::SplitHCursor:
     440        xpm = cursor_hsplit_xpm;
     441        xpm_hx = cursor_hsplit_x;
     442        xpm_hy = cursor_hsplit_y;
     443        break;
     444    case Qt::PointingHandCursor:
     445        xpm = cursor_hand_xpm;
     446        xpm_hx = cursor_hand_x;
     447        xpm_hy = cursor_hand_y;
     448        break;
    171449    case Qt::ForbiddenCursor:
    172450        id = SPTR_ILLEGAL;
    173451        break;
     452    case Qt::WhatsThisCursor:
     453        xpm = cursor_whatsthis_xpm;
     454        xpm_hx = cursor_whatsthis_x;
     455        xpm_hy = cursor_whatsthis_y;
     456        break;
     457    case Qt::BusyCursor:
     458        id = SPTR_WAIT;
     459        break;
     460    case Qt::OpenHandCursor:
     461        xpm = cursor_openhand_xpm;
     462        xpm_hx = cursor_openhand_x;
     463        xpm_hy = cursor_openhand_y;
     464        break;
     465    case Qt::ClosedHandCursor:
     466        xpm = cursor_closedhand_xpm;
     467        xpm_hx = cursor_closedhand_x;
     468        xpm_hy = cursor_closedhand_y;
     469        break;
    174470    default:
    175         // @temporary
     471        qWarning("QCursor::update: Invalid cursor shape %d", cshape);
     472        return;
     473    }
     474
     475    if (!id) {
     476#ifndef QT_NO_IMAGEFORMAT_XPM
     477        QPixmap pm(xpm);
     478        hptr = QPixmap::toPmHPOINTER(QIcon(pm), true, xpm_hx, xpm_hy);
     479        Q_ASSERT(hptr);
     480        isSysPtr = false;
     481        return;
     482#else
    176483        id = SPTR_ARROW;
    177         break;
    178         // @todo later here will be this:
    179 //      qWarning("QCursor::update: Invalid cursor shape %d", cshape);
    180 //      return;
     484#endif
    181485    }
    182486
    183 
    184     if ((bits && mask) || isbitmap) {
    185         // @todo later
    186         hptr = 0;
    187         isSysPtr = false;
    188     } else {
    189         hptr = WinQuerySysPointer(HWND_DESKTOP, id, FALSE);
    190         isSysPtr = true;
    191     }
     487    Q_ASSERT(id);
     488
     489    hptr = WinQuerySysPointer(HWND_DESKTOP, id, FALSE);
     490    Q_ASSERT(hptr);
     491    isSysPtr = true;
    192492}
    193493
Note: See TracChangeset for help on using the changeset viewer.