style with FrameSvg all the lineedits, spinboxes and comboboxes, use
Plasma::Style to achieve that, since it's a kinda repetitive thing and comboboxes and spinboxes are complex controls the svg used will probably change svn path=/trunk/KDE/kdelibs/; revision=912567
This commit is contained in:
parent
22b6670f00
commit
53658a106e
@ -22,6 +22,9 @@
|
||||
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionComplex>
|
||||
#include <QSpinBox>
|
||||
#include <QComboBox>
|
||||
#include <QApplication>
|
||||
|
||||
#include <kdebug.h>
|
||||
|
||||
@ -32,8 +35,10 @@ namespace Plasma {
|
||||
class StylePrivate
|
||||
{
|
||||
public:
|
||||
StylePrivate()
|
||||
: scrollbar(0)
|
||||
StylePrivate(Style *style)
|
||||
: q(style),
|
||||
scrollbar(0),
|
||||
textBox(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -41,7 +46,27 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void createScrollbar()
|
||||
{
|
||||
if (!scrollbar) {
|
||||
scrollbar = new Plasma::FrameSvg(q);
|
||||
scrollbar->setImagePath("widgets/scrollbar");
|
||||
scrollbar->setCacheAllRenderedFrames(true);
|
||||
}
|
||||
}
|
||||
|
||||
void createTextBox()
|
||||
{
|
||||
if (!textBox) {
|
||||
textBox = new Plasma::FrameSvg(q);
|
||||
textBox->setImagePath("widgets/frame");
|
||||
textBox->setElementPrefix("sunken");
|
||||
}
|
||||
}
|
||||
|
||||
Style *q;
|
||||
Plasma::FrameSvg *scrollbar;
|
||||
Plasma::FrameSvg *textBox;
|
||||
static Plasma::Style::Ptr s_sharedStyle;
|
||||
};
|
||||
|
||||
@ -65,11 +90,8 @@ void Style::doneWithSharedStyle()
|
||||
|
||||
Style::Style()
|
||||
: QCommonStyle(),
|
||||
d(new StylePrivate)
|
||||
d(new StylePrivate(this))
|
||||
{
|
||||
d->scrollbar = new Plasma::FrameSvg(this);
|
||||
d->scrollbar->setImagePath("widgets/scrollbar");
|
||||
d->scrollbar->setCacheAllRenderedFrames(true);
|
||||
}
|
||||
|
||||
Style::~Style()
|
||||
@ -82,84 +104,176 @@ void Style::drawComplexControl(ComplexControl control,
|
||||
QPainter *painter,
|
||||
const QWidget *widget) const
|
||||
{
|
||||
if (control != CC_ScrollBar) {
|
||||
QCommonStyle::drawComplexControl(control, option, painter, widget);
|
||||
return;
|
||||
}
|
||||
switch (control) {
|
||||
case CC_ScrollBar: {
|
||||
d->createScrollbar();
|
||||
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
const bool sunken = option->state & State_Sunken;
|
||||
const QStyleOptionSlider *scrollOption = qstyleoption_cast<const QStyleOptionSlider *>(option);
|
||||
QString prefix;
|
||||
const bool sunken = option->state & State_Sunken;
|
||||
const QStyleOptionSlider *scrollOption = qstyleoption_cast<const QStyleOptionSlider *>(option);
|
||||
QString prefix;
|
||||
|
||||
if (option->state & State_MouseOver) {
|
||||
prefix= "mouseover-";
|
||||
}
|
||||
|
||||
QRect subLine;
|
||||
QRect addLine;
|
||||
if (scrollOption && scrollOption->orientation == Qt::Horizontal) {
|
||||
subLine = d->scrollbar->elementRect(prefix + "arrow-left").toRect();
|
||||
addLine = d->scrollbar->elementRect(prefix + "arrow-right").toRect();
|
||||
} else {
|
||||
subLine = d->scrollbar->elementRect(prefix + "arrow-up").toRect();
|
||||
addLine = d->scrollbar->elementRect(prefix + "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->resizeFrame(option->rect.size());
|
||||
d->scrollbar->paintFrame(painter);
|
||||
|
||||
if (sunken && scrollOption && scrollOption->activeSubControls & SC_ScrollBarSlider) {
|
||||
d->scrollbar->setElementPrefix("sunken-slider");
|
||||
} else {
|
||||
d->scrollbar->setElementPrefix(prefix + "slider");
|
||||
}
|
||||
|
||||
d->scrollbar->resizeFrame(slider.size());
|
||||
d->scrollbar->paintFrame(painter, slider.topLeft());
|
||||
|
||||
if (scrollOption && scrollOption->orientation == Qt::Horizontal) {
|
||||
if (sunken && scrollOption->activeSubControls & SC_ScrollBarAddLine) {
|
||||
d->scrollbar->paint(painter, addLine, "sunken-arrow-right");
|
||||
} else {
|
||||
d->scrollbar->paint(painter, addLine, prefix + "arrow-right");
|
||||
if (option->state & State_MouseOver) {
|
||||
prefix= "mouseover-";
|
||||
}
|
||||
|
||||
if (sunken && scrollOption->activeSubControls & SC_ScrollBarSubLine) {
|
||||
d->scrollbar->paint(painter, subLine, "sunken-arrow-left");
|
||||
QRect subLine;
|
||||
QRect addLine;
|
||||
if (scrollOption && scrollOption->orientation == Qt::Horizontal) {
|
||||
subLine = d->scrollbar->elementRect(prefix + "arrow-left").toRect();
|
||||
addLine = d->scrollbar->elementRect(prefix + "arrow-right").toRect();
|
||||
} else {
|
||||
d->scrollbar->paint(painter, subLine, prefix + "arrow-left");
|
||||
}
|
||||
} else {
|
||||
if (sunken && scrollOption && scrollOption->activeSubControls & SC_ScrollBarAddLine) {
|
||||
d->scrollbar->paint(painter, addLine, "sunken-arrow-down");
|
||||
} else {
|
||||
d->scrollbar->paint(painter, addLine, prefix + "arrow-down");
|
||||
subLine = d->scrollbar->elementRect(prefix + "arrow-up").toRect();
|
||||
addLine = d->scrollbar->elementRect(prefix + "arrow-down").toRect();
|
||||
}
|
||||
|
||||
if (sunken && scrollOption && scrollOption->activeSubControls & SC_ScrollBarSubLine) {
|
||||
d->scrollbar->paint(painter, subLine, "sunken-arrow-up");
|
||||
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->resizeFrame(option->rect.size());
|
||||
d->scrollbar->paintFrame(painter);
|
||||
|
||||
if (sunken && scrollOption && scrollOption->activeSubControls & SC_ScrollBarSlider) {
|
||||
d->scrollbar->setElementPrefix("sunken-slider");
|
||||
} else {
|
||||
d->scrollbar->paint(painter, subLine, prefix + "arrow-up");
|
||||
d->scrollbar->setElementPrefix(prefix + "slider");
|
||||
}
|
||||
|
||||
d->scrollbar->resizeFrame(slider.size());
|
||||
d->scrollbar->paintFrame(painter, slider.topLeft());
|
||||
|
||||
if (scrollOption && scrollOption->orientation == Qt::Horizontal) {
|
||||
if (sunken && scrollOption->activeSubControls & SC_ScrollBarAddLine) {
|
||||
d->scrollbar->paint(painter, addLine, "sunken-arrow-right");
|
||||
} else {
|
||||
d->scrollbar->paint(painter, addLine, prefix + "arrow-right");
|
||||
}
|
||||
|
||||
if (sunken && scrollOption->activeSubControls & SC_ScrollBarSubLine) {
|
||||
d->scrollbar->paint(painter, subLine, "sunken-arrow-left");
|
||||
} else {
|
||||
d->scrollbar->paint(painter, subLine, prefix + "arrow-left");
|
||||
}
|
||||
} else {
|
||||
if (sunken && scrollOption && scrollOption->activeSubControls & SC_ScrollBarAddLine) {
|
||||
d->scrollbar->paint(painter, addLine, "sunken-arrow-down");
|
||||
} else {
|
||||
d->scrollbar->paint(painter, addLine, prefix + "arrow-down");
|
||||
}
|
||||
|
||||
if (sunken && scrollOption && scrollOption->activeSubControls & SC_ScrollBarSubLine) {
|
||||
d->scrollbar->paint(painter, subLine, "sunken-arrow-up");
|
||||
} else {
|
||||
d->scrollbar->paint(painter, subLine, prefix + "arrow-up");
|
||||
}
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
break;
|
||||
}
|
||||
case CC_SpinBox: {
|
||||
d->createTextBox();
|
||||
|
||||
painter->restore();
|
||||
d->textBox->resizeFrame(option->rect.size());
|
||||
d->textBox->paintFrame(painter);
|
||||
|
||||
const QStyleOptionSpinBox *spinOpt = qstyleoption_cast<const QStyleOptionSpinBox *>(option);
|
||||
bool upSunken = (spinOpt->activeSubControls & SC_SpinBoxUp) &&
|
||||
(spinOpt->state & (State_Sunken | State_On));
|
||||
bool downSunken = (spinOpt->activeSubControls & SC_SpinBoxDown) &&
|
||||
(spinOpt->state & (State_Sunken | State_On));
|
||||
|
||||
const QSpinBox *spin = qobject_cast<const QSpinBox *>(widget);
|
||||
PrimitiveElement pe;
|
||||
if (spin->buttonSymbols() == QSpinBox::PlusMinus) {
|
||||
pe = PE_IndicatorSpinPlus;
|
||||
} else {
|
||||
pe = PE_IndicatorArrowUp;
|
||||
}
|
||||
|
||||
QStyleOption upOpt;
|
||||
upOpt = *option;
|
||||
upOpt.rect = subControlRect(CC_SpinBox, option, SC_SpinBoxUp, widget);
|
||||
|
||||
if (upSunken) {
|
||||
upOpt.state = State_Sunken|State_Enabled;
|
||||
} else {
|
||||
upOpt.state = State_Enabled;
|
||||
}
|
||||
|
||||
qApp->style()->drawPrimitive(pe, &upOpt, painter, widget);
|
||||
|
||||
if (spin->buttonSymbols() == QSpinBox::PlusMinus) {
|
||||
pe = PE_IndicatorSpinMinus;
|
||||
} else {
|
||||
pe = PE_IndicatorArrowDown;
|
||||
}
|
||||
|
||||
QStyleOption downOpt;
|
||||
downOpt= *option;
|
||||
downOpt.rect = subControlRect(CC_SpinBox, option, SC_SpinBoxDown, widget);
|
||||
|
||||
if (downSunken) {
|
||||
downOpt.state = State_Sunken|State_Enabled;
|
||||
} else {
|
||||
downOpt.state = State_Enabled;
|
||||
}
|
||||
|
||||
qApp->style()->drawPrimitive(pe, &downOpt, painter, widget);
|
||||
break;
|
||||
}
|
||||
case CC_ComboBox: {
|
||||
const QComboBox *combo = qobject_cast<const QComboBox *>(widget);
|
||||
if (!combo->isEditable()) {
|
||||
qApp->style()->drawComplexControl(control, option, painter, widget);
|
||||
} else {
|
||||
d->createTextBox();
|
||||
d->textBox->resizeFrame(option->rect.size());
|
||||
d->textBox->paintFrame(painter);
|
||||
|
||||
QStyleOption arrowOpt;
|
||||
arrowOpt = *option;
|
||||
arrowOpt.rect = subControlRect(CC_ComboBox, option, SC_ComboBoxArrow, widget);
|
||||
qApp->style()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
qApp->style()->drawComplexControl(control, option, painter, widget);
|
||||
}
|
||||
}
|
||||
|
||||
void Style::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
|
||||
{
|
||||
Q_UNUSED(widget)
|
||||
|
||||
switch (element) {
|
||||
case PE_PanelLineEdit:
|
||||
//comboboxes draws their own frame
|
||||
if (qobject_cast<QComboBox *>(widget->parent())) {
|
||||
return;
|
||||
}
|
||||
d->createTextBox();
|
||||
|
||||
d->textBox->resizeFrame(option->rect.size());
|
||||
d->textBox->paintFrame(painter);
|
||||
break;
|
||||
default:
|
||||
qApp->style()->drawPrimitive(element, option, painter, widget);
|
||||
}
|
||||
}
|
||||
|
||||
int Style::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
|
||||
{
|
||||
switch (metric) {
|
||||
case PM_ScrollBarExtent: {
|
||||
d->createScrollbar();
|
||||
const QStyleOptionSlider *scrollOption = qstyleoption_cast<const QStyleOptionSlider *>(option);
|
||||
if (scrollOption && scrollOption->orientation == Qt::Vertical) {
|
||||
return d->scrollbar->elementSize("arrow-down").width() + 2;
|
||||
|
@ -44,6 +44,8 @@ public:
|
||||
explicit Style();
|
||||
~Style();
|
||||
|
||||
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = 0) const;
|
||||
|
||||
protected:
|
||||
void drawComplexControl(ComplexControl control,
|
||||
const QStyleOptionComplex *option,
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <kiconeffect.h>
|
||||
#include <kiconloader.h>
|
||||
|
||||
#include <plasma/private/style_p.h>
|
||||
#include "theme.h"
|
||||
#include "framesvg.h"
|
||||
#include "animator.h"
|
||||
@ -59,6 +60,7 @@ public:
|
||||
bool fadeIn;
|
||||
qreal opacity;
|
||||
QRectF activeRect;
|
||||
Plasma::Style::Ptr style;
|
||||
};
|
||||
|
||||
void ComboBoxPrivate::syncActiveRect()
|
||||
@ -90,6 +92,15 @@ void ComboBoxPrivate::syncBorders()
|
||||
|
||||
//calc the rect for the over effect
|
||||
syncActiveRect();
|
||||
|
||||
KComboBox *native = q->nativeWidget();
|
||||
QColor color = Theme::defaultTheme()->color(Theme::TextColor);
|
||||
QPalette p = native->palette();
|
||||
|
||||
p.setColor(QPalette::Normal, QPalette::Text, color);
|
||||
p.setColor(QPalette::Inactive, QPalette::Text, color);
|
||||
native->setPalette(p);
|
||||
native->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
|
||||
}
|
||||
|
||||
void ComboBoxPrivate::animationUpdate(qreal progress)
|
||||
@ -122,11 +133,14 @@ ComboBox::ComboBox(QGraphicsWidget *parent)
|
||||
d->syncBorders();
|
||||
setAcceptHoverEvents(true);
|
||||
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(syncBorders()));
|
||||
d->style = Plasma::Style::sharedStyle();
|
||||
native->setStyle(d->style.data());
|
||||
}
|
||||
|
||||
ComboBox::~ComboBox()
|
||||
{
|
||||
delete d;
|
||||
Plasma::Style::doneWithSharedStyle();
|
||||
}
|
||||
|
||||
QString ComboBox::text() const
|
||||
|
@ -24,6 +24,8 @@
|
||||
#include <klineedit.h>
|
||||
#include <kmimetype.h>
|
||||
|
||||
#include <plasma/private/style_p.h>
|
||||
|
||||
#include "theme.h"
|
||||
#include "svg.h"
|
||||
|
||||
@ -33,18 +35,34 @@ namespace Plasma
|
||||
class LineEditPrivate
|
||||
{
|
||||
public:
|
||||
LineEditPrivate()
|
||||
LineEditPrivate(LineEdit *lineEdit)
|
||||
:q(lineEdit)
|
||||
{
|
||||
}
|
||||
|
||||
~LineEditPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
void setPalette()
|
||||
{
|
||||
KLineEdit *native = q->nativeWidget();
|
||||
QColor color = Theme::defaultTheme()->color(Theme::TextColor);
|
||||
QPalette p = native->palette();
|
||||
|
||||
p.setColor(QPalette::Normal, QPalette::Text, color);
|
||||
p.setColor(QPalette::Inactive, QPalette::Text, color);
|
||||
native->setPalette(p);
|
||||
native->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
|
||||
}
|
||||
|
||||
LineEdit *q;
|
||||
Plasma::Style::Ptr style;
|
||||
};
|
||||
|
||||
LineEdit::LineEdit(QGraphicsWidget *parent)
|
||||
: QGraphicsProxyWidget(parent),
|
||||
d(new LineEditPrivate)
|
||||
d(new LineEditPrivate(this))
|
||||
{
|
||||
KLineEdit *native = new KLineEdit;
|
||||
connect(native, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
|
||||
@ -52,11 +70,17 @@ LineEdit::LineEdit(QGraphicsWidget *parent)
|
||||
connect(native, SIGNAL(textEdited(const QString&)), this, SIGNAL(textEdited(const QString&)));
|
||||
setWidget(native);
|
||||
native->setAttribute(Qt::WA_NoSystemBackground);
|
||||
d->style = Plasma::Style::sharedStyle();
|
||||
native->setStyle(d->style.data());
|
||||
|
||||
d->setPalette();
|
||||
connect(Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(setPalette()));
|
||||
}
|
||||
|
||||
LineEdit::~LineEdit()
|
||||
{
|
||||
delete d;
|
||||
Plasma::Style::doneWithSharedStyle();
|
||||
}
|
||||
|
||||
void LineEdit::setText(const QString &text)
|
||||
|
@ -84,6 +84,8 @@ Q_SIGNALS:
|
||||
void textEdited(const QString &text);
|
||||
|
||||
private:
|
||||
Q_PRIVATE_SLOT(d, void setPalette())
|
||||
|
||||
LineEditPrivate *const d;
|
||||
};
|
||||
|
||||
|
@ -25,24 +25,47 @@
|
||||
#include <knuminput.h>
|
||||
#include <kmimetype.h>
|
||||
|
||||
#include <plasma/theme.h>
|
||||
#include <plasma/private/style_p.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class SpinBoxPrivate
|
||||
{
|
||||
public:
|
||||
SpinBoxPrivate()
|
||||
SpinBoxPrivate(SpinBox *spinBox)
|
||||
: q(spinBox)
|
||||
{
|
||||
}
|
||||
|
||||
~SpinBoxPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
void setPalette()
|
||||
{
|
||||
QSpinBox *native = q->nativeWidget();
|
||||
QColor color = Theme::defaultTheme()->color(Theme::TextColor);
|
||||
QPalette p = native->palette();
|
||||
|
||||
p.setColor(QPalette::Normal, QPalette::Text, color);
|
||||
p.setColor(QPalette::Inactive, QPalette::Text, color);
|
||||
p.setColor(QPalette::Normal, QPalette::ButtonText, color);
|
||||
p.setColor(QPalette::Inactive, QPalette::ButtonText, color);
|
||||
p.setColor(QPalette::Normal, QPalette::Base, QColor(0,0,0,0));
|
||||
p.setColor(QPalette::Inactive, QPalette::Base, QColor(0,0,0,0));
|
||||
native->setPalette(p);
|
||||
native->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
|
||||
}
|
||||
|
||||
SpinBox *q;
|
||||
Plasma::Style::Ptr style;
|
||||
};
|
||||
|
||||
SpinBox::SpinBox(QGraphicsWidget *parent)
|
||||
: QGraphicsProxyWidget(parent),
|
||||
d(new SpinBoxPrivate)
|
||||
d(new SpinBoxPrivate(this))
|
||||
{
|
||||
KIntSpinBox *native = new KIntSpinBox;
|
||||
|
||||
@ -51,11 +74,18 @@ SpinBox::SpinBox(QGraphicsWidget *parent)
|
||||
|
||||
setWidget(native);
|
||||
native->setAttribute(Qt::WA_NoSystemBackground);
|
||||
native->setAutoFillBackground(false);
|
||||
|
||||
d->style = Plasma::Style::sharedStyle();
|
||||
native->setStyle(d->style.data());
|
||||
d->setPalette();
|
||||
connect(Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(setPalette()));
|
||||
}
|
||||
|
||||
SpinBox::~SpinBox()
|
||||
{
|
||||
delete d;
|
||||
Plasma::Style::doneWithSharedStyle();
|
||||
}
|
||||
|
||||
void SpinBox::setMaximum(int max)
|
||||
|
@ -131,6 +131,8 @@ Q_SIGNALS:
|
||||
void editingFinished();
|
||||
|
||||
private:
|
||||
Q_PRIVATE_SLOT(d, void setPalette())
|
||||
|
||||
SpinBoxPrivate * const d;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user