Initial implementation of barcode object.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -60,8 +60,8 @@ namespace glabels
|
||||
static const QList<QString>& getBackendNameList();
|
||||
static const QList<QString>& 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<QString,BarcodeStyle*> StyleMap;
|
||||
typedef QMap<QString,BarcodeStyle> StyleMap;
|
||||
static StyleMap mStyleIdMap;
|
||||
static StyleMap mStyleNameMap;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -176,4 +176,13 @@ namespace glabels
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// "Not equals" operator
|
||||
///
|
||||
bool BarcodeStyle::operator!=( const BarcodeStyle& other ) const
|
||||
{
|
||||
return mId != other.mId;
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
|
||||
@@ -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
|
||||
/////////////////////////////////
|
||||
|
||||
@@ -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
|
||||
|
||||
+15
-1
@@ -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!";
|
||||
|
||||
@@ -0,0 +1,395 @@
|
||||
/* LabelModelBarcodeObject.cpp
|
||||
*
|
||||
* Copyright (C) 2017 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "LabelModelBarcodeObject.h"
|
||||
|
||||
#include "BarcodeBackends.h"
|
||||
#include "Size.h"
|
||||
|
||||
#include "glbarcode/Factory.h"
|
||||
#include "glbarcode/QtRenderer.h"
|
||||
|
||||
#include <QBrush>
|
||||
#include <QPen>
|
||||
#include <QTextDocument>
|
||||
#include <QTextBlock>
|
||||
#include <QRegularExpression>
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
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
|
||||
@@ -0,0 +1,149 @@
|
||||
/* LabelModelBarcodeObject.h
|
||||
*
|
||||
* Copyright (C) 2017 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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
|
||||
@@ -1278,7 +1278,8 @@ namespace glabels
|
||||
///
|
||||
void MainWindow::objectsCreateBarcode()
|
||||
{
|
||||
qDebug() << "ACTION: objects->Create->Barcode";
|
||||
mUndoRedoModel->checkpoint( tr("Create Barcode") );
|
||||
mLabelEditor->createBarcodeMode();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user