changeset 31304:d3231a604a62

re-enable user preferences for current editor line color (bug #62984) * gui-preferences-ed.h: include gui-settings instead of gui-preferences, new gui-pref for current line color with magenta as default for automatic computation of the color * gui-settings.h: more detailed comment for settings_color_no_change * file-editor-tab.cc (update_lexer_settings): compute and/or set current line color depending on color mode and user preference * settings-dialog.cc (settings_dialog): rename ed_mode in mode, add and initialize color picker for current line color; (update_editor_lexers): get current color for new color picker; (write_lexer_settings): read value from color picker and wirte it to file * settings-dialog.ui: update layouts for including new color picker
author Torsten Lilge <ttl-octave@mailbox.org>
date Sat, 15 Oct 2022 13:34:05 +0200
parents 75451e28f912
children ef3cd4d7691f
files libgui/src/gui-preferences-ed.h libgui/src/gui-settings.h libgui/src/m-editor/file-editor-tab.cc libgui/src/settings-dialog.cc libgui/src/settings-dialog.ui
diffstat 5 files changed, 74 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/gui-preferences-ed.h	Fri Oct 14 13:06:43 2022 -0400
+++ b/libgui/src/gui-preferences-ed.h	Sat Oct 15 13:34:05 2022 +0200
@@ -30,7 +30,7 @@
 #include <Qsci/qsciscintilla.h>
 #endif
 
-#include "gui-preferences.h"
+#include "gui-settings.h"
 #include "localcharset-wrapper.h"
 
 // Editor preferences
@@ -144,6 +144,10 @@
 ed_highlight_current_line ("editor/highlightCurrentLine", QVariant (true));
 
 const gui_pref
+ed_highlight_current_line_color ("editor/highlight_current_line_color",
+                                 QVariant (settings_color_no_change));
+
+const gui_pref
 ed_show_white_space ("editor/show_white_space", QVariant (false));
 
 const gui_pref
--- a/libgui/src/gui-settings.h	Fri Oct 14 13:06:43 2022 -0400
+++ b/libgui/src/gui-settings.h	Sat Oct 15 13:34:05 2022 +0200
@@ -126,6 +126,7 @@
 // Some constants used several times in the settings
 
 // Special color indicating no change compared to default color
+// or automatically computed color
 const QColor settings_color_no_change (255, 0, 255);
 
 // Other color schemes (currently one extra, but possibly more in the future)
--- a/libgui/src/m-editor/file-editor-tab.cc	Fri Oct 14 13:06:43 2022 -0400
+++ b/libgui/src/m-editor/file-editor-tab.cc	Sat Oct 15 13:34:05 2022 +0200
@@ -907,7 +907,13 @@
     m_edit_area->setMarginsBackgroundColor (bgm);
     m_edit_area->setFoldMarginColors (bgm, fgm);
 
-    bgm = interpolate_color (bg, fg, 0.5, 0.1);
+    QColor current_line_bg
+      = settings->color_value (ed_highlight_current_line_color, mode);
+    if (current_line_bg == settings_color_no_change)
+       bgm = interpolate_color (bg, fg, 0.5, 0.1);  // It is the "auto" color
+     else
+       bgm = current_line_bg;  // Specific color given
+
     m_edit_area->setCaretLineBackgroundColor (bgm);
 
     // color indicator for highlighting all occurrences:
--- a/libgui/src/settings-dialog.cc	Fri Oct 14 13:06:43 2022 -0400
+++ b/libgui/src/settings-dialog.cc	Sat Oct 15 13:34:05 2022 +0200
@@ -457,22 +457,38 @@
 
 #if defined (HAVE_QSCINTILLA)
 
-    int ed_mode = settings->value (ed_color_mode).toInt ();
+    int mode = settings->value (ed_color_mode).toInt ();
 
     QCheckBox *cb_color_mode = new QCheckBox (settings_color_modes,
                                               group_box_editor_styles);
     cb_color_mode->setToolTip (settings_color_modes_tooltip);
-    cb_color_mode->setChecked (ed_mode > 0);
+    cb_color_mode->setChecked (mode > 0);
     cb_color_mode->setObjectName (ed_color_mode.key);
 
     QPushButton *pb_reload_default_colors = new QPushButton (settings_reload_styles);
     pb_reload_default_colors->setToolTip (settings_reload_styles_tooltip);
 
-    editor_style_grid->addWidget (cb_color_mode, 0, 0);
-    editor_style_grid->addWidget (pb_reload_default_colors, 0, 1);
-    editor_style_grid->addItem (new QSpacerItem (5, 5, QSizePolicy::Expanding), 0, 2);
+    color_picker *current_line_color = new color_picker (
+      settings->value (ed_highlight_current_line_color.key +
+                       settings_color_modes_ext[mode],
+                       ed_highlight_current_line_color.def).value<QColor> (), this);
+    current_line_color->setObjectName (ed_highlight_current_line_color.key);
+    QLabel *current_line_color_label = new QLabel(
+      tr ("Color of highlighted current line (magenta (255,0,255) for automatic color)")
+    );
 
+    QHBoxLayout *color_mode = new QHBoxLayout ();
+    color_mode->addWidget (cb_color_mode);
+    color_mode->addItem (new QSpacerItem (5, 5, QSizePolicy::Expanding));
+    color_mode->addWidget (pb_reload_default_colors);
 
+    QHBoxLayout *current_line = new QHBoxLayout ();
+    current_line->addWidget (current_line_color_label);
+    current_line->addWidget (current_line_color);
+    current_line->addItem (new QSpacerItem (5, 5, QSizePolicy::Expanding));
+
+    editor_styles_layout->addLayout (color_mode);
+    editor_styles_layout->addLayout (current_line);
 
     // update colors depending on second theme selection
     connect (cb_color_mode, &QCheckBox::stateChanged,
@@ -629,6 +645,9 @@
   {
 #if defined (HAVE_QSCINTILLA)
 
+    resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
+    gui_settings *settings = rmgr.get_settings ();
+
     QCheckBox *cb_color_mode
       = group_box_editor_styles->findChild <QCheckBox *> (ed_color_mode.key);
 
@@ -636,13 +655,25 @@
     if (cb_color_mode && cb_color_mode->isChecked ())
       m = 1;
 
+    color_picker *c_picker = findChild <color_picker *> (ed_highlight_current_line_color.key);
+    if (c_picker)
+      {
+        if (def != settings_reload_default_colors_flag)
+          {
+            // Get current value from settings or the default
+            c_picker->set_color (settings->color_value (ed_highlight_current_line_color, m));
+          }
+        else
+          {
+            // Get the default value
+            c_picker->set_color (settings->get_color_value (ed_highlight_current_line_color.def, m));
+          }
+      }
+
     // editor styles: create lexer, read settings, and
     // create or update dialog elements
     QsciLexer *lexer;
 
-    resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
-    gui_settings *settings = rmgr.get_settings ();
-
 #  if defined (HAVE_LEXER_OCTAVE)
     lexer = new QsciLexerOctave ();
     update_lexer (lexer, settings, m, def);
@@ -912,6 +943,11 @@
     color_picker *bg_color;
     int default_size = 10;
 
+    color = findChild <color_picker *> (ed_highlight_current_line_color.key);
+    if (color)
+      settings->setValue (ed_highlight_current_line_color.key
+                          + settings_color_modes_ext[mode], color->color ());
+
     QString default_font_name
       = settings->value (global_mono_font).toString ();
     QFont default_font = QFont (default_font_name, 10, -1, 0);
--- a/libgui/src/settings-dialog.ui	Fri Oct 14 13:06:43 2022 -0400
+++ b/libgui/src/settings-dialog.ui	Sat Oct 15 13:34:05 2022 +0200
@@ -35,7 +35,7 @@
       <string/>
      </property>
      <property name="currentIndex">
-      <number>0</number>
+      <number>2</number>
      </property>
      <widget class="QWidget" name="tab_general">
       <property name="enabled">
@@ -56,7 +56,7 @@
             <x>0</x>
             <y>0</y>
             <width>1021</width>
-            <height>618</height>
+            <height>584</height>
            </rect>
           </property>
           <layout class="QVBoxLayout" name="verticalLayout_17">
@@ -588,7 +588,7 @@
             <x>0</x>
             <y>0</y>
             <width>1035</width>
-            <height>569</height>
+            <height>573</height>
            </rect>
           </property>
           <layout class="QVBoxLayout" name="verticalLayout_7">
@@ -867,9 +867,9 @@
           <property name="geometry">
            <rect>
             <x>0</x>
-            <y>0</y>
+            <y>-839</y>
             <width>1021</width>
-            <height>1497</height>
+            <height>1427</height>
            </rect>
           </property>
           <layout class="QVBoxLayout" name="verticalLayout_16">
@@ -2117,6 +2117,13 @@
              </property>
              <layout class="QVBoxLayout" name="verticalLayout_31">
               <item>
+               <layout class="QVBoxLayout" name="editor_styles_layout">
+                <property name="bottomMargin">
+                 <number>8</number>
+                </property>
+               </layout>
+              </item>
+              <item>
                <widget class="QLabel" name="label_23">
                 <property name="text">
                  <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Select font, font size (as a difference from the default size), font style (&lt;b&gt;b&lt;/b&gt;old, &lt;b&gt;i&lt;/b&gt;talic, &lt;b&gt;u&lt;/b&gt;nderline), text color, and background color (for the latter, the color magenta (255,0,255) is a placeholder for the default background color).&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@@ -2127,9 +2134,6 @@
                </widget>
               </item>
               <item>
-               <layout class="QGridLayout" name="editor_style_grid"/>
-              </item>
-              <item>
                <widget class="QTabWidget" name="tabs_editor_lexers">
                 <property name="sizePolicy">
                  <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@@ -2177,7 +2181,7 @@
             <x>0</x>
             <y>0</y>
             <width>1035</width>
-            <height>569</height>
+            <height>573</height>
            </rect>
           </property>
           <layout class="QGridLayout" name="gridLayout_8">
@@ -2327,7 +2331,7 @@
             <x>0</x>
             <y>0</y>
             <width>1035</width>
-            <height>569</height>
+            <height>573</height>
            </rect>
           </property>
           <layout class="QVBoxLayout" name="verticalLayout_19">
@@ -2389,7 +2393,7 @@
             <x>0</x>
             <y>0</y>
             <width>1035</width>
-            <height>569</height>
+            <height>573</height>
            </rect>
           </property>
           <layout class="QVBoxLayout" name="verticalLayout_vesc_manual">
@@ -2554,7 +2558,7 @@
             <x>0</x>
             <y>0</y>
             <width>1035</width>
-            <height>569</height>
+            <height>573</height>
            </rect>
           </property>
           <layout class="QVBoxLayout" name="verticalLayout_25">
@@ -2774,7 +2778,7 @@
             <x>0</x>
             <y>0</y>
             <width>1035</width>
-            <height>569</height>
+            <height>573</height>
            </rect>
           </property>
           <layout class="QVBoxLayout" name="verticalLayout_20">