[Kstars-devel] KDE/kdeedu/kstars/kstars

Jason Harris kstars at 30doradus.org
Thu Jan 24 17:56:16 CET 2008


SVN commit 765743 by harris:

Make color scheme settings persistent across restarts.  The problem
was in the ColorScheme ctor, I set the colors to their defaults, and
then tried to read from the config object.  However, setColor() writes
to the config, so the config was being overwritten by the defaults on
startup.  Now the ctor just reads from the config (which has defaults
anyway).

CCMAIL: kstars-devel at kde.org



 M  +11 -8     colorscheme.cpp  
 M  +2 -4      colorscheme.h  
 M  +1 -1      kstars.cpp  
 M  +12 -12    kstars.kcfg  
 M  +1 -1      kstarsactions.cpp  
 M  +1 -1      main.cpp  


--- trunk/KDE/kdeedu/kstars/kstars/colorscheme.cpp #765742:765743
@@ -118,10 +118,8 @@
     Name.append( i18n( "Satellite Track" ) );
     Default.append( "#007777" );
 
-    //Set the default colors in the Palette.
-    for ( int i=0; i<KeyName.size(); ++i ) {
-        setColor( KeyName[i], Default[i] );
-    }
+		//Load colors from config object
+		loadFromConfig();
 
     //Default values for integer variables:
     StarColorMode = 0;
@@ -180,6 +178,9 @@
 void ColorScheme::setColor( const QString &key, const QString &color ) {
     //We can blindly insert() the new value; if the key exists, the old value is replaced
     Palette.insert( key, color );
+
+    KConfigGroup cg = KGlobal::config()->group( "Colors" );
+    cg.writeEntry( key, color );
 }
 
 bool ColorScheme::load( const QString &name ) {
@@ -316,11 +317,13 @@
     }
 
     FileName = filename;
+    saveToConfig();
     return true;
 }
 
-void ColorScheme::loadFromConfig( KConfig *conf ) {
-    KConfigGroup cg (conf, "");
+void ColorScheme::loadFromConfig() {
+    KConfigGroup cg = KGlobal::config()->group( "Colors" );
+
     for ( int i=0; i < KeyName.size(); ++i )
         setColor( KeyName.at(i), cg.readEntry( KeyName.at(i).toUtf8().constData(), Default.at( i ) ) );
 
@@ -328,8 +331,8 @@
     setStarColorIntensity( cg.readEntry( "StarColorIntensity", 5 ) );
 }
 
-void ColorScheme::saveToConfig( KConfig *conf ) {
-    KConfigGroup cg (conf, "");
+void ColorScheme::saveToConfig() {
+    KConfigGroup cg = KGlobal::config()->group( "Colors" );
     for ( int i=0; i < KeyName.size(); ++i ) {
         QString c = colorNamed( KeyName.at(i) ).name();
         cg.writeEntry( KeyName.at(i), c );
--- trunk/KDE/kdeedu/kstars/kstars/colorscheme.h #765742:765743
@@ -22,8 +22,6 @@
 #include <qmap.h>
 #include <qstringlist.h>
 
-class KConfig;
-
 /**
 	*@class ColorScheme
 	*This class stores all of the adjustable colors in KStars, in 
@@ -127,12 +125,12 @@
     /**
       *Read color-scheme data from the Config object.
     	*/
-    void loadFromConfig( KConfig* );
+    void loadFromConfig();
 
     /**
       *Save color-scheme data to the Config object.
     	*/
-    void saveToConfig( KConfig* );
+    void saveToConfig();
 
     /**
       *@return the number of colors in the color scheme.
--- trunk/KDE/kdeedu/kstars/kstars/kstars.cpp #765742:765743
@@ -174,7 +174,7 @@
     ((KToggleAction*)actionCollection()->action("show_horizon"))->setChecked( Options::showGround() );
 
     //color scheme
-    kstarsData->colorScheme()->loadFromConfig( KGlobal::config().data() );
+    kstarsData->colorScheme()->loadFromConfig();
     if ( Options::darkAppColors() ) {
         QApplication::setPalette( DarkPalette );
     } else {
--- trunk/KDE/kdeedu/kstars/kstars/kstars.kcfg #765742:765743
@@ -534,18 +534,6 @@
 			<whatsthis>The background fill mode for the on-screen information boxes: 0="no BG"; 1="semi-transparent BG"; 2="opaque BG"</whatsthis>
 			<default>1</default>
 		</entry>
-		<entry name="StarColorMode" type="UInt">
-			<label>Mode for rendering stars</label>
-			<whatsthis>The method for rendering stars: 0="realistic colors"; 1="solid red"; 2="solid black"; 3="solid white"</whatsthis>
-			<default>0</default>
-			<max>3</max>
-		</entry>
-		<entry name="StarColorIntensity" type="UInt">
-			<label>Saturation level of star colors</label>
-			<whatsthis>The color saturation level of stars (only applicable when using "realistic colors" mode).</whatsthis>
-			<default>4</default>
-			<max>10</max>
-		</entry>
 		<entry name="Projection" type="UInt">
 			<label>Mapping projection algorithm</label>
 			<whatsthis>Algorithm for the mapping projection.</whatsthis>
@@ -665,6 +653,18 @@
 			<whatsthis>If true, then the application window colors will be switched to a dark red theme, for better night vision.</whatsthis>
 			<default>false</default>
 		</entry>
+		<entry name="StarColorMode" type="UInt">
+			<label>Mode for rendering stars</label>
+			<whatsthis>The method for rendering stars: 0="realistic colors"; 1="solid red"; 2="solid black"; 3="solid white"</whatsthis>
+			<default>0</default>
+			<max>3</max>
+		</entry>
+		<entry name="StarColorIntensity" type="UInt">
+			<label>Saturation level of star colors</label>
+			<whatsthis>The color saturation level of stars (only applicable when using "realistic colors" mode).</whatsthis>
+			<default>4</default>
+			<max>10</max>
+		</entry>
 		<entry name="AngularRulerColor" type="String">
 			<label>Color of angular distance ruler</label>
 			<whatsthis>The color for the angular-distance measurement ruler.</whatsthis>
--- trunk/KDE/kdeedu/kstars/kstars/kstarsactions.cpp #765742:765743
@@ -1074,7 +1074,7 @@
     Options::setWindowHeight( height() );
 
     //explicitly save the colorscheme data to the config file
-    data()->colorScheme()->saveToConfig( KGlobal::config().data() );
+    data()->colorScheme()->saveToConfig();
 
     KConfigGroup cg = KGlobal::config()->group( "MainToolBar" );
     //explicitly save toolbar settings to config file
--- trunk/KDE/kdeedu/kstars/kstars/main.cpp #765742:765743
@@ -103,7 +103,7 @@
         dat->setLocationFromOptions();
 
         //Set color scheme
-        dat->colorScheme()->loadFromConfig( KGlobal::config().data() );
+        dat->colorScheme()->loadFromConfig();
 
         //set clock now that we have a location:
         //Check to see if user provided a date/time string.  If not, use current CPU time


More information about the Kstars-devel mailing list