@@ -63,6 +63,11 @@ QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend *legend )
6363 setupUi ( this );
6464 setPanelTitle ( tr ( " Legend properties" ) );
6565
66+ mTitleFontButton ->setMode ( QgsFontButton::ModeQFont );
67+ mGroupFontButton ->setMode ( QgsFontButton::ModeQFont );
68+ mLayerFontButton ->setMode ( QgsFontButton::ModeQFont );
69+ mItemFontButton ->setMode ( QgsFontButton::ModeQFont );
70+
6671 // setup icons
6772 mAddToolButton ->setIcon ( QIcon ( QgsApplication::iconPath ( " symbologyAdd.svg" ) ) );
6873 mEditPushButton ->setIcon ( QIcon ( QgsApplication::iconPath ( " symbologyEdit.png" ) ) );
@@ -108,6 +113,10 @@ QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend *legend )
108113
109114 connect ( mItemTreeView ->selectionModel (), &QItemSelectionModel::currentChanged,
110115 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 );
111120}
112121
113122QgsComposerLegendWidget::QgsComposerLegendWidget (): QgsComposerItemBaseWidget( nullptr , nullptr ), mLegend( nullptr )
@@ -162,6 +171,11 @@ void QgsComposerLegendWidget::setGuiElements()
162171 const QgsComposerMap *map = mLegend ->composerMap ();
163172 mMapComboBox ->setItem ( map );
164173 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+
165179 blockAllSignals ( false );
166180
167181 on_mCheckBoxAutoUpdate_stateChanged ( mLegend ->autoUpdateModel () ? Qt::Checked : Qt::Unchecked );
@@ -353,71 +367,51 @@ void QgsComposerLegendWidget::on_mIconLabelSpaceSpinBox_valueChanged( double d )
353367 }
354368}
355369
356- void QgsComposerLegendWidget::on_mTitleFontButton_clicked ()
370+ void QgsComposerLegendWidget::titleFontChanged ()
357371{
358372 if ( mLegend )
359373 {
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 ();
370379 }
371380}
372381
373- void QgsComposerLegendWidget::on_mGroupFontButton_clicked ()
382+ void QgsComposerLegendWidget::groupFontChanged ()
374383{
375384 if ( mLegend )
376385 {
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 ();
387391 }
388392}
389393
390- void QgsComposerLegendWidget::on_mLayerFontButton_clicked ()
394+ void QgsComposerLegendWidget::layerFontChanged ()
391395{
392396 if ( mLegend )
393397 {
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 ();
404403 }
405404}
406405
407- void QgsComposerLegendWidget::on_mItemFontButton_clicked ()
406+ void QgsComposerLegendWidget::itemFontChanged ()
408407{
409408 if ( mLegend )
410409 {
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 ();
421415 }
422416}
423417
@@ -939,6 +933,10 @@ void QgsComposerLegendWidget::blockAllSignals( bool b )
939933 mCheckboxResizeContents ->blockSignals ( b );
940934 mTitleSpaceBottomSpinBox ->blockSignals ( b );
941935 mFilterLegendByAtlasCheckBox ->blockSignals ( b );
936+ mTitleFontButton ->blockSignals ( b );
937+ mGroupFontButton ->blockSignals ( b );
938+ mLayerFontButton ->blockSignals ( b );
939+ mItemFontButton ->blockSignals ( b );
942940}
943941
944942void QgsComposerLegendWidget::selectedChanged ( const QModelIndex ¤t, const QModelIndex &previous )
0 commit comments