1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qpagesetupdialog.h"
41#include <private/qpagesetupdialog_p.h>
42
43#include <QtPrintSupport/qprinter.h>
44
45QT_BEGIN_NAMESPACE
46
47/*!
48 \class QPageSetupDialog
49
50 \brief The QPageSetupDialog class provides a configuration dialog
51 for the page-related options on a printer.
52
53 \ingroup standard-dialogs
54 \ingroup printing
55 \inmodule QtPrintSupport
56
57 On Windows and \macos the page setup dialog is implemented using
58 the native page setup dialogs.
59
60 Note that on Windows and \macos custom paper sizes won't be
61 reflected in the native page setup dialogs. Additionally, custom
62 page margins set on a QPrinter won't show in the native \macos
63 page setup dialog.
64
65 \sa QPrinter, QPrintDialog
66*/
67
68
69/*!
70 \fn QPageSetupDialog::QPageSetupDialog(QPrinter *printer, QWidget *parent)
71
72 Constructs a page setup dialog that configures \a printer with \a
73 parent as the parent widget.
74*/
75
76/*!
77 \fn QPageSetupDialog::~QPageSetupDialog()
78
79 Destroys the page setup dialog.
80*/
81
82/*!
83 \since 4.5
84
85 \fn QPageSetupDialog::QPageSetupDialog(QWidget *parent)
86
87 Constructs a page setup dialog that configures a default-constructed
88 QPrinter with \a parent as the parent widget.
89
90 \sa printer()
91*/
92
93/*!
94 \fn QPrinter *QPageSetupDialog::printer()
95
96 Returns the printer that was passed to the QPageSetupDialog
97 constructor.
98*/
99
100QPageSetupDialogPrivate::QPageSetupDialogPrivate(QPrinter *prntr) : printer(nullptr), ownsPrinter(false)
101{
102 setPrinter(prntr);
103}
104
105void QPageSetupDialogPrivate::setPrinter(QPrinter *newPrinter)
106{
107 if (printer && ownsPrinter)
108 delete printer;
109
110 if (newPrinter) {
111 printer = newPrinter;
112 ownsPrinter = false;
113 } else {
114 printer = new QPrinter;
115 ownsPrinter = true;
116 }
117 if (printer->outputFormat() != QPrinter::NativeFormat)
118 qWarning(msg: "QPageSetupDialog: Cannot be used on non-native printers");
119}
120
121/*!
122 \overload
123 \since 4.5
124
125 Opens the dialog and connects its accepted() signal to the slot specified
126 by \a receiver and \a member.
127
128 The signal will be disconnected from the slot when the dialog is closed.
129*/
130void QPageSetupDialog::open(QObject *receiver, const char *member)
131{
132 Q_D(QPageSetupDialog);
133 connect(sender: this, SIGNAL(accepted()), receiver, member);
134 d->receiverToDisconnectOnClose = receiver;
135 d->memberToDisconnectOnClose = member;
136 QDialog::open();
137}
138
139#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
140/*! \fn void QPageSetupDialog::setVisible(bool visible)
141 \reimp
142*/
143#endif
144
145QPageSetupDialog::~QPageSetupDialog()
146{
147 Q_D(QPageSetupDialog);
148 if (d->ownsPrinter)
149 delete d->printer;
150}
151
152QPrinter *QPageSetupDialog::printer()
153{
154 Q_D(QPageSetupDialog);
155 return d->printer;
156}
157
158/*!
159 \fn int QPageSetupDialog::exec()
160
161 This virtual function is called to pop up the dialog. It must be
162 reimplemented in subclasses.
163*/
164
165/*!
166 \reimp
167*/
168void QPageSetupDialog::done(int result)
169{
170 Q_D(QPageSetupDialog);
171 QDialog::done(result);
172 if (d->receiverToDisconnectOnClose) {
173 disconnect(sender: this, SIGNAL(accepted()),
174 receiver: d->receiverToDisconnectOnClose, member: d->memberToDisconnectOnClose);
175 d->receiverToDisconnectOnClose = nullptr;
176 }
177 d->memberToDisconnectOnClose.clear();
178
179}
180
181QT_END_NAMESPACE
182

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