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"
21 #include "ControlPrefs.h"
22 #include "QPrefsDialog.h"
23 #include "ui/QPrefAsciiModule.h"
24 #include "ui/QPrefDateModule.h"
25 #include "ui/QPrefKeyboardModule.h"
26 #include "ui/QPrefLatexModule.h"
27 #include "ui/QPrefScreenFontsModule.h"
28 #include "ui/QPrefColorsModule.h"
29 #include "ui/QPrefDisplayModule.h"
30 #include "ui/QPrefPathsModule.h"
31 #include "ui/QPrefSpellcheckerModule.h"
32 #include "ui/QPrefConvertersModule.h"
33 #include "ui/QPrefFileformatsModule.h"
34 #include "ui/QPrefLanguageModule.h"
35 #include "ui/QPrefPrinterModule.h"
36 #include "ui/QPrefUIModule.h"
40 #include "frnt_lang.h"
41 #include "helper_funcs.h"
44 #include <qpushbutton.h>
45 #include <qcheckbox.h>
46 #include <qlineedit.h>
48 #include <qcombobox.h>
51 #include "qcoloritem.h"
54 using std::ostringstream;
59 typedef Qt2CB<ControlPrefs, Qt2DB<QPrefsDialog> > base_class;
63 : base_class(_("LyX: Preferences"))
68 void QPrefs::build_dialog()
70 dialog_.reset(new QPrefsDialog(this));
72 bc().setOK(dialog_->savePB);
73 bc().setApply(dialog_->applyPB);
74 bc().setCancel(dialog_->closePB);
75 bc().setRestore(dialog_->restorePB);
77 QPrefLanguageModule * langmod(dialog_->languageModule);
79 langmod->defaultLanguageCO->clear();
80 // store the lang identifiers for later
81 vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
82 lang_ = getSecond(langs);
84 vector<frnt::LanguagePair>::const_iterator lit = langs.begin();
85 vector<frnt::LanguagePair>::const_iterator lend = langs.end();
86 for (; lit != lend; ++lit) {
87 langmod->defaultLanguageCO->insertItem(lit->first.c_str());
94 LyXRC & rc(controller().rc());
98 QPrefLanguageModule * langmod(dialog_->languageModule);
100 // FIXME: remove rtl_support bool
101 rc.rtl_support = langmod->rtlCB->isChecked();
102 rc.mark_foreign_language = langmod->markForeignCB->isChecked();
103 rc.language_auto_begin = langmod->autoBeginCB->isChecked();
104 rc.language_auto_end = langmod->autoEndCB->isChecked();
105 rc.language_use_babel = langmod->useBabelCB->isChecked();
106 rc.language_global_options = langmod->globalCB->isChecked();
107 rc.language_package = langmod->languagePackageED->text().latin1();
108 rc.language_command_begin = langmod->startCommandED->text().latin1();
109 rc.language_command_end = langmod->endCommandED->text().latin1();
110 rc.default_language = lang_[langmod->defaultLanguageCO->currentItem()];
112 QPrefUIModule * uimod(dialog_->uiModule);
114 rc.ui_file = uimod->uiFileED->text().latin1();
115 rc.bind_file = uimod->bindFileED->text().latin1();
116 rc.cursor_follows_scrollbar = uimod->cursorFollowsCB->isChecked();
117 rc.wheel_jump = uimod->wheelMouseSB->value();
118 rc.autosave = uimod->autoSaveSB->value() * 60;
119 rc.make_backup = uimod->autoSaveCB->isChecked();
120 rc.num_lastfiles = uimod->lastfilesSB->value();
123 QPrefKeyboardModule * keymod(dialog_->keyboardModule);
125 // FIXME: can derive CB from the two EDs
126 rc.use_kbmap = keymod->keymapCB->isChecked();
127 rc.primary_kbmap = keymod->firstKeymapED->text().latin1();
128 rc.secondary_kbmap = keymod->secondKeymapED->text().latin1();
131 QPrefAsciiModule * ascmod(dialog_->asciiModule);
133 rc.ascii_linelen = ascmod->asciiLinelengthSB->value();
134 rc.ascii_roff_command = ascmod->asciiRoffED->text().latin1();
137 QPrefDateModule * datemod(dialog_->dateModule);
139 rc.date_insert_format = datemod->DateED->text().latin1();
142 QPrefLatexModule * latexmod(dialog_->latexModule);
144 rc.fontenc = latexmod->latexEncodingED->text().latin1();
145 rc.chktex_command = latexmod->latexChecktexED->text().latin1();
146 rc.auto_reset_options = latexmod->latexAutoresetCB->isChecked();
147 rc.view_dvi_paper_option = latexmod->latexDviPaperED->text().latin1();
148 rc.default_papersize =
149 static_cast<BufferParams::PAPER_SIZE>(latexmod->latexPaperSizeCO->currentItem());
152 QPrefDisplayModule * displaymod(dialog_->displayModule);
154 rc.preview = displaymod->previewCB->isChecked();
156 grfx::DisplayType dtype(grfx::ColorDisplay);
158 switch (displaymod->displayGraphicsCO->currentItem()) {
159 case 3: dtype = grfx::NoDisplay; break;
160 case 2: dtype = grfx::ColorDisplay; break;
161 case 1: dtype = grfx::GrayscaleDisplay; break;
162 case 0: dtype = grfx::MonochromeDisplay; break;
164 rc.display_graphics = dtype;
167 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
170 if (old_value != rc.display_graphics) {
171 grfx::GCache & gc = grfx::GCache::get();
176 QPrefPathsModule * pathsmod(dialog_->pathsModule);
178 rc.document_path = pathsmod->workingDirED->text().latin1();
179 rc.template_path = pathsmod->templateDirED->text().latin1();
180 rc.backupdir_path = pathsmod->backupDirED->text().latin1();
181 rc.use_tempdir = pathsmod->tempDirCB->isChecked();
182 rc.tempdir_path = pathsmod->tempDirED->text().latin1();
183 // FIXME: should be a checkbox only
184 rc.lyxpipes = pathsmod->lyxserverDirED->text().latin1();
187 QPrefSpellcheckerModule * spellmod(dialog_->spellcheckerModule);
189 if (spellmod->spellCommandCO->currentItem() == 0)
190 rc.isp_command = "ispell";
192 rc.isp_command = "aspell";
194 // FIXME: remove isp_use_alt_lang
195 rc.isp_alt_lang = spellmod->altLanguageED->text().latin1();
196 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
197 // FIXME: remove isp_use_esc_chars
198 rc.isp_esc_chars = spellmod->escapeCharactersED->text().latin1();
199 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
200 // FIXME: remove isp_use_pers_dict
201 rc.isp_pers_dict = spellmod->persDictionaryED->text().latin1();
202 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
203 rc.isp_accept_compound = spellmod->compoundWordCB->isChecked();
204 rc.isp_use_input_encoding = spellmod->inputEncodingCB->isChecked();
207 QPrefPrinterModule * printmod(dialog_->printerModule);
209 rc.print_adapt_output = printmod->printerAdaptCB->isChecked();
210 rc.print_command = printmod->printerCommandED->text().latin1();
211 rc.printer = printmod->printerNameED->text().latin1();
213 rc.print_pagerange_flag = printmod->printerPageRangeED->text().latin1();
214 rc.print_copies_flag = printmod->printerCopiesED->text().latin1();
215 rc.print_reverse_flag = printmod->printerReverseED->text().latin1();
216 rc.print_to_printer = printmod->printerToPrinterED->text().latin1();
217 rc.print_file_extension = printmod->printerExtensionED->text().latin1();
218 rc.print_file_extension = printmod->printerSpoolCommandED->text().latin1();
219 rc.print_paper_flag = printmod->printerPaperTypeED->text().latin1();
220 rc.print_evenpage_flag = printmod->printerEvenED->text().latin1();
221 rc.print_oddpage_flag = printmod->printerOddED->text().latin1();
222 rc.print_collcopies_flag = printmod->printerCollatedED->text().latin1();
223 rc.print_landscape_flag = printmod->printerLandscapeED->text().latin1();
224 rc.print_to_file = printmod->printerToFileED->text().latin1();
225 rc.print_extra_options = printmod->printerExtraED->text().latin1();
226 rc.print_spool_printerprefix = printmod->printerSpoolPrefixED->text().latin1();
227 rc.print_paper_dimension_flag = printmod->printerPaperSizeED->text().latin1();
230 QPrefScreenFontsModule * fontmod(dialog_->screenfontsModule);
232 LyXRC const oldrc(rc);
234 rc.roman_font_name = fontmod->screenRomanCO->currentText().latin1();
235 rc.sans_font_name = fontmod->screenSansCO->currentText().latin1();
236 rc.typewriter_font_name = fontmod->screenTypewriterCO->currentText().latin1();
237 rc.zoom = fontmod->screenZoomSB->value();
238 rc.dpi = fontmod->screenDpiSB->value();
239 rc.font_sizes[LyXFont::SIZE_TINY] = strToDbl(fontmod->screenTinyED->text().latin1());
240 rc.font_sizes[LyXFont::SIZE_SCRIPT] = strToDbl(fontmod->screenSmallestED->text().latin1());
241 rc.font_sizes[LyXFont::SIZE_FOOTNOTE] = strToDbl(fontmod->screenSmallerED->text().latin1());
242 rc.font_sizes[LyXFont::SIZE_SMALL] = strToDbl(fontmod->screenSmallED->text().latin1());
243 rc.font_sizes[LyXFont::SIZE_NORMAL] = strToDbl(fontmod->screenNormalED->text().latin1());
244 rc.font_sizes[LyXFont::SIZE_LARGE] = strToDbl(fontmod->screenLargeED->text().latin1());
245 rc.font_sizes[LyXFont::SIZE_LARGER] = strToDbl(fontmod->screenLargerED->text().latin1());
246 rc.font_sizes[LyXFont::SIZE_LARGEST] = strToDbl(fontmod->screenLargestED->text().latin1());
247 rc.font_sizes[LyXFont::SIZE_HUGE] = strToDbl(fontmod->screenHugeED->text().latin1());
248 rc.font_sizes[LyXFont::SIZE_HUGER] = strToDbl(fontmod->screenHugerED->text().latin1());
250 if (rc.font_sizes != oldrc.font_sizes
251 || rc.roman_font_name != oldrc.roman_font_name
252 || rc.sans_font_name != oldrc.sans_font_name
253 || rc.typewriter_font_name != oldrc.typewriter_font_name
254 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
255 controller().updateScreenFonts();
258 controller().setConverters(converters_);
259 controller().setFormats(formats_);
261 QPrefColorsModule * colmod(dialog_->colorsModule);
265 for (i = 0; i < colmod->lyxObjectsLB->count(); ++i) {
266 QListBoxItem * ib(colmod->lyxObjectsLB->item(i));
267 QColorItem * ci(static_cast<QColorItem*>(ib));
271 ostr << '#' << std::setbase(16) << setfill('0')
272 << setw(2) << ci->color().red()
273 << setw(2) << ci->color().green()
274 << setw(2) << ci->color().blue();
276 string newhex(STRCONV(ostr.str()));
278 LColor::color col(dialog_->colors_[i]);
280 // FIXME: dubious, but it's what xforms does
281 if (lcolor.getX11Name(col) != newhex) {
282 controller().setColor(col, newhex);
288 // FIXME: move to helper_funcs.h
292 typename std::vector<A>::size_type
293 findPos(std::vector<A> const & vec, A const & val)
295 typename std::vector<A>::const_iterator it =
296 std::find(vec.begin(), vec.end(), val);
299 return std::distance(vec.begin(), it);
304 void QPrefs::update_contents()
306 LyXRC const & rc(controller().rc());
308 QPrefLanguageModule * langmod(dialog_->languageModule);
310 // FIXME: remove rtl_support bool
311 langmod->rtlCB->setChecked(rc.rtl_support);
312 langmod->markForeignCB->setChecked(rc.mark_foreign_language);
313 langmod->autoBeginCB->setChecked(rc.language_auto_begin);
314 langmod->autoEndCB->setChecked(rc.language_auto_end);
315 langmod->useBabelCB->setChecked(rc.language_use_babel);
316 langmod->globalCB->setChecked(rc.language_global_options);
317 langmod->languagePackageED->setText(rc.language_package.c_str());
318 langmod->startCommandED->setText(rc.language_command_begin.c_str());
319 langmod->endCommandED->setText(rc.language_command_end.c_str());
321 int const pos = int(findPos(lang_, rc.default_language));
322 langmod->defaultLanguageCO->setCurrentItem(pos);
324 QPrefUIModule * uimod(dialog_->uiModule);
326 uimod->uiFileED->setText(rc.ui_file.c_str());
327 uimod->bindFileED->setText(rc.bind_file.c_str());
328 uimod->cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
329 uimod->wheelMouseSB->setValue(rc.wheel_jump);
330 // convert to minutes
331 int mins(rc.autosave / 60);
332 if (rc.autosave && !mins)
334 uimod->autoSaveSB->setValue(mins);
335 uimod->autoSaveCB->setChecked(rc.make_backup);
336 uimod->lastfilesSB->setValue(rc.num_lastfiles);
339 QPrefKeyboardModule * keymod(dialog_->keyboardModule);
341 // FIXME: can derive CB from the two EDs
342 keymod->keymapCB->setChecked(rc.use_kbmap);
343 // no idea why we need these. Fscking Qt.
344 keymod->firstKeymapED->setEnabled(rc.use_kbmap);
345 keymod->firstKeymapPB->setEnabled(rc.use_kbmap);
346 keymod->firstKeymapLA->setEnabled(rc.use_kbmap);
347 keymod->secondKeymapED->setEnabled(rc.use_kbmap);
348 keymod->secondKeymapPB->setEnabled(rc.use_kbmap);
349 keymod->secondKeymapLA->setEnabled(rc.use_kbmap);
350 keymod->firstKeymapED->setText(rc.primary_kbmap.c_str());
351 keymod->secondKeymapED->setText(rc.secondary_kbmap.c_str());
354 QPrefAsciiModule * ascmod(dialog_->asciiModule);
356 ascmod->asciiLinelengthSB->setValue(rc.ascii_linelen);
357 ascmod->asciiRoffED->setText(rc.ascii_roff_command.c_str());
360 QPrefDateModule * datemod(dialog_->dateModule);
362 datemod->DateED->setText(rc.date_insert_format.c_str());
365 QPrefLatexModule * latexmod(dialog_->latexModule);
367 latexmod->latexEncodingED->setText(rc.fontenc.c_str());
368 latexmod->latexChecktexED->setText(rc.chktex_command.c_str());
369 latexmod->latexAutoresetCB->setChecked(rc.auto_reset_options);
370 latexmod->latexDviPaperED->setText(rc.view_dvi_paper_option.c_str());
371 latexmod->latexPaperSizeCO->setCurrentItem(rc.default_papersize);
374 QPrefDisplayModule * displaymod(dialog_->displayModule);
376 displaymod->previewCB->setChecked(rc.preview);
380 switch (rc.display_graphics) {
381 case grfx::NoDisplay: item = 3; break;
382 case grfx::ColorDisplay: item = 2; break;
383 case grfx::GrayscaleDisplay: item = 1; break;
384 case grfx::MonochromeDisplay: item = 0; break;
386 displaymod->displayGraphicsCO->setCurrentItem(item);
389 QPrefPathsModule * pathsmod(dialog_->pathsModule);
391 pathsmod->workingDirED->setText(rc.document_path.c_str());
392 pathsmod->templateDirED->setText(rc.template_path.c_str());
393 pathsmod->backupDirED->setText(rc.backupdir_path.c_str());
394 pathsmod->tempDirCB->setChecked(rc.use_tempdir);
395 pathsmod->tempDirED->setText(rc.tempdir_path.c_str());
396 // FIXME: should be a checkbox only
397 pathsmod->lyxserverDirED->setText(rc.lyxpipes.c_str());
400 QPrefSpellcheckerModule * spellmod(dialog_->spellcheckerModule);
402 item = (rc.isp_command == "ispell") ? 0 : 1;
403 spellmod->spellCommandCO->setCurrentItem(item);
404 // FIXME: remove isp_use_alt_lang
405 spellmod->altLanguageED->setText(rc.isp_alt_lang.c_str());
406 // FIXME: remove isp_use_esc_chars
407 spellmod->escapeCharactersED->setText(rc.isp_esc_chars.c_str());
408 // FIXME: remove isp_use_pers_dict
409 spellmod->persDictionaryED->setText(rc.isp_pers_dict.c_str());
410 spellmod->compoundWordCB->setChecked(rc.isp_accept_compound);
411 spellmod->inputEncodingCB->setChecked(rc.isp_use_input_encoding);
414 QPrefPrinterModule * printmod(dialog_->printerModule);
416 printmod->printerAdaptCB->setChecked(rc.print_adapt_output);
417 printmod->printerCommandED->setText(rc.print_command.c_str());
418 printmod->printerNameED->setText(rc.printer.c_str());
420 printmod->printerPageRangeED->setText(rc.print_pagerange_flag.c_str());
421 printmod->printerCopiesED->setText(rc.print_copies_flag.c_str());
422 printmod->printerReverseED->setText(rc.print_reverse_flag.c_str());
423 printmod->printerToPrinterED->setText(rc.print_to_printer.c_str());
424 printmod->printerExtensionED->setText(rc.print_file_extension.c_str());
425 printmod->printerSpoolCommandED->setText(rc.print_file_extension.c_str());
426 printmod->printerPaperTypeED->setText(rc.print_paper_flag.c_str());
427 printmod->printerEvenED->setText(rc.print_evenpage_flag.c_str());
428 printmod->printerOddED->setText(rc.print_oddpage_flag.c_str());
429 printmod->printerCollatedED->setText(rc.print_collcopies_flag.c_str());
430 printmod->printerLandscapeED->setText(rc.print_landscape_flag.c_str());
431 printmod->printerToFileED->setText(rc.print_to_file.c_str());
432 printmod->printerExtraED->setText(rc.print_extra_options.c_str());
433 printmod->printerSpoolPrefixED->setText(rc.print_spool_printerprefix.c_str());
434 printmod->printerPaperSizeED->setText(rc.print_paper_dimension_flag.c_str());
437 QPrefScreenFontsModule * fontmod(dialog_->screenfontsModule);
439 QString roman(rc.roman_font_name.c_str());
440 QString sans(rc.sans_font_name.c_str());
441 QString typewriter(rc.typewriter_font_name.c_str());
443 for (int i = 0; i < fontmod->screenRomanCO->count(); ++i) {
444 if (fontmod->screenRomanCO->text(i) == roman) {
445 fontmod->screenRomanCO->setCurrentItem(i);
450 for (int i = 0; i < fontmod->screenSansCO->count(); ++i) {
451 if (fontmod->screenSansCO->text(i) == sans) {
452 fontmod->screenSansCO->setCurrentItem(i);
457 for (int i = 0; i < fontmod->screenTypewriterCO->count(); ++i) {
458 if (fontmod->screenTypewriterCO->text(i) == typewriter) {
459 fontmod->screenTypewriterCO->setCurrentItem(i);
464 // Fucked if I know why we need this. But we do
465 dialog_->select_roman(roman);
466 dialog_->select_sans(sans);
467 dialog_->select_typewriter(typewriter);
469 fontmod->screenZoomSB->setValue(rc.zoom);
470 fontmod->screenDpiSB->setValue(int(rc.dpi));
471 fontmod->screenTinyED->setText(tostr(rc.font_sizes[LyXFont::SIZE_TINY]).c_str());
472 fontmod->screenSmallestED->setText(tostr(rc.font_sizes[LyXFont::SIZE_SCRIPT]).c_str());
473 fontmod->screenSmallerED->setText(tostr(rc.font_sizes[LyXFont::SIZE_FOOTNOTE]).c_str());
474 fontmod->screenSmallED->setText(tostr(rc.font_sizes[LyXFont::SIZE_SMALL]).c_str());
475 fontmod->screenNormalED->setText(tostr(rc.font_sizes[LyXFont::SIZE_NORMAL]).c_str());
476 fontmod->screenLargeED->setText(tostr(rc.font_sizes[LyXFont::SIZE_LARGE]).c_str());
477 fontmod->screenLargerED->setText(tostr(rc.font_sizes[LyXFont::SIZE_LARGER]).c_str());
478 fontmod->screenLargestED->setText(tostr(rc.font_sizes[LyXFont::SIZE_LARGEST]).c_str());
479 fontmod->screenHugeED->setText(tostr(rc.font_sizes[LyXFont::SIZE_HUGE]).c_str());
480 fontmod->screenHugerED->setText(tostr(rc.font_sizes[LyXFont::SIZE_HUGER]).c_str());
484 dialog_->updateFormats();
486 converters_ = converters;
488 dialog_->updateConverters();