Skip to content

Commit

Permalink
[FEATURE] Expose "justify" text alignment as an option for
Browse files Browse the repository at this point in the history
composer label alignment

It's supported by Qt already, just not shown as an option
in the config widget!
  • Loading branch information
nyalldawson committed Sep 1, 2017
1 parent 7ca0b2d commit 9d3c9e1
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 67 deletions.
14 changes: 14 additions & 0 deletions src/app/composer/qgscomposerlabelwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ QgsComposerLabelWidget::QgsComposerLabelWidget( QgsComposerLabel *label ): QgsCo
}

connect( mFontButton, &QgsFontButton::changed, this, &QgsComposerLabelWidget::fontChanged );
connect( mJustifyRadioButton, &QRadioButton::clicked, this, &QgsComposerLabelWidget::justifyClicked );
}

void QgsComposerLabelWidget::on_mHtmlCheckBox_stateChanged( int state )
Expand Down Expand Up @@ -96,6 +97,17 @@ void QgsComposerLabelWidget::fontChanged()
}
}

void QgsComposerLabelWidget::justifyClicked()
{
if ( mComposerLabel )
{
mComposerLabel->beginCommand( tr( "Label alignment changed" ) );
mComposerLabel->setHAlign( Qt::AlignJustify );
mComposerLabel->update();
mComposerLabel->endCommand();
}
}

void QgsComposerLabelWidget::on_mMarginXDoubleSpinBox_valueChanged( double d )
{
if ( mComposerLabel )
Expand Down Expand Up @@ -240,6 +252,7 @@ void QgsComposerLabelWidget::setGuiElementValues()
mMiddleRadioButton->setChecked( mComposerLabel->vAlign() == Qt::AlignVCenter );
mBottomRadioButton->setChecked( mComposerLabel->vAlign() == Qt::AlignBottom );
mLeftRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignLeft );
mJustifyRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignJustify );
mCenterRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignHCenter );
mRightRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignRight );
mFontColorButton->setColor( mComposerLabel->fontColor() );
Expand All @@ -264,6 +277,7 @@ void QgsComposerLabelWidget::blockAllSignals( bool block )
mLeftRadioButton->blockSignals( block );
mCenterRadioButton->blockSignals( block );
mRightRadioButton->blockSignals( block );
mJustifyRadioButton->blockSignals( block );
mFontColorButton->blockSignals( block );
mFontButton->blockSignals( block );
}
1 change: 1 addition & 0 deletions src/app/composer/qgscomposerlabelwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class QgsComposerLabelWidget: public QgsComposerItemBaseWidget, private Ui::QgsC
private slots:
void setGuiElementValues();
void fontChanged();
void justifyClicked();

private:
QgsComposerLabel *mComposerLabel = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposerlabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ QUrl QgsComposerLabel::createStylesheetUrl() const
stylesheet += QStringLiteral( "body { margin: %1 %2;" ).arg( std::max( mMarginY * mHtmlUnitsToMM, 0.0 ) ).arg( std::max( mMarginX * mHtmlUnitsToMM, 0.0 ) );
stylesheet += QgsFontUtils::asCSS( mFont, 0.352778 * mHtmlUnitsToMM );
stylesheet += QStringLiteral( "color: %1;" ).arg( mFontColor.name() );
stylesheet += QStringLiteral( "text-align: %1; }" ).arg( mHAlignment == Qt::AlignLeft ? "left" : mHAlignment == Qt::AlignRight ? "right" : "center" );
stylesheet += QStringLiteral( "text-align: %1; }" ).arg( mHAlignment == Qt::AlignLeft ? QStringLiteral( "left" ) : mHAlignment == Qt::AlignRight ? QStringLiteral( "right" ) : mHAlignment == Qt::AlignHCenter ? QStringLiteral( "center" ) : QStringLiteral( "justify" ) );

QByteArray ba;
ba.append( stylesheet.toUtf8() );
Expand Down
129 changes: 63 additions & 66 deletions src/ui/composer/qgscomposerlabelwidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>302</width>
<height>686</height>
<width>446</width>
<height>665</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout">
Expand Down Expand Up @@ -126,14 +126,24 @@
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<item row="4" column="0" colspan="2">
<widget class="QLabel" name="mHorizontalAlignementLabel">
<property name="text">
<string>Font color</string>
<string>Horizontal alignment</string>
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<item row="3" column="1">
<widget class="QgsDoubleSpinBox" name="mMarginYDoubleSpinBox">
<property name="suffix">
<string> mm</string>
</property>
<property name="minimum">
<double>-99.989999999999995</double>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QRadioButton" name="mTopRadioButton">
Expand Down Expand Up @@ -180,6 +190,20 @@
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mMarginYLabel">
<property name="text">
<string>Vertical margin</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mMarginXLabel">
<property name="text">
<string>Horizontal margin</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QgsDoubleSpinBox" name="mMarginXDoubleSpinBox">
<property name="prefix">
Expand All @@ -193,9 +217,16 @@
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Font color</string>
</property>
</widget>
</item>
<item row="5" column="0">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QRadioButton" name="mLeftRadioButton">
<property name="text">
<string>Left</string>
Expand All @@ -205,17 +236,17 @@
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="mCenterRadioButton">
<item row="0" column="3">
<widget class="QRadioButton" name="mJustifyRadioButton">
<property name="text">
<string>Center</string>
<string>Justify</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup_2</string>
</attribute>
</widget>
</item>
<item>
<item row="0" column="2">
<widget class="QRadioButton" name="mRightRadioButton">
<property name="text">
<string>Right</string>
Expand All @@ -225,39 +256,35 @@
</attribute>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>20</height>
</size>
<item row="0" column="1">
<widget class="QRadioButton" name="mCenterRadioButton">
<property name="text">
<string>Center</string>
</property>
</spacer>
<attribute name="buttonGroup">
<string notr="true">buttonGroup_2</string>
</attribute>
</widget>
</item>
</layout>
</item>
<item row="4" column="0" colspan="2">
<widget class="QLabel" name="mHorizontalAlignementLabel">
<property name="text">
<string>Horizontal alignment</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<item row="7" column="0" colspan="2">
<widget class="QLabel" name="mVerticalAlignementLabel">
<property name="text">
<string>Vertical alignment</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mMarginXLabel">
<item row="0" column="0" colspan="2">
<widget class="QgsFontButton" name="mFontButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Horizontal margin</string>
<string>Font</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -297,36 +324,6 @@
</item>
</layout>
</item>
<item row="3" column="1">
<widget class="QgsDoubleSpinBox" name="mMarginYDoubleSpinBox">
<property name="suffix">
<string> mm</string>
</property>
<property name="minimum">
<double>-99.989999999999995</double>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mMarginYLabel">
<property name="text">
<string>Vertical margin</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QgsFontButton" name="mFontButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Font</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -388,7 +385,7 @@
<resources/>
<connections/>
<buttongroups>
<buttongroup name="buttonGroup"/>
<buttongroup name="buttonGroup_2"/>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>

1 comment on commit 9d3c9e1

@andreasneumann
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice - Thanks!

Please sign in to comment.