diff --git a/private/style.cpp b/private/style.cpp index c634206f8..2dc8efea9 100644 --- a/private/style.cpp +++ b/private/style.cpp @@ -22,6 +22,9 @@ #include #include +#include +#include +#include #include @@ -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(option); - QString prefix; + const bool sunken = option->state & State_Sunken; + const QStyleOptionSlider *scrollOption = qstyleoption_cast(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(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(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(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(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(option); if (scrollOption && scrollOption->orientation == Qt::Vertical) { return d->scrollbar->elementSize("arrow-down").width() + 2; diff --git a/private/style_p.h b/private/style_p.h index 07281f964..d99633f6b 100644 --- a/private/style_p.h +++ b/private/style_p.h @@ -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, diff --git a/widgets/combobox.cpp b/widgets/combobox.cpp index 8c7820382..836f4e9b2 100644 --- a/widgets/combobox.cpp +++ b/widgets/combobox.cpp @@ -27,6 +27,7 @@ #include #include +#include #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 diff --git a/widgets/lineedit.cpp b/widgets/lineedit.cpp index 448540762..807ce4854 100644 --- a/widgets/lineedit.cpp +++ b/widgets/lineedit.cpp @@ -24,6 +24,8 @@ #include #include +#include + #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) diff --git a/widgets/lineedit.h b/widgets/lineedit.h index c1e29a3b6..7882c4abe 100644 --- a/widgets/lineedit.h +++ b/widgets/lineedit.h @@ -84,6 +84,8 @@ Q_SIGNALS: void textEdited(const QString &text); private: + Q_PRIVATE_SLOT(d, void setPalette()) + LineEditPrivate *const d; }; diff --git a/widgets/spinbox.cpp b/widgets/spinbox.cpp index c139b1380..ea9ee6e7c 100644 --- a/widgets/spinbox.cpp +++ b/widgets/spinbox.cpp @@ -25,24 +25,47 @@ #include #include +#include +#include + 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) diff --git a/widgets/spinbox.h b/widgets/spinbox.h index 9ac99f713..5f00e8c02 100644 --- a/widgets/spinbox.h +++ b/widgets/spinbox.h @@ -131,6 +131,8 @@ Q_SIGNALS: void editingFinished(); private: + Q_PRIVATE_SLOT(d, void setPalette()) + SpinBoxPrivate * const d; };