Added unit-independent distance type.
This commit is contained in:
+1
-1
@@ -24,7 +24,7 @@ find_package(Qt4 4.8.4 REQUIRED QtCore QtGui QtXml)
|
||||
find_package(ZLIB REQUIRED)
|
||||
|
||||
|
||||
add_definitions (-g)
|
||||
add_definitions (-std=c++11 -g)
|
||||
|
||||
|
||||
#
|
||||
|
||||
+10
-4
@@ -76,11 +76,15 @@ glabels::Handle::Location glabels::Handle::location() const
|
||||
///
|
||||
/// Draw Handle at x,y
|
||||
///
|
||||
void glabels::Handle::drawAt( QPainter* painter, double scale, double x, double y, QColor color ) const
|
||||
void glabels::Handle::drawAt( QPainter* painter,
|
||||
double scale,
|
||||
const libglabels::Distance& x,
|
||||
const libglabels::Distance& y,
|
||||
QColor color ) const
|
||||
{
|
||||
painter->save();
|
||||
|
||||
painter->translate( x, y );
|
||||
painter->translate( x.pt(), y.pt() );
|
||||
|
||||
double s = 1.0 / scale;
|
||||
|
||||
@@ -100,14 +104,16 @@ void glabels::Handle::drawAt( QPainter* painter, double scale, double x, double
|
||||
///
|
||||
/// Create Handle path at x,y
|
||||
///
|
||||
QPainterPath glabels::Handle::pathAt( double scale, double x, double y ) const
|
||||
QPainterPath glabels::Handle::pathAt( double scale,
|
||||
const libglabels::Distance& x,
|
||||
const libglabels::Distance& y ) const
|
||||
{
|
||||
QPainterPath path;
|
||||
|
||||
double s = 1/scale;
|
||||
|
||||
path.addRect( -s*handlePixels/2, -s*handlePixels/2, s*handlePixels, s*handlePixels );
|
||||
path.translate( x, y );
|
||||
path.translate( x.pt(), y.pt() );
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
+10
-2
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
#include "libglabels/Distance.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
@@ -67,8 +68,15 @@ namespace glabels
|
||||
virtual void draw( QPainter* painter, double scale ) const = 0;
|
||||
virtual QPainterPath path( double scale ) const = 0;
|
||||
protected:
|
||||
void drawAt( QPainter* painter, double scale, double x, double y, QColor color ) const;
|
||||
QPainterPath pathAt( double scale, double x, double y ) const;
|
||||
void drawAt( QPainter* painter,
|
||||
double scale,
|
||||
const libglabels::Distance& x,
|
||||
const libglabels::Distance& y,
|
||||
QColor color ) const;
|
||||
|
||||
QPainterPath pathAt( double scale,
|
||||
const libglabels::Distance& x,
|
||||
const libglabels::Distance& y ) const;
|
||||
|
||||
|
||||
////////////////////////////
|
||||
|
||||
+39
-35
@@ -1,6 +1,6 @@
|
||||
/* LabelModel.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -116,7 +116,9 @@ namespace glabels
|
||||
///
|
||||
/// Object at x,y
|
||||
///
|
||||
LabelModelObject* LabelModel::objectAt( double scale, double x, double y ) const
|
||||
LabelModelObject* LabelModel::objectAt( double scale,
|
||||
const libglabels::Distance& x,
|
||||
const libglabels::Distance& y ) const
|
||||
{
|
||||
/* Search object list in reverse order. I.e. from top to bottom. */
|
||||
QList<LabelModelObject*>::const_iterator it = mObjectList.end();
|
||||
@@ -137,7 +139,9 @@ namespace glabels
|
||||
///
|
||||
/// Handle at x,y
|
||||
///
|
||||
Handle* LabelModel::handleAt( double scale, double x, double y ) const
|
||||
Handle* LabelModel::handleAt( double scale,
|
||||
const libglabels::Distance& x,
|
||||
const libglabels::Distance& y ) const
|
||||
{
|
||||
foreach( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
@@ -234,10 +238,10 @@ namespace glabels
|
||||
using std::min;
|
||||
using std::max;
|
||||
|
||||
double rX1 = min( region.x1(), region.x2() );
|
||||
double rY1 = min( region.y1(), region.y2() );
|
||||
double rX2 = max( region.x1(), region.x2() );
|
||||
double rY2 = max( region.y1(), region.y2() );
|
||||
libglabels::Distance rX1 = min( region.x1(), region.x2() );
|
||||
libglabels::Distance rY1 = min( region.y1(), region.y2() );
|
||||
libglabels::Distance rX2 = max( region.x1(), region.x2() );
|
||||
libglabels::Distance rY2 = max( region.y1(), region.y2() );
|
||||
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
@@ -559,7 +563,7 @@ namespace glabels
|
||||
QList<LabelModelObject*> selectedList = getSelection();
|
||||
|
||||
/// Find left-most edge.
|
||||
double x1_min = 7200; /// Start with a very large value: 7200pts = 100in
|
||||
libglabels::Distance x1_min = 7200; /// Start with a very large value: 7200pts = 100in
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
@@ -570,7 +574,7 @@ namespace glabels
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
double dx = x1_min - r.x1();
|
||||
libglabels::Distance dx = x1_min - r.x1();
|
||||
object->setPositionRelative( dx, 0 );
|
||||
}
|
||||
|
||||
@@ -594,7 +598,7 @@ namespace glabels
|
||||
QList<LabelModelObject*> selectedList = getSelection();
|
||||
|
||||
/// Find right-most edge.
|
||||
double x1_max = -7200; /// Start with a very large negative value: 7200pts = 100in
|
||||
libglabels::Distance x1_max = -7200; /// Start with a very large negative value: 7200pts = 100in
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
@@ -605,7 +609,7 @@ namespace glabels
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
double dx = x1_max - r.x1();
|
||||
libglabels::Distance dx = x1_max - r.x1();
|
||||
object->setPositionRelative( dx, 0 );
|
||||
}
|
||||
|
||||
@@ -629,7 +633,7 @@ namespace glabels
|
||||
QList<LabelModelObject*> selectedList = getSelection();
|
||||
|
||||
/// Find average center of objects.
|
||||
double xsum = 0;
|
||||
libglabels::Distance xsum = 0;
|
||||
int n = 0;
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
@@ -637,15 +641,15 @@ namespace glabels
|
||||
xsum += (r.x1() + r.x2()) / 2.0;
|
||||
n++;
|
||||
}
|
||||
double xavg = xsum / n;
|
||||
libglabels::Distance xavg = xsum / n;
|
||||
|
||||
/// Find object closest to average center of objects.
|
||||
double xcenter = 7200; /// Start with very large value.
|
||||
double dxmin = fabs( xavg - xcenter );
|
||||
libglabels::Distance xcenter = 7200; /// Start with very large value.
|
||||
libglabels::Distance dxmin = fabs( xavg - xcenter );
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
double dx = fabs( xavg - (r.x1() + r.x2())/2.0 );
|
||||
libglabels::Distance dx = fabs( xavg - (r.x1() + r.x2())/2.0 );
|
||||
if ( dx < dxmin )
|
||||
{
|
||||
dxmin = dx;
|
||||
@@ -657,7 +661,7 @@ namespace glabels
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
double dx = xcenter - (r.x1() + r.x2())/2.0;
|
||||
libglabels::Distance dx = xcenter - (r.x1() + r.x2())/2.0;
|
||||
object->setPositionRelative( dx, 0 );
|
||||
}
|
||||
|
||||
@@ -681,7 +685,7 @@ namespace glabels
|
||||
QList<LabelModelObject*> selectedList = getSelection();
|
||||
|
||||
/// Find top-most edge.
|
||||
double y1_min = 7200; /// Start with a very large value: 7200pts = 100in
|
||||
libglabels::Distance y1_min = 7200; /// Start with a very large value: 7200pts = 100in
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
@@ -692,7 +696,7 @@ namespace glabels
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
double dy = y1_min - r.y1();
|
||||
libglabels::Distance dy = y1_min - r.y1();
|
||||
object->setPositionRelative( 0, dy );
|
||||
}
|
||||
|
||||
@@ -716,7 +720,7 @@ namespace glabels
|
||||
QList<LabelModelObject*> selectedList = getSelection();
|
||||
|
||||
/// Find bottom-most edge.
|
||||
double y1_max = -7200; /// Start with a very large negative value: 7200pts = 100in
|
||||
libglabels::Distance y1_max = -7200; /// Start with a very large negative value: 7200pts = 100in
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
@@ -727,7 +731,7 @@ namespace glabels
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
double dy = y1_max - r.y1();
|
||||
libglabels::Distance dy = y1_max - r.y1();
|
||||
object->setPositionRelative( 0, dy );
|
||||
}
|
||||
|
||||
@@ -751,7 +755,7 @@ namespace glabels
|
||||
QList<LabelModelObject*> selectedList = getSelection();
|
||||
|
||||
/// Find average center of objects.
|
||||
double ysum = 0;
|
||||
libglabels::Distance ysum = 0;
|
||||
int n = 0;
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
@@ -759,15 +763,15 @@ namespace glabels
|
||||
ysum += (r.y1() + r.y2()) / 2.0;
|
||||
n++;
|
||||
}
|
||||
double yavg = ysum / n;
|
||||
libglabels::Distance yavg = ysum / n;
|
||||
|
||||
/// Find object closest to average center of objects.
|
||||
double ycenter = 7200; /// Start with very large value.
|
||||
double dymin = fabs( yavg - ycenter );
|
||||
libglabels::Distance ycenter = 7200; /// Start with very large value.
|
||||
libglabels::Distance dymin = fabs( yavg - ycenter );
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
double dy = fabs( yavg - (r.y1() + r.y2())/2.0 );
|
||||
libglabels::Distance dy = fabs( yavg - (r.y1() + r.y2())/2.0 );
|
||||
if ( dy < dymin )
|
||||
{
|
||||
dymin = dy;
|
||||
@@ -779,7 +783,7 @@ namespace glabels
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
double dy = ycenter - (r.y1() + r.y2())/2.0;
|
||||
libglabels::Distance dy = ycenter - (r.y1() + r.y2())/2.0;
|
||||
object->setPositionRelative( 0, dy );
|
||||
}
|
||||
|
||||
@@ -795,15 +799,15 @@ namespace glabels
|
||||
///
|
||||
void LabelModel::centerSelectionHoriz()
|
||||
{
|
||||
double xLabelCenter = w() / 2.0;
|
||||
libglabels::Distance xLabelCenter = w() / 2.0;
|
||||
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
double xObjectCenter = (r.x1() + r.x2()) / 2.0;
|
||||
double dx = xLabelCenter - xObjectCenter;
|
||||
libglabels::Distance xObjectCenter = (r.x1() + r.x2()) / 2.0;
|
||||
libglabels::Distance dx = xLabelCenter - xObjectCenter;
|
||||
object->setPositionRelative( dx, 0 );
|
||||
}
|
||||
}
|
||||
@@ -820,15 +824,15 @@ namespace glabels
|
||||
///
|
||||
void LabelModel::centerSelectionVert()
|
||||
{
|
||||
double yLabelCenter = h() / 2.0;
|
||||
libglabels::Distance yLabelCenter = h() / 2.0;
|
||||
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
double yObjectCenter = (r.y1() + r.y2()) / 2.0;
|
||||
double dy = yLabelCenter - yObjectCenter;
|
||||
libglabels::Distance yObjectCenter = (r.y1() + r.y2()) / 2.0;
|
||||
libglabels::Distance dy = yLabelCenter - yObjectCenter;
|
||||
object->setPositionRelative( 0, dy );
|
||||
}
|
||||
}
|
||||
@@ -843,7 +847,7 @@ namespace glabels
|
||||
///
|
||||
/// Move Selected Objects By dx,dy
|
||||
///
|
||||
void LabelModel::moveSelection( double dx, double dy )
|
||||
void LabelModel::moveSelection( const libglabels::Distance& dx, const libglabels::Distance& dy )
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
@@ -1023,7 +1027,7 @@ namespace glabels
|
||||
///
|
||||
/// Set Line Width Of Selected Objects
|
||||
///
|
||||
void LabelModel::setSelectionLineWidth( double lineWidth )
|
||||
void LabelModel::setSelectionLineWidth( const libglabels::Distance& lineWidth )
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
|
||||
+14
-9
@@ -1,6 +1,6 @@
|
||||
/* LabelModel.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -88,8 +88,8 @@ namespace glabels
|
||||
inline bool rotate() const;
|
||||
inline void setRotate( bool rotate );
|
||||
|
||||
inline double w() const;
|
||||
inline double h() const;
|
||||
inline libglabels::Distance w() const;
|
||||
inline libglabels::Distance h() const;
|
||||
|
||||
inline const QList<LabelModelObject*>& objectList() const;
|
||||
|
||||
@@ -101,8 +101,13 @@ namespace glabels
|
||||
void addObject( LabelModelObject* object );
|
||||
void deleteObject( LabelModelObject* object );
|
||||
|
||||
LabelModelObject* objectAt( double scale, double x, double y ) const;
|
||||
Handle* handleAt( double scale, double x, double y ) const;
|
||||
LabelModelObject* objectAt( double scale,
|
||||
const libglabels::Distance& x,
|
||||
const libglabels::Distance& y ) const;
|
||||
|
||||
Handle* handleAt( double scale,
|
||||
const libglabels::Distance& x,
|
||||
const libglabels::Distance& y ) const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
@@ -156,7 +161,7 @@ namespace glabels
|
||||
void alignSelectionVCenter();
|
||||
void centerSelectionHoriz();
|
||||
void centerSelectionVert();
|
||||
void moveSelection( double dx, double dy );
|
||||
void moveSelection( const libglabels::Distance& dx, const libglabels::Distance& dy );
|
||||
void setSelectionFontFamily( const QString& fontFamily );
|
||||
void setSelectionFontSize( double fontSize );
|
||||
void setSelectionFontWeight( QFont::Weight fontWeight );
|
||||
@@ -165,7 +170,7 @@ namespace glabels
|
||||
void setSelectionTextVAlign( Qt::Alignment textVAlign );
|
||||
void setSelectionTextLineSpacing( double textLineSpacing );
|
||||
void setSelectionTextColorNode( ColorNode textColorNode );
|
||||
void setSelectionLineWidth( double lineWidth );
|
||||
void setSelectionLineWidth( const libglabels::Distance& lineWidth );
|
||||
void setSelectionLineColorNode( ColorNode lineColorNode );
|
||||
void setSelectionFillColorNode( ColorNode fillColorNode );
|
||||
|
||||
@@ -284,13 +289,13 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
inline double LabelModel::w() const
|
||||
inline libglabels::Distance LabelModel::w() const
|
||||
{
|
||||
return mRotate ? mFrame->h() : mFrame->w();
|
||||
}
|
||||
|
||||
|
||||
inline double LabelModel::h() const
|
||||
inline libglabels::Distance LabelModel::h() const
|
||||
{
|
||||
return mRotate ? mFrame->w() : mFrame->h();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* LabelModelBoxObject.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -70,12 +70,15 @@ namespace glabels
|
||||
if ( lineColor.alpha() )
|
||||
{
|
||||
/* Has FILL and OUTLINE: adjust size to account for line width. */
|
||||
painter->drawRect( QRectF( -mLineWidth/2, -mLineWidth/2, mW+mLineWidth, mH+mLineWidth ) );
|
||||
painter->drawRect( QRectF( -mLineWidth.pt()/2,
|
||||
-mLineWidth.pt()/2,
|
||||
(mW + mLineWidth).pt(),
|
||||
(mH + mLineWidth).pt() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Has FILL, but no OUTLINE. */
|
||||
painter->drawRect( QRectF( 0, 0, mW, mH ) );
|
||||
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -83,10 +86,10 @@ namespace glabels
|
||||
if ( lineColor.alpha() )
|
||||
{
|
||||
/* Has only OUTLINE. */
|
||||
painter->setPen( QPen( shadowColor, mLineWidth ) );
|
||||
painter->setPen( QPen( shadowColor, mLineWidth.pt() ) );
|
||||
painter->setBrush( Qt::NoBrush );
|
||||
|
||||
painter->drawRect( QRectF( 0, 0, mW, mH ) );
|
||||
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,10 +106,10 @@ namespace glabels
|
||||
QColor lineColor = mLineColorNode.color();
|
||||
QColor fillColor = mFillColorNode.color();
|
||||
|
||||
painter->setPen( QPen( lineColor, mLineWidth ) );
|
||||
painter->setPen( QPen( lineColor, mLineWidth.pt() ) );
|
||||
painter->setBrush( fillColor );
|
||||
|
||||
painter->drawRect( QRectF( 0, 0, mW, mH ) );
|
||||
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -121,21 +124,26 @@ namespace glabels
|
||||
|
||||
if ( mFillColorNode.color().alpha() && mLineColorNode.color().alpha() )
|
||||
{
|
||||
path.addRect( -mLineWidth/2, -mLineWidth/2, mW+mLineWidth, mH+mLineWidth );
|
||||
path.addRect( -mLineWidth.pt()/2, -mLineWidth.pt()/2, (mW+mLineWidth).pt(), (mH+mLineWidth).pt() );
|
||||
}
|
||||
else if ( mFillColorNode.color().alpha() && !(mLineColorNode.color().alpha()) )
|
||||
{
|
||||
path.addRect( 0, 0, mW, mH );
|
||||
path.addRect( 0, 0, mW.pt(), mH.pt() );
|
||||
}
|
||||
else if ( mLineColorNode.color().alpha() )
|
||||
{
|
||||
path.addRect( (-mLineWidth/2)-s*slopPixels, (-mLineWidth/2)-s*slopPixels,
|
||||
mW+mLineWidth+s*2*slopPixels, mH+mLineWidth+s*2*slopPixels );
|
||||
path.addRect( (-mLineWidth.pt()/2) - s*slopPixels,
|
||||
(-mLineWidth.pt()/2) - s*slopPixels,
|
||||
(mW + mLineWidth).pt() + s*2*slopPixels,
|
||||
(mH + mLineWidth).pt() + s*2*slopPixels );
|
||||
path.closeSubpath();
|
||||
path.addRect( mLineWidth/2+s*slopPixels, mLineWidth/2+s*slopPixels,
|
||||
mW-mLineWidth-s*2*slopPixels, mH-mLineWidth-s*2*slopPixels );
|
||||
path.addRect( mLineWidth.pt()/2 + s*slopPixels,
|
||||
mLineWidth.pt()/2 + s*slopPixels,
|
||||
(mW - mLineWidth).pt() - s*2*slopPixels,
|
||||
(mH - mLineWidth).pt() - s*2*slopPixels );
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* LabelModelBoxObject.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace glabels
|
||||
///
|
||||
/// X0 Property Getter
|
||||
///
|
||||
double LabelModelObject::x0() const
|
||||
libglabels::Distance LabelModelObject::x0() const
|
||||
{
|
||||
return mX0;
|
||||
}
|
||||
@@ -122,7 +122,7 @@ namespace glabels
|
||||
///
|
||||
/// X0 Property Setter
|
||||
///
|
||||
void LabelModelObject::setX0( double value )
|
||||
void LabelModelObject::setX0( const libglabels::Distance& value )
|
||||
{
|
||||
if ( mX0 != value )
|
||||
{
|
||||
@@ -135,7 +135,7 @@ namespace glabels
|
||||
///
|
||||
/// Y0 Property Getter
|
||||
///
|
||||
double LabelModelObject::y0() const
|
||||
libglabels::Distance LabelModelObject::y0() const
|
||||
{
|
||||
return mY0;
|
||||
}
|
||||
@@ -144,7 +144,7 @@ namespace glabels
|
||||
///
|
||||
/// Y0 Property Setter
|
||||
///
|
||||
void LabelModelObject::setY0( double value )
|
||||
void LabelModelObject::setY0( const libglabels::Distance& value )
|
||||
{
|
||||
if ( mY0 != value )
|
||||
{
|
||||
@@ -157,7 +157,7 @@ namespace glabels
|
||||
///
|
||||
/// W (Width) Property Getter
|
||||
///
|
||||
double LabelModelObject::w() const
|
||||
libglabels::Distance LabelModelObject::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
@@ -166,7 +166,7 @@ namespace glabels
|
||||
///
|
||||
/// W (Width) Property Setter
|
||||
///
|
||||
void LabelModelObject::setW( double value )
|
||||
void LabelModelObject::setW( const libglabels::Distance& value )
|
||||
{
|
||||
if ( mW != value )
|
||||
{
|
||||
@@ -179,7 +179,7 @@ namespace glabels
|
||||
///
|
||||
/// H (Height) Property Getter
|
||||
///
|
||||
double LabelModelObject::h() const
|
||||
libglabels::Distance LabelModelObject::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
@@ -188,7 +188,7 @@ namespace glabels
|
||||
///
|
||||
/// H (Height) Property Setter
|
||||
///
|
||||
void LabelModelObject::setH( double value )
|
||||
void LabelModelObject::setH( const libglabels::Distance& value )
|
||||
{
|
||||
if ( mH != value )
|
||||
{
|
||||
@@ -245,7 +245,7 @@ namespace glabels
|
||||
///
|
||||
/// Shadow X Property Getter
|
||||
///
|
||||
double LabelModelObject::shadowX() const
|
||||
libglabels::Distance LabelModelObject::shadowX() const
|
||||
{
|
||||
return mShadowX;
|
||||
}
|
||||
@@ -254,7 +254,7 @@ namespace glabels
|
||||
///
|
||||
/// Shadow X Property Setter
|
||||
///
|
||||
void LabelModelObject::setShadowX( double value )
|
||||
void LabelModelObject::setShadowX( const libglabels::Distance& value )
|
||||
{
|
||||
if ( mShadowX != value )
|
||||
{
|
||||
@@ -267,7 +267,7 @@ namespace glabels
|
||||
///
|
||||
/// Shadow Y Property Getter
|
||||
///
|
||||
double LabelModelObject::shadowY() const
|
||||
libglabels::Distance LabelModelObject::shadowY() const
|
||||
{
|
||||
return mShadowY;
|
||||
}
|
||||
@@ -276,7 +276,7 @@ namespace glabels
|
||||
///
|
||||
/// Shadow Y Property Setter
|
||||
///
|
||||
void LabelModelObject::setShadowY( double value )
|
||||
void LabelModelObject::setShadowY( const libglabels::Distance& value )
|
||||
{
|
||||
if ( mShadowY != value )
|
||||
{
|
||||
@@ -524,7 +524,7 @@ namespace glabels
|
||||
/// Virtual Line Width Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
double LabelModelObject::lineWidth() const
|
||||
libglabels::Distance LabelModelObject::lineWidth() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -534,7 +534,7 @@ namespace glabels
|
||||
/// Virtual Line Width Property Default Setter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
void LabelModelObject::setLineWidth( double value )
|
||||
void LabelModelObject::setLineWidth( const libglabels::Distance& value )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -734,7 +734,8 @@ namespace glabels
|
||||
///
|
||||
/// Set Absolute Position
|
||||
///
|
||||
void LabelModelObject::setPosition( double x0, double y0 )
|
||||
void LabelModelObject::setPosition( const libglabels::Distance& x0,
|
||||
const libglabels::Distance& y0 )
|
||||
{
|
||||
if ( ( mX0 != x0 ) || ( mY0 != y0 ) )
|
||||
{
|
||||
@@ -749,7 +750,8 @@ namespace glabels
|
||||
///
|
||||
/// Set Relative Position
|
||||
///
|
||||
void LabelModelObject::setPositionRelative( double dx, double dy )
|
||||
void LabelModelObject::setPositionRelative( const libglabels::Distance& dx,
|
||||
const libglabels::Distance& dy )
|
||||
{
|
||||
if ( ( dx != 0 ) || ( dy != 0 ) )
|
||||
{
|
||||
@@ -764,7 +766,8 @@ namespace glabels
|
||||
///
|
||||
/// Set Size
|
||||
///
|
||||
void LabelModelObject::setSize( double w, double h )
|
||||
void LabelModelObject::setSize( const libglabels::Distance& w,
|
||||
const libglabels::Distance& h )
|
||||
{
|
||||
mW = w;
|
||||
mH = h;
|
||||
@@ -776,30 +779,33 @@ namespace glabels
|
||||
///
|
||||
/// Set Size (But Maintain Current Aspect Ratio)
|
||||
///
|
||||
void LabelModelObject::setSizeHonorAspect( double w, double h )
|
||||
void LabelModelObject::setSizeHonorAspect( const libglabels::Distance& w,
|
||||
const libglabels::Distance& h )
|
||||
{
|
||||
double aspectRatio = mH / mW;
|
||||
libglabels::Distance wNew = w;
|
||||
libglabels::Distance hNew = h;
|
||||
|
||||
if ( h > (w*aspectRatio) )
|
||||
{
|
||||
h = w*aspectRatio;
|
||||
hNew = w*aspectRatio;
|
||||
}
|
||||
else
|
||||
{
|
||||
w = h/aspectRatio;
|
||||
wNew = h/aspectRatio;
|
||||
}
|
||||
|
||||
setSize( w, h );
|
||||
setSize( wNew, hNew );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set Width (But Maintain Current Aspect Ratio)
|
||||
///
|
||||
void LabelModelObject::setWHonorAspect( double w )
|
||||
void LabelModelObject::setWHonorAspect( const libglabels::Distance& w )
|
||||
{
|
||||
double aspectRatio = mH / mW;
|
||||
double h = w * aspectRatio;
|
||||
libglabels::Distance h = w * aspectRatio;
|
||||
|
||||
if ( ( mW != w ) || ( mH != h ) )
|
||||
{
|
||||
@@ -814,10 +820,10 @@ namespace glabels
|
||||
///
|
||||
/// Set Height (But Maintain Current Aspect Ratio)
|
||||
///
|
||||
void LabelModelObject::setHHonorAspect( double h )
|
||||
void LabelModelObject::setHHonorAspect( const libglabels::Distance& h )
|
||||
{
|
||||
double aspectRatio = mH / mW;
|
||||
double w = h / aspectRatio;
|
||||
libglabels::Distance w = h / aspectRatio;
|
||||
|
||||
if ( ( mW != w ) || ( mH != h ) )
|
||||
{
|
||||
@@ -837,10 +843,10 @@ namespace glabels
|
||||
using std::min;
|
||||
using std::max;
|
||||
|
||||
QPointF a1( - lineWidth()/2, - lineWidth()/2 );
|
||||
QPointF a2( mW + lineWidth()/2, - lineWidth()/2 );
|
||||
QPointF a3( mW + lineWidth()/2, mH + lineWidth()/2 );
|
||||
QPointF a4( - lineWidth()/2, mH + lineWidth()/2 );
|
||||
QPointF a1( ( - lineWidth()/2).pt(), ( - lineWidth()/2).pt() );
|
||||
QPointF a2( (mW + lineWidth()/2).pt(), ( - lineWidth()/2).pt() );
|
||||
QPointF a3( (mW + lineWidth()/2).pt(), (mH + lineWidth()/2).pt() );
|
||||
QPointF a4( ( - lineWidth()/2).pt(), (mH + lineWidth()/2).pt() );
|
||||
|
||||
a1 = mMatrix.map( a1 );
|
||||
a2 = mMatrix.map( a2 );
|
||||
@@ -848,10 +854,10 @@ namespace glabels
|
||||
a4 = mMatrix.map( a4 );
|
||||
|
||||
LabelRegion region;
|
||||
region.setX1( min( a1.x(), min( a2.x(), min( a3.x(), a4.x() ) ) ) + mX0 );
|
||||
region.setY1( min( a1.y(), min( a2.y(), min( a3.y(), a4.y() ) ) ) + mY0 );
|
||||
region.setX2( max( a1.x(), max( a2.x(), max( a3.x(), a4.x() ) ) ) + mX0 );
|
||||
region.setY2( max( a1.y(), max( a2.y(), max( a3.y(), a4.y() ) ) ) + mY0 );
|
||||
region.setX1( libglabels::Distance(min( a1.x(), min( a2.x(), min( a3.x(), a4.x() ) ) )) + mX0 );
|
||||
region.setY1( libglabels::Distance(min( a1.y(), min( a2.y(), min( a3.y(), a4.y() ) ) )) + mY0 );
|
||||
region.setX2( libglabels::Distance(max( a1.x(), max( a2.x(), max( a3.x(), a4.x() ) ) )) + mX0 );
|
||||
region.setY2( libglabels::Distance(max( a1.y(), max( a2.y(), max( a3.y(), a4.y() ) ) )) + mY0 );
|
||||
|
||||
return region;
|
||||
}
|
||||
@@ -902,14 +908,16 @@ namespace glabels
|
||||
///
|
||||
/// Is this object located at x,y?
|
||||
///
|
||||
bool LabelModelObject::isLocatedAt( double scale, double x, double y ) const
|
||||
bool LabelModelObject::isLocatedAt( double scale,
|
||||
const libglabels::Distance& x,
|
||||
const libglabels::Distance& y ) const
|
||||
{
|
||||
QPointF p( x, y );
|
||||
QPointF p( x.pt(), y.pt() );
|
||||
|
||||
/*
|
||||
* Change point to object relative coordinates
|
||||
*/
|
||||
p -= QPointF( mX0, mY0 ); // Translate point to x0,y0
|
||||
p -= QPointF( mX0.pt(), mY0.pt() ); // Translate point to x0,y0
|
||||
p = mMatrix.inverted().map( p );
|
||||
|
||||
if ( hoverPath( scale ).contains( p ) )
|
||||
@@ -931,12 +939,14 @@ namespace glabels
|
||||
///
|
||||
/// Is one of this object's handles locate at x,y? If so, return it.
|
||||
///
|
||||
Handle* LabelModelObject::handleAt( double scale, double x, double y ) const
|
||||
Handle* LabelModelObject::handleAt( double scale,
|
||||
const libglabels::Distance& x,
|
||||
const libglabels::Distance& y ) const
|
||||
{
|
||||
if ( mSelectedFlag )
|
||||
{
|
||||
QPointF p( x, y );
|
||||
p -= QPointF( mX0, mY0 ); // Translate point to x0,y0
|
||||
QPointF p( x.pt(), y.pt() );
|
||||
p -= QPointF( mX0.pt(), mY0.pt() ); // Translate point to x0,y0
|
||||
|
||||
foreach ( Handle* handle, mHandles )
|
||||
{
|
||||
@@ -958,12 +968,12 @@ namespace glabels
|
||||
void LabelModelObject::draw( QPainter* painter, bool inEditor, MergeRecord* record ) const
|
||||
{
|
||||
painter->save();
|
||||
painter->translate( mX0, mY0 );
|
||||
painter->translate( mX0.pt(), mY0.pt() );
|
||||
|
||||
if ( mShadowState )
|
||||
{
|
||||
painter->save();
|
||||
painter->translate( mShadowX, mShadowY );
|
||||
painter->translate( mShadowX.pt(), mShadowY.pt() );
|
||||
painter->setMatrix( mMatrix, true );
|
||||
drawShadow( painter, inEditor, record );
|
||||
painter->restore();
|
||||
@@ -983,7 +993,7 @@ namespace glabels
|
||||
{
|
||||
painter->save();
|
||||
|
||||
painter->translate( mX0, mY0 );
|
||||
painter->translate( mX0.pt(), mY0.pt() );
|
||||
painter->setMatrix( mMatrix, true );
|
||||
|
||||
if ( mOutline )
|
||||
@@ -1000,7 +1010,5 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
+36
-97
@@ -1,6 +1,6 @@
|
||||
/* LabelModelObject.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <QMatrix>
|
||||
#include <QPainter>
|
||||
|
||||
#include "libglabels/Distance.h"
|
||||
#include "ColorNode.h"
|
||||
#include "TextNode.h"
|
||||
#include "BarcodeStyle.h"
|
||||
@@ -70,15 +71,11 @@ namespace glabels
|
||||
//
|
||||
// ID Property.
|
||||
//
|
||||
Q_PROPERTY( int id READ id )
|
||||
|
||||
int id() const;
|
||||
|
||||
//
|
||||
// Selected Property.
|
||||
//
|
||||
Q_PROPERTY( bool selected READ isSelected WRITE select RESET unselect )
|
||||
|
||||
bool isSelected() const;
|
||||
void select( bool value = true );
|
||||
void unselect();
|
||||
@@ -87,44 +84,34 @@ namespace glabels
|
||||
//
|
||||
// x0 Property ( x coordinate of origin )
|
||||
//
|
||||
Q_PROPERTY( double x0 READ x0 WRITE setX0 );
|
||||
|
||||
double x0() const;
|
||||
void setX0( double value );
|
||||
libglabels::Distance x0() const;
|
||||
void setX0( const libglabels::Distance& value );
|
||||
|
||||
|
||||
//
|
||||
// y0 Property ( y coordinate of origin )
|
||||
//
|
||||
Q_PROPERTY( double y0 READ y0 WRITE setY0 );
|
||||
|
||||
double y0() const;
|
||||
void setY0( double value );
|
||||
libglabels::Distance y0() const;
|
||||
void setY0( const libglabels::Distance& value );
|
||||
|
||||
|
||||
//
|
||||
// w Property ( width of bounding box )
|
||||
//
|
||||
Q_PROPERTY( double w READ w WRITE setW );
|
||||
|
||||
double w() const;
|
||||
void setW( double value );
|
||||
libglabels::Distance w() const;
|
||||
void setW( const libglabels::Distance& value );
|
||||
|
||||
|
||||
//
|
||||
// h Property ( height of bounding box )
|
||||
//
|
||||
Q_PROPERTY( double h READ h WRITE setH );
|
||||
|
||||
double h() const;
|
||||
void setH( double value );
|
||||
libglabels::Distance h() const;
|
||||
void setH( const libglabels::Distance& value );
|
||||
|
||||
|
||||
//
|
||||
// Transformation Matrix Property
|
||||
//
|
||||
Q_PROPERTY( QMatrix matrix READ matrix WRITE setMatrix );
|
||||
|
||||
QMatrix matrix() const;
|
||||
void setMatrix( const QMatrix& value );
|
||||
|
||||
@@ -132,8 +119,6 @@ namespace glabels
|
||||
//
|
||||
// Shadow State Property
|
||||
//
|
||||
Q_PROPERTY( bool shadow READ shadow WRITE setShadow );
|
||||
|
||||
bool shadow() const;
|
||||
void setShadow( bool value );
|
||||
|
||||
@@ -141,26 +126,20 @@ namespace glabels
|
||||
//
|
||||
// Shadow x Offset Property
|
||||
//
|
||||
Q_PROPERTY( double shadowX READ shadowX WRITE setShadowX );
|
||||
|
||||
double shadowX() const;
|
||||
void setShadowX( double value );
|
||||
libglabels::Distance shadowX() const;
|
||||
void setShadowX( const libglabels::Distance& value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow y Offset Property
|
||||
//
|
||||
Q_PROPERTY( double shadowY READ shadowY WRITE setShadowY );
|
||||
|
||||
double shadowY() const;
|
||||
void setShadowY( double value );
|
||||
libglabels::Distance shadowY() const;
|
||||
void setShadowY( const libglabels::Distance& value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow opacity Property
|
||||
//
|
||||
Q_PROPERTY( double shadowOpacity READ shadowOpacity WRITE setShadowOpacity );
|
||||
|
||||
double shadowOpacity() const;
|
||||
void setShadowOpacity( double value );
|
||||
|
||||
@@ -168,8 +147,6 @@ namespace glabels
|
||||
//
|
||||
// Shadow Color Property
|
||||
//
|
||||
Q_PROPERTY( ColorNode shadowColorNode READ shadowColorNode WRITE setShadowColorNode );
|
||||
|
||||
ColorNode shadowColorNode() const;
|
||||
void setShadowColorNode( const ColorNode& value );
|
||||
|
||||
@@ -181,8 +158,6 @@ namespace glabels
|
||||
//
|
||||
// Virtual Text Property: fontFamily
|
||||
//
|
||||
Q_PROPERTY( QString fontFamily READ fontFamily WRITE setFontFamily );
|
||||
|
||||
virtual QString fontFamily() const;
|
||||
virtual void setFontFamily( const QString &value );
|
||||
|
||||
@@ -190,8 +165,6 @@ namespace glabels
|
||||
//
|
||||
// Virtual Text Property: fontSize
|
||||
//
|
||||
Q_PROPERTY( double fontSize READ fontSize WRITE setFontSize );
|
||||
|
||||
virtual double fontSize() const;
|
||||
virtual void setFontSize( double value );
|
||||
|
||||
@@ -199,8 +172,6 @@ namespace glabels
|
||||
//
|
||||
// Virtual Text Property: fontWeight
|
||||
//
|
||||
Q_PROPERTY( QFont::Weight fontWeight READ fontWeight WRITE setFontWeight );
|
||||
|
||||
virtual QFont::Weight fontWeight() const;
|
||||
virtual void setFontWeight( QFont::Weight value );
|
||||
|
||||
@@ -208,8 +179,6 @@ namespace glabels
|
||||
//
|
||||
// Virtual Text Property: fontItalicFlag
|
||||
//
|
||||
Q_PROPERTY( bool fontItalicFlag READ fontItalicFlag WRITE setFontItalicFlag );
|
||||
|
||||
virtual bool fontItalicFlag() const;
|
||||
virtual void setFontItalicFlag( bool value );
|
||||
|
||||
@@ -217,8 +186,6 @@ namespace glabels
|
||||
//
|
||||
// Virtual Text Property: fontUnderlineFlag
|
||||
//
|
||||
Q_PROPERTY( bool fontUnderlineFlag READ fontUnderlineFlag WRITE setFontUnderlineFlag );
|
||||
|
||||
virtual bool fontUnderlineFlag() const;
|
||||
virtual void setFontUnderlineFlag( bool value );
|
||||
|
||||
@@ -226,8 +193,6 @@ namespace glabels
|
||||
//
|
||||
// Virtual Text Property: textColorNode
|
||||
//
|
||||
Q_PROPERTY( ColorNode textColorNode READ textColorNode WRITE setTextColorNode );
|
||||
|
||||
virtual ColorNode textColorNode() const;
|
||||
virtual void setTextColorNode( const ColorNode &value );
|
||||
|
||||
@@ -235,8 +200,6 @@ namespace glabels
|
||||
//
|
||||
// Virtual Text Property: textHAlign
|
||||
//
|
||||
Q_PROPERTY( Qt::Alignment textHAlign READ textHAlign WRITE setTextHAlign );
|
||||
|
||||
virtual Qt::Alignment textHAlign() const;
|
||||
virtual void setTextHAlign( Qt::Alignment value );
|
||||
|
||||
@@ -244,8 +207,6 @@ namespace glabels
|
||||
//
|
||||
// Virtual Text Property: textVAlign
|
||||
//
|
||||
Q_PROPERTY( Qt::Alignment textVAlign READ textVAlign WRITE setTextVAlign );
|
||||
|
||||
virtual Qt::Alignment textVAlign() const;
|
||||
virtual void setTextVAlign( Qt::Alignment value );
|
||||
|
||||
@@ -253,8 +214,6 @@ namespace glabels
|
||||
//
|
||||
// Virtual Text Property: textLineSpacing
|
||||
//
|
||||
Q_PROPERTY( double textLineSpacing READ textLineSpacing WRITE setTextLineSpacing );
|
||||
|
||||
virtual double textLineSpacing() const;
|
||||
virtual void setTextLineSpacing( double value );
|
||||
|
||||
@@ -266,8 +225,6 @@ namespace glabels
|
||||
//
|
||||
// Virtual Image Property: filenameNode
|
||||
//
|
||||
Q_PROPERTY( TextNode filenameNode READ filenameNode WRITE setFilenameNode );
|
||||
|
||||
virtual TextNode filenameNode() const;
|
||||
virtual void setFilenameNode( const TextNode &value );
|
||||
|
||||
@@ -279,17 +236,13 @@ namespace glabels
|
||||
//
|
||||
// Virtual Shape Property: lineWidth
|
||||
//
|
||||
Q_PROPERTY( double lineWidth READ lineWidth WRITE setLineWidth );
|
||||
|
||||
virtual double lineWidth() const;
|
||||
virtual void setLineWidth( double value );
|
||||
virtual libglabels::Distance lineWidth() const;
|
||||
virtual void setLineWidth( const libglabels::Distance& value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Shape Property: lineColorNode
|
||||
//
|
||||
Q_PROPERTY( ColorNode lineColorNode READ lineColorNode WRITE setLineColorNode );
|
||||
|
||||
virtual ColorNode lineColorNode() const;
|
||||
virtual void setLineColorNode( const ColorNode &value );
|
||||
|
||||
@@ -297,8 +250,6 @@ namespace glabels
|
||||
//
|
||||
// Virtual Shape Property: fillColorNode
|
||||
//
|
||||
Q_PROPERTY( ColorNode fillColorNode READ fillColorNode WRITE setFillColorNode );
|
||||
|
||||
virtual ColorNode fillColorNode() const;
|
||||
virtual void setFillColorNode( const ColorNode &value );
|
||||
|
||||
@@ -310,8 +261,6 @@ namespace glabels
|
||||
//
|
||||
// Virtual Barcode Property: bcDataNode
|
||||
//
|
||||
Q_PROPERTY( TextNode bcDataNode READ bcDataNode WRITE setBcDataNode );
|
||||
|
||||
virtual TextNode bcDataNode() const;
|
||||
virtual void setBcDataNode( const TextNode &value );
|
||||
|
||||
@@ -319,8 +268,6 @@ namespace glabels
|
||||
//
|
||||
// Virtual Barcode Property: bcTextFlag
|
||||
//
|
||||
Q_PROPERTY( bool bcTextFlag READ bcTextFlag WRITE setBcTextFlag );
|
||||
|
||||
virtual bool bcTextFlag() const;
|
||||
virtual void setBcTextFlag( bool value );
|
||||
|
||||
@@ -328,8 +275,6 @@ namespace glabels
|
||||
//
|
||||
// Virtual Barcode Property: bcChecksumFlag
|
||||
//
|
||||
Q_PROPERTY( bool bcChecksumFlag READ bcChecksumFlag WRITE setBcChecksumFlag );
|
||||
|
||||
virtual bool bcChecksumFlag() const;
|
||||
virtual void setBcChecksumFlag( bool value );
|
||||
|
||||
@@ -337,8 +282,6 @@ namespace glabels
|
||||
//
|
||||
// Virtual Barcode Property: bcColorNode
|
||||
//
|
||||
Q_PROPERTY( ColorNode bcColorNode READ bcColorNode WRITE setBcColorNode );
|
||||
|
||||
virtual ColorNode bcColorNode() const;
|
||||
virtual void setBcColorNode( const ColorNode &value );
|
||||
|
||||
@@ -346,8 +289,6 @@ namespace glabels
|
||||
//
|
||||
// Virtual Barcode Property: bcStyle
|
||||
//
|
||||
Q_PROPERTY( BarcodeStyle bcStyle READ bcStyle WRITE setBcStyle );
|
||||
|
||||
virtual BarcodeStyle bcStyle() const;
|
||||
virtual void setBcStyle( const BarcodeStyle &value );
|
||||
|
||||
@@ -355,8 +296,6 @@ namespace glabels
|
||||
//
|
||||
// Virtual Barcode Property: bcFormatDigits
|
||||
//
|
||||
Q_PROPERTY( int bcFormatDigits READ bcFormatDigits WRITE setBcFormatDigits );
|
||||
|
||||
virtual int bcFormatDigits() const;
|
||||
virtual void setBcFormatDigits( int value );
|
||||
|
||||
@@ -375,18 +314,18 @@ namespace glabels
|
||||
// Position and Size methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
void setPosition( double x0, double y0 );
|
||||
void setPositionRelative( double dx, double dy );
|
||||
void setSize( double w, double h );
|
||||
void setSizeHonorAspect( double w, double h );
|
||||
void setWHonorAspect( double w );
|
||||
void setHHonorAspect( double h );
|
||||
void setPosition( const libglabels::Distance& x0, const libglabels::Distance& y0 );
|
||||
void setPositionRelative( const libglabels::Distance& dx, const libglabels::Distance& dy );
|
||||
void setSize( const libglabels::Distance& w, const libglabels::Distance& h );
|
||||
void setSizeHonorAspect( const libglabels::Distance& w, const libglabels::Distance& h );
|
||||
void setWHonorAspect( const libglabels::Distance& w );
|
||||
void setHHonorAspect( const libglabels::Distance& h );
|
||||
LabelRegion getExtent();
|
||||
void rotate( double thetaDegs );
|
||||
void flipHoriz();
|
||||
void flipVert();
|
||||
bool isLocatedAt( double scale, double x, double y ) const;
|
||||
Handle* handleAt( double scale, double x, double y ) const;
|
||||
bool isLocatedAt( double scale, const libglabels::Distance& x, const libglabels::Distance& y ) const;
|
||||
Handle* handleAt( double scale, const libglabels::Distance& x, const libglabels::Distance& y ) const;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
@@ -406,21 +345,21 @@ namespace glabels
|
||||
// Protected Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
bool mSelectedFlag;
|
||||
bool mSelectedFlag;
|
||||
|
||||
double mX0;
|
||||
double mY0;
|
||||
double mW;
|
||||
double mH;
|
||||
libglabels::Distance mX0;
|
||||
libglabels::Distance mY0;
|
||||
libglabels::Distance mW;
|
||||
libglabels::Distance mH;
|
||||
|
||||
bool mShadowState;
|
||||
double mShadowX;
|
||||
double mShadowY;
|
||||
double mShadowOpacity;
|
||||
ColorNode mShadowColorNode;
|
||||
bool mShadowState;
|
||||
libglabels::Distance mShadowX;
|
||||
libglabels::Distance mShadowY;
|
||||
double mShadowOpacity;
|
||||
ColorNode mShadowColorNode;
|
||||
|
||||
QList<Handle*> mHandles;
|
||||
Outline* mOutline;
|
||||
QList<Handle*> mHandles;
|
||||
Outline* mOutline;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* LabelModelShapeObject.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -67,7 +67,7 @@ namespace glabels
|
||||
///
|
||||
/// Line Width Property Getter
|
||||
///
|
||||
double LabelModelShapeObject::lineWidth( void ) const
|
||||
libglabels::Distance LabelModelShapeObject::lineWidth( void ) const
|
||||
{
|
||||
return mLineWidth;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ namespace glabels
|
||||
///
|
||||
/// Line Width Property Setter
|
||||
///
|
||||
void LabelModelShapeObject::setLineWidth( double value )
|
||||
void LabelModelShapeObject::setLineWidth( const libglabels::Distance& value )
|
||||
{
|
||||
if ( mLineWidth != value )
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* LabelModelShapeObject.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -50,8 +50,8 @@ namespace glabels
|
||||
//
|
||||
// Shape Property: lineWidth
|
||||
//
|
||||
virtual double lineWidth( void ) const;
|
||||
virtual void setLineWidth( double value );
|
||||
virtual libglabels::Distance lineWidth( void ) const;
|
||||
virtual void setLineWidth( const libglabels::Distance& value );
|
||||
|
||||
|
||||
//
|
||||
@@ -81,9 +81,9 @@ namespace glabels
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
double mLineWidth;
|
||||
ColorNode mLineColorNode;
|
||||
ColorNode mFillColorNode;
|
||||
libglabels::Distance mLineWidth;
|
||||
ColorNode mLineColorNode;
|
||||
ColorNode mFillColorNode;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* LabelRegion.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -34,10 +34,10 @@ namespace glabels
|
||||
|
||||
QRectF r;
|
||||
|
||||
r.setX( min( mX1, mX2 ) );
|
||||
r.setY( min( mY1, mY2 ) );
|
||||
r.setWidth( fabs( mX2 - mX1 ) );
|
||||
r.setHeight( fabs( mY2 - mY1 ) );
|
||||
r.setX( min( mX1, mX2 ).pt() );
|
||||
r.setY( min( mY1, mY2 ).pt() );
|
||||
r.setWidth( fabs( mX2 - mX1 ).pt() );
|
||||
r.setHeight( fabs( mY2 - mY1 ).pt() );
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
+21
-20
@@ -22,6 +22,7 @@
|
||||
#define glabels_LabelRegion_h
|
||||
|
||||
#include <QRectF>
|
||||
#include "libglabels/Distance.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
@@ -40,30 +41,30 @@ namespace glabels
|
||||
//
|
||||
// X1 Property
|
||||
//
|
||||
inline double x1( void ) const;
|
||||
inline void setX1( double value );
|
||||
libglabels::Distance x1( void ) const;
|
||||
void setX1( const libglabels::Distance& value );
|
||||
|
||||
|
||||
//
|
||||
// Y1 Property
|
||||
//
|
||||
inline double y1( void ) const;
|
||||
inline void setY1( double value );
|
||||
libglabels::Distance y1( void ) const;
|
||||
void setY1( const libglabels::Distance& value );
|
||||
|
||||
|
||||
//
|
||||
// X2 Property
|
||||
//
|
||||
inline double x2( void ) const;
|
||||
inline void setX2( double value );
|
||||
libglabels::Distance x2( void ) const;
|
||||
void setX2( const libglabels::Distance& value );
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Y2 Property
|
||||
//
|
||||
inline double y2( void ) const;
|
||||
inline void setY2( double value );
|
||||
libglabels::Distance y2( void ) const;
|
||||
void setY2( const libglabels::Distance& value );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
@@ -77,59 +78,59 @@ namespace glabels
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
double mX1;
|
||||
double mY1;
|
||||
double mX2;
|
||||
double mY2;
|
||||
libglabels::Distance mX1;
|
||||
libglabels::Distance mY1;
|
||||
libglabels::Distance mX2;
|
||||
libglabels::Distance mY2;
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// INLINE METHODS
|
||||
/////////////////////////////////
|
||||
double LabelRegion::x1( void ) const
|
||||
inline libglabels::Distance LabelRegion::x1( void ) const
|
||||
{
|
||||
return mX1;
|
||||
}
|
||||
|
||||
|
||||
void LabelRegion::setX1( double value )
|
||||
inline void LabelRegion::setX1( const libglabels::Distance& value )
|
||||
{
|
||||
mX1 = value;
|
||||
}
|
||||
|
||||
|
||||
double LabelRegion::y1( void ) const
|
||||
inline libglabels::Distance LabelRegion::y1( void ) const
|
||||
{
|
||||
return mY1;
|
||||
}
|
||||
|
||||
|
||||
void LabelRegion::setY1( double value )
|
||||
inline void LabelRegion::setY1( const libglabels::Distance& value )
|
||||
{
|
||||
mY1 = value;
|
||||
}
|
||||
|
||||
|
||||
double LabelRegion::x2( void ) const
|
||||
inline libglabels::Distance LabelRegion::x2( void ) const
|
||||
{
|
||||
return mX2;
|
||||
}
|
||||
|
||||
|
||||
void LabelRegion::setX2( double value )
|
||||
inline void LabelRegion::setX2( const libglabels::Distance& value )
|
||||
{
|
||||
mX2 = value;
|
||||
}
|
||||
|
||||
|
||||
double LabelRegion::y2( void ) const
|
||||
inline libglabels::Distance LabelRegion::y2( void ) const
|
||||
{
|
||||
return mY2;
|
||||
}
|
||||
|
||||
|
||||
void LabelRegion::setY2( double value )
|
||||
inline void LabelRegion::setY2( const libglabels::Distance& value )
|
||||
{
|
||||
mY2 = value;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* NewLabelDialog.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -165,7 +165,7 @@ namespace glabels
|
||||
QString pgSizeString = libglabels::Db::lookupPaperNameFromId( tmplate->paperId() );
|
||||
pageSizeLabel->setText( pgSizeString );
|
||||
|
||||
QString labelSizeString = frame->sizeDescription( libglabels::Units::inch() );
|
||||
QString labelSizeString = frame->sizeDescription( libglabels::Distance::Units::IN );
|
||||
labelSizeLabel->setText( labelSizeString );
|
||||
|
||||
QString layoutString = frame->layoutDescription();
|
||||
|
||||
+23
-23
@@ -1,6 +1,6 @@
|
||||
/* ObjectEditor.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -78,7 +78,7 @@ namespace glabels
|
||||
{
|
||||
mBlocked = true;
|
||||
|
||||
lineWidthSpin->setValue( mObject->lineWidth() );
|
||||
lineWidthSpin->setValue( mObject->lineWidth().pt() );
|
||||
lineColorButton->setColorNode( mObject->lineColorNode() );
|
||||
fillColorButton->setColorNode( mObject->fillColorNode() );
|
||||
|
||||
@@ -93,8 +93,8 @@ namespace glabels
|
||||
{
|
||||
mBlocked = true;
|
||||
|
||||
posXSpin->setValue( mObject->x0() );
|
||||
posYSpin->setValue( mObject->y0() );
|
||||
posXSpin->setValue( mObject->x0().in() );
|
||||
posYSpin->setValue( mObject->y0().in() );
|
||||
|
||||
mBlocked = false;
|
||||
}
|
||||
@@ -107,8 +107,8 @@ namespace glabels
|
||||
{
|
||||
mBlocked = true;
|
||||
|
||||
sizeWSpin->setValue( mObject->w() );
|
||||
sizeHSpin->setValue( mObject->h() );
|
||||
sizeWSpin->setValue( mObject->w().in() );
|
||||
sizeHSpin->setValue( mObject->h().in() );
|
||||
|
||||
mBlocked = false;
|
||||
}
|
||||
@@ -122,8 +122,8 @@ namespace glabels
|
||||
mBlocked = true;
|
||||
|
||||
shadowEnableCheck->setChecked( mObject->shadow() );
|
||||
shadowXSpin->setValue( mObject->shadowX() );
|
||||
shadowYSpin->setValue( mObject->shadowY() );
|
||||
shadowXSpin->setValue( mObject->shadowX().in() );
|
||||
shadowYSpin->setValue( mObject->shadowY().in() );
|
||||
shadowColorButton->setColorNode( mObject->shadowColorNode() );
|
||||
shadowOpacitySpin->setValue( 100*mObject->shadowOpacity() );
|
||||
|
||||
@@ -138,12 +138,12 @@ namespace glabels
|
||||
{
|
||||
mBlocked = true;
|
||||
|
||||
double whMax = std::max( mModel->w(), mModel->h() );
|
||||
libglabels::Distance whMax = std::max( mModel->w(), mModel->h() );
|
||||
|
||||
posXSpin->setRange( -whMax, 2*whMax );
|
||||
posYSpin->setRange( -whMax, 2*whMax );
|
||||
sizeWSpin->setRange( 0, 2*whMax );
|
||||
sizeHSpin->setRange( 0, 2*whMax );
|
||||
posXSpin->setRange( -whMax.in(), 2*whMax.in() );
|
||||
posYSpin->setRange( -whMax.in(), 2*whMax.in() );
|
||||
sizeWSpin->setRange( 0, 2*whMax.in() );
|
||||
sizeHSpin->setRange( 0, 2*whMax.in() );
|
||||
|
||||
mBlocked = false;
|
||||
}
|
||||
@@ -236,7 +236,7 @@ namespace glabels
|
||||
{
|
||||
mBlocked = true;
|
||||
|
||||
mObject->setLineWidth( lineWidthSpin->value() );
|
||||
mObject->setLineWidth( libglabels::Distance::pt(lineWidthSpin->value()) );
|
||||
mObject->setLineColorNode( lineColorButton->colorNode() );
|
||||
|
||||
mBlocked = false;
|
||||
@@ -275,26 +275,26 @@ namespace glabels
|
||||
if ( !mBlocked )
|
||||
{
|
||||
mBlocked = true;
|
||||
|
||||
|
||||
libglabels::Distance spinW = libglabels::Distance::in(sizeWSpin->value());
|
||||
libglabels::Distance spinH = libglabels::Distance::in(sizeHSpin->value());
|
||||
|
||||
if ( sizeAspectCheck->isChecked() )
|
||||
{
|
||||
double spinW = sizeWSpin->value();
|
||||
double spinH = sizeHSpin->value();
|
||||
|
||||
if ( fabs(spinW - mObject->w()) > fabs(spinH - mObject->h()) )
|
||||
{
|
||||
mObject->setWHonorAspect( spinW );
|
||||
sizeHSpin->setValue( mObject->h() );
|
||||
sizeHSpin->setValue( mObject->h().in() );
|
||||
}
|
||||
else
|
||||
{
|
||||
mObject->setHHonorAspect( spinH );
|
||||
sizeWSpin->setValue( mObject->w() );
|
||||
sizeWSpin->setValue( mObject->w().in() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mObject->setSize( sizeWSpin->value(), sizeHSpin->value() );
|
||||
mObject->setSize( spinW, spinH );
|
||||
}
|
||||
|
||||
mBlocked = false;
|
||||
@@ -309,8 +309,8 @@ namespace glabels
|
||||
mBlocked = true;
|
||||
|
||||
mObject->setShadow( shadowEnableCheck->isChecked() );
|
||||
mObject->setShadowX( shadowXSpin->value() );
|
||||
mObject->setShadowY( shadowYSpin->value() );
|
||||
mObject->setShadowX( libglabels::Distance::in(shadowXSpin->value()) );
|
||||
mObject->setShadowY( libglabels::Distance::in(shadowYSpin->value()) );
|
||||
mObject->setShadowColorNode( shadowColorButton->colorNode() );
|
||||
mObject->setShadowOpacity( shadowOpacitySpin->value()/100.0 );
|
||||
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
/* Outline.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -78,10 +78,10 @@ void glabels::Outline::draw( QPainter* painter ) const
|
||||
painter->setBrush( Qt::NoBrush );
|
||||
|
||||
painter->setPen( mPen1 );
|
||||
painter->drawRect( QRectF( 0, 0, mOwner->w(), mOwner->h() ) );
|
||||
painter->drawRect( QRectF( 0, 0, mOwner->w().pt(), mOwner->h().pt() ) );
|
||||
|
||||
painter->setPen( mPen2 );
|
||||
painter->drawRect( QRectF( 0, 0, mOwner->w(), mOwner->h() ) );
|
||||
painter->drawRect( QRectF( 0, 0, mOwner->w().pt(), mOwner->h().pt() ) );
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
@@ -97,10 +97,10 @@ QPainterPath glabels::Outline::hoverPath( double scale ) const
|
||||
QPainterPath path;
|
||||
|
||||
path.addRect( -s*slopPixels, -s*slopPixels,
|
||||
mOwner->w()+s*2*slopPixels, mOwner->h()+s*2*slopPixels );
|
||||
mOwner->w().pt()+s*2*slopPixels, mOwner->h().pt()+s*2*slopPixels );
|
||||
path.closeSubpath();
|
||||
path.addRect( s*slopPixels, s*slopPixels,
|
||||
mOwner->w()-s*2*slopPixels, mOwner->h()-s*2*slopPixels );
|
||||
mOwner->w().pt()-s*2*slopPixels, mOwner->h().pt()-s*2*slopPixels );
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/* Outline.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* PageRenderer.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2014 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -104,7 +104,7 @@ namespace glabels
|
||||
{
|
||||
if ( mModel )
|
||||
{
|
||||
return QRectF( 0, 0, mModel->tmplate()->pageWidth(), mModel->tmplate()->pageHeight() );
|
||||
return QRectF( 0, 0, mModel->tmplate()->pageWidth().pt(), mModel->tmplate()->pageHeight().pt() );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -178,7 +178,7 @@ namespace glabels
|
||||
for ( int i = iStart; i < iEnd; i++ )
|
||||
{
|
||||
painter->save();
|
||||
painter->translate( mOrigins[i].x(), mOrigins[i].y() );
|
||||
painter->translate( mOrigins[i].x().pt(), mOrigins[i].y().pt() );
|
||||
|
||||
painter->save();
|
||||
clipLabel( painter );
|
||||
@@ -238,12 +238,12 @@ namespace glabels
|
||||
if ( mModel->rotate() )
|
||||
{
|
||||
painter->rotate( 90.0 );
|
||||
painter->translate( 0, mModel->h() );
|
||||
painter->translate( 0, mModel->h().pt() );
|
||||
}
|
||||
|
||||
if ( mPrintReverse )
|
||||
{
|
||||
painter->translate( mModel->w(), 0 );
|
||||
painter->translate( mModel->w().pt(), 0 );
|
||||
painter->scale( -1, 1 );
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* PageRenderer.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
|
||||
+12
-10
@@ -1,6 +1,6 @@
|
||||
/* Preview.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -79,12 +79,12 @@ namespace glabels
|
||||
if ( mModel != NULL )
|
||||
{
|
||||
// Set scene up with a 5% margin around paper
|
||||
double x = -0.05 * mModel->tmplate()->pageWidth();
|
||||
double y = -0.05 * mModel->tmplate()->pageHeight();
|
||||
double w = 1.10 * mModel->tmplate()->pageWidth();
|
||||
double h = 1.10 * mModel->tmplate()->pageHeight();
|
||||
libglabels::Distance x = -0.05 * mModel->tmplate()->pageWidth();
|
||||
libglabels::Distance y = -0.05 * mModel->tmplate()->pageHeight();
|
||||
libglabels::Distance w = 1.10 * mModel->tmplate()->pageWidth();
|
||||
libglabels::Distance h = 1.10 * mModel->tmplate()->pageHeight();
|
||||
|
||||
mScene->setSceneRect( x, y, w, h );
|
||||
mScene->setSceneRect( x.pt(), y.pt(), w.pt(), h.pt() );
|
||||
fitInView( mScene->sceneRect(), Qt::KeepAspectRatio );
|
||||
|
||||
drawPaper( mModel->tmplate()->pageWidth(), mModel->tmplate()->pageHeight() );
|
||||
@@ -128,7 +128,7 @@ namespace glabels
|
||||
///
|
||||
/// Draw Paper
|
||||
///
|
||||
void Preview::drawPaper( double pw, double ph )
|
||||
void Preview::drawPaper( const libglabels::Distance& pw, const libglabels::Distance& ph )
|
||||
{
|
||||
QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect();
|
||||
shadowEffect->setColor( shadowColor );
|
||||
@@ -140,7 +140,7 @@ namespace glabels
|
||||
pen.setCosmetic( true );
|
||||
pen.setWidthF( paperOutlineWidthPixels );
|
||||
|
||||
QGraphicsRectItem *pageItem = new QGraphicsRectItem( 0, 0, pw, ph );
|
||||
QGraphicsRectItem *pageItem = new QGraphicsRectItem( 0, 0, pw.pt(), ph.pt() );
|
||||
pageItem->setBrush( brush );
|
||||
pageItem->setPen( pen );
|
||||
pageItem->setGraphicsEffect( shadowEffect );
|
||||
@@ -166,7 +166,9 @@ namespace glabels
|
||||
///
|
||||
/// Draw a Single Label at x,y
|
||||
///
|
||||
void Preview::drawLabel( double x, double y, const QPainterPath &path )
|
||||
void Preview::drawLabel( const libglabels::Distance& x,
|
||||
const libglabels::Distance& y,
|
||||
const QPainterPath& path )
|
||||
{
|
||||
QBrush brush( Qt::NoBrush );
|
||||
QPen pen( labelOutlineColor );
|
||||
@@ -177,7 +179,7 @@ namespace glabels
|
||||
QGraphicsPathItem *labelOutlineItem = new QGraphicsPathItem( path );
|
||||
labelOutlineItem->setBrush( brush );
|
||||
labelOutlineItem->setPen( pen );
|
||||
labelOutlineItem->setPos( x, y );
|
||||
labelOutlineItem->setPos( x.pt(), y.pt() );
|
||||
|
||||
mScene->addItem( labelOutlineItem );
|
||||
}
|
||||
|
||||
+6
-3
@@ -1,6 +1,6 @@
|
||||
/* Preview.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -67,9 +67,12 @@ namespace glabels
|
||||
/////////////////////////////////
|
||||
private:
|
||||
void clearScene();
|
||||
void drawPaper( double pw, double ph );
|
||||
void drawPaper( const libglabels::Distance& pw, const libglabels::Distance& ph );
|
||||
void drawLabels();
|
||||
void drawLabel( double x, double y, const QPainterPath &path );
|
||||
void drawLabel( const libglabels::Distance& x,
|
||||
const libglabels::Distance& y,
|
||||
const QPainterPath& path );
|
||||
|
||||
void drawPreviewOverlay();
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* PrintView.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -138,7 +138,7 @@ namespace glabels
|
||||
///
|
||||
void PrintView::onPrintButtonClicked()
|
||||
{
|
||||
QSizeF pageSize( mModel->tmplate()->pageWidth(), mModel->tmplate()->pageHeight() );
|
||||
QSizeF pageSize( mModel->tmplate()->pageWidth().pt(), mModel->tmplate()->pageHeight().pt() );
|
||||
mPrinter->setPaperSize( pageSize, QPrinter::Point );
|
||||
mPrinter->setFullPage( true );
|
||||
mPrinter->setPageMargins( 0, 0, 0, 0, QPrinter::Point );
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/* PrintView.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
|
||||
+28
-26
@@ -1,6 +1,6 @@
|
||||
/* SimplePreview.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -110,12 +110,12 @@ namespace glabels
|
||||
if ( mTmplate != NULL )
|
||||
{
|
||||
// Set scene up with a 5% margin around paper
|
||||
double x = -0.05 * mTmplate->pageWidth();
|
||||
double y = -0.05 * mTmplate->pageHeight();
|
||||
double w = 1.10 * mTmplate->pageWidth();
|
||||
double h = 1.10 * mTmplate->pageHeight();
|
||||
libglabels::Distance x = -0.05 * mTmplate->pageWidth();
|
||||
libglabels::Distance y = -0.05 * mTmplate->pageHeight();
|
||||
libglabels::Distance w = 1.10 * mTmplate->pageWidth();
|
||||
libglabels::Distance h = 1.10 * mTmplate->pageHeight();
|
||||
|
||||
mScene->setSceneRect( x, y, w, h );
|
||||
mScene->setSceneRect( x.pt(), y.pt(), w.pt(), h.pt() );
|
||||
fitInView( mScene->sceneRect(), Qt::KeepAspectRatio );
|
||||
|
||||
drawPaper( mTmplate->pageWidth(), mTmplate->pageHeight() );
|
||||
@@ -141,7 +141,7 @@ namespace glabels
|
||||
///
|
||||
/// Draw Paper
|
||||
///
|
||||
void SimplePreview::drawPaper( double pw, double ph )
|
||||
void SimplePreview::drawPaper( const libglabels::Distance& pw, const libglabels::Distance& ph )
|
||||
{
|
||||
QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect();
|
||||
shadowEffect->setColor( shadowColor );
|
||||
@@ -153,7 +153,7 @@ namespace glabels
|
||||
pen.setCosmetic( true );
|
||||
pen.setWidthF( paperOutlineWidthPixels );
|
||||
|
||||
QGraphicsRectItem *pageItem = new QGraphicsRectItem( 0, 0, pw, ph );
|
||||
QGraphicsRectItem *pageItem = new QGraphicsRectItem( 0, 0, pw.pt(), ph.pt() );
|
||||
pageItem->setBrush( brush );
|
||||
pageItem->setPen( pen );
|
||||
pageItem->setGraphicsEffect( shadowEffect );
|
||||
@@ -179,7 +179,9 @@ namespace glabels
|
||||
///
|
||||
/// Draw a Single Label at x,y
|
||||
///
|
||||
void SimplePreview::drawLabel( double x, double y, const QPainterPath &path )
|
||||
void SimplePreview::drawLabel( const libglabels::Distance& x,
|
||||
const libglabels::Distance& y,
|
||||
const QPainterPath& path )
|
||||
{
|
||||
QBrush brush( labelColor );
|
||||
QPen pen( labelOutlineColor );
|
||||
@@ -189,7 +191,7 @@ namespace glabels
|
||||
QGraphicsPathItem *labelItem = new QGraphicsPathItem( path );
|
||||
labelItem->setBrush( brush );
|
||||
labelItem->setPen( pen );
|
||||
labelItem->setPos( x, y );
|
||||
labelItem->setPos( x.pt(), y.pt() );
|
||||
|
||||
mScene->addItem( labelItem );
|
||||
}
|
||||
@@ -202,32 +204,32 @@ namespace glabels
|
||||
{
|
||||
libglabels::Frame *frame = mTmplate->frames().first();
|
||||
|
||||
double w = frame->w();
|
||||
double h = frame->h();
|
||||
libglabels::Distance w = frame->w();
|
||||
libglabels::Distance h = frame->h();
|
||||
|
||||
double min = ( w < h ) ? w : h;
|
||||
libglabels::Distance min = libglabels::min( w, h );
|
||||
|
||||
QPen pen( arrowColor );
|
||||
pen.setWidthF( 0.25*min*arrowScale );
|
||||
pen.setWidthF( 0.25*min.pt()*arrowScale );
|
||||
pen.setCapStyle( Qt::FlatCap );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
|
||||
QBrush brush( upColor );
|
||||
|
||||
libglabels::Point origin = frame->getOrigins().first();
|
||||
double x0 = origin.x();
|
||||
double y0 = origin.y();
|
||||
libglabels::Distance x0 = origin.x();
|
||||
libglabels::Distance y0 = origin.y();
|
||||
|
||||
QPainterPath path;
|
||||
path.moveTo( 0, min*arrowScale/3 );
|
||||
path.lineTo( 0, -min*arrowScale );
|
||||
path.moveTo( -min*arrowScale/2, -min*arrowScale/2 );
|
||||
path.lineTo( 0, -min*arrowScale );
|
||||
path.lineTo( min*arrowScale/2, -min*arrowScale/2 );
|
||||
path.moveTo( 0, min.pt()*arrowScale/3 );
|
||||
path.lineTo( 0, -min.pt()*arrowScale );
|
||||
path.moveTo( -min.pt()*arrowScale/2, -min.pt()*arrowScale/2 );
|
||||
path.lineTo( 0, -min.pt()*arrowScale );
|
||||
path.lineTo( min.pt()*arrowScale/2, -min.pt()*arrowScale/2 );
|
||||
|
||||
QGraphicsPathItem *arrowItem = new QGraphicsPathItem( path );
|
||||
arrowItem->setPen( pen );
|
||||
arrowItem->setPos( x0+w/2, y0+h/2 );
|
||||
arrowItem->setPos( (x0+w/2).pt(), (y0+h/2).pt() );
|
||||
if ( mRotateFlag )
|
||||
{
|
||||
arrowItem->setRotation( 90 );
|
||||
@@ -235,17 +237,17 @@ namespace glabels
|
||||
|
||||
QGraphicsSimpleTextItem *upItem = new QGraphicsSimpleTextItem( tr("Up") );
|
||||
upItem->setBrush( brush );
|
||||
upItem->setFont( QFont( upFontFamily, min*upScale, QFont::Bold ) );
|
||||
upItem->setPos( x0+w/2, y0+h/2 );
|
||||
upItem->setFont( QFont( upFontFamily, min.pt()*upScale, QFont::Bold ) );
|
||||
upItem->setPos( (x0+w/2).pt(), (y0+h/2).pt() );
|
||||
QRectF rect = upItem->boundingRect();
|
||||
if ( mRotateFlag )
|
||||
{
|
||||
upItem->setPos( upItem->x()-min/8, upItem->y()-rect.width()/2 );
|
||||
upItem->setPos( upItem->x()-min.pt()/8, upItem->y()-rect.width()/2 );
|
||||
upItem->setRotation( 90 );
|
||||
}
|
||||
else
|
||||
{
|
||||
upItem->setPos( upItem->x()-rect.width()/2, upItem->y()+min/8 );
|
||||
upItem->setPos( upItem->x()-rect.width()/2, upItem->y()+min.pt()/8 );
|
||||
}
|
||||
|
||||
mScene->addItem( arrowItem );
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* SimplePreview.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -68,9 +68,11 @@ namespace glabels
|
||||
private:
|
||||
void update();
|
||||
void clearScene();
|
||||
void drawPaper( double pw, double ph );
|
||||
void drawPaper( const libglabels::Distance& pw, const libglabels::Distance& ph );
|
||||
void drawLabels();
|
||||
void drawLabel( double x, double y, const QPainterPath &path );
|
||||
void drawLabel( const libglabels::Distance& x,
|
||||
const libglabels::Distance& y,
|
||||
const QPainterPath& path );
|
||||
void drawArrow();
|
||||
|
||||
|
||||
|
||||
+49
-43
@@ -1,6 +1,6 @@
|
||||
/* View.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -59,7 +59,7 @@ namespace
|
||||
|
||||
const QColor gridLineColor( 192, 192, 192 );
|
||||
const double gridLineWidthPixels = 1;
|
||||
const double gridSpacing = 9; // TODO: determine from locale.
|
||||
const libglabels::Distance gridSpacing = libglabels::Distance::pt(9); // TODO: determine from locale.
|
||||
|
||||
const QColor markupLineColor( 240, 99, 99 );
|
||||
const double markupLineWidthPixels = 1;
|
||||
@@ -235,8 +235,8 @@ glabels::View::zoomToFit()
|
||||
double wPixels = mScrollArea->maximumViewportSize().width();
|
||||
double hPixels = mScrollArea->maximumViewportSize().height();
|
||||
|
||||
double x_scale = ( wPixels - ZOOM_TO_FIT_PAD ) / mModel->w();
|
||||
double y_scale = ( hPixels - ZOOM_TO_FIT_PAD ) / mModel->h();
|
||||
double x_scale = ( wPixels - ZOOM_TO_FIT_PAD ) / mModel->w().pt();
|
||||
double y_scale = ( hPixels - ZOOM_TO_FIT_PAD ) / mModel->h().pt();
|
||||
double newZoom = min( x_scale, y_scale ) * PTS_PER_INCH / physicalDpiX();
|
||||
|
||||
// Limits
|
||||
@@ -279,7 +279,8 @@ glabels::View::setZoomReal( double zoom, bool zoomToFitFlag )
|
||||
/* Actual scale depends on DPI of display (assume DpiX == DpiY). */
|
||||
mScale = zoom * physicalDpiX() / PTS_PER_INCH;
|
||||
|
||||
setMinimumSize( mScale*mModel->w() + ZOOM_TO_FIT_PAD, mScale*mModel->h() + ZOOM_TO_FIT_PAD );
|
||||
setMinimumSize( mScale*mModel->w().pt() + ZOOM_TO_FIT_PAD,
|
||||
mScale*mModel->h().pt() + ZOOM_TO_FIT_PAD );
|
||||
|
||||
/* Adjust origin to center label in widget. */
|
||||
mX0 = (width()/mScale - mModel->w()) / 2;
|
||||
@@ -354,11 +355,11 @@ glabels::View::mousePressEvent( QMouseEvent* event )
|
||||
QTransform transform;
|
||||
|
||||
transform.scale( mScale, mScale );
|
||||
transform.translate( mX0, mY0 );
|
||||
transform.translate( mX0.pt(), mY0.pt() );
|
||||
|
||||
QPointF pWorld = transform.inverted().map( event->posF() );
|
||||
double xWorld = pWorld.x();
|
||||
double yWorld = pWorld.y();
|
||||
libglabels::Distance xWorld = libglabels::Distance::pt( pWorld.x() );
|
||||
libglabels::Distance yWorld = libglabels::Distance::pt( pWorld.y() );
|
||||
|
||||
|
||||
if ( event->button() & Qt::LeftButton )
|
||||
@@ -523,11 +524,11 @@ glabels::View::mouseMoveEvent( QMouseEvent* event )
|
||||
QTransform transform;
|
||||
|
||||
transform.scale( mScale, mScale );
|
||||
transform.translate( mX0, mY0 );
|
||||
transform.translate( mX0.pt(), mY0.pt() );
|
||||
|
||||
QPointF pWorld = transform.inverted().map( event->posF() );
|
||||
double xWorld = pWorld.x();
|
||||
double yWorld = pWorld.y();
|
||||
libglabels::Distance xWorld = libglabels::Distance::pt( pWorld.x() );
|
||||
libglabels::Distance yWorld = libglabels::Distance::pt( pWorld.y() );
|
||||
|
||||
|
||||
/*
|
||||
@@ -624,11 +625,11 @@ glabels::View::mouseReleaseEvent( QMouseEvent* event )
|
||||
QTransform transform;
|
||||
|
||||
transform.scale( mScale, mScale );
|
||||
transform.translate( mX0, mY0 );
|
||||
transform.translate( mX0.pt(), mY0.pt() );
|
||||
|
||||
QPointF pWorld = transform.inverted().map( event->posF() );
|
||||
double xWorld = pWorld.x();
|
||||
double yWorld = pWorld.y();
|
||||
libglabels::Distance xWorld = libglabels::Distance::pt( pWorld.x() );
|
||||
libglabels::Distance yWorld = libglabels::Distance::pt( pWorld.y() );
|
||||
|
||||
|
||||
if ( event->button() & Qt::LeftButton )
|
||||
@@ -703,15 +704,16 @@ glabels::View::leaveEvent( QEvent* event )
|
||||
/// Handle resize motion
|
||||
///
|
||||
void
|
||||
glabels::View::handleResizeMotion( double xWorld, double yWorld )
|
||||
glabels::View::handleResizeMotion( const libglabels::Distance& xWorld,
|
||||
const libglabels::Distance& yWorld )
|
||||
{
|
||||
QPointF p( xWorld, yWorld );
|
||||
QPointF p( xWorld.pt(), yWorld.pt() );
|
||||
Handle::Location location = mResizeHandle->location();
|
||||
|
||||
/*
|
||||
* Change point to object relative coordinates
|
||||
*/
|
||||
p -= QPointF( mResizeObject->x0(), mResizeObject->y0() );
|
||||
p -= QPointF( mResizeObject->x0().pt(), mResizeObject->y0().pt() );
|
||||
p = mResizeObject->matrix().inverted().map( p );
|
||||
|
||||
/*
|
||||
@@ -723,8 +725,8 @@ glabels::View::handleResizeMotion( double xWorld, double yWorld )
|
||||
double x1 = 0.0;
|
||||
double y1 = 0.0;
|
||||
|
||||
double x2 = mResizeObject->w();
|
||||
double y2 = mResizeObject->h();
|
||||
double x2 = mResizeObject->w().pt();
|
||||
double y2 = mResizeObject->h().pt();
|
||||
|
||||
/*
|
||||
* Calculate new size
|
||||
@@ -793,20 +795,22 @@ glabels::View::handleResizeMotion( double xWorld, double yWorld )
|
||||
{
|
||||
case Handle::E:
|
||||
case Handle::W:
|
||||
mResizeObject->setWHonorAspect( w );
|
||||
mResizeObject->setWHonorAspect( libglabels::Distance::pt(w) );
|
||||
break;
|
||||
case Handle::N:
|
||||
case Handle::S:
|
||||
mResizeObject->setHHonorAspect( h );
|
||||
mResizeObject->setHHonorAspect( libglabels::Distance::pt(h) );
|
||||
break;
|
||||
default:
|
||||
mResizeObject->setSizeHonorAspect( w, h );
|
||||
mResizeObject->setSizeHonorAspect( libglabels::Distance::pt(w),
|
||||
libglabels::Distance::pt(h) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mResizeObject->setSize( w, h );
|
||||
mResizeObject->setSize( libglabels::Distance::pt(w),
|
||||
libglabels::Distance::pt(h) );
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -815,16 +819,16 @@ glabels::View::handleResizeMotion( double xWorld, double yWorld )
|
||||
switch ( location )
|
||||
{
|
||||
case Handle::NW:
|
||||
x0 += x2 - mResizeObject->w();
|
||||
y0 += y2 - mResizeObject->h();
|
||||
x0 += x2 - mResizeObject->w().pt();
|
||||
y0 += y2 - mResizeObject->h().pt();
|
||||
break;
|
||||
case Handle::N:
|
||||
case Handle::NE:
|
||||
y0 += y2 - mResizeObject->h();
|
||||
y0 += y2 - mResizeObject->h().pt();
|
||||
break;
|
||||
case Handle::W:
|
||||
case Handle::SW:
|
||||
x0 += x2 - mResizeObject->w();
|
||||
x0 += x2 - mResizeObject->w().pt();
|
||||
break;
|
||||
defaule:
|
||||
break;
|
||||
@@ -832,7 +836,8 @@ glabels::View::handleResizeMotion( double xWorld, double yWorld )
|
||||
}
|
||||
else
|
||||
{
|
||||
mResizeObject->setSize( w, h );
|
||||
mResizeObject->setSize( libglabels::Distance::pt(w),
|
||||
libglabels::Distance::pt(h) );
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -840,8 +845,9 @@ glabels::View::handleResizeMotion( double xWorld, double yWorld )
|
||||
*/
|
||||
QPointF p0( x0, y0 );
|
||||
p0 = mResizeObject->matrix().map( p0 );
|
||||
p0 += QPointF( mResizeObject->x0(), mResizeObject->y0() );
|
||||
mResizeObject->setPosition( p0.x(), p0.y() );
|
||||
p0 += QPointF( mResizeObject->x0().pt(), mResizeObject->y0().pt() );
|
||||
mResizeObject->setPosition( libglabels::Distance::pt(p0.x()),
|
||||
libglabels::Distance::pt(p0.y()) );
|
||||
}
|
||||
|
||||
|
||||
@@ -866,7 +872,7 @@ glabels::View::paintEvent( QPaintEvent* event )
|
||||
|
||||
/* Transform. */
|
||||
painter.scale( mScale, mScale );
|
||||
painter.translate( mX0, mY0 );
|
||||
painter.translate( mX0.pt(), mY0.pt() );
|
||||
|
||||
/* Now draw from the bottom layer up. */
|
||||
drawBgLayer( &painter );
|
||||
@@ -899,7 +905,7 @@ glabels::View::drawBgLayer( QPainter* painter )
|
||||
if ( mModel->rotate() )
|
||||
{
|
||||
painter->rotate( -90 );
|
||||
painter->translate( -mModel->frame()->w(), 0 );
|
||||
painter->translate( -mModel->frame()->w().pt(), 0 );
|
||||
}
|
||||
painter->drawPath( mModel->frame()->path() );
|
||||
|
||||
@@ -917,7 +923,7 @@ glabels::View::drawBgLayer( QPainter* painter )
|
||||
if ( mModel->rotate() )
|
||||
{
|
||||
painter->rotate( -90 );
|
||||
painter->translate( -mModel->frame()->w(), 0 );
|
||||
painter->translate( -mModel->frame()->w().pt(), 0 );
|
||||
}
|
||||
painter->drawPath( mModel->frame()->path() );
|
||||
|
||||
@@ -933,10 +939,10 @@ glabels::View::drawGridLayer( QPainter* painter )
|
||||
{
|
||||
if ( mGridVisible )
|
||||
{
|
||||
double w = mModel->frame()->w();
|
||||
double h = mModel->frame()->h();
|
||||
libglabels::Distance w = mModel->frame()->w();
|
||||
libglabels::Distance h = mModel->frame()->h();
|
||||
|
||||
double x0, y0;
|
||||
libglabels::Distance x0, y0;
|
||||
if ( dynamic_cast<const libglabels::FrameRect*>( mModel->frame() ) )
|
||||
{
|
||||
x0 = gridSpacing;
|
||||
@@ -953,7 +959,7 @@ glabels::View::drawGridLayer( QPainter* painter )
|
||||
if ( mModel->rotate() )
|
||||
{
|
||||
painter->rotate( -90 );
|
||||
painter->translate( -mModel->frame()->w(), 0 );
|
||||
painter->translate( -mModel->frame()->w().pt(), 0 );
|
||||
}
|
||||
|
||||
painter->setClipPath( mModel->frame()->path() );
|
||||
@@ -962,14 +968,14 @@ glabels::View::drawGridLayer( QPainter* painter )
|
||||
pen.setCosmetic( true );
|
||||
painter->setPen( pen );
|
||||
|
||||
for ( double x = x0; x < w; x += gridSpacing )
|
||||
for ( libglabels::Distance x = x0; x < w; x += gridSpacing )
|
||||
{
|
||||
painter->drawLine( x, 0, x, h );
|
||||
painter->drawLine( x.pt(), 0, x.pt(), h.pt() );
|
||||
}
|
||||
|
||||
for ( double y = y0; y < h; y += gridSpacing )
|
||||
for ( libglabels::Distance y = y0; y < h; y += gridSpacing )
|
||||
{
|
||||
painter->drawLine( 0, y, w, y );
|
||||
painter->drawLine( 0, y.pt(), w.pt(), y.pt() );
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
@@ -993,7 +999,7 @@ glabels::View::drawMarkupLayer( QPainter* painter )
|
||||
if ( mModel->rotate() )
|
||||
{
|
||||
painter->rotate( -90 );
|
||||
painter->translate( -mModel->frame()->w(), 0 );
|
||||
painter->translate( -mModel->frame()->w().pt(), 0 );
|
||||
}
|
||||
|
||||
foreach( libglabels::Markup* markup, mModel->frame()->markups() )
|
||||
@@ -1035,7 +1041,7 @@ glabels::View::drawFgLayer( QPainter* painter )
|
||||
if ( mModel->rotate() )
|
||||
{
|
||||
painter->rotate( -90 );
|
||||
painter->translate( -mModel->frame()->w(), 0 );
|
||||
painter->translate( -mModel->frame()->w().pt(), 0 );
|
||||
}
|
||||
painter->drawPath( mModel->frame()->path() );
|
||||
|
||||
|
||||
+26
-25
@@ -1,6 +1,6 @@
|
||||
/* View.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -56,7 +56,7 @@ namespace glabels
|
||||
signals:
|
||||
void contextMenuActivate();
|
||||
void zoomChanged();
|
||||
void pointerMoved( double x, double y );
|
||||
void pointerMoved( const libglabels::Distance& x, const libglabels::Distance& y );
|
||||
void pointerExited();
|
||||
void modeChanged();
|
||||
|
||||
@@ -128,7 +128,8 @@ namespace glabels
|
||||
// Private methods
|
||||
/////////////////////////////////////
|
||||
private:
|
||||
void handleResizeMotion( double xWorld, double yWorld );
|
||||
void handleResizeMotion( const libglabels::Distance& xWorld,
|
||||
const libglabels::Distance& yWorld );
|
||||
|
||||
void drawBgLayer( QPainter* painter );
|
||||
void drawGridLayer( QPainter* painter );
|
||||
@@ -169,41 +170,41 @@ namespace glabels
|
||||
Barcode
|
||||
};
|
||||
|
||||
QScrollArea* mScrollArea;
|
||||
QScrollArea* mScrollArea;
|
||||
|
||||
double mZoom;
|
||||
bool mZoomToFitFlag;
|
||||
double mScale;
|
||||
double mX0;
|
||||
double mY0;
|
||||
double mZoom;
|
||||
bool mZoomToFitFlag;
|
||||
double mScale;
|
||||
libglabels::Distance mX0;
|
||||
libglabels::Distance mY0;
|
||||
|
||||
bool mMarkupVisible;
|
||||
bool mGridVisible;
|
||||
bool mMarkupVisible;
|
||||
bool mGridVisible;
|
||||
|
||||
double mGridSpacing;
|
||||
double mGridSpacing;
|
||||
|
||||
LabelModel* mModel;
|
||||
LabelModel* mModel;
|
||||
|
||||
State mState;
|
||||
State mState;
|
||||
|
||||
/* ArrowSelectRegion state */
|
||||
bool mSelectRegionVisible;
|
||||
LabelRegion mSelectRegion;
|
||||
bool mSelectRegionVisible;
|
||||
LabelRegion mSelectRegion;
|
||||
|
||||
/* ArrowMove state */
|
||||
double mMoveLastX;
|
||||
double mMoveLastY;
|
||||
libglabels::Distance mMoveLastX;
|
||||
libglabels::Distance mMoveLastY;
|
||||
|
||||
/* ArrowResize state */
|
||||
LabelModelObject* mResizeObject;
|
||||
Handle* mResizeHandle;
|
||||
bool mResizeHonorAspect;
|
||||
LabelModelObject* mResizeObject;
|
||||
Handle* mResizeHandle;
|
||||
bool mResizeHonorAspect;
|
||||
|
||||
/* CreateDrag state */
|
||||
CreateType mCreateObjectType;
|
||||
LabelModelObject* mCreateObject;
|
||||
double mCreateX0;
|
||||
double mCreateY0;
|
||||
CreateType mCreateObjectType;
|
||||
LabelModelObject* mCreateObject;
|
||||
libglabels::Distance mCreateX0;
|
||||
libglabels::Distance mCreateY0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XmlLabelParser.cpp
|
||||
*
|
||||
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2014-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -374,7 +374,7 @@ glabels::XmlLabelParser::parseShadowAttrs( const QDomElement &node, LabelModelOb
|
||||
|
||||
object->setShadowColorNode( ColorNode( field_flag, color, key ) );
|
||||
|
||||
object->setShadowOpacity( XmlUtil::getLengthAttr( node, "shadow_y", 1.0 ) );
|
||||
object->setShadowOpacity( XmlUtil::getDoubleAttr( node, "shadow_opacity", 1.0 ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XmlLabelParser.h
|
||||
*
|
||||
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2014-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
|
||||
@@ -8,7 +8,6 @@ set (libglabels_sources
|
||||
Category.cpp
|
||||
Paper.cpp
|
||||
Vendor.cpp
|
||||
Units.cpp
|
||||
Point.cpp
|
||||
Layout.cpp
|
||||
Markup.cpp
|
||||
@@ -27,6 +26,7 @@ set (libglabels_sources
|
||||
XmlTemplateCreator.cpp
|
||||
XmlUtil.cpp
|
||||
MiniPreviewPixmap.cpp
|
||||
Distance.cpp
|
||||
)
|
||||
|
||||
set (libglabels_qobject_headers
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Units.inl
|
||||
/* Constants.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -18,16 +18,19 @@
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef libglabels_Constants_h
|
||||
#define libglabels_Constants_h
|
||||
|
||||
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
inline QString Units::id() const { return mId; }
|
||||
|
||||
inline QString Units::name() const { return mName; }
|
||||
|
||||
inline double Units::pointsPerUnit() const { return mPointsPerUnit; }
|
||||
|
||||
inline double Units::unitsPerPoint() const { return mUnitsPerPoint; }
|
||||
const double PTS_PER_PT = 1.0;
|
||||
const double PTS_PER_INCH = 72.0;
|
||||
const double PTS_PER_MM = 2.83464566929;
|
||||
const double PTS_PER_CM = (10.0*PTS_PER_MM);
|
||||
const double PTS_PER_PICA = (1.0/12.0);
|
||||
|
||||
}
|
||||
|
||||
#endif // libglabels_Constants_h
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
/* Db.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -483,10 +483,10 @@ namespace libglabels
|
||||
foreach ( Paper *paper, mPapers )
|
||||
{
|
||||
qDebug() << "paper "
|
||||
<< "id=" << paper->id() << ", "
|
||||
<< "name=" << paper->name() << ", "
|
||||
<< "width=" << paper->width() << "pts, "
|
||||
<< "height=" << paper->height() << "pts, "
|
||||
<< "id=" << paper->id() << ", "
|
||||
<< "name=" << paper->name() << ", "
|
||||
<< "width=" << paper->width().pt() << "pts, "
|
||||
<< "height=" << paper->height().pt() << "pts, "
|
||||
<< "pwg_size=" << paper->pwgSize();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,255 @@
|
||||
/* Distance.cpp
|
||||
*
|
||||
* Copyright (C) 2016 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 "Distance.h"
|
||||
|
||||
#include <QTextStream>
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
QString Distance::toId( Units units )
|
||||
{
|
||||
QString idString;
|
||||
|
||||
switch (units)
|
||||
{
|
||||
case Units::PT:
|
||||
idString = "pt";
|
||||
break;
|
||||
case Units::IN:
|
||||
idString = "in";
|
||||
break;
|
||||
case Units::MM:
|
||||
idString = "mm";
|
||||
break;
|
||||
case Units::CM:
|
||||
idString = "cm";
|
||||
break;
|
||||
case Units::PC:
|
||||
idString = "pc";
|
||||
break;
|
||||
}
|
||||
|
||||
return idString;
|
||||
}
|
||||
|
||||
|
||||
QString Distance::toTrName( Units units )
|
||||
{
|
||||
QString nameString;
|
||||
|
||||
switch (units)
|
||||
{
|
||||
case Units::PT:
|
||||
nameString = tr("points");
|
||||
break;
|
||||
case Units::IN:
|
||||
nameString = tr("inches");
|
||||
break;
|
||||
case Units::MM:
|
||||
nameString = tr("mm");
|
||||
break;
|
||||
case Units::CM:
|
||||
nameString = tr("cm");
|
||||
break;
|
||||
case Units::PC:
|
||||
nameString = tr("picas");
|
||||
break;
|
||||
}
|
||||
|
||||
return nameString;
|
||||
}
|
||||
|
||||
|
||||
bool Distance::isIdValid( const QString& unitsId )
|
||||
{
|
||||
bool retValue = false;
|
||||
|
||||
if ( unitsId == "pt" )
|
||||
{
|
||||
retValue = true;
|
||||
}
|
||||
else if ( unitsId == "in" )
|
||||
{
|
||||
retValue = true;
|
||||
}
|
||||
else if ( unitsId == "mm" )
|
||||
{
|
||||
retValue = true;
|
||||
}
|
||||
else if ( unitsId == "cm" )
|
||||
{
|
||||
retValue = true;
|
||||
}
|
||||
else if ( unitsId == "pc" )
|
||||
{
|
||||
retValue = true;
|
||||
}
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
|
||||
Distance::Units Distance::toUnits( const QString& unitsId )
|
||||
{
|
||||
Units units;
|
||||
|
||||
if ( unitsId == "pt" )
|
||||
{
|
||||
units = Units::PT;
|
||||
}
|
||||
else if ( unitsId == "in" )
|
||||
{
|
||||
units = Units::IN;
|
||||
}
|
||||
else if ( unitsId == "mm" )
|
||||
{
|
||||
units = Units::MM;
|
||||
}
|
||||
else if ( unitsId == "cm" )
|
||||
{
|
||||
units = Units::CM;
|
||||
}
|
||||
else if ( unitsId == "pc" )
|
||||
{
|
||||
units = Units::PC;
|
||||
}
|
||||
else
|
||||
{
|
||||
units = Units::PT;
|
||||
}
|
||||
|
||||
return units;
|
||||
}
|
||||
|
||||
|
||||
Distance::Distance( double d, Units units )
|
||||
{
|
||||
switch (units)
|
||||
{
|
||||
case Units::PT:
|
||||
mDPts = d;
|
||||
break;
|
||||
case Units::IN:
|
||||
mDPts = d * PTS_PER_INCH;
|
||||
break;
|
||||
case Units::MM:
|
||||
mDPts = d * PTS_PER_MM;
|
||||
break;
|
||||
case Units::CM:
|
||||
mDPts = d * PTS_PER_CM;
|
||||
break;
|
||||
case Units::PC:
|
||||
mDPts = d * PTS_PER_PICA;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Distance::Distance( double d, const QString& unitsId )
|
||||
{
|
||||
Units units = toUnits( unitsId );
|
||||
|
||||
switch (units)
|
||||
{
|
||||
case Units::PT:
|
||||
mDPts = d;
|
||||
break;
|
||||
case Units::IN:
|
||||
mDPts = d * PTS_PER_INCH;
|
||||
break;
|
||||
case Units::MM:
|
||||
mDPts = d * PTS_PER_MM;
|
||||
break;
|
||||
case Units::CM:
|
||||
mDPts = d * PTS_PER_CM;
|
||||
break;
|
||||
case Units::PC:
|
||||
mDPts = d * PTS_PER_PICA;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Distance Distance::fromString( const QString& string )
|
||||
{
|
||||
QString stringCopy = string;
|
||||
QTextStream valueStream( &stringCopy, QIODevice::ReadOnly );
|
||||
|
||||
double value;
|
||||
QString unitsString;
|
||||
valueStream >> value >> unitsString;
|
||||
|
||||
if ( !unitsString.isEmpty() && !isIdValid( unitsString ) )
|
||||
{
|
||||
qWarning() << "Error: invalid Distance::Units \"" << string << "\"";
|
||||
}
|
||||
|
||||
return Distance( value, unitsString );
|
||||
}
|
||||
|
||||
|
||||
double Distance::inUnits( Units units ) const
|
||||
{
|
||||
double d;
|
||||
|
||||
switch (units)
|
||||
{
|
||||
case Units::PT:
|
||||
d = pt();
|
||||
break;
|
||||
case Units::IN:
|
||||
d = in();
|
||||
break;
|
||||
case Units::MM:
|
||||
d = mm();
|
||||
break;
|
||||
case Units::CM:
|
||||
d = cm();
|
||||
break;
|
||||
case Units::PC:
|
||||
d = pc();
|
||||
break;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
double Distance::inUnits( const QString& unitsId ) const
|
||||
{
|
||||
return inUnits( toUnits( unitsId ) );
|
||||
}
|
||||
|
||||
|
||||
QString Distance::toString( Units units ) const
|
||||
{
|
||||
return QString::number( inUnits(units) ) + toId(units);
|
||||
}
|
||||
|
||||
|
||||
QString Distance::toString( const QString& unitsId ) const
|
||||
{
|
||||
return QString::number( inUnits(unitsId) ) + unitsId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/* Distance.h
|
||||
*
|
||||
* Copyright (C) 2016 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 libglabels_Distance_h
|
||||
#define libglabels_Distance_h
|
||||
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QString>
|
||||
#include "Constants.h"
|
||||
|
||||
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
|
||||
class Distance
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(Distance)
|
||||
|
||||
public:
|
||||
enum class Units { PT, IN, MM, CM, PC };
|
||||
|
||||
static QString toId( Units units );
|
||||
static QString toTrName( Units units );
|
||||
static bool isIdValid( const QString& unitsId );
|
||||
static Units toUnits( const QString& unitsId );
|
||||
|
||||
|
||||
Distance();
|
||||
Distance( double d, Units units = Units::PT );
|
||||
Distance( double d, const QString& unitsId );
|
||||
|
||||
static Distance pt( double dPts );
|
||||
static Distance in( double dInches );
|
||||
static Distance mm( double dMm );
|
||||
static Distance cm( double dCm );
|
||||
static Distance pc( double dPicas );
|
||||
static Distance fromString( const QString& string );
|
||||
|
||||
|
||||
double pt() const;
|
||||
double in() const;
|
||||
double mm() const;
|
||||
double cm() const;
|
||||
double pc() const;
|
||||
double inUnits( Units units ) const;
|
||||
double inUnits( const QString& unitsId ) const;
|
||||
|
||||
|
||||
QString toString( Units units ) const;
|
||||
QString toString( const QString& unitsId ) const;
|
||||
|
||||
|
||||
Distance& operator+=( const Distance& d );
|
||||
Distance& operator-=( const Distance& d );
|
||||
Distance operator-();
|
||||
|
||||
friend inline Distance operator+( const Distance& d1, const Distance& d2 );
|
||||
friend inline Distance operator-( const Distance& d1, const Distance& d2 );
|
||||
friend inline Distance operator*( double x, const Distance& d );
|
||||
friend inline Distance operator*( const Distance& d, double x );
|
||||
friend inline double operator/( const Distance& d1, const Distance& d2 );
|
||||
friend inline Distance operator/( const Distance& d, double x );
|
||||
|
||||
friend inline bool operator<( const Distance& d1, const Distance& d2 );
|
||||
friend inline bool operator<=( const Distance& d1, const Distance& d2 );
|
||||
friend inline bool operator>( const Distance& d1, const Distance& d2 );
|
||||
friend inline bool operator>=( const Distance& d1, const Distance& d2 );
|
||||
friend inline bool operator==( const Distance& d1, const Distance& d2 );
|
||||
friend inline bool operator!=( const Distance& d1, const Distance& d2 );
|
||||
|
||||
friend inline Distance fabs( const Distance& d );
|
||||
friend inline Distance min( const Distance& d1, const Distance& d2 );
|
||||
friend inline Distance max( const Distance& d1, const Distance& d2 );
|
||||
friend inline Distance fmod( const Distance& d1, const Distance& d2 );
|
||||
|
||||
|
||||
private:
|
||||
double mDPts;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#include "Distance.inl"
|
||||
|
||||
|
||||
#endif // libglabels_Distance_h
|
||||
@@ -0,0 +1,218 @@
|
||||
/* Distance.inl
|
||||
*
|
||||
* Copyright (C) 2016 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 <cmath>
|
||||
|
||||
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
inline Distance::Distance() : mDPts(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inline Distance Distance::pt( double dPts )
|
||||
{
|
||||
Distance d;
|
||||
d.mDPts = dPts;
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
inline Distance Distance::in( double dInches )
|
||||
{
|
||||
Distance d;
|
||||
d.mDPts = dInches * PTS_PER_INCH;
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
inline Distance Distance::mm( double dMm )
|
||||
{
|
||||
Distance d;
|
||||
d.mDPts = dMm * PTS_PER_MM;
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
inline Distance Distance::cm( double dCm )
|
||||
{
|
||||
Distance d;
|
||||
d.mDPts = dCm * PTS_PER_CM;
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
inline Distance Distance::pc( double dPicas )
|
||||
{
|
||||
Distance d;
|
||||
d.mDPts = dPicas * PTS_PER_PICA;
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
inline double Distance::pt() const
|
||||
{
|
||||
return mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline double Distance::in() const
|
||||
{
|
||||
return mDPts / PTS_PER_INCH;
|
||||
}
|
||||
|
||||
|
||||
inline double Distance::mm() const
|
||||
{
|
||||
return mDPts / PTS_PER_MM;
|
||||
}
|
||||
|
||||
|
||||
inline double Distance::cm() const
|
||||
{
|
||||
return mDPts / PTS_PER_CM;
|
||||
}
|
||||
|
||||
|
||||
inline double Distance::pc() const
|
||||
{
|
||||
return mDPts / PTS_PER_PICA;
|
||||
}
|
||||
|
||||
|
||||
inline Distance& Distance::operator+=( const Distance& d )
|
||||
{
|
||||
mDPts += d.mDPts;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Distance& Distance::operator-=( const Distance& d )
|
||||
{
|
||||
mDPts -= d.mDPts;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Distance Distance::operator-()
|
||||
{
|
||||
return Distance::pt( -mDPts );
|
||||
}
|
||||
|
||||
|
||||
inline Distance operator+( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return Distance::pt( d1.mDPts + d2.mDPts );
|
||||
}
|
||||
|
||||
|
||||
inline Distance operator-( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return Distance::pt( d1.mDPts - d2.mDPts );
|
||||
}
|
||||
|
||||
|
||||
inline Distance operator*( double x, const Distance& d )
|
||||
{
|
||||
return Distance::pt( x * d.mDPts );
|
||||
}
|
||||
|
||||
|
||||
inline Distance operator*( const Distance& d, double x )
|
||||
{
|
||||
return Distance::pt( d.mDPts * x );
|
||||
}
|
||||
|
||||
|
||||
inline double operator/( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return d1.mDPts / d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline Distance operator/( const Distance& d, double x )
|
||||
{
|
||||
return Distance::pt( d.mDPts / x );
|
||||
}
|
||||
|
||||
|
||||
inline bool operator<( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return d1.mDPts < d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator<=( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return d1.mDPts <= d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator>( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return d1.mDPts > d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator>=( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return d1.mDPts >= d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator==( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return d1.mDPts == d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator!=( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return d1.mDPts != d2.mDPts;
|
||||
}
|
||||
|
||||
|
||||
inline Distance fabs( const Distance& d )
|
||||
{
|
||||
return Distance::pt( std::fabs( d.mDPts ) );
|
||||
}
|
||||
|
||||
|
||||
inline Distance min( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return (d1.mDPts < d2.mDPts) ? d1 : d2;
|
||||
}
|
||||
|
||||
|
||||
inline Distance max( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return (d1.mDPts > d2.mDPts) ? d1 : d2;
|
||||
}
|
||||
|
||||
|
||||
inline Distance fmod( const Distance& d1, const Distance& d2 )
|
||||
{
|
||||
return Distance::pt( std::fmod( d1.mDPts, d2.mDPts ) );
|
||||
}
|
||||
|
||||
}
|
||||
+5
-5
@@ -27,7 +27,7 @@
|
||||
#include <QPainterPath>
|
||||
#include <QVector>
|
||||
|
||||
#include "Units.h"
|
||||
#include "Distance.h"
|
||||
#include "Point.h"
|
||||
#include "Layout.h"
|
||||
|
||||
@@ -59,14 +59,14 @@ namespace libglabels
|
||||
void addLayout( Layout* layout );
|
||||
void addMarkup( Markup* markup );
|
||||
|
||||
virtual double w() const = 0;
|
||||
virtual double h() const = 0;
|
||||
virtual Distance w() const = 0;
|
||||
virtual Distance h() const = 0;
|
||||
|
||||
virtual const QString sizeDescription( const Units& units ) const = 0;
|
||||
virtual const QString sizeDescription( Distance::Units units ) const = 0;
|
||||
virtual bool isSimilarTo( Frame* other ) const = 0;
|
||||
|
||||
virtual const QPainterPath& path() const = 0;
|
||||
virtual QPainterPath marginPath( double size ) const = 0;
|
||||
virtual QPainterPath marginPath( const Distance& size ) const = 0;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
+28
-23
@@ -1,6 +1,6 @@
|
||||
/* FrameCd.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -30,20 +30,25 @@
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
FrameCd::FrameCd( double r1, double r2, double w, double h, double waste, QString id )
|
||||
FrameCd::FrameCd( const Distance& r1,
|
||||
const Distance& r2,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& waste,
|
||||
const QString& id )
|
||||
: mR1(r1), mR2(r2), mW(w), mH(h), mWaste(waste), Frame(id)
|
||||
{
|
||||
double wReal = (mW == 0) ? 2*mR1 : mW;
|
||||
double hReal = (mH == 0) ? 2*mR1 : mH;
|
||||
Distance wReal = (mW == 0) ? 2*mR1 : mW;
|
||||
Distance hReal = (mH == 0) ? 2*mR1 : mH;
|
||||
|
||||
/*
|
||||
* Construct outer subpath (may be clipped if it's a business card CD)
|
||||
*/
|
||||
QPainterPath outerPath;
|
||||
outerPath.addEllipse( wReal/2 - r1, hReal/2 - r1, 2*r1, 2*r1 );
|
||||
outerPath.addEllipse( (wReal/2 - r1).pt(), (hReal/2 - r1).pt(), 2*r1.pt(), 2*r1.pt() );
|
||||
|
||||
QPainterPath clipPath;
|
||||
clipPath.addRect( 0, 0, wReal, hReal );
|
||||
clipPath.addRect( 0, 0, wReal.pt(), hReal.pt() );
|
||||
|
||||
mPath.addPath( outerPath & clipPath );
|
||||
mPath.closeSubpath();
|
||||
@@ -51,7 +56,7 @@ namespace libglabels
|
||||
/*
|
||||
* Add inner subpath
|
||||
*/
|
||||
mPath.addEllipse( wReal/2 - r2, hReal/2 - r2, 2*r2, 2*r2 );
|
||||
mPath.addEllipse( (wReal/2 - r2).pt(), (hReal/2 - r2).pt(), 2*r2.pt(), 2*r2.pt() );
|
||||
}
|
||||
|
||||
|
||||
@@ -68,34 +73,34 @@ namespace libglabels
|
||||
}
|
||||
|
||||
|
||||
double FrameCd::w() const
|
||||
Distance FrameCd::w() const
|
||||
{
|
||||
return (mW == 0) ? 2*mR1 : mW;
|
||||
}
|
||||
|
||||
|
||||
double FrameCd::h() const
|
||||
Distance FrameCd::h() const
|
||||
{
|
||||
return (mH == 0) ? 2*mR1 : mH;
|
||||
}
|
||||
|
||||
|
||||
const QString FrameCd::sizeDescription( const Units& units ) const
|
||||
const QString FrameCd::sizeDescription( Distance::Units units ) const
|
||||
{
|
||||
if ( units.id() == "in" )
|
||||
if ( units == Distance::Units::IN )
|
||||
{
|
||||
QString dStr = StrUtil::formatFraction( 2 * mR1 * units.unitsPerPoint() );
|
||||
QString dStr = StrUtil::formatFraction( 2 * mR1.in() );
|
||||
|
||||
return QString().sprintf( "%s %s %s",
|
||||
qPrintable(dStr),
|
||||
qPrintable(units.name()),
|
||||
qPrintable(Distance::toTrName(units)),
|
||||
qPrintable(tr("diameter")) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString().sprintf( "%.5g %s %s",
|
||||
2 * mR1 * units.unitsPerPoint(),
|
||||
qPrintable(units.name()),
|
||||
2 * mR1.inUnits(units),
|
||||
qPrintable(Distance::toTrName(units)),
|
||||
qPrintable(tr("diameter")) );
|
||||
}
|
||||
}
|
||||
@@ -123,13 +128,13 @@ namespace libglabels
|
||||
}
|
||||
|
||||
|
||||
QPainterPath FrameCd::marginPath( double size ) const
|
||||
QPainterPath FrameCd::marginPath( const Distance& size ) const
|
||||
{
|
||||
double wReal = (mW == 0) ? 2*mR1 : mW;
|
||||
double hReal = (mH == 0) ? 2*mR1 : mH;
|
||||
Distance wReal = (mW == 0) ? 2*mR1 : mW;
|
||||
Distance hReal = (mH == 0) ? 2*mR1 : mH;
|
||||
|
||||
double r1 = mR1 - size;
|
||||
double r2 = mR2 + size;
|
||||
Distance r1 = mR1 - size;
|
||||
Distance r2 = mR2 + size;
|
||||
|
||||
QPainterPath path;
|
||||
|
||||
@@ -137,10 +142,10 @@ namespace libglabels
|
||||
* Construct outer subpath (may be clipped if it's a business card CD)
|
||||
*/
|
||||
QPainterPath outerPath;
|
||||
outerPath.addEllipse( wReal/2 - r1, hReal/2 - r1, 2*r1, 2*r1 );
|
||||
outerPath.addEllipse( (wReal/2 - r1).pt(), (hReal/2 - r1).pt(), 2*r1.pt(), 2*r1.pt() );
|
||||
|
||||
QPainterPath clipPath;
|
||||
clipPath.addRect( size, size, wReal-2*size, hReal-2*size );
|
||||
clipPath.addRect( size.pt(), size.pt(), (wReal-2*size).pt(), (hReal-2*size).pt() );
|
||||
|
||||
path.addPath( outerPath & clipPath );
|
||||
path.closeSubpath();
|
||||
@@ -148,7 +153,7 @@ namespace libglabels
|
||||
/*
|
||||
* Add inner subpath
|
||||
*/
|
||||
path.addEllipse( wReal/2 - r2, hReal/2 - r2, 2*r2, 2*r2 );
|
||||
path.addEllipse( (wReal/2 - r2).pt(), (hReal/2 - r2).pt(), 2*r2.pt(), 2*r2.pt() );
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
+19
-14
@@ -1,6 +1,6 @@
|
||||
/* FrameCd.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -30,32 +30,37 @@ namespace libglabels
|
||||
class FrameCd : public Frame
|
||||
{
|
||||
public:
|
||||
FrameCd( double r1, double r2, double w, double h, double waste, QString id = "0" );
|
||||
FrameCd( const Distance& r1,
|
||||
const Distance& r2,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& waste,
|
||||
const QString& id = "0" );
|
||||
|
||||
FrameCd( const FrameCd &other );
|
||||
|
||||
Frame *dup() const;
|
||||
|
||||
double r1() const;
|
||||
double r2() const;
|
||||
double waste() const;
|
||||
Distance r1() const;
|
||||
Distance r2() const;
|
||||
Distance waste() const;
|
||||
|
||||
double w() const;
|
||||
double h() const;
|
||||
Distance w() const;
|
||||
Distance h() const;
|
||||
|
||||
const QString sizeDescription( const Units& units ) const;
|
||||
const QString sizeDescription( Distance::Units units ) const;
|
||||
bool isSimilarTo( Frame* other ) const;
|
||||
|
||||
const QPainterPath& path() const;
|
||||
QPainterPath marginPath( double size ) const;
|
||||
QPainterPath marginPath( const Distance& size ) const;
|
||||
|
||||
|
||||
private:
|
||||
double mR1;
|
||||
double mR2;
|
||||
double mW;
|
||||
double mH;
|
||||
double mWaste;
|
||||
Distance mR1;
|
||||
Distance mR2;
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
Distance mWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* FrameCd.inl
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -22,19 +22,19 @@
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
inline double FrameCd::r1() const
|
||||
inline Distance FrameCd::r1() const
|
||||
{
|
||||
return mR1;
|
||||
}
|
||||
|
||||
|
||||
inline double FrameCd::r2() const
|
||||
inline Distance FrameCd::r2() const
|
||||
{
|
||||
return mR2;
|
||||
}
|
||||
|
||||
|
||||
inline double FrameCd::waste() const
|
||||
inline Distance FrameCd::waste() const
|
||||
{
|
||||
return mWaste;
|
||||
}
|
||||
|
||||
+20
-17
@@ -1,6 +1,6 @@
|
||||
/* FrameEllipse.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -29,10 +29,13 @@
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
FrameEllipse::FrameEllipse( double w, double h, double waste, QString id )
|
||||
FrameEllipse::FrameEllipse( const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& waste,
|
||||
const QString& id )
|
||||
: mW(w), mH(h), mWaste(waste), Frame(id)
|
||||
{
|
||||
mPath.addEllipse( 0, 0, mW, mH );
|
||||
mPath.addEllipse( 0, 0, mW.pt(), mH.pt() );
|
||||
}
|
||||
|
||||
FrameEllipse::FrameEllipse( const FrameEllipse& other )
|
||||
@@ -47,36 +50,36 @@ namespace libglabels
|
||||
}
|
||||
|
||||
|
||||
double FrameEllipse::w() const
|
||||
Distance FrameEllipse::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
|
||||
|
||||
double FrameEllipse::h() const
|
||||
Distance FrameEllipse::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
|
||||
|
||||
const QString FrameEllipse::sizeDescription( const Units& units ) const
|
||||
const QString FrameEllipse::sizeDescription( Distance::Units units ) const
|
||||
{
|
||||
if ( units.id() == "in" )
|
||||
if ( units == Distance::Units::IN )
|
||||
{
|
||||
QString wStr = StrUtil::formatFraction( mW * units.unitsPerPoint() );
|
||||
QString hStr = StrUtil::formatFraction( mH * units.unitsPerPoint() );
|
||||
QString wStr = StrUtil::formatFraction( mW.in() );
|
||||
QString hStr = StrUtil::formatFraction( mH.in() );
|
||||
|
||||
return QString().sprintf( "%s x %s %s",
|
||||
qPrintable(wStr),
|
||||
qPrintable(hStr),
|
||||
qPrintable(units.name()) );
|
||||
qPrintable(Distance::toTrName(units)) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString().sprintf( "%.5g x %.5g %s",
|
||||
mW * units.unitsPerPoint(),
|
||||
mH * units.unitsPerPoint(),
|
||||
qPrintable(units.name()) );
|
||||
mW.inUnits(units),
|
||||
mH.inUnits(units),
|
||||
qPrintable(Distance::toTrName(units)) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,13 +104,13 @@ namespace libglabels
|
||||
}
|
||||
|
||||
|
||||
QPainterPath FrameEllipse::marginPath( double size ) const
|
||||
QPainterPath FrameEllipse::marginPath( const Distance& size ) const
|
||||
{
|
||||
double w = mW - 2*size;
|
||||
double h = mH - 2*size;
|
||||
Distance w = mW - 2*size;
|
||||
Distance h = mH - 2*size;
|
||||
|
||||
QPainterPath path;
|
||||
path.addEllipse( size, size, w, h );
|
||||
path.addEllipse( size.pt(), size.pt(), w.pt(), h.pt() );
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
+13
-10
@@ -1,6 +1,6 @@
|
||||
/* FrameEllipse.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -31,28 +31,31 @@ namespace libglabels
|
||||
{
|
||||
|
||||
public:
|
||||
FrameEllipse( double w, double h, double waste, QString id = "0" );
|
||||
FrameEllipse( const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& waste,
|
||||
const QString& id = "0" );
|
||||
|
||||
FrameEllipse( const FrameEllipse& other );
|
||||
|
||||
Frame* dup() const;
|
||||
|
||||
double waste() const;
|
||||
Distance waste() const;
|
||||
|
||||
double w() const;
|
||||
double h() const;
|
||||
Distance w() const;
|
||||
Distance h() const;
|
||||
|
||||
const QString sizeDescription( const Units& units ) const;
|
||||
const QString sizeDescription( Distance::Units units ) const;
|
||||
bool isSimilarTo( Frame* other ) const;
|
||||
|
||||
const QPainterPath& path() const;
|
||||
QPainterPath marginPath( double size ) const;
|
||||
QPainterPath marginPath( const Distance& size ) const;
|
||||
|
||||
|
||||
private:
|
||||
double mW;
|
||||
double mH;
|
||||
double mWaste;
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
Distance mWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* FrameEllipse.inl
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -22,7 +22,7 @@
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
inline double FrameEllipse::waste() const
|
||||
inline Distance FrameEllipse::waste() const
|
||||
{
|
||||
return mWaste;
|
||||
}
|
||||
|
||||
+23
-18
@@ -1,6 +1,6 @@
|
||||
/* FrameRect.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -29,10 +29,15 @@
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
FrameRect::FrameRect( double w, double h, double r, double xWaste, double yWaste, QString id )
|
||||
FrameRect::FrameRect( const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& r,
|
||||
const Distance& xWaste,
|
||||
const Distance& yWaste,
|
||||
const QString& id )
|
||||
: mW(w), mH(h), mR(r), mXWaste(xWaste), mYWaste(yWaste), Frame(id)
|
||||
{
|
||||
mPath.addRoundedRect( 0, 0, mW, mH, mR, mR );
|
||||
mPath.addRoundedRect( 0, 0, mW.pt(), mH.pt(), mR.pt(), mR.pt() );
|
||||
}
|
||||
|
||||
|
||||
@@ -49,36 +54,36 @@ namespace libglabels
|
||||
}
|
||||
|
||||
|
||||
double FrameRect::w() const
|
||||
Distance FrameRect::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
|
||||
|
||||
double FrameRect::h() const
|
||||
Distance FrameRect::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
|
||||
|
||||
const QString FrameRect::sizeDescription( const Units& units ) const
|
||||
const QString FrameRect::sizeDescription( Distance::Units units ) const
|
||||
{
|
||||
if ( units.id() == "in" )
|
||||
if ( units == Distance::Units::IN )
|
||||
{
|
||||
QString wStr = StrUtil::formatFraction( mW * units.unitsPerPoint() );
|
||||
QString hStr = StrUtil::formatFraction( mH * units.unitsPerPoint() );
|
||||
QString wStr = StrUtil::formatFraction( mW.in() );
|
||||
QString hStr = StrUtil::formatFraction( mH.in() );
|
||||
|
||||
return QString().sprintf( "%s x %s %s",
|
||||
qPrintable(wStr),
|
||||
qPrintable(hStr),
|
||||
qPrintable(units.name()) );
|
||||
qPrintable(Distance::toTrName(units)) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString().sprintf( "%.5g x %.5g %s",
|
||||
mW * units.unitsPerPoint(),
|
||||
mH * units.unitsPerPoint(),
|
||||
qPrintable(units.name()) );
|
||||
mW.inUnits(units),
|
||||
mH.inUnits(units),
|
||||
qPrintable(Distance::toTrName(units)) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,14 +108,14 @@ namespace libglabels
|
||||
}
|
||||
|
||||
|
||||
QPainterPath FrameRect::marginPath( double size ) const
|
||||
QPainterPath FrameRect::marginPath( const Distance& size ) const
|
||||
{
|
||||
double w = mW - 2*size;
|
||||
double h = mH - 2*size;
|
||||
double r = std::max( mR - size, 0.0 );
|
||||
Distance w = mW - 2*size;
|
||||
Distance h = mH - 2*size;
|
||||
Distance r = std::max( mR - size, Distance(0.0) );
|
||||
|
||||
QPainterPath path;
|
||||
path.addRoundedRect( size, size, w, h, r, r );
|
||||
path.addRoundedRect( size.pt(), size.pt(), w.pt(), h.pt(), r.pt(), r.pt() );
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
+18
-18
@@ -30,38 +30,38 @@ namespace libglabels
|
||||
class FrameRect : public Frame
|
||||
{
|
||||
public:
|
||||
FrameRect( double w,
|
||||
double h,
|
||||
double r,
|
||||
double xWaste,
|
||||
double yWaste,
|
||||
QString id = "0" );
|
||||
FrameRect( const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& r,
|
||||
const Distance& xWaste,
|
||||
const Distance& yWaste,
|
||||
const QString& id = "0" );
|
||||
|
||||
FrameRect( const FrameRect& other );
|
||||
|
||||
Frame* dup() const;
|
||||
|
||||
double r() const;
|
||||
double xWaste() const;
|
||||
double yWaste() const;
|
||||
Distance r() const;
|
||||
Distance xWaste() const;
|
||||
Distance yWaste() const;
|
||||
|
||||
double w() const;
|
||||
double h() const;
|
||||
Distance w() const;
|
||||
Distance h() const;
|
||||
|
||||
const QString sizeDescription( const Units& units ) const;
|
||||
const QString sizeDescription( Distance::Units units ) const;
|
||||
|
||||
bool isSimilarTo( Frame* other ) const;
|
||||
|
||||
const QPainterPath& path() const;
|
||||
QPainterPath marginPath( double size ) const;
|
||||
QPainterPath marginPath( const Distance& size ) const;
|
||||
|
||||
|
||||
private:
|
||||
double mW;
|
||||
double mH;
|
||||
double mR;
|
||||
double mXWaste;
|
||||
double mYWaste;
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
Distance mR;
|
||||
Distance mXWaste;
|
||||
Distance mYWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* FrameRect.inl
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -22,19 +22,19 @@
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
inline double FrameRect::r() const
|
||||
inline Distance FrameRect::r() const
|
||||
{
|
||||
return mR;
|
||||
}
|
||||
|
||||
|
||||
inline double FrameRect::xWaste() const
|
||||
inline Distance FrameRect::xWaste() const
|
||||
{
|
||||
return mXWaste;
|
||||
}
|
||||
|
||||
|
||||
inline double FrameRect::yWaste() const
|
||||
inline Distance FrameRect::yWaste() const
|
||||
{
|
||||
return mYWaste;
|
||||
}
|
||||
|
||||
+16
-14
@@ -1,6 +1,6 @@
|
||||
/* FrameRound.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -29,10 +29,12 @@
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
FrameRound::FrameRound( double r, double waste, QString id )
|
||||
FrameRound::FrameRound( const Distance& r,
|
||||
const Distance& waste,
|
||||
const QString& id )
|
||||
: mR(r), mWaste(waste), Frame(id)
|
||||
{
|
||||
mPath.addEllipse( 0, 0, 2*mR, 2*mR );
|
||||
mPath.addEllipse( 0, 0, 2*mR.pt(), 2*mR.pt() );
|
||||
}
|
||||
|
||||
|
||||
@@ -48,34 +50,34 @@ namespace libglabels
|
||||
}
|
||||
|
||||
|
||||
double FrameRound::w() const
|
||||
Distance FrameRound::w() const
|
||||
{
|
||||
return 2*mR;
|
||||
}
|
||||
|
||||
|
||||
double FrameRound::h() const
|
||||
Distance FrameRound::h() const
|
||||
{
|
||||
return 2*mR;
|
||||
}
|
||||
|
||||
|
||||
const QString FrameRound::sizeDescription( const Units& units ) const
|
||||
const QString FrameRound::sizeDescription( Distance::Units units ) const
|
||||
{
|
||||
if ( units.id() == "in" )
|
||||
if ( units == Distance::Units::IN )
|
||||
{
|
||||
QString dStr = StrUtil::formatFraction( 2 * mR * units.unitsPerPoint() );
|
||||
QString dStr = StrUtil::formatFraction( 2 * mR.in() );
|
||||
|
||||
return QString().sprintf( "%s %s %s",
|
||||
qPrintable(dStr),
|
||||
qPrintable(units.name()),
|
||||
qPrintable(Distance::toTrName(units)),
|
||||
qPrintable(tr("diameter")) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString().sprintf( "%.5g %s %s",
|
||||
2 * mR * units.unitsPerPoint(),
|
||||
qPrintable(units.name()),
|
||||
2 * mR.inUnits(units),
|
||||
qPrintable(Distance::toTrName(units)),
|
||||
qPrintable(tr("diameter")) );
|
||||
}
|
||||
}
|
||||
@@ -100,12 +102,12 @@ namespace libglabels
|
||||
}
|
||||
|
||||
|
||||
QPainterPath FrameRound::marginPath( double size ) const
|
||||
QPainterPath FrameRound::marginPath( const Distance& size ) const
|
||||
{
|
||||
double r = mR - size;
|
||||
Distance r = mR - size;
|
||||
|
||||
QPainterPath path;
|
||||
path.addEllipse( size, size, 2*r, 2*r );
|
||||
path.addEllipse( size.pt(), size.pt(), 2*r.pt(), 2*r.pt() );
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
+12
-10
@@ -1,6 +1,6 @@
|
||||
/* FrameRound.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -31,28 +31,30 @@ namespace libglabels
|
||||
{
|
||||
|
||||
public:
|
||||
FrameRound( double r, double waste, QString id = "0" );
|
||||
FrameRound( const Distance& r,
|
||||
const Distance& waste,
|
||||
const QString& id = "0" );
|
||||
|
||||
FrameRound( const FrameRound &other );
|
||||
|
||||
Frame *dup() const;
|
||||
|
||||
double r() const;
|
||||
double waste() const;
|
||||
Distance r() const;
|
||||
Distance waste() const;
|
||||
|
||||
double w() const;
|
||||
double h() const;
|
||||
Distance w() const;
|
||||
Distance h() const;
|
||||
|
||||
const QString sizeDescription( const Units& units ) const;
|
||||
const QString sizeDescription( Distance::Units units ) const;
|
||||
bool isSimilarTo( Frame* other ) const;
|
||||
|
||||
const QPainterPath& path() const;
|
||||
QPainterPath marginPath( double size ) const;
|
||||
QPainterPath marginPath( const Distance& size ) const;
|
||||
|
||||
|
||||
private:
|
||||
double mR;
|
||||
double mWaste;
|
||||
Distance mR;
|
||||
Distance mWaste;
|
||||
|
||||
QPainterPath mPath;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* FrameRound.inl
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -22,13 +22,13 @@
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
inline double FrameRound::r() const
|
||||
inline Distance FrameRound::r() const
|
||||
{
|
||||
return mR;
|
||||
}
|
||||
|
||||
|
||||
inline double FrameRound::waste() const
|
||||
inline Distance FrameRound::waste() const
|
||||
{
|
||||
return mWaste;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Layout.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -28,7 +28,12 @@
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
Layout::Layout( int nx, int ny, double x0, double y0, double dx, double dy )
|
||||
Layout::Layout( int nx,
|
||||
int ny,
|
||||
const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& dx,
|
||||
const Distance& dy )
|
||||
: mNx(nx), mNy(ny), mX0(x0), mY0(y0), mDx(dx), mDy(dy)
|
||||
{
|
||||
}
|
||||
|
||||
+19
-12
@@ -1,6 +1,6 @@
|
||||
/* Layout.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -21,6 +21,8 @@
|
||||
#ifndef libglabels_Layout_h
|
||||
#define libglabels_Layout_h
|
||||
|
||||
#include "Distance.h"
|
||||
|
||||
|
||||
namespace libglabels
|
||||
{
|
||||
@@ -29,18 +31,23 @@ namespace libglabels
|
||||
{
|
||||
|
||||
public:
|
||||
Layout( int nx, int ny, double x0, double y0, double dx, double dy );
|
||||
Layout( int nx,
|
||||
int ny,
|
||||
const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& dx,
|
||||
const Distance& dy );
|
||||
|
||||
Layout( const Layout &other );
|
||||
|
||||
int nx() const;
|
||||
int ny() const;
|
||||
|
||||
double x0() const;
|
||||
double y0() const;
|
||||
Distance x0() const;
|
||||
Distance y0() const;
|
||||
|
||||
double dx() const;
|
||||
double dy() const;
|
||||
Distance dx() const;
|
||||
Distance dy() const;
|
||||
|
||||
bool isSimilarTo( const Layout *other );
|
||||
|
||||
@@ -48,12 +55,12 @@ namespace libglabels
|
||||
|
||||
|
||||
private:
|
||||
int mNx;
|
||||
int mNy;
|
||||
double mX0;
|
||||
double mY0;
|
||||
double mDx;
|
||||
double mDy;
|
||||
int mNx;
|
||||
int mNy;
|
||||
Distance mX0;
|
||||
Distance mY0;
|
||||
Distance mDx;
|
||||
Distance mDy;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Layout.inl
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -34,25 +34,25 @@ namespace libglabels
|
||||
}
|
||||
|
||||
|
||||
inline double Layout::x0() const
|
||||
inline Distance Layout::x0() const
|
||||
{
|
||||
return mX0;
|
||||
}
|
||||
|
||||
|
||||
inline double Layout::y0() const
|
||||
inline Distance Layout::y0() const
|
||||
{
|
||||
return mY0;
|
||||
}
|
||||
|
||||
|
||||
inline double Layout::dx() const
|
||||
inline Distance Layout::dx() const
|
||||
{
|
||||
return mDx;
|
||||
}
|
||||
|
||||
|
||||
inline double Layout::dy() const
|
||||
inline Distance Layout::dy() const
|
||||
{
|
||||
return mDy;
|
||||
}
|
||||
|
||||
+24
-11
@@ -1,6 +1,6 @@
|
||||
/* Markup.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -30,7 +30,8 @@ namespace libglabels
|
||||
}
|
||||
|
||||
|
||||
MarkupMargin::MarkupMargin( const Frame* frame, double size )
|
||||
MarkupMargin::MarkupMargin( const Frame* frame,
|
||||
const Distance& size )
|
||||
: mFrame(frame), mSize(size)
|
||||
{
|
||||
mPath = frame->marginPath( size );
|
||||
@@ -43,11 +44,14 @@ namespace libglabels
|
||||
}
|
||||
|
||||
|
||||
MarkupLine::MarkupLine( double x1, double y1, double x2, double y2 )
|
||||
MarkupLine::MarkupLine( const Distance& x1,
|
||||
const Distance& y1,
|
||||
const Distance& x2,
|
||||
const Distance& y2 )
|
||||
: mX1(x1), mY1(y1), mX2(x2), mY2(y2)
|
||||
{
|
||||
mPath.moveTo( x1, y1 );
|
||||
mPath.lineTo( x2, y2 );
|
||||
mPath.moveTo( x1.pt(), y1.pt() );
|
||||
mPath.lineTo( x2.pt(), y2.pt() );
|
||||
}
|
||||
|
||||
|
||||
@@ -57,10 +61,14 @@ namespace libglabels
|
||||
}
|
||||
|
||||
|
||||
MarkupRect::MarkupRect( double x1, double y1, double w, double h, double r )
|
||||
MarkupRect::MarkupRect( const Distance& x1,
|
||||
const Distance& y1,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& r )
|
||||
: mX1(x1), mY1(y1), mW(w), mH(h), mR(r)
|
||||
{
|
||||
mPath.addRoundedRect( x1, y1, w, h, r, r );
|
||||
mPath.addRoundedRect( x1.pt(), y1.pt(), w.pt(), h.pt(), r.pt(), r.pt() );
|
||||
}
|
||||
|
||||
|
||||
@@ -70,10 +78,13 @@ namespace libglabels
|
||||
}
|
||||
|
||||
|
||||
MarkupEllipse::MarkupEllipse( double x1, double y1, double w, double h )
|
||||
MarkupEllipse::MarkupEllipse( const Distance& x1,
|
||||
const Distance& y1,
|
||||
const Distance& w,
|
||||
const Distance& h )
|
||||
: mX1(x1), mY1(y1), mW(w), mH(h)
|
||||
{
|
||||
mPath.addEllipse( x1, y1, w, h );
|
||||
mPath.addEllipse( x1.pt(), y1.pt(), w.pt(), h.pt() );
|
||||
}
|
||||
|
||||
|
||||
@@ -83,10 +94,12 @@ namespace libglabels
|
||||
}
|
||||
|
||||
|
||||
MarkupCircle::MarkupCircle( double x0, double y0, double r )
|
||||
MarkupCircle::MarkupCircle( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& r )
|
||||
: mX0(x0), mY0(y0), mR(r)
|
||||
{
|
||||
mPath.addEllipse( x0-r, y0-r, 2*r, 2*r );
|
||||
mPath.addEllipse( (x0-r).pt(), (y0-r).pt(), 2*r.pt(), 2*r.pt() );
|
||||
}
|
||||
|
||||
Markup* MarkupCircle::dup() const
|
||||
|
||||
+53
-40
@@ -1,6 +1,6 @@
|
||||
/* Markup.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -44,95 +44,108 @@ namespace libglabels
|
||||
class MarkupMargin : public Markup
|
||||
{
|
||||
public:
|
||||
MarkupMargin( const Frame* frame, double size );
|
||||
MarkupMargin( const Frame* frame,
|
||||
const Distance& size );
|
||||
|
||||
double size() const;
|
||||
Distance size() const;
|
||||
|
||||
Markup* dup() const;
|
||||
|
||||
private:
|
||||
const Frame* mFrame;
|
||||
double mSize;
|
||||
Distance mSize;
|
||||
};
|
||||
|
||||
|
||||
class MarkupLine : public Markup
|
||||
{
|
||||
public:
|
||||
MarkupLine( double x1, double y1, double x2, double y2 );
|
||||
MarkupLine( const Distance& x1,
|
||||
const Distance& y1,
|
||||
const Distance& x2,
|
||||
const Distance& y2 );
|
||||
|
||||
double x1() const;
|
||||
double y1() const;
|
||||
double x2() const;
|
||||
double y2() const;
|
||||
Distance x1() const;
|
||||
Distance y1() const;
|
||||
Distance x2() const;
|
||||
Distance y2() const;
|
||||
|
||||
Markup* dup() const;
|
||||
|
||||
private:
|
||||
double mX1;
|
||||
double mY1;
|
||||
double mX2;
|
||||
double mY2;
|
||||
Distance mX1;
|
||||
Distance mY1;
|
||||
Distance mX2;
|
||||
Distance mY2;
|
||||
};
|
||||
|
||||
|
||||
class MarkupRect : public Markup
|
||||
{
|
||||
public:
|
||||
MarkupRect( double x1, double y1, double w, double h, double r );
|
||||
MarkupRect( const Distance& x1,
|
||||
const Distance& y1,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
const Distance& r );
|
||||
|
||||
double x1() const;
|
||||
double y1() const;
|
||||
double w() const;
|
||||
double h() const;
|
||||
double r() const;
|
||||
Distance x1() const;
|
||||
Distance y1() const;
|
||||
Distance w() const;
|
||||
Distance h() const;
|
||||
Distance r() const;
|
||||
|
||||
Markup* dup() const;
|
||||
|
||||
private:
|
||||
double mX1;
|
||||
double mY1;
|
||||
double mW;
|
||||
double mH;
|
||||
double mR;
|
||||
Distance mX1;
|
||||
Distance mY1;
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
Distance mR;
|
||||
};
|
||||
|
||||
|
||||
class MarkupEllipse : public Markup
|
||||
{
|
||||
public:
|
||||
MarkupEllipse( double x1, double y1, double w, double h );
|
||||
MarkupEllipse( const Distance& x1,
|
||||
const Distance& y1,
|
||||
const Distance& w,
|
||||
const Distance& h );
|
||||
|
||||
double x1() const;
|
||||
double y1() const;
|
||||
double w() const;
|
||||
double h() const;
|
||||
Distance x1() const;
|
||||
Distance y1() const;
|
||||
Distance w() const;
|
||||
Distance h() const;
|
||||
|
||||
Markup* dup() const;
|
||||
|
||||
private:
|
||||
double mX1;
|
||||
double mY1;
|
||||
double mW;
|
||||
double mH;
|
||||
Distance mX1;
|
||||
Distance mY1;
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
};
|
||||
|
||||
|
||||
class MarkupCircle : public Markup
|
||||
{
|
||||
public:
|
||||
MarkupCircle( double x0, double y0, double r );
|
||||
MarkupCircle( const Distance& x0,
|
||||
const Distance& y0,
|
||||
const Distance& r );
|
||||
|
||||
double x0() const;
|
||||
double y0() const;
|
||||
double r() const;
|
||||
Distance x0() const;
|
||||
Distance y0() const;
|
||||
Distance r() const;
|
||||
|
||||
Markup* dup() const;
|
||||
|
||||
private:
|
||||
double mX0;
|
||||
double mY0;
|
||||
double mR;
|
||||
Distance mX0;
|
||||
Distance mY0;
|
||||
Distance mR;
|
||||
};
|
||||
|
||||
|
||||
|
||||
+18
-18
@@ -1,6 +1,6 @@
|
||||
/* Markup.inl
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -22,26 +22,26 @@
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
inline double MarkupMargin::size() const { return mSize; }
|
||||
inline Distance MarkupMargin::size() const { return mSize; }
|
||||
|
||||
inline double MarkupLine::x1() const { return mX1; }
|
||||
inline double MarkupLine::y1() const { return mY1; }
|
||||
inline double MarkupLine::x2() const { return mX2; }
|
||||
inline double MarkupLine::y2() const { return mY2; }
|
||||
inline Distance MarkupLine::x1() const { return mX1; }
|
||||
inline Distance MarkupLine::y1() const { return mY1; }
|
||||
inline Distance MarkupLine::x2() const { return mX2; }
|
||||
inline Distance MarkupLine::y2() const { return mY2; }
|
||||
|
||||
inline double MarkupRect::x1() const { return mX1; }
|
||||
inline double MarkupRect::y1() const { return mY1; }
|
||||
inline double MarkupRect::w() const { return mW; }
|
||||
inline double MarkupRect::h() const { return mH; }
|
||||
inline double MarkupRect::r() const { return mR; }
|
||||
inline Distance MarkupRect::x1() const { return mX1; }
|
||||
inline Distance MarkupRect::y1() const { return mY1; }
|
||||
inline Distance MarkupRect::w() const { return mW; }
|
||||
inline Distance MarkupRect::h() const { return mH; }
|
||||
inline Distance MarkupRect::r() const { return mR; }
|
||||
|
||||
inline double MarkupEllipse::x1() const { return mX1; }
|
||||
inline double MarkupEllipse::y1() const { return mY1; }
|
||||
inline double MarkupEllipse::w() const { return mW; }
|
||||
inline double MarkupEllipse::h() const { return mH; }
|
||||
inline Distance MarkupEllipse::x1() const { return mX1; }
|
||||
inline Distance MarkupEllipse::y1() const { return mY1; }
|
||||
inline Distance MarkupEllipse::w() const { return mW; }
|
||||
inline Distance MarkupEllipse::h() const { return mH; }
|
||||
|
||||
inline double MarkupCircle::x0() const { return mX0; }
|
||||
inline double MarkupCircle::y0() const { return mY0; }
|
||||
inline double MarkupCircle::r() const { return mR; }
|
||||
inline Distance MarkupCircle::x0() const { return mX0; }
|
||||
inline Distance MarkupCircle::y0() const { return mY0; }
|
||||
inline Distance MarkupCircle::r() const { return mR; }
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* MiniPreviewPixmap.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -43,14 +43,14 @@ namespace libglabels
|
||||
}
|
||||
|
||||
|
||||
MiniPreviewPixmap::MiniPreviewPixmap( const Template *tmplate, int width, int height )
|
||||
MiniPreviewPixmap::MiniPreviewPixmap( const Template* tmplate, int width, int height )
|
||||
: QPixmap( width, height )
|
||||
{
|
||||
draw( tmplate, width, height );
|
||||
}
|
||||
|
||||
|
||||
void MiniPreviewPixmap::draw( const Template *tmplate, int width, int height )
|
||||
void MiniPreviewPixmap::draw( const Template* tmplate, int width, int height )
|
||||
{
|
||||
fill( Qt::transparent );
|
||||
|
||||
@@ -62,26 +62,26 @@ namespace libglabels
|
||||
double w = width - 1;
|
||||
double h = height - 1;
|
||||
double scale;
|
||||
if ( (w/tmplate->pageWidth()) > (h/tmplate->pageHeight()) )
|
||||
if ( (w/tmplate->pageWidth().pt()) > (h/tmplate->pageHeight().pt()) )
|
||||
{
|
||||
scale = h / tmplate->pageHeight();
|
||||
scale = h / tmplate->pageHeight().pt();
|
||||
}
|
||||
else
|
||||
{
|
||||
scale = w / tmplate->pageWidth();
|
||||
scale = w / tmplate->pageWidth().pt();
|
||||
}
|
||||
painter.scale( scale, scale );
|
||||
|
||||
double xOffset = ( width/scale - tmplate->pageWidth() ) / 2;
|
||||
double yOffset = ( height/scale - tmplate->pageHeight() ) / 2;
|
||||
painter.translate( xOffset, yOffset );
|
||||
Distance xOffset = ( Distance::pt(width/scale) - tmplate->pageWidth() ) / 2;
|
||||
Distance yOffset = ( Distance::pt(height/scale) - tmplate->pageHeight() ) / 2;
|
||||
painter.translate( xOffset.pt(), yOffset.pt() );
|
||||
|
||||
drawPaper( painter, tmplate, scale );
|
||||
drawLabelOutlines( painter, tmplate, scale );
|
||||
}
|
||||
|
||||
|
||||
void MiniPreviewPixmap::drawPaper( QPainter &painter, const Template *tmplate, double scale )
|
||||
void MiniPreviewPixmap::drawPaper( QPainter& painter, const Template* tmplate, double scale )
|
||||
{
|
||||
QBrush brush( paperColor );
|
||||
QPen pen( paperOutlineColor );
|
||||
@@ -91,13 +91,13 @@ namespace libglabels
|
||||
|
||||
painter.setBrush( brush );
|
||||
painter.setPen( pen );
|
||||
painter.drawRect( 0, 0, tmplate->pageWidth(), tmplate->pageHeight() );
|
||||
painter.drawRect( 0, 0, tmplate->pageWidth().pt(), tmplate->pageHeight().pt() );
|
||||
|
||||
painter.restore();
|
||||
}
|
||||
|
||||
|
||||
void MiniPreviewPixmap::drawLabelOutlines( QPainter &painter, const Template *tmplate, double scale )
|
||||
void MiniPreviewPixmap::drawLabelOutlines( QPainter& painter, const Template* tmplate, double scale )
|
||||
{
|
||||
QBrush brush( labelColor );
|
||||
QPen pen( labelOutlineColor );
|
||||
@@ -111,20 +111,20 @@ namespace libglabels
|
||||
Frame *frame = tmplate->frames().first();
|
||||
QVector<Point> origins = frame->getOrigins();
|
||||
|
||||
foreach ( Point point, origins )
|
||||
foreach ( Point p0, origins )
|
||||
{
|
||||
drawLabelOutline( painter, frame, point.x(), point.y() );
|
||||
drawLabelOutline( painter, frame, p0 );
|
||||
}
|
||||
|
||||
painter.restore();
|
||||
}
|
||||
|
||||
|
||||
void MiniPreviewPixmap::drawLabelOutline( QPainter &painter, const Frame *frame, double x0, double y0 )
|
||||
void MiniPreviewPixmap::drawLabelOutline( QPainter& painter, const Frame* frame, const Point& p0 )
|
||||
{
|
||||
painter.save();
|
||||
|
||||
painter.translate( x0, y0 );
|
||||
painter.translate( p0.x().pt(), p0.y().pt() );
|
||||
painter.drawPath( frame->path() );
|
||||
|
||||
painter.restore();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* MiniPreviewPixmap.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <QPixmap>
|
||||
#include <QPainter>
|
||||
#include "Point.h"
|
||||
|
||||
|
||||
namespace libglabels
|
||||
@@ -38,14 +39,14 @@ namespace libglabels
|
||||
public:
|
||||
MiniPreviewPixmap();
|
||||
|
||||
MiniPreviewPixmap( const Template *tmplate, int width, int height );
|
||||
MiniPreviewPixmap( const Template* tmplate, int width, int height );
|
||||
|
||||
|
||||
private:
|
||||
void draw( const Template *tmplate, int width, int height );
|
||||
void drawPaper( QPainter &painter, const Template *tmplate, double scale );
|
||||
void drawLabelOutlines( QPainter &painter, const Template *tmplate, double scale );
|
||||
void drawLabelOutline( QPainter &painter, const Frame *frame, double x0, double y0 );
|
||||
void draw( const Template* tmplate, int width, int height );
|
||||
void drawPaper( QPainter& painter, const Template* tmplate, double scale );
|
||||
void drawLabelOutlines( QPainter& painter, const Template* tmplate, double scale );
|
||||
void drawLabelOutline( QPainter& painter, const Frame *frame, const Point& point0 );
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Paper.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -24,7 +24,11 @@
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
Paper::Paper( const QString& id, const QString& name, double width, double height, const QString& pwgSize )
|
||||
Paper::Paper( const QString& id,
|
||||
const QString& name,
|
||||
const Distance& width,
|
||||
const Distance& height,
|
||||
const QString& pwgSize )
|
||||
: mId(id), mName(name), mWidth(width), mHeight(height), mPwgSize(pwgSize)
|
||||
{
|
||||
}
|
||||
|
||||
+16
-11
@@ -1,6 +1,6 @@
|
||||
/* Paper.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
|
||||
#include <QString>
|
||||
#include "Distance.h"
|
||||
|
||||
|
||||
namespace libglabels
|
||||
@@ -31,16 +32,20 @@ namespace libglabels
|
||||
class Paper
|
||||
{
|
||||
public:
|
||||
Paper( const QString& id, const QString& name, double width, double height, const QString& pwgSize );
|
||||
Paper( const QString& id,
|
||||
const QString& name,
|
||||
const Distance& width,
|
||||
const Distance& height,
|
||||
const QString& pwgSize );
|
||||
|
||||
inline const QString& id() const;
|
||||
inline const QString& name() const;
|
||||
|
||||
/* Width (in points) */
|
||||
inline double width() const;
|
||||
/* Width */
|
||||
inline Distance width() const;
|
||||
|
||||
/* Height (in points) */
|
||||
inline double height() const;
|
||||
/* Height */
|
||||
inline Distance height() const;
|
||||
|
||||
/* PWG 5101.1-2002 size name */
|
||||
inline QString pwgSize() const;
|
||||
@@ -49,11 +54,11 @@ namespace libglabels
|
||||
inline bool isSizeUs() const;
|
||||
|
||||
private:
|
||||
QString mId;
|
||||
QString mName;
|
||||
double mWidth;
|
||||
double mHeight;
|
||||
QString mPwgSize;
|
||||
QString mId;
|
||||
QString mName;
|
||||
Distance mWidth;
|
||||
Distance mHeight;
|
||||
QString mPwgSize;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ namespace libglabels
|
||||
inline const QString& Paper::id() const { return mId; }
|
||||
inline const QString& Paper::name() const { return mName; }
|
||||
|
||||
inline double Paper::width() const { return mWidth; }
|
||||
inline double Paper::height() const { return mHeight; }
|
||||
inline Distance Paper::width() const { return mWidth; }
|
||||
inline Distance Paper::height() const { return mHeight; }
|
||||
|
||||
inline QString Paper::pwgSize() const { return mPwgSize; }
|
||||
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
Point::Point() : mX(0), mY(0)
|
||||
Point::Point() : mX(Distance(0)), mY(Distance(0))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Point::Point( double x, double y ) : mX(x), mY(y)
|
||||
Point::Point( Distance x, Distance y ) : mX(x), mY(y)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
+8
-6
@@ -1,6 +1,6 @@
|
||||
/* Point.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -21,6 +21,8 @@
|
||||
#ifndef libglabels_Point_h
|
||||
#define libglabels_Point_h
|
||||
|
||||
#include "Distance.h"
|
||||
|
||||
|
||||
namespace libglabels
|
||||
{
|
||||
@@ -30,17 +32,17 @@ namespace libglabels
|
||||
public:
|
||||
Point();
|
||||
|
||||
Point( double x, double y );
|
||||
Point( Distance x, Distance y );
|
||||
|
||||
double x() const;
|
||||
double y() const;
|
||||
Distance x() const;
|
||||
Distance y() const;
|
||||
|
||||
bool operator<( const Point &other ) const;
|
||||
|
||||
|
||||
private:
|
||||
double mX;
|
||||
double mY;
|
||||
Distance mX;
|
||||
Distance mY;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+11
-3
@@ -1,6 +1,6 @@
|
||||
/* Point.inl
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -22,7 +22,15 @@
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
inline double Point::x() const { return mX; }
|
||||
inline double Point::y() const { return mY; }
|
||||
inline Distance Point::x() const
|
||||
{
|
||||
return mX;
|
||||
}
|
||||
|
||||
|
||||
inline Distance Point::y() const
|
||||
{
|
||||
return mY;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Template.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -28,12 +28,12 @@
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
Template::Template( const QString& brand,
|
||||
const QString& part,
|
||||
const QString& description,
|
||||
const QString& paperId,
|
||||
double pageWidth = 0,
|
||||
double pageHeight = 0 )
|
||||
Template::Template( const QString& brand,
|
||||
const QString& part,
|
||||
const QString& description,
|
||||
const QString& paperId,
|
||||
const Distance& pageWidth,
|
||||
const Distance& pageHeight )
|
||||
: mBrand(brand),
|
||||
mPart(part),
|
||||
mDescription(description),
|
||||
|
||||
+15
-15
@@ -1,6 +1,6 @@
|
||||
/* Template.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "Units.h"
|
||||
#include "Distance.h"
|
||||
#include "Point.h"
|
||||
#include "Frame.h"
|
||||
#include "MiniPreviewPixmap.h"
|
||||
@@ -46,12 +46,12 @@ namespace libglabels
|
||||
|
||||
public:
|
||||
|
||||
Template( const QString& brand,
|
||||
const QString& part,
|
||||
const QString& description,
|
||||
const QString& paperId,
|
||||
double pageWidth,
|
||||
double pageHeight );
|
||||
Template( const QString& brand,
|
||||
const QString& part,
|
||||
const QString& description,
|
||||
const QString& paperId,
|
||||
const Distance& pageWidth,
|
||||
const Distance& pageHeight );
|
||||
|
||||
Template( const Template& other );
|
||||
|
||||
@@ -71,8 +71,8 @@ namespace libglabels
|
||||
const QString& description() const;
|
||||
|
||||
const QString& paperId() const;
|
||||
double pageWidth() const;
|
||||
double pageHeight() const;
|
||||
Distance pageWidth() const;
|
||||
Distance pageHeight() const;
|
||||
bool isSizeIso() const;
|
||||
bool isSizeUs() const;
|
||||
bool isSizeOther() const;
|
||||
@@ -104,11 +104,11 @@ namespace libglabels
|
||||
QString mPart;
|
||||
QString mDescription;
|
||||
|
||||
QString mPaperId;
|
||||
double mPageWidth;
|
||||
double mPageHeight;
|
||||
bool mIsSizeIso;
|
||||
bool mIsSizeUs;
|
||||
QString mPaperId;
|
||||
Distance mPageWidth;
|
||||
Distance mPageHeight;
|
||||
bool mIsSizeIso;
|
||||
bool mIsSizeUs;
|
||||
|
||||
QString mEquivPart;
|
||||
QString mName;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Template.inl
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -27,8 +27,8 @@ namespace libglabels
|
||||
inline const QString& Template::description() const { return mDescription; }
|
||||
|
||||
inline const QString& Template::paperId() const { return mPaperId; }
|
||||
inline double Template::pageWidth() const { return mPageWidth; }
|
||||
inline double Template::pageHeight() const { return mPageHeight; }
|
||||
inline Distance Template::pageWidth() const { return mPageWidth; }
|
||||
inline Distance Template::pageHeight() const { return mPageHeight; }
|
||||
inline bool Template::isSizeIso() const { return mIsSizeIso; }
|
||||
inline bool Template::isSizeUs() const { return mIsSizeUs; }
|
||||
inline bool Template::isSizeOther() const { return !mIsSizeIso && !mIsSizeUs; }
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
/* Units.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 "Units.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
const double POINTS_PER_POINT = 1.0; /* internal units are points. */
|
||||
const double POINTS_PER_INCH = 72.0;
|
||||
const double POINTS_PER_MM = 2.83464566929;
|
||||
const double POINTS_PER_CM = (10.0*POINTS_PER_MM);
|
||||
const double POINTS_PER_PICA = (1.0/12.0);
|
||||
}
|
||||
|
||||
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
Units::Units( const QString &id, const QString &name, double pointsPerUnit )
|
||||
: mId(id), mName(name), mPointsPerUnit(pointsPerUnit)
|
||||
{
|
||||
mUnitsPerPoint = 1.0 / mPointsPerUnit;
|
||||
}
|
||||
|
||||
|
||||
Units::Units()
|
||||
: mId("pt"), mName(tr("points")), mPointsPerUnit(POINTS_PER_POINT)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Units Units::fromId( const QString &id )
|
||||
{
|
||||
if ( id == "pt" )
|
||||
{
|
||||
return point();
|
||||
}
|
||||
else if ( id == "in" )
|
||||
{
|
||||
return inch();
|
||||
}
|
||||
else if ( id == "mm" )
|
||||
{
|
||||
return mm();
|
||||
}
|
||||
else if ( id == "cm" )
|
||||
{
|
||||
return cm();
|
||||
}
|
||||
else if ( id == "pc" )
|
||||
{
|
||||
return pica();
|
||||
}
|
||||
else if ( id == "" )
|
||||
{
|
||||
/* Missing or empty units id defaults to points. */
|
||||
return point();
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "Unknown Units ID \"" << id << "\", defaults to \"pt\"";
|
||||
return point();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Units Units::point()
|
||||
{
|
||||
return Units( "pt", tr("points"), POINTS_PER_POINT );
|
||||
}
|
||||
|
||||
|
||||
Units Units::inch()
|
||||
{
|
||||
return Units( "in", tr("inches"), POINTS_PER_INCH );
|
||||
}
|
||||
|
||||
|
||||
Units Units::mm()
|
||||
{
|
||||
return Units( "mm", tr("mm"), POINTS_PER_MM );
|
||||
}
|
||||
|
||||
|
||||
Units Units::cm()
|
||||
{
|
||||
return Units( "cm", tr("cm"), POINTS_PER_CM );
|
||||
}
|
||||
|
||||
|
||||
Units Units::pica()
|
||||
{
|
||||
return Units( "pc", tr("picas"), POINTS_PER_PICA );
|
||||
}
|
||||
|
||||
|
||||
bool Units::isIdValid( QString id )
|
||||
{
|
||||
return ( (id == "pt") || (id == "in") || (id == "mm") || (id == "cm") || (id == "pc") || (id == "") );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/* Units.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 libglabels_Units_h
|
||||
#define libglabels_Units_h
|
||||
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
|
||||
class Units
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(Units)
|
||||
|
||||
|
||||
private:
|
||||
Units( const QString &id, const QString &name, double pointsPerUnit );
|
||||
|
||||
public:
|
||||
Units();
|
||||
|
||||
QString id() const;
|
||||
QString name() const;
|
||||
|
||||
double pointsPerUnit() const;
|
||||
double unitsPerPoint() const;
|
||||
|
||||
static Units fromId( const QString &id );
|
||||
|
||||
static Units point();
|
||||
|
||||
static Units inch();
|
||||
|
||||
static Units mm();
|
||||
|
||||
static Units cm();
|
||||
|
||||
static Units pica();
|
||||
|
||||
static bool isIdValid( QString id );
|
||||
|
||||
|
||||
private:
|
||||
QString mId;
|
||||
QString mName;
|
||||
double mPointsPerUnit;
|
||||
double mUnitsPerPoint;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#include "Units.inl"
|
||||
|
||||
|
||||
#endif // libglabels_Units_h
|
||||
@@ -93,8 +93,8 @@ namespace libglabels
|
||||
QString id = XmlUtil::getStringAttr( node, "id", "" );
|
||||
QString name = XmlUtil::getI18nAttr( node, "name", "" );
|
||||
|
||||
double width = XmlUtil::getLengthAttr( node, "width", 0 );
|
||||
double height = XmlUtil::getLengthAttr( node, "height", 0 );
|
||||
Distance width = XmlUtil::getLengthAttr( node, "width", Distance(0) );
|
||||
Distance height = XmlUtil::getLengthAttr( node, "height", Distance(0) );
|
||||
|
||||
QString pwgSize = XmlUtil::getStringAttr( node, "pwg_size", "" );
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XmlTemplateCreator.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -203,11 +203,11 @@ namespace libglabels
|
||||
XmlUtil::setLengthAttr( node, "radius", frame->r1() );
|
||||
XmlUtil::setLengthAttr( node, "hole", frame->r2() );
|
||||
XmlUtil::setLengthAttr( node, "waste", frame->waste() );
|
||||
if ( frame->w() )
|
||||
if ( frame->w() != Distance(0) )
|
||||
{
|
||||
XmlUtil::setLengthAttr( node, "width", frame->w() );
|
||||
}
|
||||
if ( frame->h() )
|
||||
if ( frame->h() != Distance(0) )
|
||||
{
|
||||
XmlUtil::setLengthAttr( node, "height", frame->h() );
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XmlTemplateParser.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -165,8 +165,8 @@ namespace libglabels
|
||||
}
|
||||
else
|
||||
{
|
||||
double width = XmlUtil::getLengthAttr( node, "width", 0 );
|
||||
double height = XmlUtil::getLengthAttr( node, "height", 0 );
|
||||
Distance width = XmlUtil::getLengthAttr( node, "width", Distance(0) );
|
||||
Distance height = XmlUtil::getLengthAttr( node, "height", Distance(0) );
|
||||
|
||||
tmplate = new Template( brand, part, description, paperId, width, height );
|
||||
}
|
||||
@@ -226,22 +226,22 @@ namespace libglabels
|
||||
{
|
||||
QString id = XmlUtil::getStringAttr( node, "id", "0" );
|
||||
|
||||
double w = XmlUtil::getLengthAttr( node, "width", 0 );
|
||||
double h = XmlUtil::getLengthAttr( node, "height", 0 );
|
||||
double r = XmlUtil::getLengthAttr( node, "round", 0 );
|
||||
Distance w = XmlUtil::getLengthAttr( node, "width", Distance(0) );
|
||||
Distance h = XmlUtil::getLengthAttr( node, "height", Distance(0) );
|
||||
Distance r = XmlUtil::getLengthAttr( node, "round", Distance(0) );
|
||||
|
||||
double xWaste, yWaste;
|
||||
Distance xWaste, yWaste;
|
||||
|
||||
double waste = XmlUtil::getLengthAttr( node, "waste", -1 );
|
||||
if ( waste >= 0 )
|
||||
Distance waste = XmlUtil::getLengthAttr( node, "waste", Distance(-1) );
|
||||
if ( waste >= Distance(0) )
|
||||
{
|
||||
xWaste = waste;
|
||||
yWaste = waste;
|
||||
}
|
||||
else
|
||||
{
|
||||
xWaste = XmlUtil::getLengthAttr( node, "x_waste", 0 );
|
||||
yWaste = XmlUtil::getLengthAttr( node, "y_waste", 0 );
|
||||
xWaste = XmlUtil::getLengthAttr( node, "x_waste", Distance(0) );
|
||||
yWaste = XmlUtil::getLengthAttr( node, "y_waste", Distance(0) );
|
||||
}
|
||||
|
||||
Frame *frame = new FrameRect( w, h, r, xWaste, yWaste, id );
|
||||
@@ -256,9 +256,9 @@ namespace libglabels
|
||||
{
|
||||
QString id = XmlUtil::getStringAttr( node, "id", "0" );
|
||||
|
||||
double w = XmlUtil::getLengthAttr( node, "width", 0 );
|
||||
double h = XmlUtil::getLengthAttr( node, "height", 0 );
|
||||
double waste = XmlUtil::getLengthAttr( node, "waste", -1 );
|
||||
Distance w = XmlUtil::getLengthAttr( node, "width", Distance(0) );
|
||||
Distance h = XmlUtil::getLengthAttr( node, "height", Distance(0) );
|
||||
Distance waste = XmlUtil::getLengthAttr( node, "waste", Distance(0) );
|
||||
|
||||
Frame *frame = new FrameEllipse( w, h, waste, id );
|
||||
|
||||
@@ -272,8 +272,8 @@ namespace libglabels
|
||||
{
|
||||
QString id = XmlUtil::getStringAttr( node, "id", "0" );
|
||||
|
||||
double r = XmlUtil::getLengthAttr( node, "radius", 0 );
|
||||
double waste = XmlUtil::getLengthAttr( node, "waste", -1 );
|
||||
Distance r = XmlUtil::getLengthAttr( node, "radius", Distance(0) );
|
||||
Distance waste = XmlUtil::getLengthAttr( node, "waste", Distance(0) );
|
||||
|
||||
Frame *frame = new FrameRound( r, waste, id );
|
||||
|
||||
@@ -287,11 +287,11 @@ namespace libglabels
|
||||
{
|
||||
QString id = XmlUtil::getStringAttr( node, "id", "0" );
|
||||
|
||||
double r1 = XmlUtil::getLengthAttr( node, "radius", 0 );
|
||||
double r2 = XmlUtil::getLengthAttr( node, "hole", 0 );
|
||||
double w = XmlUtil::getLengthAttr( node, "width", 0 );
|
||||
double h = XmlUtil::getLengthAttr( node, "height", 0 );
|
||||
double waste = XmlUtil::getLengthAttr( node, "waste", -1 );
|
||||
Distance r1 = XmlUtil::getLengthAttr( node, "radius", Distance(0) );
|
||||
Distance r2 = XmlUtil::getLengthAttr( node, "hole", Distance(0) );
|
||||
Distance w = XmlUtil::getLengthAttr( node, "width", Distance(0) );
|
||||
Distance h = XmlUtil::getLengthAttr( node, "height", Distance(0) );
|
||||
Distance waste = XmlUtil::getLengthAttr( node, "waste", Distance(0) );
|
||||
|
||||
Frame *frame = new FrameCd( r1, r2, w, h, waste, id );
|
||||
|
||||
@@ -341,14 +341,14 @@ namespace libglabels
|
||||
|
||||
void XmlTemplateParser::parseLayoutNode( const QDomElement &node, Frame *frame )
|
||||
{
|
||||
int nX = XmlUtil::getIntAttr( node, "nx", 1 );
|
||||
int nY = XmlUtil::getIntAttr( node, "ny", 1 );
|
||||
int nX = XmlUtil::getIntAttr( node, "nx", 1 );
|
||||
int nY = XmlUtil::getIntAttr( node, "ny", 1 );
|
||||
|
||||
double x0 = XmlUtil::getLengthAttr( node, "x0", 0 );
|
||||
double y0 = XmlUtil::getLengthAttr( node, "y0", 0 );
|
||||
Distance x0 = XmlUtil::getLengthAttr( node, "x0", Distance(0) );
|
||||
Distance y0 = XmlUtil::getLengthAttr( node, "y0", Distance(0) );
|
||||
|
||||
double dX = XmlUtil::getLengthAttr( node, "dx", 0 );
|
||||
double dY = XmlUtil::getLengthAttr( node, "dy", 0 );
|
||||
Distance dX = XmlUtil::getLengthAttr( node, "dx", Distance(0) );
|
||||
Distance dY = XmlUtil::getLengthAttr( node, "dy", Distance(0) );
|
||||
|
||||
frame->addLayout( new Layout( nX, nY, x0, y0, dX, dY ) );
|
||||
}
|
||||
@@ -356,7 +356,7 @@ namespace libglabels
|
||||
|
||||
void XmlTemplateParser::parseMarkupMarginNode( const QDomElement &node, Frame *frame )
|
||||
{
|
||||
double size = XmlUtil::getLengthAttr( node, "size", 0 );
|
||||
Distance size = XmlUtil::getLengthAttr( node, "size", Distance(0) );
|
||||
|
||||
frame->addMarkup( new MarkupMargin( frame, size ) );
|
||||
}
|
||||
@@ -364,10 +364,10 @@ namespace libglabels
|
||||
|
||||
void XmlTemplateParser::parseMarkupLineNode( const QDomElement &node, Frame *frame )
|
||||
{
|
||||
double x1 = XmlUtil::getLengthAttr( node, "x1", 0 );
|
||||
double y1 = XmlUtil::getLengthAttr( node, "y1", 0 );
|
||||
double x2 = XmlUtil::getLengthAttr( node, "x2", 0 );
|
||||
double y2 = XmlUtil::getLengthAttr( node, "y2", 0 );
|
||||
Distance x1 = XmlUtil::getLengthAttr( node, "x1", Distance(0) );
|
||||
Distance y1 = XmlUtil::getLengthAttr( node, "y1", Distance(0) );
|
||||
Distance x2 = XmlUtil::getLengthAttr( node, "x2", Distance(0) );
|
||||
Distance y2 = XmlUtil::getLengthAttr( node, "y2", Distance(0) );
|
||||
|
||||
frame->addMarkup( new MarkupLine( x1, y1, x2, y2 ) );
|
||||
}
|
||||
@@ -375,9 +375,9 @@ namespace libglabels
|
||||
|
||||
void XmlTemplateParser::parseMarkupCircleNode( const QDomElement &node, Frame *frame )
|
||||
{
|
||||
double x0 = XmlUtil::getLengthAttr( node, "x0", 0 );
|
||||
double y0 = XmlUtil::getLengthAttr( node, "y0", 0 );
|
||||
double r = XmlUtil::getLengthAttr( node, "radius", 0 );
|
||||
Distance x0 = XmlUtil::getLengthAttr( node, "x0", Distance(0) );
|
||||
Distance y0 = XmlUtil::getLengthAttr( node, "y0", Distance(0) );
|
||||
Distance r = XmlUtil::getLengthAttr( node, "radius", Distance(0) );
|
||||
|
||||
frame->addMarkup( new MarkupCircle( x0, y0, r ) );
|
||||
}
|
||||
@@ -385,11 +385,11 @@ namespace libglabels
|
||||
|
||||
void XmlTemplateParser::parseMarkupRectNode( const QDomElement &node, Frame *frame )
|
||||
{
|
||||
double x1 = XmlUtil::getLengthAttr( node, "x1", 0 );
|
||||
double y1 = XmlUtil::getLengthAttr( node, "y1", 0 );
|
||||
double w = XmlUtil::getLengthAttr( node, "w", 0 );
|
||||
double h = XmlUtil::getLengthAttr( node, "h", 0 );
|
||||
double r = XmlUtil::getLengthAttr( node, "r", 0 );
|
||||
Distance x1 = XmlUtil::getLengthAttr( node, "x1", Distance(0) );
|
||||
Distance y1 = XmlUtil::getLengthAttr( node, "y1", Distance(0) );
|
||||
Distance w = XmlUtil::getLengthAttr( node, "w", Distance(0) );
|
||||
Distance h = XmlUtil::getLengthAttr( node, "h", Distance(0) );
|
||||
Distance r = XmlUtil::getLengthAttr( node, "r", Distance(0) );
|
||||
|
||||
frame->addMarkup( new MarkupRect( x1, y1, w, h, r ) );
|
||||
}
|
||||
@@ -397,10 +397,10 @@ namespace libglabels
|
||||
|
||||
void XmlTemplateParser::parseMarkupEllipseNode( const QDomElement &node, Frame *frame )
|
||||
{
|
||||
double x1 = XmlUtil::getLengthAttr( node, "x1", 0 );
|
||||
double y1 = XmlUtil::getLengthAttr( node, "y1", 0 );
|
||||
double w = XmlUtil::getLengthAttr( node, "w", 0 );
|
||||
double h = XmlUtil::getLengthAttr( node, "h", 0 );
|
||||
Distance x1 = XmlUtil::getLengthAttr( node, "x1", Distance(0) );
|
||||
Distance y1 = XmlUtil::getLengthAttr( node, "y1", Distance(0) );
|
||||
Distance w = XmlUtil::getLengthAttr( node, "w", Distance(0) );
|
||||
Distance h = XmlUtil::getLengthAttr( node, "h", Distance(0) );
|
||||
|
||||
frame->addMarkup( new MarkupEllipse( x1, y1, w, h ) );
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XmlTemplateParser.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
|
||||
+17
-21
@@ -1,6 +1,6 @@
|
||||
/* XmlUtil.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -27,12 +27,12 @@
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
Units XmlUtil::mDefaultUnits;
|
||||
Distance::Units XmlUtil::mUnits;
|
||||
|
||||
|
||||
XmlUtil::XmlUtil()
|
||||
{
|
||||
mDefaultUnits = Units::point();
|
||||
mUnits = Distance::Units::PT;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,25 +42,25 @@ namespace libglabels
|
||||
}
|
||||
|
||||
|
||||
Units XmlUtil::defaultUnits()
|
||||
Distance::Units XmlUtil::units()
|
||||
{
|
||||
init();
|
||||
|
||||
return mDefaultUnits;
|
||||
return mUnits;
|
||||
}
|
||||
|
||||
|
||||
void XmlUtil::setDefaultUnits( const Units& defaultUnits )
|
||||
void XmlUtil::setUnits( Distance::Units units )
|
||||
{
|
||||
init();
|
||||
|
||||
mDefaultUnits = defaultUnits;
|
||||
mUnits = units;
|
||||
}
|
||||
|
||||
|
||||
QString XmlUtil::getStringAttr( const QDomElement& node,
|
||||
const QString& name,
|
||||
const QString& default_value )
|
||||
const QString& default_value )
|
||||
{
|
||||
init();
|
||||
|
||||
@@ -200,9 +200,9 @@ namespace libglabels
|
||||
}
|
||||
|
||||
|
||||
double XmlUtil::getLengthAttr( const QDomElement& node,
|
||||
const QString& name,
|
||||
double default_value )
|
||||
Distance XmlUtil::getLengthAttr( const QDomElement& node,
|
||||
const QString& name,
|
||||
const Distance& default_value )
|
||||
{
|
||||
init();
|
||||
|
||||
@@ -215,16 +215,13 @@ namespace libglabels
|
||||
|
||||
valueStream >> value >> unitsString;
|
||||
|
||||
if ( !Units::isIdValid( unitsString ) )
|
||||
if ( !unitsString.isEmpty() && !Distance::isIdValid( unitsString ) )
|
||||
{
|
||||
qWarning() << "Error: bad length value in attribute "
|
||||
<< node.tagName() << ":" << name << "=" << valueString;
|
||||
return default_value;
|
||||
}
|
||||
|
||||
Units units = Units::fromId( unitsString );
|
||||
|
||||
return value * units.pointsPerUnit();
|
||||
return Distance( value, unitsString );
|
||||
}
|
||||
|
||||
return default_value;
|
||||
@@ -281,14 +278,13 @@ namespace libglabels
|
||||
}
|
||||
|
||||
|
||||
void XmlUtil::setLengthAttr( QDomElement& node,
|
||||
const QString& name,
|
||||
double value )
|
||||
void XmlUtil::setLengthAttr( QDomElement& node,
|
||||
const QString& name,
|
||||
const Distance& value )
|
||||
{
|
||||
init();
|
||||
|
||||
value *= mDefaultUnits.unitsPerPoint();
|
||||
node.setAttribute( name, QString::number(value) + mDefaultUnits.id() );
|
||||
node.setAttribute( name, QString::number(value.inUnits(mUnits)) + Distance::toId(mUnits) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,6 +1,6 @@
|
||||
/* XmlUtil.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <QDomElement>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Units.h"
|
||||
#include "Distance.h"
|
||||
|
||||
|
||||
namespace libglabels
|
||||
@@ -41,8 +41,8 @@ namespace libglabels
|
||||
|
||||
static void init();
|
||||
|
||||
static Units defaultUnits();
|
||||
static void setDefaultUnits( const Units& defaultUnits );
|
||||
static Distance::Units units();
|
||||
static void setUnits( Distance::Units units );
|
||||
|
||||
static QString getStringAttr( const QDomElement& node,
|
||||
const QString& name,
|
||||
@@ -68,9 +68,9 @@ namespace libglabels
|
||||
const QString& name,
|
||||
const QString& default_value );
|
||||
|
||||
static double getLengthAttr( const QDomElement& node,
|
||||
static Distance getLengthAttr( const QDomElement& node,
|
||||
const QString& name,
|
||||
double default_value );
|
||||
const Distance& default_value );
|
||||
|
||||
static void setStringAttr( QDomElement& node,
|
||||
const QString& name,
|
||||
@@ -92,12 +92,12 @@ namespace libglabels
|
||||
const QString& name,
|
||||
uint32_t value );
|
||||
|
||||
static void setLengthAttr( QDomElement& node,
|
||||
const QString& name,
|
||||
double value );
|
||||
static void setLengthAttr( QDomElement& node,
|
||||
const QString& name,
|
||||
const Distance& value );
|
||||
|
||||
private:
|
||||
static Units mDefaultUnits;
|
||||
static Distance::Units mUnits;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#define libglabels_privateConstants_h
|
||||
|
||||
|
||||
#include <QString>
|
||||
#include "Distance.h"
|
||||
|
||||
|
||||
namespace libglabels
|
||||
@@ -31,7 +31,8 @@ namespace libglabels
|
||||
namespace Constants
|
||||
{
|
||||
|
||||
const double EPSILON = 0.5; /* Allowed error when comparing dimensions. (0.5pts ~= .007in ~= .2mm) */
|
||||
const Distance EPSILON( 0.5, Distance::Units::PT );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user