1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qpagesetupdialog.h"
5#include <private/qpagesetupdialog_p.h>
6
7#include <QtPrintSupport/qprinter.h>
8
9QT_BEGIN_NAMESPACE
10
11/*!
12 \class QPageSetupDialog
13
14 \brief The QPageSetupDialog class provides a configuration dialog
15 for the page-related options on a printer.
16
17 \ingroup standard-dialogs
18 \ingroup printing
19 \inmodule QtPrintSupport
20
21 On Windows and \macos the page setup dialog is implemented using
22 the native page setup dialogs.
23
24 Note that on Windows and \macos custom paper sizes won't be
25 reflected in the native page setup dialogs. Additionally, custom
26 page margins set on a QPrinter won't show in the native \macos
27 page setup dialog.
28
29 \sa QPrinter, QPrintDialog
30*/
31
32
33/*!
34 \fn QPageSetupDialog::QPageSetupDialog(QPrinter *printer, QWidget *parent)
35
36 Constructs a page setup dialog that configures \a printer with \a
37 parent as the parent widget.
38*/
39
40/*!
41 \fn QPageSetupDialog::~QPageSetupDialog()
42
43 Destroys the page setup dialog.
44*/
45
46/*!
47 \since 4.5
48
49 \fn QPageSetupDialog::QPageSetupDialog(QWidget *parent)
50
51 Constructs a page setup dialog that configures a default-constructed
52 QPrinter with \a parent as the parent widget.
53
54 \sa printer()
55*/
56
57/*!
58 \fn QPrinter *QPageSetupDialog::printer()
59
60 Returns the printer that was passed to the QPageSetupDialog
61 constructor.
62*/
63
64QPageSetupDialogPrivate::QPageSetupDialogPrivate(QPrinter *prntr) : printer(nullptr), ownsPrinter(false)
65{
66 setPrinter(prntr);
67}
68
69void QPageSetupDialogPrivate::setPrinter(QPrinter *newPrinter)
70{
71 if (printer && ownsPrinter)
72 delete printer;
73
74 if (newPrinter) {
75 printer = newPrinter;
76 ownsPrinter = false;
77 } else {
78 printer = new QPrinter;
79 ownsPrinter = true;
80 }
81 if (printer->outputFormat() != QPrinter::NativeFormat)
82 qWarning(msg: "QPageSetupDialog: Cannot be used on non-native printers");
83}
84
85/*!
86 \overload
87 \since 4.5
88
89 Opens the dialog and connects its accepted() signal to the slot specified
90 by \a receiver and \a member.
91
92 The signal will be disconnected from the slot when the dialog is closed.
93*/
94void QPageSetupDialog::open(QObject *receiver, const char *member)
95{
96 Q_D(QPageSetupDialog);
97 connect(sender: this, SIGNAL(accepted()), receiver, member);
98 d->receiverToDisconnectOnClose = receiver;
99 d->memberToDisconnectOnClose = member;
100 QDialog::open();
101}
102
103#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
104/*! \fn void QPageSetupDialog::setVisible(bool visible)
105 \reimp
106*/
107#endif
108
109QPageSetupDialog::~QPageSetupDialog()
110{
111 Q_D(QPageSetupDialog);
112 if (d->ownsPrinter)
113 delete d->printer;
114}
115
116QPrinter *QPageSetupDialog::printer()
117{
118 Q_D(QPageSetupDialog);
119 return d->printer;
120}
121
122/*!
123 \fn int QPageSetupDialog::exec()
124
125 This virtual function is called to pop up the dialog. It must be
126 reimplemented in subclasses.
127*/
128
129/*!
130 \reimp
131*/
132void QPageSetupDialog::done(int result)
133{
134 Q_D(QPageSetupDialog);
135 QDialog::done(result);
136 if (d->receiverToDisconnectOnClose) {
137 disconnect(sender: this, SIGNAL(accepted()),
138 receiver: d->receiverToDisconnectOnClose, member: d->memberToDisconnectOnClose);
139 d->receiverToDisconnectOnClose = nullptr;
140 }
141 d->memberToDisconnectOnClose.clear();
142
143}
144
145QT_END_NAMESPACE
146

source code of qtbase/src/printsupport/dialogs/qpagesetupdialog.cpp