windowmodality test: Allow exec() with ApplicationModal dialogs

Add a checkbox to the main window and dialog .ui files to allow
exec()ing ApplicationModal dialogs.

Change-Id: I4d8a4be136d0f6b688938a8020a6ebcc69a9dfe8
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
This commit is contained in:
Bradley T. Hughes 2012-03-28 08:04:26 +02:00 committed by Qt by Nokia
parent 6c45614cbe
commit 448b9c00be
3 changed files with 184 additions and 148 deletions

View File

@ -1,106 +1,125 @@
<ui version="4.0" > <?xml version="1.0" encoding="UTF-8"?>
<author></author> <ui version="4.0">
<comment></comment>
<exportmacro></exportmacro>
<class>Dialog</class> <class>Dialog</class>
<widget class="QDialog" name="Dialog" > <widget class="QDialog" name="Dialog">
<property name="geometry" > <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>565</width>
<height>420</height> <height>361</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle">
<string>Dialog</string> <string>Dialog</string>
</property> </property>
<layout class="QVBoxLayout" > <layout class="QVBoxLayout" name="verticalLayout">
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item> <item>
<widget class="QGroupBox" name="groupBox" > <widget class="QGroupBox" name="groupBox">
<property name="title" > <property name="title">
<string>Modality Types</string> <string>Select the type of dialog to create:</string>
</property> </property>
<layout class="QVBoxLayout" > <layout class="QGridLayout" name="gridLayout">
<property name="margin" > <item row="5" column="0">
<number>9</number> <widget class="QPushButton" name="siblingApplicationModalButton">
</property> <property name="text">
<property name="spacing" > <string>Sibling Application Modal Dialog</string>
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="modelessButton" >
<property name="text" >
<string>Modeless Dialog</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="1" column="0">
<widget class="QPushButton" name="modelessNoParentButton" > <widget class="QPushButton" name="windowModalButton">
<property name="text" > <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> <string>Window Modal Dialog</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="7" column="1">
<widget class="QPushButton" name="windowModalNoParentButton" > <widget class="QPushButton" name="applicationModalChildButton">
<property name="text" > <property name="text">
<string>Window Modal Dialog w/ no parent</string> <string>Application Modal Child Widget</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="2" column="0">
<widget class="QPushButton" name="windowModalChildButton" > <widget class="QPushButton" name="siblingWindowModalButton">
<property name="text" > <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> <string>Sibling Window Modal Dialog</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="0" column="1">
<widget class="QPushButton" name="applicationModalButton" > <widget class="QPushButton" name="modelessNoParentButton">
<property name="text" > <property name="text">
<string>Modeless Dialog (no parent)</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QPushButton" name="applicationModalButton">
<property name="text">
<string>Application Modal</string> <string>Application Modal</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="1" column="1">
<widget class="QPushButton" name="applicationModalNoParentButton" > <widget class="QPushButton" name="windowModalNoParentButton">
<property name="text" > <property name="text">
<string>Application Modal Dialog w/ no parent</string> <string>Window Modal Dialog (no parent)</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="7" column="0">
<widget class="QPushButton" name="applicationModalChildButton" > <widget class="QPushButton" name="windowModalChildButton">
<property name="text" > <property name="text">
<string>Application Modal Child Widget (hidden after 5 seconds)</string> <string>Window Modal Child Widget</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="4" column="1">
<widget class="QPushButton" name="siblingApplicationModalButton" > <widget class="QPushButton" name="applicationModalNoParentButton">
<property name="text" > <property name="text">
<string>Sibling Application Modal Dialog</string> <string>Application Modal Dialog (no parent)</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QLabel" name="modalChildWidgetInfoLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>Note: Modal Child Widgets are invisible and hidden after 5 seconds.</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="modelessButton">
<property name="text">
<string>Modeless Dialog</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="applicationModalUseExecCheckBox">
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>Application Modal Dialogs use exec()</string>
</property>
<property name="checked">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
@ -108,19 +127,13 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" > <layout class="QHBoxLayout">
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item> <item>
<spacer> <spacer>
<property name="orientation" > <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0">
<size> <size>
<width>131</width> <width>131</width>
<height>31</height> <height>31</height>
@ -129,8 +142,8 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="okButton" > <widget class="QPushButton" name="okButton">
<property name="text" > <property name="text">
<string>Close</string> <string>Close</string>
</property> </property>
</widget> </widget>
@ -139,7 +152,6 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<pixmapfunction></pixmapfunction>
<resources/> <resources/>
<connections> <connections>
<connection> <connection>
@ -148,11 +160,11 @@
<receiver>Dialog</receiver> <receiver>Dialog</receiver>
<slot>accept()</slot> <slot>accept()</slot>
<hints> <hints>
<hint type="sourcelabel" > <hint type="sourcelabel">
<x>397</x> <x>397</x>
<y>338</y> <y>338</y>
</hint> </hint>
<hint type="destinationlabel" > <hint type="destinationlabel">
<x>96</x> <x>96</x>
<y>254</y> <y>254</y>
</hint> </hint>

View File

@ -93,7 +93,10 @@ private:
Dialog *dialog = new Dialog(parent); Dialog *dialog = new Dialog(parent);
dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setWindowModality(windowModality); dialog->setWindowModality(windowModality);
dialog->show(); if (windowModality == Qt::ApplicationModal && applicationModalUseExecCheckBox->isChecked())
dialog->exec();
else
dialog->show();
} }
void newChildWidget(Qt::WindowModality windowModality) void newChildWidget(Qt::WindowModality windowModality)
{ {
@ -107,7 +110,7 @@ private:
bool event(QEvent *event) bool event(QEvent *event)
{ {
if (event->type() == QEvent::WindowBlocked) if (event->type() == QEvent::WindowBlocked)
setPalette(Qt::red); setPalette(Qt::darkGray);
else if (event->type() == QEvent::WindowUnblocked) else if (event->type() == QEvent::WindowUnblocked)
setPalette(QPalette()); setPalette(QPalette());
return QWidget::event(event); return QWidget::event(event);
@ -156,7 +159,10 @@ private:
Dialog *dialog = new Dialog(withParent ? this : 0); Dialog *dialog = new Dialog(withParent ? this : 0);
dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setWindowModality(windowModality); dialog->setWindowModality(windowModality);
dialog->show(); if (windowModality == Qt::ApplicationModal && applicationModalUseExecCheckBox->isChecked())
dialog->exec();
else
dialog->show();
} }
void newChildWidget(Qt::WindowModality windowModality) void newChildWidget(Qt::WindowModality windowModality)
{ {

View File

@ -1,106 +1,125 @@
<ui version="4.0" > <?xml version="1.0" encoding="UTF-8"?>
<author></author> <ui version="4.0">
<comment></comment>
<exportmacro></exportmacro>
<class>Widget</class> <class>Widget</class>
<widget class="QWidget" name="Widget" > <widget class="QWidget" name="Widget">
<property name="geometry" > <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>568</width> <width>558</width>
<height>473</height> <height>268</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QVBoxLayout" > <layout class="QVBoxLayout">
<property name="margin" >
<number>40</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item> <item>
<widget class="QGroupBox" name="groupBox" > <widget class="QGroupBox" name="groupBox">
<property name="title" > <property name="title">
<string>New Window Type</string> <string>Select the type of window to create:</string>
</property> </property>
<layout class="QVBoxLayout" > <layout class="QGridLayout" name="gridLayout">
<property name="margin" > <item row="0" column="0">
<number>8</number> <widget class="QPushButton" name="windowButton">
</property> <property name="text">
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="windowButton" >
<property name="text" >
<string>Window</string> <string>Window</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="0" column="1">
<widget class="QPushButton" name="groupLeaderButton" > <widget class="QPushButton" name="groupLeaderButton">
<property name="text" > <property name="text">
<string>Window (Group Leader)</string> <string>Window (Group Leader)</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="1" column="0">
<widget class="QPushButton" name="modelessButton" > <widget class="QPushButton" name="modelessButton">
<property name="text" > <property name="text">
<string>Modeless Dialog</string> <string>Modeless Dialog</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="1" column="1">
<widget class="QPushButton" name="modelessNoParentButton" > <widget class="QPushButton" name="modelessNoParentButton">
<property name="text" > <property name="text">
<string>Modeless Dialog w/ no parent</string> <string>Modeless Dialog (no parent)</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="2" column="0">
<widget class="QPushButton" name="windowModalButton" > <widget class="QPushButton" name="windowModalButton">
<property name="text" > <property name="text">
<string>Window Modal Dialog</string> <string>Window Modal Dialog</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="2" column="1">
<widget class="QPushButton" name="windowModalNoParentButton" > <widget class="QPushButton" name="windowModalNoParentButton">
<property name="text" > <property name="text">
<string>Window Modal Dialog w/ no parent</string> <string>Window Modal Dialog (no parent)</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="3" column="0" colspan="2">
<widget class="QPushButton" name="windowModalChildButton" > <widget class="QCheckBox" name="applicationModalUseExecCheckBox">
<property name="text" > <property name="font">
<string>Window Modal Child Widget (hidden after 5 seconds)</string> <font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>Application Modal Dialogs use exec()</string>
</property>
<property name="checked">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="4" column="0">
<widget class="QPushButton" name="applicationModalButton" > <widget class="QPushButton" name="applicationModalButton">
<property name="text" > <property name="text">
<string>Application Modal Dialog</string> <string>Application Modal Dialog</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="4" column="1">
<widget class="QPushButton" name="applicationModalNoParentButton" > <widget class="QPushButton" name="applicationModalNoParentButton">
<property name="text" > <property name="text">
<string>Application Modal Dialog w/ no parent</string> <string>Application Modal Dialog (no parent)</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="5" column="0" colspan="2">
<widget class="QPushButton" name="applicationModalChildButton" > <widget class="QLabel" name="modalChildWidgetInfoLabel">
<property name="text" > <property name="sizePolicy">
<string>Application Modal Child Widget (hidden after 5 seconds)</string> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>Note: Modal Child Widgets are invisible and hidden after 5 seconds.</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QPushButton" name="applicationModalChildButton">
<property name="text">
<string>Application Modal Child Widget</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QPushButton" name="windowModalChildButton">
<property name="text">
<string>Window Modal Child Widget</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -109,7 +128,6 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<pixmapfunction></pixmapfunction>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>