Correctly draw rotated labels.
This commit is contained in:
+1
-1
@@ -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;
|
||||
|
||||
|
||||
|
||||
+40
-13
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user