Skip to content

Commit

Permalink
[ui] Fix broken text annotation background color
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed May 1, 2019
1 parent 619d0f4 commit cdaf2b9
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 @@ -74,6 +74,18 @@ QgsAnnotationWidget::QgsAnnotationWidget( QgsMapCanvasAnnotationItem *item, QWid
mMapMarkerButton->setMessageBar( QgisApp::instance()->messageBar() ); mMapMarkerButton->setMessageBar( QgisApp::instance()->messageBar() );
mFrameStyleButton->setMapCanvas( QgisApp::instance()->mapCanvas() ); mFrameStyleButton->setMapCanvas( QgisApp::instance()->mapCanvas() );
mFrameStyleButton->setMessageBar( QgisApp::instance()->messageBar() ); mFrameStyleButton->setMessageBar( QgisApp::instance()->messageBar() );

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() 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 Q_OBJECT
public: public:

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


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

void apply(); void apply();


private:

void frameStyleChanged();

signals: signals:


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


private: private:

QgsMapCanvasAnnotationItem *mItem = nullptr; QgsMapCanvasAnnotationItem *mItem = nullptr;


void blockAllSignals( bool block ); 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->addWidget( mEmbeddedWidget );
mStackedWidget->setCurrentWidget( mEmbeddedWidget ); mStackedWidget->setCurrentWidget( mEmbeddedWidget );
connect( mEmbeddedWidget, &QgsAnnotationWidget::backgroundColorChanged, this, &QgsTextAnnotationDialog::backgroundColorChanged ); connect( mEmbeddedWidget, &QgsAnnotationWidget::backgroundColorChanged, this, &QgsTextAnnotationDialog::backgroundColorChanged );
mTextEdit->setAttribute( Qt::WA_TranslucentBackground );
if ( mItem && mItem->annotation() ) if ( mItem && mItem->annotation() )
{ {
QgsTextAnnotation *annotation = static_cast< QgsTextAnnotation * >( mItem->annotation() ); QgsTextAnnotation *annotation = static_cast< QgsTextAnnotation * >( mItem->annotation() );
Expand All @@ -53,6 +53,7 @@ QgsTextAnnotationDialog::QgsTextAnnotationDialog( QgsMapCanvasAnnotationItem *it
mFontColorButton->setContext( QStringLiteral( "symbology" ) ); mFontColorButton->setContext( QStringLiteral( "symbology" ) );


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


QObject::connect( mButtonBox, &QDialogButtonBox::accepted, this, &QgsTextAnnotationDialog::applyTextToItem ); QObject::connect( mButtonBox, &QDialogButtonBox::accepted, this, &QgsTextAnnotationDialog::applyTextToItem );
QObject::connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsTextAnnotationDialog::showHelp ); 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(); QPalette p = mTextEdit->viewport()->palette();
p.setColor( QPalette::Base, color ); p.setColor( QPalette::Base, color );
mTextEdit->viewport()->setPalette( p ); mTextEdit->viewport()->setPalette( p );
mTextEdit->setStyleSheet( QStringLiteral( "QTextEdit { background-color: %1; }" ).arg( color.name() ) );
} }


void QgsTextAnnotationDialog::applyTextToItem() void QgsTextAnnotationDialog::applyTextToItem()
Expand Down

0 comments on commit cdaf2b9

Please sign in to comment.