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 <Friedemann.Kleint@nokia.com>
This commit is contained in:
Bradley T. Hughes 2012-03-27 12:05:41 +02:00 committed by Qt by Nokia
parent 798ccb30cf
commit aea0b24d69
4 changed files with 468 additions and 0 deletions

View File

@ -0,0 +1,162 @@
<ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<class>Dialog</class>
<widget class="QDialog" name="Dialog" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>420</height>
</rect>
</property>
<property name="windowTitle" >
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox" >
<property name="title" >
<string>Modality Types</string>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="modelessButton" >
<property name="text" >
<string>Modeless Dialog</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="modelessNoParentButton" >
<property name="text" >
<string>Modeless Dialog w/ no parent</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="windowModalButton" >
<property name="text" >
<string>Window Modal Dialog</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="windowModalNoParentButton" >
<property name="text" >
<string>Window Modal Dialog w/ no parent</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="windowModalChildButton" >
<property name="text" >
<string>Window Modal Child Widget (hidden after 5 seconds)</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="siblingWindowModalButton" >
<property name="text" >
<string>Sibling Window Modal Dialog</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="applicationModalButton" >
<property name="text" >
<string>Application Modal</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="applicationModalNoParentButton" >
<property name="text" >
<string>Application Modal Dialog w/ no parent</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="applicationModalChildButton" >
<property name="text" >
<string>Application Modal Child Widget (hidden after 5 seconds)</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="siblingApplicationModalButton" >
<property name="text" >
<string>Sibling Application Modal Dialog</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>131</width>
<height>31</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okButton" >
<property name="text" >
<string>Close</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<pixmapfunction></pixmapfunction>
<resources/>
<connections>
<connection>
<sender>okButton</sender>
<signal>clicked()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<x>397</x>
<y>338</y>
</hint>
<hint type="destinationlabel" >
<x>96</x>
<y>254</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -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 <QtCore/QDebug>
#include <QtCore/QTimer>
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"

View File

@ -0,0 +1,3 @@
SOURCES = main.cpp
FORMS = widget.ui dialog.ui
QT += widgets

View File

@ -0,0 +1,115 @@
<ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<class>Widget</class>
<widget class="QWidget" name="Widget" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>568</width>
<height>473</height>
</rect>
</property>
<property name="windowTitle" >
<string>Form</string>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>40</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox" >
<property name="title" >
<string>New Window Type</string>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>8</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="windowButton" >
<property name="text" >
<string>Window</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="groupLeaderButton" >
<property name="text" >
<string>Window (Group Leader)</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="modelessButton" >
<property name="text" >
<string>Modeless Dialog</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="modelessNoParentButton" >
<property name="text" >
<string>Modeless Dialog w/ no parent</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="windowModalButton" >
<property name="text" >
<string>Window Modal Dialog</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="windowModalNoParentButton" >
<property name="text" >
<string>Window Modal Dialog w/ no parent</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="windowModalChildButton" >
<property name="text" >
<string>Window Modal Child Widget (hidden after 5 seconds)</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="applicationModalButton" >
<property name="text" >
<string>Application Modal Dialog</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="applicationModalNoParentButton" >
<property name="text" >
<string>Application Modal Dialog w/ no parent</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="applicationModalChildButton" >
<property name="text" >
<string>Application Modal Child Widget (hidden after 5 seconds)</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<pixmapfunction></pixmapfunction>
<resources/>
<connections/>
</ui>