Skip to content

Commit 547a05a

Browse files
committed
Update to adv labeling dialog, also addresses #4385
- Fix for resizing of dialog (#4385) - New label preview pane with custom text entry and background color (preview moved to Label settings tab) - Fix preview for labels using map units (standardized to 24 pt) - Preview layout accommodates up 150 pt fonts on larger screens - Set step increment for buffer to a more reasonable 0.1 - New, fairly complete QFont properties added to GUI (some may not be able to be used until after derived PAL solution) - Transparency for buffering added to GUI - New data defined mappings in the GUI to match new layer-level options - New Show Label and Min/Max Scale mappings added to GUI - All new options and mappings that are not yet functional are greyed (all greyed with this commit)
1 parent f69d8d2 commit 547a05a

File tree

5 files changed

+1918
-580
lines changed

5 files changed

+1918
-580
lines changed

src/app/qgslabelinggui.cpp

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
4242

4343
setupUi( this );
4444

45+
mRefFont = lblFontPreview->font();
46+
mPreviewBackgroundBtn->setColor( Qt::white );
47+
connect( mPreviewBackgroundBtn, SIGNAL( clicked() ), this, SLOT( changePreviewBackground( ) ) );
48+
4549
connect( btnTextColor, SIGNAL( clicked() ), this, SLOT( changeTextColor() ) );
4650
connect( btnChangeFont, SIGNAL( clicked() ), this, SLOT( changeTextFont() ) );
4751
connect( chkBuffer, SIGNAL( toggled( bool ) ), this, SLOT( updatePreview() ) );
@@ -277,7 +281,7 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
277281

278282

279283
lyr.textColor = btnTextColor->color();
280-
lyr.textFont = lblFontPreview->font();
284+
lyr.textFont = mRefFont;
281285
lyr.enabled = chkEnableLabeling->isChecked();
282286
lyr.priority = sliderPriority->value();
283287
lyr.obstacle = !chkNoObstacle->isChecked();
@@ -448,6 +452,18 @@ void QgsLabelingGui::populateDataDefinedCombos( QgsPalLayerSettings& s )
448452
setCurrentComboValue( mRotationComboBox, s, QgsPalLayerSettings::Rotation );
449453
}
450454

455+
void QgsLabelingGui::changePreviewBackground()
456+
{
457+
QColor color = QColorDialog::getColor( mPreviewBackgroundBtn->color(), this );
458+
if ( !color.isValid() )
459+
return;
460+
461+
mPreviewBackgroundBtn->setColor( color );
462+
scrollArea_mPreview->widget()->setStyleSheet( QString( "background: rgb(%1, %2, %3);" ).arg( QString::number( color.red() ),
463+
QString::number( color.green() ),
464+
QString::number( color.blue() ) ) );
465+
}
466+
451467
void QgsLabelingGui::changeTextColor()
452468
{
453469
QColor color = QColorDialog::getColor( btnTextColor->color(), this );
@@ -463,38 +479,65 @@ void QgsLabelingGui::changeTextFont()
463479
bool ok;
464480
#if defined(Q_WS_MAC) && QT_VERSION >= 0x040500 && defined(QT_MAC_USE_COCOA)
465481
// Native Mac dialog works only for Qt Carbon
466-
QFont font = QFontDialog::getFont( &ok, lblFontPreview->font(), 0, QString(), QFontDialog::DontUseNativeDialog );
482+
QFont font = QFontDialog::getFont( &ok, mRefFont, 0, QString(), QFontDialog::DontUseNativeDialog );
467483
#else
468-
QFont font = QFontDialog::getFont( &ok, lblFontPreview->font() );
484+
QFont font = QFontDialog::getFont( &ok, mRefFont );
469485
#endif
470486
if ( ok )
471487
{
472488
updateFont( font );
473489
}
474-
mFontSizeSpinBox->setValue( font.pointSizeF() );
490+
mFontSizeSpinBox->setValue( mRefFont.pointSizeF() );
475491
}
476492

477493
void QgsLabelingGui::updateFont( QFont font )
478494
{
495+
// update background reference font
496+
if ( font != mRefFont )
497+
{
498+
mRefFont = font;
499+
}
500+
479501
QString fontSizeUnitString = tr( "pt" );
480502
if ( mFontSizeUnitComboBox->currentIndex() == 1 )
481503
{
482504
fontSizeUnitString = tr( "map units" );
483505
}
484-
lblFontName->setText( QString( "%1, %2 %3" ).arg( font.family() ).arg( font.pointSizeF() ).arg( fontSizeUnitString ) );
485-
lblFontPreview->setFont( font );
506+
lblFontName->setText( QString( "%1, %2 %3" ).arg( font.family() ).arg( mRefFont.pointSizeF() ).arg( fontSizeUnitString ) );
507+
486508
updatePreview();
487509
}
488510

489511
void QgsLabelingGui::updatePreview()
490512
{
513+
scrollPreview();
514+
lblFontPreview->setFont( mRefFont );
515+
QFont previewFont = lblFontPreview->font();
516+
if ( mFontSizeUnitComboBox->currentIndex() == 1 )
517+
{
518+
// TODO: maybe match current map zoom level instead?
519+
previewFont.setPointSize( 24 );
520+
groupBox_mPreview->setTitle( tr( "Sample @ 24 pts (using map units)" ) );
521+
}
522+
else
523+
{
524+
previewFont.setPointSize( mFontSizeSpinBox->value() );
525+
groupBox_mPreview->setTitle( tr( "Sample" ) );
526+
}
527+
lblFontPreview->setFont( previewFont );
528+
491529
lblFontPreview->setTextColor( btnTextColor->color() );
492530
if ( chkBuffer->isChecked() )
493531
lblFontPreview->setBuffer( spinBufferSize->value(), btnBufferColor->color() );
494532
else
495533
lblFontPreview->setBuffer( 0, Qt::white );
496534
}
497535

536+
void QgsLabelingGui::scrollPreview()
537+
{
538+
scrollArea_mPreview->ensureVisible( 0, 0, 0, 0 );
539+
}
540+
498541
void QgsLabelingGui::showEngineConfigDialog()
499542
{
500543
QgsLabelEngineConfigDialog dlg( mLBL, this );
@@ -565,16 +608,26 @@ void QgsLabelingGui::updateOptions()
565608

566609
void QgsLabelingGui::on_mFontSizeSpinBox_valueChanged( double d )
567610
{
568-
QFont font = lblFontPreview->font();
569-
font.setPointSizeF( d );
570-
lblFontPreview->setFont( font );
571-
updateFont( font );
611+
mRefFont.setPointSizeF( d );
612+
updateFont( mRefFont );
572613
}
573614

574615
void QgsLabelingGui::on_mFontSizeUnitComboBox_currentIndexChanged( int index )
575616
{
576617
Q_UNUSED( index );
577-
updateFont( lblFontPreview->font() );
618+
updateFont( mRefFont );
619+
}
620+
621+
void QgsLabelingGui::on_mFontWordSpacingSpinBox_valueChanged( double spacing )
622+
{
623+
mRefFont.setWordSpacing( spacing );
624+
updateFont( mRefFont );
625+
}
626+
627+
void QgsLabelingGui::on_mFontLetterSpacingSpinBox_valueChanged( double spacing )
628+
{
629+
mRefFont.setLetterSpacing( QFont::AbsoluteSpacing, spacing );
630+
updateFont( mRefFont );
578631
}
579632

580633
void QgsLabelingGui::on_mXCoordinateComboBox_currentIndexChanged( const QString & text )
@@ -601,6 +654,18 @@ void QgsLabelingGui::on_mYCoordinateComboBox_currentIndexChanged( const QString
601654
}
602655
}
603656

657+
void QgsLabelingGui::on_mPreviewTextEdit_textChanged( const QString & text )
658+
{
659+
lblFontPreview->setText( text );
660+
updatePreview();
661+
}
662+
663+
void QgsLabelingGui::on_mPreviewTextBtn_clicked()
664+
{
665+
mPreviewTextEdit->setText( QString( "Lorem Ipsum" ) );
666+
updatePreview();
667+
}
668+
604669
void QgsLabelingGui::disableDataDefinedAlignment()
605670
{
606671
mHorizontalAlignmentComboBox->setCurrentIndex( mHorizontalAlignmentComboBox->findText( "" ) );

src/app/qgslabelinggui.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
3838

3939
public slots:
4040
void apply();
41+
void changePreviewBackground();
4142
void changeTextColor();
4243
void changeTextFont();
4344
void showEngineConfigDialog();
@@ -46,13 +47,19 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
4647

4748
void updateUi();
4849
void updatePreview();
50+
void scrollPreview();
4951
void updateOptions();
5052

5153
void on_mFontSizeSpinBox_valueChanged( double d );
5254
void on_mFontSizeUnitComboBox_currentIndexChanged( int index );
55+
void on_mFontWordSpacingSpinBox_valueChanged(double spacing );
56+
void on_mFontLetterSpacingSpinBox_valueChanged(double spacing );
5357
void on_mXCoordinateComboBox_currentIndexChanged( const QString & text );
5458
void on_mYCoordinateComboBox_currentIndexChanged( const QString & text );
5559

60+
void on_mPreviewTextEdit_textChanged( const QString & text );
61+
void on_mPreviewTextBtn_clicked();
62+
5663
protected:
5764
void populatePlacementMethods();
5865
void populateFieldNames();
@@ -67,6 +74,9 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
6774
QgsVectorLayer* mLayer;
6875
QgsMapCanvas* mMapCanvas;
6976

77+
// background reference font
78+
QFont mRefFont;
79+
7080
void disableDataDefinedAlignment();
7181
void enableDataDefinedAlignment();
7282
};

src/app/qgslabelpreview.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "qgslabelpreview.h"
1616

1717
#include <QPainter>
18+
#include <QFontMetrics>
1819

1920
#include "qgspallabeling.h"
2021

@@ -43,7 +44,10 @@ void QgsLabelPreview::paintEvent( QPaintEvent *e )
4344

4445
p.setRenderHint( QPainter::Antialiasing );
4546
p.setFont( font() );
46-
p.translate( 10, 20 ); // uhm...
47+
QFontMetrics fm( font() );
48+
p.translate( 0, fm.ascent() + 4 );
49+
50+
// mBufferColor.setAlpha( 125 );
4751

4852
if ( mBufferSize != 0 )
4953
QgsPalLabeling::drawLabelBuffer( &p, text(), font(), mBufferSize, mBufferColor );

src/core/qgspallabeling.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,7 @@ void QgsPalLabeling::drawLabelBuffer( QPainter* p, QString text, const QFont& fo
14301430
{
14311431
QPainterPath path;
14321432
path.addText( 0, 0, font, text );
1433+
// color.setAlpha( 125 );
14331434
QPen pen( color );
14341435
pen.setWidthF( size );
14351436
p->setPen( pen );

0 commit comments

Comments
 (0)