Skip to content
Permalink
Browse files

Add map units, join styles and transp. fill to buffer options in adv …

…labeling

- Preview now shows when interior of buffer is set to transparent
- Text size in map units are now not reset to pts when choosing a font
- Preview background is now saved with PAL settings per layer
- Add groupbox title warning about missmatch of unit type between text and buffer
- Preview now does not show buffer if it is in map units and the text is in pts
- Preview now shows map units text/buffer visual ratio within reason (looks like map labels)
- Preview can now be dynamically scaled between 8 and 152 pts size
- Defaults for new setting methods set to match previous defaults (backwards compat.)
  • Loading branch information
dakcarto committed Aug 16, 2012
1 parent ac4486a commit 7079f20ebf2c0ba10b1669b5e084ca2f06d3eee2
@@ -43,14 +43,18 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
setupUi( this );

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

connect( btnTextColor, SIGNAL( clicked() ), this, SLOT( changeTextColor() ) );
connect( btnChangeFont, SIGNAL( clicked() ), this, SLOT( changeTextFont() ) );
connect( mFontSizeUnitComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( updatePreview() ) );
connect( mFontTranspSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( updatePreview() ) );
connect( chkBuffer, SIGNAL( toggled( bool ) ), this, SLOT( updatePreview() ) );
connect( btnBufferColor, SIGNAL( clicked() ), this, SLOT( changeBufferColor() ) );
connect( spinBufferSize, SIGNAL( valueChanged( double ) ), this, SLOT( updatePreview() ) );
connect( mBufferTranspSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( updatePreview() ) );
connect( mBufferJoinStyleComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( updatePreview() ) );
connect( mBufferTranspFillChbx, SIGNAL( toggled( bool ) ), this, SLOT( updatePreview() ) );
connect( btnEngineSettings, SIGNAL( clicked() ), this, SLOT( showEngineConfigDialog() ) );
connect( btnExpression, SIGNAL( clicked() ), this, SLOT( showExpressionDialog() ) );

@@ -146,6 +150,9 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
wrapCharacterEdit->setText( lyr.wrapChar );
chkPreserveRotation->setChecked( lyr.preserveRotation );

mPreviewBackgroundBtn->setColor( lyr.previewBkgrdColor );
setPreviewBackground( lyr.previewBkgrdColor );

bool scaleBased = ( lyr.scaleMin != 0 && lyr.scaleMax != 0 );
chkScaleBasedVisibility->setChecked( scaleBased );
if ( scaleBased )
@@ -157,12 +164,24 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
bool buffer = ( lyr.bufferSize != 0 );
chkBuffer->setChecked( buffer );
if ( buffer )
{
spinBufferSize->setValue( lyr.bufferSize );
if ( lyr.bufferSizeInMapUnits )
{
mBufferUnitComboBox->setCurrentIndex( 1 );
}
else
{
mBufferUnitComboBox->setCurrentIndex( 0 );
}
btnBufferColor->setColor( lyr.bufferColor );
mBufferTranspSpinBox->setValue( lyr.bufferTransp );
mBufferJoinStyleComboBox->setPenJoinStyle( lyr.bufferJoinStyle );
mBufferTranspFillChbx->setChecked( !lyr.bufferNoFill );
}

btnTextColor->setColor( lyr.textColor );
mFontTranspSpinBox->setValue( lyr.textTransp );
btnBufferColor->setColor( lyr.bufferColor );
mBufferTranspSpinBox->setValue( lyr.bufferTransp );

bool formattedNumbers = lyr.formatNumbers;
bool plusSign = lyr.plusSign;
@@ -177,7 +196,6 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
chkPlusSign->setChecked( plusSign );
}


if ( lyr.fontSizeInMapUnits )
{
mFontSizeUnitComboBox->setCurrentIndex( 1 );
@@ -285,6 +303,7 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
lyr.textColor = btnTextColor->color();
lyr.textFont = mRefFont;
lyr.textTransp = mFontTranspSpinBox->value();
lyr.previewBkgrdColor = mPreviewBackgroundBtn->color();
lyr.enabled = chkEnableLabeling->isChecked();
lyr.priority = sliderPriority->value();
lyr.obstacle = !chkNoObstacle->isChecked();
@@ -304,6 +323,9 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
lyr.bufferSize = spinBufferSize->value();
lyr.bufferColor = btnBufferColor->color();
lyr.bufferTransp = mBufferTranspSpinBox->value();
lyr.bufferSizeInMapUnits = ( mBufferUnitComboBox->currentIndex() == 1 );
lyr.bufferJoinStyle = mBufferJoinStyleComboBox->penJoinStyle();
lyr.bufferNoFill = !mBufferTranspFillChbx->isChecked();
}
else
{
@@ -438,6 +460,7 @@ void QgsLabelingGui::populateDataDefinedCombos( QgsPalLayerSettings& s )
( *comboIt )->addItem( "", QVariant() );
}

// TODO: don't add field that aren't of appropriate type for the data defined property
const QgsFieldMap& fields = mLayer->dataProvider()->fields();
for ( QgsFieldMap::const_iterator it = fields.constBegin(); it != fields.constEnd(); it++ )
{
@@ -471,18 +494,6 @@ void QgsLabelingGui::populateDataDefinedCombos( QgsPalLayerSettings& s )
setCurrentComboValue( mBufferTranspAttributeComboBox, s, QgsPalLayerSettings::BufferTransp );
}

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 );
@@ -504,9 +515,17 @@ void QgsLabelingGui::changeTextFont()
#endif
if ( ok )
{
if ( mFontSizeUnitComboBox->currentIndex() == 1 )
{
// don't override map units size with selected size from font dialog
font.setPointSizeF( mFontSizeSpinBox->value() );
}
else
{
mFontSizeSpinBox->setValue( font.pointSizeF() );
}
updateFont( font );
}
mFontSizeSpinBox->setValue( mRefFont.pointSizeF() );
}

void QgsLabelingGui::updateFont( QFont font )
@@ -517,12 +536,14 @@ void QgsLabelingGui::updateFont( QFont font )
mRefFont = font;
}

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

// update font name with font face
// QString dupFont = font.toString();
// QFont lblFont = lblFontName->font();
// lblFont.fromString( dupFont );
// lblFont.setPointSizeF( 14 );
// lblFontName->setFont(lblFont);

updatePreview();
}
@@ -532,31 +553,55 @@ void QgsLabelingGui::updatePreview()
scrollPreview();
lblFontPreview->setFont( mRefFont );
QFont previewFont = lblFontPreview->font();
double fontSize = mFontSizeSpinBox->value();
double bufferSize = spinBufferSize->value();
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)" ) );
previewFont.setPointSize( mPreviewSize );
mPreviewSizeSlider->setEnabled( true );
if ( mBufferUnitComboBox->currentIndex() == 1 )
{
groupBox_mPreview->setTitle( tr( "Sample @ %1 pts (using map units)" ).arg( mPreviewSize ) );
bufferSize = ( mPreviewSize / fontSize ) * bufferSize / 2.5;
}
else
{
groupBox_mPreview->setTitle( tr( "Sample @ %1 pts (using map units, STROKE IN mm)" ).arg( mPreviewSize ) );
}
}
else
{
previewFont.setPointSize( mFontSizeSpinBox->value() );
groupBox_mPreview->setTitle( tr( "Sample" ) );
mPreviewSizeSlider->setEnabled( false );
if ( mBufferUnitComboBox->currentIndex() == 1 )
{
groupBox_mPreview->setTitle( tr( "Sample (stroke in map units, NOT SHOWN)" ) );
bufferSize = 0;
}
else
{
previewFont.setPointSize( fontSize );
groupBox_mPreview->setTitle( tr( "Sample" ) );
}
}
lblFontPreview->setFont( previewFont );

QColor prevColor = btnTextColor->color();
prevColor.setAlphaF(( 100.0 - ( double )( mFontTranspSpinBox->value() ) ) / 100.0 );
lblFontPreview->setTextColor( prevColor );

bool bufferNoFill = false;
if ( chkBuffer->isChecked() )
{
QColor buffColor = btnBufferColor->color();
buffColor.setAlphaF(( 100.0 - ( double )( mBufferTranspSpinBox->value() ) ) / 100.0 );
lblFontPreview->setBuffer( spinBufferSize->value(), buffColor );

bufferNoFill = !mBufferTranspFillChbx->isChecked();
lblFontPreview->setBuffer( bufferSize, buffColor, mBufferJoinStyleComboBox->penJoinStyle(), bufferNoFill );
}
else
{
lblFontPreview->setBuffer( 0, Qt::white );
lblFontPreview->setBuffer( 0, Qt::white, Qt::BevelJoin, bufferNoFill );
}
}

@@ -565,6 +610,13 @@ void QgsLabelingGui::scrollPreview()
scrollArea_mPreview->ensureVisible( 0, 0, 0, 0 );
}

void QgsLabelingGui::setPreviewBackground( QColor 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::showEngineConfigDialog()
{
QgsLabelEngineConfigDialog dlg( mLBL, this );
@@ -593,6 +645,9 @@ void QgsLabelingGui::updateUi()
bool buf = chkBuffer->isChecked();
spinBufferSize->setEnabled( buf );
btnBufferColor->setEnabled( buf );
mBufferUnitComboBox->setEnabled( buf );
mBufferTranspSlider->setEnabled( buf );
mBufferTranspSpinBox->setEnabled( buf );

bool scale = chkScaleBasedVisibility->isChecked();
spinScaleMin->setEnabled( scale );
@@ -633,21 +688,15 @@ void QgsLabelingGui::updateOptions()
}
}

void QgsLabelingGui::on_mFontSizeSpinBox_valueChanged( double d )
{
mRefFont.setPointSizeF( d );
updateFont( mRefFont );
}

void QgsLabelingGui::on_mFontSizeUnitComboBox_currentIndexChanged( int index )
void QgsLabelingGui::on_mPreviewSizeSlider_valueChanged( int i )
{
Q_UNUSED( index );
updateFont( mRefFont );
mPreviewSize = i;
updatePreview();
}

void QgsLabelingGui::on_mFontTranspSpinBox_valueChanged( int i )
void QgsLabelingGui::on_mFontSizeSpinBox_valueChanged( double d )
{
Q_UNUSED( i );
mRefFont.setPointSizeF( d );
updateFont( mRefFont );
}

@@ -663,9 +712,10 @@ void QgsLabelingGui::on_mFontLetterSpacingSpinBox_valueChanged( double spacing )
updateFont( mRefFont );
}

void QgsLabelingGui::on_mBufferTranspSpinBox_valueChanged( int i )
void QgsLabelingGui::on_mBufferUnitComboBox_currentIndexChanged( int index )
{
Q_UNUSED( i );
double singleStep = ( index == 1 ) ? 1.0 : 0.1 ; //1.0 for map units, 0.1 for mm
spinBufferSize->setSingleStep( singleStep );
updateFont( mRefFont );
}

@@ -705,6 +755,16 @@ void QgsLabelingGui::on_mPreviewTextBtn_clicked()
updatePreview();
}

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

mPreviewBackgroundBtn->setColor( color );
setPreviewBackground( color );
}

void QgsLabelingGui::disableDataDefinedAlignment()
{
mHorizontalAlignmentComboBox->setCurrentIndex( mHorizontalAlignmentComboBox->findText( "" ) );
@@ -38,7 +38,6 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase

public slots:
void apply();
void changePreviewBackground();
void changeTextColor();
void changeTextFont();
void showEngineConfigDialog();
@@ -50,17 +49,17 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
void scrollPreview();
void updateOptions();

void on_mPreviewSizeSlider_valueChanged( int i );
void on_mFontSizeSpinBox_valueChanged( double d );
void on_mFontSizeUnitComboBox_currentIndexChanged( int index );
void on_mFontTranspSpinBox_valueChanged( int i );
void on_mFontWordSpacingSpinBox_valueChanged( double spacing );
void on_mFontLetterSpacingSpinBox_valueChanged( double spacing );
void on_mBufferTranspSpinBox_valueChanged( int i );
void on_mBufferUnitComboBox_currentIndexChanged( int index );
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();
void on_mPreviewBackgroundBtn_clicked();

protected:
void populatePlacementMethods();
@@ -78,6 +77,8 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase

// background reference font
QFont mRefFont;
int mPreviewSize;
void setPreviewBackground( QColor color );

void disableDataDefinedAlignment();
void enableDataDefinedAlignment();
@@ -30,10 +30,12 @@ void QgsLabelPreview::setTextColor( QColor color )
update();
}

void QgsLabelPreview::setBuffer( double size, QColor color )
void QgsLabelPreview::setBuffer( double size, QColor color, Qt::PenJoinStyle joinStyle, bool noFill )
{
mBufferSize = size * 88 / 25.4; //assume standard dpi for preview
mBufferColor = color;
mBufferJoinStyle = joinStyle;
mBufferNoFill = noFill;
update();
}

@@ -45,10 +47,15 @@ void QgsLabelPreview::paintEvent( QPaintEvent *e )
p.setRenderHint( QPainter::Antialiasing );
p.setFont( font() );
QFontMetrics fm( font() );
p.translate( 0, fm.ascent() + 4 );

double xtrans = 0;
if ( mBufferSize != 0 )
QgsPalLabeling::drawLabelBuffer( &p, text(), font(), mBufferSize, mBufferColor );
xtrans = mBufferSize / 4;

p.translate( xtrans, fm.ascent() + 4 );

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

p.setPen( mTextColor );
p.drawText( 0, 0, text() );
@@ -24,7 +24,7 @@ class QgsLabelPreview : public QLabel

void setTextColor( QColor color );

void setBuffer( double size, QColor color );
void setBuffer( double size, QColor color, Qt::PenJoinStyle joinStyle, bool noFill = false );

void setFont( QFont f ) { mFont = f; }
QFont font() { return mFont; }
@@ -34,6 +34,8 @@ class QgsLabelPreview : public QLabel
private:
int mBufferSize;
QColor mBufferColor;
Qt::PenJoinStyle mBufferJoinStyle;
bool mBufferNoFill;
QColor mTextColor;
QFont mFont;
};

0 comments on commit 7079f20

Please sign in to comment.
You can’t perform that action at this time.