Propagate window state changes to QWidget.

Apply the state in QWidgetWindow and send an event to
the widget unless the code is triggered by
QWidget::setWindowState().

Change-Id: Ibf2f4e730384e41636841b9216eecfdff35b7bcb
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
This commit is contained in:
Friedemann Kleint 2012-04-11 12:07:59 +02:00 committed by Qt by Nokia
parent 54f718e552
commit ce84af7c9b

View File

@ -454,10 +454,38 @@ void QWidgetWindow::handleWindowStateChangedEvent(QWindowStateChangeEvent *event
{
// QWindow does currently not know 'active'.
Qt::WindowStates eventState = event->oldState();
if (m_widget->windowState() & Qt::WindowActive)
Qt::WindowStates widgetState = m_widget->windowState();
if (widgetState & Qt::WindowActive)
eventState |= Qt::WindowActive;
QWindowStateChangeEvent widgetEvent(eventState);
QGuiApplication::sendSpontaneousEvent(m_widget, &widgetEvent);
// Determine the new widget state, remember maximized/full screen
// during minimized.
switch (windowState()) {
case Qt::WindowNoState:
widgetState &= ~(Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen);
break;
case Qt::WindowMinimized:
widgetState |= Qt::WindowMinimized;
break;
case Qt::WindowMaximized:
widgetState &= ~Qt::WindowFullScreen;
widgetState |= Qt::WindowMaximized;
break;
case Qt::WindowFullScreen:
widgetState &= ~Qt::WindowMaximized;
widgetState |= Qt::WindowFullScreen;
break;
case Qt::WindowActive: // Not handled by QWindow
break;
}
// Sent event if the state changed (that is, it is not triggered by
// QWidget::setWindowState(), which also sends an event to the widget).
if (widgetState != m_widget->data->window_state) {
m_widget->data->window_state = widgetState;
QWindowStateChangeEvent widgetEvent(eventState);
QGuiApplication::sendSpontaneousEvent(m_widget, &widgetEvent);
}
}
bool QWidgetWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)