consolidate all the theming (palette, fonts) code for widgets into a private interface: ThemeWidgetInterface. have the relevant *Private classes inherit from it and all the tricky logic is now in one place and consistent.

svn path=/trunk/KDE/kdelibs/; revision=1188314
This commit is contained in:
Aaron J. Seigo 2010-10-22 00:25:17 +00:00
parent 22d9baccef
commit a793185b21
17 changed files with 284 additions and 457 deletions

View File

@ -22,18 +22,19 @@
#include <QAction>
#include "private/themedwidgetinterface_p.h"
namespace Plasma
{
template <class T>
class ActionWidgetInterface
class ActionWidgetInterface : public ThemedWidgetInterface<T>
{
public:
T *t;
QAction *action;
ActionWidgetInterface(T *publicClass)
: t(publicClass),
ActionWidgetInterface(T *parent)
: ThemedWidgetInterface(parent)
action(0)
{
}
@ -56,20 +57,20 @@ public:
void syncToAction()
{
if (!action) {
t->setIcon(QIcon());
t->setText(QString());
t->setEnabled(false);
q->setIcon(QIcon());
q->setText(QString());
q->setEnabled(false);
return;
}
//we don't get told *what* changed, just that something changed
//so we update everything we care about
t->setIcon(action->icon());
t->setText(action->iconText());
t->setEnabled(action->isEnabled());
t->setVisible(action->isVisible());
q->setIcon(action->icon());
q->setText(action->iconText());
q->setEnabled(action->isEnabled());
q->setVisible(action->isVisible());
if (!t->toolTip().isEmpty()) {
t->setToolTip(action->text());
if (!q->toolTip().isEmpty()) {
q->setToolTip(action->text());
}
changed();

View File

@ -0,0 +1,112 @@
/******************************************************************************
* Copyright 2009 by Aaron Seigo <aseigo@kde.org> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public License *
* along with this library; see the file COPYING.LIB. If not, write to *
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301, USA. *
*******************************************************************************/
#ifndef ACTIONWIDGETINTERFACE_P_H
#define ACTIONWIDGETINTERFACE_P_H
#include "kglobalsettings.h"
#include "theme.h"
namespace Plasma
{
template <class T>
class ThemedWidgetInterface
{
public:
ThemedWidgetInterface(T *publicClass)
: q(publicClass),
customPalette(false),
customFont(false)
{
QObject::connect(Theme::defaultTheme(), SIGNAL(themeChanged()), q, SLOT(setPalette()));
QObject::connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), q, SLOT(setPalette()));
}
void initTheming()
{
customPalette = false;
customFont = false;
setPalette();
}
void setPalette()
{
if (!customPalette) {
QColor color = Theme::defaultTheme()->color(Theme::TextColor);
QPalette p = q->palette();
p.setColor(QPalette::Normal, QPalette::WindowText, color);
p.setColor(QPalette::Inactive, QPalette::WindowText, color);
p.setColor(QPalette::Normal, QPalette::Text, color);
p.setColor(QPalette::Inactive, QPalette::Text, color);
color.setAlphaF(0.6);
p.setColor(QPalette::Disabled, QPalette::WindowText, color);
p.setColor(QPalette::Normal, QPalette::Link, Theme::defaultTheme()->color(Theme::LinkColor));
p.setColor(QPalette::Normal, QPalette::LinkVisited, Theme::defaultTheme()->color(Theme::VisitedLinkColor));
p.setColor(QPalette::Normal, QPalette::ButtonText, color);
p.setColor(QPalette::Inactive, QPalette::ButtonText, color);
//FIXME: hardcoded colors .. looks incorrect
p.setColor(QPalette::Normal, QPalette::Base, QColor(0,0,0,0));
p.setColor(QPalette::Inactive, QPalette::Base, QColor(0,0,0,0));
q->setPalette(p);
customPalette = false;
}
if (!customFont) {
q->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
customFont = false;
}
}
void changeEvent(QEvent *event)
{
switch (event->type()) {
case QEvent::FontChange:
customFont = q->font() != QApplication::font();
break;
case QEvent::PaletteChange:
customPalette = true;
break;
default:
break;
}
}
void event(QEvent *event)
{
if (event->type() == QEvent::Show) {
customFont = q->font() != QApplication::font();
}
}
T *q;
bool customPalette : 1;
bool customFont : 1;
};
} // namespace Plasma
#endif

View File

@ -25,19 +25,19 @@
#include <kmimetype.h>
#include "theme.h"
#include "private/themedwidgetinterface_p.h"
#include "svg.h"
#include "theme.h"
namespace Plasma
{
class CheckBoxPrivate
class CheckBoxPrivate : public ThemedWidgetInterface<CheckBox>
{
public:
CheckBoxPrivate(CheckBox *c)
: q(c),
svg(0),
customFont(false)
: ThemedWidgetInterface(c),
svg(0)
{
}
@ -76,24 +76,9 @@ public:
static_cast<QCheckBox*>(q->widget())->setIcon(QIcon(pm));
}
void setPalette()
{
QColor color = Theme::defaultTheme()->color(Theme::TextColor);
QPalette p = q->palette();
p.setColor(QPalette::Normal, QPalette::WindowText, color);
p.setColor(QPalette::Inactive, QPalette::WindowText, color);
q->setPalette(p);
if (!customFont) {
q->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
customFont = false;
}
}
CheckBox *q;
QString imagePath;
QString absImagePath;
Svg *svg;
bool customFont;
};
CheckBox::CheckBox(QGraphicsWidget *parent)
@ -104,9 +89,9 @@ CheckBox::CheckBox(QGraphicsWidget *parent)
connect(native, SIGNAL(toggled(bool)), this, SIGNAL(toggled(bool)));
setWidget(native);
native->setWindowIcon(QIcon());
d->setPalette();
native->setAttribute(Qt::WA_NoSystemBackground);
connect(Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(setPalette()));
d->initTheming();
}
CheckBox::~CheckBox()
@ -190,10 +175,7 @@ bool CheckBox::isChecked() const
void CheckBox::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
}
d->changeEvent(event);
QGraphicsProxyWidget::changeEvent(event);
}

View File

@ -20,31 +20,28 @@
#include "combobox.h"
#include <QPainter>
#include <QApplication>
#include <kcombobox.h>
#include <kmimetype.h>
#include <kiconeffect.h>
#include <kiconloader.h>
#include <kmimetype.h>
#include <plasma/private/style_p.h>
#include <plasma/private/focusindicator_p.h>
#include "applet.h"
#include "theme.h"
#include "framesvg.h"
#include "animator.h"
#include "paintutils.h"
#include "private/style_p.h"
#include "private/focusindicator_p.h"
#include "private/themedwidgetinterface_p.h"
#include "theme.h"
namespace Plasma
{
class ComboBoxPrivate
class ComboBoxPrivate : public ThemedWidgetInterface<ComboBox>
{
public:
ComboBoxPrivate(ComboBox *comboBox)
: q(comboBox),
: ThemedWidgetInterface(comboBox),
background(0),
customFont(false),
underMouse(false)
{
}
@ -56,15 +53,12 @@ public:
void syncActiveRect();
void syncBorders();
ComboBox *q;
FrameSvg *background;
FrameSvg *lineEditBackground;
int animId;
qreal opacity;
QRectF activeRect;
Style::Ptr style;
bool customFont;
bool underMouse;
};
@ -127,6 +121,7 @@ ComboBox::ComboBox(QGraphicsWidget *parent)
new FocusIndicator(this, d->background);
setNativeWidget(new KComboBox);
connect(d->background, SIGNAL(repaintNeeded()), SLOT(syncBorders()));
d->initTheming();
}
ComboBox::~ComboBox()
@ -298,10 +293,7 @@ void ComboBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
void ComboBox::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
}
d->changeEvent(event);
QGraphicsProxyWidget::changeEvent(event);
}

View File

@ -20,18 +20,18 @@
#include "frame.h"
//Qt
#include <QPainter>
#include <QGraphicsSceneResizeEvent>
#include <QWidget>
#include <QDir>
#include <QApplication>
#include <QPainter>
//KDE
#include <kmimetype.h>
//Plasma
#include "plasma/theme.h"
#include "plasma/framesvg.h"
#include "framesvg.h"
#include "private/themedwidgetinterface_p.h"
#include "theme.h"
namespace Plasma
{
@ -39,12 +39,11 @@ namespace Plasma
class FramePrivate
{
public:
FramePrivate(Frame *parent)
: q(parent),
FramePrivate(Frame *parent) : ThemedWidgetInterface<Frame>
: ThemedWidgetInterface(parent),
svg(0),
image(0),
pixmap(0),
customFont(false)
pixmap(0)
{
}
@ -54,9 +53,7 @@ public:
}
void syncBorders();
QFont widgetFont() const;
Frame *q;
FrameSvg *svg;
Frame::Shadow shadow;
QString text;
@ -65,18 +62,8 @@ public:
QString absImagePath;
Svg *image;
QPixmap *pixmap;
bool customFont;
};
QFont FramePrivate::widgetFont() const
{
if (customFont) {
return q->font();
} else {
return Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
}
}
void FramePrivate::syncBorders()
{
//set margins from the normal element
@ -85,7 +72,7 @@ void FramePrivate::syncBorders()
svg->getMargins(left, top, right, bottom);
if (!text.isNull()) {
QFontMetricsF fm(widgetFont());
QFontMetricsF fm(q->font());
top += fm.height();
}
@ -102,6 +89,7 @@ Frame::Frame(QGraphicsWidget *parent)
d->syncBorders();
connect(d->svg, SIGNAL(repaintNeeded()), SLOT(syncBorders()));
d->initTheming();
}
Frame::~Frame()
@ -231,10 +219,10 @@ void Frame::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi
d->svg->paintFrame(painter);
if (!d->text.isNull()) {
QFontMetricsF fm(d->widgetFont());
QFontMetricsF fm(font());
QRectF textRect = d->svg->contentsRect();
textRect.setHeight(fm.height());
painter->setFont(d->widgetFont());
painter->setFont(font());
painter->setPen(Plasma::Theme::defaultTheme()->color(Theme::TextColor));
painter->drawText(textRect, Qt::AlignHCenter|Qt::AlignTop, d->text);
}
@ -264,7 +252,7 @@ QSizeF Frame::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
QSizeF hint = QGraphicsWidget::sizeHint(which, constraint);
if (!d->image && !layout()) {
QFontMetricsF fm(d->widgetFont());
QFontMetricsF fm(font());
qreal left, top, right, bottom;
d->svg->getMargins(left, top, right, bottom);
@ -281,10 +269,7 @@ QSizeF Frame::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
void Frame::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
}
d->changeEvent(event);
QGraphicsWidget::changeEvent(event);
}

View File

@ -20,46 +20,29 @@
#include "groupbox.h"
#include <QGroupBox>
#include <QPainter>
#include <QIcon>
#include <QPainter>
#include <kmimetype.h>
#include "theme.h"
#include "svg.h"
#include "private/themedwidgetinterface_p.h"
#include "theme.h"
namespace Plasma
{
class GroupBoxPrivate
class GroupBoxPrivate : ThemedWidgetInterface<GroupBox>
{
public:
GroupBoxPrivate(GroupBox *groupBox)
:q(groupBox),
customFont(false)
:ThemedWidgetInterface(groupBox)
{
}
~GroupBoxPrivate()
{
}
void setPalette()
{
QColor color = Theme::defaultTheme()->color(Theme::TextColor);
QPalette p = q->palette();
p.setColor(QPalette::Normal, QPalette::WindowText, color);
p.setColor(QPalette::Inactive, QPalette::WindowText, color);
q->setPalette(p);
if (!customFont) {
q->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
customFont = false;
}
}
GroupBox *q;
bool customFont;
};
GroupBox::GroupBox(QGraphicsWidget *parent)
@ -70,7 +53,7 @@ GroupBox::GroupBox(QGraphicsWidget *parent)
setWidget(native);
native->setWindowIcon(QIcon());
native->setAttribute(Qt::WA_NoSystemBackground);
connect(Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(setPalette()));
d->initTheming();
}
GroupBox::~GroupBox()
@ -110,10 +93,7 @@ void GroupBox::resizeEvent(QGraphicsSceneResizeEvent *event)
void GroupBox::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
}
d->changeEvent(event);
QGraphicsProxyWidget::changeEvent(event);
}

View File

@ -27,27 +27,28 @@
#include <QAction>
#include <QApplication>
#include <QPainter>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsView>
#include <QMenu>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <QTextLayout>
#include <kcolorscheme.h>
#include <kdebug.h>
#include <kglobalsettings.h>
#include <kicon.h>
#include <kiconeffect.h>
#include <kiconloader.h>
#include <kicon.h>
#include <kurl.h>
#include <krun.h>
#include <kmimetype.h>
#include <kdebug.h>
#include <kcolorscheme.h>
#include <krun.h>
#include <kurl.h>
#include <plasma/animator.h>
#include <plasma/animations/animation.h>
#include <plasma/paintutils.h>
#include <plasma/theme.h>
#include "animator.h"
#include "animations/animation.h"
#include "paintutils.h"
#include "private/themedwidgetinterface_p.h"
#include "theme.h"
#include "svg.h"
@ -99,8 +100,7 @@ void IconHoverAnimation::setAnimation(QPropertyAnimation *animation)
}
IconWidgetPrivate::IconWidgetPrivate(IconWidget *i)
: ActionWidgetInterface<IconWidget>(i),
q(i),
: ActionWidgetInterface(i),
iconSvg(0),
hoverAnimation(new IconHoverAnimation(q)),
iconSize(48, 48),
@ -114,9 +114,9 @@ IconWidgetPrivate::IconWidgetPrivate(IconWidget *i)
iconSvgElementChanged(false),
invertLayout(false),
drawBg(false),
textBgCustomized(false),
customFont(false)
textBgCustomized(false)
{
d->initTheming();
}
IconWidgetPrivate::~IconWidgetPrivate()
@ -159,15 +159,6 @@ void IconWidgetPrivate::iconConfigChanged()
}
}
QFont IconWidgetPrivate::widgetFont() const
{
if (customFont) {
return q->font();
} else {
return Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
}
}
IconAction::IconAction(IconWidget *icon, QAction *action)
: m_icon(icon),
m_action(action),
@ -548,7 +539,7 @@ QSizeF IconWidgetPrivate::displaySizeHint(const QStyleOptionGraphicsItem *option
//allow only five lines of text
const qreal maxHeight =
numDisplayLines * QFontMetrics(widgetFont()).lineSpacing();
numDisplayLines * QFontMetrics(q->font()).lineSpacing();
// To compute the nominal size for the label + info, we'll just append
// the information string to the label
@ -558,7 +549,7 @@ QSizeF IconWidgetPrivate::displaySizeHint(const QStyleOptionGraphicsItem *option
QTextLayout layout;
setLayoutOptions(layout, option, q->orientation());
layout.setFont(widgetFont());
layout.setFont(q->font());
QSizeF size = layoutText(layout, option, label, QSizeF(textWidth, maxHeight));
return addMargin(size, TextMargin);
@ -1520,7 +1511,7 @@ QSizeF IconWidget::sizeFromIconSize(const qreal iconWidth) const
return d->addMargin(QSizeF(iconWidth, iconWidth), IconWidgetPrivate::ItemMargin);
}
QFontMetricsF fm(d->widgetFont());
QFontMetricsF fm(font());
qreal width = 0;
if (d->orientation == Qt::Vertical) {
@ -1572,10 +1563,7 @@ QSizeF IconWidget::sizeFromIconSize(const qreal iconWidth) const
void IconWidget::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
}
d->changeEvent(event);
QGraphicsWidget::changeEvent(event);
}

View File

@ -20,32 +20,31 @@
#include "label.h"
#include <QApplication>
#include <QLabel>
#include <QPainter>
#include <QDir>
#include <QStyleOptionGraphicsItem>
#include <QGraphicsSceneMouseEvent>
#include <QLabel>
#include <QMenu>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <kmimetype.h>
#include <kglobalsettings.h>
#include <kcolorscheme.h>
#include <kglobalsettings.h>
#include <kmimetype.h>
#include "theme.h"
#include "private/themedwidgetinterface_p.h"
#include "svg.h"
#include "theme.h"
namespace Plasma
{
class LabelPrivate
class LabelPrivate : public ThemedWidgetInterface<Label>
{
public:
LabelPrivate(Label *label)
: q(label),
: ThemedWidgetInterface(label),
svg(0),
textSelectable(false),
customFont(false),
customPalette(false)
textSelectable(false)
{
}
@ -84,36 +83,10 @@ public:
static_cast<QLabel*>(q->widget())->setPixmap(pm);
}
void setPalette()
{
if (customPalette) {
return;
}
QColor color = Theme::defaultTheme()->color(Theme::TextColor);
QPalette p = q->palette();
p.setColor(QPalette::Normal, QPalette::WindowText, color);
p.setColor(QPalette::Inactive, QPalette::WindowText, color);
color.setAlphaF(0.6);
p.setColor(QPalette::Disabled, QPalette::WindowText, color);
p.setColor(QPalette::Normal, QPalette::Link, Theme::defaultTheme()->color(Theme::LinkColor));
p.setColor(QPalette::Normal, QPalette::LinkVisited, Theme::defaultTheme()->color(Theme::VisitedLinkColor));
q->setPalette(p);
if (!customFont) {
q->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
customFont = false;
}
}
Label *q;
QString imagePath;
QString absImagePath;
Svg *svg;
bool textSelectable : 1;
bool customFont : 1;
bool customPalette : 1;
};
Label::Label(QGraphicsWidget *parent)
@ -125,14 +98,11 @@ Label::Label(QGraphicsWidget *parent)
connect(native, SIGNAL(linkActivated(QString)), this, SIGNAL(linkActivated(QString)));
connect(native, SIGNAL(linkHovered(QString)), this, SIGNAL(linkHovered(QString)));
connect(Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(setPalette()));
connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), this, SLOT(setPalette()));
native->setAttribute(Qt::WA_NoSystemBackground);
native->setWordWrap(true);
setWidget(native);
native->setWindowIcon(QIcon());
d->setPalette();
d->initTheming();
}
Label::~Label()
@ -338,30 +308,13 @@ void Label::paint(QPainter *painter,
void Label::changeEvent(QEvent *event)
{
switch (event->type()) {
case QEvent::FontChange:
if (font() != QApplication::font()) {
d->customFont = true;
}
break;
case QEvent::PaletteChange:
d->customPalette = true;
break;
default:
break;
}
d->changeEvent(event);
QGraphicsProxyWidget::changeEvent(event);
}
bool Label::event(QEvent *event)
{
if (event->type() == QEvent::Show && font() != QApplication::font()) {
d->customFont = true;
}
d->event(event);
return QGraphicsProxyWidget::event(event);
}

View File

@ -19,20 +19,19 @@
#include "lineedit.h"
#include <QPainter>
#include <QIcon>
#include <QGraphicsSceneResizeEvent>
#include <QIcon>
#include <QPainter>
#include <klineedit.h>
#include <kmimetype.h>
#include <plasma/private/style_p.h>
#include <plasma/private/focusindicator_p.h>
#include "applet.h"
#include "theme.h"
#include "svg.h"
#include "framesvg.h"
#include "private/style_p.h"
#include "private/focusindicator_p.h"
#include "private/themedwidgetinterface_p.h"
#include "theme.h"
namespace Plasma
{
@ -40,9 +39,8 @@ namespace Plasma
class LineEditPrivate
{
public:
LineEditPrivate(LineEdit *lineEdit)
:q(lineEdit),
customFont(false)
LineEditPrivate(LineEdit *lineEdit) : ThemedWidgetInterface<Label>
: ThemedWidgetInterface(lineEdit)
{
}
@ -50,25 +48,9 @@ public:
{
}
void setPalette()
{
QColor color = Theme::defaultTheme()->color(Theme::ButtonTextColor);
QPalette p = q->palette();
p.setColor(QPalette::Normal, QPalette::Text, color);
p.setColor(QPalette::Inactive, QPalette::Text, color);
q->setPalette(p);
if (!customFont) {
q->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
customFont = false;
}
}
LineEdit *q;
Plasma::Style::Ptr style;
Plasma::FrameSvg *background;
bool customFont;
};
LineEdit::LineEdit(QGraphicsWidget *parent)
@ -82,7 +64,6 @@ LineEdit::LineEdit(QGraphicsWidget *parent)
new FocusIndicator(this, d->background);
setNativeWidget(new KLineEdit);
connect(Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(setPalette()));
}
LineEdit::~LineEdit()
@ -149,8 +130,7 @@ void LineEdit::setNativeWidget(KLineEdit *nativeWidget)
nativeWidget->setAttribute(Qt::WA_NoSystemBackground);
nativeWidget->setStyle(d->style.data());
d->setPalette();
d->initTheming();
}
KLineEdit *LineEdit::nativeWidget() const
@ -180,10 +160,7 @@ void LineEdit::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
void LineEdit::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
}
d->changEvent();
QGraphicsProxyWidget::changeEvent(event);
}

View File

@ -20,27 +20,24 @@
#include "pushbutton.h"
#include <QStyleOptionGraphicsItem>
#include <QPainter>
#include <QDir>
#include <QApplication>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <QWeakPointer>
#include <QPropertyAnimation>
#include <kicon.h>
#include <kiconeffect.h>
#include <kmimetype.h>
#include <kpushbutton.h>
#include "theme.h"
#include "svg.h"
#include "framesvg.h"
#include "animator.h"
#include "animations/animation.h"
#include "framesvg.h"
#include "paintutils.h"
#include "private/actionwidgetinterface_p.h"
#include <plasma/private/focusindicator_p.h>
#include "animations/animation.h"
#include "private/focusindicator_p.h"
#include "private/themedwidgetinterface_p.h"
#include "theme.h"
namespace Plasma
{
@ -50,11 +47,9 @@ class PushButtonPrivate : public ActionWidgetInterface<PushButton>
public:
PushButtonPrivate(PushButton *pushButton)
: ActionWidgetInterface<PushButton>(pushButton),
q(pushButton),
background(0),
fadeIn(false),
svg(0),
customFont(false)
svg(0)
{
}
@ -133,7 +128,6 @@ public:
QString absImagePath;
Svg *svg;
QString svgElement;
bool customFont;
};
void PushButtonPrivate::syncActiveRect()
@ -200,6 +194,7 @@ PushButton::PushButton(QGraphicsWidget *parent)
setAcceptHoverEvents(true);
connect(d->background, SIGNAL(repaintNeeded()), SLOT(syncBorders()));
d->initTheming();
}
PushButton::~PushButton()
@ -428,14 +423,7 @@ void PushButton::paint(QPainter *painter,
}
}
QFont widgetFont;
if (d->customFont) {
widgetFont = font();
} else {
widgetFont = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
}
QFontMetricsF fm(widgetFont);
QFontMetricsF fm(font());
// If the height is too small increase the Height of the button to shall the whole text #192988
if (rect.height() < fm.height()) {
rect.setHeight(fm.height());
@ -451,7 +439,7 @@ void PushButton::paint(QPainter *painter,
QPainter p(&bufferPixmap);
p.setPen(painter->pen());
p.setFont(widgetFont);
p.setFont(font());
// Create the alpha gradient for the fade out effect
QLinearGradient alphaGradient(0, 0, 1, 0);
@ -473,7 +461,7 @@ void PushButton::paint(QPainter *painter,
painter->drawPixmap(rect.topLeft(), bufferPixmap);
} else {
painter->setFont(widgetFont);
painter->setFont(font());
painter->drawText(rect, Qt::AlignCenter|Qt::TextShowMnemonic, nativeWidget()->text());
}
}
@ -499,10 +487,7 @@ void PushButton::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
void PushButton::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
}
d->changeEvent(event);
QGraphicsProxyWidget::changeEvent(event);
}

View File

@ -19,25 +19,25 @@
#include "radiobutton.h"
#include <QRadioButton>
#include <QPainter>
#include <QDir>
#include <QPainter>
#include <QRadioButton>
#include <kmimetype.h>
#include "theme.h"
#include "private/themedwidgetinterface_p.h"
#include "svg.h"
#include "theme.h"
namespace Plasma
{
class RadioButtonPrivate
class RadioButtonPrivate : public ThemedWidgetInterface<RadioButton>
{
public:
RadioButtonPrivate(RadioButton *radio)
: q(radio),
svg(0),
customFont(false)
: ThemedWidgetInterface(radio),
svg(0)
{
}
@ -66,26 +66,9 @@ public:
static_cast<QRadioButton*>(q->widget())->setIcon(QIcon(pm));
}
void setPalette()
{
QColor color = Theme::defaultTheme()->color(Theme::TextColor);
QPalette p = q->palette();
p.setColor(QPalette::Normal, QPalette::Text, color);
p.setColor(QPalette::Inactive, QPalette::Text, color);
q->setPalette(p);
if (!customFont) {
q->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
customFont = false;
}
}
RadioButton *q;
QString imagePath;
QString absImagePath;
Svg *svg;
bool customFont;
};
RadioButton::RadioButton(QGraphicsWidget *parent)
@ -97,7 +80,7 @@ RadioButton::RadioButton(QGraphicsWidget *parent)
setWidget(native);
native->setWindowIcon(QIcon());
native->setAttribute(Qt::WA_NoSystemBackground);
connect(Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(setPalette()));
d->initTheming();
}
RadioButton::~RadioButton()
@ -181,10 +164,7 @@ bool RadioButton::isChecked() const
void RadioButton::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
}
d->changeEvent(event);
QGraphicsProxyWidget::changeEvent(event);
}

View File

@ -20,29 +20,28 @@
#include "spinbox.h"
#include <QApplication>
#include <QPainter>
#include <QStyleOptionSpinBox>
#include <knuminput.h>
#include <kmimetype.h>
#include <knuminput.h>
#include <plasma/applet.h>
#include <plasma/theme.h>
#include <plasma/framesvg.h>
#include <plasma/private/style_p.h>
#include <plasma/private/focusindicator_p.h>
#include "applet.h"
#include "framesvg.h"
#include "private/focusindicator_p.h"
#include "private/style_p.h"
#include "private/themedwidgetinterface_p.h"
#include "theme.h"
namespace Plasma
{
class SpinBoxPrivate
class SpinBoxPrivate : public ThemedWidgetInterface<SpinBox>
{
public:
SpinBoxPrivate(SpinBox *spinBox)
: q(spinBox),
focusIndicator(0),
customFont(false)
: ThemedWidgetInterface(spinBox),
focusIndicator(0)
{
}
@ -50,30 +49,9 @@ public:
{
}
void setPalette()
{
QColor color = Theme::defaultTheme()->color(Theme::ButtonTextColor);
QPalette p = q->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));
q->setPalette(p);
if (!customFont) {
q->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
customFont = false;
}
}
SpinBox *q;
Plasma::Style::Ptr style;
Plasma::FrameSvg *background;
FocusIndicator *focusIndicator;
bool customFont;
};
SpinBox::SpinBox(QGraphicsWidget *parent)
@ -99,8 +77,7 @@ SpinBox::SpinBox(QGraphicsWidget *parent)
d->style = Plasma::Style::sharedStyle();
native->setStyle(d->style.data());
d->setPalette();
connect(Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(setPalette()));
d->initTheming();
}
SpinBox::~SpinBox()
@ -161,10 +138,7 @@ KIntSpinBox *SpinBox::nativeWidget() const
void SpinBox::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
}
d->changeEvent(event);
QGraphicsProxyWidget::changeEvent(event);
}

View File

@ -21,22 +21,23 @@
#include <QGraphicsLinearLayout>
#include <QGraphicsLayoutItem>
#include <QString>
#include <QGraphicsScene>
#include <QGraphicsProxyWidget>
#include <QGraphicsScene>
#include <QGraphicsSceneWheelEvent>
#include <QIcon>
#include <QStyleOption>
#include <QMenu>
#include <QPainter>
#include <QParallelAnimationGroup>
#include <QString>
#include <QStyleOption>
#include <kdebug.h>
#include <plasma/animator.h>
#include <plasma/animations/animation.h>
#include <plasma/theme.h>
#include "animator.h"
#include "animations/animation.h"
#include "private/nativetabbar_p.h"
#include "private/themedwidgetinterface_p.h"
#include "theme.h"
namespace Plasma
{
@ -67,17 +68,16 @@ public:
NativeTabBar *native;
};
class TabBarPrivate
class TabBarPrivate : public ThemedWidgetInterface<TabBar>
{
public:
TabBarPrivate(TabBar *parent)
: q(parent),
: ThemedWidgetInterface(parent),
tabProxy(0),
currentIndex(0),
tabWidgetMode(true),
oldPageAnimId(-1),
newPageAnimId(-1),
customFont(false),
tabBarShown(true)
{
}
@ -91,9 +91,7 @@ public:
void slidingNewPageCompleted();
void slidingOldPageCompleted();
void shapeChanged(const KTabBar::Shape shape);
void setPalette();
TabBar *q;
TabBarProxy *tabProxy;
QList<QGraphicsWidget *> pages;
QGraphicsWidget *emptyTabBarSpacer;
@ -110,7 +108,6 @@ public:
Animation *oldPageAnim;
Animation *newPageAnim;
QParallelAnimationGroup *animGroup;
bool customFont;
bool tabBarShown;
QWeakPointer<QGraphicsWidget> firstPositionWidget;
QWeakPointer<QGraphicsWidget> lastPositionWidget;
@ -221,26 +218,6 @@ void TabBarPrivate::shapeChanged(const QTabBar::Shape shape)
tabProxy->setPreferredSize(tabProxy->native->sizeHint());
}
void TabBarPrivate::setPalette()
{
QColor color = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
QPalette p = q->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));
q->setPalette(p);
if (!customFont) {
q->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
customFont = false;
}
}
TabBar::TabBar(QGraphicsWidget *parent)
: QGraphicsWidget(parent),
d(new TabBarPrivate(this))
@ -286,8 +263,7 @@ TabBar::TabBar(QGraphicsWidget *parent)
this, SLOT(shapeChanged(QTabBar::Shape)));
connect(d->newPageAnim, SIGNAL(finished()), this, SLOT(slidingNewPageCompleted()));
connect(d->oldPageAnim, SIGNAL(finished()), this, SLOT(slidingOldPageCompleted()));
connect(Theme::defaultTheme(), SIGNAL(themeChanged()),
this, SLOT(setPalette()));
d->initTheming();
}
TabBar::~TabBar()
@ -625,10 +601,7 @@ void TabBar::wheelEvent(QGraphicsSceneWheelEvent * event)
void TabBar::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
}
d->changeEvent(event);
QGraphicsWidget::changeEvent(event);
}

View File

@ -19,31 +19,31 @@
#include "textbrowser.h"
#include <QPainter>
#include <QScrollBar>
#include <QGraphicsSceneWheelEvent>
#include <QMenu>
#include <QPainter>
#include <QScrollBar>
#include <kmimetype.h>
#include <ktextbrowser.h>
#include "plasma/theme.h"
#include "plasma/svg.h"
#include "svg.h"
#include "theme.h"
#include "private/style_p.h"
#include "private/themedwidgetinterface_p.h"
namespace Plasma
{
class TextBrowserPrivate
class TextBrowserPrivate : public ThemedWidgetInterface<TextBrowser>
{
public:
TextBrowserPrivate(TextBrowser *browser)
: q(browser),
: ThemedWidgetInterface(browser),
native(0),
savedMinimumHeight(0),
savedMaximumHeight(QWIDGETSIZE_MAX),
wasNotFixed(true),
customFont(false)
wasNotFixed(true)
{
}
@ -68,33 +68,11 @@ public:
}
}
void setPalette()
{
QColor color = Theme::defaultTheme()->color(Theme::TextColor);
QPalette p = q->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));
q->setPalette(p);
if (!customFont) {
q->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
customFont = false;
}
}
TextBrowser *q;
KTextBrowser *native;
Plasma::Style::Ptr style;
int savedMinimumHeight;
int savedMaximumHeight;
bool wasNotFixed;
bool customFont;
};
TextBrowser::TextBrowser(QGraphicsWidget *parent)
@ -115,8 +93,7 @@ TextBrowser::TextBrowser(QGraphicsWidget *parent)
d->style = Plasma::Style::sharedStyle();
native->verticalScrollBar()->setStyle(d->style.data());
native->horizontalScrollBar()->setStyle(d->style.data());
connect(Theme::defaultTheme(), SIGNAL(themeChanged()),
this, SLOT(setPalette()));
d->initTheming();
}
TextBrowser::~TextBrowser()
@ -206,10 +183,7 @@ void TextBrowser::wheelEvent(QGraphicsSceneWheelEvent *event)
void TextBrowser::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
}
d->changeEvent(event);
QGraphicsProxyWidget::changeEvent(event);
}

View File

@ -19,28 +19,28 @@
#include "textedit.h"
#include <QGraphicsSceneContextMenuEvent>
#include <QMenu>
#include <QPainter>
#include <QScrollBar>
#include <QMenu>
#include <QGraphicsSceneContextMenuEvent>
#include <kmimetype.h>
#include <ktextedit.h>
#include "applet.h"
#include "theme.h"
#include "svg.h"
#include "private/style_p.h"
#include "private/themedwidgetinterface_p.h"
#include "svg.h"
#include "theme.h"
namespace Plasma
{
class TextEditPrivate
class TextEditPrivate : public ThemedWidgetInterface<TextEdit>
{
public:
TextEditPrivate(TextEdit *textEdit)
: q(textEdit),
customFont(false)
: ThemedWidgetInterface(textEdit)
{
}
@ -48,39 +48,16 @@ public:
{
}
void setPalette()
{
QColor color = Theme::defaultTheme()->color(Theme::TextColor);
QPalette p = q->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));
q->setPalette(p);
if (!customFont) {
q->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
customFont = false;
}
}
TextEdit *q;
Plasma::Style::Ptr style;
bool customFont;
};
TextEdit::TextEdit(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new TextEditPrivate(this))
{
d->style = Plasma::Style::sharedStyle();
setNativeWidget(new KTextEdit);
connect(Theme::defaultTheme(), SIGNAL(themeChanged()),
this, SLOT(setPalette()));
d->style = Plasma::Style::sharedStyle();
d->initTheming();
}
TextEdit::~TextEdit()
@ -178,10 +155,7 @@ void TextEdit::resizeEvent(QGraphicsSceneResizeEvent *event)
void TextEdit::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
}
d->changeEvent(event);
QGraphicsProxyWidget::changeEvent(event);
}

View File

@ -19,24 +19,23 @@
#include "toolbutton.h"
#include <QStyleOptionGraphicsItem>
#include <QPainter>
#include <QDir>
#include <QToolButton>
#include <QApplication>
#include <QPainter>
#include <QPropertyAnimation>
#include <QStyleOptionGraphicsItem>
#include <QToolButton>
#include <kcolorutils.h>
#include <kicon.h>
#include <kiconeffect.h>
#include <kmimetype.h>
#include <kcolorutils.h>
#include "theme.h"
#include "svg.h"
#include "framesvg.h"
#include "animator.h"
#include "framesvg.h"
#include "paintutils.h"
#include "private/actionwidgetinterface_p.h"
#include "private/themedwidgetinterface_p.h"
#include "theme.h"
namespace Plasma
{
@ -45,11 +44,9 @@ class ToolButtonPrivate : public ActionWidgetInterface<ToolButton>
{
public:
ToolButtonPrivate(ToolButton *toolButton)
: ActionWidgetInterface<ToolButton>(toolButton),
q(toolButton),
: ActionWidgetInterface(toolButton),
background(0),
svg(0),
customFont(false),
underMouse(false)
{
}
@ -116,7 +113,6 @@ public:
QString absImagePath;
Svg *svg;
QString svgElement;
bool customFont;
bool underMouse;
};
@ -184,6 +180,8 @@ ToolButton::ToolButton(QGraphicsWidget *parent)
d->animation = new QPropertyAnimation(this, "animationUpdate");
d->animation->setStartValue(0);
d->animation->setEndValue(1);
d->initTheming();
}
ToolButton::~ToolButton()
@ -380,7 +378,7 @@ void ToolButton::paint(QPainter *painter,
buttonOpt.palette.setColor(QPalette::ButtonText, Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
}
buttonOpt.font = d->customFont ? font() : Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
buttonOpt.font = font();
painter->setFont(buttonOpt.font);
button->style()->drawControl(QStyle::CE_ToolButtonLabel, &buttonOpt, painter, button);
@ -431,9 +429,9 @@ void ToolButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
void ToolButton::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
} else if (event->type() == QEvent::EnabledChange && !isEnabled()) {
d->changeEvent(event);
if (event->type() == QEvent::EnabledChange && !isEnabled()) {
d->underMouse = false;
}

View File

@ -57,7 +57,6 @@ public:
};
WebView::WebView(QGraphicsItem *parent)
: QGraphicsWidget(parent),
d(new WebViewPrivate(this))
{