use the plasma font...

unless someone called QGraphicsWidget::setFont()

svn path=/trunk/KDE/kdelibs/; revision=1022790
This commit is contained in:
Marco Martin 2009-09-12 15:05:39 +00:00
parent 6e412aedd9
commit a827d621f8
2 changed files with 21 additions and 4 deletions

View File

@ -49,7 +49,8 @@ public:
background(0),
animId(-1),
fadeIn(false),
svg(0)
svg(0),
customFont(false)
{
}
@ -110,6 +111,7 @@ public:
QString absImagePath;
Svg *svg;
QString svgElement;
bool customFont;
};
void PushButtonPrivate::syncActiveRect()
@ -382,8 +384,15 @@ void PushButton::paint(QPainter *painter,
}
}
QFont widgetFont;
if (d->customFont) {
widgetFont = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
} else {
widgetFont = font();
}
//if there is not enough room for the text make it to fade out
QFontMetricsF fm(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
QFontMetricsF fm(widgetFont);
if (rect.width() < fm.width(nativeWidget()->text())) {
if (bufferPixmap.isNull()) {
bufferPixmap = QPixmap(rect.size().toSize());
@ -392,7 +401,7 @@ void PushButton::paint(QPainter *painter,
QPainter p(&bufferPixmap);
p.setPen(painter->pen());
p.setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
p.setFont(widgetFont);
// Create the alpha gradient for the fade out effect
QLinearGradient alphaGradient(0, 0, 1, 0);
@ -414,7 +423,7 @@ void PushButton::paint(QPainter *painter,
painter->drawPixmap(rect.topLeft(), bufferPixmap);
} else {
painter->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
painter->setFont(widgetFont);
painter->drawText(rect, Qt::AlignCenter, nativeWidget()->text());
}
}
@ -439,6 +448,13 @@ void PushButton::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
QGraphicsProxyWidget::hoverEnterEvent(event);
}
void PushButton::changeEvent(QEvent *event)
{
if (event->type() == QEvent::FontChange) {
d->customFont = true;
}
}
void PushButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
if (nativeWidget()->isDown()) {

View File

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