From a827d621f8964ba9671456ce75224fe476fa694c Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Sat, 12 Sep 2009 15:05:39 +0000 Subject: [PATCH] use the plasma font... unless someone called QGraphicsWidget::setFont() svn path=/trunk/KDE/kdelibs/; revision=1022790 --- widgets/pushbutton.cpp | 24 ++++++++++++++++++++---- widgets/pushbutton.h | 1 + 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/widgets/pushbutton.cpp b/widgets/pushbutton.cpp index aed52ac0f..e79cc3b85 100644 --- a/widgets/pushbutton.cpp +++ b/widgets/pushbutton.cpp @@ -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()) { diff --git a/widgets/pushbutton.h b/widgets/pushbutton.h index 7f2a4c9e7..c29ee6ae4 100644 --- a/widgets/pushbutton.h +++ b/widgets/pushbutton.h @@ -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;