/
style.cpp
86 lines (71 loc) · 2.49 KB
/
style.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "style.hpp"
#include "routines.hpp"
#include "../widgets/QcSlider.h"
using namespace QtCollider::Style;
void StyleImpl::polish ( QPalette & p )
{
_colors[Focus] = p.color(QPalette::Highlight);
_colors[Groove] = p.color(QPalette::Window).darker(120);
}
void StyleImpl::drawControl ( ControlElement elem, const QStyleOption * option,
QPainter * p, const QWidget * w ) const
{
if( elem == CE_PushButton ) {
p->save();
p->setRenderHint( QPainter::Antialiasing, true );
const QStyleOptionButton *opt = static_cast<const QStyleOptionButton*>(option);
const QPalette &plt = opt->palette;
bool sunken = opt->state & State_Sunken || opt->state & State_On;
int radius = 2;
QColor color( sunken ? plt.color(QPalette::Button).darker(120) : plt.color(QPalette::Button) );
QColor focusColor( opt->state & State_HasFocus ? _colors[Focus] : QColor() );
RoundRect frame( opt->rect, radius );
if( sunken )
drawSunken( p, plt, frame, color, focusColor);
else
drawRaised( p, plt, frame, color, focusColor );
if( !opt->text.isEmpty() )
drawItemText( p, opt->rect, Qt::AlignCenter, plt, opt->state & State_Enabled, opt->text, QPalette::ButtonText );
p->restore();
}
else {
ProxyStyle::drawControl( elem, option, p, w );
}
}
void StyleImpl::drawComplexControl ( QStyle::ComplexControl cc, const QStyleOptionComplex * option,
QPainter *p, const QWidget *w ) const
{
switch( (int) cc ) {
case CC_Slider: {
const QcSlider *slider = qobject_cast<const QcSlider*>(w);
if(!slider) break;
Slider::cc_draw( static_cast<const QStyleOptionSlider*>(option), p, slider );
return;
}
default:
break;
}
ProxyStyle::drawComplexControl( cc, option, p, w );
}
QRect StyleImpl::subControlRect ( QStyle::ComplexControl cc, const QStyleOptionComplex *option,
QStyle::SubControl sc, const QWidget *w ) const
{
int iCC = cc;
switch(iCC) {
case CC_Slider:
{
const QcSlider *slider = qobject_cast<const QcSlider*>(w);
if(!slider) break;
const QStyleOptionSlider *opt = static_cast<const QStyleOptionSlider*>(option);
switch( sc ) {
case SC_SliderHandle: return Slider::sc_handle( opt, slider );
case SC_SliderGroove: return Slider::sc_groove( opt, slider );
default: ;
}
break;
}
default:
break;
}
return QProxyStyle::subControlRect ( cc, option, sc, w );
}