scide: implement selectionLength for openDocument
[supercollider.git] / QtCollider / style / slider_style.cpp
blob2236f0971abdc143ca24fab9b6ef469f7da1820b
1 #include "style.hpp"
2 #include "routines.hpp"
3 #include "../widgets/QcSlider.h"
5 #include <QPainter>
7 namespace QtCollider {
8 namespace Style {
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();
24 QRect r;
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() ) );
31 else {
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 ) );
37 return r;
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;
47 p->save();
48 p->setRenderHint( QPainter::Antialiasing, true );
50 QRect rGroove = opt->rect;
52 // draw groove
53 RoundRect shGroove( rGroove, 2 );
55 QColor baseColor( slider->grooveColor() );
56 QColor focusColor;
57 if( opt->state & QStyle::State_HasFocus )
58 focusColor = slider->focusColor();
60 drawSunken( p, plt, shGroove, baseColor, focusColor );
62 // geometry
63 QRect rHandle( sc_handle( opt, slider ) );
65 // draw handle
66 RoundRect shHandle( rHandle, 2 );
67 drawRaised( p, plt, shHandle, plt.color(QPalette::Button).lighter(105) );
69 p->restore();
71 // draw marker
72 QPen pen(plt.color(QPalette::ButtonText));
73 pen.setWidth(2);
74 p->setPen(pen);
75 if(opt->orientation == Qt::Horizontal) {
76 qreal center = rHandle.center().x() + 1;
77 QLine line( center, rHandle.top() + 3, center, rHandle.bottom() - 2 );
78 p->drawLine(line);
79 pen.setColor(plt.color(QPalette::Light));
80 } else {
81 qreal center = rHandle.center().y() + 1;
82 QLine line( rHandle.left() + 3, center, rHandle.right() - 2, center );
83 p->drawLine(line);
84 pen.setColor(plt.color(QPalette::Light));
88 } // namespace Style
89 } // namespace QtCollider