Correctly draw rotated labels.
This commit is contained in:
+5
-4
@@ -512,17 +512,18 @@ glabels::View::drawBgLayer( QPainter* painter )
|
|||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
QBrush brush( shadowColor );
|
|
||||||
painter->setBrush( QBrush( shadowColor ) );
|
painter->setBrush( QBrush( shadowColor ) );
|
||||||
|
painter->setPen( Qt::NoPen );
|
||||||
painter->translate( shadowOffsetPixels/mZoom, shadowOffsetPixels/mZoom );
|
painter->translate( shadowOffsetPixels/mZoom, shadowOffsetPixels/mZoom );
|
||||||
painter->drawPath( mModel->frame()->path() );
|
painter->drawPath( mModel->frame()->path( mModel->rotate() ) );
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
painter->setBrush( QBrush( labelColor ) );
|
painter->setBrush( QBrush( labelColor ) );
|
||||||
painter->drawPath( mModel->frame()->path() );
|
painter->setPen( QPen( labelOutlineColor ) );
|
||||||
|
painter->drawPath( mModel->frame()->path( mModel->rotate() ) );
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
@@ -554,7 +555,7 @@ glabels::View::drawGridLayer( QPainter* painter )
|
|||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
painter->setClipPath( mModel->frame()->path() );
|
painter->setClipPath( mModel->frame()->path( mModel->rotate() ) );
|
||||||
|
|
||||||
painter->setPen( QPen( gridLineColor, gridLineWidthPixels/mZoom ) );
|
painter->setPen( QPen( gridLineColor, gridLineWidthPixels/mZoom ) );
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -69,7 +69,7 @@ namespace libglabels
|
|||||||
virtual const QString sizeDescription( const Units *units ) const = 0;
|
virtual const QString sizeDescription( const Units *units ) const = 0;
|
||||||
virtual bool isSimilarTo( Frame *other ) 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;
|
virtual QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+40
-13
@@ -68,22 +68,49 @@ namespace libglabels
|
|||||||
|
|
||||||
void FrameCd::initPath()
|
void FrameCd::initPath()
|
||||||
{
|
{
|
||||||
// Outer path (may be clipped in the case business card type CD)
|
//
|
||||||
double theta1 = acos( w() / (2*mR1) ) * 180/M_PI;
|
// First the un-rotated path
|
||||||
double theta2 = asin( h() / (2*mR1) ) * 180/M_PI;
|
//
|
||||||
|
{
|
||||||
|
// 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.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, theta1, theta2-theta1 );
|
||||||
mPath.arcTo( 0, 0, 2*mR1, 2*mR1, 180-theta2, 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, 180+theta1, theta2-theta1 );
|
||||||
mPath.arcTo( 0, 0, 2*mR1, 2*mR1, 360-theta2, theta2-theta1 );
|
mPath.arcTo( 0, 0, 2*mR1, 2*mR1, 360-theta2, theta2-theta1 );
|
||||||
mPath.closeSubpath();
|
mPath.closeSubpath();
|
||||||
|
|
||||||
// Inner path (hole)
|
// Inner path (hole)
|
||||||
mPath.addEllipse( mR1-mR2, mR1-mR2, 2*mR2, 2*mR2 );
|
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)
|
// Translate to account for offset with clipped business card CDs
|
||||||
mPath.translate( w()/2 - mR1, h()/2 - mR1 );
|
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;
|
const QString sizeDescription( const Units *units ) const;
|
||||||
bool isSimilarTo( Frame *other ) 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;
|
QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const;
|
||||||
|
|
||||||
|
|
||||||
@@ -73,6 +73,7 @@ namespace libglabels
|
|||||||
double mWaste;
|
double mWaste;
|
||||||
|
|
||||||
QPainterPath mPath;
|
QPainterPath mPath;
|
||||||
|
QPainterPath mRotatedPath;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ namespace libglabels
|
|||||||
: mW(w), mH(h), mWaste(waste), Frame(id)
|
: mW(w), mH(h), mWaste(waste), Frame(id)
|
||||||
{
|
{
|
||||||
mPath.addEllipse( 0, 0, mW, mH );
|
mPath.addEllipse( 0, 0, mW, mH );
|
||||||
|
mRotatedPath.addEllipse( 0, 0, mH, mW );
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameEllipse( const FrameEllipse &other )
|
FrameEllipse( const FrameEllipse &other )
|
||||||
@@ -54,7 +55,7 @@ namespace libglabels
|
|||||||
const QString sizeDescription( const Units *units ) const;
|
const QString sizeDescription( const Units *units ) const;
|
||||||
bool isSimilarTo( Frame *other ) 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;
|
QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const;
|
||||||
|
|
||||||
|
|
||||||
@@ -64,6 +65,7 @@ namespace libglabels
|
|||||||
double mWaste;
|
double mWaste;
|
||||||
|
|
||||||
QPainterPath mPath;
|
QPainterPath mPath;
|
||||||
|
QPainterPath mRotatedPath;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ namespace libglabels
|
|||||||
: mW(w), mH(h), mR(r), mXWaste(xWaste), mYWaste(yWaste), Frame(id)
|
: mW(w), mH(h), mR(r), mXWaste(xWaste), mYWaste(yWaste), Frame(id)
|
||||||
{
|
{
|
||||||
mPath.addRoundedRect( 0, 0, mW, mH, mR, mR );
|
mPath.addRoundedRect( 0, 0, mW, mH, mR, mR );
|
||||||
|
mRotatedPath.addRoundedRect( 0, 0, mH, mW, mR, mR );
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameRect( const FrameRect &other )
|
FrameRect( const FrameRect &other )
|
||||||
@@ -59,7 +60,7 @@ namespace libglabels
|
|||||||
const QString sizeDescription( const Units *units ) const;
|
const QString sizeDescription( const Units *units ) const;
|
||||||
bool isSimilarTo( Frame *other ) 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;
|
QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const;
|
||||||
|
|
||||||
|
|
||||||
@@ -71,6 +72,7 @@ namespace libglabels
|
|||||||
double mYWaste;
|
double mYWaste;
|
||||||
|
|
||||||
QPainterPath mPath;
|
QPainterPath mPath;
|
||||||
|
QPainterPath mRotatedPath;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ namespace libglabels
|
|||||||
const QString sizeDescription( const Units *units ) const;
|
const QString sizeDescription( const Units *units ) const;
|
||||||
bool isSimilarTo( Frame *other ) 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;
|
QGraphicsItem* createMarginGraphicsItem( double size, const QPen& pen ) const;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user