18 #include "KReportItemBarcode.h"
19 #include "KReportUtils.h"
22 #include <KPropertyListData>
23 #include <KPropertySet>
27 #include "kreportplugin_debug.h"
31 KReportItemBarcode::KReportItemBarcode()
32 : m_minWidthData(0), m_minWidthTotal(0), m_minHeight(0)
37 KReportItemBarcode::KReportItemBarcode(
const QDomNode & element)
38 : KReportItemBarcode()
40 nameProperty()->setValue(KReportUtils::readNameAttribute(element.
toElement()));
50 void KReportItemBarcode::setMaxLength(
int i)
53 if (m_maxLength->value().toInt() != i) {
54 m_maxLength->setValue(i);
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();
116 void KReportItemBarcode::createProperties()
118 createDataSourceProperty();
121 tr(
"Value used if not bound to a field"));
125 QVariantList{ tr(
"Left"), tr(
"Center"), tr(
"Right") });
127 tr(
"Horizontal Alignment"));
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")
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);
156 KReportItemBarcode::~KReportItemBarcode()
160 Qt::Alignment KReportItemBarcode::horizontalAlignment()
const
162 return KReportUtils::horizontalAlignment(m_horizontalAlignment->value().toString(),
166 QString KReportItemBarcode::format()
const
168 return m_format->value().toString();
171 int KReportItemBarcode::maxLength()
const
173 return m_maxLength->value().
toInt();
176 void KReportItemBarcode::setFormat(
const QString& f)
178 m_format->setValue(f);
181 void KReportItemBarcode::setHorizontalAlignment(
Qt::Alignment value)
183 m_horizontalAlignment->setValue(KReportUtils::horizontalToString(value));
187 QString KReportItemBarcode::typeName()
const
193 const QVariant &data, KReportScriptHandler *script)
198 QPointF pos = scenePosition(position());
199 QSizeF siz = sceneSize(size());
206 if (itemDataSource().isEmpty()) {
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;