From cf000a5d5ceabb7d5ccfdeaf6e1f168779e58412 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sat, 29 Apr 2017 19:12:20 -0400 Subject: [PATCH] Initial implementation of barcode object. --- glabels/BarcodeBackends.cpp | 20 +- glabels/BarcodeBackends.h | 6 +- glabels/BarcodeMenu.cpp | 6 +- glabels/BarcodeMenu.h | 6 +- glabels/BarcodeMenuButton.cpp | 6 +- glabels/BarcodeMenuButton.h | 6 +- glabels/BarcodeMenuItem.cpp | 6 +- glabels/BarcodeMenuItem.h | 8 +- glabels/BarcodeStyle.cpp | 9 + glabels/BarcodeStyle.h | 9 +- glabels/CMakeLists.txt | 7 + glabels/LabelEditor.cpp | 16 +- glabels/LabelModelBarcodeObject.cpp | 395 ++++++++++++++++++++++++++++ glabels/LabelModelBarcodeObject.h | 149 +++++++++++ glabels/MainWindow.cpp | 3 +- glbarcode/QtRenderer.cpp | 4 +- translations/glabels_C.ts | 47 ++-- 17 files changed, 647 insertions(+), 56 deletions(-) create mode 100644 glabels/LabelModelBarcodeObject.cpp create mode 100644 glabels/LabelModelBarcodeObject.h diff --git a/glabels/BarcodeBackends.cpp b/glabels/BarcodeBackends.cpp index 6a26a7e..5ce2093 100644 --- a/glabels/BarcodeBackends.cpp +++ b/glabels/BarcodeBackends.cpp @@ -124,7 +124,7 @@ namespace glabels } - const BarcodeStyle* BarcodeBackends::lookupStyleFromId( const QString& id ) + BarcodeStyle BarcodeBackends::lookupStyleFromId( const QString& id ) { StyleMap::iterator i = mStyleIdMap.find( id ); if ( i != mStyleIdMap.end() ) @@ -132,11 +132,12 @@ namespace glabels return i.value(); } - return nullptr; + return BarcodeStyle( QString("code39"), QString(""), tr("Code 39"), + true, true, true, true, QString("1234567890"), true, 10 ); } - const BarcodeStyle* BarcodeBackends::lookupStyleFromName( const QString& name ) + BarcodeStyle BarcodeBackends::lookupStyleFromName( const QString& name ) { StyleMap::iterator i = mStyleNameMap.find( name ); if ( i != mStyleNameMap.end() ) @@ -144,7 +145,8 @@ namespace glabels return i.value(); } - return nullptr; + return BarcodeStyle( QString("code39"), QString(""), tr("Code 39"), + true, true, true, true, QString("1234567890"), true, 10 ); } @@ -167,11 +169,11 @@ namespace glabels bool canFreeForm, int preferedN ) { - BarcodeStyle* style = new BarcodeStyle( QString(id), QString(backendId), name, - canText, textOptional, - canChecksum, checksumOptional, - QString(defaultDigits), - canFreeForm, preferedN ); + BarcodeStyle style( QString(id), QString(backendId), name, + canText, textOptional, + canChecksum, checksumOptional, + QString(defaultDigits), + canFreeForm, preferedN ); QString fqName = QString(backendId) + QString(".") + name; // Name may not be unique diff --git a/glabels/BarcodeBackends.h b/glabels/BarcodeBackends.h index 7a028d4..cbbf887 100644 --- a/glabels/BarcodeBackends.h +++ b/glabels/BarcodeBackends.h @@ -60,8 +60,8 @@ namespace glabels static const QList& getBackendNameList(); static const QList& getNameList(); - static const BarcodeStyle* lookupStyleFromId( const QString& id ); - static const BarcodeStyle* lookupStyleFromName( const QString& name ); + static BarcodeStyle lookupStyleFromId( const QString& id ); + static BarcodeStyle lookupStyleFromName( const QString& name ); ///////////////////////////////// @@ -89,7 +89,7 @@ namespace glabels static BackendMap mBackendIdMap; static BackendMap mBackendNameMap; - typedef QMap StyleMap; + typedef QMap StyleMap; static StyleMap mStyleIdMap; static StyleMap mStyleNameMap; diff --git a/glabels/BarcodeMenu.cpp b/glabels/BarcodeMenu.cpp index e8cd1dd..cdd9d5b 100644 --- a/glabels/BarcodeMenu.cpp +++ b/glabels/BarcodeMenu.cpp @@ -34,7 +34,7 @@ namespace glabels { foreach ( QString name, BarcodeBackends::getNameList() ) { - const BarcodeStyle* bcStyle = BarcodeBackends::lookupStyleFromName( name ); + BarcodeStyle bcStyle = BarcodeBackends::lookupStyleFromName( name ); BarcodeMenuItem* bcMenuItem = new BarcodeMenuItem( bcStyle ); connect( bcMenuItem, SIGNAL(activated()), this, SLOT(onMenuItemActivated) ); @@ -47,7 +47,7 @@ namespace glabels /// /// bcStyle getter /// - const BarcodeStyle* BarcodeMenu::bcStyle() const + BarcodeStyle BarcodeMenu::bcStyle() const { return mBcStyle; } @@ -56,7 +56,7 @@ namespace glabels /// /// onMenuItemActivated slot /// - void BarcodeMenu::onMenuItemActivated( BarcodeStyle *bcStyle ) + void BarcodeMenu::onMenuItemActivated( BarcodeStyle bcStyle ) { mBcStyle = bcStyle; diff --git a/glabels/BarcodeMenu.h b/glabels/BarcodeMenu.h index 82a1fc4..41262d5 100644 --- a/glabels/BarcodeMenu.h +++ b/glabels/BarcodeMenu.h @@ -55,21 +55,21 @@ namespace glabels // Properties ///////////////////////////////// public: - const BarcodeStyle* bcStyle() const; + BarcodeStyle bcStyle() const; ///////////////////////////////// // Slots ///////////////////////////////// private slots: - void onMenuItemActivated( BarcodeStyle *bcStyle ); + void onMenuItemActivated( BarcodeStyle bcStyle ); ///////////////////////////////// // Private Data ///////////////////////////////// private: - BarcodeStyle* mBcStyle; + BarcodeStyle mBcStyle; }; diff --git a/glabels/BarcodeMenuButton.cpp b/glabels/BarcodeMenuButton.cpp index b25582e..b7243ca 100644 --- a/glabels/BarcodeMenuButton.cpp +++ b/glabels/BarcodeMenuButton.cpp @@ -37,7 +37,7 @@ namespace glabels setMenu( mMenu ); mBcStyle = BarcodeBackends::lookupStyleFromId( "" ); // Default style - setText( mBcStyle->name() ); + setText( mBcStyle.name() ); connect( mMenu, SIGNAL(styleChanged()), this, SLOT(onMenuStyleChanged()) ); } @@ -46,7 +46,7 @@ namespace glabels /// /// bcStyle getter /// - const BarcodeStyle* BarcodeMenuButton::bcStyle() const + BarcodeStyle BarcodeMenuButton::bcStyle() const { return mBcStyle; } @@ -58,7 +58,7 @@ namespace glabels void BarcodeMenuButton::onMenuStyleChanged() { mBcStyle = mMenu->bcStyle(); - setText( mBcStyle->name() ); + setText( mBcStyle.name() ); emit styleChanged(); } diff --git a/glabels/BarcodeMenuButton.h b/glabels/BarcodeMenuButton.h index 7769af0..d0b90ed 100644 --- a/glabels/BarcodeMenuButton.h +++ b/glabels/BarcodeMenuButton.h @@ -56,7 +56,7 @@ namespace glabels // Properties ///////////////////////////////// public: - const BarcodeStyle* bcStyle() const; + BarcodeStyle bcStyle() const; ///////////////////////////////// @@ -70,8 +70,8 @@ namespace glabels // Private Data ///////////////////////////////// private: - BarcodeMenu* mMenu; - const BarcodeStyle* mBcStyle; + BarcodeMenu* mMenu; + BarcodeStyle mBcStyle; }; diff --git a/glabels/BarcodeMenuItem.cpp b/glabels/BarcodeMenuItem.cpp index f021b56..8d44d71 100644 --- a/glabels/BarcodeMenuItem.cpp +++ b/glabels/BarcodeMenuItem.cpp @@ -27,10 +27,10 @@ namespace glabels /// /// Constructor From Data /// - BarcodeMenuItem::BarcodeMenuItem( const BarcodeStyle* bcStyle, QObject* parent ) + BarcodeMenuItem::BarcodeMenuItem( const BarcodeStyle& bcStyle, QObject* parent ) : QAction(parent), mBcStyle(bcStyle) { - setText( bcStyle->name() ); + setText( bcStyle.name() ); connect( this, SIGNAL(triggered()), this, SLOT(onTriggered()) ); } @@ -39,7 +39,7 @@ namespace glabels /// /// bcStyle Property Getter /// - const BarcodeStyle* BarcodeMenuItem::bcStyle() const + BarcodeStyle BarcodeMenuItem::bcStyle() const { return mBcStyle; } diff --git a/glabels/BarcodeMenuItem.h b/glabels/BarcodeMenuItem.h index 72b0376..76b0e90 100644 --- a/glabels/BarcodeMenuItem.h +++ b/glabels/BarcodeMenuItem.h @@ -41,21 +41,21 @@ namespace glabels // Life Cycle ///////////////////////////////// public: - BarcodeMenuItem( const BarcodeStyle* bcStyle, QObject* parent = nullptr ); + BarcodeMenuItem( const BarcodeStyle& bcStyle, QObject* parent = nullptr ); ///////////////////////////////// // Signals ///////////////////////////////// signals: - void activated( const BarcodeStyle* bcStyle ); + void activated( const BarcodeStyle& bcStyle ); ///////////////////////////////// // Properties ///////////////////////////////// public: - const BarcodeStyle* bcStyle() const; + BarcodeStyle bcStyle() const; ///////////////////////////////// @@ -69,7 +69,7 @@ namespace glabels // Private Data ///////////////////////////////// private: - const BarcodeStyle* mBcStyle; + BarcodeStyle mBcStyle; }; diff --git a/glabels/BarcodeStyle.cpp b/glabels/BarcodeStyle.cpp index 16b56b6..f41f4ea 100644 --- a/glabels/BarcodeStyle.cpp +++ b/glabels/BarcodeStyle.cpp @@ -176,4 +176,13 @@ namespace glabels } } + + /// + /// "Not equals" operator + /// + bool BarcodeStyle::operator!=( const BarcodeStyle& other ) const + { + return mId != other.mId; + } + } // namespace glabels diff --git a/glabels/BarcodeStyle.h b/glabels/BarcodeStyle.h index c91d20e..d09819a 100644 --- a/glabels/BarcodeStyle.h +++ b/glabels/BarcodeStyle.h @@ -31,7 +31,7 @@ namespace glabels /// /// Barcode Style Type /// - struct BarcodeStyle + class BarcodeStyle { ///////////////////////////////// @@ -83,6 +83,13 @@ namespace glabels QString exampleDigits( int n ) const; + ///////////////////////////////// + // Operators + ///////////////////////////////// + public: + bool operator!=( const BarcodeStyle& other ) const; + + ///////////////////////////////// // Private Data ///////////////////////////////// diff --git a/glabels/CMakeLists.txt b/glabels/CMakeLists.txt index 0ab387f..3788c6b 100644 --- a/glabels/CMakeLists.txt +++ b/glabels/CMakeLists.txt @@ -57,6 +57,7 @@ set (glabels_sources LabelEditor.cpp LabelModel.cpp LabelModelObject.cpp + LabelModelBarcodeObject.cpp LabelModelBoxObject.cpp LabelModelEllipseObject.cpp LabelModelImageObject.cpp @@ -118,6 +119,7 @@ set (glabels_qobject_headers LabelEditor.h LabelModel.h LabelModelObject.h + LabelModelBarcodeObject.h LabelModelBoxObject.h LabelModelEllipseObject.h LabelModelImageObject.h @@ -176,6 +178,7 @@ add_executable (glabels-qt WIN32 target_link_libraries (glabels-qt Merge + glbarcode ${Qt5Widgets_LIBRARIES} ${Qt5PrintSupport_LIBRARIES} ${Qt5Xml_LIBRARIES} @@ -196,6 +199,10 @@ include_directories ( ${Qt5Svg_INCLUDE_DIRS} ) +link_directories ( + ${glabels_qt_SOURCE_DIR}/glbarcode +) + #======================================= # Subdirectories diff --git a/glabels/LabelEditor.cpp b/glabels/LabelEditor.cpp index d1e39f3..999a1fc 100644 --- a/glabels/LabelEditor.cpp +++ b/glabels/LabelEditor.cpp @@ -27,6 +27,7 @@ #include "FrameRound.h" #include "LabelModel.h" #include "LabelModelObject.h" +#include "LabelModelBarcodeObject.h" #include "LabelModelBoxObject.h" #include "LabelModelEllipseObject.h" #include "LabelModelImageObject.h" @@ -377,6 +378,19 @@ namespace glabels } + /// + /// Create barcode mode + /// + void + LabelEditor::createBarcodeMode() + { + setCursor( Cursors::Barcode() ); + + mCreateObjectType = Barcode; + mState = CreateIdle; + } + + /// /// Resize Event Handler /// @@ -522,7 +536,7 @@ namespace glabels mCreateObject = new LabelModelTextObject(); break; case Barcode: - // mCreateObject = new LabelModelBarcodeObject(); + mCreateObject = new LabelModelBarcodeObject(); break; default: qDebug() << "LabelEditor::mousePressEvent: Invalid creation type. Should not happen!"; diff --git a/glabels/LabelModelBarcodeObject.cpp b/glabels/LabelModelBarcodeObject.cpp new file mode 100644 index 0000000..44e8e3a --- /dev/null +++ b/glabels/LabelModelBarcodeObject.cpp @@ -0,0 +1,395 @@ +/* LabelModelBarcodeObject.cpp + * + * Copyright (C) 2017 Jim Evins + * + * This file is part of gLabels-qt. + * + * gLabels-qt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels-qt 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels-qt. If not, see . + */ + +#include "LabelModelBarcodeObject.h" + +#include "BarcodeBackends.h" +#include "Size.h" + +#include "glbarcode/Factory.h" +#include "glbarcode/QtRenderer.h" + +#include +#include +#include +#include +#include +#include + + +namespace glabels +{ + + // + // Private + // + namespace + { + } + + + /// + /// Constructor + /// + LabelModelBarcodeObject::LabelModelBarcodeObject() + { + mOutline = new Outline( this ); + + mHandles << new HandleNorthWest( this ); + mHandles << new HandleNorth( this ); + mHandles << new HandleNorthEast( this ); + mHandles << new HandleEast( this ); + mHandles << new HandleSouthEast( this ); + mHandles << new HandleSouth( this ); + mHandles << new HandleSouthWest( this ); + mHandles << new HandleWest( this ); + + mBcStyle = BarcodeBackends::lookupStyleFromId( "code39" ); + mBcTextFlag = mBcStyle.canText(); + mBcChecksumFlag = mBcStyle.canChecksum(); + mBcFormatDigits = mBcStyle.preferedN(); + mBcDataNode = TextNode( false, mBcStyle.defaultDigits() ); + mBcColorNode = ColorNode( Qt::black ); + + update(); // Initialize cached editor layouts + } + + + /// + /// Copy constructor + /// + LabelModelBarcodeObject::LabelModelBarcodeObject( const LabelModelBarcodeObject* object ) + : LabelModelObject(object) + { + mBcStyle = object->mBcStyle; + mBcTextFlag = object->mBcTextFlag; + mBcChecksumFlag = object->mBcChecksumFlag; + mBcFormatDigits = object->mBcFormatDigits; + mBcDataNode = object->mBcDataNode; + mBcColorNode = object->mBcColorNode; + + mEditorBarcode = nullptr; + update(); // Initialize cached editor layouts + } + + + /// + /// Destructor + /// + LabelModelBarcodeObject::~LabelModelBarcodeObject() + { + delete mOutline; + + foreach( Handle* handle, mHandles ) + { + delete handle; + } + mHandles.clear(); + + delete mEditorBarcode; + } + + + /// + /// Clone + /// + LabelModelBarcodeObject* LabelModelBarcodeObject::clone() const + { + return new LabelModelBarcodeObject( this ); + } + + + /// + /// bcDataNode Property Getter + /// + TextNode LabelModelBarcodeObject::bcDataNode() const + { + return mBcDataNode; + } + + + /// + /// bcDataNode Property Setter + /// + void LabelModelBarcodeObject::setBcDataNode( const TextNode& value ) + { + if ( mBcDataNode != value ) + { + mBcDataNode = value; + update(); + emit changed(); + } + } + + + /// + /// bcTextFlag Property Getter + /// + bool LabelModelBarcodeObject::bcTextFlag() const + { + return mBcTextFlag; + } + + + /// + /// bcTextFlag Property Setter + /// + void LabelModelBarcodeObject::setBcTextFlag( bool value ) + { + if ( mBcTextFlag != value ) + { + mBcTextFlag = value; + update(); + emit changed(); + } + } + + + /// + /// bcChecksumFlag Property Getter + /// + bool LabelModelBarcodeObject::bcChecksumFlag() const + { + return mBcChecksumFlag; + } + + + /// + /// bcChecksumFlag Property Setter + /// + void LabelModelBarcodeObject::setBcChecksumFlag( bool value ) + { + if ( mBcChecksumFlag != value ) + { + mBcChecksumFlag = value; + update(); + emit changed(); + } + } + + + /// + /// Barcode Color Node Property Getter + /// + ColorNode LabelModelBarcodeObject::bcColorNode() const + { + return mBcColorNode; + } + + + /// + /// Barcode Color Node Property Setter + /// + void LabelModelBarcodeObject::setBcColorNode( const ColorNode& value ) + { + if ( mBcColorNode != value ) + { + mBcColorNode = value; + update(); + emit changed(); + } + } + + + /// + /// Barcode Style Property Getter + /// + BarcodeStyle LabelModelBarcodeObject::bcStyle() const + { + return mBcStyle; + } + + + /// + /// Barcode Style Property Setter + /// + void LabelModelBarcodeObject::setBcStyle( const BarcodeStyle& value ) + { + if ( mBcStyle != value ) + { + mBcStyle = value; + update(); + emit changed(); + } + } + + + /// + /// Barcode Format Digits Property Getter + /// + int LabelModelBarcodeObject::bcFormatDigits() const + { + return mBcFormatDigits; + } + + + /// + /// Barcode Format Digits Property Setter + /// + void LabelModelBarcodeObject::setBcFormatDigits( int value ) + { + if ( mBcFormatDigits != value ) + { + mBcFormatDigits = value; + update(); + emit changed(); + } + } + + + /// + /// Draw shadow of object + /// + void LabelModelBarcodeObject::drawShadow( QPainter* painter, + bool inEditor, + merge::Record* record ) const + { + QColor bcColor = mBcColorNode.color( record ); + + if ( bcColor.alpha() ) + { + QColor shadowColor = mShadowColorNode.color( record ); + shadowColor.setAlphaF( mShadowOpacity ); + + if ( inEditor ) + { + drawBcInEditor( painter, shadowColor ); + } + else + { + drawBc( painter, shadowColor, record ); + } + } + } + + + /// + /// Draw object itself + /// + void LabelModelBarcodeObject::drawObject( QPainter* painter, + bool inEditor, + merge::Record* record ) const + { + QColor bcColor = mBcColorNode.color( record ); + + if ( inEditor ) + { + drawBcInEditor( painter, bcColor ); + } + else + { + drawBc( painter, bcColor, record ); + } + } + + + /// + /// Path to test for hover condition + /// + QPainterPath LabelModelBarcodeObject::hoverPath( double scale ) const + { + return mHoverPath; + } + + + /// + /// Size updated + /// + void LabelModelBarcodeObject::sizeUpdated() + { + update(); + } + + + /// + /// Update cached information for editor view + /// + void LabelModelBarcodeObject::update() + { + if ( mEditorBarcode ) + { + delete mEditorBarcode; + } + mEditorBarcode = glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() ); + mEditorBarcode->setChecksum(mBcChecksumFlag); + mEditorBarcode->setShowText(mBcTextFlag); + + if ( mBcDataNode.isField() ) + { + mEditorBarcode->build( mBcStyle.defaultDigits().toStdString(), mW.pt(), mH.pt() ); + } + else + { + mEditorBarcode->build( mBcDataNode.data().toStdString(), mW.pt(), mH.pt() ); + } + + mW = Distance::pt( mEditorBarcode->width() ); + mH = Distance::pt( mEditorBarcode->height() ); + + QPainterPath path; + path.addRect( 0, 0, mEditorBarcode->width(), mEditorBarcode->height() ); + mHoverPath = path; + } + + + /// + /// Draw text in editor from cached information + /// + void LabelModelBarcodeObject::drawBcInEditor( QPainter* painter, const QColor& color ) const + { + painter->setPen( QPen( color ) ); + + if ( mEditorBarcode->isDataValid() ) + { + glbarcode::QtRenderer renderer(painter); + mEditorBarcode->render( renderer ); + } + else if ( mEditorBarcode->isEmpty() ) + { + // FIXME: display "Empty" + } + else + { + // FIXME: display "Invalid data" + } + } + + + /// + /// Draw text in final printout or preview + /// + void + LabelModelBarcodeObject::drawBc( QPainter* painter, + const QColor& color, + merge::Record* record ) const + { + painter->setPen( QPen( color ) ); + + glbarcode::Barcode* bc = glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() ); + bc->setChecksum(mBcChecksumFlag); + bc->setShowText(mBcTextFlag); + + bc->build( mBcDataNode.text(record).toStdString(), mW.pt(), mH.pt() ); + + glbarcode::QtRenderer renderer(painter); + bc->render( renderer ); + } + +} // namespace glabels diff --git a/glabels/LabelModelBarcodeObject.h b/glabels/LabelModelBarcodeObject.h new file mode 100644 index 0000000..05359d1 --- /dev/null +++ b/glabels/LabelModelBarcodeObject.h @@ -0,0 +1,149 @@ +/* LabelModelBarcodeObject.h + * + * Copyright (C) 2017 Jim Evins + * + * This file is part of gLabels-qt. + * + * gLabels-qt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels-qt 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels-qt. If not, see . + */ + +#ifndef LabelModelBarcodeObject_h +#define LabelModelBarcodeObject_h + + +#include "LabelModelObject.h" + +#include "glbarcode/Barcode.h" + + +namespace glabels +{ + + /// + /// Label Model Line Object + /// + class LabelModelBarcodeObject : public LabelModelObject + { + Q_OBJECT + + /////////////////////////////////////////////////////////////// + // Lifecycle Methods + /////////////////////////////////////////////////////////////// + public: + LabelModelBarcodeObject(); + LabelModelBarcodeObject( const LabelModelBarcodeObject* object ); + ~LabelModelBarcodeObject() override; + + + /////////////////////////////////////////////////////////////// + // Object duplication + /////////////////////////////////////////////////////////////// + LabelModelBarcodeObject* clone() const override; + + + /////////////////////////////////////////////////////////////// + // Property Implementations + /////////////////////////////////////////////////////////////// + public: + // + // Barcode Property: bcDataNode + // + TextNode bcDataNode() const override; + void setBcDataNode( const TextNode &value ) override; + + + // + // Barcode Property: bcTextFlag + // + bool bcTextFlag() const override; + void setBcTextFlag( bool value ) override; + + + // + // Barcode Property: bcChecksumFlag + // + bool bcChecksumFlag() const override; + void setBcChecksumFlag( bool value ) override; + + + // + // Barcode Property: bcColorNode + // + ColorNode bcColorNode() const override; + void setBcColorNode( const ColorNode &value ) override; + + + // + // Barcode Property: bcStyle + // + BarcodeStyle bcStyle() const override; + void setBcStyle( const BarcodeStyle &value ) override; + + + // + // Barcode Property: bcFormatDigits + // + int bcFormatDigits() const override; + void setBcFormatDigits( int value ) override; + + + + /////////////////////////////////////////////////////////////// + // Capability Implementations + /////////////////////////////////////////////////////////////// + public: + + + /////////////////////////////////////////////////////////////// + // Drawing operations + /////////////////////////////////////////////////////////////// + protected: + void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const override; + void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const override; + QPainterPath hoverPath( double scale ) const override; + + + /////////////////////////////////////////////////////////////// + // Private methods + /////////////////////////////////////////////////////////////// + private: + void sizeUpdated() override; + void update(); + + void drawBcInEditor( QPainter* painter, const QColor& color ) const; + void drawBc( QPainter* painter, const QColor& color, merge::Record* record ) const; + + + + /////////////////////////////////////////////////////////////// + // Private Members + /////////////////////////////////////////////////////////////// + private: + BarcodeStyle mBcStyle; + bool mBcTextFlag; + bool mBcChecksumFlag; + int mBcFormatDigits; + TextNode mBcDataNode; + ColorNode mBcColorNode; + + glbarcode::Barcode* mEditorBarcode; + + QPainterPath mHoverPath; + + }; + +} + + +#endif // LabelModelBarcodeObject_h diff --git a/glabels/MainWindow.cpp b/glabels/MainWindow.cpp index 1cd67c7..12f43cf 100644 --- a/glabels/MainWindow.cpp +++ b/glabels/MainWindow.cpp @@ -1278,7 +1278,8 @@ namespace glabels /// void MainWindow::objectsCreateBarcode() { - qDebug() << "ACTION: objects->Create->Barcode"; + mUndoRedoModel->checkpoint( tr("Create Barcode") ); + mLabelEditor->createBarcodeMode(); } diff --git a/glbarcode/QtRenderer.cpp b/glbarcode/QtRenderer.cpp index 051d8ad..04265a7 100644 --- a/glbarcode/QtRenderer.cpp +++ b/glbarcode/QtRenderer.cpp @@ -112,7 +112,7 @@ namespace glbarcode { double x1 = x + w/2; // Offset line origin by 1/2 line width. - d->painter->setPen( QPen( d->color, w ) ); + d->painter->setPen( QPen( d->color, w, Qt::SolidLine, Qt::FlatCap ) ); d->painter->drawLine( QPointF(x1, y), QPointF(x1, y+h) ); } } @@ -145,7 +145,7 @@ namespace glbarcode QRect rect = fm.boundingRect( QString::fromStdString(text) ); double xCorner = x - rect.width()/2.0; - double yCorner = y - rect.height() + fm.descent(); + double yCorner = y + fm.descent(); d->painter->drawText( QPointF(xCorner, yCorner), QString::fromStdString(text) ); } diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index 0da4b0e..78c204b 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -800,6 +800,8 @@ + + Code 39 @@ -1115,16 +1117,16 @@ glabels::LabelEditor - - - - - + + + + + Move - + Delete @@ -1486,7 +1488,7 @@ - + Bring To Front @@ -1497,7 +1499,7 @@ - + Send To Back @@ -1508,7 +1510,7 @@ - + Rotate Left @@ -1519,7 +1521,7 @@ - + Rotate Right @@ -1530,7 +1532,7 @@ - + Flip Horizontally @@ -1541,7 +1543,7 @@ - + Flip Vertically @@ -1552,7 +1554,7 @@ - + Align Left @@ -1563,7 +1565,7 @@ - + Align Center @@ -1574,7 +1576,7 @@ - + Align Right @@ -1585,7 +1587,7 @@ - + Align Top @@ -1596,7 +1598,7 @@ - + Align Middle @@ -1607,7 +1609,7 @@ - + Align Bottom @@ -1618,7 +1620,7 @@ - + Center Horizontally @@ -1629,7 +1631,7 @@ - + Center Vertically @@ -1778,6 +1780,11 @@ Create Image + + + Create Barcode + + glabels::MergeView