int KoReportItemLabel::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KRScriptHandler *script) { Q_UNUSED(data) Q_UNUSED(script) OROTextBox * tb = new OROTextBox(); tb->setPosition(m_pos.toScene() + offset); tb->setSize(m_size.toScene()); tb->setFont(font()); tb->setText(text()); tb->setFlags(textFlags()); tb->setTextStyle(textStyle()); tb->setLineStyle(lineStyle()); if (page) { page->addPrimitive(tb); } if (section) { OROPrimitive *clone = tb->clone(); clone->setPosition(m_pos.toScene()); section->addPrimitive(clone); } if (!page) { delete tb; } return 0; //Item doesn't stretch the section height }
int KReportItemText::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { Q_UNUSED(script); QString qstrValue; QString cs = itemDataSource(); if (!cs.isEmpty()) { if (cs.left(1) == QLatin1String("$")) { //Everything past $ is treated as a string qstrValue = cs.mid(1); } else { qstrValue = data.toString(); } } else { qstrValue = m_itemValue->value().toString(); } QPointF pos = m_pos.toScene(); QSizeF size = m_size.toScene(); pos += offset; QRectF trf(pos, size); qreal intStretch = trf.top() - offset.y(); if (qstrValue.length()) { QRectF rect = trf; int pos = 0; QChar separator; QRegExp re(QLatin1String("\\s")); QPrinter prnt(QPrinter::HighResolution); QFontMetrics fm(font(), &prnt); // int intRectWidth = (int)(trf.width() * prnt.resolution()) - 10; int intRectWidth = (int)((m_size.toPoint().width() / 72) * prnt.resolution()); int intLineCounter = 0; qreal intBaseTop = trf.top(); qreal intRectHeight = trf.height(); while (qstrValue.length()) { int idx = re.indexIn(qstrValue, pos); if (idx == -1) { idx = qstrValue.length(); separator = QLatin1Char('\n'); } else separator = qstrValue.at(idx); if (fm.boundingRect(qstrValue.left(idx)).width() < intRectWidth || pos == 0) { pos = idx + 1; if (separator == QLatin1Char('\n')) { QString line = qstrValue.left(idx); qstrValue.remove(0, idx + 1); pos = 0; rect.setTop(intBaseTop + (intLineCounter * intRectHeight)); rect.setBottom(rect.top() + intRectHeight); OROTextBox * tb = new OROTextBox(); tb->setPosition(rect.topLeft()); tb->setSize(rect.size()); tb->setFont(font()); tb->setText(line); tb->setFlags(textFlags()); tb->setTextStyle(textStyle()); tb->setLineStyle(lineStyle()); if (page) { page->addPrimitive(tb); } if (section) { OROTextBox *tb2 = dynamic_cast<OROTextBox*>(tb->clone()); tb2->setPosition(m_pos.toPoint()); section->addPrimitive(tb2); } if (!page) { delete tb; } intStretch += intRectHeight; intLineCounter++; } } else { QString line = qstrValue.left(pos - 1); qstrValue.remove(0, pos); pos = 0; rect.setTop(intBaseTop + (intLineCounter * intRectHeight)); rect.setBottom(rect.top() + intRectHeight); OROTextBox * tb = new OROTextBox(); tb->setPosition(rect.topLeft()); tb->setSize(rect.size()); tb->setFont(font()); tb->setText(line); tb->setFlags(textFlags()); tb->setTextStyle(textStyle()); tb->setLineStyle(lineStyle()); if (page) page->addPrimitive(tb); intStretch += intRectHeight; intLineCounter++; } } intStretch += (m_bottomPadding / 100.0); } return intStretch; //Item returns its required section height }
void renderCodeEAN13(OROPage * page, const QRectF & r, const QString & _str, ORBarcodeData * bc) { int val[13]; int i = 0; // initialize all the values just so we can be predictable for(i = 0; i < 13; i++) val[i] = -1; // verify that the passed in string is valid // if it's not either twelve or thirteen characters // then it must be invalid to begin with if(_str.length() != 12 && _str.length() != 13) return; // loop through and convert each char to a digit. // if we can't convert all characters then this is // an invalid number for(i = 0; i < _str.length(); i++) { val[i] = ((QChar)_str.at(i)).digitValue(); if(val[i] == -1) return; } // calculate and append the checksum value int old_sum = val[12]; // get the old check sum value (-1 if none was set) int checksum = 0; for(i = 0; i < 12; i++) checksum += val[i] * (i % 2 ? 3 : 1); checksum = (checksum % 10); if(checksum) checksum = 10 - checksum; val[12] = checksum; // if we had an old checksum value and if it doesn't match what we came // up with then the string must be invalid so we will bail if(old_sum != -1 && old_sum != checksum) return; // lets determine some core attributes about this barcode qreal bar_width = bc->narrowBarWidth; // this is are mandatory minimum quiet zone qreal quiet_zone = bar_width * 10; if(quiet_zone < 0.1) quiet_zone = 0.1; // what kind of area do we have to work with qreal draw_width = r.width(); qreal draw_height = r.height() - 0.02; // L = 95X // L length of barcode (excluding quite zone) in units same as X and I // X the width of a bar (pixels in our case) qreal L; qreal X = bar_width; L = (95.0 * X); // now we have the actual width the barcode will be so can determine the actual // size of the quiet zone (we assume we center the barcode in the given area // what should we do if the area is too small???? // At the moment the way the code is written is we will always start at the minimum // required quiet zone if we don't have enough space.... I guess we'll just have over-run // to the right // // calculate the starting position based on the alignment option // for left align we don't need to do anything as the values are already setup for it if(bc->align == 1) // center { qreal nqz = (draw_width - L) / 2; if(nqz > quiet_zone) quiet_zone = nqz; } else if(bc->align > 1) // right quiet_zone = draw_width - (L + quiet_zone); // else if(align < 1) {} // left : do nothing qreal pos = r.left() + quiet_zone; qreal top = r.top(); QPen pen(Qt::NoPen); QBrush brush(QColor("black")); int b = 0; int w = 0; // render open guard ORORect * rect = new ORORect(bc); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height)); rect->setRotationAxis(r.topLeft()); page->addPrimitive(rect); pos += (bar_width * 2.0); rect = new ORORect(bc); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height)); rect->setRotationAxis(r.topLeft()); page->addPrimitive(rect); pos += bar_width; // render first set for(i = 0; i < 6; i++) { b = val[i+1]; for(w = 0; w < 7; w++) { if(_encodings[b][_parity[val[0]][i]][w]) { rect = new ORORect(bc); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height-0.07)); rect->setRotationAxis(r.topLeft()); page->addPrimitive(rect); } pos += bar_width; } } // render center guard pos += bar_width; rect = new ORORect(bc); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height)); rect->setRotationAxis(r.topLeft()); page->addPrimitive(rect); pos += (bar_width * 2.0); rect = new ORORect(bc); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height)); rect->setRotationAxis(r.topLeft()); page->addPrimitive(rect); pos += (bar_width * 2.0); // render last set for(i = 0; i < 6; i++) { b = val[i+7]; for(w = 0; w < 7; w++) { if(_encodings[b][RIGHTHAND][w]) { rect = new ORORect(bc); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height-0.07)); rect->setRotationAxis(r.topLeft()); page->addPrimitive(rect); } pos += bar_width; } } // render close guard rect = new ORORect(bc); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height)); rect->setRotationAxis(r.topLeft()); page->addPrimitive(rect); pos += (bar_width * 2.0); rect = new ORORect(bc); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height)); rect->setRotationAxis(r.topLeft()); page->addPrimitive(rect); QString parstr = QString("%1").arg(val[0]); QString leftstr = QString().sprintf("%d%d%d%d%d%d", val[1], val[2], val[3], val[4], val[5], val[6]); QString rightstr = QString().sprintf("%d%d%d%d%d%d", val[7], val[8], val[9], val[10], val[11], val[12]); QFont font("Arial", 6); OROTextBox * tb = new OROTextBox(bc); tb->setPosition(QPointF(r.left(), r.top() + draw_height - 0.12)); tb->setSize(QSizeF(quiet_zone - 0.02, 0.12)); tb->setFont(font); tb->setText(parstr); tb->setFlags(Qt::AlignRight | Qt::AlignTop); rect->setRotationAxis(r.topLeft()); page->addPrimitive(tb); tb = new OROTextBox(bc); tb->setPosition(QPointF(r.left() + quiet_zone + 0.03, (r.top() + draw_height) - 0.07)); tb->setSize(QSizeF(0.42, 0.1)); tb->setFont(font); tb->setText(leftstr); tb->setFlags(Qt::AlignHCenter | Qt::AlignTop); rect->setRotationAxis(r.topLeft()); page->addPrimitive(tb); tb = new OROTextBox(bc); tb->setPosition(QPointF(r.left() + quiet_zone + 0.5, (r.top() + draw_height) - 0.07)); tb->setSize(QSizeF(0.42, 0.1)); tb->setFont(font); tb->setText(rightstr); tb->setFlags(Qt::AlignHCenter | Qt::AlignTop); rect->setRotationAxis(r.topLeft()); page->addPrimitive(tb); return; }
void renderCodeUPCE(OROPage * page, const QRectF & r, const QString & _str, int align) { int val[8]; int i = 0; // initialize all the values just so we can be predictable for(i = 0; i < 8; i++) val[i] = -1; // verify that the passed in string is valid // if it's not either twelve or thirteen characters // then it must be invalid to begin with if(_str.length() != 8) return; // loop through and convert each char to a digit. // if we can't convert all characters then this is // an invalid number for(i = 0; i < _str.length(); i++) { val[i] = ((QChar)_str.at(i)).digitValue(); if(val[i] == -1) return; } // calculate and append the checksum value // because everything is so messed up we don't calculate // the checksum and require that it be passed in already // however we do have to verify that the first digit is // either 0 or 1 as that is our parity if(val[0] != 0 && val[0] != 1) return; // lets determine some core attributes about this barcode qreal bar_width = 0.01; // the width of the base unit bar // this is are mandatory minimum quiet zone qreal quiet_zone = bar_width * 0.10; if(quiet_zone < 0.10) quiet_zone = 0.10; // what kind of area do we have to work with qreal draw_width = r.width(); qreal draw_height = r.height() - 0.02; // L = 51X // L length of barcode (excluding quite zone) in units same as X and I // X the width of a bar (pixels in our case) qreal L; qreal X = bar_width; L = (51.0 * X); // now we have the actual width the barcode will be so can determine the actual // size of the quiet zone (we assume we center the barcode in the given area // what should we do if the area is too small???? // At the moment the way the code is written is we will always start at the minimum // required quiet zone if we don't have enough space.... I guess we'll just have over-run // to the right // // calculate the starting position based on the alignment option // for left align we don't need to do anything as the values are already setup for it if(align == 1) // center { qreal nqz = (draw_width - L) / 2; if(nqz > quiet_zone) quiet_zone = nqz; } else if(align > 1) // right quiet_zone = draw_width - (L + quiet_zone); // else if(align < 1) {} // left : do nothing qreal pos = r.left() + quiet_zone; qreal top = r.top(); QPen pen(Qt::NoPen); QBrush brush(QColor("black")); int b = 0; int w = 0; // render open guard ORORect * rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height)); page->addPrimitive(rect); pos += (bar_width * 2.0); rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height)); page->addPrimitive(rect); pos += bar_width; // render first set for(i = 0; i < 6; i++) { b = val[i+1]; for(w = 0; w < 7; w++) { if(_encodings[b][_upcparenc[val[7]][val[0]][i]][w]) { rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height - 0.07)); page->addPrimitive(rect); } pos += bar_width; } } // render center guard pos += bar_width; rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height)); page->addPrimitive(rect); pos += (bar_width * 2.0); rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height)); page->addPrimitive(rect); pos += (bar_width * 2.0); // render close guard rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height)); page->addPrimitive(rect); QString parstr = QString("%1").arg(val[0]); QString chkstr = QString("%1").arg(val[7]); QString leftstr = QString().sprintf("%d%d%d%d%d%d", val[1], val[2], val[3], val[4], val[5], val[6]); QFont font("Arial",6); OROTextBox * tb = new OROTextBox(); tb->setPosition(QPointF(r.left(), r.top() + draw_height - 0.12)); tb->setSize(QSizeF(quiet_zone - 0.02, 0.12)); tb->setFont(font); tb->setText(parstr); tb->setFlags(Qt::AlignRight | Qt::AlignTop); page->addPrimitive(tb); tb = new OROTextBox(); tb->setPosition(QPointF(r.left() + quiet_zone + 0.03, (r.top() + draw_height) - 0.07)); tb->setSize(QSizeF(0.42, 0.10)); tb->setFont(font); tb->setText(leftstr); tb->setFlags(Qt::AlignHCenter | Qt::AlignTop); page->addPrimitive(tb); tb = new OROTextBox(); tb->setPosition(QPointF(r.left() + quiet_zone + L + 0.02, r.top() + draw_height - 0.12)); tb->setSize(QSizeF(0.08, 0.12)); tb->setFont(font); tb->setText(chkstr); tb->setFlags(Qt::AlignLeft | Qt::AlignTop); page->addPrimitive(tb); return; }
int KReportItemField::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { OROTextBox * tb = new OROTextBox(); tb->setPosition(scenePosition(position()) + offset); tb->setSize(sceneSize(size())); tb->setFont(font()); tb->setFlags(textFlags()); tb->setTextStyle(textStyle()); tb->setLineStyle(lineStyle()); tb->setCanGrow(m_canGrow->value().toBool()); tb->setWordWrap(m_wordWrap->value().toBool()); QString str; QString ids = itemDataSource(); if (!ids.isEmpty()) { #ifdef KREPORT_SCRIPTING if (ids.left(1) == QLatin1String("=") && script) { //Everything after = is treated as code if (!ids.contains(QLatin1String("PageTotal()"))) { QVariant v = script->evaluate(ids.mid(1)); str = v.toString(); } else { str = ids.mid(1); tb->setRequiresPostProcessing(true); } } else #else Q_UNUSED(script); #endif if (ids.left(1) == QLatin1String("$")) { //Everything past $ is treated as a string str = ids.mid(1); } else { str = data.toString(); } } else { str = m_itemValue->value().toString(); } tb->setText(str); //Work out the size of the text if (tb->canGrow()) { QRect r; if (tb->wordWrap()) { //Grow vertically QFontMetrics metrics(font()); QRect temp(tb->position().x(), tb->position().y(), tb->size().width(), 5000); // a large vertical height r = metrics.boundingRect(temp, tb->flags(), str); } else { //Grow Horizontally QFontMetrics metrics(font()); QRect temp(tb->position().x(), tb->position().y(), 5000, tb->size().height()); // a large vertical height r = metrics.boundingRect(temp, tb->flags(), str); } tb->setSize(r.size() + QSize(4,4)); } if (page) { page->insertPrimitive(tb); } if (section) { OROPrimitive *clone = tb->clone(); clone->setPosition(scenePosition(position())); section->addPrimitive(clone); } int height = scenePosition(position()).y() + tb->size().height(); //If there is no page to add the item to, delete it now because it wont be deleted later if (!page) { delete tb; } return height; }