From f05cc4144e06fd06eed12a3e427eb49e7ad1cf85 Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Tue, 18 Dec 2018 16:49:20 +0300 Subject: QDialog: Pass transient parent as a parent to native dialogs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sometimes it's needed to show a native dialog for another process, for example in xdg-desktop-portal-kde. In this case we have WId of a parent window which can be used for calling QWindow::setTransientParent(QWindow::fromWinId(...)). Pass this transient parent to a native dialog so it could use it as a transient parent for itself. Rename QDialogPrivate::parentWindow() for clarity. Change-Id: I68974ddea35f9366a0ddffe602d9d028f45e26fa Reviewed-by: Tor Arne Vestbø --- src/widgets/dialogs/qdialog.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/widgets/dialogs/qdialog.cpp') diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp index 06f0393b4c..6f96018f3e 100644 --- a/src/widgets/dialogs/qdialog.cpp +++ b/src/widgets/dialogs/qdialog.cpp @@ -145,10 +145,13 @@ bool QDialogPrivate::canBeNativeDialog() const return false; } -QWindow *QDialogPrivate::parentWindow() const +QWindow *QDialogPrivate::transientParentWindow() const { - if (const QWidget *parent = q_func()->nativeParentWidget()) + Q_Q(const QDialog); + if (const QWidget *parent = q->nativeParentWidget()) return parent->windowHandle(); + else if (q->windowHandle()) + return q->windowHandle()->transientParent(); return 0; } @@ -158,7 +161,7 @@ bool QDialogPrivate::setNativeDialogVisible(bool visible) if (visible) { Q_Q(QDialog); helperPrepareShow(helper); - nativeDialogInUse = helper->show(q->windowFlags(), q->windowModality(), parentWindow()); + nativeDialogInUse = helper->show(q->windowFlags(), q->windowModality(), transientParentWindow()); } else if (nativeDialogInUse) { helper->hide(); } -- cgit v1.2.3 From d8bbb5ee0e60d44a70d29306e607a59caf7fe5bc Mon Sep 17 00:00:00 2001 From: Vitaly Fanaskov Date: Fri, 7 Dec 2018 16:04:33 +0100 Subject: Respect roles of buttons added to QMessageBox MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a button added to QMessageBox has AcceptRole or YesRole, the signal accepted() will be emitted upon click on the button. If the button has RejectRole or NoRole, the signal rejected() will be emitted upon click on the button. If a button has a different role, neither accepted() nor rejected() will be emitted. This works for both standard and custom buttons. The signal finished() with result code will be sent regardless of a clicked button role. Also added documentation strings for some methods of private classes in order to have better tooltips in IDE(s). Task-number: QTBUG-44131 Change-Id: I521a4e5112eb4cf168f6fbb4c002dbe119aeeb09 Reviewed-by: Tor Arne Vestbø --- src/widgets/dialogs/qdialog.cpp | 48 +++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 11 deletions(-) (limited to 'src/widgets/dialogs/qdialog.cpp') diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp index 6f96018f3e..1fb5e61301 100644 --- a/src/widgets/dialogs/qdialog.cpp +++ b/src/widgets/dialogs/qdialog.cpp @@ -145,6 +145,41 @@ bool QDialogPrivate::canBeNativeDialog() const return false; } +/*! + \internal + + Properly hides dialog and sets the \p resultCode + */ +void QDialogPrivate::hide(int resultCode) +{ + Q_Q(QDialog); + + q->setResult(resultCode); + q->hide(); + + close_helper(QWidgetPrivate::CloseNoEvent); + resetModalitySetByOpen(); +} + +/*! + \internal + + Emits finished() signal with \p resultCode. If the \p dialogCode + is equal to 0 emits rejected(), if the \p dialogCode is equal to + 1 emits accepted(). + */ +void QDialogPrivate::finalize(int resultCode, int dialogCode) +{ + Q_Q(QDialog); + + if (dialogCode == QDialog::Accepted) + emit q->accepted(); + else if (dialogCode == QDialog::Rejected) + emit q->rejected(); + + emit q->finished(resultCode); +} + QWindow *QDialogPrivate::transientParentWindow() const { Q_Q(const QDialog); @@ -593,17 +628,8 @@ int QDialog::exec() void QDialog::done(int r) { Q_D(QDialog); - setResult(r); - hide(); - - d->close_helper(QWidgetPrivate::CloseNoEvent); - d->resetModalitySetByOpen(); - - emit finished(r); - if (r == Accepted) - emit accepted(); - else if (r == Rejected) - emit rejected(); + d->hide(r); + d->finalize(r, r); } /*! -- cgit v1.2.3