svg themed scrollbars:
scrollbar widget in libplasma private qstyle that draws scrollbars with svg folderview uses the scrollbar widget textview scrollbars themed svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=846473
This commit is contained in:
parent
ab28f7685b
commit
76d6071e46
@ -47,6 +47,7 @@ set(plasma_LIB_SRCS
|
||||
private/nativetabbar.cpp
|
||||
private/packages.cpp
|
||||
private/paneltoolbox.cpp
|
||||
private/style.cpp
|
||||
private/toolbox.cpp
|
||||
private/tooltip.cpp
|
||||
querymatch.cpp
|
||||
@ -76,6 +77,7 @@ set(plasma_LIB_SRCS
|
||||
widgets/meter.cpp
|
||||
widgets/pushbutton.cpp
|
||||
widgets/radiobutton.cpp
|
||||
widgets/scrollbar.cpp
|
||||
widgets/signalplotter.cpp
|
||||
widgets/slider.cpp
|
||||
widgets/tabbar.cpp
|
||||
@ -181,6 +183,7 @@ install(FILES
|
||||
widgets/meter.h
|
||||
widgets/pushbutton.h
|
||||
widgets/radiobutton.h
|
||||
widgets/scrollbar.h
|
||||
widgets/signalplotter.h
|
||||
widgets/slider.h
|
||||
widgets/tabbar.h
|
||||
@ -236,6 +239,7 @@ includes/RunnerContext
|
||||
includes/RunnerManager
|
||||
includes/RunnerScript
|
||||
includes/ScriptEngine
|
||||
includes/ScrollBar
|
||||
includes/Service
|
||||
includes/ServiceJob
|
||||
includes/SignalPlotter
|
||||
|
109
private/style.cpp
Normal file
109
private/style.cpp
Normal file
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright © 2008 Fredrik Höglund <fredrik@kde.org>
|
||||
* Copyright © 2008 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* 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 {
|
||||
|
||||
class StylePrivate {
|
||||
public:
|
||||
StylePrivate()
|
||||
: scrollbar(0)
|
||||
{
|
||||
}
|
||||
|
||||
~StylePrivate()
|
||||
{
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
const QStyleOptionSlider *scrollOption = qstyleoption_cast<const QStyleOptionSlider *>(option);
|
||||
|
||||
QRect subLine;
|
||||
QRect addLine;
|
||||
if (scrollOption && scrollOption->orientation == Qt::Horizontal) {
|
||||
subLine = d->scrollbar->elementRect("arrow-left").toRect();
|
||||
addLine = d->scrollbar->elementRect("arrow-right").toRect();
|
||||
} else {
|
||||
subLine = d->scrollbar->elementRect("arrow-up").toRect();
|
||||
addLine = d->scrollbar->elementRect("arrow-down").toRect();
|
||||
}
|
||||
|
||||
subLine.moveCenter(subControlRect(control, option, SC_ScrollBarSubLine, widget).center());
|
||||
addLine.moveCenter(subControlRect(control, option, SC_ScrollBarAddLine, widget).center());
|
||||
|
||||
const QRect slider = subControlRect(control, option, SC_ScrollBarSlider, widget).adjusted(1, 0, -1, 0);
|
||||
|
||||
d->scrollbar->setElementPrefix("background");
|
||||
d->scrollbar->resizePanel(option->rect.size());
|
||||
d->scrollbar->paintPanel(painter);
|
||||
|
||||
d->scrollbar->setElementPrefix("slider");
|
||||
d->scrollbar->resizePanel(slider.size());
|
||||
d->scrollbar->paintPanel(painter, slider.topLeft());
|
||||
|
||||
if (scrollOption && scrollOption->orientation == Qt::Horizontal) {
|
||||
d->scrollbar->paint(painter, addLine.topLeft(), "arrow-left");
|
||||
d->scrollbar->paint(painter, subLine.topLeft(), "arrow-right");
|
||||
} else {
|
||||
d->scrollbar->paint(painter, addLine.topLeft(), "arrow-down");
|
||||
d->scrollbar->paint(painter, subLine.topLeft(), "arrow-up");
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
};
|
||||
|
51
private/style.h
Normal file
51
private/style.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright © 2008 Fredrik Höglund <fredrik@kde.org>
|
||||
* Copyright © 2008 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PLASMA_STYLE_H
|
||||
#define PLASMA_STYLE_H
|
||||
|
||||
#include <QtGui/QCommonStyle>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class StylePrivate;
|
||||
|
||||
class Style : public QCommonStyle
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Style();
|
||||
~Style();
|
||||
|
||||
protected:
|
||||
void drawComplexControl(ComplexControl control,
|
||||
const QStyleOptionComplex *option,
|
||||
QPainter *painter,
|
||||
const QWidget *widget) const;
|
||||
private:
|
||||
StylePrivate *d;
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#endif // multiple inclusion guard
|
94
widgets/scrollbar.cpp
Normal file
94
widgets/scrollbar.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright © 2008 Fredrik Höglund <fredrik@kde.org>
|
||||
* Copyright © 2008 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* 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 "scrollbar.h"
|
||||
|
||||
#include <plasma/private/style.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
ScrollBar::ScrollBar(Qt::Orientation orientation, QGraphicsWidget *parent)
|
||||
: QGraphicsProxyWidget(parent)
|
||||
{
|
||||
QScrollBar *scrollbar = new QScrollBar(orientation);
|
||||
scrollbar->setAttribute(Qt::WA_NoSystemBackground);
|
||||
setWidget(scrollbar);
|
||||
Plasma::Style *style = new Plasma::Style();
|
||||
scrollbar->setStyle(style);
|
||||
}
|
||||
|
||||
ScrollBar::~ScrollBar()
|
||||
{
|
||||
}
|
||||
|
||||
void ScrollBar::setRange(int min, int max)
|
||||
{
|
||||
static_cast<QScrollBar*>(widget())->setRange(min, max);
|
||||
}
|
||||
|
||||
void ScrollBar::setSingleStep(int val)
|
||||
{
|
||||
static_cast<QScrollBar*>(widget())->setSingleStep(val);
|
||||
}
|
||||
|
||||
void ScrollBar::setPageStep(int val)
|
||||
{
|
||||
static_cast<QScrollBar*>(widget())->setPageStep(val);
|
||||
}
|
||||
|
||||
void ScrollBar::setValue(int val)
|
||||
{
|
||||
static_cast<QScrollBar*>(widget())->setValue(val);
|
||||
}
|
||||
|
||||
int ScrollBar::value() const
|
||||
{
|
||||
return static_cast<QScrollBar*>(widget())->value();
|
||||
}
|
||||
|
||||
int ScrollBar::minimum() const
|
||||
{
|
||||
return static_cast<QScrollBar*>(widget())->minimum();
|
||||
}
|
||||
|
||||
int ScrollBar::maximum() const
|
||||
{
|
||||
return static_cast<QScrollBar*>(widget())->maximum();
|
||||
}
|
||||
|
||||
void ScrollBar::setStyleSheet(const QString &stylesheet)
|
||||
{
|
||||
widget()->setStyleSheet(stylesheet);
|
||||
}
|
||||
|
||||
QString ScrollBar::styleSheet()
|
||||
{
|
||||
return widget()->styleSheet();
|
||||
}
|
||||
|
||||
QScrollBar *ScrollBar::nativeWidget() const
|
||||
{
|
||||
return static_cast<QScrollBar*>(widget());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#include <scrollbar.moc>
|
48
widgets/scrollbar.h
Normal file
48
widgets/scrollbar.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright © 2008 Fredrik Höglund <fredrik@kde.org>
|
||||
* Copyright © 2008 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* 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 <QScrollBar>
|
||||
#include <QGraphicsProxyWidget>
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
// Wraps a QScrollBar in a QGraphicsProxyWidget
|
||||
class PLASMA_EXPORT ScrollBar : public QGraphicsProxyWidget
|
||||
{
|
||||
public:
|
||||
explicit ScrollBar(Qt::Orientation orientation, QGraphicsWidget *parent);
|
||||
~ScrollBar();
|
||||
|
||||
void setRange(int min, int max);
|
||||
void setSingleStep(int val);
|
||||
void setPageStep(int val);
|
||||
void setValue(int val);
|
||||
int value() const;
|
||||
int minimum() const;
|
||||
int maximum() const;
|
||||
void setStyleSheet(const QString &stylesheet);
|
||||
QString styleSheet();
|
||||
QScrollBar *nativeWidget() const;
|
||||
};
|
||||
|
||||
};
|
@ -29,6 +29,8 @@
|
||||
#include <KDebug>
|
||||
|
||||
#include <plasma/animator.h>
|
||||
#include <plasma/panelsvg.h>
|
||||
#include <plasma/theme.h>
|
||||
|
||||
#include "private/nativetabbar_p.h"
|
||||
|
||||
@ -53,11 +55,13 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void syncBorders();
|
||||
void slidingCompleted(QGraphicsItem *item);
|
||||
void shapeChanged(const QTabBar::Shape shape);
|
||||
|
||||
TabBar *q;
|
||||
NativeTabBar *tabBar;
|
||||
PanelSvg *background;
|
||||
QList<QGraphicsWidget *> pages;
|
||||
QGraphicsLinearLayout *mainLayout;
|
||||
QGraphicsLinearLayout *tabBarLayout;
|
||||
@ -69,6 +73,15 @@ public:
|
||||
int newPageAnimId;
|
||||
};
|
||||
|
||||
void TabBarPrivate::syncBorders()
|
||||
{
|
||||
//set margins from the normal element
|
||||
qreal left, top, right, bottom;
|
||||
|
||||
background->getMargins(left, top, right, bottom);
|
||||
|
||||
q->setContentsMargins(left, top, right, bottom);
|
||||
}
|
||||
|
||||
void TabBarPrivate::slidingCompleted(QGraphicsItem *item)
|
||||
{
|
||||
@ -132,6 +145,13 @@ TabBar::TabBar(QGraphicsWidget *parent)
|
||||
d->tabBarLayout->addItem(tabProxy);
|
||||
d->tabBarLayout->addStretch();
|
||||
|
||||
//background painting stuff
|
||||
d->background = new Plasma::PanelSvg(this);
|
||||
d->background->setImagePath("widgets/frame");
|
||||
d->background->setElementPrefix("sunken");
|
||||
|
||||
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(syncBorders()));
|
||||
|
||||
connect(d->tabBar, SIGNAL(currentChanged(int)), this, SLOT(setCurrentIndex(int)));
|
||||
connect(d->tabBar, SIGNAL(shapeChanged(QTabBar::Shape)), this, SLOT(shapeChanged(QTabBar::Shape)));
|
||||
connect(Plasma::Animator::self(), SIGNAL(movementFinished(QGraphicsItem*)), this, SLOT(slidingCompleted(QGraphicsItem*)));
|
||||
@ -316,6 +336,21 @@ QTabBar *TabBar::nativeWidget() const
|
||||
return d->tabBar;
|
||||
}
|
||||
|
||||
void TabBar::paint(QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option)
|
||||
Q_UNUSED(widget)
|
||||
|
||||
d->background->paintPanel(painter, QPoint(contentsRect().left(), contentsRect().top() + nativeWidget()->height()/1.5));
|
||||
}
|
||||
|
||||
void TabBar::resizeEvent(QGraphicsSceneResizeEvent *event)
|
||||
{
|
||||
d->background->resizePanel(event->newSize() - QSize(0, nativeWidget()->height()/2));
|
||||
}
|
||||
|
||||
void TabBar::wheelEvent(QGraphicsSceneWheelEvent * event)
|
||||
{
|
||||
//FIXME: probably this would make more sense in NativeTabBar, but it works only here
|
||||
|
@ -187,11 +187,16 @@ Q_SIGNALS:
|
||||
void currentChanged(int index);
|
||||
|
||||
protected:
|
||||
void paint(QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget);
|
||||
void resizeEvent(QGraphicsSceneResizeEvent *event);
|
||||
void wheelEvent(QGraphicsSceneWheelEvent *event);
|
||||
|
||||
private:
|
||||
TabBarPrivate * const d;
|
||||
|
||||
Q_PRIVATE_SLOT(d, void syncBorders())
|
||||
Q_PRIVATE_SLOT(d, void slidingCompleted(QGraphicsItem *item))
|
||||
Q_PRIVATE_SLOT(d, void shapeChanged(const QTabBar::Shape shape))
|
||||
};
|
||||
|
@ -21,11 +21,13 @@
|
||||
|
||||
#include <KTextEdit>
|
||||
#include <QPainter>
|
||||
#include <QScrollBar>
|
||||
|
||||
#include <KMimeType>
|
||||
|
||||
#include "theme.h"
|
||||
#include "svg.h"
|
||||
#include "private/style.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
@ -50,6 +52,9 @@ TextEdit::TextEdit(QGraphicsWidget *parent)
|
||||
connect(native, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
|
||||
setWidget(native);
|
||||
native->setAttribute(Qt::WA_NoSystemBackground);
|
||||
Plasma::Style *style = new Plasma::Style();
|
||||
native->verticalScrollBar()->setStyle(style);
|
||||
native->horizontalScrollBar()->setStyle(style);
|
||||
}
|
||||
|
||||
TextEdit::~TextEdit()
|
||||
|
Loading…
Reference in New Issue
Block a user