Qwt User's Guide: qwt_vectorfield_symbol.cpp Source File

Qwt User's Guide 6.2.0

qwt_vectorfield_symbol.cpp
1 /******************************************************************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *****************************************************************************/
9
10 #include "qwt_vectorfield_symbol.h"
11
12 #include <qpainter.h>
13 #include <qpainterpath.h>
14
16 QwtVectorFieldSymbol::QwtVectorFieldSymbol()
17 {
18 }
19
21 QwtVectorFieldSymbol::~QwtVectorFieldSymbol()
22 {
23 }
24
25 class QwtVectorFieldArrow::PrivateData
26 {
27 public:
28 PrivateData( qreal headW, qreal tailW )
29 : headWidth( headW )
30 , tailWidth( tailW )
31 , length( headW + 4.0 )
32 {
33 /*
34 Arrow is drawn horizontally, pointing into positive x direction
35 with tip at 0,0.
36 */
37
38 path.lineTo( -headWidth, headWidth );
39 path.lineTo( -headWidth, tailWidth );
40 path.lineTo( -length, tailWidth );
41 path.lineTo( -length, -tailWidth );
42 path.lineTo( -headWidth, -tailWidth );
43 path.lineTo( -headWidth, -headWidth );
44
45 path.closeSubpath();
46 }
47
48 void setLength( qreal l )
49 {
50 length = qMax( l, headWidth );
51
52 path.setElementPositionAt( 3, -length, tailWidth );
53 path.setElementPositionAt( 4, -length, -tailWidth );
54 }
55
56 const qreal headWidth;
57 const qreal tailWidth;
58 qreal length;
59
60 QPainterPath path;
61
62 };
63
74 QwtVectorFieldArrow::QwtVectorFieldArrow( qreal headWidth, qreal tailWidth )
75 {
76 m_data = new PrivateData( headWidth, tailWidth );
77 }
78
80 QwtVectorFieldArrow::~QwtVectorFieldArrow()
81 {
82 delete m_data;
83 }
84
85 void QwtVectorFieldArrow::setLength( qreal length )
86 {
87 m_data->setLength( length );
88 }
89
90 qreal QwtVectorFieldArrow::length() const
91 {
92 return m_data->length;
93 }
94
95 void QwtVectorFieldArrow::paint( QPainter* painter ) const
96 {
97 painter->drawPath( m_data->path );
98 }
99
100 class QwtVectorFieldThinArrow::PrivateData
101 {
102 public:
103 PrivateData( qreal headW )
104 : headWidth( headW )
105 , length( headW + 4.0 )
106 {
107 path.lineTo( -headWidth, headWidth * 0.6 );
108 path.moveTo( 0, 0 );
109 path.lineTo( -headWidth, -headWidth * 0.6 );
110 path.moveTo( 0, 0 );
111 path.lineTo( -length, 0 );
112 }
113
114 const qreal headWidth;
115 qreal length;
116
117 QPainterPath path;
118 };
119
128 QwtVectorFieldThinArrow::QwtVectorFieldThinArrow( qreal headWidth )
129 {
130 m_data = new PrivateData( headWidth );
131 }
132
134 QwtVectorFieldThinArrow::~QwtVectorFieldThinArrow()
135 {
136 delete m_data;
137 }
138
139 void QwtVectorFieldThinArrow::setLength( qreal length )
140 {
141 m_data->length = length;
142
143 const qreal headWidth = qMin( m_data->headWidth, length / 3.0 );
144
145 QPainterPath& path = m_data->path;
146
147 path.setElementPositionAt( 1, -headWidth, headWidth * 0.6 );
148 path.setElementPositionAt( 3, -headWidth, -headWidth * 0.6 );
149 path.setElementPositionAt( 5, -length, 0 );
150 }
151
152 qreal QwtVectorFieldThinArrow::length() const
153 {
154 return m_data->length;
155 }
156
157 void QwtVectorFieldThinArrow::paint(QPainter* p) const
158 {
159 p->drawPath( m_data->path );
160 }
QwtVectorFieldArrow::paint
virtual void paint(QPainter *) const override
Draw the symbol/arrow.
Definition: qwt_vectorfield_symbol.cpp:95
QwtVectorFieldArrow::QwtVectorFieldArrow
QwtVectorFieldArrow(qreal headWidth=6.0, qreal tailWidth=1.0)
Constructor.
Definition: qwt_vectorfield_symbol.cpp:74
QwtVectorFieldArrow::setLength
virtual void setLength(qreal length) override
Definition: qwt_vectorfield_symbol.cpp:85
QwtVectorFieldArrow::length
virtual qreal length() const override
Definition: qwt_vectorfield_symbol.cpp:90
QwtVectorFieldArrow::~QwtVectorFieldArrow
virtual ~QwtVectorFieldArrow() override
Destructor.
Definition: qwt_vectorfield_symbol.cpp:80
QwtVectorFieldSymbol::QwtVectorFieldSymbol
QwtVectorFieldSymbol()
Constructor.
Definition: qwt_vectorfield_symbol.cpp:16
QwtVectorFieldSymbol::~QwtVectorFieldSymbol
virtual ~QwtVectorFieldSymbol()
Destructor.
Definition: qwt_vectorfield_symbol.cpp:21
QwtVectorFieldThinArrow::QwtVectorFieldThinArrow
QwtVectorFieldThinArrow(qreal headWidth=6.0)
Constructor.
Definition: qwt_vectorfield_symbol.cpp:128
QwtVectorFieldThinArrow::setLength
virtual void setLength(qreal length) override
Definition: qwt_vectorfield_symbol.cpp:139
QwtVectorFieldThinArrow::paint
virtual void paint(QPainter *) const override
Draw the symbol/arrow.
Definition: qwt_vectorfield_symbol.cpp:157
QwtVectorFieldThinArrow::~QwtVectorFieldThinArrow
virtual ~QwtVectorFieldThinArrow() override
Destructor.
Definition: qwt_vectorfield_symbol.cpp:134
QwtVectorFieldThinArrow::length
virtual qreal length() const override
Definition: qwt_vectorfield_symbol.cpp:152