Quantum GIS API Documentation  1.8
src/gui/qgsvertexmarker.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002     qgsvertexmarker.cpp  - canvas item which shows a simple vertex marker
00003     ---------------------
00004     begin                : February 2006
00005     copyright            : (C) 2006 by Martin Dobias
00006     email                : wonder.sk at gmail dot com
00007  ***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  ***************************************************************************/
00015 
00016 #include <QPainter>
00017 
00018 #include "qgsvertexmarker.h"
00019 
00020 
00021 QgsVertexMarker::QgsVertexMarker( QgsMapCanvas* mapCanvas )
00022     : QgsMapCanvasItem( mapCanvas )
00023 {
00024   mIconSize = 10;
00025   mIconType = ICON_X;
00026   mColor = QColor( 255, 0, 0 );
00027   mPenWidth = 1;
00028 }
00029 
00030 void QgsVertexMarker::setIconType( int type )
00031 {
00032   mIconType = type;
00033 }
00034 
00035 void QgsVertexMarker::setIconSize( int iconSize )
00036 {
00037   mIconSize = iconSize;
00038 }
00039 
00040 void QgsVertexMarker::setCenter( const QgsPoint& point )
00041 {
00042   mCenter = point;
00043   QPointF pt = toCanvasCoordinates( mCenter );
00044   setPos( pt );
00045 }
00046 
00047 void QgsVertexMarker::setColor( const QColor& color )
00048 {
00049   mColor = color;
00050 }
00051 
00052 void QgsVertexMarker::setPenWidth( int width )
00053 {
00054   mPenWidth = width;
00055 }
00056 
00057 void QgsVertexMarker::paint( QPainter* p )
00058 {
00059   qreal s = ( mIconSize - 1 ) / 2;
00060 
00061   QPen pen( mColor );
00062   pen.setWidth( mPenWidth );
00063   p->setPen( pen );
00064 
00065   switch ( mIconType )
00066   {
00067     case ICON_NONE:
00068       break;
00069 
00070     case ICON_CROSS:
00071       p->drawLine( QLineF( -s, 0, s, 0 ) );
00072       p->drawLine( QLineF( 0, -s, 0, s ) );
00073       break;
00074 
00075     case ICON_X:
00076       p->drawLine( QLineF( -s, -s, s, s ) );
00077       p->drawLine( QLineF( -s, s, s, -s ) );
00078       break;
00079 
00080     case ICON_BOX:
00081       p->drawLine( QLineF( -s, -s, s, -s ) );
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       break;
00086   }
00087 }
00088 
00089 
00090 QRectF QgsVertexMarker::boundingRect() const
00091 {
00092   qreal s = qreal( mIconSize + mPenWidth ) / 2.0;
00093   return QRectF( -s, -s, 2.0*s, 2.0*s );
00094 }
00095 
00096 void QgsVertexMarker::updatePosition()
00097 {
00098   setCenter( mCenter );
00099 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines