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>
50 #include "qcoloritem.h"
53 using std::ostringstream;
58 typedef Qt2CB<ControlPrefs, Qt2DB<QPrefsDialog> > base_class;
62 : base_class(_("LyX: Preferences"))
67 void QPrefs::build_dialog()
69 dialog_.reset(new QPrefsDialog(this));
71 bc().setOK(dialog_->savePB);
72 bc().setApply(dialog_->applyPB);
73 bc().setCancel(dialog_->closePB);
74 bc().setRestore(dialog_->restorePB);
76 QPrefLanguageModule * langmod(dialog_->languageModule);
78 langmod->defaultLanguageCO->clear();
79 // store the lang identifiers for later
80 vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
81 lang_ = getSecond(langs);
83 vector<frnt::LanguagePair>::const_iterator lit = langs.begin();
84 vector<frnt::LanguagePair>::const_iterator lend = langs.end();
85 for (; lit != lend; ++lit) {
86 langmod->defaultLanguageCO->insertItem(lit->first.c_str());
93 LyXRC & rc(controller().rc());
97 QPrefLanguageModule * langmod(dialog_->languageModule);
99 // FIXME: remove rtl_support bool
100 rc.rtl_support = langmod->rtlCB->isChecked();
101 rc.mark_foreign_language = langmod->markForeignCB->isChecked();
102 rc.language_auto_begin = langmod->autoBeginCB->isChecked();
103 rc.language_auto_end = langmod->autoEndCB->isChecked();
104 rc.language_use_babel = langmod->useBabelCB->isChecked();
105 rc.language_global_options = langmod->globalCB->isChecked();
106 rc.language_package = langmod->languagePackageED->text().latin1();
107 rc.language_command_begin = langmod->startCommandED->text().latin1();
108 rc.language_command_end = langmod->endCommandED->text().latin1();
109 rc.default_language = lang_[langmod->defaultLanguageCO->currentItem()];
111 QPrefUIModule * uimod(dialog_->uiModule);
113 rc.bind_file = uimod->uiFileED->text().latin1();
114 rc.ui_file = uimod->bindFileED->text().latin1();
115 rc.cursor_follows_scrollbar = uimod->cursorFollowsCB->isChecked();
116 rc.wheel_jump = uimod->wheelMouseSB->value();
117 rc.autosave = uimod->autoSaveSB->value() * 60;
118 rc.make_backup = uimod->autoSaveCB->isChecked();
119 rc.num_lastfiles = uimod->lastfilesSB->value();
122 QPrefKeyboardModule * keymod(dialog_->keyboardModule);
124 // FIXME: can derive CB from the two EDs
125 rc.use_kbmap = keymod->keymapCB->isChecked();
126 rc.primary_kbmap = keymod->firstKeymapED->text().latin1();
127 rc.secondary_kbmap = keymod->secondKeymapED->text().latin1();
130 QPrefAsciiModule * ascmod(dialog_->asciiModule);
132 rc.ascii_linelen = ascmod->asciiLinelengthSB->value();
133 rc.ascii_roff_command = ascmod->asciiRoffED->text().latin1();
136 QPrefDateModule * datemod(dialog_->dateModule);
138 rc.date_insert_format = datemod->DateED->text().latin1();
141 QPrefLatexModule * latexmod(dialog_->latexModule);
143 rc.fontenc = latexmod->latexEncodingED->text().latin1();
144 rc.chktex_command = latexmod->latexChecktexED->text().latin1();
145 rc.auto_reset_options = latexmod->latexAutoresetCB->isChecked();
146 rc.view_dvi_paper_option = latexmod->latexDviPaperED->text().latin1();
147 rc.default_papersize =
148 static_cast<BufferParams::PAPER_SIZE>(latexmod->latexPaperSizeCO->currentItem());
151 QPrefDisplayModule * displaymod(dialog_->displayModule);
153 rc.preview = displaymod->previewCB->isChecked();
155 grfx::DisplayType dtype(grfx::ColorDisplay);
157 switch (displaymod->displayGraphicsCO->currentItem()) {
158 case 3: dtype = grfx::NoDisplay; break;
159 case 2: dtype = grfx::ColorDisplay; break;
160 case 1: dtype = grfx::GrayscaleDisplay; break;
161 case 0: dtype = grfx::MonochromeDisplay; break;
163 rc.display_graphics = dtype;
166 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
169 if (old_value != rc.display_graphics) {
170 grfx::GCache & gc = grfx::GCache::get();
175 QPrefPathsModule * pathsmod(dialog_->pathsModule);
177 rc.document_path = pathsmod->workingDirED->text().latin1();
178 rc.template_path = pathsmod->templateDirED->text().latin1();
179 rc.backupdir_path = pathsmod->backupDirED->text().latin1();
180 rc.use_tempdir = pathsmod->tempDirCB->isChecked();
181 rc.tempdir_path = pathsmod->tempDirED->text().latin1();
182 // FIXME: should be a checkbox only
183 rc.lyxpipes = pathsmod->lyxserverDirED->text().latin1();
186 QPrefSpellcheckerModule * spellmod(dialog_->spellcheckerModule);
188 if (spellmod->spellCommandCO->currentItem() == 0)
189 rc.isp_command = "ispell";
191 rc.isp_command = "aspell";
193 // FIXME: remove isp_use_alt_lang
194 rc.isp_alt_lang = spellmod->altLanguageED->text().latin1();
195 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
196 // FIXME: remove isp_use_esc_chars
197 rc.isp_esc_chars = spellmod->escapeCharactersED->text().latin1();
198 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
199 // FIXME: remove isp_use_pers_dict
200 rc.isp_pers_dict = spellmod->persDictionaryED->text().latin1();
201 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
202 rc.isp_accept_compound = spellmod->compoundWordCB->isChecked();
203 rc.isp_use_input_encoding = spellmod->inputEncodingCB->isChecked();
206 QPrefPrinterModule * printmod(dialog_->printerModule);
208 rc.print_adapt_output = printmod->printerAdaptCB->isChecked();
209 rc.print_command = printmod->printerCommandED->text().latin1();
210 rc.printer = printmod->printerNameED->text().latin1();
212 rc.print_pagerange_flag = printmod->printerPageRangeED->text().latin1();
213 rc.print_copies_flag = printmod->printerCopiesED->text().latin1();
214 rc.print_reverse_flag = printmod->printerReverseED->text().latin1();
215 rc.print_to_printer = printmod->printerToPrinterED->text().latin1();
216 rc.print_file_extension = printmod->printerExtensionED->text().latin1();
217 rc.print_file_extension = printmod->printerSpoolCommandED->text().latin1();
218 rc.print_paper_flag = printmod->printerPaperTypeED->text().latin1();
219 rc.print_evenpage_flag = printmod->printerEvenED->text().latin1();
220 rc.print_oddpage_flag = printmod->printerOddED->text().latin1();
221 rc.print_collcopies_flag = printmod->printerCollatedED->text().latin1();
222 rc.print_landscape_flag = printmod->printerLandscapeED->text().latin1();
223 rc.print_to_file = printmod->printerToFileED->text().latin1();
224 rc.print_extra_options = printmod->printerExtraED->text().latin1();
225 rc.print_spool_printerprefix = printmod->printerSpoolPrefixED->text().latin1();
226 rc.print_paper_dimension_flag = printmod->printerPaperSizeED->text().latin1();
229 QPrefScreenFontsModule * fontmod(dialog_->screenfontsModule);
231 LyXRC const oldrc(rc);
233 rc.roman_font_name = fontmod->screenRomanED->text().latin1();
234 rc.sans_font_name = fontmod->screenSansED->text().latin1();
235 rc.typewriter_font_name = fontmod->screenTypewriterED->text().latin1();
236 rc.zoom = fontmod->screenZoomSB->value();
237 rc.dpi = fontmod->screenDpiSB->value();
238 rc.font_sizes[LyXFont::SIZE_TINY] = strToDbl(fontmod->screenTinyED->text().latin1());
239 rc.font_sizes[LyXFont::SIZE_SCRIPT] = strToDbl(fontmod->screenSmallestED->text().latin1());
240 rc.font_sizes[LyXFont::SIZE_FOOTNOTE] = strToDbl(fontmod->screenSmallerED->text().latin1());
241 rc.font_sizes[LyXFont::SIZE_SMALL] = strToDbl(fontmod->screenSmallED->text().latin1());
242 rc.font_sizes[LyXFont::SIZE_NORMAL] = strToDbl(fontmod->screenNormalED->text().latin1());
243 rc.font_sizes[LyXFont::SIZE_LARGE] = strToDbl(fontmod->screenLargeED->text().latin1());
244 rc.font_sizes[LyXFont::SIZE_LARGER] = strToDbl(fontmod->screenLargerED->text().latin1());
245 rc.font_sizes[LyXFont::SIZE_LARGEST] = strToDbl(fontmod->screenLargestED->text().latin1());
246 rc.font_sizes[LyXFont::SIZE_HUGE] = strToDbl(fontmod->screenHugeED->text().latin1());
247 rc.font_sizes[LyXFont::SIZE_HUGER] = strToDbl(fontmod->screenHugerED->text().latin1());
249 if (rc.font_sizes != oldrc.font_sizes
250 || rc.roman_font_name != oldrc.roman_font_name
251 || rc.sans_font_name != oldrc.sans_font_name
252 || rc.typewriter_font_name != oldrc.typewriter_font_name
253 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
254 controller().updateScreenFonts();
257 controller().setConverters(converters_);
258 controller().setFormats(formats_);
260 QPrefColorsModule * colmod(dialog_->colorsModule);
264 for (i = 0; i < colmod->lyxObjectsLB->count(); ++i) {
265 QListBoxItem * ib(colmod->lyxObjectsLB->item(i));
266 QColorItem * ci(static_cast<QColorItem*>(ib));
270 ostr << "#" << std::setbase(16) << setfill('0')
271 << setw(2) << ci->color().red()
272 << setw(2) << ci->color().green()
273 << setw(2) << ci->color().blue();
275 string newhex(STRCONV(ostr.str()));
277 LColor::color col(dialog_->colors_[i]);
279 // FIXME: dubious, but it's what xforms does
280 if (lcolor.getX11Name(col) != newhex) {
281 controller().setColor(col, newhex);
287 // FIXME: move to helper_funcs.h
291 typename std::vector<A>::size_type
292 findPos(std::vector<A> const & vec, A const & val)
294 typename std::vector<A>::const_iterator it =
295 std::find(vec.begin(), vec.end(), val);
298 return std::distance(vec.begin(), it);
303 void QPrefs::update_contents()
305 LyXRC const & rc(controller().rc());
307 QPrefLanguageModule * langmod(dialog_->languageModule);
309 // FIXME: remove rtl_support bool
310 langmod->rtlCB->setChecked(rc.rtl_support);
311 langmod->markForeignCB->setChecked(rc.mark_foreign_language);
312 langmod->autoBeginCB->setChecked(rc.language_auto_begin);
313 langmod->autoEndCB->setChecked(rc.language_auto_end);
314 langmod->useBabelCB->setChecked(rc.language_use_babel);
315 langmod->globalCB->setChecked(rc.language_global_options);
316 langmod->languagePackageED->setText(rc.language_package.c_str());
317 langmod->startCommandED->setText(rc.language_command_begin.c_str());
318 langmod->endCommandED->setText(rc.language_command_end.c_str());
320 int const pos = int(findPos(lang_, rc.default_language));
321 langmod->defaultLanguageCO->setCurrentItem(pos);
323 QPrefUIModule * uimod(dialog_->uiModule);
325 uimod->uiFileED->setText(rc.bind_file.c_str());
326 uimod->bindFileED->setText(rc.ui_file.c_str());
327 uimod->cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
328 uimod->wheelMouseSB->setValue(rc.wheel_jump);
329 // convert to minutes
330 int mins(rc.autosave / 60);
331 if (rc.autosave && !mins)
333 uimod->autoSaveSB->setValue(mins);
334 uimod->autoSaveCB->setChecked(rc.make_backup);
335 uimod->lastfilesSB->setValue(rc.num_lastfiles);
338 QPrefKeyboardModule * keymod(dialog_->keyboardModule);
340 // FIXME: can derive CB from the two EDs
341 keymod->keymapCB->setChecked(rc.use_kbmap);
342 keymod->firstKeymapED->setText(rc.primary_kbmap.c_str());
343 keymod->secondKeymapED->setText(rc.secondary_kbmap.c_str());
346 QPrefAsciiModule * ascmod(dialog_->asciiModule);
348 ascmod->asciiLinelengthSB->setValue(rc.ascii_linelen);
349 ascmod->asciiRoffED->setText(rc.ascii_roff_command.c_str());
352 QPrefDateModule * datemod(dialog_->dateModule);
354 datemod->DateED->setText(rc.date_insert_format.c_str());
357 QPrefLatexModule * latexmod(dialog_->latexModule);
359 latexmod->latexEncodingED->setText(rc.fontenc.c_str());
360 latexmod->latexChecktexED->setText(rc.chktex_command.c_str());
361 latexmod->latexAutoresetCB->setChecked(rc.auto_reset_options);
362 latexmod->latexDviPaperED->setText(rc.view_dvi_paper_option.c_str());
363 latexmod->latexPaperSizeCO->setCurrentItem(rc.default_papersize);
366 QPrefDisplayModule * displaymod(dialog_->displayModule);
368 displaymod->previewCB->setChecked(rc.preview);
372 switch (rc.display_graphics) {
373 case grfx::NoDisplay: item = 3; break;
374 case grfx::ColorDisplay: item = 2; break;
375 case grfx::GrayscaleDisplay: item = 1; break;
376 case grfx::MonochromeDisplay: item = 0; break;
378 displaymod->displayGraphicsCO->setCurrentItem(item);
381 QPrefPathsModule * pathsmod(dialog_->pathsModule);
383 pathsmod->workingDirED->setText(rc.document_path.c_str());
384 pathsmod->templateDirED->setText(rc.template_path.c_str());
385 pathsmod->backupDirED->setText(rc.backupdir_path.c_str());
386 pathsmod->tempDirCB->setChecked(rc.use_tempdir);
387 pathsmod->tempDirED->setText(rc.tempdir_path.c_str());
388 // FIXME: should be a checkbox only
389 pathsmod->lyxserverDirED->setText(rc.lyxpipes.c_str());
392 QPrefSpellcheckerModule * spellmod(dialog_->spellcheckerModule);
394 item = (rc.isp_command == "ispell") ? 0 : 1;
395 spellmod->spellCommandCO->setCurrentItem(item);
396 // FIXME: remove isp_use_alt_lang
397 spellmod->altLanguageED->setText(rc.isp_alt_lang.c_str());
398 // FIXME: remove isp_use_esc_chars
399 spellmod->escapeCharactersED->setText(rc.isp_esc_chars.c_str());
400 // FIXME: remove isp_use_pers_dict
401 spellmod->persDictionaryED->setText(rc.isp_pers_dict.c_str());
402 spellmod->compoundWordCB->setChecked(rc.isp_accept_compound);
403 spellmod->inputEncodingCB->setChecked(rc.isp_use_input_encoding);
406 QPrefPrinterModule * printmod(dialog_->printerModule);
408 printmod->printerAdaptCB->setChecked(rc.print_adapt_output);
409 printmod->printerCommandED->setText(rc.print_command.c_str());
410 printmod->printerNameED->setText(rc.printer.c_str());
412 printmod->printerPageRangeED->setText(rc.print_pagerange_flag.c_str());
413 printmod->printerCopiesED->setText(rc.print_copies_flag.c_str());
414 printmod->printerReverseED->setText(rc.print_reverse_flag.c_str());
415 printmod->printerToPrinterED->setText(rc.print_to_printer.c_str());
416 printmod->printerExtensionED->setText(rc.print_file_extension.c_str());
417 printmod->printerSpoolCommandED->setText(rc.print_file_extension.c_str());
418 printmod->printerPaperTypeED->setText(rc.print_paper_flag.c_str());
419 printmod->printerEvenED->setText(rc.print_evenpage_flag.c_str());
420 printmod->printerOddED->setText(rc.print_oddpage_flag.c_str());
421 printmod->printerCollatedED->setText(rc.print_collcopies_flag.c_str());
422 printmod->printerLandscapeED->setText(rc.print_landscape_flag.c_str());
423 printmod->printerToFileED->setText(rc.print_to_file.c_str());
424 printmod->printerExtraED->setText(rc.print_extra_options.c_str());
425 printmod->printerSpoolPrefixED->setText(rc.print_spool_printerprefix.c_str());
426 printmod->printerPaperSizeED->setText(rc.print_paper_dimension_flag.c_str());
429 QPrefScreenFontsModule * fontmod(dialog_->screenfontsModule);
431 fontmod->screenRomanED->setText(rc.roman_font_name.c_str());
432 fontmod->screenSansED->setText(rc.sans_font_name.c_str());
433 fontmod->screenTypewriterED->setText(rc.typewriter_font_name.c_str());
434 fontmod->screenZoomSB->setValue(rc.zoom);
435 fontmod->screenDpiSB->setValue(int(rc.dpi));
436 fontmod->screenTinyED->setText(tostr(rc.font_sizes[LyXFont::SIZE_TINY]).c_str());
437 fontmod->screenSmallestED->setText(tostr(rc.font_sizes[LyXFont::SIZE_SCRIPT]).c_str());
438 fontmod->screenSmallerED->setText(tostr(rc.font_sizes[LyXFont::SIZE_FOOTNOTE]).c_str());
439 fontmod->screenSmallED->setText(tostr(rc.font_sizes[LyXFont::SIZE_SMALL]).c_str());
440 fontmod->screenNormalED->setText(tostr(rc.font_sizes[LyXFont::SIZE_NORMAL]).c_str());
441 fontmod->screenLargeED->setText(tostr(rc.font_sizes[LyXFont::SIZE_LARGE]).c_str());
442 fontmod->screenLargerED->setText(tostr(rc.font_sizes[LyXFont::SIZE_LARGER]).c_str());
443 fontmod->screenLargestED->setText(tostr(rc.font_sizes[LyXFont::SIZE_LARGEST]).c_str());
444 fontmod->screenHugeED->setText(tostr(rc.font_sizes[LyXFont::SIZE_HUGE]).c_str());
445 fontmod->screenHugerED->setText(tostr(rc.font_sizes[LyXFont::SIZE_HUGER]).c_str());
449 dialog_->updateFormats();
451 converters_ = converters;
453 dialog_->updateConverters();