Public feed #727474

Anonymous

public text v1 · immutable
Raw Edit
·published 2007-10-06 01:15 UTC
rendered paste body
Index: colorscm.cpp
===================================================================
--- colorscm.cpp	(revision 721614)
+++ colorscm.cpp	(working copy)
@@ -20,6 +20,7 @@
 
 #include "colorscm.h"
 
+#include <QtCore/QFileInfo>
 #include <QtGui/QHeaderView>
 #include <QtGui/QStackedWidget>
 #include <QtDBus/QtDBus>
@@ -31,6 +32,7 @@
 #include <KGlobalSettings>
 #include <KAboutData>
 #include <KListWidget>
+#include <KStandardDirs>
 
 K_PLUGIN_FACTORY( KolorFactory, registerPlugin<KColorCm>(); )
 K_EXPORT_PLUGIN( KolorFactory("kcmcolors") )
@@ -53,7 +55,11 @@
     setupUi(this);
 
     connect(colorSet, SIGNAL(currentIndexChanged(int)), this, SLOT(updateColorTable()));
+    connect(schemeList, SIGNAL(currentRowChanged(int)), this, SLOT(loadScheme()));
 
+    // only needs to be called once
+    setupColorTable();
+
     load();
 }
 
@@ -62,6 +68,39 @@
     m_config->rollback();
 }
 
+void KColorCm::populateSchemeList()
+{
+    QStringList schemeFiles = KGlobal::dirs()->findAllResources("data", "color-schemes/*");
+    for (int i = 0; i < schemeFiles.size(); ++i)
+    {
+        // TODO: add some processing to show some sample of the colorscheme in the icon 
+        // like kde3 colors kcm had
+        QString filename = schemeFiles[i];
+        QFileInfo info(filename);
+        schemeList->addItem(info.fileName());
+    }
+}
+
+void KColorCm::loadScheme()
+{
+    if (schemeList->currentItem() != NULL)
+    {
+        QString path = KGlobal::dirs()->findResource("data", 
+            "color-schemes/" + schemeList->currentItem()->text());
+        KSharedConfigPtr temp = m_config;
+        m_config = KSharedConfig::openConfig(path);
+        updateColorSchemes();
+        updateColorTable();
+
+        schemePreview->setPalette(m_config);
+        inactivePreview->setPalette(m_config, QPalette::Inactive);
+        disabledPreview->setPalette(m_config, QPalette::Disabled);
+
+        m_config = temp;
+        emit changed(true);
+    }
+}
+
 void KColorCm::createColorEntry(QString text, QString key, QList<KColorButton *> &list, int index)
 {
     KColorButton *button = new KColorButton(this);
@@ -163,6 +202,7 @@
     colorTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
     colorTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
 
+    updateColorSchemes();
     updateColorTable();
 }
 
@@ -513,9 +553,11 @@
     // rollback the config, in case we have changed the in-memory kconfig
     m_config->rollback();
 
-    updateColorSchemes();
+    // update the color table
+    updateColorTable();
 
-    setupColorTable();
+    // fill in the color scheme list
+    populateSchemeList();
 
     contrastSlider->setValue(KGlobalSettings::contrast());
     shadeSortedColumn->setCheckState(KGlobalSettings::shadeSortColumn() ?
Index: colorscm.h
===================================================================
--- colorscm.h	(revision 721614)
+++ colorscm.h	(working copy)
@@ -60,18 +60,24 @@
 
     /** slot called when color on a KColorButton changes */
     void colorChanged( const QColor &newColor );
-    
+
     /** slot called when the contrast slider on the main page changes */
     void on_contrastSlider_valueChanged(int value);
-    
+
     /** slot called when the shadeSortedColumn checkbox is checked/unchecked */
     void on_shadeSortedColumn_stateChanged(int state);
-    
+
     /** slot called when any varies button is clicked */
     void variesClicked();
 
+    /** slot called when the schemeList selection changes */
+    void loadScheme();
+
 private:
 
+    /** populate the schemeList with color schemes found on the system */
+    void populateSchemeList();
+
     /** update m_colorSchemes contents from the values in m_config */
     void updateColorSchemes();