Implemented close event for QWindow and QWidgetWindow.
This commit is contained in:
parent
3edff16c87
commit
59ded5cce4
@ -63,6 +63,9 @@ void HelloWindow::updateColor()
|
||||
|
||||
void HelloWindow::render()
|
||||
{
|
||||
if (!glContext())
|
||||
return;
|
||||
|
||||
glContext()->makeCurrent();
|
||||
|
||||
glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
|
||||
|
@ -710,11 +710,11 @@ void QGuiApplicationPrivate::processGeometryChangeEvent(QWindowSystemInterfacePr
|
||||
|
||||
void QGuiApplicationPrivate::processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e)
|
||||
{
|
||||
if (e->topLevel.isNull()) {
|
||||
//qDebug() << "QGuiApplicationPrivate::processCloseEvent NULL";
|
||||
if (e->window.isNull())
|
||||
return;
|
||||
}
|
||||
// e->topLevel.data()->d_func()->close_helper(QWidgetPrivate::CloseWithSpontaneousEvent);
|
||||
|
||||
QCloseEvent event;
|
||||
QGuiApplication::sendSpontaneousEvent(e->window.data(), &event);
|
||||
}
|
||||
|
||||
void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *)
|
||||
|
@ -41,6 +41,8 @@
|
||||
|
||||
#include "qwidgetwindow_qpa_p.h"
|
||||
|
||||
#include "private/qwidget_p.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QWidgetWindow::QWidgetWindow(QWidget *widget)
|
||||
@ -51,11 +53,8 @@ QWidgetWindow::QWidgetWindow(QWidget *widget)
|
||||
bool QWidgetWindow::event(QEvent *event)
|
||||
{
|
||||
switch (event->type()) {
|
||||
case QEvent::MouseMove:
|
||||
case QEvent::MouseButtonPress:
|
||||
case QEvent::MouseButtonRelease:
|
||||
case QEvent::MouseButtonDblClick:
|
||||
handleMouseEvent(static_cast<QMouseEvent *>(event));
|
||||
case QEvent::Close:
|
||||
handleCloseEvent(static_cast<QCloseEvent *>(event));
|
||||
return true;
|
||||
|
||||
case QEvent::KeyPress:
|
||||
@ -63,6 +62,13 @@ bool QWidgetWindow::event(QEvent *event)
|
||||
handleKeyEvent(static_cast<QKeyEvent *>(event));
|
||||
return true;
|
||||
|
||||
case QEvent::MouseMove:
|
||||
case QEvent::MouseButtonPress:
|
||||
case QEvent::MouseButtonRelease:
|
||||
case QEvent::MouseButtonDblClick:
|
||||
handleMouseEvent(static_cast<QMouseEvent *>(event));
|
||||
return true;
|
||||
|
||||
case QEvent::Move:
|
||||
handleMoveEvent(static_cast<QMoveEvent *>(event));
|
||||
return true;
|
||||
@ -116,4 +122,9 @@ void QWidgetWindow::handleResizeEvent(QResizeEvent *event)
|
||||
QGuiApplication::sendSpontaneousEvent(m_widget, event);
|
||||
}
|
||||
|
||||
void QWidgetWindow::handleCloseEvent(QCloseEvent *)
|
||||
{
|
||||
m_widget->d_func()->close_helper(QWidgetPrivate::CloseWithSpontaneousEvent);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -63,8 +63,9 @@ public:
|
||||
protected:
|
||||
bool event(QEvent *);
|
||||
|
||||
void handleMouseEvent(QMouseEvent *);
|
||||
void handleCloseEvent(QCloseEvent *);
|
||||
void handleKeyEvent(QKeyEvent *);
|
||||
void handleMouseEvent(QMouseEvent *);
|
||||
void handleMoveEvent(QMoveEvent *);
|
||||
void handleResizeEvent(QResizeEvent *);
|
||||
|
||||
|
@ -293,7 +293,7 @@ void QWindow::setWindowIcon(const QImage &icon) const
|
||||
QWindowContext * QWindow::glContext() const
|
||||
{
|
||||
Q_D(const QWindow);
|
||||
if (!d->glContext)
|
||||
if (d->platformWindow && !d->glContext)
|
||||
const_cast<QWindowPrivate *>(d)->glContext = new QWindowContext(const_cast<QWindow *>(this));
|
||||
return d->glContext;
|
||||
}
|
||||
@ -411,6 +411,10 @@ bool QWindow::event(QEvent *event)
|
||||
break;
|
||||
#endif
|
||||
|
||||
case QEvent::Close:
|
||||
destroy();
|
||||
break;
|
||||
|
||||
default:
|
||||
return QObject::event(event);
|
||||
}
|
||||
|
@ -73,9 +73,9 @@ public:
|
||||
|
||||
class CloseEvent : public WindowSystemEvent {
|
||||
public:
|
||||
CloseEvent(QWindow *tlw)
|
||||
: WindowSystemEvent(Close), topLevel(tlw) { }
|
||||
QWeakPointer<QWindow> topLevel;
|
||||
CloseEvent(QWindow *w)
|
||||
: WindowSystemEvent(Close), window(w) { }
|
||||
QWeakPointer<QWindow> window;
|
||||
};
|
||||
|
||||
class GeometryChangeEvent : public WindowSystemEvent {
|
||||
|
Loading…
Reference in New Issue
Block a user