Skip to content

Commit 9d3c9e1

Browse files
committedSep 1, 2017
[FEATURE] Expose "justify" text alignment as an option for
composer label alignment It's supported by Qt already, just not shown as an option in the config widget!
1 parent 7ca0b2d commit 9d3c9e1

File tree

4 files changed

+79
-67
lines changed

4 files changed

+79
-67
lines changed
 

‎src/app/composer/qgscomposerlabelwidget.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ QgsComposerLabelWidget::QgsComposerLabelWidget( QgsComposerLabel *label ): QgsCo
5050
}
5151

5252
connect( mFontButton, &QgsFontButton::changed, this, &QgsComposerLabelWidget::fontChanged );
53+
connect( mJustifyRadioButton, &QRadioButton::clicked, this, &QgsComposerLabelWidget::justifyClicked );
5354
}
5455

5556
void QgsComposerLabelWidget::on_mHtmlCheckBox_stateChanged( int state )
@@ -96,6 +97,17 @@ void QgsComposerLabelWidget::fontChanged()
9697
}
9798
}
9899

100+
void QgsComposerLabelWidget::justifyClicked()
101+
{
102+
if ( mComposerLabel )
103+
{
104+
mComposerLabel->beginCommand( tr( "Label alignment changed" ) );
105+
mComposerLabel->setHAlign( Qt::AlignJustify );
106+
mComposerLabel->update();
107+
mComposerLabel->endCommand();
108+
}
109+
}
110+
99111
void QgsComposerLabelWidget::on_mMarginXDoubleSpinBox_valueChanged( double d )
100112
{
101113
if ( mComposerLabel )
@@ -240,6 +252,7 @@ void QgsComposerLabelWidget::setGuiElementValues()
240252
mMiddleRadioButton->setChecked( mComposerLabel->vAlign() == Qt::AlignVCenter );
241253
mBottomRadioButton->setChecked( mComposerLabel->vAlign() == Qt::AlignBottom );
242254
mLeftRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignLeft );
255+
mJustifyRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignJustify );
243256
mCenterRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignHCenter );
244257
mRightRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignRight );
245258
mFontColorButton->setColor( mComposerLabel->fontColor() );
@@ -264,6 +277,7 @@ void QgsComposerLabelWidget::blockAllSignals( bool block )
264277
mLeftRadioButton->blockSignals( block );
265278
mCenterRadioButton->blockSignals( block );
266279
mRightRadioButton->blockSignals( block );
280+
mJustifyRadioButton->blockSignals( block );
267281
mFontColorButton->blockSignals( block );
268282
mFontButton->blockSignals( block );
269283
}

‎src/app/composer/qgscomposerlabelwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class QgsComposerLabelWidget: public QgsComposerItemBaseWidget, private Ui::QgsC
4949
private slots:
5050
void setGuiElementValues();
5151
void fontChanged();
52+
void justifyClicked();
5253

5354
private:
5455
QgsComposerLabel *mComposerLabel = nullptr;

‎src/core/composer/qgscomposerlabel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ QUrl QgsComposerLabel::createStylesheetUrl() const
612612
stylesheet += QStringLiteral( "body { margin: %1 %2;" ).arg( std::max( mMarginY * mHtmlUnitsToMM, 0.0 ) ).arg( std::max( mMarginX * mHtmlUnitsToMM, 0.0 ) );
613613
stylesheet += QgsFontUtils::asCSS( mFont, 0.352778 * mHtmlUnitsToMM );
614614
stylesheet += QStringLiteral( "color: %1;" ).arg( mFontColor.name() );
615-
stylesheet += QStringLiteral( "text-align: %1; }" ).arg( mHAlignment == Qt::AlignLeft ? "left" : mHAlignment == Qt::AlignRight ? "right" : "center" );
615+
stylesheet += QStringLiteral( "text-align: %1; }" ).arg( mHAlignment == Qt::AlignLeft ? QStringLiteral( "left" ) : mHAlignment == Qt::AlignRight ? QStringLiteral( "right" ) : mHAlignment == Qt::AlignHCenter ? QStringLiteral( "center" ) : QStringLiteral( "justify" ) );
616616

617617
QByteArray ba;
618618
ba.append( stylesheet.toUtf8() );

‎src/ui/composer/qgscomposerlabelwidgetbase.ui

Lines changed: 63 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
<rect>
6262
<x>0</x>
6363
<y>0</y>
64-
<width>302</width>
65-
<height>686</height>
64+
<width>446</width>
65+
<height>665</height>
6666
</rect>
6767
</property>
6868
<layout class="QVBoxLayout" name="mainLayout">
@@ -126,14 +126,24 @@
126126
<bool>false</bool>
127127
</property>
128128
<layout class="QGridLayout" name="gridLayout">
129-
<item row="1" column="0">
130-
<widget class="QLabel" name="label_2">
129+
<item row="4" column="0" colspan="2">
130+
<widget class="QLabel" name="mHorizontalAlignementLabel">
131131
<property name="text">
132-
<string>Font color</string>
132+
<string>Horizontal alignment</string>
133133
</property>
134134
</widget>
135135
</item>
136-
<item row="7" column="0" colspan="2">
136+
<item row="3" column="1">
137+
<widget class="QgsDoubleSpinBox" name="mMarginYDoubleSpinBox">
138+
<property name="suffix">
139+
<string> mm</string>
140+
</property>
141+
<property name="minimum">
142+
<double>-99.989999999999995</double>
143+
</property>
144+
</widget>
145+
</item>
146+
<item row="8" column="0" colspan="2">
137147
<layout class="QHBoxLayout" name="horizontalLayout_6">
138148
<item>
139149
<widget class="QRadioButton" name="mTopRadioButton">
@@ -180,6 +190,20 @@
180190
</item>
181191
</layout>
182192
</item>
193+
<item row="3" column="0">
194+
<widget class="QLabel" name="mMarginYLabel">
195+
<property name="text">
196+
<string>Vertical margin</string>
197+
</property>
198+
</widget>
199+
</item>
200+
<item row="2" column="0">
201+
<widget class="QLabel" name="mMarginXLabel">
202+
<property name="text">
203+
<string>Horizontal margin</string>
204+
</property>
205+
</widget>
206+
</item>
183207
<item row="2" column="1">
184208
<widget class="QgsDoubleSpinBox" name="mMarginXDoubleSpinBox">
185209
<property name="prefix">
@@ -193,9 +217,16 @@
193217
</property>
194218
</widget>
195219
</item>
196-
<item row="5" column="0" colspan="2">
197-
<layout class="QHBoxLayout" name="horizontalLayout_5">
198-
<item>
220+
<item row="1" column="0">
221+
<widget class="QLabel" name="label_2">
222+
<property name="text">
223+
<string>Font color</string>
224+
</property>
225+
</widget>
226+
</item>
227+
<item row="5" column="0">
228+
<layout class="QGridLayout" name="gridLayout_3">
229+
<item row="0" column="0">
199230
<widget class="QRadioButton" name="mLeftRadioButton">
200231
<property name="text">
201232
<string>Left</string>
@@ -205,17 +236,17 @@
205236
</attribute>
206237
</widget>
207238
</item>
208-
<item>
209-
<widget class="QRadioButton" name="mCenterRadioButton">
239+
<item row="0" column="3">
240+
<widget class="QRadioButton" name="mJustifyRadioButton">
210241
<property name="text">
211-
<string>Center</string>
242+
<string>Justify</string>
212243
</property>
213244
<attribute name="buttonGroup">
214245
<string notr="true">buttonGroup_2</string>
215246
</attribute>
216247
</widget>
217248
</item>
218-
<item>
249+
<item row="0" column="2">
219250
<widget class="QRadioButton" name="mRightRadioButton">
220251
<property name="text">
221252
<string>Right</string>
@@ -225,39 +256,35 @@
225256
</attribute>
226257
</widget>
227258
</item>
228-
<item>
229-
<spacer name="horizontalSpacer_4">
230-
<property name="orientation">
231-
<enum>Qt::Horizontal</enum>
232-
</property>
233-
<property name="sizeHint" stdset="0">
234-
<size>
235-
<width>0</width>
236-
<height>20</height>
237-
</size>
259+
<item row="0" column="1">
260+
<widget class="QRadioButton" name="mCenterRadioButton">
261+
<property name="text">
262+
<string>Center</string>
238263
</property>
239-
</spacer>
264+
<attribute name="buttonGroup">
265+
<string notr="true">buttonGroup_2</string>
266+
</attribute>
267+
</widget>
240268
</item>
241269
</layout>
242270
</item>
243-
<item row="4" column="0" colspan="2">
244-
<widget class="QLabel" name="mHorizontalAlignementLabel">
245-
<property name="text">
246-
<string>Horizontal alignment</string>
247-
</property>
248-
</widget>
249-
</item>
250-
<item row="6" column="0" colspan="2">
271+
<item row="7" column="0" colspan="2">
251272
<widget class="QLabel" name="mVerticalAlignementLabel">
252273
<property name="text">
253274
<string>Vertical alignment</string>
254275
</property>
255276
</widget>
256277
</item>
257-
<item row="2" column="0">
258-
<widget class="QLabel" name="mMarginXLabel">
278+
<item row="0" column="0" colspan="2">
279+
<widget class="QgsFontButton" name="mFontButton">
280+
<property name="sizePolicy">
281+
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
282+
<horstretch>0</horstretch>
283+
<verstretch>0</verstretch>
284+
</sizepolicy>
285+
</property>
259286
<property name="text">
260-
<string>Horizontal margin</string>
287+
<string>Font</string>
261288
</property>
262289
</widget>
263290
</item>
@@ -297,36 +324,6 @@
297324
</item>
298325
</layout>
299326
</item>
300-
<item row="3" column="1">
301-
<widget class="QgsDoubleSpinBox" name="mMarginYDoubleSpinBox">
302-
<property name="suffix">
303-
<string> mm</string>
304-
</property>
305-
<property name="minimum">
306-
<double>-99.989999999999995</double>
307-
</property>
308-
</widget>
309-
</item>
310-
<item row="3" column="0">
311-
<widget class="QLabel" name="mMarginYLabel">
312-
<property name="text">
313-
<string>Vertical margin</string>
314-
</property>
315-
</widget>
316-
</item>
317-
<item row="0" column="0" colspan="2">
318-
<widget class="QgsFontButton" name="mFontButton">
319-
<property name="sizePolicy">
320-
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
321-
<horstretch>0</horstretch>
322-
<verstretch>0</verstretch>
323-
</sizepolicy>
324-
</property>
325-
<property name="text">
326-
<string>Font</string>
327-
</property>
328-
</widget>
329-
</item>
330327
</layout>
331328
</widget>
332329
</item>
@@ -388,7 +385,7 @@
388385
<resources/>
389386
<connections/>
390387
<buttongroups>
391-
<buttongroup name="buttonGroup"/>
392388
<buttongroup name="buttonGroup_2"/>
389+
<buttongroup name="buttonGroup"/>
393390
</buttongroups>
394391
</ui>

1 commit comments

Comments
 (1)

andreasneumann commented on Sep 4, 2017

@andreasneumann
Member

Nice - Thanks!

Please sign in to comment.