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
+20
View File
@@ -605,6 +605,26 @@ glabels::View::drawGridLayer( QPainter* painter )
void void
glabels::View::drawMarkupLayer( QPainter* painter ) glabels::View::drawMarkupLayer( QPainter* painter )
{ {
if ( mMarkupVisible )
{
painter->save();
painter->setBrush( Qt::NoBrush );
painter->setPen( QPen( markupLineColor ) );
if ( mModel->rotate() )
{
painter->rotate( -90 );
painter->translate( -mModel->frame()->w(), 0 );
}
foreach( libglabels::Markup* markup, mModel->frame()->markups() )
{
painter->drawPath( markup->path() );
}
painter->restore();
}
} }
+33 -26
View File
@@ -24,6 +24,7 @@
#include "StrUtil.h" #include "StrUtil.h"
#include "privateConstants.h" #include "privateConstants.h"
#include <QtDebug>
namespace libglabels namespace libglabels
@@ -32,22 +33,25 @@ namespace libglabels
FrameCd::FrameCd( double r1, double r2, double w, double h, double waste, QString id ) 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) : 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 wReal = (mW == 0) ? 2*mR1 : mW;
double theta1 = acos( w / (2*mR1) ) * 180/M_PI; double hReal = (mH == 0) ? 2*mR1 : mH;
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 ); * Construct outer subpath (may be clipped if it's a business card CD)
mPath.arcTo( 0, 0, 2*mR1, 2*mR1, 180-theta2, theta2-theta1 ); */
mPath.arcTo( 0, 0, 2*mR1, 2*mR1, 180+theta1, theta2-theta1 ); QPainterPath outerPath;
mPath.arcTo( 0, 0, 2*mR1, 2*mR1, 360-theta2, theta2-theta1 ); 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(); mPath.closeSubpath();
// Inner path (hole) /*
mPath.addEllipse( mR1-mR2, mR1-mR2, 2*mR2, 2*mR2 ); * Add inner subpath
*/
// Translate to account for offset with clipped business card CDs mPath.addEllipse( wReal/2 - r2, hReal/2 - r2, 2*r2, 2*r2 );
mPath.translate( w/2 - mR1, h/2 - mR1 );
} }
@@ -121,27 +125,30 @@ namespace libglabels
QPainterPath FrameCd::marginPath( double size ) const 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 r1 = mR1 - size;
double r2 = mR2 + size; double r2 = mR2 + size;
QPainterPath path; 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; * Construct outer subpath (may be clipped if it's a business card CD)
double theta2 = asin( (mH-2*size) / (2*r1) ) * 180/M_PI; */
QPainterPath outerPath;
outerPath.addEllipse( wReal/2 - r1, hReal/2 - r1, 2*r1, 2*r1 );
path.arcMoveTo( 0, 0, 2*r1, 2*r1, theta1 ); QPainterPath clipPath;
path.arcTo( 0, 0, 2*r1, 2*r1, theta1, theta2-theta1 ); clipPath.addRect( size, size, wReal-2*size, hReal-2*size );
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.addPath( outerPath & clipPath );
path.arcTo( 0, 0, 2*r1, 2*r1, 360-theta2, theta2-theta1 );
path.closeSubpath(); path.closeSubpath();
// Inner path (hole) /*
path.addEllipse( r1-r2, r1-r2, 2*r2, 2*r2 ); * Add inner subpath
*/
// Translate to account for offset with clipped business card CDs path.addEllipse( wReal/2 - r2, hReal/2 - r2, 2*r2, 2*r2 );
path.translate( mW/2 - r1, mH/2 - r1 );
return path; return path;
} }