Skip to content

Commit

Permalink
Fix text annotation edit background should match frame background
Browse files Browse the repository at this point in the history
Otherwise white text is not visible. Fix #10553.
  • Loading branch information
nyalldawson committed Jul 26, 2016
1 parent 0fa6499 commit 76c4cae
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/app/qgsannotationwidget.cpp
Expand Up @@ -54,6 +54,8 @@ QgsAnnotationWidget::QgsAnnotationWidget( QgsAnnotationItem* item, QWidget * par
mBackgroundColorButton->setNoColorString( tr( "Transparent" ) );
mBackgroundColorButton->setShowNoColor( true );

connect( mBackgroundColorButton, SIGNAL( colorChanged( QColor ) ), this, SIGNAL( backgroundColorChanged( QColor ) ) );

const QgsMarkerSymbolV2* symbol = mItem->markerSymbol();
if ( symbol )
{
Expand Down
5 changes: 5 additions & 0 deletions src/app/qgsannotationwidget.h
Expand Up @@ -34,6 +34,11 @@ class APP_EXPORT QgsAnnotationWidget: public QWidget, private Ui::QgsAnnotationW

void apply();

signals:

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

private slots:
void on_mMapMarkerButton_clicked();

Expand Down
16 changes: 15 additions & 1 deletion src/app/qgstextannotationdialog.cpp
Expand Up @@ -27,11 +27,14 @@ QgsTextAnnotationDialog::QgsTextAnnotationDialog( QgsTextAnnotationItem* item, Q
mEmbeddedWidget = new QgsAnnotationWidget( mItem );
mStackedWidget->addWidget( mEmbeddedWidget );
mStackedWidget->setCurrentWidget( mEmbeddedWidget );
connect( mEmbeddedWidget, SIGNAL( backgroundColorChanged( QColor ) ), this, SLOT( backgroundColorChanged( QColor ) ) );
mTextEdit->setAttribute( Qt::WA_TranslucentBackground );
if ( mItem )
{
mTextDocument = mItem->document();
mTextEdit->setDocument( mTextDocument );
}

mFontColorButton->setColorDialogTitle( tr( "Select font color" ) );
mFontColorButton->setAllowAlpha( true );
mFontColorButton->setContext( "symbology" );
Expand All @@ -45,7 +48,6 @@ QgsTextAnnotationDialog::QgsTextAnnotationDialog( QgsTextAnnotationItem* item, Q
QObject::connect( mItalicsPushButton, SIGNAL( toggled( bool ) ), this, SLOT( changeCurrentFormat() ) );
QObject::connect( mTextEdit, SIGNAL( cursorPositionChanged() ), this, SLOT( setCurrentFontPropertiesToGui() ) );

QObject::connect( mButtonBox, SIGNAL( accepted() ), this, SLOT( applySettingsToItem() ) );
QPushButton* deleteButton = new QPushButton( tr( "Delete" ) );
QObject::connect( deleteButton, SIGNAL( clicked() ), this, SLOT( deleteItem() ) );
mButtonBox->addButton( deleteButton, QDialogButtonBox::RejectRole );
Expand All @@ -56,6 +58,11 @@ QgsTextAnnotationDialog::~QgsTextAnnotationDialog()
delete mTextDocument;
}

void QgsTextAnnotationDialog::showEvent( QShowEvent* )
{
backgroundColorChanged( mItem ? mItem->frameBackgroundColor() : Qt::white );
}

void QgsTextAnnotationDialog::on_mButtonBox_clicked( QAbstractButton *button )
{
if ( mButtonBox->buttonRole( button ) == QDialogButtonBox::ApplyRole )
Expand All @@ -65,6 +72,13 @@ void QgsTextAnnotationDialog::on_mButtonBox_clicked( QAbstractButton *button )
}
}

void QgsTextAnnotationDialog::backgroundColorChanged( const QColor& color )
{
QPalette p = mTextEdit->viewport()->palette();
p.setColor( QPalette::Base, color );
mTextEdit->viewport()->setPalette( p );
}

void QgsTextAnnotationDialog::applyTextToItem()
{
if ( mItem && mTextDocument )
Expand Down
5 changes: 5 additions & 0 deletions src/app/qgstextannotationdialog.h
Expand Up @@ -30,6 +30,10 @@ class APP_EXPORT QgsTextAnnotationDialog: public QDialog, private Ui::QgsTextAnn
QgsTextAnnotationDialog( QgsTextAnnotationItem* item, QWidget * parent = nullptr, Qt::WindowFlags f = 0 );
~QgsTextAnnotationDialog();

protected:

virtual void showEvent( QShowEvent * event ) override;

private:
QgsTextAnnotationItem* mItem;
/** Text document (a clone of the annotation items document)*/
Expand All @@ -45,6 +49,7 @@ class APP_EXPORT QgsTextAnnotationDialog: public QDialog, private Ui::QgsTextAnn
void setCurrentFontPropertiesToGui();
void deleteItem();
void on_mButtonBox_clicked( QAbstractButton* button );
void backgroundColorChanged( const QColor& color );
};

#endif // QGSTEXTANNOTATIONDIALOG_H

1 comment on commit 76c4cae

@nirvn
Copy link
Contributor

@nirvn nirvn commented on 76c4cae Jul 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay, no more white text on white background!

Please sign in to comment.