GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
settings-dialog.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2011-2013 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include "resource-manager.h"
28 #include "workspace-model.h"
29 #include "settings-dialog.h"
30 #include "ui-settings-dialog.h"
31 #include <QDir>
32 #include <QFileInfo>
33 #include <QVector>
34 #include <QHash>
35 
36 #ifdef HAVE_QSCINTILLA
37 #include <QScrollArea>
38 
39 #if defined (HAVE_QSCI_QSCILEXEROCTAVE_H)
40 #define HAVE_LEXER_OCTAVE
41 #include <Qsci/qscilexeroctave.h>
42 #elif defined (HAVE_QSCI_QSCILEXERMATLAB_H)
43 #define HAVE_LEXER_MATLAB
44 #include <Qsci/qscilexermatlab.h>
45 #endif
46 
47 #include <Qsci/qscilexercpp.h>
48 #include <Qsci/qscilexerbash.h>
49 #include <Qsci/qscilexerperl.h>
50 #include <Qsci/qscilexerbatch.h>
51 #include <Qsci/qscilexerdiff.h>
52 #endif
53 
54 settings_dialog::settings_dialog (QWidget *p, const QString& desired_tab):
55  QDialog (p), ui (new Ui::settings_dialog)
56 {
57  ui->setupUi (this);
58 
59  QSettings *settings = resource_manager::get_settings ();
60  // FIXME: what should happen if settings is 0?
61 
62  // look for available language files and the actual settings
63  QString qm_dir_name = resource_manager::get_gui_translation_dir ();
64  QDir qm_dir (qm_dir_name);
65  QFileInfoList qm_files = qm_dir.entryInfoList (QStringList ("*.qm"),
66  QDir::Files | QDir::Readable,
67  QDir::Name);
68  for (int i = 0; i < qm_files.length (); i++) // insert available languages
69  ui->comboBox_language->addItem (qm_files.at (i).baseName ());
70  // System at beginning
71  ui->comboBox_language->insertItem (0,tr ("System setting"));
72  ui->comboBox_language->insertSeparator (1); // separator after System
73  QString language = settings->value ("language","SYSTEM").toString ();
74  if (language == "SYSTEM")
75  language = tr ("System setting");
76  int selected = ui->comboBox_language->findText (language);
77  if (selected >= 0)
78  ui->comboBox_language->setCurrentIndex (selected);
79  else
80  ui->comboBox_language->setCurrentIndex (0); // System is default
81 
82  ui->toolbar_icon_size->setValue (settings->value ("toolbar_icon_size",
83  16).toInt ());
84 
85  // which icon has to be selected
86  QString widget_icon_set =
87  settings->value ("DockWidgets/widget_icon_set","NONE").toString ();
88  ui->general_icon_octave-> setChecked (true); // the default (if invalid set)
89  ui->general_icon_octave-> setChecked (widget_icon_set == "NONE");
90  ui->general_icon_graphic-> setChecked (widget_icon_set == "GRAPHIC");
91  ui->general_icon_letter-> setChecked (widget_icon_set == "LETTER");
92 
93  ui->useCustomFileEditor->setChecked (settings->value ("useCustomFileEditor",
94  false).toBool ());
95  ui->customFileEditor->setText (
96  settings->value ("customFileEditor").toString ());
97  ui->editor_showLineNumbers->setChecked (
98  settings->value ("editor/showLineNumbers",true).toBool () );
99 
100  QVariant default_var = QColor (240, 240, 240);
101  QColor setting_color = settings->value ("editor/highlight_current_line_color",
102  default_var).value<QColor> ();
103  _editor_current_line_color = new color_picker (setting_color);
104  ui->editor_grid_current_line->addWidget (_editor_current_line_color,0,3);
105  _editor_current_line_color->setMinimumSize (50,10);
106  _editor_current_line_color->setEnabled (false);
107  connect (ui->editor_highlightCurrentLine, SIGNAL (toggled (bool)),
108  _editor_current_line_color, SLOT (setEnabled (bool)));
109  ui->editor_highlightCurrentLine->setChecked (
110  settings->value ("editor/highlightCurrentLine",true).toBool () );
111 
112  ui->editor_codeCompletion->setChecked (
113  settings->value ("editor/codeCompletion", true).toBool () );
114  ui->editor_spinbox_ac_threshold->setValue (
115  settings->value ("editor/codeCompletion_threshold",2).toInt ());
116  ui->editor_checkbox_ac_keywords->setChecked (
117  settings->value ("editor/codeCompletion_keywords",true).toBool ());
118  ui->editor_checkbox_ac_document->setChecked (
119  settings->value ("editor/codeCompletion_document",false).toBool ());
120  ui->editor_checkbox_ac_case->setChecked (
121  settings->value ("editor/codeCompletion_case",true).toBool ());
122  ui->editor_checkbox_ac_replace->setChecked (
123  settings->value ("editor/codeCompletion_replace",false).toBool ());
124  ui->editor_ws_checkbox->setChecked (
125  settings->value ("editor/show_white_space", false).toBool ());
126  ui->editor_ws_indent_checkbox->setChecked (
127  settings->value ("editor/show_white_space_indent",false).toBool ());
128  ui->editor_auto_ind_checkbox->setChecked (
129  settings->value ("editor/auto_indent", true).toBool ());
130  ui->editor_tab_ind_checkbox->setChecked (
131  settings->value ("editor/tab_indents_line",false).toBool ());
132  ui->editor_bs_unind_checkbox->setChecked (
133  settings->value ("editor/backspace_unindents_line",false).toBool ());
134  ui->editor_ind_guides_checkbox->setChecked (
135  settings->value ("editor/show_indent_guides",false).toBool ());
136  ui->editor_ind_width_spinbox->setValue (
137  settings->value ("editor/indent_width", 2).toInt ());
138  ui->editor_tab_width_spinbox->setValue (
139  settings->value ("editor/tab_width", 2).toInt ());
140  ui->editor_longWindowTitle->setChecked (
141  settings->value ("editor/longWindowTitle",false).toBool ());
142  ui->editor_restoreSession->setChecked (
143  settings->value ("editor/restoreSession", true).toBool ());
144  ui->editor_create_new_file->setChecked (
145  settings->value ("editor/create_new_file",false).toBool ());
146  ui->terminal_fontName->setCurrentFont (QFont (
147  settings->value ("terminal/fontName","Courier New").toString ()) );
148  ui->terminal_fontSize->setValue (
149  settings->value ("terminal/fontSize", 10).toInt ());
150  ui->showFileSize->setChecked (
151  settings->value ("filesdockwidget/showFileSize", false).toBool ());
152  ui->showFileType->setChecked (
153  settings->value ("filesdockwidget/showFileType", false).toBool ());
154  ui->showLastModified->setChecked (
155  settings->value ("filesdockwidget/showLastModified",false).toBool ());
156  ui->showHiddenFiles->setChecked (
157  settings->value ("filesdockwidget/showHiddenFiles",false).toBool ());
158  ui->useAlternatingRowColors->setChecked (
159  settings->value ("filesdockwidget/useAlternatingRowColors",true).toBool ());
160  ui->sync_octave_directory->setChecked (
161  settings->value ("filesdockwidget/sync_octave_directory",true).toBool ());
162  ui->checkbox_allow_web_connect->setChecked (
163  settings->value ("news/allow_web_connection",false).toBool ());
164  ui->useProxyServer->setChecked (
165  settings->value ("useProxyServer", false).toBool ());
166  ui->proxyHostName->setText (settings->value ("proxyHostName").toString ());
167  ui->terminal_cursorBlinking->setChecked (
168  settings->value ("terminal/cursorBlinking",true).toBool ());
169  ui->terminal_cursorUseForegroundColor->setChecked (
170  settings->value ("terminal/cursorUseForegroundColor",true).toBool ());
171 
172  QString cursorType
173  = settings->value ("terminal/cursorType", "ibeam").toString ();
174 
175  QStringList items;
176  items << QString ("0") << QString ("1") << QString ("2");
177  ui->terminal_cursorType->addItems (items);
178  ui->terminal_cursorType->setItemText (0, tr ("IBeam Cursor"));
179  ui->terminal_cursorType->setItemText (1, tr ("Block Cursor"));
180  ui->terminal_cursorType->setItemText (2, tr ("Underline Cursor"));
181 
182  if (cursorType == "ibeam")
183  ui->terminal_cursorType->setCurrentIndex (0);
184  else if (cursorType == "block")
185  ui->terminal_cursorType->setCurrentIndex (1);
186  else if (cursorType == "underline")
187  ui->terminal_cursorType->setCurrentIndex (2);
188 
189  int currentIndex = 0;
190  QString proxyTypeString = settings->value ("proxyType").toString ();
191  while ( (currentIndex < ui->proxyType->count ())
192  && (ui->proxyType->currentText () != proxyTypeString))
193  {
194  currentIndex++;
195  ui->proxyType->setCurrentIndex (currentIndex);
196  }
197 
198  ui->proxyPort->setText (settings->value ("proxyPort").toString ());
199  ui->proxyUserName->setText (settings->value ("proxyUserName").toString ());
200  ui->proxyPassword->setText (settings->value ("proxyPassword").toString ());
201 
202  // qorkspace colors
203  read_workspace_colors (settings);
204 
205  // terminal colors
206  read_terminal_colors (settings);
207 
208 #ifdef HAVE_QSCINTILLA
209  // editor styles: create lexer, read settings, and create dialog elements
210  QsciLexer *lexer;
211 #if defined (HAVE_LEXER_OCTAVE)
212  lexer = new QsciLexerOctave ();
213  read_lexer_settings (lexer,settings);
214  delete lexer;
215 #elif defined (HAVE_LEXER_MATLAB)
216  lexer = new QsciLexerMatlab ();
217  read_lexer_settings (lexer,settings);
218  delete lexer;
219 #endif
220  lexer = new QsciLexerCPP ();
221  read_lexer_settings (lexer,settings);
222  delete lexer;
223  lexer = new QsciLexerPerl ();
224  read_lexer_settings (lexer,settings);
225  delete lexer;
226  lexer = new QsciLexerBatch ();
227  read_lexer_settings (lexer,settings);
228  delete lexer;
229  lexer = new QsciLexerDiff ();
230  read_lexer_settings (lexer,settings);
231  delete lexer;
232  lexer = new QsciLexerBash ();
233  read_lexer_settings (lexer,settings);
234  delete lexer;
235 #endif
236 
237  // which tab is the desired one?
238  if (desired_tab.isEmpty ())
239  ui->tabWidget->setCurrentIndex (settings->value ("settings/last_tab",
240  0).toInt ());
241  else
242  {
243  QHash <QString, QWidget*> tab_hash;
244  tab_hash["editor"] = ui->tab_editor;
245  tab_hash["editor_styles"] = ui->tab_editor_styles;
246  ui->tabWidget->setCurrentIndex (
247  ui->tabWidget->indexOf (tab_hash.value (desired_tab)));
248  }
249 
250 
251 }
252 
254 {
255  delete ui;
256 }
257 
258 
259 #ifdef HAVE_QSCINTILLA
260 int
261 settings_dialog::get_valid_lexer_styles (QsciLexer *lexer, int styles[])
262 {
263  int max_style = 0;
264  int actual_style = 0;
265  while (actual_style < MaxStyleNumber && max_style < MaxLexerStyles)
266  {
267  if ((lexer->description (actual_style)) != "") // valid style
268  styles[max_style++] = actual_style;
269  actual_style++;
270  }
271  return max_style;
272 }
273 
274 void
275 settings_dialog::read_lexer_settings (QsciLexer *lexer, QSettings *settings)
276 {
277  lexer->readSettings (*settings);
278  int styles[MaxLexerStyles]; // array for saving valid styles
279  // (enum is not continuous)
280  int max_style = get_valid_lexer_styles (lexer, styles);
281  QGridLayout *style_grid = new QGridLayout ();
282  QVector<QLabel*> description (max_style);
283  QVector<QFontComboBox*> select_font (max_style);
284  QVector<QSpinBox*> font_size (max_style);
285  QVector<QCheckBox*> attrib_font (3 * max_style);
286  QVector<color_picker*> color (max_style);
287  QVector<color_picker*> bg_color (max_style);
288  int default_size = 10;
289  QFont default_font = QFont ();
290  QColor default_color = QColor ();
291  QColor dummy_color = QColor (255,0,255);
292 
293  for (int i = 0; i < max_style; i++) // create dialog elements for all styles
294  {
295  QString actual_name = lexer->description (styles[i]);
296  QFont actual_font = lexer->font (styles[i]);
297  description[i] = new QLabel (actual_name);
298  description[i]->setWordWrap (true);
299  description[i]->setMaximumSize (160,QWIDGETSIZE_MAX);
300  description[i]->setMinimumSize (160,1);
301  select_font[i] = new QFontComboBox ();
302  select_font[i]->setObjectName (actual_name+"_font");
303  select_font[i]->setMaximumSize (180,QWIDGETSIZE_MAX);
304  select_font[i]->setMinimumSize (180,1);
305  font_size[i] = new QSpinBox ();
306  font_size[i]->setObjectName (actual_name+"_size");
307  if (styles[i] == 0) // the default
308  {
309  select_font[i]->setCurrentFont (actual_font);
310  default_font = actual_font;
311  font_size[i]->setRange (6,24);
312  default_size = actual_font.pointSize ();
313  font_size[i]->setValue (default_size);
314  default_color = lexer->defaultPaper ();
315  bg_color[i] = new color_picker (default_color);
316  }
317  else // other styles
318  {
319  select_font[i]->setCurrentFont (actual_font);
320  if (actual_font.family () == default_font.family ())
321  select_font[i]->setEditText (lexer->description (0));
322  font_size[i]->setRange (-4,4);
323  font_size[i]->setValue (actual_font.pointSize ()-default_size);
324  font_size[i]->setToolTip (tr ("Difference to the default size"));
325  if (lexer->paper (styles[i]) == default_color)
326  bg_color[i] = new color_picker (dummy_color);
327  else
328  bg_color[i] = new color_picker (lexer->paper (styles[i]));
329  bg_color[i]->setToolTip
330  (tr ("Background color, pink (255,0,255) means default"));
331  }
332  attrib_font[0+3*i] = new QCheckBox (tr ("b"));
333  attrib_font[1+3*i] = new QCheckBox (tr ("i"));
334  attrib_font[2+3*i] = new QCheckBox (tr ("u"));
335  attrib_font[0+3*i]->setChecked (Qt::Checked && actual_font.bold ());
336  attrib_font[0+3*i]->setObjectName (actual_name+"_bold");
337  attrib_font[1+3*i]->setChecked (Qt::Checked && actual_font.italic ());
338  attrib_font[1+3*i]->setObjectName (actual_name+"_italic");
339  attrib_font[2+3*i]->setChecked (Qt::Checked && actual_font.underline ());
340  attrib_font[2+3*i]->setObjectName (actual_name+"_underline");
341  color[i] = new color_picker (lexer->color (styles[i]));
342  color[i]->setObjectName (actual_name+"_color");
343  bg_color[i]->setObjectName (actual_name+"_bg_color");
344  int column = 1;
345  style_grid->addWidget (description[i], i, column++);
346  style_grid->addWidget (select_font[i], i, column++);
347  style_grid->addWidget (font_size[i], i, column++);
348  style_grid->addWidget (attrib_font[0+3*i], i, column++);
349  style_grid->addWidget (attrib_font[1+3*i], i, column++);
350  style_grid->addWidget (attrib_font[2+3*i], i, column++);
351  style_grid->addWidget (color[i], i, column++);
352  style_grid->addWidget (bg_color[i], i, column++);
353  }
354  // place grid with elements into the tab
355  QScrollArea *scroll_area = new QScrollArea ();
356  QWidget *scroll_area_contents = new QWidget ();
357  scroll_area_contents->setObjectName (QString (lexer->language ())+"_styles");
358  scroll_area_contents->setLayout (style_grid);
359  scroll_area->setWidget (scroll_area_contents);
360  ui->tabs_editor_lexers->addTab (scroll_area,lexer->language ());
361 
362  ui->tabs_editor_lexers->setCurrentIndex (
363  settings->value ("settings/last_editor_styles_tab",0).toInt ());
364 }
365 #endif
366 
367 void
369 {
370 
371  QList<QColor> default_colors =
373  QStringList class_names = resource_manager::storage_class_names ();
374  QString class_chars = resource_manager::storage_class_chars ();
375  int nr_of_classes = class_chars.length ();
376 
377  QGridLayout *style_grid = new QGridLayout ();
378  QVector<QLabel*> description (nr_of_classes);
379  QVector<color_picker*> color (nr_of_classes);
380 
381  int column = 0;
382  int row = 0;
383  for (int i = 0; i < nr_of_classes; i++)
384  {
385  description[i] = new QLabel (" " + class_names.at (i));
386  description[i]->setAlignment (Qt::AlignRight);
387  QVariant default_var = default_colors.at (i);
388  QColor setting_color = settings->value ("workspaceview/color_"
389  + class_chars.mid (i,1),
390  default_var).value<QColor> ();
391  color[i] = new color_picker (setting_color);
392  color[i]->setObjectName ("color_"+class_chars.mid (i, 1));
393  color[i]->setMinimumSize (30, 10);
394  style_grid->addWidget (description[i], row, 3*column);
395  style_grid->addWidget (color[i], row, 3*column+1);
396  if (++column == 3)
397  {
398  style_grid->setColumnStretch (4*column, 10);
399  row++;
400  column = 0;
401  }
402  }
403 
404  // place grid with elements into the tab
405  ui->workspace_colors_box->setLayout (style_grid);
406 }
407 
408 void
410 {
411 
413  QStringList class_names = resource_manager::terminal_color_names ();
414  QString class_chars = resource_manager::terminal_color_chars ();
415  int nr_of_classes = class_chars.length ();
416 
417  QGridLayout *style_grid = new QGridLayout ();
418  QVector<QLabel*> description (nr_of_classes);
419  QVector<color_picker*> color (nr_of_classes);
420 
421  int column = 0;
422  int row = 0;
423  for (int i = 0; i < nr_of_classes; i++)
424  {
425  description[i] = new QLabel (" " + class_names.at (i));
426  description[i]->setAlignment (Qt::AlignRight);
427  QVariant default_var = default_colors.at (i);
428  QColor setting_color = settings->value ("terminal/color_"
429  + class_chars.mid (i,1),
430  default_var).value<QColor> ();
431  color[i] = new color_picker (setting_color);
432  color[i]->setObjectName ("terminal_color_"+class_chars.mid (i, 1));
433  color[i]->setMinimumSize (30, 10);
434  style_grid->addWidget (description[i], row, 2*column);
435  style_grid->addWidget (color[i], row, 2*column+1);
436  if (++column == 2)
437  {
438  style_grid->setColumnStretch (3*column, 10);
439  row++;
440  column = 0;
441  }
442  }
443 
444  // place grid with elements into the tab
445  ui->terminal_colors_box->setLayout (style_grid);
446 }
447 
448 void
450 {
451  QSettings *settings = resource_manager::get_settings ();
452  // FIXME: what should happen if settings is 0?
453 
454  // the icon set
455  QString widget_icon_set = "NONE";
456  if (ui->general_icon_letter->isChecked ())
457  widget_icon_set = "LETTER";
458  else if (ui->general_icon_graphic->isChecked ())
459  widget_icon_set = "GRAPHIC";
460  settings->setValue ("DockWidgets/widget_icon_set",widget_icon_set);
461 
462  // language
463  QString language = ui->comboBox_language->currentText ();
464  if (language == tr ("System setting"))
465  language = "SYSTEM";
466  settings->setValue ("language", language);
467 
468  // other settings
469  settings->setValue ("toolbar_icon_size", ui->toolbar_icon_size->value ());
470  settings->setValue ("useCustomFileEditor",
471  ui->useCustomFileEditor->isChecked ());
472  settings->setValue ("customFileEditor", ui->customFileEditor->text ());
473  settings->setValue ("editor/showLineNumbers",
474  ui->editor_showLineNumbers->isChecked ());
475  settings->setValue ("editor/highlightCurrentLine",
476  ui->editor_highlightCurrentLine->isChecked ());
477  settings->setValue ("editor/highlight_current_line_color",
479  settings->setValue ("editor/codeCompletion",
480  ui->editor_codeCompletion->isChecked ());
481  settings->setValue ("editor/codeCompletion_threshold",
482  ui->editor_spinbox_ac_threshold->value ());
483  settings->setValue ("editor/codeCompletion_keywords",
484  ui->editor_checkbox_ac_keywords->isChecked ());
485  settings->setValue ("editor/codeCompletion_document",
486  ui->editor_checkbox_ac_document->isChecked ());
487  settings->setValue ("editor/codeCompletion_case",
488  ui->editor_checkbox_ac_case->isChecked ());
489  settings->setValue ("editor/codeCompletion_replace",
490  ui->editor_checkbox_ac_replace->isChecked ());
491  settings->setValue ("editor/show_white_space",
492  ui->editor_ws_checkbox->isChecked ());
493  settings->setValue ("editor/show_white_space_indent",
494  ui->editor_ws_indent_checkbox->isChecked ());
495  settings->setValue ("editor/auto_indent",
496  ui->editor_auto_ind_checkbox->isChecked ());
497  settings->setValue ("editor/tab_indents_line",
498  ui->editor_tab_ind_checkbox->isChecked ());
499  settings->setValue ("editor/backspace_unindents_line",
500  ui->editor_bs_unind_checkbox->isChecked ());
501  settings->setValue ("editor/show_indent_guides",
502  ui->editor_ind_guides_checkbox->isChecked ());
503  settings->setValue ("editor/indent_width",
504  ui->editor_ind_width_spinbox->value ());
505  settings->setValue ("editor/tab_width",
506  ui->editor_tab_width_spinbox->value ());
507  settings->setValue ("editor/longWindowTitle",
508  ui->editor_longWindowTitle->isChecked ());
509  settings->setValue ("editor/restoreSession",
510  ui->editor_restoreSession->isChecked ());
511  settings->setValue ("editor/create_new_file",
512  ui->editor_create_new_file->isChecked ());
513  settings->setValue ("terminal/fontSize", ui->terminal_fontSize->value ());
514  settings->setValue ("terminal/fontName",
515  ui->terminal_fontName->currentFont ().family ());
516  settings->setValue ("filesdockwidget/showFileSize",
517  ui->showFileSize->isChecked ());
518  settings->setValue ("filesdockwidget/showFileType",
519  ui->showFileType->isChecked ());
520  settings->setValue ("filesdockwidget/showLastModified",
521  ui->showLastModified->isChecked ());
522  settings->setValue ("filesdockwidget/showHiddenFiles",
523  ui->showHiddenFiles->isChecked ());
524  settings->setValue ("filesdockwidget/useAlternatingRowColors",
525  ui->useAlternatingRowColors->isChecked ());
526  settings->setValue ("filesdockwidget/sync_octave_directory",
527  ui->sync_octave_directory->isChecked ());
528  settings->setValue ("news/allow_web_connection",
529  ui->checkbox_allow_web_connect->isChecked ());
530  settings->setValue ("useProxyServer", ui->useProxyServer->isChecked ());
531  settings->setValue ("proxyType", ui->proxyType->currentText ());
532  settings->setValue ("proxyHostName", ui->proxyHostName->text ());
533  settings->setValue ("proxyPort", ui->proxyPort->text ());
534  settings->setValue ("proxyUserName", ui->proxyUserName->text ());
535  settings->setValue ("proxyPassword", ui->proxyPassword->text ());
536  settings->setValue ("terminal/cursorBlinking",
537  ui->terminal_cursorBlinking->isChecked ());
538  settings->setValue ("terminal/cursorUseForegroundColor",
539  ui->terminal_cursorUseForegroundColor->isChecked ());
540 
541  // the cursor
542  QString cursorType;
543  switch (ui->terminal_cursorType->currentIndex ())
544  {
545  case 0: cursorType = "ibeam"; break;
546  case 1: cursorType = "block"; break;
547  case 2: cursorType = "underline"; break;
548  }
549  settings->setValue ("terminal/cursorType", cursorType);
550  settings->sync ();
551 
552 #ifdef HAVE_QSCINTILLA
553  // editor styles: create lexer, get dialog contents, and write settings
554  QsciLexer *lexer;
555 #if defined (HAVE_LEXER_OCTAVE)
556  lexer = new QsciLexerOctave ();
557  write_lexer_settings (lexer,settings);
558  delete lexer;
559 #elif defined (HAVE_LEXER_MATLAB)
560  lexer = new QsciLexerMatlab ();
561  write_lexer_settings (lexer,settings);
562  delete lexer;
563 #endif
564  lexer = new QsciLexerCPP ();
565  write_lexer_settings (lexer,settings);
566  delete lexer;
567  lexer = new QsciLexerPerl ();
568  write_lexer_settings (lexer,settings);
569  delete lexer;
570  lexer = new QsciLexerBatch ();
571  write_lexer_settings (lexer,settings);
572  delete lexer;
573  lexer = new QsciLexerDiff ();
574  write_lexer_settings (lexer,settings);
575  delete lexer;
576  lexer = new QsciLexerBash ();
577  write_lexer_settings (lexer,settings);
578  delete lexer;
579 #endif
580 
581  write_workspace_colors (settings);
582 
583  write_terminal_colors (settings);
584 
585  settings->setValue ("settings/last_tab",ui->tabWidget->currentIndex ());
586 }
587 
588 #ifdef HAVE_QSCINTILLA
589 void
590 settings_dialog::write_lexer_settings (QsciLexer *lexer, QSettings *settings)
591 {
592  QWidget *tab = ui->tabs_editor_lexers->
593  findChild <QWidget *>(QString (lexer->language ())+"_styles");
594  int styles[MaxLexerStyles]; // array for saving valid styles
595  // (enum is not continuous)
596  int max_style = get_valid_lexer_styles (lexer, styles);
597  QFontComboBox *select_font;
598  QSpinBox *font_size;
599  QCheckBox *attrib_font[3];
600  color_picker *color;
601  color_picker *bg_color;
602  int default_size = 10;
603  QFont default_font = QFont ("Courier New",10,-1,0);
604  QColor default_color = QColor ();
605  QColor dummy_color = QColor (255,0,255);
606 
607  for (int i = 0; i < max_style; i++) // get dialog elements and their contents
608  {
609  QString actual_name = lexer->description (styles[i]);
610  select_font = tab->findChild <QFontComboBox *>(actual_name+"_font");
611  font_size = tab->findChild <QSpinBox *>(actual_name+"_size");
612  attrib_font[0] = tab->findChild <QCheckBox *>(actual_name+"_bold");
613  attrib_font[1] = tab->findChild <QCheckBox *>(actual_name+"_italic");
614  attrib_font[2] = tab->findChild <QCheckBox *>(actual_name+"_underline");
615  color = tab->findChild <color_picker *>(actual_name+"_color");
616  bg_color = tab->findChild <color_picker *>(actual_name+"_bg_color");
617  QFont new_font = default_font;
618  if (select_font)
619  {
620  new_font = select_font->currentFont ();
621  if (styles[i] == 0)
622  default_font = new_font;
623  else if (select_font->currentText () == lexer->description (0))
624  new_font = default_font;
625  }
626  if (font_size)
627  {
628  if (styles[i] == 0)
629  {
630  default_size = font_size->value ();
631  new_font.setPointSize (font_size->value ());
632  }
633  else
634  new_font.setPointSize (font_size->value ()+default_size);
635  }
636  if (attrib_font[0])
637  new_font.setBold (attrib_font[0]->isChecked ());
638  if (attrib_font[1])
639  new_font.setItalic (attrib_font[1]->isChecked ());
640  if (attrib_font[2])
641  new_font.setUnderline (attrib_font[2]->isChecked ());
642  lexer->setFont (new_font,styles[i]);
643  if (styles[i] == 0)
644  lexer->setDefaultFont (new_font);
645  if (color)
646  lexer->setColor (color->color (),styles[i]);
647  if (bg_color)
648  {
649  if (styles[i] == 0)
650  {
651  default_color = bg_color->color ();
652  lexer->setPaper (default_color,styles[i]);
653  lexer->setDefaultPaper (default_color);
654  }
655  else
656  {
657  if (bg_color->color () == dummy_color)
658  lexer->setPaper (default_color,styles[i]);
659  else
660  lexer->setPaper (bg_color->color (),styles[i]);
661  }
662  }
663  }
664 
665  lexer->writeSettings (*settings);
666 
667  settings->setValue (
668  "settings/last_editor_styles_tab",ui->tabs_editor_lexers->currentIndex ());
669 }
670 #endif
671 
672 void
674 {
675 
676  QString class_chars = resource_manager::storage_class_chars ();
677  color_picker *color;
678 
679  for (int i = 0; i < class_chars.length (); i++)
680  {
681  color = ui->workspace_colors_box->findChild <color_picker *>(
682  "color_"+class_chars.mid (i,1));
683  if (color)
684  settings->setValue ("workspaceview/color_"+class_chars.mid (i,1),
685  color->color ());
686  }
687  settings->sync ();
688 }
689 
690 void
692 {
693  QString class_chars = resource_manager::terminal_color_chars ();
694  color_picker *color;
695 
696  for (int i = 0; i < class_chars.length (); i++)
697  {
698  color = ui->terminal_colors_box->findChild <color_picker *>(
699  "terminal_color_"+class_chars.mid (i,1));
700  if (color)
701  settings->setValue ("terminal/color_"+class_chars.mid (i,1),
702  color->color ());
703  }
704  settings->sync ();
705 }