2 #include "routines.hpp"
3 #include "../widgets/QcSlider.h"
10 QRect
Slider::sc_groove ( const QStyleOption
*opt
, const QcSlider
* )
12 return sunkenContentsRect(opt
->rect
);
15 QRect
Slider::sc_handle ( const QStyleOptionSlider
*opt
, const QcSlider
*s
)
17 QRect
contRect( sunkenContentsRect(opt
->rect
) );
19 double valRange
= opt
->maximum
- opt
->minimum
;
20 double val
= valRange
> 0.0 ? (opt
->sliderPosition
- opt
->minimum
) / valRange
: 0.0;
22 int len
= s
->handleLength();
25 if( opt
->orientation
== Qt::Horizontal
) {
26 int pos
= val
* (contRect
.width() - len
);
27 r
.setX( pos
+ contRect
.left() );
28 r
.setY( contRect
.top() );
29 r
.setSize( QSize( len
, contRect
.height() ) );
32 int pos
= val
* (contRect
.height() - len
);
33 r
.setX( contRect
.left() );
34 r
.setY( contRect
.bottom() - pos
- len
+ 1 );
35 r
.setSize( QSize( contRect
.width(), len
) );
40 void Slider::cc_draw ( const QStyleOptionSlider
*opt
, QPainter
*p
, const QcSlider
*slider
)
42 using QtCollider::Style::Ellipse
;
43 using QtCollider::Style::RoundRect
;
45 const QPalette
&plt
= opt
->palette
;
48 p
->setRenderHint( QPainter::Antialiasing
, true );
50 QRect rGroove
= opt
->rect
;
53 RoundRect
shGroove( rGroove
, 2 );
55 QColor
baseColor( slider
->grooveColor() );
57 if( opt
->state
& QStyle::State_HasFocus
)
58 focusColor
= slider
->focusColor();
60 drawSunken( p
, plt
, shGroove
, baseColor
, focusColor
);
63 QRect
rHandle( sc_handle( opt
, slider
) );
66 RoundRect
shHandle( rHandle
, 2 );
67 drawRaised( p
, plt
, shHandle
, plt
.color(QPalette::Button
).lighter(105) );
72 QPen
pen(plt
.color(QPalette::ButtonText
));
75 if(opt
->orientation
== Qt::Horizontal
) {
76 qreal center
= rHandle
.center().x() + 1;
77 QLine
line( center
, rHandle
.top() + 3, center
, rHandle
.bottom() - 2 );
79 pen
.setColor(plt
.color(QPalette::Light
));
81 qreal center
= rHandle
.center().y() + 1;
82 QLine
line( rHandle
.left() + 3, center
, rHandle
.right() - 2, center
);
84 pen
.setColor(plt
.color(QPalette::Light
));
89 } // namespace QtCollider