diff --git a/glabels/PageRenderer.cpp b/glabels/PageRenderer.cpp index a33c430..7bfce3c 100644 --- a/glabels/PageRenderer.cpp +++ b/glabels/PageRenderer.cpp @@ -175,11 +175,12 @@ void PageRenderer::printSimplePage( QPainter* painter, int iPage ) const for ( int i = iStart; i < iEnd; i++ ) { painter->save(); + painter->translate( mOrigins[i].x().pt(), mOrigins[i].y().pt() ); painter->save(); - clipLabel( painter ); + clipLabel( painter ); printLabel( painter, 0 ); painter->restore(); // From before clip @@ -224,7 +225,7 @@ void PageRenderer::printOutline( QPainter* painter ) const void PageRenderer::clipLabel( QPainter* painter ) const { - // TODO: add clipPath() method to frame + painter->setClipPath( mModel->frame()->clipPath() ); } diff --git a/libglabels/Frame.h b/libglabels/Frame.h index 5aa7391..2d4cb6b 100644 --- a/libglabels/Frame.h +++ b/libglabels/Frame.h @@ -66,6 +66,7 @@ namespace glabels virtual bool isSimilarTo( Frame* other ) const = 0; virtual const QPainterPath& path() const = 0; + virtual const QPainterPath& clipPath() const = 0; virtual QPainterPath marginPath( const Distance& size ) const = 0; diff --git a/libglabels/FrameCd.cpp b/libglabels/FrameCd.cpp index 6dce429..5ee209f 100644 --- a/libglabels/FrameCd.cpp +++ b/libglabels/FrameCd.cpp @@ -41,22 +41,54 @@ namespace glabels Distance wReal = (mW == 0) ? 2*mR1 : mW; Distance hReal = (mH == 0) ? 2*mR1 : mH; - /* - * Construct outer subpath (may be clipped if it's a business card CD) - */ - QPainterPath outerPath; - outerPath.addEllipse( (wReal/2 - r1).pt(), (hReal/2 - r1).pt(), 2*r1.pt(), 2*r1.pt() ); + // + // Create path + // + { + /* + * Construct outer subpath (may be clipped if it's a business card CD) + */ + QPainterPath outerPath; + outerPath.addEllipse( (wReal/2 - r1).pt(), (hReal/2 - r1).pt(), 2*r1.pt(), 2*r1.pt() ); - QPainterPath clipPath; - clipPath.addRect( 0, 0, wReal.pt(), hReal.pt() ); + QPainterPath clipPath; + clipPath.addRect( 0, 0, wReal.pt(), hReal.pt() ); - mPath.addPath( outerPath & clipPath ); - mPath.closeSubpath(); + mPath.addPath( outerPath & clipPath ); + mPath.closeSubpath(); - /* - * Add inner subpath - */ - mPath.addEllipse( (wReal/2 - r2).pt(), (hReal/2 - r2).pt(), 2*r2.pt(), 2*r2.pt() ); + /* + * Add inner subpath + */ + mPath.addEllipse( (wReal/2 - r2).pt(), (hReal/2 - r2).pt(), 2*r2.pt(), 2*r2.pt() ); + } + + // + // Create clip path + // + { + Distance r1Clip = mR1 + mWaste; + Distance r2Clip = mR2 - mWaste; + Distance wClip = (mW == 0) ? 2*r1Clip : mW + 2*mWaste; + Distance hClip = (mH == 0) ? 2*r1Clip : mH + 2*mWaste; + + /* + * Construct outer subpath (may be clipped if it's a business card CD) + */ + QPainterPath outerPath; + outerPath.addEllipse( (wReal/2 - r1Clip).pt(), (hReal/2 - r1Clip).pt(), 2*r1Clip.pt(), 2*r1Clip.pt() ); + + QPainterPath clipPath; + clipPath.addRect( -mWaste.pt(), -mWaste.pt(), wClip.pt(), hClip.pt() ); + + mClipPath.addPath( outerPath & clipPath ); + mClipPath.closeSubpath(); + + /* + * Add inner subpath + */ + mClipPath.addEllipse( (wReal/2 - r2Clip).pt(), (hReal/2 - r2Clip).pt(), 2*r2Clip.pt(), 2*r2Clip.pt() ); + } } @@ -128,6 +160,12 @@ namespace glabels } + const QPainterPath& FrameCd::clipPath() const + { + return mClipPath; + } + + QPainterPath FrameCd::marginPath( const Distance& size ) const { Distance wReal = (mW == 0) ? 2*mR1 : mW; diff --git a/libglabels/FrameCd.h b/libglabels/FrameCd.h index 4efdf21..b1282bf 100644 --- a/libglabels/FrameCd.h +++ b/libglabels/FrameCd.h @@ -52,6 +52,7 @@ namespace glabels bool isSimilarTo( Frame* other ) const; const QPainterPath& path() const; + const QPainterPath& clipPath() const; QPainterPath marginPath( const Distance& size ) const; @@ -63,6 +64,7 @@ namespace glabels Distance mWaste; QPainterPath mPath; + QPainterPath mClipPath; }; diff --git a/libglabels/FrameEllipse.cpp b/libglabels/FrameEllipse.cpp index 704e081..8e7e8b1 100644 --- a/libglabels/FrameEllipse.cpp +++ b/libglabels/FrameEllipse.cpp @@ -36,6 +36,7 @@ namespace glabels : mW(w), mH(h), mWaste(waste), Frame(id) { mPath.addEllipse( 0, 0, mW.pt(), mH.pt() ); + mClipPath.addEllipse( -mWaste.pt(), -mWaste.pt(), (mW+2*mWaste).pt(), (mH+2*mWaste).pt() ); } FrameEllipse::FrameEllipse( const FrameEllipse& other ) @@ -104,6 +105,12 @@ namespace glabels } + const QPainterPath& FrameEllipse::clipPath() const + { + return mClipPath; + } + + QPainterPath FrameEllipse::marginPath( const Distance& size ) const { Distance w = mW - 2*size; diff --git a/libglabels/FrameEllipse.h b/libglabels/FrameEllipse.h index 4af5069..9b48dda 100644 --- a/libglabels/FrameEllipse.h +++ b/libglabels/FrameEllipse.h @@ -49,6 +49,7 @@ namespace glabels bool isSimilarTo( Frame* other ) const; const QPainterPath& path() const; + const QPainterPath& clipPath() const; QPainterPath marginPath( const Distance& size ) const; @@ -58,6 +59,7 @@ namespace glabels Distance mWaste; QPainterPath mPath; + QPainterPath mClipPath; }; diff --git a/libglabels/FrameRect.cpp b/libglabels/FrameRect.cpp index 3f3b255..108acdb 100644 --- a/libglabels/FrameRect.cpp +++ b/libglabels/FrameRect.cpp @@ -38,6 +38,10 @@ namespace glabels : mW(w), mH(h), mR(r), mXWaste(xWaste), mYWaste(yWaste), Frame(id) { mPath.addRoundedRect( 0, 0, mW.pt(), mH.pt(), mR.pt(), mR.pt() ); + + mClipPath.addRoundedRect( -mXWaste.pt(), -mYWaste.pt(), + mW.pt() + 2*mXWaste.pt(), mH.pt() + 2*mYWaste.pt(), + mR.pt(), mR.pt() ); } @@ -108,6 +112,12 @@ namespace glabels } + const QPainterPath& FrameRect::clipPath() const + { + return mClipPath; + } + + QPainterPath FrameRect::marginPath( const Distance& size ) const { Distance w = mW - 2*size; diff --git a/libglabels/FrameRect.h b/libglabels/FrameRect.h index c36a626..6c6e29f 100644 --- a/libglabels/FrameRect.h +++ b/libglabels/FrameRect.h @@ -53,6 +53,7 @@ namespace glabels bool isSimilarTo( Frame* other ) const; const QPainterPath& path() const; + const QPainterPath& clipPath() const; QPainterPath marginPath( const Distance& size ) const; @@ -64,6 +65,7 @@ namespace glabels Distance mYWaste; QPainterPath mPath; + QPainterPath mClipPath; }; diff --git a/libglabels/FrameRound.cpp b/libglabels/FrameRound.cpp index 62042eb..041af77 100644 --- a/libglabels/FrameRound.cpp +++ b/libglabels/FrameRound.cpp @@ -35,6 +35,7 @@ namespace glabels : mR(r), mWaste(waste), Frame(id) { mPath.addEllipse( 0, 0, 2*mR.pt(), 2*mR.pt() ); + mClipPath.addEllipse( -mWaste.pt(), -mWaste.pt(), 2*(mR+mWaste).pt(), 2*(mR+mWaste).pt() ); } @@ -102,6 +103,12 @@ namespace glabels } + const QPainterPath& FrameRound::clipPath() const + { + return mClipPath; + } + + QPainterPath FrameRound::marginPath( const Distance& size ) const { Distance r = mR - size; diff --git a/libglabels/FrameRound.h b/libglabels/FrameRound.h index be939ff..0cf209b 100644 --- a/libglabels/FrameRound.h +++ b/libglabels/FrameRound.h @@ -49,6 +49,7 @@ namespace glabels bool isSimilarTo( Frame* other ) const; const QPainterPath& path() const; + const QPainterPath& clipPath() const; QPainterPath marginPath( const Distance& size ) const; @@ -57,6 +58,7 @@ namespace glabels Distance mWaste; QPainterPath mPath; + QPainterPath mClipPath; };