summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qwidget.cpp
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2012-03-28 15:26:17 +0200
committerQt by Nokia <qt-info@nokia.com>2012-04-11 16:17:59 +0200
commitad1bd1563f3f65d0f7b65687af2ade42f7f9f3d9 (patch)
treecaf53878e581afa44a53458dc5bcc23ea5eea972 /src/widgets/kernel/qwidget.cpp
parenteff344ab8a509996cab491347aed4a4d8ea5b2ab (diff)
Implement window modality in QtGui
QWindow already has windowModality() and setWindowModality() as part of its API from commit 516f4e283ba4626d7239630397ef867ab0366071. Platform plugins can use this already to setup modality hints on windows that they create, but it's not enough to implement modality fully. QGuiApplication gets a modalWindow() static method, which is similar to QApplication::activeModalWidget() in that it returns the last modal window to be shown. The modal window "stack" moves from QApplicationPrivate to QGuiApplicationPrivate. The enterModal*() and leaveModal*() functions in QApplicationPrivate are removed and replaced by QGuiApplicationPrivate::showModalWindow() and hideModalWindow(), which are called by QWindow::setVisible() just before calling QPlatformWindow::setVisible(). The virtual QGuiApplicationPrivate::isWindowBlocked() will tell us if a window is blocked by a modal window (and tell which modal window for any interested callers). The default implementation works on the QWindow level. QApplicationPrivate reimplements isWindowBlocked() and adds popup and WA_GroupLeader support. QGuiApplication uses the state set from isWindowBlocked() to block user-input events: mouse press, mouse move, mouse release, wheel, key presses, key releases, enter/leave events, close events, and touch begin, update, and end events. Note also that the modality helper functions in QtWidgets and QApplicationPrivate are left in place and working as they always have. The behavior of QWidget in the presence of modal windows/dialogs should not change. Change-Id: I2c89e6026d40160387787a6e009ae1fdc12dfd69 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com> Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com> Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
Diffstat (limited to 'src/widgets/kernel/qwidget.cpp')
-rw-r--r--src/widgets/kernel/qwidget.cpp23
1 files changed, 4 insertions, 19 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index cccde764ad..70839e705f 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -7080,12 +7080,6 @@ void QWidgetPrivate::show_helper()
QShowEvent showEvent;
QApplication::sendEvent(q, &showEvent);
- if (!isEmbedded && q->isModal() && q->isWindow())
- // QApplicationPrivate::enterModal *before* show, otherwise the initial
- // stacking might be wrong
- QApplicationPrivate::enterModal(q);
-
-
show_sys();
if (!isEmbedded && q->windowType() == Qt::Popup)
@@ -7141,12 +7135,6 @@ void QWidgetPrivate::hide_helper()
if (!isEmbedded && (q->windowType() == Qt::Popup))
qApp->d_func()->closePopup(q);
- // Move test modal here. Otherwise, a modal dialog could get
- // destroyed and we lose all access to its parent because we haven't
- // left modality. (Eg. modal Progress Dialog)
- if (!isEmbedded && q->isModal() && q->isWindow())
- QApplicationPrivate::leaveModal(q);
-
#if defined(Q_WS_WIN)
if (q->isWindow() && !(q->windowType() == Qt::Popup) && q->parentWidget()
&& !q->parentWidget()->isHidden() && q->isActiveWindow())
@@ -10047,9 +10035,7 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
break;
case Qt::WA_ShowModal:
if (!on) {
- if (isVisible())
- QApplicationPrivate::leaveModal(this);
- // reset modality type to Modeless when clearing WA_ShowModal
+ // reset modality type to NonModal when clearing WA_ShowModal
data->window_modality = Qt::NonModal;
} else if (data->window_modality == Qt::NonModal) {
// determine the modality type if it hasn't been set prior
@@ -10067,10 +10053,9 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
data->window_modality = (w && w->testAttribute(Qt::WA_GroupLeader))
? Qt::WindowModal
: Qt::ApplicationModal;
- // Some window managers does not allow us to enter modal after the
- // window is showing. Therefore, to be consistent, we cannot call
- // QApplicationPrivate::enterModal(this) here. The window must be
- // hidden before changing modality.
+ // Some window managers do not allow us to enter modality after the
+ // window is visible.The window must be hidden before changing the
+ // windowModality property and then reshown.
}
if (testAttribute(Qt::WA_WState_Created)) {
// don't call setModal_sys() before create_sys()