Skip to content

Commit

Permalink
[feature] Add font color control for grid annotations (fix #7789)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 13, 2013
1 parent 881602e commit 6249818
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 10 deletions.
17 changes: 17 additions & 0 deletions src/app/composer/qgscomposermapwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ void QgsComposerMapWidget::updateGuiElements()
initAnnotationDirectionBox( mAnnotationDirectionComboBoxTop, mComposerMap->gridAnnotationDirection( QgsComposerMap::Top ) );
initAnnotationDirectionBox( mAnnotationDirectionComboBoxBottom, mComposerMap->gridAnnotationDirection( QgsComposerMap::Bottom ) );

mAnnotationFontColorButton->setColor( mComposerMap->annotationFontColor() );
mAnnotationFontColorButton->setColorDialogTitle( tr( "Select font color" ) );
mAnnotationFontColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );

mDistanceToMapFrameSpinBox->setValue( mComposerMap->annotationFrameDistance() );

if ( mComposerMap->showGridAnnotation() )
Expand Down Expand Up @@ -440,6 +444,7 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
mAnnotationDirectionComboBoxTop->blockSignals( b );
mAnnotationDirectionComboBoxBottom->blockSignals( b );
mCoordinatePrecisionSpinBox->blockSignals( b );
mAnnotationFontColorButton->blockSignals( b );
mDrawCanvasItemsCheckBox->blockSignals( b );
mFrameStyleComboBox->blockSignals( b );
mFrameWidthSpinBox->blockSignals( b );
Expand Down Expand Up @@ -743,6 +748,18 @@ void QgsComposerMapWidget::on_mAnnotationFontButton_clicked()
}
}

void QgsComposerMapWidget::on_mAnnotationFontColorButton_colorChanged( const QColor& newFontColor )
{
if ( !mComposerMap )
{
return;
}
mComposerMap->beginCommand( tr( "Label font changed" ) );
mComposerMap->setAnnotationFontColor( newFontColor );
mComposerMap->update();
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mDistanceToMapFrameSpinBox_valueChanged( double d )
{
if ( !mComposerMap )
Expand Down
1 change: 1 addition & 0 deletions src/app/composer/qgscomposermapwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
void on_mCrossWidthSpinBox_valueChanged( double d );
void on_mGridBlendComboBox_currentIndexChanged( int index );
void on_mAnnotationFontButton_clicked();
void on_mAnnotationFontColorButton_colorChanged( const QColor& newFontColor );
void on_mDistanceToMapFrameSpinBox_valueChanged( double d );

void on_mAnnotationFormatComboBox_currentIndexChanged( int index );
Expand Down
34 changes: 29 additions & 5 deletions src/core/composer/qgscomposermap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height )
: QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ),
mOverviewFrameMapId( -1 ), mOverviewBlendMode( QPainter::CompositionMode_SourceOver ), mOverviewInverted( false ), mGridEnabled( false ), mGridStyle( Solid ),
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ),
mGridBlendMode( QPainter::CompositionMode_SourceOver ), mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ),
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationFontColor( QColor( 0, 0, 0 ) ),
mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), mGridBlendMode( QPainter::CompositionMode_SourceOver ),
mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ),
mTopGridAnnotationPosition( OutsideMapFrame ), mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ),
mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ), mTopGridAnnotationDirection( Horizontal ),
mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ),
Expand Down Expand Up @@ -86,8 +87,9 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
QgsComposerMap::QgsComposerMap( QgsComposition *composition )
: QgsComposerItem( 0, 0, 10, 10, composition ), mKeepLayerSet( false ), mOverviewFrameMapId( -1 ),
mOverviewBlendMode( QPainter::CompositionMode_SourceOver ), mOverviewInverted( false ), mGridEnabled( false ), mGridStyle( Solid ),
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ),
mGridBlendMode( QPainter::CompositionMode_SourceOver ), mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ),
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationFontColor( QColor( 0, 0, 0 ) ),
mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), mGridBlendMode( QPainter::CompositionMode_SourceOver ),
mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ),
mTopGridAnnotationPosition( OutsideMapFrame ), mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ),
mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ), mTopGridAnnotationDirection( Horizontal ),
mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ), mCrossLength( 3 ),
Expand Down Expand Up @@ -813,6 +815,12 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
annotationElem.setAttribute( "frameDistance", QString::number( mAnnotationFrameDistance ) );
annotationElem.setAttribute( "font", mGridAnnotationFont.toString() );
annotationElem.setAttribute( "precision", mGridAnnotationPrecision );
//annotation font color
QDomElement annotationFontColorElem = doc.createElement( "fontColor" );
annotationFontColorElem.setAttribute( "red", mGridAnnotationFontColor.red() );
annotationFontColorElem.setAttribute( "green", mGridAnnotationFontColor.green() );
annotationFontColorElem.setAttribute( "blue", mGridAnnotationFontColor.blue() );
annotationElem.appendChild( annotationFontColorElem );

gridElem.appendChild( annotationElem );
composerMapElem.appendChild( gridElem );
Expand Down Expand Up @@ -975,6 +983,22 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
mBottomGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "bottomDirection", "0" ).toInt() );
mAnnotationFrameDistance = annotationElem.attribute( "frameDistance", "0" ).toDouble();
mGridAnnotationFont.fromString( annotationElem.attribute( "font", "" ) );

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

mGridAnnotationPrecision = annotationElem.attribute( "precision", "3" ).toInt();
}
}
Expand Down Expand Up @@ -1398,7 +1422,7 @@ void QgsComposerMap::drawAnnotation( QPainter* p, const QPointF& pos, int rotati
p->save();
p->translate( pos );
p->rotate( rotation );
p->setPen( QColor( 0, 0, 0 ) );
p->setPen( QPen( QColor( mGridAnnotationFontColor ) ) );
drawText( p, 0, 0, annotationText, mGridAnnotationFont );
p->restore();
}
Expand Down
9 changes: 9 additions & 0 deletions src/core/composer/qgscomposermap.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
void setGridAnnotationFont( const QFont& f ) { mGridAnnotationFont = f; }
QFont gridAnnotationFont() const { return mGridAnnotationFont; }

/**Sets font color for grid annotations
@note: this function was added in version 2.0*/
void setAnnotationFontColor( const QColor& c ) {mGridAnnotationFontColor = c;}
/**Get font color for grid annotations
@note: this function was added in version 2.0*/
QColor annotationFontColor() const {return mGridAnnotationFontColor;}

/**Sets coordinate precision for grid annotations
@note this function was added in version 1.4*/
void setGridAnnotationPrecision( int p ) {mGridAnnotationPrecision = p;}
Expand Down Expand Up @@ -422,6 +429,8 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
double mGridOffsetY;
/**Font for grid line annotation*/
QFont mGridAnnotationFont;
/**Font color for grid line annotation*/
QColor mGridAnnotationFontColor;
/**Digits after the dot*/
int mGridAnnotationPrecision;
/**True if coordinate values should be drawn*/
Expand Down
22 changes: 17 additions & 5 deletions src/ui/qgscomposermapwidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<x>0</x>
<y>-202</y>
<width>440</width>
<height>1347</height>
<height>1380</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -593,7 +593,7 @@
</property>
</widget>
</item>
<item row="10" column="0">
<item row="11" column="0">
<widget class="QLabel" name="mDistanceToFrameLabel">
<property name="text">
<string>Distance to map frame</string>
Expand All @@ -606,10 +606,10 @@
</property>
</widget>
</item>
<item row="10" column="1">
<item row="11" column="1">
<widget class="QDoubleSpinBox" name="mDistanceToMapFrameSpinBox"/>
</item>
<item row="11" column="0">
<item row="12" column="0">
<widget class="QLabel" name="mCoordinatePrecisionLabel">
<property name="text">
<string>Coordinate precision</string>
Expand All @@ -622,9 +622,16 @@
</property>
</widget>
</item>
<item row="11" column="1">
<item row="12" column="1">
<widget class="QSpinBox" name="mCoordinatePrecisionSpinBox"/>
</item>
<item row="10" column="1">
<widget class="QgsColorButton" name="mAnnotationFontColorButton">
<property name="text">
<string>Font color...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -712,6 +719,11 @@
<extends>QComboBox</extends>
<header>qgsblendmodecombobox.h</header>
</customwidget>
<customwidget>
<class>QgsColorButton</class>
<extends>QPushButton</extends>
<header>qgscolorbutton.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
Expand Down

0 comments on commit 6249818

Please sign in to comment.