qwt_vectorfield_symbol.cpp
Go to the documentation of this file.
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 
17 {
18 }
19 
22 {
23 }
24 
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 
81 {
82  delete m_data;
83 }
84 
86 {
87  m_data->setLength( length );
88 }
89 
91 {
92  return m_data->length;
93 }
94 
95 void QwtVectorFieldArrow::paint( QPainter* painter ) const
96 {
97  painter->drawPath( m_data->path );
98 }
99 
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 
129 {
130  m_data = new PrivateData( headWidth );
131 }
132 
135 {
136  delete m_data;
137 }
138 
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 
153 {
154  return m_data->length;
155 }
156 
157 void QwtVectorFieldThinArrow::paint(QPainter* p) const
158 {
159  p->drawPath( m_data->path );
160 }
virtual ~QwtVectorFieldArrow() QWT_OVERRIDE
Destructor.
virtual qreal length() const QWT_OVERRIDE
virtual qreal length() const =0
virtual void paint(QPainter *) const QWT_OVERRIDE
Draw the symbol/arrow.
QwtVectorFieldArrow(qreal headWidth=6.0, qreal tailWidth=1.0)
Constructor.
virtual void setLength(qreal length) QWT_OVERRIDE
virtual qreal length() const QWT_OVERRIDE
virtual ~QwtVectorFieldThinArrow() QWT_OVERRIDE
Destructor.
virtual ~QwtVectorFieldSymbol()
Destructor.
QwtVectorFieldThinArrow(qreal headWidth=6.0)
Constructor.
virtual void setLength(qreal length) QWT_OVERRIDE
virtual void paint(QPainter *) const QWT_OVERRIDE
Draw the symbol/arrow.


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Jun 19 2023 03:01:39