diff --git a/src/items/label/KReportBoundedTextItem.cpp b/src/items/label/KReportBoundedTextItem.cpp index f284eef3..39b1ac59 100644 --- a/src/items/label/KReportBoundedTextItem.cpp +++ b/src/items/label/KReportBoundedTextItem.cpp @@ -1,84 +1,91 @@ /* This file is part of the KDE project Copyright (C) 2014 Adam Pigg + Copyright (C) 2016 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "KReportBoundedTextItem.h" #include #include #include BoundedTextItem::BoundedTextItem(QGraphicsItem* parent): QGraphicsTextItem(parent) + , m_backgroundOpacity(1.0) { setTextInteractionFlags(Qt::TextEditorInteraction); setCursor(QCursor(Qt::IBeamCursor)); } QRectF BoundedTextItem::boundingRect() const { if (parentItem()) { return parentItem()->boundingRect(); } return QGraphicsTextItem::boundingRect(); } void BoundedTextItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *o, QWidget *w) { QColor bg = m_backgroundColor.isValid() ? m_backgroundColor : o->palette.base().color(); bg.setAlphaF(m_backgroundOpacity * 0.01); QColor fc = m_foregroundColor.isValid() ? m_foregroundColor : o->palette.text().color(); painter->setBrush(bg); painter->setPen(fc); painter->drawRect(boundingRect()); QStyleOptionGraphicsItem opt(*o); opt.state &= ~QStyle::State_HasFocus; QGraphicsTextItem::paint(painter, &opt, w); } void BoundedTextItem::setBackgroudColor(const QColor& bc) { m_backgroundColor = bc; } void BoundedTextItem::setForegroundColor(const QColor& fc) { m_foregroundColor = fc; } void BoundedTextItem::setDisplayFont(const QFont& f) { m_font = f; setFont(m_font); } -void BoundedTextItem::setBackgroudOpacity(int o) +qreal BoundedTextItem::backgroudOpacity() const { - m_backgroundOpacity = o; + return m_backgroundOpacity; +} + +void BoundedTextItem::setBackgroudOpacity(qreal opacity) +{ + m_backgroundOpacity = std::min(1.0, std::max(0.0, opacity)); } void BoundedTextItem::keyReleaseEvent(QKeyEvent* event) { if (event->key() == Qt::Key_Escape) { emit exitEditMode(); } else { QGraphicsTextItem::keyReleaseEvent(event); } } diff --git a/src/items/label/KReportBoundedTextItem.h b/src/items/label/KReportBoundedTextItem.h index 337dfca9..3bf1f500 100644 --- a/src/items/label/KReportBoundedTextItem.h +++ b/src/items/label/KReportBoundedTextItem.h @@ -1,62 +1,69 @@ /* This file is part of the KDE project Copyright (C) 2014 Adam Pigg + Copyright (C) 2016 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KREPORT_BOUNDEDTEXTITEM_H #define KREPORT_BOUNDEDTEXTITEM_H #include #include /** * @brief Subclass of QGraphicsTextItem which simply forces * its boundingRect to be the same as its parent. * By default a QGraphicsTextItem will size to its text and * we want it to size to the parent item. * */ class BoundedTextItem : public QGraphicsTextItem { Q_OBJECT public: explicit BoundedTextItem(QGraphicsItem *parent); virtual QRectF boundingRect() const; virtual void paint( QPainter *painter, const QStyleOptionGraphicsItem *o, QWidget *w); void setBackgroudColor(const QColor &bc); void setForegroundColor(const QColor &fc); - void setBackgroudOpacity(int o); + + //! @return background opacity, 0..1.0 + qreal backgroudOpacity() const; + + //! Sets background opacity, 0..1.0 + void setBackgroudOpacity(qreal opacity); + void setDisplayFont(const QFont &f); protected: virtual void keyReleaseEvent ( QKeyEvent * event ); private: QColor m_backgroundColor; QColor m_foregroundColor; QFont m_font; - int m_backgroundOpacity; + qreal m_backgroundOpacity; Q_SIGNALS: void exitEditMode(); }; #endif // KREPORT_BOUNDEDTEXTITEM_H diff --git a/src/items/label/KReportDesignerItemLabel.cpp b/src/items/label/KReportDesignerItemLabel.cpp index 9e6cf19c..8584dace 100644 --- a/src/items/label/KReportDesignerItemLabel.cpp +++ b/src/items/label/KReportDesignerItemLabel.cpp @@ -1,223 +1,223 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportDesignerItemLabel.h" #include "KReportDesignerItemBase.h" #include "KReportDesigner.h" #include "KReportDesignerSectionScene.h" #include "KReportLineStyle.h" #include #include #include #include #include #include #include void KReportDesignerItemLabel::init(QGraphicsScene *scene, KReportDesigner *d) { if (scene) scene->addItem(this); KReportDesignerItemRectBase::init(&m_pos, &m_size, m_set, d); connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); setZValue(Z); setFlag(ItemIsFocusable); m_inlineEdit = new BoundedTextItem(this); m_inlineEdit->setVisible(false); m_inlineEdit->setFlag(ItemIsFocusable); m_inlineEdit->setFlag(ItemIsSelectable, false); QTextDocument *doc = new QTextDocument; doc->setDocumentMargin(0); doc->setPlainText(text()); m_inlineEdit->setDocument(doc); connect(m_inlineEdit, SIGNAL(exitEditMode()), this, SLOT(exitInlineEditingMode())); } // methods (constructors) KReportDesignerItemLabel::KReportDesignerItemLabel(KReportDesigner* d, QGraphicsScene * scene, const QPointF &pos) : KReportDesignerItemRectBase(d) { Q_UNUSED(pos); init(scene, d); setSceneRect(properRect(*d, getTextRect().width(), getTextRect().height())); m_name->setValue(m_reportDesigner->suggestEntityName(typeName())); enterInlineEditingMode(); } KReportDesignerItemLabel::KReportDesignerItemLabel(const QDomNode & element, KReportDesigner * d, QGraphicsScene * s) : KReportItemLabel(element), KReportDesignerItemRectBase(d), m_inlineEdit(0) { init(s, d); setSceneRect(m_pos.toScene(), m_size.toScene()); } KReportDesignerItemLabel* KReportDesignerItemLabel::clone() { QDomDocument d; QDomElement e = d.createElement(QLatin1String("clone")); QDomNode n; buildXML(&d, &e); n = e.firstChild(); return new KReportDesignerItemLabel(n, designer(), 0); } // methods (deconstructor) KReportDesignerItemLabel::~KReportDesignerItemLabel() {} QRectF KReportDesignerItemLabel::getTextRect() const { return QFontMetrics(font()).boundingRect(x(), y(), 0, 0, textFlags(), m_text->value().toString()); } void KReportDesignerItemLabel::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(option); Q_UNUSED(widget); if (m_inlineEdit->isVisible()) { return; } // store any values we plan on changing so we can restore them QFont f = painter->font(); QPen p = painter->pen(); painter->setFont(font()); painter->setBackgroundMode(Qt::TransparentMode); QColor bg = m_backgroundColor->value().value(); bg.setAlphaF(m_backgroundOpacity->value().toReal() * 0.01); painter->setPen(m_foregroundColor->value().value()); painter->fillRect(QGraphicsRectItem::rect(), bg); painter->drawText(rect(), textFlags(), text()); if ((Qt::PenStyle)m_lineStyle->value().toInt() == Qt::NoPen || m_lineWeight->value().toInt() <= 0) { painter->setPen(QPen(QColor(224, 224, 224))); } else { painter->setPen(QPen(m_lineColor->value().value(), m_lineWeight->value().toInt(), (Qt::PenStyle)m_lineStyle->value().toInt())); } painter->drawRect(QGraphicsRectItem::rect()); painter->setPen(m_foregroundColor->value().value()); drawHandles(painter); // restore an values before we started just in case painter->setFont(f); painter->setPen(p); } void KReportDesignerItemLabel::buildXML(QDomDocument *doc, QDomElement *parent) { //kreportpluginDebug(); QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); // properties addPropertyAsAttribute(&entity, m_name); addPropertyAsAttribute(&entity, m_text); addPropertyAsAttribute(&entity, m_verticalAlignment); addPropertyAsAttribute(&entity, m_horizontalAlignment); entity.setAttribute(QLatin1String("report:z-index"), zValue()); // bounding rect buildXMLRect(doc, &entity, &m_pos, &m_size); //text style info buildXMLTextStyle(doc, &entity, textStyle()); //Line Style buildXMLLineStyle(doc, &entity, lineStyle()); parent->appendChild(entity); } void KReportDesignerItemLabel::slotPropertyChanged(KPropertySet &s, KProperty &p) { Q_UNUSED(s); if (p.name() == "name") { //For some reason p.oldValue returns an empty string if (!m_reportDesigner->isEntityNameUnique(p.value().toString(), this)) { p.setValue(m_oldName); } else { m_oldName = p.value().toString(); } } else if (p.name() == "caption") { m_inlineEdit->setPlainText(p.value().toString()); } KReportDesignerItemRectBase::propertyChanged(s, p); if (m_reportDesigner) m_reportDesigner->setModified(true); } void KReportDesignerItemLabel::enterInlineEditingMode() { if (!m_inlineEdit->isVisible()) { m_inlineEdit->setVisible(true); m_inlineEdit->setPlainText(text()); m_inlineEdit->setFocus(); QTextCursor c = m_inlineEdit->textCursor(); c.select(QTextCursor::Document); m_inlineEdit->setTextCursor(c); m_inlineEdit->setFont(m_font->value().value()); m_inlineEdit->setDefaultTextColor(m_foregroundColor->value().value()); m_inlineEdit->setBackgroudColor(m_backgroundColor->value().value()); - m_inlineEdit->setBackgroudOpacity(m_backgroundOpacity->value().toInt()); + m_inlineEdit->setBackgroudOpacity(m_backgroundOpacity->value().toDouble() / 100.0); m_inlineEdit->setForegroundColor(m_foregroundColor->value().value()); m_inlineEdit->setFont(m_font->value().value()); update(); } } void KReportDesignerItemLabel::exitInlineEditingMode() { if (m_inlineEdit->isVisible()) { m_inlineEdit->setVisible(false); setText(m_inlineEdit->toPlainText()); } } void KReportDesignerItemLabel::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) { Q_UNUSED(event); enterInlineEditingMode(); } void KReportDesignerItemLabel::keyReleaseEvent(QKeyEvent* event) { if (event->key() == Qt::Key_F2) { enterInlineEditingMode(); } else { QGraphicsRectItem::keyReleaseEvent(event); } } diff --git a/src/plugins/barcode/KReportItemBarcode.cpp b/src/plugins/barcode/KReportItemBarcode.cpp index 43fc4ceb..b78390c5 100644 --- a/src/plugins/barcode/KReportItemBarcode.cpp +++ b/src/plugins/barcode/KReportItemBarcode.cpp @@ -1,254 +1,257 @@ /* This file is part of the KDE project * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportItemBarcode.h" #include #include #include #include "kreportplugin_debug.h" #include "barcodes.h" KReportItemBarcode::KReportItemBarcode() + : KReportItemBarcode(QDomNode()) { - createProperties(); } KReportItemBarcode::KReportItemBarcode(const QDomNode & element) + : m_minWidthData(0), m_minWidthTotal(0), m_minHeight(0) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; m_name->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); m_itemValue->setValue(element.toElement().attribute(QLatin1String("report:value"))); Z = element.toElement().attribute(QLatin1String("report:z-index")).toDouble(); m_horizontalAlignment->setValue(element.toElement().attribute(QLatin1String("report:horizontal-align"))); m_maxLength->setValue(element.toElement().attribute(QLatin1String("report:barcode-max-length"))); m_format->setValue(element.toElement().attribute(QLatin1String("report:barcode-format"))); parseReportRect(element.toElement(), &m_pos, &m_size); } void KReportItemBarcode::setMaxLength(int i) { if (i > 0) { if (m_maxLength->value().toInt() != i) { m_maxLength->setValue(i); } if (m_format->value().toString() == QLatin1String("3of9")) { int C = i; // number of characters int N = 2; // narrow mult for wide line int X = 1; // narrow line width int I = 1; // interchange line width m_minWidthData = (((C + 2) * ((3 * N) + 6) * X) + ((C + 1) * I)) / 100.0; - m_minHeight = m_minWidthData * 0.15; - /*if(min_height < 0.25)*/ m_minHeight = 0.25; + //m_minHeight = m_minWidthData * 0.15; + /*if(min_height < 0.25)*/ + m_minHeight = 0.25; m_minWidthTotal = m_minWidthData + 0.22; // added a little buffer to make sure we don't loose any // of our required quiet zone in conversions } else if (m_format->value().toString() == QLatin1String("3of9+")) { int C = i * 2; // number of characters int N = 2; // narrow mult for wide line int X = 1; // 1px narrow line int I = 1; // 1px narrow line interchange m_minWidthData = (((C + 2) * ((3 * N) + 6) * X) + ((C + 1) * I)) / 100.0; - m_minHeight = m_minWidthData * 0.15; - /*if(min_height < 0.25)*/ m_minHeight = 0.25; + //m_minHeight = m_minWidthData * 0.15; + /*if(min_height < 0.25)*/ + m_minHeight = 0.25; m_minWidthTotal = m_minWidthData + 0.22; // added a little buffer to make sure we don't loose any // of our required quiet zone in conversions } else if (m_format->value().toString() == QLatin1String("i2of5")) { int C = i * 2; // number of characters int N = 2; // narrow mult for wide line int X = 1; // 1px narrow line m_minWidthTotal = ((C * (2.0*N + 3.0) + 6.0 + N) * X); m_minHeight = 0.25; m_minWidthTotal = m_minWidthData + 0.22; } else if (m_format->value().toString() == QLatin1String("128")) { int C = i; // assuming 1:1 ratio of data passed in to data actually used in encoding int X = 1; // 1px wide m_minWidthData = (((11 * C) + 35) * X) / 100.0; // assuming CODE A or CODE B //m_minHeight = m_minWidthData * 0.15; /*if(min_height < 0.25)*/ m_minHeight = 0.25; m_minWidthTotal = m_minWidthData + 0.22; // added a little bugger to make sure we don't loose any // of our required quiet zone in conversions } else if (m_format->value().toString() == QLatin1String("upc-a")) { m_minWidthData = 0.95; m_minWidthTotal = 1.15; m_minHeight = 0.25; } else if (m_format->value().toString() == QLatin1String("upc-e")) { m_minWidthData = 0.52; m_minWidthTotal = 0.70; m_minHeight = 0.25; } else if (m_format->value().toString() == QLatin1String("ean13")) { m_minWidthData = 0.95; m_minWidthTotal = 1.15; m_minHeight = 0.25; } else if (m_format->value().toString() == QLatin1String("ean8")) { m_minWidthData = 0.67; m_minWidthTotal = 0.90; m_minHeight = 0.25; } else { kreportpluginWarning() << "Unknown format encountered: " << m_format->value().toString(); } } } void KReportItemBarcode::createProperties() { m_set = new KPropertySet; QStringList keys, strings; m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); m_itemValue = new KProperty("value", QString(), tr("Value"), tr("Value used if not bound to a field")); keys << QLatin1String("left") << QLatin1String("center") << QLatin1String("right"); strings << tr("Left") << tr("Center") << tr("Right"); m_horizontalAlignment = new KProperty("horizontal-align", keys, strings, QLatin1String("left"), tr("Horizontal Alignment")); keys.clear(); strings.clear(); keys << QLatin1String("3of9") << QLatin1String("3of9+") << QLatin1String("128") << QLatin1String("ean8") << QLatin1String("ean13") << QLatin1String("i2of5") << QLatin1String("upc-a") << QLatin1String("upc-e"); strings << tr("Code 3 of 9", "Barcode symbology, keep short") << tr("Code 3 of 9 Ext.", "3 of 3 Extended: Barcode symbology, keep short") << tr("Code 128", "Barcode symbology, keep short") << tr("EAN-8", "Barcode symbology, keep short") << tr("EAN-13", "Barcode symbology, keep short") << tr("Interleaved 2 of 5", "Interleaved barcode 2 of 5: barcode symbology, keep short") << tr("UPC-A", "Barcode symbology, keep short") << tr("UPC-E", "Barcode symbology, keep short"); m_format = new KProperty("barcode-format", keys, strings, QLatin1String("3of9"), tr("Barcode Format")); m_maxLength = new KProperty("barcode-max-length", 5, tr("Max Length"), tr("Maximum Barcode Length")); addDefaultProperties(); m_set->addProperty(m_controlSource); m_set->addProperty(m_itemValue); m_set->addProperty(m_format); m_set->addProperty(m_horizontalAlignment); m_set->addProperty(m_maxLength); } KReportItemBarcode::~KReportItemBarcode() { delete m_set; } int KReportItemBarcode::alignment() { QByteArray a = m_horizontalAlignment->value().toByteArray(); if (a == "left") return 0; else if (a == "center") return 1; else if (a == "right") return 2; else return 0; } QString KReportItemBarcode::itemDataSource() const { return m_controlSource->value().toString(); } QString KReportItemBarcode::format() { return m_format->value().toString(); } int KReportItemBarcode::maxLength() { return m_maxLength->value().toInt(); } void KReportItemBarcode::setFormat(const QString& f) { m_format->setValue(f); } void KReportItemBarcode::setAlignment(int) { //! @todo Barcode alignment } //RTTI QString KReportItemBarcode::typeName() const { return QLatin1String("barcode"); } int KReportItemBarcode::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { Q_UNUSED(section); Q_UNUSED(script); QPointF pos = m_pos.toScene(); QSizeF size = m_size.toScene(); pos += offset; QRectF rect = QRectF(pos, size); QString val; if (m_controlSource->value().toString().isEmpty()) { val = m_itemValue->value().toString(); } else { val = data.toString(); } if (page) { QByteArray fmt = m_format->value().toByteArray(); int align = alignment(); if (fmt == "3of9") render3of9(page, rect, val, align); else if (fmt == "3of9+") renderExtended3of9(page, rect, val, align); else if (fmt == "i2of5") renderI2of5(page, rect, val, align); else if (fmt == "128") renderCode128(page, rect, val, align); else if (fmt == "ean13") renderCodeEAN13(page, rect, val, align); else if (fmt == "ean8") renderCodeEAN8(page, rect, val, align); else if (fmt == "upc-a") renderCodeUPCA(page, rect, val, align); else if (fmt == "upc-e") renderCodeUPCE(page, rect, val, align); else { kreportpluginWarning() << "Unknown barcode format:" << fmt; } } return 0; }