Quantum GIS API Documentation  1.7.4
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 /* $Id$ */
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 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines