Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[ui] Fix broken text annotation background color
  • Loading branch information
nirvn committed May 1, 2019
1 parent 1114cdc commit ef52134
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/app/qgsannotationwidget.cpp
Expand Up @@ -72,6 +72,18 @@ QgsAnnotationWidget::QgsAnnotationWidget( QgsMapCanvasAnnotationItem *item, QWid
}
mMapMarkerButton->setMapCanvas( QgisApp::instance()->mapCanvas() );
mFrameStyleButton->setMapCanvas( QgisApp::instance()->mapCanvas() );

connect( mFrameStyleButton, &QgsSymbolButton::changed, this, &QgsAnnotationWidget::frameStyleChanged );
}

QColor QgsAnnotationWidget::backgroundColor()
{
return mFrameStyleButton->symbol() ? mFrameStyleButton->symbol()->color() : QColor();
}

void QgsAnnotationWidget::frameStyleChanged()
{
emit backgroundColorChanged( backgroundColor() );
}

void QgsAnnotationWidget::apply()
Expand Down
9 changes: 9 additions & 0 deletions src/app/qgsannotationwidget.h
Expand Up @@ -33,16 +33,25 @@ class APP_EXPORT QgsAnnotationWidget: public QWidget, private Ui::QgsAnnotationW
{
Q_OBJECT
public:

QgsAnnotationWidget( QgsMapCanvasAnnotationItem *item, QWidget *parent = nullptr, Qt::WindowFlags f = nullptr );

//! Returns the annotation frame symbol fill color
QColor backgroundColor();

void apply();

private:

void frameStyleChanged();

signals:

//! Emitted when the background color of the annotation is changed
void backgroundColorChanged( const QColor &color );

private:

QgsMapCanvasAnnotationItem *mItem = nullptr;

void blockAllSignals( bool block );
Expand Down
4 changes: 3 additions & 1 deletion src/app/qgstextannotationdialog.cpp
Expand Up @@ -38,7 +38,7 @@ QgsTextAnnotationDialog::QgsTextAnnotationDialog( QgsMapCanvasAnnotationItem *it
mStackedWidget->addWidget( mEmbeddedWidget );
mStackedWidget->setCurrentWidget( mEmbeddedWidget );
connect( mEmbeddedWidget, &QgsAnnotationWidget::backgroundColorChanged, this, &QgsTextAnnotationDialog::backgroundColorChanged );
mTextEdit->setAttribute( Qt::WA_TranslucentBackground );

if ( mItem && mItem->annotation() )
{
QgsTextAnnotation *annotation = static_cast< QgsTextAnnotation * >( mItem->annotation() );
Expand All @@ -53,6 +53,7 @@ QgsTextAnnotationDialog::QgsTextAnnotationDialog( QgsMapCanvasAnnotationItem *it
mFontColorButton->setContext( QStringLiteral( "symbology" ) );

setCurrentFontPropertiesToGui();
backgroundColorChanged( mEmbeddedWidget->backgroundColor() );

QObject::connect( mButtonBox, &QDialogButtonBox::accepted, this, &QgsTextAnnotationDialog::applyTextToItem );
QObject::connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsTextAnnotationDialog::showHelp );
Expand Down Expand Up @@ -86,6 +87,7 @@ void QgsTextAnnotationDialog::backgroundColorChanged( const QColor &color )
QPalette p = mTextEdit->viewport()->palette();
p.setColor( QPalette::Base, color );
mTextEdit->viewport()->setPalette( p );
mTextEdit->setStyleSheet( QStringLiteral( "QTextEdit { background-color: %1; }" ).arg( color.name() ) );
}

void QgsTextAnnotationDialog::applyTextToItem()
Expand Down

0 comments on commit ef52134

Please sign in to comment.