14 #include <qpainterpath.h> 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 )
79 int numThorns,
int numThornLevels )
82 d_data->numThorns = numThorns;
83 d_data->numThornLevels = numThornLevels;
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 d_data->shrinkFactor = factor;
119 return d_data->shrinkFactor;
132 double radius,
double north, QPalette::ColorGroup cg )
const 135 pal.setCurrentColorGroup( cg );
137 drawRose( painter, pal, center, radius, north, d_data->width,
138 d_data->numThorns, d_data->numThornLevels, d_data->shrinkFactor );
157 const QPointF &
center,
double radius,
double north,
double width,
158 int numThorns,
int numThornLevels,
double shrinkFactor )
164 numThorns += 4 - numThorns % 4;
166 if ( numThornLevels <= 0 )
167 numThornLevels = numThorns / 4;
169 if ( shrinkFactor >= 1.0 )
172 if ( shrinkFactor <= 0.5 )
177 painter->setPen( Qt::NoPen );
179 for (
int j = 1; j <= numThornLevels; j++ )
181 double step = std::pow( 2.0, j ) *
M_PI / numThorns;
186 for (
int k = 0; k < 3; k++ )
188 if ( j + k < numThornLevels )
192 double leafWidth = r * width;
193 if ( 2.0 *
M_PI / step > 32 )
197 for (
double angle = origin;
198 angle < 2.0 *
M_PI + origin; angle += step )
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 );
211 painter->setBrush( palette.brush( QPalette::Dark ) );
212 painter->drawPath( darkPath );
214 QPainterPath lightPath;
215 lightPath.moveTo( center );
216 lightPath.lineTo( p );
219 painter->setBrush( palette.brush( QPalette::Light ) );
220 painter->drawPath( lightPath );
234 d_data->width = width;
235 if ( d_data->width < 0.03 )
236 d_data->width = 0.03;
238 if ( d_data->width > 0.4 )
248 return d_data->width;
264 numThorns += 4 - numThorns % 4;
266 d_data->numThorns = numThorns;
275 return d_data->numThorns;
286 d_data->numThornLevels = numThornLevels;
295 return d_data->numThornLevels;
virtual ~QwtCompassRose()
Destructor.
const QPalette & palette() const
static void drawRose(QPainter *, const QPalette &, const QPointF ¢er, double radius, double north, double width, int numThorns, int numThornLevels, double shrinkFactor)
static QPointF qwtIntersection(QPointF p11, QPointF p12, QPointF p21, QPointF p22)
virtual void setPalette(const QPalette &)
Assign a palette.
QPoint qwtPolar2Pos(const QPoint &pole, double radius, double angle)
QwtCompassRose()
Constructor.
void setNumThornLevels(int)
double qwtRadians(double degrees)
Translate degrees into radians.
QwtSimpleCompassRose(int numThorns=8, int numThornLevels=-1)
double shrinkFactor() const
int numThornLevels() const
virtual ~QwtSimpleCompassRose()
Destructor.
void setShrinkFactor(double factor)
virtual void draw(QPainter *, const QPointF ¢er, double radius, double north, QPalette::ColorGroup=QPalette::Active) const QWT_OVERRIDE