Added markup layer to view. Fixed CD frame path problems.

This commit is contained in:
Jim Evins
2015-08-12 10:06:03 -04:00
parent 721746007c
commit 527d2e73dc
2 changed files with 53 additions and 26 deletions
+33 -26
View File
@@ -24,6 +24,7 @@
#include "StrUtil.h"
#include "privateConstants.h"
#include <QtDebug>
namespace libglabels
@@ -32,22 +33,25 @@ 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)
{
// 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;
double wReal = (mW == 0) ? 2*mR1 : mW;
double hReal = (mH == 0) ? 2*mR1 : mH;
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 );
/*
* 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 );
QPainterPath clipPath;
clipPath.addRect( 0, 0, wReal, hReal );
mPath.addPath( outerPath & clipPath );
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 );
/*
* Add inner subpath
*/
mPath.addEllipse( wReal/2 - r2, hReal/2 - r2, 2*r2, 2*r2 );
}
@@ -121,27 +125,30 @@ namespace libglabels
QPainterPath FrameCd::marginPath( double size ) const
{
double wReal = (mW == 0) ? 2*mR1 : mW;
double hReal = (mH == 0) ? 2*mR1 : mH;
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;
/*
* 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 );
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 );
QPainterPath clipPath;
clipPath.addRect( size, size, wReal-2*size, hReal-2*size );
path.addPath( outerPath & clipPath );
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
path.translate( mW/2 - r1, mH/2 - r1 );
/*
* Add inner subpath
*/
path.addEllipse( wReal/2 - r2, hReal/2 - r2, 2*r2, 2*r2 );
return path;
}