Render barcode placeholder for invalid data in label editor.
This commit is contained in:
@@ -735,6 +735,9 @@ namespace glabels
|
|||||||
case Text:
|
case Text:
|
||||||
mCreateObject->setSize( 72, 36 );
|
mCreateObject->setSize( 72, 36 );
|
||||||
break;
|
break;
|
||||||
|
case Barcode:
|
||||||
|
mCreateObject->setSize( 72, 36 );
|
||||||
|
break;
|
||||||
case Line:
|
case Line:
|
||||||
mCreateObject->setSize( 72, 0 );
|
mCreateObject->setSize( 72, 0 );
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ namespace glabels
|
|||||||
//
|
//
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
const QColor emptyFillColor = QColor( 128, 128, 128, 128 );
|
||||||
|
const Distance pad = Distance::pt(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -65,7 +67,7 @@ namespace glabels
|
|||||||
mBcTextFlag = mBcStyle.canText();
|
mBcTextFlag = mBcStyle.canText();
|
||||||
mBcChecksumFlag = mBcStyle.canChecksum();
|
mBcChecksumFlag = mBcStyle.canChecksum();
|
||||||
mBcFormatDigits = mBcStyle.preferedN();
|
mBcFormatDigits = mBcStyle.preferedN();
|
||||||
mBcData = mBcStyle.defaultDigits();
|
mBcData = "";
|
||||||
mBcColorNode = ColorNode( Qt::black );
|
mBcColorNode = ColorNode( Qt::black );
|
||||||
|
|
||||||
update(); // Initialize cached editor layouts
|
update(); // Initialize cached editor layouts
|
||||||
@@ -261,22 +263,7 @@ namespace glabels
|
|||||||
bool inEditor,
|
bool inEditor,
|
||||||
merge::Record* record ) const
|
merge::Record* record ) const
|
||||||
{
|
{
|
||||||
QColor bcColor = mBcColorNode.color( record );
|
// Barcodes don't support shadows.
|
||||||
|
|
||||||
if ( bcColor.alpha() )
|
|
||||||
{
|
|
||||||
QColor shadowColor = mShadowColorNode.color( record );
|
|
||||||
shadowColor.setAlphaF( mShadowOpacity );
|
|
||||||
|
|
||||||
if ( inEditor )
|
|
||||||
{
|
|
||||||
drawBcInEditor( painter, shadowColor );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
drawBc( painter, shadowColor, record );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -333,11 +320,14 @@ namespace glabels
|
|||||||
|
|
||||||
mEditorBarcode->build( mBcData.toStdString(), mW.pt(), mH.pt() );
|
mEditorBarcode->build( mBcData.toStdString(), mW.pt(), mH.pt() );
|
||||||
|
|
||||||
|
if ( mEditorBarcode->isDataValid() )
|
||||||
|
{
|
||||||
mW = Distance::pt( mEditorBarcode->width() );
|
mW = Distance::pt( mEditorBarcode->width() );
|
||||||
mH = Distance::pt( mEditorBarcode->height() );
|
mH = Distance::pt( mEditorBarcode->height() );
|
||||||
|
}
|
||||||
|
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
path.addRect( 0, 0, mEditorBarcode->width(), mEditorBarcode->height() );
|
path.addRect( 0, 0, mW.pt(), mH.pt() );
|
||||||
mHoverPath = path;
|
mHoverPath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,13 +344,43 @@ namespace glabels
|
|||||||
glbarcode::QtRenderer renderer(painter);
|
glbarcode::QtRenderer renderer(painter);
|
||||||
mEditorBarcode->render( renderer );
|
mEditorBarcode->render( renderer );
|
||||||
}
|
}
|
||||||
else if ( mEditorBarcode->isEmpty() )
|
else
|
||||||
{
|
{
|
||||||
// FIXME: display "Empty"
|
QString text;
|
||||||
|
|
||||||
|
if ( mEditorBarcode->isEmpty() )
|
||||||
|
{
|
||||||
|
text = tr("No barcode data");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// FIXME: display "Invalid data"
|
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>
|
<name>glabels::LabelEditor</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../glabels/LabelEditor.cpp" line="640"/>
|
<location filename="../glabels/LabelEditor.cpp" line="640"/>
|
||||||
<location filename="../glabels/LabelEditor.cpp" line="937"/>
|
<location filename="../glabels/LabelEditor.cpp" line="940"/>
|
||||||
<location filename="../glabels/LabelEditor.cpp" line="942"/>
|
<location filename="../glabels/LabelEditor.cpp" line="945"/>
|
||||||
<location filename="../glabels/LabelEditor.cpp" line="947"/>
|
<location filename="../glabels/LabelEditor.cpp" line="950"/>
|
||||||
<location filename="../glabels/LabelEditor.cpp" line="952"/>
|
<location filename="../glabels/LabelEditor.cpp" line="955"/>
|
||||||
<source>Move</source>
|
<source>Move</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../glabels/LabelEditor.cpp" line="957"/>
|
<location filename="../glabels/LabelEditor.cpp" line="960"/>
|
||||||
<source>Delete</source>
|
<source>Delete</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
@@ -1114,6 +1114,19 @@
|
|||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</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>
|
<context>
|
||||||
<name>glabels::LabelModelTextObject</name>
|
<name>glabels::LabelModelTextObject</name>
|
||||||
<message>
|
<message>
|
||||||
|
|||||||
Reference in New Issue
Block a user