diff --git a/glabels/BarcodeBackends.cpp b/glabels/BarcodeBackends.cpp index 5ce2093..b148a57 100644 --- a/glabels/BarcodeBackends.cpp +++ b/glabels/BarcodeBackends.cpp @@ -29,16 +29,25 @@ namespace glabels // BarcodeBackends::BackendMap BarcodeBackends::mBackendIdMap; BarcodeBackends::BackendMap BarcodeBackends::mBackendNameMap; - - BarcodeBackends::StyleMap BarcodeBackends::mStyleIdMap; - BarcodeBackends::StyleMap BarcodeBackends::mStyleNameMap; - QList BarcodeBackends::mBackendNameList; - QList BarcodeBackends::mNameList; + QList BarcodeBackends::mStyleList; + BarcodeBackends::BarcodeBackends() { + registerStyle( "code39", "", tr("Code 39"), + true, true, true, true, "1234567890", true, 10 ); + + registerStyle( "code39ext", "", tr("Code 39 Extended"), + true, true, true, true, "1234567890", true, 10 ); + + registerStyle( "upc-a", "", tr("UPC-A"), + true, false, true, false, "12345678901", false, 11 ); + + registerStyle( "ean-13", "", tr("EAN-13"), + true, false, true, false, "123456789012", false, 12 ); + registerStyle( "postnet", "", tr("POSTNET (any)"), false, false, true, false, "12345-6789-12", false, 11 ); @@ -57,23 +66,12 @@ namespace glabels registerStyle( "onecode", "", tr("USPS Intelligent Mail"), false, false, true, false, "12345678901234567890", false, 20 ); - registerStyle( "code39", "", tr("Code 39"), - true, true, true, true, "1234567890", true, 10 ); - - registerStyle( "code39ext", "", tr("Code 39 Extended"), - true, true, true, true, "1234567890", true, 10 ); - - registerStyle( "upc-A", "", tr("UPC-A"), - true, false, true, false, "12345678901", false, 11 ); - - registerStyle( "ean-13", "", tr("EAN-13"), - true, false, true, false, "123456789012", false, 12 ); - registerStyle( "datamatrix", "", tr("DataMatrix"), false, false, true, false, "1234567890AB", false, 12 ); registerStyle( "qrcode", "", tr("QRCode"), false, false, true, false, "1234567890AB", false, 12 ); + } @@ -88,65 +86,15 @@ namespace glabels } - QString BarcodeBackends::BackendIdToName( const QString& backendId ) + const QList& BarcodeBackends::styleList() { - BackendMap::iterator i = mBackendIdMap.find( backendId ); - if ( i != mBackendIdMap.end() ) - { - return i.value(); - } - - return ""; + return mStyleList; } - QString BarcodeBackends::BackendNameToId( const QString& backendName ) + const BarcodeStyle& BarcodeBackends::defaultStyle() { - BackendMap::iterator i = mBackendNameMap.find( backendName ); - if ( i != mBackendNameMap.end() ) - { - return i.value(); - } - - return ""; - } - - - const QList& BarcodeBackends::getBackendNameList() - { - return mBackendNameList; - } - - - const QList& BarcodeBackends::getNameList() - { - return mNameList; - } - - - BarcodeStyle BarcodeBackends::lookupStyleFromId( const QString& id ) - { - StyleMap::iterator i = mStyleIdMap.find( id ); - if ( i != mStyleIdMap.end() ) - { - return i.value(); - } - - return BarcodeStyle( QString("code39"), QString(""), tr("Code 39"), - true, true, true, true, QString("1234567890"), true, 10 ); - } - - - BarcodeStyle BarcodeBackends::lookupStyleFromName( const QString& name ) - { - StyleMap::iterator i = mStyleNameMap.find( name ); - if ( i != mStyleNameMap.end() ) - { - return i.value(); - } - - return BarcodeStyle( QString("code39"), QString(""), tr("Code 39"), - true, true, true, true, QString("1234567890"), true, 10 ); + return mStyleList[0]; } @@ -175,11 +123,7 @@ namespace glabels QString(defaultDigits), canFreeForm, preferedN ); - QString fqName = QString(backendId) + QString(".") + name; // Name may not be unique - - mNameList.append( name ); - mStyleIdMap.insert( id, style ); - mStyleNameMap.insert( fqName, style ); + mStyleList.append( style ); } } // namespace glabels diff --git a/glabels/BarcodeBackends.h b/glabels/BarcodeBackends.h index cbbf887..e8c8220 100644 --- a/glabels/BarcodeBackends.h +++ b/glabels/BarcodeBackends.h @@ -54,14 +54,8 @@ namespace glabels // Public Methods ///////////////////////////////// public: - static QString BackendIdToName( const QString& backendId ); - static QString BackendNameToId( const QString& backendName ); - - static const QList& getBackendNameList(); - static const QList& getNameList(); - - static BarcodeStyle lookupStyleFromId( const QString& id ); - static BarcodeStyle lookupStyleFromName( const QString& name ); + static const QList& styleList(); + static const BarcodeStyle& defaultStyle(); ///////////////////////////////// @@ -88,13 +82,9 @@ namespace glabels typedef QMap BackendMap; static BackendMap mBackendIdMap; static BackendMap mBackendNameMap; - - typedef QMap StyleMap; - static StyleMap mStyleIdMap; - static StyleMap mStyleNameMap; - static QList mBackendNameList; - static QList mNameList; + + static QList mStyleList; }; diff --git a/glabels/BarcodeMenu.cpp b/glabels/BarcodeMenu.cpp index cdd9d5b..5a023d6 100644 --- a/glabels/BarcodeMenu.cpp +++ b/glabels/BarcodeMenu.cpp @@ -23,6 +23,8 @@ #include "BarcodeBackends.h" #include "BarcodeMenuItem.h" +#include + namespace glabels { @@ -32,12 +34,11 @@ namespace glabels /// BarcodeMenu::BarcodeMenu() { - foreach ( QString name, BarcodeBackends::getNameList() ) + foreach ( const BarcodeStyle& bcStyle, BarcodeBackends::styleList() ) { - BarcodeStyle bcStyle = BarcodeBackends::lookupStyleFromName( name ); - BarcodeMenuItem* bcMenuItem = new BarcodeMenuItem( bcStyle ); - connect( bcMenuItem, SIGNAL(activated()), this, SLOT(onMenuItemActivated) ); + connect( bcMenuItem, SIGNAL(activated(const BarcodeStyle&)), + this, SLOT(onMenuItemActivated(const BarcodeStyle&)) ); addAction( bcMenuItem ); } @@ -56,11 +57,11 @@ namespace glabels /// /// onMenuItemActivated slot /// - void BarcodeMenu::onMenuItemActivated( BarcodeStyle bcStyle ) + void BarcodeMenu::onMenuItemActivated( const BarcodeStyle& bcStyle ) { mBcStyle = bcStyle; - emit styleChanged(); + emit selectionChanged(); } } // namespace glabels diff --git a/glabels/BarcodeMenu.h b/glabels/BarcodeMenu.h index 41262d5..8471bfc 100644 --- a/glabels/BarcodeMenu.h +++ b/glabels/BarcodeMenu.h @@ -48,7 +48,7 @@ namespace glabels // Signals ///////////////////////////////// signals: - void styleChanged(); + void selectionChanged(); ///////////////////////////////// @@ -62,7 +62,7 @@ namespace glabels // Slots ///////////////////////////////// private slots: - void onMenuItemActivated( BarcodeStyle bcStyle ); + void onMenuItemActivated( const BarcodeStyle& bcStyle ); ///////////////////////////////// diff --git a/glabels/BarcodeMenuButton.cpp b/glabels/BarcodeMenuButton.cpp index b7243ca..67d2a66 100644 --- a/glabels/BarcodeMenuButton.cpp +++ b/glabels/BarcodeMenuButton.cpp @@ -23,6 +23,8 @@ #include "BarcodeBackends.h" #include "BarcodeMenuItem.h" +#include + namespace glabels { @@ -36,10 +38,10 @@ namespace glabels mMenu = new BarcodeMenu(); setMenu( mMenu ); - mBcStyle = BarcodeBackends::lookupStyleFromId( "" ); // Default style + mBcStyle = BarcodeBackends::defaultStyle(); setText( mBcStyle.name() ); - connect( mMenu, SIGNAL(styleChanged()), this, SLOT(onMenuStyleChanged()) ); + connect( mMenu, SIGNAL(selectionChanged()), this, SLOT(onMenuSelectionChanged()) ); } @@ -52,15 +54,25 @@ namespace glabels } + /// + /// bcStyle setter + /// + void BarcodeMenuButton::setBcStyle( const BarcodeStyle& bcStyle ) + { + mBcStyle = bcStyle; + setText( mBcStyle.name() ); + } + + /// /// onMenuStyleChanged slot /// - void BarcodeMenuButton::onMenuStyleChanged() + void BarcodeMenuButton::onMenuSelectionChanged() { mBcStyle = mMenu->bcStyle(); setText( mBcStyle.name() ); - emit styleChanged(); + emit selectionChanged(); } } // namespace glabels diff --git a/glabels/BarcodeMenuButton.h b/glabels/BarcodeMenuButton.h index d0b90ed..263ecd6 100644 --- a/glabels/BarcodeMenuButton.h +++ b/glabels/BarcodeMenuButton.h @@ -49,7 +49,7 @@ namespace glabels // Signals ///////////////////////////////// signals: - void styleChanged(); + void selectionChanged(); ///////////////////////////////// @@ -57,13 +57,14 @@ namespace glabels ///////////////////////////////// public: BarcodeStyle bcStyle() const; + void setBcStyle( const BarcodeStyle& bcStyle ); ///////////////////////////////// // Slots ///////////////////////////////// private slots: - void onMenuStyleChanged(); + void onMenuSelectionChanged(); ///////////////////////////////// diff --git a/glabels/BarcodeMenuItem.cpp b/glabels/BarcodeMenuItem.cpp index 8d44d71..1150501 100644 --- a/glabels/BarcodeMenuItem.cpp +++ b/glabels/BarcodeMenuItem.cpp @@ -20,6 +20,8 @@ #include "BarcodeMenuItem.h" +#include + namespace glabels { diff --git a/glabels/LabelModelBarcodeObject.cpp b/glabels/LabelModelBarcodeObject.cpp index 8235334..7a26b57 100644 --- a/glabels/LabelModelBarcodeObject.cpp +++ b/glabels/LabelModelBarcodeObject.cpp @@ -44,6 +44,8 @@ namespace glabels { const QColor emptyFillColor = QColor( 128, 128, 128, 128 ); const Distance pad = Distance::pt(4); + const Distance minW = Distance::pt(18); + const Distance minH = Distance::pt(18); } @@ -63,7 +65,7 @@ namespace glabels mHandles << new HandleSouthWest( this ); mHandles << new HandleWest( this ); - mBcStyle = BarcodeBackends::lookupStyleFromId( "code39" ); + mBcStyle = BarcodeBackends::defaultStyle(); mBcTextFlag = mBcStyle.canText(); mBcChecksumFlag = mBcStyle.canChecksum(); mBcFormatDigits = mBcStyle.preferedN(); @@ -315,6 +317,12 @@ namespace glabels delete mEditorBarcode; } mEditorBarcode = glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() ); + if ( !mEditorBarcode ) + { + qWarning() << "Invalid barcode style" << mBcStyle.id() << "using \"code39\"."; + mBcStyle = BarcodeBackends::defaultStyle(); + mEditorBarcode = glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() ); + } mEditorBarcode->setChecksum(mBcChecksumFlag); mEditorBarcode->setShowText(mBcTextFlag); @@ -325,6 +333,11 @@ namespace glabels mW = Distance::pt( mEditorBarcode->width() ); mH = Distance::pt( mEditorBarcode->height() ); } + else + { + mW = max( mW, minW ); + mH = max( mH, minH ); + } QPainterPath path; path.addRect( 0, 0, mW.pt(), mH.pt() ); diff --git a/glabels/ObjectEditor.cpp b/glabels/ObjectEditor.cpp index ebcce19..1807516 100644 --- a/glabels/ObjectEditor.cpp +++ b/glabels/ObjectEditor.cpp @@ -249,8 +249,24 @@ namespace glabels { mBlocked = true; - barcodeShowTextCheck->setChecked( mObject->bcTextFlag() ); - barcodeChecksumCheck->setChecked( mObject->bcChecksumFlag() ); + BarcodeStyle bcStyle = mObject->bcStyle(); + + barcodeShowTextCheck->setEnabled( bcStyle.textOptional() ); + barcodeChecksumCheck->setEnabled( bcStyle.checksumOptional() ); + + // May need to adjust current text flag, if style changed + bool textFlag = (mObject->bcTextFlag() && bcStyle.canText()) + || (bcStyle.canText() && !bcStyle.textOptional()); + mObject->setBcTextFlag( textFlag ); + + // May need to adjust current checksum flag, if style changed + bool csFlag = (mObject->bcChecksumFlag() && bcStyle.canChecksum()) + || (bcStyle.canChecksum() && !bcStyle.checksumOptional()); + mObject->setBcChecksumFlag( csFlag ); + + barcodeStyleButton->setBcStyle( bcStyle ); + barcodeShowTextCheck->setChecked( textFlag ); + barcodeChecksumCheck->setChecked( csFlag ); barcodeColorButton->setColorNode( mObject->bcColorNode() ); barcodeDataEdit->setText( mObject->bcData() ); @@ -702,8 +718,24 @@ namespace glabels { mBlocked = true; - mObject->setBcTextFlag( barcodeShowTextCheck->isChecked() ); - mObject->setBcChecksumFlag( barcodeChecksumCheck->isChecked() ); + BarcodeStyle bcStyle = barcodeStyleButton->bcStyle(); + + barcodeShowTextCheck->setEnabled( bcStyle.textOptional() ); + barcodeChecksumCheck->setEnabled( bcStyle.checksumOptional() ); + + // May need to adjust current text flag, if style changed + bool textFlag = (barcodeShowTextCheck->isChecked() && bcStyle.canText()) + || (bcStyle.canText() && !bcStyle.textOptional()); + barcodeShowTextCheck->setChecked( textFlag ); + + // May need to adjust current checksum flag, if style changed + bool csFlag = (barcodeChecksumCheck->isChecked() && bcStyle.canChecksum()) + || (bcStyle.canChecksum() && !bcStyle.checksumOptional()); + barcodeChecksumCheck->setChecked( csFlag ); + + mObject->setBcStyle( bcStyle ); + mObject->setBcTextFlag( textFlag ); + mObject->setBcChecksumFlag( csFlag ); mObject->setBcColorNode( barcodeColorButton->colorNode() ); mObject->setBcData( barcodeDataEdit->toPlainText() ); diff --git a/glabels/glabels_main.cpp b/glabels/glabels_main.cpp index fdcba4e..85799e1 100644 --- a/glabels/glabels_main.cpp +++ b/glabels/glabels_main.cpp @@ -18,6 +18,7 @@ * along with gLabels-qt. If not, see . */ +#include "BarcodeBackends.h" #include "FileUtil.h" #include "Db.h" #include "LabelModel.h" @@ -89,6 +90,7 @@ int main( int argc, char **argv ) glabels::Settings::init(); glabels::Db::init(); glabels::merge::Factory::init(); + glabels::BarcodeBackends::init(); // diff --git a/glabels/ui/ObjectEditor.ui b/glabels/ui/ObjectEditor.ui index 4592bc7..5c65a1b 100644 --- a/glabels/ui/ObjectEditor.ui +++ b/glabels/ui/ObjectEditor.ui @@ -562,9 +562,6 @@ - - - @@ -610,6 +607,9 @@ + + + @@ -1489,6 +1489,14 @@ keySelected(QString) + + glabels::BarcodeMenuButton + QPushButton +
BarcodeMenuButton.h
+ + selectionChanged() + +
@@ -2006,22 +2014,6 @@ - - barcodeTypeCombo - textChanged(QString) - ObjectEditor - onBarcodeControlsChanged() - - - 102 - 116 - - - 399 - 144 - - - barcodeShowTextCheck toggled(bool) @@ -2102,6 +2094,22 @@ + + barcodeStyleButton + selectionChanged() + ObjectEditor + onBarcodeControlsChanged() + + + 114 + 121 + + + 5 + 94 + + + onChanged() diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index f557a96..63ca387 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -204,7 +204,7 @@ - + @@ -232,12 +232,12 @@ - + Show text - + Checksum @@ -744,64 +744,62 @@ glabels::BarcodeBackends - + POSTNET (any) - + POSTNET-5 (ZIP only) - + POSTNET-9 (ZIP+4) - + POSTNET-11 (DPBC) - + CEPNET - + USPS Intelligent Mail - - - + Code 39 - + Code 39 Extended - + UPC-A - + EAN-13 - + DataMatrix - + QRCode @@ -1117,12 +1115,12 @@ glabels::LabelModelBarcodeObject - + No barcode data - + Invalid barcode data @@ -1800,134 +1798,134 @@ - + Box object properties - + Ellipse object properties - + Image object properties - + Line object properties - + Text object properties - + Barcode object properties - + Line - + Fill - + Image files (*.png *.jpg *.jpeg *.gif *.bmp *.pbm *.pgm *.ppm *.xbm *.xpm *.svg) - + All files (*) - + PNG - Portable Network Graphics (*.png) - + BMP - Windows Bitmap (*.bmp) - + GIF - Graphics Interchange Format (*.gif) - + JPEG - Joint Photographic Experts Group (*.jpg *.jpeg) - + PBM - Portable Bitmap (*.pbm) - + PGM - Portable Graymap (*.pgm) - + PPM - Portable Pixmap (*.ppm) - + SVG - Scalable Vector Graphics (*.svg) - + XBM - X11 Bitmap (*.xbm) - + XPM - X11 Pixmap (*.xpm) - + gLabels - Select image file - - + + Set image - + Move - - + + Size - + Text - + Shadow @@ -1974,12 +1972,12 @@ main - + gLabels Label Designer - + gLabels project files to open, optionally.