diff options
Diffstat (limited to 'tests/manual/dialogs')
-rw-r--r-- | tests/manual/dialogs/colordialogpanel.cpp | 261 | ||||
-rw-r--r-- | tests/manual/dialogs/colordialogpanel.h | 86 | ||||
-rw-r--r-- | tests/manual/dialogs/dialogs.pro | 6 | ||||
-rw-r--r-- | tests/manual/dialogs/filedialogpanel.cpp | 105 | ||||
-rw-r--r-- | tests/manual/dialogs/filedialogpanel.h | 13 | ||||
-rw-r--r-- | tests/manual/dialogs/fontdialogpanel.cpp | 208 | ||||
-rw-r--r-- | tests/manual/dialogs/fontdialogpanel.h | 87 | ||||
-rw-r--r-- | tests/manual/dialogs/main.cpp | 7 | ||||
-rw-r--r-- | tests/manual/dialogs/wizardpanel.cpp | 361 | ||||
-rw-r--r-- | tests/manual/dialogs/wizardpanel.h | 69 |
10 files changed, 1178 insertions, 25 deletions
diff --git a/tests/manual/dialogs/colordialogpanel.cpp b/tests/manual/dialogs/colordialogpanel.cpp new file mode 100644 index 0000000000..695e37a4c7 --- /dev/null +++ b/tests/manual/dialogs/colordialogpanel.cpp @@ -0,0 +1,261 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "colordialogpanel.h" + +#include <QGroupBox> +#include <QCheckBox> +#include <QPushButton> +#include <QVBoxLayout> +#include <QHBoxLayout> +#include <QMessageBox> +#include <QSortFilterProxyModel> +#include <QComboBox> +#include <QTimer> +#include <QDebug> + +// SVG color keyword names provided by the World Wide Web Consortium +static inline QStringList svgColorNames() +{ + return QStringList() + << "aliceblue" << "antiquewhite" << "aqua" << "aquamarine" << "azure" << "beige" << "bisque" + << "black" << "blanchedalmond" << "blue" << "blueviolet" << "brown" << "burlywood" << "cadetblue" + << "chartreuse" << "chocolate" << "coral" << "cornflowerblue" << "cornsilk" << "crimson" << "cyan" + << "darkblue" << "darkcyan" << "darkgoldenrod" << "darkgray" << "darkgreen" << "darkgrey" + << "darkkhaki" << "darkmagenta" << "darkolivegreen" << "darkorange" << "darkorchid" << "darkred" + << "darksalmon" << "darkseagreen" << "darkslateblue" << "darkslategray" << "darkslategrey" + << "darkturquoise" << "darkviolet" << "deeppink" << "deepskyblue" << "dimgray" << "dimgrey" + << "dodgerblue" << "firebrick" << "floralwhite" << "forestgreen" << "fuchsia" << "gainsboro" + << "ghostwhite" << "gold" << "goldenrod" << "gray" << "grey" << "green" << "greenyellow" + << "honeydew" << "hotpink" << "indianred" << "indigo" << "ivory" << "khaki" << "lavender" + << "lavenderblush" << "lawngreen" << "lemonchiffon" << "lightblue" << "lightcoral" << "lightcyan" + << "lightgoldenrodyellow" << "lightgray" << "lightgreen" << "lightgrey" << "lightpink" + << "lightsalmon" << "lightseagreen" << "lightskyblue" << "lightslategray" << "lightslategrey" + << "lightsteelblue" << "lightyellow" << "lime" << "limegreen" << "linen" << "magenta" + << "maroon" << "mediumaquamarine" << "mediumblue" << "mediumorchid" << "mediumpurple" + << "mediumseagreen" << "mediumslateblue" << "mediumspringgreen" << "mediumturquoise" + << "mediumvioletred" << "midnightblue" << "mintcream" << "mistyrose" << "moccasin" + << "navajowhite" << "navy" << "oldlace" << "olive" << "olivedrab" << "orange" << "orangered" + << "orchid" << "palegoldenrod" << "palegreen" << "paleturquoise" << "palevioletred" + << "papayawhip" << "peachpuff" << "peru" << "pink" << "plum" << "powderblue" << "purple" << "red" + << "rosybrown" << "royalblue" << "saddlebrown" << "salmon" << "sandybrown" << "seagreen" + << "seashell" << "sienna" << "silver" << "skyblue" << "slateblue" << "slategray" << "slategrey" + << "snow" << "springgreen" << "steelblue" << "tan" << "teal" << "thistle" << "tomato" + << "turquoise" << "violet" << "wheat" << "white" << "whitesmoke" << "yellow" << "yellowgreen"; +} + +static inline QPushButton *addButton(const QString &description, QVBoxLayout *layout, + QObject *receiver, const char *slotFunc) +{ + QPushButton *button = new QPushButton(description); + QObject::connect(button, SIGNAL(clicked()), receiver, slotFunc); + layout->addWidget(button); + return button; +} + +class ColorProxyModel : public QSortFilterProxyModel +{ +public: + ColorProxyModel(QObject *parent = 0) : QSortFilterProxyModel(parent) + { + } + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const + { + if (role == Qt::DisplayRole) { + QString name = data(index, Qt::EditRole).toString(); + return tr("%1 (%2)").arg(name, QColor(name).name()); + } + if (role == Qt::DecorationRole) + return QColor(data(index, Qt::EditRole).toString()); + return QSortFilterProxyModel::data(index, role); + } +}; + +ColorDialogPanel::ColorDialogPanel(QWidget *parent) + : QWidget(parent) + , m_colorComboBox(new QComboBox) + , m_showAlphaChannel(new QCheckBox(tr("Show alpha channel"))) + , m_noButtons(new QCheckBox(tr("Don't display OK/Cancel buttons"))) + , m_dontUseNativeDialog(new QCheckBox(tr("Don't use native dialog"))) +{ + // Options + QGroupBox *optionsGroupBox = new QGroupBox(tr("Options"), this); + QVBoxLayout *optionsLayout = new QVBoxLayout(optionsGroupBox); + optionsLayout->addWidget(m_showAlphaChannel); + optionsLayout->addWidget(m_noButtons); + optionsLayout->addWidget(m_dontUseNativeDialog); + + // Color + QGroupBox *colorGroupBox = new QGroupBox(tr("Color"), this); + QVBoxLayout *colorLayout = new QVBoxLayout(colorGroupBox); + colorLayout->addWidget(m_colorComboBox); + m_colorComboBox->addItems(svgColorNames()); + m_colorComboBox->setEditable(true); + + QAbstractItemModel *sourceModel = m_colorComboBox->model(); + ColorProxyModel* proxyModel = new ColorProxyModel(m_colorComboBox); + proxyModel->setSourceModel(sourceModel); + sourceModel->setParent(proxyModel); + m_colorComboBox->setModel(proxyModel); + + // Buttons + QGroupBox *buttonsGroupBox = new QGroupBox(tr("Show")); + QVBoxLayout *buttonsLayout = new QVBoxLayout(buttonsGroupBox); + addButton(tr("Exec modal"), buttonsLayout, this, SLOT(execModal())); + addButton(tr("Show modal"), buttonsLayout, this, SLOT(showModal())); + m_deleteModalDialogButton = + addButton(tr("Delete modal"), buttonsLayout, this, SLOT(deleteModalDialog())); + addButton(tr("Show non-modal"), buttonsLayout, this, SLOT(showNonModal())); + m_deleteNonModalDialogButton = + addButton(tr("Delete non-modal"), buttonsLayout, this, SLOT(deleteNonModalDialog())); + addButton(tr("Restore defaults"), buttonsLayout, this, SLOT(restoreDefaults())); + buttonsLayout->addStretch(); + + // Main layout + QHBoxLayout *mainLayout = new QHBoxLayout(this); + QVBoxLayout *leftLayout = new QVBoxLayout; + leftLayout->addWidget(optionsGroupBox); + leftLayout->addWidget(colorGroupBox); + leftLayout->addStretch(); + mainLayout->addLayout(leftLayout); + mainLayout->addWidget(buttonsGroupBox); + + enableDeleteModalDialogButton(); + enableDeleteNonModalDialogButton(); + restoreDefaults(); +} + +void ColorDialogPanel::execModal() +{ + QColorDialog dialog(this); + applySettings(&dialog); + connect(&dialog, SIGNAL(accepted()), this, SLOT(accepted())); + dialog.setWindowTitle(tr("Modal Color Dialog Qt %1").arg(QLatin1String(QT_VERSION_STR))); + dialog.exec(); +} + +void ColorDialogPanel::showModal() +{ + if (m_modalDialog.isNull()) { + static int n = 0; + m_modalDialog = new QColorDialog(this); + m_modalDialog->setModal(true); + connect(m_modalDialog.data(), SIGNAL(accepted()), this, SLOT(accepted())); + m_modalDialog->setWindowTitle(tr("Modal Color Dialog #%1 Qt %2") + .arg(++n) + .arg(QLatin1String(QT_VERSION_STR))); + enableDeleteModalDialogButton(); + } + applySettings(m_modalDialog); + m_modalDialog->show(); +} + +void ColorDialogPanel::showNonModal() +{ + if (m_nonModalDialog.isNull()) { + static int n = 0; + m_nonModalDialog = new QColorDialog(this); + connect(m_nonModalDialog.data(), SIGNAL(accepted()), this, SLOT(accepted())); + m_nonModalDialog->setWindowTitle(tr("Non-Modal Color Dialog #%1 Qt %2") + .arg(++n) + .arg(QLatin1String(QT_VERSION_STR))); + enableDeleteNonModalDialogButton(); + } + applySettings(m_nonModalDialog); + m_nonModalDialog->show(); +} + +void ColorDialogPanel::deleteNonModalDialog() +{ + if (!m_nonModalDialog.isNull()) + delete m_nonModalDialog; + enableDeleteNonModalDialogButton(); +} + +void ColorDialogPanel::deleteModalDialog() +{ + if (!m_modalDialog.isNull()) + delete m_modalDialog; + enableDeleteModalDialogButton(); +} + +void ColorDialogPanel::accepted() +{ + const QColorDialog *d = qobject_cast<const QColorDialog *>(sender()); + Q_ASSERT(d); + m_result.clear(); + QDebug(&m_result).nospace() + << "Current color: " << d->currentColor() + << "\nSelected color: " << d->selectedColor(); + QTimer::singleShot(0, this, SLOT(showAcceptedResult())); // Avoid problems with the closing (modal) dialog as parent. +} + +void ColorDialogPanel::showAcceptedResult() +{ + QMessageBox::information(this, tr("Color Dialog Accepted"), m_result, QMessageBox::Ok); +} + +void ColorDialogPanel::restoreDefaults() +{ + QColorDialog d; + m_showAlphaChannel->setChecked(d.testOption(QColorDialog::ShowAlphaChannel)); + m_noButtons->setChecked(d.testOption(QColorDialog::NoButtons)); + m_dontUseNativeDialog->setChecked(d.testOption(QColorDialog::DontUseNativeDialog)); +} + +void ColorDialogPanel::enableDeleteNonModalDialogButton() +{ + m_deleteNonModalDialogButton->setEnabled(!m_nonModalDialog.isNull()); +} + +void ColorDialogPanel::enableDeleteModalDialogButton() +{ + m_deleteModalDialogButton->setEnabled(!m_modalDialog.isNull()); +} + +void ColorDialogPanel::applySettings(QColorDialog *d) const +{ + d->setOption(QColorDialog::ShowAlphaChannel, m_showAlphaChannel->isChecked()); + d->setOption(QColorDialog::NoButtons, m_noButtons->isChecked()); + d->setOption(QColorDialog::DontUseNativeDialog, m_dontUseNativeDialog->isChecked()); + d->setCurrentColor(QColor(m_colorComboBox->itemData(m_colorComboBox->currentIndex(), Qt::EditRole).toString())); +} diff --git a/tests/manual/dialogs/colordialogpanel.h b/tests/manual/dialogs/colordialogpanel.h new file mode 100644 index 0000000000..bcd2cf6e52 --- /dev/null +++ b/tests/manual/dialogs/colordialogpanel.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef COLORDIALOGPANEL_H +#define COLORDIALOGPANEL_H + +#include <QPointer> +#include <QColorDialog> + +class QComboBox; +class QCheckBox; +class QPushButton; + +class ColorDialogPanel : public QWidget +{ + Q_OBJECT +public: + explicit ColorDialogPanel(QWidget *parent = 0); + +public slots: + void execModal(); + void showModal(); + void showNonModal(); + void deleteNonModalDialog(); + void deleteModalDialog(); + void accepted(); + void showAcceptedResult(); + void restoreDefaults(); + +private slots: + void enableDeleteNonModalDialogButton(); + void enableDeleteModalDialogButton(); + +private: + void applySettings(QColorDialog *d) const; + + QComboBox *m_colorComboBox; + QCheckBox *m_showAlphaChannel; + QCheckBox *m_noButtons; + QCheckBox *m_dontUseNativeDialog; + QPushButton *m_deleteNonModalDialogButton; + QPushButton *m_deleteModalDialogButton; + QString m_result; + QPointer<QColorDialog> m_modalDialog; + QPointer<QColorDialog> m_nonModalDialog; +}; + +#endif // COLORDIALOGPANEL_H diff --git a/tests/manual/dialogs/dialogs.pro b/tests/manual/dialogs/dialogs.pro index ff916d3854..4ed200ab7f 100644 --- a/tests/manual/dialogs/dialogs.pro +++ b/tests/manual/dialogs/dialogs.pro @@ -4,5 +4,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = dialogs TEMPLATE = app -SOURCES += main.cpp filedialogpanel.cpp -HEADERS += filedialogpanel.h +SOURCES += main.cpp filedialogpanel.cpp colordialogpanel.cpp fontdialogpanel.cpp \ + wizardpanel.cpp +HEADERS += filedialogpanel.h colordialogpanel.h fontdialogpanel.h \ + wizardpanel.h diff --git a/tests/manual/dialogs/filedialogpanel.cpp b/tests/manual/dialogs/filedialogpanel.cpp index 66a5201db0..636e65b684 100644 --- a/tests/manual/dialogs/filedialogpanel.cpp +++ b/tests/manual/dialogs/filedialogpanel.cpp @@ -44,6 +44,7 @@ #include <QGridLayout> #include <QVBoxLayout> #include <QHBoxLayout> +#include <QGridLayout> #include <QFormLayout> #include <QSpacerItem> #include <QGroupBox> @@ -105,11 +106,13 @@ inline void setComboBoxValue(QComboBox *c, int v) c->setCurrentIndex(c->findData(QVariant(v))); } -static inline void addButton(const QString &description, QBoxLayout *layout, QObject *receiver, const char *slotFunc) +static inline QPushButton *addButton(const QString &description, QGridLayout *layout, + int &row, int column, QObject *receiver, const char *slotFunc) { QPushButton *button = new QPushButton(description); QObject::connect(button, SIGNAL(clicked()), receiver, slotFunc); - layout->addWidget(button); + layout->addWidget(button, row++, column); + return button; } // A line edit for editing the label fields of the dialog, keeping track of whether it has @@ -159,6 +162,8 @@ FileDialogPanel::FileDialogPanel(QWidget *parent) , m_selectedFileName(new QLineEdit(this)) , m_nameFilters(new QPlainTextEdit) , m_selectedNameFilter(new QLineEdit(this)) + , m_deleteNonModalDialogButton(0) + , m_deleteModalDialogButton(0) { // Options QGroupBox *optionsGroupBox = new QGroupBox(tr("Options")); @@ -197,19 +202,24 @@ FileDialogPanel::FileDialogPanel(QWidget *parent) labelsLayout->addRow(tr("Reject label:"), m_labelLineEdits.back()); // Buttons - QVBoxLayout *buttonLayout = new QVBoxLayout; - buttonLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding)); - addButton(tr("Show modal"), buttonLayout, this, SLOT(showModal())); - addButton(tr("Show non-modal"), buttonLayout, this, SLOT(showNonModal())); - addButton(tr("getOpenFileName"), buttonLayout, this, SLOT(getOpenFileName())); - addButton(tr("getOpenFileNames"), buttonLayout, this, SLOT(getOpenFileNames())); - addButton(tr("getSaveFileName"), buttonLayout, this, SLOT(getSaveFileName())); - addButton(tr("getExistingDirectory"), buttonLayout, this, SLOT(getExistingDirectory())); - addButton(tr("Restore defaults"), buttonLayout, this, SLOT(restoreDefaults())); QGroupBox *buttonsGroupBox = new QGroupBox(tr("Show")); - QHBoxLayout *buttonsGroupLayout = new QHBoxLayout(buttonsGroupBox); - buttonsGroupLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored)); - buttonsGroupLayout->addLayout(buttonLayout); + QGridLayout *buttonLayout = new QGridLayout(buttonsGroupBox); + int row = 0; + int column = 0; + addButton(tr("Exec modal"), buttonLayout, row, column, this, SLOT(execModal())); + addButton(tr("Show modal"), buttonLayout, row, column, this, SLOT(showModal())); + m_deleteModalDialogButton = + addButton(tr("Delete modal"), buttonLayout, row, column, this, SLOT(deleteModalDialog())); + addButton(tr("Show non-modal"), buttonLayout, row, column, this, SLOT(showNonModal())); + m_deleteNonModalDialogButton = + addButton(tr("Delete non-modal"), buttonLayout, row, column, this, SLOT(deleteNonModalDialog())); + row = 0; + column++; + addButton(tr("getOpenFileName"), buttonLayout, row, column, this, SLOT(getOpenFileName())); + addButton(tr("getOpenFileNames"), buttonLayout, row, column, this, SLOT(getOpenFileNames())); + addButton(tr("getSaveFileName"), buttonLayout, row, column, this, SLOT(getSaveFileName())); + addButton(tr("getExistingDirectory"), buttonLayout, row, column, this, SLOT(getExistingDirectory())); + addButton(tr("Restore defaults"), buttonLayout, row, column, this, SLOT(restoreDefaults())); // Main layout QGridLayout *gridLayout = new QGridLayout(this); @@ -218,26 +228,76 @@ FileDialogPanel::FileDialogPanel(QWidget *parent) gridLayout->addWidget(labelsGroupBox, 1, 0); gridLayout->addWidget(buttonsGroupBox, 1, 1); + enableDeleteModalDialogButton(); + enableDeleteNonModalDialogButton(); restoreDefaults(); } -void FileDialogPanel::showModal() +void FileDialogPanel::execModal() { QFileDialog dialog(this); applySettings(&dialog); + connect(&dialog, SIGNAL(accepted()), this, SLOT(accepted())); dialog.setWindowTitle(tr("Modal File Dialog Qt %1").arg(QLatin1String(QT_VERSION_STR))); dialog.exec(); } +void FileDialogPanel::showModal() +{ + if (m_modalDialog.isNull()) { + static int n = 0; + m_modalDialog = new QFileDialog(this); + m_modalDialog->setModal(true); + connect(m_modalDialog.data(), SIGNAL(accepted()), this, SLOT(accepted())); + m_modalDialog->setWindowTitle(tr("Modal File Dialog #%1 Qt %2") + .arg(++n) + .arg(QLatin1String(QT_VERSION_STR))); + enableDeleteModalDialogButton(); + } + applySettings(m_modalDialog); + m_modalDialog->show(); +} + void FileDialogPanel::showNonModal() { - QFileDialog *dialog = new QFileDialog(this); - dialog->setAttribute(Qt::WA_DeleteOnClose); - applySettings(dialog); - dialog->setWindowTitle(tr("Non-Modal File Dialog Qt %1").arg(QLatin1String(QT_VERSION_STR))); - dialog->show(); + if (m_nonModalDialog.isNull()) { + static int n = 0; + m_nonModalDialog = new QFileDialog(this); + connect(m_nonModalDialog.data(), SIGNAL(accepted()), this, SLOT(accepted())); + m_nonModalDialog->setWindowTitle(tr("Non-Modal File Dialog #%1 Qt %2") + .arg(++n) + .arg(QLatin1String(QT_VERSION_STR))); + enableDeleteNonModalDialogButton(); + } + applySettings(m_nonModalDialog); + m_nonModalDialog->show(); +} + +void FileDialogPanel::deleteNonModalDialog() +{ + if (!m_nonModalDialog.isNull()) + delete m_nonModalDialog; + enableDeleteNonModalDialogButton(); } +void FileDialogPanel::deleteModalDialog() +{ + if (!m_modalDialog.isNull()) + delete m_modalDialog; + enableDeleteModalDialogButton(); +} + +void FileDialogPanel::enableDeleteNonModalDialogButton() +{ + m_deleteNonModalDialogButton->setEnabled(!m_nonModalDialog.isNull()); +} + +void FileDialogPanel::enableDeleteModalDialogButton() +{ + m_deleteModalDialogButton->setEnabled(!m_modalDialog.isNull()); +} + + QString FileDialogPanel::filterString() const { return m_nameFilters->toPlainText().trimmed().replace(QLatin1String("\n"), QLatin1String(";;")); @@ -340,7 +400,9 @@ void FileDialogPanel::applySettings(QFileDialog *d) const d->setFileMode(comboBoxValue<QFileDialog::FileMode>(m_fileMode)); d->setOptions(options()); d->setDefaultSuffix(m_defaultSuffix->text().trimmed()); - d->setDirectory(m_directory->text().trimmed()); + const QString directory = m_directory->text().trimmed(); + if (!directory.isEmpty()) + d->setDirectory(directory); const QString file = m_selectedFileName->text().trimmed(); if (!file.isEmpty()) d->selectFile(file); @@ -350,7 +412,6 @@ void FileDialogPanel::applySettings(QFileDialog *d) const d->selectNameFilter(filter); foreach (LabelLineEdit *l, m_labelLineEdits) l->apply(d); - connect(d, SIGNAL(accepted()), this, SLOT(accepted())); } void FileDialogPanel::accepted() diff --git a/tests/manual/dialogs/filedialogpanel.h b/tests/manual/dialogs/filedialogpanel.h index 699d917e4d..7ee7cb3f60 100644 --- a/tests/manual/dialogs/filedialogpanel.h +++ b/tests/manual/dialogs/filedialogpanel.h @@ -44,7 +44,9 @@ #include <QGroupBox> #include <QFileDialog> +#include <QPointer> +class QPushButton; class QCheckBox; class QComboBox; class QLineEdit; @@ -58,8 +60,11 @@ public: explicit FileDialogPanel(QWidget *parent = 0); public slots: + void execModal(); void showModal(); void showNonModal(); + void deleteNonModalDialog(); + void deleteModalDialog(); void getOpenFileNames(); void getOpenFileName(); void getSaveFileName(); @@ -68,6 +73,10 @@ public slots: void showAcceptedResult(); void restoreDefaults(); +private slots: + void enableDeleteNonModalDialogButton(); + void enableDeleteModalDialogButton(); + private: QString filterString() const; QFileDialog::Options options() const; @@ -87,7 +96,11 @@ private: QList<LabelLineEdit *> m_labelLineEdits; QPlainTextEdit *m_nameFilters; QLineEdit *m_selectedNameFilter; + QPushButton *m_deleteNonModalDialogButton; + QPushButton *m_deleteModalDialogButton; QString m_result; + QPointer<QFileDialog> m_modalDialog; + QPointer<QFileDialog> m_nonModalDialog; }; #endif // FILEDIALOGPANEL_H diff --git a/tests/manual/dialogs/fontdialogpanel.cpp b/tests/manual/dialogs/fontdialogpanel.cpp new file mode 100644 index 0000000000..2bdbb0625a --- /dev/null +++ b/tests/manual/dialogs/fontdialogpanel.cpp @@ -0,0 +1,208 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "fontdialogpanel.h" + +#include <QGroupBox> +#include <QCheckBox> +#include <QPushButton> +#include <QVBoxLayout> +#include <QHBoxLayout> +#include <QMessageBox> +#include <QFontComboBox> +#include <QDoubleSpinBox> +#include <QTimer> +#include <QDebug> + +static inline QPushButton *addButton(const QString &description, QVBoxLayout *layout, + QObject *receiver, const char *slotFunc) +{ + QPushButton *button = new QPushButton(description); + QObject::connect(button, SIGNAL(clicked()), receiver, slotFunc); + layout->addWidget(button); + return button; +} + +FontDialogPanel::FontDialogPanel(QWidget *parent) + : QWidget(parent) + , m_fontFamilyBox(new QFontComboBox) + , m_fontSizeBox(new QDoubleSpinBox) + , m_noButtons(new QCheckBox(tr("Don't display OK/Cancel buttons"))) + , m_dontUseNativeDialog(new QCheckBox(tr("Don't use native dialog"))) +{ + // Options + QGroupBox *optionsGroupBox = new QGroupBox(tr("Options"), this); + QVBoxLayout *optionsLayout = new QVBoxLayout(optionsGroupBox); + optionsLayout->addWidget(m_noButtons); + optionsLayout->addWidget(m_dontUseNativeDialog); + + // Font + QGroupBox *fontGroupBox = new QGroupBox(tr("Font"), this); + QHBoxLayout *fontLayout = new QHBoxLayout(fontGroupBox); + fontLayout->addWidget(m_fontFamilyBox); + fontLayout->addWidget(m_fontSizeBox); + m_fontSizeBox->setValue(QFont().pointSizeF()); + + // Buttons + QGroupBox *buttonsGroupBox = new QGroupBox(tr("Show")); + QVBoxLayout *buttonsLayout = new QVBoxLayout(buttonsGroupBox); + addButton(tr("Exec modal"), buttonsLayout, this, SLOT(execModal())); + addButton(tr("Show modal"), buttonsLayout, this, SLOT(showModal())); + m_deleteModalDialogButton = + addButton(tr("Delete modal"), buttonsLayout, this, SLOT(deleteModalDialog())); + addButton(tr("Show non-modal"), buttonsLayout, this, SLOT(showNonModal())); + m_deleteNonModalDialogButton = + addButton(tr("Delete non-modal"), buttonsLayout, this, SLOT(deleteNonModalDialog())); + addButton(tr("Restore defaults"), buttonsLayout, this, SLOT(restoreDefaults())); + buttonsLayout->addStretch(); + + // Main layout + QHBoxLayout *mainLayout = new QHBoxLayout(this); + QVBoxLayout *leftLayout = new QVBoxLayout; + leftLayout->addWidget(optionsGroupBox); + leftLayout->addWidget(fontGroupBox); + leftLayout->addStretch(); + mainLayout->addLayout(leftLayout); + mainLayout->addWidget(buttonsGroupBox); + + enableDeleteModalDialogButton(); + enableDeleteNonModalDialogButton(); + restoreDefaults(); +} + +void FontDialogPanel::execModal() +{ + QFontDialog dialog(this); + applySettings(&dialog); + connect(&dialog, SIGNAL(accepted()), this, SLOT(accepted())); + dialog.setWindowTitle(tr("Modal Font Dialog Qt %1").arg(QLatin1String(QT_VERSION_STR))); + dialog.exec(); +} + +void FontDialogPanel::showModal() +{ + if (m_modalDialog.isNull()) { + static int n = 0; + m_modalDialog = new QFontDialog(this); + m_modalDialog->setModal(true); + connect(m_modalDialog.data(), SIGNAL(accepted()), this, SLOT(accepted())); + m_modalDialog->setWindowTitle(tr("Modal Font Dialog #%1 Qt %2") + .arg(++n) + .arg(QLatin1String(QT_VERSION_STR))); + enableDeleteModalDialogButton(); + } + applySettings(m_modalDialog); + m_modalDialog->show(); +} + +void FontDialogPanel::showNonModal() +{ + if (m_nonModalDialog.isNull()) { + static int n = 0; + m_nonModalDialog = new QFontDialog(this); + connect(m_nonModalDialog.data(), SIGNAL(accepted()), this, SLOT(accepted())); + m_nonModalDialog->setWindowTitle(tr("Non-Modal Font Dialog #%1 Qt %2") + .arg(++n) + .arg(QLatin1String(QT_VERSION_STR))); + enableDeleteNonModalDialogButton(); + } + applySettings(m_nonModalDialog); + m_nonModalDialog->show(); +} + +void FontDialogPanel::deleteNonModalDialog() +{ + if (!m_nonModalDialog.isNull()) + delete m_nonModalDialog; + enableDeleteNonModalDialogButton(); +} + +void FontDialogPanel::deleteModalDialog() +{ + if (!m_modalDialog.isNull()) + delete m_modalDialog; + enableDeleteModalDialogButton(); +} + +void FontDialogPanel::accepted() +{ + const QFontDialog *d = qobject_cast<const QFontDialog *>(sender()); + Q_ASSERT(d); + m_result.clear(); + QDebug(&m_result).nospace() + << "Current font: " << d->currentFont() + << "\nSelected font: " << d->selectedFont(); + QTimer::singleShot(0, this, SLOT(showAcceptedResult())); // Avoid problems with the closing (modal) dialog as parent. +} + +void FontDialogPanel::showAcceptedResult() +{ + QMessageBox::information(this, tr("Color Dialog Accepted"), m_result, QMessageBox::Ok); +} + +void FontDialogPanel::restoreDefaults() +{ + QFontDialog d; + m_noButtons->setChecked(d.testOption(QFontDialog::NoButtons)); + m_dontUseNativeDialog->setChecked(d.testOption(QFontDialog::DontUseNativeDialog)); + m_fontFamilyBox->setCurrentFont(QFont()); + m_fontSizeBox->setValue(QFont().pointSizeF()); +} + +void FontDialogPanel::enableDeleteNonModalDialogButton() +{ + m_deleteNonModalDialogButton->setEnabled(!m_nonModalDialog.isNull()); +} + +void FontDialogPanel::enableDeleteModalDialogButton() +{ + m_deleteModalDialogButton->setEnabled(!m_modalDialog.isNull()); +} + +void FontDialogPanel::applySettings(QFontDialog *d) const +{ + d->setOption(QFontDialog::NoButtons, m_noButtons->isChecked()); + d->setOption(QFontDialog::DontUseNativeDialog, m_dontUseNativeDialog->isChecked()); + + QFont font = m_fontFamilyBox->currentFont(); + font.setPointSizeF(m_fontSizeBox->value()); + d->setCurrentFont(font); +} diff --git a/tests/manual/dialogs/fontdialogpanel.h b/tests/manual/dialogs/fontdialogpanel.h new file mode 100644 index 0000000000..92f2b7313f --- /dev/null +++ b/tests/manual/dialogs/fontdialogpanel.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef FONTDIALOGPANEL_H +#define FONTDIALOGPANEL_H + +#include <QPointer> +#include <QFontDialog> + +class QCheckBox; +class QPushButton; +class QFontComboBox; +class QDoubleSpinBox; + +class FontDialogPanel : public QWidget +{ + Q_OBJECT +public: + explicit FontDialogPanel(QWidget *parent = 0); + +public slots: + void execModal(); + void showModal(); + void showNonModal(); + void deleteNonModalDialog(); + void deleteModalDialog(); + void accepted(); + void showAcceptedResult(); + void restoreDefaults(); + +private slots: + void enableDeleteNonModalDialogButton(); + void enableDeleteModalDialogButton(); + +private: + void applySettings(QFontDialog *d) const; + + QFontComboBox *m_fontFamilyBox; + QDoubleSpinBox *m_fontSizeBox; + QCheckBox *m_noButtons; + QCheckBox *m_dontUseNativeDialog; + QPushButton *m_deleteNonModalDialogButton; + QPushButton *m_deleteModalDialogButton; + QString m_result; + QPointer<QFontDialog> m_modalDialog; + QPointer<QFontDialog> m_nonModalDialog; +}; + +#endif // FONTDIALOGPANEL_H diff --git a/tests/manual/dialogs/main.cpp b/tests/manual/dialogs/main.cpp index c1ea7b0d8f..86e6c90b3f 100644 --- a/tests/manual/dialogs/main.cpp +++ b/tests/manual/dialogs/main.cpp @@ -40,6 +40,9 @@ ****************************************************************************/ #include "filedialogpanel.h" +#include "colordialogpanel.h" +#include "fontdialogpanel.h" +#include "wizardpanel.h" #include <QMainWindow> #include <QApplication> @@ -50,7 +53,6 @@ #include <QKeySequence> // Test for dialogs, allowing to play with all dialog options for implementing native dialogs. -// Currently, only QFileDialog is implemented. // Compiles with Qt 4.8 and Qt 5. class MainWindow : public QMainWindow { @@ -68,6 +70,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); QTabWidget *tabWidget = new QTabWidget; tabWidget->addTab(new FileDialogPanel, tr("QFileDialog")); + tabWidget->addTab(new ColorDialogPanel, tr("QColorDialog")); + tabWidget->addTab(new FontDialogPanel, tr("QFontDialog")); + tabWidget->addTab(new WizardPanel, tr("QWizard")); setCentralWidget(tabWidget); } diff --git a/tests/manual/dialogs/wizardpanel.cpp b/tests/manual/dialogs/wizardpanel.cpp new file mode 100644 index 0000000000..1306062426 --- /dev/null +++ b/tests/manual/dialogs/wizardpanel.cpp @@ -0,0 +1,361 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "wizardpanel.h" + +#include <QWizard> +#include <QWizardPage> +#include <QVBoxLayout> +#include <QGridLayout> +#include <QRadioButton> +#include <QPushButton> +#include <QCheckBox> +#include <QButtonGroup> +#include <QSpacerItem> +#include <QGroupBox> +#include <QLabel> +#include <QStyle> +#include <QIcon> +#include <QImage> +#include <QPainter> +#include <QFont> +#include <QFontMetrics> +#include <QHash> + +static QIcon coloredIcon(const Qt::GlobalColor color) +{ + QImage image(QSize(24, 24), QImage::Format_RGB32); + image.fill(color); + return QIcon(QPixmap::fromImage(image)); +} + +static QPixmap pixmapWithText(const QString &text, const QColor color) +{ + QFont font; + QFontMetrics metric(font); + QRect rectangle = metric.boundingRect(text); + rectangle.setBottomRight(rectangle.bottomRight() + QPoint(20, 20)); + QImage image(rectangle.size(), QImage::Format_RGB32); + image.fill(color); + QPainter painter(&image); + painter.setFont(font); + painter.drawText(rectangle, Qt::AlignHCenter | Qt::AlignVCenter, text); + return QPixmap::fromImage(image); +} + +// A radio-group control for QWizard::WizardStyle. +class WizardStyleControl : public QGroupBox +{ + Q_OBJECT +public: + WizardStyleControl(QWidget *parent = 0); + + void setWizardStyle(int style); + QWizard::WizardStyle wizardStyle() const; + +signals: + void wizardStyleChanged(int); + +private: + QButtonGroup *m_group; +}; + +WizardStyleControl::WizardStyleControl(QWidget *parent) + : QGroupBox(tr("Style"), parent) + , m_group(new QButtonGroup(this)) +{ + m_group->setExclusive(true); + connect(m_group, SIGNAL(buttonClicked(int)), this, SIGNAL(wizardStyleChanged(int))); + QVBoxLayout *vLayout = new QVBoxLayout(this); + QRadioButton *radioButton = new QRadioButton(tr("None/OS Default"), this); + m_group->addButton(radioButton, QWizard::NStyles); + vLayout->addWidget(radioButton); + radioButton = new QRadioButton(tr("ClassicStyle"), this); + m_group->addButton(radioButton, QWizard::ClassicStyle); + vLayout->addWidget(radioButton); + radioButton = new QRadioButton(tr("ModernStyle"), this); + m_group->addButton(radioButton, QWizard::ModernStyle); + vLayout->addWidget(radioButton); + radioButton = new QRadioButton(tr("MacStyle"), this); + m_group->addButton(radioButton, QWizard::MacStyle); + vLayout->addWidget(radioButton); + radioButton = new QRadioButton(tr("AeroStyle"), this); + m_group->addButton(radioButton, QWizard::AeroStyle); + vLayout->addWidget(radioButton); + vLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding)); + + setWizardStyle(style()->styleHint(QStyle::SH_WizardStyle)); +} + +QWizard::WizardStyle WizardStyleControl::wizardStyle() const +{ + return static_cast<QWizard::WizardStyle>(m_group->checkedId()); +} + +void WizardStyleControl::setWizardStyle(int wizardStyle) +{ + if (wizardStyle < 0 || wizardStyle > QWizard::NStyles) + wizardStyle = QWizard::NStyles; + QAbstractButton *button = m_group->button(wizardStyle); + Q_ASSERT(button); + const bool blocked = m_group->blockSignals(true); + button->setChecked(true); + m_group->blockSignals(blocked); +} + +// A control with checkboxes for QWizard::WizardOption. +class WizardOptionsControl : public QGroupBox +{ +public: + explicit WizardOptionsControl(QWidget *parent = 0); + + QWizard::WizardOption wizardOptions() const; + void setWizardOptions(int options); + +private: + typedef QHash<int, QCheckBox *> CheckBoxHash; + + void addCheckBox(QVBoxLayout *layout, int flag, const QString &title); + + CheckBoxHash m_checkBoxes; +}; + +WizardOptionsControl::WizardOptionsControl(QWidget *parent) + : QGroupBox(tr("Options"), parent) +{ + QVBoxLayout *vLayout = new QVBoxLayout(this); + addCheckBox(vLayout, QWizard::IndependentPages, QLatin1String("IndependentPages")); + addCheckBox(vLayout, QWizard::IgnoreSubTitles, QLatin1String("IgnoreSubTitles")); + addCheckBox(vLayout, QWizard::ExtendedWatermarkPixmap, QLatin1String("ExtendedWatermarkPixmap")); + addCheckBox(vLayout, QWizard::NoDefaultButton, QLatin1String("NoDefaultButton")); + addCheckBox(vLayout, QWizard::NoBackButtonOnStartPage, QLatin1String("NoBackButtonOnStartPage")); + addCheckBox(vLayout, QWizard::NoBackButtonOnLastPage, QLatin1String("NoBackButtonOnLastPage")); + addCheckBox(vLayout, QWizard::DisabledBackButtonOnLastPage, QLatin1String("DisabledBackButtonOnLastPage")); + addCheckBox(vLayout, QWizard::HaveNextButtonOnLastPage, QLatin1String("HaveNextButtonOnLastPage")); + addCheckBox(vLayout, QWizard::HaveFinishButtonOnEarlyPages, QLatin1String("HaveFinishButtonOnEarlyPages")); + addCheckBox(vLayout, QWizard::NoCancelButton, QLatin1String("NoCancelButton")); + addCheckBox(vLayout, QWizard::CancelButtonOnLeft, QLatin1String("CancelButtonOnLeft")); + addCheckBox(vLayout, QWizard::HaveHelpButton, QLatin1String("HaveHelpButton")); + addCheckBox(vLayout, QWizard::HelpButtonOnRight, QLatin1String("HelpButtonOnRight")); + addCheckBox(vLayout, QWizard::HaveCustomButton1, QLatin1String("HaveCustomButton1")); + addCheckBox(vLayout, QWizard::HaveCustomButton2, QLatin1String("HaveCustomButton2")); + addCheckBox(vLayout, QWizard::HaveCustomButton3, QLatin1String("HaveCustomButton3")); + vLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding)); +} + +void WizardOptionsControl::addCheckBox(QVBoxLayout *layout, int flag, const QString &title) +{ + QCheckBox *checkBox = new QCheckBox(title, this); + layout->addWidget(checkBox); + m_checkBoxes.insert(flag, checkBox); +} + +QWizard::WizardOption WizardOptionsControl::wizardOptions() const +{ + int result = 0; + typedef CheckBoxHash::const_iterator ConstIterator; + const ConstIterator cend = m_checkBoxes.constEnd(); + for (ConstIterator it = m_checkBoxes.constBegin(); it != cend; ++it) + if (it.value()->isChecked()) + result |= it.key(); + return static_cast<QWizard::WizardOption>(result); +} + +void WizardOptionsControl::setWizardOptions(int options) +{ + typedef CheckBoxHash::iterator Iterator; + const Iterator end = m_checkBoxes.end(); + for (Iterator it = m_checkBoxes.begin(); it != end; ++it) + it.value()->setChecked(options & it.key()); +} + +// A test wizard with a slot to change its style. +class Wizard : public QWizard { + Q_OBJECT +public: + explicit Wizard(QWidget *parent = 0, Qt::WindowFlags flags = 0); + +public slots: + void changeWizardStyle(int newStyle); +}; + +void Wizard::changeWizardStyle(int newStyle) +{ + if (newStyle >= 0 && newStyle < int(QWizard::NStyles)) + setWizardStyle(static_cast<QWizard::WizardStyle>(newStyle)); +} + +// A test wizard page with a WizardStyleControl. +class WizardPage : public QWizardPage +{ +public: + explicit WizardPage(const QString &title, QWidget *parent = 0); + + void initializePage(); + +private: + WizardStyleControl *m_styleControl; + bool m_firstTimeShown; +}; + +WizardPage::WizardPage(const QString &title, QWidget *parent) + : QWizardPage(parent) + , m_styleControl(new WizardStyleControl(this)) + , m_firstTimeShown(true) +{ + setTitle(title); + setSubTitle(title + QLatin1String(" SubTitle")); + QVBoxLayout *vLayout = new QVBoxLayout(this); + vLayout->addWidget(m_styleControl); +} + +void WizardPage::initializePage() +{ + m_styleControl->setWizardStyle(wizard()->wizardStyle()); + if (m_firstTimeShown) { + m_firstTimeShown = false; + connect(m_styleControl, SIGNAL(wizardStyleChanged(int)), + wizard(), SLOT(changeWizardStyle(int))); + } +} + +Wizard::Wizard(QWidget *parent, Qt::WindowFlags flags) + : QWizard(parent, flags) +{ + setWindowIcon(coloredIcon(Qt::red)); + setWindowTitle(QLatin1String("Wizard ") + QLatin1String(QT_VERSION_STR)); + addPage(new WizardPage(tr("Page 1"), this)); + addPage(new WizardPage(tr("Page 2"), this)); + addPage(new WizardPage(tr("Page 3"), this)); +} + +// A dialog using a Wizard as child widget (emulating Qt Designer). +class WizardEmbeddingDialog : public QDialog { +public: + explicit WizardEmbeddingDialog(QWidget *parent = 0); + + Wizard *wizard() const { return m_wizard; } + +private: + Wizard *m_wizard; +}; + +WizardEmbeddingDialog::WizardEmbeddingDialog(QWidget *parent) + : QDialog(parent) + , m_wizard(new Wizard) +{ + setWindowTitle(QString::fromLatin1("Dialog Embedding QWizard %1").arg(QT_VERSION_STR)); + QGridLayout *gridLayout = new QGridLayout(this); + gridLayout->addWidget(new QLabel(tr("Above wizard")), 0, 0, 1, 3); + gridLayout->addWidget(new QLabel(tr("Left of wizard")), 1, 0); + m_wizard->setObjectName(QLatin1String("EmbeddedWizard")); + m_wizard->setParent(this, Qt::Widget); + gridLayout->addWidget(m_wizard, 1, 1); + gridLayout->addWidget(new QLabel(tr("Right of wizard")), 1, 2); + gridLayout->addWidget(new QLabel(tr("Below wizard")), 2, 0, 1, 3); +} + +WizardPanel::WizardPanel(QWidget *parent) + : QWidget(parent) + , m_styleControl(new WizardStyleControl(this)) + , m_optionsControl(new WizardOptionsControl(this)) +{ + { + QWizard wizard; + m_optionsControl->setWizardOptions(wizard.options()); + m_styleControl->setWizardStyle(wizard.wizardStyle()); + } + + QGridLayout *gridLayout = new QGridLayout(this); + gridLayout->addWidget(m_optionsControl, 0, 0, 2, 1); + gridLayout->addWidget(m_styleControl, 0, 1); + QGroupBox *buttonGroupBox = new QGroupBox(this); + QVBoxLayout *vLayout = new QVBoxLayout(buttonGroupBox); + QPushButton *button = new QPushButton(tr("Show modal"), this); + connect(button, SIGNAL(clicked()), this, SLOT(showModal())); + vLayout->addWidget(button); + button = new QPushButton(tr("Show non-modal"), this); + connect(button, SIGNAL(clicked()), this, SLOT(showNonModal())); + vLayout->addWidget(button); + button = new QPushButton(tr("Show embedded"), this); + button->setToolTip(tr("Test QWizard's behavior when used as a widget child.")); + connect(button, SIGNAL(clicked()), this, SLOT(showEmbedded())); + vLayout->addWidget(button); + vLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding)); + gridLayout->addWidget(buttonGroupBox, 1, 1); +} + +void WizardPanel::showModal() +{ + Wizard wizard(this); + applyParameters(&wizard); + wizard.exec(); +} + +void WizardPanel::showNonModal() +{ + Wizard *wizard = new Wizard(this); + applyParameters(wizard); + wizard->setModal(false); + wizard->setAttribute(Qt::WA_DeleteOnClose); + wizard->show(); +} + +void WizardPanel::showEmbedded() +{ + WizardEmbeddingDialog *dialog = new WizardEmbeddingDialog(this); + applyParameters(dialog->wizard()); + dialog->setModal(false); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); +} + +void WizardPanel::applyParameters(QWizard *wizard) const +{ + wizard->setWizardStyle(m_styleControl->wizardStyle()); + wizard->setOptions(m_optionsControl->wizardOptions()); + wizard->setPixmap(QWizard::WatermarkPixmap, pixmapWithText(QLatin1String("Watermark"), QColor(Qt::blue).lighter())); + wizard->setPixmap(QWizard::LogoPixmap, pixmapWithText(QLatin1String("Logo"), Qt::green)); + wizard->setPixmap(QWizard::BannerPixmap, pixmapWithText(QLatin1String("Banner"), Qt::green)); + wizard->setPixmap(QWizard::BackgroundPixmap, pixmapWithText(QLatin1String("Background"), QColor(Qt::red).lighter())); +} + +#include "wizardpanel.moc" diff --git a/tests/manual/dialogs/wizardpanel.h b/tests/manual/dialogs/wizardpanel.h new file mode 100644 index 0000000000..0a4ec8e467 --- /dev/null +++ b/tests/manual/dialogs/wizardpanel.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WIZARDPANEL_H +#define WIZARDPANEL_H + +#include <QWidget> + +class WizardStyleControl; +class WizardOptionsControl; +class QWizard; + +class WizardPanel : public QWidget +{ + Q_OBJECT +public: + explicit WizardPanel(QWidget *parent = 0); + +public slots: + void showModal(); + void showNonModal(); + void showEmbedded(); + +private: + void applyParameters(QWizard *wizard) const; + + WizardStyleControl *m_styleControl; + WizardOptionsControl *m_optionsControl; +}; + +#endif // WIZARDPANEL_H |