summaryrefslogtreecommitdiffstats
path: root/tests/manual/dialogs/printdialogpanel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/dialogs/printdialogpanel.cpp')
-rw-r--r--tests/manual/dialogs/printdialogpanel.cpp63
1 files changed, 48 insertions, 15 deletions
diff --git a/tests/manual/dialogs/printdialogpanel.cpp b/tests/manual/dialogs/printdialogpanel.cpp
index 21656d2da2..202a291e5f 100644
--- a/tests/manual/dialogs/printdialogpanel.cpp
+++ b/tests/manual/dialogs/printdialogpanel.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
@@ -10,9 +10,9 @@
** 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.
+** 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.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -23,8 +23,8 @@
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** 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
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
@@ -50,6 +50,7 @@
#include <QGridLayout>
#include <QFormLayout>
#include <QVBoxLayout>
+#include <QMessageBox>
#include <QDoubleSpinBox>
#include <QPainter>
#include <QFont>
@@ -258,9 +259,27 @@ static void drawVertCmRuler(QPainter &painter, int x, int y1, int y2)
}
}
-static void print(QPrinter *printer)
+static bool print(QPrinter *printer, QString *errorMessage)
{
- QPainter painter(printer);
+ QPainter painter;
+
+ if (!printer->isValid()) {
+ *errorMessage = QLatin1String("Invalid printer.");
+ return false;
+ }
+
+ if (printer->printerState() != QPrinter::Idle) {
+ *errorMessage = QLatin1String("Printer not idle (state ")
+ + QString::number(printer->printerState())
+ + QLatin1String(").");
+ return false;
+ }
+
+ if (!painter.begin(printer)) {
+ *errorMessage = QLatin1String("QPainter::begin() failed.");
+ return false;
+ }
+
const QRectF pageF = printer->pageRect();
QFont font = painter.font();
@@ -280,8 +299,8 @@ static void print(QPrinter *printer)
<< *printer;
if (!painter.device()->logicalDpiY() || !painter.device()->logicalDpiX()) {
- qWarning() << Q_FUNC_INFO << "Bailing out due to invalid DPI: " << msg;
- return;
+ *errorMessage = QLatin1String("Bailing out due to invalid DPI.");
+ return false;
}
painter.drawRect(pageF);
@@ -296,7 +315,21 @@ static void print(QPrinter *printer)
textPoint.ry() += (15 * charHeight) / 10;
}
- painter.end();
+ if (!painter.end()) {
+ *errorMessage = QLatin1String("QPainter::end() failed.");
+ return false;
+ }
+
+ return true;
+}
+
+static bool print(QPrinter *printer, QWidget *dialogParent)
+{
+ QString errorMessage;
+ const bool result = print(printer, &errorMessage);
+ if (!result)
+ QMessageBox::warning(dialogParent, QLatin1String("Printing Failed"), errorMessage);
+ return result;
}
class PrintPreviewDialog : public QPrintPreviewDialog {
@@ -308,7 +341,7 @@ public:
}
public slots:
- void slotPaintRequested(QPrinter *p) { print(p); }
+ void slotPaintRequested(QPrinter *p) { print(p, this); }
};
PrintDialogPanel::PrintDialogPanel(QWidget *parent)
@@ -669,7 +702,7 @@ void PrintDialogPanel::showPrintDialog()
dialog.setOptions(m_panel.m_dialogOptionsGroupBox->value<QPrintDialog::PrintDialogOptions>());
if (dialog.exec() == QDialog::Accepted) {
retrieveSettings(m_printer.data());
- print(m_printer.data());
+ print(m_printer.data(), this);
}
}
@@ -693,7 +726,7 @@ void PrintDialogPanel::showPageSetupDialog()
void PrintDialogPanel::directPrint()
{
applySettings(m_printer.data());
- print(m_printer.data());
+ print(m_printer.data(), this);
retrieveSettings(m_printer.data());
}