Skip to content

Commit

Permalink
Update to adv labeling dialog, also addresses #4385
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
dakcarto committed Aug 12, 2012
1 parent f69d8d2 commit 547a05a
Show file tree
Hide file tree
Showing 5 changed files with 1,918 additions and 580 deletions.
87 changes: 76 additions & 11 deletions src/app/qgslabelinggui.cpp
Expand Up @@ -42,6 +42,10 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM

setupUi( this );

mRefFont = lblFontPreview->font();
mPreviewBackgroundBtn->setColor( Qt::white );
connect( mPreviewBackgroundBtn, SIGNAL( clicked() ), this, SLOT( changePreviewBackground( ) ) );

connect( btnTextColor, SIGNAL( clicked() ), this, SLOT( changeTextColor() ) );
connect( btnChangeFont, SIGNAL( clicked() ), this, SLOT( changeTextFont() ) );
connect( chkBuffer, SIGNAL( toggled( bool ) ), this, SLOT( updatePreview() ) );
Expand Down Expand Up @@ -277,7 +281,7 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()


lyr.textColor = btnTextColor->color();
lyr.textFont = lblFontPreview->font();
lyr.textFont = mRefFont;
lyr.enabled = chkEnableLabeling->isChecked();
lyr.priority = sliderPriority->value();
lyr.obstacle = !chkNoObstacle->isChecked();
Expand Down Expand Up @@ -448,6 +452,18 @@ void QgsLabelingGui::populateDataDefinedCombos( QgsPalLayerSettings& s )
setCurrentComboValue( mRotationComboBox, s, QgsPalLayerSettings::Rotation );
}

void QgsLabelingGui::changePreviewBackground()
{
QColor color = QColorDialog::getColor( mPreviewBackgroundBtn->color(), this );
if ( !color.isValid() )
return;

mPreviewBackgroundBtn->setColor( color );
scrollArea_mPreview->widget()->setStyleSheet( QString( "background: rgb(%1, %2, %3);" ).arg( QString::number( color.red() ),
QString::number( color.green() ),
QString::number( color.blue() ) ) );
}

void QgsLabelingGui::changeTextColor()
{
QColor color = QColorDialog::getColor( btnTextColor->color(), this );
Expand All @@ -463,38 +479,65 @@ void QgsLabelingGui::changeTextFont()
bool ok;
#if defined(Q_WS_MAC) && QT_VERSION >= 0x040500 && defined(QT_MAC_USE_COCOA)
// Native Mac dialog works only for Qt Carbon
QFont font = QFontDialog::getFont( &ok, lblFontPreview->font(), 0, QString(), QFontDialog::DontUseNativeDialog );
QFont font = QFontDialog::getFont( &ok, mRefFont, 0, QString(), QFontDialog::DontUseNativeDialog );
#else
QFont font = QFontDialog::getFont( &ok, lblFontPreview->font() );
QFont font = QFontDialog::getFont( &ok, mRefFont );
#endif
if ( ok )
{
updateFont( font );
}
mFontSizeSpinBox->setValue( font.pointSizeF() );
mFontSizeSpinBox->setValue( mRefFont.pointSizeF() );
}

void QgsLabelingGui::updateFont( QFont font )
{
// update background reference font
if ( font != mRefFont )
{
mRefFont = font;
}

QString fontSizeUnitString = tr( "pt" );
if ( mFontSizeUnitComboBox->currentIndex() == 1 )
{
fontSizeUnitString = tr( "map units" );
}
lblFontName->setText( QString( "%1, %2 %3" ).arg( font.family() ).arg( font.pointSizeF() ).arg( fontSizeUnitString ) );
lblFontPreview->setFont( font );
lblFontName->setText( QString( "%1, %2 %3" ).arg( font.family() ).arg( mRefFont.pointSizeF() ).arg( fontSizeUnitString ) );

updatePreview();
}

void QgsLabelingGui::updatePreview()
{
scrollPreview();
lblFontPreview->setFont( mRefFont );
QFont previewFont = lblFontPreview->font();
if ( mFontSizeUnitComboBox->currentIndex() == 1 )
{
// TODO: maybe match current map zoom level instead?
previewFont.setPointSize( 24 );
groupBox_mPreview->setTitle( tr( "Sample @ 24 pts (using map units)" ) );
}
else
{
previewFont.setPointSize( mFontSizeSpinBox->value() );
groupBox_mPreview->setTitle( tr( "Sample" ) );
}
lblFontPreview->setFont( previewFont );

lblFontPreview->setTextColor( btnTextColor->color() );
if ( chkBuffer->isChecked() )
lblFontPreview->setBuffer( spinBufferSize->value(), btnBufferColor->color() );
else
lblFontPreview->setBuffer( 0, Qt::white );
}

void QgsLabelingGui::scrollPreview()
{
scrollArea_mPreview->ensureVisible( 0, 0, 0, 0 );
}

void QgsLabelingGui::showEngineConfigDialog()
{
QgsLabelEngineConfigDialog dlg( mLBL, this );
Expand Down Expand Up @@ -565,16 +608,26 @@ void QgsLabelingGui::updateOptions()

void QgsLabelingGui::on_mFontSizeSpinBox_valueChanged( double d )
{
QFont font = lblFontPreview->font();
font.setPointSizeF( d );
lblFontPreview->setFont( font );
updateFont( font );
mRefFont.setPointSizeF( d );
updateFont( mRefFont );
}

void QgsLabelingGui::on_mFontSizeUnitComboBox_currentIndexChanged( int index )
{
Q_UNUSED( index );
updateFont( lblFontPreview->font() );
updateFont( mRefFont );
}

void QgsLabelingGui::on_mFontWordSpacingSpinBox_valueChanged( double spacing )
{
mRefFont.setWordSpacing( spacing );
updateFont( mRefFont );
}

void QgsLabelingGui::on_mFontLetterSpacingSpinBox_valueChanged( double spacing )
{
mRefFont.setLetterSpacing( QFont::AbsoluteSpacing, spacing );
updateFont( mRefFont );
}

void QgsLabelingGui::on_mXCoordinateComboBox_currentIndexChanged( const QString & text )
Expand All @@ -601,6 +654,18 @@ void QgsLabelingGui::on_mYCoordinateComboBox_currentIndexChanged( const QString
}
}

void QgsLabelingGui::on_mPreviewTextEdit_textChanged( const QString & text )
{
lblFontPreview->setText( text );
updatePreview();
}

void QgsLabelingGui::on_mPreviewTextBtn_clicked()
{
mPreviewTextEdit->setText( QString( "Lorem Ipsum" ) );
updatePreview();
}

void QgsLabelingGui::disableDataDefinedAlignment()
{
mHorizontalAlignmentComboBox->setCurrentIndex( mHorizontalAlignmentComboBox->findText( "" ) );
Expand Down
10 changes: 10 additions & 0 deletions src/app/qgslabelinggui.h
Expand Up @@ -38,6 +38,7 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase

public slots:
void apply();
void changePreviewBackground();
void changeTextColor();
void changeTextFont();
void showEngineConfigDialog();
Expand All @@ -46,13 +47,19 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase

void updateUi();
void updatePreview();
void scrollPreview();
void updateOptions();

void on_mFontSizeSpinBox_valueChanged( double d );
void on_mFontSizeUnitComboBox_currentIndexChanged( int index );
void on_mFontWordSpacingSpinBox_valueChanged(double spacing );
void on_mFontLetterSpacingSpinBox_valueChanged(double spacing );
void on_mXCoordinateComboBox_currentIndexChanged( const QString & text );
void on_mYCoordinateComboBox_currentIndexChanged( const QString & text );

void on_mPreviewTextEdit_textChanged( const QString & text );
void on_mPreviewTextBtn_clicked();

protected:
void populatePlacementMethods();
void populateFieldNames();
Expand All @@ -67,6 +74,9 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
QgsVectorLayer* mLayer;
QgsMapCanvas* mMapCanvas;

// background reference font
QFont mRefFont;

void disableDataDefinedAlignment();
void enableDataDefinedAlignment();
};
Expand Down
6 changes: 5 additions & 1 deletion src/app/qgslabelpreview.cpp
Expand Up @@ -15,6 +15,7 @@
#include "qgslabelpreview.h"

#include <QPainter>
#include <QFontMetrics>

#include "qgspallabeling.h"

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

p.setRenderHint( QPainter::Antialiasing );
p.setFont( font() );
p.translate( 10, 20 ); // uhm...
QFontMetrics fm( font() );
p.translate( 0, fm.ascent() + 4 );

// mBufferColor.setAlpha( 125 );

if ( mBufferSize != 0 )
QgsPalLabeling::drawLabelBuffer( &p, text(), font(), mBufferSize, mBufferColor );
Expand Down
1 change: 1 addition & 0 deletions src/core/qgspallabeling.cpp
Expand Up @@ -1430,6 +1430,7 @@ void QgsPalLabeling::drawLabelBuffer( QPainter* p, QString text, const QFont& fo
{
QPainterPath path;
path.addText( 0, 0, font, text );
// color.setAlpha( 125 );
QPen pen( color );
pen.setWidthF( size );
p->setPen( pen );
Expand Down

0 comments on commit 547a05a

Please sign in to comment.