share one style amongst all the widgets

svn path=/trunk/KDE/kdelibs/; revision=897366
This commit is contained in:
Aaron J. Seigo 2008-12-15 21:17:43 +00:00
parent adaed62351
commit 9c25aa59a5
5 changed files with 43 additions and 15 deletions

View File

@ -42,8 +42,27 @@ public:
}
Plasma::FrameSvg *scrollbar;
static Plasma::Style::Ptr s_sharedStyle;
};
Style::Ptr StylePrivate::s_sharedStyle(0);
Style::Ptr Style::sharedStyle()
{
if (!StylePrivate::s_sharedStyle) {
StylePrivate::s_sharedStyle = new Style();
}
return StylePrivate::s_sharedStyle;
}
void Style::doneWithSharedStyle()
{
if (StylePrivate::s_sharedStyle.isUnique()) {
StylePrivate::s_sharedStyle = 0;
}
}
Style::Style()
: QCommonStyle(),
d(new StylePrivate)

View File

@ -21,18 +21,26 @@
#ifndef PLASMA_STYLE_H
#define PLASMA_STYLE_H
#include <QtCore/QSharedData>
#include <QtGui/QCommonStyle>
#include <ksharedptr.h>
namespace Plasma
{
class StylePrivate;
class Style : public QCommonStyle
class Style : public QCommonStyle, public QSharedData
{
Q_OBJECT
public:
typedef KSharedPtr<Style> Ptr;
static Style::Ptr sharedStyle();
static void doneWithSharedStyle();
explicit Style();
~Style();
@ -43,6 +51,7 @@ protected:
const QWidget *widget) const;
int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const;
private:
StylePrivate *d;
};

View File

@ -28,7 +28,7 @@ namespace Plasma
class ScrollBarPrivate
{
public:
Plasma::Style *style;
Plasma::Style::Ptr style;
};
ScrollBar::ScrollBar(QGraphicsWidget *parent)
@ -38,8 +38,8 @@ ScrollBar::ScrollBar(QGraphicsWidget *parent)
QScrollBar *scrollbar = new QScrollBar();
scrollbar->setAttribute(Qt::WA_NoSystemBackground);
setWidget(scrollbar);
d->style = new Plasma::Style();
scrollbar->setStyle(d->style);
d->style = Plasma::Style::sharedStyle();
scrollbar->setStyle(d->style.data());
scrollbar->resize(scrollbar->sizeHint());
connect(scrollbar, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
@ -48,8 +48,8 @@ ScrollBar::ScrollBar(QGraphicsWidget *parent)
ScrollBar::~ScrollBar()
{
widget()->setStyle(0);
delete d->style;
delete d;
Plasma::Style::doneWithSharedStyle();
}
void ScrollBar::setRange(int min, int max)

View File

@ -35,7 +35,7 @@ namespace Plasma
class TextEditPrivate
{
public:
Plasma::Style *style;
Plasma::Style::Ptr style;
};
TextEdit::TextEdit(QGraphicsWidget *parent)
@ -46,17 +46,17 @@ TextEdit::TextEdit(QGraphicsWidget *parent)
connect(native, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
setWidget(native);
native->setAttribute(Qt::WA_NoSystemBackground);
d->style = new Plasma::Style();
native->verticalScrollBar()->setStyle(d->style);
native->horizontalScrollBar()->setStyle(d->style);
d->style = Plasma::Style::sharedStyle();
native->verticalScrollBar()->setStyle(d->style.data());
native->horizontalScrollBar()->setStyle(d->style.data());
}
TextEdit::~TextEdit()
{
nativeWidget()->verticalScrollBar()->setStyle(0);
nativeWidget()->horizontalScrollBar()->setStyle(0);
delete d->style;
delete d;
Plasma::Style::doneWithSharedStyle();
}
void TextEdit::setText(const QString &text)

View File

@ -33,7 +33,7 @@ namespace Plasma
class TreeViewPrivate
{
public:
Plasma::Style *style;
Plasma::Style::Ptr style;
};
TreeView::TreeView(QGraphicsWidget *parent)
@ -45,15 +45,15 @@ TreeView::TreeView(QGraphicsWidget *parent)
native->setAttribute(Qt::WA_NoSystemBackground);
native->setFrameStyle(QFrame::NoFrame);
d->style = new Plasma::Style();
native->verticalScrollBar()->setStyle(d->style);
native->horizontalScrollBar()->setStyle(d->style);
d->style = Plasma::Style::sharedStyle();
native->verticalScrollBar()->setStyle(d->style.data());
native->horizontalScrollBar()->setStyle(d->style.data());
}
TreeView::~TreeView()
{
delete d->style;
delete d;
Plasma::Style::doneWithSharedStyle();
}
void TreeView::setModel(QAbstractItemModel *model)