Added unit-independent distance type.
This commit is contained in:
@@ -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