Refactor frame and markup code to use paths.

- CD frames are currently broken.
This commit is contained in:
Jim Evins
2015-08-12 01:20:52 -04:00
parent 0ad6caeeca
commit 721746007c
13 changed files with 110 additions and 164 deletions
+20 -50
View File
@@ -32,49 +32,22 @@ 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;
// 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();
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 );
// 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 );
}
// Translate to account for offset with clipped business card CDs
mPath.translate( w/2 - mR1, h/2 - mR1 );
}
@@ -103,7 +76,7 @@ namespace libglabels
}
const QString FrameCd::sizeDescription( const Units *units ) const
const QString FrameCd::sizeDescription( const Units* units ) const
{
if ( units->id() == "in" )
{
@@ -124,7 +97,7 @@ namespace libglabels
}
bool FrameCd::isSimilarTo( Frame *other ) const
bool FrameCd::isSimilarTo( Frame* other ) const
{
if ( FrameCd *otherCd = dynamic_cast<FrameCd*>(other) )
{
@@ -140,13 +113,13 @@ namespace libglabels
}
const QPainterPath& FrameCd::path( bool isRotated ) const
const QPainterPath& FrameCd::path() const
{
return isRotated ? mRotatedPath : mPath;
return mPath;
}
QGraphicsItem* FrameCd::createMarginGraphicsItem( double size, const QPen& pen ) const
QPainterPath FrameCd::marginPath( double size ) const
{
double r1 = mR1 - size;
double r2 = mR2 + size;
@@ -167,13 +140,10 @@ namespace libglabels
// 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)
// Translate to account for offset with clipped business card CDs
path.translate( mW/2 - r1, mH/2 - r1 );
QGraphicsPathItem* item = new QGraphicsPathItem( path );
item->setPen( pen );
return item;
return path;
}
}