From b68d0688feb7b01eca91b33566887200de7fc89a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Samuel=20R=C3=B8dal?= Date: Thu, 28 Apr 2011 13:50:07 +0200 Subject: [PATCH] Add resize event support to QWindow. (cherry picked from commit 12b4e7e5a2b18cdd23f540821e1f2785f62b0b9a) --- examples/opengl/hellowindow/hellowindow.cpp | 7 +++ examples/opengl/hellowindow/hellowindow.h | 1 + src/gui/kernel/kernel.pri | 1 + src/gui/kernel/qguiapplication_qpa.cpp | 29 ++++++++- src/gui/kernel/qwindow_qpa.cpp | 46 +++------------ src/gui/kernel/qwindow_qpa_p.h | 92 +++++++++++++++++++++++++++++ 6 files changed, 137 insertions(+), 39 deletions(-) create mode 100644 src/gui/kernel/qwindow_qpa_p.h diff --git a/examples/opengl/hellowindow/hellowindow.cpp b/examples/opengl/hellowindow/hellowindow.cpp index 6de48e8..b0576c1 100644 --- a/examples/opengl/hellowindow/hellowindow.cpp +++ b/examples/opengl/hellowindow/hellowindow.cpp @@ -34,6 +34,13 @@ void HelloWindow::mousePressEvent(QMouseEvent *) updateColor(); } +void HelloWindow::resizeEvent(QResizeEvent *) +{ + glContext()->makeCurrent(); + + glViewport(0, 0, geometry().width(), geometry().height()); +} + void HelloWindow::updateColor() { float colors[][4] = diff --git a/examples/opengl/hellowindow/hellowindow.h b/examples/opengl/hellowindow/hellowindow.h index b0adecb..f0b8ee8 100644 --- a/examples/opengl/hellowindow/hellowindow.h +++ b/examples/opengl/hellowindow/hellowindow.h @@ -13,6 +13,7 @@ public: protected: void mousePressEvent(QMouseEvent *); + void resizeEvent(QResizeEvent *); private slots: void render(); diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri index d7a4f42..c77d62a 100644 --- a/src/gui/kernel/kernel.pri +++ b/src/gui/kernel/kernel.pri @@ -230,6 +230,7 @@ qpa { kernel/qwindowformat_qpa.h \ kernel/qguiapplication_qpa.h \ kernel/qguiapplication_qpa_p.h \ + kernel/qwindow_qpa_p.h \ kernel/qwindow_qpa.h SOURCES += \ diff --git a/src/gui/kernel/qguiapplication_qpa.cpp b/src/gui/kernel/qguiapplication_qpa.cpp index 4c4f427..3a09c68 100644 --- a/src/gui/kernel/qguiapplication_qpa.cpp +++ b/src/gui/kernel/qguiapplication_qpa.cpp @@ -61,6 +61,7 @@ #include #include "private/qwindowsysteminterface_qpa_p.h" +#include "private/qwindow_qpa_p.h" #ifndef QT_NO_CLIPBOARD #include @@ -658,8 +659,32 @@ void QGuiApplicationPrivate::processGeometryChangeEvent(QWindowSystemInterfacePr { if (e->tlw.isNull()) return; - QWidget *tlw = e->tlw.data() ? e->tlw.data()->widget() : 0; - if (!tlw || !tlw->isWindow()) + + QWindow *window = e->tlw.data(); + QWidget *tlw = window ? window->widget() : 0; + if (!tlw) { + if (window) { + QRect newRect = e->newGeometry; + QRect cr = window->geometry(); + + bool isResize = cr.size() != newRect.size(); + bool isMove = cr.topLeft() != newRect.topLeft(); + window->d_func()->geometry = newRect; + if (isResize) { + QResizeEvent e(newRect.size(), cr.size()); + QGuiApplication::sendSpontaneousEvent(window, &e); + } + + if (isMove) { + //### frame geometry + QMoveEvent e(newRect.topLeft(), cr.topLeft()); + QGuiApplication::sendSpontaneousEvent(window, &e); + } + } + return; + } + + if (!tlw->isWindow()) return; //geo of native child widgets is controlled by lighthouse //so we already have sent the events; besides this new rect //is not mapped to parent diff --git a/src/gui/kernel/qwindow_qpa.cpp b/src/gui/kernel/qwindow_qpa.cpp index 469afaa..0e24752 100644 --- a/src/gui/kernel/qwindow_qpa.cpp +++ b/src/gui/kernel/qwindow_qpa.cpp @@ -46,44 +46,13 @@ #include "qplatformglcontext_qpa.h" #include "qwindowcontext_qpa.h" +#include "qwindow_qpa_p.h" #include "qapplication_p.h" #include QT_BEGIN_NAMESPACE -class QWindowPrivate : public QObjectPrivate -{ -public: - QWindowPrivate() - : QObjectPrivate() - , windowFlags(Qt::Window) - , surfaceType(QWindow::RasterSurface) - , platformWindow(0) - , visible(false) - , glContext(0) - , widget(0) - { - isWindow = true; - } - - ~QWindowPrivate() - { - - } - - Qt::WindowFlags windowFlags; - QWindow::SurfaceType surfaceType; - QWindow *parentWindow; - QPlatformWindow *platformWindow; - bool visible; - QWindowFormat requestedFormat; - QString windowTitle; - QRect geometry; - QWindowContext *glContext; - QWidget *widget; -}; - QWindow::QWindow(QWindow *parent) : QObject(*new QWindowPrivate()) { @@ -397,7 +366,6 @@ bool QWindow::close() void QWindow::resizeEvent(QResizeEvent *) { - qDebug() << "unimplemented:" << __FILE__ << __LINE__; } void QWindow::showEvent(QShowEvent *) @@ -414,19 +382,23 @@ bool QWindow::event(QEvent *event) { switch (event->type()) { case QEvent::MouseMove: - mouseMoveEvent((QMouseEvent*)event); + mouseMoveEvent(static_cast(event)); break; case QEvent::MouseButtonPress: - mousePressEvent((QMouseEvent*)event); + mousePressEvent(static_cast(event)); break; case QEvent::MouseButtonRelease: - mouseReleaseEvent((QMouseEvent*)event); + mouseReleaseEvent(static_cast(event)); break; case QEvent::MouseButtonDblClick: - mouseDoubleClickEvent((QMouseEvent*)event); + mouseDoubleClickEvent(static_cast(event)); + break; + + case QEvent::Resize: + resizeEvent(static_cast(event)); break; default: diff --git a/src/gui/kernel/qwindow_qpa_p.h b/src/gui/kernel/qwindow_qpa_p.h new file mode 100644 index 0000000..5a1b8cd --- /dev/null +++ b/src/gui/kernel/qwindow_qpa_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWINDOW_QPA_P_H +#define QWINDOW_QPA_P_H + +#include + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +class QWindowPrivate : public QObjectPrivate +{ +public: + QWindowPrivate() + : QObjectPrivate() + , windowFlags(Qt::Window) + , surfaceType(QWindow::RasterSurface) + , platformWindow(0) + , visible(false) + , glContext(0) + , widget(0) + { + isWindow = true; + } + + ~QWindowPrivate() + { + + } + + Qt::WindowFlags windowFlags; + QWindow::SurfaceType surfaceType; + QWindow *parentWindow; + QPlatformWindow *platformWindow; + bool visible; + QWindowFormat requestedFormat; + QString windowTitle; + QRect geometry; + QWindowContext *glContext; + QWidget *widget; +}; + + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QWINDOW_QPA_P_H -- 2.7.4