diff --git a/glabels/View.cpp b/glabels/View.cpp index f04d837..aa60043 100644 --- a/glabels/View.cpp +++ b/glabels/View.cpp @@ -512,17 +512,18 @@ glabels::View::drawBgLayer( QPainter* painter ) { painter->save(); - QBrush brush( shadowColor ); painter->setBrush( QBrush( shadowColor ) ); + painter->setPen( Qt::NoPen ); painter->translate( shadowOffsetPixels/mZoom, shadowOffsetPixels/mZoom ); - painter->drawPath( mModel->frame()->path() ); + painter->drawPath( mModel->frame()->path( mModel->rotate() ) ); painter->restore(); painter->save(); painter->setBrush( QBrush( labelColor ) ); - painter->drawPath( mModel->frame()->path() ); + painter->setPen( QPen( labelOutlineColor ) ); + painter->drawPath( mModel->frame()->path( mModel->rotate() ) ); painter->restore(); } @@ -554,7 +555,7 @@ glabels::View::drawGridLayer( QPainter* painter ) painter->save(); - painter->setClipPath( mModel->frame()->path() ); + painter->setClipPath( mModel->frame()->path( mModel->rotate() ) ); painter->setPen( QPen( gridLineColor, gridLineWidthPixels/mZoom ) ); diff --git a/libglabels/Frame.h b/libglabels/Frame.h index 1e5590e..9d1e107 100644 --- a/libglabels/Frame.h +++ b/libglabels/Frame.h @@ -69,7 +69,7 @@ namespace libglabels virtual const QString sizeDescription( const Units *units ) const = 0; virtual bool isSimilarTo( Frame *other ) const = 0; - virtual const QPainterPath &path() const = 0; + virtual const QPainterPath &path( bool isRotated = false ) const = 0; virtual QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const = 0; diff --git a/libglabels/FrameCd.cpp b/libglabels/FrameCd.cpp index 652ec49..e17cfa2 100644 --- a/libglabels/FrameCd.cpp +++ b/libglabels/FrameCd.cpp @@ -68,22 +68,49 @@ namespace libglabels void FrameCd::initPath() { - // 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; + // + // 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(); + 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 (applies to element already drawn) - mPath.translate( w()/2 - mR1, h()/2 - mR1 ); + // 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 ); + } } diff --git a/libglabels/FrameCd.h b/libglabels/FrameCd.h index 42b4c5d..33ad04b 100644 --- a/libglabels/FrameCd.h +++ b/libglabels/FrameCd.h @@ -59,7 +59,7 @@ namespace libglabels const QString sizeDescription( const Units *units ) const; bool isSimilarTo( Frame *other ) const; - const QPainterPath &path() const { return mPath; } + const QPainterPath &path( bool isRotated ) const { return isRotated ? mRotatedPath : mPath; } QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const; @@ -73,6 +73,7 @@ namespace libglabels double mWaste; QPainterPath mPath; + QPainterPath mRotatedPath; }; diff --git a/libglabels/FrameEllipse.h b/libglabels/FrameEllipse.h index d25a7bc..1e75243 100644 --- a/libglabels/FrameEllipse.h +++ b/libglabels/FrameEllipse.h @@ -37,6 +37,7 @@ namespace libglabels : mW(w), mH(h), mWaste(waste), Frame(id) { mPath.addEllipse( 0, 0, mW, mH ); + mRotatedPath.addEllipse( 0, 0, mH, mW ); } FrameEllipse( const FrameEllipse &other ) @@ -54,7 +55,7 @@ namespace libglabels const QString sizeDescription( const Units *units ) const; bool isSimilarTo( Frame *other ) const; - const QPainterPath &path() const { return mPath; } + const QPainterPath &path( bool isRotated ) const { return isRotated ? mRotatedPath : mPath; } QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const; @@ -64,6 +65,7 @@ namespace libglabels double mWaste; QPainterPath mPath; + QPainterPath mRotatedPath; }; diff --git a/libglabels/FrameRect.h b/libglabels/FrameRect.h index d927108..82f64fc 100644 --- a/libglabels/FrameRect.h +++ b/libglabels/FrameRect.h @@ -39,6 +39,7 @@ namespace libglabels : 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( const FrameRect &other ) @@ -59,7 +60,7 @@ namespace libglabels const QString sizeDescription( const Units *units ) const; bool isSimilarTo( Frame *other ) const; - const QPainterPath &path() const { return mPath; } + const QPainterPath &path( bool isRotated ) const { return isRotated ? mRotatedPath : mPath; } QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const; @@ -71,6 +72,7 @@ namespace libglabels double mYWaste; QPainterPath mPath; + QPainterPath mRotatedPath; }; diff --git a/libglabels/FrameRound.h b/libglabels/FrameRound.h index 5599aa2..419ffb2 100644 --- a/libglabels/FrameRound.h +++ b/libglabels/FrameRound.h @@ -54,7 +54,7 @@ namespace libglabels const QString sizeDescription( const Units *units ) const; bool isSimilarTo( Frame *other ) const; - const QPainterPath &path() const { return mPath; } + const QPainterPath &path( bool isRotated ) const { return mPath; } QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const;