Skip to content

Commit

Permalink
Preview - Add label index overlay text to preview screen
Browse files Browse the repository at this point in the history
  • Loading branch information
chmorgan committed Nov 16, 2018
1 parent 76c370b commit 8f58efb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
38 changes: 38 additions & 0 deletions glabels/Preview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ namespace glabels
const QColor labelColor( 255, 255, 255 );
const QColor labelOutlineColor( 215, 215, 215 );
const double labelOutlineWidthPixels = 1;

const QColor labelNumberColor( 192, 192, 255, 128 );
const QString labelNumberFontFamily( "Sans" );
const double labelNumberScale = 0.5;
}


Expand Down Expand Up @@ -101,9 +105,43 @@ namespace glabels
drawPaper( mModel->tmplate()->pageWidth(), mModel->tmplate()->pageHeight() );
drawLabels();
drawPreviewOverlay();
drawLabelNumberOverlay();
}
}

void Preview::drawLabelNumberOverlaySingle(const model::Distance& x, const model::Distance& y, const QPainterPath& path, uint32_t labelInstance)
{
QBrush brush( labelNumberColor );

model::Frame *frame = mModel->tmplate()->frames().first();

model::Distance w = frame->w();
model::Distance h = frame->h();

model::Distance minWH = min( w, h );

auto labelText = QString::number(labelInstance);
QGraphicsSimpleTextItem *labelNumberItem = new QGraphicsSimpleTextItem( labelText );
labelNumberItem->setBrush( brush );
labelNumberItem->setFont( QFont( labelNumberFontFamily, minWH.pt()*labelNumberScale, QFont::Bold ) );
labelNumberItem->setPos( (x+w/2).pt(), (y+h/2).pt() );
QRectF rect = labelNumberItem->boundingRect();
labelNumberItem->setPos(labelNumberItem->x() - (rect.width() / 2), labelNumberItem->y() - (rect.height() / 2));

mScene->addItem( labelNumberItem );
}

void Preview::drawLabelNumberOverlay()
{
model::Frame *frame = mModel->tmplate()->frames().first();
auto i = 0;

foreach (model::Point origin, frame->getOrigins() )
{
i++;
drawLabelNumberOverlaySingle( origin.x(), origin.y(), frame->path(), i);
}
}

///
/// Resize Event Handler
Expand Down
3 changes: 3 additions & 0 deletions glabels/Preview.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ namespace glabels

void drawPreviewOverlay();

void drawLabelNumberOverlaySingle(const model::Distance& x, const model::Distance& y, const QPainterPath& path, uint32_t labelInstance);
void drawLabelNumberOverlay();


/////////////////////////////////
// Private Data
Expand Down

0 comments on commit 8f58efb

Please sign in to comment.