Qt 4.8
qabstractprintdialog.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qabstractprintdialog_p.h"
43 #include "qcoreapplication.h"
44 #include "qprintdialog.h"
45 #include "qprinter.h"
46 #include "private/qprinter_p.h"
47 
48 #ifndef QT_NO_PRINTDIALOG
49 
51 
52 // hack
54 {
55 };
56 
122  : QDialog(*(new QAbstractPrintDialogPrivate), parent)
123 {
125  setWindowTitle(QCoreApplication::translate("QPrintDialog", "Print"));
126  d->setPrinter(printer);
127 }
128 
133  QPrinter *printer,
134  QWidget *parent)
135  : QDialog(ptr, parent)
136 {
138  setWindowTitle(QCoreApplication::translate("QPrintDialog", "Print"));
139  d->setPrinter(printer);
140 }
141 
146 {
148  if (d->ownsPrinter)
149  delete d->printer;
150 }
151 
159 {
160  Q_D(QPrintDialog);
161  if (!(d->pd->options & option) != !on)
162  setOptions(d->pd->options ^ option);
163 }
164 
172 {
173  Q_D(const QPrintDialog);
174  return (d->pd->options & option) != 0;
175 }
176 
193 void QPrintDialog::setOptions(PrintDialogOptions options)
194 {
195  Q_D(QPrintDialog);
196 
197  PrintDialogOptions changed = (options ^ d->pd->options);
198  if (!changed)
199  return;
200 
201  d->pd->options = options;
202 }
203 
204 QPrintDialog::PrintDialogOptions QPrintDialog::options() const
205 {
206  Q_D(const QPrintDialog);
207  return d->pd->options;
208 }
209 
218 void QAbstractPrintDialog::setEnabledOptions(PrintDialogOptions options)
219 {
221  d->pd->options = options;
222 }
223 
233 {
235  d->pd->options |= option;
236 }
237 
246 QAbstractPrintDialog::PrintDialogOptions QAbstractPrintDialog::enabledOptions() const
247 {
248  Q_D(const QAbstractPrintDialog);
249  return d->pd->options;
250 }
251 
261 {
262  Q_D(const QAbstractPrintDialog);
263  return d->pd->options & option;
264 }
265 
270 {
272  d->pd->printRange = range;
273 }
274 
279 {
280  Q_D(const QAbstractPrintDialog);
281  return d->pd->printRange;
282 }
283 
288 void QAbstractPrintDialog::setMinMax(int min, int max)
289 {
291  Q_ASSERT_X(min <= max, "QAbstractPrintDialog::setMinMax",
292  "'min' must be less than or equal to 'max'");
293  d->pd->minPage = min;
294  d->pd->maxPage = max;
295  d->pd->options |= PrintPageRange;
296 }
297 
303 {
304  Q_D(const QAbstractPrintDialog);
305  return d->pd->minPage;
306 }
307 
314 {
315  Q_D(const QAbstractPrintDialog);
316  return d->pd->maxPage;
317 }
318 
322 void QAbstractPrintDialog::setFromTo(int from, int to)
323 {
325  Q_ASSERT_X(from <= to, "QAbstractPrintDialog::setFromTo",
326  "'from' must be less than or equal to 'to'");
327  d->pd->fromPage = from;
328  d->pd->toPage = to;
329 
330  if (d->pd->minPage == 0 && d->pd->maxPage == 0)
331  setMinMax(1, to);
332 }
333 
339 {
340  Q_D(const QAbstractPrintDialog);
341  return d->pd->fromPage;
342 }
343 
349 {
350  Q_D(const QAbstractPrintDialog);
351  return d->pd->toPage;
352 }
353 
354 
360 {
361  Q_D(const QAbstractPrintDialog);
362  return d->printer;
363 }
364 
366 {
367  if (newPrinter) {
368  printer = newPrinter;
369  ownsPrinter = false;
370  } else {
371  printer = new QPrinter;
372  ownsPrinter = true;
373  }
374  pd = printer->d_func();
375 }
376 
472 {
474  d->setTabs(tabs);
475 }
476 
504 {
505  Q_D(QPrintDialog);
506  QDialog::done(result);
507  if (result == Accepted)
508  emit accepted(printer());
509  if (d->receiverToDisconnectOnClose) {
511  d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);
512  d->receiverToDisconnectOnClose = 0;
513  }
514  d->memberToDisconnectOnClose.clear();
515 }
516 
529 void QPrintDialog::open(QObject *receiver, const char *member)
530 {
531  Q_D(QPrintDialog);
532  connect(this, SIGNAL(accepted(QPrinter*)), receiver, member);
533  d->receiverToDisconnectOnClose = receiver;
534  d->memberToDisconnectOnClose = member;
535  QDialog::open();
536 }
537 
539 
540 #endif // QT_NO_PRINTDIALOG
double d
Definition: qnumeric_p.h:62
QAbstractPrintDialog(QPrinter *printer, QWidget *parent=0)
Constructs an abstract print dialog for printer with parent as parent widget.
bool testOption(PrintDialogOption option) const
Returns true if the given option is enabled; otherwise, returns false.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QDialog class is the base class of dialog windows.
Definition: qdialog.h:56
bool isOptionEnabled(PrintDialogOption option) const
Use QPrintDialog::testOption(option) instead.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void setOptionTabs(const QList< QWidget *> &tabs)
Set a list of widgets as tabs to be shown on the print dialog, if supported.
PrintDialogOptions options() const
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
int minPage() const
Returns the minimum page in the page range.
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
The QPrintDialog class provides a dialog for specifying the printer&#39;s configuration.
Definition: qprintdialog.h:81
QPrinter * printer() const
Returns the printer that this printer dialog operates on.
void setWindowTitle(const QString &)
Definition: qwidget.cpp:6312
PrintRange
Used to specify the print range selection option.
void setOptions(PrintDialogOptions options)
void setMinMax(int min, int max)
Sets the page range in this dialog to be from min to max.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
PrintDialogOption
Used to specify which parts of the print dialog should be visible.
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
PrintRange printRange() const
Returns the print range.
int fromPage() const
Returns the first page to be printed By default, this value is set to 0.
#define emit
Definition: qobjectdefs.h:76
int toPage() const
Returns the last page to be printed.
void setFromTo(int fromPage, int toPage)
Sets the range in the print dialog to be from from to to.
const T * ptr(const T &t)
int maxPage() const
Returns the maximum page in the page range.
void done(int result)
Closes the dialog and sets its result code to result.
virtual void done(int)
Closes the dialog and sets its result code to r.
Definition: qdialog.cpp:617
void setEnabledOptions(PrintDialogOptions options)
Use QPrintDialog::setOptions() instead.
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
The QAbstractPrintDialog class provides a base implementation for print dialogs used to configure pri...
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
int result() const
In general returns the modal dialog&#39;s result code, Accepted or Rejected.
Definition: qdialog.cpp:458
QObject * parent
Definition: qobject.h:92
void accepted()
This signal is emitted when the dialog has been accepted either by the user or by calling accept() or...
void setOption(PrintDialogOption option, bool on=true)
Sets the given option to be enabled if on is true; otherwise, clears the given option.
void setPrintRange(PrintRange range)
Sets the print range option in to be range.
void open()
Shows the dialog as a window modal dialog, returning immediately.
Definition: qdialog.cpp:492
void addEnabledOption(PrintDialogOption option)
Use QPrintDialog::setOption(option, true) instead.
PrintDialogOptions enabledOptions() const
Use QPrintDialog::options() instead.
void setPrinter(QPrinter *newPrinter)