diff --git a/libglabels/Category.cpp b/libglabels/Category.cpp index d598836..8f41a8e 100644 --- a/libglabels/Category.cpp +++ b/libglabels/Category.cpp @@ -19,3 +19,16 @@ */ #include "Category.h" + + +namespace libglabels +{ + + Category::Category( const QString &id, const QString &name ) + : mId(id), mName(name) + { + } + +} + + diff --git a/libglabels/Category.h b/libglabels/Category.h index 6653014..41fb37e 100644 --- a/libglabels/Category.h +++ b/libglabels/Category.h @@ -30,19 +30,24 @@ namespace libglabels class Category { - public: - Category( const QString &id, const QString &name ) : mId(id), mName(name) - { - } - inline const QString &id() const { return mId; } - inline const QString &name() const { return mName; } + public: + Category( const QString& id, const QString& name ); + + const QString& id() const; + const QString& name() const; + private: QString mId; QString mName; + }; } + +#include "Category.inl" + + #endif // libglabels_Category_h diff --git a/libglabels/Category.inl b/libglabels/Category.inl new file mode 100644 index 0000000..7f9f47f --- /dev/null +++ b/libglabels/Category.inl @@ -0,0 +1,37 @@ +/* Category.inl + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + + +namespace libglabels +{ + + inline const QString& Category::id() const + { + return mId; + } + + + inline const QString& Category::name() const + { + return mName; + } + +} + diff --git a/libglabels/Db.cpp b/libglabels/Db.cpp index 55e0e76..f6d1491 100644 --- a/libglabels/Db.cpp +++ b/libglabels/Db.cpp @@ -67,6 +67,19 @@ namespace libglabels } + void Db::init() + { + instance(); + } + + + Db* Db::instance() + { + static Db* db = new Db(); + return db; + } + + void Db::registerPaper( Paper *paper ) { if ( !isPaperIdKnown( paper->id() ) ) diff --git a/libglabels/Db.h b/libglabels/Db.h index 033fdcd..03b112e 100644 --- a/libglabels/Db.h +++ b/libglabels/Db.h @@ -44,22 +44,22 @@ namespace libglabels Db(); public: - static void init() { instance(); } - static Db *instance() { static Db *db = new Db(); return db; } + static void init(); + static Db* instance(); - static const QList &papers() { return mPapers; } - static const QStringList &paperIds() { return mPaperIds; } - static const QStringList &paperNames() { return mPaperNames; } + static const QList& papers(); + static const QStringList& paperIds(); + static const QStringList& paperNames(); - static const QList &categories() { return mCategories; } - static const QStringList &categoryIds() { return mCategoryIds; } - static const QStringList &categoryNames() { return mCategoryNames; } + static const QList& categories(); + static const QStringList& categoryIds(); + static const QStringList& categoryNames(); - static const QList &vendors() { return mVendors; } - static const QStringList &vendorNames() { return mVendorNames; } + static const QList& vendors(); + static const QStringList& vendorNames(); - static const QList &templates() { return mTemplates; } + static const QList& templates(); static void registerPaper( Paper *paper ); @@ -84,13 +84,15 @@ namespace libglabels static void registerTemplate( Template *tmplate ); static const Template *lookupTemplateFromName( const QString &name ); - static const Template *lookupTemplateFromBrandPart( const QString &brand, const QString &part ); + static const Template *lookupTemplateFromBrandPart( const QString &brand, + const QString &part ); static bool isTemplateKnown( const QString &brand, const QString &part ); static QStringList getNameListOfSimilarTemplates( const QString &name ); static void registerUserTemplate( Template *tmplate ); static void deleteUserTemplateByName( const QString &name ); - static void deleteUserTemplateByBrandPart( const QString &brand, const QString &part ); + static void deleteUserTemplateByBrandPart( const QString &brand, + const QString &part ); static void printKnownPapers(); static void printKnownCategories(); @@ -134,4 +136,8 @@ namespace libglabels } + +#include "Db.inl" + + #endif // libglabels_Db_h diff --git a/libglabels/Db.inl b/libglabels/Db.inl new file mode 100644 index 0000000..5501ddb --- /dev/null +++ b/libglabels/Db.inl @@ -0,0 +1,77 @@ +/* Db.inl + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + + +namespace libglabels +{ + + inline const QList& Db::papers() + { + return mPapers; + } + + + inline const QStringList& Db::paperIds() + { + return mPaperIds; + } + + + inline const QStringList& Db::paperNames() + { + return mPaperNames; + } + + + inline const QList& Db::categories() + { + return mCategories; + } + + + inline const QStringList& Db::categoryIds() + { + return mCategoryIds; + } + + + inline const QStringList& Db::categoryNames() + { + return mCategoryNames; + } + + + inline const QList& Db::vendors() + { + return mVendors; + } + + + inline const QStringList& Db::vendorNames() + { + return mVendorNames; + } + + inline const QList& Db::templates() + { + return mTemplates; + } + +} diff --git a/libglabels/Frame.cpp b/libglabels/Frame.cpp index d06a72c..24de7e1 100644 --- a/libglabels/Frame.cpp +++ b/libglabels/Frame.cpp @@ -26,7 +26,13 @@ namespace libglabels { - Frame::Frame( const Frame &other ) + Frame::Frame( const QString& id ) + : mId(id), mNLabels(0), mLayoutDescription("") + { + } + + + Frame::Frame( const Frame& other ) { mId = other.mId; mNLabels = 0; diff --git a/libglabels/Frame.h b/libglabels/Frame.h index 9d1e107..356ed14 100644 --- a/libglabels/Frame.h +++ b/libglabels/Frame.h @@ -43,34 +43,32 @@ namespace libglabels Q_DECLARE_TR_FUNCTIONS(Frame) protected: - Frame( const QString &id = "0" ) : mId(id), mNLabels(0), mLayoutDescription("") - { - } - - Frame( const Frame &other ); + Frame( const QString& id = "0" ); + Frame( const Frame& other ); public: - virtual Frame *dup() const = 0; + virtual Frame* dup() const = 0; - inline const QString &id() const { return mId; } - inline int nLabels() const { return mNLabels; } - inline const QString &layoutDescription() const { return mLayoutDescription; } - inline const QList &layouts() const { return mLayouts; } - inline const QList &markups() const { return mMarkups; } + const QString& id() const; + int nLabels() const; + const QString& layoutDescription() const; + const QList& layouts() const; + const QList& markups() const; QVector getOrigins() const; - void addLayout( Layout *layout ); - void addMarkup( Markup *markup ); + void addLayout( Layout* layout ); + void addMarkup( Markup* markup ); virtual double w() const = 0; virtual double h() const = 0; - virtual const QString sizeDescription( const Units *units ) const = 0; - virtual bool isSimilarTo( Frame *other ) const = 0; + virtual const QString sizeDescription( const Units* units ) const = 0; + virtual bool isSimilarTo( Frame* other ) const = 0; virtual const QPainterPath &path( bool isRotated = false ) const = 0; - virtual QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const = 0; + virtual QGraphicsItem* createMarginGraphicsItem( double size, + const QPen& pen ) const = 0; private: @@ -84,4 +82,8 @@ namespace libglabels } + +#include "Frame.inl" + + #endif // libglabels_Frame_h diff --git a/libglabels/Frame.inl b/libglabels/Frame.inl new file mode 100644 index 0000000..0b5edb0 --- /dev/null +++ b/libglabels/Frame.inl @@ -0,0 +1,54 @@ +/* Frame.inl + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + + +namespace libglabels +{ + + inline const QString& Frame::id() const + { + return mId; + } + + + inline int Frame::nLabels() const + { + return mNLabels; + } + + + inline const QString& Frame::layoutDescription() const + { + return mLayoutDescription; + } + + + inline const QList& Frame::layouts() const + { + return mLayouts; + } + + + inline const QList& Frame::markups() const + { + return mMarkups; + } + +} diff --git a/libglabels/FrameCd.cpp b/libglabels/FrameCd.cpp index e17cfa2..977d2ac 100644 --- a/libglabels/FrameCd.cpp +++ b/libglabels/FrameCd.cpp @@ -29,6 +29,80 @@ namespace libglabels { + FrameCd::FrameCd( double r1, double r2, double w, double h, double waste, QString id ) + : mR1(r1), mR2(r2), mW(w), mH(h), mWaste(waste), Frame(id) + { + // + // First, initialize the un-rotated path + // + { + // Outer path (may be clipped in the case business card type CD) + double theta1 = acos( w / (2*mR1) ) * 180/M_PI; + double theta2 = asin( h / (2*mR1) ) * 180/M_PI; + + mPath.arcMoveTo( 0, 0, 2*mR1, 2*mR1, theta1 ); + mPath.arcTo( 0, 0, 2*mR1, 2*mR1, theta1, theta2-theta1 ); + mPath.arcTo( 0, 0, 2*mR1, 2*mR1, 180-theta2, theta2-theta1 ); + mPath.arcTo( 0, 0, 2*mR1, 2*mR1, 180+theta1, theta2-theta1 ); + mPath.arcTo( 0, 0, 2*mR1, 2*mR1, 360-theta2, theta2-theta1 ); + mPath.closeSubpath(); + + // Inner path (hole) + mPath.addEllipse( mR1-mR2, mR1-mR2, 2*mR2, 2*mR2 ); + + // Translate to account for offset with clipped business card CDs + mPath.translate( w/2 - mR1, h/2 - mR1 ); + } + + // + // Next, initialize the rotated path + // + { + // Outer path (may be clipped in the case business card type CD) + double theta1 = acos( h / (2*mR1) ) * 180/M_PI; + double theta2 = asin( w / (2*mR1) ) * 180/M_PI; + + mRotatedPath.arcMoveTo( 0, 0, 2*mR1, 2*mR1, theta1 ); + mRotatedPath.arcTo( 0, 0, 2*mR1, 2*mR1, theta1, theta2-theta1 ); + mRotatedPath.arcTo( 0, 0, 2*mR1, 2*mR1, 180-theta2, theta2-theta1 ); + mRotatedPath.arcTo( 0, 0, 2*mR1, 2*mR1, 180+theta1, theta2-theta1 ); + mRotatedPath.arcTo( 0, 0, 2*mR1, 2*mR1, 360-theta2, theta2-theta1 ); + mRotatedPath.closeSubpath(); + + // Inner path (hole) + mRotatedPath.addEllipse( mR1-mR2, mR1-mR2, 2*mR2, 2*mR2 ); + + // Translate to account for offset with clipped business card CDs + mRotatedPath.translate( h/2 - mR1, w/2 - mR1 ); + } + } + + + FrameCd::FrameCd( const FrameCd& other ) + : mR1(other.mR1), mR2(other.mR2), mW(other.mW), mH(other.mH), mWaste(other.mWaste), + mPath(other.mPath), Frame(other) + { + } + + + Frame* FrameCd::dup() const + { + return new FrameCd( *this ); + } + + + double FrameCd::w() const + { + return (mW == 0) ? 2*mR1 : mW; + } + + + double FrameCd::h() const + { + return (mH == 0) ? 2*mR1 : mH; + } + + const QString FrameCd::sizeDescription( const Units *units ) const { if ( units->id() == "in" ) @@ -66,53 +140,11 @@ namespace libglabels } - void FrameCd::initPath() + const QPainterPath& FrameCd::path( bool isRotated ) const { - // - // First the un-rotated path - // - { - // Outer path (may be clipped in the case business card type CD) - double theta1 = acos( w() / (2*mR1) ) * 180/M_PI; - double theta2 = asin( h() / (2*mR1) ) * 180/M_PI; - - mPath.arcMoveTo( 0, 0, 2*mR1, 2*mR1, theta1 ); - mPath.arcTo( 0, 0, 2*mR1, 2*mR1, theta1, theta2-theta1 ); - mPath.arcTo( 0, 0, 2*mR1, 2*mR1, 180-theta2, theta2-theta1 ); - mPath.arcTo( 0, 0, 2*mR1, 2*mR1, 180+theta1, theta2-theta1 ); - mPath.arcTo( 0, 0, 2*mR1, 2*mR1, 360-theta2, theta2-theta1 ); - mPath.closeSubpath(); - - // Inner path (hole) - mPath.addEllipse( mR1-mR2, mR1-mR2, 2*mR2, 2*mR2 ); - - // Translate to account for offset with clipped business card CDs - mPath.translate( w()/2 - mR1, h()/2 - mR1 ); - } - - // - // Next, the rotated path - // - { - // Outer path (may be clipped in the case business card type CD) - double theta1 = acos( h() / (2*mR1) ) * 180/M_PI; - double theta2 = asin( w() / (2*mR1) ) * 180/M_PI; - - mRotatedPath.arcMoveTo( 0, 0, 2*mR1, 2*mR1, theta1 ); - mRotatedPath.arcTo( 0, 0, 2*mR1, 2*mR1, theta1, theta2-theta1 ); - mRotatedPath.arcTo( 0, 0, 2*mR1, 2*mR1, 180-theta2, theta2-theta1 ); - mRotatedPath.arcTo( 0, 0, 2*mR1, 2*mR1, 180+theta1, theta2-theta1 ); - mRotatedPath.arcTo( 0, 0, 2*mR1, 2*mR1, 360-theta2, theta2-theta1 ); - mRotatedPath.closeSubpath(); - - // Inner path (hole) - mRotatedPath.addEllipse( mR1-mR2, mR1-mR2, 2*mR2, 2*mR2 ); - - // Translate to account for offset with clipped business card CDs - mRotatedPath.translate( h()/2 - mR1, w()/2 - mR1 ); - } + return isRotated ? mRotatedPath : mPath; } - + QGraphicsItem* FrameCd::createMarginGraphicsItem( double size, const QPen& pen ) const { diff --git a/libglabels/FrameCd.h b/libglabels/FrameCd.h index 33ad04b..36daa58 100644 --- a/libglabels/FrameCd.h +++ b/libglabels/FrameCd.h @@ -30,42 +30,27 @@ namespace libglabels class FrameCd : public Frame { public: - FrameCd( double r1, - double r2, - double w, - double h, - double waste, - QString id = "0" ) - : mR1(r1), mR2(r2), mW(w), mH(h), mWaste(waste), Frame(id) - { - initPath(); - } + FrameCd( double r1, double r2, double w, double h, double waste, QString id = "0" ); - FrameCd( const FrameCd &other ) - : mR1(other.mR1), mR2(other.mR2), mW(other.mW), mH(other.mH), mWaste(other.mWaste), - mPath(other.mPath), Frame(other) - { - } + FrameCd( const FrameCd &other ); - Frame *dup() const { return new FrameCd( *this ); } + Frame *dup() const; - inline double r1() const { return mR1; } - inline double r2() const { return mR2; } - inline double waste() const { return mWaste; } + double r1() const; + double r2() const; + double waste() const; - double w() const { return (mW == 0) ? 2*mR1 : mW; } - double h() const { return (mH == 0) ? 2*mR1 : mH; } + double w() const; + double h() const; const QString sizeDescription( const Units *units ) const; bool isSimilarTo( Frame *other ) const; - const QPainterPath &path( bool isRotated ) const { return isRotated ? mRotatedPath : mPath; } + const QPainterPath &path( bool isRotated ) const; QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const; private: - void initPath(); - double mR1; double mR2; double mW; @@ -79,4 +64,8 @@ namespace libglabels } + +#include "FrameCd.inl" + + #endif // libglabels_FrameCd_h diff --git a/libglabels/FrameCd.inl b/libglabels/FrameCd.inl new file mode 100644 index 0000000..34180e1 --- /dev/null +++ b/libglabels/FrameCd.inl @@ -0,0 +1,42 @@ +/* FrameCd.inl + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + + +namespace libglabels +{ + + inline double FrameCd::r1() const + { + return mR1; + } + + + inline double FrameCd::r2() const + { + return mR2; + } + + + inline double FrameCd::waste() const + { + return mWaste; + } + +} diff --git a/libglabels/FrameEllipse.cpp b/libglabels/FrameEllipse.cpp index c9a898c..1c4ebbe 100644 --- a/libglabels/FrameEllipse.cpp +++ b/libglabels/FrameEllipse.cpp @@ -29,6 +29,37 @@ namespace libglabels { + FrameEllipse::FrameEllipse( double w, double h, double waste, QString id ) + : mW(w), mH(h), mWaste(waste), Frame(id) + { + mPath.addEllipse( 0, 0, mW, mH ); + mRotatedPath.addEllipse( 0, 0, mH, mW ); + } + + FrameEllipse::FrameEllipse( const FrameEllipse& other ) + : mW(other.mW), mH(other.mH), mWaste(other.mWaste), mPath(other.mPath), Frame(other) + { + } + + + Frame* FrameEllipse::dup() const + { + return new FrameEllipse( *this ); + } + + + double FrameEllipse::w() const + { + return mW; + } + + + double FrameEllipse::h() const + { + return mH; + } + + const QString FrameEllipse::sizeDescription( const Units *units ) const { if ( units->id() == "in" ) @@ -51,9 +82,9 @@ namespace libglabels } - bool FrameEllipse::isSimilarTo( Frame *other ) const + bool FrameEllipse::isSimilarTo( Frame* other ) const { - if ( FrameEllipse *otherEllipse = dynamic_cast(other) ) + if ( FrameEllipse* otherEllipse = dynamic_cast(other) ) { if ( (fabs( mW - otherEllipse->mW ) <= Constants::EPSILON) && (fabs( mH - otherEllipse->mH ) <= Constants::EPSILON) ) @@ -65,6 +96,12 @@ namespace libglabels } + const QPainterPath& FrameEllipse::path( bool isRotated ) const + { + return isRotated ? mRotatedPath : mPath; + } + + QGraphicsItem* FrameEllipse::createMarginGraphicsItem( double size, const QPen& pen ) const { double w = mW - 2*size; diff --git a/libglabels/FrameEllipse.h b/libglabels/FrameEllipse.h index 1e75243..27b7ca3 100644 --- a/libglabels/FrameEllipse.h +++ b/libglabels/FrameEllipse.h @@ -29,33 +29,23 @@ namespace libglabels class FrameEllipse : public Frame { + public: - FrameEllipse( double w, - double h, - double waste, - QString id = "0" ) - : mW(w), mH(h), mWaste(waste), Frame(id) - { - mPath.addEllipse( 0, 0, mW, mH ); - mRotatedPath.addEllipse( 0, 0, mH, mW ); - } + FrameEllipse( double w, double h, double waste, QString id = "0" ); - FrameEllipse( const FrameEllipse &other ) - : mW(other.mW), mH(other.mH), mWaste(other.mWaste), mPath(other.mPath), Frame(other) - { - } + FrameEllipse( const FrameEllipse& other ); - Frame *dup() const { return new FrameEllipse( *this ); } + Frame* dup() const; - inline double waste() const { return mWaste; } + double waste() const; - double w() const { return mW; } - double h() const { return mH; } + double w() const; + double h() const; - const QString sizeDescription( const Units *units ) const; - bool isSimilarTo( Frame *other ) const; + const QString sizeDescription( const Units* units ) const; + bool isSimilarTo( Frame* other ) const; - const QPainterPath &path( bool isRotated ) const { return isRotated ? mRotatedPath : mPath; } + const QPainterPath& path( bool isRotated ) const; QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const; @@ -71,4 +61,8 @@ namespace libglabels } + +#include "FrameEllipse.inl" + + #endif // libglabels_FrameEllipse_h diff --git a/libglabels/FrameEllipse.inl b/libglabels/FrameEllipse.inl new file mode 100644 index 0000000..3000d20 --- /dev/null +++ b/libglabels/FrameEllipse.inl @@ -0,0 +1,30 @@ +/* FrameEllipse.inl + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + + +namespace libglabels +{ + + inline double FrameEllipse::waste() const + { + return mWaste; + } + +} diff --git a/libglabels/FrameRect.cpp b/libglabels/FrameRect.cpp index 79a781c..46671ee 100644 --- a/libglabels/FrameRect.cpp +++ b/libglabels/FrameRect.cpp @@ -29,6 +29,39 @@ namespace libglabels { + FrameRect::FrameRect( double w, double h, double r, double xWaste, double yWaste, QString id ) + : mW(w), mH(h), mR(r), mXWaste(xWaste), mYWaste(yWaste), Frame(id) + { + mPath.addRoundedRect( 0, 0, mW, mH, mR, mR ); + mRotatedPath.addRoundedRect( 0, 0, mH, mW, mR, mR ); + } + + + FrameRect::FrameRect( const FrameRect &other ) + : mW(other.mW), mH(other.mH), mR(other.mR), mXWaste(other.mXWaste), + mYWaste(other.mYWaste), mPath(other.mPath), Frame(other) + { + } + + + Frame* FrameRect::dup() const + { + return new FrameRect( *this ); + } + + + double FrameRect::w() const + { + return mW; + } + + + double FrameRect::h() const + { + return mH; + } + + const QString FrameRect::sizeDescription( const Units *units ) const { if ( units->id() == "in" ) @@ -65,6 +98,12 @@ namespace libglabels } + const QPainterPath& FrameRect::path( bool isRotated ) const + { + return isRotated ? mRotatedPath : mPath; + } + + QGraphicsItem* FrameRect::createMarginGraphicsItem( double size, const QPen& pen ) const { double w = mW - 2*size; @@ -80,5 +119,6 @@ namespace libglabels return item; } + } diff --git a/libglabels/FrameRect.h b/libglabels/FrameRect.h index 82f64fc..dc7cbd0 100644 --- a/libglabels/FrameRect.h +++ b/libglabels/FrameRect.h @@ -35,32 +35,24 @@ namespace libglabels double r, double xWaste, double yWaste, - QString id = "0" ) - : mW(w), mH(h), mR(r), mXWaste(xWaste), mYWaste(yWaste), Frame(id) - { - mPath.addRoundedRect( 0, 0, mW, mH, mR, mR ); - mRotatedPath.addRoundedRect( 0, 0, mH, mW, mR, mR ); - } + QString id = "0" ); - FrameRect( const FrameRect &other ) - : mW(other.mW), mH(other.mH), mR(other.mR), mXWaste(other.mXWaste), mYWaste(other.mYWaste), - mPath(other.mPath), Frame(other) - { - } + FrameRect( const FrameRect& other ); - Frame *dup() const { return new FrameRect( *this ); } + Frame* dup() const; - inline double r() const { return mR; } - inline double xWaste() const { return mXWaste; } - inline double yWaste() const { return mYWaste; } + double r() const; + double xWaste() const; + double yWaste() const; - double w() const { return mW; } - double h() const { return mH; } + double w() const; + double h() const; const QString sizeDescription( const Units *units ) const; + bool isSimilarTo( Frame *other ) const; - const QPainterPath &path( bool isRotated ) const { return isRotated ? mRotatedPath : mPath; } + const QPainterPath& path( bool isRotated ) const; QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const; @@ -78,4 +70,8 @@ namespace libglabels } + +#include "FrameRect.inl" + + #endif // libglabels_FrameRect_h diff --git a/libglabels/FrameRect.inl b/libglabels/FrameRect.inl new file mode 100644 index 0000000..f3b18da --- /dev/null +++ b/libglabels/FrameRect.inl @@ -0,0 +1,42 @@ +/* FrameRect.inl + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + + +namespace libglabels +{ + + inline double FrameRect::r() const + { + return mR; + } + + + inline double FrameRect::xWaste() const + { + return mXWaste; + } + + + inline double FrameRect::yWaste() const + { + return mYWaste; + } + +} diff --git a/libglabels/FrameRound.cpp b/libglabels/FrameRound.cpp index 8560b34..e8470ff 100644 --- a/libglabels/FrameRound.cpp +++ b/libglabels/FrameRound.cpp @@ -29,6 +29,37 @@ namespace libglabels { + FrameRound::FrameRound( double r, double waste, QString id ) + : mR(r), mWaste(waste), Frame(id) + { + mPath.addEllipse( 0, 0, 2*mR, 2*mR ); + } + + + FrameRound::FrameRound( const FrameRound& other ) + : mR(other.mR), mWaste(other.mWaste), mPath(other.mPath), Frame(other) + { + } + + + Frame* FrameRound::dup() const + { + return new FrameRound( *this ); + } + + + double FrameRound::w() const + { + return 2*mR; + } + + + double FrameRound::h() const + { + return 2*mR; + } + + const QString FrameRound::sizeDescription( const Units *units ) const { if ( units->id() == "in" ) @@ -63,6 +94,12 @@ namespace libglabels } + const QPainterPath& FrameRound::path( bool isRotated ) const + { + return mPath; + } + + QGraphicsItem* FrameRound::createMarginGraphicsItem( double size, const QPen& pen ) const { double r = mR - size; diff --git a/libglabels/FrameRound.h b/libglabels/FrameRound.h index 419ffb2..56b6abb 100644 --- a/libglabels/FrameRound.h +++ b/libglabels/FrameRound.h @@ -29,32 +29,24 @@ namespace libglabels class FrameRound : public Frame { + public: - FrameRound( double r, - double waste, - QString id = "0" ) - : mR(r), mWaste(waste), Frame(id) - { - mPath.addEllipse( 0, 0, 2*mR, 2*mR ); - } + FrameRound( double r, double waste, QString id = "0" ); - FrameRound( const FrameRound &other ) - : mR(other.mR), mWaste(other.mWaste), mPath(other.mPath), Frame(other) - { - } + FrameRound( const FrameRound &other ); - Frame *dup() const { return new FrameRound( *this ); } + Frame *dup() const; - inline double r() const { return mR; } - inline double waste() const { return mWaste; } + double r() const; + double waste() const; - double w() const { return 2*mR; } - double h() const { return 2*mR; } + double w() const; + double h() const; const QString sizeDescription( const Units *units ) const; bool isSimilarTo( Frame *other ) const; - const QPainterPath &path( bool isRotated ) const { return mPath; } + const QPainterPath &path( bool isRotated ) const; QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const; @@ -68,4 +60,8 @@ namespace libglabels } + +#include "FrameRound.inl" + + #endif // libglabels_FrameRound_h diff --git a/libglabels/FrameRound.inl b/libglabels/FrameRound.inl new file mode 100644 index 0000000..2d501f1 --- /dev/null +++ b/libglabels/FrameRound.inl @@ -0,0 +1,36 @@ +/* FrameRound.inl + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + + +namespace libglabels +{ + + inline double FrameRound::r() const + { + return mR; + } + + + inline double FrameRound::waste() const + { + return mWaste; + } + +} diff --git a/libglabels/Layout.cpp b/libglabels/Layout.cpp index caff342..261743f 100644 --- a/libglabels/Layout.cpp +++ b/libglabels/Layout.cpp @@ -28,6 +28,19 @@ namespace libglabels { + Layout::Layout( int nx, int ny, double x0, double y0, double dx, double dy ) + : mNx(nx), mNy(ny), mX0(x0), mY0(y0), mDx(dx), mDy(dy) + { + } + + + Layout::Layout( const Layout& other ) + : mNx(other.mNx), mNy(other.mNy), mX0(other.mX0), mY0(other.mY0), + mDx(other.mDx), mDy(other.mDy) + { + } + + bool Layout::isSimilarTo( const Layout *other ) { return ( (mNx == other->mNx) && @@ -38,4 +51,11 @@ namespace libglabels (fabs(mDy - other->mDy) < Constants::EPSILON) ); } + + Layout* Layout::dup() const + { + Layout *other = new Layout( *this ); + return other; + } + } diff --git a/libglabels/Layout.h b/libglabels/Layout.h index 6532f86..b1c37cf 100644 --- a/libglabels/Layout.h +++ b/libglabels/Layout.h @@ -27,33 +27,24 @@ namespace libglabels class Layout { + public: - Layout( int nx, int ny, double x0, double y0, double dx, double dy ) - : mNx(nx), mNy(ny), mX0(x0), mY0(y0), mDx(dx), mDy(dy) - { - } + Layout( int nx, int ny, double x0, double y0, double dx, double dy ); - Layout( const Layout &other ) - : mNx(other.mNx), mNy(other.mNy), mX0(other.mX0), mY0(other.mY0), mDx(other.mDx), mDy(other.mDy) - { - } + Layout( const Layout &other ); - inline int nx() const { return mNx; } - inline int ny() const { return mNy; } + int nx() const; + int ny() const; - inline double x0() const { return mX0; } - inline double y0() const { return mY0; } + double x0() const; + double y0() const; - inline double dx() const { return mDx; } - inline double dy() const { return mDy; } + double dx() const; + double dy() const; bool isSimilarTo( const Layout *other ); - inline Layout *dup() const - { - Layout *other = new Layout( *this ); - return other; - } + Layout* dup() const; private: @@ -63,8 +54,13 @@ namespace libglabels double mY0; double mDx; double mDy; + }; } + +#include "Layout.inl" + + #endif // libglabels_Layout_h diff --git a/libglabels/Layout.inl b/libglabels/Layout.inl new file mode 100644 index 0000000..643dc9f --- /dev/null +++ b/libglabels/Layout.inl @@ -0,0 +1,60 @@ +/* Layout.inl + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + + +namespace libglabels +{ + + inline int Layout::nx() const + { + return mNx; + } + + + inline int Layout::ny() const + { + return mNy; + } + + + inline double Layout::x0() const + { + return mX0; + } + + + inline double Layout::y0() const + { + return mY0; + } + + + inline double Layout::dx() const + { + return mDx; + } + + + inline double Layout::dy() const + { + return mDy; + } + +} diff --git a/libglabels/Markup.cpp b/libglabels/Markup.cpp index 87b36f9..7626e4a 100644 --- a/libglabels/Markup.cpp +++ b/libglabels/Markup.cpp @@ -20,3 +20,111 @@ #include "Markup.h" + +namespace libglabels +{ + + MarkupMargin::MarkupMargin( double size ) + : mSize(size) + { + } + + + Markup* MarkupMargin::dup() const + { + return new MarkupMargin( mSize ); + } + + + QGraphicsItem* MarkupMargin::createGraphicsItem( const Frame* frame, const QPen& pen ) const + { + return frame->createMarginGraphicsItem( mSize, pen ); + } + + + MarkupLine::MarkupLine( double x1, double y1, double x2, double y2 ) + : mX1(x1), mY1(y1), mX2(x2), mY2(y2) + { + } + + + Markup* MarkupLine::dup() const + { + return new MarkupLine( mX1, mY1, mX2, mY2 ); + } + + + QGraphicsItem* MarkupLine::createGraphicsItem( const Frame* frame, const QPen& pen ) const + { + QGraphicsLineItem* item = new QGraphicsLineItem( mX1, mY1, mX2, mY2 ); + item->setPen( pen ); + + return item; + } + + + MarkupRect::MarkupRect( double x1, double y1, double w, double h, double r ) + : mX1(x1), mY1(y1), mW(w), mH(h), mR(r) + { + } + + + Markup* MarkupRect::dup() const + { + return new MarkupRect( mX1, mY1, mW, mH, mR ); + } + + + QGraphicsItem* MarkupRect::createGraphicsItem( const Frame* frame, const QPen& pen ) const + { + QPainterPath path; + path.addRoundedRect( mX1, mY1, mW, mH, mR, mR ); + + QGraphicsPathItem* item = new QGraphicsPathItem( path ); + item->setPen( pen ); + + return item; + } + + + MarkupEllipse::MarkupEllipse( double x1, double y1, double w, double h ) + : mX1(x1), mY1(y1), mW(w), mH(h) + { + } + + + Markup* MarkupEllipse::dup() const + { + return new MarkupEllipse( mX1, mY1, mW, mH ); + } + + + QGraphicsItem* MarkupEllipse::createGraphicsItem( const Frame* frame, const QPen& pen ) const + { + QGraphicsEllipseItem* item = new QGraphicsEllipseItem( mX1, mY1, mW, mH ); + item->setPen( pen ); + + return item; + } + + + MarkupCircle::MarkupCircle( double x0, double y0, double r ) + : mX0(x0), mY0(y0), mR(r) + { + } + + Markup* MarkupCircle::dup() const + { + return new MarkupCircle( mX0, mY0, mR ); + } + + + QGraphicsItem* MarkupCircle::createGraphicsItem( const Frame* frame, const QPen& pen ) const + { + QGraphicsEllipseItem* item = new QGraphicsEllipseItem( mX0-mR, mY0-mR, 2*mR, 2*mR ); + item->setPen( pen ); + + return item; + } + +} diff --git a/libglabels/Markup.h b/libglabels/Markup.h index 6c2b9b3..4f25819 100644 --- a/libglabels/Markup.h +++ b/libglabels/Markup.h @@ -33,7 +33,7 @@ namespace libglabels class Markup { public: - virtual Markup *dup() const = 0; + virtual Markup* dup() const = 0; virtual QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const = 0; }; @@ -41,18 +41,13 @@ namespace libglabels class MarkupMargin : public Markup { public: - MarkupMargin( double size ) : mSize(size) - { - } + MarkupMargin( double size ); - inline double size() const { return mSize; } + double size() const; - Markup *dup() const { return new MarkupMargin( mSize ); } + Markup* dup() const; - QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const - { - return frame->createMarginGraphicsItem( mSize, pen ); - } + QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const; private: double mSize; @@ -62,24 +57,16 @@ namespace libglabels class MarkupLine : public Markup { public: - MarkupLine( double x1, double y1, double x2, double y2 ) : mX1(x1), mY1(y1), mX2(x2), mY2(y2) - { - } + MarkupLine( double x1, double y1, double x2, double y2 ); - inline double x1() const { return mX1; } - inline double y1() const { return mY1; } - inline double x2() const { return mX2; } - inline double y2() const { return mY2; } + double x1() const; + double y1() const; + double x2() const; + double y2() const; - Markup *dup() const { return new MarkupLine( mX1, mY1, mX2, mY2 ); } + Markup* dup() const; - QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const - { - QGraphicsLineItem* item = new QGraphicsLineItem( mX1, mY1, mX2, mY2 ); - item->setPen( pen ); - - return item; - } + QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const; private: double mX1; @@ -92,29 +79,17 @@ namespace libglabels class MarkupRect : public Markup { public: - MarkupRect( double x1, double y1, double w, double h, double r ) - : mX1(x1), mY1(y1), mW(w), mH(h), mR(r) - { - } + MarkupRect( double x1, double y1, double w, double h, double r ); - inline double x1() const { return mX1; } - inline double y1() const { return mY1; } - inline double w() const { return mW; } - inline double h() const { return mH; } - inline double r() const { return mR; } + double x1() const; + double y1() const; + double w() const; + double h() const; + double r() const; - Markup *dup() const { return new MarkupRect( mX1, mY1, mW, mH, mR ); } + Markup* dup() const; - QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const - { - QPainterPath path; - path.addRoundedRect( mX1, mY1, mW, mH, mR, mR ); - - QGraphicsPathItem* item = new QGraphicsPathItem( path ); - item->setPen( pen ); - - return item; - } + QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const; private: double mX1; @@ -128,25 +103,16 @@ namespace libglabels class MarkupEllipse : public Markup { public: - MarkupEllipse( double x1, double y1, double w, double h ) - : mX1(x1), mY1(y1), mW(w), mH(h) - { - } + MarkupEllipse( double x1, double y1, double w, double h ); - inline double x1() const { return mX1; } - inline double y1() const { return mY1; } - inline double w() const { return mW; } - inline double h() const { return mH; } + double x1() const; + double y1() const; + double w() const; + double h() const; - Markup *dup() const { return new MarkupEllipse( mX1, mY1, mW, mH ); } + Markup* dup() const; - QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const - { - QGraphicsEllipseItem* item = new QGraphicsEllipseItem( mX1, mY1, mW, mH ); - item->setPen( pen ); - - return item; - } + QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const; private: double mX1; @@ -159,24 +125,15 @@ namespace libglabels class MarkupCircle : public Markup { public: - MarkupCircle( double x0, double y0, double r ) - : mX0(x0), mY0(y0), mR(r) - { - } + MarkupCircle( double x0, double y0, double r ); - inline double x0() const { return mX0; } - inline double y0() const { return mY0; } - inline double r() const { return mR; } + double x0() const; + double y0() const; + double r() const; - Markup *dup() const { return new MarkupCircle( mX0, mY0, mR ); } + Markup* dup() const; - QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const - { - QGraphicsEllipseItem* item = new QGraphicsEllipseItem( mX0-mR, mY0-mR, 2*mR, 2*mR ); - item->setPen( pen ); - - return item; - } + QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const; private: double mX0; @@ -187,4 +144,8 @@ namespace libglabels } + +#include "Markup.inl" + + #endif // libglabels_Markup_h diff --git a/libglabels/Markup.inl b/libglabels/Markup.inl new file mode 100644 index 0000000..4254973 --- /dev/null +++ b/libglabels/Markup.inl @@ -0,0 +1,47 @@ +/* Markup.inl + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + + +namespace libglabels +{ + + inline double 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 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 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 double MarkupCircle::x0() const { return mX0; } + inline double MarkupCircle::y0() const { return mY0; } + inline double MarkupCircle::r() const { return mR; } + +} diff --git a/libglabels/MiniPreviewPixmap.cpp b/libglabels/MiniPreviewPixmap.cpp index 5dcea5b..38af3f8 100644 --- a/libglabels/MiniPreviewPixmap.cpp +++ b/libglabels/MiniPreviewPixmap.cpp @@ -38,6 +38,18 @@ namespace namespace libglabels { + MiniPreviewPixmap::MiniPreviewPixmap() + { + } + + + 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 ) { fill( Qt::transparent ); diff --git a/libglabels/MiniPreviewPixmap.h b/libglabels/MiniPreviewPixmap.h index c954bfc..fc93318 100644 --- a/libglabels/MiniPreviewPixmap.h +++ b/libglabels/MiniPreviewPixmap.h @@ -34,22 +34,19 @@ namespace libglabels class MiniPreviewPixmap : public QPixmap { + public: - MiniPreviewPixmap() - { - } + MiniPreviewPixmap(); - MiniPreviewPixmap( const Template *tmplate, int width, int height ) - : QPixmap( width, height ) - { - draw( tmplate, width, 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 ); + }; } diff --git a/libglabels/Paper.cpp b/libglabels/Paper.cpp index 938f368..30ecb7b 100644 --- a/libglabels/Paper.cpp +++ b/libglabels/Paper.cpp @@ -19,3 +19,14 @@ */ #include "Paper.h" + + +namespace libglabels +{ + + Paper::Paper( const QString& id, const QString& name, double width, double height, const QString& pwgSize ) + : mId(id), mName(name), mWidth(width), mHeight(height), mPwgSize(pwgSize) + { + } + +} diff --git a/libglabels/Paper.h b/libglabels/Paper.h index e8162e5..76af162 100644 --- a/libglabels/Paper.h +++ b/libglabels/Paper.h @@ -31,29 +31,22 @@ namespace libglabels class Paper { public: - Paper( const QString &id, - const QString &name, - double width, - double height, - const QString &pwgSize ) : mId(id), mName(name), mWidth(width), mHeight(height), mPwgSize(pwgSize) - { - } + Paper( const QString& id, const QString& name, double width, double height, const QString& pwgSize ); - inline const QString &id() const { return mId; } - - inline const QString &name() const { return mName; } + inline const QString& id() const; + inline const QString& name() const; /* Width (in points) */ - inline double width() const { return mWidth; } + inline double width() const; /* Height (in points) */ - inline double height() const { return mHeight; } + inline double height() const; /* PWG 5101.1-2002 size name */ - inline QString pwgSize() const { return mPwgSize; } + inline QString pwgSize() const; - inline bool isSizeIso() const { return mPwgSize.startsWith( "iso_" ); } - inline bool isSizeUs() const { return mPwgSize.startsWith( "na_" ); } + inline bool isSizeIso() const; + inline bool isSizeUs() const; private: QString mId; @@ -65,4 +58,8 @@ namespace libglabels } + +#include "Paper.inl" + + #endif // libglabels_Paper_h diff --git a/libglabels/Paper.inl b/libglabels/Paper.inl new file mode 100644 index 0000000..82b40dd --- /dev/null +++ b/libglabels/Paper.inl @@ -0,0 +1,36 @@ +/* Paper.inl + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + + +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 QString Paper::pwgSize() const { return mPwgSize; } + + inline bool Paper::isSizeIso() const { return mPwgSize.startsWith( "iso_" ); } + inline bool Paper::isSizeUs() const { return mPwgSize.startsWith( "na_" ); } + +} diff --git a/libglabels/Point.cpp b/libglabels/Point.cpp index b8ebefe..32dade6 100644 --- a/libglabels/Point.cpp +++ b/libglabels/Point.cpp @@ -24,6 +24,16 @@ namespace libglabels { + Point::Point() : mX(0), mY(0) + { + } + + + Point::Point( double x, double y ) : mX(x), mY(y) + { + } + + bool Point::operator<( const Point &other ) const { if ( mY < other.mY ) diff --git a/libglabels/Point.h b/libglabels/Point.h index 4a18aea..8514e66 100644 --- a/libglabels/Point.h +++ b/libglabels/Point.h @@ -28,16 +28,12 @@ namespace libglabels class Point { public: - Point() : mX(0), mY(0) - { - } + Point(); + + Point( double x, double y ); - Point( double x, double y ) : mX(x), mY(y) - { - } - - inline double x() const { return mX; } - inline double y() const { return mY; } + double x() const; + double y() const; bool operator<( const Point &other ) const; @@ -49,4 +45,8 @@ namespace libglabels } + +#include "Point.inl" + + #endif // libglabels_Point_h diff --git a/libglabels/Point.inl b/libglabels/Point.inl new file mode 100644 index 0000000..8a7cef8 --- /dev/null +++ b/libglabels/Point.inl @@ -0,0 +1,28 @@ +/* Point.inl + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + + +namespace libglabels +{ + + inline double Point::x() const { return mX; } + inline double Point::y() const { return mY; } + +} diff --git a/libglabels/Template.cpp b/libglabels/Template.cpp index 424db36..f01076f 100644 --- a/libglabels/Template.cpp +++ b/libglabels/Template.cpp @@ -28,10 +28,10 @@ namespace libglabels { - Template::Template( const QString &brand, - const QString &part, - const QString &description, - const QString &paperId, + Template::Template( const QString& brand, + const QString& part, + const QString& description, + const QString& paperId, double pageWidth = 0, double pageHeight = 0 ) : mBrand(brand), @@ -48,14 +48,14 @@ namespace libglabels if ( Db::isPaperIdKnown( paperId ) ) { - const Paper *paper = Db::lookupPaperFromId( paperId ); + const Paper* paper = Db::lookupPaperFromId( paperId ); mIsSizeIso = paper->isSizeIso(); mIsSizeUs = paper->isSizeUs(); } } - Template::Template( const Template &other ) + Template::Template( const Template& other ) { mBrand = other.mBrand; mPart = other.mPart; @@ -69,7 +69,7 @@ namespace libglabels mName = other.mName; mProductUrl = other.mProductUrl; - foreach ( Frame *frame, other.mFrames ) + foreach ( Frame* frame, other.mFrames ) { addFrame( frame ); } @@ -81,8 +81,14 @@ namespace libglabels } + Template* Template::dup() const + { + return new Template( *this ); + } + + // Generic full page template - Template *Template::fullPage( const QString &paperId ) + Template* Template::fullPage( const QString& paperId ) { // TODO return NULL; @@ -90,14 +96,14 @@ namespace libglabels // From equivalent part number - Template *Template::fromEquiv( const QString &brand, - const QString &part, - const QString &equivPart ) + Template* Template::fromEquiv( const QString& brand, + const QString& part, + const QString& equivPart ) { - const Template *other = Db::lookupTemplateFromBrandPart( brand, equivPart ); + const Template* other = Db::lookupTemplateFromBrandPart( brand, equivPart ); if ( other != NULL ) { - Template *tmplate = other->dup(); + Template* tmplate = other->dup(); tmplate->mPart = part; tmplate->mEquivPart = equivPart; @@ -117,13 +123,13 @@ namespace libglabels } - void Template::addCategory( const QString &categoryId ) + void Template::addCategory( const QString& categoryId ) { mCategoryIds << categoryId; } - void Template::addFrame( Frame *frame ) + void Template::addFrame( Frame* frame ) { mFrames << frame; } @@ -135,13 +141,13 @@ namespace libglabels } - bool Template::operator==( const Template &other ) const + bool Template::operator==( const Template& other ) const { return (mBrand == other.mBrand) && (mPart == other.mPart); } - bool Template::hasCategory( const QString &categoryId ) const + bool Template::hasCategory( const QString& categoryId ) const { foreach ( QString testCategoryId, mCategoryIds ) { @@ -155,7 +161,7 @@ namespace libglabels } - bool Template::isSimilarTo( const Template *other ) const + bool Template::isSimilarTo( const Template* other ) const { // Does page size match? if ( (mPaperId != other->mPaperId) || @@ -166,18 +172,18 @@ namespace libglabels } // Are frames similar - Frame *frame1 = mFrames.first(); - Frame *frame2 = other->mFrames.first(); + Frame* frame1 = mFrames.first(); + Frame* frame2 = other->mFrames.first(); if ( !frame1->isSimilarTo( frame2 ) ) { return false; } // Are they layed out similarly? - foreach ( Layout *layout1, frame1->layouts() ) + foreach ( Layout* layout1, frame1->layouts() ) { bool matchFound = false; - foreach ( Layout *layout2, frame2->layouts() ) + foreach ( Layout* layout2, frame2->layouts() ) { if ( layout1->isSimilarTo(layout2) ) { diff --git a/libglabels/Template.h b/libglabels/Template.h index 8d468e9..97cbf7b 100644 --- a/libglabels/Template.h +++ b/libglabels/Template.h @@ -46,58 +46,57 @@ namespace libglabels public: - Template( const QString &brand, - const QString &part, - const QString &description, - const QString &paperId, + Template( const QString& brand, + const QString& part, + const QString& description, + const QString& paperId, double pageWidth, double pageHeight ); - Template( const Template &other ); - - inline Template *dup() const { return new Template( *this ); } + Template( const Template& other ); + Template* dup() const; // Generic full page template - static Template *fullPage( const QString &paperId ); + static Template* fullPage( const QString& paperId ); // From equivalent part number - static Template *fromEquiv( const QString &brand, - const QString &part, - const QString &equivPart ); + static Template* fromEquiv( const QString& brand, + const QString& part, + const QString& equivPart ); - inline const QString &brand() const { return mBrand; } - inline const QString &part() const { return mPart; } - inline const QString &description() const { return mDescription; } + const QString& brand() const; + const QString& part() const; + const QString& description() const; - inline const QString &paperId() const { return mPaperId; } - inline double pageWidth() const { return mPageWidth; } - inline double pageHeight() const { return mPageHeight; } - inline bool isSizeIso() const { return mIsSizeIso; } - inline bool isSizeUs() const { return mIsSizeUs; } - inline bool isSizeOther() const { return !mIsSizeIso && !mIsSizeUs; } + const QString& paperId() const; + double pageWidth() const; + double pageHeight() const; + bool isSizeIso() const; + bool isSizeUs() const; + bool isSizeOther() const; - inline const QString &equivPart() const { return mEquivPart; } - inline void setEquivPart( const QString &value ) { mEquivPart = value; } + const QString& equivPart() const; + void setEquivPart( const QString& value ); - inline const QString &productUrl() const { return mProductUrl; } - inline void setProductUrl( const QString &value ) { mProductUrl = value; } + const QString& productUrl() const; + void setProductUrl( const QString& value ); - inline const QString &name() const { return mName; } + const QString& name() const; - void addCategory( const QString &categoryId ); - void addFrame( Frame *frame ); + void addCategory( const QString& categoryId ); + void addFrame( Frame* frame ); void initPreview(); - inline const MiniPreviewPixmap &preview() const { return mPreview; } + const MiniPreviewPixmap& preview() const; - inline const QList &frames() const { return mFrames; } + const QList& frames() const; - bool operator==( const Template &other ) const; + bool operator==( const Template& other ) const; - bool hasCategory( const QString &categoryId ) const; - bool isSimilarTo( const Template *other ) const; + bool hasCategory( const QString& categoryId ) const; + bool isSimilarTo( const Template* other ) const; private: @@ -124,4 +123,8 @@ namespace libglabels } + +#include "Template.inl" + + #endif // libglabels_Template_h diff --git a/libglabels/Template.inl b/libglabels/Template.inl new file mode 100644 index 0000000..29bfa85 --- /dev/null +++ b/libglabels/Template.inl @@ -0,0 +1,48 @@ +/* Template.inl + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + + +namespace libglabels +{ + + inline const QString& Template::brand() const { return mBrand; } + inline const QString& Template::part() const { return mPart; } + 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 bool Template::isSizeIso() const { return mIsSizeIso; } + inline bool Template::isSizeUs() const { return mIsSizeUs; } + inline bool Template::isSizeOther() const { return !mIsSizeIso && !mIsSizeUs; } + + inline const QString& Template::equivPart() const { return mEquivPart; } + inline void Template::setEquivPart( const QString& value ) { mEquivPart = value; } + + inline const QString& Template::productUrl() const { return mProductUrl; } + inline void Template::setProductUrl( const QString& value ) { mProductUrl = value; } + + inline const QString& Template::name() const { return mName; } + + inline const MiniPreviewPixmap& Template::preview() const { return mPreview; } + + inline const QList& Template::frames() const { return mFrames; } + +} diff --git a/libglabels/Units.cpp b/libglabels/Units.cpp index 1e8f9f8..3d7cf5b 100644 --- a/libglabels/Units.cpp +++ b/libglabels/Units.cpp @@ -36,6 +36,13 @@ namespace namespace libglabels { + Units::Units( const QString &id, const QString &name, double pointsPerUnit ) + : mId(id), mName(name), mPointsPerUnit(pointsPerUnit) + { + mUnitsPerPoint = 1.0 / mPointsPerUnit; + } + + Units *Units::fromId( const QString &id ) { if ( id == "pt" ) diff --git a/libglabels/Units.h b/libglabels/Units.h index cfa570e..9d75ab4 100644 --- a/libglabels/Units.h +++ b/libglabels/Units.h @@ -36,22 +36,14 @@ namespace libglabels private: - Units( const QString &id, const QString &name, double pointsPerUnit ) - : mId(id), mName(name), mPointsPerUnit(pointsPerUnit) - { - mUnitsPerPoint = 1.0 / mPointsPerUnit; - } - + Units( const QString &id, const QString &name, double pointsPerUnit ); public: - inline QString id() const { return mId; } - - inline QString name() const { return mName; } - - inline double pointsPerUnit() const { return mPointsPerUnit; } - - inline double unitsPerPoint() const { return mUnitsPerPoint; } + QString id() const; + QString name() const; + double pointsPerUnit() const; + double unitsPerPoint() const; static Units *fromId( const QString &id ); @@ -78,4 +70,8 @@ namespace libglabels } + +#include "Units.inl" + + #endif // libglabels_Units_h diff --git a/libglabels/Units.inl b/libglabels/Units.inl new file mode 100644 index 0000000..0a5c285 --- /dev/null +++ b/libglabels/Units.inl @@ -0,0 +1,33 @@ +/* Units.inl + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + + +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; } + +} diff --git a/libglabels/Vendor.cpp b/libglabels/Vendor.cpp index 4b5c0b3..864feb0 100644 --- a/libglabels/Vendor.cpp +++ b/libglabels/Vendor.cpp @@ -19,3 +19,13 @@ */ #include "Vendor.h" + + +namespace libglabels +{ + + Vendor::Vendor( const QString &name, const QString &url ) : mName(name), mUrl(url) + { + } + +} diff --git a/libglabels/Vendor.h b/libglabels/Vendor.h index 9be5646..afe8df8 100644 --- a/libglabels/Vendor.h +++ b/libglabels/Vendor.h @@ -31,13 +31,10 @@ namespace libglabels class Vendor { public: - Vendor( const QString &name, const QString &url ) : mName(name), mUrl(url) - { - } + Vendor( const QString &name, const QString &url ); - inline const QString &name() const { return mName; } - - inline const QString &url() const { return mUrl; } + const QString& name() const; + const QString& url() const; private: QString mName; @@ -46,4 +43,8 @@ namespace libglabels } + +#include "Vendor.inl" + + #endif // libglabels_Vendor_h diff --git a/libglabels/Vendor.inl b/libglabels/Vendor.inl new file mode 100644 index 0000000..089f808 --- /dev/null +++ b/libglabels/Vendor.inl @@ -0,0 +1,28 @@ +/* Vendor.inl + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + + +namespace libglabels +{ + + inline const QString& Vendor::name() const { return mName; } + inline const QString& Vendor::url() const { return mUrl; } + +} diff --git a/libglabels/XmlUtil.cpp b/libglabels/XmlUtil.cpp index 66b3b86..f504d0e 100644 --- a/libglabels/XmlUtil.cpp +++ b/libglabels/XmlUtil.cpp @@ -27,7 +27,31 @@ namespace libglabels { - Units *XmlUtil::mDefaultUnits; + Units* XmlUtil::mDefaultUnits; + + + XmlUtil::XmlUtil() + { + mDefaultUnits = Units::point(); + } + + + void XmlUtil::init() + { + static XmlUtil* xmlUtil = new XmlUtil(); + } + + + const Units* XmlUtil::defaultUnits() + { + return mDefaultUnits; + } + + + void XmlUtil::setDefaultUnits( Units* defaultUnits ) + { + mDefaultUnits = defaultUnits; + } QString XmlUtil::getStringAttr( const QDomElement& node, @@ -186,9 +210,9 @@ namespace libglabels return default_value; } - Units *units = Units::fromId( unitsString ); + Units* units = Units::fromId( unitsString ); - return value * units->pointsPerUnit(); + return value* units->pointsPerUnit(); } return default_value; diff --git a/libglabels/XmlUtil.h b/libglabels/XmlUtil.h index 98b8a14..8ea9b7e 100644 --- a/libglabels/XmlUtil.h +++ b/libglabels/XmlUtil.h @@ -34,24 +34,15 @@ namespace libglabels class XmlUtil { private: - XmlUtil() - { - mDefaultUnits = Units::point(); - } + XmlUtil(); + public: - static void init() - { - static XmlUtil *xmlUtil = new XmlUtil(); - } + static void init(); - static const Units *defaultUnits() { return mDefaultUnits; } - - static void setDefaultUnits( Units *defaultUnits ) - { - mDefaultUnits = defaultUnits; - } + static const Units* defaultUnits(); + static void setDefaultUnits( Units* defaultUnits ); static QString getStringAttr( const QDomElement& node, const QString& name, @@ -106,7 +97,7 @@ namespace libglabels double value ); private: - static Units *mDefaultUnits; + static Units* mDefaultUnits; };