diff --git a/images/north_arrows/default.svg b/images/north_arrows/default.svg index 8b7f378a1a1..3509774df5f 100644 --- a/images/north_arrows/default.svg +++ b/images/north_arrows/default.svg @@ -25,9 +25,9 @@ borderopacity="1.0" inkscape:pageopacity="0" inkscape:pageshadow="2" - inkscape:zoom="7.919596" - inkscape:cx="-13.616663" - inkscape:cy="32.048127" + inkscape:zoom="11.2" + inkscape:cx="4.2981085" + inkscape:cy="49.312603" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="false" @@ -49,7 +49,7 @@ image/svg+xml - + @@ -59,25 +59,23 @@ id="layer1" transform="translate(-194.92496,-185.30539)"> - + sodipodi:nodetypes="ccccccccccccccccc" /> + style="font-size:10.58333302px;line-height:52.91666412px;font-family:Delicious;-inkscape-font-specification:Delicious;letter-spacing:0px;word-spacing:0px;fill:none;stroke:#000000;stroke-width:0.13229166;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="text4523" + transform="translate(0.00672731)"> + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:2.82222223px;font-family:'Arial Black';-inkscape-font-specification:'Arial Black, ';stroke-miterlimit:4;stroke-dasharray:none;" + id="path4486" + inkscape:connector-curvature="0" /> diff --git a/src/app/qgsdecorationnortharrow.cpp b/src/app/qgsdecorationnortharrow.cpp index a0c92656d5b..4e80a07479f 100644 --- a/src/app/qgsdecorationnortharrow.cpp +++ b/src/app/qgsdecorationnortharrow.cpp @@ -31,6 +31,7 @@ email : tim@linfiniti.com #include "qgslogger.h" #include "qgsmaplayer.h" #include "qgsproject.h" +#include "qgssymbollayerutils.h" #include "qgssvgcache.h" // qt includes @@ -75,6 +76,8 @@ QgsDecorationNorthArrow::~QgsDecorationNorthArrow() void QgsDecorationNorthArrow::projectRead() { QgsDecorationItem::projectRead(); + mColor = QgsSymbolLayerUtils::decodeColor( QgsProject::instance()->readEntry( mNameConfig, QStringLiteral( "/Color" ), QStringLiteral( "#000000" ) ) ); + mOutlineColor = QgsSymbolLayerUtils::decodeColor( QgsProject::instance()->readEntry( mNameConfig, QStringLiteral( "/OutlineColor" ), QStringLiteral( "#FFFFFF" ) ) ); mRotationInt = QgsProject::instance()->readNumEntry( mNameConfig, QStringLiteral( "/Rotation" ), 0 ); mAutomatic = QgsProject::instance()->readBoolEntry( mNameConfig, QStringLiteral( "/Automatic" ), true ); mMarginHorizontal = QgsProject::instance()->readNumEntry( mNameConfig, QStringLiteral( "/MarginH" ), 0 ); @@ -84,6 +87,8 @@ void QgsDecorationNorthArrow::projectRead() void QgsDecorationNorthArrow::saveToProject() { QgsDecorationItem::saveToProject(); + QgsProject::instance()->writeEntry( mNameConfig, QStringLiteral( "/Color" ), QgsSymbolLayerUtils::encodeColor( mColor ) ); + QgsProject::instance()->writeEntry( mNameConfig, QStringLiteral( "/OutlineColor" ), QgsSymbolLayerUtils::encodeColor( mOutlineColor ) ); QgsProject::instance()->writeEntry( mNameConfig, QStringLiteral( "/Rotation" ), mRotationInt ); QgsProject::instance()->writeEntry( mNameConfig, QStringLiteral( "/Automatic" ), mAutomatic ); QgsProject::instance()->writeEntry( mNameConfig, QStringLiteral( "/MarginH" ), mMarginHorizontal ); @@ -106,7 +111,7 @@ void QgsDecorationNorthArrow::render( const QgsMapSettings &mapSettings, QgsRend QSize size( 64, 64 ); QSvgRenderer svg; - const QByteArray &svgContent = QgsApplication::svgCache()->svgContent( QStringLiteral( ":/images/north_arrows/default.svg" ), size.width(), QColor( "#000000" ), QColor( "#FFFFFF" ), 0.2, 1.0 ); + const QByteArray &svgContent = QgsApplication::svgCache()->svgContent( QStringLiteral( ":/images/north_arrows/default.svg" ), size.width(), mColor, mOutlineColor, 1.0, 1.0 ); svg.load( svgContent ); if ( svg.isValid() ) diff --git a/src/app/qgsdecorationnortharrow.h b/src/app/qgsdecorationnortharrow.h index a4cc8e87724..c5f655ff0c2 100644 --- a/src/app/qgsdecorationnortharrow.h +++ b/src/app/qgsdecorationnortharrow.h @@ -54,6 +54,11 @@ class APP_EXPORT QgsDecorationNorthArrow: public QgsDecorationItem // static const double DEG2RAD; static const double TOL; + //! The north arrow fill color + QColor mColor; + //! The north arrow outline color + QColor mOutlineColor; + // The amount of rotation for the north arrow int mRotationInt; diff --git a/src/app/qgsdecorationnortharrowdialog.cpp b/src/app/qgsdecorationnortharrowdialog.cpp index d0b1b0cf81e..59a9e4cd327 100644 --- a/src/app/qgsdecorationnortharrowdialog.cpp +++ b/src/app/qgsdecorationnortharrowdialog.cpp @@ -35,8 +35,6 @@ QgsDecorationNorthArrowDialog::QgsDecorationNorthArrowDialog( QgsDecorationNorth QPushButton *applyButton = buttonBox->button( QDialogButtonBox::Apply ); connect( applyButton, &QAbstractButton::clicked, this, &QgsDecorationNorthArrowDialog::apply ); - // rotation - rotatePixmap( mDeco.mRotationInt ); // signal/slot connection defined in 'designer' causes the slider to // be moved to reflect the change in the spinbox. spinAngle->setValue( mDeco.mRotationInt ); @@ -57,6 +55,21 @@ QgsDecorationNorthArrowDialog::QgsDecorationNorthArrowDialog( QgsDecorationNorth // automatic cboxAutomatic->setChecked( mDeco.mAutomatic ); + + pbnChangeColor->setAllowAlpha( true ); + pbnChangeColor->setColor( mDeco.mColor ); + pbnChangeColor->setContext( QStringLiteral( "gui" ) ); + pbnChangeColor->setColorDialogTitle( tr( "Select north arrow fill color" ) ); + + pbnChangeOutlineColor->setAllowAlpha( true ); + pbnChangeOutlineColor->setColor( mDeco.mOutlineColor ); + pbnChangeOutlineColor->setContext( QStringLiteral( "gui" ) ); + pbnChangeOutlineColor->setColorDialogTitle( tr( "Select north arrow outline color" ) ); + + connect( pbnChangeColor, &QgsColorButton::colorChanged, this, [ = ]( QColor ) { drawNorthArrow(); } ); + connect( pbnChangeOutlineColor, &QgsColorButton::colorChanged, this, [ = ]( QColor ) { drawNorthArrow(); } ); + + drawNorthArrow(); } QgsDecorationNorthArrowDialog::~QgsDecorationNorthArrowDialog() @@ -89,11 +102,15 @@ void QgsDecorationNorthArrowDialog::on_spinAngle_valueChanged( int spinAngle ) void QgsDecorationNorthArrowDialog::on_sliderRotation_valueChanged( int rotationValue ) { - rotatePixmap( rotationValue ); + Q_UNUSED( rotationValue ); + + drawNorthArrow(); } void QgsDecorationNorthArrowDialog::apply() { + mDeco.mColor = pbnChangeColor->color(); + mDeco.mOutlineColor = pbnChangeOutlineColor->color(); mDeco.mRotationInt = sliderRotation->value(); mDeco.setPlacement( static_cast< QgsDecorationItem::Placement>( cboPlacement->currentData().toInt() ) ); mDeco.mMarginUnit = wgtUnitSelection->unit(); @@ -104,12 +121,14 @@ void QgsDecorationNorthArrowDialog::apply() mDeco.update(); } -void QgsDecorationNorthArrowDialog::rotatePixmap( int rotationInt ) +void QgsDecorationNorthArrowDialog::drawNorthArrow() { + int rotation = spinAngle->value(); + QSize size( 64, 64 ); QSvgRenderer svg; - const QByteArray &svgContent = QgsApplication::svgCache()->svgContent( QStringLiteral( ":/images/north_arrows/default.svg" ), size.width(), QColor( "#000000" ), QColor( "#FFFFFF" ), 0.2, 1.0 ); + const QByteArray &svgContent = QgsApplication::svgCache()->svgContent( QStringLiteral( ":/images/north_arrows/default.svg" ), size.width(), pbnChangeColor->color(), pbnChangeOutlineColor->color(), 1.0, 1.0 ); svg.load( svgContent ); if ( svg.isValid() ) @@ -129,11 +148,11 @@ void QgsDecorationNorthArrowDialog::rotatePixmap( int rotationInt ) //myQPainter.translate( (int)centerXDouble, (int)centerYDouble ); //rotate the canvas - myQPainter.rotate( rotationInt ); + myQPainter.rotate( rotation ); //work out how to shift the image so that it appears in the center of the canvas //(x cos a + y sin a - x, -x sin a + y cos a - y) const double PI = 3.14159265358979323846; - double myRadiansDouble = ( PI / 180 ) * rotationInt; + double myRadiansDouble = ( PI / 180 ) * rotation; int xShift = static_cast( ( ( centerXDouble * cos( myRadiansDouble ) ) + ( centerYDouble * sin( myRadiansDouble ) ) @@ -175,5 +194,5 @@ void QgsDecorationNorthArrowDialog::rotatePixmap( int rotationInt ) void QgsDecorationNorthArrowDialog::resizeEvent( QResizeEvent *resizeEvent ) { Q_UNUSED( resizeEvent ); - rotatePixmap( sliderRotation->value() ); + drawNorthArrow(); } diff --git a/src/app/qgsdecorationnortharrowdialog.h b/src/app/qgsdecorationnortharrowdialog.h index 09fea3c9946..fcf797d8326 100644 --- a/src/app/qgsdecorationnortharrowdialog.h +++ b/src/app/qgsdecorationnortharrowdialog.h @@ -26,7 +26,7 @@ class APP_EXPORT QgsDecorationNorthArrowDialog : public QDialog, private Ui::Qgs ~QgsDecorationNorthArrowDialog(); private: - void rotatePixmap( int rotationInt ); + void drawNorthArrow(); void resizeEvent( QResizeEvent * ) override; //overloads qwidget private slots: diff --git a/src/ui/qgsdecorationnortharrowdialog.ui b/src/ui/qgsdecorationnortharrowdialog.ui index ff7f078aae1..9ed4c383fbf 100644 --- a/src/ui/qgsdecorationnortharrowdialog.ui +++ b/src/ui/qgsdecorationnortharrowdialog.ui @@ -30,7 +30,76 @@ false - + + + + + 0 + 0 + + + + Color + + + + + + + + + Fill + + + + + + + + 150 + 0 + + + + + 120 + 16777215 + + + + + + + + + + + Outline + + + + + + + + 150 + 0 + + + + + 120 + 16777215 + + + + + + + + + + @@ -99,7 +168,7 @@ - + @@ -121,7 +190,7 @@ - + 360 @@ -134,7 +203,7 @@ - + Placement @@ -144,7 +213,7 @@ - + @@ -157,14 +226,14 @@ - + Placement on screen - + @@ -192,7 +261,7 @@ - + Qt::Vertical @@ -205,7 +274,7 @@ - + @@ -224,7 +293,7 @@ - + @@ -263,6 +332,12 @@ + + QgsColorButton + QToolButton +
qgscolorbutton.h
+ 1 +
QgsSpinBox QSpinBox @@ -277,6 +352,7 @@
grpEnable + pbnChangeColor sliderRotation spinAngle cboPlacement