14 #include <qapplication.h> 17 #if QT_VERSION < 0x040601 18 #define qFastSin(x) qSin(x) 19 #define qFastCos(x) qCos(x) 23 const QPalette &palette, QPalette::ColorGroup colorGroup,
26 const double r[] = { 0.4, 0.3, 1, 0.8, 1, 0.3, 0.4 };
27 const double a[] = { -45, -20, -15, 0, 15, 20, 45 };
30 for (
int i = 0;
i < 7;
i++ )
32 const double angle = a[
i] / 180.0 * M_PI;
33 const double radius = r[
i] * length;
35 const double x = radius *
qFastCos( angle );
36 const double y = radius *
qFastSin( angle );
41 painter->setPen( Qt::NoPen );
42 painter->setBrush( palette.brush( colorGroup, QPalette::Light ) );
43 painter->drawPath( path );
47 const QPalette &palette, QPalette::ColorGroup colorGroup,
double length )
49 const double ratioX = 0.7;
50 const double ratioY = 0.3;
53 path1.lineTo( ratioX * length, 0.0 );
54 path1.lineTo( length, ratioY * length );
57 path2.lineTo( ratioX * length, 0.0 );
58 path2.lineTo( length, -ratioY * length );
60 painter->setPen( Qt::NoPen );
62 painter->setBrush( palette.brush( colorGroup, QPalette::Light ) );
63 painter->drawPath( path1 );
65 painter->setBrush( palette.brush( colorGroup, QPalette::Dark ) );
66 painter->drawPath( path2 );
70 const QColor &lightColor,
const QColor &darkColor,
71 double length,
double width )
73 const double peak = qMax( length / 10.0, 5.0 );
75 const double knobWidth = width + 8;
76 QRectF knobRect( 0, 0, knobWidth, knobWidth );
77 knobRect.moveCenter( QPointF(0, 0) );
80 path1.lineTo( 0.0, 0.5 * width );
81 path1.lineTo( length - peak, 0.5 * width );
82 path1.lineTo( length, 0.0 );
83 path1.lineTo( 0.0, 0.0 );
85 QPainterPath arcPath1;
86 arcPath1.arcTo( knobRect, 0.0, -90.0 );
88 path1 = path1.united( arcPath1 );
91 path2.lineTo( 0.0, -0.5 * width );
92 path2.lineTo( length - peak, -0.5 * width );
93 path2.lineTo( length, 0.0 );
94 path2.lineTo( 0.0, 0.0 );
96 QPainterPath arcPath2;
97 arcPath2.arcTo( knobRect, 0.0, 90.0 );
99 path2 = path2.united( arcPath2 );
101 painter->setPen( Qt::NoPen );
103 painter->setBrush( lightColor );
104 painter->drawPath( path1 );
106 painter->setBrush( darkColor );
107 painter->drawPath( path2 );
111 const QPalette &palette, QPalette::ColorGroup colorGroup,
112 double length,
double width )
115 width = qMax( length * 0.06, 9.0 );
117 const double peak = qMax( 2.0, 0.4 * width );
120 path.moveTo( 0.0, 0.5 * width );
121 path.lineTo( length - peak, 0.3 * width );
122 path.lineTo( length, 0.0 );
123 path.lineTo( length - peak, -0.3 * width );
124 path.lineTo( 0.0, -0.5 * width );
126 QRectF br = path.boundingRect();
128 QPalette pal( palette.color( QPalette::Mid ) );
129 QColor c1 = pal.color( QPalette::Light );
130 QColor c2 = pal.color( QPalette::Dark );
132 QLinearGradient gradient( br.topLeft(), br.bottomLeft() );
133 gradient.setColorAt( 0.0, c1 );
134 gradient.setColorAt( 0.5, c1 );
135 gradient.setColorAt( 0.5001, c2 );
136 gradient.setColorAt( 1.0, c2 );
138 QPen pen( gradient, 1 );
139 pen.setJoinStyle( Qt::MiterJoin );
141 painter->setPen( pen );
142 painter->setBrush( palette.brush( colorGroup, QPalette::Mid ) );
144 painter->drawPath( path );
148 const QPalette &palette, QPalette::ColorGroup colorGroup,
151 const double width = qRound( length / 3.0 );
153 QPainterPath
path[4];
155 path[0].lineTo( length, 0.0 );
156 path[0].lineTo( 0.0, width / 2 );
158 path[1].lineTo( length, 0.0 );
159 path[1].lineTo( 0.0, -width / 2 );
161 path[2].lineTo( -length, 0.0 );
162 path[2].lineTo( 0.0, width / 2 );
164 path[3].lineTo( -length, 0.0 );
165 path[3].lineTo( 0.0, -width / 2 );
168 const int colorOffset = 10;
169 const QColor darkColor = palette.color( colorGroup, QPalette::Dark );
170 const QColor lightColor = palette.color( colorGroup, QPalette::Light );
173 color[0] = darkColor.light( 100 + colorOffset );
174 color[1] = darkColor.dark( 100 + colorOffset );
175 color[2] = lightColor.light( 100 + colorOffset );
176 color[3] = lightColor.dark( 100 + colorOffset );
178 painter->setPen( Qt::NoPen );
180 for (
int i = 0;
i < 4;
i++ )
182 painter->setBrush( color[
i] );
183 painter->drawPath( path[i] );
189 d_palette( QApplication::palette() )
226 const QPointF ¢er,
double length,
double direction,
227 QPalette::ColorGroup colorGroup )
const 231 painter->translate( center );
232 painter->rotate( -direction );
241 double width,
const QBrush &brush,
bool sunken )
const 243 QPalette
palette( brush.color() );
245 QColor c1 =
palette.color( QPalette::Light );
246 QColor c2 =
palette.color( QPalette::Dark );
251 QRectF rect( 0.0, 0.0, width, width );
252 rect.moveCenter( painter->combinedTransform().map( QPointF() ) );
254 QLinearGradient gradient( rect.topLeft(), rect.bottomRight() );
255 gradient.setColorAt( 0.0, c1 );
256 gradient.setColorAt( 0.3, c1 );
257 gradient.setColorAt( 0.7, c2 );
258 gradient.setColorAt( 1.0, c2 );
262 painter->resetTransform();
264 painter->setPen( QPen( gradient, 1 ) );
265 painter->setBrush( brush );
266 painter->drawEllipse( rect );
280 const QColor &mid,
const QColor &base ):
282 d_hasKnob( hasKnob ),
286 palette.setColor( QPalette::Mid, mid );
287 palette.setColor( QPalette::Base, base );
319 double length, QPalette::ColorGroup colorGroup )
const 321 double knobWidth = 0.0;
327 width = qMax(length * 0.06, 6.0);
330 palette(), colorGroup, length, width );
332 knobWidth = qMin( width * 2.0, 0.2 * length );
339 QPen pen (
palette().brush( colorGroup, QPalette::Mid ), width );
340 pen.setCapStyle( Qt::FlatCap );
342 painter->setPen( pen );
343 painter->drawLine( QPointF( 0.0, 0.0 ), QPointF( length, 0.0 ) );
345 knobWidth = qMax( width * 3.0, 5.0 );
351 palette().brush( colorGroup, QPalette::Base ),
false );
357 const QColor &light,
const QColor &dark ):
361 palette.setColor( QPalette::Light, light );
362 palette.setColor( QPalette::Dark, dark );
363 palette.setColor( QPalette::Base, Qt::gray );
376 double length, QPalette::ColorGroup colorGroup )
const 380 const double width = qMax( length / 6.0, 3.0 );
382 const int colorOffset = 10;
384 const QColor light =
palette().color( colorGroup, QPalette::Light );
385 const QColor dark =
palette().color( colorGroup, QPalette::Dark );
388 dark.light( 100 + colorOffset ),
389 dark.dark( 100 + colorOffset ),
392 painter->rotate( 180.0 );
395 light.light( 100 + colorOffset ),
396 light.dark( 100 + colorOffset ),
399 const QBrush baseBrush =
palette().brush( colorGroup, QPalette::Base );
400 drawKnob( painter, width, baseBrush,
true );
416 const QColor &light,
const QColor &dark ):
420 palette.setColor( QPalette::Light, light );
421 palette.setColor( QPalette::Dark, dark );
434 double length, QPalette::ColorGroup colorGroup )
const
static void qwtDrawArrowNeedle(QPainter *painter, const QPalette &palette, QPalette::ColorGroup colorGroup, double length, double width)
static void qwtDrawShadedPointer(QPainter *painter, const QColor &lightColor, const QColor &darkColor, double length, double width)
virtual void setPalette(const QPalette &)
virtual ~QwtDialNeedle()
Destructor.
virtual void drawNeedle(QPainter *, double length, QPalette::ColorGroup) const
TFSIMD_FORCE_INLINE const tfScalar & y() const
QwtDialSimpleNeedle(Style, bool hasKnob=true, const QColor &mid=Qt::gray, const QColor &base=Qt::darkGray)
Style
Style of the needle.
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
static void qwtDrawStyle1Needle(QPainter *painter, const QPalette &palette, QPalette::ColorGroup colorGroup, double length)
Style
Style of the needle.
virtual void drawKnob(QPainter *, double width, const QBrush &, bool sunken) const
Draw the knob.
virtual void drawNeedle(QPainter *, double length, QPalette::ColorGroup) const
virtual void drawNeedle(QPainter *painter, double length, QPalette::ColorGroup colorGroup) const =0
Draw the needle.
GraphId path[kMaxDeadlockPathLen]
virtual void drawNeedle(QPainter *, double length, QPalette::ColorGroup) const
const QPalette & palette() const
A needle pointing to the center.
TFSIMD_FORCE_INLINE const tfScalar & x() const
static void qwtDrawTriangleNeedle(QPainter *painter, const QPalette &palette, QPalette::ColorGroup colorGroup, double length)
void setWidth(double width)
QwtDialNeedle()
Constructor.
virtual void draw(QPainter *painter, const QPointF ¢er, double length, double direction, QPalette::ColorGroup=QPalette::Active) const
QwtCompassWindArrow(Style, const QColor &light=Qt::white, const QColor &dark=Qt::gray)
QwtCompassMagnetNeedle(Style=TriangleStyle, const QColor &light=Qt::white, const QColor &dark=Qt::red)
Constructor.
static void qwtDrawStyle2Needle(QPainter *painter, const QPalette &palette, QPalette::ColorGroup colorGroup, double length)