On Thursday 09 April 2009, Helio Chissini de Castro wrote:
> For light backgrounds with white text, there's no same issue. Happens
> always in the combination of dark background with light themes.

here's another approach for icons: paint a small colour lozenge behind the 
text. sort of like MacOS, iirc, but oh well.

it's turned off in the toolbox by default because the theme really ought to 
take care of that.

the rest of the icons get this treatment by default. what's kind of neat is 
that this does open the possibility to have different coloured icon lozenges. 
again, like Mac. *sigh* :P

screenshot and patch attached.

-- 
Aaron J. Seigo
humru othro a kohnu se
GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA  EE75 D6B7 2EB1 A7F1 DB43

KDE core developer sponsored by Qt Software

<<attachment: icon_with_lozenge.png>>

Index: widgets/iconwidget.h
===================================================================
--- widgets/iconwidget.h	(revision 951209)
+++ widgets/iconwidget.h	(working copy)
@@ -57,6 +57,7 @@
     Q_PROPERTY(QString text READ text WRITE setText)
     Q_PROPERTY(QString infoText READ infoText WRITE setInfoText)
     Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
+    Q_PROPERTY(QColor textBackgroundColor READ textBackgroundColor WRITE setTextBackgroundColor)
     Q_PROPERTY(QSizeF iconSize READ iconSize)
     Q_PROPERTY(QString svg WRITE setSvg)
     Q_PROPERTY(QAction *action READ action WRITE setAction)
@@ -132,6 +133,19 @@
     void setIcon(const QIcon &icon);
 
     /**
+     * @return the color to use behind the text of the icon
+     * @since 4.3
+     */
+    QColor textBackgroundColor() const;
+
+    /**
+     * Sets the color to use behind the text of the icon
+     * @param color the color, or QColor() to reset it to no background color
+     * @since 4.3
+     */
+    void setTextBackgroundColor(const QColor &color);
+
+    /**
     * Convenience method to set the icon of this Plasma::IconWidget
     * using a QString path to the icon.
     * @param icon the path to the icon to associate with this Plasma::IconWidget.
Index: widgets/iconwidget.cpp
===================================================================
--- widgets/iconwidget.cpp	(revision 951209)
+++ widgets/iconwidget.cpp	(working copy)
@@ -62,18 +62,19 @@
 IconWidgetPrivate::IconWidgetPrivate(IconWidget *i)
     : q(i),
       iconSvg(0),
-      iconSvgElementChanged(false),
-      fadeIn(false),
       hoverAnimId(-1),
       hoverAlpha(20 / 255),
       iconSize(48, 48),
       states(IconWidgetPrivate::NoState),
       orientation(Qt::Vertical),
       numDisplayLines(2),
+      action(0),
+      activeMargins(0),
+      iconSvgElementChanged(false),
+      fadeIn(false),
       invertLayout(false),
       drawBg(false),
-      action(0),
-      activeMargins(0)
+      textBgCustomized(false)
 {
 }
 
@@ -84,12 +85,18 @@
 
 void IconWidgetPrivate::readColors()
 {
+    kDebug();
     textColor = Plasma::Theme::defaultTheme()->color(Theme::TextColor);
+
     if (qGray(textColor.rgb()) > 192) {
         shadowColor = Qt::black;
     } else {
         shadowColor = Qt::white;
     }
+
+    if (!textBgCustomized) {
+        textBgColor = Theme::defaultTheme()->color(Theme::HighlightColor);
+    }
 }
 
 void IconWidgetPrivate::colorConfigChanged()
@@ -976,11 +983,34 @@
         shadowOffset = QPoint(0, 1);
     }
 
+
+    if (state == IconWidgetPrivate::NoState && d->textBgColor != QColor()) {
+        QRectF rect = textBoundingRect.adjusted(-2, -2, 4, 4);
+        painter->setPen(Qt::transparent);
+        QColor color = d->textBgColor;
+        color.setAlpha(60 * 1.0 - d->hoverAlpha);
+        painter->setBrush(color);
+        painter->setRenderHint(QPainter::Antialiasing);
+        painter->drawPath(PaintUtils::roundedRectangle(rect, 4));
+    }
+
     PaintUtils::shadowBlur(shadow, 2, d->shadowColor);
     painter->drawImage(textBoundingRect.topLeft() + shadowOffset, shadow);
     d->drawTextItems(painter, option, labelLayout, infoLayout);
 }
 
+void IconWidget::setTextBackgroundColor(const QColor &color)
+{
+    d->textBgCustomized = true;
+    d->textBgColor = color;
+    update();
+}
+
+QColor IconWidget::textBackgroundColor() const
+{
+    return d->textBgColor;
+}
+
 void IconWidget::drawActionButtonBase(QPainter *painter, const QSize &size, int element)
 {
     qreal radius = size.width() / 2;
@@ -1188,10 +1218,12 @@
 
 bool IconWidget::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
 {
-    if (event->type() == QEvent::GraphicsSceneDragEnter){
+    Q_UNUSED(watched)
+
+    if (event->type() == QEvent::GraphicsSceneDragEnter) {
         d->hoverEffect(true);
         update();
-    }else if (event->type() == QEvent::GraphicsSceneDragLeave){
+    } else if (event->type() == QEvent::GraphicsSceneDragLeave) {
         d->hoverEffect(false);
         update();
     }
Index: widgets/iconwidget_p.h
===================================================================
--- widgets/iconwidget_p.h	(revision 951209)
+++ widgets/iconwidget_p.h	(working copy)
@@ -194,11 +194,10 @@
     Svg *iconSvg;
     FrameSvg *background;
     QString iconSvgElement;
-    bool iconSvgElementChanged;
     QPixmap iconSvgPixmap;
     QColor textColor;
+    QColor textBgColor;
     QColor shadowColor;
-    bool fadeIn;
     int hoverAnimId;
     qreal hoverAlpha;
     QSizeF iconSize;
@@ -206,8 +205,6 @@
     IconWidgetStates states;
     Qt::Orientation orientation;
     int numDisplayLines;
-    bool invertLayout;
-    bool drawBg;
     QSizeF currentSize;
     QPointF clickStartPos;
 
@@ -218,6 +215,11 @@
     Margin horizontalMargin[NMargins];
     Margin *activeMargins;
 
+    bool iconSvgElementChanged : 1;
+    bool fadeIn : 1;
+    bool invertLayout : 1;
+    bool drawBg : 1;
+    bool textBgCustomized : 1;
     static const int maxDisplayLines = 5;
     static const int iconActionSize = 26;
     static const int iconActionMargin = 4;
Index: private/toolbox.cpp
===================================================================
--- private/toolbox.cpp	(revision 951209)
+++ private/toolbox.cpp	(working copy)
@@ -113,6 +113,7 @@
 
     Plasma::IconWidget *tool = new Plasma::IconWidget(this);
 
+    tool->setTextBackgroundColor(QColor());
     tool->setAction(action);
     tool->setDrawBackground(true);
     tool->setOrientation(Qt::Horizontal);

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel

Reply via email to