30 #include "ui-settings-dialog.h"
36 #ifdef HAVE_QSCINTILLA
37 #include <QScrollArea>
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>
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>
64 QDir qm_dir (qm_dir_name);
65 QFileInfoList qm_files = qm_dir.entryInfoList (QStringList (
"*.qm"),
66 QDir::Files | QDir::Readable,
68 for (
int i = 0; i < qm_files.length (); i++)
69 ui->comboBox_language->addItem (qm_files.at (i).baseName ());
71 ui->comboBox_language->insertItem (0,tr (
"System setting"));
72 ui->comboBox_language->insertSeparator (1);
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);
78 ui->comboBox_language->setCurrentIndex (selected);
80 ui->comboBox_language->setCurrentIndex (0);
82 ui->toolbar_icon_size->setValue (settings->value (
"toolbar_icon_size",
86 QString widget_icon_set =
87 settings->value (
"DockWidgets/widget_icon_set",
"NONE").toString ();
88 ui->general_icon_octave-> setChecked (
true);
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");
93 ui->useCustomFileEditor->setChecked (settings->value (
"useCustomFileEditor",
95 ui->customFileEditor->setText (
96 settings->value (
"customFileEditor").toString ());
97 ui->editor_showLineNumbers->setChecked (
98 settings->value (
"editor/showLineNumbers",
true).toBool () );
100 QVariant default_var = QColor (240, 240, 240);
101 QColor setting_color = settings->value (
"editor/highlight_current_line_color",
102 default_var).value<QColor> ();
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 () );
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 ());
173 = settings->value (
"terminal/cursorType",
"ibeam").toString ();
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"));
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);
189 int currentIndex = 0;
190 QString proxyTypeString = settings->value (
"proxyType").toString ();
191 while ( (currentIndex < ui->proxyType->count ())
192 && (
ui->proxyType->currentText () != proxyTypeString))
195 ui->proxyType->setCurrentIndex (currentIndex);
198 ui->proxyPort->setText (settings->value (
"proxyPort").toString ());
199 ui->proxyUserName->setText (settings->value (
"proxyUserName").toString ());
200 ui->proxyPassword->setText (settings->value (
"proxyPassword").toString ());
208 #ifdef HAVE_QSCINTILLA
211 #if defined (HAVE_LEXER_OCTAVE)
212 lexer =
new QsciLexerOctave ();
213 read_lexer_settings (lexer,settings);
215 #elif defined (HAVE_LEXER_MATLAB)
216 lexer =
new QsciLexerMatlab ();
217 read_lexer_settings (lexer,settings);
220 lexer =
new QsciLexerCPP ();
221 read_lexer_settings (lexer,settings);
223 lexer =
new QsciLexerPerl ();
224 read_lexer_settings (lexer,settings);
226 lexer =
new QsciLexerBatch ();
227 read_lexer_settings (lexer,settings);
229 lexer =
new QsciLexerDiff ();
230 read_lexer_settings (lexer,settings);
232 lexer =
new QsciLexerBash ();
233 read_lexer_settings (lexer,settings);
238 if (desired_tab.isEmpty ())
239 ui->tabWidget->setCurrentIndex (settings->value (
"settings/last_tab",
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)));
259 #ifdef HAVE_QSCINTILLA
261 settings_dialog::get_valid_lexer_styles (QsciLexer *
lexer,
int styles[])
264 int actual_style = 0;
265 while (actual_style < MaxStyleNumber && max_style < MaxLexerStyles)
267 if ((lexer->description (actual_style)) !=
"")
268 styles[max_style++] = actual_style;
275 settings_dialog::read_lexer_settings (QsciLexer *lexer, QSettings *settings)
277 lexer->readSettings (*settings);
278 int styles[MaxLexerStyles];
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);
293 for (
int i = 0; i < max_style; i++)
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");
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 ();
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)
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"));
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");
342 color[i]->setObjectName (actual_name+
"_color");
343 bg_color[i]->setObjectName (actual_name+
"_bg_color");
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++);
355 QScrollArea *scroll_area =
new QScrollArea ();
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 ());
362 ui->tabs_editor_lexers->setCurrentIndex (
363 settings->value (
"settings/last_editor_styles_tab",0).toInt ());
375 int nr_of_classes = class_chars.length ();
377 QGridLayout *style_grid =
new QGridLayout ();
378 QVector<QLabel*> description (nr_of_classes);
379 QVector<color_picker*> color (nr_of_classes);
383 for (
int i = 0; i < nr_of_classes; i++)
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> ();
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);
398 style_grid->setColumnStretch (4*column, 10);
405 ui->workspace_colors_box->setLayout (style_grid);
415 int nr_of_classes = class_chars.length ();
417 QGridLayout *style_grid =
new QGridLayout ();
418 QVector<QLabel*> description (nr_of_classes);
419 QVector<color_picker*> color (nr_of_classes);
423 for (
int i = 0; i < nr_of_classes; i++)
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> ();
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);
438 style_grid->setColumnStretch (3*column, 10);
445 ui->terminal_colors_box->setLayout (style_grid);
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);
463 QString language =
ui->comboBox_language->currentText ();
464 if (language == tr (
"System setting"))
466 settings->setValue (
"language", language);
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 ());
543 switch (
ui->terminal_cursorType->currentIndex ())
545 case 0: cursorType =
"ibeam";
break;
546 case 1: cursorType =
"block";
break;
547 case 2: cursorType =
"underline";
break;
549 settings->setValue (
"terminal/cursorType", cursorType);
552 #ifdef HAVE_QSCINTILLA
555 #if defined (HAVE_LEXER_OCTAVE)
556 lexer =
new QsciLexerOctave ();
557 write_lexer_settings (lexer,settings);
559 #elif defined (HAVE_LEXER_MATLAB)
560 lexer =
new QsciLexerMatlab ();
561 write_lexer_settings (lexer,settings);
564 lexer =
new QsciLexerCPP ();
565 write_lexer_settings (lexer,settings);
567 lexer =
new QsciLexerPerl ();
568 write_lexer_settings (lexer,settings);
570 lexer =
new QsciLexerBatch ();
571 write_lexer_settings (lexer,settings);
573 lexer =
new QsciLexerDiff ();
574 write_lexer_settings (lexer,settings);
576 lexer =
new QsciLexerBash ();
577 write_lexer_settings (lexer,settings);
585 settings->setValue (
"settings/last_tab",
ui->tabWidget->currentIndex ());
588 #ifdef HAVE_QSCINTILLA
590 settings_dialog::write_lexer_settings (QsciLexer *lexer, QSettings *settings)
593 findChild <QWidget *>(QString (lexer->language ())+
"_styles");
594 int styles[MaxLexerStyles];
596 int max_style = get_valid_lexer_styles (lexer, styles);
597 QFontComboBox *select_font;
599 QCheckBox *attrib_font[3];
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);
607 for (
int i = 0; i < max_style; i++)
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;
620 new_font = select_font->currentFont ();
622 default_font = new_font;
623 else if (select_font->currentText () == lexer->description (0))
624 new_font = default_font;
630 default_size = font_size->value ();
631 new_font.setPointSize (font_size->value ());
634 new_font.setPointSize (font_size->value ()+default_size);
637 new_font.setBold (attrib_font[0]->isChecked ());
639 new_font.setItalic (attrib_font[1]->isChecked ());
641 new_font.setUnderline (attrib_font[2]->isChecked ());
642 lexer->setFont (new_font,styles[i]);
644 lexer->setDefaultFont (new_font);
646 lexer->setColor (color->color (),styles[i]);
651 default_color = bg_color->
color ();
652 lexer->setPaper (default_color,styles[i]);
653 lexer->setDefaultPaper (default_color);
657 if (bg_color->
color () == dummy_color)
658 lexer->setPaper (default_color,styles[i]);
660 lexer->setPaper (bg_color->
color (),styles[i]);
665 lexer->writeSettings (*settings);
668 "settings/last_editor_styles_tab",
ui->tabs_editor_lexers->currentIndex ());
679 for (
int i = 0; i < class_chars.length (); i++)
682 "color_"+class_chars.mid (i,1));
684 settings->setValue (
"workspaceview/color_"+class_chars.mid (i,1),
696 for (
int i = 0; i < class_chars.length (); i++)
699 "terminal_color_"+class_chars.mid (i,1));
701 settings->setValue (
"terminal/color_"+class_chars.mid (i,1),