-
Notifications
You must be signed in to change notification settings - Fork 2
/
printer.h
155 lines (136 loc) · 4.54 KB
/
printer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#ifndef PRINTER_H
#define PRINTER_H
#ifndef QT_NO_PRINTER
# include <QPrinter>
# include <QPrintDialog>
#endif
#include <QQuickItem>
#include <QJSValue>
class Printer : public QQuickItem
{
Q_OBJECT
QML_ELEMENT
Q_DISABLE_COPY(Printer)
public:
typedef enum { Print, PrintToFile, GrabOnly } GrabMode;
Q_ENUMS(GrabMode);
private:
QSharedPointer<QQuickItemGrabResult> m_result;
QQuickItem *m_item;
#ifndef QT_NO_PRINTER
QPrintDialog *m_printDialogue;
QPrinter *m_printer;
bool m_pagePrinted;
bool m_sessionOpen;
int m_copyCount;
QPainter *m_painter;
bool m_antialias;
bool m_monochrome;
QString m_filepath;
QRectF m_margins;
#endif
GrabMode m_mode;
QString m_fileDest;
QString m_fileType;
int m_fileQuality;
QJSValue m_callback;
Q_PROPERTY(QQuickItem* item READ getItem WRITE setItem NOTIFY itemChanged)
Q_PROPERTY(bool printingSupported READ printingSupported CONSTANT)
#ifndef QT_NO_PRINTER
Q_PROPERTY(QString filepath READ getFilePath WRITE setFilePath NOTIFY filePathChanged)
Q_PROPERTY(bool antialias READ getAntialias WRITE setAntialias NOTIFY antialiasChanged)
Q_PROPERTY(bool monochrome READ getMonochrome WRITE setMonochrome NOTIFY monochromeChanged)
Q_PROPERTY(int resolution READ getResolution WRITE setResolution NOTIFY resolutionChanged)
Q_PROPERTY(int copyCount READ getCopyCount WRITE setCopyCount NOTIFY copyCountChanged)
Q_PROPERTY(QRectF pageRect READ getPageRect NOTIFY sizeChanged)
Q_PROPERTY(QRectF paperRect READ getPaperRect NOTIFY sizeChanged)
Q_PROPERTY(QStringList paperSizes READ getPaperSizes)
Q_PROPERTY(QString printerName READ getPrinterName WRITE setPrinterName NOTIFY printerNameChanged)
Q_PROPERTY(Status status READ getStatus)
#endif
public:
Printer(QQuickItem *parent = 0);
~Printer();
#ifndef QT_NO_PRINTER
typedef enum {
Millimeter = QPageSize::Millimeter,
Point = QPageSize::Point,
Inch = QPageSize::Inch,
Pica = QPageSize::Pica,
Didot = QPageSize::Didot,
Cicero = QPageSize::Cicero,
DevicePixel
} Unit;
Q_ENUMS(Unit)
typedef enum {
Idle = QPrinter::Idle,
Active = QPrinter::Active,
Aborted = QPrinter::Aborted,
Error = QPrinter::Error,
Unknown
} Status;
Q_ENUMS(Status)
#endif
public slots:
bool printingSupported() const;
#ifndef QT_NO_PRINTER
bool print(QJSValue callback=QJSValue());
bool setup();
bool open();
bool close();
bool newPage() const;
bool abort();
#endif
bool grabImage(const QString &fileFormat, int quality=100, QJSValue callback=QJSValue());
bool saveImage(const QString &fileName, const QString &fileFormat, int quality, QJSValue callback=QJSValue());
#ifndef QT_NO_PRINTER
bool printImage(const QImage &img);
bool printImageData(const QByteArray &img);
#endif
// Property Hooks:
void setItem( QQuickItem *item );
#ifndef QT_NO_PRINTER
void setFilePath(const QString &filepath);
void setMonochrome(bool toggle);
void setAntialias(bool toggle);
void setMargins(double top, double right, double bottom, double left);
bool setPageSize( qreal width, qreal height, Unit unit );
bool setPageSize( const QString &paperSize );
void setPrinterName(const QString &printerName);
void setResolution(int dpi);
void setCopyCount(int count);
#endif
QQuickItem *getItem() const { return m_item; }
#ifndef QT_NO_PRINTER
QString getFilePath() const { return m_filepath; }
bool getMonochrome() const { return m_monochrome; }
bool getAntialias() const { return m_antialias; }
QRectF getMargins() const { return m_margins; }
QRectF getPageRect(Unit unit=DevicePixel) const;
QRectF getPaperRect(Unit unit=DevicePixel) const;
QStringList getPaperSizes() const;
QString getPrinterName() const;
int getResolution() const { return m_printer->resolution(); }
int getCopyCount() const { return m_printer->copyCount(); }
Status getStatus() const;
#endif
private slots:
bool grab();
void grabbed();
signals:
void itemChanged();
void frameGrabbed(const QByteArray &imageData);
void sizeChanged();
void printComplete();
void printError();
#ifndef QT_NO_PRINTER
void filePathChanged();
void monochromeChanged();
void antialiasChanged();
void marginsChanged();
void printerNameChanged();
void resolutionChanged();
void copyCountChanged();
#endif
};
#endif // PRINTER_H