@@ -63,6 +63,11 @@ QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend *legend )
63
63
setupUi ( this );
64
64
setPanelTitle ( tr ( " Legend properties" ) );
65
65
66
+ mTitleFontButton ->setMode ( QgsFontButton::ModeQFont );
67
+ mGroupFontButton ->setMode ( QgsFontButton::ModeQFont );
68
+ mLayerFontButton ->setMode ( QgsFontButton::ModeQFont );
69
+ mItemFontButton ->setMode ( QgsFontButton::ModeQFont );
70
+
66
71
// setup icons
67
72
mAddToolButton ->setIcon ( QIcon ( QgsApplication::iconPath ( " symbologyAdd.svg" ) ) );
68
73
mEditPushButton ->setIcon ( QIcon ( QgsApplication::iconPath ( " symbologyEdit.png" ) ) );
@@ -108,6 +113,10 @@ QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend *legend )
108
113
109
114
connect ( mItemTreeView ->selectionModel (), &QItemSelectionModel::currentChanged,
110
115
this , &QgsComposerLegendWidget::selectedChanged );
116
+ connect ( mTitleFontButton , &QgsFontButton::changed, this , &QgsComposerLegendWidget::titleFontChanged );
117
+ connect ( mGroupFontButton , &QgsFontButton::changed, this , &QgsComposerLegendWidget::groupFontChanged );
118
+ connect ( mLayerFontButton , &QgsFontButton::changed, this , &QgsComposerLegendWidget::layerFontChanged );
119
+ connect ( mItemFontButton , &QgsFontButton::changed, this , &QgsComposerLegendWidget::itemFontChanged );
111
120
}
112
121
113
122
QgsComposerLegendWidget::QgsComposerLegendWidget (): QgsComposerItemBaseWidget( nullptr , nullptr ), mLegend( nullptr )
@@ -162,6 +171,11 @@ void QgsComposerLegendWidget::setGuiElements()
162
171
const QgsComposerMap *map = mLegend ->composerMap ();
163
172
mMapComboBox ->setItem ( map );
164
173
mFontColorButton ->setColor ( mLegend ->fontColor () );
174
+ mTitleFontButton ->setCurrentFont ( mLegend ->style ( QgsLegendStyle::Title ).font () );
175
+ mGroupFontButton ->setCurrentFont ( mLegend ->style ( QgsLegendStyle::Group ).font () );
176
+ mLayerFontButton ->setCurrentFont ( mLegend ->style ( QgsLegendStyle::Subgroup ).font () );
177
+ mItemFontButton ->setCurrentFont ( mLegend ->style ( QgsLegendStyle::SymbolLabel ).font () );
178
+
165
179
blockAllSignals ( false );
166
180
167
181
on_mCheckBoxAutoUpdate_stateChanged ( mLegend ->autoUpdateModel () ? Qt::Checked : Qt::Unchecked );
@@ -353,71 +367,51 @@ void QgsComposerLegendWidget::on_mIconLabelSpaceSpinBox_valueChanged( double d )
353
367
}
354
368
}
355
369
356
- void QgsComposerLegendWidget::on_mTitleFontButton_clicked ()
370
+ void QgsComposerLegendWidget::titleFontChanged ()
357
371
{
358
372
if ( mLegend )
359
373
{
360
- bool ok;
361
- QFont newFont = QgsGuiUtils::getFont ( ok, mLegend ->style ( QgsLegendStyle::Title ).font () );
362
- if ( ok )
363
- {
364
- mLegend ->beginCommand ( tr ( " Title font changed" ) );
365
- mLegend ->setStyleFont ( QgsLegendStyle::Title, newFont );
366
- mLegend ->adjustBoxSize ();
367
- mLegend ->update ();
368
- mLegend ->endCommand ();
369
- }
374
+ mLegend ->beginCommand ( tr ( " Title font changed" ) );
375
+ mLegend ->setStyleFont ( QgsLegendStyle::Title, mTitleFontButton ->currentFont () );
376
+ mLegend ->adjustBoxSize ();
377
+ mLegend ->update ();
378
+ mLegend ->endCommand ();
370
379
}
371
380
}
372
381
373
- void QgsComposerLegendWidget::on_mGroupFontButton_clicked ()
382
+ void QgsComposerLegendWidget::groupFontChanged ()
374
383
{
375
384
if ( mLegend )
376
385
{
377
- bool ok;
378
- QFont newFont = QgsGuiUtils::getFont ( ok, mLegend ->style ( QgsLegendStyle::Group ).font () );
379
- if ( ok )
380
- {
381
- mLegend ->beginCommand ( tr ( " Legend group font changed" ) );
382
- mLegend ->setStyleFont ( QgsLegendStyle::Group, newFont );
383
- mLegend ->adjustBoxSize ();
384
- mLegend ->update ();
385
- mLegend ->endCommand ();
386
- }
386
+ mLegend ->beginCommand ( tr ( " Legend group font changed" ) );
387
+ mLegend ->setStyleFont ( QgsLegendStyle::Group, mGroupFontButton ->currentFont () );
388
+ mLegend ->adjustBoxSize ();
389
+ mLegend ->update ();
390
+ mLegend ->endCommand ();
387
391
}
388
392
}
389
393
390
- void QgsComposerLegendWidget::on_mLayerFontButton_clicked ()
394
+ void QgsComposerLegendWidget::layerFontChanged ()
391
395
{
392
396
if ( mLegend )
393
397
{
394
- bool ok;
395
- QFont newFont = QgsGuiUtils::getFont ( ok, mLegend ->style ( QgsLegendStyle::Subgroup ).font () );
396
- if ( ok )
397
- {
398
- mLegend ->beginCommand ( tr ( " Legend layer font changed" ) );
399
- mLegend ->setStyleFont ( QgsLegendStyle::Subgroup, newFont );
400
- mLegend ->adjustBoxSize ();
401
- mLegend ->update ();
402
- mLegend ->endCommand ();
403
- }
398
+ mLegend ->beginCommand ( tr ( " Legend layer font changed" ) );
399
+ mLegend ->setStyleFont ( QgsLegendStyle::Subgroup, mLayerFontButton ->currentFont () );
400
+ mLegend ->adjustBoxSize ();
401
+ mLegend ->update ();
402
+ mLegend ->endCommand ();
404
403
}
405
404
}
406
405
407
- void QgsComposerLegendWidget::on_mItemFontButton_clicked ()
406
+ void QgsComposerLegendWidget::itemFontChanged ()
408
407
{
409
408
if ( mLegend )
410
409
{
411
- bool ok;
412
- QFont newFont = QgsGuiUtils::getFont ( ok, mLegend ->style ( QgsLegendStyle::SymbolLabel ).font () );
413
- if ( ok )
414
- {
415
- mLegend ->beginCommand ( tr ( " Legend item font changed" ) );
416
- mLegend ->setStyleFont ( QgsLegendStyle::SymbolLabel, newFont );
417
- mLegend ->adjustBoxSize ();
418
- mLegend ->update ();
419
- mLegend ->endCommand ();
420
- }
410
+ mLegend ->beginCommand ( tr ( " Legend item font changed" ) );
411
+ mLegend ->setStyleFont ( QgsLegendStyle::SymbolLabel, mItemFontButton ->currentFont () );
412
+ mLegend ->adjustBoxSize ();
413
+ mLegend ->update ();
414
+ mLegend ->endCommand ();
421
415
}
422
416
}
423
417
@@ -939,6 +933,10 @@ void QgsComposerLegendWidget::blockAllSignals( bool b )
939
933
mCheckboxResizeContents ->blockSignals ( b );
940
934
mTitleSpaceBottomSpinBox ->blockSignals ( b );
941
935
mFilterLegendByAtlasCheckBox ->blockSignals ( b );
936
+ mTitleFontButton ->blockSignals ( b );
937
+ mGroupFontButton ->blockSignals ( b );
938
+ mLayerFontButton ->blockSignals ( b );
939
+ mItemFontButton ->blockSignals ( b );
942
940
}
943
941
944
942
void QgsComposerLegendWidget::selectedChanged ( const QModelIndex ¤t, const QModelIndex &previous )
0 commit comments