diff libgui/src/settings-dialog.cc @ 16610:a1f613e5066d

workspace view colors based upon variable scope (derived from Dan's patch #8013) * resource-manager.cc/.h(storage_class_names): function returning scope names (storage_class_colors): function returning default colors for scopes (storage_class_chars): function returning the ident. characters of the scopes * color-picker.cc(constructor): prevent focus for the colored pushbutton * settings-dialog.cc/.h(read_workspace_colors): function reading the colors from the setitngs and creating a table with color-pickers in the settings dialog (write_wirkspace_colors): function getting the states of the color-pickers and writing them into the settings files * settings-dialog.cc(constructor): call read_workspace_colors (write_changed_settings): call write_workspace_colors * settings-dialog.ui: new tab for workspace settings with a box for the colors * workspace_model.cc/.h(notice_settings): reading colors from the settings * workspace-model.cc(constructor): initialize list of colors (data): reorganize determining the appropriate data and take background color role into consideration * workspace-model.h(storage_class_color): returns the color for a specific scope * workspace-view.cc/.h(notice_settings): create tool tip with color key (setModel): not inline anymore, actual model is stored in _model
author Torsten <ttl@justmail.de>
date Sat, 04 May 2013 09:37:28 +0200
parents e192525236ad
children 818eef7b2618
line wrap: on
line diff
--- a/libgui/src/settings-dialog.cc	Sat May 04 01:01:44 2013 -0400
+++ b/libgui/src/settings-dialog.cc	Sat May 04 09:37:28 2013 +0200
@@ -25,6 +25,7 @@
 #endif
 
 #include "resource-manager.h"
+#include "workspace-model.h"
 #include "settings-dialog.h"
 #include "ui-settings-dialog.h"
 #include <QSettings>
@@ -125,6 +126,9 @@
   ui->proxyUserName->setText (settings->value ("proxyUserName").toString ());
   ui->proxyPassword->setText (settings->value ("proxyPassword").toString ());
 
+  // qorkspace colors
+  read_workspace_colors (settings);
+
 #ifdef HAVE_QSCINTILLA
   // editor styles: create lexer, read settings, and create dialog elements
   QsciLexer *lexer;
@@ -243,6 +247,44 @@
 }
 #endif  
 
+void
+settings_dialog::read_workspace_colors (QSettings *settings)
+{
+
+  QList<QColor> default_colors = resource_manager::storage_class_default_colors ();
+  QStringList class_names = resource_manager::storage_class_names ();
+  QString class_chars = resource_manager::storage_class_chars ();
+  int nr_of_classes = class_chars.length ();
+
+  QGridLayout *style_grid = new QGridLayout ();
+  QLabel *description[nr_of_classes];
+  color_picker *color[nr_of_classes];
+
+  int column = 0;
+  int row = 0;
+  for (int i = 0; i < nr_of_classes; i++)
+    {
+      description[i] = new QLabel (class_names.at (i));
+      description[i]->setAlignment (Qt::AlignRight);
+      QVariant default_var = default_colors.at (i);
+      QColor setting_color = settings->value ("workspaceview/color_"+class_chars.mid (i,1),
+                                              default_var).value<QColor> ();
+      color[i] = new color_picker (setting_color);
+      color[i]->setObjectName ("color_"+class_chars.mid (i,1));
+      color[i]->setMinimumSize (30,10);
+      style_grid->addWidget (description[i], row,3*column);
+      style_grid->addWidget (color[i],       row,3*column+1);
+      if (++column == 3)
+        {
+          row++;
+          column = 0;
+        }
+    }
+
+  // place grid with elements into the tab
+  ui->workspace_colors_box->setLayout (style_grid);
+}
+
 
 void
 settings_dialog::write_changed_settings ()
@@ -322,6 +364,8 @@
   write_lexer_settings (lexer,settings);
   delete lexer;
 #endif
+
+  write_workspace_colors (settings);
 }
 
 #ifdef HAVE_QSCINTILLA
@@ -382,3 +426,21 @@
   lexer->writeSettings (*settings);
 }
 #endif
+
+void
+settings_dialog::write_workspace_colors (QSettings *settings)
+{
+
+  QString class_chars = resource_manager::storage_class_chars ();
+  color_picker *color;
+
+  for (int i = 0; i < class_chars.length (); i++)
+    {
+      color = ui->workspace_colors_box->findChild <color_picker *>(
+                            "color_"+class_chars.mid (i,1));
+      if (color)
+        settings->setValue ("workspaceview/color_"+class_chars.mid (i,1),
+                            color->color ());
+    }
+  settings->sync ();
+}