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"
38 #include "frnt_lang.h"
39 #include "helper_funcs.h"
41 #include <qpushbutton.h>
42 #include <qcheckbox.h>
43 #include <qlineedit.h>
45 #include <qcombobox.h>
48 typedef Qt2CB<ControlPrefs, Qt2DB<QPrefsDialog> > base_class;
52 : base_class(_("LyX: Preferences"))
57 void QPrefs::build_dialog()
59 dialog_.reset(new QPrefsDialog(this));
61 bc().setOK(dialog_->savePB);
62 bc().setApply(dialog_->applyPB);
63 bc().setCancel(dialog_->closePB);
64 bc().setRestore(dialog_->restorePB);
66 QPrefLanguageModule * langmod(dialog_->languageModule);
68 langmod->defaultLanguageCO->clear();
69 // store the lang identifiers for later
70 vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
71 lang_ = getSecond(langs);
73 vector<frnt::LanguagePair>::const_iterator lit = langs.begin();
74 vector<frnt::LanguagePair>::const_iterator lend = langs.end();
75 for (; lit != lend; ++lit) {
76 langmod->defaultLanguageCO->insertItem(lit->first.c_str());
83 LyXRC & rc(controller().rc());
87 QPrefLanguageModule * langmod(dialog_->languageModule);
89 // FIXME: remove rtl_support bool
90 rc.rtl_support = langmod->rtlCB->isChecked();
91 rc.mark_foreign_language = langmod->markForeignCB->isChecked();
92 rc.language_auto_begin = langmod->autoBeginCB->isChecked();
93 rc.language_auto_end = langmod->autoEndCB->isChecked();
94 rc.language_use_babel = langmod->useBabelCB->isChecked();
95 rc.language_global_options = langmod->globalCB->isChecked();
96 rc.language_package = langmod->languagePackageED->text().latin1();
97 rc.language_command_begin = langmod->startCommandED->text().latin1();
98 rc.language_command_end = langmod->endCommandED->text().latin1();
99 rc.default_language = lang_[langmod->defaultLanguageCO->currentItem()];
101 QPrefUIModule * uimod(dialog_->uiModule);
103 rc.bind_file = uimod->uiFileED->text().latin1();
104 rc.ui_file = uimod->bindFileED->text().latin1();
105 rc.cursor_follows_scrollbar = uimod->cursorFollowsCB->isChecked();
106 rc.wheel_jump = uimod->wheelMouseSB->value();
107 rc.autosave = uimod->autoSaveSB->value() * 60;
108 rc.make_backup = uimod->autoSaveCB->isChecked();
109 rc.num_lastfiles = uimod->lastfilesSB->value();
112 QPrefKeyboardModule * keymod(dialog_->keyboardModule);
114 // FIXME: can derive CB from the two EDs
115 rc.use_kbmap = keymod->keymapCB->isChecked();
116 rc.primary_kbmap = keymod->firstKeymapED->text().latin1();
117 rc.secondary_kbmap = keymod->secondKeymapED->text().latin1();
120 QPrefAsciiModule * ascmod(dialog_->asciiModule);
122 rc.ascii_linelen = ascmod->asciiLinelengthSB->value();
123 rc.ascii_roff_command = ascmod->asciiRoffED->text().latin1();
126 QPrefDateModule * datemod(dialog_->dateModule);
128 rc.date_insert_format = datemod->DateED->text().latin1();
131 QPrefLatexModule * latexmod(dialog_->latexModule);
133 rc.fontenc = latexmod->latexEncodingED->text().latin1();
134 rc.chktex_command = latexmod->latexChecktexED->text().latin1();
135 rc.auto_reset_options = latexmod->latexAutoresetCB->isChecked();
136 rc.view_dvi_paper_option = latexmod->latexDviPaperED->text().latin1();
137 rc.default_papersize =
138 static_cast<BufferParams::PAPER_SIZE>(latexmod->latexPaperSizeCO->currentItem());
141 QPrefDisplayModule * displaymod(dialog_->displayModule);
143 rc.preview = displaymod->previewCB->isChecked();
145 grfx::DisplayType dtype(grfx::ColorDisplay);
147 switch (displaymod->displayGraphicsCO->currentItem()) {
148 case 3: dtype = grfx::NoDisplay; break;
149 case 2: dtype = grfx::ColorDisplay; break;
150 case 1: dtype = grfx::GrayscaleDisplay; break;
151 case 0: dtype = grfx::MonochromeDisplay; break;
153 rc.display_graphics = dtype;
156 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
159 if (old_value != rc.display_graphics) {
160 grfx::GCache & gc = grfx::GCache::get();
165 QPrefPathsModule * pathsmod(dialog_->pathsModule);
167 rc.document_path = pathsmod->workingDirED->text().latin1();
168 rc.template_path = pathsmod->templateDirED->text().latin1();
169 rc.backupdir_path = pathsmod->backupDirED->text().latin1();
170 rc.use_tempdir = pathsmod->tempDirCB->isChecked();
171 rc.tempdir_path = pathsmod->tempDirED->text().latin1();
172 // FIXME: should be a checkbox only
173 rc.lyxpipes = pathsmod->lyxserverDirED->text().latin1();
176 QPrefSpellcheckerModule * spellmod(dialog_->spellcheckerModule);
178 if (spellmod->spellCommandCO->currentItem() == 0)
179 rc.isp_command = "ispell";
181 rc.isp_command = "aspell";
183 // FIXME: remove isp_use_alt_lang
184 rc.isp_alt_lang = spellmod->altLanguageED->text().latin1();
185 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
186 // FIXME: remove isp_use_esc_chars
187 rc.isp_esc_chars = spellmod->escapeCharactersED->text().latin1();
188 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
189 // FIXME: remove isp_use_pers_dict
190 rc.isp_pers_dict = spellmod->persDictionaryED->text().latin1();
191 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
192 rc.isp_accept_compound = spellmod->compoundWordCB->isChecked();
193 rc.isp_use_input_encoding = spellmod->inputEncodingCB->isChecked();
196 QPrefPrinterModule * printmod(dialog_->printerModule);
198 rc.print_adapt_output = printmod->printerAdaptCB->isChecked();
199 rc.print_command = printmod->printerCommandED->text().latin1();
200 rc.printer = printmod->printerNameED->text().latin1();
202 rc.print_pagerange_flag = printmod->printerPageRangeED->text().latin1();
203 rc.print_copies_flag = printmod->printerCopiesED->text().latin1();
204 rc.print_reverse_flag = printmod->printerReverseED->text().latin1();
205 rc.print_to_printer = printmod->printerToPrinterED->text().latin1();
206 rc.print_file_extension = printmod->printerExtensionED->text().latin1();
207 rc.print_file_extension = printmod->printerSpoolCommandED->text().latin1();
208 rc.print_paper_flag = printmod->printerPaperTypeED->text().latin1();
209 rc.print_evenpage_flag = printmod->printerEvenED->text().latin1();
210 rc.print_oddpage_flag = printmod->printerOddED->text().latin1();
211 rc.print_collcopies_flag = printmod->printerCollatedED->text().latin1();
212 rc.print_landscape_flag = printmod->printerLandscapeED->text().latin1();
213 rc.print_to_file = printmod->printerToFileED->text().latin1();
214 rc.print_extra_options = printmod->printerExtraED->text().latin1();
215 rc.print_spool_printerprefix = printmod->printerSpoolPrefixED->text().latin1();
216 rc.print_paper_dimension_flag = printmod->printerPaperSizeED->text().latin1();
219 QPrefScreenFontsModule * fontmod(dialog_->screenfontsModule);
221 LyXRC const oldrc(rc);
223 rc.roman_font_name = fontmod->screenRomanED->text().latin1();
224 rc.sans_font_name = fontmod->screenSansED->text().latin1();
225 rc.typewriter_font_name = fontmod->screenTypewriterED->text().latin1();
226 rc.zoom = fontmod->screenZoomSB->value();
227 rc.dpi = fontmod->screenDpiSB->value();
228 rc.font_sizes[LyXFont::SIZE_TINY] = strToDbl(fontmod->screenTinyED->text().latin1());
229 rc.font_sizes[LyXFont::SIZE_SCRIPT] = strToDbl(fontmod->screenSmallestED->text().latin1());
230 rc.font_sizes[LyXFont::SIZE_FOOTNOTE] = strToDbl(fontmod->screenSmallerED->text().latin1());
231 rc.font_sizes[LyXFont::SIZE_SMALL] = strToDbl(fontmod->screenSmallED->text().latin1());
232 rc.font_sizes[LyXFont::SIZE_NORMAL] = strToDbl(fontmod->screenNormalED->text().latin1());
233 rc.font_sizes[LyXFont::SIZE_LARGE] = strToDbl(fontmod->screenLargeED->text().latin1());
234 rc.font_sizes[LyXFont::SIZE_LARGER] = strToDbl(fontmod->screenLargerED->text().latin1());
235 rc.font_sizes[LyXFont::SIZE_LARGEST] = strToDbl(fontmod->screenLargestED->text().latin1());
236 rc.font_sizes[LyXFont::SIZE_HUGE] = strToDbl(fontmod->screenHugeED->text().latin1());
237 rc.font_sizes[LyXFont::SIZE_HUGER] = strToDbl(fontmod->screenHugerED->text().latin1());
239 if (rc.font_sizes != oldrc.font_sizes
240 || rc.roman_font_name != oldrc.roman_font_name
241 || rc.sans_font_name != oldrc.sans_font_name
242 || rc.typewriter_font_name != oldrc.typewriter_font_name
243 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
244 controller().updateScreenFonts();
247 controller().setConverters(converters_);
248 controller().setFormats(formats_);
250 // FIXME: controller().setColor(lc, hexname)
254 // FIXME: move to helper_funcs.h
258 typename std::vector<A>::size_type
259 findPos(std::vector<A> const & vec, A const & val)
261 typename std::vector<A>::const_iterator it =
262 std::find(vec.begin(), vec.end(), val);
265 return std::distance(vec.begin(), it);
270 void QPrefs::update_contents()
272 LyXRC const & rc(controller().rc());
274 QPrefLanguageModule * langmod(dialog_->languageModule);
276 // FIXME: remove rtl_support bool
277 langmod->rtlCB->setChecked(rc.rtl_support);
278 langmod->markForeignCB->setChecked(rc.mark_foreign_language);
279 langmod->autoBeginCB->setChecked(rc.language_auto_begin);
280 langmod->autoEndCB->setChecked(rc.language_auto_end);
281 langmod->useBabelCB->setChecked(rc.language_use_babel);
282 langmod->globalCB->setChecked(rc.language_global_options);
283 langmod->languagePackageED->setText(rc.language_package.c_str());
284 langmod->startCommandED->setText(rc.language_command_begin.c_str());
285 langmod->endCommandED->setText(rc.language_command_end.c_str());
287 int const pos = int(findPos(lang_, rc.default_language));
288 langmod->defaultLanguageCO->setCurrentItem(pos);
290 QPrefUIModule * uimod(dialog_->uiModule);
292 uimod->uiFileED->setText(rc.bind_file.c_str());
293 uimod->bindFileED->setText(rc.ui_file.c_str());
294 uimod->cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
295 uimod->wheelMouseSB->setValue(rc.wheel_jump);
296 // convert to minutes
297 int mins(rc.autosave / 60);
298 if (rc.autosave && !mins)
300 uimod->autoSaveSB->setValue(mins);
301 uimod->autoSaveCB->setChecked(rc.make_backup);
302 uimod->lastfilesSB->setValue(rc.num_lastfiles);
305 QPrefKeyboardModule * keymod(dialog_->keyboardModule);
307 // FIXME: can derive CB from the two EDs
308 keymod->keymapCB->setChecked(rc.use_kbmap);
309 keymod->firstKeymapED->setText(rc.primary_kbmap.c_str());
310 keymod->secondKeymapED->setText(rc.secondary_kbmap.c_str());
313 QPrefAsciiModule * ascmod(dialog_->asciiModule);
315 ascmod->asciiLinelengthSB->setValue(rc.ascii_linelen);
316 ascmod->asciiRoffED->setText(rc.ascii_roff_command.c_str());
319 QPrefDateModule * datemod(dialog_->dateModule);
321 datemod->DateED->setText(rc.date_insert_format.c_str());
324 QPrefLatexModule * latexmod(dialog_->latexModule);
326 latexmod->latexEncodingED->setText(rc.fontenc.c_str());
327 latexmod->latexChecktexED->setText(rc.chktex_command.c_str());
328 latexmod->latexAutoresetCB->setChecked(rc.auto_reset_options);
329 latexmod->latexDviPaperED->setText(rc.view_dvi_paper_option.c_str());
330 latexmod->latexPaperSizeCO->setCurrentItem(rc.default_papersize);
333 QPrefDisplayModule * displaymod(dialog_->displayModule);
335 displaymod->previewCB->setChecked(rc.preview);
339 switch (rc.display_graphics) {
340 case grfx::NoDisplay: item = 3; break;
341 case grfx::ColorDisplay: item = 2; break;
342 case grfx::GrayscaleDisplay: item = 1; break;
343 case grfx::MonochromeDisplay: item = 0; break;
345 displaymod->displayGraphicsCO->setCurrentItem(item);
348 QPrefPathsModule * pathsmod(dialog_->pathsModule);
350 pathsmod->workingDirED->setText(rc.document_path.c_str());
351 pathsmod->templateDirED->setText(rc.template_path.c_str());
352 pathsmod->backupDirED->setText(rc.backupdir_path.c_str());
353 pathsmod->tempDirCB->setChecked(rc.use_tempdir);
354 pathsmod->tempDirED->setText(rc.tempdir_path.c_str());
355 // FIXME: should be a checkbox only
356 pathsmod->lyxserverDirED->setText(rc.lyxpipes.c_str());
359 QPrefSpellcheckerModule * spellmod(dialog_->spellcheckerModule);
361 item = (rc.isp_command == "ispell") ? 0 : 1;
362 spellmod->spellCommandCO->setCurrentItem(item);
363 // FIXME: remove isp_use_alt_lang
364 spellmod->altLanguageED->setText(rc.isp_alt_lang.c_str());
365 // FIXME: remove isp_use_esc_chars
366 spellmod->escapeCharactersED->setText(rc.isp_esc_chars.c_str());
367 // FIXME: remove isp_use_pers_dict
368 spellmod->persDictionaryED->setText(rc.isp_pers_dict.c_str());
369 spellmod->compoundWordCB->setChecked(rc.isp_accept_compound);
370 spellmod->inputEncodingCB->setChecked(rc.isp_use_input_encoding);
373 QPrefPrinterModule * printmod(dialog_->printerModule);
375 printmod->printerAdaptCB->setChecked(rc.print_adapt_output);
376 printmod->printerCommandED->setText(rc.print_command.c_str());
377 printmod->printerNameED->setText(rc.printer.c_str());
379 printmod->printerPageRangeED->setText(rc.print_pagerange_flag.c_str());
380 printmod->printerCopiesED->setText(rc.print_copies_flag.c_str());
381 printmod->printerReverseED->setText(rc.print_reverse_flag.c_str());
382 printmod->printerToPrinterED->setText(rc.print_to_printer.c_str());
383 printmod->printerExtensionED->setText(rc.print_file_extension.c_str());
384 printmod->printerSpoolCommandED->setText(rc.print_file_extension.c_str());
385 printmod->printerPaperTypeED->setText(rc.print_paper_flag.c_str());
386 printmod->printerEvenED->setText(rc.print_evenpage_flag.c_str());
387 printmod->printerOddED->setText(rc.print_oddpage_flag.c_str());
388 printmod->printerCollatedED->setText(rc.print_collcopies_flag.c_str());
389 printmod->printerLandscapeED->setText(rc.print_landscape_flag.c_str());
390 printmod->printerToFileED->setText(rc.print_to_file.c_str());
391 printmod->printerExtraED->setText(rc.print_extra_options.c_str());
392 printmod->printerSpoolPrefixED->setText(rc.print_spool_printerprefix.c_str());
393 printmod->printerPaperSizeED->setText(rc.print_paper_dimension_flag.c_str());
396 QPrefScreenFontsModule * fontmod(dialog_->screenfontsModule);
398 fontmod->screenRomanED->setText(rc.roman_font_name.c_str());
399 fontmod->screenSansED->setText(rc.sans_font_name.c_str());
400 fontmod->screenTypewriterED->setText(rc.typewriter_font_name.c_str());
401 fontmod->screenZoomSB->setValue(rc.zoom);
402 fontmod->screenDpiSB->setValue(int(rc.dpi));
403 fontmod->screenTinyED->setText(tostr(rc.font_sizes[LyXFont::SIZE_TINY]).c_str());
404 fontmod->screenSmallestED->setText(tostr(rc.font_sizes[LyXFont::SIZE_SCRIPT]).c_str());
405 fontmod->screenSmallerED->setText(tostr(rc.font_sizes[LyXFont::SIZE_FOOTNOTE]).c_str());
406 fontmod->screenSmallED->setText(tostr(rc.font_sizes[LyXFont::SIZE_SMALL]).c_str());
407 fontmod->screenNormalED->setText(tostr(rc.font_sizes[LyXFont::SIZE_NORMAL]).c_str());
408 fontmod->screenLargeED->setText(tostr(rc.font_sizes[LyXFont::SIZE_LARGE]).c_str());
409 fontmod->screenLargerED->setText(tostr(rc.font_sizes[LyXFont::SIZE_LARGER]).c_str());
410 fontmod->screenLargestED->setText(tostr(rc.font_sizes[LyXFont::SIZE_LARGEST]).c_str());
411 fontmod->screenHugeED->setText(tostr(rc.font_sizes[LyXFont::SIZE_HUGE]).c_str());
412 fontmod->screenHugerED->setText(tostr(rc.font_sizes[LyXFont::SIZE_HUGER]).c_str());
416 dialog_->updateFormats();
418 converters_ = converters;
420 dialog_->updateConverters();
423 // FIXME: populate colors