Barcode tweaks.
- Add capability to disable text in glbarcode UPC/EAN barcodes. (#79) - Add backend name to display text in BarcodeMenuButton.
This commit is contained in:
@@ -50,10 +50,10 @@ namespace glabels
|
||||
true, true, true, true, "1234567890", true, 10 );
|
||||
|
||||
registerStyle( "upc-a", "", tr("UPC-A"),
|
||||
true, false, true, false, "12345678901", false, 11 );
|
||||
true, true, true, false, "12345678901", false, 11 );
|
||||
|
||||
registerStyle( "ean-13", "", tr("EAN-13"),
|
||||
true, false, true, false, "123456789012", false, 12 );
|
||||
true, true, true, false, "123456789012", false, 12 );
|
||||
|
||||
registerStyle( "postnet", "", tr("POSTNET (any)"),
|
||||
false, false, true, false, "12345-6789-12", false, 11 );
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
#include "Style.h"
|
||||
|
||||
#include "Backends.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
@@ -116,6 +118,22 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Full Name Property Getter
|
||||
///
|
||||
QString Style::fullName() const
|
||||
{
|
||||
if ( mBackendId == "" )
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Backends::backendName(mBackendId) + " / " + mName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Text Property Getter
|
||||
///
|
||||
|
||||
@@ -65,6 +65,8 @@ namespace glabels
|
||||
|
||||
const QString& name() const;
|
||||
|
||||
QString fullName() const;
|
||||
|
||||
bool canText() const;
|
||||
|
||||
bool textOptional() const;
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace glabels
|
||||
setMenu( mMenu );
|
||||
|
||||
mBcStyle = barcode::Backends::defaultStyle();
|
||||
setText( mBcStyle.name() );
|
||||
setText( mBcStyle.fullName() );
|
||||
|
||||
connect( mMenu, SIGNAL(selectionChanged()), this, SLOT(onMenuSelectionChanged()) );
|
||||
}
|
||||
@@ -61,7 +61,7 @@ namespace glabels
|
||||
void BarcodeMenuButton::setBcStyle( const barcode::Style& bcStyle )
|
||||
{
|
||||
mBcStyle = bcStyle;
|
||||
setText( mBcStyle.name() );
|
||||
setText( mBcStyle.fullName() );
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace glabels
|
||||
void BarcodeMenuButton::onMenuSelectionChanged()
|
||||
{
|
||||
mBcStyle = mMenu->bcStyle();
|
||||
setText( mBcStyle.name() );
|
||||
setText( mBcStyle.fullName() );
|
||||
|
||||
emit selectionChanged();
|
||||
}
|
||||
|
||||
@@ -192,6 +192,8 @@ namespace glbarcode
|
||||
{
|
||||
std::string displayText;
|
||||
|
||||
if ( showText() )
|
||||
{
|
||||
for (char c : rawData)
|
||||
{
|
||||
if ( isdigit( c ) )
|
||||
@@ -201,6 +203,7 @@ namespace glbarcode
|
||||
}
|
||||
|
||||
displayText += (mCheckDigitVal + '0');
|
||||
}
|
||||
|
||||
return displayText;
|
||||
}
|
||||
@@ -238,23 +241,10 @@ namespace glbarcode
|
||||
double xQuiet = mscale * QUIET_MODULES;
|
||||
|
||||
/* determine bar height */
|
||||
double hTextArea = scale * BASE_TEXT_AREA_HEIGHT;
|
||||
double hTextArea = showText() ? scale * BASE_TEXT_AREA_HEIGHT : 0;
|
||||
double hBar1 = std::max( (h - hTextArea), width/2 );
|
||||
double hBar2 = hBar1 + hTextArea/2;
|
||||
|
||||
/* determine text parameters */
|
||||
double textSize1 = scale * BASE_FONT_SIZE;
|
||||
double textSize2 = 0.75*textSize1;
|
||||
|
||||
double textX1Left = xQuiet + mscale*(0.25*nModules + 0.5*mEndBarsModules - 0.75);
|
||||
double textX1Right = xQuiet + mscale*(0.75*nModules - 0.5*mEndBarsModules + 0.75);
|
||||
double textX2Left = 0.5*xQuiet;
|
||||
double textX2Right = 1.5*xQuiet + mscale*nModules;
|
||||
|
||||
double textY1 = hBar2 + textSize1/4;
|
||||
double textY2 = hBar2 + textSize2/4;
|
||||
|
||||
|
||||
/* now traverse the code string and draw each bar */
|
||||
auto nBarsSpaces = int( codedData.size() - 1 ); /* coded data has dummy "0" on end. */
|
||||
|
||||
@@ -283,11 +273,29 @@ namespace glbarcode
|
||||
xModules += wSpace;
|
||||
}
|
||||
|
||||
|
||||
/* draw text */
|
||||
if ( showText() )
|
||||
{
|
||||
/* determine text parameters */
|
||||
double textSize1 = scale * BASE_FONT_SIZE;
|
||||
double textSize2 = 0.75*textSize1;
|
||||
|
||||
double textX1Left = xQuiet + mscale*(0.25*nModules + 0.5*mEndBarsModules - 0.75);
|
||||
double textX1Right = xQuiet + mscale*(0.75*nModules - 0.5*mEndBarsModules + 0.75);
|
||||
double textX2Left = 0.5*xQuiet;
|
||||
double textX2Right = 1.5*xQuiet + mscale*nModules;
|
||||
|
||||
double textY1 = hBar2 + textSize1/4;
|
||||
double textY2 = hBar2 + textSize2/4;
|
||||
|
||||
/* draw text (call implementation from concrete class) */
|
||||
vectorizeText( displayText,
|
||||
textSize1, textSize2,
|
||||
textX1Left, textX1Right, textY1,
|
||||
textX2Left, textX2Right, textY2 );
|
||||
}
|
||||
|
||||
|
||||
/* Overwrite requested size with actual size. */
|
||||
w = width;
|
||||
|
||||
Reference in New Issue
Block a user