From c3da77798b876716ce038a30e9aa8517ec158c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Thu, 21 Jul 2011 13:50:28 +0200 Subject: Added workable QScreen API on top of QPlatformScreen. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QPlatformIntegration::screens() no longer has to be implemented, implementations should call QPlatformIntegration::screenAdded() for each screen instead. This is for being able to support adding screens at run-time later on, by connecting it to a signal in QGuiApplication. The QGuiGLContext API has changed a bit, by not sending in all the parameters in the constructor but instead having a create() function. The createPlatformGLContext() factory in QPlatformIntegration takes a QGuiGLContext * instead of a QSurfaceFormat and a share context, similar to how the window and backing store factory functions work. The XCB plugin has experimental support for connecting to multiple X displays simultaneously, creating one or more QScreen for each. Change-Id: I248a22a4fd3481280710110272c04a30a8021e8f Reviewed-on: http://codereview.qt.nokia.com/2103 Reviewed-by: Qt Sanity Bot Reviewed-by: Jørgen Lind --- examples/opengl/hellowindow/hellowindow.cpp | 4 +++- examples/qpa/windows/main.cpp | 12 ++++++++++ examples/qpa/windows/window.cpp | 34 ++++++++++++++++++++++++----- examples/qpa/windows/window.h | 6 +++++ 4 files changed, 50 insertions(+), 6 deletions(-) (limited to 'examples') diff --git a/examples/opengl/hellowindow/hellowindow.cpp b/examples/opengl/hellowindow/hellowindow.cpp index 9575d3e3c7..5a232e6a7b 100644 --- a/examples/opengl/hellowindow/hellowindow.cpp +++ b/examples/opengl/hellowindow/hellowindow.cpp @@ -12,7 +12,9 @@ Renderer::Renderer() m_format.setDepthBufferSize(16); m_format.setSamples(4); - m_context = new QGuiGLContext(m_format); + m_context = new QGuiGLContext; + m_context->setFormat(m_format); + m_context->create(); } QSurfaceFormat Renderer::format() const diff --git a/examples/qpa/windows/main.cpp b/examples/qpa/windows/main.cpp index 99c24fa017..e4cd14398c 100644 --- a/examples/qpa/windows/main.cpp +++ b/examples/qpa/windows/main.cpp @@ -1,4 +1,5 @@ #include +#include #include "window.h" @@ -15,5 +16,16 @@ int main(int argc, char **argv) Window child(&b); child.setVisible(true); + // create one window on each additional screen as well + + QList screens = app.screens(); + foreach (QScreen *screen, screens) { + if (screen == app.primaryScreen()) + continue; + Window *window = new Window(screen); + window->setVisible(true); + window->setWindowTitle(screen->name()); + } + return app.exec(); } diff --git a/examples/qpa/windows/window.cpp b/examples/qpa/windows/window.cpp index bbfc6a3116..fecc22034a 100644 --- a/examples/qpa/windows/window.cpp +++ b/examples/qpa/windows/window.cpp @@ -14,13 +14,23 @@ QColor colorTable[] = QColor("#c0ef8f") }; +Window::Window(QScreen *screen) + : QWindow(screen) + , m_backgroundColorIndex(colorIndexId++) +{ + initialize(); +} + Window::Window(QWindow *parent) : QWindow(parent) , m_backgroundColorIndex(colorIndexId++) { - setWindowTitle(QLatin1String("Window")); + initialize(); +} - if (parent) +void Window::initialize() +{ + if (parent()) setGeometry(QRect(160, 120, 320, 240)); else { setGeometry(QRect(10, 10, 640, 480)); @@ -38,6 +48,7 @@ Window::Window(QWindow *parent) m_image.fill(colorTable[m_backgroundColorIndex % (sizeof(colorTable) / sizeof(colorTable[0]))].rgba()); m_lastPos = QPoint(-1, -1); + m_renderTimer = 0; } void Window::mousePressEvent(QMouseEvent *event) @@ -54,7 +65,7 @@ void Window::mouseMoveEvent(QMouseEvent *event) m_lastPos = event->pos(); } - render(); + scheduleRender(); } void Window::mouseReleaseEvent(QMouseEvent *event) @@ -66,12 +77,12 @@ void Window::mouseReleaseEvent(QMouseEvent *event) m_lastPos = QPoint(-1, -1); } - render(); + scheduleRender(); } void Window::exposeEvent(QExposeEvent *) { - render(); + scheduleRender(); } void Window::resizeEvent(QResizeEvent *) @@ -106,7 +117,20 @@ void Window::keyPressEvent(QKeyEvent *event) m_text.append(event->text()); break; } + scheduleRender(); +} + +void Window::scheduleRender() +{ + if (!m_renderTimer) + m_renderTimer = startTimer(1); +} + +void Window::timerEvent(QTimerEvent *) +{ render(); + killTimer(m_renderTimer); + m_renderTimer = 0; } void Window::render() diff --git a/examples/qpa/windows/window.h b/examples/qpa/windows/window.h index 546cf67bce..bf664d148e 100644 --- a/examples/qpa/windows/window.h +++ b/examples/qpa/windows/window.h @@ -5,6 +5,7 @@ class Window : public QWindow { public: Window(QWindow *parent = 0); + Window(QScreen *screen); protected: void mousePressEvent(QMouseEvent *); @@ -16,12 +17,17 @@ protected: void exposeEvent(QExposeEvent *); void resizeEvent(QResizeEvent *); + void timerEvent(QTimerEvent *); + private: void render(); + void scheduleRender(); + void initialize(); QString m_text; QImage m_image; QPoint m_lastPos; int m_backgroundColorIndex; QBackingStore *m_backingStore; + int m_renderTimer; }; -- cgit v1.2.3