2008-08-13 16:47:27 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2008 Fredrik Höglund <fredrik@kde.org>
|
2008-10-12 01:28:20 +02:00
|
|
|
* Copyright © 2008 Marco Martin <notmart@gmail.com>
|
2008-08-13 16:47:27 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "style.h"
|
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QStyleOptionComplex>
|
|
|
|
|
|
|
|
#include <KDebug>
|
|
|
|
|
|
|
|
#include <plasma/panelsvg.h>
|
|
|
|
|
|
|
|
namespace Plasma {
|
|
|
|
|
2008-10-12 01:28:20 +02:00
|
|
|
class StylePrivate
|
|
|
|
{
|
2008-08-13 16:47:27 +02:00
|
|
|
public:
|
|
|
|
StylePrivate()
|
|
|
|
: scrollbar(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~StylePrivate()
|
|
|
|
{
|
|
|
|
}
|
2008-10-12 01:28:20 +02:00
|
|
|
|
2008-08-13 16:47:27 +02:00
|
|
|
Plasma::PanelSvg *scrollbar;
|
|
|
|
};
|
|
|
|
|
|
|
|
Style::Style()
|
|
|
|
: QCommonStyle(),
|
|
|
|
d(new StylePrivate)
|
|
|
|
{
|
|
|
|
d->scrollbar = new Plasma::PanelSvg(this);
|
|
|
|
d->scrollbar->setImagePath("widgets/scrollbar");
|
|
|
|
d->scrollbar->setCacheAllRenderedPanels(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
Style::~Style()
|
|
|
|
{
|
2008-08-14 08:39:58 +02:00
|
|
|
delete d;
|
2008-08-13 16:47:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Style::drawComplexControl(ComplexControl control,
|
|
|
|
const QStyleOptionComplex *option,
|
|
|
|
QPainter *painter,
|
|
|
|
const QWidget *widget) const
|
|
|
|
{
|
|
|
|
if (control != CC_ScrollBar) {
|
|
|
|
QCommonStyle::drawComplexControl(control, option, painter, widget);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
painter->save();
|
|
|
|
painter->setRenderHint(QPainter::Antialiasing);
|
|
|
|
|
2008-10-12 01:28:20 +02:00
|
|
|
const bool sunken = option->state & State_Sunken;
|
2008-08-13 16:47:27 +02:00
|
|
|
const QStyleOptionSlider *scrollOption = qstyleoption_cast<const QStyleOptionSlider *>(option);
|
2008-08-21 22:15:32 +02:00
|
|
|
QString prefix;
|
|
|
|
|
|
|
|
if (option->state & State_MouseOver) {
|
|
|
|
prefix= "mouseover-";
|
|
|
|
}
|
2008-08-13 16:47:27 +02:00
|
|
|
|
|
|
|
QRect subLine;
|
|
|
|
QRect addLine;
|
|
|
|
if (scrollOption && scrollOption->orientation == Qt::Horizontal) {
|
2008-08-21 22:15:32 +02:00
|
|
|
subLine = d->scrollbar->elementRect(prefix + "arrow-left").toRect();
|
|
|
|
addLine = d->scrollbar->elementRect(prefix + "arrow-right").toRect();
|
2008-08-13 16:47:27 +02:00
|
|
|
} else {
|
2008-08-21 22:15:32 +02:00
|
|
|
subLine = d->scrollbar->elementRect(prefix + "arrow-up").toRect();
|
|
|
|
addLine = d->scrollbar->elementRect(prefix + "arrow-down").toRect();
|
2008-08-13 16:47:27 +02:00
|
|
|
}
|
2008-08-21 22:15:32 +02:00
|
|
|
|
2008-08-13 16:47:27 +02:00
|
|
|
subLine.moveCenter(subControlRect(control, option, SC_ScrollBarSubLine, widget).center());
|
|
|
|
addLine.moveCenter(subControlRect(control, option, SC_ScrollBarAddLine, widget).center());
|
2008-08-21 22:15:32 +02:00
|
|
|
|
2008-10-12 01:28:20 +02:00
|
|
|
const QRect slider =
|
|
|
|
subControlRect(control, option, SC_ScrollBarSlider, widget).adjusted(1, 0, -1, 0);
|
2008-08-13 16:47:27 +02:00
|
|
|
|
|
|
|
d->scrollbar->setElementPrefix("background");
|
|
|
|
d->scrollbar->resizePanel(option->rect.size());
|
|
|
|
d->scrollbar->paintPanel(painter);
|
2008-08-21 22:15:32 +02:00
|
|
|
|
2008-09-24 23:55:37 +02:00
|
|
|
if (sunken && scrollOption && scrollOption->activeSubControls & SC_ScrollBarSlider) {
|
2008-08-21 22:15:32 +02:00
|
|
|
d->scrollbar->setElementPrefix("sunken-slider");
|
|
|
|
} else {
|
|
|
|
d->scrollbar->setElementPrefix(prefix + "slider");
|
|
|
|
}
|
|
|
|
|
2008-08-13 16:47:27 +02:00
|
|
|
d->scrollbar->resizePanel(slider.size());
|
|
|
|
d->scrollbar->paintPanel(painter, slider.topLeft());
|
|
|
|
|
|
|
|
if (scrollOption && scrollOption->orientation == Qt::Horizontal) {
|
2008-08-21 22:15:32 +02:00
|
|
|
if (sunken && scrollOption->activeSubControls & SC_ScrollBarAddLine) {
|
2008-10-17 20:42:44 +02:00
|
|
|
d->scrollbar->paint(painter, addLine, "sunken-arrow-right");
|
2008-08-21 22:15:32 +02:00
|
|
|
} else {
|
2008-10-17 20:42:44 +02:00
|
|
|
d->scrollbar->paint(painter, addLine, prefix + "arrow-right");
|
2008-08-21 22:15:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sunken && scrollOption->activeSubControls & SC_ScrollBarSubLine) {
|
2008-10-17 20:42:44 +02:00
|
|
|
d->scrollbar->paint(painter, subLine, "sunken-arrow-left");
|
2008-08-21 22:15:32 +02:00
|
|
|
} else {
|
2008-10-17 20:42:44 +02:00
|
|
|
d->scrollbar->paint(painter, subLine, prefix + "arrow-left");
|
2008-08-21 22:15:32 +02:00
|
|
|
}
|
2008-08-13 16:47:27 +02:00
|
|
|
} else {
|
2008-09-24 23:55:37 +02:00
|
|
|
if (sunken && scrollOption && scrollOption->activeSubControls & SC_ScrollBarAddLine) {
|
2008-10-17 20:42:44 +02:00
|
|
|
d->scrollbar->paint(painter, addLine, "sunken-arrow-down");
|
2008-08-21 22:15:32 +02:00
|
|
|
} else {
|
2008-10-17 20:42:44 +02:00
|
|
|
d->scrollbar->paint(painter, addLine, prefix + "arrow-down");
|
2008-08-21 22:15:32 +02:00
|
|
|
}
|
|
|
|
|
2008-09-24 23:55:37 +02:00
|
|
|
if (sunken && scrollOption && scrollOption->activeSubControls & SC_ScrollBarSubLine) {
|
2008-10-17 20:42:44 +02:00
|
|
|
d->scrollbar->paint(painter, subLine, "sunken-arrow-up");
|
2008-08-21 22:15:32 +02:00
|
|
|
} else {
|
2008-10-17 20:42:44 +02:00
|
|
|
d->scrollbar->paint(painter, subLine, prefix + "arrow-up");
|
2008-08-21 22:15:32 +02:00
|
|
|
}
|
2008-08-13 16:47:27 +02:00
|
|
|
}
|
2008-08-21 22:15:32 +02:00
|
|
|
|
2008-08-13 16:47:27 +02:00
|
|
|
painter->restore();
|
|
|
|
}
|
|
|
|
|
2008-08-13 22:21:06 +02:00
|
|
|
}
|
2008-08-13 16:47:27 +02:00
|
|
|
|