Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qabstractprintdialog.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
5#include "qcoreapplication.h"
6#include "qprintdialog.h"
7#include "qprinter.h"
8#include "private/qprinter_p.h"
9
11
58 : QDialog(*(new QAbstractPrintDialogPrivate), parent)
59{
61 setWindowTitle(QCoreApplication::translate("QPrintDialog", "Print"));
62 d->setPrinter(printer);
63 d->minPage = printer->fromPage();
64 int to = printer->toPage();
65 d->maxPage = to > 0 ? to : INT_MAX;
66}
67
72 QPrinter *printer,
73 QWidget *parent)
74 : QDialog(ptr, parent)
75{
77 setWindowTitle(QCoreApplication::translate("QPrintDialog", "Print"));
78 d->setPrinter(printer);
79}
80
85{
87 if (d->ownsPrinter)
88 delete d->printer;
89}
90
98{
99 auto *d = static_cast<QAbstractPrintDialogPrivate *>(d_ptr.data());
100 if (!(d->options & option) != !on)
101 setOptions(d->options ^ option);
102}
103
111{
112 auto *d = static_cast<const QAbstractPrintDialogPrivate *>(d_ptr.data());
113 return (d->options & option) != 0;
114}
115
129void QPrintDialog::setOptions(PrintDialogOptions options)
130{
131 auto *d = static_cast<QAbstractPrintDialogPrivate *>(d_ptr.data());
132
133 PrintDialogOptions changed = (options ^ d->options);
134 if (!changed)
135 return;
136
137 d->options = options;
138}
139
140QPrintDialog::PrintDialogOptions QPrintDialog::options() const
141{
142 auto *d = static_cast<const QAbstractPrintDialogPrivate *>(d_ptr.data());
143 return d->options;
144}
145
154
163
169{
171 Q_ASSERT_X(min <= max, "QAbstractPrintDialog::setMinMax",
172 "'min' must be less than or equal to 'max'");
173 d->minPage = min;
174 d->maxPage = max;
175 d->options |= PrintPageRange;
176}
177
183{
184 Q_D(const QAbstractPrintDialog);
185 return d->minPage;
186}
187
194{
195 Q_D(const QAbstractPrintDialog);
196 return d->maxPage;
197}
198
203{
205 Q_ASSERT_X(from <= to, "QAbstractPrintDialog::setFromTo",
206 "'from' must be less than or equal to 'to'");
207 d->printer->setFromTo(from, to);
208
209 if (d->minPage == 0 && d->maxPage == 0)
210 setMinMax(1, to);
211}
212
218{
219 Q_D(const QAbstractPrintDialog);
220 return d->printer->fromPage();
221}
222
228{
229 Q_D(const QAbstractPrintDialog);
230 return d->printer->toPage();
231}
232
233
239{
240 Q_D(const QAbstractPrintDialog);
241 return d->printer;
242}
243
245{
246 if (newPrinter) {
247 printer = newPrinter;
248 ownsPrinter = false;
249 if (printer->fromPage() || printer->toPage())
251 } else {
252 printer = new QPrinter;
253 ownsPrinter = true;
254 }
255 pd = printer->d_func();
256}
257
333void QAbstractPrintDialog::setOptionTabs(const QList<QWidget*> &tabs)
334{
336 d->setTabs(tabs);
337}
338
366{
367 auto *d = static_cast<QAbstractPrintDialogPrivate *>(d_ptr.data());
369 if (result == Accepted)
371 if (d->receiverToDisconnectOnClose) {
373 d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);
374 d->receiverToDisconnectOnClose = nullptr;
375 }
376 d->memberToDisconnectOnClose.clear();
377}
378
388void QPrintDialog::open(QObject *receiver, const char *member)
389{
390 auto *d = static_cast<QAbstractPrintDialogPrivate *>(d_ptr.data());
391 connect(this, SIGNAL(accepted(QPrinter*)), receiver, member);
392 d->receiverToDisconnectOnClose = receiver;
393 d->memberToDisconnectOnClose = member;
395}
396
398
399#include "moc_qabstractprintdialog.cpp"
QAbstractPrintDialog::PrintDialogOptions options
void setPrinter(QPrinter *newPrinter)
The QAbstractPrintDialog class provides a base implementation for print dialogs used to configure pri...
PrintDialogOption
Used to specify which parts of the print dialog should be visible.
PrintRange printRange() const
Returns the print range.
PrintRange
Used to specify the print range selection option.
void setFromTo(int fromPage, int toPage)
Sets the range in the print dialog to be from from to to.
int toPage() const
Returns the last page to be printed.
int maxPage() const
Returns the maximum page in the page range.
int minPage() const
Returns the minimum page in the page range.
QPrinter * printer() const
Returns the printer that this printer dialog operates on.
void setOptionTabs(const QList< QWidget * > &tabs)
int fromPage() const
Returns the first page to be printed By default, this value is set to 0.
QAbstractPrintDialog(QPrinter *printer, QWidget *parent=nullptr)
Constructs an abstract print dialog for printer with parent as parent widget.
void setPrintRange(PrintRange range)
Sets the print range option in to be range.
void setMinMax(int min, int max)
Sets the page range in this dialog to be from min to max.
static QString translate(const char *context, const char *key, const char *disambiguation=nullptr, int n=-1)
\threadsafe
The QDialog class is the base class of dialog windows.
Definition qdialog.h:19
@ Accepted
Definition qdialog.h:30
virtual void done(int)
Closes the dialog and sets its result code to r.
Definition qdialog.cpp:602
virtual void open()
Definition qdialog.cpp:503
\inmodule QtCore
Definition qobject.h:103
QScopedPointer< QObjectData > d_ptr
Definition qobject.h:373
PrintDialogOptions options
the various options that affect the look and feel of the dialog
void setOptions(PrintDialogOptions options)
void accepted()
bool testOption(PrintDialogOption option) const
Returns true if the given option is enabled; otherwise, returns false.
void setOption(PrintDialogOption option, bool on=true)
Sets the given option to be enabled if on is true; otherwise, clears the given option.
virtual void open()
Definition qdialog.cpp:503
void done(int result) override
Closes the dialog and sets its result code to result.
\reentrant
Definition qprinter.h:28
int toPage() const
int fromPage() const
PrintRange
Used to specify the print range selection option.
Definition qprinter.h:72
T * data() const noexcept
Returns the value of the pointer referenced by this object.
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setWindowTitle(const QString &)
Definition qwidget.cpp:6105
Combined button and popup list for selecting options.
static ControlElement< T > * ptr(QWidget *widget)
#define SIGNAL(a)
Definition qobjectdefs.h:53
GLsizei range
GLuint64EXT * result
[6]
GLuint GLenum option
#define Q_ASSERT_X(cond, x, msg)
Definition qrandom.cpp:48
#define emit
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
myObject disconnect()
[26]