Skip to content

Commit 056833e

Browse files
committedMay 30, 2019
[layout][ui] Fix missing opacity setting for the label font color button
1 parent 1d1d2ca commit 056833e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed
 

‎src/app/layout/qgslayoutlabelwidget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ QgsLayoutLabelWidget::QgsLayoutLabelWidget( QgsLayoutItemLabel *label )
5454

5555
mFontColorButton->setColorDialogTitle( tr( "Select Font Color" ) );
5656
mFontColorButton->setContext( QStringLiteral( "composer" ) );
57+
mFontColorButton->setAllowOpacity( true );
5758

5859
mMarginXDoubleSpinBox->setClearValue( 0.0 );
5960
mMarginYDoubleSpinBox->setClearValue( 0.0 );

‎src/core/layout/qgslayoutitemlabel.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ bool QgsLayoutItemLabel::writePropertiesToElement( QDomElement &layoutLabelElem,
363363
fontColorElem.setAttribute( QStringLiteral( "red" ), mFontColor.red() );
364364
fontColorElem.setAttribute( QStringLiteral( "green" ), mFontColor.green() );
365365
fontColorElem.setAttribute( QStringLiteral( "blue" ), mFontColor.blue() );
366+
fontColorElem.setAttribute( QStringLiteral( "alpha" ), mFontColor.alpha() );
366367
layoutLabelElem.appendChild( fontColorElem );
367368

368369
return true;
@@ -408,7 +409,8 @@ bool QgsLayoutItemLabel::readPropertiesFromElement( const QDomElement &itemElem,
408409
int red = fontColorElem.attribute( QStringLiteral( "red" ), QStringLiteral( "0" ) ).toInt();
409410
int green = fontColorElem.attribute( QStringLiteral( "green" ), QStringLiteral( "0" ) ).toInt();
410411
int blue = fontColorElem.attribute( QStringLiteral( "blue" ), QStringLiteral( "0" ) ).toInt();
411-
mFontColor = QColor( red, green, blue );
412+
int alpha = fontColorElem.attribute( QStringLiteral( "alpha" ), QStringLiteral( "255" ) ).toInt();
413+
mFontColor = QColor( red, green, blue, alpha );
412414
}
413415
else
414416
{
@@ -580,7 +582,7 @@ QUrl QgsLayoutItemLabel::createStylesheetUrl() const
580582
QString stylesheet;
581583
stylesheet += QStringLiteral( "body { margin: %1 %2;" ).arg( std::max( mMarginY * mHtmlUnitsToLayoutUnits, 0.0 ) ).arg( std::max( mMarginX * mHtmlUnitsToLayoutUnits, 0.0 ) );
582584
stylesheet += QgsFontUtils::asCSS( mFont, 0.352778 * mHtmlUnitsToLayoutUnits );
583-
stylesheet += QStringLiteral( "color: %1;" ).arg( mFontColor.name() );
585+
stylesheet += QStringLiteral( "color: rgba(%1,%2,%3,%4);" ).arg( mFontColor.red() ).arg( mFontColor.green() ).arg( mFontColor.blue() ).arg( QString::number( mFontColor.alphaF(), 'f', 4 ) );
584586
stylesheet += QStringLiteral( "text-align: %1; }" ).arg( mHAlignment == Qt::AlignLeft ? QStringLiteral( "left" ) : mHAlignment == Qt::AlignRight ? QStringLiteral( "right" ) : mHAlignment == Qt::AlignHCenter ? QStringLiteral( "center" ) : QStringLiteral( "justify" ) );
585587

586588
QByteArray ba;

0 commit comments

Comments
 (0)
Please sign in to comment.