1 | /* Mpcgui for SMPlayer.
|
---|
2 | Copyright (C) 2008 matt_ <matt@endboss.org>
|
---|
3 |
|
---|
4 | This program is free software; you can redistribute it and/or modify
|
---|
5 | it under the terms of the GNU General Public License as published by
|
---|
6 | the Free Software Foundation; either version 2 of the License, or
|
---|
7 | (at your option) any later version.
|
---|
8 |
|
---|
9 | This program is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | GNU General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU General Public License
|
---|
15 | along with this program; if not, write to the Free Software
|
---|
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "mpcstyles.h"
|
---|
20 |
|
---|
21 | #include <QProxyStyle>
|
---|
22 | #include <QStyleOptionToolBar>
|
---|
23 | #include <QSlider>
|
---|
24 | #include <QPainter>
|
---|
25 | #include <qdrawutil.h>
|
---|
26 |
|
---|
27 | void
|
---|
28 | MpcToolbarStyle::drawControl(ControlElement control, const QStyleOption *option,
|
---|
29 | QPainter *painter, const QWidget *widget) const
|
---|
30 | {
|
---|
31 | if(control == CE_ToolBar)
|
---|
32 | {
|
---|
33 | if (const QStyleOptionToolBar *toolbar = qstyleoption_cast<const QStyleOptionToolBar *>(option)) {
|
---|
34 | QRect rect = option->rect;
|
---|
35 |
|
---|
36 | if( toolbar->toolBarArea == Qt::BottomToolBarArea &&
|
---|
37 | toolbar->positionOfLine == QStyleOptionToolBar::End )
|
---|
38 | {
|
---|
39 | painter->setPen(QPen(option->palette.light().color()));
|
---|
40 | painter->drawLine(rect.topLeft().x(),
|
---|
41 | rect.topLeft().y(),
|
---|
42 | rect.topRight().x(),
|
---|
43 | rect.topRight().y());
|
---|
44 |
|
---|
45 | painter->setPen(QPen(option->palette.light().color()));
|
---|
46 | painter->drawLine(rect.topLeft().x(),
|
---|
47 | rect.topLeft().y(),
|
---|
48 | rect.bottomLeft().x(),
|
---|
49 | rect.bottomLeft().y());
|
---|
50 |
|
---|
51 | painter->setPen(QPen(option->palette.dark().color()));
|
---|
52 | painter->drawLine(rect.topRight().x(),
|
---|
53 | rect.topRight().y(),
|
---|
54 | rect.bottomRight().x(),
|
---|
55 | rect.bottomRight().y());
|
---|
56 |
|
---|
57 | }
|
---|
58 | else if( toolbar->toolBarArea == Qt::BottomToolBarArea &&
|
---|
59 | toolbar->positionOfLine == QStyleOptionToolBar::Beginning )
|
---|
60 | {
|
---|
61 | painter->setPen(QPen(option->palette.light().color()));
|
---|
62 | painter->drawLine(rect.topLeft().x(),
|
---|
63 | rect.topLeft().y(),
|
---|
64 | rect.bottomLeft().x(),
|
---|
65 | rect.bottomLeft().y());
|
---|
66 |
|
---|
67 | painter->setPen(QPen(option->palette.dark().color()));
|
---|
68 | painter->drawLine(rect.topRight().x(),
|
---|
69 | rect.topRight().y(),
|
---|
70 | rect.bottomRight().x(),
|
---|
71 | rect.bottomRight().y());
|
---|
72 |
|
---|
73 | painter->setPen(QPen(option->palette.dark().color()));
|
---|
74 | painter->drawLine(rect.bottomLeft().x(),
|
---|
75 | rect.bottomLeft().y(),
|
---|
76 | rect.bottomRight().x(),
|
---|
77 | rect.bottomRight().y());
|
---|
78 | }
|
---|
79 | else
|
---|
80 | {
|
---|
81 | QProxyStyle::drawControl(control,toolbar, painter, widget);
|
---|
82 | }
|
---|
83 | }
|
---|
84 | }
|
---|
85 | else
|
---|
86 | {
|
---|
87 | QProxyStyle::drawControl(control,option, painter, widget);
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | // draw custom slider + handle for volume widget
|
---|
92 | void MpcVolumeSlideStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
|
---|
93 | QPainter *p, const QWidget *widget) const
|
---|
94 | {
|
---|
95 | if( cc == CC_Slider )
|
---|
96 | {
|
---|
97 | if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
|
---|
98 | QRect groove = subControlRect(CC_Slider, slider, SC_SliderGroove, widget);
|
---|
99 | QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, widget);
|
---|
100 |
|
---|
101 | if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {
|
---|
102 |
|
---|
103 | p->setPen(slider->palette.shadow().color());
|
---|
104 | if (slider->orientation == Qt::Horizontal) {
|
---|
105 | static QPoint points[3] = {
|
---|
106 | QPoint(groove.x() , groove.y() + slider->rect.height() ),
|
---|
107 | QPoint(groove.x() + groove.width() -2 , groove.y() + slider->rect.height() ),
|
---|
108 | QPoint(groove.x() + groove.width() -2 , groove.y() ),
|
---|
109 | };
|
---|
110 | QPen oldPen = p->pen();
|
---|
111 |
|
---|
112 | p->setPen(slider->palette.dark().color());
|
---|
113 | p->drawLine(QPoint(points[0].x(), points[0].y() -2 ),QPoint(points[2].x(), points[2].y()));
|
---|
114 |
|
---|
115 | QPoint b[3] = { QPoint(points[0].x(),points[0].y()-1), QPoint(points[1].x()-1, points[1].y()-1), QPoint(points[2].x()-1,points[2].y()) };
|
---|
116 | p->setPen(slider->palette.light().color());
|
---|
117 | p->drawPolyline(b, 3);
|
---|
118 | p->setPen(oldPen);
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 |
|
---|
123 | if (slider->subControls & SC_SliderTickmarks) {
|
---|
124 | QStyleOptionSlider tmpSlider = *slider;
|
---|
125 | tmpSlider.subControls = SC_SliderTickmarks;
|
---|
126 | QCommonStyle::drawComplexControl(cc, &tmpSlider, p, widget);
|
---|
127 | }
|
---|
128 |
|
---|
129 | if (slider->subControls & SC_SliderHandle) {
|
---|
130 | /*
|
---|
131 | const QColor c0 = slider->palette.shadow().color();
|
---|
132 | const QColor c1 = slider->palette.dark().color();
|
---|
133 | // const QColor c2 = g.button();
|
---|
134 | const QColor c3 = slider->palette.midlight().color();
|
---|
135 | const QColor c4 = slider->palette.light().color();
|
---|
136 | */
|
---|
137 | QBrush handleBrush;
|
---|
138 |
|
---|
139 | if (slider->state & State_Enabled) {
|
---|
140 | handleBrush = slider->palette.color(QPalette::Button);
|
---|
141 | } else {
|
---|
142 | handleBrush = QBrush(slider->palette.color(QPalette::Button),
|
---|
143 | Qt::Dense4Pattern);
|
---|
144 | }
|
---|
145 |
|
---|
146 |
|
---|
147 | int x = handle.x() , y = handle.y(),
|
---|
148 | wi = handle.width() - 2, he = slider->rect.height();
|
---|
149 |
|
---|
150 | if (slider->state & State_HasFocus) {
|
---|
151 | QStyleOptionFocusRect fropt;
|
---|
152 | fropt.QStyleOption::operator=(*slider);
|
---|
153 | fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
|
---|
154 | drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
|
---|
155 | }
|
---|
156 |
|
---|
157 | Qt::BGMode oldMode = p->backgroundMode();
|
---|
158 | p->setBackgroundMode(Qt::OpaqueMode);
|
---|
159 | qDrawWinButton(p, QRect(x, y, wi, he), slider->palette, false,
|
---|
160 | &handleBrush);
|
---|
161 | p->setBackgroundMode(oldMode);
|
---|
162 |
|
---|
163 | }
|
---|
164 | }
|
---|
165 | }
|
---|
166 | else
|
---|
167 | {
|
---|
168 | QProxyStyle::drawComplexControl(cc,opt,p,widget);
|
---|
169 | }
|
---|
170 | }
|
---|
171 |
|
---|
172 | // draw custom slider + handle for timeslide widget
|
---|
173 | void MpcTimeSlideStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
|
---|
174 | QPainter *p, const QWidget *widget) const
|
---|
175 | {
|
---|
176 | if( cc == CC_Slider )
|
---|
177 | {
|
---|
178 | if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
|
---|
179 | QRect groove = subControlRect(CC_Slider, slider, SC_SliderGroove, widget);
|
---|
180 | QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, widget);
|
---|
181 |
|
---|
182 | if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {
|
---|
183 | if (slider->orientation == Qt::Horizontal) {
|
---|
184 | int x = groove.x() + 2;
|
---|
185 | int y = slider->rect.height() / 2 - 4;
|
---|
186 | int w = groove.width() - 4;
|
---|
187 | int h = 7;
|
---|
188 | qDrawShadeRect (p,x,y,w,h, slider->palette, true,1,0,
|
---|
189 | &slider->palette.brush(QPalette::Light));
|
---|
190 | }
|
---|
191 | }
|
---|
192 |
|
---|
193 |
|
---|
194 | if (slider->subControls & SC_SliderTickmarks) {
|
---|
195 | QStyleOptionSlider tmpSlider = *slider;
|
---|
196 | tmpSlider.subControls = SC_SliderTickmarks;
|
---|
197 | QCommonStyle::drawComplexControl(cc, &tmpSlider, p, widget);
|
---|
198 | }
|
---|
199 |
|
---|
200 | if (slider->subControls & SC_SliderHandle) {
|
---|
201 | /*
|
---|
202 | const QColor c0 = slider->palette.shadow().color();
|
---|
203 | const QColor c1 = slider->palette.dark().color();
|
---|
204 | // const QColor c2 = g.button();
|
---|
205 | const QColor c3 = slider->palette.midlight().color();
|
---|
206 | const QColor c4 = slider->palette.light().color();
|
---|
207 | */
|
---|
208 | QBrush handleBrush;
|
---|
209 |
|
---|
210 | if (slider->state & State_Enabled) {
|
---|
211 | handleBrush = slider->palette.color(QPalette::Button);
|
---|
212 | } else {
|
---|
213 | handleBrush = QBrush(slider->palette.color(QPalette::Button),
|
---|
214 | Qt::Dense4Pattern);
|
---|
215 | }
|
---|
216 |
|
---|
217 |
|
---|
218 | int x = handle.x() , y = handle.y() + 1,
|
---|
219 | wi = 13, he = 14;
|
---|
220 |
|
---|
221 | if (slider->state & State_HasFocus) {
|
---|
222 | QStyleOptionFocusRect fropt;
|
---|
223 | fropt.QStyleOption::operator=(*slider);
|
---|
224 | fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
|
---|
225 | drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
|
---|
226 | }
|
---|
227 |
|
---|
228 | Qt::BGMode oldMode = p->backgroundMode();
|
---|
229 | p->setBackgroundMode(Qt::OpaqueMode);
|
---|
230 | qDrawWinPanel(p, QRect(x, y, wi, he), slider->palette, false,
|
---|
231 | &handleBrush);
|
---|
232 | qDrawShadeRect (p, QRect(x+2,y+3, wi-4, he-6), slider->palette, true,1,0,
|
---|
233 | &slider->palette.brush(QPalette::Light));
|
---|
234 | p->setBackgroundMode(oldMode);
|
---|
235 | }
|
---|
236 | }
|
---|
237 | }
|
---|
238 | else
|
---|
239 | {
|
---|
240 | QProxyStyle::drawComplexControl(cc,opt,p,widget);
|
---|
241 | }
|
---|
242 | }
|
---|
243 |
|
---|
244 | #include "moc_mpcstyles.cpp"
|
---|