Render barcode placeholder for invalid data in label editor.
This commit is contained in:
@@ -735,6 +735,9 @@ namespace glabels
|
||||
case Text:
|
||||
mCreateObject->setSize( 72, 36 );
|
||||
break;
|
||||
case Barcode:
|
||||
mCreateObject->setSize( 72, 36 );
|
||||
break;
|
||||
case Line:
|
||||
mCreateObject->setSize( 72, 0 );
|
||||
break;
|
||||
|
||||
@@ -42,6 +42,8 @@ namespace glabels
|
||||
//
|
||||
namespace
|
||||
{
|
||||
const QColor emptyFillColor = QColor( 128, 128, 128, 128 );
|
||||
const Distance pad = Distance::pt(4);
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +67,7 @@ namespace glabels
|
||||
mBcTextFlag = mBcStyle.canText();
|
||||
mBcChecksumFlag = mBcStyle.canChecksum();
|
||||
mBcFormatDigits = mBcStyle.preferedN();
|
||||
mBcData = mBcStyle.defaultDigits();
|
||||
mBcData = "";
|
||||
mBcColorNode = ColorNode( Qt::black );
|
||||
|
||||
update(); // Initialize cached editor layouts
|
||||
@@ -261,22 +263,7 @@ namespace glabels
|
||||
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 );
|
||||
}
|
||||
}
|
||||
// Barcodes don't support shadows.
|
||||
}
|
||||
|
||||
|
||||
@@ -333,11 +320,14 @@ namespace glabels
|
||||
|
||||
mEditorBarcode->build( mBcData.toStdString(), mW.pt(), mH.pt() );
|
||||
|
||||
mW = Distance::pt( mEditorBarcode->width() );
|
||||
mH = Distance::pt( mEditorBarcode->height() );
|
||||
if ( mEditorBarcode->isDataValid() )
|
||||
{
|
||||
mW = Distance::pt( mEditorBarcode->width() );
|
||||
mH = Distance::pt( mEditorBarcode->height() );
|
||||
}
|
||||
|
||||
QPainterPath path;
|
||||
path.addRect( 0, 0, mEditorBarcode->width(), mEditorBarcode->height() );
|
||||
path.addRect( 0, 0, mW.pt(), mH.pt() );
|
||||
mHoverPath = path;
|
||||
}
|
||||
|
||||
@@ -354,13 +344,43 @@ namespace glabels
|
||||
glbarcode::QtRenderer renderer(painter);
|
||||
mEditorBarcode->render( renderer );
|
||||
}
|
||||
else if ( mEditorBarcode->isEmpty() )
|
||||
{
|
||||
// FIXME: display "Empty"
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME: display "Invalid data"
|
||||
QString text;
|
||||
|
||||
if ( mEditorBarcode->isEmpty() )
|
||||
{
|
||||
text = tr("No barcode data");
|
||||
}
|
||||
else
|
||||
{
|
||||
text = tr("Invalid barcode data");
|
||||
}
|
||||
|
||||
painter->setPen( Qt::NoPen );
|
||||
painter->setBrush( QBrush( emptyFillColor ) );
|
||||
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
|
||||
QFont font( "Sans" );
|
||||
font.setPointSizeF( 6 );
|
||||
|
||||
QFontMetricsF fm(font);
|
||||
QRectF textRect = fm.boundingRect( text );
|
||||
|
||||
double wPts = (mW - 2*pad).pt();
|
||||
double hPts = (mH - 2*pad).pt();
|
||||
if ( (wPts < textRect.width()) || (hPts < textRect.height()) )
|
||||
{
|
||||
double scaleX = wPts / textRect.width();
|
||||
double scaleY = hPts / textRect.height();
|
||||
font.setPointSizeF( 6 * std::min( scaleX, scaleY ) );
|
||||
}
|
||||
|
||||
painter->setFont( font );
|
||||
painter->setPen( QPen( color ) );
|
||||
painter->drawText( QRectF( 0, 0, mW.pt(), mH.pt() ),
|
||||
Qt::AlignCenter,
|
||||
text );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1093,15 +1093,15 @@
|
||||
<name>glabels::LabelEditor</name>
|
||||
<message>
|
||||
<location filename="../glabels/LabelEditor.cpp" line="640"/>
|
||||
<location filename="../glabels/LabelEditor.cpp" line="937"/>
|
||||
<location filename="../glabels/LabelEditor.cpp" line="942"/>
|
||||
<location filename="../glabels/LabelEditor.cpp" line="947"/>
|
||||
<location filename="../glabels/LabelEditor.cpp" line="952"/>
|
||||
<location filename="../glabels/LabelEditor.cpp" line="940"/>
|
||||
<location filename="../glabels/LabelEditor.cpp" line="945"/>
|
||||
<location filename="../glabels/LabelEditor.cpp" line="950"/>
|
||||
<location filename="../glabels/LabelEditor.cpp" line="955"/>
|
||||
<source>Move</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../glabels/LabelEditor.cpp" line="957"/>
|
||||
<location filename="../glabels/LabelEditor.cpp" line="960"/>
|
||||
<source>Delete</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
@@ -1114,6 +1114,19 @@
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>glabels::LabelModelBarcodeObject</name>
|
||||
<message>
|
||||
<location filename="../glabels/LabelModelBarcodeObject.cpp" line="353"/>
|
||||
<source>No barcode data</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../glabels/LabelModelBarcodeObject.cpp" line="357"/>
|
||||
<source>Invalid barcode data</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>glabels::LabelModelTextObject</name>
|
||||
<message>
|
||||
|
||||
Reference in New Issue
Block a user