Skip to content
Permalink
Browse files

Fix opacity in svg marker dxf export

  • Loading branch information
mhugent committed Apr 3, 2018
1 parent a20ae46 commit abf2fc6c95c274783115a14cca817ee71ce20ef1
Showing with 36 additions and 4 deletions.
  1. +32 −4 src/core/dxf/qgsdxfpaintengine.cpp
  2. +4 −0 src/core/dxf/qgsdxfpaintengine.h
@@ -24,6 +24,7 @@ QgsDxfPaintEngine::QgsDxfPaintEngine( const QgsDxfPaintDevice* dxfDevice, QgsDxf
: QPaintEngine( QPaintEngine::AllFeatures /*QPaintEngine::PainterPaths | QPaintEngine::PaintOutsidePaintEvent*/ )
, mPaintDevice( dxfDevice )
, mDxf( dxf )
, mOpacity( 1.0 )
{
}

@@ -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 )
@@ -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() );
}
}

@@ -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();
}
@@ -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() );
}
}

@@ -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;
}
@@ -61,6 +61,7 @@ class CORE_EXPORT QgsDxfPaintEngine: public QPaintEngine
QTransform mTransform;
QPen mPen;
QBrush mBrush;
double mOpacity;
QString mLayer;
QPointF mShift;
QgsRingSequenceV2 mPolygon;
@@ -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.
You can’t perform that action at this time.