Big-Ugly Style Update (#278)
* Bulk replaced tabs with spaces * Bulk removed trailing whitespace from lines * Replaced c-style comments with c++-style comments in file banners * Replace nested namespace definitions with single concise definitions (C++17), this keeps the indentation more manageable * Cleanup ordering and spacing of include directives * Bulk renaming of header file extensions from '.h' to '.hpp'. * Update CODING-STYLE.md * Update target_compile_features from cxx_std_11 to cxx_std_20. * Refresh .clang-format file. Still needs a lot of tweaking.
This commit is contained in:
+209
-208
@@ -1,253 +1,254 @@
|
||||
/* Preview.cpp
|
||||
*
|
||||
* Copyright (C) 2013-2016 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// Preview.cpp
|
||||
//
|
||||
// Copyright (C) 2013-2016 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// gLabels-qt is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "Preview.h"
|
||||
|
||||
#include "PreviewOverlayItem.h"
|
||||
#include "RollTemplatePath.h"
|
||||
#include "Preview.hpp"
|
||||
|
||||
#include "PreviewOverlayItem.hpp"
|
||||
#include "RollTemplatePath.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
#include <QGraphicsRectItem>
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
//
|
||||
// Private
|
||||
//
|
||||
namespace
|
||||
{
|
||||
const QColor paperColor( 242, 242, 242 );
|
||||
const QColor paperOutlineColor( 0, 0, 0 );
|
||||
const double paperOutlineWidthPixels = 1;
|
||||
|
||||
const QColor shadowColor( 64, 64, 64 );
|
||||
const double shadowOffsetPixels = 3;
|
||||
const double shadowRadiusPixels = 12;
|
||||
|
||||
const QColor labelColor( 255, 255, 255 );
|
||||
const QColor labelOutlineColor( 192, 192, 192 );
|
||||
const double labelOutlineWidthPixels = 1;
|
||||
|
||||
const QColor labelNumberColor( 192, 192, 255, 128 );
|
||||
const QString labelNumberFontFamily( "Sans" );
|
||||
const double labelNumberScale = 0.5;
|
||||
}
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
//
|
||||
// Private
|
||||
//
|
||||
namespace
|
||||
{
|
||||
const QColor paperColor( 242, 242, 242 );
|
||||
const QColor paperOutlineColor( 0, 0, 0 );
|
||||
const double paperOutlineWidthPixels = 1;
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
Preview::Preview( QWidget *parent )
|
||||
: QGraphicsView(parent), mModel(nullptr), mRenderer(nullptr)
|
||||
{
|
||||
mScene = new QGraphicsScene();
|
||||
setScene( mScene );
|
||||
|
||||
const QColor shadowColor( 64, 64, 64 );
|
||||
const double shadowOffsetPixels = 3;
|
||||
const double shadowRadiusPixels = 12;
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
viewport()->setAutoFillBackground(false);
|
||||
|
||||
const QColor labelColor( 255, 255, 255 );
|
||||
const QColor labelOutlineColor( 192, 192, 192 );
|
||||
const double labelOutlineWidthPixels = 1;
|
||||
|
||||
const QColor labelNumberColor( 192, 192, 255, 128 );
|
||||
const QString labelNumberFontFamily( "Sans" );
|
||||
const double labelNumberScale = 0.5;
|
||||
}
|
||||
setFrameStyle( QFrame::NoFrame );
|
||||
setRenderHints( QPainter::Antialiasing );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
Preview::Preview( QWidget *parent )
|
||||
: QGraphicsView(parent), mModel(nullptr), mRenderer(nullptr)
|
||||
{
|
||||
mScene = new QGraphicsScene();
|
||||
setScene( mScene );
|
||||
///
|
||||
/// Set renderer
|
||||
///
|
||||
void Preview::setRenderer( const model::PageRenderer* renderer )
|
||||
{
|
||||
mRenderer = renderer;
|
||||
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
viewport()->setAutoFillBackground(false);
|
||||
|
||||
setFrameStyle( QFrame::NoFrame );
|
||||
setRenderHints( QPainter::Antialiasing );
|
||||
}
|
||||
connect( mRenderer, SIGNAL(changed()), this, SLOT(onRendererChanged()) );
|
||||
onRendererChanged();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set renderer
|
||||
///
|
||||
void Preview::setRenderer( const model::PageRenderer* renderer )
|
||||
{
|
||||
mRenderer = renderer;
|
||||
///
|
||||
/// Renderer changed handler
|
||||
///
|
||||
void Preview::onRendererChanged()
|
||||
{
|
||||
mModel = mRenderer->model();
|
||||
|
||||
connect( mRenderer, SIGNAL(changed()), this, SLOT(onRendererChanged()) );
|
||||
onRendererChanged();
|
||||
}
|
||||
mScene->clear();
|
||||
|
||||
if ( mModel != nullptr )
|
||||
{
|
||||
auto tmplate = mModel->tmplate();
|
||||
|
||||
// For "Roll" templates, allow extra room to draw continuation break lines.
|
||||
model::Distance drawHeight = mModel->tmplate().pageHeight();
|
||||
model::Distance drawOffset = 0;
|
||||
if ( tmplate.isRoll() )
|
||||
{
|
||||
drawHeight = 1.2 * tmplate.pageHeight();
|
||||
drawOffset = 0.1 * tmplate.pageHeight();
|
||||
}
|
||||
|
||||
// Set scene up with a 5% margin around paper
|
||||
model::Distance x = -0.05 * tmplate.pageWidth();
|
||||
model::Distance y = -0.05 * drawHeight - drawOffset;
|
||||
model::Distance w = 1.10 * tmplate.pageWidth();
|
||||
model::Distance h = 1.10 * drawHeight;
|
||||
|
||||
mScene->setSceneRect( x.pt(), y.pt(), w.pt(), h.pt() );
|
||||
fitInView( mScene->sceneRect(), Qt::KeepAspectRatio );
|
||||
|
||||
drawPaper();
|
||||
drawLabels();
|
||||
drawPreviewOverlay();
|
||||
drawLabelNumberOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Renderer changed handler
|
||||
///
|
||||
void Preview::onRendererChanged()
|
||||
{
|
||||
mModel = mRenderer->model();
|
||||
void Preview::drawLabelNumberOverlaySingle( model::Distance x,
|
||||
model::Distance y,
|
||||
const QPainterPath& path,
|
||||
uint32_t labelInstance)
|
||||
{
|
||||
QBrush brush( labelNumberColor );
|
||||
|
||||
mScene->clear();
|
||||
auto frame = mModel->tmplate().frame();
|
||||
|
||||
if ( mModel != nullptr )
|
||||
{
|
||||
auto tmplate = mModel->tmplate();
|
||||
model::Distance w = frame->w();
|
||||
model::Distance h = frame->h();
|
||||
|
||||
// For "Roll" templates, allow extra room to draw continuation break lines.
|
||||
model::Distance drawHeight = mModel->tmplate().pageHeight();
|
||||
model::Distance drawOffset = 0;
|
||||
if ( tmplate.isRoll() )
|
||||
{
|
||||
drawHeight = 1.2 * tmplate.pageHeight();
|
||||
drawOffset = 0.1 * tmplate.pageHeight();
|
||||
}
|
||||
|
||||
// Set scene up with a 5% margin around paper
|
||||
model::Distance x = -0.05 * tmplate.pageWidth();
|
||||
model::Distance y = -0.05 * drawHeight - drawOffset;
|
||||
model::Distance w = 1.10 * tmplate.pageWidth();
|
||||
model::Distance h = 1.10 * drawHeight;
|
||||
model::Distance minWH = min( w, h );
|
||||
|
||||
mScene->setSceneRect( x.pt(), y.pt(), w.pt(), h.pt() );
|
||||
fitInView( mScene->sceneRect(), Qt::KeepAspectRatio );
|
||||
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));
|
||||
|
||||
drawPaper();
|
||||
drawLabels();
|
||||
drawPreviewOverlay();
|
||||
drawLabelNumberOverlay();
|
||||
}
|
||||
}
|
||||
mScene->addItem( labelNumberItem );
|
||||
}
|
||||
|
||||
|
||||
void Preview::drawLabelNumberOverlaySingle( model::Distance x,
|
||||
model::Distance y,
|
||||
const QPainterPath& path,
|
||||
uint32_t labelInstance)
|
||||
{
|
||||
QBrush brush( labelNumberColor );
|
||||
void Preview::drawLabelNumberOverlay()
|
||||
{
|
||||
auto frame = mModel->tmplate().frame();
|
||||
auto i = 0;
|
||||
|
||||
auto frame = mModel->tmplate().frame();
|
||||
|
||||
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 );
|
||||
}
|
||||
for ( model::Point origin : frame->getOrigins() )
|
||||
{
|
||||
i++;
|
||||
drawLabelNumberOverlaySingle( origin.x(), origin.y(), frame->path(), i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Preview::drawLabelNumberOverlay()
|
||||
{
|
||||
auto frame = mModel->tmplate().frame();
|
||||
auto i = 0;
|
||||
|
||||
for ( model::Point origin : frame->getOrigins() )
|
||||
{
|
||||
i++;
|
||||
drawLabelNumberOverlaySingle( origin.x(), origin.y(), frame->path(), i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Resize Event Handler
|
||||
///
|
||||
void Preview::resizeEvent( QResizeEvent* event )
|
||||
{
|
||||
fitInView( mScene->sceneRect(), Qt::KeepAspectRatio );
|
||||
}
|
||||
///
|
||||
/// Resize Event Handler
|
||||
///
|
||||
void Preview::resizeEvent( QResizeEvent* event )
|
||||
{
|
||||
fitInView( mScene->sceneRect(), Qt::KeepAspectRatio );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw Paper
|
||||
///
|
||||
void Preview::drawPaper()
|
||||
{
|
||||
auto *shadowEffect = new QGraphicsDropShadowEffect();
|
||||
shadowEffect->setColor( shadowColor );
|
||||
shadowEffect->setOffset( shadowOffsetPixels );
|
||||
shadowEffect->setBlurRadius( shadowRadiusPixels );
|
||||
///
|
||||
/// Draw Paper
|
||||
///
|
||||
void Preview::drawPaper()
|
||||
{
|
||||
auto *shadowEffect = new QGraphicsDropShadowEffect();
|
||||
shadowEffect->setColor( shadowColor );
|
||||
shadowEffect->setOffset( shadowOffsetPixels );
|
||||
shadowEffect->setBlurRadius( shadowRadiusPixels );
|
||||
|
||||
QBrush brush( paperColor );
|
||||
QPen pen( paperOutlineColor );
|
||||
pen.setCosmetic( true );
|
||||
pen.setWidthF( paperOutlineWidthPixels );
|
||||
QBrush brush( paperColor );
|
||||
QPen pen( paperOutlineColor );
|
||||
pen.setCosmetic( true );
|
||||
pen.setWidthF( paperOutlineWidthPixels );
|
||||
|
||||
QAbstractGraphicsShapeItem* pageItem;
|
||||
auto tmplate = mModel->tmplate();
|
||||
if ( !tmplate.isRoll() )
|
||||
{
|
||||
pageItem = new QGraphicsRectItem( 0, 0, tmplate.pageWidth().pt(), tmplate.pageHeight().pt() );
|
||||
}
|
||||
else
|
||||
{
|
||||
pageItem = new QGraphicsPathItem( RollTemplatePath( tmplate ) );
|
||||
}
|
||||
pageItem->setBrush( brush );
|
||||
pageItem->setPen( pen );
|
||||
pageItem->setGraphicsEffect( shadowEffect );
|
||||
|
||||
mScene->addItem( pageItem );
|
||||
}
|
||||
QAbstractGraphicsShapeItem* pageItem;
|
||||
auto tmplate = mModel->tmplate();
|
||||
if ( !tmplate.isRoll() )
|
||||
{
|
||||
pageItem = new QGraphicsRectItem( 0, 0, tmplate.pageWidth().pt(), tmplate.pageHeight().pt() );
|
||||
}
|
||||
else
|
||||
{
|
||||
pageItem = new QGraphicsPathItem( RollTemplatePath( tmplate ) );
|
||||
}
|
||||
pageItem->setBrush( brush );
|
||||
pageItem->setPen( pen );
|
||||
pageItem->setGraphicsEffect( shadowEffect );
|
||||
|
||||
mScene->addItem( pageItem );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw Labels on Paper
|
||||
///
|
||||
void Preview::drawLabels()
|
||||
{
|
||||
auto frame = mModel->tmplate().frame();
|
||||
///
|
||||
/// Draw Labels on Paper
|
||||
///
|
||||
void Preview::drawLabels()
|
||||
{
|
||||
auto frame = mModel->tmplate().frame();
|
||||
|
||||
for ( model::Point origin : frame->getOrigins() )
|
||||
{
|
||||
drawLabel( origin.x(), origin.y(), frame->path() );
|
||||
}
|
||||
}
|
||||
for ( model::Point origin : frame->getOrigins() )
|
||||
{
|
||||
drawLabel( origin.x(), origin.y(), frame->path() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw a Single Label at x,y
|
||||
///
|
||||
void Preview::drawLabel( model::Distance x,
|
||||
model::Distance y,
|
||||
const QPainterPath& path )
|
||||
{
|
||||
QBrush brush( labelColor );
|
||||
QPen pen( labelOutlineColor );
|
||||
pen.setCosmetic( true );
|
||||
pen.setWidthF( labelOutlineWidthPixels );
|
||||
///
|
||||
/// Draw a Single Label at x,y
|
||||
///
|
||||
void Preview::drawLabel( model::Distance x,
|
||||
model::Distance y,
|
||||
const QPainterPath& path )
|
||||
{
|
||||
QBrush brush( labelColor );
|
||||
QPen pen( labelOutlineColor );
|
||||
pen.setCosmetic( true );
|
||||
pen.setWidthF( labelOutlineWidthPixels );
|
||||
|
||||
auto *labelOutlineItem = new QGraphicsPathItem( path );
|
||||
labelOutlineItem->setBrush( brush );
|
||||
labelOutlineItem->setPen( pen );
|
||||
labelOutlineItem->setPos( x.pt(), y.pt() );
|
||||
auto *labelOutlineItem = new QGraphicsPathItem( path );
|
||||
labelOutlineItem->setBrush( brush );
|
||||
labelOutlineItem->setPen( pen );
|
||||
labelOutlineItem->setPos( x.pt(), y.pt() );
|
||||
|
||||
mScene->addItem( labelOutlineItem );
|
||||
}
|
||||
mScene->addItem( labelOutlineItem );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw Preview Overlay
|
||||
///
|
||||
void Preview::drawPreviewOverlay()
|
||||
{
|
||||
if ( mRenderer )
|
||||
{
|
||||
auto* overlayItem = new PreviewOverlayItem( mRenderer );
|
||||
mScene->addItem( overlayItem );
|
||||
}
|
||||
}
|
||||
///
|
||||
/// Draw Preview Overlay
|
||||
///
|
||||
void Preview::drawPreviewOverlay()
|
||||
{
|
||||
if ( mRenderer )
|
||||
{
|
||||
auto* overlayItem = new PreviewOverlayItem( mRenderer );
|
||||
mScene->addItem( overlayItem );
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace glabels
|
||||
|
||||
Reference in New Issue
Block a user