changeset 29487:00674bc1446d

provide second color mode for workspace view * gui-preferences-ws.h: using the extensions for color preference keys of different color modes, define the keys for new mode, define preference for the selected modes * gui-settings.cc: slightly change the way for inverting the lightness of the default color * gui-settings.h: update the text and tooltip of the color mode checkbox * settings-dialog.cc (read_workspace_colors): add checkbox for second color mode, connect trigger signal of this checkbox to new slot update_workspace_colors, use new method color_value for reading colors from the settings; (update_workspace_colors): slot for updating the current color picker colors depending on selected color mode; (write_workspace_colors): use new method set_color_value for writing colors to settings depending on color mode; (read_terminal_colors): read integer from color mode settings, not boolean; (write_terminal_colors): test if check box was really found * settings-dialog.h: new slot update_workspace_colors * workspace-model.cc (notice_settings): get colors with new method color_value from gui_settings
author Torsten Lilge <ttl-octave@mailbox.org>
date Sat, 03 Apr 2021 08:26:30 +0200
parents 3dd4301296de
children 2a251de6c1a5
files libgui/src/gui-preferences-ws.h libgui/src/gui-settings.cc libgui/src/gui-settings.h libgui/src/settings-dialog.cc libgui/src/settings-dialog.h libgui/src/workspace-model.cc
diffstat 6 files changed, 75 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/gui-preferences-ws.h	Fri Apr 02 17:02:36 2021 +0200
+++ b/libgui/src/gui-preferences-ws.h	Sat Apr 03 08:26:30 2021 +0200
@@ -27,6 +27,7 @@
 #define octave_gui_preferences_ws_h 1
 
 #include "gui-preferences.h"
+#include "gui-settings.h"
 
 // Workspace view
 
@@ -69,13 +70,18 @@
 const gui_pref
 ws_max_filter_history ("workspaceview/max_filter_history", QVariant (10));
 
-const int ws_colors_count = 3;
+const gui_pref
+ws_color_mode ("workspaceview/color_mode", QVariant (0));
 
-const gui_pref ws_colors[ws_colors_count] =
+const int ws_colors_count = 3;
+const gui_pref ws_colors[2*ws_colors_count] =
 {
-  {"workspaceview/color_a", QVariant (QColor(190,255,255))},
-  {"workspaceview/color_g", QVariant (QColor(255,255,190))},
-  {"workspaceview/color_p", QVariant (QColor(255,190,255))}
+  {"workspaceview/color_a" + settings_color_modes_ext[0], QVariant (QPalette::Button)},
+  {"workspaceview/color_g" + settings_color_modes_ext[0], QVariant (QPalette::Mid)},
+  {"workspaceview/color_p" + settings_color_modes_ext[0], QVariant (QPalette::Dark)},
+  {"workspaceview/color_a" + settings_color_modes_ext[1], QVariant ()},
+  {"workspaceview/color_g" + settings_color_modes_ext[1], QVariant ()},
+  {"workspaceview/color_p" + settings_color_modes_ext[1], QVariant ()}
 };
 
 const QString ws_class_chars ("agp");
--- a/libgui/src/gui-settings.cc	Fri Apr 02 17:02:36 2021 +0200
+++ b/libgui/src/gui-settings.cc	Sat Apr 03 08:26:30 2021 +0200
@@ -58,7 +58,7 @@
         // In second mode, determine the default color from the first mode
         qreal h, s, l, a;
         default_color.getHslF (&h, &s, &l, &a);
-        default_color.setHslF (h, s, 1.0-l, a);
+        default_color.setHslF (h, s, 1.0-l*0.85, a);
       }
 
     return value (pref.key + settings_color_modes_ext.at (mode),
--- a/libgui/src/gui-settings.h	Fri Apr 02 17:02:36 2021 +0200
+++ b/libgui/src/gui-settings.h	Sat Apr 03 08:26:30 2021 +0200
@@ -113,10 +113,12 @@
 // Other color schemes (currently one extra, but possibly more in the future)
 const QString settings_color_modes = QT_TRANSLATE_NOOP (
     "octave::settings_dialog",
-    "Second color mode (light/dark)\n(discards non-applied current changes)");
+    "Second color mode (light/dark)");
 const QString settings_color_modes_tooltip = QT_TRANSLATE_NOOP (
     "octave::settings_dialog",
-    "Switches to another set of colors. Useful for defining a dark/light mode");
+    "Switches to another set of colors.\n"
+    "Useful for defining a dark/light mode.\n"
+    "Discards non-applied current changes!");
 const QStringList settings_color_modes_ext (QStringList () << "" << "_2");
 
 #endif
--- a/libgui/src/settings-dialog.cc	Fri Apr 02 17:02:36 2021 +0200
+++ b/libgui/src/settings-dialog.cc	Sat Apr 03 08:26:30 2021 +0200
@@ -1112,7 +1112,9 @@
     QVector<color_picker*> color (ws_colors_count);
 
     int column = 0;
+    const int color_columns = 3;  // place colors in so many columns
     int row = 0;
+    int mode = settings->value (ws_color_mode).toInt ();
 
     m_ws_enable_colors = new QCheckBox (tr ("Enable attribute colors"));
     style_grid->addWidget (m_ws_enable_colors, row++, column, 1, 4);
@@ -1124,40 +1126,73 @@
     m_ws_hide_tool_tips->setChecked
       (settings->value (ws_hide_tool_tips).toBool ());
 
+    QCheckBox *cb_color_mode = new QCheckBox (settings_color_modes);
+    cb_color_mode->setToolTip (settings_color_modes_tooltip);
+    cb_color_mode->setChecked (mode == 1);
+    cb_color_mode->setObjectName (ws_color_mode.key);
+    connect (m_ws_enable_colors, SIGNAL (toggled (bool)),
+             cb_color_mode, SLOT (setEnabled (bool)));
+    style_grid->addWidget (cb_color_mode, row, column++);
+
+    bool colors_enabled = settings->value (ws_enable_colors).toBool ();
+
     for (int i = 0; i < ws_colors_count; i++)
       {
         description[i] = new QLabel ("    "
           + tr (ws_color_names.at (i).toStdString ().data ()));
         description[i]->setAlignment (Qt::AlignRight);
+        description[i]->setEnabled (colors_enabled);
         connect (m_ws_enable_colors, SIGNAL (toggled (bool)),
                  description[i], SLOT(setEnabled (bool)));
 
-        QColor setting_color = settings->value (ws_colors[i].key,
-                                                ws_colors[i].def).value<QColor> ();
+        QColor setting_color = settings->color_value (ws_colors[i], mode);
         color[i] = new color_picker (setting_color);
         color[i]->setObjectName (ws_colors[i].key);
         color[i]->setMinimumSize (30, 10);
+        color[i]->setEnabled (colors_enabled);
         connect (m_ws_enable_colors, SIGNAL (toggled (bool)),
                  color[i], SLOT(setEnabled (bool)));
 
         style_grid->addWidget (description[i], row, 3*column);
         style_grid->addWidget (color[i], row, 3*column+1);
-        if (++column == 3)
+        if (++column > color_columns)
           {
             style_grid->setColumnStretch (4*column, 10);
             row++;
-            column = 0;
+            column = 1;
           }
       }
 
     // Load enable settings at the end for having signals already connected
-    bool colors_enabled =
-      settings->value (ws_enable_colors).toBool ();
     m_ws_enable_colors->setChecked (colors_enabled);
     m_ws_hide_tool_tips->setEnabled (colors_enabled);
+    cb_color_mode->setEnabled (colors_enabled);
 
     // place grid with elements into the tab
     workspace_colors_box->setLayout (style_grid);
+
+    // update colors depending on second theme selection
+    connect (cb_color_mode, SIGNAL (stateChanged (int)),
+             this, SLOT (update_workspace_colors (int)));
+  }
+
+  void settings_dialog::update_workspace_colors (int mode)
+  {
+    int m = mode;
+    if (m > 1)
+      m = 1; // Currently one more color mode
+
+    resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
+    gui_settings *settings = rmgr.get_settings ();
+
+    color_picker *c_picker;
+
+    for (unsigned int i = 0; i < ws_colors_count; i++)
+      {
+        c_picker = workspace_colors_box->findChild <color_picker *> (ws_colors[i].key);
+        if (c_picker)
+          c_picker->set_color (settings->color_value (ws_colors[i], m));
+      }
   }
 
   void settings_dialog::write_workspace_colors (gui_settings *settings)
@@ -1165,14 +1200,24 @@
     settings->setValue (ws_enable_colors.key, m_ws_enable_colors->isChecked ());
     settings->setValue (ws_hide_tool_tips.key, m_ws_hide_tool_tips->isChecked ());
 
+    QCheckBox *cb_color_mode
+      = workspace_colors_box->findChild <QCheckBox *> (ws_color_mode.key);
+
+    int mode = 0;
+    if (cb_color_mode && cb_color_mode->isChecked ())
+      mode = 1;
+
     color_picker *color;
 
     for (int i = 0; i < ws_colors_count; i++)
       {
         color = workspace_colors_box->findChild <color_picker *> (ws_colors[i].key);
         if (color)
-          settings->setValue (ws_colors[i].key, color->color ());
+          settings->set_color_value (ws_colors[i], color->color (), mode);
       }
+
+    settings->setValue (ws_color_mode.key, mode);
+
     settings->sync ();
   }
 
@@ -1182,9 +1227,7 @@
     QVector<QLabel*> description (cs_colors_count);
     QVector<color_picker*> color (cs_colors_count);
 
-    int mode = 0;
-    if (settings->value (cs_color_mode).toBool ())
-      mode = 1;
+    int mode = settings->value (cs_color_mode).toInt ();
 
     QCheckBox *cb_color_mode = new QCheckBox (settings_color_modes);
     cb_color_mode->setToolTip (settings_color_modes_tooltip);
@@ -1247,7 +1290,7 @@
       = terminal_colors_box->findChild <QCheckBox *> (cs_color_mode.key);
 
     int mode = 0;
-    if (cb_color_mode->isChecked ())
+    if (cb_color_mode && cb_color_mode->isChecked ())
       mode = 1;
 
     color_picker *color;
--- a/libgui/src/settings-dialog.h	Fri Apr 02 17:02:36 2021 +0200
+++ b/libgui/src/settings-dialog.h	Sat Apr 03 08:26:30 2021 +0200
@@ -68,7 +68,8 @@
     void proxy_items_update (void);
 
     // slots updating colors depending on theme
-    void update_terminal_colors (int cb_dark);
+    void update_terminal_colors (int mode);
+    void update_workspace_colors (int mode);
 
     // slots for dialog's buttons
     void button_clicked (QAbstractButton *button);
--- a/libgui/src/workspace-model.cc	Fri Apr 02 17:02:36 2021 +0200
+++ b/libgui/src/workspace-model.cc	Sat Apr 03 08:26:30 2021 +0200
@@ -200,10 +200,11 @@
   {
     m_enable_colors = settings->value (ws_enable_colors).toBool ();
 
+    int mode = settings->value (ws_color_mode).toInt ();
+
     for (int i = 0; i < ws_colors_count; i++)
       {
-        QColor setting_color = settings->value (ws_colors[i].key,
-                                                ws_colors[i].def).value<QColor> ();
+        QColor setting_color = settings->color_value (ws_colors[i], mode);
 
         QPalette p (setting_color);
         m_storage_class_colors.replace (i,setting_color);