24 #include <QColorDialog>
25 #include <QFontDialog>
35 connect( mHtmlCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutLabelWidget::mHtmlCheckBox_stateChanged );
36 connect( mTextEdit, &QPlainTextEdit::textChanged,
this, &QgsLayoutLabelWidget::mTextEdit_textChanged );
37 connect( mInsertExpressionButton, &QPushButton::clicked,
this, &QgsLayoutLabelWidget::mInsertExpressionButton_clicked );
38 connect( mMarginXDoubleSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLabelWidget::mMarginXDoubleSpinBox_valueChanged );
39 connect( mMarginYDoubleSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLabelWidget::mMarginYDoubleSpinBox_valueChanged );
41 connect( mCenterRadioButton, &QRadioButton::clicked,
this, &QgsLayoutLabelWidget::mCenterRadioButton_clicked );
42 connect( mLeftRadioButton, &QRadioButton::clicked,
this, &QgsLayoutLabelWidget::mLeftRadioButton_clicked );
43 connect( mRightRadioButton, &QRadioButton::clicked,
this, &QgsLayoutLabelWidget::mRightRadioButton_clicked );
44 connect( mTopRadioButton, &QRadioButton::clicked,
this, &QgsLayoutLabelWidget::mTopRadioButton_clicked );
45 connect( mBottomRadioButton, &QRadioButton::clicked,
this, &QgsLayoutLabelWidget::mBottomRadioButton_clicked );
46 connect( mMiddleRadioButton, &QRadioButton::clicked,
this, &QgsLayoutLabelWidget::mMiddleRadioButton_clicked );
53 mainLayout->addWidget( mItemPropertiesWidget );
55 mFontColorButton->setColorDialogTitle( tr(
"Select Font Color" ) );
56 mFontColorButton->setContext( QStringLiteral(
"composer" ) );
57 mFontColorButton->setAllowOpacity(
true );
59 mMarginXDoubleSpinBox->setClearValue( 0.0 );
60 mMarginYDoubleSpinBox->setClearValue( 0.0 );
62 setGuiElementValues();
66 connect( mJustifyRadioButton, &QRadioButton::clicked,
this, &QgsLayoutLabelWidget::justifyClicked );
71 if ( mItemPropertiesWidget )
85 mLabel = qobject_cast< QgsLayoutItemLabel * >( item );
86 mItemPropertiesWidget->
setItem( mLabel );
93 setGuiElementValues();
98 void QgsLayoutLabelWidget::mHtmlCheckBox_stateChanged(
int state )
102 mVerticalAlignementLabel->setDisabled( state );
103 mTopRadioButton->setDisabled( state );
104 mMiddleRadioButton->setDisabled( state );
105 mBottomRadioButton->setDisabled( state );
107 mLabel->beginCommand( tr(
"Change Label Mode" ) );
108 mLabel->blockSignals(
true );
110 mLabel->setText( mTextEdit->toPlainText() );
112 mLabel->blockSignals(
false );
113 mLabel->endCommand();
117 void QgsLayoutLabelWidget::mTextEdit_textChanged()
122 mLabel->blockSignals(
true );
123 mLabel->setText( mTextEdit->toPlainText() );
125 mLabel->blockSignals(
false );
126 mLabel->endCommand();
130 void QgsLayoutLabelWidget::fontChanged()
134 QFont newFont = mFontButton->currentFont();
136 mLabel->setFont( newFont );
138 mLabel->endCommand();
142 void QgsLayoutLabelWidget::justifyClicked()
146 mLabel->beginCommand( tr(
"Change Label Alignment" ) );
147 mLabel->setHAlign( Qt::AlignJustify );
149 mLabel->endCommand();
153 void QgsLayoutLabelWidget::mMarginXDoubleSpinBox_valueChanged(
double d )
158 mLabel->setMarginX( d );
160 mLabel->endCommand();
164 void QgsLayoutLabelWidget::mMarginYDoubleSpinBox_valueChanged(
double d )
169 mLabel->setMarginY( d );
171 mLabel->endCommand();
175 void QgsLayoutLabelWidget::mFontColorButton_colorChanged(
const QColor &newLabelColor )
183 mLabel->setFontColor( newLabelColor );
185 mLabel->endCommand();
188 void QgsLayoutLabelWidget::mInsertExpressionButton_clicked()
195 QString selText = mTextEdit->textCursor().selectedText();
198 selText = selText.replace( QChar( 0x2029 ), QChar(
'\n' ) );
201 if ( selText.startsWith( QLatin1String(
"[%" ) ) && selText.endsWith( QLatin1String(
"%]" ) ) )
202 selText = selText.mid( 2, selText.size() - 4 );
210 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
211 if ( exprDlg.exec() == QDialog::Accepted )
213 QString expression = exprDlg.expressionText();
214 if ( !expression.isEmpty() )
216 mLabel->beginCommand( tr(
"Insert expression" ) );
217 mTextEdit->insertPlainText(
"[%" + expression +
"%]" );
218 mLabel->endCommand();
223 void QgsLayoutLabelWidget::mCenterRadioButton_clicked()
227 mLabel->beginCommand( tr(
"Change Label Alignment" ) );
228 mLabel->setHAlign( Qt::AlignHCenter );
230 mLabel->endCommand();
234 void QgsLayoutLabelWidget::mRightRadioButton_clicked()
238 mLabel->beginCommand( tr(
"Change Label Alignment" ) );
239 mLabel->setHAlign( Qt::AlignRight );
241 mLabel->endCommand();
245 void QgsLayoutLabelWidget::mLeftRadioButton_clicked()
249 mLabel->beginCommand( tr(
"Change Label Alignment" ) );
250 mLabel->setHAlign( Qt::AlignLeft );
252 mLabel->endCommand();
256 void QgsLayoutLabelWidget::mTopRadioButton_clicked()
260 mLabel->beginCommand( tr(
"Change Label Alignment" ) );
261 mLabel->setVAlign( Qt::AlignTop );
263 mLabel->endCommand();
267 void QgsLayoutLabelWidget::mBottomRadioButton_clicked()
271 mLabel->beginCommand( tr(
"Change Label Alignment" ) );
272 mLabel->setVAlign( Qt::AlignBottom );
274 mLabel->endCommand();
278 void QgsLayoutLabelWidget::mMiddleRadioButton_clicked()
282 mLabel->beginCommand( tr(
"Change Label Alignment" ) );
283 mLabel->setVAlign( Qt::AlignVCenter );
285 mLabel->endCommand();
289 void QgsLayoutLabelWidget::setGuiElementValues()
291 blockAllSignals(
true );
292 mTextEdit->setPlainText( mLabel->text() );
293 mTextEdit->moveCursor( QTextCursor::End, QTextCursor::MoveAnchor );
294 mMarginXDoubleSpinBox->setValue( mLabel->marginX() );
295 mMarginYDoubleSpinBox->setValue( mLabel->marginY() );
297 mTopRadioButton->setChecked( mLabel->vAlign() == Qt::AlignTop );
298 mMiddleRadioButton->setChecked( mLabel->vAlign() == Qt::AlignVCenter );
299 mBottomRadioButton->setChecked( mLabel->vAlign() == Qt::AlignBottom );
300 mLeftRadioButton->setChecked( mLabel->hAlign() == Qt::AlignLeft );
301 mJustifyRadioButton->setChecked( mLabel->hAlign() == Qt::AlignJustify );
302 mCenterRadioButton->setChecked( mLabel->hAlign() == Qt::AlignHCenter );
303 mRightRadioButton->setChecked( mLabel->hAlign() == Qt::AlignRight );
304 mFontColorButton->setColor( mLabel->fontColor() );
305 mFontButton->setCurrentFont( mLabel->font() );
311 blockAllSignals(
false );
314 void QgsLayoutLabelWidget::blockAllSignals(
bool block )
316 mTextEdit->blockSignals( block );
317 mHtmlCheckBox->blockSignals( block );
318 mMarginXDoubleSpinBox->blockSignals( block );
319 mMarginYDoubleSpinBox->blockSignals( block );
320 mTopRadioButton->blockSignals( block );
321 mMiddleRadioButton->blockSignals( block );
322 mBottomRadioButton->blockSignals( block );
323 mLeftRadioButton->blockSignals( block );
324 mCenterRadioButton->blockSignals( block );
325 mRightRadioButton->blockSignals( block );
326 mJustifyRadioButton->blockSignals( block );
327 mFontColorButton->blockSignals( block );
328 mFontButton->blockSignals( block );