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"
42 #include "qt_helpers.h"
45 #include <boost/tuple/tuple.hpp>
47 #include <qpushbutton.h>
48 #include <qcheckbox.h>
49 #include <qlineedit.h>
51 #include <qcombobox.h>
54 #include "qcoloritem.h"
58 using std::ostringstream;
63 typedef Qt2CB<ControlPrefs, Qt2DB<QPrefsDialog> > base_class;
67 : base_class(_("LyX: Preferences"))
72 void QPrefs::build_dialog()
74 dialog_.reset(new QPrefsDialog(this));
76 bc().setOK(dialog_->savePB);
77 bc().setApply(dialog_->applyPB);
78 bc().setCancel(dialog_->closePB);
79 bc().setRestore(dialog_->restorePB);
81 QPrefLanguageModule * langmod(dialog_->languageModule);
83 langmod->defaultLanguageCO->clear();
84 // store the lang identifiers for later
85 vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
86 lang_ = getSecond(langs);
88 vector<frnt::LanguagePair>::const_iterator lit = langs.begin();
89 vector<frnt::LanguagePair>::const_iterator lend = langs.end();
90 for (; lit != lend; ++lit) {
91 langmod->defaultLanguageCO->insertItem(lit->first.c_str());
98 LyXRC & rc(controller().rc());
102 QPrefLanguageModule * langmod(dialog_->languageModule);
104 // FIXME: remove rtl_support bool
105 rc.rtl_support = langmod->rtlCB->isChecked();
106 rc.mark_foreign_language = langmod->markForeignCB->isChecked();
107 rc.language_auto_begin = langmod->autoBeginCB->isChecked();
108 rc.language_auto_end = langmod->autoEndCB->isChecked();
109 rc.language_use_babel = langmod->useBabelCB->isChecked();
110 rc.language_global_options = langmod->globalCB->isChecked();
111 rc.language_package = langmod->languagePackageED->text().latin1();
112 rc.language_command_begin = langmod->startCommandED->text().latin1();
113 rc.language_command_end = langmod->endCommandED->text().latin1();
114 rc.default_language = lang_[langmod->defaultLanguageCO->currentItem()];
116 QPrefUIModule * uimod(dialog_->uiModule);
118 rc.ui_file = uimod->uiFileED->text().latin1();
119 rc.bind_file = uimod->bindFileED->text().latin1();
120 rc.cursor_follows_scrollbar = uimod->cursorFollowsCB->isChecked();
121 rc.wheel_jump = uimod->wheelMouseSB->value();
122 rc.autosave = uimod->autoSaveSB->value() * 60;
123 rc.make_backup = uimod->autoSaveCB->isChecked();
124 rc.num_lastfiles = uimod->lastfilesSB->value();
127 QPrefKeyboardModule * keymod(dialog_->keyboardModule);
129 // FIXME: can derive CB from the two EDs
130 rc.use_kbmap = keymod->keymapCB->isChecked();
131 rc.primary_kbmap = keymod->firstKeymapED->text().latin1();
132 rc.secondary_kbmap = keymod->secondKeymapED->text().latin1();
135 QPrefAsciiModule * ascmod(dialog_->asciiModule);
137 rc.ascii_linelen = ascmod->asciiLinelengthSB->value();
138 rc.ascii_roff_command = ascmod->asciiRoffED->text().latin1();
141 QPrefDateModule * datemod(dialog_->dateModule);
143 rc.date_insert_format = datemod->DateED->text().latin1();
146 QPrefLatexModule * latexmod(dialog_->latexModule);
148 rc.fontenc = latexmod->latexEncodingED->text().latin1();
149 rc.chktex_command = latexmod->latexChecktexED->text().latin1();
150 rc.auto_reset_options = latexmod->latexAutoresetCB->isChecked();
151 rc.view_dvi_paper_option = latexmod->latexDviPaperED->text().latin1();
152 rc.default_papersize =
153 static_cast<BufferParams::PAPER_SIZE>(latexmod->latexPaperSizeCO->currentItem());
156 QPrefDisplayModule * displaymod(dialog_->displayModule);
158 rc.preview = displaymod->previewCB->isChecked();
160 grfx::DisplayType dtype(grfx::ColorDisplay);
162 switch (displaymod->displayGraphicsCO->currentItem()) {
163 case 3: dtype = grfx::NoDisplay; break;
164 case 2: dtype = grfx::ColorDisplay; break;
165 case 1: dtype = grfx::GrayscaleDisplay; break;
166 case 0: dtype = grfx::MonochromeDisplay; break;
168 rc.display_graphics = dtype;
171 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
174 if (old_value != rc.display_graphics) {
175 grfx::GCache & gc = grfx::GCache::get();
180 QPrefPathsModule * pathsmod(dialog_->pathsModule);
182 rc.document_path = pathsmod->workingDirED->text().latin1();
183 rc.template_path = pathsmod->templateDirED->text().latin1();
184 rc.backupdir_path = pathsmod->backupDirED->text().latin1();
185 rc.use_tempdir = pathsmod->tempDirCB->isChecked();
186 rc.tempdir_path = pathsmod->tempDirED->text().latin1();
187 // FIXME: should be a checkbox only
188 rc.lyxpipes = pathsmod->lyxserverDirED->text().latin1();
191 QPrefSpellcheckerModule * spellmod(dialog_->spellcheckerModule);
193 if (spellmod->spellCommandCO->currentItem() == 0)
194 rc.isp_command = "ispell";
196 rc.isp_command = "aspell";
198 // FIXME: remove isp_use_alt_lang
199 rc.isp_alt_lang = spellmod->altLanguageED->text().latin1();
200 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
201 // FIXME: remove isp_use_esc_chars
202 rc.isp_esc_chars = spellmod->escapeCharactersED->text().latin1();
203 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
204 // FIXME: remove isp_use_pers_dict
205 rc.isp_pers_dict = spellmod->persDictionaryED->text().latin1();
206 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
207 rc.isp_accept_compound = spellmod->compoundWordCB->isChecked();
208 rc.isp_use_input_encoding = spellmod->inputEncodingCB->isChecked();
211 QPrefPrinterModule * printmod(dialog_->printerModule);
213 rc.print_adapt_output = printmod->printerAdaptCB->isChecked();
214 rc.print_command = printmod->printerCommandED->text().latin1();
215 rc.printer = printmod->printerNameED->text().latin1();
217 rc.print_pagerange_flag = printmod->printerPageRangeED->text().latin1();
218 rc.print_copies_flag = printmod->printerCopiesED->text().latin1();
219 rc.print_reverse_flag = printmod->printerReverseED->text().latin1();
220 rc.print_to_printer = printmod->printerToPrinterED->text().latin1();
221 rc.print_file_extension = printmod->printerExtensionED->text().latin1();
222 rc.print_file_extension = printmod->printerSpoolCommandED->text().latin1();
223 rc.print_paper_flag = printmod->printerPaperTypeED->text().latin1();
224 rc.print_evenpage_flag = printmod->printerEvenED->text().latin1();
225 rc.print_oddpage_flag = printmod->printerOddED->text().latin1();
226 rc.print_collcopies_flag = printmod->printerCollatedED->text().latin1();
227 rc.print_landscape_flag = printmod->printerLandscapeED->text().latin1();
228 rc.print_to_file = printmod->printerToFileED->text().latin1();
229 rc.print_extra_options = printmod->printerExtraED->text().latin1();
230 rc.print_spool_printerprefix = printmod->printerSpoolPrefixED->text().latin1();
231 rc.print_paper_dimension_flag = printmod->printerPaperSizeED->text().latin1();
234 QPrefScreenFontsModule * fontmod(dialog_->screenfontsModule);
236 LyXRC const oldrc(rc);
238 boost::tie(rc.roman_font_name, rc.roman_font_foundry)
239 = parseFontName(fontmod->screenRomanCO->currentText().latin1());
240 boost::tie(rc.sans_font_name, rc.sans_font_foundry) =
241 parseFontName(fontmod->screenSansCO->currentText().latin1());
242 boost::tie(rc.typewriter_font_name, rc.typewriter_font_foundry) =
243 parseFontName(fontmod->screenTypewriterCO->currentText().latin1());
245 rc.zoom = fontmod->screenZoomSB->value();
246 rc.dpi = fontmod->screenDpiSB->value();
247 rc.font_sizes[LyXFont::SIZE_TINY] = strToDbl(fontmod->screenTinyED->text().latin1());
248 rc.font_sizes[LyXFont::SIZE_SCRIPT] = strToDbl(fontmod->screenSmallestED->text().latin1());
249 rc.font_sizes[LyXFont::SIZE_FOOTNOTE] = strToDbl(fontmod->screenSmallerED->text().latin1());
250 rc.font_sizes[LyXFont::SIZE_SMALL] = strToDbl(fontmod->screenSmallED->text().latin1());
251 rc.font_sizes[LyXFont::SIZE_NORMAL] = strToDbl(fontmod->screenNormalED->text().latin1());
252 rc.font_sizes[LyXFont::SIZE_LARGE] = strToDbl(fontmod->screenLargeED->text().latin1());
253 rc.font_sizes[LyXFont::SIZE_LARGER] = strToDbl(fontmod->screenLargerED->text().latin1());
254 rc.font_sizes[LyXFont::SIZE_LARGEST] = strToDbl(fontmod->screenLargestED->text().latin1());
255 rc.font_sizes[LyXFont::SIZE_HUGE] = strToDbl(fontmod->screenHugeED->text().latin1());
256 rc.font_sizes[LyXFont::SIZE_HUGER] = strToDbl(fontmod->screenHugerED->text().latin1());
258 if (rc.font_sizes != oldrc.font_sizes
259 || rc.roman_font_name != oldrc.roman_font_name
260 || rc.sans_font_name != oldrc.sans_font_name
261 || rc.typewriter_font_name != oldrc.typewriter_font_name
262 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
263 controller().updateScreenFonts();
266 controller().setConverters(converters_);
267 controller().setFormats(formats_);
269 QPrefColorsModule * colmod(dialog_->colorsModule);
273 for (i = 0; i < colmod->lyxObjectsLB->count(); ++i) {
274 QListBoxItem * ib(colmod->lyxObjectsLB->item(i));
275 QColorItem * ci(static_cast<QColorItem*>(ib));
279 ostr << '#' << std::setbase(16) << setfill('0')
280 << setw(2) << ci->color().red()
281 << setw(2) << ci->color().green()
282 << setw(2) << ci->color().blue();
284 string newhex(STRCONV(ostr.str()));
286 LColor::color col(dialog_->colors_[i]);
288 // FIXME: dubious, but it's what xforms does
289 if (lcolor.getX11Name(col) != newhex) {
290 controller().setColor(col, newhex);
296 // FIXME: move to helper_funcs.h
300 typename std::vector<A>::size_type
301 findPos(std::vector<A> const & vec, A const & val)
303 typename std::vector<A>::const_iterator it =
304 std::find(vec.begin(), vec.end(), val);
307 return std::distance(vec.begin(), it);
310 void setComboxFont(QComboBox * cb,
311 string const & family, string const & foundry)
314 string const name = makeFontName(family, foundry);
315 for (int i = 0; i < cb->count(); ++i) {
316 if (compare_no_case(cb->text(i).latin1(), name) == 0) {
317 cb->setCurrentItem(i);
322 // Try matching without foundary name
323 for (int i = cb->count() - 1; i >= 0; --i) {
324 // We count in reverse in order to prefer the Xft foundry
325 pair<string, string> tmp = parseFontName(cb->text(i).latin1());
326 if (compare_no_case(tmp.first, family) == 0) {
327 cb->setCurrentItem(i);
335 void QPrefs::update_contents()
337 LyXRC const & rc(controller().rc());
339 QPrefLanguageModule * langmod(dialog_->languageModule);
341 // FIXME: remove rtl_support bool
342 langmod->rtlCB->setChecked(rc.rtl_support);
343 langmod->markForeignCB->setChecked(rc.mark_foreign_language);
344 langmod->autoBeginCB->setChecked(rc.language_auto_begin);
345 langmod->autoEndCB->setChecked(rc.language_auto_end);
346 langmod->useBabelCB->setChecked(rc.language_use_babel);
347 langmod->globalCB->setChecked(rc.language_global_options);
348 langmod->languagePackageED->setText(rc.language_package.c_str());
349 langmod->startCommandED->setText(rc.language_command_begin.c_str());
350 langmod->endCommandED->setText(rc.language_command_end.c_str());
352 int const pos = int(findPos(lang_, rc.default_language));
353 langmod->defaultLanguageCO->setCurrentItem(pos);
355 QPrefUIModule * uimod(dialog_->uiModule);
357 uimod->uiFileED->setText(rc.ui_file.c_str());
358 uimod->bindFileED->setText(rc.bind_file.c_str());
359 uimod->cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
360 uimod->wheelMouseSB->setValue(rc.wheel_jump);
361 // convert to minutes
362 int mins(rc.autosave / 60);
363 if (rc.autosave && !mins)
365 uimod->autoSaveSB->setValue(mins);
366 uimod->autoSaveCB->setChecked(rc.make_backup);
367 uimod->lastfilesSB->setValue(rc.num_lastfiles);
370 QPrefKeyboardModule * keymod(dialog_->keyboardModule);
372 // FIXME: can derive CB from the two EDs
373 keymod->keymapCB->setChecked(rc.use_kbmap);
374 // no idea why we need these. Fscking Qt.
375 keymod->firstKeymapED->setEnabled(rc.use_kbmap);
376 keymod->firstKeymapPB->setEnabled(rc.use_kbmap);
377 keymod->firstKeymapLA->setEnabled(rc.use_kbmap);
378 keymod->secondKeymapED->setEnabled(rc.use_kbmap);
379 keymod->secondKeymapPB->setEnabled(rc.use_kbmap);
380 keymod->secondKeymapLA->setEnabled(rc.use_kbmap);
381 keymod->firstKeymapED->setText(rc.primary_kbmap.c_str());
382 keymod->secondKeymapED->setText(rc.secondary_kbmap.c_str());
385 QPrefAsciiModule * ascmod(dialog_->asciiModule);
387 ascmod->asciiLinelengthSB->setValue(rc.ascii_linelen);
388 ascmod->asciiRoffED->setText(rc.ascii_roff_command.c_str());
391 QPrefDateModule * datemod(dialog_->dateModule);
393 datemod->DateED->setText(rc.date_insert_format.c_str());
396 QPrefLatexModule * latexmod(dialog_->latexModule);
398 latexmod->latexEncodingED->setText(rc.fontenc.c_str());
399 latexmod->latexChecktexED->setText(rc.chktex_command.c_str());
400 latexmod->latexAutoresetCB->setChecked(rc.auto_reset_options);
401 latexmod->latexDviPaperED->setText(rc.view_dvi_paper_option.c_str());
402 latexmod->latexPaperSizeCO->setCurrentItem(rc.default_papersize);
405 QPrefDisplayModule * displaymod(dialog_->displayModule);
407 displaymod->previewCB->setChecked(rc.preview);
411 switch (rc.display_graphics) {
412 case grfx::NoDisplay: item = 3; break;
413 case grfx::ColorDisplay: item = 2; break;
414 case grfx::GrayscaleDisplay: item = 1; break;
415 case grfx::MonochromeDisplay: item = 0; break;
417 displaymod->displayGraphicsCO->setCurrentItem(item);
420 QPrefPathsModule * pathsmod(dialog_->pathsModule);
422 pathsmod->workingDirED->setText(rc.document_path.c_str());
423 pathsmod->templateDirED->setText(rc.template_path.c_str());
424 pathsmod->backupDirED->setText(rc.backupdir_path.c_str());
425 pathsmod->tempDirCB->setChecked(rc.use_tempdir);
426 pathsmod->tempDirED->setText(rc.tempdir_path.c_str());
427 // FIXME: should be a checkbox only
428 pathsmod->lyxserverDirED->setText(rc.lyxpipes.c_str());
431 QPrefSpellcheckerModule * spellmod(dialog_->spellcheckerModule);
433 item = (rc.isp_command == "ispell") ? 0 : 1;
434 spellmod->spellCommandCO->setCurrentItem(item);
435 // FIXME: remove isp_use_alt_lang
436 spellmod->altLanguageED->setText(rc.isp_alt_lang.c_str());
437 // FIXME: remove isp_use_esc_chars
438 spellmod->escapeCharactersED->setText(rc.isp_esc_chars.c_str());
439 // FIXME: remove isp_use_pers_dict
440 spellmod->persDictionaryED->setText(rc.isp_pers_dict.c_str());
441 spellmod->compoundWordCB->setChecked(rc.isp_accept_compound);
442 spellmod->inputEncodingCB->setChecked(rc.isp_use_input_encoding);
445 QPrefPrinterModule * printmod(dialog_->printerModule);
447 printmod->printerAdaptCB->setChecked(rc.print_adapt_output);
448 printmod->printerCommandED->setText(rc.print_command.c_str());
449 printmod->printerNameED->setText(rc.printer.c_str());
451 printmod->printerPageRangeED->setText(rc.print_pagerange_flag.c_str());
452 printmod->printerCopiesED->setText(rc.print_copies_flag.c_str());
453 printmod->printerReverseED->setText(rc.print_reverse_flag.c_str());
454 printmod->printerToPrinterED->setText(rc.print_to_printer.c_str());
455 printmod->printerExtensionED->setText(rc.print_file_extension.c_str());
456 printmod->printerSpoolCommandED->setText(rc.print_file_extension.c_str());
457 printmod->printerPaperTypeED->setText(rc.print_paper_flag.c_str());
458 printmod->printerEvenED->setText(rc.print_evenpage_flag.c_str());
459 printmod->printerOddED->setText(rc.print_oddpage_flag.c_str());
460 printmod->printerCollatedED->setText(rc.print_collcopies_flag.c_str());
461 printmod->printerLandscapeED->setText(rc.print_landscape_flag.c_str());
462 printmod->printerToFileED->setText(rc.print_to_file.c_str());
463 printmod->printerExtraED->setText(rc.print_extra_options.c_str());
464 printmod->printerSpoolPrefixED->setText(rc.print_spool_printerprefix.c_str());
465 printmod->printerPaperSizeED->setText(rc.print_paper_dimension_flag.c_str());
468 QPrefScreenFontsModule * fontmod(dialog_->screenfontsModule);
470 setComboxFont(fontmod->screenRomanCO,
471 rc.roman_font_name, rc.roman_font_foundry);
472 setComboxFont(fontmod->screenSansCO,
473 rc.sans_font_name, rc.sans_font_foundry);
474 setComboxFont(fontmod->screenTypewriterCO,
475 rc.typewriter_font_name, rc.typewriter_font_foundry);
477 dialog_->select_roman(fontmod->screenRomanCO->currentText());
478 dialog_->select_sans(fontmod->screenSansCO->currentText());
479 dialog_->select_typewriter(fontmod->screenTypewriterCO->currentText());
481 fontmod->screenZoomSB->setValue(rc.zoom);
482 fontmod->screenDpiSB->setValue(int(rc.dpi));
483 fontmod->screenTinyED->setText(tostr(rc.font_sizes[LyXFont::SIZE_TINY]).c_str());
484 fontmod->screenSmallestED->setText(tostr(rc.font_sizes[LyXFont::SIZE_SCRIPT]).c_str());
485 fontmod->screenSmallerED->setText(tostr(rc.font_sizes[LyXFont::SIZE_FOOTNOTE]).c_str());
486 fontmod->screenSmallED->setText(tostr(rc.font_sizes[LyXFont::SIZE_SMALL]).c_str());
487 fontmod->screenNormalED->setText(tostr(rc.font_sizes[LyXFont::SIZE_NORMAL]).c_str());
488 fontmod->screenLargeED->setText(tostr(rc.font_sizes[LyXFont::SIZE_LARGE]).c_str());
489 fontmod->screenLargerED->setText(tostr(rc.font_sizes[LyXFont::SIZE_LARGER]).c_str());
490 fontmod->screenLargestED->setText(tostr(rc.font_sizes[LyXFont::SIZE_LARGEST]).c_str());
491 fontmod->screenHugeED->setText(tostr(rc.font_sizes[LyXFont::SIZE_HUGE]).c_str());
492 fontmod->screenHugerED->setText(tostr(rc.font_sizes[LyXFont::SIZE_HUGER]).c_str());
496 dialog_->updateFormats();
498 converters_ = converters;
500 dialog_->updateConverters();