[kstars] kstars: Update color schemes to properly account for Dark Palette option. It was only enabled for night vision scheme, but if a user customizes the night vision scheme and saves it as a new scheme then

Jasem Mutlaq null at kde.org
Sat Feb 4 13:01:58 UTC 2017


Git commit 849a505d31a43e2c182046e78d49f1f7e9b4ada1 by Jasem Mutlaq.
Committed on 04/02/2017 at 12:59.
Pushed by mutlaqja into branch 'master'.

Update color schemes to properly account for Dark Palette option. It was only enabled for night vision scheme, but if a user customizes the night vision scheme and saves it as a new scheme then
dark palette is no longer used because it was hard-coded to night vision scheme only. Now it is a separate option that is saved to both config and color scheme files. Please test.

CCMAIL:kstars-devel at kde.org

M  +35   -7    kstars/auxiliary/colorscheme.cpp
M  +10   -1    kstars/auxiliary/colorscheme.h
M  +1    -1    kstars/data/chart.colors
M  +1    -1    kstars/data/classic.colors
M  +1    -1    kstars/data/moonless-night.colors
M  +1    -1    kstars/data/night.colors
M  +12   -8    kstars/kstarsdbus.cpp
M  +9    -0    kstars/options/opscolors.cpp
M  +1    -0    kstars/options/opscolors.h
M  +87   -17   kstars/options/opscolors.ui

https://commits.kde.org/kstars/849a505d31a43e2c182046e78d49f1f7e9b4ada1

diff --git a/kstars/auxiliary/colorscheme.cpp b/kstars/auxiliary/colorscheme.cpp
index 9c926762e..752f1e6f0 100644
--- a/kstars/auxiliary/colorscheme.cpp
+++ b/kstars/auxiliary/colorscheme.cpp
@@ -101,6 +101,7 @@ ColorScheme::ColorScheme() : FileName() {
     //Default values for integer variables:
     StarColorMode = 0;
     StarColorIntensity = 4;
+    DarkPalette = 0;
 }
 
 void ColorScheme::appendItem(QString key, QString name, QString def) {
@@ -178,17 +179,34 @@ bool ColorScheme::load( const QString &name ) {
     //If we reach here, the file should have been successfully opened
     QTextStream stream( &file );
 
-    //first line is the star-color mode and star color intensity
+    //first line is the star-color mode and star color intensity and dark palette
     QString line = stream.readLine();
-    int newmode = line.left(1).toInt( &ok );
-    if( ok )
-        setStarColorMode( newmode );
-    if( line.contains(':') ) {
-        int newintens = line.mid( line.indexOf(':')+1, 2 ).toInt( &ok );
+    QStringList modes = line.split(":");
+
+    // Star Color Mode
+    if (modes.count() > 0)
+    {
+        int newmode = modes[0].toInt( &ok );
+        if( ok )
+            setStarColorMode( newmode );
+    }
+
+    // Star Intensity
+    if (modes.count() > 1)
+    {
+        int newintens = modes[1].toInt( &ok );
         if ( ok )
             setStarColorIntensity( newintens );
     }
 
+    // Dark Palette
+    if (modes.count() > 2)
+    {
+        int newintens = modes[2].toInt( &ok );
+        if ( ok )
+            setDarkPalette(newintens == 1);
+    }
+
     //More flexible method for reading in color values.  Any order is acceptable, and
     //missing entries are ignored.
     while ( !stream.atEnd() ) {
@@ -254,7 +272,7 @@ bool ColorScheme::save( const QString &name ) {
             return false;
         } else {
             QTextStream stream( &file );
-            stream << StarColorMode << ":" << StarColorIntensity << endl;
+            stream << StarColorMode << ":" << StarColorIntensity << ":" << DarkPalette << endl;
 
             foreach(const QString& key, KeyName )
                 stream << Palette[ key ] << " :" << key << endl;
@@ -298,6 +316,7 @@ void ColorScheme::loadFromConfig() {
         setColor( KeyName.at(i), cg.readEntry( KeyName.at(i).toUtf8().constData(), Default.at( i ) ) );
 
     setStarColorModeIntensity( cg.readEntry( "StarColorMode", 0 ), cg.readEntry( "StarColorIntensity", 5 ) );
+    setDarkPalette(cg.readEntry("DarkAppColors", false));
 
     FileName = cg.readEntry( "ColorSchemeFile", "moonless-night.colors" );
 }
@@ -312,6 +331,7 @@ void ColorScheme::saveToConfig() {
     cg.writeEntry( "StarColorMode", starColorMode() );
     cg.writeEntry( "StarColorIntensity", starColorIntensity() );
     cg.writeEntry( "ColorSchemeFile", FileName);
+    cg.writeEntry( "DarkAppColors", useDarkPalette());
 }
 
 void ColorScheme::setStarColorMode( int mode ) { 
@@ -322,6 +342,14 @@ void ColorScheme::setStarColorMode( int mode ) {
 #endif
 }
 
+void ColorScheme::setDarkPalette( bool enable ) {
+    DarkPalette = enable ? 1 : 0 ;
+    Options::setDarkAppColors(enable);
+#ifndef KSTARS_LITE
+    SkyQPainter::initStarImages();
+#endif
+}
+
 void ColorScheme::setStarColorIntensity( int intens ) { 
     StarColorIntensity = intens;
     Options::setStarColorIntensity( intens );
diff --git a/kstars/auxiliary/colorscheme.h b/kstars/auxiliary/colorscheme.h
index ffff1a61f..919d429cf 100644
--- a/kstars/auxiliary/colorscheme.h
+++ b/kstars/auxiliary/colorscheme.h
@@ -104,6 +104,9 @@ public:
     /** @return the star color mode used by the color scheme */
     int starColorMode() const { return StarColorMode; }
 
+    /** @return True if dark palette colors are used by the color scheme */
+    bool useDarkPalette() const { return DarkPalette == 1; }
+
     /** @return the star color intensity value used by the color scheme */
     int starColorIntensity() const { return StarColorIntensity; }
 
@@ -123,11 +126,17 @@ public:
      */
     void setStarColorModeIntensity( int mode, int intens);
 
+    /**
+     * @brief setDarkPalette Set whether the color schemes uses dark palette
+     * @param enable True to use dark palette. False to use application default palette
+     */
+    void setDarkPalette( bool enable );
+
 private:
     /** Append items to all string lists. */
     void appendItem(QString key, QString name, QString def);
 
-    int StarColorMode, StarColorIntensity;
+    int StarColorMode, StarColorIntensity, DarkPalette;
     QString FileName;
     QStringList KeyName, Name, Default;
     QMap<QString,QString> Palette;
diff --git a/kstars/data/chart.colors b/kstars/data/chart.colors
index 7ca5dbadc..4b0d718f2 100644
--- a/kstars/data/chart.colors
+++ b/kstars/data/chart.colors
@@ -1,4 +1,4 @@
-2:0        StarColorMode:StarColorIntensity
+2:0:0
 #FFFFFF :SkyColor
 #00FF00 :MessColor
 #006666 :NGCColor
diff --git a/kstars/data/classic.colors b/kstars/data/classic.colors
index 2b2441651..25e426185 100644
--- a/kstars/data/classic.colors
+++ b/kstars/data/classic.colors
@@ -1,4 +1,4 @@
-0:4        StarColorMode:StarColorIntensity
+0:4:0
 #000022 :SkyColor 
 #00FF00 :MessColor
 #006666 :NGCColor
diff --git a/kstars/data/moonless-night.colors b/kstars/data/moonless-night.colors
index 0a48f76d7..0c985e63d 100644
--- a/kstars/data/moonless-night.colors
+++ b/kstars/data/moonless-night.colors
@@ -1,4 +1,4 @@
-0:4
+0:4:0
 #000000 :SkyColor
 #008f00 :MessColor
 #006666 :NGCColor
diff --git a/kstars/data/night.colors b/kstars/data/night.colors
index 85cf938b8..470561cfb 100644
--- a/kstars/data/night.colors
+++ b/kstars/data/night.colors
@@ -1,4 +1,4 @@
-1:0        StarColorMode:StarColorIntensity
+1:0:1
 #000000 :SkyColor
 #CC0099 :MessColor
 #CC0099 :NGCColor 
diff --git a/kstars/kstarsdbus.cpp b/kstars/kstarsdbus.cpp
index 5deab5ae6..22db62536 100644
--- a/kstars/kstarsdbus.cpp
+++ b/kstars/kstarsdbus.cpp
@@ -400,13 +400,16 @@ void KStars::setColor( const QString &name, const QString &value ) {
 
 void KStars::loadColorScheme( const QString &name ) {
     bool ok = data()->colorScheme()->load( name );
-    QString filename = data()->colorScheme()->fileName();
+    //QString filename = data()->colorScheme()->fileName();
 
-    if ( ok ) {
+    if ( ok )
+    {
         //set the application colors for the Night Vision scheme
-        if ( Options::darkAppColors() == false && filename == "night.colors" )  {
-            Options::setDarkAppColors( true );
-            OriginalPalette = QApplication::palette();
+        //if ( Options::darkAppColors() == false && filename == "night.colors" )  {
+            //Options::setDarkAppColors( true );
+        if (Options::darkAppColors())
+        {
+            //OriginalPalette = QApplication::palette();
             QApplication::setPalette( DarkPalette );
             //Note:  This uses style sheets to set the dark colors, this is cross platform.  Palettes have a different behavior on OS X and Windows as opposed to Linux.
             //It might be a good idea to use stylesheets in the future instead of palettes but this will work for now for OS X.
@@ -437,9 +440,10 @@ void KStars::loadColorScheme( const QString &name ) {
                                 "");
             #endif
         }
-
-        if ( Options::darkAppColors() && filename != "night.colors" ) {
-            Options::setDarkAppColors( false );
+        else
+        {
+        //if ( Options::darkAppColors() && filename != "night.colors" ) {
+            //Options::setDarkAppColors( false );
             QApplication::setPalette( OriginalPalette );
             #ifdef Q_OS_OSX
             qApp->setStyleSheet("QRoundProgressBar { background-color: rgb(208,208,208) }" \
diff --git a/kstars/options/opscolors.cpp b/kstars/options/opscolors.cpp
index 62c1e9368..6fb80245b 100644
--- a/kstars/options/opscolors.cpp
+++ b/kstars/options/opscolors.cpp
@@ -102,9 +102,12 @@ OpsColors::OpsColors()
     else
         kcfg_StarColorIntensity->setEnabled( true );
 
+    kcfg_DarkAppColors->setChecked(KStarsData::Instance()->colorScheme()->useDarkPalette());
+
     connect( ColorPalette, SIGNAL( itemClicked( QListWidgetItem* ) ), this, SLOT( newColor( QListWidgetItem* ) ) );
     connect( kcfg_StarColorIntensity, SIGNAL( valueChanged( int ) ), this, SLOT( slotStarColorIntensity( int ) ) );
     connect( kcfg_StarColorMode, SIGNAL( activated( int ) ), this, SLOT( slotStarColorMode( int ) ) );
+    connect( kcfg_DarkAppColors, SIGNAL(toggled(bool)), this, SLOT(slotDarkAppColors(bool)));
     connect( PresetBox, SIGNAL( currentRowChanged( int ) ), this, SLOT( slotPreset( int ) ) );
     connect( AddPreset, SIGNAL( clicked() ), this, SLOT( slotAddPreset() ) );
     connect( RemovePreset, SIGNAL( clicked() ), this, SLOT( slotRemovePreset() ) );
@@ -165,6 +168,7 @@ bool OpsColors::setColors( const QString &filename ) {
 
     kcfg_StarColorMode->setCurrentIndex( KStarsData::Instance()->colorScheme()->starColorMode() );
     kcfg_StarColorIntensity->setValue( KStarsData::Instance()->colorScheme()->starColorIntensity() );
+    kcfg_DarkAppColors->setChecked(KStarsData::Instance()->colorScheme()->useDarkPalette());
 
     for ( unsigned int i=0; i < KStarsData::Instance()->colorScheme()->numberOfColors(); ++i ) {
         QColor itemColor( KStarsData::Instance()->colorScheme()->colorAt( i ) );
@@ -274,4 +278,9 @@ void OpsColors::slotStarColorIntensity( int i ) {
     KStarsData::Instance()->colorScheme()->setStarColorIntensity( i );
 }
 
+void OpsColors::slotDarkAppColors(bool enable)
+{
+    KStarsData::Instance()->colorScheme()->setDarkPalette(enable);
+}
+
 
diff --git a/kstars/options/opscolors.h b/kstars/options/opscolors.h
index fca9a4fe6..800b2b0d7 100644
--- a/kstars/options/opscolors.h
+++ b/kstars/options/opscolors.h
@@ -52,6 +52,7 @@ private slots:
     void slotRemovePreset();
     void slotStarColorMode( int );
     void slotStarColorIntensity( int );
+    void slotDarkAppColors(bool);
 
 private:
     bool setColors( const QString &filename );
diff --git a/kstars/options/opscolors.ui b/kstars/options/opscolors.ui
index abcb6d551..c2fee6962 100644
--- a/kstars/options/opscolors.ui
+++ b/kstars/options/opscolors.ui
@@ -6,16 +6,25 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>590</width>
-    <height>445</height>
+    <width>447</width>
+    <height>336</height>
    </rect>
   </property>
   <layout class="QHBoxLayout">
    <property name="spacing">
-    <number>6</number>
+    <number>5</number>
    </property>
-   <property name="margin">
-    <number>8</number>
+   <property name="leftMargin">
+    <number>5</number>
+   </property>
+   <property name="topMargin">
+    <number>5</number>
+   </property>
+   <property name="rightMargin">
+    <number>5</number>
+   </property>
+   <property name="bottomMargin">
+    <number>5</number>
    </property>
    <item>
     <widget class="QGroupBox" name="groupBox">
@@ -24,10 +33,19 @@
      </property>
      <layout class="QVBoxLayout">
       <property name="spacing">
-       <number>6</number>
+       <number>5</number>
+      </property>
+      <property name="leftMargin">
+       <number>5</number>
+      </property>
+      <property name="topMargin">
+       <number>5</number>
       </property>
-      <property name="margin">
-       <number>8</number>
+      <property name="rightMargin">
+       <number>5</number>
+      </property>
+      <property name="bottomMargin">
+       <number>5</number>
       </property>
       <item>
        <widget class="QListWidget" name="ColorPalette">
@@ -42,9 +60,18 @@
       <item>
        <layout class="QHBoxLayout">
         <property name="spacing">
-         <number>6</number>
+         <number>3</number>
+        </property>
+        <property name="leftMargin">
+         <number>0</number>
+        </property>
+        <property name="topMargin">
+         <number>0</number>
+        </property>
+        <property name="rightMargin">
+         <number>0</number>
         </property>
-        <property name="margin">
+        <property name="bottomMargin">
          <number>0</number>
         </property>
         <item>
@@ -80,7 +107,16 @@
         <property name="spacing">
          <number>6</number>
         </property>
-        <property name="margin">
+        <property name="leftMargin">
+         <number>0</number>
+        </property>
+        <property name="topMargin">
+         <number>0</number>
+        </property>
+        <property name="rightMargin">
+         <number>0</number>
+        </property>
+        <property name="bottomMargin">
          <number>0</number>
         </property>
         <item>
@@ -108,9 +144,18 @@
       <item>
        <layout class="QHBoxLayout">
         <property name="spacing">
-         <number>6</number>
+         <number>3</number>
         </property>
-        <property name="margin">
+        <property name="leftMargin">
+         <number>0</number>
+        </property>
+        <property name="topMargin">
+         <number>0</number>
+        </property>
+        <property name="rightMargin">
+         <number>0</number>
+        </property>
+        <property name="bottomMargin">
          <number>0</number>
         </property>
         <item>
@@ -132,6 +177,13 @@
         </item>
        </layout>
       </item>
+      <item>
+       <widget class="QCheckBox" name="kcfg_DarkAppColors">
+        <property name="text">
+         <string>Use Dark Palette</string>
+        </property>
+       </widget>
+      </item>
      </layout>
     </widget>
    </item>
@@ -142,10 +194,19 @@
      </property>
      <layout class="QVBoxLayout">
       <property name="spacing">
-       <number>6</number>
+       <number>5</number>
       </property>
-      <property name="margin">
-       <number>8</number>
+      <property name="leftMargin">
+       <number>5</number>
+      </property>
+      <property name="topMargin">
+       <number>5</number>
+      </property>
+      <property name="rightMargin">
+       <number>5</number>
+      </property>
+      <property name="bottomMargin">
+       <number>5</number>
       </property>
       <item>
        <widget class="QListWidget" name="PresetBox">
@@ -159,7 +220,16 @@
       </item>
       <item>
        <layout class="QGridLayout">
-        <property name="margin">
+        <property name="leftMargin">
+         <number>0</number>
+        </property>
+        <property name="topMargin">
+         <number>0</number>
+        </property>
+        <property name="rightMargin">
+         <number>0</number>
+        </property>
+        <property name="bottomMargin">
          <number>0</number>
         </property>
         <property name="spacing">


More information about the Kstars-devel mailing list