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

List:       kde-core-devel
Subject:    Re: setting tooltip colors
From:       Matthew Woehlke <mw_triad () users ! sourceforge ! net>
Date:       2007-10-11 2:26:20
Message-ID: fek1kd$953$1 () sea ! gmane ! org
[Download RAW message or body]

Matthew Woehlke wrote:
> It came to my attention (1) that AFAIK (also tested by jpwhiting) KDE 
> doesn't actually /set/ tooltip colors yet. As I recall, setting them 
> means calling a Qt method, i.e. I am not sure if we can enforce KDE's 
> color preference for non-KDE applications. Anyway, this will require a 
> change in libs; unless someone has a better idea, I guess it will mean 
> setting the colors in KGlobalSettings::createApplicationPalette.
> 
> I'll post the patch when it's ready, but this is a heads-up that a 
> change is needed (and a call for ideas if anyone has better knowledge 
> than me). I do not expect this to affect BC/SC in any way.
> 
> 1: http://permalink.gmane.org/gmane.comp.kde.general/17490

Here is the patch (attached; tested with kwrite). Can I please get an 
go/no-go to commit this?

I am still thinking about having KStyle (or at least oxygen for now) do 
this also, to catch at least Qt-only applications when using a KStyle, 
but to do it "nicely" (i.e. not duplicate this code) really needs the 
introduction of createTooltipPalette in KGlobalSettings. Thus, two 
obvious options:

- add it, breaking the freeze for this small change
- wait for 4.1, meanwhile duplicating this code

There is also a less obvious option (that I think I may prefer, to be 
honest): add the method as a global function in kglobalsettings.cpp, 
with an 'extern' declaration in kstyle.cpp. This would allow KStyle to 
use it, without the function being exported or declared in any header, 
since KStyle (now) also lives in kdeui. Of course this only works if we 
put the code in KStyle right away, which means probably going with 
option 2 (duplicate the code) until 4.1 anyway.

Thoughts?

-- 
Matthew
If you can read this, you're too close.

["set-tooltip-colors.patch" (text/x-patch)]

Index: kernel/kglobalsettings.cpp
===================================================================
--- kernel/kglobalsettings.cpp  (revision 723885)
+++ kernel/kglobalsettings.cpp  (working copy)
@@ -44,6 +44,7 @@
 #include <QApplication>
 #include <QtDBus/QtDBus>
 #include <QtGui/QStyleFactory>
+#include <QtGui/QToolTip>

 #ifdef Q_WS_WIN
 #include <windows.h>
@@ -850,6 +851,7 @@
 QPalette KGlobalSettings::createApplicationPalette(const KSharedConfigPtr &config)
 {
     QPalette palette;
+    QPalette tooltipPalette = QToolTip::palette();

     QPalette::ColorGroup states[3] = { QPalette::Active, QPalette::Inactive,
                                        QPalette::Disabled };
@@ -881,6 +883,35 @@
         palette.setBrush( state, QPalette::LinkVisited, schemeView.foreground( \
KColorScheme::VisitedText ) );  }

+    for ( int i = 0; i < 3 ; i++ ) {
+        // tooltips are never active (arguably a bug?), but should be drawn as if \
they were +        QPalette::ColorGroup state = states[i];
+        QPalette::ColorGroup stateUsed = (state == QPalette::Inactive ? \
QPalette::Active : state); +        KColorScheme schemeButton(stateUsed, \
KColorScheme::Button, config); +        KColorScheme schemeSelection(stateUsed, \
KColorScheme::Selection, config); +        KColorScheme schemeTooltip(stateUsed, \
KColorScheme::Tooltip, config); +
+        tooltipPalette.setBrush( state, QPalette::WindowText, \
schemeTooltip.foreground() ); +        tooltipPalette.setBrush( state, \
QPalette::Window, schemeTooltip.background() ); +        tooltipPalette.setBrush( \
state, QPalette::Base, schemeTooltip.background() ); +        \
tooltipPalette.setBrush( state, QPalette::Text, schemeTooltip.foreground() ); +       \
tooltipPalette.setBrush( state, QPalette::Button, schemeButton.background() ); +      \
tooltipPalette.setBrush( state, QPalette::ButtonText, schemeButton.foreground() ); +  \
tooltipPalette.setBrush( state, QPalette::Highlight, schemeSelection.background() ); \
+        tooltipPalette.setBrush( state, QPalette::HighlightedText, \
schemeSelection.foreground() ); +
+        tooltipPalette.setColor( state, QPalette::Light, schemeTooltip.shade( \
KColorScheme::LightShade ) ); +        tooltipPalette.setColor( state, \
QPalette::Midlight, schemeTooltip.shade( KColorScheme::MidlightShade ) ); +        \
tooltipPalette.setColor( state, QPalette::Mid, schemeTooltip.shade( \
KColorScheme::MidShade ) ); +        tooltipPalette.setColor( state, QPalette::Dark, \
schemeTooltip.shade( KColorScheme::DarkShade ) ); +        tooltipPalette.setColor( \
state, QPalette::Shadow, schemeTooltip.shade( KColorScheme::ShadowShade ) ); +
+        tooltipPalette.setBrush( state, QPalette::AlternateBase, \
schemeTooltip.background( KColorScheme::AlternateBackground) ); +        \
tooltipPalette.setBrush( state, QPalette::Link, schemeTooltip.foreground( \
KColorScheme::LinkText ) ); +        tooltipPalette.setBrush( state, \
QPalette::LinkVisited, schemeTooltip.foreground( KColorScheme::VisitedText ) ); +    \
} +
+    QToolTip::setPalette(tooltipPalette);
     return palette;
 }



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

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