A simple rose for QwtCompass. More...
#include <qwt_compass_rose.h>


Public Member Functions | |
| QwtSimpleCompassRose (int numThorns=8, int numThornLevels=-1) | |
| void | setWidth (double w) |
| double | width () const |
| void | setNumThorns (int count) |
| int | numThorns () const |
| void | setNumThornLevels (int count) |
| int | numThornLevels () const |
| void | setShrinkFactor (double factor) |
| double | shrinkFactor () const |
| virtual void | draw (QPainter *, const QPoint ¢er, int radius, double north, QPalette::ColorGroup=QPalette::Active) const |
Static Public Member Functions | |
| static void | drawRose (QPainter *, const QColorGroup &, const QPoint ¢er, int radius, double origin, double width, int numThorns, int numThornLevels, double shrinkFactor) |
A simple rose for QwtCompass.
Definition at line 52 of file qwt_compass_rose.h.
| QwtSimpleCompassRose::QwtSimpleCompassRose | ( | int | numThorns = 8, |
| int | numThornLevels = -1 |
||
| ) |
Constructor
| numThorns | Number of thorns |
| numThornLevels | Number of thorn levels |
Definition at line 61 of file qwt_compass_rose.cpp.
References QwtCompassRose::palette(), and QwtCompassRose::setPalette().
:
d_width(0.2),
d_numThorns(numThorns),
d_numThornLevels(numThornLevels),
d_shrinkFactor(0.9)
{
const QColor dark(128,128,255);
const QColor light(192,255,255);
QPalette palette;
for ( int i = 0; i < QPalette::NColorGroups; i++ )
{
#if QT_VERSION < 0x040000
palette.setColor((QPalette::ColorGroup)i,
QColorGroup::Dark, dark);
palette.setColor((QPalette::ColorGroup)i,
QColorGroup::Light, light);
#else
palette.setColor((QPalette::ColorGroup)i,
QPalette::Dark, dark);
palette.setColor((QPalette::ColorGroup)i,
QPalette::Light, light);
#endif
}
setPalette(palette);
}
| void QwtSimpleCompassRose::draw | ( | QPainter * | painter, |
| const QPoint & | center, | ||
| int | radius, | ||
| double | north, | ||
| QPalette::ColorGroup | cg = QPalette::Active |
||
| ) | const [virtual] |
Draw the rose
| painter | Painter |
| center | Center point |
| radius | Radius of the rose |
| north | Position |
| cg | Color group |
Implements QwtCompassRose.
Definition at line 98 of file qwt_compass_rose.cpp.
References drawRose(), and QwtCompassRose::palette().
{
#if QT_VERSION < 0x040000
QColorGroup colorGroup;
switch(cg)
{
case QPalette::Disabled:
colorGroup = palette().disabled();
case QPalette::Inactive:
colorGroup = palette().inactive();
default:
colorGroup = palette().active();
}
drawRose(painter, colorGroup, center, radius, north, d_width,
d_numThorns, d_numThornLevels, d_shrinkFactor);
#else
QPalette pal = palette();
pal.setCurrentColorGroup(cg);
drawRose(painter, pal, center, radius, north, d_width,
d_numThorns, d_numThornLevels, d_shrinkFactor);
#endif
}
| void QwtSimpleCompassRose::drawRose | ( | QPainter * | painter, |
| const QColorGroup & | cg, | ||
| const QPoint & | center, | ||
| int | radius, | ||
| double | north, | ||
| double | width, | ||
| int | numThorns, | ||
| int | numThornLevels, | ||
| double | shrinkFactor | ||
| ) | [static] |
Draw the rose
| painter | Painter |
| palette | Palette |
| center | Center of the rose |
| radius | Radius of the rose |
| north | Position pointing to north |
| width | Width of the rose |
| numThorns | Number of thorns |
| numThornLevels | Number of thorn levels |
| shrinkFactor | Factor to shrink the thorns with each level |
Definition at line 136 of file qwt_compass_rose.cpp.
References cutPoint(), M_PI, M_PI_2, numThornLevels(), QuadProgPP::pow(), qwtPolar2Pos(), shrinkFactor(), and width().
Referenced by draw().
{
if ( numThorns < 4 )
numThorns = 4;
if ( numThorns % 4 )
numThorns += 4 - numThorns % 4;
if ( numThornLevels <= 0 )
numThornLevels = numThorns / 4;
if ( shrinkFactor >= 1.0 )
shrinkFactor = 1.0;
if ( shrinkFactor <= 0.5 )
shrinkFactor = 0.5;
painter->save();
painter->setPen(Qt::NoPen);
for ( int j = 1; j <= numThornLevels; j++ )
{
double step = pow(2.0, j) * M_PI / (double)numThorns;
if ( step > M_PI_2 )
break;
double r = radius;
for ( int k = 0; k < 3; k++ )
{
if ( j + k < numThornLevels )
r *= shrinkFactor;
}
double leafWidth = r * width;
if ( 2.0 * M_PI / step > 32 )
leafWidth = 16;
const double origin = north / 180.0 * M_PI;
for ( double angle = origin;
angle < 2.0 * M_PI + origin; angle += step)
{
const QPoint p = qwtPolar2Pos(center, r, angle);
QPoint p1 = qwtPolar2Pos(center, leafWidth, angle + M_PI_2);
QPoint p2 = qwtPolar2Pos(center, leafWidth, angle - M_PI_2);
QwtPolygon pa(3);
pa.setPoint(0, center);
pa.setPoint(1, p);
QPoint p3 = qwtPolar2Pos(center, r, angle + step / 2.0);
p1 = cutPoint(center, p3, p1, p);
pa.setPoint(2, p1);
#if QT_VERSION < 0x040000
painter->setBrush(cg.brush(QColorGroup::Dark));
#else
painter->setBrush(palette.brush(QPalette::Dark));
#endif
painter->drawPolygon(pa);
QPoint p4 = qwtPolar2Pos(center, r, angle - step / 2.0);
p2 = cutPoint(center, p4, p2, p);
pa.setPoint(2, p2);
#if QT_VERSION < 0x040000
painter->setBrush(cg.brush(QColorGroup::Light));
#else
painter->setBrush(palette.brush(QPalette::Light));
#endif
painter->drawPolygon(pa);
}
}
painter->restore();
}
| int QwtSimpleCompassRose::numThornLevels | ( | ) | const |
Definition at line 278 of file qwt_compass_rose.cpp.
Referenced by drawRose(), and setNumThornLevels().
{
return d_numThornLevels;
}
| int QwtSimpleCompassRose::numThorns | ( | ) | const |
Definition at line 258 of file qwt_compass_rose.cpp.
Referenced by setNumThorns().
{
return d_numThorns;
}
| void QwtSimpleCompassRose::setNumThornLevels | ( | int | numThornLevels ) |
Set the of thorns levels
| numThornLevels | Number of thorns levels |
Definition at line 269 of file qwt_compass_rose.cpp.
References numThornLevels().
{
d_numThornLevels = numThornLevels;
}
| void QwtSimpleCompassRose::setNumThorns | ( | int | numThorns ) |
Set the number of thorns on one level The number is aligned to a multiple of 4, with a minimum of 4
| numThorns | Number of thorns |
Definition at line 243 of file qwt_compass_rose.cpp.
References numThorns().
| void QwtSimpleCompassRose::setShrinkFactor | ( | double | factor ) | [inline] |
Definition at line 68 of file qwt_compass_rose.h.
{ d_shrinkFactor = factor; }
| void QwtSimpleCompassRose::setWidth | ( | double | width ) |
Set the width of the rose heads. Lower value make thinner heads. The range is limited from 0.03 to 0.4.
| width | Width |
Definition at line 226 of file qwt_compass_rose.cpp.
References width().
{
d_width = width;
if (d_width < 0.03)
d_width = 0.03;
if (d_width > 0.4)
d_width = 0.4;
}
| double QwtSimpleCompassRose::shrinkFactor | ( | ) | const [inline] |
Definition at line 69 of file qwt_compass_rose.h.
Referenced by drawRose().
{ return d_shrinkFactor; }
| double QwtSimpleCompassRose::width | ( | ) | const [inline] |
Definition at line 60 of file qwt_compass_rose.h.
Referenced by drawRose(), and setWidth().
{ return d_width; }
1.7.2