From aea0b24d69253285e23bbc2eeaac29b5d19cd868 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Tue, 27 Mar 2012 12:05:41 +0200 Subject: [PATCH] Add manual test for window modality This test allows us to recreate any modal scenario. Multiple top-level windows with any depth of window and application modal dialogs is possible. Change-Id: Ieef2c557d2f9ad2d2b2d2b598e9415f4c1e2dcb5 Reviewed-by: Friedemann Kleint --- tests/manual/windowmodality/dialog.ui | 162 +++++++++++++++++++ tests/manual/windowmodality/main.cpp | 188 +++++++++++++++++++++++ tests/manual/windowmodality/modality.pro | 3 + tests/manual/windowmodality/widget.ui | 115 ++++++++++++++ 4 files changed, 468 insertions(+) create mode 100644 tests/manual/windowmodality/dialog.ui create mode 100644 tests/manual/windowmodality/main.cpp create mode 100644 tests/manual/windowmodality/modality.pro create mode 100644 tests/manual/windowmodality/widget.ui diff --git a/tests/manual/windowmodality/dialog.ui b/tests/manual/windowmodality/dialog.ui new file mode 100644 index 00000000000..91c6bf2dc92 --- /dev/null +++ b/tests/manual/windowmodality/dialog.ui @@ -0,0 +1,162 @@ + + + + + Dialog + + + + 0 + 0 + 400 + 420 + + + + Dialog + + + + 9 + + + 6 + + + + + Modality Types + + + + 9 + + + 6 + + + + + Modeless Dialog + + + + + + + Modeless Dialog w/ no parent + + + + + + + Window Modal Dialog + + + + + + + Window Modal Dialog w/ no parent + + + + + + + Window Modal Child Widget (hidden after 5 seconds) + + + + + + + Sibling Window Modal Dialog + + + + + + + Application Modal + + + + + + + Application Modal Dialog w/ no parent + + + + + + + Application Modal Child Widget (hidden after 5 seconds) + + + + + + + Sibling Application Modal Dialog + + + + + + + + + + 0 + + + 6 + + + + + Qt::Horizontal + + + + 131 + 31 + + + + + + + + Close + + + + + + + + + + + + okButton + clicked() + Dialog + accept() + + + 397 + 338 + + + 96 + 254 + + + + + diff --git a/tests/manual/windowmodality/main.cpp b/tests/manual/windowmodality/main.cpp new file mode 100644 index 00000000000..db3a0b072f6 --- /dev/null +++ b/tests/manual/windowmodality/main.cpp @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "ui_dialog.h" +#include "ui_widget.h" + +#include +#include + +class Dialog : public QDialog, public Ui::Dialog +{ + Q_OBJECT +public: + Dialog(QWidget *parent = 0) + : QDialog(parent) + { + setupUi(this); + connect(this, SIGNAL(finished(int)), SLOT(dialogFinished(int))); + connect(this, SIGNAL(accepted()), SLOT(dialogAccepted())); + connect(this, SIGNAL(rejected()), SLOT(dialogRejected())); + } + +private slots: + void on_modelessButton_clicked() + { newDialog(Qt::NonModal, this); } + void on_modelessNoParentButton_clicked() + { newDialog(Qt::NonModal, 0); } + void on_windowModalButton_clicked() + { newDialog(Qt::WindowModal, this); } + void on_windowModalNoParentButton_clicked() + { newDialog(Qt::WindowModal, 0); } + void on_windowModalChildButton_clicked() + { newChildWidget(Qt::WindowModal); } + void on_siblingWindowModalButton_clicked() + { newDialog(Qt::WindowModal, parentWidget()); } + void on_applicationModalButton_clicked() + { newDialog(Qt::ApplicationModal, this); } + void on_applicationModalNoParentButton_clicked() + { newDialog(Qt::ApplicationModal, 0); } + void on_applicationModalChildButton_clicked() + { newChildWidget(Qt::ApplicationModal); } + void on_siblingApplicationModalButton_clicked() + { newDialog(Qt::ApplicationModal, parentWidget()); } + + void dialogFinished(int result) + { qDebug() << "Dialog finished, result" << result; } + void dialogAccepted() + { qDebug() << "Dialog accepted"; } + void dialogRejected() + { qDebug() << "Dialog rejected"; } + +private: + void newDialog(Qt::WindowModality windowModality, QWidget *parent) + { + Dialog *dialog = new Dialog(parent); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->setWindowModality(windowModality); + dialog->show(); + } + void newChildWidget(Qt::WindowModality windowModality) + { + QWidget *w = new QWidget(this); + w->setAttribute(Qt::WA_DeleteOnClose); + w->setWindowModality(windowModality); + w->setGeometry(0, 0, 0, 0); + w->show(); + QTimer::singleShot(5000, w, SLOT(close())); + } + bool event(QEvent *event) + { + if (event->type() == QEvent::WindowBlocked) + setPalette(Qt::red); + else if (event->type() == QEvent::WindowUnblocked) + setPalette(QPalette()); + return QWidget::event(event); + } +}; + +class Widget : public QWidget, public Ui::Widget +{ + Q_OBJECT +public: + Widget(QWidget *parent = 0) + : QWidget(parent) + { + setupUi(this); + } + +private slots: + void on_windowButton_clicked() + { (new Widget)->show(); } + void on_groupLeaderButton_clicked() + { + Widget *w = new Widget; + w->setAttribute(Qt::WA_GroupLeader); + w->show(); + } + void on_modelessButton_clicked() + { newDialog(Qt::NonModal); } + void on_modelessNoParentButton_clicked() + { newDialog(Qt::NonModal, false); } + void on_windowModalButton_clicked() + { newDialog(Qt::WindowModal); } + void on_windowModalNoParentButton_clicked() + { newDialog(Qt::WindowModal, false); } + void on_windowModalChildButton_clicked() + { newChildWidget(Qt::WindowModal); } + void on_applicationModalButton_clicked() + { newDialog(Qt::ApplicationModal); } + void on_applicationModalNoParentButton_clicked() + { newDialog(Qt::ApplicationModal, false); } + void on_applicationModalChildButton_clicked() + { newChildWidget(Qt::ApplicationModal); } + +private: + void newDialog(Qt::WindowModality windowModality, bool withParent = true) + { + Dialog *dialog = new Dialog(withParent ? this : 0); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->setWindowModality(windowModality); + dialog->show(); + } + void newChildWidget(Qt::WindowModality windowModality) + { + QWidget *w = new QWidget(this); + w->setAttribute(Qt::WA_DeleteOnClose); + w->setWindowModality(windowModality); + w->setGeometry(0, 0, 0, 0); + w->show(); + QTimer::singleShot(5000, w, SLOT(close())); + } + bool event(QEvent *event) + { + if (event->type() == QEvent::WindowBlocked) + setPalette(Qt::darkGray); + else if (event->type() == QEvent::WindowUnblocked) + setPalette(QPalette()); + return QWidget::event(event); + } +}; + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + Widget widget; + widget.show(); + return app.exec(); +} + +#include "main.moc" diff --git a/tests/manual/windowmodality/modality.pro b/tests/manual/windowmodality/modality.pro new file mode 100644 index 00000000000..7bed916c361 --- /dev/null +++ b/tests/manual/windowmodality/modality.pro @@ -0,0 +1,3 @@ +SOURCES = main.cpp +FORMS = widget.ui dialog.ui +QT += widgets diff --git a/tests/manual/windowmodality/widget.ui b/tests/manual/windowmodality/widget.ui new file mode 100644 index 00000000000..cc3bf854ec9 --- /dev/null +++ b/tests/manual/windowmodality/widget.ui @@ -0,0 +1,115 @@ + + + + + Widget + + + + 0 + 0 + 568 + 473 + + + + Form + + + + 40 + + + 6 + + + + + New Window Type + + + + 8 + + + 6 + + + + + Window + + + + + + + Window (Group Leader) + + + + + + + Modeless Dialog + + + + + + + Modeless Dialog w/ no parent + + + + + + + Window Modal Dialog + + + + + + + Window Modal Dialog w/ no parent + + + + + + + Window Modal Child Widget (hidden after 5 seconds) + + + + + + + Application Modal Dialog + + + + + + + Application Modal Dialog w/ no parent + + + + + + + Application Modal Child Widget (hidden after 5 seconds) + + + + + + + + + + + +