Skip to content

Commit

Permalink
Allow setting of font color in QgsComposerLegend
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierdalang authored and mhugent committed Jan 22, 2013
1 parent 6566bab commit d033124
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 25 deletions.
22 changes: 22 additions & 0 deletions src/app/composer/qgscomposerlegendwidget.cpp
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
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
30 changes: 26 additions & 4 deletions src/core/composer/qgscomposerlegend.cpp
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,12 @@ bool QgsComposerLegend::writeXML( QDomElement& elem, QDomDocument & doc ) const
composerLegendElem.setAttribute( "symbolWidth", QString::number( mSymbolWidth ) );
composerLegendElem.setAttribute( "symbolHeight", QString::number( mSymbolHeight ) );
composerLegendElem.setAttribute( "wrapChar", mWrapChar );
//font color
QDomElement colorElem = doc.createElement( "fontColor" );
colorElem.setAttribute( "red", mFontColor.red() );
colorElem.setAttribute( "green", mFontColor.green() );
colorElem.setAttribute( "blue", mFontColor.blue() );
composerLegendElem.appendChild( colorElem );

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

//font color
QDomNodeList fontColorList = itemElem.elementsByTagName( "fontColor" );
if ( fontColorList.size() > 0 )
{
QDomElement fontColorElem = fontColorList.at( 0 ).toElement();
int red = fontColorElem.attribute( "red", "0" ).toInt();
int green = fontColorElem.attribute( "green", "0" ).toInt();
int blue = fontColorElem.attribute( "blue", "0" ).toInt();
mFontColor = QColor( red, green, blue );
}
else
{
mFontColor = QColor( 0, 0, 0 );
}

//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
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
46 changes: 25 additions & 21 deletions src/ui/qgscomposerlegendwidgetbase.ui
Expand Up @@ -50,9 +50,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-115</y>
<width>370</width>
<height>562</height>
<y>0</y>
<width>362</width>
<height>647</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -93,7 +93,7 @@
</property>
</widget>
</item>
<item row="11" column="1">
<item row="12" column="1">
<widget class="QDoubleSpinBox" name="mSymbolWidthSpinBox">
<property name="prefix">
<string>Symbol width </string>
Expand All @@ -103,7 +103,7 @@
</property>
</widget>
</item>
<item row="12" column="1">
<item row="13" column="1">
<widget class="QDoubleSpinBox" name="mSymbolHeightSpinBox">
<property name="prefix">
<string>Symbol height </string>
Expand All @@ -113,7 +113,7 @@
</property>
</widget>
</item>
<item row="14" column="1">
<item row="15" column="1">
<widget class="QDoubleSpinBox" name="mLayerSpaceSpinBox">
<property name="prefix">
<string>Layer space </string>
Expand All @@ -123,7 +123,7 @@
</property>
</widget>
</item>
<item row="16" column="1">
<item row="17" column="1">
<widget class="QDoubleSpinBox" name="mSymbolSpaceSpinBox">
<property name="prefix">
<string>Symbol space </string>
Expand All @@ -133,7 +133,7 @@
</property>
</widget>
</item>
<item row="17" column="1">
<item row="18" column="1">
<widget class="QDoubleSpinBox" name="mIconLabelSpaceSpinBox">
<property name="prefix">
<string>Icon label space </string>
Expand All @@ -143,7 +143,7 @@
</property>
</widget>
</item>
<item row="18" column="1">
<item row="19" column="1">
<widget class="QDoubleSpinBox" name="mBoxSpaceSpinBox">
<property name="prefix">
<string>Box space </string>
Expand All @@ -153,7 +153,7 @@
</property>
</widget>
</item>
<item row="25" column="1">
<item row="26" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -166,17 +166,17 @@
</property>
</spacer>
</item>
<item row="21" column="1">
<item row="22" column="1">
<widget class="QComboBox" name="mMapComboBox"/>
</item>
<item row="20" column="1">
<item row="21" column="1">
<widget class="QLabel" name="mMapLabel">
<property name="text">
<string>Map</string>
</property>
</widget>
</item>
<item row="13" column="1">
<item row="14" column="1">
<widget class="QDoubleSpinBox" name="mGroupSpaceSpinBox">
<property name="prefix">
<string>Group Space </string>
Expand All @@ -186,14 +186,14 @@
</property>
</widget>
</item>
<item row="23" column="1">
<item row="24" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>Wrap text on</string>
</property>
</widget>
</item>
<item row="24" column="1">
<item row="25" column="1">
<widget class="QLineEdit" name="mWrapCharLineEdit">
<property name="frame">
<bool>true</bool>
Expand Down Expand Up @@ -247,7 +247,7 @@
</property>
</widget>
</item>
<item row="19" column="1">
<item row="20" column="1">
<widget class="QDoubleSpinBox" name="mColumnSpaceSpinBox">
<property name="prefix">
<string>Column space </string>
Expand All @@ -257,15 +257,22 @@
</property>
</widget>
</item>
<item row="11" column="1">
<widget class="QPushButton" name="mFontColorPushButton">
<property name="text">
<string>Font color...</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>427</width>
<height>139</height>
<width>429</width>
<height>385</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -308,9 +315,6 @@
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
<item row="2" column="0">
Expand Down

0 comments on commit d033124

Please sign in to comment.