Skip to content
Permalink
Browse files
[FEATURE] Add opacity support to copyright decorator
  • Loading branch information
nirvn committed May 9, 2017
1 parent 83e8ece commit cb23ebed65eae97a8fc18acb3aba9ebd9efb5929
Showing with 20 additions and 16 deletions.
  1. +13 −12 src/app/qgsdecorationcopyright.cpp
  2. +3 −1 src/app/qgsdecorationcopyright.h
  3. +4 −3 src/app/qgsdecorationcopyrightdialog.cpp
@@ -24,11 +24,12 @@ email : tim@linfiniti.com
#include "qgsdecorationcopyright.h"
#include "qgsdecorationcopyrightdialog.h"

#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgisapp.h"
#include "qgssymbollayerutils.h"

#include <QPainter>
#include <QMenu>
@@ -64,23 +65,22 @@ void QgsDecorationCopyright::projectRead()
// there is no font setting in the UI, so just use the Qt/QGIS default font (what mQFont gets when created)
// mQFont.setFamily( QgsProject::instance()->readEntry( "CopyrightLabel", "/FontName", "Sans Serif" ) );
// mQFont.setPointSize( QgsProject::instance()->readNumEntry( "CopyrightLabel", "/FontSize", 9 ) );
QgsProject *prj = QgsProject::instance();
mLabelQString = prj->readEntry( mNameConfig, QStringLiteral( "/Label" ), defString );

mLabelQString = QgsProject::instance()->readEntry( mNameConfig, QStringLiteral( "/Label" ), defString );
mMarginHorizontal = QgsProject::instance()->readNumEntry( mNameConfig, QStringLiteral( "/MarginH" ), 0 );
mMarginVertical = QgsProject::instance()->readNumEntry( mNameConfig, QStringLiteral( "/MarginV" ), 0 );
mLabelQColor.setNamedColor( prj->readEntry( mNameConfig, QStringLiteral( "/Color" ), QStringLiteral( "#000000" ) ) ); // default color is black
mColor = QgsSymbolLayerUtils::decodeColor( QgsProject::instance()->readEntry( mNameConfig, QStringLiteral( "/Color" ), QStringLiteral( "#000000" ) ) );
}

void QgsDecorationCopyright::saveToProject()
{
QgsDecorationItem::saveToProject();
QgsProject *prj = QgsProject::instance();
prj->writeEntry( mNameConfig, QStringLiteral( "/FontName" ), mQFont.family() );
prj->writeEntry( mNameConfig, QStringLiteral( "/FontSize" ), mQFont.pointSize() );
prj->writeEntry( mNameConfig, QStringLiteral( "/Label" ), mLabelQString );
prj->writeEntry( mNameConfig, QStringLiteral( "/Color" ), mLabelQColor.name() );
prj->writeEntry( mNameConfig, QStringLiteral( "/MarginH" ), mMarginHorizontal );
prj->writeEntry( mNameConfig, QStringLiteral( "/MarginV" ), mMarginVertical );
QgsProject::instance()->writeEntry( mNameConfig, QStringLiteral( "/FontName" ), mQFont.family() );
QgsProject::instance()->writeEntry( mNameConfig, QStringLiteral( "/FontSize" ), mQFont.pointSize() );
QgsProject::instance()->writeEntry( mNameConfig, QStringLiteral( "/Label" ), mLabelQString );
QgsProject::instance()->writeEntry( mNameConfig, QStringLiteral( "/Color" ), QgsSymbolLayerUtils::encodeColor( mColor ) );
QgsProject::instance()->writeEntry( mNameConfig, QStringLiteral( "/MarginH" ), mMarginHorizontal );
QgsProject::instance()->writeEntry( mNameConfig, QStringLiteral( "/MarginV" ), mMarginVertical );
}

// Slot called when the buffer menu item is activated
@@ -104,8 +104,9 @@ void QgsDecorationCopyright::render( const QgsMapSettings &mapSettings, QgsRende
QTextDocument text;
text.setDefaultFont( mQFont );
// To set the text color in a QTextDocument we use a CSS style

QString style = "<style type=\"text/css\"> p {color: " +
mLabelQColor.name() + "}</style>";
QString( "rgba( %1, %2, %3, %4 )" ).arg( mColor.red() ).arg( mColor.green() ).arg( mColor.blue() ).arg( QString::number( mColor.alphaF(), 'f', 2 ) ) + "}</style>";
text.setHtml( style + "<p>" + mLabelQString + "</p>" );
QSizeF size = text.size();

@@ -54,8 +54,10 @@ class APP_EXPORT QgsDecorationCopyright : public QgsDecorationItem
QFont mQFont;
//! This is the string that will be used for the copyright label
QString mLabelQString;

//! This is the color for the copyright label
QColor mLabelQColor;
QColor mColor;

//! enable or disable use of position percentage for placement
int mMarginHorizontal;
int mMarginVertical;
@@ -50,13 +50,14 @@ QgsDecorationCopyrightDialog::QgsDecorationCopyrightDialog( QgsDecorationCopyrig
wgtUnitSelection->setUnit( mDeco.mMarginUnit );

// color
pbnColorChooser->setColor( mDeco.mLabelQColor );
pbnColorChooser->setAllowAlpha( true );
pbnColorChooser->setColor( mDeco.mColor );
pbnColorChooser->setContext( QStringLiteral( "gui" ) );
pbnColorChooser->setColorDialogTitle( tr( "Select text color" ) );

QTextCursor cursor = txtCopyrightText->textCursor();
txtCopyrightText->selectAll();
txtCopyrightText->setTextColor( mDeco.mLabelQColor );
txtCopyrightText->setTextColor( mDeco.mColor );
txtCopyrightText->setTextCursor( cursor );
}

@@ -89,7 +90,7 @@ void QgsDecorationCopyrightDialog::apply()
{
mDeco.mQFont = txtCopyrightText->currentFont();
mDeco.mLabelQString = txtCopyrightText->toPlainText();
mDeco.mLabelQColor = pbnColorChooser->color();
mDeco.mColor = pbnColorChooser->color();
mDeco.setPlacement( static_cast< QgsDecorationItem::Placement>( cboPlacement->currentData().toInt() ) );
mDeco.mMarginUnit = wgtUnitSelection->unit();
mDeco.mMarginHorizontal = spnHorizontal->value();

0 comments on commit cb23ebe

Please sign in to comment.