-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbarcode.h
155 lines (137 loc) · 4.77 KB
/
barcode.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
155
/*
SPDX-FileCopyrightText: 2010-2016 Sune Vuorela <[email protected]>
SPDX-FileCopyrightText: 2023 Volker Krause <[email protected]>
SPDX-License-Identifier: MIT
*/
#ifndef PRISON_BARCODE_H
#define PRISON_BARCODE_H
#include "prison_export.h"
#include "prison.h"
#include <qglobal.h>
#include <memory>
class QByteArray;
class QColor;
class QImage;
class QSizeF;
class QString;
namespace Prison
{
class AbstractBarcodePrivate;
/**
* A barcode generator for a fixed barcode format.
*
* @note This replaces Prison::createBarcode and AbstractBarcode* from KF5.
* You can create Barcode instances directly now and specify the format in its
* constructor.
* Rather than checking for createBarcode returning a @c nullptr, check whether
* the format is not Prison::Null.
*
* @since 6.0
*/
class PRISON_EXPORT Barcode
{
public:
Barcode(Barcode &&);
~Barcode();
Barcode &operator=(Barcode &&);
/** Barcode format of this barcode generator. */
Prison::BarcodeType format() const;
/**
* Textual content encoded in this barcode.
* This returns an empty QString if binary content is set.
* @see byteArrayData()
*/
QString data() const;
/**
* Binary data encoded in this barcode.
* This returns an empty QByteArray if textual content is set.
* @see data()
* @since 5.85
*/
QByteArray byteArrayData() const;
/**
* Sets textual data to be drawn as a barcode.
* Only use this function if your content is textual, use the QByteArray overload
* when your content contains non-textual binary content.
* Calling this function does not do any repaints of anything, they are
* your own responsibility.
* @param data textual barcode content
*/
void setData(const QString &data);
/**
* Sets binary data to be drawn as a barcode.
* Prefer the QString overload if your content is purely textual, to reduce
* the risk of encoding issues for non-ASCII content.
* Calling this function does not do any repaints of anything, they are
* your own responsibility.
* @param data binary barcode content
* @since 5.85
*/
void setData(const QByteArray &data);
/**
* Creates a image with a barcode on
* @return QImage with a barcode on, trying to match the requested \param size
*
* If one of the dimensions of @param size is smaller than the matching dimension in \ref minimumSize,
* a null QImage will be returned
*/
QImage toImage(const QSizeF &size);
/**
* The minimal amount of pixels needed to represent this barcode without loss of information.
* That is, the size of the barcode image if each line or dot is just one pixel wide.
* On normal screens that is not enough for barcode scanners to reliably detect the barcode
* though.
* @see preferredSize
*/
QSizeF minimumSize() const;
/**
* The recommended size for this barcode when shown on a screen.
* This is typically significantly larger than trueMinimumSize() so that
* barcode scanners tend to reliably detect the code. As this depends
* on the physical resolution of the output, you have to pass the device
* pixel ration of the output screen here.
* @param devicePixelRatio The device pixel ratio of the screen this is shown on.
* @see trueMinimumSize
* @since 5.69
*/
QSizeF preferredSize(qreal devicePixelRatio) const;
/**
* @return the foreground color (by default black) to be used for the barcode.
*/
QColor foregroundColor() const;
/**
* @return the background color (by default white) to be used for the barcode.
*/
QColor backgroundColor() const;
/**
* sets the foreground color
* @param foregroundcolor - the new foreground color
*/
void setForegroundColor(const QColor &foregroundcolor);
/**
* sets the background color
* @param backgroundcolor - the new background color
*/
void setBackgroundColor(const QColor &backgroundcolor);
/** Dimensions of the barcode. */
enum Dimensions : uint8_t {
NoDimensions, ///< Null barcode.
OneDimension, ///< One-dimensional barcode.
TwoDimensions, ///< 2D matrix code.
};
/** Returns the amount of dimensions of the barcode. */
Dimensions dimensions() const;
/** Create a new barcode generator.
*
* If a format is requested that is not supported by the current build
* due to missing/disabled optional dependencies, Barcode::format() will
* return Prison::Null.
*/
static std::optional<Prison::Barcode> create(Prison::BarcodeType type);
private:
friend class AbstractBarcodePrivate;
explicit Barcode(std::unique_ptr<AbstractBarcodePrivate> &&d);
std::unique_ptr<class AbstractBarcodePrivate> d;
};
}
#endif