A never ending story.

Michael Reiher michael.reiher at gmx.de
Mon Oct 28 15:22:36 GMT 2002


Dirk Mueller schrieb:
> 
> On Fre, 04 Okt 2002, Dirk Mueller wrote:
> 
> > > "right" palette. But no clue how.
> >
> > Yeah, me neither.
But isn't this actually a non issue under X? Quote from
QApplication::palette():

If a widget is passed in w, the default palette for the widget's class is
returned. This may or may not be the application palette. In most cases there
isn't a special palette for certain types of widgets, but one notable exception
is the popup menu under Windows, if the user has defined a special background
color for menus in the display settings.

> >
> > kapp->palette() returns the default palette, i.e. not the one that is
> > inverted ? Otherwise I don't see how your patch would make a difference.
Erm, not sure what you mean ... kapp->palette() returns the one which all KDE
apps usually use, which in my case is light-font-on-dark-background and which
thus makes webpages unreadable. Whereas I set a
(configurable)dark-font-on-light-background palette for khtmls viewport(and
thus it's children).

Btw. I just see: In e.g. HTMLInputElementImpl::attach() there is only the
foreground color of form elements being set. Isn't that a bit strange? I mean
even without my patch is actually useless, as the foreground, which is set in
helper.cpp, is actually from the KDE global palette while the background
defaults to parents background which is in the end kapp->palette(), too.

> >
> > BTW, why did you change the loading of the color definitions for window
> > decoration colors etc ? I don't think there was any page depending on
> > "wrong" colors in this case, were they ?
> >
Oops, this was a mistake. Will fix.

> > BTW, do you have a default color palette that matches all requirements for
> > webpages ?
Erm..you mean like this?

Add that to you kdeglobals:
[HTML Colors]
background=220,220,220
foreground=0,0,0
buttonBackground=220,220,220
buttonForeground=0,0,0
linkColor=0,0,255
visitedLinkColor=255,0,255
selectBackground=84,112,152
selectForeground=255,255,255
windowBackground=255,255,255
windowForeground=0,0,0

> >
> >
> > > The only _real_solution_  I see is to let khtml run in an own color environment
> > > where all colors(text, background, widgets, links) match. And the IMHO easiest
> > > and most flexible way, from the users POV, is to use existing colorschemes.
> >
> > The funny part is that we behave just like IE when it comes to color
> > defaults, so apparently nobody is disturbed that IE is broken with inverted
> > color shemes. Or do they still do something different from us ?
No, all the other browsers I checked are broken in that respect. You can't read
certain pages with dark colorschemes. But, for my part I'm not disturbed that
IE is broken as I don't use it. But I'm definitely disturbed when Konqy
broken;)

> >
> > I actually very much like the idea that khtml reacts to user color styles
> > automatically :/
> >
Well it still would with my patch. If there are no custom colors defined, the
application palette is use, just like before.

> > > No idea:) What did I break regarding CSS requirements?
> >
> > the changing of the color definitions in misc/helper.cpp
> >
For the window decorations, see above. And for the rest I actually only put a
comment behind with what it should be IMHO.

> 
> Does anybody care to answer ? I'd really like to close this issue.
> 
Darn! I completely forgot! I was busy with my exam the last weeks. Sorry!

I attached a revised patch. I changed helper.cpp to read the decoration colors
from config file again.
-------------- next part --------------
? colorfix.diff
Index: khtml_part.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtml_part.cpp,v
retrieving revision 1.760
diff -b -u -p -r1.760 khtml_part.cpp
--- khtml_part.cpp	2002/10/25 13:05:37	1.760
+++ khtml_part.cpp	2002/10/28 15:14:50
@@ -164,6 +164,7 @@ void KHTMLPart::init( KHTMLView *view, G
 
   d->m_view = view;
   setWidget( d->m_view );
+  d->m_view->viewport()->setPalette( d->m_settings->htmlPalette() );
 
   d->m_guiProfile = prof;
   d->m_extension = new KHTMLPartBrowserExtension( this );
Index: khtml_settings.cc
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtml_settings.cc,v
retrieving revision 1.88
diff -b -u -p -r1.88 khtml_settings.cc
--- khtml_settings.cc	2002/07/19 19:06:14	1.88
+++ khtml_settings.cc	2002/10/28 15:14:51
@@ -19,6 +19,7 @@
 
 #include <qfontdatabase.h>
 #include <qregexp.h>
+#include <qpalette.h>
 
 #include "khtml_settings.h"
 #include "khtmldefaults.h"
@@ -26,6 +27,7 @@
 #include <kconfig.h>
 #include <kglobal.h>
 #include <klocale.h>
+#include <kapplication.h>
 #include <kdebug.h>
 #include <qregexp.h>
 
@@ -55,9 +57,7 @@ public:
     QString m_encoding;
     QString m_userSheet;
 
-    QColor m_textColor;
-    QColor m_linkColor;
-    QColor m_vLinkColor;
+    QPalette m_htmlPalette;
 
     QMap<QString,KHTMLSettings::KJavaScriptAdvice> javaDomainPolicy;
     QMap<QString,KHTMLSettings::KJavaScriptAdvice> javaScriptDomainPolicy;
@@ -245,21 +245,88 @@ void KHTMLSettings::init( KConfig * conf
     d->m_maxFormCompletionItems = config->readNumEntry("MaxFormCompletionItems", 10);
   }
 
-  // Colors
-  if ( reset || config->hasGroup( "General" ) )
+  // Local HTML palette ( code taken from KApplication )
+  if ( reset || config->hasGroup( "HTML Colors" ) )
   {
-    config->setGroup( "General" ); // group will be restored by cgs anyway
-    if ( reset || config->hasKey( "foreground" ) )
-      d->m_textColor = config->readColorEntry( "foreground", &HTML_DEFAULT_TXT_COLOR );
+    config->setGroup( "HTML Colors" );
 
-    if ( reset || config->hasKey( "linkColor" ) )
-      d->m_linkColor = config->readColorEntry( "linkColor", &HTML_DEFAULT_LNK_COLOR );
+    int contrast_ = KGlobalSettings::contrast();
+    const QPalette &defaultPal = kapp->palette();
 
-    if ( reset || config->hasKey( "visitedLinkColor" ) )
-      d->m_vLinkColor = config->readColorEntry( "visitedLinkColor", &HTML_DEFAULT_VLNK_COLOR);
-  }
+    QColor background = config->readColorEntry( "background", &defaultPal.active().background() );
+    QColor foreground = config->readColorEntry( "foreground", &defaultPal.active().foreground() );
+    QColor button = config->readColorEntry( "buttonBackground", &background );
+    QColor buttonText = config->readColorEntry( "buttonForeground", &foreground );
+    QColor highlight = config->readColorEntry( "selectBackground", &defaultPal.active().highlight() );
+    QColor highlightedText = config->readColorEntry( "selectForeground", &defaultPal.active().highlightedText() );
+    QColor base = config->readColorEntry( "windowBackground", &defaultPal.active().base() );
+    QColor baseText = config->readColorEntry( "windowForeground", &defaultPal.active().text() );
+    QColor link = config->readColorEntry( "linkColor", &defaultPal.active().link() );
+    QColor visitedLink = config->readColorEntry( "visitedLinkColor", &defaultPal.active().linkVisited() );
+
+    int highlightVal = 100 + (2*contrast_+4)*16/10;
+    int lowlightVal = 100 + (2*contrast_+4)*10;
+
+    QColor disfg = foreground;
+
+    int h, s, v;
+    disfg.hsv( &h, &s, &v );
+    if (v > 128)
+      // dark bg, light fg - need a darker disabled fg
+      disfg = disfg.dark(lowlightVal);
+    else if (disfg != Qt::black)
+      // light bg, dark fg - need a lighter disabled fg - but only if !black
+      disfg = disfg.light(highlightVal);
+    else
+      // black fg - use darkgrey disabled fg
+      disfg = Qt::darkGray;
+
+
+    QColorGroup disabledgrp(disfg, background,
+                            background.light(highlightVal),
+                            background.dark(lowlightVal),
+                            background.dark(120),
+                            background.dark(120), base);
+
+    QColorGroup colgrp(foreground, background, background.light(highlightVal),
+                       background.dark(lowlightVal),
+                       background.dark(120),
+                       baseText, base);
+
+    int inlowlightVal = lowlightVal-25;
+    if(inlowlightVal < 120)
+      inlowlightVal = 120;
+
+    colgrp.setColor(QColorGroup::Highlight, highlight);
+    colgrp.setColor(QColorGroup::HighlightedText, highlightedText);
+    colgrp.setColor(QColorGroup::Button, button);
+    colgrp.setColor(QColorGroup::ButtonText, buttonText);
+    colgrp.setColor(QColorGroup::Midlight, background.light(110));
+    colgrp.setColor(QColorGroup::Link, link);
+    colgrp.setColor(QColorGroup::LinkVisited, visitedLink);
+
+    disabledgrp.setColor(QColorGroup::Button, button);
+
+    QColor disbtntext = buttonText;
+    disbtntext.hsv( &h, &s, &v );
+    if (v > 128)
+      // dark button, light buttonText - need a darker disabled buttonText
+      disbtntext = disbtntext.dark(lowlightVal);
+    else if (disbtntext != Qt::black)
+      // light buttonText, dark button - need a lighter disabled buttonText - but only if !black
+      disbtntext = disbtntext.light(highlightVal);
+    else
+      // black button - use darkgrey disabled buttonText
+      disbtntext = Qt::darkGray;
 
+    disabledgrp.setColor(QColorGroup::ButtonText, disbtntext);
+    disabledgrp.setColor(QColorGroup::Midlight, background.light(110));
+    disabledgrp.setColor(QColorGroup::Link, link);
+    disabledgrp.setColor(QColorGroup::LinkVisited, visitedLink);
 
+    d->m_htmlPalette = QPalette(colgrp, disabledgrp, colgrp);
+  }
+
   if( reset || config->hasGroup( "Java/JavaScript Settings" ) )
   {
     config->setGroup( "Java/JavaScript Settings" );
@@ -445,7 +512,7 @@ QString KHTMLSettings::settingsToCSS() c
 {
     // lets start with the link properties
     QString str = "a:link {\ncolor: ";
-    str += d->m_linkColor.name();
+    str += d->m_htmlPalette.active().color(QColorGroup::Link).name();
     str += ";";
     if(d->m_underlineLink)
         str += "\ntext-decoration: underline;";
@@ -457,7 +524,7 @@ QString KHTMLSettings::settingsToCSS() c
     }
     str += "\n}\n";
     str += "a:visited {\ncolor: ";
-    str += d->m_vLinkColor.name();
+    str += d->m_htmlPalette.active().color(QColorGroup::LinkVisited).name();
     str += ";";
     if(d->m_underlineLink)
         str += "\ntext-decoration: underline;";
@@ -571,17 +638,22 @@ const QString &KHTMLSettings::encoding()
 
 const QColor& KHTMLSettings::textColor() const
 {
-  return d->m_textColor;
+  return d->m_htmlPalette.active().color(QColorGroup::Foreground);
 }
 
 const QColor& KHTMLSettings::linkColor() const
 {
-  return d->m_linkColor;
+  return d->m_htmlPalette.active().color(QColorGroup::Link);
 }
 
 const QColor& KHTMLSettings::vLinkColor() const
+{
+  return d->m_htmlPalette.active().color(QColorGroup::LinkVisited);
+}
+
+const QPalette& KHTMLSettings::htmlPalette() const
 {
-  return d->m_vLinkColor;
+  return d->m_htmlPalette;
 }
 
 bool KHTMLSettings::autoLoadImages() const
Index: khtml_settings.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtml_settings.h,v
retrieving revision 1.33
diff -b -u -p -r1.33 khtml_settings.h
--- khtml_settings.h	2002/07/19 19:06:14	1.33
+++ khtml_settings.h	2002/10/28 15:14:51
@@ -97,9 +97,10 @@ public:
     const QString &encoding() const;
 
     // Color settings
-    const QColor& textColor() const;
-    const QColor& linkColor() const;
-    const QColor& vLinkColor() const;
+    const QColor& textColor() const; // obsolete, use htmlPalette()
+    const QColor& linkColor() const; // obsolete, use htmlPalette()
+    const QColor& vLinkColor() const; // obsolete, use htmlPalette()
+    const QPalette& htmlPalette() const;
 
     // Autoload images
     bool autoLoadImages() const;
Index: khtmldefaults.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtmldefaults.h,v
retrieving revision 1.5
diff -b -u -p -r1.5 khtmldefaults.h
--- khtmldefaults.h	2000/07/06 14:04:34	1.5
+++ khtmldefaults.h	2002/10/28 15:14:51
@@ -18,11 +18,6 @@
    Boston, MA 02111-1307, USA.
 */
 
-// browser window color defaults -- Bernd
-#define HTML_DEFAULT_LNK_COLOR Qt::blue
-#define HTML_DEFAULT_TXT_COLOR Qt::black
-#define HTML_DEFAULT_VLNK_COLOR Qt::magenta
-
 // KEEP IN SYNC WITH konqdefaults.h in kdebase/libkonq!
 // lets be modern .. -- Bernd
 #define HTML_DEFAULT_VIEW_FONT "helvetica"
Index: html/html_baseimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_baseimpl.cpp,v
retrieving revision 1.166
diff -b -u -p -r1.166 html_baseimpl.cpp
--- html/html_baseimpl.cpp	2002/08/23 18:44:44	1.166
+++ html/html_baseimpl.cpp	2002/10/28 15:14:51
@@ -172,9 +172,6 @@ void HTMLBodyElementImpl::insertedIntoDo
         addCSSLength(CSS_PROP_MARGIN_BOTTOM, s);
     }
 
-    if ( m_bgSet && !m_fgSet )
-        addCSSProperty(CSS_PROP_COLOR, "#000000");
-
     if (m_styleSheet)
         getDocument()->updateStyleSelector();
 }
Index: html/html_formimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_formimpl.cpp,v
retrieving revision 1.295
diff -b -u -p -r1.295 html_formimpl.cpp
--- html/html_formimpl.cpp	2002/10/18 11:33:48	1.295
+++ html/html_formimpl.cpp	2002/10/28 15:14:53
@@ -1071,9 +1071,11 @@ void HTMLInputElementImpl::attach()
     case SUBMIT:
     case RESET:
     case BUTTON:
+        addCSSProperty(CSS_PROP_COLOR, "buttontext");
+        break;
     case CHECKBOX:
     case RADIO:
-        addCSSProperty(CSS_PROP_COLOR, "buttontext" );
+        addCSSProperty(CSS_PROP_COLOR, "text" );
     case HIDDEN:
     case IMAGE:
         if (!getAttribute(ATTR_WIDTH).isNull())
Index: misc/helper.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/misc/helper.cpp,v
retrieving revision 1.51
diff -b -u -p -r1.51 helper.cpp
--- misc/helper.cpp	2002/10/27 17:13:23	1.51
+++ misc/helper.cpp	2002/10/28 15:14:54
@@ -30,6 +30,8 @@
 #include <kstaticdeleter.h>
 #include <kapplication.h>
 #include <kconfig.h>
+#include <kglobalsettings.h>
+#include <kdebug.h>
 #include <qtooltip.h>
 
 using namespace DOM;
@@ -62,7 +64,7 @@ static const colorMap cmap[] = {
    { 0, 0 }
 };
 
-struct uiColors {
+struct decoColors {
     const char * name;
     const char * configGroup;
     const char * configEntry;
@@ -71,76 +73,170 @@ struct uiColors {
 };
 
 const char * const wmgroup = "WM";
-const char * const generalgroup = "General";
 
-static const uiColors uimap[] = {
+static const widgetColors decomap[] = {
 	// Active window border.
     { "activeborder", wmgroup, "background", QPalette::Active, QColorGroup::Light },
 	// Active window caption.
     { "activecaption", wmgroup, "background", QPalette::Active, QColorGroup::Text },
         // Text in caption, size box, and scrollbar arrow box.
     { "captiontext", wmgroup, "activeForeground", QPalette::Active, QColorGroup::Text },
+  // Inactive window border.
+  { "inactiveborder", wmgroup, "background", QPalette::Disabled, QColorGroup::Background },
+  // Inactive window caption.
+  { "inactivecaption", wmgroup, "inactiveBackground", QPalette::Disabled, QColorGroup::Background },
+  // Color of text in an inactive caption.
+  { "inactivecaptiontext", wmgroup, "inactiveForeground", QPalette::Disabled, QColorGroup::Text },
+  { 0, 0, 0, QPalette::NColorGroups, QColorGroup::NColorRoles }
+};
+
+struct widgetColors {
+    const char * name;
+    QPalette::ColorGroup group;
+    QColorGroup::ColorRole role;
+};
+
+static const widgetColors widgetmap[] = {
 	// Face color for three-dimensional display elements.
-    { "buttonface", wmgroup, 0, QPalette::Inactive, QColorGroup::Button },
+    { "buttonface", QPalette::Inactive, QColorGroup::Button }, // MR: shouldn't this be QColorGroup::ButtonText
 	// Dark shadow for three-dimensional display elements (for edges facing away from the light source).
-    { "buttonhighlight", wmgroup, 0, QPalette::Inactive, QColorGroup::Light },
+    { "buttonhighlight", QPalette::Inactive, QColorGroup::Light },
 	// Shadow color for three-dimensional display elements.
-    { "buttonshadow", wmgroup, 0, QPalette::Inactive, QColorGroup::Shadow },
+    { "buttonshadow", QPalette::Inactive, QColorGroup::Shadow },
 	// Text on push buttons.
-    { "buttontext", wmgroup, "buttonForeground", QPalette::Inactive, QColorGroup::ButtonText },
+    { "buttontext", QPalette::Inactive, QColorGroup::ButtonText },
 	// Dark shadow for three-dimensional display elements.
-    { "threeddarkshadow", wmgroup, 0, QPalette::Inactive, QColorGroup::Dark },
+    { "threeddarkshadow", QPalette::Inactive, QColorGroup::Dark },
 	// Face color for three-dimensional display elements.
-    { "threedface", wmgroup, 0, QPalette::Inactive, QColorGroup::Button },
+    { "threedface", QPalette::Inactive, QColorGroup::Button }, // MR: shouldn't this be QColorGroup::ButtonText
 	// Highlight color for three-dimensional display elements.
-    { "threedhighlight", wmgroup, 0, QPalette::Inactive, QColorGroup::Light },
+    { "threedhighlight", QPalette::Inactive, QColorGroup::Light },
 	// Light color for three-dimensional display elements (for edges facing the light source).
-    { "threedlightshadow", wmgroup, 0, QPalette::Inactive, QColorGroup::Midlight },
+    { "threedlightshadow", QPalette::Inactive, QColorGroup::Midlight },
 	// Dark shadow for three-dimensional display elements.
-    { "threedshadow", wmgroup, 0, QPalette::Inactive, QColorGroup::Shadow },
+    { "threedshadow", QPalette::Inactive, QColorGroup::Shadow },
 
-    // Inactive window border.
-    { "inactiveborder", wmgroup, "background", QPalette::Disabled, QColorGroup::Background },
-    // Inactive window caption.
-    { "inactivecaption", wmgroup, "inactiveBackground", QPalette::Disabled, QColorGroup::Background },
-    // Color of text in an inactive caption.
-    { "inactivecaptiontext", wmgroup, "inactiveForeground", QPalette::Disabled, QColorGroup::Text },
-    { "graytext", wmgroup, 0, QPalette::Disabled, QColorGroup::Text },
+    { "graytext", QPalette::Disabled, QColorGroup::Text },
 
 	// Menu background
-    { "menu", generalgroup, "background", QPalette::Inactive, QColorGroup::Background },
+    { "menu", QPalette::Inactive, QColorGroup::Background },
 	// Text in menus
-    { "menutext", generalgroup, "foreground", QPalette::Inactive, QColorGroup::Background },
+    { "menutext", QPalette::Inactive, QColorGroup::Background }, // MR: shouldn't this be QColorGroup::Foreground
 
         // Text of item(s) selected in a control.
-    { "highlight", generalgroup, "selectBackground", QPalette::Inactive, QColorGroup::Background },
+    { "highlight", QPalette::Inactive, QColorGroup::Background }, // MR: shouldn't this be QColorGroup::Highlight
 
     // Text of item(s) selected in a control.
-    { "highlighttext", generalgroup, "selectForeground", QPalette::Inactive, QColorGroup::Background },
+    { "highlighttext", QPalette::Inactive, QColorGroup::Background }, // MR: shouldn't this be QColorGroup::HighlightedText
 
 	// Background color of multiple document interface.
-    { "appworkspace", generalgroup, "background", QPalette::Inactive, QColorGroup::Text },
+    { "appworkspace", QPalette::Inactive, QColorGroup::Text }, // MR: shouldn't this be QColorGroup::Base
 
 	// Scroll bar gray area.
-    { "scrollbar", generalgroup, "background", QPalette::Inactive, QColorGroup::Background },
+    { "scrollbar", QPalette::Inactive, QColorGroup::Background },
 
 	// Window background.
-    { "window", generalgroup, "windowBackground", QPalette::Inactive, QColorGroup::Background },
+    { "window", QPalette::Inactive, QColorGroup::Background },
 	// Window frame.
-    { "windowframe", generalgroup, "windowBackground", QPalette::Inactive, QColorGroup::Background },
+    { "windowframe", QPalette::Inactive, QColorGroup::Background },
         // WindowText
-    { "windowtext", generalgroup, "windowForeground", QPalette::Inactive, QColorGroup::Text },
-    { "text", generalgroup, 0, QPalette::Inactive, QColorGroup::Text },
-    { 0, 0, 0, QPalette::NColorGroups, QColorGroup::NColorRoles }
+    { "windowtext", QPalette::Inactive, QColorGroup::Text }, // MR: shouldn't this be QColorGroup::Foreground
+    { "text", QPalette::Inactive, QColorGroup::Text },
+    { 0, QPalette::NColorGroups, QColorGroup::NColorRoles }
 };
 
 HTMLColors::HTMLColors()
 {
+  // Local HTML palette for widget colors ( code taken from KApplication )
+  KConfig *config = KGlobal::config();
+  QString lastConfigGroup = config->group();
+  config->setGroup( "HTML Colors" );
+
+  int contrast_ = KGlobalSettings::contrast();
+  const QPalette &defaultPal = kapp->palette();
+
+  QColor background = config->readColorEntry( "background", &defaultPal.active().background() );
+  QColor foreground = config->readColorEntry( "foreground", &defaultPal.active().foreground() );
+  QColor button = config->readColorEntry( "buttonBackground", &background );
+  QColor buttonText = config->readColorEntry( "buttonForeground", &foreground );
+  QColor highlight = config->readColorEntry( "selectBackground", &defaultPal.active().highlight() );
+  QColor highlightedText = config->readColorEntry( "selectForeground", &defaultPal.active().highlightedText() );
+  QColor base = config->readColorEntry( "windowBackground", &defaultPal.active().base() );
+  QColor baseText = config->readColorEntry( "windowForeground", &defaultPal.active().text() );
+  QColor link = config->readColorEntry( "linkColor", &defaultPal.active().link() );
+  QColor visitedLink = config->readColorEntry( "visitedLinkColor", &defaultPal.active().linkVisited() );
+
+  int highlightVal = 100 + (2*contrast_+4)*16/10;
+  int lowlightVal = 100 + (2*contrast_+4)*10;
+
+  QColor disfg = foreground;
+
+  int h, s, v;
+  disfg.hsv( &h, &s, &v );
+  if (v > 128)
+    // dark bg, light fg - need a darker disabled fg
+    disfg = disfg.dark(lowlightVal);
+  else if (disfg != Qt::black)
+    // light bg, dark fg - need a lighter disabled fg - but only if !black
+    disfg = disfg.light(highlightVal);
+  else
+    // black fg - use darkgrey disabled fg
+    disfg = Qt::darkGray;
+
+
+  QColorGroup disabledgrp(disfg, background,
+                          background.light(highlightVal),
+                          background.dark(lowlightVal),
+                          background.dark(120),
+                          background.dark(120), base);
+
+  QColorGroup colgrp(foreground, background, background.light(highlightVal),
+                     background.dark(lowlightVal),
+                     background.dark(120),
+                     baseText, base);
+
+  int inlowlightVal = lowlightVal-25;
+  if(inlowlightVal < 120)
+    inlowlightVal = 120;
+
+  colgrp.setColor(QColorGroup::Highlight, highlight);
+  colgrp.setColor(QColorGroup::HighlightedText, highlightedText);
+  colgrp.setColor(QColorGroup::Button, button);
+  colgrp.setColor(QColorGroup::ButtonText, buttonText);
+  colgrp.setColor(QColorGroup::Midlight, background.light(110));
+  colgrp.setColor(QColorGroup::Link, link);
+  colgrp.setColor(QColorGroup::LinkVisited, visitedLink);
+
+  disabledgrp.setColor(QColorGroup::Button, button);
+
+  QColor disbtntext = buttonText;
+  disbtntext.hsv( &h, &s, &v );
+  if (v > 128)
+    // dark button, light buttonText - need a darker disabled buttonText
+    disbtntext = disbtntext.dark(lowlightVal);
+  else if (disbtntext != Qt::black)
+    // light buttonText, dark button - need a lighter disabled buttonText - but only if !black
+    disbtntext = disbtntext.light(highlightVal);
+  else
+    // black button - use darkgrey disabled buttonText
+    disbtntext = Qt::darkGray;
+
+  disabledgrp.setColor(QColorGroup::ButtonText, disbtntext);
+  disabledgrp.setColor(QColorGroup::Midlight, background.light(110));
+  disabledgrp.setColor(QColorGroup::Link, link);
+  disabledgrp.setColor(QColorGroup::LinkVisited, visitedLink);
+
+  QPalette htmlPal(colgrp, disabledgrp, colgrp);
+
+  config->setGroup( lastConfigGroup );
+
+
     const colorMap *color = cmap;
     while ( color->name ) {
 	map[color->name] = color->value;
 	++color;
     }
+
     // ### react to style changes
     // see http://www.richinstyle.com for details
 
@@ -148,21 +244,27 @@ HTMLColors::HTMLColors()
      * Tried hard to get an appropriate mapping - schlpbch
      */
 
-    KConfig *globalConfig = KGlobal::config();
-    const QPalette &pal = kapp->palette();
+  // set widget colors
+  const widgetColors *widgetcol = widgetmap;
+  while( widgetcol->name ) {
+    QColor c = htmlPal.color( widgetcol->group, widgetcol->role );
+    map[widgetcol->name] = c;
+    ++widgetcol;
+  }
 
-    const uiColors *uicol = uimap;
+  // set decoration colors
+  const decoColors *decocol = decomap;
     const char *lastConfigGroup = 0;
-    while( uicol->name ) {
-	if ( lastConfigGroup != uicol->configGroup ) {
-	    lastConfigGroup = uicol->configGroup;
+  while( decocol->name ) {
+    if ( lastConfigGroup != decocol->configGroup ) {
+      lastConfigGroup = decocol->configGroup;
 	    globalConfig->setGroup( lastConfigGroup );
 	}
-	QColor c = pal.color( uicol->group, uicol->role );
-	if ( uicol->configEntry )
-	    c = globalConfig->readColorEntry( uicol->configEntry, &c );
-	map[uicol->name] = c;
-	++uicol;
+    QColor c = htmlPal.color( decocol->group, decocol->role );
+    if ( decocol->configEntry )
+	    c = globalConfig->readColorEntry( decocol->configEntry, &c );
+    map[decocol->name] = c;
+    ++decocol;
     }
 
 #ifndef QT_NO_TOOLTIP
@@ -175,7 +277,7 @@ HTMLColors::HTMLColors()
     KConfig bckgrConfig("kdesktoprc", true, false); // No multi-screen support
     bckgrConfig.setGroup("Desktop0");
         // Desktop background.
-    map["background"] = bckgrConfig.readColorEntry("Color1", &pal.disabled().background());
+  map["background"] = bckgrConfig.readColorEntry("Color1", &htmlPal.disabled().background());
 };
 
 
Index: rendering/render_html.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/rendering/render_html.cpp,v
retrieving revision 1.24
diff -b -u -p -r1.24 render_html.cpp
--- rendering/render_html.cpp	2002/01/14 19:56:45	1.24
+++ rendering/render_html.cpp	2002/10/28 15:14:54
@@ -26,6 +26,9 @@
 
 #include "khtmlview.h"
 
+#include <kglobal.h>
+#include <kapplication.h>
+#include <kconfig.h>
 #include <kdebug.h>
 
 using namespace khtml;
@@ -68,7 +71,7 @@ void RenderHtml::printBoxDecorations(QPa
 	if( !bg )
 	    bg = firstChild()->style()->backgroundImage();
         if( !c.isValid() && root()->view())
-            c = root()->view()->palette().active().color(QColorGroup::Base);
+        c = root()->view()->viewport()->palette().active().color(QColorGroup::Base);
     }
 
     int w = width();
Index: rendering/render_replaced.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/rendering/render_replaced.cpp,v
retrieving revision 1.103
diff -b -u -p -r1.103 render_replaced.cpp
--- rendering/render_replaced.cpp	2002/10/17 02:29:50	1.103
+++ rendering/render_replaced.cpp	2002/10/28 15:14:55
@@ -228,7 +228,7 @@ void RenderWidget::updateFromElement()
         QColor backgroundColor = style()->backgroundColor();
 
         if ( color.isValid() || backgroundColor.isValid() ) {
-            QPalette pal(QApplication::palette(m_widget));
+            QPalette pal(view()->viewport()->palette());
 
             int contrast_ = KGlobalSettings::contrast();
             int highlightVal = 100 + (2*contrast_+4)*16/10;


More information about the kfm-devel mailing list