Added markup implementation.

This commit is contained in:
Jim Evins
2013-12-13 22:56:58 -05:00
parent f017af3cac
commit 5c74625a97
14 changed files with 177 additions and 13 deletions
+2
View File
@@ -20,6 +20,8 @@
#include "Frame.h"
#include "Markup.h"
namespace libglabels
{
+4 -1
View File
@@ -25,16 +25,18 @@
#include <QString>
#include <QList>
#include <QPainterPath>
#include <QGraphicsItem>
#include <QVector>
#include "Units.h"
#include "Point.h"
#include "Layout.h"
#include "Markup.h"
namespace libglabels
{
class Markup; // Forward reference
class Frame
{
@@ -68,6 +70,7 @@ namespace libglabels
virtual bool isSimilarTo( Frame *other ) const = 0;
virtual const QPainterPath &path() const = 0;
virtual QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const = 0;
private:
+31
View File
@@ -86,5 +86,36 @@ namespace libglabels
mPath.translate( w()/2 - mR1, h()/2 - mR1 );
}
QGraphicsItem* FrameCd::createMarginGraphicsItem( double size, const QPen& pen ) const
{
double r1 = mR1 - size;
double r2 = mR2 + size;
QPainterPath path;
// Outer path (may be clipped in the case business card type CD)
double theta1 = acos( (mW-2*size) / (2*r1) ) * 180/M_PI;
double theta2 = asin( (mH-2*size) / (2*r1) ) * 180/M_PI;
path.arcMoveTo( 0, 0, 2*r1, 2*r1, theta1 );
path.arcTo( 0, 0, 2*r1, 2*r1, theta1, theta2-theta1 );
path.arcTo( 0, 0, 2*r1, 2*r1, 180-theta2, theta2-theta1 );
path.arcTo( 0, 0, 2*r1, 2*r1, 180+theta1, theta2-theta1 );
path.arcTo( 0, 0, 2*r1, 2*r1, 360-theta2, theta2-theta1 );
path.closeSubpath();
// Inner path (hole)
path.addEllipse( r1-r2, r1-r2, 2*r2, 2*r2 );
// Translate to account for offset with clipped business card CDs (applies to element already drawn)
path.translate( mW/2 - r1, mH/2 - r1 );
QGraphicsPathItem* item = new QGraphicsPathItem( path );
item->setPen( pen );
return item;
}
}
+1
View File
@@ -60,6 +60,7 @@ namespace libglabels
bool isSimilarTo( Frame *other ) const;
const QPainterPath &path() const { return mPath; }
QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const;
private:
+12
View File
@@ -64,5 +64,17 @@ namespace libglabels
return false;
}
QGraphicsItem* FrameEllipse::createMarginGraphicsItem( double size, const QPen& pen ) const
{
double w = mW - 2*size;
double h = mH - 2*size;
QGraphicsEllipseItem* item = new QGraphicsEllipseItem( size, size, w, h );
item->setPen( pen );
return item;
}
}
+1
View File
@@ -55,6 +55,7 @@ namespace libglabels
bool isSimilarTo( Frame *other ) const;
const QPainterPath &path() const { return mPath; }
QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const;
private:
+16
View File
@@ -64,5 +64,21 @@ namespace libglabels
return false;
}
QGraphicsItem* FrameRect::createMarginGraphicsItem( double size, const QPen& pen ) const
{
double w = mW - 2*size;
double h = mH - 2*size;
double r = std::max( mR - size, 0.0 );
QPainterPath path;
path.addRoundedRect( size, size, w, h, r, r );
QGraphicsPathItem* item = new QGraphicsPathItem( path );
item->setPen( pen );
return item;
}
}
+1
View File
@@ -60,6 +60,7 @@ namespace libglabels
bool isSimilarTo( Frame *other ) const;
const QPainterPath &path() const { return mPath; }
QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const;
private:
+11
View File
@@ -62,5 +62,16 @@ namespace libglabels
return false;
}
QGraphicsItem* FrameRound::createMarginGraphicsItem( double size, const QPen& pen ) const
{
double r = mR - size;
QGraphicsEllipseItem* item = new QGraphicsEllipseItem( mR-r, mR-r, 2*r, 2*r );
item->setPen( pen );
return item;
}
}
+1
View File
@@ -55,6 +55,7 @@ namespace libglabels
bool isSimilarTo( Frame *other ) const;
const QPainterPath &path() const { return mPath; }
QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const;
private:
+46 -2
View File
@@ -21,6 +21,11 @@
#ifndef libglabels_Markup_h
#define libglabels_Markup_h
#include <QGraphicsItem>
#include <QPainterPath>
#include "Frame.h"
namespace libglabels
{
@@ -29,6 +34,7 @@ namespace libglabels
{
public:
virtual Markup *dup() const = 0;
virtual QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const = 0;
};
@@ -43,6 +49,11 @@ namespace libglabels
Markup *dup() const { return new MarkupMargin( mSize ); }
QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const
{
return frame->createMarginGraphicsItem( mSize, pen );
}
private:
double mSize;
};
@@ -62,6 +73,14 @@ namespace libglabels
Markup *dup() const { return new MarkupLine( mX1, mY1, mX2, mY2 ); }
QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const
{
QGraphicsLineItem* item = new QGraphicsLineItem( mX1, mY1, mX2, mY2 );
item->setPen( pen );
return item;
}
private:
double mX1;
double mY1;
@@ -86,6 +105,17 @@ namespace libglabels
Markup *dup() const { return new MarkupRect( mX1, mY1, mW, mH, mR ); }
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;
}
private:
double mX1;
double mY1;
@@ -110,6 +140,14 @@ namespace libglabels
Markup *dup() const { return new MarkupEllipse( mX1, mY1, mW, mH ); }
QGraphicsItem* createGraphicsItem( const Frame* frame, const QPen& pen ) const
{
QGraphicsEllipseItem* item = new QGraphicsEllipseItem( mX1, mY1, mW, mH );
item->setPen( pen );
return item;
}
private:
double mX1;
double mY1;
@@ -132,13 +170,19 @@ namespace libglabels
Markup *dup() const { return new MarkupCircle( mX0, mY0, mR ); }
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;
}
private:
double mX0;
double mY0;
double mR;
};
}