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 #include "support/lstrings.h"
18 #include "ControlPrefs.h"
19 #include "QPrefsDialog.h"
20 #include "ui/QPrefAsciiModule.h"
21 #include "ui/QPrefDateModule.h"
22 #include "ui/QPrefKeyboardModule.h"
23 #include "ui/QPrefLatexModule.h"
24 #include "ui/QPrefScreenFontsModule.h"
25 #include "ui/QPrefColorsModule.h"
26 #include "ui/QPrefDisplayModule.h"
27 #include "ui/QPrefPathsModule.h"
28 #include "ui/QPrefSpellcheckerModule.h"
29 #include "ui/QPrefConvertersModule.h"
30 #include "ui/QPrefFileformatsModule.h"
31 #include "ui/QPrefLanguageModule.h"
32 #include "ui/QPrefPrinterModule.h"
33 #include "ui/QPrefUIModule.h"
34 #include "ui/QPrefIdentityModule.h"
38 #include "frnt_lang.h"
39 #include "helper_funcs.h"
40 #include "qt_helpers.h"
43 #include <boost/tuple/tuple.hpp>
45 #include <qpushbutton.h>
46 #include <qcheckbox.h>
47 #include <qlineedit.h>
49 #include <qcombobox.h>
52 #include "qcoloritem.h"
56 using std::ostringstream;
61 typedef Qt2CB<ControlPrefs, Qt2DB<QPrefsDialog> > base_class;
65 : base_class(qt_("LyX: Preferences"))
70 void QPrefs::build_dialog()
72 dialog_.reset(new QPrefsDialog(this));
74 bc().setOK(dialog_->savePB);
75 bc().setApply(dialog_->applyPB);
76 bc().setCancel(dialog_->closePB);
77 bc().setRestore(dialog_->restorePB);
79 QPrefLanguageModule * langmod(dialog_->languageModule);
81 langmod->defaultLanguageCO->clear();
82 // store the lang identifiers for later
83 vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
84 lang_ = getSecond(langs);
86 vector<frnt::LanguagePair>::const_iterator lit = langs.begin();
87 vector<frnt::LanguagePair>::const_iterator lend = langs.end();
88 for (; lit != lend; ++lit) {
89 langmod->defaultLanguageCO->insertItem(toqstr(lit->first));
96 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 = fromqstr(langmod->languagePackageED->text());
108 rc.language_command_begin = fromqstr(langmod->startCommandED->text());
109 rc.language_command_end = fromqstr(langmod->endCommandED->text());
110 rc.default_language = lang_[langmod->defaultLanguageCO->currentItem()];
112 QPrefUIModule * uimod(dialog_->uiModule);
114 rc.ui_file = fromqstr(uimod->uiFileED->text());
115 rc.bind_file = fromqstr(uimod->bindFileED->text());
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 = fromqstr(keymod->firstKeymapED->text());
128 rc.secondary_kbmap = fromqstr(keymod->secondKeymapED->text());
131 QPrefAsciiModule * ascmod(dialog_->asciiModule);
133 rc.ascii_linelen = ascmod->asciiLinelengthSB->value();
134 rc.ascii_roff_command = fromqstr(ascmod->asciiRoffED->text());
137 QPrefDateModule * datemod(dialog_->dateModule);
139 rc.date_insert_format = fromqstr(datemod->DateED->text());
142 QPrefLatexModule * latexmod(dialog_->latexModule);
144 rc.fontenc = fromqstr(latexmod->latexEncodingED->text());
145 rc.chktex_command = fromqstr(latexmod->latexChecktexED->text());
146 rc.auto_reset_options = latexmod->latexAutoresetCB->isChecked();
147 rc.view_dvi_paper_option = fromqstr(latexmod->latexDviPaperED->text());
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 = fromqstr(pathsmod->workingDirED->text());
179 rc.template_path = fromqstr(pathsmod->templateDirED->text());
180 rc.backupdir_path = fromqstr(pathsmod->backupDirED->text());
181 rc.use_tempdir = pathsmod->tempDirCB->isChecked();
182 rc.tempdir_path = fromqstr(pathsmod->tempDirED->text());
183 // FIXME: should be a checkbox only
184 rc.lyxpipes = fromqstr(pathsmod->lyxserverDirED->text());
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 = fromqstr(spellmod->altLanguageED->text());
196 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
197 // FIXME: remove isp_use_esc_chars
198 rc.isp_esc_chars = fromqstr(spellmod->escapeCharactersED->text());
199 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
200 // FIXME: remove isp_use_pers_dict
201 rc.isp_pers_dict = fromqstr(spellmod->persDictionaryED->text());
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 = fromqstr(printmod->printerCommandED->text());
211 rc.printer = fromqstr(printmod->printerNameED->text());
213 rc.print_pagerange_flag = fromqstr(printmod->printerPageRangeED->text());
214 rc.print_copies_flag = fromqstr(printmod->printerCopiesED->text());
215 rc.print_reverse_flag = fromqstr(printmod->printerReverseED->text());
216 rc.print_to_printer = fromqstr(printmod->printerToPrinterED->text());
217 rc.print_file_extension = fromqstr(printmod->printerExtensionED->text());
218 rc.print_file_extension = fromqstr(printmod->printerSpoolCommandED->text());
219 rc.print_paper_flag = fromqstr(printmod->printerPaperTypeED->text());
220 rc.print_evenpage_flag = fromqstr(printmod->printerEvenED->text());
221 rc.print_oddpage_flag = fromqstr(printmod->printerOddED->text());
222 rc.print_collcopies_flag = fromqstr(printmod->printerCollatedED->text());
223 rc.print_landscape_flag = fromqstr(printmod->printerLandscapeED->text());
224 rc.print_to_file = fromqstr(printmod->printerToFileED->text());
225 rc.print_extra_options = fromqstr(printmod->printerExtraED->text());
226 rc.print_spool_printerprefix = fromqstr(printmod->printerSpoolPrefixED->text());
227 rc.print_paper_dimension_flag = fromqstr(printmod->printerPaperSizeED->text());
230 QPrefIdentityModule * idmod(dialog_->identityModule);
231 rc.user_name = fromqstr(idmod->nameED->text());
232 rc.user_email = fromqstr(idmod->emailED->text());
234 QPrefScreenFontsModule * fontmod(dialog_->screenfontsModule);
236 LyXRC const oldrc(rc);
238 boost::tie(rc.roman_font_name, rc.roman_font_foundry)
239 = parseFontName(fromqstr(fontmod->screenRomanCO->currentText()));
240 boost::tie(rc.sans_font_name, rc.sans_font_foundry) =
241 parseFontName(fromqstr(fontmod->screenSansCO->currentText()));
242 boost::tie(rc.typewriter_font_name, rc.typewriter_font_foundry) =
243 parseFontName(fromqstr(fontmod->screenTypewriterCO->currentText()));
245 rc.zoom = fontmod->screenZoomSB->value();
246 rc.dpi = fontmod->screenDpiSB->value();
247 rc.font_sizes[LyXFont::SIZE_TINY] = strToDbl(fromqstr(fontmod->screenTinyED->text()));
248 rc.font_sizes[LyXFont::SIZE_SCRIPT] = strToDbl(fromqstr(fontmod->screenSmallestED->text()));
249 rc.font_sizes[LyXFont::SIZE_FOOTNOTE] = strToDbl(fromqstr(fontmod->screenSmallerED->text()));
250 rc.font_sizes[LyXFont::SIZE_SMALL] = strToDbl(fromqstr(fontmod->screenSmallED->text()));
251 rc.font_sizes[LyXFont::SIZE_NORMAL] = strToDbl(fromqstr(fontmod->screenNormalED->text()));
252 rc.font_sizes[LyXFont::SIZE_LARGE] = strToDbl(fromqstr(fontmod->screenLargeED->text()));
253 rc.font_sizes[LyXFont::SIZE_LARGER] = strToDbl(fromqstr(fontmod->screenLargerED->text()));
254 rc.font_sizes[LyXFont::SIZE_LARGEST] = strToDbl(fromqstr(fontmod->screenLargestED->text()));
255 rc.font_sizes[LyXFont::SIZE_HUGE] = strToDbl(fromqstr(fontmod->screenHugeED->text()));
256 rc.font_sizes[LyXFont::SIZE_HUGER] = strToDbl(fromqstr(fontmod->screenHugerED->text()));
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().setFormats(formats_);
267 controller().setConverters(converters_);
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, string const & family,
311 string const & foundry, QFont::StyleHint hint)
313 string const name = makeFontName(family, foundry);
314 for (int i = 0; i < cb->count(); ++i) {
315 if (fromqstr(cb->text(i)) == name) {
316 cb->setCurrentItem(i);
321 // Try matching without foundary name
323 // We count in reverse in order to prefer the Xft foundry
324 for (int i = cb->count() - 1; i >= 0; --i) {
325 pair<string, string> tmp = parseFontName(fromqstr(cb->text(i)));
326 if (compare_no_case(tmp.first, family) == 0) {
327 cb->setCurrentItem(i);
334 font.setStyleHint(hint);
337 for (int i = cb->count() - 1; i >= 0; --i) {
338 if (cb->text(i) == fi.family()) {
339 cb->setCurrentItem(i);
347 void QPrefs::update_contents()
349 LyXRC const & rc(controller().rc());
351 QPrefLanguageModule * langmod(dialog_->languageModule);
353 // FIXME: remove rtl_support bool
354 langmod->rtlCB->setChecked(rc.rtl_support);
355 langmod->markForeignCB->setChecked(rc.mark_foreign_language);
356 langmod->autoBeginCB->setChecked(rc.language_auto_begin);
357 langmod->autoEndCB->setChecked(rc.language_auto_end);
358 langmod->useBabelCB->setChecked(rc.language_use_babel);
359 langmod->globalCB->setChecked(rc.language_global_options);
360 langmod->languagePackageED->setText(toqstr(rc.language_package));
361 langmod->startCommandED->setText(toqstr(rc.language_command_begin));
362 langmod->endCommandED->setText(toqstr(rc.language_command_end));
364 int const pos = int(findPos(lang_, rc.default_language));
365 langmod->defaultLanguageCO->setCurrentItem(pos);
367 QPrefUIModule * uimod(dialog_->uiModule);
369 uimod->uiFileED->setText(toqstr(rc.ui_file));
370 uimod->bindFileED->setText(toqstr(rc.bind_file));
371 uimod->cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
372 uimod->wheelMouseSB->setValue(rc.wheel_jump);
373 // convert to minutes
374 int mins(rc.autosave / 60);
375 if (rc.autosave && !mins)
377 uimod->autoSaveSB->setValue(mins);
378 uimod->autoSaveCB->setChecked(rc.make_backup);
379 uimod->lastfilesSB->setValue(rc.num_lastfiles);
382 QPrefIdentityModule * idmod(dialog_->identityModule);
383 idmod->nameED->setText(toqstr(rc.user_name));
384 idmod->emailED->setText(toqstr(rc.user_email));
387 QPrefKeyboardModule * keymod(dialog_->keyboardModule);
389 // FIXME: can derive CB from the two EDs
390 keymod->keymapCB->setChecked(rc.use_kbmap);
391 // no idea why we need these. Fscking Qt.
392 keymod->firstKeymapED->setEnabled(rc.use_kbmap);
393 keymod->firstKeymapPB->setEnabled(rc.use_kbmap);
394 keymod->firstKeymapLA->setEnabled(rc.use_kbmap);
395 keymod->secondKeymapED->setEnabled(rc.use_kbmap);
396 keymod->secondKeymapPB->setEnabled(rc.use_kbmap);
397 keymod->secondKeymapLA->setEnabled(rc.use_kbmap);
398 keymod->firstKeymapED->setText(toqstr(rc.primary_kbmap));
399 keymod->secondKeymapED->setText(toqstr(rc.secondary_kbmap));
402 QPrefAsciiModule * ascmod(dialog_->asciiModule);
404 ascmod->asciiLinelengthSB->setValue(rc.ascii_linelen);
405 ascmod->asciiRoffED->setText(toqstr(rc.ascii_roff_command));
408 QPrefDateModule * datemod(dialog_->dateModule);
410 datemod->DateED->setText(toqstr(rc.date_insert_format));
413 QPrefLatexModule * latexmod(dialog_->latexModule);
415 latexmod->latexEncodingED->setText(toqstr(rc.fontenc));
416 latexmod->latexChecktexED->setText(toqstr(rc.chktex_command));
417 latexmod->latexAutoresetCB->setChecked(rc.auto_reset_options);
418 latexmod->latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
419 latexmod->latexPaperSizeCO->setCurrentItem(rc.default_papersize);
422 QPrefDisplayModule * displaymod(dialog_->displayModule);
424 displaymod->previewCB->setChecked(rc.preview);
428 switch (rc.display_graphics) {
429 case grfx::NoDisplay: item = 3; break;
430 case grfx::ColorDisplay: item = 2; break;
431 case grfx::GrayscaleDisplay: item = 1; break;
432 case grfx::MonochromeDisplay: item = 0; break;
435 displaymod->displayGraphicsCO->setCurrentItem(item);
438 QPrefPathsModule * pathsmod(dialog_->pathsModule);
440 pathsmod->workingDirED->setText(toqstr(rc.document_path));
441 pathsmod->templateDirED->setText(toqstr(rc.template_path));
442 pathsmod->backupDirED->setText(toqstr(rc.backupdir_path));
443 pathsmod->tempDirCB->setChecked(rc.use_tempdir);
444 pathsmod->tempDirED->setText(toqstr(rc.tempdir_path));
445 // FIXME: should be a checkbox only
446 pathsmod->lyxserverDirED->setText(toqstr(rc.lyxpipes));
449 QPrefSpellcheckerModule * spellmod(dialog_->spellcheckerModule);
451 item = (rc.isp_command == "ispell") ? 0 : 1;
452 spellmod->spellCommandCO->setCurrentItem(item);
453 // FIXME: remove isp_use_alt_lang
454 spellmod->altLanguageED->setText(toqstr(rc.isp_alt_lang));
455 // FIXME: remove isp_use_esc_chars
456 spellmod->escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
457 // FIXME: remove isp_use_pers_dict
458 spellmod->persDictionaryED->setText(toqstr(rc.isp_pers_dict));
459 spellmod->compoundWordCB->setChecked(rc.isp_accept_compound);
460 spellmod->inputEncodingCB->setChecked(rc.isp_use_input_encoding);
463 QPrefPrinterModule * printmod(dialog_->printerModule);
465 printmod->printerAdaptCB->setChecked(rc.print_adapt_output);
466 printmod->printerCommandED->setText(toqstr(rc.print_command));
467 printmod->printerNameED->setText(toqstr(rc.printer));
469 printmod->printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
470 printmod->printerCopiesED->setText(toqstr(rc.print_copies_flag));
471 printmod->printerReverseED->setText(toqstr(rc.print_reverse_flag));
472 printmod->printerToPrinterED->setText(toqstr(rc.print_to_printer));
473 printmod->printerExtensionED->setText(toqstr(rc.print_file_extension));
474 printmod->printerSpoolCommandED->setText(toqstr(rc.print_file_extension));
475 printmod->printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
476 printmod->printerEvenED->setText(toqstr(rc.print_evenpage_flag));
477 printmod->printerOddED->setText(toqstr(rc.print_oddpage_flag));
478 printmod->printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
479 printmod->printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
480 printmod->printerToFileED->setText(toqstr(rc.print_to_file));
481 printmod->printerExtraED->setText(toqstr(rc.print_extra_options));
482 printmod->printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
483 printmod->printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
486 QPrefScreenFontsModule * fontmod(dialog_->screenfontsModule);
488 setComboxFont(fontmod->screenRomanCO, rc.roman_font_name,
489 rc.roman_font_foundry, QFont::Serif);
490 setComboxFont(fontmod->screenSansCO, rc.sans_font_name,
491 rc.sans_font_foundry, QFont::SansSerif);
492 setComboxFont(fontmod->screenTypewriterCO, rc.typewriter_font_name,
493 rc.typewriter_font_foundry, QFont::TypeWriter);
495 dialog_->select_roman(fontmod->screenRomanCO->currentText());
496 dialog_->select_sans(fontmod->screenSansCO->currentText());
497 dialog_->select_typewriter(fontmod->screenTypewriterCO->currentText());
499 fontmod->screenZoomSB->setValue(rc.zoom);
500 fontmod->screenDpiSB->setValue(int(rc.dpi));
501 fontmod->screenTinyED->setText(toqstr(tostr(rc.font_sizes[LyXFont::SIZE_TINY])));
502 fontmod->screenSmallestED->setText(toqstr(tostr(rc.font_sizes[LyXFont::SIZE_SCRIPT])));
503 fontmod->screenSmallerED->setText(toqstr(tostr(rc.font_sizes[LyXFont::SIZE_FOOTNOTE])));
504 fontmod->screenSmallED->setText(toqstr(tostr(rc.font_sizes[LyXFont::SIZE_SMALL])));
505 fontmod->screenNormalED->setText(toqstr(tostr(rc.font_sizes[LyXFont::SIZE_NORMAL])));
506 fontmod->screenLargeED->setText(toqstr(tostr(rc.font_sizes[LyXFont::SIZE_LARGE])));
507 fontmod->screenLargerED->setText(toqstr(tostr(rc.font_sizes[LyXFont::SIZE_LARGER])));
508 fontmod->screenLargestED->setText(toqstr(tostr(rc.font_sizes[LyXFont::SIZE_LARGEST])));
509 fontmod->screenHugeED->setText(toqstr(tostr(rc.font_sizes[LyXFont::SIZE_HUGE])));
510 fontmod->screenHugerED->setText(toqstr(tostr(rc.font_sizes[LyXFont::SIZE_HUGER])));
514 dialog_->updateFormats();
516 converters_ = converters;
518 dialog_->updateConverters();