Skip to content
Permalink
Browse files

Add capitalization support to PAL layer of adv labeling

- Title case does not convert existing uppercase->lowercase, only lowercase->uppercase (Qt issue)
- Didn't offer QFont::SmallCaps option as it does not work right with QPainterPath::addText()
  see https://bugreports.qt-project.org/browse/QTBUG-13965
- Store and re-apply some QFont properties stripped when choosing new typeface
- Move sample background color selector right of sample text
  • Loading branch information
dakcarto committed Aug 29, 2012
1 parent 84f2726 commit 0386a637c77bee093013196e138a3b4fd7554058
Showing with 76 additions and 46 deletions.
  1. +30 −1 src/app/qgslabelinggui.cpp
  2. +2 −0 src/app/qgslabelinggui.h
  3. +2 −0 src/core/qgspallabeling.cpp
  4. +42 −45 src/ui/qgslabelingguibase.ui
@@ -85,6 +85,7 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
lyr.readFromLayer( layer );
populateFieldNames();
populateDataDefinedCombos( lyr );
populateFontCapitalsComboBox();

chkEnableLabeling->setChecked( lyr.enabled );
mTabWidget->setEnabled( lyr.enabled );
@@ -509,6 +510,9 @@ void QgsLabelingGui::changeTextColor()

void QgsLabelingGui::changeTextFont()
{
// store properties of QFont that might be stripped by font dialog
QFont::Capitalization captials = mRefFont.capitalization();

bool ok;
#if defined(Q_WS_MAC) && QT_VERSION >= 0x040500 && defined(QT_MAC_USE_COCOA)
// Native Mac dialog works only for Qt Carbon
@@ -527,6 +531,10 @@ void QgsLabelingGui::changeTextFont()
{
mFontSizeSpinBox->setValue( font.pointSizeF() );
}

// reassign possibly stripped QFont properties
font.setCapitalization( captials );

updateFont( font );
}
}
@@ -558,6 +566,7 @@ void QgsLabelingGui::updateFontViaStyle( const QString & fontstyle )
}
if ( foundmatch )
{
styledfont.setCapitalization( mRefFont.capitalization() );
styledfont.setUnderline( mRefFont.underline() );
styledfont.setStrikeOut( mRefFont.strikeOut() );
mRefFont = styledfont;
@@ -598,12 +607,14 @@ void QgsLabelingGui::updateFont( QFont font )

blockFontChangeSignals( true );
populateFontStyleComboBox();
int idx = mFontCapitalsComboBox->findData( QVariant(( unsigned int ) mRefFont.capitalization() ) );
mFontCapitalsComboBox->setCurrentIndex( idx == -1 ? 0 : idx );
mFontUnderlineBtn->setChecked( mRefFont.underline() );
mFontStrikethroughBtn->setChecked( mRefFont.strikeOut() );
blockFontChangeSignals( false );

// update font name with font face
// font.setPixelSize( 18 );
// font.setPixelSize( 24 );
// lblFontName->setFont( QFont( font ) );

updatePreview();
@@ -769,6 +780,17 @@ void QgsLabelingGui::updateOptions()
}
}

void QgsLabelingGui::populateFontCapitalsComboBox()
{
mFontCapitalsComboBox->addItem( tr( "Mixed Case" ), QVariant( 0 ) );
mFontCapitalsComboBox->addItem( tr( "All Uppercase" ), QVariant( 1 ) );
mFontCapitalsComboBox->addItem( tr( "All Lowercase" ), QVariant( 2 ) );
// Small caps doesn't work right with QPainterPath::addText()
// https://bugreports.qt-project.org/browse/QTBUG-13965
// mFontCapitalsComboBox->addItem( tr( "Small Caps" ), QVariant( 3 ) );
mFontCapitalsComboBox->addItem( tr( "Title Case" ), QVariant( 4 ) );
}

void QgsLabelingGui::populateFontStyleComboBox()
{
mFontStyleComboBox->clear();
@@ -791,6 +813,13 @@ void QgsLabelingGui::on_mFontSizeSpinBox_valueChanged( double d )
updateFont( mRefFont );
}

void QgsLabelingGui::on_mFontCapitalsComboBox_currentIndexChanged( int index )
{
int capitalsindex = mFontCapitalsComboBox->itemData( index ).toUInt();
mRefFont.setCapitalization(( QFont::Capitalization ) capitalsindex );
updateFont( mRefFont );
}

void QgsLabelingGui::on_mFontStyleComboBox_currentIndexChanged( const QString & text )
{
updateFontViaStyle( text );
@@ -52,6 +52,7 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase

void on_mPreviewSizeSlider_valueChanged( int i );
void on_mFontSizeSpinBox_valueChanged( double d );
void on_mFontCapitalsComboBox_currentIndexChanged( int index );
void on_mFontStyleComboBox_currentIndexChanged( const QString & text );
void on_mFontUnderlineBtn_toggled( bool ckd );
void on_mFontStrikethroughBtn_toggled( bool ckd );
@@ -69,6 +70,7 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
void blockFontChangeSignals( bool blk );
void setPreviewBackground( QColor color );
void updateFontViaStyle( const QString & fontstyle );
void populateFontCapitalsComboBox();
void populateFontStyleComboBox();
void populatePlacementMethods();
void populateFieldNames();
@@ -351,6 +351,7 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
textFont.setPointSizeF( fontSize ); //double precision needed because of map units
textNamedStyle = layer->customProperty( "labeling/namedStyle", QVariant( "" ) ).toString();
updateFontViaStyle( textNamedStyle );
textFont.setCapitalization(( QFont::Capitalization ) layer->customProperty( "labeling/fontCapitals", QVariant( 0 ) ).toUInt() );
textFont.setUnderline( layer->customProperty( "labeling/fontUnderline" ).toBool() );
textFont.setStrikeOut( layer->customProperty( "labeling/fontStrikeout" ).toBool() );
textColor = _readColor( layer, "labeling/textColor" );
@@ -394,6 +395,7 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer* layer )

layer->setCustomProperty( "labeling/fontFamily", textFont.family() );
layer->setCustomProperty( "labeling/namedStyle", textNamedStyle );
layer->setCustomProperty( "labeling/fontCapitals", ( unsigned int )textFont.capitalization() );
layer->setCustomProperty( "labeling/fontSize", textFont.pointSizeF() );
layer->setCustomProperty( "labeling/fontWeight", textFont.weight() );
layer->setCustomProperty( "labeling/fontItalic", textFont.italic() );
@@ -256,25 +256,6 @@
<property name="leftMargin">
<number>0</number>
</property>
<item>
<widget class="QgsColorButton" name="mPreviewBackgroundBtn">
<property name="minimumSize">
<size>
<width>48</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>22</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mPreviewTextEdit">
<property name="sizePolicy">
@@ -356,6 +337,9 @@
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Size for sample text in map units</string>
</property>
<property name="minimum">
<number>8</number>
</property>
@@ -376,6 +360,44 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>6</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QgsColorButton" name="mPreviewBackgroundBtn">
<property name="minimumSize">
<size>
<width>48</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>22</height>
</size>
</property>
<property name="toolTip">
<string>Sample Background</string>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
@@ -997,39 +1019,14 @@
<item row="4" column="1">
<widget class="QComboBox" name="mFontCapitalsComboBox">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<item>
<property name="text">
<string>Mixed Case</string>
</property>
</item>
<item>
<property name="text">
<string>All Uppercase</string>
</property>
</item>
<item>
<property name="text">
<string>All Lowercase</string>
</property>
</item>
<item>
<property name="text">
<string>Small Caps</string>
</property>
</item>
<item>
<property name="text">
<string>Capitalize</string>
</property>
</item>
</widget>
</item>
</layout>

0 comments on commit 0386a63

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