Skip to content
Permalink
Browse files
Allow setting of font color in QgsComposerLegend
  • Loading branch information
olivierdalang authored and mhugent committed Jan 22, 2013
1 parent 6566bab commit d0331246962c08791f5cce1804b603ebf5f7ec99
@@ -23,6 +23,7 @@
#include "qgscomposeritemwidget.h"
#include "qgscomposermap.h"
#include <QFontDialog>
#include <QColorDialog>

#include "qgsapplegendinterface.h"
#include "qgisapp.h"
@@ -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 )
@@ -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 );
@@ -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 );
@@ -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 )
{
@@ -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 )
@@ -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 )
@@ -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;

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

@@ -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;
@@ -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">
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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">
@@ -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">

0 comments on commit d033124

Please sign in to comment.