1 #ifndef QC_STYLE_ROUTINES_H
2 #define QC_STYLE_ROUTINES_H
10 namespace ReliefType
{
16 using namespace ReliefType
;
22 struct RightRoundRect
;
24 struct BottomRoundRect
;
27 using namespace ShapeType
;
31 template<typename Shape
>
32 void drawShape( QPainter
*, const QRect
& );
34 template<typename Shape
>
35 void drawShape( QPainter
*, const QRect
&, qreal param1
);
38 void drawShape
<Rect
> ( QPainter
*p
, const QRect
&r
)
44 void drawShape
<Ellipse
> ( QPainter
*p
, const QRect
&r
)
50 void drawShape
<RoundRect
> ( QPainter
*p
, const QRect
&r
, qreal radius
)
52 p
->drawRoundedRect( r
, radius
, radius
, Qt::RelativeSize
);
57 template<typename ShapeT
> struct Shape
59 template<typename RectT
> void draw();
65 Rect( QRectF rect
) : _rect(rect
) {}
66 template<typename RectT
> inline void draw( QPainter
* p
, const RectT
&r
) const {
74 RoundRect( QRectF rect
, qreal radius
) : _rect(rect
), _radius(radius
) {}
75 template<typename RectT
> inline void draw( QPainter
* p
, const RectT
&r
) const {
76 p
->drawRoundedRect(r
, _radius
, _radius
, Qt::AbsoluteSize
);
84 Ellipse( QRectF rect
) : _rect(rect
) {}
85 template<typename RectT
> inline void draw( QPainter
* p
, const RectT
&r
) const {
91 template<typename ShapeT
> void drawRaised (QPainter
*p
, const QPalette
&plt
, const ShapeT
&shape
,
92 const QColor
&color
, const QColor
&focusColor
= QColor())
96 bool focus
= focusColor
.isValid();
98 QRectF
r( shape
._rect
);
100 p
->setBrush(Qt::NoBrush
);
107 pen
.setColor(focusColor
);
109 shape
.draw( p
, r
.adjusted(1,1,-1,-1) );
118 QColor
edgeClr( focus
? plt
.color(QPalette::Light
) : plt
.color(QPalette::Dark
) );
119 if(focus
) edgeClr
.setAlpha(100);
120 else edgeClr
.setAlpha( color
.alpha() );
121 pen
.setColor(edgeClr
);
127 double pos
= shape
._rect
.height();
128 pos
= (pos
- 3) / pos
;
130 QLinearGradient
lgrad( shape
._rect
.topLeft(), shape
._rect
.bottomLeft() );
131 lgrad
.setColorAt( 0, color
.lighter(110) );
132 lgrad
.setColorAt( pos
, color
.darker(105) );
133 lgrad
.setColorAt( 1, color
.darker(115) );
135 p
->setPen(Qt::NoPen
);
136 p
->setBrush( QBrush(lgrad
) );
142 template<typename ShapeT
> void drawSunken (QPainter
*p
, const QPalette
&plt
, const ShapeT
&shape
,
143 const QColor
&color
, const QColor
&focusColor
= QColor())
152 QColor c
= focusColor
.isValid() ? focusColor
: plt
.color(QPalette::Window
).lighter(105);
155 p
->setBrush(Qt::NoBrush
);
156 shape
.draw( p
, shape
._rect
.adjusted(1,1,-1,-1) );
160 QColor
c1( plt
.color(QPalette::Shadow
) );
164 p
->setBrush(Qt::NoBrush
);
165 shape
.draw( p
, shape
._rect
.adjusted(2,2,-2,-2) );
169 QColor c2
=color
; c2
.setAlpha(150);
170 p
->setPen(Qt::NoPen
);
172 shape
.draw( p
, shape
._rect
.adjusted(2,2,-2,-2) );
177 shape
.draw( p
, shape
._rect
.adjusted(2,3,-2,-2) );
182 template<typename RectT
> RectT
sunkenContentsRect ( const RectT
& r
)
184 return r
.adjusted(1, 1,-1,-1 );
187 template<typename RectT
>
188 qreal
xValue ( qreal x
, const RectT
& bounds
)
190 return (x
- bounds
.x()) / bounds
.width();
193 template<typename RectT
>
194 qreal
yValue ( qreal y
, const RectT
& bounds
)
196 return (bounds
.y() + bounds
.height() - y
) / bounds
.height();
199 template<typename RectT
, typename SizeT
>
200 qreal
xValue ( qreal x
, const RectT
& bounds
, const SizeT
& margin
)
202 return margin
.width() < bounds
.width() ?
203 (x
- bounds
.x() - (margin
.width() * 0.5)) /
204 (bounds
.width() - margin
.width())
208 template<typename RectT
, typename SizeT
>
209 qreal
yValue ( qreal y
, const RectT
& bounds
, const SizeT
& margin
)
211 return margin
.height() < bounds
.height() ?
212 (bounds
.y() + bounds
.height() - y
- (margin
.height() * 0.5)) /
213 (bounds
.height() - margin
.height())
217 template<typename RectT
, typename PointT
>
218 QPointF
value ( const PointT
& pos
, const RectT
& bounds
)
220 return QPointF( xValue(pos
.x(), bounds
), yValue(pos
.y(), bounds
) );
223 template<typename RectT
, typename SizeT
, typename PointT
>
224 QPointF
value ( const PointT
& pos
, const RectT
& bounds
, const SizeT
& margin
)
226 return QPointF( xValue(pos
.x(), bounds
, margin
), yValue(pos
.y(), bounds
, margin
) );
229 template<typename RectT
, typename SizeT
>
230 RectT
marginsRect ( const RectT
& bounds
, const SizeT
& margin
)
233 r
.setSize( SizeT( qMax((qreal
)bounds
.width() - margin
.width(), qreal(0.0)),
234 qMax((qreal
)bounds
.height() - margin
.height(), qreal(0.0)) ) );
235 r
.moveCenter( bounds
.center() );
239 template<typename RectT
, typename SizeT
>
240 RectT
rect ( const QPointF
& value
, const RectT
& bounds
, const SizeT
& size
)
242 qreal x
= value
.x() * (bounds
.width() - size
.width()) + bounds
.left();
243 qreal y
= bounds
.top() + bounds
.height() - size
.height() - value
.y() * (bounds
.height() - size
.height());
244 return RectT( x
, y
, size
.width(), size
.height() );
247 template<typename RectT
, typename SizeT
>
248 QPointF
pos ( const QPointF
& value
, const RectT
& bounds
, const SizeT
& margin
)
250 qreal x
= value
.x() * (bounds
.width() - margin
.width()) + bounds
.left() + margin
.x() * 0.5;
251 qreal y
= - value
.y() * (bounds
.height() - margin
.height()) + bounds
.top() + bounds
.height() - margin
.y() * 0.5;
255 template<typename RectT
>
256 QPointF
pos ( const QPointF
& value
, const RectT
& bounds
)
258 qreal x
= value
.x() * bounds
.width() + bounds
.left();
259 qreal y
= - value
.y() * bounds
.height() + bounds
.top() + bounds
.height();
263 } // namespace QtCollider