| 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 <QWindowsStyle>
|
|---|
| 22 | #include <QStyleOptionToolBar>
|
|---|
| 23 | #include <QSlider>
|
|---|
| 24 | #include <QPainter>
|
|---|
| 25 |
|
|---|
| 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 | QWindowsStyle::drawControl(control,toolbar, painter, widget);
|
|---|
| 82 | }
|
|---|
| 83 | }
|
|---|
| 84 | }
|
|---|
| 85 | else
|
|---|
| 86 | {
|
|---|
| 87 | QWindowsStyle::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 | const QColor c0 = slider->palette.shadow().color();
|
|---|
| 131 | const QColor c1 = slider->palette.dark().color();
|
|---|
| 132 | // const QColor c2 = g.button();
|
|---|
| 133 | const QColor c3 = slider->palette.midlight().color();
|
|---|
| 134 | const QColor c4 = slider->palette.light().color();
|
|---|
| 135 | QBrush handleBrush;
|
|---|
| 136 |
|
|---|
| 137 | if (slider->state & State_Enabled) {
|
|---|
| 138 | handleBrush = slider->palette.color(QPalette::Button);
|
|---|
| 139 | } else {
|
|---|
| 140 | handleBrush = QBrush(slider->palette.color(QPalette::Button),
|
|---|
| 141 | Qt::Dense4Pattern);
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 | int x = handle.x() , y = handle.y(),
|
|---|
| 146 | wi = handle.width() - 2, he = slider->rect.height();
|
|---|
| 147 |
|
|---|
| 148 | if (slider->state & State_HasFocus) {
|
|---|
| 149 | QStyleOptionFocusRect fropt;
|
|---|
| 150 | fropt.QStyleOption::operator=(*slider);
|
|---|
| 151 | fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
|
|---|
| 152 | drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | Qt::BGMode oldMode = p->backgroundMode();
|
|---|
| 156 | p->setBackgroundMode(Qt::OpaqueMode);
|
|---|
| 157 | qDrawWinButton(p, QRect(x, y, wi, he), slider->palette, false,
|
|---|
| 158 | &handleBrush);
|
|---|
| 159 | p->setBackgroundMode(oldMode);
|
|---|
| 160 |
|
|---|
| 161 | }
|
|---|
| 162 | }
|
|---|
| 163 | }
|
|---|
| 164 | else
|
|---|
| 165 | {
|
|---|
| 166 | QWindowsStyle::drawComplexControl(cc,opt,p,widget);
|
|---|
| 167 | }
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | // draw custom slider + handle for timeslide widget
|
|---|
| 171 | void MpcTimeSlideStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
|
|---|
| 172 | QPainter *p, const QWidget *widget) const
|
|---|
| 173 | {
|
|---|
| 174 | if( cc == CC_Slider )
|
|---|
| 175 | {
|
|---|
| 176 | if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
|
|---|
| 177 | QRect groove = subControlRect(CC_Slider, slider, SC_SliderGroove, widget);
|
|---|
| 178 | QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, widget);
|
|---|
| 179 |
|
|---|
| 180 | if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {
|
|---|
| 181 | if (slider->orientation == Qt::Horizontal) {
|
|---|
| 182 | int x = groove.x() + 2;
|
|---|
| 183 | int y = slider->rect.height() / 2 - 4;
|
|---|
| 184 | int w = groove.width() - 4;
|
|---|
| 185 | int h = 7;
|
|---|
| 186 | qDrawShadeRect (p,x,y,w,h, slider->palette, true,1,0,
|
|---|
| 187 | &slider->palette.brush(QPalette::Light));
|
|---|
| 188 | }
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 | if (slider->subControls & SC_SliderTickmarks) {
|
|---|
| 193 | QStyleOptionSlider tmpSlider = *slider;
|
|---|
| 194 | tmpSlider.subControls = SC_SliderTickmarks;
|
|---|
| 195 | QCommonStyle::drawComplexControl(cc, &tmpSlider, p, widget);
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | if (slider->subControls & SC_SliderHandle) {
|
|---|
| 199 | const QColor c0 = slider->palette.shadow().color();
|
|---|
| 200 | const QColor c1 = slider->palette.dark().color();
|
|---|
| 201 | // const QColor c2 = g.button();
|
|---|
| 202 | const QColor c3 = slider->palette.midlight().color();
|
|---|
| 203 | const QColor c4 = slider->palette.light().color();
|
|---|
| 204 | QBrush handleBrush;
|
|---|
| 205 |
|
|---|
| 206 | if (slider->state & State_Enabled) {
|
|---|
| 207 | handleBrush = slider->palette.color(QPalette::Button);
|
|---|
| 208 | } else {
|
|---|
| 209 | handleBrush = QBrush(slider->palette.color(QPalette::Button),
|
|---|
| 210 | Qt::Dense4Pattern);
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 | int x = handle.x() , y = handle.y() + 1,
|
|---|
| 215 | wi = 13, he = 14;
|
|---|
| 216 |
|
|---|
| 217 | if (slider->state & State_HasFocus) {
|
|---|
| 218 | QStyleOptionFocusRect fropt;
|
|---|
| 219 | fropt.QStyleOption::operator=(*slider);
|
|---|
| 220 | fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
|
|---|
| 221 | drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | Qt::BGMode oldMode = p->backgroundMode();
|
|---|
| 225 | p->setBackgroundMode(Qt::OpaqueMode);
|
|---|
| 226 | qDrawWinPanel(p, QRect(x, y, wi, he), slider->palette, false,
|
|---|
| 227 | &handleBrush);
|
|---|
| 228 | qDrawShadeRect (p, QRect(x+2,y+3, wi-4, he-6), slider->palette, true,1,0,
|
|---|
| 229 | &slider->palette.brush(QPalette::Light));
|
|---|
| 230 | p->setBackgroundMode(oldMode);
|
|---|
| 231 | }
|
|---|
| 232 | }
|
|---|
| 233 | }
|
|---|
| 234 | else
|
|---|
| 235 | {
|
|---|
| 236 | QWindowsStyle::drawComplexControl(cc,opt,p,widget);
|
|---|
| 237 | }
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|