changeset 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 6f7940e36322
children 999400bebe5e 5d6243c2acbf
files libgui/src/color-picker.cc libgui/src/resource-manager.cc libgui/src/resource-manager.h libgui/src/settings-dialog.cc libgui/src/settings-dialog.h libgui/src/settings-dialog.ui libgui/src/workspace-model.cc libgui/src/workspace-model.h libgui/src/workspace-view.cc libgui/src/workspace-view.h
diffstat 10 files changed, 217 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/color-picker.cc	Sat May 04 01:01:44 2013 -0400
+++ b/libgui/src/color-picker.cc	Sat May 04 09:37:28 2013 +0200
@@ -29,6 +29,7 @@
 {
   _color = old_color;
   setFlat (true);
+  setFocusPolicy(Qt::NoFocus);  // no focus, would changes the color
   update_button ();
   connect(this, SIGNAL (clicked ()), SLOT (select_color ()));
 }
--- a/libgui/src/resource-manager.cc	Sat May 04 01:01:44 2013 -0400
+++ b/libgui/src/resource-manager.cc	Sat May 04 09:37:28 2013 +0200
@@ -195,6 +195,28 @@
   QNetworkProxy::setApplicationProxy (proxy);
 }
 
+QStringList 
+resource_manager::storage_class_names (void)
+{
+  return QStringList () << QObject::tr ("automatic")
+                        << QObject::tr ("function")
+                        << QObject::tr ("global")
+                        << QObject::tr ("hidden")
+                        << QObject::tr ("inherited")
+                        << QObject::tr ("persistent");
+}
+
+QList<QColor>
+resource_manager::storage_class_default_colors (void)
+{
+  return QList<QColor> () << QColor(190,255,255)
+                          << QColor(220,255,220)
+                          << QColor(220,220,255)
+                          << QColor(255,255,190)
+                          << QColor(255,220,220)
+                          << QColor(255,190,255);
+}
+
 const char*
 resource_manager::octave_keywords (void)
 {
--- a/libgui/src/resource-manager.h	Sat May 04 01:01:44 2013 -0400
+++ b/libgui/src/resource-manager.h	Sat May 04 09:37:28 2013 +0200
@@ -82,6 +82,10 @@
   }
 
   static const char *octave_keywords (void);
+  
+  static QString storage_class_chars (void) { return "afghip"; }
+  static QStringList storage_class_names (void);
+  static QList<QColor> storage_class_default_colors (void);
 
 private:
 
--- 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 ();
+}
--- a/libgui/src/settings-dialog.h	Sat May 04 01:01:44 2013 -0400
+++ b/libgui/src/settings-dialog.h	Sat May 04 09:37:28 2013 +0200
@@ -49,6 +49,9 @@
   enum { MaxLexerStyles = 64,
          MaxStyleNumber = 128 };
 #endif
+
+  void read_workspace_colors (QSettings *settings);
+  void write_workspace_colors (QSettings *settings);
 };
 
 #endif // SETTINGSDIALOG_H
--- a/libgui/src/settings-dialog.ui	Sat May 04 01:01:44 2013 -0400
+++ b/libgui/src/settings-dialog.ui	Sat May 04 09:37:28 2013 +0200
@@ -500,6 +500,24 @@
        </item>
       </layout>
      </widget>
+     <widget class="QWidget" name="tab_workspace">
+      <attribute name="title">
+       <string>Workspace</string>
+      </attribute>
+      <widget class="QGroupBox" name="workspace_colors_box">
+       <property name="geometry">
+        <rect>
+         <x>19</x>
+         <y>19</y>
+         <width>631</width>
+         <height>81</height>
+        </rect>
+       </property>
+       <property name="title">
+        <string>Storage Class Colors</string>
+       </property>
+      </widget>
+     </widget>
      <widget class="QWidget" name="tab_3">
       <attribute name="title">
        <string>Network</string>
--- a/libgui/src/workspace-model.cc	Sat May 04 01:01:44 2013 -0400
+++ b/libgui/src/workspace-model.cc	Sat May 04 09:37:28 2013 +0200
@@ -26,9 +26,10 @@
 #endif
 
 #include <QTreeWidget>
+#include <QSettings>
 
 #include "utils.h"
-
+#include "resource-manager.h"
 #include "workspace-model.h"
 
 workspace_model::workspace_model (QObject *p)
@@ -39,16 +40,20 @@
   _columnNames.append (tr ("Dimension"));
   _columnNames.append (tr ("Value"));
   _columnNames.append (tr ("Storage Class"));
+
+  for (int i = 0; i < resource_manager::storage_class_chars ().length (); i++)
+    _storage_class_colors.append (QColor (Qt::white));
+
 }
 
 int
-workspace_model::rowCount(const QModelIndex& p) const
+workspace_model::rowCount (const QModelIndex&) const
 {
   return _symbols.size ();
 }
 
 int
-workspace_model::columnCount (const QModelIndex& p) const
+workspace_model::columnCount (const QModelIndex&) const
 {
   return _columnNames.size ();
 }
@@ -84,53 +89,56 @@
 {
   QVariant retval;
 
-  if (idx.isValid ()
-      && (role == Qt::DisplayRole
-          || (idx.column () == 0 && (role == Qt::EditRole
-                                     || role == Qt::ToolTipRole))))
+  if (idx.isValid ())
     {
-      switch (idx.column ())
+      if (role == Qt::BackgroundColorRole)
         {
-        case 0:
-          if (role == Qt::ToolTipRole)
-            retval = QVariant (tr ("Right click to copy, rename, or display"));
+          QString class_chars = resource_manager::storage_class_chars ();
+          int actual_class = class_chars.indexOf (_scopes[idx.row()].toAscii ());
+          if (actual_class >= 0)
+            return QVariant (_storage_class_colors.at (actual_class));
           else
-            retval = QVariant (_symbols[idx.row()]);
-          break;
+            return retval;
+        }
 
-        case 1:
-          retval = QVariant (_class_names[idx.row()]);
-          break;
-
-        case 2:
-          retval = QVariant (_dimensions[idx.row()]);
-          break;
+      if (role == Qt::DisplayRole
+          || (idx.column () == 0 && role == Qt::EditRole)
+          || (idx.column () == 0 && role == Qt::ToolTipRole) )
+        {
+          switch (idx.column ())
+            {
+            case 0:
+              if (role == Qt::ToolTipRole)
+                retval = QVariant (tr ("Right click to copy, rename, or display"));
+              else
+                retval = QVariant (_symbols[idx.row()]);
+              break;
 
-        case 3:
-          retval = QVariant (_values[idx.row()]);
-          break;
+            case 1:
+              retval = QVariant (_class_names[idx.row()]);
+              break;
 
-        case 4:
-          {
-            QChar c = _scopes[idx.row()];
+            case 2:
+              retval = QVariant (_dimensions[idx.row()]);
+              break;
+
+            case 3:
+              retval = QVariant (_values[idx.row()]);
+              break;
 
-            if (c == 'g')
-              retval = QVariant (tr ("global"));
-            else if (c == 'p')
-              retval = QVariant (tr ("persistent"));
-            else if (c == 'a')
-              retval = QVariant (tr ("automatic"));
-            else if (c == 'f')
-              retval = QVariant (tr ("function parameter"));
-            else if (c == 'h')
-              retval = QVariant (tr ("hidden"));
-            else if (c == 'i')
-              retval = QVariant (tr ("inherited"));
+            case 4:
+              retval = QVariant ();
+              QString class_chars = resource_manager::storage_class_chars ();
+              int actual_class = class_chars.indexOf (_scopes[idx.row()].toAscii ());
+              if (actual_class >= 0)
+                {
+                  QStringList class_names = resource_manager::storage_class_names ();
+                  retval = QVariant (class_names.at (actual_class));
+                }
+              break;
+
           }
-
-        default:
-          break;
-        }
+      }
     }
 
   return retval;
@@ -213,3 +221,18 @@
 
   emit model_changed ();
 }
+
+void
+workspace_model::notice_settings (const QSettings *settings)
+{
+  QList<QColor> default_colors = resource_manager::storage_class_default_colors ();
+  QString class_chars = resource_manager::storage_class_chars ();
+
+  for (int i = 0; i < class_chars.length (); i++)
+    {
+      QVariant default_var = default_colors.at (i);
+      QColor setting_color = settings->value ("workspaceview/color_"+class_chars.mid (i,1),
+                                             default_var).value<QColor> ();
+      _storage_class_colors.replace (i,setting_color);
+    }
+}
--- a/libgui/src/workspace-model.h	Sat May 04 01:01:44 2013 -0400
+++ b/libgui/src/workspace-model.h	Sat May 04 09:37:28 2013 +0200
@@ -28,6 +28,9 @@
 #include <QVector>
 #include <QSemaphore>
 #include <QStringList>
+#include <QChar>
+#include <QColor>
+#include <QSettings>
 
 class workspace_model
   : public QAbstractTableModel
@@ -56,6 +59,8 @@
 
   bool is_top_level (void) const { return _top_level; }
 
+  QColor storage_class_color (int s_class) { return _storage_class_colors.at (s_class); }
+
 public slots:
 
   void set_workspace (bool top_level,
@@ -67,6 +72,8 @@
 
   void clear_workspace (void);
 
+  void notice_settings (const QSettings *);
+
 signals:
 
   void model_changed (void);
@@ -86,6 +93,9 @@
   QStringList _values;
 
   QStringList _columnNames;
+
+  QList<QColor>  _storage_class_colors;
+
 };
 
 #endif
--- a/libgui/src/workspace-view.cc	Sat May 04 01:01:44 2013 -0400
+++ b/libgui/src/workspace-view.cc	Sat May 04 09:37:28 2013 +0200
@@ -77,6 +77,10 @@
 
   connect (this, SIGNAL (command_requested (const QString&)),
            p, SLOT (execute_command_in_terminal (const QString&)));
+
+  connect (parent (), SIGNAL (settings_changed (const QSettings *)),
+           this, SLOT (notice_settings (const QSettings *)));
+
 }
 
 workspace_view::~workspace_view (void)
@@ -89,6 +93,12 @@
   settings->sync ();
 }
 
+void workspace_view::setModel (workspace_model *model)
+{
+  view->setModel (model);
+  _model = model;
+}
+
 void
 workspace_view::closeEvent (QCloseEvent *e)
 {
@@ -242,3 +252,20 @@
     view->setRowHeight (i, row_height);
   view_previous_row_count = new_row_count;
 }
+
+void
+workspace_view::notice_settings (const QSettings *settings)
+{
+  _model->notice_settings (settings); // update colors of model first
+
+  QString tool_tip;
+  tool_tip  =  QString (tr ("View the variables in the active workspace.<br>"));
+  tool_tip +=  QString (tr ("Colors for the storage class:"));
+  for (int i = 0; i < resource_manager::storage_class_chars ().length (); i++)
+    {
+      tool_tip +=  QString ("<div style=\"background-color:%1;color:#000000\">%2</div>")
+               .arg (_model->storage_class_color (i).name ())
+               .arg (resource_manager::storage_class_names ().at (i));
+    }
+  setToolTip (tool_tip);
+}
--- a/libgui/src/workspace-view.h	Sat May 04 01:01:44 2013 -0400
+++ b/libgui/src/workspace-view.h	Sat May 04 09:37:28 2013 +0200
@@ -41,9 +41,11 @@
 
   ~workspace_view (void);
 
-public:
+public slots:
 
-  void setModel (workspace_model *model) { view->setModel (model); }
+  void notice_settings (const QSettings *);
+
+  void setModel (workspace_model *model);
 
 signals:
 
@@ -73,6 +75,7 @@
 
   QTableView *view;
   int view_previous_row_count;
+  workspace_model *_model;
 };
 
 #endif