[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    [PATCH] K Menu side image color problem
From:       Fredrik =?iso-8859-1?q?H=F6glund?= <fredrik () kde ! org>
Date:       2002-02-19 20:48:56
[Download RAW message or body]

Hi,

There have been some difficulties in creating a side image for the
K Menu that works with all the color schemes in KDE. The one we have
now is a compromise; it's one that's not too bright for dark color
schemes and not too dark for bright ones. This compromise doesn't
work as well when it comes to the colors - it's always blue regardless
of what color scheme you use.

I've come up with a solution to this problem: dynamically recoloring
the side image to the active titlebar color when it's loaded. Should
the user change color schemes, the image is again recolored to match
the new scheme.

This has the advantage of not only making the image always match the
users color scheme, but IMO it also makes the side image seem more
like an integrated part of the menu. It also gives the users a little
more control over the look & feel of their desktops.

Qwertz was kind enough to put up a screenshot on his website that
shows what this looks like: http://qwertz.r--e.net/composite.png
Note that this screenshot was created with the previous version of
the side image.

The patch limits the max/min brightness of the color that's used to
a range of approx. 30% - 70%, so it will work even with color
schemes that have a completely black or white titlebar.

Since this patch solves a problem that we're having now, and since
it's also quite trivial I'm interested in knowing if this is something
that should be done for KDE 3.0. It is something that I had originally
planned on doing for KDE 3.1.

While experimenting with this I also found a small bug in the
colorize() method in KIconEffect that will cause pixel corruption
in the image with certain colors. The second patch attached to this
email fixes that, so you'll want to apply that patch too if
you want to test the first one. 

Regards,
Fredrik



["kicker.diff" (text/x-diff)]

Index: k_mnu.cpp
===================================================================
RCS file: /home/kde/kdebase/kicker/ui/k_mnu.cpp,v
retrieving revision 1.35
diff -u -3 -p -r1.35 k_mnu.cpp
--- k_mnu.cpp	2002/02/08 13:29:34	1.35
+++ k_mnu.cpp	2002/02/19 16:59:18
@@ -28,6 +28,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE 
 #include <kglobal.h>
 #include <kglobalsettings.h>
 #include <kiconloader.h>
+#include <kiconeffect.h>
 #include <klocale.h>
 #include <kconfig.h>
 #include <kwin.h>
@@ -69,34 +70,58 @@ PanelKMenu::PanelKMenu(QWidget *parent, 
 bool PanelKMenu::loadSidePixmap()
 {
   KConfig *config = KGlobal::config();
+  QColor color = palette().active().highlight();
+  QImage image;
 
-  config->setGroup("KMenu");
+  config->setGroup("WM");
+  color = config->readColorEntry("activeBackground", &color);
 
+  config->setGroup("KMenu");
   if (!config->readBoolEntry("UseSidePixmap", true))
   {
     return false;
   }
 
+  // limit max/min brightness
+  int r, g, b;
+  color.rgb(&r, &g, &b);
+  int gray = qGray(r, g, b);
+  if (gray > 180) {
+    r = (r - (gray - 180) < 0 ? 0 : r - (gray - 180));
+    g = (g - (gray - 180) < 0 ? 0 : g - (gray - 180));
+    b = (b - (gray - 180) < 0 ? 0 : b - (gray - 180));
+  } else if (gray < 76) {
+    r = (r + (76 - gray) > 255 ? 255 : r + (76 - gray));
+    g = (g + (76 - gray) > 255 ? 255 : g + (76 - gray));
+    b = (b + (76 - gray) > 255 ? 255 : b + (76 - gray));
+  }
+  color.setRgb(r, g, b);
+
   QString sideName = config->readEntry("SideName", "kside.png");
   QString sideTileName = config->readEntry("SideTileName", "kside_tile.png");
 
-  sidePixmap.load(locate("data", "kicker/pics/" + sideName));
+  image.load(locate("data", "kicker/pics/" + sideName));
 
-  if (sidePixmap.isNull())
+  if (image.isNull())
   {
     kdDebug(1210) << "Can't find a side pixmap" << endl;
     return false;
   }
+
+  KIconEffect::colorize(image, color, 1.0);
+  sidePixmap.convertFromImage(image);
 
-  sideTilePixmap.load(locate("data", "kicker/pics/" + sideTileName));
+  image.load(locate("data", "kicker/pics/" + sideTileName));
 
-  if (sideTilePixmap.isNull())
+  if (image.isNull())
   {
     kdDebug(1210) << "Can't find a side tile pixmap" << endl;
-
     return false;
   }
 
+  KIconEffect::colorize(image, color, 1.0);
+  sideTilePixmap.convertFromImage(image);
+
   if (sidePixmap.width() != sideTilePixmap.width())
   {
     kdDebug(1210) << "Pixmaps have to be the same size" << endl;
@@ -106,6 +131,12 @@ bool PanelKMenu::loadSidePixmap()
   return true;
 }
 
+void PanelKMenu::paletteChanged()
+{
+    if (!loadSidePixmap())
+      sidePixmap = sideTilePixmap = QPixmap();
+}
+
 PanelKMenu::~PanelKMenu()
 {
     if (pop)
@@ -121,9 +152,9 @@ void PanelKMenu::initialize()
     if (initialized()) return;
 
     if (!loadSidePixmap())
-    {
       sidePixmap = sideTilePixmap = QPixmap();
-    }
+    else
+      connect(kapp, SIGNAL(kdisplayPaletteChanged()), SLOT(paletteChanged()));
 
     // add services
     PanelServiceMenu::initialize();
Index: k_mnu.h
===================================================================
RCS file: /home/kde/kdebase/kicker/ui/k_mnu.h,v
retrieving revision 1.12
diff -u -3 -p -r1.12 k_mnu.h
--- k_mnu.h	2001/12/24 06:48:44	1.12
+++ k_mnu.h	2002/02/19 16:59:18
@@ -58,6 +58,7 @@ protected slots:
     void slotLogout();
     void slotRunCommand();
     void hidePopup();
+    void paletteChanged();
 
 protected:
     void resizeEvent(QResizeEvent *);

["kdecore.diff" (text/x-diff)]

Index: kiconeffect.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kiconeffect.cpp,v
retrieving revision 1.36
diff -u -3 -p -r1.36 kiconeffect.cpp
--- kiconeffect.cpp	2001/12/02 23:35:41	1.36
+++ kiconeffect.cpp	2002/02/13 16:31:56
@@ -258,12 +258,9 @@ void KIconEffect::colorize(QImage &img, 
     unsigned int *data = img.depth() > 8 ? (unsigned int *) img.bits()
 	    : (unsigned int *) img.colorTable();
     int rval, gval, bval, val, alpha, i;
-    float rcol, gcol, bcol;
+    float rcol = col.red(), gcol = col.green(), bcol = col.blue();
     for (i=0; i<pixels; i++)
     {
-        rcol = col.red();
-        gcol = col.green();
-        bcol = col.blue();
         val = qGray(data[i]);
         if (val < 128)
         {
@@ -271,12 +268,18 @@ void KIconEffect::colorize(QImage &img, 
              gval = static_cast<int>(gcol/128*val);
              bval = static_cast<int>(bcol/128*val);
         }
-        else if (val >= 128)
+        else if (val > 128)
         {
              rval = static_cast<int>((val-128)*(2-rcol/128)+rcol-1);
              gval = static_cast<int>((val-128)*(2-gcol/128)+gcol-1);
              bval = static_cast<int>((val-128)*(2-bcol/128)+bcol-1);
         }
+	else if (val == 128)
+	{
+             rval = rcol;
+             gval = gcol;
+             bval = bcol;
+	}
 	if (value < 1.0)
 	{
 	    rval = static_cast<int>(value*rval+(1.0 - value)*qRed(data[i]));


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic