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

List:       kde-core-devel
Subject:    KColorScheme - additional (convenience) ctors
From:       Matthew Woehlke <mw_triad () users ! sourceforge ! net>
Date:       2007-09-01 3:17:51
Message-ID: fbalkv$ana$1 () sea ! gmane ! org
[Download RAW message or body]

If no one objects, I would like to add additional ctors to KColorScheme 
this Monday (September 3). These will look and behave just like the 
QPalette::ColorGroup ctor, except will take a const QPalette& or const 
QWidget& (effectively they will be the same except will use the current 
state of the QPalette or QWidget), which will make porting from the old 
ctor more convenient (for "proper use" users, anyway).

Patch attached.

-- 
Matthew
"I can hear you / just barely hear you / I can just barely hear you"
   -- "I Can Hear You", by They Might Be Giants

["kcs-convenient-ctors.patch" (text/x-patch)]

Index: colors/kcolorscheme.cpp
===================================================================
--- colors/kcolorscheme.cpp     (revision 707100)
+++ colors/kcolorscheme.cpp     (working copy)
@@ -25,6 +25,7 @@
 #include <kglobalsettings.h>
 #include <kcolorutils.h>

+#include <QtGui/QWidget>
 #include <QtGui/QColor>
 #include <QtGui/QBrush>

@@ -116,6 +117,21 @@
     // apply state adjustments
     if (state != QPalette::Active) {
         // TODO - now tweak all the colors based on the state!

This hunk will not apply. If you are trying to apply it, maybe you should fix
this block of text that I randomly inserted. Anyway, this is the test code that
I am using until the KCM works. Curious people might want to play around with
it to see what the fuss is about.

Hopefully I'll remember to remove it before checking this patch in :-).

+        // FIXME - this code is temporary, proof-of-concept
+        if (state == QPalette::Inactive) {
+            _colors.bg[0] = KColorUtils::darken(_colors.bg[0], 0.3);
+            _colors.bg[1] = KColorUtils::darken(_colors.bg[1], 0.3);
+            _colors.deco[0] = KColorUtils::darken(_colors.deco[0], 0.3);
+            _colors.deco[1] = KColorUtils::darken(_colors.deco[1], 0.3);
+            for (int i=0; i<7; i++) {
+                _colors.fg[i] = KColorUtils::darken(_colors.fg[i], 0.3);
+            }
+        }
+        else {
+            for (int i=0; i<7; i++) {
+                _colors.fg[i] = KColorUtils::mix(_colors.fg[i], _colors.bg[0], 0.7);
+            }
+        }
     }

     // calculated backgrounds
@@ -203,30 +219,26 @@

 KColorScheme::KColorScheme(ColorSet set, KSharedConfigPtr config)
 {
-    // bleh, copied code, a good reason for this ctor to go away
-    if (!config) {
-        config = KGlobal::config();
-    }
-    switch (set) {
-        case Window:
-            d = new KColorSchemePrivate(config, QPalette::Active, "Colors:Window", \
                defaultWindowColors);
-            break;
-        case Button:
-            d = new KColorSchemePrivate(config, QPalette::Active, "Colors:Button", \
                defaultButtonColors);
-            break;
-        case Selection:
-            d = new KColorSchemePrivate(config, QPalette::Active, \
                "Colors:Selection", defaultSelectionColors);
-            break;
-        case Tooltip:
-            d = new KColorSchemePrivate(config, QPalette::Active, "Colors:Tooltip", \
                defaultTooltipColors);
-            break;
-        default:
-            d = new KColorSchemePrivate(config, QPalette::Active, "Colors:View", \
                defaultViewColors);
-    }
+    init(QPalette::Active, set, config);
 }

 KColorScheme::KColorScheme(QPalette::ColorGroup state, ColorSet set, \
KSharedConfigPtr config)  {
+    init(state, set, config);
+}
+
+KColorScheme::KColorScheme(const QPalette &palette, ColorSet set, KSharedConfigPtr \
config) +{
+    init(palette.currentColorGroup(), set, config);
+}
+
+KColorScheme::KColorScheme(const QWidget &widget, ColorSet set, KSharedConfigPtr \
config) +{
+    init(widget.palette().currentColorGroup(), set, config);
+}
+
+void KColorScheme::init(QPalette::ColorGroup state, ColorSet set, KSharedConfigPtr \
config) +{
     if (!config) {
         config = KGlobal::config();
     }
Index: colors/kcolorscheme.h
===================================================================
--- colors/kcolorscheme.h       (revision 707100)
+++ colors/kcolorscheme.h       (working copy)
@@ -30,6 +30,7 @@
 class KConfigBase;
 class QColor;
 class QBrush;
+class QWidget;

 class KColorSchemePrivate;

@@ -275,6 +276,20 @@
     explicit KColorScheme(QPalette::ColorGroup, ColorSet = View, KSharedConfigPtr = \
KSharedConfigPtr());

     /**
+     * Construct a palette from given color set and state, using the colors
+     * from the given KConfig (if null, the system colors are used). This
+     * convenience overload uses the current state of the specified palette.
+     */
+    explicit KColorScheme(const QPalette&, ColorSet = View, KSharedConfigPtr = \
KSharedConfigPtr()); +
+    /**
+     * Construct a palette from given color set and state, using the colors
+     * from the given KConfig (if null, the system colors are used). This
+     * convenience overload uses the current state of the specified widget.
+     */
+    explicit KColorScheme(const QWidget&, ColorSet = View, KSharedConfigPtr = \
KSharedConfigPtr()); +
+    /**
      * Retrieve the requested background brush.
      */
     QBrush background(BackgroundRole = NormalBackground) const;
@@ -338,6 +353,8 @@
                         qreal contrast, qreal chromaAdjust = 0.0);

 private:
+    void init(QPalette::ColorGroup state, ColorSet set, KSharedConfigPtr config);
+
     QExplicitlySharedDataPointer<KColorSchemePrivate> d;
 };



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

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