@@ -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+
451467void 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
477493void 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
489511void 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+
498541void QgsLabelingGui::showEngineConfigDialog ()
499542{
500543 QgsLabelEngineConfigDialog dlg ( mLBL , this );
@@ -565,16 +608,26 @@ void QgsLabelingGui::updateOptions()
565608
566609void 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
574615void 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
580633void 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+
604669void QgsLabelingGui::disableDataDefinedAlignment ()
605670{
606671 mHorizontalAlignmentComboBox ->setCurrentIndex ( mHorizontalAlignmentComboBox ->findText ( " " ) );
0 commit comments