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