Skip to content

Commit

Permalink
Add possibility to select outline / fill transparency for composer sh…
Browse files Browse the repository at this point in the history
…apes in color dialog. Make item fill/outline transparent white for composer shapes by default

git-svn-id: http://svn.osgeo.org/qgis/trunk@12237 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Nov 24, 2009
1 parent c2b76d9 commit b511494
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/app/composer/qgscomposershapewidget.cpp
Expand Up @@ -124,7 +124,7 @@ void QgsComposerShapeWidget::on_mOutlineColorButton_clicked()
return;
}
QColor existingColor = mComposerShape->outlineColor();
QColor newColor = QColorDialog::getColor( existingColor, 0 );
QColor newColor = QColorDialog::getColor( existingColor, 0, tr( "Select outline color" ), QColorDialog::ShowAlphaChannel );
if ( newColor.isValid() )
{
mComposerShape->setOutlineColor( newColor );
Expand Down Expand Up @@ -169,7 +169,7 @@ void QgsComposerShapeWidget::on_mFillColorButton_clicked()
return;
}
QColor existingColor = mComposerShape->fillColor();
QColor newColor = QColorDialog::getColor( existingColor, 0 );
QColor newColor = QColorDialog::getColor( existingColor, 0, tr( "Select fill color" ), QColorDialog::ShowAlphaChannel );
if ( newColor.isValid() )
{
mComposerShape->setFillColor( newColor );
Expand Down
18 changes: 13 additions & 5 deletions src/core/composer/qgscomposershape.cpp
Expand Up @@ -20,13 +20,13 @@

QgsComposerShape::QgsComposerShape( QgsComposition* composition ): QgsComposerItem( composition ), mShape( Ellipse )
{
initBrushAndPen();
initGraphicsSettings();
}

QgsComposerShape::QgsComposerShape( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition ): QgsComposerItem( x, y, width, height, composition ), mShape( Ellipse )
{
setSceneRect( QRectF( x, y, width, height ) );
initBrushAndPen();
initGraphicsSettings();
}

QgsComposerShape::~QgsComposerShape()
Expand Down Expand Up @@ -93,11 +93,13 @@ bool QgsComposerShape::writeXML( QDomElement& elem, QDomDocument & doc ) const
outlineColorElem.setAttribute( "red", mPen.color().red() );
outlineColorElem.setAttribute( "green", mPen.color().green() );
outlineColorElem.setAttribute( "blue", mPen.color().blue() );
outlineColorElem.setAttribute( "alpha", mPen.color().alpha() );
composerShapeElem.appendChild( outlineColorElem );
QDomElement fillColorElem = doc.createElement( "FillColor" );
fillColorElem.setAttribute( "red", mBrush.color().red() );
fillColorElem.setAttribute( "green", mBrush.color().green() );
fillColorElem.setAttribute( "blue", mBrush.color().blue() );
fillColorElem.setAttribute( "alpha", mBrush.color().alpha() );
composerShapeElem.appendChild( fillColorElem );
elem.appendChild( composerShapeElem );
return _writeXML( composerShapeElem, doc );
Expand Down Expand Up @@ -127,7 +129,8 @@ bool QgsComposerShape::readXML( const QDomElement& itemElem, const QDomDocument&
int penRed = outlineColorElem.attribute( "red", "0" ).toInt();
int penGreen = outlineColorElem.attribute( "green", "0" ).toInt();
int penBlue = outlineColorElem.attribute( "blue", "0" ).toInt();
mPen.setColor( QColor( penRed, penGreen, penBlue ) );
int penAlpha = outlineColorElem.attribute( "alpha", "255" ).toInt();
mPen.setColor( QColor( penRed, penGreen, penBlue, penAlpha ) );
}

//fill color
Expand All @@ -138,7 +141,8 @@ bool QgsComposerShape::readXML( const QDomElement& itemElem, const QDomDocument&
int brushRed = fillColorElem.attribute( "red", "0" ).toInt();
int brushGreen = fillColorElem.attribute( "green", "0" ).toInt();
int brushBlue = fillColorElem.attribute( "blue", "0" ).toInt();
mBrush.setColor( QColor( brushRed, brushGreen, brushBlue ) );
int brushAlpha = fillColorElem.attribute( "alpha", "255" ).toInt();
mBrush.setColor( QColor( brushRed, brushGreen, brushBlue, brushAlpha ) );
}


Expand Down Expand Up @@ -199,11 +203,15 @@ void QgsComposerShape::setTransparentFill( bool transparent )
}
}

void QgsComposerShape::initBrushAndPen()
void QgsComposerShape::initGraphicsSettings()
{
mPen.setColor( QColor( 0, 0, 0 ) );
mPen.setWidthF( 1 );
mPen.setJoinStyle( Qt::RoundJoin );
mBrush.setColor( QColor( 0, 0, 0 ) );
mBrush.setStyle( Qt::NoBrush );

//set composer item brush and pen to transparent white by default
setPen( QPen( QColor( 255, 255, 255, 0 ) ) );
setBrush( QBrush( QColor( 255, 255, 255, 0 ) ) );
}
3 changes: 2 additions & 1 deletion src/core/composer/qgscomposershape.h
Expand Up @@ -70,8 +70,9 @@ class CORE_EXPORT QgsComposerShape: public QgsComposerItem
QPen mPen;
/**Shape fill*/
QBrush mBrush;

/**Apply default graphics settings*/
void initBrushAndPen();
void initGraphicsSettings();

/**Returns a point on the line from startPoint to directionPoint that is a certain distance away from the starting point*/
QPointF pointOnLineWithDistance( const QPointF& startPoint, const QPointF& directionPoint, double distance ) const;
Expand Down

0 comments on commit b511494

Please sign in to comment.