Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgsvertexmarker.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvertexmarker.cpp - canvas item which shows a simple vertex marker
3  ---------------------
4  begin : February 2006
5  copyright : (C) 2006 by Martin Dobias
6  email : wonder.sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 /* $Id$ */
16 
17 #include <QPainter>
18 
19 #include "qgsvertexmarker.h"
20 
21 
23  : QgsMapCanvasItem( mapCanvas )
24 {
25  mIconSize = 10;
26  mIconType = ICON_X;
27  mColor = QColor( 255, 0, 0 );
28  mPenWidth = 1;
29 }
30 
32 {
33  mIconType = type;
34 }
35 
36 void QgsVertexMarker::setIconSize( int iconSize )
37 {
38  mIconSize = iconSize;
39 }
40 
42 {
43  mCenter = point;
44  QPointF pt = toCanvasCoordinates( mCenter );
45  setPos( pt );
46 }
47 
48 void QgsVertexMarker::setColor( const QColor& color )
49 {
50  mColor = color;
51 }
52 
54 {
55  mPenWidth = width;
56 }
57 
58 void QgsVertexMarker::paint( QPainter* p )
59 {
60  qreal s = ( mIconSize - 1 ) / 2;
61 
62  QPen pen( mColor );
63  pen.setWidth( mPenWidth );
64  p->setPen( pen );
65 
66  switch ( mIconType )
67  {
68  case ICON_NONE:
69  break;
70 
71  case ICON_CROSS:
72  p->drawLine( QLineF( -s, 0, s, 0 ) );
73  p->drawLine( QLineF( 0, -s, 0, s ) );
74  break;
75 
76  case ICON_X:
77  p->drawLine( QLineF( -s, -s, s, s ) );
78  p->drawLine( QLineF( -s, s, s, -s ) );
79  break;
80 
81  case ICON_BOX:
82  p->drawLine( QLineF( -s, -s, s, -s ) );
83  p->drawLine( QLineF( s, -s, s, s ) );
84  p->drawLine( QLineF( s, s, -s, s ) );
85  p->drawLine( QLineF( -s, s, -s, -s ) );
86  break;
87  }
88 }
89 
90 
92 {
93  qreal s = qreal( mIconSize + mPenWidth ) / 2.0;
94  return QRectF( -s, -s, 2.0*s, 2.0*s );
95 }
96 
98 {
99  setCenter( mCenter );
100 }