GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
settings-dialog.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2011-2018 Jacob Dawid
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 // Programming Note: this file has many lines longer than 80 characters
24 // due to long function, variable, and property names. Please don't
25 // break those lines as it tends to make this code even harder to read.
26 
27 #if defined (HAVE_CONFIG_H)
28 # include "config.h"
29 #endif
30 
31 #include "resource-manager.h"
32 #include "shortcut-manager.h"
33 #include "variable-editor.h"
34 #include "workspace-model.h"
35 #include "settings-dialog.h"
36 #include "ui-settings-dialog.h"
37 
38 #include <QButtonGroup>
39 #include <QDir>
40 #include <QFileInfo>
41 #include <QFileDialog>
42 #include <QVector>
43 #include <QHash>
44 #include <QMessageBox>
45 #include <QTextCodec>
46 
47 #if defined (HAVE_QSCINTILLA)
48 # include "octave-qscintilla.h"
49 # include "octave-txt-lexer.h"
50 # include <QScrollArea>
51 
52 # if defined (HAVE_QSCI_QSCILEXEROCTAVE_H)
53 # define HAVE_LEXER_OCTAVE 1
54 # include <Qsci/qscilexeroctave.h>
55 # elif defined (HAVE_QSCI_QSCILEXERMATLAB_H)
56 # define HAVE_LEXER_MATLAB 1
57 # include <Qsci/qscilexermatlab.h>
58 # endif
59 
60 # include <Qsci/qscilexercpp.h>
61 # include <Qsci/qscilexerbash.h>
62 # include <Qsci/qscilexerperl.h>
63 # include <Qsci/qscilexerbatch.h>
64 # include <Qsci/qscilexerdiff.h>
65 #endif
66 
67 #if defined (HAVE_QSCINTILLA)
68 
69 static const int MaxLexerStyles = 64;
70 static const int MaxStyleNumber = 128;
71 
72 static int
73 get_valid_lexer_styles (QsciLexer *lexer, int styles[])
74 {
75  int max_style = 0;
76  int actual_style = 0;
77  while (actual_style < MaxStyleNumber && max_style < MaxLexerStyles)
78  {
79  if ((lexer->description (actual_style)) != "") // valid style
80  styles[max_style++] = actual_style;
81  actual_style++;
82  }
83  return max_style;
84 }
85 
86 static void
87 read_lexer_settings (Ui::settings_dialog *ui, QsciLexer *lexer,
88  QSettings *settings)
89 {
90  lexer->readSettings (*settings);
91  int styles[MaxLexerStyles]; // array for saving valid styles
92  // (enum is not continuous)
93  int max_style = get_valid_lexer_styles (lexer, styles);
94  QGridLayout *style_grid = new QGridLayout ();
95  QVector<QLabel*> description (max_style);
96  QVector<QFontComboBox*> select_font (max_style);
97  QVector<QSpinBox*> font_size (max_style);
98  QVector<QCheckBox*> attrib_font (3 * max_style);
99  QVector<color_picker*> color (max_style);
100  QVector<color_picker*> bg_color (max_style);
101  int default_size = 10;
102  QFont default_font = QFont ();
103  int label_width;
104  QColor default_color = QColor ();
105  QColor dummy_color = QColor (255, 0, 255);
106 
107  for (int i = 0; i < max_style; i++) // create dialog elements for all styles
108  {
109  QString actual_name = lexer->description (styles[i]);
110  QFont actual_font = lexer->font (styles[i]);
111  description[i] = new QLabel (actual_name);
112  description[i]->setWordWrap (true);
113  label_width = 24*description[i]->fontMetrics ().averageCharWidth ();
114  description[i]->setMaximumSize (label_width, QWIDGETSIZE_MAX);
115  description[i]->setMinimumSize (label_width, 1);
116  select_font[i] = new QFontComboBox ();
117  select_font[i]->setObjectName (actual_name + "_font");
118  select_font[i]->setMaximumSize (label_width, QWIDGETSIZE_MAX);
119  select_font[i]->setMinimumSize (label_width, 1);
120  font_size[i] = new QSpinBox ();
121  font_size[i]->setObjectName (actual_name + "_size");
122  if (styles[i] == 0) // the default
123  {
124  select_font[i]->setCurrentFont (actual_font);
125  default_font = actual_font;
126  font_size[i]->setRange (6, 24);
127  default_size = actual_font.pointSize ();
128  font_size[i]->setValue (default_size);
129  default_color = lexer->defaultPaper ();
130  bg_color[i] = new color_picker (default_color);
131  }
132  else // other styles
133  {
134  select_font[i]->setCurrentFont (actual_font);
135  if (actual_font.family () == default_font.family ())
136  select_font[i]->setEditText (lexer->description (0));
137  font_size[i]->setRange (-4, 4);
138  font_size[i]->setValue (actual_font.pointSize ()-default_size);
139  font_size[i]->setToolTip (QObject::tr ("Difference to the default size"));
140  if (lexer->paper (styles[i]) == default_color)
141  bg_color[i] = new color_picker (dummy_color);
142  else
143  bg_color[i] = new color_picker (lexer->paper (styles[i]));
144  bg_color[i]->setToolTip
145  (QObject::tr ("Background color, pink (255, 0, 255) means default"));
146  }
147  attrib_font[0+3*i] = new QCheckBox (QObject::tr ("b", "short form for bold"));
148  attrib_font[1+3*i] = new QCheckBox (QObject::tr ("i", "short form for italic"));
149  attrib_font[2+3*i] = new QCheckBox (QObject::tr ("u", "short form for underlined"));
150  attrib_font[0+3*i]->setChecked (actual_font.bold ());
151  attrib_font[0+3*i]->setObjectName (actual_name + "_bold");
152  attrib_font[1+3*i]->setChecked (actual_font.italic ());
153  attrib_font[1+3*i]->setObjectName (actual_name + "_italic");
154  attrib_font[2+3*i]->setChecked (actual_font.underline ());
155  attrib_font[2+3*i]->setObjectName (actual_name + "_underline");
156  color[i] = new color_picker (lexer->color (styles[i]));
157  color[i]->setObjectName (actual_name + "_color");
158  bg_color[i]->setObjectName (actual_name + "_bg_color");
159  int column = 1;
160  style_grid->addWidget (description[i], i, column++);
161  style_grid->addWidget (select_font[i], i, column++);
162  style_grid->addWidget (font_size[i], i, column++);
163  style_grid->addWidget (attrib_font[0+3*i], i, column++);
164  style_grid->addWidget (attrib_font[1+3*i], i, column++);
165  style_grid->addWidget (attrib_font[2+3*i], i, column++);
166  style_grid->addWidget (color[i], i, column++);
167  style_grid->addWidget (bg_color[i], i, column++);
168  }
169  // place grid with elements into the tab
170  QScrollArea *scroll_area = new QScrollArea ();
171  QWidget *scroll_area_contents = new QWidget ();
172  scroll_area_contents->setObjectName (QString (lexer->language ()) + "_styles");
173  scroll_area_contents->setLayout (style_grid);
174  scroll_area->setWidget (scroll_area_contents);
175  ui->tabs_editor_lexers->addTab (scroll_area, lexer->language ());
176 
177  ui->tabs_editor_lexers->setCurrentIndex (settings->value ("settings/last_editor_styles_tab", 0).toInt ());
178 }
179 
180 static void
181 write_lexer_settings (Ui::settings_dialog *ui, QsciLexer *lexer,
182  QSettings *settings)
183 {
184  QWidget *tab = ui->tabs_editor_lexers->
185  findChild <QWidget *> (QString (lexer->language ()) + "_styles");
186  int styles[MaxLexerStyles]; // array for saving valid styles
187  // (enum is not continuous)
188  int max_style = get_valid_lexer_styles (lexer, styles);
189  QFontComboBox *select_font;
190  QSpinBox *font_size;
191  QCheckBox *attrib_font[3];
192  color_picker *color;
193  color_picker *bg_color;
194  int default_size = 10;
195  QFont default_font = QFont ("Courier New", 10, -1, 0);
196  QColor default_color = QColor ();
197  QColor dummy_color = QColor (255, 0, 255);
198 
199  for (int i = 0; i < max_style; i++) // get dialog elements and their contents
200  {
201  QString actual_name = lexer->description (styles[i]);
202  select_font = tab->findChild <QFontComboBox *> (actual_name + "_font");
203  font_size = tab->findChild <QSpinBox *> (actual_name + "_size");
204  attrib_font[0] = tab->findChild <QCheckBox *> (actual_name + "_bold");
205  attrib_font[1] = tab->findChild <QCheckBox *> (actual_name + "_italic");
206  attrib_font[2] = tab->findChild <QCheckBox *> (actual_name + "_underline");
207  color = tab->findChild <color_picker *> (actual_name + "_color");
208  bg_color = tab->findChild <color_picker *> (actual_name + "_bg_color");
209  QFont new_font = default_font;
210  if (select_font)
211  {
212  new_font = select_font->currentFont ();
213  if (styles[i] == 0)
214  default_font = new_font;
215  else if (select_font->currentText () == lexer->description (0))
216  new_font = default_font;
217  }
218  if (font_size)
219  {
220  if (styles[i] == 0)
221  {
222  default_size = font_size->value ();
223  new_font.setPointSize (font_size->value ());
224  }
225  else
226  new_font.setPointSize (font_size->value ()+default_size);
227  }
228  if (attrib_font[0])
229  new_font.setBold (attrib_font[0]->isChecked ());
230  if (attrib_font[1])
231  new_font.setItalic (attrib_font[1]->isChecked ());
232  if (attrib_font[2])
233  new_font.setUnderline (attrib_font[2]->isChecked ());
234  lexer->setFont (new_font, styles[i]);
235  if (styles[i] == 0)
236  lexer->setDefaultFont (new_font);
237  if (color)
238  lexer->setColor (color->color (), styles[i]);
239  if (bg_color)
240  {
241  if (styles[i] == 0)
242  {
243  default_color = bg_color->color ();
244  lexer->setPaper (default_color, styles[i]);
245  lexer->setDefaultPaper (default_color);
246  }
247  else
248  {
249  if (bg_color->color () == dummy_color)
250  lexer->setPaper (default_color, styles[i]);
251  else
252  lexer->setPaper (bg_color->color (), styles[i]);
253  }
254  }
255  }
256 
257  lexer->writeSettings (*settings);
258 
259  settings->setValue ("settings/last_editor_styles_tab",
260  ui->tabs_editor_lexers->currentIndex ());
261  settings->sync ();
262 }
263 
264 #endif
265 
266 settings_dialog::settings_dialog (QWidget *p, const QString& desired_tab):
267  QDialog (p), ui (new Ui::settings_dialog)
268 {
269  ui->setupUi (this);
270 
271  QSettings *settings = resource_manager::get_settings ();
272 
273  if (! settings)
274  {
275  QMessageBox msgBox
276  (QMessageBox::Warning, tr ("Octave Settings"),
277  tr ("Unable to save settings. Missing settings file or unknown directory."));
278 
279  msgBox.exec ();
280 
281  return;
282  }
283 
284  // look for available language files and the actual settings
285  QString qm_dir_name = resource_manager::get_gui_translation_dir ();
286  QDir qm_dir (qm_dir_name);
287  QFileInfoList qm_files = qm_dir.entryInfoList (QStringList ("*.qm"), QDir::Files | QDir::Readable, QDir::Name);
288 
289  for (int i = 0; i < qm_files.length (); i++) // insert available languages
290  ui->comboBox_language->addItem (qm_files.at (i).baseName ());
291  // System at beginning
292  ui->comboBox_language->insertItem (0, tr ("System setting"));
293  ui->comboBox_language->insertSeparator (1); // separator after System
294  QString language = settings->value ("language", "SYSTEM").toString ();
295  if (language == "SYSTEM")
296  language = tr ("System setting");
297  int selected = ui->comboBox_language->findText (language);
298  if (selected >= 0)
299  ui->comboBox_language->setCurrentIndex (selected);
300  else
301  ui->comboBox_language->setCurrentIndex (0); // System is default
302 
303  // icon size
304  QButtonGroup *icon_size_group = new QButtonGroup (this);
305  icon_size_group->addButton (ui->icon_size_small);
306  icon_size_group->addButton (ui->icon_size_normal);
307  icon_size_group->addButton (ui->icon_size_large);
308  int icon_size = settings->value ("toolbar_icon_size", 0).toInt ();
309  ui->icon_size_normal->setChecked (true); // the default
310  ui->icon_size_small->setChecked (icon_size == -1);
311  ui->icon_size_large->setChecked (icon_size == 1);
312 
313  // which icon has to be selected
314  QButtonGroup *icon_group = new QButtonGroup (this);
315  icon_group->addButton (ui->general_icon_octave);
316  icon_group->addButton (ui->general_icon_graphic);
317  icon_group->addButton (ui->general_icon_letter);
318  QString widget_icon_set =
319  settings->value ("DockWidgets/widget_icon_set", "NONE").toString ();
320  ui->general_icon_octave->setChecked (true); // the default (if invalid set)
321  ui->general_icon_octave->setChecked (widget_icon_set == "NONE");
322  ui->general_icon_graphic->setChecked (widget_icon_set == "GRAPHIC");
323  ui->general_icon_letter->setChecked (widget_icon_set == "LETTER");
324 
325  // custom title bar of dock widget
326  QVariant default_var = QColor (255, 255, 255);
327  QColor bg_color = settings->value ("DockWidgets/title_bg_color",
328  default_var).value<QColor> ();
329  m_widget_title_bg_color = new color_picker (bg_color);
330  m_widget_title_bg_color->setEnabled (false);
331  ui->layout_widget_bgtitle->addWidget (m_widget_title_bg_color, 0);
332 
333  connect (ui->cb_widget_custom_style, SIGNAL (toggled (bool)),
334  m_widget_title_bg_color, SLOT (setEnabled (bool)));
335 
336  default_var = QColor (192, 192, 192);
337  QColor bg_color_active = settings->value ("DockWidgets/title_bg_color_active",
338  default_var).value<QColor> ();
339  m_widget_title_bg_color_active = new color_picker (bg_color_active);
340  m_widget_title_bg_color_active->setEnabled (false);
341  ui->layout_widget_bgtitle_active->addWidget (m_widget_title_bg_color_active, 0);
342 
343  connect (ui->cb_widget_custom_style, SIGNAL (toggled (bool)),
344  m_widget_title_bg_color_active, SLOT (setEnabled (bool)));
345 
346  default_var = QColor (0, 0, 0);
347  QColor fg_color = settings->value ("DockWidgets/title_fg_color",
348  default_var).value<QColor> ();
349  m_widget_title_fg_color = new color_picker (fg_color);
350  m_widget_title_fg_color->setEnabled (false);
351  ui->layout_widget_fgtitle->addWidget (m_widget_title_fg_color, 0);
352 
353  connect (ui->cb_widget_custom_style, SIGNAL (toggled (bool)),
354  m_widget_title_fg_color, SLOT (setEnabled (bool)));
355 
356  default_var = QColor (0, 0, 0);
357  QColor fg_color_active = settings->value ("DockWidgets/title_fg_color_active",
358  default_var).value<QColor> ();
359  m_widget_title_fg_color_active = new color_picker (fg_color_active);
360  m_widget_title_fg_color_active->setEnabled (false);
361  ui->layout_widget_fgtitle_active->addWidget (m_widget_title_fg_color_active, 0);
362 
363  connect (ui->cb_widget_custom_style, SIGNAL (toggled (bool)),
364  m_widget_title_fg_color_active, SLOT (setEnabled (bool)));
365 
366  ui->sb_3d_title->setValue (settings->value ("DockWidgets/widget_title_3d", 50).toInt ());
367  ui->cb_widget_custom_style->setChecked (settings->value ("DockWidgets/widget_title_custom_style", false).toBool ());
368 
369  // Cursor blinking: consider old terminal related setting if not yet set
370  // TODO: This pref. can be deprecated / removed if Qt adds support for
371  // getting the cursor blink preferences from all OS environments
372  if (settings->contains ("cursor_blinking"))
373  {
374  // Preference exists, read its value
375  ui->cb_cursor_blinking->setChecked (settings->value ("cursor_blinking", true).toBool ());
376  }
377  else
378  {
379  // Pref. does not exist, so take old terminal related pref.
380  ui->cb_cursor_blinking->setChecked (settings->value ("terminal/cursorBlinking", true).toBool ());
381  }
382 
383  // prompt on exit
384  ui->cb_prompt_to_exit->setChecked (settings->value ("prompt_to_exit", false).toBool ());
385 
386  // Main status bar
387  ui->cb_status_bar->setChecked (settings->value ("show_status_bar", true).toBool ());
388 
389  // Octave startup
390  ui->cb_restore_octave_dir->setChecked (settings->value ("restore_octave_dir", false).toBool ());
391  ui->le_octave_dir->setText (settings->value ("octave_startup_dir").toString ());
392 
393  connect (ui->pb_octave_dir, SIGNAL (pressed (void)),
394  this, SLOT (get_octave_dir (void)));
395 
396  //
397  // editor
398  //
399  ui->useCustomFileEditor->setChecked (settings->value ("useCustomFileEditor", false).toBool ());
400  ui->customFileEditor->setText (settings->value ("customFileEditor").toString ());
401  ui->editor_showLineNumbers->setChecked (settings->value ("editor/showLineNumbers", true).toBool ());
402  ui->editor_linenr_size->setValue (settings->value ("editor/line_numbers_size", 0).toInt ());
403 
404  resource_manager::combo_encoding (ui->editor_combo_encoding);
405 
406  default_var = QColor (240, 240, 240);
407  QColor setting_color = settings->value ("editor/highlight_current_line_color", default_var).value<QColor> ();
408  m_editor_current_line_color = new color_picker (setting_color);
409  ui->editor_grid_current_line->addWidget (m_editor_current_line_color, 0, 3);
410  m_editor_current_line_color->setMinimumSize (20, 10);
411  m_editor_current_line_color->setEnabled (false);
412 
413  connect (ui->editor_highlightCurrentLine, SIGNAL (toggled (bool)),
414  m_editor_current_line_color, SLOT (setEnabled (bool)));
415 
416  ui->editor_highlightCurrentLine->setChecked (settings->value ("editor/highlightCurrentLine", true).toBool ());
417  ui->editor_long_line_marker->setChecked (settings->value ("editor/long_line_marker", true).toBool ());
418  bool long_line =
419  settings->value ("editor/long_line_marker_line", true).toBool ();
420  ui->editor_long_line_marker_line->setChecked (long_line);
421  bool long_back =
422  settings->value ("editor/long_line_marker_background", false).toBool ();
423  ui->editor_long_line_marker_background->setChecked (long_back);
424  if (! (long_line || long_back))
425  ui->editor_long_line_marker_line->setChecked (true);
426  ui->editor_long_line_column->setValue (settings->value ("editor/long_line_column", 80).toInt ());
427  ui->editor_break_checkbox->setChecked (settings->value ("editor/break_lines", false).toBool ());
428  ui->editor_break_checkbox->setChecked (settings->value ("editor/break_lines_comments", false).toBool ());
429  ui->editor_wrap_checkbox->setChecked (settings->value ("editor/wrap_lines", false).toBool ());
430  ui->cb_edit_status_bar->setChecked (settings->value ("editor/show_edit_status_bar", true).toBool ());
431  ui->cb_edit_tool_bar->setChecked (settings->value ("editor/show_toolbar", true).toBool ());
432  ui->cb_code_folding->setChecked (settings->value ("editor/code_folding", true).toBool ());
433  ui->editor_highlight_all_occurrences->setChecked (settings->value ("editor/highlight_all_occurrences", true).toBool ());
434 
435  ui->editor_auto_endif->setCurrentIndex (settings->value ("editor/auto_endif", 1).toInt () );
436  ui->editor_codeCompletion->setChecked (settings->value ("editor/codeCompletion", true).toBool ());
437  ui->editor_spinbox_ac_threshold->setValue (settings->value ("editor/codeCompletion_threshold", 2).toInt ());
438  ui->editor_checkbox_ac_keywords->setChecked (settings->value ("editor/codeCompletion_keywords", true).toBool ());
439  ui->editor_checkbox_ac_builtins->setEnabled (ui->editor_checkbox_ac_keywords->isChecked ());
440  ui->editor_checkbox_ac_functions->setEnabled (ui->editor_checkbox_ac_keywords->isChecked ());
441  ui->editor_checkbox_ac_builtins->setChecked (settings->value ("editor/codeCompletion_octave_builtins", true).toBool ());
442  ui->editor_checkbox_ac_functions->setChecked (settings->value ("editor/codeCompletion_octave_functions", true).toBool ());
443  ui->editor_checkbox_ac_document->setChecked (settings->value ("editor/codeCompletion_document", false).toBool ());
444  ui->editor_checkbox_ac_case->setChecked (settings->value ("editor/codeCompletion_case", true).toBool ());
445  ui->editor_checkbox_ac_replace->setChecked (settings->value ("editor/codeCompletion_replace", false).toBool ());
446  ui->editor_ws_checkbox->setChecked (settings->value ("editor/show_white_space", false).toBool ());
447  ui->editor_ws_indent_checkbox->setChecked (settings->value ("editor/show_white_space_indent", false).toBool ());
448  ui->cb_show_eol->setChecked (settings->value ("editor/show_eol_chars", false).toBool ());
449  ui->cb_show_hscrollbar->setChecked (settings->value ("editor/show_hscroll_bar", true).toBool ());
450 
451  int selected_comment_string, selected_uncomment_string;
452 
453  if (settings->contains (oct_comment_str)) // new version (radio buttons)
454  selected_comment_string = settings->value (oct_comment_str,
455  oct_comment_str_d).toInt ();
456  else // old version (combo box)
457  selected_comment_string = settings->value (oct_comment_str_old,
458  oct_comment_str_d).toInt ();
459 
460  selected_uncomment_string = settings->value (oct_uncomment_str,
461  oct_uncomment_str_d).toInt ();
462 
463  for (int i = 0; i < oct_comment_strings_count; i++)
464  {
465  m_rb_comment_strings[i] = new QRadioButton ();
466  m_rb_uncomment_strings[i] = new QRadioButton ();
467 
468  connect (m_rb_comment_strings[i], SIGNAL (clicked (bool)),
469  m_rb_uncomment_strings[i], SLOT (setChecked (bool)));
470  connect (m_rb_comment_strings[i], SIGNAL (toggled (bool)),
471  m_rb_uncomment_strings[i], SLOT (setDisabled (bool)));
472 
474  m_rb_comment_strings[i]->setChecked (i == selected_comment_string);
475  ui->layout_comment_strings->addWidget (m_rb_comment_strings[i]);
476 
478  m_rb_uncomment_strings[i]->setAutoExclusive (false);
479  m_rb_uncomment_strings[i]->setChecked ( 1 << i & selected_uncomment_string);
480  ui->layout_uncomment_strings->addWidget (m_rb_uncomment_strings[i]);
481  }
482 
483 
484 #if defined (HAVE_QSCINTILLA)
485 # if defined (Q_OS_WIN32)
486  int eol_mode = QsciScintilla::EolWindows;
487 #elif defined (Q_OS_MAC)
488  int eol_mode = QsciScintilla::EolMac;
489 #else
490  int eol_mode = QsciScintilla::EolUnix;
491 #endif
492 #else
493  int eol_mode = 2;
494 #endif
495  ui->combo_eol_mode->setCurrentIndex (settings->value ("editor/default_eol_mode", eol_mode).toInt ());
496  ui->editor_auto_ind_checkbox->setChecked (settings->value ("editor/auto_indent", true).toBool ());
497  ui->editor_tab_ind_checkbox->setChecked (settings->value ("editor/tab_indents_line", false).toBool ());
498  ui->editor_bs_unind_checkbox->setChecked (settings->value ("editor/backspace_unindents_line", false).toBool ());
499  ui->editor_ind_guides_checkbox->setChecked (settings->value ("editor/show_indent_guides", false).toBool ());
500  ui->editor_ind_width_spinbox->setValue (settings->value ("editor/indent_width", 2).toInt ());
501  ui->editor_ind_uses_tabs_checkbox->setChecked (settings->value ("editor/indent_uses_tabs", false).toBool ());
502  ui->editor_tab_width_spinbox->setValue (settings->value ("editor/tab_width", 2).toInt ());
503  ui->editor_longWindowTitle->setChecked (settings->value ("editor/longWindowTitle", false).toBool ());
504  ui->editor_notebook_tab_width_min->setValue (settings->value ("editor/notebook_tab_width_min", 160).toInt ());
505  ui->editor_notebook_tab_width_max->setValue (settings->value ("editor/notebook_tab_width_max", 300).toInt ());
506  ui->editor_restoreSession->setChecked (settings->value ("editor/restoreSession", true).toBool ());
507  ui->editor_create_new_file->setChecked (settings->value ("editor/create_new_file", false).toBool ());
508  ui->editor_reload_changed_files->setChecked (settings->value ("editor/always_reload_changed_files", false).toBool ());
509  ui->editor_hiding_closes_files->setChecked (settings->value ("editor/hiding_closes_files", false).toBool ());
510 
511  // terminal
512  ui->terminal_fontName->setCurrentFont (QFont (settings->value ("terminal/fontName", "Courier New").toString ()));
513  ui->terminal_fontSize->setValue (settings->value ("terminal/fontSize", 10).toInt ());
514  ui->terminal_history_buffer->setValue (settings->value ("terminal/history_buffer", 1000).toInt ());
515  ui->terminal_cursorUseForegroundColor->setChecked (settings->value ("terminal/cursorUseForegroundColor", true).toBool ());
516  ui->terminal_focus_command->setChecked (settings->value ("terminal/focus_after_command", false).toBool ());
517  ui->terminal_print_dbg_location->setChecked (settings->value ("terminal/print_debug_location", false).toBool ());
518 
519  QString cursorType
520  = settings->value ("terminal/cursorType", "ibeam").toString ();
521 
522  QStringList items;
523  items << QString ("0") << QString ("1") << QString ("2");
524  ui->terminal_cursorType->addItems (items);
525  ui->terminal_cursorType->setItemText (0, tr ("IBeam Cursor"));
526  ui->terminal_cursorType->setItemText (1, tr ("Block Cursor"));
527  ui->terminal_cursorType->setItemText (2, tr ("Underline Cursor"));
528 
529  if (cursorType == "ibeam")
530  ui->terminal_cursorType->setCurrentIndex (0);
531  else if (cursorType == "block")
532  ui->terminal_cursorType->setCurrentIndex (1);
533  else if (cursorType == "underline")
534  ui->terminal_cursorType->setCurrentIndex (2);
535 
536  // file browser
537  connect (ui->sync_octave_directory, SIGNAL (toggled (bool)),
538  this, SLOT (set_disabled_pref_file_browser_dir (bool)));
539 
540  ui->sync_octave_directory->setChecked (settings->value ("filesdockwidget/sync_octave_directory", true).toBool ());
541  ui->cb_restore_file_browser_dir->setChecked (settings->value ("filesdockwidget/restore_last_dir", false).toBool ());
542  ui->le_file_browser_dir->setText (settings->value ("filesdockwidget/startup_dir").toString ());
543 
544  connect (ui->pb_file_browser_dir, SIGNAL (pressed (void)),
545  this, SLOT (get_file_browser_dir (void)));
546 
547  ui->le_file_browser_extensions->setText (settings->value ("filesdockwidget/txt_file_extensions", "m;c;cc;cpp;h;txt").toString ());
548 
549  ui->checkbox_allow_web_connect->setChecked (settings->value ("news/allow_web_connection", false).toBool ());
550  ui->useProxyServer->setChecked (settings->value ("useProxyServer", false).toBool ());
551  ui->proxyHostName->setText (settings->value ("proxyHostName").toString ());
552 
553  int currentIndex = 0;
554  QString proxyTypeString = settings->value ("proxyType").toString ();
555  while ((currentIndex < ui->proxyType->count ())
556  && (ui->proxyType->currentText () != proxyTypeString))
557  {
558  currentIndex++;
559  ui->proxyType->setCurrentIndex (currentIndex);
560  }
561 
562  ui->proxyPort->setText (settings->value ("proxyPort").toString ());
563  ui->proxyUserName->setText (settings->value ("proxyUserName").toString ());
564  ui->proxyPassword->setText (settings->value ("proxyPassword").toString ());
565 
566  // Workspace
567  // colors
568  read_workspace_colors (settings);
569  // hide tool tips
570  ui->cb_hide_tool_tips->setChecked (settings->value ("workspaceview/hide_tool_tips", false).toBool ());
571 
572  // terminal colors
573  read_terminal_colors (settings);
574 
575  // variable editor
576  ui->varedit_columnWidth->setValue (settings->value ("variable_editor/column_width", 100).toInt ());
577  ui->varedit_autoFitColumnWidth->setChecked (settings->value ("variable_editor/autofit_column_width", false).toBool ());
578  ui->varedit_autofitType->setCurrentIndex (settings->value ("autofit_type", 0).toInt ());
579  ui->varedit_rowHeight->setValue (settings->value ("variable_editor/row_height", 10).toInt ());
580  ui->varedit_rowAutofit->setChecked (settings->value ("variable_editor/autofit_row_height", true).toBool ());
581 
582  ui->varedit_font->setCurrentFont (QFont (settings->value ("variable_editor/font_name", settings->value ("terminal/fontName", "Courier New")).toString ()));
583  ui->varedit_fontSize->setValue (settings->value ("variable_editor/font_size", QVariant (10)).toInt ());
584  connect (ui->varedit_useTerminalFont, SIGNAL (toggled (bool)),
585  ui->varedit_font, SLOT (setDisabled (bool)));
586  connect (ui->varedit_useTerminalFont, SIGNAL (toggled (bool)),
587  ui->varedit_fontSize, SLOT (setDisabled (bool)));
588  ui->varedit_useTerminalFont->setChecked (settings->value ("variable_editor/use_terminal_font", false).toBool ());
589  ui->varedit_font->setDisabled (ui->varedit_useTerminalFont->isChecked ());
590  ui->varedit_fontSize->setDisabled (ui->varedit_useTerminalFont->isChecked ());
591 
592  ui->varedit_alternate->setChecked (settings->value ("variable_editor/alternate_rows", QVariant (false)).toBool ());
593 
594  // variable editor colors
595  read_varedit_colors (settings);
596 
597  // shortcuts
598 
599  ui->cb_prevent_readline_conflicts->setChecked (settings->value ("shortcuts/prevent_readline_conflicts", true).toBool ());
600 
601  // initialize the tree view with all shortcut data
602  shortcut_manager::fill_treewidget (ui->shortcuts_treewidget);
603 
604  // connect the buttons for import/export of the shortcut sets
605  connect (ui->btn_import_shortcut_set, SIGNAL (clicked (void)),
606  this, SLOT (import_shortcut_set (void)));
607 
608  connect (ui->btn_export_shortcut_set, SIGNAL (clicked (void)),
609  this, SLOT (export_shortcut_set (void)));
610 
611  connect (ui->btn_default_shortcut_set, SIGNAL (clicked (void)),
612  this, SLOT (default_shortcut_set (void)));
613 
614 #if defined (HAVE_QSCINTILLA)
615 
616  // editor styles: create lexer, read settings, and create dialog elements
617  QsciLexer *lexer;
618 
619 #if defined (HAVE_LEXER_OCTAVE)
620 
621  lexer = new QsciLexerOctave ();
622  read_lexer_settings (ui, lexer, settings);
623  delete lexer;
624 
625 #elif defined (HAVE_LEXER_MATLAB)
626 
627  lexer = new QsciLexerMatlab ();
628  read_lexer_settings (ui, lexer, settings);
629  delete lexer;
630 
631 #endif
632 
633  lexer = new QsciLexerCPP ();
634  read_lexer_settings (ui, lexer, settings);
635  delete lexer;
636 
637  lexer = new QsciLexerPerl ();
638  read_lexer_settings (ui, lexer, settings);
639  delete lexer;
640 
641  lexer = new QsciLexerBatch ();
642  read_lexer_settings (ui, lexer, settings);
643  delete lexer;
644 
645  lexer = new QsciLexerDiff ();
646  read_lexer_settings (ui, lexer, settings);
647  delete lexer;
648 
649  lexer = new QsciLexerBash ();
650  read_lexer_settings (ui, lexer, settings);
651  delete lexer;
652 
653  lexer = new octave::octave_txt_lexer ();
654  read_lexer_settings (ui, lexer, settings);
655  delete lexer;
656 
657 #endif
658 
659  // which tab is the desired one?
660  show_tab (desired_tab);
661 
662  // connect button box signal
663  connect (ui->button_box, SIGNAL (clicked (QAbstractButton *)),
664  this, SLOT (button_clicked (QAbstractButton *)));
665 
666  // restore last geometry
667  if (settings->contains ("settings/geometry"))
668  restoreGeometry (settings->value ("settings/geometry").toByteArray ());
669  else
670  setGeometry (QRect (10,50,1000,600));
671 }
672 
674 {
675  delete ui;
676 }
677 
678 void
679 settings_dialog::show_tab (const QString& tab)
680 {
681  if (tab.isEmpty ())
682  {
683  QSettings *settings = resource_manager::get_settings ();
684  if (settings)
685  ui->tabWidget->setCurrentIndex (settings->value ("settings/last_tab", 0).toInt ());
686  }
687  else
688  {
689  QHash <QString, QWidget*> tab_hash;
690  tab_hash["editor"] = ui->tab_editor;
691  tab_hash["editor_styles"] = ui->tab_editor_styles;
692  ui->tabWidget->setCurrentIndex (ui->tabWidget->indexOf (tab_hash.value (tab)));
693  }
694 }
695 
696 void
698 {
699  get_dir (ui->le_octave_dir, tr ("Set Octave Startup Directory"));
700 }
701 
702 void
704 {
705  get_dir (ui->le_file_browser_dir, tr ("Set File Browser Startup Directory"));
706 }
707 
708 void
709 settings_dialog::get_dir (QLineEdit *line_edit, const QString& title)
710 {
711  QString dir = QFileDialog::getExistingDirectory
712  (this, title, line_edit->text (), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
713 
714  line_edit->setText (dir);
715 }
716 
717 void
718 settings_dialog::button_clicked (QAbstractButton *button)
719 {
720  QDialogButtonBox::ButtonRole button_role = ui->button_box->buttonRole (button);
721 
722  if (button_role == QDialogButtonBox::ApplyRole
723  || button_role == QDialogButtonBox::AcceptRole)
724  {
725  write_changed_settings (button_role == QDialogButtonBox::AcceptRole);
726  emit apply_new_settings ();
727  }
728 
729  if (button_role == QDialogButtonBox::RejectRole
730  || button_role == QDialogButtonBox::AcceptRole)
731  close ();
732 }
733 
734 void
736 {
737  ui->cb_restore_file_browser_dir->setDisabled (disable);
738 
739  if (! disable)
740  {
741  ui->le_file_browser_dir->setDisabled (ui->cb_restore_file_browser_dir->isChecked ());
742  ui->pb_file_browser_dir->setDisabled (ui->cb_restore_file_browser_dir->isChecked ());
743  }
744  else
745  {
746  ui->le_file_browser_dir->setDisabled (disable);
747  ui->pb_file_browser_dir->setDisabled (disable);
748  }
749 }
750 
751 // slots for import/export of shortcut sets
752 void
754 {
755  shortcut_manager::import_export (shortcut_manager::OSC_IMPORT);
756 }
757 
758 void
760 {
761  shortcut_manager::import_export (shortcut_manager::OSC_EXPORT);
762 }
763 
764 void
766 {
767  shortcut_manager::import_export (shortcut_manager::OSC_DEFAULT);
768 }
769 
770 void
772 {
773  QSettings *settings = resource_manager::get_settings ();
774 
775  // the icon set
776  QString widget_icon_set = "NONE";
777  if (ui->general_icon_letter->isChecked ())
778  widget_icon_set = "LETTER";
779  else if (ui->general_icon_graphic->isChecked ())
780  widget_icon_set = "GRAPHIC";
781  settings->setValue ("DockWidgets/widget_icon_set", widget_icon_set);
782 
783  // language
784  QString language = ui->comboBox_language->currentText ();
785  if (language == tr ("System setting"))
786  language = "SYSTEM";
787  settings->setValue ("language", language);
788 
789  // dock widget title bar
790  settings->setValue ("DockWidgets/widget_title_custom_style", ui->cb_widget_custom_style->isChecked ());
791  settings->setValue ("DockWidgets/widget_title_3d", ui->sb_3d_title->value ());
792  settings->setValue ("DockWidgets/title_bg_color", m_widget_title_bg_color->color ());
793  settings->setValue ("DockWidgets/title_bg_color_active", m_widget_title_bg_color_active->color ());
794  settings->setValue ("DockWidgets/title_fg_color", m_widget_title_fg_color->color ());
795  settings->setValue ("DockWidgets/title_fg_color_active", m_widget_title_fg_color_active->color ());
796 
797  // icon size
798  int icon_size = 0;
799  if (ui->icon_size_small->isChecked ())
800  icon_size = -1;
801  else if (ui->icon_size_large->isChecked ())
802  icon_size = 1;
803  settings->setValue ("toolbar_icon_size", icon_size);
804 
805  // cursor blinking
806  settings->setValue ("cursor_blinking", ui->cb_cursor_blinking->isChecked ());
807 
808  // promp to exit
809  settings->setValue ("prompt_to_exit", ui->cb_prompt_to_exit->isChecked ());
810 
811  // status bar
812  settings->setValue ("show_status_bar", ui->cb_status_bar->isChecked ());
813 
814  // Octave startup
815  settings->setValue ("restore_octave_dir", ui->cb_restore_octave_dir->isChecked ());
816  settings->setValue ("octave_startup_dir", ui->le_octave_dir->text ());
817 
818  //editor
819  settings->setValue ("useCustomFileEditor", ui->useCustomFileEditor->isChecked ());
820  settings->setValue ("customFileEditor", ui->customFileEditor->text ());
821  settings->setValue ("editor/showLineNumbers", ui->editor_showLineNumbers->isChecked ());
822  settings->setValue ("editor/line_numbers_size", ui->editor_linenr_size->value ());
823  settings->setValue ("editor/highlightCurrentLine", ui->editor_highlightCurrentLine->isChecked ());
824  settings->setValue ("editor/highlight_current_line_color", m_editor_current_line_color->color ());
825  settings->setValue ("editor/long_line_marker", ui->editor_long_line_marker->isChecked ());
826  settings->setValue ("editor/long_line_marker_line", ui->editor_long_line_marker_line->isChecked ());
827  settings->setValue ("editor/long_line_marker_background", ui->editor_long_line_marker_background->isChecked ());
828  settings->setValue ("editor/long_line_column", ui->editor_long_line_column->value ());
829  settings->setValue ("editor/break_lines", ui->editor_break_checkbox->isChecked ());
830  settings->setValue ("editor/break_lines_comments", ui->editor_break_comments_checkbox->isChecked ());
831  settings->setValue ("editor/wrap_lines", ui->editor_wrap_checkbox->isChecked ());
832  settings->setValue ("editor/code_folding", ui->cb_code_folding->isChecked ());
833  settings->setValue ("editor/show_edit_status_bar", ui->cb_edit_status_bar->isChecked ());
834  settings->setValue ("editor/show_toolbar", ui->cb_edit_tool_bar->isChecked ());
835  settings->setValue ("editor/highlight_all_occurrences", ui->editor_highlight_all_occurrences->isChecked ());
836  settings->setValue ("editor/codeCompletion", ui->editor_codeCompletion->isChecked ());
837  settings->setValue ("editor/codeCompletion_threshold", ui->editor_spinbox_ac_threshold->value ());
838  settings->setValue ("editor/codeCompletion_keywords", ui->editor_checkbox_ac_keywords->isChecked ());
839  settings->setValue ("editor/codeCompletion_octave_builtins", ui->editor_checkbox_ac_builtins->isChecked ());
840  settings->setValue ("editor/codeCompletion_octave_functions", ui->editor_checkbox_ac_functions->isChecked ());
841  settings->setValue ("editor/codeCompletion_document", ui->editor_checkbox_ac_document->isChecked ());
842  settings->setValue ("editor/codeCompletion_case", ui->editor_checkbox_ac_case->isChecked ());
843  settings->setValue ("editor/codeCompletion_replace", ui->editor_checkbox_ac_replace->isChecked ());
844  settings->setValue ("editor/auto_endif", ui->editor_auto_endif->currentIndex ());
845  settings->setValue ("editor/show_white_space", ui->editor_ws_checkbox->isChecked ());
846  settings->setValue ("editor/show_white_space_indent", ui->editor_ws_indent_checkbox->isChecked ());
847  settings->setValue ("editor/show_eol_chars", ui->cb_show_eol->isChecked ());
848  settings->setValue ("editor/show_hscroll_bar", ui->cb_show_hscrollbar->isChecked ());
849  settings->setValue ("editor/default_eol_mode", ui->combo_eol_mode->currentIndex ());
850 
851  // Comment strings
852  int rb_uncomment = 0;
853  for (int i = 0; i < oct_comment_strings_count; i++)
854  {
855  if (m_rb_comment_strings[i]->isChecked ())
856  {
857  settings->setValue (oct_comment_str, i);
858  if (i < 3)
859  settings->setValue (oct_comment_str_old, i);
860  else
861  settings->setValue (oct_comment_str_old, oct_comment_str_d);
862  }
863  if (m_rb_uncomment_strings[i]->isChecked ())
864  rb_uncomment = rb_uncomment + (1 << i);
865  }
866  settings->setValue (oct_uncomment_str, rb_uncomment);
867 
868  settings->setValue ("editor/default_encoding", ui->editor_combo_encoding->currentText ());
869  settings->setValue ("editor/auto_indent", ui->editor_auto_ind_checkbox->isChecked ());
870  settings->setValue ("editor/tab_indents_line", ui->editor_tab_ind_checkbox->isChecked ());
871  settings->setValue ("editor/backspace_unindents_line", ui->editor_bs_unind_checkbox->isChecked ());
872  settings->setValue ("editor/show_indent_guides", ui->editor_ind_guides_checkbox->isChecked ());
873  settings->setValue ("editor/indent_width", ui->editor_ind_width_spinbox->value ());
874  settings->setValue ("editor/indent_uses_tabs", ui->editor_ind_uses_tabs_checkbox->isChecked ());
875  settings->setValue ("editor/tab_width", ui->editor_tab_width_spinbox->value ());
876  settings->setValue ("editor/longWindowTitle", ui->editor_longWindowTitle->isChecked ());
877  settings->setValue ("editor/notebook_tab_width_min", ui->editor_notebook_tab_width_min->value ());
878  settings->setValue ("editor/notebook_tab_width_max", ui->editor_notebook_tab_width_max->value ());
879  settings->setValue ("editor/restoreSession", ui->editor_restoreSession->isChecked ());
880  settings->setValue ("editor/create_new_file", ui->editor_create_new_file->isChecked ());
881  settings->setValue ("editor/hiding_closes_files", ui->editor_hiding_closes_files->isChecked ());
882  settings->setValue ("editor/always_reload_changed_files", ui->editor_reload_changed_files->isChecked ());
883  settings->setValue ("terminal/fontSize", ui->terminal_fontSize->value ());
884  settings->setValue ("terminal/fontName", ui->terminal_fontName->currentFont ().family ());
885 
886  // file browser
887  settings->setValue ("filesdockwidget/sync_octave_directory", ui->sync_octave_directory->isChecked ());
888  settings->setValue ("filesdockwidget/restore_last_dir", ui->cb_restore_file_browser_dir->isChecked ());
889  settings->setValue ("filesdockwidget/startup_dir", ui->le_file_browser_dir->text ());
890  settings->setValue ("filesdockwidget/txt_file_extensions", ui->le_file_browser_extensions->text ());
891 
892  settings->setValue ("news/allow_web_connection", ui->checkbox_allow_web_connect->isChecked ());
893  settings->setValue ("useProxyServer", ui->useProxyServer->isChecked ());
894  settings->setValue ("proxyType", ui->proxyType->currentText ());
895  settings->setValue ("proxyHostName", ui->proxyHostName->text ());
896  settings->setValue ("proxyPort", ui->proxyPort->text ());
897  settings->setValue ("proxyUserName", ui->proxyUserName->text ());
898  settings->setValue ("proxyPassword", ui->proxyPassword->text ());
899  settings->setValue ("terminal/cursorUseForegroundColor", ui->terminal_cursorUseForegroundColor->isChecked ());
900  settings->setValue ("terminal/focus_after_command", ui->terminal_focus_command->isChecked ());
901  settings->setValue ("terminal/print_debug_location", ui->terminal_print_dbg_location->isChecked ());
902  settings->setValue ("terminal/history_buffer", ui->terminal_history_buffer->value ());
903 
904  // the cursor
905  QString cursorType;
906  switch (ui->terminal_cursorType->currentIndex ())
907  {
908  case 0: cursorType = "ibeam"; break;
909  case 1: cursorType = "block"; break;
910  case 2: cursorType = "underline"; break;
911  }
912  settings->setValue ("terminal/cursorType", cursorType);
913 
914 #if defined (HAVE_QSCINTILLA)
915  // editor styles: create lexer, get dialog contents, and write settings
916  QsciLexer *lexer;
917 
918 #if defined (HAVE_LEXER_OCTAVE)
919 
920  lexer = new QsciLexerOctave ();
921  write_lexer_settings (ui, lexer, settings);
922  delete lexer;
923 
924 #elif defined (HAVE_LEXER_MATLAB)
925 
926  lexer = new QsciLexerMatlab ();
927  write_lexer_settings (ui, lexer, settings);
928  delete lexer;
929 
930 #endif
931 
932  lexer = new QsciLexerCPP ();
933  write_lexer_settings (ui, lexer, settings);
934  delete lexer;
935 
936  lexer = new QsciLexerPerl ();
937  write_lexer_settings (ui, lexer, settings);
938  delete lexer;
939 
940  lexer = new QsciLexerBatch ();
941  write_lexer_settings (ui, lexer, settings);
942  delete lexer;
943 
944  lexer = new QsciLexerDiff ();
945  write_lexer_settings (ui, lexer, settings);
946  delete lexer;
947 
948  lexer = new QsciLexerBash ();
949  write_lexer_settings (ui, lexer, settings);
950  delete lexer;
951 
952  lexer = new octave::octave_txt_lexer ();
953  write_lexer_settings (ui, lexer, settings);
954  delete lexer;
955 
956 #endif
957 
958  // Workspace
959  write_workspace_colors (settings);
960  // hide tool tips
961  settings->setValue ("workspaceview/hide_tool_tips", ui->cb_hide_tool_tips->isChecked ());
962 
963  // Terminal
964  write_terminal_colors (settings);
965 
966  // Variable editor
967  settings->setValue ("variable_editor/autofit_column_width", ui->varedit_autoFitColumnWidth->isChecked ());
968  settings->setValue ("variable_editor/autofit_type", ui->varedit_autofitType->currentIndex ());
969  settings->setValue ("variable_editor/column_width", ui->varedit_columnWidth->value ());
970  settings->setValue ("variable_editor/row_height", ui->varedit_rowHeight->value ());
971  settings->setValue ("variable_editor/autofit_row_height", ui->varedit_rowAutofit->isChecked ());
972  settings->setValue ("variable_editor/use_terminal_font", ui->varedit_useTerminalFont->isChecked ());
973  settings->setValue ("variable_editor/alternate_rows", ui->varedit_alternate->isChecked ());
974  settings->setValue ("variable_editor/font_name", ui->varedit_font->currentFont ().family ());
975  settings->setValue ("variable_editor/font_size", ui->varedit_fontSize->value ());
976  write_varedit_colors (settings);
977 
978  // shortcuts
979  settings->setValue ("shortcuts/prevent_readline_conflicts", ui->cb_prevent_readline_conflicts->isChecked ());
980  shortcut_manager::write_shortcuts (settings, closing);
981 
982  // settings dialog's geometry
983  settings->setValue ("settings/last_tab", ui->tabWidget->currentIndex ());
984  settings->setValue ("settings/geometry", saveGeometry ());
985 
986  settings->sync ();
987 }
988 
989 void
991 {
992 
993  QList<QColor> default_colors =
994  resource_manager::storage_class_default_colors ();
995  QStringList class_names = resource_manager::storage_class_names ();
996  QString class_chars = resource_manager::storage_class_chars ();
997  int nr_of_classes = class_chars.length ();
998 
999  QGridLayout *style_grid = new QGridLayout ();
1000  QVector<QLabel*> description (nr_of_classes);
1001  QVector<color_picker*> color (nr_of_classes);
1002 
1003  int column = 0;
1004  int row = 0;
1005  for (int i = 0; i < nr_of_classes; i++)
1006  {
1007  description[i] = new QLabel (" " + class_names.at (i));
1008  description[i]->setAlignment (Qt::AlignRight);
1009  QVariant default_var = default_colors.at (i);
1010  QColor setting_color = settings->value ("workspaceview/color_" + class_chars.mid (i, 1), default_var).value<QColor> ();
1011  color[i] = new color_picker (setting_color);
1012  color[i]->setObjectName ("color_" + class_chars.mid (i, 1));
1013  color[i]->setMinimumSize (30, 10);
1014  style_grid->addWidget (description[i], row, 3*column);
1015  style_grid->addWidget (color[i], row, 3*column+1);
1016  if (++column == 3)
1017  {
1018  style_grid->setColumnStretch (4*column, 10);
1019  row++;
1020  column = 0;
1021  }
1022  }
1023 
1024  // place grid with elements into the tab
1025  ui->workspace_colors_box->setLayout (style_grid);
1026 }
1027 
1028 void
1030 {
1031 
1032  QString class_chars = resource_manager::storage_class_chars ();
1033  color_picker *color;
1034 
1035  for (int i = 0; i < class_chars.length (); i++)
1036  {
1037  color = ui->workspace_colors_box->findChild <color_picker *> ("color_" + class_chars.mid (i, 1));
1038  if (color)
1039  settings->setValue ("workspaceview/color_" + class_chars.mid (i, 1), color->color ());
1040  }
1041  settings->sync ();
1042 }
1043 
1044 void
1046 {
1047 
1048  QList<QColor> default_colors = resource_manager::terminal_default_colors ();
1049  QStringList class_names = resource_manager::terminal_color_names ();
1050  QString class_chars = resource_manager::terminal_color_chars ();
1051  int nr_of_classes = class_chars.length ();
1052 
1053  QGridLayout *style_grid = new QGridLayout ();
1054  QVector<QLabel*> description (nr_of_classes);
1055  QVector<color_picker*> color (nr_of_classes);
1056 
1057  int column = 0;
1058  int row = 0;
1059  for (int i = 0; i < nr_of_classes; i++)
1060  {
1061  description[i] = new QLabel (" " + class_names.at (i));
1062  description[i]->setAlignment (Qt::AlignRight);
1063  QVariant default_var = default_colors.at (i);
1064  QColor setting_color = settings->value ("terminal/color_" + class_chars.mid (i, 1), default_var).value<QColor> ();
1065  color[i] = new color_picker (setting_color);
1066  color[i]->setObjectName ("terminal_color_" + class_chars.mid (i, 1));
1067  color[i]->setMinimumSize (30, 10);
1068  style_grid->addWidget (description[i], row, 2*column);
1069  style_grid->addWidget (color[i], row, 2*column+1);
1070  if (++column == 2)
1071  {
1072  style_grid->setColumnStretch (3*column, 10);
1073  row++;
1074  column = 0;
1075  }
1076  }
1077 
1078  // place grid with elements into the tab
1079  ui->terminal_colors_box->setLayout (style_grid);
1080 }
1081 
1082 void
1084 {
1085  QString class_chars = resource_manager::terminal_color_chars ();
1086  color_picker *color;
1087 
1088  for (int i = 0; i < class_chars.length (); i++)
1089  {
1090  color = ui->terminal_colors_box->findChild <color_picker *> ("terminal_color_" + class_chars.mid (i, 1));
1091  if (color)
1092  settings->setValue ("terminal/color_" + class_chars.mid (i, 1), color->color ());
1093  }
1094 
1095  settings->sync ();
1096 }
1097 
1098 void
1100 {
1102  QStringList class_names = octave::variable_editor::color_names ();
1103  QString class_chars = resource_manager::varedit_color_chars ();
1104  int nr_of_classes = class_chars.length ();
1105 
1106  QGridLayout *style_grid = new QGridLayout ();
1107  QVector<QLabel*> description (nr_of_classes);
1108  QVector<color_picker*> color (nr_of_classes);
1109 
1110  int column = 0;
1111  int row = 0;
1112  for (int i = 0; i < nr_of_classes; i++)
1113  {
1114  description[i] = new QLabel (" " + class_names.at (i));
1115  description[i]->setAlignment (Qt::AlignRight);
1116  QVariant default_var = default_colors.at (i);
1117  QColor setting_color = settings->value ("variable_editor/color_" + class_chars.mid (i, 1), default_var).value<QColor> ();
1118  color[i] = new color_picker (setting_color);
1119  color[i]->setObjectName ("varedit_color_" + class_chars.mid (i, 1));
1120  color[i]->setMinimumSize (30, 10);
1121  style_grid->addWidget (description[i], row, 2*column);
1122  style_grid->addWidget (color[i], row, 2*column+1);
1123  if (++column == 2)
1124  {
1125  style_grid->setColumnStretch (3*column, 10);
1126  row++;
1127  column = 0;
1128  }
1129  }
1130 
1131  // place grid with elements into the tab
1132  ui->varedit_colors_box->setLayout (style_grid);
1133 }
1134 
1135 void
1137 {
1138  QString class_chars = resource_manager::varedit_color_chars ();
1139  color_picker *color;
1140 
1141  for (int i = 0; i < class_chars.length (); i++)
1142  {
1143  color = ui->varedit_colors_box->findChild <color_picker *> ("varedit_color_" + class_chars.mid (i, 1));
1144  if (color)
1145  settings->setValue ("variable_editor/color_" + class_chars.mid (i, 1), color->color ());
1146  }
1147 
1148  settings->sync ();
1149 }
static const int MaxLexerStyles
static QStringList color_names(void)
settings_dialog(QWidget *parent, const QString &desired_tab=QString())
OCTAVE_EXPORT octave_value_list column
Definition: sparse.cc:123
const QStringList oct_comment_strings(QStringList()<< "##"<< "#"<< "%"<< "%%"<< "%!")
QColor color(void) const
Definition: color-picker.h:45
static int get_valid_lexer_styles(QsciLexer *lexer, int styles[])
static void write_lexer_settings(Ui::settings_dialog *ui, QsciLexer *lexer, QSettings *settings)
color_picker * m_widget_title_fg_color_active
void read_varedit_colors(QSettings *settings)
void set_disabled_pref_file_browser_dir(bool disable)
void get_octave_dir(void)
const int oct_comment_str_d
Ui::settings_dialog * ui
void read_terminal_colors(QSettings *settings)
static void read_lexer_settings(Ui::settings_dialog *ui, QsciLexer *lexer, QSettings *settings)
void export_shortcut_set(void)
void default_shortcut_set(void)
void get_file_browser_dir(void)
color_picker * m_widget_title_bg_color
const QString oct_comment_str("editor/oct_comment_str")
color_picker * m_editor_current_line_color
void write_workspace_colors(QSettings *settings)
const int oct_uncomment_str_d
void apply_new_settings(void)
static QList< QColor > default_colors(void)
QRadioButton * m_rb_comment_strings[oct_comment_strings_count]
color_picker * m_widget_title_fg_color
const QString oct_comment_str_old("editor/octave_comment_string")
void import_shortcut_set(void)
void write_changed_settings(bool closing)
QRadioButton * m_rb_uncomment_strings[oct_comment_strings_count]
void show_tab(const QString &)
p
Definition: lu.cc:138
const QString oct_uncomment_str("editor/oct_uncomment_str")
for i
Definition: data.cc:5264
void write_terminal_colors(QSettings *settings)
void get_dir(QLineEdit *, const QString &)
const int oct_comment_strings_count
void button_clicked(QAbstractButton *button)
void read_workspace_colors(QSettings *settings)
where the brackets indicate optional arguments and and character or cell array For character arrays the conversion is repeated for every row
Definition: str2double.cc:342
void write_varedit_colors(QSettings *settings)
color_picker * m_widget_title_bg_color_active
static const int MaxStyleNumber