summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2013-02-04 14:51:15 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-02-05 14:42:50 +0100
commit5809471ac7dd7bba7f434fc6ed779abd78518360 (patch)
tree884394a02368160992c41f161d92b944263bc12e
parent6c6960015ef32f3e58c9a1a14fe61413cbb19ce8 (diff)
Manual test for QFontDialog
Change-Id: I2bcdd30990e88af45c8d4b2756fcdd48fc2a47d7 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
-rw-r--r--tests/manual/dialogs/dialogs.pro4
-rw-r--r--tests/manual/dialogs/fontdialogpanel.cpp208
-rw-r--r--tests/manual/dialogs/fontdialogpanel.h87
-rw-r--r--tests/manual/dialogs/main.cpp3
4 files changed, 299 insertions, 3 deletions
diff --git a/tests/manual/dialogs/dialogs.pro b/tests/manual/dialogs/dialogs.pro
index 79fa5dbb86..fe40994241 100644
--- a/tests/manual/dialogs/dialogs.pro
+++ b/tests/manual/dialogs/dialogs.pro
@@ -4,5 +4,5 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = dialogs
TEMPLATE = app
-SOURCES += main.cpp filedialogpanel.cpp colordialogpanel.cpp
-HEADERS += filedialogpanel.h colordialogpanel.h
+SOURCES += main.cpp filedialogpanel.cpp colordialogpanel.cpp fontdialogpanel.cpp
+HEADERS += filedialogpanel.h colordialogpanel.h fontdialogpanel.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 fae9833f2a..f137df1f49 100644
--- a/tests/manual/dialogs/main.cpp
+++ b/tests/manual/dialogs/main.cpp
@@ -41,6 +41,7 @@
#include "filedialogpanel.h"
#include "colordialogpanel.h"
+#include "fontdialogpanel.h"
#include <QMainWindow>
#include <QApplication>
@@ -51,7 +52,6 @@
#include <QKeySequence>
// Test for dialogs, allowing to play with all dialog options for implementing native dialogs.
-// Currently, only QFileDialog and QColorDialog are implemented.
// Compiles with Qt 4.8 and Qt 5.
class MainWindow : public QMainWindow {
@@ -70,6 +70,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
QTabWidget *tabWidget = new QTabWidget;
tabWidget->addTab(new FileDialogPanel, tr("QFileDialog"));
tabWidget->addTab(new ColorDialogPanel, tr("QColorDialog"));
+ tabWidget->addTab(new FontDialogPanel, tr("QFontDialog"));
setCentralWidget(tabWidget);
}