3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
14 #pragma implementation
17 #include "support/lstrings.h"
19 #include "ControlPrefs.h"
20 #include "QPrefsDialog.h"
21 #include "ui/QPrefAsciiModule.h"
22 #include "ui/QPrefDateModule.h"
23 #include "ui/QPrefKeyboardModule.h"
24 #include "ui/QPrefLatexModule.h"
25 #include "ui/QPrefScreenFontsModule.h"
26 #include "ui/QPrefColorsModule.h"
27 #include "ui/QPrefDisplayModule.h"
28 #include "ui/QPrefPathsModule.h"
29 #include "ui/QPrefSpellcheckerModule.h"
30 #include "ui/QPrefConvertersModule.h"
31 #include "ui/QPrefFileformatsModule.h"
32 #include "ui/QPrefLanguageModule.h"
33 #include "ui/QPrefPrinterModule.h"
34 #include "ui/QPrefUIModule.h"
39 #include <qpushbutton.h>
40 #include <qcheckbox.h>
41 #include <qlineedit.h>
44 typedef Qt2CB<ControlPrefs, Qt2DB<QPrefsDialog> > base_class;
48 : base_class(_("LyX: Preferences"))
53 void QPrefs::build_dialog()
55 dialog_.reset(new QPrefsDialog(this));
57 bc().setOK(dialog_->savePB);
58 bc().setApply(dialog_->applyPB);
59 bc().setCancel(dialog_->closePB);
60 bc().setRestore(dialog_->restorePB);
66 LyXRC & rc(controller().rc());
71 bool modifiedText = false;
72 bool modifiedBackground = false;
74 // Now do the same for the LyX LColors...
75 for (vector<NamedColor>::const_iterator cit = lyxColorDB.begin();
76 cit != lyxColorDB.end(); ++cit) {
77 LColor::color lc = lcolor.getFromGUIName(cit->getname());
78 if (lc == LColor::inherit) continue;
80 // Create a valid X11 name of the form "#rrggbb"
81 string const hexname = X11hexname(cit->color());
83 if (lcolor.getX11Name(lc) != hexname) {
85 << "FormPreferences::Colors::apply: "
86 << "resetting LColor " << lcolor.getGUIName(lc)
87 << " from \"" << lcolor.getX11Name(lc)
88 << "\" to \"" << hexname << "\"."
91 parent_.controller().setColor(lc, hexname);
96 parent_.controller().setConverters(local_converters);
98 parent_.controller().setFormats(local_formats);
100 rc.date_insert_format =
101 fl_get_input(dialog_->input_date_format);
103 rc.popup_normal_font =
104 fl_get_input(dialog_->input_popup_normal_font);
105 rc.popup_bold_font = fl_get_input(dialog_->input_popup_bold_font);
106 rc.popup_font_encoding =
107 fl_get_input(dialog_->input_popup_font_encoding);
108 rc.bind_file = fl_get_input(dialog_->input_bind_file);
109 rc.ui_file = fl_get_input(dialog_->input_ui_file);
110 rc.override_x_deadkeys =
111 fl_get_button(dialog_->check_override_x_dead_keys);
113 int const pos = combo_default_lang->get();
114 rc.default_language = lang_[pos-1];
116 int button = fl_get_button(dialog_->check_use_kbmap);
117 string const name_1 = fl_get_input(dialog_->input_kbmap1);
118 string const name_2 = fl_get_input(dialog_->input_kbmap2);
120 button = !(name_1.empty() && name_2.empty());
121 rc.use_kbmap = static_cast<bool>(button);
124 rc.primary_kbmap = name_1;
125 rc.secondary_kbmap = name_2;
128 button = fl_get_button(dialog_->check_rtl_support);
129 rc.rtl_support = static_cast<bool>(button);
131 button = fl_get_button(dialog_->check_mark_foreign);
132 rc.mark_foreign_language = static_cast<bool>(button);
134 button = fl_get_button(dialog_->check_auto_begin);
135 rc.language_auto_begin = static_cast<bool>(button);
137 button = fl_get_button(dialog_->check_auto_end);
138 rc.language_auto_end = static_cast<bool>(button);
140 button = fl_get_button(dialog_->check_use_babel);
141 rc.language_use_babel = static_cast<bool>(button);
143 button = fl_get_button(dialog_->check_global_options);
144 rc.language_global_options = static_cast<bool>(button);
146 rc.language_package = fl_get_input(dialog_->input_package);
147 rc.language_command_begin = fl_get_input(dialog_->input_command_begin);
148 rc.language_command_end = fl_get_input(dialog_->input_command_end);
150 // Ensure that all is self-consistent.
154 rc.auto_region_delete =
155 fl_get_button(dialog_->check_auto_region_delete);
156 rc.cursor_follows_scrollbar =
157 fl_get_button(dialog_->check_cursor_follows_scrollbar);
158 rc.dialogs_iconify_with_main =
159 fl_get_button(dialog_->check_dialogs_iconify_with_main);
160 rc.preview = fl_get_button(dialog_->check_preview_latex);
161 rc.autosave = static_cast<unsigned int>
162 (fl_get_counter_value(dialog_->counter_autosave));
163 rc.wheel_jump = static_cast<unsigned int>
164 (fl_get_counter_value(dialog_->counter_wm_jump));
167 // grfx::DisplayType old_value = rc.display_graphics;
168 switch (fl_get_choice(dialog_->choice_display)) {
169 case 4: rc.display_graphics = grfx::NoDisplay; break;
170 case 3: rc.display_graphics = grfx::ColorDisplay; break;
171 case 2: rc.display_graphics = grfx::GrayscaleDisplay; break;
172 case 1: rc.display_graphics = grfx::MonochromeDisplay; break;
173 default: rc.display_graphics = grfx::ColorDisplay; break;
177 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
180 if (old_value != rc.display_graphics) {
181 grfx::GCache & gc = grfx::GCache::get();
188 rc.ascii_linelen = static_cast<unsigned int>
189 (fl_get_counter_value(dialog_->counter_line_len));
190 rc.fontenc = fl_get_input(dialog_->input_tex_encoding);
193 fl_get_choice(dialog_->choice_default_papersize) - 1;
194 rc.default_papersize = static_cast<BufferParams::PAPER_SIZE>(choice);
196 rc.ascii_roff_command = fl_get_input(dialog_->input_ascii_roff);
197 rc.chktex_command = fl_get_input(dialog_->input_checktex);
198 rc.view_dvi_paper_option = fl_get_input(dialog_->input_paperoption);
199 rc.auto_reset_options = fl_get_button(dialog_->check_autoreset_classopt);
203 rc.document_path = fl_get_input(dialog_->input_default_path);
204 rc.template_path = fl_get_input(dialog_->input_template_path);
206 int button = fl_get_button(dialog_->check_use_temp_dir);
207 string str = fl_get_input(dialog_->input_temp_dir);
211 rc.use_tempdir = button;
212 rc.tempdir_path = str;
214 button = fl_get_button(dialog_->check_last_files);
215 str = fl_get_input(dialog_->input_lastfiles);
216 if (!button) str.erase();
218 rc.check_lastfiles = button;
220 rc.num_lastfiles = static_cast<unsigned int>
221 (fl_get_counter_value(dialog_->counter_lastfiles));
223 button = fl_get_button(dialog_->check_make_backups);
224 str = fl_get_input(dialog_->input_backup_path);
228 rc.make_backup = button;
229 rc.backupdir_path = str;
231 rc.lyxpipes = fl_get_input(dialog_->input_serverpipe);
237 rc.print_adapt_output = fl_get_button(dialog_->check_adapt_output);
238 rc.print_command = fl_get_input(dialog_->input_command);
239 rc.print_pagerange_flag = fl_get_input(dialog_->input_page_range);
240 rc.print_copies_flag = fl_get_input(dialog_->input_copies);
241 rc.print_reverse_flag = fl_get_input(dialog_->input_reverse);
242 rc.print_to_printer = fl_get_input(dialog_->input_to_printer);
243 rc.print_file_extension =
244 fl_get_input(dialog_->input_file_extension);
245 rc.print_spool_command =
246 fl_get_input(dialog_->input_spool_command);
247 rc.print_paper_flag = fl_get_input(dialog_->input_paper_type);
248 rc.print_evenpage_flag = fl_get_input(dialog_->input_even_pages);
249 rc.print_oddpage_flag = fl_get_input(dialog_->input_odd_pages);
250 rc.print_collcopies_flag = fl_get_input(dialog_->input_collated);
251 rc.print_landscape_flag = fl_get_input(dialog_->input_landscape);
252 rc.print_to_file = fl_get_input(dialog_->input_to_file);
253 rc.print_extra_options =
254 fl_get_input(dialog_->input_extra_options);
255 rc.print_spool_printerprefix =
256 fl_get_input(dialog_->input_spool_prefix);
257 rc.print_paper_dimension_flag =
258 fl_get_input(dialog_->input_paper_size);
259 rc.printer = fl_get_input(dialog_->input_name);
263 bool changed = false;
265 string str = fl_get_input(dialog_->input_roman);
266 if (rc.roman_font_name != str) {
268 rc.roman_font_name = str;
271 str = fl_get_input(dialog_->input_sans);
272 if (rc.sans_font_name != str) {
274 rc.sans_font_name = str;
277 str = fl_get_input(dialog_->input_typewriter);
278 if (rc.typewriter_font_name != str) {
280 rc.typewriter_font_name = str;
283 str = fl_get_input(dialog_->input_screen_encoding);
284 if (rc.font_norm != str) {
289 bool button = fl_get_button(dialog_->check_scalable);
290 if (rc.use_scalable_fonts != button) {
292 rc.use_scalable_fonts = button;
295 unsigned int ivalue = static_cast<unsigned int>
296 (fl_get_counter_value(dialog_->counter_zoom));
297 if (rc.zoom != ivalue) {
302 ivalue = static_cast<unsigned int>
303 (fl_get_counter_value(dialog_->counter_dpi));
304 if (rc.dpi != ivalue) {
309 double dvalue = strToDbl(fl_get_input(dialog_->input_tiny));
310 if (rc.font_sizes[LyXFont::SIZE_TINY] != dvalue) {
312 rc.font_sizes[LyXFont::SIZE_TINY] = dvalue;
315 dvalue = strToDbl(fl_get_input(dialog_->input_script));
316 if (rc.font_sizes[LyXFont::SIZE_SCRIPT] != dvalue) {
318 rc.font_sizes[LyXFont::SIZE_SCRIPT] = dvalue;
321 dvalue = strToDbl(fl_get_input(dialog_->input_footnote));
322 if (rc.font_sizes[LyXFont::SIZE_FOOTNOTE] != dvalue) {
324 rc.font_sizes[LyXFont::SIZE_FOOTNOTE] = dvalue;
327 dvalue = strToDbl(fl_get_input(dialog_->input_small));
328 if (rc.font_sizes[LyXFont::SIZE_SMALL] != dvalue) {
330 rc.font_sizes[LyXFont::SIZE_SMALL] = dvalue;
333 dvalue = strToDbl(fl_get_input(dialog_->input_normal));
334 if (rc.font_sizes[LyXFont::SIZE_NORMAL] != dvalue) {
336 rc.font_sizes[LyXFont::SIZE_NORMAL] = dvalue;
339 dvalue = strToDbl(fl_get_input(dialog_->input_large));
340 if (rc.font_sizes[LyXFont::SIZE_LARGE] != dvalue) {
342 rc.font_sizes[LyXFont::SIZE_LARGE] = dvalue;
345 dvalue = strToDbl(fl_get_input(dialog_->input_larger));
346 if (rc.font_sizes[LyXFont::SIZE_LARGER] != dvalue) {
348 rc.font_sizes[LyXFont::SIZE_LARGER] = dvalue;
351 dvalue = strToDbl(fl_get_input(dialog_->input_largest));
352 if (rc.font_sizes[LyXFont::SIZE_LARGEST] != dvalue) {
354 rc.font_sizes[LyXFont::SIZE_LARGEST] = dvalue;
357 dvalue = strToDbl(fl_get_input(dialog_->input_huge));
358 if (rc.font_sizes[LyXFont::SIZE_HUGE] != dvalue) {
360 rc.font_sizes[LyXFont::SIZE_HUGE] = dvalue;
363 dvalue = strToDbl(fl_get_input(dialog_->input_huger));
364 if (rc.font_sizes[LyXFont::SIZE_HUGER] != dvalue) {
366 rc.font_sizes[LyXFont::SIZE_HUGER] = dvalue;
370 // Now update the buffers
371 // Can anything below here affect the redraw process?
372 parent_.controller().updateScreenFonts();
376 string choice = fl_get_choice_text(dialog_->choice_spell_command);
377 choice = trim(choice);
379 rc.isp_command = choice;
382 // If spell checker == "none", all other input set to off.
383 if (fl_get_choice(dialog_->choice_spell_command) == 1) {
384 rc.isp_use_alt_lang = false;
385 rc.isp_alt_lang.erase();
387 rc.isp_use_esc_chars = false;
388 rc.isp_esc_chars.erase();
390 rc.isp_use_pers_dict = false;
391 rc.isp_pers_dict.erase();
393 rc.isp_accept_compound = false;
394 rc.isp_use_input_encoding = false;
397 int button = fl_get_button(dialog_->check_alt_lang);
398 choice = fl_get_input(dialog_->input_alt_lang);
399 if (button && choice.empty()) button = 0;
400 if (!button) choice.erase();
402 rc.isp_use_alt_lang = static_cast<bool>(button);
403 rc.isp_alt_lang = choice;
405 button = fl_get_button(dialog_->check_escape_chars);
406 choice = fl_get_input(dialog_->input_escape_chars);
407 if (button && choice.empty()) button = 0;
408 if (!button) choice.erase();
410 rc.isp_use_esc_chars = static_cast<bool>(button);
411 rc.isp_esc_chars = choice;
413 button = fl_get_button(dialog_->check_personal_dict);
414 choice = fl_get_input(dialog_->input_personal_dict);
415 if (button && choice.empty()) button = 0;
416 if (!button) choice.erase();
418 rc.isp_use_pers_dict = static_cast<bool>(button);
419 rc.isp_pers_dict = choice;
421 button = fl_get_button(dialog_->check_compound_words);
422 rc.isp_accept_compound = static_cast<bool>(button);
424 button = fl_get_button(dialog_->check_input_enc);
425 rc.isp_use_input_encoding = static_cast<bool>(button);
438 void QPrefs::update_contents()
440 LyXRC const & rc(controller().rc());
442 QPrefLanguageModule * langmod(dialog_->languageModule);
444 // FIXME: remove rtl_support bool
445 langmod->rtlCB->setChecked(rc.rtl_support);
446 langmod->markForeignCB->setChecked(rc.mark_foreign_language);
447 langmod->autoBeginCB->setChecked(rc.language_auto_begin);
448 langmod->autoEndCB->setChecked(rc.language_auto_end);
449 langmod->useBabelCB->setChecked(rc.language_use_babel);
450 langmod->globalCB->setChecked(rc.language_global_options);
451 langmod->languagePackageED->setText(rc.language_package.c_str());
452 langmod->startCommandED->setText(rc.language_command_begin.c_str());
453 langmod->endCommandED->setText(rc.language_command_end.c_str());
456 QPrefUIModule * uimod(dialog_->uiModule);
458 uimod->uiFileED->setText(rc.bind_file.c_str());
459 uimod->bindFileED->setText(rc.ui_file.c_str());
460 uimod->cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
461 uimod->wheelMouseSB->setValue(rc.wheel_jump);
462 // convert to minutes
463 int mins(rc.wheel_jump / 60);
464 if (rc.wheel_jump && !mins)
466 uimod->autoSaveSB->setValue(mins);
469 QPrefKeyboardModule * keymod(dialog_->keyboardModule);
471 // FIXME: can derive CB from the two EDs
472 keymod->keymapCB->setChecked(rc.use_kbmap);
473 keymod->firstKeymapED->setText(rc.primary_kbmap.c_str());
474 keymod->secondKeymapED->setText(rc.secondary_kbmap.c_str());
477 QPrefAsciiModule * ascmod(dialog_->asciiModule);
479 ascmod->asciiLinelengthSB->setValue(rc.ascii_linelen);
480 ascmod->asciiRoffED->setText(rc.ascii_roff_command.c_str());
483 QPrefDateModule * datemod(dialog_->dateModule);
485 datemod->DateED->setText(rc.date_insert_format.c_str());
488 QPrefLatexModule * latexmod(dialog_->latexModule);
490 latexmod->latexEncodingED->setText(rc.fontenc.c_str());
491 latexmod->latexChecktexED->setText(rc.chktex_command.c_str());
492 latexmod->latexAutoresetCB->setChecked(rc.auto_reset_options);
493 latexmod->latexDviPaperED->setText(rc.view_dvi_paper_option.c_str());
496 local_converters = converters;
497 local_converters.update(local_formats);
500 local_formats = formats;
503 int const pos = int(findPos(lang_, rc.default_language));
504 combo_default_lang->select(pos + 1);
506 fl_set_button(dialog_->check_preview_latex,
509 switch (rc.display_graphics) {
510 case grfx::NoDisplay: fl_set_choice(dialog_->choice_display, 4); break;
511 case grfx::ColorDisplay: fl_set_choice(dialog_->choice_display, 3); break;
512 case grfx::GrayscaleDisplay: fl_set_choice(dialog_->choice_display, 2); break;
513 case grfx::MonochromeDisplay: fl_set_choice(dialog_->choice_display, 1); break;
514 default: fl_set_choice(dialog_->choice_display, 3); break;
517 fl_set_choice(dialog_->choice_default_papersize,
518 rc.default_papersize + 1);
520 fl_set_input(dialog_->input_default_path,
521 rc.document_path.c_str());
522 fl_set_input(dialog_->input_template_path,
523 rc.template_path.c_str());
527 str = rc.backupdir_path;
529 fl_set_button(dialog_->check_make_backups,
531 fl_set_input(dialog_->input_backup_path, str.c_str());
535 str = rc.tempdir_path;
537 fl_set_button(dialog_->check_use_temp_dir,
539 fl_set_input(dialog_->input_temp_dir, str.c_str());
542 if (rc.check_lastfiles)
545 fl_set_button(dialog_->check_last_files,
547 fl_set_input(dialog_->input_lastfiles, str.c_str());
548 fl_set_counter_value(dialog_->counter_lastfiles,
551 fl_set_input(dialog_->input_serverpipe, rc.lyxpipes.c_str());
553 // Activate/Deactivate the input fields dependent on the state of the
558 fl_set_button(dialog_->check_adapt_output,
559 rc.print_adapt_output);
560 fl_set_input(dialog_->input_command,
561 rc.print_command.c_str());
562 fl_set_input(dialog_->input_page_range,
563 rc.print_pagerange_flag.c_str());
564 fl_set_input(dialog_->input_copies,
565 rc.print_copies_flag.c_str());
566 fl_set_input(dialog_->input_reverse,
567 rc.print_reverse_flag.c_str());
568 fl_set_input(dialog_->input_to_printer,
569 rc.print_to_printer.c_str());
570 fl_set_input(dialog_->input_file_extension,
571 rc.print_file_extension.c_str());
572 fl_set_input(dialog_->input_spool_command,
573 rc.print_spool_command.c_str());
574 fl_set_input(dialog_->input_paper_type,
575 rc.print_paper_flag.c_str());
576 fl_set_input(dialog_->input_even_pages,
577 rc.print_evenpage_flag.c_str());
578 fl_set_input(dialog_->input_odd_pages,
579 rc.print_oddpage_flag.c_str());
580 fl_set_input(dialog_->input_collated,
581 rc.print_collcopies_flag.c_str());
582 fl_set_input(dialog_->input_landscape,
583 rc.print_landscape_flag.c_str());
584 fl_set_input(dialog_->input_to_file,
585 rc.print_to_file.c_str());
586 fl_set_input(dialog_->input_extra_options,
587 rc.print_extra_options.c_str());
588 fl_set_input(dialog_->input_spool_prefix,
589 rc.print_spool_printerprefix.c_str());
590 fl_set_input(dialog_->input_paper_size,
591 rc.print_paper_dimension_flag.c_str());
592 fl_set_input(dialog_->input_name,
597 fl_set_input(dialog_->input_roman,
598 rc.roman_font_name.c_str());
599 fl_set_input(dialog_->input_sans,
600 rc.sans_font_name.c_str());
601 fl_set_input(dialog_->input_typewriter,
602 rc.typewriter_font_name.c_str());
603 fl_set_input(dialog_->input_screen_encoding,
604 rc.font_norm.c_str());
605 fl_set_button(dialog_->check_scalable,
606 rc.use_scalable_fonts);
607 fl_set_counter_value(dialog_->counter_zoom, rc.zoom);
608 fl_set_counter_value(dialog_->counter_dpi, rc.dpi);
609 fl_set_input(dialog_->input_tiny,
610 tostr(rc.font_sizes[LyXFont::SIZE_TINY]).c_str());
611 fl_set_input(dialog_->input_script,
612 tostr(rc.font_sizes[LyXFont::SIZE_SCRIPT]).c_str());
613 fl_set_input(dialog_->input_footnote,
614 tostr(rc.font_sizes[LyXFont::SIZE_FOOTNOTE]).c_str());
615 fl_set_input(dialog_->input_small,
616 tostr(rc.font_sizes[LyXFont::SIZE_SMALL]).c_str());
617 fl_set_input(dialog_->input_normal,
618 tostr(rc.font_sizes[LyXFont::SIZE_NORMAL]).c_str());
619 fl_set_input(dialog_->input_large,
620 tostr(rc.font_sizes[LyXFont::SIZE_LARGE]).c_str());
621 fl_set_input(dialog_->input_larger,
622 tostr(rc.font_sizes[LyXFont::SIZE_LARGER]).c_str());
623 fl_set_input(dialog_->input_largest,
624 tostr(rc.font_sizes[LyXFont::SIZE_LARGEST]).c_str());
625 fl_set_input(dialog_->input_huge,
626 tostr(rc.font_sizes[LyXFont::SIZE_HUGE]).c_str());
627 fl_set_input(dialog_->input_huger,
628 tostr(rc.font_sizes[LyXFont::SIZE_HUGER]).c_str());
633 if (rc.isp_command == "none")
635 else if (rc.isp_command == "ispell")
637 else if (rc.isp_command == "aspell")
640 if (rc.isp_command == "ispell")
642 else if (rc.isp_command == "aspell")
645 fl_set_choice(dialog_->choice_spell_command, choice);
648 if (rc.isp_use_alt_lang)
649 str = rc.isp_alt_lang;
651 fl_set_button(dialog_->check_alt_lang,
652 rc.isp_use_alt_lang);
653 fl_set_input(dialog_->input_alt_lang, str.c_str());
656 if (rc.isp_use_esc_chars)
657 str = rc.isp_esc_chars;
659 fl_set_button(dialog_->check_escape_chars,
660 rc.isp_use_esc_chars);
661 fl_set_input(dialog_->input_escape_chars, str.c_str());
664 if (rc.isp_use_pers_dict)
665 str = rc.isp_pers_dict;
667 fl_set_button(dialog_->check_personal_dict,
668 rc.isp_use_pers_dict);
669 fl_set_input(dialog_->input_personal_dict, str.c_str());
671 fl_set_button(dialog_->check_compound_words,
672 rc.isp_accept_compound);
673 fl_set_button(dialog_->check_input_enc,
674 rc.isp_use_input_encoding);
676 // Activate/Deactivate the input fields dependent on the state of the