Skip to content

Commit

Permalink
Use alignment comboboxes for layout label alignment widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 17, 2024
1 parent 5205fc4 commit e9ed5ce
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 233 deletions.
105 changes: 19 additions & 86 deletions src/gui/layout/qgslayoutlabelwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ QgsLayoutLabelWidget::QgsLayoutLabelWidget( QgsLayoutItemLabel *label )
connect( mInsertExpressionButton, &QPushButton::clicked, this, &QgsLayoutLabelWidget::mInsertExpressionButton_clicked );
connect( mMarginXDoubleSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutLabelWidget::mMarginXDoubleSpinBox_valueChanged );
connect( mMarginYDoubleSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutLabelWidget::mMarginYDoubleSpinBox_valueChanged );
connect( mCenterRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::mCenterRadioButton_clicked );
connect( mLeftRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::mLeftRadioButton_clicked );
connect( mRightRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::mRightRadioButton_clicked );
connect( mTopRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::mTopRadioButton_clicked );
connect( mBottomRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::mBottomRadioButton_clicked );
connect( mMiddleRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::mMiddleRadioButton_clicked );

mHAlignmentComboBox->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight | Qt::AlignJustify );
mVAlignmentComboBox->setAvailableAlignments( Qt::AlignTop | Qt::AlignVCenter | Qt::AlignBottom );

connect( mHAlignmentComboBox, &QgsAlignmentComboBox::changed, this, &QgsLayoutLabelWidget::horizontalAlignmentChanged );
connect( mVAlignmentComboBox, &QgsAlignmentComboBox::changed, this, &QgsLayoutLabelWidget::verticalAlignmentChanged );

setPanelTitle( tr( "Label Properties" ) );

mFontButton->setMode( QgsFontButton::ModeTextRenderer );
Expand All @@ -66,7 +67,6 @@ QgsLayoutLabelWidget::QgsLayoutLabelWidget( QgsLayoutItemLabel *label )
connect( mLabel, &QgsLayoutObject::changed, this, &QgsLayoutLabelWidget::setGuiElementValues );

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

mDynamicTextMenu = new QMenu( this );
mDynamicTextButton->setMenu( mDynamicTextMenu );
Expand Down Expand Up @@ -267,9 +267,7 @@ void QgsLayoutLabelWidget::mHtmlCheckBox_stateChanged( int state )
if ( mLabel )
{
mVerticalAlignementLabel->setDisabled( state );
mTopRadioButton->setDisabled( state );
mMiddleRadioButton->setDisabled( state );
mBottomRadioButton->setDisabled( state );
mVAlignmentComboBox->setDisabled( state );

mLabel->beginCommand( tr( "Change Label Mode" ) );
mLabel->blockSignals( true );
Expand Down Expand Up @@ -305,17 +303,6 @@ void QgsLayoutLabelWidget::fontChanged()
}
}

void QgsLayoutLabelWidget::justifyClicked()
{
if ( mLabel )
{
mLabel->beginCommand( tr( "Change Label Alignment" ) );
mLabel->setHAlign( Qt::AlignJustify );
mLabel->update();
mLabel->endCommand();
}
}

void QgsLayoutLabelWidget::mMarginXDoubleSpinBox_valueChanged( double d )
{
if ( mLabel )
Expand Down Expand Up @@ -366,67 +353,23 @@ void QgsLayoutLabelWidget::mInsertExpressionButton_clicked()
}
}

void QgsLayoutLabelWidget::mCenterRadioButton_clicked()
{
if ( mLabel )
{
mLabel->beginCommand( tr( "Change Label Alignment" ) );
mLabel->setHAlign( Qt::AlignHCenter );
mLabel->update();
mLabel->endCommand();
}
}

void QgsLayoutLabelWidget::mRightRadioButton_clicked()
{
if ( mLabel )
{
mLabel->beginCommand( tr( "Change Label Alignment" ) );
mLabel->setHAlign( Qt::AlignRight );
mLabel->update();
mLabel->endCommand();
}
}

void QgsLayoutLabelWidget::mLeftRadioButton_clicked()
void QgsLayoutLabelWidget::horizontalAlignmentChanged()
{
if ( mLabel )
{
mLabel->beginCommand( tr( "Change Label Alignment" ) );
mLabel->setHAlign( Qt::AlignLeft );
mLabel->setHAlign( static_cast< Qt::AlignmentFlag >( static_cast< int >( mHAlignmentComboBox->currentAlignment() ) ) );
mLabel->update();
mLabel->endCommand();
}
}

void QgsLayoutLabelWidget::mTopRadioButton_clicked()
void QgsLayoutLabelWidget::verticalAlignmentChanged()
{
if ( mLabel )
{
mLabel->beginCommand( tr( "Change Label Alignment" ) );
mLabel->setVAlign( Qt::AlignTop );
mLabel->update();
mLabel->endCommand();
}
}

void QgsLayoutLabelWidget::mBottomRadioButton_clicked()
{
if ( mLabel )
{
mLabel->beginCommand( tr( "Change Label Alignment" ) );
mLabel->setVAlign( Qt::AlignBottom );
mLabel->update();
mLabel->endCommand();
}
}

void QgsLayoutLabelWidget::mMiddleRadioButton_clicked()
{
if ( mLabel )
{
mLabel->beginCommand( tr( "Change Label Alignment" ) );
mLabel->setVAlign( Qt::AlignVCenter );
mLabel->setVAlign( static_cast< Qt::AlignmentFlag >( static_cast< int >( mVAlignmentComboBox->currentAlignment() ) ) );
mLabel->update();
mLabel->endCommand();
}
Expand All @@ -440,18 +383,13 @@ void QgsLayoutLabelWidget::setGuiElementValues()
mMarginXDoubleSpinBox->setValue( mLabel->marginX() );
mMarginYDoubleSpinBox->setValue( mLabel->marginY() );
mHtmlCheckBox->setChecked( mLabel->mode() == QgsLayoutItemLabel::ModeHtml );
mTopRadioButton->setChecked( mLabel->vAlign() == Qt::AlignTop );
mMiddleRadioButton->setChecked( mLabel->vAlign() == Qt::AlignVCenter );
mBottomRadioButton->setChecked( mLabel->vAlign() == Qt::AlignBottom );
mLeftRadioButton->setChecked( mLabel->hAlign() == Qt::AlignLeft );
mJustifyRadioButton->setChecked( mLabel->hAlign() == Qt::AlignJustify );
mCenterRadioButton->setChecked( mLabel->hAlign() == Qt::AlignHCenter );
mRightRadioButton->setChecked( mLabel->hAlign() == Qt::AlignRight );

mHAlignmentComboBox->setCurrentAlignment( mLabel->hAlign() );
mVAlignmentComboBox->setCurrentAlignment( mLabel->vAlign() );

mFontButton->setTextFormat( mLabel->textFormat() );
mVerticalAlignementLabel->setDisabled( mLabel->mode() == QgsLayoutItemLabel::ModeHtml );
mTopRadioButton->setDisabled( mLabel->mode() == QgsLayoutItemLabel::ModeHtml );
mMiddleRadioButton->setDisabled( mLabel->mode() == QgsLayoutItemLabel::ModeHtml );
mBottomRadioButton->setDisabled( mLabel->mode() == QgsLayoutItemLabel::ModeHtml );
mVAlignmentComboBox->setDisabled( mLabel->mode() == QgsLayoutItemLabel::ModeHtml );

blockAllSignals( false );
}
Expand All @@ -462,12 +400,7 @@ void QgsLayoutLabelWidget::blockAllSignals( bool block )
mHtmlCheckBox->blockSignals( block );
mMarginXDoubleSpinBox->blockSignals( block );
mMarginYDoubleSpinBox->blockSignals( block );
mTopRadioButton->blockSignals( block );
mMiddleRadioButton->blockSignals( block );
mBottomRadioButton->blockSignals( block );
mLeftRadioButton->blockSignals( block );
mCenterRadioButton->blockSignals( block );
mRightRadioButton->blockSignals( block );
mJustifyRadioButton->blockSignals( block );
mHAlignmentComboBox->blockSignals( block );
mVAlignmentComboBox->blockSignals( block );
mFontButton->blockSignals( block );
}
9 changes: 2 additions & 7 deletions src/gui/layout/qgslayoutlabelwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,10 @@ class GUI_EXPORT QgsLayoutLabelWidget: public QgsLayoutItemBaseWidget, public Qg
void mInsertExpressionButton_clicked();
void mMarginXDoubleSpinBox_valueChanged( double d );
void mMarginYDoubleSpinBox_valueChanged( double d );
void mCenterRadioButton_clicked();
void mLeftRadioButton_clicked();
void mRightRadioButton_clicked();
void mTopRadioButton_clicked();
void mBottomRadioButton_clicked();
void mMiddleRadioButton_clicked();
void horizontalAlignmentChanged();
void verticalAlignmentChanged();
void setGuiElementValues();
void fontChanged();
void justifyClicked();

private:
QPointer< QgsLayoutItemLabel > mLabel = nullptr;
Expand Down
Loading

0 comments on commit e9ed5ce

Please sign in to comment.