share one style amongst all the widgets
svn path=/trunk/KDE/kdelibs/; revision=897366
This commit is contained in:
parent
adaed62351
commit
9c25aa59a5
@ -42,8 +42,27 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
Plasma::FrameSvg *scrollbar;
|
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()
|
Style::Style()
|
||||||
: QCommonStyle(),
|
: QCommonStyle(),
|
||||||
d(new StylePrivate)
|
d(new StylePrivate)
|
||||||
|
@ -21,18 +21,26 @@
|
|||||||
#ifndef PLASMA_STYLE_H
|
#ifndef PLASMA_STYLE_H
|
||||||
#define PLASMA_STYLE_H
|
#define PLASMA_STYLE_H
|
||||||
|
|
||||||
|
#include <QtCore/QSharedData>
|
||||||
#include <QtGui/QCommonStyle>
|
#include <QtGui/QCommonStyle>
|
||||||
|
|
||||||
|
#include <ksharedptr.h>
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
class StylePrivate;
|
class StylePrivate;
|
||||||
|
|
||||||
class Style : public QCommonStyle
|
class Style : public QCommonStyle, public QSharedData
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
typedef KSharedPtr<Style> Ptr;
|
||||||
|
|
||||||
|
static Style::Ptr sharedStyle();
|
||||||
|
static void doneWithSharedStyle();
|
||||||
|
|
||||||
explicit Style();
|
explicit Style();
|
||||||
~Style();
|
~Style();
|
||||||
|
|
||||||
@ -43,6 +51,7 @@ protected:
|
|||||||
const QWidget *widget) const;
|
const QWidget *widget) const;
|
||||||
|
|
||||||
int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const;
|
int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StylePrivate *d;
|
StylePrivate *d;
|
||||||
};
|
};
|
||||||
|
@ -28,7 +28,7 @@ namespace Plasma
|
|||||||
class ScrollBarPrivate
|
class ScrollBarPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Plasma::Style *style;
|
Plasma::Style::Ptr style;
|
||||||
};
|
};
|
||||||
|
|
||||||
ScrollBar::ScrollBar(QGraphicsWidget *parent)
|
ScrollBar::ScrollBar(QGraphicsWidget *parent)
|
||||||
@ -38,8 +38,8 @@ ScrollBar::ScrollBar(QGraphicsWidget *parent)
|
|||||||
QScrollBar *scrollbar = new QScrollBar();
|
QScrollBar *scrollbar = new QScrollBar();
|
||||||
scrollbar->setAttribute(Qt::WA_NoSystemBackground);
|
scrollbar->setAttribute(Qt::WA_NoSystemBackground);
|
||||||
setWidget(scrollbar);
|
setWidget(scrollbar);
|
||||||
d->style = new Plasma::Style();
|
d->style = Plasma::Style::sharedStyle();
|
||||||
scrollbar->setStyle(d->style);
|
scrollbar->setStyle(d->style.data());
|
||||||
|
|
||||||
scrollbar->resize(scrollbar->sizeHint());
|
scrollbar->resize(scrollbar->sizeHint());
|
||||||
connect(scrollbar, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
|
connect(scrollbar, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
|
||||||
@ -48,8 +48,8 @@ ScrollBar::ScrollBar(QGraphicsWidget *parent)
|
|||||||
ScrollBar::~ScrollBar()
|
ScrollBar::~ScrollBar()
|
||||||
{
|
{
|
||||||
widget()->setStyle(0);
|
widget()->setStyle(0);
|
||||||
delete d->style;
|
|
||||||
delete d;
|
delete d;
|
||||||
|
Plasma::Style::doneWithSharedStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollBar::setRange(int min, int max)
|
void ScrollBar::setRange(int min, int max)
|
||||||
|
@ -35,7 +35,7 @@ namespace Plasma
|
|||||||
class TextEditPrivate
|
class TextEditPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Plasma::Style *style;
|
Plasma::Style::Ptr style;
|
||||||
};
|
};
|
||||||
|
|
||||||
TextEdit::TextEdit(QGraphicsWidget *parent)
|
TextEdit::TextEdit(QGraphicsWidget *parent)
|
||||||
@ -46,17 +46,17 @@ TextEdit::TextEdit(QGraphicsWidget *parent)
|
|||||||
connect(native, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
|
connect(native, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
|
||||||
setWidget(native);
|
setWidget(native);
|
||||||
native->setAttribute(Qt::WA_NoSystemBackground);
|
native->setAttribute(Qt::WA_NoSystemBackground);
|
||||||
d->style = new Plasma::Style();
|
d->style = Plasma::Style::sharedStyle();
|
||||||
native->verticalScrollBar()->setStyle(d->style);
|
native->verticalScrollBar()->setStyle(d->style.data());
|
||||||
native->horizontalScrollBar()->setStyle(d->style);
|
native->horizontalScrollBar()->setStyle(d->style.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEdit::~TextEdit()
|
TextEdit::~TextEdit()
|
||||||
{
|
{
|
||||||
nativeWidget()->verticalScrollBar()->setStyle(0);
|
nativeWidget()->verticalScrollBar()->setStyle(0);
|
||||||
nativeWidget()->horizontalScrollBar()->setStyle(0);
|
nativeWidget()->horizontalScrollBar()->setStyle(0);
|
||||||
delete d->style;
|
|
||||||
delete d;
|
delete d;
|
||||||
|
Plasma::Style::doneWithSharedStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEdit::setText(const QString &text)
|
void TextEdit::setText(const QString &text)
|
||||||
|
@ -33,7 +33,7 @@ namespace Plasma
|
|||||||
class TreeViewPrivate
|
class TreeViewPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Plasma::Style *style;
|
Plasma::Style::Ptr style;
|
||||||
};
|
};
|
||||||
|
|
||||||
TreeView::TreeView(QGraphicsWidget *parent)
|
TreeView::TreeView(QGraphicsWidget *parent)
|
||||||
@ -45,15 +45,15 @@ TreeView::TreeView(QGraphicsWidget *parent)
|
|||||||
native->setAttribute(Qt::WA_NoSystemBackground);
|
native->setAttribute(Qt::WA_NoSystemBackground);
|
||||||
native->setFrameStyle(QFrame::NoFrame);
|
native->setFrameStyle(QFrame::NoFrame);
|
||||||
|
|
||||||
d->style = new Plasma::Style();
|
d->style = Plasma::Style::sharedStyle();
|
||||||
native->verticalScrollBar()->setStyle(d->style);
|
native->verticalScrollBar()->setStyle(d->style.data());
|
||||||
native->horizontalScrollBar()->setStyle(d->style);
|
native->horizontalScrollBar()->setStyle(d->style.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeView::~TreeView()
|
TreeView::~TreeView()
|
||||||
{
|
{
|
||||||
delete d->style;
|
|
||||||
delete d;
|
delete d;
|
||||||
|
Plasma::Style::doneWithSharedStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeView::setModel(QAbstractItemModel *model)
|
void TreeView::setModel(QAbstractItemModel *model)
|
||||||
|
Loading…
Reference in New Issue
Block a user