diff libgui/src/settings-dialog.cc @ 23927:e3a36f84d01d

provide variable-editor widget for the GUI This patch is the work of RĂ¼diger Sonderfeld <ruediger on savannah> Philip Nienhuis Michael Barnes <mjbcode@runbox.com> jwe * libgui/src/variable-editor.cc, libgui/src/variable-editor.h, libgui/src/variable-editor-model.cc, libgui/src/variable-editor-model.h:: New files. * libgui/src/module.mk: Update. * main-window.cc, main-window.h (main_window::main_window): Initialize variable_editor_window. (main_window::~main_window): Delete variable_editor_window. (main_window::connect_uiwidget_links): Connect variable window signals to octave_qt_link slots and callbacks. Add variable editor to menus. (main_window::variable_editor_callback, main_window::force_refresh_workspace, main_window::edit_variable, main_window::clear_variable_editor_cache): New functions. (main_window::configure_shortcuts): Also configure variable editor shortcuts. * resource-manager.cc, resource-manager.h (varedit_color_chars, varedit_color_names, varedit_default_colors): New functions. * settings-dialog.ui: New configuration info for variable editor. * settings-dialog.cc, settings-dialog.h (settings_dialog::read_varedit_colors, settings_dialog::write_varedit_colors): New functions. (settings_dialog::settings_dialog, settings_dialog::write_changed_settings): Also handle settings for variable editor. * workspace-model.h (workspace_model::prompt_variable_editor): New signal. * workspace-view.cc, workspace-view.h (workspace_view::workspace_view): Also connect eidt_variable_signal to edit_variable slot. (workspace_view::contextmenu_requested): Handle opening variabl in variable editor. (workspace_view::handle_contextmenu_edit): New function. (workspace_view::edit_variable_signal): New signal. * octave-link.cc, octave-link.h (Fopenvar): New function. (octave_link::post_event, octave_link::do_post_event): New variants for methods with two, three, or four arguments. (octave_link::set_workspace): New argument, update_variable_editor. (octave_link::openvar): New function. (octave_link::do_openvar): New pure virtual. * octave-qt-link.cc, octave-qt-link.h (octave_qt_link::do_set_workspace): New argument, update_variable_editor. (octave_qt_link::do_set_workspace): Optionally emit refresh_variable_editor signal (octave_qt_link::do_openvar): New function. (octave_qt_link::open_variable, octave_qt_link::refresh_variable_editor): New signals. * gui.txi: Document openvar. * variables.cc, variables.h (symbol_exist): New function. * action-container.h (action_container::method_arg2_elem, action_container::method_arg3_elem, action_container::method_arg4_elem): New classes. (action_container::add_method): New variants for two, three, or four arguments.
author Michael Barnes <mjbcode@runbox.com>
date Fri, 19 May 2017 18:15:48 +0200
parents 9c24aae7515f
children c4683bc64ecc
line wrap: on
line diff
--- a/libgui/src/settings-dialog.cc	Mon Aug 21 17:22:28 2017 +0200
+++ b/libgui/src/settings-dialog.cc	Fri May 19 18:15:48 2017 +0200
@@ -26,6 +26,7 @@
 
 #include "resource-manager.h"
 #include "shortcut-manager.h"
+#include "variable-editor.h"
 #include "workspace-model.h"
 #include "settings-dialog.h"
 #include "ui-settings-dialog.h"
@@ -590,6 +591,21 @@
   // terminal colors
   read_terminal_colors (settings);
 
+  // variable editor
+  ui->varedit_columnWidth->setText(settings->value("variable_editor/column_width","100").toString());
+  ui->varedit_autoFitColumnWidth->setChecked(settings->value("variable_editor/autofit_column_width",false).toBool());
+  ui->varedit_autofitType->setCurrentIndex(settings->value("autofit_type",0).toInt());
+  ui->varedit_rowHeight->setText(settings->value("variable_editor/row_height","2").toString());
+  ui->varedit_rowAutofit->setChecked(settings->value("variable_editor/autofit_row_height",true).toBool());
+  ui->varedit_font->setFont(QFont(settings->value("variable_editor/font",settings->value("terminal/FontName","Courier New")).toString()));
+  ui->varedit_fontSize->setValue(settings->value("variable_editor/font_size",QVariant(10)).toInt());
+  ui->varedit_useTerminalFont->setChecked(settings->value("variable_editor/use_terminal_font",false).toBool());
+  ui->varedit_alternate->setChecked(settings->value("variable_editor/alternate_rows",QVariant(false)).toBool());
+  ui->varedit_toolbarSize->setValue(settings->value("variable_editor/toolbar_size",24).toInt());
+
+  // variable editor colors
+  read_varedit_colors(settings);
+
   // shortcuts
 
   ui->cb_prevent_readline_conflicts->setChecked (
@@ -753,6 +769,64 @@
 }
 
 void
+settings_dialog::write_varedit_colors (QSettings *settings)
+{
+    QString class_chars = resource_manager::varedit_color_chars ();
+    color_picker *color;
+
+    for (int i = 0; i < class_chars.length (); i++)
+      {
+        color = ui->varedit_colors_box->findChild <color_picker *>(
+                  "varedit_color_"+class_chars.mid (i,1));
+        if (color)
+          settings->setValue ("variable_editor/color_"+class_chars.mid (i,1),
+                              color->color ());
+      }
+    settings->sync ();
+}
+
+
+void
+settings_dialog::read_varedit_colors (QSettings *settings)
+{
+  QList<QColor> default_colors = variable_editor::default_colors ();
+  QStringList class_names = variable_editor::color_names ();
+  QString class_chars = resource_manager::varedit_color_chars ();
+  int nr_of_classes = class_chars.length ();
+
+  QGridLayout *style_grid = new QGridLayout ();
+  QVector<QLabel*> description (nr_of_classes);
+  QVector<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 ("variable_editor/color_"
+                                              + class_chars.mid (i,1),
+                                              default_var).value<QColor> ();
+      color[i] = new color_picker (setting_color);
+      color[i]->setObjectName ("varedit_color_"+class_chars.mid (i, 1));
+      color[i]->setMinimumSize (30, 10);
+      style_grid->addWidget (description[i], row, 2*column);
+      style_grid->addWidget (color[i],       row, 2*column+1);
+      if (++column == 2)
+        {
+          style_grid->setColumnStretch (3*column, 10);
+          row++;
+          column = 0;
+        }
+    }
+
+  // place grid with elements into the tab
+  ui->varedit_colors_box->setLayout (style_grid);
+
+}
+
+void
 settings_dialog::write_changed_settings (bool closing)
 {
   QSettings *settings = resource_manager::get_settings ();
@@ -983,6 +1057,19 @@
   // Terminal
   write_terminal_colors (settings);
 
+  // Variable editor
+  settings->setValue("variable_editor/autofit_column_width",ui->varedit_autoFitColumnWidth->isChecked());
+  settings->setValue("variable_editor/autofit_type",ui->varedit_autofitType->currentIndex());
+  settings->setValue("variable_editor/column_width",ui->varedit_columnWidth->text());
+  settings->setValue("variable_editor/row_height", ui->varedit_rowHeight->text());
+  settings->setValue("variable_editor/autofit_row_height",ui->varedit_rowAutofit->isChecked());
+  settings->setValue("variable_editor/use_terminal_font",ui->varedit_useTerminalFont->isChecked());
+  settings->setValue("variable_editor/alternate_rows",ui->varedit_alternate->isChecked());
+  settings->setValue("variable_editor/font_name",ui->varedit_font->currentFont().family());
+  settings->setValue("variable_editor/font_size",ui->varedit_fontSize->value());
+  settings->setValue("variable_editor/toolbar_size",ui->varedit_toolbarSize->value());
+  write_varedit_colors(settings);
+
   // shortcuts
   settings->setValue ("shortcuts/prevent_readline_conflicts",
                       ui->cb_prevent_readline_conflicts->isChecked ());