Skip to content

Commit 6249818

Browse files
committed
[feature] Add font color control for grid annotations (fix #7789)
1 parent 881602e commit 6249818

File tree

5 files changed

+73
-10
lines changed

5 files changed

+73
-10
lines changed

src/app/composer/qgscomposermapwidget.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ void QgsComposerMapWidget::updateGuiElements()
362362
initAnnotationDirectionBox( mAnnotationDirectionComboBoxTop, mComposerMap->gridAnnotationDirection( QgsComposerMap::Top ) );
363363
initAnnotationDirectionBox( mAnnotationDirectionComboBoxBottom, mComposerMap->gridAnnotationDirection( QgsComposerMap::Bottom ) );
364364

365+
mAnnotationFontColorButton->setColor( mComposerMap->annotationFontColor() );
366+
mAnnotationFontColorButton->setColorDialogTitle( tr( "Select font color" ) );
367+
mAnnotationFontColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
368+
365369
mDistanceToMapFrameSpinBox->setValue( mComposerMap->annotationFrameDistance() );
366370

367371
if ( mComposerMap->showGridAnnotation() )
@@ -440,6 +444,7 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
440444
mAnnotationDirectionComboBoxTop->blockSignals( b );
441445
mAnnotationDirectionComboBoxBottom->blockSignals( b );
442446
mCoordinatePrecisionSpinBox->blockSignals( b );
447+
mAnnotationFontColorButton->blockSignals( b );
443448
mDrawCanvasItemsCheckBox->blockSignals( b );
444449
mFrameStyleComboBox->blockSignals( b );
445450
mFrameWidthSpinBox->blockSignals( b );
@@ -743,6 +748,18 @@ void QgsComposerMapWidget::on_mAnnotationFontButton_clicked()
743748
}
744749
}
745750

751+
void QgsComposerMapWidget::on_mAnnotationFontColorButton_colorChanged( const QColor& newFontColor )
752+
{
753+
if ( !mComposerMap )
754+
{
755+
return;
756+
}
757+
mComposerMap->beginCommand( tr( "Label font changed" ) );
758+
mComposerMap->setAnnotationFontColor( newFontColor );
759+
mComposerMap->update();
760+
mComposerMap->endCommand();
761+
}
762+
746763
void QgsComposerMapWidget::on_mDistanceToMapFrameSpinBox_valueChanged( double d )
747764
{
748765
if ( !mComposerMap )

src/app/composer/qgscomposermapwidget.h

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
6262
void on_mCrossWidthSpinBox_valueChanged( double d );
6363
void on_mGridBlendComboBox_currentIndexChanged( int index );
6464
void on_mAnnotationFontButton_clicked();
65+
void on_mAnnotationFontColorButton_colorChanged( const QColor& newFontColor );
6566
void on_mDistanceToMapFrameSpinBox_valueChanged( double d );
6667

6768
void on_mAnnotationFormatComboBox_currentIndexChanged( int index );

src/core/composer/qgscomposermap.cpp

+29-5
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@
4242
QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height )
4343
: QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ),
4444
mOverviewFrameMapId( -1 ), mOverviewBlendMode( QPainter::CompositionMode_SourceOver ), mOverviewInverted( false ), mGridEnabled( false ), mGridStyle( Solid ),
45-
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ),
46-
mGridBlendMode( QPainter::CompositionMode_SourceOver ), mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ),
45+
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationFontColor( QColor( 0, 0, 0 ) ),
46+
mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), mGridBlendMode( QPainter::CompositionMode_SourceOver ),
47+
mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ),
4748
mTopGridAnnotationPosition( OutsideMapFrame ), mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ),
4849
mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ), mTopGridAnnotationDirection( Horizontal ),
4950
mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ),
@@ -86,8 +87,9 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
8687
QgsComposerMap::QgsComposerMap( QgsComposition *composition )
8788
: QgsComposerItem( 0, 0, 10, 10, composition ), mKeepLayerSet( false ), mOverviewFrameMapId( -1 ),
8889
mOverviewBlendMode( QPainter::CompositionMode_SourceOver ), mOverviewInverted( false ), mGridEnabled( false ), mGridStyle( Solid ),
89-
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ),
90-
mGridBlendMode( QPainter::CompositionMode_SourceOver ), mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ),
90+
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationFontColor( QColor( 0, 0, 0 ) ),
91+
mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), mGridBlendMode( QPainter::CompositionMode_SourceOver ),
92+
mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ),
9193
mTopGridAnnotationPosition( OutsideMapFrame ), mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ),
9294
mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ), mTopGridAnnotationDirection( Horizontal ),
9395
mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ), mCrossLength( 3 ),
@@ -813,6 +815,12 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
813815
annotationElem.setAttribute( "frameDistance", QString::number( mAnnotationFrameDistance ) );
814816
annotationElem.setAttribute( "font", mGridAnnotationFont.toString() );
815817
annotationElem.setAttribute( "precision", mGridAnnotationPrecision );
818+
//annotation font color
819+
QDomElement annotationFontColorElem = doc.createElement( "fontColor" );
820+
annotationFontColorElem.setAttribute( "red", mGridAnnotationFontColor.red() );
821+
annotationFontColorElem.setAttribute( "green", mGridAnnotationFontColor.green() );
822+
annotationFontColorElem.setAttribute( "blue", mGridAnnotationFontColor.blue() );
823+
annotationElem.appendChild( annotationFontColorElem );
816824

817825
gridElem.appendChild( annotationElem );
818826
composerMapElem.appendChild( gridElem );
@@ -975,6 +983,22 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
975983
mBottomGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "bottomDirection", "0" ).toInt() );
976984
mAnnotationFrameDistance = annotationElem.attribute( "frameDistance", "0" ).toDouble();
977985
mGridAnnotationFont.fromString( annotationElem.attribute( "font", "" ) );
986+
987+
//annotation font color
988+
QDomNodeList annotationFontColorList = annotationElem.elementsByTagName( "fontColor" );
989+
if ( annotationFontColorList.size() > 0 )
990+
{
991+
QDomElement fontColorElem = annotationFontColorList.at( 0 ).toElement();
992+
int red = fontColorElem.attribute( "red", "0" ).toInt();
993+
int green = fontColorElem.attribute( "green", "0" ).toInt();
994+
int blue = fontColorElem.attribute( "blue", "0" ).toInt();
995+
mGridAnnotationFontColor = QColor( red, green, blue );
996+
}
997+
else
998+
{
999+
mGridAnnotationFontColor = QColor( 0, 0, 0 );
1000+
}
1001+
9781002
mGridAnnotationPrecision = annotationElem.attribute( "precision", "3" ).toInt();
9791003
}
9801004
}
@@ -1398,7 +1422,7 @@ void QgsComposerMap::drawAnnotation( QPainter* p, const QPointF& pos, int rotati
13981422
p->save();
13991423
p->translate( pos );
14001424
p->rotate( rotation );
1401-
p->setPen( QColor( 0, 0, 0 ) );
1425+
p->setPen( QPen( QColor( mGridAnnotationFontColor ) ) );
14021426
drawText( p, 0, 0, annotationText, mGridAnnotationFont );
14031427
p->restore();
14041428
}

src/core/composer/qgscomposermap.h

+9
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,13 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
246246
void setGridAnnotationFont( const QFont& f ) { mGridAnnotationFont = f; }
247247
QFont gridAnnotationFont() const { return mGridAnnotationFont; }
248248

249+
/**Sets font color for grid annotations
250+
@note: this function was added in version 2.0*/
251+
void setAnnotationFontColor( const QColor& c ) {mGridAnnotationFontColor = c;}
252+
/**Get font color for grid annotations
253+
@note: this function was added in version 2.0*/
254+
QColor annotationFontColor() const {return mGridAnnotationFontColor;}
255+
249256
/**Sets coordinate precision for grid annotations
250257
@note this function was added in version 1.4*/
251258
void setGridAnnotationPrecision( int p ) {mGridAnnotationPrecision = p;}
@@ -422,6 +429,8 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
422429
double mGridOffsetY;
423430
/**Font for grid line annotation*/
424431
QFont mGridAnnotationFont;
432+
/**Font color for grid line annotation*/
433+
QColor mGridAnnotationFontColor;
425434
/**Digits after the dot*/
426435
int mGridAnnotationPrecision;
427436
/**True if coordinate values should be drawn*/

src/ui/qgscomposermapwidgetbase.ui

+17-5
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<x>0</x>
5757
<y>-202</y>
5858
<width>440</width>
59-
<height>1347</height>
59+
<height>1380</height>
6060
</rect>
6161
</property>
6262
<property name="sizePolicy">
@@ -593,7 +593,7 @@
593593
</property>
594594
</widget>
595595
</item>
596-
<item row="10" column="0">
596+
<item row="11" column="0">
597597
<widget class="QLabel" name="mDistanceToFrameLabel">
598598
<property name="text">
599599
<string>Distance to map frame</string>
@@ -606,10 +606,10 @@
606606
</property>
607607
</widget>
608608
</item>
609-
<item row="10" column="1">
609+
<item row="11" column="1">
610610
<widget class="QDoubleSpinBox" name="mDistanceToMapFrameSpinBox"/>
611611
</item>
612-
<item row="11" column="0">
612+
<item row="12" column="0">
613613
<widget class="QLabel" name="mCoordinatePrecisionLabel">
614614
<property name="text">
615615
<string>Coordinate precision</string>
@@ -622,9 +622,16 @@
622622
</property>
623623
</widget>
624624
</item>
625-
<item row="11" column="1">
625+
<item row="12" column="1">
626626
<widget class="QSpinBox" name="mCoordinatePrecisionSpinBox"/>
627627
</item>
628+
<item row="10" column="1">
629+
<widget class="QgsColorButton" name="mAnnotationFontColorButton">
630+
<property name="text">
631+
<string>Font color...</string>
632+
</property>
633+
</widget>
634+
</item>
628635
</layout>
629636
</widget>
630637
</item>
@@ -712,6 +719,11 @@
712719
<extends>QComboBox</extends>
713720
<header>qgsblendmodecombobox.h</header>
714721
</customwidget>
722+
<customwidget>
723+
<class>QgsColorButton</class>
724+
<extends>QPushButton</extends>
725+
<header>qgscolorbutton.h</header>
726+
</customwidget>
715727
</customwidgets>
716728
<resources/>
717729
<connections/>

0 commit comments

Comments
 (0)