| 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 |
|
|---|
| 15 | //! Constructor
|
|---|
| 16 | QwtVectorFieldSymbol::QwtVectorFieldSymbol()
|
|---|
| 17 | {
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | //! Destructor
|
|---|
| 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 |
|
|---|
| 64 | /*!
|
|---|
| 65 | \brief Constructor
|
|---|
| 66 |
|
|---|
| 67 | The length is initialized by headWidth + 4
|
|---|
| 68 |
|
|---|
| 69 | \param headWidth Width of the triangular head
|
|---|
| 70 | \param tailWidth Width of the arrow tail
|
|---|
| 71 |
|
|---|
| 72 | \sa setLength()
|
|---|
| 73 | */
|
|---|
| 74 | QwtVectorFieldArrow::QwtVectorFieldArrow( qreal headWidth, qreal tailWidth )
|
|---|
| 75 | {
|
|---|
| 76 | m_data = new PrivateData( headWidth, tailWidth );
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | //! Destructor
|
|---|
| 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 |
|
|---|
| 120 | /*!
|
|---|
| 121 | \brief Constructor
|
|---|
| 122 |
|
|---|
| 123 | The length is initialized by headWidth + 4
|
|---|
| 124 |
|
|---|
| 125 | \param headWidth Width of the triangular head
|
|---|
| 126 | \sa setLength()
|
|---|
| 127 | */
|
|---|
| 128 | QwtVectorFieldThinArrow::QwtVectorFieldThinArrow( qreal headWidth )
|
|---|
| 129 | {
|
|---|
| 130 | m_data = new PrivateData( headWidth );
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | //! \brief Destructor
|
|---|
| 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 | }
|
|---|