style the tabbar scroll buttons with plasma colors
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=868202
This commit is contained in:
parent
06e71be8c3
commit
0dc100928d
@ -30,6 +30,8 @@
|
|||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QStyleOption>
|
||||||
|
#include <QToolButton>
|
||||||
|
|
||||||
#include <QGradient>
|
#include <QGradient>
|
||||||
#include <QLinearGradient>
|
#include <QLinearGradient>
|
||||||
@ -38,6 +40,9 @@
|
|||||||
#include "plasma/theme.h"
|
#include "plasma/theme.h"
|
||||||
#include "plasma/animator.h"
|
#include "plasma/animator.h"
|
||||||
#include "plasma/panelsvg.h"
|
#include "plasma/panelsvg.h"
|
||||||
|
#include "plasma/paintutils.h"
|
||||||
|
|
||||||
|
#include "private/style.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
@ -265,6 +270,44 @@ void NativeTabBar::paintEvent(QPaintEvent *event)
|
|||||||
|
|
||||||
painter.drawText(textRect, Qt::AlignCenter | Qt::TextHideMnemonic, tabText(i));
|
painter.drawText(textRect, Qt::AlignCenter | Qt::TextHideMnemonic, tabText(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRect scrollButtonsRect;
|
||||||
|
foreach (QObject *child, children()) {
|
||||||
|
QToolButton *childWidget = qobject_cast<QToolButton *>(child);
|
||||||
|
if (childWidget) {
|
||||||
|
if (!childWidget->isVisible()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scrollButtonsRect.isValid()) {
|
||||||
|
scrollButtonsRect = scrollButtonsRect.united(childWidget->geometry());
|
||||||
|
} else {
|
||||||
|
scrollButtonsRect = childWidget->geometry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scrollButtonsRect.isValid()) {
|
||||||
|
scrollButtonsRect.adjust(2, 4, -2, -4);
|
||||||
|
painter.save();
|
||||||
|
|
||||||
|
QColor background(Plasma::Theme::defaultTheme()->color(Theme::BackgroundColor));
|
||||||
|
background.setAlphaF(0.75);
|
||||||
|
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
painter.fillPath(PaintUtils::roundedRectangle(scrollButtonsRect, 5), background);
|
||||||
|
painter.restore();
|
||||||
|
|
||||||
|
QStyleOption so;
|
||||||
|
so.initFrom(this);
|
||||||
|
so.palette.setColor(QPalette::ButtonText, Plasma::Theme::defaultTheme()->color(Theme::TextColor));
|
||||||
|
|
||||||
|
so.rect = scrollButtonsRect.adjusted(0, 0, -scrollButtonsRect.width()/2, 0);
|
||||||
|
style()->drawPrimitive(QStyle::PE_IndicatorArrowLeft, &so, &painter, this);
|
||||||
|
|
||||||
|
so.rect = scrollButtonsRect.adjusted(scrollButtonsRect.width()/2, 0, 0, 0);
|
||||||
|
style()->drawPrimitive(QStyle::PE_IndicatorArrowRight, &so, &painter, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeTabBar::resizeEvent(QResizeEvent* event)
|
void NativeTabBar::resizeEvent(QResizeEvent* event)
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
#include <QGraphicsProxyWidget>
|
#include <QGraphicsProxyWidget>
|
||||||
#include <QGraphicsSceneWheelEvent>
|
#include <QGraphicsSceneWheelEvent>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
#include <QStyleOption>
|
||||||
|
#include <QPainter>
|
||||||
#include <KDebug>
|
#include <KDebug>
|
||||||
|
|
||||||
#include <plasma/animator.h>
|
#include <plasma/animator.h>
|
||||||
@ -35,12 +37,37 @@
|
|||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class TabBarProxy : public QGraphicsProxyWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TabBarProxy(QGraphicsWidget *parent)
|
||||||
|
: QGraphicsProxyWidget(parent)
|
||||||
|
{
|
||||||
|
native = new NativeTabBar();
|
||||||
|
native->setAttribute(Qt::WA_NoSystemBackground);
|
||||||
|
setWidget(native);
|
||||||
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||||
|
}
|
||||||
|
|
||||||
|
void paint(QPainter *painter,
|
||||||
|
const QStyleOptionGraphicsItem *option,
|
||||||
|
QWidget *widget)
|
||||||
|
{
|
||||||
|
Q_UNUSED(option)
|
||||||
|
Q_UNUSED(widget)
|
||||||
|
//Don't paint the child widgets
|
||||||
|
static_cast<NativeTabBar *>(QGraphicsProxyWidget::widget())->render(painter, QPoint(0,0), QRegion(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
NativeTabBar *native;
|
||||||
|
};
|
||||||
|
|
||||||
class TabBarPrivate
|
class TabBarPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TabBarPrivate(TabBar *parent)
|
TabBarPrivate(TabBar *parent)
|
||||||
: q(parent),
|
: q(parent),
|
||||||
tabBar(0),
|
tabProxy(0),
|
||||||
currentIndex(0),
|
currentIndex(0),
|
||||||
oldPage(0),
|
oldPage(0),
|
||||||
newPage(0),
|
newPage(0),
|
||||||
@ -58,8 +85,7 @@ public:
|
|||||||
void shapeChanged(const QTabBar::Shape shape);
|
void shapeChanged(const QTabBar::Shape shape);
|
||||||
|
|
||||||
TabBar *q;
|
TabBar *q;
|
||||||
NativeTabBar *tabBar;
|
TabBarProxy *tabProxy;
|
||||||
QGraphicsProxyWidget *tabProxy;
|
|
||||||
QGraphicsWidget *leftSpacer;
|
QGraphicsWidget *leftSpacer;
|
||||||
QGraphicsWidget *rightSpacer;
|
QGraphicsWidget *rightSpacer;
|
||||||
QList<QGraphicsWidget *> pages;
|
QList<QGraphicsWidget *> pages;
|
||||||
@ -142,7 +168,7 @@ void TabBarPrivate::shapeChanged(const QTabBar::Shape shape)
|
|||||||
mainLayout->itemAt(1)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
mainLayout->itemAt(1)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
tabProxy->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
tabProxy->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||||
}
|
}
|
||||||
tabProxy->setPreferredSize(tabBar->sizeHint());
|
tabProxy->setPreferredSize(tabProxy->native->sizeHint());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -150,8 +176,7 @@ TabBar::TabBar(QGraphicsWidget *parent)
|
|||||||
: QGraphicsWidget(parent),
|
: QGraphicsWidget(parent),
|
||||||
d(new TabBarPrivate(this))
|
d(new TabBarPrivate(this))
|
||||||
{
|
{
|
||||||
d->tabBar = new NativeTabBar();
|
d->tabProxy = new TabBarProxy(this);
|
||||||
d->tabBar->setAttribute(Qt::WA_NoSystemBackground);
|
|
||||||
d->mainLayout = new QGraphicsLinearLayout(Qt::Vertical);
|
d->mainLayout = new QGraphicsLinearLayout(Qt::Vertical);
|
||||||
d->tabBarLayout = new QGraphicsLinearLayout(Qt::Horizontal);
|
d->tabBarLayout = new QGraphicsLinearLayout(Qt::Horizontal);
|
||||||
|
|
||||||
@ -159,9 +184,6 @@ TabBar::TabBar(QGraphicsWidget *parent)
|
|||||||
|
|
||||||
d->mainLayout->addItem(d->tabBarLayout);
|
d->mainLayout->addItem(d->tabBarLayout);
|
||||||
|
|
||||||
d->tabProxy = new QGraphicsProxyWidget(this);
|
|
||||||
d->tabProxy->setWidget(d->tabBar);
|
|
||||||
d->tabProxy->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
|
||||||
|
|
||||||
//tabBar is centered, so a stretch at begin one at the end
|
//tabBar is centered, so a stretch at begin one at the end
|
||||||
//FIXME: doesn't seem to be possible to remove stretches from a layout
|
//FIXME: doesn't seem to be possible to remove stretches from a layout
|
||||||
@ -174,8 +196,8 @@ TabBar::TabBar(QGraphicsWidget *parent)
|
|||||||
d->tabBarLayout->addItem(d->rightSpacer);
|
d->tabBarLayout->addItem(d->rightSpacer);
|
||||||
//d->tabBarLayout->setStretchFactor(d->tabProxy, 2);
|
//d->tabBarLayout->setStretchFactor(d->tabProxy, 2);
|
||||||
|
|
||||||
connect(d->tabBar, SIGNAL(currentChanged(int)), this, SLOT(setCurrentIndex(int)));
|
connect(d->tabProxy->native, SIGNAL(currentChanged(int)), this, SLOT(setCurrentIndex(int)));
|
||||||
connect(d->tabBar, SIGNAL(shapeChanged(QTabBar::Shape)), this, SLOT(shapeChanged(QTabBar::Shape)));
|
connect(d->tabProxy->native, SIGNAL(shapeChanged(QTabBar::Shape)), this, SLOT(shapeChanged(QTabBar::Shape)));
|
||||||
connect(Plasma::Animator::self(), SIGNAL(movementFinished(QGraphicsItem*)), this, SLOT(slidingCompleted(QGraphicsItem*)));
|
connect(Plasma::Animator::self(), SIGNAL(movementFinished(QGraphicsItem*)), this, SLOT(slidingCompleted(QGraphicsItem*)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,11 +230,11 @@ int TabBar::insertTab(int index, const QIcon &icon, const QString &label, QGraph
|
|||||||
page->setEnabled(false);
|
page->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
d->tabProxy->setPreferredSize(d->tabBar->sizeHint());
|
d->tabProxy->setPreferredSize(d->tabProxy->native->sizeHint());
|
||||||
d->updateTabWidgetMode();
|
d->updateTabWidgetMode();
|
||||||
|
|
||||||
int actualIndex = d->tabBar->insertTab(index, icon, label);
|
int actualIndex = d->tabProxy->native->insertTab(index, icon, label);
|
||||||
d->tabProxy->setPreferredSize(d->tabBar->sizeHint());
|
d->tabProxy->setPreferredSize(d->tabProxy->native->sizeHint());
|
||||||
d->updateTabWidgetMode();
|
d->updateTabWidgetMode();
|
||||||
return actualIndex;
|
return actualIndex;
|
||||||
}
|
}
|
||||||
@ -234,17 +256,17 @@ int TabBar::addTab(const QString &label, QGraphicsLayoutItem *content)
|
|||||||
|
|
||||||
int TabBar::currentIndex() const
|
int TabBar::currentIndex() const
|
||||||
{
|
{
|
||||||
return d->tabBar->currentIndex();
|
return d->tabProxy->native->currentIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabBar::setCurrentIndex(int index)
|
void TabBar::setCurrentIndex(int index)
|
||||||
{
|
{
|
||||||
if (index > d->tabBar->count() || d->tabBar->count() <= 1) {
|
if (index > d->tabProxy->native->count() || d->tabProxy->native->count() <= 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d->currentIndex != index) {
|
if (d->currentIndex != index) {
|
||||||
d->tabBar->setCurrentIndex(index);
|
d->tabProxy->native->setCurrentIndex(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
d->mainLayout->removeAt(1);
|
d->mainLayout->removeAt(1);
|
||||||
@ -312,9 +334,9 @@ void TabBar::removeTab(int index)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int currentIndex = d->tabBar->currentIndex();
|
int currentIndex = d->tabProxy->native->currentIndex();
|
||||||
|
|
||||||
d->tabBar->removeTab(index);
|
d->tabProxy->native->removeTab(index);
|
||||||
QGraphicsWidget *page = d->pages.takeAt(index);
|
QGraphicsWidget *page = d->pages.takeAt(index);
|
||||||
|
|
||||||
if (index == currentIndex) {
|
if (index == currentIndex) {
|
||||||
@ -325,7 +347,7 @@ void TabBar::removeTab(int index)
|
|||||||
page->deleteLater();
|
page->deleteLater();
|
||||||
|
|
||||||
d->updateTabWidgetMode();
|
d->updateTabWidgetMode();
|
||||||
d->tabProxy->setPreferredSize(d->tabBar->sizeHint());
|
d->tabProxy->setPreferredSize(d->tabProxy->native->sizeHint());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabBar::setTabText(int index, const QString &label)
|
void TabBar::setTabText(int index, const QString &label)
|
||||||
@ -334,66 +356,66 @@ void TabBar::setTabText(int index, const QString &label)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->tabBar->setTabText(index, label);
|
d->tabProxy->native->setTabText(index, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TabBar::tabText(int index) const
|
QString TabBar::tabText(int index) const
|
||||||
{
|
{
|
||||||
return d->tabBar->tabText(index);
|
return d->tabProxy->native->tabText(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabBar::setTabIcon(int index, const QIcon &icon)
|
void TabBar::setTabIcon(int index, const QIcon &icon)
|
||||||
{
|
{
|
||||||
d->tabBar->setTabIcon(index, icon);
|
d->tabProxy->native->setTabIcon(index, icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon TabBar::tabIcon(int index) const
|
QIcon TabBar::tabIcon(int index) const
|
||||||
{
|
{
|
||||||
return d->tabBar->tabIcon(index);
|
return d->tabProxy->native->tabIcon(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabBar::setStyleSheet(const QString &stylesheet)
|
void TabBar::setStyleSheet(const QString &stylesheet)
|
||||||
{
|
{
|
||||||
d->tabBar->setStyleSheet(stylesheet);
|
d->tabProxy->native->setStyleSheet(stylesheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TabBar::styleSheet() const
|
QString TabBar::styleSheet() const
|
||||||
{
|
{
|
||||||
return d->tabBar->styleSheet();
|
return d->tabProxy->native->styleSheet();
|
||||||
}
|
}
|
||||||
|
|
||||||
QTabBar *TabBar::nativeWidget() const
|
QTabBar *TabBar::nativeWidget() const
|
||||||
{
|
{
|
||||||
return d->tabBar;
|
return d->tabProxy->native;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabBar::wheelEvent(QGraphicsSceneWheelEvent * event)
|
void TabBar::wheelEvent(QGraphicsSceneWheelEvent * event)
|
||||||
{
|
{
|
||||||
//FIXME: probably this would make more sense in NativeTabBar, but it works only here
|
//FIXME: probably this would make more sense in NativeTabBar, but it works only here
|
||||||
|
|
||||||
if (d->tabBar->underMouse()) {
|
if (d->tabProxy->native->underMouse()) {
|
||||||
//Cycle tabs with the circular array tecnique
|
//Cycle tabs with the circular array tecnique
|
||||||
if (event->delta() < 0) {
|
if (event->delta() < 0) {
|
||||||
int index = d->tabBar->currentIndex();
|
int index = d->tabProxy->native->currentIndex();
|
||||||
//search for an enabled tab
|
//search for an enabled tab
|
||||||
for (int i = 0; i < d->tabBar->count()-1; ++i) {
|
for (int i = 0; i < d->tabProxy->native->count()-1; ++i) {
|
||||||
index = (index + 1) % d->tabBar->count();
|
index = (index + 1) % d->tabProxy->native->count();
|
||||||
if (d->tabBar->isTabEnabled(index)) {
|
if (d->tabProxy->native->isTabEnabled(index)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
d->tabBar->setCurrentIndex(index);
|
d->tabProxy->native->setCurrentIndex(index);
|
||||||
} else {
|
} else {
|
||||||
int index = d->tabBar->currentIndex();
|
int index = d->tabProxy->native->currentIndex();
|
||||||
for (int i = 0; i < d->tabBar->count()-1; ++i) {
|
for (int i = 0; i < d->tabProxy->native->count()-1; ++i) {
|
||||||
index = (d->tabBar->count() + index -1) % d->tabBar->count();
|
index = (d->tabProxy->native->count() + index -1) % d->tabProxy->native->count();
|
||||||
if (d->tabBar->isTabEnabled(index)) {
|
if (d->tabProxy->native->isTabEnabled(index)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
d->tabBar->setCurrentIndex(index);
|
d->tabProxy->native->setCurrentIndex(index);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
QGraphicsWidget::wheelEvent(event);
|
QGraphicsWidget::wheelEvent(event);
|
||||||
|
Loading…
Reference in New Issue
Block a user