Add resize event support to QWindow.

(cherry picked from commit 12b4e7e5a2b18cdd23f540821e1f2785f62b0b9a)
This commit is contained in:
Samuel Rødal 2011-04-28 13:50:07 +02:00
parent 33e1b8dda5
commit b68d0688fe
6 changed files with 137 additions and 39 deletions

View File

@ -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] =

View File

@ -13,6 +13,7 @@ public:
protected:
void mousePressEvent(QMouseEvent *);
void resizeEvent(QResizeEvent *);
private slots:
void render();

View File

@ -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 += \

View File

@ -61,6 +61,7 @@
#include <QWindowSystemInterface>
#include "private/qwindowsysteminterface_qpa_p.h"
#include "private/qwindow_qpa_p.h"
#ifndef QT_NO_CLIPBOARD
#include <QtGui/QClipboard>
@ -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

View File

@ -46,44 +46,13 @@
#include "qplatformglcontext_qpa.h"
#include "qwindowcontext_qpa.h"
#include "qwindow_qpa_p.h"
#include "qapplication_p.h"
#include <QtCore/QDebug>
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<QMouseEvent*>(event));
break;
case QEvent::MouseButtonPress:
mousePressEvent((QMouseEvent*)event);
mousePressEvent(static_cast<QMouseEvent*>(event));
break;
case QEvent::MouseButtonRelease:
mouseReleaseEvent((QMouseEvent*)event);
mouseReleaseEvent(static_cast<QMouseEvent*>(event));
break;
case QEvent::MouseButtonDblClick:
mouseDoubleClickEvent((QMouseEvent*)event);
mouseDoubleClickEvent(static_cast<QMouseEvent*>(event));
break;
case QEvent::Resize:
resizeEvent(static_cast<QResizeEvent*>(event));
break;
default:

View File

@ -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 <QtGui/qwindow_qpa.h>
#include <QtCore/private/qobject_p.h>
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