diff options
author | Jeremy Katz <jeremy.katz@nokia.com> | 2009-11-26 12:39:06 (GMT) |
---|---|---|
committer | Jeremy Katz <jeremy.katz@nokia.com> | 2009-11-26 13:27:45 (GMT) |
commit | c290785d0f8e1ef7af4bdff683aab40b8ff33681 (patch) | |
tree | ed3ff2635d237ef9853cd940b39650fd41718661 /src/plugins | |
parent | 19039afd151f2c2401659904b89968d302149493 (diff) | |
download | Qt-c290785d0f8e1ef7af4bdff683aab40b8ff33681.zip Qt-c290785d0f8e1ef7af4bdff683aab40b8ff33681.tar.gz Qt-c290785d0f8e1ef7af4bdff683aab40b8ff33681.tar.bz2 |
move software cursor from QGraphicsSystemCursor into QGraphicsSystemSoftwareCursor
Diffstat (limited to 'src/plugins')
6 files changed, 106 insertions, 21 deletions
diff --git a/src/plugins/graphicssystems/fb_base/fb_base.cpp b/src/plugins/graphicssystems/fb_base/fb_base.cpp index 6ecfd1b..27cb8a4 100644 --- a/src/plugins/graphicssystems/fb_base/fb_base.cpp +++ b/src/plugins/graphicssystems/fb_base/fb_base.cpp @@ -3,9 +3,81 @@ #include <qpainter.h> #include <private/qapplication_p.h> #include <qdebug.h> - +#include <qbitmap.h> #include <qgraphicssystemcursor.h> +QGraphicsSystemSoftwareCursor::QGraphicsSystemSoftwareCursor(QGraphicsSystemScreen *scr) + : QGraphicsSystemCursor(scr), currentRect(QRect()), prevRect(QRect()) +{ + graphic = new QGraphicsSystemCursorImage(0, 0, 0, 0, 0, 0); + setCursor(Qt::ArrowCursor); +} + +QRect QGraphicsSystemSoftwareCursor::getCurrentRect() +{ + QRect rect = graphic->image()->rect().translated(-graphic->hotspot().x(), + -graphic->hotspot().y()); + rect.translate(QCursor::pos()); + return rect; +} + + +void QGraphicsSystemSoftwareCursor::pointerEvent(const QMouseEvent & e) +{ + Q_UNUSED(e); + currentRect = getCurrentRect(); + screen->setDirty(currentRect); +} + +QRect QGraphicsSystemSoftwareCursor::drawCursor(QPainter & painter) +{ + if (currentRect.isNull()) + return QRect(); + + prevRect = currentRect; + painter.drawImage(prevRect, *graphic->image()); + return prevRect; +} + +QRect QGraphicsSystemSoftwareCursor::dirtyRect() +{ + if (!prevRect.isNull()) { + QRect rect = prevRect; + prevRect = QRect(); + return rect; + } + return QRect(); +} + +void QGraphicsSystemSoftwareCursor::setCursor(Qt::CursorShape shape) +{ + graphic->set(shape); +} + +void QGraphicsSystemSoftwareCursor::setCursor(const uchar *data, const uchar *mask, int width, int height, int hotX, int hotY) +{ + graphic->set(data, mask, width, height, hotX, hotY); +} + +void QGraphicsSystemSoftwareCursor::changeCursor(QCursor * widgetCursor, QWidget * widget) +{ + Q_UNUSED(widget); + Qt::CursorShape shape = widgetCursor->shape(); + + if (shape == Qt::BitmapCursor) { + // application supplied cursor + const QBitmap * map = widgetCursor->bitmap(); + const QBitmap * mask = widgetCursor->mask(); + QPoint spot = widgetCursor->hotSpot(); + setCursor(map->toImage().bits(), mask->toImage().bits(), map->width(), map->height(), spot.x(), spot.y()); + } else { + // system cursor + setCursor(shape); + } + currentRect = getCurrentRect(); + screen->setDirty(currentRect); +} + QGraphicsSystemFbScreen::QGraphicsSystemFbScreen() : cursor(0), mGeometry(), mDepth(16), mFormat(QImage::Format_RGB16), mScreenImage(0) { mScreenImage = new QImage(mGeometry.size(), mFormat); diff --git a/src/plugins/graphicssystems/fb_base/fb_base.h b/src/plugins/graphicssystems/fb_base/fb_base.h index 8e54f47..9abd5d0 100644 --- a/src/plugins/graphicssystems/fb_base/fb_base.h +++ b/src/plugins/graphicssystems/fb_base/fb_base.h @@ -15,6 +15,30 @@ class QPainter; class QGraphicsSystemFbWindowSurface; class QGraphicsSystemFbScreen; +class QGraphicsSystemSoftwareCursor : public QGraphicsSystemCursor +{ +public: + QGraphicsSystemSoftwareCursor(QGraphicsSystemScreen * scr); + + // output methods + QRect dirtyRect(); + virtual QRect drawCursor(QPainter & painter); + + // input methods + virtual void pointerEvent(const QMouseEvent & event); + virtual void changeCursor(QCursor * widgetCursor, QWidget * widget); + +protected: + QGraphicsSystemCursorImage * graphic; + +private: + void setCursor(const uchar *data, const uchar *mask, int width, int height, int hotX, int hotY); + void setCursor(Qt::CursorShape shape); + QRect currentRect; // next place to draw the cursor + QRect prevRect; // last place the cursor was drawn + QRect getCurrentRect(); +}; + class QGraphicsSystemFbWindowSurface : public QWindowSurface { public: @@ -74,7 +98,7 @@ public: protected: QList<QGraphicsSystemFbWindowSurface *> windowStack; QRegion repaintRegion; - QGraphicsSystemCursor * cursor; + QGraphicsSystemSoftwareCursor * cursor; QTimer redrawTimer; protected slots: diff --git a/src/plugins/graphicssystems/linuxfb/qgraphicssystem_linuxfb.cpp b/src/plugins/graphicssystems/linuxfb/qgraphicssystem_linuxfb.cpp index 2a0007b..f5ca6e7 100644 --- a/src/plugins/graphicssystems/linuxfb/qgraphicssystem_linuxfb.cpp +++ b/src/plugins/graphicssystems/linuxfb/qgraphicssystem_linuxfb.cpp @@ -807,7 +807,7 @@ QLinuxFbGraphicsSystemScreen::QLinuxFbGraphicsSystemScreen(uchar * d, int w, mFormat); mFbScreenImage = new QImage(data, mGeometry.width(), mGeometry.height(), bytesPerLine, mFormat); - cursor = new QGraphicsSystemCursor(this); + cursor = new QGraphicsSystemSoftwareCursor(this); } void QLinuxFbGraphicsSystemScreen::setGeometry(QRect rect) diff --git a/src/plugins/graphicssystems/testlite/qgraphicssystem_testlite.cpp b/src/plugins/graphicssystems/testlite/qgraphicssystem_testlite.cpp index 450905c..bdcac37 100644 --- a/src/plugins/graphicssystems/testlite/qgraphicssystem_testlite.cpp +++ b/src/plugins/graphicssystems/testlite/qgraphicssystem_testlite.cpp @@ -72,14 +72,6 @@ public: ws->setCursor(cursor->shape()); } - - //#### remove this - void pointerEvent(const QMouseEvent & event) { - Q_UNUSED(event); -#if 0 - qDebug() << "pointerEvent" << event.globalPos(); -#endif - } }; diff --git a/src/plugins/graphicssystems/vnc/qvnccursor.cpp b/src/plugins/graphicssystems/vnc/qvnccursor.cpp index 55d1c61..fb214d8 100644 --- a/src/plugins/graphicssystems/vnc/qvnccursor.cpp +++ b/src/plugins/graphicssystems/vnc/qvnccursor.cpp @@ -54,13 +54,13 @@ QT_BEGIN_NAMESPACE QVNCCursor::QVNCCursor(QVNCServer * srvr, QVNCGraphicsSystemScreen *scr ) - :QGraphicsSystemCursor::QGraphicsSystemCursor(scr), useVncCursor(false), server(srvr) + :QGraphicsSystemSoftwareCursor(scr), useVncCursor(false), server(srvr) { } void QVNCCursor::changeCursor(QCursor * widgetCursor, QWidget * widget) { - QGraphicsSystemCursor::changeCursor(widgetCursor, widget); + QGraphicsSystemSoftwareCursor::changeCursor(widgetCursor, widget); if (useVncCursor) { server->setDirtyCursor(); } else { @@ -71,8 +71,7 @@ void QVNCCursor::changeCursor(QCursor * widgetCursor, QWidget * widget) void QVNCCursor::setCursorMode(bool vnc) { if (vnc) { - screen->setDirty(prevRect); - prevRect = QRect(); + screen->setDirty(dirtyRect()); server->setDirtyCursor(); } else { server->setDirtyCursor(); @@ -85,10 +84,7 @@ QRect QVNCCursor::drawCursor(QPainter & painter) if (useVncCursor) return QRect(); - if (currentRect.isNull()) - return QRect(); - - return QGraphicsSystemCursor::drawCursor(painter); + return QGraphicsSystemSoftwareCursor::drawCursor(painter); } void QVNCCursor::clearClientCursor() diff --git a/src/plugins/graphicssystems/vnc/qvnccursor.h b/src/plugins/graphicssystems/vnc/qvnccursor.h index a90b7e2..8ea0f45 100644 --- a/src/plugins/graphicssystems/vnc/qvnccursor.h +++ b/src/plugins/graphicssystems/vnc/qvnccursor.h @@ -41,7 +41,7 @@ #ifndef QVNCCURSOR_H #define QVNCCURSOR_H -#include "qgraphicssystemcursor.h" +#include "../fb_base/fb_base.h" #include <QList> #include <QImage> #include <QMouseEvent> @@ -51,13 +51,14 @@ QT_BEGIN_NAMESPACE class QVNCGraphicsSystemScreen; class QVNCServer; -class QVNCCursor : public QGraphicsSystemCursor { +class QVNCCursor : public QGraphicsSystemSoftwareCursor { public: QVNCCursor(QVNCServer *, QVNCGraphicsSystemScreen *); // input methods void setCursorMode(bool vnc); void changeCursor(QCursor * widgetCursor, QWidget * widget); + // output methods QRect drawCursor(QPainter &); |