18#include "KReportItemBarcode.h"
19#include "KReportUtils.h"
22#include <KPropertyListData>
23#include <KPropertySet>
27#include "kreportplugin_debug.h"
31KReportItemBarcode::KReportItemBarcode()
32 : m_minWidthData(0), m_minWidthTotal(0), m_minHeight(0)
37KReportItemBarcode::KReportItemBarcode(
const QDomNode & element)
38 : KReportItemBarcode()
40 nameProperty()->setValue(KReportUtils::readNameAttribute(element.
toElement()));
50void KReportItemBarcode::setMaxLength(
int i)
53 if (m_maxLength->value().toInt() != i) {
54 m_maxLength->setValue(i);
56 if (m_format->value().toString() == QLatin1String(
"3of9")) {
61 m_minWidthData = (((C + 2) * ((3 * N) + 6) * X) + ((C + 1) * I)) / 100.0;
65 m_minWidthTotal = m_minWidthData + 0.22;
67 }
else if (m_format->value().toString() == QLatin1String(
"3of9+")) {
72 m_minWidthData = (((C + 2) * ((3 * N) + 6) * X) + ((C + 1) * I)) / 100.0;
76 m_minWidthTotal = m_minWidthData + 0.22;
78 }
else if (m_format->value().toString() == QLatin1String(
"i2of5")) {
82 m_minWidthTotal = ((C * (2.0*N + 3.0) + 6.0 + N) * X);
84 m_minWidthTotal = m_minWidthData + 0.22;
85 }
else if (m_format->value().toString() == QLatin1String(
"128")) {
88 m_minWidthData = (((11 * C) + 35) * X) / 100.0;
92 m_minWidthTotal = m_minWidthData + 0.22;
94 }
else if (m_format->value().toString() == QLatin1String(
"upc-a")) {
95 m_minWidthData = 0.95;
96 m_minWidthTotal = 1.15;
98 }
else if (m_format->value().toString() == QLatin1String(
"upc-e")) {
99 m_minWidthData = 0.52;
100 m_minWidthTotal = 0.70;
102 }
else if (m_format->value().toString() == QLatin1String(
"ean13")) {
103 m_minWidthData = 0.95;
104 m_minWidthTotal = 1.15;
106 }
else if (m_format->value().toString() == QLatin1String(
"ean8")) {
107 m_minWidthData = 0.67;
108 m_minWidthTotal = 0.90;
111 kreportpluginWarning() <<
"Unknown format encountered: " << m_format->value().toString();
116void KReportItemBarcode::createProperties()
118 createDataSourceProperty();
120 m_itemValue =
new KProperty(
"value", QString(),
tr(
"Value"),
121 tr(
"Value used if not bound to a field"));
123 KPropertyListData *listData =
new KPropertyListData(
124 { QLatin1String(
"left"), QLatin1String(
"center"), QLatin1String(
"right") },
125 QVariantList{
tr(
"Left"),
tr(
"Center"),
tr(
"Right") });
126 m_horizontalAlignment =
new KProperty(
"horizontal-align", listData, QLatin1String(
"left"),
127 tr(
"Horizontal Alignment"));
129 listData =
new KPropertyListData(
131 << QLatin1String(
"3of9") << QLatin1String(
"3of9+") << QLatin1String(
"128")
132 << QLatin1String(
"ean8") << QLatin1String(
"ean13") << QLatin1String(
"i2of5")
133 << QLatin1String(
"upc-a") << QLatin1String(
"upc-e"),
135 <<
tr(
"Code 3 of 9",
"Barcode symbology, keep short")
136 <<
tr(
"Code 3 of 9 Ext.",
"3 of 3 Extended: Barcode symbology, keep short")
137 <<
tr(
"Code 128",
"Barcode symbology, keep short")
138 <<
tr(
"EAN-8",
"Barcode symbology, keep short")
139 <<
tr(
"EAN-13",
"Barcode symbology, keep short")
140 <<
tr(
"Interleaved 2 of 5",
"Interleaved barcode 2 of 5: barcode symbology, keep short")
141 <<
tr(
"UPC-A",
"Barcode symbology, keep short")
142 <<
tr(
"UPC-E",
"Barcode symbology, keep short")
144 m_format =
new KProperty(
"barcode-format", listData, QLatin1String(
"3of9"),
145 tr(
"Barcode Format"));
147 m_maxLength =
new KProperty(
"barcode-max-length", 5,
tr(
"Max Length"),
148 tr(
"Maximum Barcode Length"));
150 propertySet()->addProperty(m_itemValue);
151 propertySet()->addProperty(m_format);
152 propertySet()->addProperty(m_horizontalAlignment);
153 propertySet()->addProperty(m_maxLength);
156KReportItemBarcode::~KReportItemBarcode()
162 return KReportUtils::horizontalAlignment(m_horizontalAlignment->value().toString(),
166QString KReportItemBarcode::format()
const
168 return m_format->value().toString();
171int KReportItemBarcode::maxLength()
const
173 return m_maxLength->value().
toInt();
176void KReportItemBarcode::setFormat(
const QString& f)
178 m_format->setValue(f);
181void KReportItemBarcode::setHorizontalAlignment(
Qt::Alignment value)
183 m_horizontalAlignment->setValue(KReportUtils::horizontalToString(value));
187QString KReportItemBarcode::typeName()
const
189 return QLatin1String(
"barcode");
193 const QVariant &data, KReportScriptHandler *script)
202 QRectF rect = QRectF(pos, siz);
207 val = m_itemValue->value().toString();
213 QByteArray fmt = m_format->value().toByteArray();
216 render3of9(page, rect, val, align);
217 else if (fmt ==
"3of9+")
218 renderExtended3of9(page, rect, val, align);
219 else if (fmt ==
"i2of5")
220 renderI2of5(page, rect, val, align);
221 else if (fmt ==
"128")
222 renderCode128(page, rect, val, align);
223 else if (fmt ==
"ean13")
224 renderCodeEAN13(page, rect, val, align);
225 else if (fmt ==
"ean8")
226 renderCodeEAN8(page, rect, val, align);
227 else if (fmt ==
"upc-a")
228 renderCodeUPCA(page, rect, val, align);
229 else if (fmt ==
"upc-e")
230 renderCodeUPCE(page, rect, val, align);
232 kreportpluginWarning() <<
"Unknown barcode format:" << fmt;
static QPointF scenePosition(const QPointF &ptPos)
Helper function mapping to screen units (pixels), ptPos is in points.
QPointF position() const
Return the position in points.
static QSizeF sceneSize(const QSizeF &ptSize)
Helper function mapping to screen units (pixels), ptSize is in points.
QSizeF size() const
Return the size in points.
QString itemDataSource() const
Represents a single page in a document and may contain zero or more OROPrimitive objects all of which...
Represents a single a single row in a document and may contain zero or more OROPrimitives.
QString attribute(const QString &name, const QString &defValue) const const
QDomElement toElement() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
int toInt(bool *ok, int base) const const
QString toString() const const