00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <QPainter>
00018
00019 #include "qgsvertexmarker.h"
00020
00021
00022 QgsVertexMarker::QgsVertexMarker( QgsMapCanvas* mapCanvas )
00023 : QgsMapCanvasItem( mapCanvas )
00024 {
00025 mIconSize = 10;
00026 mIconType = ICON_X;
00027 mColor = QColor( 255, 0, 0 );
00028 mPenWidth = 1;
00029 }
00030
00031 void QgsVertexMarker::setIconType( int type )
00032 {
00033 mIconType = type;
00034 }
00035
00036 void QgsVertexMarker::setIconSize( int iconSize )
00037 {
00038 mIconSize = iconSize;
00039 }
00040
00041 void QgsVertexMarker::setCenter( const QgsPoint& point )
00042 {
00043 mCenter = point;
00044 QPointF pt = toCanvasCoordinates( mCenter );
00045 setPos( pt );
00046 }
00047
00048 void QgsVertexMarker::setColor( const QColor& color )
00049 {
00050 mColor = color;
00051 }
00052
00053 void QgsVertexMarker::setPenWidth( int width )
00054 {
00055 mPenWidth = width;
00056 }
00057
00058 void QgsVertexMarker::paint( QPainter* p )
00059 {
00060 qreal s = ( mIconSize - 1 ) / 2;
00061
00062 QPen pen( mColor );
00063 pen.setWidth( mPenWidth );
00064 p->setPen( pen );
00065
00066 switch ( mIconType )
00067 {
00068 case ICON_NONE:
00069 break;
00070
00071 case ICON_CROSS:
00072 p->drawLine( QLineF( -s, 0, s, 0 ) );
00073 p->drawLine( QLineF( 0, -s, 0, s ) );
00074 break;
00075
00076 case ICON_X:
00077 p->drawLine( QLineF( -s, -s, s, s ) );
00078 p->drawLine( QLineF( -s, s, s, -s ) );
00079 break;
00080
00081 case ICON_BOX:
00082 p->drawLine( QLineF( -s, -s, s, -s ) );
00083 p->drawLine( QLineF( s, -s, s, s ) );
00084 p->drawLine( QLineF( s, s, -s, s ) );
00085 p->drawLine( QLineF( -s, s, -s, -s ) );
00086 break;
00087 }
00088 }
00089
00090
00091 QRectF QgsVertexMarker::boundingRect() const
00092 {
00093 qreal s = qreal( mIconSize + mPenWidth ) / 2.0;
00094 return QRectF( -s, -s, 2.0*s, 2.0*s );
00095 }
00096
00097 void QgsVertexMarker::updatePosition()
00098 {
00099 setCenter( mCenter );
00100 }