10 #include "qwt_compass_rose.h"
11 #include "qwt_point_polar.h"
14 #include <qpainterpath.h>
16 static QPointF qwtIntersection(
17 QPointF p11, QPointF p12, QPointF p21, QPointF p22 )
19 const QLineF line1( p11, p12 );
20 const QLineF line2( p21, p22 );
23 #if QT_VERSION >= 0x050e00
24 if ( line1.intersects( line2, &pos ) == QLineF::NoIntersection )
26 if ( line1.intersect( line2, &pos ) == QLineF::NoIntersection )
55 class QwtSimpleCompassRose::PrivateData
79 int numThorns,
int numThornLevels )
81 m_data =
new PrivateData();
85 const QColor dark( 128, 128, 255 );
86 const QColor light( 192, 255, 255 );
89 palette.setColor( QPalette::Dark, dark );
90 palette.setColor( QPalette::Light, light );
110 m_data->shrinkFactor = factor;
119 return m_data->shrinkFactor;
132 double radius,
double north, QPalette::ColorGroup cg )
const
135 pal.setCurrentColorGroup( cg );
137 drawRose( painter, pal, center, radius, north, m_data->width,
138 m_data->numThorns, m_data->numThornLevels, m_data->shrinkFactor );
156 const QPalette& palette,
157 const QPointF& center,
double radius,
double north,
double width,
158 int numThorns,
int numThornLevels,
double shrinkFactor )
177 painter->setPen( Qt::NoPen );
181 double step = std::pow( 2.0, j ) * M_PI /
numThorns;
186 for (
int k = 0; k < 3; k++ )
192 double leafWidth = r *
width;
193 if ( 2.0 * M_PI / step > 32 )
196 const double origin = qwtRadians( north );
197 for (
double angle = origin;
198 angle < 2.0 * M_PI + origin; angle += step )
200 const QPointF p = qwtPolar2Pos( center, r, angle );
201 const QPointF p1 = qwtPolar2Pos( center, leafWidth, angle + M_PI_2 );
202 const QPointF p2 = qwtPolar2Pos( center, leafWidth, angle - M_PI_2 );
203 const QPointF p3 = qwtPolar2Pos( center, r, angle + step / 2.0 );
204 const QPointF p4 = qwtPolar2Pos( center, r, angle - step / 2.0 );
206 QPainterPath darkPath;
207 darkPath.moveTo( center );
208 darkPath.lineTo( p );
209 darkPath.lineTo( qwtIntersection( center, p3, p1, p ) );
211 painter->setBrush(
palette.brush( QPalette::Dark ) );
212 painter->drawPath( darkPath );
214 QPainterPath lightPath;
215 lightPath.moveTo( center );
216 lightPath.lineTo( p );
217 lightPath.lineTo( qwtIntersection( center, p4, p2, p ) );
219 painter->setBrush(
palette.brush( QPalette::Light ) );
220 painter->drawPath( lightPath );
234 m_data->width =
width;
235 if ( m_data->width < 0.03 )
236 m_data->width = 0.03;
238 if ( m_data->width > 0.4 )
248 return m_data->width;
275 return m_data->numThorns;
295 return m_data->numThornLevels;
virtual ~QwtCompassRose()
Destructor.
QwtCompassRose()
Constructor.
virtual void setPalette(const QPalette &)
Assign a palette.
const QPalette & palette() const
virtual ~QwtSimpleCompassRose()
Destructor.
void setNumThornLevels(int)
double shrinkFactor() const
QwtSimpleCompassRose(int numThorns=8, int numThornLevels=-1)
int numThornLevels() const
virtual void draw(QPainter *, const QPointF ¢er, double radius, double north, QPalette::ColorGroup=QPalette::Active) const override
static void drawRose(QPainter *, const QPalette &, const QPointF ¢er, double radius, double north, double width, int numThorns, int numThornLevels, double shrinkFactor)
void setShrinkFactor(double factor)