2012-03-27 10:05:41 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2015-01-28 08:44:43 +00:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
** Contact: http://www.qt.io/licensing/
|
2012-03-27 10:05:41 +00:00
|
|
|
**
|
2013-05-24 13:49:24 +00:00
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
2012-03-27 10:05:41 +00:00
|
|
|
**
|
2014-08-21 13:51:22 +00:00
|
|
|
** $QT_BEGIN_LICENSE:LGPL21$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see http://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at http://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2012-03-27 10:05:41 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-08-21 13:51:22 +00:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-03-27 10:05:41 +00:00
|
|
|
**
|
2015-01-28 08:44:43 +00:00
|
|
|
** As a special exception, The Qt Company gives you certain additional
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2012-03-27 10:05:41 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "ui_dialog.h"
|
|
|
|
#include "ui_widget.h"
|
|
|
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
#include <QtCore/QTimer>
|
2012-05-04 11:15:02 +00:00
|
|
|
#include <QColorDialog>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QFontDialog>
|
|
|
|
#include <QPageSetupDialog>
|
|
|
|
#include <QPrintDialog>
|
2012-03-27 10:05:41 +00:00
|
|
|
|
2012-03-29 12:16:02 +00:00
|
|
|
enum DialogType
|
|
|
|
{
|
|
|
|
CustomDialogType,
|
|
|
|
ColorDialogType,
|
|
|
|
FileDialogType,
|
|
|
|
FontDialogType,
|
|
|
|
PageSetupDialogType,
|
|
|
|
PrintDialogType
|
|
|
|
};
|
|
|
|
|
|
|
|
class CustomDialog : public QDialog, public Ui::Dialog
|
2012-03-27 10:05:41 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2012-03-29 12:16:02 +00:00
|
|
|
CustomDialog(QWidget *parent = 0)
|
2012-03-27 10:05:41 +00:00
|
|
|
: QDialog(parent)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
2012-03-29 12:16:02 +00:00
|
|
|
|
|
|
|
// hide the "Create new dialogs as siblings of this dialog" button when
|
|
|
|
// we don't have a parent of our own (they would be parentless anyway)
|
|
|
|
if (!parent) {
|
|
|
|
createSiblingDialogCheckBox->setChecked(false);
|
|
|
|
createSiblingDialogCheckBox->setVisible(false);
|
|
|
|
}
|
2012-03-27 10:05:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private slots:
|
2012-03-29 12:16:02 +00:00
|
|
|
void on_modelessCustomDialogButton_clicked()
|
|
|
|
{ newDialog(CustomDialogType, Qt::NonModal); }
|
|
|
|
void on_modelessColorDialogButton_clicked()
|
|
|
|
{ newDialog(ColorDialogType, Qt::NonModal); }
|
|
|
|
void on_modelessFontDialogButton_clicked()
|
|
|
|
{ newDialog(FontDialogType, Qt::NonModal); }
|
|
|
|
|
|
|
|
void on_windowModalCustomDialogButton_clicked()
|
|
|
|
{ newDialog(CustomDialogType, Qt::WindowModal); }
|
|
|
|
void on_windowModalColorDialogButton_clicked()
|
|
|
|
{ newDialog(ColorDialogType, Qt::WindowModal); }
|
|
|
|
void on_windowModalFileDialogButton_clicked()
|
|
|
|
{ newDialog(FileDialogType, Qt::WindowModal); }
|
|
|
|
void on_windowModalFontDialogButton_clicked()
|
|
|
|
{ newDialog(FontDialogType, Qt::WindowModal); }
|
|
|
|
void on_windowModalPageSetupDialogButton_clicked()
|
|
|
|
{ newDialog(PageSetupDialogType, Qt::WindowModal); }
|
|
|
|
void on_windowModalPrintDialogButton_clicked()
|
|
|
|
{ newDialog(PrintDialogType, Qt::WindowModal); }
|
|
|
|
|
|
|
|
void on_applicationModalCustomDialogButton_clicked()
|
|
|
|
{ newDialog(CustomDialogType, Qt::ApplicationModal); }
|
|
|
|
void on_applicationModalColorDialogButton_clicked()
|
|
|
|
{ newDialog(ColorDialogType, Qt::ApplicationModal); }
|
|
|
|
void on_applicationModalFileDialogButton_clicked()
|
|
|
|
{ newDialog(FileDialogType, Qt::ApplicationModal); }
|
|
|
|
void on_applicationModalFontDialogButton_clicked()
|
|
|
|
{ newDialog(FontDialogType, Qt::ApplicationModal); }
|
|
|
|
void on_applicationModalPageSetupDialogButton_clicked()
|
|
|
|
{ newDialog(PageSetupDialogType, Qt::ApplicationModal); }
|
|
|
|
void on_applicationModalPrintDialogButton_clicked()
|
|
|
|
{ newDialog(PrintDialogType, Qt::ApplicationModal); }
|
2012-03-27 10:05:41 +00:00
|
|
|
|
|
|
|
private:
|
2012-03-29 12:16:02 +00:00
|
|
|
void newDialog(DialogType dialogType, Qt::WindowModality windowModality)
|
2012-03-27 10:05:41 +00:00
|
|
|
{
|
2012-03-29 12:16:02 +00:00
|
|
|
QWidget *parent = 0;
|
|
|
|
if (useThisAsParentCheckBox->isChecked())
|
|
|
|
parent = this;
|
|
|
|
else if (createSiblingDialogCheckBox->isChecked())
|
|
|
|
parent = parentWidget();
|
|
|
|
|
|
|
|
QDialog *dialog;
|
|
|
|
switch (dialogType) {
|
|
|
|
case CustomDialogType:
|
|
|
|
dialog = new CustomDialog(parent);
|
|
|
|
break;
|
|
|
|
case ColorDialogType:
|
|
|
|
if (windowModality == Qt::ApplicationModal && applicationModalUseExecCheckBox->isChecked()) {
|
|
|
|
QColorDialog::getColor(Qt::white, parent);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dialog = new QColorDialog(parent);
|
|
|
|
break;
|
|
|
|
case FileDialogType:
|
|
|
|
if (windowModality == Qt::ApplicationModal && applicationModalUseExecCheckBox->isChecked()) {
|
|
|
|
QFileDialog::getOpenFileName(parent);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dialog = new QFileDialog(parent);
|
|
|
|
break;
|
|
|
|
case FontDialogType:
|
|
|
|
if (windowModality == Qt::ApplicationModal && applicationModalUseExecCheckBox->isChecked()) {
|
|
|
|
bool unused = false;
|
|
|
|
QFontDialog::getFont(&unused, parent);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dialog = new QFontDialog(parent);
|
|
|
|
break;
|
|
|
|
case PageSetupDialogType:
|
|
|
|
dialog = new QPageSetupDialog(parent);
|
|
|
|
break;
|
|
|
|
case PrintDialogType:
|
|
|
|
dialog = new QPrintDialog(parent);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-27 10:05:41 +00:00
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
dialog->setWindowModality(windowModality);
|
2012-03-29 12:16:02 +00:00
|
|
|
|
2012-03-28 06:04:26 +00:00
|
|
|
if (windowModality == Qt::ApplicationModal && applicationModalUseExecCheckBox->isChecked())
|
|
|
|
dialog->exec();
|
2012-03-29 12:16:02 +00:00
|
|
|
else if (windowModality == Qt::WindowModal)
|
|
|
|
dialog->open();
|
2012-03-28 06:04:26 +00:00
|
|
|
else
|
|
|
|
dialog->show();
|
2012-03-27 10:05:41 +00:00
|
|
|
}
|
|
|
|
bool event(QEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::WindowBlocked)
|
2012-03-28 06:04:26 +00:00
|
|
|
setPalette(Qt::darkGray);
|
2012-03-27 10:05:41 +00:00
|
|
|
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();
|
|
|
|
}
|
2012-03-29 12:16:02 +00:00
|
|
|
|
|
|
|
void on_modelessCustomDialogButton_clicked()
|
|
|
|
{ newDialog(CustomDialogType, Qt::NonModal); }
|
|
|
|
void on_modelessColorDialogButton_clicked()
|
|
|
|
{ newDialog(ColorDialogType, Qt::NonModal); }
|
|
|
|
void on_modelessFontDialogButton_clicked()
|
|
|
|
{ newDialog(FontDialogType, Qt::NonModal); }
|
|
|
|
|
|
|
|
void on_windowModalCustomDialogButton_clicked()
|
|
|
|
{ newDialog(CustomDialogType, Qt::WindowModal); }
|
|
|
|
void on_windowModalColorDialogButton_clicked()
|
|
|
|
{ newDialog(ColorDialogType, Qt::WindowModal); }
|
|
|
|
void on_windowModalFileDialogButton_clicked()
|
|
|
|
{ newDialog(FileDialogType, Qt::WindowModal); }
|
|
|
|
void on_windowModalFontDialogButton_clicked()
|
|
|
|
{ newDialog(FontDialogType, Qt::WindowModal); }
|
|
|
|
void on_windowModalPageSetupDialogButton_clicked()
|
|
|
|
{ newDialog(PageSetupDialogType, Qt::WindowModal); }
|
|
|
|
void on_windowModalPrintDialogButton_clicked()
|
|
|
|
{ newDialog(PrintDialogType, Qt::WindowModal); }
|
|
|
|
|
|
|
|
void on_applicationModalCustomDialogButton_clicked()
|
|
|
|
{ newDialog(CustomDialogType, Qt::ApplicationModal); }
|
|
|
|
void on_applicationModalColorDialogButton_clicked()
|
|
|
|
{ newDialog(ColorDialogType, Qt::ApplicationModal); }
|
|
|
|
void on_applicationModalFileDialogButton_clicked()
|
|
|
|
{ newDialog(FileDialogType, Qt::ApplicationModal); }
|
|
|
|
void on_applicationModalFontDialogButton_clicked()
|
|
|
|
{ newDialog(FontDialogType, Qt::ApplicationModal); }
|
|
|
|
void on_applicationModalPageSetupDialogButton_clicked()
|
|
|
|
{ newDialog(PageSetupDialogType, Qt::ApplicationModal); }
|
|
|
|
void on_applicationModalPrintDialogButton_clicked()
|
|
|
|
{ newDialog(PrintDialogType, Qt::ApplicationModal); }
|
2012-03-27 10:05:41 +00:00
|
|
|
|
|
|
|
private:
|
2012-03-29 12:16:02 +00:00
|
|
|
void newDialog(DialogType dialogType, Qt::WindowModality windowModality)
|
2012-03-27 10:05:41 +00:00
|
|
|
{
|
2012-03-29 12:16:02 +00:00
|
|
|
QWidget *parent = 0;
|
|
|
|
if (useThisAsParentCheckBox->isChecked())
|
|
|
|
parent = this;
|
|
|
|
|
|
|
|
QDialog *dialog;
|
|
|
|
switch (dialogType) {
|
|
|
|
case CustomDialogType:
|
|
|
|
dialog = new CustomDialog(parent);
|
|
|
|
break;
|
|
|
|
case ColorDialogType:
|
|
|
|
if (windowModality == Qt::ApplicationModal && applicationModalUseExecCheckBox->isChecked()) {
|
|
|
|
QColorDialog::getColor(Qt::white, parent);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dialog = new QColorDialog(parent);
|
|
|
|
break;
|
|
|
|
case FileDialogType:
|
|
|
|
if (windowModality == Qt::ApplicationModal && applicationModalUseExecCheckBox->isChecked()) {
|
|
|
|
QFileDialog::getOpenFileName(parent);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dialog = new QFileDialog(parent);
|
|
|
|
break;
|
|
|
|
case FontDialogType:
|
|
|
|
if (windowModality == Qt::ApplicationModal && applicationModalUseExecCheckBox->isChecked()) {
|
|
|
|
bool unused = false;
|
|
|
|
QFontDialog::getFont(&unused, parent);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dialog = new QFontDialog(parent);
|
|
|
|
break;
|
|
|
|
case PageSetupDialogType:
|
|
|
|
dialog = new QPageSetupDialog(parent);
|
|
|
|
break;
|
|
|
|
case PrintDialogType:
|
|
|
|
dialog = new QPrintDialog(parent);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-27 10:05:41 +00:00
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
dialog->setWindowModality(windowModality);
|
2012-03-29 12:16:02 +00:00
|
|
|
|
2012-03-28 06:04:26 +00:00
|
|
|
if (windowModality == Qt::ApplicationModal && applicationModalUseExecCheckBox->isChecked())
|
|
|
|
dialog->exec();
|
2012-03-29 12:16:02 +00:00
|
|
|
else if (windowModality == Qt::WindowModal)
|
|
|
|
dialog->open();
|
2012-03-28 06:04:26 +00:00
|
|
|
else
|
|
|
|
dialog->show();
|
2012-03-27 10:05:41 +00:00
|
|
|
}
|
|
|
|
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"
|