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>
47 typedef Qt2CB<ControlPrefs, Qt2DB<QPrefsDialog> > base_class;
51 : base_class(_("LyX: Preferences"))
56 void QPrefs::build_dialog()
58 dialog_.reset(new QPrefsDialog(this));
60 bc().setOK(dialog_->savePB);
61 bc().setApply(dialog_->applyPB);
62 bc().setCancel(dialog_->closePB);
63 bc().setRestore(dialog_->restorePB);
65 QPrefLanguageModule * langmod(dialog_->languageModule);
67 langmod->defaultLanguageCO->clear();
68 // store the lang identifiers for later
69 vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
70 lang_ = getSecond(langs);
72 vector<frnt::LanguagePair>::const_iterator lit = langs.begin();
73 vector<frnt::LanguagePair>::const_iterator lend = langs.end();
74 for (; lit != lend; ++lit) {
75 langmod->defaultLanguageCO->insertItem(lit->first.c_str());
82 LyXRC & rc(controller().rc());
86 QPrefLanguageModule * langmod(dialog_->languageModule);
88 // FIXME: remove rtl_support bool
89 rc.rtl_support = langmod->rtlCB->isChecked();
90 rc.mark_foreign_language = langmod->markForeignCB->isChecked();
91 rc.language_auto_begin = langmod->autoBeginCB->isChecked();
92 rc.language_auto_end = langmod->autoEndCB->isChecked();
93 rc.language_use_babel = langmod->useBabelCB->isChecked();
94 rc.language_global_options = langmod->globalCB->isChecked();
95 rc.language_package = langmod->languagePackageED->text().latin1();
96 rc.language_command_begin = langmod->startCommandED->text().latin1();
97 rc.language_command_end = langmod->endCommandED->text().latin1();
98 rc.default_language = lang_[langmod->defaultLanguageCO->currentItem()];
100 QPrefUIModule * uimod(dialog_->uiModule);
102 rc.bind_file = uimod->uiFileED->text().latin1();
103 rc.ui_file = uimod->bindFileED->text().latin1();
104 rc.cursor_follows_scrollbar = uimod->cursorFollowsCB->isChecked();
105 rc.wheel_jump = uimod->wheelMouseSB->value();
106 rc.autosave = uimod->autoSaveSB->value() * 60;
107 rc.make_backup = uimod->autoSaveCB->isChecked();
108 rc.num_lastfiles = uimod->lastfilesSB->value();
111 QPrefKeyboardModule * keymod(dialog_->keyboardModule);
113 // FIXME: can derive CB from the two EDs
114 rc.use_kbmap = keymod->keymapCB->isChecked();
115 rc.primary_kbmap = keymod->firstKeymapED->text().latin1();
116 rc.secondary_kbmap = keymod->secondKeymapED->text().latin1();
119 QPrefAsciiModule * ascmod(dialog_->asciiModule);
121 rc.ascii_linelen = ascmod->asciiLinelengthSB->value();
122 rc.ascii_roff_command = ascmod->asciiRoffED->text().latin1();
125 QPrefDateModule * datemod(dialog_->dateModule);
127 rc.date_insert_format = datemod->DateED->text().latin1();
130 QPrefLatexModule * latexmod(dialog_->latexModule);
132 rc.fontenc = latexmod->latexEncodingED->text().latin1();
133 rc.chktex_command = latexmod->latexChecktexED->text().latin1();
134 rc.auto_reset_options = latexmod->latexAutoresetCB->isChecked();
135 rc.view_dvi_paper_option = latexmod->latexDviPaperED->text().latin1();
136 rc.default_papersize =
137 static_cast<BufferParams::PAPER_SIZE>(latexmod->latexPaperSizeCO->currentItem());
140 QPrefDisplayModule * displaymod(dialog_->displayModule);
142 rc.preview = displaymod->previewCB->isChecked();
144 grfx::DisplayType dtype(grfx::ColorDisplay);
146 switch (displaymod->displayGraphicsCO->currentItem()) {
147 case 3: dtype = grfx::NoDisplay; break;
148 case 2: dtype = grfx::ColorDisplay; break;
149 case 1: dtype = grfx::GrayscaleDisplay; break;
150 case 0: dtype = grfx::MonochromeDisplay; break;
152 rc.display_graphics = dtype;
155 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
158 if (old_value != rc.display_graphics) {
159 grfx::GCache & gc = grfx::GCache::get();
164 QPrefPathsModule * pathsmod(dialog_->pathsModule);
166 rc.document_path = pathsmod->workingDirED->text().latin1();
167 rc.template_path = pathsmod->templateDirED->text().latin1();
168 rc.backupdir_path = pathsmod->backupDirED->text().latin1();
169 rc.use_tempdir = pathsmod->tempDirCB->isChecked();
170 rc.tempdir_path = pathsmod->tempDirED->text().latin1();
171 // FIXME: should be a checkbox only
172 rc.lyxpipes = pathsmod->lyxserverDirED->text().latin1();
175 QPrefSpellcheckerModule * spellmod(dialog_->spellcheckerModule);
177 if (spellmod->spellCommandCO->currentItem() == 0)
178 rc.isp_command = "ispell";
180 rc.isp_command = "aspell";
182 // FIXME: remove isp_use_alt_lang
183 rc.isp_alt_lang = spellmod->altLanguageED->text().latin1();
184 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
185 // FIXME: remove isp_use_esc_chars
186 rc.isp_esc_chars = spellmod->escapeCharactersED->text().latin1();
187 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
188 // FIXME: remove isp_use_pers_dict
189 rc.isp_pers_dict = spellmod->persDictionaryED->text().latin1();
190 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
191 rc.isp_accept_compound = spellmod->compoundWordCB->isChecked();
192 rc.isp_use_input_encoding = spellmod->inputEncodingCB->isChecked();
195 QPrefPrinterModule * printmod(dialog_->printerModule);
197 rc.print_adapt_output = printmod->printerAdaptCB->isChecked();
198 rc.print_command = printmod->printerCommandED->text().latin1();
199 rc.printer = printmod->printerNameED->text().latin1();
201 rc.print_pagerange_flag = printmod->printerPageRangeED->text().latin1();
202 rc.print_copies_flag = printmod->printerCopiesED->text().latin1();
203 rc.print_reverse_flag = printmod->printerReverseED->text().latin1();
204 rc.print_to_printer = printmod->printerToPrinterED->text().latin1();
205 rc.print_file_extension = printmod->printerExtensionED->text().latin1();
206 rc.print_file_extension = printmod->printerSpoolCommandED->text().latin1();
207 rc.print_paper_flag = printmod->printerPaperTypeED->text().latin1();
208 rc.print_evenpage_flag = printmod->printerEvenED->text().latin1();
209 rc.print_oddpage_flag = printmod->printerOddED->text().latin1();
210 rc.print_collcopies_flag = printmod->printerCollatedED->text().latin1();
211 rc.print_landscape_flag = printmod->printerLandscapeED->text().latin1();
212 rc.print_to_file = printmod->printerToFileED->text().latin1();
213 rc.print_extra_options = printmod->printerExtraED->text().latin1();
214 rc.print_spool_printerprefix = printmod->printerSpoolPrefixED->text().latin1();
215 rc.print_paper_dimension_flag = printmod->printerPaperSizeED->text().latin1();
218 QPrefScreenFontsModule * fontmod(dialog_->screenfontsModule);
220 LyXRC const oldrc(rc);
222 rc.roman_font_name = fontmod->screenRomanED->text().latin1();
223 rc.sans_font_name = fontmod->screenSansED->text().latin1();
224 rc.typewriter_font_name = fontmod->screenTypewriterED->text().latin1();
225 rc.zoom = fontmod->screenZoomSB->value();
226 rc.dpi = fontmod->screenDpiSB->value();
227 rc.font_sizes[LyXFont::SIZE_TINY] = strToDbl(fontmod->screenTinyED->text().latin1());
228 rc.font_sizes[LyXFont::SIZE_SCRIPT] = strToDbl(fontmod->screenSmallestED->text().latin1());
229 rc.font_sizes[LyXFont::SIZE_FOOTNOTE] = strToDbl(fontmod->screenSmallerED->text().latin1());
230 rc.font_sizes[LyXFont::SIZE_SMALL] = strToDbl(fontmod->screenSmallED->text().latin1());
231 rc.font_sizes[LyXFont::SIZE_NORMAL] = strToDbl(fontmod->screenNormalED->text().latin1());
232 rc.font_sizes[LyXFont::SIZE_LARGE] = strToDbl(fontmod->screenLargeED->text().latin1());
233 rc.font_sizes[LyXFont::SIZE_LARGER] = strToDbl(fontmod->screenLargerED->text().latin1());
234 rc.font_sizes[LyXFont::SIZE_LARGEST] = strToDbl(fontmod->screenLargestED->text().latin1());
235 rc.font_sizes[LyXFont::SIZE_HUGE] = strToDbl(fontmod->screenHugeED->text().latin1());
236 rc.font_sizes[LyXFont::SIZE_HUGER] = strToDbl(fontmod->screenHugerED->text().latin1());
238 if (rc.font_sizes != oldrc.font_sizes
239 || rc.roman_font_name != oldrc.roman_font_name
240 || rc.sans_font_name != oldrc.sans_font_name
241 || rc.typewriter_font_name != oldrc.typewriter_font_name
242 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
243 controller().updateScreenFonts();
246 // FIXME: here we read new converters/ formats
248 controller().setConverters(converters_);
249 controller().setFormats(formats_);
251 // FIXME: controller().setColor(lc, hexname)
255 // FIXME: move to helper_funcs.h
259 typename std::vector<A>::size_type
260 findPos(std::vector<A> const & vec, A const & val)
262 typename std::vector<A>::const_iterator it =
263 std::find(vec.begin(), vec.end(), val);
266 return std::distance(vec.begin(), it);
271 void QPrefs::update_contents()
273 LyXRC const & rc(controller().rc());
275 QPrefLanguageModule * langmod(dialog_->languageModule);
277 // FIXME: remove rtl_support bool
278 langmod->rtlCB->setChecked(rc.rtl_support);
279 langmod->markForeignCB->setChecked(rc.mark_foreign_language);
280 langmod->autoBeginCB->setChecked(rc.language_auto_begin);
281 langmod->autoEndCB->setChecked(rc.language_auto_end);
282 langmod->useBabelCB->setChecked(rc.language_use_babel);
283 langmod->globalCB->setChecked(rc.language_global_options);
284 langmod->languagePackageED->setText(rc.language_package.c_str());
285 langmod->startCommandED->setText(rc.language_command_begin.c_str());
286 langmod->endCommandED->setText(rc.language_command_end.c_str());
288 int const pos = int(findPos(lang_, rc.default_language));
289 langmod->defaultLanguageCO->setCurrentItem(pos);
291 QPrefUIModule * uimod(dialog_->uiModule);
293 uimod->uiFileED->setText(rc.bind_file.c_str());
294 uimod->bindFileED->setText(rc.ui_file.c_str());
295 uimod->cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
296 uimod->wheelMouseSB->setValue(rc.wheel_jump);
297 // convert to minutes
298 int mins(rc.autosave / 60);
299 if (rc.autosave && !mins)
301 uimod->autoSaveSB->setValue(mins);
302 uimod->autoSaveCB->setChecked(rc.make_backup);
303 uimod->lastfilesSB->setValue(rc.num_lastfiles);
306 QPrefKeyboardModule * keymod(dialog_->keyboardModule);
308 // FIXME: can derive CB from the two EDs
309 keymod->keymapCB->setChecked(rc.use_kbmap);
310 keymod->firstKeymapED->setText(rc.primary_kbmap.c_str());
311 keymod->secondKeymapED->setText(rc.secondary_kbmap.c_str());
314 QPrefAsciiModule * ascmod(dialog_->asciiModule);
316 ascmod->asciiLinelengthSB->setValue(rc.ascii_linelen);
317 ascmod->asciiRoffED->setText(rc.ascii_roff_command.c_str());
320 QPrefDateModule * datemod(dialog_->dateModule);
322 datemod->DateED->setText(rc.date_insert_format.c_str());
325 QPrefLatexModule * latexmod(dialog_->latexModule);
327 latexmod->latexEncodingED->setText(rc.fontenc.c_str());
328 latexmod->latexChecktexED->setText(rc.chktex_command.c_str());
329 latexmod->latexAutoresetCB->setChecked(rc.auto_reset_options);
330 latexmod->latexDviPaperED->setText(rc.view_dvi_paper_option.c_str());
331 latexmod->latexPaperSizeCO->setCurrentItem(rc.default_papersize);
334 QPrefDisplayModule * displaymod(dialog_->displayModule);
336 displaymod->previewCB->setChecked(rc.preview);
340 switch (rc.display_graphics) {
341 case grfx::NoDisplay: item = 3; break;
342 case grfx::ColorDisplay: item = 2; break;
343 case grfx::GrayscaleDisplay: item = 1; break;
344 case grfx::MonochromeDisplay: item = 0; break;
346 displaymod->displayGraphicsCO->setCurrentItem(item);
349 QPrefPathsModule * pathsmod(dialog_->pathsModule);
351 pathsmod->workingDirED->setText(rc.document_path.c_str());
352 pathsmod->templateDirED->setText(rc.template_path.c_str());
353 pathsmod->backupDirED->setText(rc.backupdir_path.c_str());
354 pathsmod->tempDirCB->setChecked(rc.use_tempdir);
355 pathsmod->tempDirED->setText(rc.tempdir_path.c_str());
356 // FIXME: should be a checkbox only
357 pathsmod->lyxserverDirED->setText(rc.lyxpipes.c_str());
360 QPrefSpellcheckerModule * spellmod(dialog_->spellcheckerModule);
362 item = (rc.isp_command == "ispell") ? 0 : 1;
363 spellmod->spellCommandCO->setCurrentItem(item);
364 // FIXME: remove isp_use_alt_lang
365 spellmod->altLanguageED->setText(rc.isp_alt_lang.c_str());
366 // FIXME: remove isp_use_esc_chars
367 spellmod->escapeCharactersED->setText(rc.isp_esc_chars.c_str());
368 // FIXME: remove isp_use_pers_dict
369 spellmod->persDictionaryED->setText(rc.isp_pers_dict.c_str());
370 spellmod->compoundWordCB->setChecked(rc.isp_accept_compound);
371 spellmod->inputEncodingCB->setChecked(rc.isp_use_input_encoding);
374 QPrefPrinterModule * printmod(dialog_->printerModule);
376 printmod->printerAdaptCB->setChecked(rc.print_adapt_output);
377 printmod->printerCommandED->setText(rc.print_command.c_str());
378 printmod->printerNameED->setText(rc.printer.c_str());
380 printmod->printerPageRangeED->setText(rc.print_pagerange_flag.c_str());
381 printmod->printerCopiesED->setText(rc.print_copies_flag.c_str());
382 printmod->printerReverseED->setText(rc.print_reverse_flag.c_str());
383 printmod->printerToPrinterED->setText(rc.print_to_printer.c_str());
384 printmod->printerExtensionED->setText(rc.print_file_extension.c_str());
385 printmod->printerSpoolCommandED->setText(rc.print_file_extension.c_str());
386 printmod->printerPaperTypeED->setText(rc.print_paper_flag.c_str());
387 printmod->printerEvenED->setText(rc.print_evenpage_flag.c_str());
388 printmod->printerOddED->setText(rc.print_oddpage_flag.c_str());
389 printmod->printerCollatedED->setText(rc.print_collcopies_flag.c_str());
390 printmod->printerLandscapeED->setText(rc.print_landscape_flag.c_str());
391 printmod->printerToFileED->setText(rc.print_to_file.c_str());
392 printmod->printerExtraED->setText(rc.print_extra_options.c_str());
393 printmod->printerSpoolPrefixED->setText(rc.print_spool_printerprefix.c_str());
394 printmod->printerPaperSizeED->setText(rc.print_paper_dimension_flag.c_str());
397 QPrefScreenFontsModule * fontmod(dialog_->screenfontsModule);
399 fontmod->screenRomanED->setText(rc.roman_font_name.c_str());
400 fontmod->screenSansED->setText(rc.sans_font_name.c_str());
401 fontmod->screenTypewriterED->setText(rc.typewriter_font_name.c_str());
402 fontmod->screenZoomSB->setValue(rc.zoom);
403 fontmod->screenDpiSB->setValue(int(rc.dpi));
404 fontmod->screenTinyED->setText(tostr(rc.font_sizes[LyXFont::SIZE_TINY]).c_str());
405 fontmod->screenSmallestED->setText(tostr(rc.font_sizes[LyXFont::SIZE_SCRIPT]).c_str());
406 fontmod->screenSmallerED->setText(tostr(rc.font_sizes[LyXFont::SIZE_FOOTNOTE]).c_str());
407 fontmod->screenSmallED->setText(tostr(rc.font_sizes[LyXFont::SIZE_SMALL]).c_str());
408 fontmod->screenNormalED->setText(tostr(rc.font_sizes[LyXFont::SIZE_NORMAL]).c_str());
409 fontmod->screenLargeED->setText(tostr(rc.font_sizes[LyXFont::SIZE_LARGE]).c_str());
410 fontmod->screenLargerED->setText(tostr(rc.font_sizes[LyXFont::SIZE_LARGER]).c_str());
411 fontmod->screenLargestED->setText(tostr(rc.font_sizes[LyXFont::SIZE_LARGEST]).c_str());
412 fontmod->screenHugeED->setText(tostr(rc.font_sizes[LyXFont::SIZE_HUGE]).c_str());
413 fontmod->screenHugerED->setText(tostr(rc.font_sizes[LyXFont::SIZE_HUGER]).c_str());
415 converters_ = converters;
418 // FIXME: populate converters/formats
420 // FIXME: populate colors