22 changes: 22 additions & 0 deletions src/app/composer/qgscomposerlegendwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "qgscomposeritemwidget.h"
#include "qgscomposermap.h"
#include <QFontDialog>
#include <QColorDialog>

#include "qgsapplegendinterface.h"
#include "qgisapp.h"
Expand Down Expand Up @@ -337,6 +338,27 @@ void QgsComposerLegendWidget::on_mItemFontButton_clicked()
}
}

void QgsComposerLegendWidget::on_mFontColorPushButton_clicked()
{
if ( !mLegend )
{
return;
}

QColor oldColor = mLegend->fontColor();
QColor newColor = QColorDialog::getColor( oldColor, 0 );

if ( !newColor.isValid() ) //user canceled the dialog
{
return;
}

mLegend->beginCommand( tr( "Legend font color changed" ) );
mLegend->setFontColor( newColor );
mLegend->update();
mLegend->endCommand();
}

void QgsComposerLegendWidget::on_mBoxSpaceSpinBox_valueChanged( double d )
{
if ( mLegend )
Expand Down
1 change: 1 addition & 0 deletions src/app/composer/qgscomposerlegendwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class QgsComposerLegendWidget: public QWidget, private Ui::QgsComposerLegendWidg
void on_mGroupFontButton_clicked();
void on_mLayerFontButton_clicked();
void on_mItemFontButton_clicked();
void on_mFontColorPushButton_clicked();
void on_mBoxSpaceSpinBox_valueChanged( double d );
void on_mColumnSpaceSpinBox_valueChanged( double d );
void on_mCheckBoxAutoUpdate_stateChanged( int state );
Expand Down
50 changes: 49 additions & 1 deletion src/app/composer/qgscomposerscalebarwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void QgsComposerScaleBarWidget::on_mLineWidthSpinBox_valueChanged( double d )

mComposerScaleBar->beginCommand( tr( "Scalebar line width" ), QgsComposerMergeCommand::ScaleBarLineWidth );
disconnectUpdateSignal();
QPen newPen( QColor( 0, 0, 0 ) );
QPen newPen( mComposerScaleBar->pen().color() );
newPen.setWidthF( d );
mComposerScaleBar->setPen( newPen );
mComposerScaleBar->update();
Expand Down Expand Up @@ -297,6 +297,29 @@ void QgsComposerScaleBarWidget::on_mFontButton_clicked()
mComposerScaleBar->update();
}

void QgsComposerScaleBarWidget::on_mFontColorPushButton_clicked()
{
if ( !mComposerScaleBar )
{
return;
}

QColor oldColor = mComposerScaleBar->fontColor();
QColor newColor = QColorDialog::getColor( oldColor, 0 );

if ( !newColor.isValid() ) //user canceled the dialog
{
return;
}

mComposerScaleBar->beginCommand( tr( "Scalebar font color changed" ) );
disconnectUpdateSignal();
mComposerScaleBar->setFontColor( newColor );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}

void QgsComposerScaleBarWidget::on_mColorPushButton_clicked()
{
if ( !mComposerScaleBar )
Expand All @@ -321,6 +344,31 @@ void QgsComposerScaleBarWidget::on_mColorPushButton_clicked()
mComposerScaleBar->endCommand();
}

void QgsComposerScaleBarWidget::on_mStrokeColorPushButton_clicked()
{
if ( !mComposerScaleBar )
{
return;
}

QColor oldColor = mComposerScaleBar->pen().color();
QColor newColor = QColorDialog::getColor( oldColor, 0 );

if ( !newColor.isValid() ) //user canceled the dialog
{
return;
}

mComposerScaleBar->beginCommand( tr( "Scalebar stroke color changed" ) );
disconnectUpdateSignal();
QPen newPen = mComposerScaleBar->pen();
newPen.setColor( newColor );
mComposerScaleBar->setPen( newPen );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}

void QgsComposerScaleBarWidget::on_mUnitLabelLineEdit_textChanged( const QString& text )
{
if ( !mComposerScaleBar )
Expand Down
2 changes: 2 additions & 0 deletions src/app/composer/qgscomposerscalebarwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ class QgsComposerScaleBarWidget: public QWidget, private Ui::QgsComposerScaleBar
void on_mUnitLabelLineEdit_textChanged( const QString& text );
void on_mMapUnitsPerBarUnitSpinBox_valueChanged( double d );
void on_mColorPushButton_clicked();
void on_mStrokeColorPushButton_clicked();
void on_mFontButton_clicked();
void on_mFontColorPushButton_clicked();
void on_mStyleComboBox_currentIndexChanged( const QString& text );
void on_mLabelBarSpaceSpinBox_valueChanged( double d );
void on_mBoxSizeSpinBox_valueChanged( double d );
Expand Down
1 change: 0 additions & 1 deletion src/core/composer/qgscomposeritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,6 @@ void QgsComposerItem::drawText( QPainter* p, double x, double y, const QString&

p->save();
p->setFont( textFont );
p->setPen( QColor( 0, 0, 0 ) ); //draw text always in black
double scaleFactor = 1.0 / FONT_WORKAROUND_SCALE;
p->scale( scaleFactor, scaleFactor );
p->drawText( QPointF( x * FONT_WORKAROUND_SCALE, y * FONT_WORKAROUND_SCALE ), text );
Expand Down
13 changes: 9 additions & 4 deletions src/core/composer/qgscomposerlegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ QgsComposerLegend::QgsComposerLegend( QgsComposition* composition )
, mComposerMap( 0 )
, mSplitLayer( false )
, mEqualColumnWidth( false )
, mFontColor( QColor( 0, 0, 0 ) )
{
//QStringList idList = layerIdList();
//mLegendModel.setLayerSet( idList );
Expand Down Expand Up @@ -206,7 +207,7 @@ QSizeF QgsComposerLegend::drawTitle( QPainter* painter, QPointF point, Qt::Align

double y = point.y();

if ( painter ) painter->setPen( QColor( 0, 0, 0 ) );
if ( painter ) painter->setPen( mFontColor );

for ( QStringList::Iterator titlePart = lines.begin(); titlePart != lines.end(); ++titlePart )
{
Expand Down Expand Up @@ -241,7 +242,7 @@ QSizeF QgsComposerLegend::drawGroupItemTitle( QgsComposerGroupItem* groupItem, Q

double y = point.y();

if ( painter ) painter->setPen( QColor( 0, 0, 0 ) );
if ( painter ) painter->setPen( mFontColor );

QStringList lines = splitStringForWrapping( groupItem->text() );
for ( QStringList::Iterator groupPart = lines.begin(); groupPart != lines.end(); ++groupPart )
Expand Down Expand Up @@ -269,7 +270,7 @@ QSizeF QgsComposerLegend::drawLayerItemTitle( QgsComposerLayerItem* layerItem, Q

double y = point.y();

if ( painter ) painter->setPen( QColor( 0, 0, 0 ) );
if ( painter ) painter->setPen( mFontColor );

QStringList lines = splitStringForWrapping( layerItem->text() );
for ( QStringList::Iterator layerItemPart = lines.begin(); layerItemPart != lines.end(); ++layerItemPart )
Expand Down Expand Up @@ -377,7 +378,7 @@ QgsComposerLegend::Nucleon QgsComposerLegend::drawSymbolItem( QgsComposerLegendI
}
}

if ( painter ) painter->setPen( QColor( 0, 0, 0 ) );
if ( painter ) painter->setPen( mFontColor );

double labelX = point.x() + labelXOffset; // + mIconLabelSpace;

Expand Down Expand Up @@ -727,6 +728,7 @@ bool QgsComposerLegend::writeXML( QDomElement& elem, QDomDocument & doc ) const
composerLegendElem.setAttribute( "symbolWidth", QString::number( mSymbolWidth ) );
composerLegendElem.setAttribute( "symbolHeight", QString::number( mSymbolHeight ) );
composerLegendElem.setAttribute( "wrapChar", mWrapChar );
composerLegendElem.setAttribute( "fontColor", mFontColor.name() );

if ( mComposerMap )
{
Expand Down Expand Up @@ -779,6 +781,9 @@ bool QgsComposerLegend::readXML( const QDomElement& itemElem, const QDomDocument
mItemFont.fromString( itemFontString );
}

//font color
mFontColor.setNamedColor( itemElem.attribute( "fontColor", "#000000" ) );

//spaces
mBoxSpace = itemElem.attribute( "boxSpace", "2.0" ).toDouble();
mColumnSpace = itemElem.attribute( "columnSpace", "2.0" ).toDouble();
Expand Down
4 changes: 4 additions & 0 deletions src/core/composer/qgscomposerlegend.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
QFont itemFont() const;
void setItemFont( const QFont& f );

QColor fontColor() const {return mFontColor;}
void setFontColor( const QColor& c ) {mFontColor = c;}

double boxSpace() const {return mBoxSpace;}
void setBoxSpace( double s ) {mBoxSpace = s;}

Expand Down Expand Up @@ -141,6 +144,7 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
QFont mGroupFont;
QFont mLayerFont;
QFont mItemFont;
QColor mFontColor;

/**Space between item box and contents*/
double mBoxSpace;
Expand Down
20 changes: 12 additions & 8 deletions src/core/composer/qgscomposerscalebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ QgsComposerScaleBar::QgsComposerScaleBar( QgsComposition* composition )
: QgsComposerItem( composition )
, mComposerMap( 0 )
, mNumUnitsPerSegment( 0 )
, mFontColor( QColor( 0, 0, 0 ) )
, mStyle( 0 )
, mSegmentMillimeters( 0.0 )
, mAlignment( Left )
Expand All @@ -60,7 +61,6 @@ void QgsComposerScaleBar::paint( QPainter* painter, const QStyleOptionGraphicsIt
}

drawBackground( painter );
painter->setPen( QPen( QColor( 0, 0, 0 ) ) ); //draw all text black

//x-offset is half of first label width because labels are drawn centered
QString firstLabel = firstLabelString();
Expand Down Expand Up @@ -228,6 +228,7 @@ void QgsComposerScaleBar::applyDefaultSettings()
mBrush.setStyle( Qt::SolidPattern );

mFont.setPointSizeF( 12.0 );
mFontColor = QColor( 0, 0, 0 );

mLabelBarSpace = 3.0;
mBoxContentSpace = 1.0;
Expand Down Expand Up @@ -422,13 +423,10 @@ bool QgsComposerScaleBar::writeXML( QDomElement& elem, QDomDocument & doc ) cons
composerScaleBarElem.setAttribute( "mapId", mComposerMap->id() );
}

//fill color
QColor brushColor = mBrush.color();
QDomElement colorElem = doc.createElement( "BrushColor" );
colorElem.setAttribute( "red", brushColor.red() );
colorElem.setAttribute( "green", brushColor.green() );
colorElem.setAttribute( "blue", brushColor.blue() );
composerScaleBarElem.appendChild( colorElem );
//colors
composerScaleBarElem.setAttribute( "brushColor", mBrush.color().name() );
composerScaleBarElem.setAttribute( "penColor", mPen.color().name() );
composerScaleBarElem.setAttribute( "fontColor", mFontColor.name() );

//alignment
composerScaleBarElem.setAttribute( "alignment", QString::number(( int ) mAlignment ) );
Expand Down Expand Up @@ -460,6 +458,12 @@ bool QgsComposerScaleBar::readXML( const QDomElement& itemElem, const QDomDocume
mFont.fromString( fontString );
}

//colors
//fill color
mBrush.setColor( QColor( itemElem.attribute( "brushColor", "#000000" ) ) );
mPen.setColor( QColor( itemElem.attribute( "penColor", "#000000" ) ) );
mFontColor.setNamedColor( itemElem.attribute( "fontColor", "#000000" ) );

//style
delete mStyle;
mStyle = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/core/composer/qgscomposerscalebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "qgscomposeritem.h"
#include <QPen>
#include <QColor>

class QgsComposerMap;
class QgsScaleBarStyle;
Expand Down Expand Up @@ -74,6 +75,9 @@ class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem

QFont font() const;

QColor fontColor() const {return mFontColor;}
void setFontColor( const QColor& c ) {mFontColor = c;}

void setFont( const QFont& font );

QPen pen() const {return mPen;}
Expand Down Expand Up @@ -172,6 +176,7 @@ class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem
QString mUnitLabeling;
/**Font*/
QFont mFont;
QColor mFontColor;
/**Outline*/
QPen mPen;
/**Fill*/
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgsdoubleboxscalebarstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void QgsDoubleBoxScaleBarStyle::draw( QPainter* p, double xOffset ) const
double segmentHeight = mScaleBar->height() / 2;

p->save();
p->setPen( p->pen() );
p->setPen( mScaleBar->pen() );

QList<QPair<double, double> > segmentInfo;
mScaleBar->segmentPositions( segmentInfo );
Expand Down
3 changes: 1 addition & 2 deletions src/core/composer/qgsscalebarstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void QgsScaleBarStyle::drawLabels( QPainter* p ) const
p->save();

p->setFont( mScaleBar->font() );
p->setPen( QPen(mScaleBar->fontColor()) );

QString firstLabel = mScaleBar->firstLabelString();
double xOffset = mScaleBar->textWidthMillimeters( mScaleBar->font(), firstLabel ) / 2;
Expand Down Expand Up @@ -78,7 +79,6 @@ void QgsScaleBarStyle::drawLabels( QPainter* p ) const

if ( segmentCounter == 0 || segmentCounter >= nSegmentsLeft ) //don't draw label for intermediate left segments
{
p->setPen( QColor( 0, 0, 0 ) );
mScaleBar->drawText( p, segmentIt->first - mScaleBar->textWidthMillimeters( mScaleBar->font(), currentNumericLabel ) / 2 + xOffset, mScaleBar->fontAscentMillimeters( mScaleBar->font() ) + mScaleBar->boxContentSpace(), currentNumericLabel, mScaleBar->font() );
}

Expand All @@ -93,7 +93,6 @@ void QgsScaleBarStyle::drawLabels( QPainter* p ) const
if ( !segmentInfo.isEmpty() )
{
currentNumericLabel = QString::number( currentLabelNumber / mScaleBar->numMapUnitsPerScaleBarUnit() );
p->setPen( QColor( 0, 0, 0 ) );
mScaleBar->drawText( p, segmentInfo.last().first + mScaleBar->segmentMillimeters() - mScaleBar->textWidthMillimeters( mScaleBar->font(), currentNumericLabel ) / 2 + xOffset, mScaleBar->fontAscentMillimeters( mScaleBar->font() ) + mScaleBar->boxContentSpace(), currentNumericLabel + " " + mScaleBar->unitLabeling(), mScaleBar->font() );
}

Expand Down
3 changes: 2 additions & 1 deletion src/core/composer/qgssingleboxscalebarstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ void QgsSingleBoxScaleBarStyle::draw( QPainter* p, double xOffset ) const
double barTopPosition = mScaleBar->fontAscentMillimeters( mScaleBar->font() ) + mScaleBar->labelBarSpace() + mScaleBar->boxContentSpace();

p->save();
p->setPen( p->pen() );
p->setPen( mScaleBar->pen() );


QList<QPair<double, double> > segmentInfo;
mScaleBar->segmentPositions( segmentInfo );
Expand Down
Loading