On Friday 11 September 2009, Aaron J. Seigo wrote:
> On September 11, 2009, Marco Martin wrote:
> > but the ones thatreally have to use the proxywidget to paint, like the
> > ones that have to layout text there wouldn't be much we can do about
> > (maybe syncing the nativewidget font with the plasma theme one?)
>
> that'd probably be the best we could do...
was thinking about that, if it's ok i'll start the monkeycode device...

-- 
Marco Martin
Index: pushbutton.cpp
===================================================================
--- pushbutton.cpp	(revision 1022402)
+++ pushbutton.cpp	(working copy)
@@ -49,7 +49,8 @@
           background(0),
           animId(-1),
           fadeIn(false),
-          svg(0)
+          svg(0),
+          customFont(false)
     {
     }
 
@@ -110,6 +111,7 @@
     QString absImagePath;
     Svg *svg;
     QString svgElement;
+    bool customFont;
 };
 
 void PushButtonPrivate::syncActiveRect()
@@ -382,8 +384,15 @@
         }
     }
 
+    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 @@
 
         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 @@
 
         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 @@
     QGraphicsProxyWidget::hoverEnterEvent(event);
 }
 
+void PushButton::changeEvent(QEvent *event)
+{
+    if (event->type() == QEvent::FontChange) {
+        d->customFont = true;
+    }
+}
+
 void PushButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
 {
     if (nativeWidget()->isDown()) {
Index: pushbutton.h
===================================================================
--- pushbutton.h	(revision 1022402)
+++ pushbutton.h	(working copy)
@@ -167,6 +167,7 @@
     void resizeEvent(QGraphicsSceneResizeEvent *event);
     void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
     void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
+    void changeEvent(QEvent *event);
 
 private:
     PushButtonPrivate *const d;
_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel

Reply via email to