diff options
author | Paul Olav Tvete <paul.tvete@nokia.com> | 2010-04-13 18:07:12 +0200 |
---|---|---|
committer | Paul Olav Tvete <paul.tvete@nokia.com> | 2010-04-13 18:07:12 +0200 |
commit | 029018357554b7a2f4da18bf3f5456159d853d62 (patch) | |
tree | d96ef67ab82eb65e51f0e3dcb276faaecbc47e30 | |
parent | d0fd682035d6227b103adb84d4931b494bc555d8 (diff) |
Port to new API
-rw-r--r-- | devdays.pro | 2 | ||||
-rw-r--r-- | main.cpp | 8 | ||||
-rw-r--r-- | qgraphicssystem_dd.cpp | 94 | ||||
-rw-r--r-- | qgraphicssystem_dd.h | 37 |
4 files changed, 103 insertions, 38 deletions
diff --git a/devdays.pro b/devdays.pro index eb22a96..8eb03ca 100644 --- a/devdays.pro +++ b/devdays.pro @@ -7,5 +7,5 @@ QT += network SOURCES = main.cpp qgraphicssystem_dd.cpp HEADERS = qgraphicssystem_dd.h protocol.h -target.path += $$[QT_INSTALL_PLUGINS]/graphicssystems +target.path += $$[QT_INSTALL_PLUGINS]/platforms INSTALLS += target @@ -21,16 +21,16 @@ ** ****************************************************************************/ -#include <private/qgraphicssystemplugin_p.h> +#include <QPlatformIntegrationPlugin> #include "qgraphicssystem_dd.h" QT_BEGIN_NAMESPACE -class QDevDaysGraphicsSystemPlugin : public QGraphicsSystemPlugin +class QDevDaysGraphicsSystemPlugin : public QPlatformIntegrationPlugin { public: QStringList keys() const; - QGraphicsSystem *create(const QString &system); + QPlatformIntegration *create(const QString &system); }; QStringList QDevDaysGraphicsSystemPlugin::keys() const @@ -40,7 +40,7 @@ QStringList QDevDaysGraphicsSystemPlugin::keys() const return list; } -QGraphicsSystem* QDevDaysGraphicsSystemPlugin::create(const QString &system) +QPlatformIntegration* QDevDaysGraphicsSystemPlugin::create(const QString &system) { if (system.toLower() == "devdays") return new QDevDaysGraphicsSystem; diff --git a/qgraphicssystem_dd.cpp b/qgraphicssystem_dd.cpp index 637e6e6..da93be7 100644 --- a/qgraphicssystem_dd.cpp +++ b/qgraphicssystem_dd.cpp @@ -40,28 +40,44 @@ QT_BEGIN_NAMESPACE // window surface // -QDevDaysWindowSurface::QDevDaysWindowSurface(QWidget *window, QDevDaysGraphicsSystem *system) - : QWindowSurface(window), m_system(system) + +QDevDaysWindow::QDevDaysWindow(QWidget *window, const QDevDaysGraphicsSystem *system) + : QPlatformWindow(window), m_system(const_cast<QDevDaysGraphicsSystem*>(system)) { + quint32 parentId = system->m_ids.value(window->parentWidget(), 0); Request request(Request::CreateWindowRequest, parentId); - system->sendRequest(request); + m_system->sendRequest(request); Response response; - system->waitForResponse(response); + m_system->waitForResponse(response); m_id = response.id; m_system->m_surfaces.insert(m_id, this); m_system->m_ids.insert(window, m_id); + } -QDevDaysWindowSurface::~QDevDaysWindowSurface() +QDevDaysWindow::~QDevDaysWindow() { Request request(Request::DestroyWindowRequest, m_id); m_system->sendRequest(request); m_system->m_surfaces.remove(m_id); - m_system->m_ids.remove(window()); + m_system->m_ids.remove(widget()); +} + + + +QDevDaysWindowSurface::QDevDaysWindowSurface(QWidget *window, QDevDaysGraphicsSystem *system) + : QWindowSurface(window), m_system(system) +{ + QDevDaysWindow *w = static_cast<QDevDaysWindow*>(window->platformWindow()); + m_id = w->m_id; +} + +QDevDaysWindowSurface::~QDevDaysWindowSurface() +{ } QPaintDevice *QDevDaysWindowSurface::paintDevice() @@ -82,14 +98,12 @@ void QDevDaysWindowSurface::flush(QWidget *widget, const QRegion ®ion, const // we don't expect any response } -void QDevDaysWindowSurface::setGeometry(const QRect &rect) +void QDevDaysWindowSurface::resize(const QSize &size) { - qDebug() << "WINDOW: setGeometry"; - QWindowSurface::setGeometry(rect); - qDebug() << "WINDOW: geometry" << geometry(); + QWindowSurface::resize(size); // create or resize the shared memory - qint32 byteCount = rect.width() * rect.height() * sizeof(quint32); // ### server should hold the pixel format + qint32 byteCount = size.width() * size.height() * sizeof(quint32); // ### server should hold the pixel format qDebug() << "WINDOW: byte count" << byteCount; if (byteCount > m_shared.size()) { if (!m_shared.key().isEmpty()) @@ -101,10 +115,25 @@ void QDevDaysWindowSurface::setGeometry(const QRect &rect) Q_ASSERT(m_shared.data()); } +} + + + +void QDevDaysWindow::setGeometry(const QRect &rect) +{ + qDebug() << "WINDOW: setGeometry"; + QPlatformWindow::setGeometry(rect); + qDebug() << "WINDOW: geometry" << geometry(); + Request request(Request::SetWindowGeometryRequest, m_id, 0, rect); m_system->sendRequest(request); + } + + + + bool QDevDaysWindowSurface::scroll(const QRegion &area, int dx, int dy) { // the server doesn't have scroll @@ -114,13 +143,13 @@ bool QDevDaysWindowSurface::scroll(const QRegion &area, int dx, int dy) void QDevDaysWindowSurface::beginPaint(const QRegion ®ion) { Q_UNUSED(region); - qDebug() << "WINDOW: begin paint" << m_id << geometry(); + qDebug() << "WINDOW: begin paint" << m_id << size(); // lock the surface shared memory before painting if (m_shared.lock() && m_shared.data()) - m_image = QImage((uchar*)m_shared.data(), geometry().width(), geometry().height(), m_system->screens().first()->format()); + m_image = QImage((uchar*)m_shared.data(), size().width(), size().height(), m_system->screens().first()->format()); else qDebug() << m_shared.errorString(); - qDebug() << "WINDOW: image" << m_image.size() << "geometry" << geometry() << "data" << m_shared.data() << "key" << m_shared.key(); + qDebug() << "WINDOW: image" << m_image.size() << "size" << size() << "data" << m_shared.data() << "key" << m_shared.key(); } void QDevDaysWindowSurface::endPaint(const QRegion ®ion) @@ -136,25 +165,25 @@ void QDevDaysWindowSurface::endPaint(const QRegion ®ion) } -void QDevDaysWindowSurface::setVisible(bool visible) +void QDevDaysWindow::setVisible(bool visible) { qDebug() << "WINDOW: setVisible()" << visible; Request request(visible ? Request::ShowWindowRequest : Request::HideWindowRequest, m_id); m_system->sendRequest(request); } -Qt::WindowFlags QDevDaysWindowSurface::setWindowFlags(Qt::WindowFlags type) +Qt::WindowFlags QDevDaysWindow::setWindowFlags(Qt::WindowFlags type) { return window_flags = type; } -Qt::WindowFlags QDevDaysWindowSurface::windowFlags() const +Qt::WindowFlags QDevDaysWindow::windowFlags() const { return window_flags; } -void QDevDaysWindowSurface::raise() +void QDevDaysWindow::raise() { qDebug() << "WINDOW: raise()"; Request request(Request::RaiseWindowRequest, m_id); @@ -162,7 +191,7 @@ void QDevDaysWindowSurface::raise() } -void QDevDaysWindowSurface::lower() +void QDevDaysWindow::lower() { qDebug() << "WINDOW: lower()"; Request request(Request::LowerWindowRequest, m_id); @@ -189,7 +218,7 @@ QPixmapData *QDevDaysGraphicsSystem::createPixmapData(QPixmapData::PixelType typ return new QRasterPixmapData(type); } -QWindowSurface *QDevDaysGraphicsSystem::createWindowSurface(QWidget *widget) const +QWindowSurface *QDevDaysGraphicsSystem::createWindowSurfaceForWindow(QWidget *widget, WId) const { qDebug() << "SYSTEM: create window surface"; // send create request to the server @@ -199,10 +228,27 @@ QWindowSurface *QDevDaysGraphicsSystem::createWindowSurface(QWidget *widget) con return new QDevDaysWindowSurface(widget, const_cast<QDevDaysGraphicsSystem*>(this)); } -QList<QGraphicsSystemScreen*> QDevDaysGraphicsSystem::screens() const + + +QPlatformWindow *QDevDaysGraphicsSystem::createPlatformWindow(QWidget *widget, WId) const +{ + qDebug() << "SYSTEM: create window surface"; + // send create request to the server + Q_ASSERT(widget); + if (widget->windowType() == Qt::Desktop) + return 0; + return new QDevDaysWindow(widget, const_cast<QDevDaysGraphicsSystem*>(this)); +} + + + + + + +QList<QPlatformScreen*> QDevDaysGraphicsSystem::screens() const { // qDebug() << "SYSTEM: screens"; - return QList<QGraphicsSystemScreen*>() << &m_screen; + return QList<QPlatformScreen*>() << &m_screen; } bool QDevDaysGraphicsSystem::connectToServer() @@ -253,8 +299,8 @@ void QDevDaysGraphicsSystem::eventDispatcher() in >> m_message; switch (m_message.message) { case Event::EventMessage: { - QDevDaysWindowSurface *surface = m_surfaces.value(m_message.id); - QWidget *window = surface ? surface->window() : 0; + QDevDaysWindow *platformWindow = m_surfaces.value(m_message.id); + QWidget *window = platformWindow ? platformWindow->widget() : 0; qDebug() << "SYSTEM: received event" << m_message.type << window; switch (m_message.type) { case Event::GeometryChangeEvent: { diff --git a/qgraphicssystem_dd.h b/qgraphicssystem_dd.h index 4abbcb2..7240cac 100644 --- a/qgraphicssystem_dd.h +++ b/qgraphicssystem_dd.h @@ -29,6 +29,9 @@ #include <QtNetwork/qtcpsocket.h> #include <QtGui/private/qgraphicssystem_p.h> +#include <QPlatformWindow> +#include <QPlatformScreen> +#include <QPlatformIntegration> #include "protocol.h" QT_BEGIN_NAMESPACE @@ -44,26 +47,40 @@ public: QPaintDevice *paintDevice(); void flush(QWidget *widget, const QRegion ®ion, const QPoint &offset); - void setGeometry(const QRect &rect); + void resize(const QSize &size); bool scroll(const QRegion &area, int dx, int dy); void beginPaint(const QRegion ®ion); void endPaint(const QRegion ®ion); +private: + QDevDaysGraphicsSystem *m_system; + quint32 m_id; + QSharedMemory m_shared; + QImage m_image; +}; + + +class QDevDaysWindow : public QPlatformWindow +{ +public: + QDevDaysWindow(QWidget *window, const QDevDaysGraphicsSystem *platformIntegration); + ~QDevDaysWindow(); + void setGeometry(const QRect &rect); + void setVisible(bool visible); void raise(); void lower(); Qt::WindowFlags setWindowFlags(Qt::WindowFlags type); Qt::WindowFlags windowFlags() const; - private: + friend class QDevDaysWindowSurface; QDevDaysGraphicsSystem *m_system; quint32 m_id; - QSharedMemory m_shared; - QImage m_image; Qt::WindowFlags window_flags; }; -class QDevDaysGraphicsSystemScreen : public QGraphicsSystemScreen + +class QDevDaysGraphicsSystemScreen : public QPlatformScreen { public: QDevDaysGraphicsSystemScreen() {} @@ -75,7 +92,7 @@ public: QSize physicalSize() const { return QSize(80, 108); } // size in milimeters }; -class QDevDaysGraphicsSystem : public QObject, public QGraphicsSystem +class QDevDaysGraphicsSystem : public QObject, public QPlatformIntegration { Q_OBJECT public: @@ -83,8 +100,10 @@ public: // QGraphicsSystem interface QPixmapData *createPixmapData(QPixmapData::PixelType type) const; - QWindowSurface *createWindowSurface(QWidget *widget) const; - QList<QGraphicsSystemScreen*> screens() const; + QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId) const; + QWindowSurface *createWindowSurfaceForWindow(QWidget *widget, WId winId) const; + + QList<QPlatformScreen*> screens() const; // client interface bool connectToServer(); @@ -99,7 +118,7 @@ private: Message m_message; public: - mutable QHash<quint32, QDevDaysWindowSurface*> m_surfaces; + mutable QHash<quint32, QDevDaysWindow*> m_surfaces; mutable QHash<QWidget*, quint32> m_ids; mutable QDevDaysGraphicsSystemScreen m_screen; //mutable Client m_client; |