mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
Improve appearance and readability of rotate marker overlay
This commit is contained in:
parent
690d403f55
commit
0480a646f5
@ -16,6 +16,7 @@
|
|||||||
#include "qgspointrotationitem.h"
|
#include "qgspointrotationitem.h"
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include "qgsguiutils.h"
|
||||||
|
|
||||||
QgsPointRotationItem::QgsPointRotationItem( QgsMapCanvas *canvas )
|
QgsPointRotationItem::QgsPointRotationItem( QgsMapCanvas *canvas )
|
||||||
: QgsMapCanvasItem( canvas )
|
: QgsMapCanvasItem( canvas )
|
||||||
@ -37,6 +38,7 @@ void QgsPointRotationItem::paint( QPainter *painter )
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
painter->setRenderHint( QPainter::Antialiasing, true );
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
//do a bit of trigonometry to find out how to transform a rotated item such that the center point is at the point feature
|
//do a bit of trigonometry to find out how to transform a rotated item such that the center point is at the point feature
|
||||||
@ -55,12 +57,35 @@ void QgsPointRotationItem::paint( QPainter *painter )
|
|||||||
painter->translate( x - mPixmap.width() / 2.0, -y - mPixmap.height() / 2.0 );
|
painter->translate( x - mPixmap.width() / 2.0, -y - mPixmap.height() / 2.0 );
|
||||||
painter->drawPixmap( 0, 0, mPixmap );
|
painter->drawPixmap( 0, 0, mPixmap );
|
||||||
|
|
||||||
//draw numeric value beside the symbol
|
//draw arrow, using a red line over a thicker white line so that the arrow is visible against a range of backgrounds
|
||||||
|
QPen pen;
|
||||||
|
pen.setWidth( QgsGuiUtils::scaleIconSize( 4 ) );
|
||||||
|
pen.setColor( QColor( Qt::white ) );
|
||||||
|
painter->setPen( pen );
|
||||||
|
painter->drawPath( mArrowPath );
|
||||||
|
pen.setWidth( QgsGuiUtils::scaleIconSize( 1 ) );
|
||||||
|
pen.setColor( QColor( Qt::red ) );
|
||||||
|
painter->setPen( pen );
|
||||||
|
painter->drawPath( mArrowPath );
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
|
//draw numeric value beside the symbol
|
||||||
|
painter->save();
|
||||||
|
|
||||||
|
QPen bufferPen;
|
||||||
|
bufferPen.setColor( Qt::white );
|
||||||
|
bufferPen.setWidthF( QgsGuiUtils::scaleIconSize( 4 ) );
|
||||||
QFontMetricsF fm( mFont );
|
QFontMetricsF fm( mFont );
|
||||||
painter->fillRect( mPixmap.width(), 0, mItemSize.width() - mPixmap.width(), mItemSize.height(), QColor( Qt::white ) );
|
QPainterPath label;
|
||||||
painter->setFont( mFont );
|
label.addText( mPixmap.width(), mPixmap.height() / 2.0 + fm.height() / 2.0, mFont, QString::number( mRotation ) );
|
||||||
painter->drawText( mPixmap.width(), mPixmap.height() / 2.0 + fm.height() / 2.0, QString::number( mRotation ) );
|
painter->setPen( bufferPen );
|
||||||
|
painter->setBrush( Qt::NoBrush );
|
||||||
|
painter->drawPath( label );
|
||||||
|
painter->setPen( Qt::NoPen );
|
||||||
|
painter->setBrush( QBrush( Qt::black ) );
|
||||||
|
painter->drawPath( label );
|
||||||
|
|
||||||
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsPointRotationItem::setPointLocation( const QgsPointXY &p )
|
void QgsPointRotationItem::setPointLocation( const QgsPointXY &p )
|
||||||
@ -74,25 +99,13 @@ void QgsPointRotationItem::setSymbol( const QImage &symbolImage )
|
|||||||
mPixmap = QPixmap::fromImage( symbolImage );
|
mPixmap = QPixmap::fromImage( symbolImage );
|
||||||
QFontMetricsF fm( mFont );
|
QFontMetricsF fm( mFont );
|
||||||
|
|
||||||
//draw arrow
|
|
||||||
QPainter p( &mPixmap );
|
|
||||||
QPen pen;
|
|
||||||
pen.setWidth( 1 );
|
|
||||||
pen.setColor( QColor( Qt::red ) );
|
|
||||||
p.setPen( pen );
|
|
||||||
int halfItemWidth = mPixmap.width() / 2;
|
|
||||||
int quarterItemHeight = mPixmap.height() / 4;
|
|
||||||
p.drawLine( halfItemWidth, mPixmap.height(), halfItemWidth, 0 );
|
|
||||||
p.drawLine( halfItemWidth, 0, mPixmap.width() / 4, quarterItemHeight );
|
|
||||||
p.drawLine( halfItemWidth, 0, mPixmap.width() * 0.75, quarterItemHeight );
|
|
||||||
|
|
||||||
//set item size
|
//set item size
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
|
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
|
||||||
mItemSize.setWidth( mPixmap.width() + fm.width( QStringLiteral( "360" ) ) );
|
mItemSize.setWidth( mPixmap.width() + fm.width( QStringLiteral( "360" ) ) );
|
||||||
#else
|
#else
|
||||||
mItemSize.setWidth( mPixmap.width() + fm.horizontalAdvance( QStringLiteral( "360" ) ) );
|
mItemSize.setWidth( mPixmap.width() + fm.horizontalAdvance( QStringLiteral( "360" ) ) );
|
||||||
#endif
|
#endif
|
||||||
double pixmapHeight = mPixmap.height();
|
const double pixmapHeight = mPixmap.height();
|
||||||
double fontHeight = fm.height();
|
double fontHeight = fm.height();
|
||||||
if ( pixmapHeight >= fontHeight )
|
if ( pixmapHeight >= fontHeight )
|
||||||
{
|
{
|
||||||
@ -102,6 +115,14 @@ void QgsPointRotationItem::setSymbol( const QImage &symbolImage )
|
|||||||
{
|
{
|
||||||
mItemSize.setHeight( fm.height() );
|
mItemSize.setHeight( fm.height() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const double halfItemWidth = mPixmap.width() / 2.0;
|
||||||
|
mArrowPath.clear();
|
||||||
|
mArrowPath.moveTo( halfItemWidth, pixmapHeight );
|
||||||
|
mArrowPath.lineTo( halfItemWidth, 0 );
|
||||||
|
mArrowPath.moveTo( mPixmap.width() * 0.25, pixmapHeight * 0.25 );
|
||||||
|
mArrowPath.lineTo( halfItemWidth, 0 );
|
||||||
|
mArrowPath.lineTo( mPixmap.width() * 0.75, pixmapHeight * 0.25 );
|
||||||
}
|
}
|
||||||
|
|
||||||
int QgsPointRotationItem::painterRotation( int rotation ) const
|
int QgsPointRotationItem::painterRotation( int rotation ) const
|
||||||
|
@ -62,6 +62,8 @@ class APP_EXPORT QgsPointRotationItem: public QgsMapCanvasItem
|
|||||||
//! Symbol pixmap
|
//! Symbol pixmap
|
||||||
QPixmap mPixmap;
|
QPixmap mPixmap;
|
||||||
int mRotation;
|
int mRotation;
|
||||||
|
QPainterPath mArrowPath;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QGSPOINTROTATIONITEM_H
|
#endif // QGSPOINTROTATIONITEM_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user