13 #include <qapplication.h>
15 #include <qpainterpath.h>
19 const QPalette& palette, QPalette::ColorGroup colorGroup, qreal length )
21 const qreal r[] = { 0.4, 0.3, 1, 0.8, 1, 0.3, 0.4 };
22 const qreal a[] = { -45, -20, -15, 0, 15, 20, 45 };
25 for (
int i = 0; i < 7; i++ )
27 const qreal angle = a[i] / 180.0 *
M_PI;
28 const qreal radius = r[i] * length;
30 const qreal
x = radius * qFastCos( angle );
31 const qreal
y = radius * qFastSin( angle );
36 painter->setPen( Qt::NoPen );
37 painter->setBrush( palette.brush( colorGroup, QPalette::Light ) );
38 painter->drawPath( path );
42 const QPalette& palette, QPalette::ColorGroup colorGroup, qreal length )
44 const qreal ratioX = 0.7;
45 const qreal ratioY = 0.3;
48 path1.lineTo( ratioX * length, 0.0 );
49 path1.lineTo( length, ratioY * length );
52 path2.lineTo( ratioX * length, 0.0 );
53 path2.lineTo( length, -ratioY * length );
55 painter->setPen( Qt::NoPen );
57 painter->setBrush( palette.brush( colorGroup, QPalette::Light ) );
58 painter->drawPath( path1 );
60 painter->setBrush( palette.brush( colorGroup, QPalette::Dark ) );
61 painter->drawPath( path2 );
65 const QColor& lightColor,
const QColor& darkColor,
66 qreal length, qreal width )
68 const qreal peak =
qwtMaxF( length / 10.0, 5.0 );
70 const qreal knobWidth = width + 8;
71 QRectF knobRect( 0, 0, knobWidth, knobWidth );
72 knobRect.moveCenter( QPointF(0, 0) );
75 path1.lineTo( 0.0, 0.5 * width );
76 path1.lineTo( length - peak, 0.5 * width );
77 path1.lineTo( length, 0.0 );
78 path1.lineTo( 0.0, 0.0 );
80 QPainterPath arcPath1;
81 arcPath1.arcTo( knobRect, 0.0, -90.0 );
83 path1 = path1.united( arcPath1 );
86 path2.lineTo( 0.0, -0.5 * width );
87 path2.lineTo( length - peak, -0.5 * width );
88 path2.lineTo( length, 0.0 );
89 path2.lineTo( 0.0, 0.0 );
91 QPainterPath arcPath2;
92 arcPath2.arcTo( knobRect, 0.0, 90.0 );
94 path2 = path2.united( arcPath2 );
96 painter->setPen( Qt::NoPen );
98 painter->setBrush( lightColor );
99 painter->drawPath( path1 );
101 painter->setBrush( darkColor );
102 painter->drawPath( path2 );
106 const QPalette& palette, QPalette::ColorGroup colorGroup,
107 qreal length, qreal width )
110 width =
qwtMaxF( length * 0.06, 9.0 );
112 const qreal peak =
qwtMaxF( 2.0, 0.4 * width );
115 path.moveTo( 0.0, 0.5 * width );
116 path.lineTo( length - peak, 0.3 * width );
117 path.lineTo( length, 0.0 );
118 path.lineTo( length - peak, -0.3 * width );
119 path.lineTo( 0.0, -0.5 * width );
121 QRectF br = path.boundingRect();
123 QPalette pal( palette.color( QPalette::Mid ) );
124 QColor c1 = pal.color( QPalette::Light );
125 QColor c2 = pal.color( QPalette::Dark );
127 QLinearGradient gradient( br.topLeft(), br.bottomLeft() );
128 gradient.setColorAt( 0.0, c1 );
129 gradient.setColorAt( 0.5, c1 );
130 gradient.setColorAt( 0.5001, c2 );
131 gradient.setColorAt( 1.0, c2 );
133 QPen pen( gradient, 1 );
134 pen.setJoinStyle( Qt::MiterJoin );
136 painter->setPen( pen );
137 painter->setBrush( palette.brush( colorGroup, QPalette::Mid ) );
139 painter->drawPath( path );
143 const QPalette& palette, QPalette::ColorGroup colorGroup, qreal length )
145 const qreal width = qRound( length / 3.0 );
147 QPainterPath path[4];
149 path[0].lineTo( length, 0.0 );
150 path[0].lineTo( 0.0, width / 2 );
152 path[1].lineTo( length, 0.0 );
153 path[1].lineTo( 0.0, -width / 2 );
155 path[2].lineTo( -length, 0.0 );
156 path[2].lineTo( 0.0, width / 2 );
158 path[3].lineTo( -length, 0.0 );
159 path[3].lineTo( 0.0, -width / 2 );
162 const int colorOffset = 10;
163 const QColor darkColor = palette.color( colorGroup, QPalette::Dark );
164 const QColor lightColor = palette.color( colorGroup, QPalette::Light );
167 color[0] = darkColor.lighter( 100 + colorOffset );
168 color[1] = darkColor.darker( 100 + colorOffset );
169 color[2] = lightColor.lighter( 100 + colorOffset );
170 color[3] = lightColor.darker( 100 + colorOffset );
172 painter->setPen( Qt::NoPen );
174 for (
int i = 0; i < 4; i++ )
176 painter->setBrush(
color[i] );
177 painter->drawPath( path[i] );
183 : m_palette( QApplication::palette() )
220 const QPointF& center,
double length,
double direction,
221 QPalette::ColorGroup colorGroup )
const
225 painter->translate( center );
226 painter->rotate( -direction );
235 double width,
const QBrush& brush,
bool sunken )
const
237 QPalette
palette( brush.color() );
239 QColor c1 =
palette.color( QPalette::Light );
240 QColor c2 =
palette.color( QPalette::Dark );
245 QRectF rect( 0.0, 0.0, width, width );
246 rect.moveCenter( painter->transform().map( QPointF() ) );
248 QLinearGradient gradient( rect.topLeft(), rect.bottomRight() );
249 gradient.setColorAt( 0.0, c1 );
250 gradient.setColorAt( 0.3, c1 );
251 gradient.setColorAt( 0.7, c2 );
252 gradient.setColorAt( 1.0, c2 );
256 painter->resetTransform();
258 painter->setPen( QPen( gradient, 1 ) );
259 painter->setBrush( brush );
260 painter->drawEllipse( rect );
274 const QColor& mid,
const QColor& base ):
276 m_hasKnob( hasKnob ),
280 palette.setColor( QPalette::Mid, mid );
281 palette.setColor( QPalette::Base, base );
313 double length, QPalette::ColorGroup colorGroup )
const
315 qreal knobWidth = 0.0;
333 QPen pen (
palette().brush( colorGroup, QPalette::Mid ),
width );
334 pen.setCapStyle( Qt::FlatCap );
336 painter->setPen( pen );
337 painter->drawLine( QPointF( 0.0, 0.0 ), QPointF( length, 0.0 ) );
345 palette().brush( colorGroup, QPalette::Base ),
false );
351 const QColor& light,
const QColor& dark ):
355 palette.setColor( QPalette::Light, light );
356 palette.setColor( QPalette::Dark, dark );
357 palette.setColor( QPalette::Base, Qt::gray );
370 double length, QPalette::ColorGroup colorGroup )
const
374 const qreal width =
qwtMaxF( length / 6.0, 3.0 );
376 const int colorOffset = 10;
378 const QColor light =
palette().color( colorGroup, QPalette::Light );
379 const QColor dark =
palette().color( colorGroup, QPalette::Dark );
382 dark.lighter( 100 + colorOffset ),
383 dark.darker( 100 + colorOffset ),
386 painter->rotate( 180.0 );
389 light.lighter( 100 + colorOffset ),
390 light.darker( 100 + colorOffset ),
393 const QBrush baseBrush =
palette().brush( colorGroup, QPalette::Base );
394 drawKnob( painter, width, baseBrush,
true );
410 const QColor& light,
const QColor& dark ):
414 palette.setColor( QPalette::Light, light );
415 palette.setColor( QPalette::Dark, dark );
428 double length, QPalette::ColorGroup colorGroup )
const