Doc/Printsupport: misc fixes

- use new signal/slot syntax
- fix includes
- adjust style

Change-Id: Icdc9b33e72e24c39cc6e96b4f2cafa78e179efbf
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
This commit is contained in:
Christian Ehrlicher 2020-01-29 20:06:45 +01:00
parent c7f59cad19
commit b4db334c03
3 changed files with 23 additions and 12 deletions

View File

@ -48,7 +48,11 @@
** **
****************************************************************************/ ****************************************************************************/
#include <QtGui> #include <QtWidgets>
#include <QtPrintSupport/qtprintsupportglobal.h>
#if QT_CONFIG(printdialog)
#include <QPrinter>
#endif
int main(int argc, char **argv) int main(int argc, char **argv)
{ {

View File

@ -48,9 +48,14 @@
** **
****************************************************************************/ ****************************************************************************/
#include <QtGui>
#include "object.h" #include "object.h"
#include <QtWidgets>
#include <QtPrintSupport/qtprintsupportglobal.h>
#if QT_CONFIG(printdialog)
#include <QPrinter>
#endif
Object::Object(QObject *parent) Object::Object(QObject *parent)
: QObject(parent) : QObject(parent)
{ {

View File

@ -48,7 +48,6 @@
** **
****************************************************************************/ ****************************************************************************/
#include <QtGui>
#include <QtWidgets> #include <QtWidgets>
#include <QtPrintSupport/qtprintsupportglobal.h> #include <QtPrintSupport/qtprintsupportglobal.h>
#if QT_CONFIG(printdialog) #if QT_CONFIG(printdialog)
@ -61,11 +60,12 @@ class Window : public QWidget
Q_OBJECT Q_OBJECT
public: public:
Window() { Window()
{
myWidget = new QPushButton("Print Me"); myWidget = new QPushButton("Print Me");
connect(myWidget, SIGNAL(clicked()), this, SLOT(print())); connect(myWidget, &QPushButton::clicked, this, &Window::print);
myWidget2 = new QPushButton("Print Document"); myWidget2 = new QPushButton("Print Document");
connect(myWidget2, SIGNAL(clicked()), this, SLOT(printFile())); connect(myWidget2, &QPushButton::clicked, this, &Window::printFile);
editor = new QTextEdit(this); editor = new QTextEdit(this);
QVBoxLayout *layout = new QVBoxLayout; QVBoxLayout *layout = new QVBoxLayout;
@ -76,8 +76,9 @@ public:
} }
private slots: private slots:
void print() { void print()
#if !defined(QT_NO_PRINTER) {
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)
QPrinter printer(QPrinter::HighResolution); QPrinter printer(QPrinter::HighResolution);
printer.setOutputFileName("test.pdf"); printer.setOutputFileName("test.pdf");
@ -85,8 +86,8 @@ private slots:
//! [0] //! [0]
QPainter painter; QPainter painter;
painter.begin(&printer); painter.begin(&printer);
double xscale = printer.pageRect().width()/double(myWidget->width()); double xscale = printer.pageRect().width() / double(myWidget->width());
double yscale = printer.pageRect().height()/double(myWidget->height()); double yscale = printer.pageRect().height() / double(myWidget->height());
double scale = qMin(xscale, yscale); double scale = qMin(xscale, yscale);
painter.translate(printer.paperRect().x() + printer.pageRect().width()/2, painter.translate(printer.paperRect().x() + printer.pageRect().width()/2,
printer.paperRect().y() + printer.pageRect().height()/2); printer.paperRect().y() + printer.pageRect().height()/2);
@ -98,8 +99,9 @@ private slots:
#endif #endif
} }
void printFile() { void printFile()
#if QT_CONFIG(printdialog) {
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog)
//! [1] //! [1]
QPrinter printer; QPrinter printer;