From efa0d024fc262b89189c0589a0ee81fe083635b1 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Tue, 24 Nov 2009 13:57:27 +0100 Subject: Cursor shapes for the testlite backend --- .../testlite/qgraphicssystem_testlite.cpp | 55 +++++++++++++ .../testlite/qwindowsurface_testlite.cpp | 6 ++ .../testlite/qwindowsurface_testlite.h | 2 + src/plugins/graphicssystems/testlite/x11util.cpp | 93 +++++++++++++++++++++- src/plugins/graphicssystems/testlite/x11util.h | 1 + 5 files changed, 155 insertions(+), 2 deletions(-) diff --git a/src/plugins/graphicssystems/testlite/qgraphicssystem_testlite.cpp b/src/plugins/graphicssystems/testlite/qgraphicssystem_testlite.cpp index 9991e75..64386b7 100644 --- a/src/plugins/graphicssystems/testlite/qgraphicssystem_testlite.cpp +++ b/src/plugins/graphicssystems/testlite/qgraphicssystem_testlite.cpp @@ -44,12 +44,62 @@ #include #include +#include + + #include "x11util.h" QT_BEGIN_NAMESPACE +class MyCursor : QGraphicsSystemCursor +{ +public: + MyCursor(QGraphicsSystemScreen *screen) : QGraphicsSystemCursor(screen) {} + + // input methods + void setCursor(const uchar */*data*/, const uchar */*mask*/, int width, int height, int hotX, int hotY) {qDebug() << "setCursor data..." << width << height << hotX << hotY;} + + void setCursor(Qt::CursorShape shape) { + static int oldshape = -1; + if (shape != oldshape) { + qDebug() << "setCursor" << shape; QGraphicsSystemCursor::setCursor(shape); + oldshape = shape; + } + } + + void changeCursor(QWidget * widget) { + + QTestLiteWindowSurface *ws = 0; + if (widget) { + QWidget *window = widget->window(); + ws = static_cast(window->windowSurface()); + } + + //qDebug() << "changeCursor" << widget << ws; + if (!ws) + return; + + ws->setCursor(widget->cursor().shape()); + } + +// void changeCursor(QCursor * widgetCursor) { +// //qDebug() << "changeCursor widgetCursor"; +// QGraphicsSystemCursor::changeCursor(widgetCursor); +// } + + //#### remove this + void pointerEvent(const QMouseEvent & event) { + Q_UNUSED(event); +#if 0 + qDebug() << "pointerEvent" << event.globalPos(); +#endif + } +}; + + QTestLiteGraphicsSystem::QTestLiteGraphicsSystem() { + xd = new MyDisplay; mPrimaryScreen = new QTestLiteGraphicsSystemScreen(); @@ -62,6 +112,10 @@ QTestLiteGraphicsSystem::QTestLiteGraphicsSystem() QSize(xd->physicalWidth, xd->physicalHeight); mScreens.append(mPrimaryScreen); + + + (void)new MyCursor(mPrimaryScreen); + } QPixmapData *QTestLiteGraphicsSystem::createPixmapData(QPixmapData::PixelType type) const @@ -85,4 +139,5 @@ QPixmap QTestLiteGraphicsSystem::grabWindow(WId window, int x, int y, int width, } + QT_END_NAMESPACE diff --git a/src/plugins/graphicssystems/testlite/qwindowsurface_testlite.cpp b/src/plugins/graphicssystems/testlite/qwindowsurface_testlite.cpp index be86cb5..495b572 100644 --- a/src/plugins/graphicssystems/testlite/qwindowsurface_testlite.cpp +++ b/src/plugins/graphicssystems/testlite/qwindowsurface_testlite.cpp @@ -589,4 +589,10 @@ void QTestLiteWindowSurface::lower() WId window = winId(); XLowerWindow(mGraphicsSystem->xd->display, window); } + + +void QTestLiteWindowSurface::setCursor(Qt::CursorShape shape) +{ + xw->setCursorShape(shape); +} QT_END_NAMESPACE diff --git a/src/plugins/graphicssystems/testlite/qwindowsurface_testlite.h b/src/plugins/graphicssystems/testlite/qwindowsurface_testlite.h index 3603e93..cedd66c 100644 --- a/src/plugins/graphicssystems/testlite/qwindowsurface_testlite.h +++ b/src/plugins/graphicssystems/testlite/qwindowsurface_testlite.h @@ -82,6 +82,8 @@ public: void raise(); void lower(); + void setCursor(Qt::CursorShape shape); + private: QTestLiteGraphicsSystem *mGraphicsSystem; QTestLiteGraphicsSystemScreen *mScreen; diff --git a/src/plugins/graphicssystems/testlite/x11util.cpp b/src/plugins/graphicssystems/testlite/x11util.cpp index 0c6f3c5..5830550 100644 --- a/src/plugins/graphicssystems/testlite/x11util.cpp +++ b/src/plugins/graphicssystems/testlite/x11util.cpp @@ -55,6 +55,7 @@ #include +#include //### remove stuff we don't want from qt_x11_p.h @@ -480,7 +481,7 @@ void MyWindow::setGeometry(int x, int y, int w, int h) } -void MyWindow::enterEvent(XCrossingEvent *e) +void MyWindow::enterEvent(XCrossingEvent *) { #ifdef MYX11_DEBUG qDebug() << "MyWindow::enterEvent" << hex << window; @@ -488,7 +489,7 @@ void MyWindow::enterEvent(XCrossingEvent *e) windowSurface->handleEnterEvent(); } -void MyWindow::leaveEvent(XCrossingEvent *e) +void MyWindow::leaveEvent(XCrossingEvent *) { #ifdef MYX11_DEBUG qDebug() << "MyWindow::enterEvent" << hex << window; @@ -782,3 +783,91 @@ void MyWindow::setVisible(bool visible) else XUnmapWindow(xd->display, window); } + + +void MyWindow::setCursorShape(int cshape) +{ + if (cshape < 0 || cshape > Qt::LastCursor) + return; + + static Cursor cursors[Qt::LastCursor+1] = {XNone}; + + Cursor cursor = cursors[cshape]; + if (!cursor) { + switch (cshape) { + case Qt::ArrowCursor: + cursor = XCreateFontCursor(xd->display, XC_left_ptr); + break; + case Qt::UpArrowCursor: + cursor = XCreateFontCursor(xd->display, XC_center_ptr); + break; + case Qt::CrossCursor: + cursor = XCreateFontCursor(xd->display, XC_crosshair); + break; + case Qt::WaitCursor: + cursor = XCreateFontCursor(xd->display, XC_watch); + break; + case Qt::IBeamCursor: + cursor = XCreateFontCursor(xd->display, XC_xterm); + break; + case Qt::SizeAllCursor: + cursor = XCreateFontCursor(xd->display, XC_fleur); + break; + case Qt::PointingHandCursor: + cursor = XCreateFontCursor(xd->display, XC_hand2); + break; + case Qt::SizeBDiagCursor: + cursor = XCreateFontCursor(xd->display, XC_top_right_corner); + break; + case Qt::SizeFDiagCursor: + cursor = XCreateFontCursor(xd->display, XC_bottom_right_corner); + break; + case Qt::SizeVerCursor: + case Qt::SplitVCursor: + cursor = XCreateFontCursor(xd->display, XC_sb_v_double_arrow); + break; + case Qt::SizeHorCursor: + case Qt::SplitHCursor: + cursor = XCreateFontCursor(xd->display, XC_sb_h_double_arrow); + break; + case Qt::WhatsThisCursor: + cursor = XCreateFontCursor(xd->display, XC_question_arrow); + break; + case Qt::ForbiddenCursor: + cursor = XCreateFontCursor(xd->display, XC_circle); + break; + case Qt::BusyCursor: + cursor = XCreateFontCursor(xd->display, XC_watch); + break; + + default: //default cursor for all the rest + break; + } + cursors[cshape] = cursor; + } + XDefineCursor(xd->display, window, cursor); +} + + +#if 0 + + + switch (cshape) { // map Q cursor to X cursor + case Qt::BlankCursor: + XColor bg, fg; + bg.red = 255 << 8; + bg.green = 255 << 8; + bg.blue = 255 << 8; + fg.red = 0; + fg.green = 0; + fg.blue = 0; + pm = XCreateBitmapFromData(dpy, rootwin, cur_blank_bits, 16, 16); + pmm = XCreateBitmapFromData(dpy, rootwin, cur_blank_bits, 16, 16); + hcurs = XCreatePixmapCursor(dpy, pm, pmm, &fg, &bg, 8, 8); + return; + break; + default: + qWarning("QCursor::update: Invalid cursor shape %d", cshape); + return; + } +#endif diff --git a/src/plugins/graphicssystems/testlite/x11util.h b/src/plugins/graphicssystems/testlite/x11util.h index 39fc331..e9d4c7b 100644 --- a/src/plugins/graphicssystems/testlite/x11util.h +++ b/src/plugins/graphicssystems/testlite/x11util.h @@ -109,6 +109,7 @@ public: Qt::WindowFlags setWindowFlags(Qt::WindowFlags flags); void setVisible(bool visible); + void setCursorShape(int cshape); public: //### -- cgit v0.12