Added page renderer class. Use renderer to overlay onto preview.
This commit is contained in:
@@ -34,8 +34,10 @@ set (glabels_sources
|
||||
NewLabelDialog.cpp
|
||||
ObjectEditor.cpp
|
||||
Outline.cpp
|
||||
PageRenderer.cpp
|
||||
PrintView.cpp
|
||||
Preview.cpp
|
||||
PreviewOverlayItem.cpp
|
||||
TemplatePicker.cpp
|
||||
TemplatePickerItem.cpp
|
||||
TextNode.cpp
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
/* PageRenderer.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim 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 "PageRenderer.h"
|
||||
|
||||
#include "LabelModel.h"
|
||||
#include "MergeRecord.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
const QColor labelOutlineColor( 0, 0, 0 );
|
||||
const double labelOutlineWidth = 0.25;
|
||||
const double tickOffset = 2.25;
|
||||
const double tickLength = 18;
|
||||
}
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
PageRenderer::PageRenderer()
|
||||
: mModel(0), mNLabels(0), mStartLabel(0),
|
||||
mPrintOutlines(false), mPrintCropMarks(false), mPrintReverse(false),
|
||||
mIPage(0), mNPages(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void PageRenderer::setModel( const LabelModel* model )
|
||||
{
|
||||
mModel = model;
|
||||
mOrigins = mModel->frame()->getOrigins();
|
||||
mNLabelsPerPage = mModel->frame()->nLabels();
|
||||
updateNPages();
|
||||
}
|
||||
|
||||
|
||||
void PageRenderer::setNLabels( int nLabels )
|
||||
{
|
||||
mNLabels = nLabels;
|
||||
updateNPages();
|
||||
}
|
||||
|
||||
|
||||
void PageRenderer::setStartLabel( int startLabel )
|
||||
{
|
||||
mStartLabel = startLabel;
|
||||
updateNPages();
|
||||
}
|
||||
|
||||
|
||||
void PageRenderer::setPrintOutlines( bool printOutlinesFlag )
|
||||
{
|
||||
mPrintOutlines = printOutlinesFlag;
|
||||
}
|
||||
|
||||
|
||||
void PageRenderer::setPrintCropMarks( bool printCropMarksFlag )
|
||||
{
|
||||
mPrintCropMarks = printCropMarksFlag;
|
||||
}
|
||||
|
||||
|
||||
void PageRenderer::setPrintReverse( bool printReverseFlag )
|
||||
{
|
||||
mPrintReverse = printReverseFlag;
|
||||
}
|
||||
|
||||
|
||||
void PageRenderer::setIPage( int iPage )
|
||||
{
|
||||
mIPage = iPage;
|
||||
}
|
||||
|
||||
|
||||
int PageRenderer::nPages() const
|
||||
{
|
||||
return mNPages;
|
||||
}
|
||||
|
||||
|
||||
QRectF PageRenderer::pageRect() const
|
||||
{
|
||||
if ( mModel )
|
||||
{
|
||||
return QRectF( 0, 0, mModel->tmplate()->pageWidth(), mModel->tmplate()->pageHeight() );
|
||||
}
|
||||
else
|
||||
{
|
||||
return QRectF( 0, 0, 0, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PageRenderer::updateNPages()
|
||||
{
|
||||
if ( mModel )
|
||||
{
|
||||
/// @TODO merge case
|
||||
|
||||
int lastLabel = mStartLabel + mNLabels;
|
||||
|
||||
mNPages = lastLabel / mNLabelsPerPage;
|
||||
if ( lastLabel % mNLabelsPerPage )
|
||||
{
|
||||
mNPages++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mNPages = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PageRenderer::printPage( QPainter* painter ) const
|
||||
{
|
||||
if ( mModel )
|
||||
{
|
||||
/// @TODO merge case
|
||||
|
||||
printSimplePage( painter, mIPage );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PageRenderer::printSimplePage( QPainter* painter, int iPage ) const
|
||||
{
|
||||
int iStart = 0;
|
||||
int iEnd = mNLabelsPerPage;
|
||||
|
||||
if ( iPage == 0 )
|
||||
{
|
||||
iStart = mStartLabel;
|
||||
}
|
||||
|
||||
int lastLabel = mStartLabel + mNLabels;
|
||||
if ( (lastLabel / mNLabelsPerPage) == iPage )
|
||||
{
|
||||
iEnd = lastLabel % mNLabelsPerPage;
|
||||
}
|
||||
|
||||
printCropMarks( painter );
|
||||
|
||||
for ( int i = iStart; i < iEnd; i++ )
|
||||
{
|
||||
painter->save();
|
||||
painter->translate( mOrigins[i].x(), mOrigins[i].y() );
|
||||
|
||||
painter->save();
|
||||
clipLabel( painter );
|
||||
|
||||
printLabel( painter, 0 );
|
||||
|
||||
painter->restore(); // From before clip
|
||||
|
||||
printOutline( painter );
|
||||
|
||||
painter->restore(); // From before translation
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PageRenderer::printMergePage( QPainter* painter, int iPage ) const
|
||||
{
|
||||
/// @TODO merge case
|
||||
}
|
||||
|
||||
|
||||
void PageRenderer::printCropMarks( QPainter* painter ) const
|
||||
{
|
||||
if ( mPrintCropMarks )
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PageRenderer::printOutline( QPainter* painter ) const
|
||||
{
|
||||
if ( mPrintOutlines )
|
||||
{
|
||||
painter->save();
|
||||
|
||||
painter->setBrush( QBrush( Qt::NoBrush ) );
|
||||
painter->setPen( QPen( labelOutlineColor, labelOutlineWidth ) );
|
||||
|
||||
painter->drawPath( mModel->frame()->path() );
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PageRenderer::clipLabel( QPainter* painter ) const
|
||||
{
|
||||
// TODO: add clipPath() method to frame
|
||||
}
|
||||
|
||||
|
||||
void PageRenderer::printLabel( QPainter* painter, MergeRecord* record ) const
|
||||
{
|
||||
painter->save();
|
||||
|
||||
if ( mModel->rotate() )
|
||||
{
|
||||
painter->rotate( 90.0 );
|
||||
painter->translate( 0, mModel->h() );
|
||||
}
|
||||
|
||||
if ( mPrintReverse )
|
||||
{
|
||||
painter->translate( mModel->w(), 0 );
|
||||
painter->scale( -1, 1 );
|
||||
}
|
||||
|
||||
mModel->draw( painter, false, record );
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/* PageRenderer.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim 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/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_PageRenderer_h
|
||||
#define glabels_PageRenderer_h
|
||||
|
||||
|
||||
#include "libglabels/Point.h"
|
||||
|
||||
#include <QVector>
|
||||
#include <QRect>
|
||||
|
||||
|
||||
class QPainter; // Forward reference
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
class LabelModel; // Forward reference
|
||||
class MergeRecord; // Forward reference
|
||||
|
||||
|
||||
///
|
||||
/// PageRenderer Widget
|
||||
///
|
||||
class PageRenderer
|
||||
{
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
PageRenderer();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Public Methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void setModel( const LabelModel* model );
|
||||
void setNLabels( int nLabels );
|
||||
void setStartLabel( int startLabel );
|
||||
void setPrintOutlines( bool printOutlinesFlag );
|
||||
void setPrintCropMarks( bool printCropMarksFlag );
|
||||
void setPrintReverse( bool printReverseFlag );
|
||||
void setIPage( int iPage );
|
||||
int nPages() const;
|
||||
QRectF pageRect() const;
|
||||
void printPage( QPainter* painter ) const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Internal Methods
|
||||
/////////////////////////////////
|
||||
private:
|
||||
void updateNPages();
|
||||
void printSimplePage( QPainter* painter, int iPage ) const;
|
||||
void printMergePage( QPainter* painter, int iPage ) const;
|
||||
void printCropMarks( QPainter* painter ) const;
|
||||
void printOutline( QPainter* painter ) const;
|
||||
void clipLabel( QPainter* painter ) const;
|
||||
void printLabel( QPainter* painter, MergeRecord* record ) const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
const LabelModel* mModel;
|
||||
int mNLabels;
|
||||
int mStartLabel;
|
||||
bool mPrintOutlines;
|
||||
bool mPrintCropMarks;
|
||||
bool mPrintReverse;
|
||||
int mIPage;
|
||||
|
||||
int mNPages;
|
||||
int mNLabelsPerPage;
|
||||
|
||||
QVector<libglabels::Point> mOrigins;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_PageRenderer_h
|
||||
+31
-7
@@ -21,6 +21,7 @@
|
||||
#include "Preview.h"
|
||||
|
||||
#include "LabelModel.h"
|
||||
#include "PreviewOverlayItem.h"
|
||||
|
||||
#include <QGraphicsRectItem>
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
@@ -53,7 +54,7 @@ namespace glabels
|
||||
/// Constructor
|
||||
///
|
||||
Preview::Preview( QWidget *parent )
|
||||
: mModel(0), QGraphicsView(parent)
|
||||
: mModel(0), mRenderer(0), QGraphicsView(parent)
|
||||
{
|
||||
mScene = new QGraphicsScene();
|
||||
setScene( mScene );
|
||||
@@ -88,10 +89,20 @@ namespace glabels
|
||||
|
||||
drawPaper( mModel->tmplate()->pageWidth(), mModel->tmplate()->pageHeight() );
|
||||
drawLabels();
|
||||
drawPreviewOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set renderer
|
||||
///
|
||||
void Preview::setRenderer( const PageRenderer* renderer )
|
||||
{
|
||||
mRenderer = renderer;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Resize Event Handler
|
||||
///
|
||||
@@ -157,18 +168,31 @@ namespace glabels
|
||||
///
|
||||
void Preview::drawLabel( double x, double y, const QPainterPath &path )
|
||||
{
|
||||
QBrush brush( labelColor );
|
||||
QBrush brush( Qt::NoBrush );
|
||||
QPen pen( labelOutlineColor );
|
||||
pen.setStyle( Qt::DotLine );
|
||||
pen.setCosmetic( true );
|
||||
pen.setWidthF( labelOutlineWidthPixels );
|
||||
|
||||
QGraphicsPathItem *labelItem = new QGraphicsPathItem( path );
|
||||
labelItem->setBrush( brush );
|
||||
labelItem->setPen( pen );
|
||||
labelItem->setPos( x, y );
|
||||
QGraphicsPathItem *labelOutlineItem = new QGraphicsPathItem( path );
|
||||
labelOutlineItem->setBrush( brush );
|
||||
labelOutlineItem->setPen( pen );
|
||||
labelOutlineItem->setPos( x, y );
|
||||
|
||||
mScene->addItem( labelItem );
|
||||
mScene->addItem( labelOutlineItem );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw Preview Overlay
|
||||
///
|
||||
void Preview::drawPreviewOverlay()
|
||||
{
|
||||
if ( mRenderer )
|
||||
{
|
||||
PreviewOverlayItem* overlayItem = new PreviewOverlayItem( mRenderer );
|
||||
mScene->addItem( overlayItem );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+6
-3
@@ -24,7 +24,7 @@
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsScene>
|
||||
|
||||
#include <QList>
|
||||
#include "PageRenderer.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
@@ -52,6 +52,7 @@ namespace glabels
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void setModel( const LabelModel* model );
|
||||
void setRenderer( const PageRenderer* renderer );
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
@@ -69,14 +70,16 @@ namespace glabels
|
||||
void drawPaper( double pw, double ph );
|
||||
void drawLabels();
|
||||
void drawLabel( double x, double y, const QPainterPath &path );
|
||||
void drawPreviewOverlay();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
const LabelModel* mModel;
|
||||
QGraphicsScene* mScene;
|
||||
const LabelModel* mModel;
|
||||
const PageRenderer* mRenderer;
|
||||
QGraphicsScene* mScene;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/* PreviewOverlayItem.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim 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 "PreviewOverlayItem.h"
|
||||
|
||||
#include "PageRenderer.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
PreviewOverlayItem::PreviewOverlayItem( const PageRenderer* renderer, QGraphicsItem* parent )
|
||||
: QGraphicsItem(parent), mRenderer(renderer)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QRectF PreviewOverlayItem::boundingRect() const
|
||||
{
|
||||
return mRenderer->pageRect();
|
||||
}
|
||||
|
||||
|
||||
void PreviewOverlayItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget )
|
||||
{
|
||||
mRenderer->printPage( painter );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/* PreviewOverlayItem.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim 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/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_PreviewOverlayItem_h
|
||||
#define glabels_PreviewOverlayItem_h
|
||||
|
||||
#include <QGraphicsItem>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
class PageRenderer; // Forward reference
|
||||
|
||||
|
||||
///
|
||||
/// PreviewOverlayItem Widget
|
||||
///
|
||||
class PreviewOverlayItem : public QGraphicsItem
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
PreviewOverlayItem( const PageRenderer* renderer, QGraphicsItem* parent = 0 );
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// Virtual method implementations
|
||||
/////////////////////////////////////
|
||||
public:
|
||||
QRectF boundingRect() const;
|
||||
void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
const PageRenderer* mRenderer;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_PreviewOverlayItem_h
|
||||
@@ -33,6 +33,8 @@ namespace glabels
|
||||
: QWidget(parent)
|
||||
{
|
||||
setupUi( this );
|
||||
|
||||
preview->setRenderer( &mRenderer );
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +44,8 @@ namespace glabels
|
||||
void PrintView::setModel( LabelModel* model )
|
||||
{
|
||||
mModel = model;
|
||||
mRenderer.setModel( model );
|
||||
mRenderer.setNLabels( model->frame()->nLabels() );
|
||||
|
||||
connect( mModel, SIGNAL(sizeChanged()), this, SLOT(onLabelSizeChanged()) );
|
||||
connect( mModel, SIGNAL(changed()), this, SLOT(onLabelChanged()) );
|
||||
@@ -57,6 +61,7 @@ namespace glabels
|
||||
void PrintView::onLabelSizeChanged()
|
||||
{
|
||||
preview->setModel( mModel );
|
||||
mRenderer.setModel( mModel );
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +70,7 @@ namespace glabels
|
||||
///
|
||||
void PrintView::onLabelChanged()
|
||||
{
|
||||
preview->update();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-1
@@ -22,6 +22,7 @@
|
||||
#define glabels_PrintView_h
|
||||
|
||||
#include "ui_PrintView.h"
|
||||
#include "PageRenderer.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
@@ -62,7 +63,8 @@ namespace glabels
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
LabelModel* mModel;
|
||||
LabelModel* mModel;
|
||||
PageRenderer mRenderer;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user