Qt 4.8
qprinterinfo_mac.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 "qprinterinfo.h"
43 #include "qprinterinfo_p.h"
44 
45 #include "private/qt_mac_p.h"
46 
48 
49 #ifndef QT_NO_PRINTER
50 
51 extern QPrinter::PaperSize qSizeFTopaperSize(const QSizeF &size);
52 
54 {
55  QList<QPrinterInfo> printers;
56 
57  QCFType<CFArrayRef> array;
58  if (PMServerCreatePrinterList(kPMServerLocal, &array) == noErr) {
59  CFIndex count = CFArrayGetCount(array);
60  for (int i = 0; i < count; ++i) {
61  PMPrinter printer = static_cast<PMPrinter>(const_cast<void *>(CFArrayGetValueAtIndex(array, i)));
62  QString printerName = QCFString::toQString(PMPrinterGetName(printer));
63 
64  QPrinterInfo printerInfo(printerName);
65  if (PMPrinterIsDefault(printer))
66  printerInfo.d_ptr->isDefault = true;
67  printers.append(printerInfo);
68  }
69  }
70 
71  return printers;
72 }
73 
75 {
77  foreach (const QPrinterInfo &printerInfo, printers) {
78  if (printerInfo.isDefault())
79  return printerInfo;
80  }
81 
82  return printers.value(0);
83 }
84 
86 {
87  const Q_D(QPrinterInfo);
88 
89  QList<QPrinter::PaperSize> paperSizes;
90  if (isNull())
91  return paperSizes;
92 
93  PMPrinter cfPrn = PMPrinterCreateFromPrinterID(QCFString::toCFStringRef(d->name));
94  if (!cfPrn)
95  return paperSizes;
96 
97  CFArrayRef array;
98  if (PMPrinterGetPaperList(cfPrn, &array) != noErr) {
99  PMRelease(cfPrn);
100  return paperSizes;
101  }
102 
103  int count = CFArrayGetCount(array);
104  for (int i = 0; i < count; ++i) {
105  PMPaper paper = static_cast<PMPaper>(const_cast<void *>(CFArrayGetValueAtIndex(array, i)));
106  double width, height;
107  if (PMPaperGetWidth(paper, &width) == noErr && PMPaperGetHeight(paper, &height) == noErr) {
108  QSizeF size(width * 0.3527, height * 0.3527);
109  paperSizes.append(qSizeFTopaperSize(size));
110  }
111  }
112 
113  PMRelease(cfPrn);
114 
115  return paperSizes;
116 }
117 
118 #endif // QT_NO_PRINTER
119 
double d
Definition: qnumeric_p.h:62
QPrinter::PaperSize qSizeFTopaperSize(const QSizeF &size)
Definition: qprinter.cpp:2629
static QPrinterInfo defaultPrinter()
Returns the default printer on the system.
QList< QPrinter::PaperSize > supportedPaperSizes() const
Returns a list of supported paper sizes by the printer.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static CFStringRef toCFStringRef(const QString &str)
Definition: qcore_mac.cpp:69
static QString toQString(CFStringRef cfstr)
Definition: qcore_mac.cpp:47
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
T value(int i) const
Returns the value at index position i in the list.
Definition: qlist.h:661
bool isDefault() const
Returns whether this printer is the default printer.
The QPrinterInfo class gives access to information about existing printers.
Definition: qprinterinfo.h:58
QString printerName() const
Returns the name of the printer.
QScopedPointer< QPrinterInfoPrivate, QPrinterInfoPrivateDeleter > d_ptr
Definition: qprinterinfo.h:81
PaperSize
This enum type specifies what paper size QPrinter should use.
Definition: qprinter.h:91
static QList< QPrinterInfo > availablePrinters()
Returns a list of available printers on the system.
bool isNull() const
Returns whether this QPrinterInfo object holds a printer definition.
const struct __CFArray * CFArrayRef
The QList class is a template class that provides lists.
Definition: qdatastream.h:62