Skip to content
Permalink
Browse files
Fix text annotation edit background should match frame background
Otherwise white text is not visible. Fix #10553.
  • Loading branch information
nyalldawson committed Jul 26, 2016
1 parent 0fa6499 commit 76c4cae0a3fbfdc454dc758356608b603ea20bb3
@@ -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 )
{
@@ -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();

@@ -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" );
@@ -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 );
@@ -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 )
@@ -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 )
@@ -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)*/
@@ -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

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn commented on 76c4cae Jul 26, 2016

Yay, no more white text on white background!

Please sign in to comment.