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

widget
round one:widgets that draws themselves without native()-render()
and don't have a setFont function themselves

svn path=/trunk/KDE/kdelibs/; revision=1022897
This commit is contained in:
Marco Martin 2009-09-13 13:13:55 +00:00
parent a827d621f8
commit 5cc2ddf8ad
13 changed files with 119 additions and 15 deletions

View File

@ -41,7 +41,8 @@ class ComboBoxPrivate
public:
ComboBoxPrivate(ComboBox *comboBox)
: q(comboBox),
background(0)
background(0),
customFont(0)
{
}
@ -61,6 +62,7 @@ public:
qreal opacity;
QRectF activeRect;
Style::Ptr style;
bool customFont;
};
void ComboBoxPrivate::syncActiveRect()
@ -94,7 +96,11 @@ void ComboBoxPrivate::syncBorders()
syncActiveRect();
KComboBox *native = q->nativeWidget();
native->setFont(Theme::defaultTheme()->font(Theme::DefaultFont));
if (customFont) {
native->setFont(Theme::defaultTheme()->font(Theme::DefaultFont));
} else {
native->setFont(q->font());
}
}
void ComboBoxPrivate::animationUpdate(qreal progress)
@ -297,6 +303,15 @@ void ComboBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
QGraphicsProxyWidget::hoverLeaveEvent(event);
}
void ComboBox::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
}
QGraphicsProxyWidget::changeEvent(event);
}
} // namespace Plasma
#include <combobox.moc>

View File

@ -91,6 +91,7 @@ protected:
QWidget *widget);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void changeEvent(QEvent *event);
private:
ComboBoxPrivate * const d;

View File

@ -63,6 +63,7 @@ public:
QString absImagePath;
Svg *image;
QPixmap *pixmap;
bool customFont;
};
void FramePrivate::syncBorders()
@ -72,8 +73,15 @@ void FramePrivate::syncBorders()
svg->getMargins(left, top, right, bottom);
QFont widgetFont;
if (customFont) {
widgetFont = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
} else {
widgetFont = q->font();
}
if (!text.isNull()) {
QFontMetricsF fm(QApplication::font());
QFontMetricsF fm(widgetFont);
top += fm.height();
}
@ -204,10 +212,18 @@ void Frame::paint(QPainter *painter,
d->svg->paintFrame(painter);
QFont widgetFont;
if (d->customFont) {
widgetFont = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
} else {
widgetFont = font();
}
if (!d->text.isNull()) {
QFontMetricsF fm(QApplication::font());
QFontMetricsF fm(widgetFont);
QRectF textRect = d->svg->contentsRect();
textRect.setHeight(fm.height());
painter->setFont(widgetFont);
painter->setPen(Plasma::Theme::defaultTheme()->color(Theme::TextColor));
painter->drawText(textRect, Qt::AlignHCenter|Qt::AlignTop, d->text);
}
@ -246,6 +262,15 @@ QSizeF Frame::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
return hint;
}
void Frame::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
}
QGraphicsWidget::changeEvent(event);
}
} // namespace Plasma
#include <frame.moc>

View File

@ -123,6 +123,7 @@ protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint) const;
void changeEvent(QEvent *event);
private:
FramePrivate * const d;

View File

@ -74,7 +74,8 @@ IconWidgetPrivate::IconWidgetPrivate(IconWidget *i)
fadeIn(false),
invertLayout(false),
drawBg(false),
textBgCustomized(false)
textBgCustomized(false),
customFont(false)
{
}
@ -349,7 +350,6 @@ void IconWidgetPrivate::init()
setActiveMargins();
currentSize = QSizeF(-1, -1);
q->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
}
void IconWidget::addIconAction(QAction *action)
@ -471,9 +471,16 @@ QSizeF IconWidgetPrivate::displaySizeHint(const QStyleOptionGraphicsItem *option
horizontalMargin[IconWidgetPrivate::TextMargin].left -
horizontalMargin[IconWidgetPrivate::TextMargin].right;
QFont widgetFont;
if (customFont) {
widgetFont = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
} else {
widgetFont = q->font();
}
//allow only five lines of text
const qreal maxHeight =
numDisplayLines * Plasma::Theme::defaultTheme()->fontMetrics().lineSpacing();
numDisplayLines * QFontMetrics(widgetFont).lineSpacing();
// To compute the nominal size for the label + info, we'll just append
// the information string to the label
@ -483,7 +490,7 @@ QSizeF IconWidgetPrivate::displaySizeHint(const QStyleOptionGraphicsItem *option
QTextLayout layout;
setLayoutOptions(layout, option, q->orientation());
layout.setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
layout.setFont(widgetFont);
QSizeF size = layoutText(layout, option, label, QSizeF(textWidth, maxHeight));
return addMargin(size, TextMargin);
@ -527,8 +534,14 @@ void IconWidgetPrivate::layoutIcons(const QStyleOptionGraphicsItem *option)
}
iconWidth -= horizontalMargin[IconWidgetPrivate::ItemMargin].left + horizontalMargin[IconWidgetPrivate::ItemMargin].right;
} else {
QFont widgetFont;
if (customFont) {
widgetFont = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
} else {
widgetFont = q->font();
}
//Horizontal layout
QFontMetricsF fm = Plasma::Theme::defaultTheme()->fontMetrics();
QFontMetricsF fm = QFontMetrics(widgetFont);
//if there is text resize the icon in order to make room for the text
if (text.isEmpty() && infoText.isEmpty()) {
@ -991,10 +1004,17 @@ void IconWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
}
}
QFont widgetFont;
if (d->customFont) {
widgetFont = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
} else {
widgetFont = font();
}
// Draw text last because it is overlayed
QTextLayout labelLayout, infoLayout;
labelLayout.setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
infoLayout.setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
labelLayout.setFont(widgetFont);
infoLayout.setFont(widgetFont);
QRectF textBoundingRect;
@ -1319,7 +1339,14 @@ QSizeF IconWidget::sizeFromIconSize(const qreal iconWidth) const
IconWidgetPrivate::ItemMargin);
}
QFontMetricsF fm = Plasma::Theme::defaultTheme()->fontMetrics();
QFont widgetFont;
if (d->customFont) {
widgetFont = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
} else {
widgetFont = font();
}
QFontMetricsF fm(widgetFont);
qreal width = 0;
if (d->orientation == Qt::Vertical) {
@ -1370,6 +1397,15 @@ QSizeF IconWidget::sizeFromIconSize(const qreal iconWidth) const
return d->addMargin(QSizeF(width, height), IconWidgetPrivate::ItemMargin);
}
void IconWidget::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
}
QGraphicsWidget::changeEvent(event);
}
} // namespace Plasma
#include "iconwidget.moc"

View File

@ -304,6 +304,7 @@ protected:
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event);
void changeEvent(QEvent *event);
public:
/**

View File

@ -226,6 +226,7 @@ public:
static const int maxDisplayLines = 5;
static const int iconActionSize = 26;
static const int iconActionMargin = 4;
bool customFont;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(IconWidgetPrivate::IconWidgetStates)

View File

@ -453,6 +453,8 @@ void PushButton::changeEvent(QEvent *event)
if (event->type() == QEvent::FontChange) {
d->customFont = true;
}
QGraphicsProxyWidget::changeEvent(event);
}
void PushButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)

View File

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

View File

@ -37,7 +37,7 @@ class SeparatorPrivate;
class PLASMA_EXPORT Separator : public QGraphicsWidget
{
Q_OBJECT
Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
public:

View File

@ -84,6 +84,7 @@ public:
*/
KIntSpinBox *nativeWidget() const;
public Q_SLOTS:
/**
* Sets the maximum value the slider can take.

View File

@ -49,7 +49,8 @@ public:
background(0),
animId(0),
fadeIn(false),
svg(0)
svg(0),
customFont(false)
{
}
@ -110,6 +111,7 @@ public:
QString absImagePath;
Svg *svg;
QString svgElement;
bool customFont;
};
void ToolButtonPrivate::syncActiveRect()
@ -346,7 +348,15 @@ void ToolButton::paint(QPainter *painter,
buttonOpt.palette.setColor(QPalette::ButtonText, Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
}
painter->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
QFont widgetFont;
if (d->customFont) {
widgetFont = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
} else {
widgetFont = font();
}
buttonOpt.font = widgetFont;
painter->setFont(widgetFont);
button->style()->drawControl(QStyle::CE_ToolButtonLabel, &buttonOpt, painter, button);
}
@ -392,6 +402,15 @@ void ToolButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
QGraphicsProxyWidget::hoverLeaveEvent(event);
}
void ToolButton::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
}
QGraphicsProxyWidget::changeEvent(event);
}
} // namespace Plasma
#include <toolbutton.moc>

View File

@ -157,6 +157,7 @@ protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void changeEvent(QEvent *event);
private:
ToolButtonPrivate *const d;