always use plasma::theme font, unless somebody call setFont on the

widget                                                                                
round two: sync the native widgets fonts with the plasma::theme font,                 
unless setFont was called

svn path=/trunk/KDE/kdelibs/; revision=1023050
This commit is contained in:
Marco Martin 2009-09-13 19:18:29 +00:00
parent 1730d86a73
commit 67515c758a
20 changed files with 270 additions and 31 deletions

View File

@ -36,7 +36,8 @@ class CheckBoxPrivate
public:
CheckBoxPrivate(CheckBox *c)
: q(c),
svg(0)
svg(0),
customFont(false)
{
}
@ -83,12 +84,16 @@ public:
p.setColor(QPalette::Normal, QPalette::WindowText, color);
p.setColor(QPalette::Inactive, QPalette::WindowText, color);
native->setPalette(p);
if (!customFont) {
q->nativeWidget()->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
}
}
CheckBox *q;
QString imagePath;
QString absImagePath;
Svg *svg;
bool customFont;
};
CheckBox::CheckBox(QGraphicsWidget *parent)
@ -182,6 +187,16 @@ bool CheckBox::isChecked() const
return static_cast<QCheckBox*>(widget())->isChecked();
}
void CheckBox::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
nativeWidget()->setFont(font());
}
QGraphicsProxyWidget::changeEvent(event);
}
} // namespace Plasma
#include <checkbox.moc>

View File

@ -109,6 +109,7 @@ Q_SIGNALS:
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void changeEvent(QEvent *event);
private:
Q_PRIVATE_SLOT(d, void setPalette())

View File

@ -307,6 +307,7 @@ void ComboBox::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
nativeWidget()->setFont(font());
}
QGraphicsProxyWidget::changeEvent(event);

View File

@ -33,22 +33,42 @@ namespace Plasma
class GroupBoxPrivate
{
public:
GroupBoxPrivate()
GroupBoxPrivate(GroupBox *groupBox)
:q(groupBox),
customFont(false)
{
}
~GroupBoxPrivate()
{
}
void setPalette()
{
QGroupBox *native = q->nativeWidget();
QColor color = Theme::defaultTheme()->color(Theme::TextColor);
QPalette p = native->palette();
p.setColor(QPalette::Normal, QPalette::WindowText, color);
p.setColor(QPalette::Inactive, QPalette::WindowText, color);
native->setPalette(p);
if (!customFont) {
q->nativeWidget()->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
}
}
GroupBox *q;
bool customFont;
};
GroupBox::GroupBox(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new GroupBoxPrivate)
d(new GroupBoxPrivate(this))
{
QGroupBox *native = new QGroupBox;
setWidget(native);
native->setAttribute(Qt::WA_NoSystemBackground);
connect(Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(setPalette()));
}
GroupBox::~GroupBox()
@ -86,6 +106,16 @@ void GroupBox::resizeEvent(QGraphicsSceneResizeEvent *event)
QGraphicsProxyWidget::resizeEvent(event);
}
void GroupBox::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
nativeWidget()->setFont(font());
}
QGraphicsProxyWidget::changeEvent(event);
}
} // namespace Plasma
#include <groupbox.moc>

View File

@ -82,9 +82,11 @@ Q_SIGNALS:
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void changeEvent(QEvent *event);
private:
GroupBoxPrivate * const d;
Q_PRIVATE_SLOT(d, void setPalette())
};
} // namespace Plasma

View File

@ -40,7 +40,8 @@ class LabelPrivate
public:
LabelPrivate(Label *label)
: q(label),
svg(0)
svg(0),
customFont(false)
{
}
@ -90,7 +91,10 @@ public:
p.setColor(QPalette::Normal, QPalette::Link, Theme::defaultTheme()->color(Theme::LinkColor));
p.setColor(QPalette::Normal, QPalette::LinkVisited, Theme::defaultTheme()->color(Theme::VisitedLinkColor));
native->setPalette(p);
native->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
if (!customFont) {
q->nativeWidget()->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
}
}
Label *q;
@ -98,6 +102,7 @@ public:
QString absImagePath;
Svg *svg;
bool textSelectable;
bool customFont;
};
Label::Label(QGraphicsWidget *parent)
@ -286,6 +291,16 @@ void Label::paint(QPainter *painter,
}
}
void Label::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
nativeWidget()->setFont(font());
}
QGraphicsProxyWidget::changeEvent(event);
}
} // namespace Plasma
#include <label.moc>

View File

@ -150,6 +150,7 @@ protected:
void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget);
void changeEvent(QEvent *event);
private:
Q_PRIVATE_SLOT(d, void setPalette())

View File

@ -36,7 +36,8 @@ class LineEditPrivate
{
public:
LineEditPrivate(LineEdit *lineEdit)
:q(lineEdit)
:q(lineEdit),
customFont(false)
{
}
@ -54,10 +55,15 @@ public:
p.setColor(QPalette::Inactive, QPalette::Text, color);
native->setPalette(p);
native->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
if (!customFont) {
q->nativeWidget()->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
}
}
LineEdit *q;
Plasma::Style::Ptr style;
bool customFont;
};
LineEdit::LineEdit(QGraphicsWidget *parent)
@ -118,6 +124,16 @@ KLineEdit *LineEdit::nativeWidget() const
return static_cast<KLineEdit*>(widget());
}
void LineEdit::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
nativeWidget()->setFont(font());
}
QGraphicsProxyWidget::changeEvent(event);
}
} // namespace Plasma
#include <lineedit.moc>

View File

@ -91,6 +91,9 @@ public:
*/
KLineEdit *nativeWidget() const;
protected:
void changeEvent(QEvent *event);
Q_SIGNALS:
void editingFinished();
void returnPressed();

View File

@ -34,9 +34,10 @@ namespace Plasma
class RadioButtonPrivate
{
public:
RadioButtonPrivate(RadioButton *w)
: q(w),
svg(0)
RadioButtonPrivate(RadioButton *radio)
: q(radio),
svg(0),
customFont(false)
{
}
@ -45,40 +46,47 @@ public:
delete svg;
}
void setPixmap()
void setPixmap(RadioButton *q)
{
if (imagePath.isEmpty()) {
delete svg;
svg = 0;
return;
}
KMimeType::Ptr mime = KMimeType::findByPath(absImagePath);
QPixmap pm(q->size().toSize());
if (mime->is("image/svg+xml") || mime->is("image/svg+xml-compressed")) {
if (!svg || svg->imagePath() != imagePath) {
delete svg;
svg = new Svg();
svg->setImagePath(imagePath);
QObject::connect(svg, SIGNAL(repaintNeeded()), q, SLOT(setPixmap()));
}
if (mime->is("image/svg+xml")) {
svg = new Svg();
QPainter p(&pm);
svg->paint(&p, pm.rect());
} else {
delete svg;
svg = 0;
pm = QPixmap(absImagePath);
}
static_cast<QRadioButton*>(q->widget())->setIcon(QIcon(pm));
}
void setPalette()
{
QRadioButton *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));
if (!customFont) {
q->nativeWidget()->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
}
}
RadioButton *q;
QString imagePath;
QString absImagePath;
Svg *svg;
bool customFont;
};
RadioButton::RadioButton(QGraphicsWidget *parent)
@ -89,6 +97,7 @@ RadioButton::RadioButton(QGraphicsWidget *parent)
connect(native, SIGNAL(toggled(bool)), this, SIGNAL(toggled(bool)));
setWidget(native);
native->setAttribute(Qt::WA_NoSystemBackground);
connect(Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(setPalette()));
}
RadioButton::~RadioButton()
@ -131,7 +140,7 @@ void RadioButton::setImage(const QString &path)
d->absImagePath = Theme::defaultTheme()->imagePath(path);
}
d->setPixmap();
d->setPixmap(this);
}
QString RadioButton::image() const
@ -156,7 +165,7 @@ QRadioButton *RadioButton::nativeWidget() const
void RadioButton::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap();
d->setPixmap(this);
QGraphicsProxyWidget::resizeEvent(event);
}
@ -170,6 +179,16 @@ bool RadioButton::isChecked() const
return static_cast<QRadioButton*>(widget())->isChecked();
}
void RadioButton::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
nativeWidget()->setFont(font());
}
QGraphicsProxyWidget::changeEvent(event);
}
} // namespace Plasma
#include <radiobutton.moc>

View File

@ -109,11 +109,13 @@ Q_SIGNALS:
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void changeEvent(QEvent *event);
private:
Q_PRIVATE_SLOT(d, void setPixmap())
RadioButtonPrivate * const d;
Q_PRIVATE_SLOT(d, void setPalette())
};
} // namespace Plasma

View File

@ -118,7 +118,6 @@ public:
*/
QScrollBar *nativeWidget() const;
public Q_SLOTS:
/**
* Sets the current value for the ScrollBar

View File

@ -35,7 +35,8 @@ class SpinBoxPrivate
{
public:
SpinBoxPrivate(SpinBox *spinBox)
: q(spinBox)
: q(spinBox),
customFont(false)
{
}
@ -56,11 +57,15 @@ public:
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));
if (!customFont) {
q->nativeWidget()->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
}
}
SpinBox *q;
Plasma::Style::Ptr style;
bool customFont;
};
SpinBox::SpinBox(QGraphicsWidget *parent)
@ -138,6 +143,16 @@ KIntSpinBox *SpinBox::nativeWidget() const
return static_cast<KIntSpinBox*>(widget());
}
void SpinBox::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
nativeWidget()->setFont(font());
}
QGraphicsProxyWidget::changeEvent(event);
}
} // namespace Plasma
#include <spinbox.moc>

View File

@ -84,6 +84,8 @@ public:
*/
KIntSpinBox *nativeWidget() const;
protected:
void changeEvent(QEvent *event);
public Q_SLOTS:
/**

View File

@ -32,6 +32,7 @@
#include <kdebug.h>
#include <plasma/animator.h>
#include <plasma/theme.h>
#include "private/nativetabbar_p.h"
@ -75,7 +76,8 @@ public:
oldPage(0),
newPage(0),
oldPageAnimId(-1),
newPageAnimId(-1)
newPageAnimId(-1),
customFont(true)
{
}
@ -86,6 +88,7 @@ public:
void updateTabWidgetMode();
void slidingCompleted(QGraphicsItem *item);
void shapeChanged(const KTabBar::Shape shape);
void setPalette();
TabBar *q;
TabBarProxy *tabProxy;
@ -100,6 +103,7 @@ public:
QGraphicsWidget *newPage;
int oldPageAnimId;
int newPageAnimId;
bool customFont;
};
void TabBarPrivate::updateTabWidgetMode()
@ -185,6 +189,26 @@ void TabBarPrivate::shapeChanged(const QTabBar::Shape shape)
tabProxy->setPreferredSize(tabProxy->native->sizeHint());
}
void TabBarPrivate::setPalette()
{
QTabBar *native = q->nativeWidget();
QColor color = Plasma::Theme::defaultTheme()->color(Plasma::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);
if (!customFont) {
q->nativeWidget()->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
}
}
TabBar::TabBar(QGraphicsWidget *parent)
: QGraphicsWidget(parent),
d(new TabBarPrivate(this))
@ -213,6 +237,8 @@ TabBar::TabBar(QGraphicsWidget *parent)
this, SLOT(shapeChanged(QTabBar::Shape)));
connect(Plasma::Animator::self(), SIGNAL(movementFinished(QGraphicsItem*)),
this, SLOT(slidingCompleted(QGraphicsItem*)));
connect(Theme::defaultTheme(), SIGNAL(themeChanged()),
this, SLOT(setPalette()));
}
TabBar::~TabBar()
@ -509,6 +535,16 @@ void TabBar::wheelEvent(QGraphicsSceneWheelEvent * event)
//Still here for binary compatibility
}
void TabBar::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
nativeWidget()->setFont(font());
}
QGraphicsWidget::changeEvent(event);
}
} // namespace Plasma
#include <tabbar.moc>

View File

@ -125,7 +125,7 @@ public:
* @since 4.4
*/
QGraphicsLayoutItem *takeTab(int index);
/**
* Returns the contents of a page
*
@ -226,12 +226,14 @@ Q_SIGNALS:
protected:
void wheelEvent(QGraphicsSceneWheelEvent *event);
void resizeEvent(QGraphicsSceneResizeEvent * event);
void changeEvent(QEvent *event);
private:
TabBarPrivate * const d;
Q_PRIVATE_SLOT(d, void slidingCompleted(QGraphicsItem *item))
Q_PRIVATE_SLOT(d, void shapeChanged(const QTabBar::Shape shape))
Q_PRIVATE_SLOT(d, void setPalette())
};
} // namespace Plasma

View File

@ -41,7 +41,8 @@ public:
native(0),
savedMinimumHeight(0),
savedMaximumHeight(QWIDGETSIZE_MAX),
wasNotFixed(true)
wasNotFixed(true),
customFont(false)
{
}
@ -66,6 +67,25 @@ public:
}
}
void setPalette()
{
KTextBrowser *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);
if (!customFont) {
q->nativeWidget()->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
}
}
TextBrowser *q;
KTextBrowser *native;
@ -73,6 +93,7 @@ public:
int savedMinimumHeight;
int savedMaximumHeight;
bool wasNotFixed;
bool customFont;
};
TextBrowser::TextBrowser(QGraphicsWidget *parent)
@ -91,6 +112,8 @@ 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()));
}
TextBrowser::~TextBrowser()
@ -165,6 +188,16 @@ void TextBrowser::wheelEvent(QGraphicsSceneWheelEvent *event)
}
}
void TextBrowser::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
nativeWidget()->setFont(font());
}
QGraphicsProxyWidget::changeEvent(event);
}
} // namespace Plasma
#include <textbrowser.moc>

View File

@ -100,11 +100,13 @@ Q_SIGNALS:
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void wheelEvent(QGraphicsSceneWheelEvent *event);
void changeEvent(QEvent *event);
private:
TextBrowserPrivate * const d;
Q_PRIVATE_SLOT(d, void setFixedHeight())
Q_PRIVATE_SLOT(d, void setPalette())
};
} // namespace Plasma

View File

@ -35,12 +35,43 @@ namespace Plasma
class TextEditPrivate
{
public:
TextEditPrivate(TextEdit *textEdit)
: q(textEdit),
customFont(false)
{
}
~TextEditPrivate()
{
}
void setPalette()
{
KTextEdit *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);
if (!customFont) {
q->nativeWidget()->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
}
}
TextEdit *q;
Plasma::Style::Ptr style;
bool customFont;
};
TextEdit::TextEdit(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new TextEditPrivate)
d(new TextEditPrivate(this))
{
KTextEdit *native = new KTextEdit;
connect(native, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
@ -52,6 +83,8 @@ TextEdit::TextEdit(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()));
}
TextEdit::~TextEdit()
@ -105,6 +138,16 @@ void TextEdit::resizeEvent(QGraphicsSceneResizeEvent *event)
QGraphicsProxyWidget::resizeEvent(event);
}
void TextEdit::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
nativeWidget()->setFont(font());
}
QGraphicsProxyWidget::changeEvent(event);
}
} // namespace Plasma
#include <textedit.moc>

View File

@ -87,9 +87,11 @@ Q_SIGNALS:
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void changeEvent(QEvent *event);
private:
TextEditPrivate * const d;
Q_PRIVATE_SLOT(d, void setPalette())
};
} // namespace Plasma