Skip to content

Commit

Permalink
Fix opacity in svg marker dxf export
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Apr 3, 2018
1 parent a20ae46 commit abf2fc6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
36 changes: 32 additions & 4 deletions src/core/dxf/qgsdxfpaintengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ QgsDxfPaintEngine::QgsDxfPaintEngine( const QgsDxfPaintDevice* dxfDevice, QgsDxf
: QPaintEngine( QPaintEngine::AllFeatures /*QPaintEngine::PainterPaths | QPaintEngine::PaintOutsidePaintEvent*/ )
, mPaintDevice( dxfDevice )
, mDxf( dxf )
, mOpacity( 1.0 )
{
}

Expand Down Expand Up @@ -64,6 +65,11 @@ void QgsDxfPaintEngine::updateState( const QPaintEngineState& state )

if ( state.state() & QPaintEngine::DirtyBrush )
mBrush = state.brush();

if ( state.state() & QPaintEngine::DirtyOpacity )
{
mOpacity = state.opacity();
}
}

void QgsDxfPaintEngine::setRing( QgsPointSequenceV2 &polyline, const QPointF *points, int pointCount )
Expand All @@ -86,12 +92,12 @@ void QgsDxfPaintEngine::drawPolygon( const QPointF *points, int pointCount, Poly
if ( mode == QPaintEngine::PolylineMode )
{
if ( mPen.style() != Qt::NoPen && mPen.brush().style() != Qt::NoBrush )
mDxf->writePolyline( polygon.at( 0 ), mLayer, "CONTINUOUS", mPen.color(), currentWidth() );
mDxf->writePolyline( polygon.at( 0 ), mLayer, "CONTINUOUS", penColor(), currentWidth() );
}
else
{
if ( mBrush.style() != Qt::NoBrush )
mDxf->writePolygon( polygon, mLayer, "SOLID", mBrush.color() );
mDxf->writePolygon( polygon, mLayer, "SOLID", brushColor() );
}
}

Expand Down Expand Up @@ -122,7 +128,7 @@ void QgsDxfPaintEngine::drawPath( const QPainterPath& path )
endPolygon();

if ( !mPolygon.isEmpty() && mBrush.style() != Qt::NoBrush )
mDxf->writePolygon( mPolygon, mLayer, "SOLID", mBrush.color() );
mDxf->writePolygon( mPolygon, mLayer, "SOLID", brushColor() );

mPolygon.clear();
}
Expand Down Expand Up @@ -198,7 +204,7 @@ void QgsDxfPaintEngine::drawLines( const QLineF* lines, int lineCount )
{
mDxf->writeLine( toDxfCoordinates( lines[i].p1() ),
toDxfCoordinates( lines[i].p2() ),
mLayer, "CONTINUOUS", mPen.color(), currentWidth() );
mLayer, "CONTINUOUS", penColor(), currentWidth() );
}
}

Expand Down Expand Up @@ -291,3 +297,25 @@ int QgsDxfPaintEngine::faculty( int n )

return result;
}

QColor QgsDxfPaintEngine::penColor() const
{
if ( qgsDoubleNear( mOpacity, 1.0 ) )
{
return mPen.color();
}
QColor c = mPen.color();
c.setAlphaF( c.alphaF() * mOpacity );
return c;
}

QColor QgsDxfPaintEngine::brushColor() const
{
if ( qgsDoubleNear( mOpacity, 1.0 ) )
{
return mBrush.color();
}
QColor c = mBrush.color();
c.setAlphaF( c.alphaF() * mOpacity );
return c;
}
4 changes: 4 additions & 0 deletions src/core/dxf/qgsdxfpaintengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class CORE_EXPORT QgsDxfPaintEngine: public QPaintEngine
QTransform mTransform;
QPen mPen;
QBrush mBrush;
double mOpacity;
QString mLayer;
QPointF mShift;
QgsRingSequenceV2 mPolygon;
Expand All @@ -84,6 +85,9 @@ class CORE_EXPORT QgsDxfPaintEngine: public QPaintEngine
static int lower( int n, int i );
static double power( double a, int b );
static int faculty( int n );

QColor penColor() const;
QColor brushColor() const;
};

#endif // QGSDXFPAINTENGINE_H

0 comments on commit abf2fc6

Please sign in to comment.