3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Abdelrazak Younes
9 * Full author contact details are available in file CREDITS.
14 #include "qt_helpers.h"
16 #include "lcolorcache.h"
18 #include "qt_helpers.h"
25 #include "support/lstrings.h"
26 #include "support/os.h"
28 #include "controllers/ControlPrefs.h"
29 #include "controllers/frnt_lang.h"
30 #include "controllers/helper_funcs.h"
32 #include "frontends/Alert.h"
33 #include "frontends/lyx_gui.h"
35 #include "QPrefsDialog.h"
38 #include "panelstack.h"
39 #include "qcoloritem.h"
40 #include "qfontexample.h"
42 #include "ui/QPrefAsciiUi.h"
43 #include "ui/QPrefDateUi.h"
44 #include "ui/QPrefKeyboardUi.h"
45 #include "ui/QPrefLatexUi.h"
46 #include "ui/QPrefScreenFontsUi.h"
47 #include "ui/QPrefColorsUi.h"
48 #if defined(__CYGWIN__) || defined(__CYGWIN32__)
49 #include "ui/QPrefCygwinPathUi.h"
51 #include "ui/QPrefDisplayUi.h"
52 #include "ui/QPrefPathsUi.h"
53 #include "ui/QPrefSpellcheckerUi.h"
54 #include "ui/QPrefConvertersUi.h"
55 #include "ui/QPrefCopiersUi.h"
56 #include "ui/QPrefFileformatsUi.h"
57 #include "ui/QPrefLanguageUi.h"
58 #include "ui/QPrefPrinterUi.h"
59 #include "ui/QPrefUi.h"
60 #include "ui/QPrefIdentityUi.h"
64 #include "lcolorcache.h"
66 #include "controllers/ControlPrefs.h"
69 #include <QColorDialog>
70 #include <QFontDatabase>
72 #include <QPushButton>
76 #include <QCloseEvent>
78 #include <boost/tuple/tuple.hpp>
82 using lyx::support::compare_no_case;
89 using std::ostringstream;
96 QPrefsDialog::QPrefsDialog(QPrefs * form)
101 connect(savePB, SIGNAL(clicked()),
102 form, SLOT(slotOK()));
103 connect(applyPB, SIGNAL(clicked()),
104 form, SLOT(slotApply()));
105 connect(closePB, SIGNAL(clicked()),
106 form, SLOT(slotClose()));
107 connect(restorePB, SIGNAL(clicked()),
108 form, SLOT(slotRestore()));
112 asciiModule = new UiWidget<Ui::QPrefAsciiUi>(this);
113 connect(asciiModule->asciiLinelengthSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
114 connect(asciiModule->asciiRoffED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
117 dateModule = new UiWidget<Ui::QPrefDateUi>(this);
118 connect(dateModule->DateED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
122 keyboardModule = new UiWidget<Ui::QPrefKeyboardUi>(this);
123 connect( keyboardModule->keymapCB, SIGNAL( toggled(bool) ),
124 keyboardModule->firstKeymapLA, SLOT( setEnabled(bool) ) );
125 connect( keyboardModule->keymapCB, SIGNAL( toggled(bool) ),
126 keyboardModule->secondKeymapLA, SLOT( setEnabled(bool) ) );
127 connect( keyboardModule->keymapCB, SIGNAL( toggled(bool) ),
128 keyboardModule->firstKeymapED, SLOT( setEnabled(bool) ) );
129 connect( keyboardModule->keymapCB, SIGNAL( toggled(bool) ),
130 keyboardModule->secondKeymapED, SLOT( setEnabled(bool) ) );
131 connect( keyboardModule->keymapCB, SIGNAL( toggled(bool) ),
132 keyboardModule->firstKeymapPB, SLOT( setEnabled(bool) ) );
133 connect( keyboardModule->keymapCB, SIGNAL( toggled(bool) ),
134 keyboardModule->secondKeymapPB, SLOT( setEnabled(bool) ) );
135 connect(keyboardModule->firstKeymapPB, SIGNAL(clicked()), this, SLOT(select_keymap1()));
136 connect(keyboardModule->secondKeymapPB, SIGNAL(clicked()), this, SLOT(select_keymap2()));
137 connect(keyboardModule->keymapCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
138 connect(keyboardModule->firstKeymapED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
139 connect(keyboardModule->secondKeymapED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
143 latexModule = new UiWidget<Ui::QPrefLatexUi>(this);
144 connect(latexModule->latexEncodingED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
145 connect(latexModule->latexChecktexED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
146 connect(latexModule->latexBibtexED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
147 connect(latexModule->latexIndexED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
148 connect(latexModule->latexAutoresetCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
149 connect(latexModule->latexDviPaperED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
150 connect(latexModule->latexPaperSizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
155 screenfontsModule = new UiWidget<Ui::QPrefScreenFontsUi>(this);
156 connect(screenfontsModule->screenRomanCO, SIGNAL(activated(const QString&)), this, SLOT(select_roman(const QString&)));
157 connect(screenfontsModule->screenSansCO, SIGNAL(activated(const QString&)), this, SLOT(select_sans(const QString&)));
158 connect(screenfontsModule->screenTypewriterCO, SIGNAL(activated(const QString&)), this, SLOT(select_typewriter(const QString&)));
160 QFontDatabase fontdb;
161 QStringList families(fontdb.families());
162 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
163 screenfontsModule->screenRomanCO->insertItem(*it);
164 screenfontsModule->screenSansCO->insertItem(*it);
165 screenfontsModule->screenTypewriterCO->insertItem(*it);
167 connect(screenfontsModule->screenRomanCO, SIGNAL(activated(const QString&)), this, SLOT(change_adaptor()));
168 connect(screenfontsModule->screenSansCO, SIGNAL(activated(const QString&)), this, SLOT(change_adaptor()));
169 connect(screenfontsModule->screenTypewriterCO, SIGNAL(activated(const QString&)), this, SLOT(change_adaptor()));
170 connect(screenfontsModule->screenZoomSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
171 connect(screenfontsModule->screenDpiSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
172 connect(screenfontsModule->screenTinyED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
173 connect(screenfontsModule->screenSmallestED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
174 connect(screenfontsModule->screenSmallerED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
175 connect(screenfontsModule->screenSmallED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
176 connect(screenfontsModule->screenNormalED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
177 connect(screenfontsModule->screenLargeED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
178 connect(screenfontsModule->screenLargerED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
179 connect(screenfontsModule->screenLargestED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
180 connect(screenfontsModule->screenHugeED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
181 connect(screenfontsModule->screenHugerED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
183 screenfontsModule->screenTinyED->setValidator(new QDoubleValidator(
184 screenfontsModule->screenTinyED));
185 screenfontsModule->screenSmallestED->setValidator(new QDoubleValidator(
186 screenfontsModule->screenSmallestED));
187 screenfontsModule->screenSmallerED->setValidator(new QDoubleValidator(
188 screenfontsModule->screenSmallerED));
189 screenfontsModule->screenSmallED->setValidator(new QDoubleValidator(
190 screenfontsModule->screenSmallED));
191 screenfontsModule->screenNormalED->setValidator(new QDoubleValidator(
192 screenfontsModule->screenNormalED));
193 screenfontsModule->screenLargeED->setValidator(new QDoubleValidator(
194 screenfontsModule->screenLargeED));
195 screenfontsModule->screenLargerED->setValidator(new QDoubleValidator(
196 screenfontsModule->screenLargerED));
197 screenfontsModule->screenLargestED->setValidator(new QDoubleValidator(
198 screenfontsModule->screenLargestED));
199 screenfontsModule->screenHugeED->setValidator(new QDoubleValidator(
200 screenfontsModule->screenHugeED));
201 screenfontsModule->screenHugerED->setValidator(new QDoubleValidator(
202 screenfontsModule->screenHugerED));
207 colorsModule = new UiWidget<Ui::QPrefColorsUi>(this);
208 // FIXME: put in controller
209 for (int i = 0; i < LColor::ignore; ++i) {
210 LColor::color lc = static_cast<LColor::color>(i);
211 if (lc == LColor::none
212 || lc == LColor::black
213 || lc == LColor::white
215 || lc == LColor::green
216 || lc == LColor::blue
217 || lc == LColor::cyan
218 || lc == LColor::magenta
219 || lc == LColor::yellow
220 || lc == LColor::inherit
221 || lc == LColor::ignore) continue;
223 colors_.push_back(lc);
224 string const guiname(lcolor.getGUIName(lc));
225 QColorItem * ci(new QColorItem(lcolorcache.get(lc),
227 colorsModule->lyxObjectsLB->insertItem(ci);
229 connect(colorsModule->colorChangePB, SIGNAL(clicked()), this, SLOT(change_color()));
230 connect(colorsModule->lyxObjectsLB, SIGNAL(selected(int)), this, SLOT(change_color()));
235 #if defined(__CYGWIN__) || defined(__CYGWIN32__)
236 cygwinpathModule = new UiWidget<Ui::QPrefCygwinPathUi>(this);
237 connect(cygwinpathModule->pathCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
242 displayModule = new UiWidget<Ui::QPrefDisplayUi>(this);
243 connect(displayModule->instantPreviewCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
244 connect(displayModule->displayGraphicsCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
248 pathsModule = new UiWidget<Ui::QPrefPathsUi>(this);
249 connect(pathsModule->templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
250 connect(pathsModule->tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
251 connect(pathsModule->backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
252 connect(pathsModule->workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
253 connect(pathsModule->lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
254 connect(pathsModule->workingDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
255 connect(pathsModule->templateDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
256 connect(pathsModule->backupDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
257 connect(pathsModule->tempDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
258 connect(pathsModule->lyxserverDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
259 connect(pathsModule->pathPrefixED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
263 spellcheckerModule = new UiWidget<Ui::QPrefSpellcheckerUi>(this);
264 connect(spellcheckerModule->persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
265 #if defined (USE_ISPELL)
266 connect(spellcheckerModule->spellCommandCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
268 spellcheckerModule->spellCommandCO->setEnabled(false);
270 connect(spellcheckerModule->altLanguageED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
271 connect(spellcheckerModule->escapeCharactersED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
272 connect(spellcheckerModule->persDictionaryED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
273 connect(spellcheckerModule->compoundWordCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
274 connect(spellcheckerModule->inputEncodingCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
275 spellcheckerModule->spellCommandCO->insertItem(qt_("ispell"));
276 spellcheckerModule->spellCommandCO->insertItem(qt_("aspell"));
277 spellcheckerModule->spellCommandCO->insertItem(qt_("hspell"));
279 spellcheckerModule->spellCommandCO->insertItem(qt_("pspell (library)"));
282 spellcheckerModule->spellCommandCO->insertItem(qt_("aspell (library)"));
288 convertersModule = new UiWidget<Ui::QPrefConvertersUi>(this);
289 connect(convertersModule->converterNewPB, SIGNAL(clicked()), this, SLOT(new_converter()));
290 connect(convertersModule->converterRemovePB, SIGNAL(clicked()), this, SLOT(remove_converter()));
291 connect(convertersModule->converterModifyPB, SIGNAL(clicked()), this, SLOT(modify_converter()));
292 connect(convertersModule->convertersLB, SIGNAL(highlighted(int)), this, SLOT(switch_converter(int)));
293 connect(convertersModule->converterFromCO, SIGNAL(activated(const QString&)), this, SLOT(converter_changed()));
294 connect(convertersModule->converterToCO, SIGNAL(activated(const QString&)), this, SLOT(converter_changed()));
295 connect(convertersModule->converterED, SIGNAL(textChanged(const QString&)), this, SLOT(converter_changed()));
296 connect(convertersModule->converterFlagED, SIGNAL(textChanged(const QString&)), this, SLOT(converter_changed()));
297 connect(convertersModule->converterNewPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
298 connect(convertersModule->converterRemovePB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
299 connect(convertersModule->converterModifyPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
303 copiersModule = new UiWidget<Ui::QPrefCopiersUi>(this);
304 connect(copiersModule->copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
305 connect(copiersModule->copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
306 connect(copiersModule->copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
307 connect(copiersModule->AllCopiersLB, SIGNAL(highlighted(int)), this, SLOT(switch_copierLB(int)));
308 connect(copiersModule->copierFormatCO, SIGNAL(activated(int)), this, SLOT(switch_copierCO(int)));
309 connect(copiersModule->copierNewPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
310 connect(copiersModule->copierRemovePB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
311 connect(copiersModule->copierModifyPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
312 connect(copiersModule->copierFormatCO, SIGNAL(activated(const QString&)), this, SLOT(copiers_changed()));
313 connect(copiersModule->copierED, SIGNAL(textChanged(const QString&)), this, SLOT(copiers_changed()));
318 fileformatsModule = new UiWidget<Ui::QPrefFileformatsUi>(this);
319 connect(fileformatsModule->formatNewPB, SIGNAL(clicked()), this, SLOT(new_format()));
320 connect(fileformatsModule->formatRemovePB, SIGNAL(clicked()), this, SLOT(remove_format()));
321 connect(fileformatsModule->formatModifyPB, SIGNAL(clicked()), this, SLOT(modify_format()));
322 connect(fileformatsModule->formatsLB, SIGNAL(highlighted(int)), this, SLOT(switch_format(int)));
323 connect(fileformatsModule->formatED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
324 connect(fileformatsModule->guiNameED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
325 connect(fileformatsModule->shortcutED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
326 connect(fileformatsModule->extensionED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
327 connect(fileformatsModule->viewerED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
328 connect(fileformatsModule->editorED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
329 connect(fileformatsModule->formatNewPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
330 connect(fileformatsModule->formatRemovePB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
331 connect(fileformatsModule->formatModifyPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
336 languageModule = new UiWidget<Ui::QPrefLanguageUi>(this);
337 connect(languageModule->rtlCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
338 connect(languageModule->markForeignCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
339 connect(languageModule->autoBeginCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
340 connect(languageModule->autoEndCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
341 connect(languageModule->useBabelCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
342 connect(languageModule->globalCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
343 connect(languageModule->languagePackageED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
344 connect(languageModule->startCommandED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
345 connect(languageModule->endCommandED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
346 connect(languageModule->defaultLanguageCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
348 languageModule->defaultLanguageCO->clear();
350 // store the lang identifiers for later
351 using lyx::frontend::LanguagePair;
352 std::vector<LanguagePair> const langs =
353 lyx::frontend::getLanguageData(false);
354 lang_ = getSecond(langs);
356 std::vector<LanguagePair>::const_iterator lit = langs.begin();
357 std::vector<LanguagePair>::const_iterator lend = langs.end();
358 for (; lit != lend; ++lit) {
359 languageModule->defaultLanguageCO->insertItem(toqstr(lit->first));
366 printerModule = new UiWidget<Ui::QPrefPrinterUi>(this);
367 connect(printerModule->printerAdaptCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
368 connect(printerModule->printerCommandED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
369 connect(printerModule->printerNameED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
370 connect(printerModule->printerPageRangeED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
371 connect(printerModule->printerCopiesED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
372 connect(printerModule->printerReverseED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
373 connect(printerModule->printerToPrinterED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
374 connect(printerModule->printerExtensionED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
375 connect(printerModule->printerSpoolCommandED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
376 connect(printerModule->printerPaperTypeED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
377 connect(printerModule->printerEvenED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
378 connect(printerModule->printerOddED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
379 connect(printerModule->printerCollatedED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
380 connect(printerModule->printerLandscapeED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
381 connect(printerModule->printerToFileED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
382 connect(printerModule->printerExtraED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
383 connect(printerModule->printerSpoolPrefixED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
384 connect(printerModule->printerPaperSizeED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
389 uiModule = new UiWidget<Ui::QPrefUi>(this);
390 connect( uiModule->autoSaveCB, SIGNAL( toggled(bool) ), uiModule->autoSaveLA, SLOT( setEnabled(bool) ) );
391 connect( uiModule->autoSaveCB, SIGNAL( toggled(bool) ), uiModule->autoSaveSB, SLOT( setEnabled(bool) ) );
392 connect( uiModule->autoSaveCB, SIGNAL( toggled(bool) ), uiModule->TextLabel1, SLOT( setEnabled(bool) ) );
393 connect(uiModule->uiFilePB, SIGNAL(clicked()), this, SLOT(select_ui()));
394 connect(uiModule->bindFilePB, SIGNAL(clicked()), this, SLOT(select_bind()));
395 connect(uiModule->uiFileED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
396 connect(uiModule->bindFileED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
397 connect(uiModule->cursorFollowsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
398 connect(uiModule->autoSaveSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
399 connect(uiModule->autoSaveCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
400 connect(uiModule->lastfilesSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
401 uiModule->lastfilesSB->setMaxValue(maxlastfiles);
406 identityModule = new UiWidget<Ui::QPrefIdentityUi>(this);
407 connect(identityModule->nameED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
408 connect(identityModule->emailED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
413 string const laf = _("Look and feel");
414 prefsPS->addCategory(laf);
415 prefsPS->addPanel(uiModule, _("User interface"), laf);
416 prefsPS->addPanel(screenfontsModule, _("Screen fonts"), laf);
417 prefsPS->addPanel(colorsModule, _("Colors"), laf);
418 prefsPS->addPanel(displayModule, _("Graphics"), laf);
419 prefsPS->addPanel(keyboardModule, _("Keyboard"), laf);
421 string const ls = _("Language settings");
422 prefsPS->addCategory(ls);
423 prefsPS->addPanel(languageModule, _("Language"), ls);
424 prefsPS->addPanel(spellcheckerModule, _("Spellchecker"), ls);
426 string const op = _("Outputs");
427 prefsPS->addCategory(op);
428 prefsPS->addPanel(asciiModule, _("Plain text"), op);
429 prefsPS->addPanel(dateModule, _("Date format"), op);
430 prefsPS->addPanel(latexModule, _("LaTeX"), op);
431 #if defined(__CYGWIN__) || defined(__CYGWIN32__)
432 prefsPS->addPanel(cygwinpathModule, _("Paths"), op);
434 prefsPS->addPanel(printerModule, _("Printer"), op);
436 prefsPS->addPanel(identityModule, _("Identity"));
437 prefsPS->addPanel(pathsModule, _("Paths"));
438 prefsPS->addPanel(fileformatsModule, _("File formats"));
439 prefsPS->addPanel(convertersModule, _("Converters"));
440 prefsPS->addPanel(copiersModule, _("Copiers"));
442 prefsPS->setCurrentPanel(_("User interface"));
445 form_->bcview().setOK(savePB);
446 form_->bcview().setApply(applyPB);
447 form_->bcview().setCancel(closePB);
448 form_->bcview().setRestore(restorePB);
454 QPrefsDialog::~QPrefsDialog()
459 void QPrefsDialog::closeEvent(QCloseEvent * e)
466 void QPrefsDialog::change_adaptor()
472 void QPrefsDialog::updateConverters()
474 Ui::QPrefConvertersUi* convertmod(convertersModule);
476 // save current selection
477 QString current = convertmod->converterFromCO->currentText()
478 + " -> " + convertmod->converterToCO->currentText();
480 convertmod->converterFromCO->clear();
481 convertmod->converterToCO->clear();
483 Formats::const_iterator cit = form_->formats().begin();
484 Formats::const_iterator end = form_->formats().end();
485 for (; cit != end; ++cit) {
486 convertmod->converterFromCO->insertItem(toqstr(cit->prettyname()));
487 convertmod->converterToCO->insertItem(toqstr(cit->prettyname()));
490 convertmod->convertersLB->clear();
492 Converters::const_iterator ccit = form_->converters().begin();
493 Converters::const_iterator cend = form_->converters().end();
494 for (; ccit != cend; ++ccit) {
495 std::string const name = ccit->From->prettyname() + " -> "
496 + ccit->To->prettyname();
497 convertmod->convertersLB->insertItem(toqstr(name));
501 if (!current.isEmpty()) {
502 Q3ListBoxItem * item = convertmod->convertersLB->findItem(current);
503 convertmod->convertersLB->setCurrentItem(item);
505 // select first element if restoring failed
506 if (convertmod->convertersLB->currentItem() == -1)
507 convertmod->convertersLB->setCurrentItem(0);
509 updateConverterButtons();
513 void QPrefsDialog::switch_converter(int nr)
515 Converter const & c(form_->converters().get(nr));
516 convertersModule->converterFromCO->setCurrentItem(form_->formats().getNumber(c.from));
517 convertersModule->converterToCO->setCurrentItem(form_->formats().getNumber(c.to));
518 convertersModule->converterED->setText(toqstr(c.command));
519 convertersModule->converterFlagED->setText(toqstr(c.flags));
521 updateConverterButtons();
525 void QPrefsDialog::converter_changed()
527 updateConverterButtons();
531 void QPrefsDialog::updateConverterButtons()
533 Format const & from(form_->formats().get(
534 convertersModule->converterFromCO->currentItem()));
535 Format const & to(form_->formats().get(
536 convertersModule->converterToCO->currentItem()));
537 int const sel = form_->converters().getNumber(from.name(), to.name());
538 bool const known = !(sel < 0);
539 bool const valid = !(convertersModule->converterED->text().isEmpty()
540 || from.name() == to.name());
542 Converter const & c(form_->converters().get(
543 convertersModule->convertersLB->currentItem()));
544 string const old_command = c.command;
545 string const old_flag = c.flags;
546 string const new_command(fromqstr(convertersModule->converterED->text()));
547 string const new_flag(fromqstr(convertersModule->converterFlagED->text()));
549 bool modified = ((old_command != new_command) || (old_flag != new_flag));
551 convertersModule->converterModifyPB->setEnabled(valid && known && modified);
552 convertersModule->converterNewPB->setEnabled(valid && !known);
553 convertersModule->converterRemovePB->setEnabled(known);
558 // specify unique from/to or it doesn't appear. This is really bad UI
559 void QPrefsDialog::new_converter()
561 Format const & from(form_->formats().get(convertersModule->converterFromCO->currentItem()));
562 Format const & to(form_->formats().get(convertersModule->converterToCO->currentItem()));
563 string const command(fromqstr(convertersModule->converterED->text()));
564 string const flags(fromqstr(convertersModule->converterFlagED->text()));
566 Converter const * old = form_->converters().getConverter(from.name(), to.name());
567 form_->converters().add(from.name(), to.name(), command, flags);
569 form_->converters().updateLast(form_->formats());
572 convertersModule->convertersLB->setCurrentItem(convertersModule->convertersLB->count() - 1);
576 void QPrefsDialog::modify_converter()
578 int const top_item = convertersModule->convertersLB->topItem();
579 QString const current_text =
580 convertersModule->convertersLB->currentText();
582 Format const & from(form_->formats().get(convertersModule->converterFromCO->currentItem()));
583 Format const & to(form_->formats().get(convertersModule->converterToCO->currentItem()));
584 string flags(fromqstr(convertersModule->converterFlagED->text()));
585 string name(fromqstr(convertersModule->converterED->text()));
587 Converter const * old = form_->converters().getConverter(from.name(), to.name());
588 form_->converters().add(from.name(), to.name(), name, flags);
590 form_->converters().updateLast(form_->formats());
594 Q3ListBoxItem * const item =
595 convertersModule->convertersLB->findItem(current_text);
596 convertersModule->convertersLB->setCurrentItem(item);
597 convertersModule->convertersLB->setTopItem(top_item);
601 void QPrefsDialog::remove_converter()
603 Format const & from(form_->formats().get(convertersModule->converterFromCO->currentItem()));
604 Format const & to(form_->formats().get(convertersModule->converterToCO->currentItem()));
605 form_->converters().erase(from.name(), to.name());
610 void QPrefsDialog::updateCopiers()
613 // save current selection
614 QString current = copiersModule->copierFormatCO->currentText();
615 copiersModule->copierFormatCO->clear();
617 for (Formats::const_iterator it = form_->formats().begin(),
618 end = form_->formats().end();
620 copiersModule->copierFormatCO->insertItem(toqstr(it->prettyname()));
623 // The browser widget
624 copiersModule->AllCopiersLB->clear();
626 for (Movers::iterator it = form_->movers().begin(),
627 end = form_->movers().end();
629 std::string const & command = it->second.command();
632 std::string const & fmt = it->first;
633 std::string const & pretty = form_->formats().prettyName(fmt);
635 copiersModule->AllCopiersLB->insertItem(toqstr(pretty));
639 if (!current.isEmpty()) {
640 Q3ListBoxItem * item = copiersModule->AllCopiersLB->findItem(current);
641 copiersModule->AllCopiersLB->setCurrentItem(item);
643 // select first element if restoring failed
644 if (copiersModule->AllCopiersLB->currentItem() == -1)
645 copiersModule->AllCopiersLB->setCurrentItem(0);
651 class SamePrettyName {
653 SamePrettyName(string const & n) : pretty_name_(n) {}
655 bool operator()(::Format const & fmt) const {
656 return fmt.prettyname() == pretty_name_;
660 string const pretty_name_;
664 Format const * getFormat(std::string const & prettyname)
666 Formats::const_iterator it = ::formats.begin();
667 Formats::const_iterator const end = ::formats.end();
668 it = std::find_if(it, end, SamePrettyName(prettyname));
669 return it == end ? 0 : &*it;
675 void QPrefsDialog::switch_copierLB(int)
677 std::string const browser_text =
678 fromqstr(copiersModule->AllCopiersLB->currentText());
679 Format const * fmt = getFormat(browser_text);
683 string const & fmt_name = fmt->name();
684 string const & gui_name = fmt->prettyname();
685 string const & command = form_->movers().command(fmt_name);
687 copiersModule->copierED->clear();
688 int const combo_size = copiersModule->copierFormatCO->count();
689 for (int i = 0; i < combo_size; ++i) {
690 QString const qtext = copiersModule->copierFormatCO->text(i);
691 std::string const text = fromqstr(qtext);
692 if (text == gui_name) {
693 copiersModule->copierFormatCO->setCurrentItem(i);
694 copiersModule->copierED->setText(toqstr(command));
698 updateCopierButtons();
702 void QPrefsDialog::switch_copierCO(int)
704 std::string const combo_text =
705 fromqstr(copiersModule->copierFormatCO->currentText());
706 Format const * fmt = getFormat(combo_text);
710 string const & fmt_name = fmt->name();
711 string const & gui_name = fmt->prettyname();
712 string const & command = form_->movers().command(fmt_name);
714 copiersModule->copierED->setText(toqstr(command));
716 int const index = copiersModule->AllCopiersLB->currentItem();
718 copiersModule->AllCopiersLB->setSelected(index, false);
720 int const browser_size = copiersModule->AllCopiersLB->count();
721 for (int i = 0; i < browser_size; ++i) {
722 QString const qtext = copiersModule->AllCopiersLB->text(i);
723 std::string const text = fromqstr(qtext);
724 if (text == gui_name) {
725 copiersModule->AllCopiersLB->setSelected(i, true);
726 int top = std::max(i - 5, 0);
727 copiersModule->AllCopiersLB->setTopItem(top);
734 void QPrefsDialog::copiers_changed()
736 updateCopierButtons();
740 void QPrefsDialog::updateCopierButtons()
742 QString selected = copiersModule->copierFormatCO->currentText();
745 for (unsigned int i = 0; i != copiersModule->AllCopiersLB->count(); i++) {
746 if (copiersModule->AllCopiersLB->text(i) == selected)
750 bool const valid = !copiersModule->copierED->text().isEmpty();
752 Format const * fmt = getFormat(fromqstr(selected));
753 string const old_command = form_->movers().command(fmt->name());
754 string const new_command(fromqstr(copiersModule->copierED->text()));
756 bool modified = (old_command != new_command);
758 copiersModule->copierModifyPB->setEnabled(valid && known && modified);
759 copiersModule->copierNewPB->setEnabled(valid && !known);
760 copiersModule->copierRemovePB->setEnabled(known);
764 void QPrefsDialog::new_copier()
766 std::string const combo_text =
767 fromqstr(copiersModule->copierFormatCO->currentText());
768 Format const * fmt = getFormat(combo_text);
772 string const command = fromqstr(copiersModule->copierED->text());
776 form_->movers().set(fmt->name(), command);
779 int const last = copiersModule->AllCopiersLB->count() - 1;
780 copiersModule->AllCopiersLB->setCurrentItem(last);
782 updateCopierButtons();
786 void QPrefsDialog::modify_copier()
788 std::string const combo_text =
789 fromqstr(copiersModule->copierFormatCO->currentText());
790 Format const * fmt = getFormat(combo_text);
794 string const command = fromqstr(copiersModule->copierED->text());
795 form_->movers().set(fmt->name(), command);
798 updateCopierButtons();
802 void QPrefsDialog::remove_copier()
804 std::string const combo_text =
805 fromqstr(copiersModule->copierFormatCO->currentText());
806 Format const * fmt = getFormat(combo_text);
810 string const & fmt_name = fmt->name();
811 form_->movers().set(fmt_name, string());
814 updateCopierButtons();
818 void QPrefsDialog::updateFormats()
820 Ui::QPrefFileformatsUi * formatmod(fileformatsModule);
822 // save current selection
823 QString current = formatmod->guiNameED->text();
825 formatmod->formatsLB->clear();
827 Formats::const_iterator cit = form_->formats().begin();
828 Formats::const_iterator end = form_->formats().end();
829 for (; cit != end; ++cit) {
830 formatmod->formatsLB->insertItem(toqstr(cit->prettyname()));
834 if (!current.isEmpty()) {
835 Q3ListBoxItem * item = formatmod->formatsLB->findItem(current);
836 formatmod->formatsLB->setCurrentItem(item);
838 // select first element if restoring failed
839 if (formatmod->formatsLB->currentItem() == -1)
840 formatmod->formatsLB->setCurrentItem(0);
844 void QPrefsDialog::switch_format(int nr)
846 Format const & f(form_->formats().get(nr));
847 fileformatsModule->formatED->setText(toqstr(f.name()));
848 fileformatsModule->guiNameED->setText(toqstr(f.prettyname()));
849 fileformatsModule->extensionED->setText(toqstr(f.extension()));
850 fileformatsModule->shortcutED->setText(toqstr(f.shortcut()));
851 fileformatsModule->viewerED->setText(toqstr(f.viewer()));
852 fileformatsModule->editorED->setText(toqstr(f.editor()));
853 fileformatsModule->formatRemovePB->setEnabled(
854 !form_->converters().formatIsUsed(f.name()));
856 updateFormatsButtons();
860 void QPrefsDialog::fileformat_changed()
862 updateFormatsButtons();
866 void QPrefsDialog::updateFormatsButtons()
868 QString const format = fileformatsModule->formatED->text();
869 QString const gui_name = fileformatsModule->guiNameED->text();
870 int const sel = form_->formats().getNumber(fromqstr(format));
871 bool gui_name_known = false;
873 for (unsigned int i = 0; i != fileformatsModule->formatsLB->count(); i++) {
874 if (fileformatsModule->formatsLB->text(i) == gui_name) {
875 gui_name_known = true;
880 // assure that a gui name cannot be chosen twice
881 bool const known_otherwise = gui_name_known && (where != sel);
883 bool const known = !(sel < 0);
884 bool const valid = (!fileformatsModule->formatED->text().isEmpty()
885 && !fileformatsModule->guiNameED->text().isEmpty());
887 Format const & f(form_->formats().get(
888 fileformatsModule->formatsLB->currentItem()));
889 string const old_pretty(f.prettyname());
890 string const old_shortcut(f.shortcut());
891 string const old_extension(f.extension());
892 string const old_viewer(f.viewer());
893 string const old_editor(f.editor());
895 string const new_pretty(fromqstr(gui_name));
896 string const new_shortcut(fromqstr(fileformatsModule->shortcutED->text()));
897 string const new_extension(fromqstr(fileformatsModule->extensionED->text()));
898 string const new_viewer(fromqstr(fileformatsModule->viewerED->text()));
899 string const new_editor(fromqstr(fileformatsModule->editorED->text()));
901 bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
902 || (old_extension != new_extension) || (old_viewer != new_viewer)
903 || (old_editor != new_editor));
905 fileformatsModule->formatModifyPB->setEnabled(
906 valid && known && modified && !known_otherwise);
907 fileformatsModule->formatNewPB->setEnabled(valid && !known && !gui_name_known);
908 fileformatsModule->formatRemovePB->setEnabled(known);
912 void QPrefsDialog::new_format()
914 string const name = fromqstr(fileformatsModule->formatED->text());
915 string const prettyname = fromqstr(fileformatsModule->guiNameED->text());
916 string const extension = fromqstr(fileformatsModule->extensionED->text());
917 string const shortcut = fromqstr(fileformatsModule->shortcutED->text());
918 string const viewer = fromqstr(fileformatsModule->viewerED->text());
919 string const editor = fromqstr(fileformatsModule->editorED->text());
921 form_->formats().add(name, extension, prettyname, shortcut, viewer, editor);
922 form_->formats().sort();
924 fileformatsModule->formatsLB->setCurrentItem(form_->formats().getNumber(name));
925 form_->converters().update(form_->formats());
928 updateFormatsButtons();
932 void QPrefsDialog::modify_format()
934 int const top_item = fileformatsModule->formatsLB->topItem();
935 int const current_item = fileformatsModule->formatsLB->currentItem();
936 QString const current_text =
937 fileformatsModule->formatsLB->currentText();
939 Format const & oldformat(form_->formats().get(current_item));
940 string const oldpretty(oldformat.prettyname());
941 string const name(fromqstr(fileformatsModule->formatED->text()));
942 form_->formats().erase(oldformat.name());
944 string const prettyname = fromqstr(fileformatsModule->guiNameED->text());
945 string const extension = fromqstr(fileformatsModule->extensionED->text());
946 string const shortcut = fromqstr(fileformatsModule->shortcutED->text());
947 string const viewer = fromqstr(fileformatsModule->viewerED->text());
948 string const editor = fromqstr(fileformatsModule->editorED->text());
950 form_->formats().add(name, extension, prettyname, shortcut, viewer, editor);
951 form_->formats().sort();
953 fileformatsModule->formatsLB->setUpdatesEnabled(false);
955 fileformatsModule->formatsLB->setUpdatesEnabled(true);
956 fileformatsModule->formatsLB->update();
959 updateFormatsButtons();
961 Q3ListBoxItem * const item =
962 fileformatsModule->formatsLB->findItem(current_text);
963 fileformatsModule->formatsLB->setCurrentItem(item);
964 fileformatsModule->formatsLB->setTopItem(top_item);
968 void QPrefsDialog::remove_format()
970 int const nr(fileformatsModule->formatsLB->currentItem());
973 string const current_text = form_->formats().get(nr).name();
974 if (form_->converters().formatIsUsed(current_text)) {
975 Alert::error(_("Format in use"),
976 _("Cannot remove a Format used by a Converter. "
977 "Remove the converter first."));
980 form_->formats().erase(current_text);
982 form_->converters().update(form_->formats());
985 updateFormatsButtons();
989 void QPrefsDialog::change_color()
991 Q3ListBox * lb(colorsModule->lyxObjectsLB);
992 if (lb->currentItem() < 0)
994 Q3ListBoxItem * ib(lb->item(lb->currentItem()));
995 QColorItem * ci(static_cast<QColorItem*>(ib));
996 QColor c(QColorDialog::getColor(ci->color(), qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget()));
999 lb->triggerUpdate(false);
1005 void QPrefsDialog::select_ui()
1007 string file(form_->controller().browseUI(fromqstr(uiModule->uiFileED->text())));
1009 uiModule->uiFileED->setText(toqstr(file));
1013 void QPrefsDialog::select_bind()
1015 string file(form_->controller().browsebind(fromqstr(uiModule->bindFileED->text())));
1017 uiModule->bindFileED->setText(toqstr(file));
1021 void QPrefsDialog::select_keymap1()
1023 string file(form_->controller().browsekbmap(fromqstr(keyboardModule->firstKeymapED->text())));
1025 keyboardModule->firstKeymapED->setText(toqstr(file));
1029 void QPrefsDialog::select_keymap2()
1031 string file(form_->controller().browsekbmap(fromqstr(keyboardModule->secondKeymapED->text())));
1033 keyboardModule->secondKeymapED->setText(toqstr(file));
1037 void QPrefsDialog::select_dict()
1039 string file(form_->controller().browsedict(fromqstr(spellcheckerModule->persDictionaryED->text())));
1041 spellcheckerModule->persDictionaryED->setText(toqstr(file));
1045 // NB: the _() is OK here because it gets passed back and we toqstr() them
1047 void QPrefsDialog::select_templatedir()
1049 string file(form_->controller().browsedir(fromqstr(pathsModule->templateDirED->text()), _("Select a document templates directory")));
1051 pathsModule->templateDirED->setText(toqstr(file));
1055 void QPrefsDialog::select_tempdir()
1057 string file(form_->controller().browsedir(fromqstr(pathsModule->tempDirED->text()), _("Select a temporary directory")));
1059 pathsModule->tempDirED->setText(toqstr(file));
1063 void QPrefsDialog::select_backupdir()
1065 string file(form_->controller().browsedir(fromqstr(pathsModule->backupDirED->text()), _("Select a backups directory")));
1067 pathsModule->backupDirED->setText(toqstr(file));
1071 void QPrefsDialog::select_workingdir()
1073 string file(form_->controller().browsedir(fromqstr(pathsModule->workingDirED->text()), _("Select a document directory")));
1075 pathsModule->workingDirED->setText(toqstr(file));
1079 void QPrefsDialog::select_lyxpipe()
1081 string file(form_->controller().browse(fromqstr(pathsModule->lyxserverDirED->text()), _("Give a filename for the LyX server pipe")));
1083 pathsModule->lyxserverDirED->setText(toqstr(file));
1087 void QPrefsDialog::select_roman(const QString& name)
1089 screenfontsModule->screenRomanFE->set(QFont(name), name);
1093 void QPrefsDialog::select_sans(const QString& name)
1095 screenfontsModule->screenSansFE->set(QFont(name), name);
1099 void QPrefsDialog::select_typewriter(const QString& name)
1101 screenfontsModule->screenTypewriterFE->set(QFont(name), name);
1106 string const internal_path(QString const & input)
1108 return lyx::support::os::internal_path(fromqstr(input));
1113 void QPrefsDialog::apply(LyXRC & rc) const
1115 // FIXME: remove rtl_support bool
1116 rc.rtl_support = languageModule->rtlCB->isChecked();
1117 rc.mark_foreign_language = languageModule->markForeignCB->isChecked();
1118 rc.language_auto_begin = languageModule->autoBeginCB->isChecked();
1119 rc.language_auto_end = languageModule->autoEndCB->isChecked();
1120 rc.language_use_babel = languageModule->useBabelCB->isChecked();
1121 rc.language_global_options = languageModule->globalCB->isChecked();
1122 rc.language_package = fromqstr(languageModule->languagePackageED->text());
1123 rc.language_command_begin = fromqstr(languageModule->startCommandED->text());
1124 rc.language_command_end = fromqstr(languageModule->endCommandED->text());
1125 rc.default_language = lang_[languageModule->defaultLanguageCO->currentItem()];
1128 rc.ui_file = internal_path(uiModule->uiFileED->text());
1129 rc.bind_file = internal_path(uiModule->bindFileED->text());
1130 rc.cursor_follows_scrollbar = uiModule->cursorFollowsCB->isChecked();
1131 rc.autosave = uiModule->autoSaveSB->value() * 60;
1132 rc.make_backup = uiModule->autoSaveCB->isChecked();
1133 rc.num_lastfiles = uiModule->lastfilesSB->value();
1136 // FIXME: can derive CB from the two EDs
1137 rc.use_kbmap = keyboardModule->keymapCB->isChecked();
1138 rc.primary_kbmap = internal_path(keyboardModule->firstKeymapED->text());
1139 rc.secondary_kbmap = internal_path(keyboardModule->secondKeymapED->text());
1142 rc.ascii_linelen = asciiModule->asciiLinelengthSB->value();
1143 rc.ascii_roff_command = fromqstr(asciiModule->asciiRoffED->text());
1146 rc.date_insert_format = fromqstr(dateModule->DateED->text());
1149 #if defined(__CYGWIN__) || defined(__CYGWIN32__)
1150 rc.cygwin_path_fix = cygwinpathModule->pathCB->isChecked();
1154 rc.fontenc = fromqstr(latexModule->latexEncodingED->text());
1155 rc.chktex_command = fromqstr(latexModule->latexChecktexED->text());
1156 rc.bibtex_command = fromqstr(latexModule->latexBibtexED->text());
1157 rc.index_command = fromqstr(latexModule->latexIndexED->text());
1158 rc.auto_reset_options = latexModule->latexAutoresetCB->isChecked();
1159 rc.view_dvi_paper_option = fromqstr(latexModule->latexDviPaperED->text());
1160 rc.default_papersize =
1161 form_->controller().toPaperSize(latexModule->latexPaperSizeCO->currentItem());
1164 switch (displayModule->instantPreviewCO->currentItem()) {
1165 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
1166 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
1167 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
1170 lyx::graphics::DisplayType dtype;
1171 switch (displayModule->displayGraphicsCO->currentItem()) {
1172 case 3: dtype = lyx::graphics::NoDisplay; break;
1173 case 2: dtype = lyx::graphics::ColorDisplay; break;
1174 case 1: dtype = lyx::graphics::GrayscaleDisplay; break;
1175 case 0: dtype = lyx::graphics::MonochromeDisplay; break;
1176 default: dtype = lyx::graphics::GrayscaleDisplay;
1178 rc.display_graphics = dtype;
1180 #ifdef WITH_WARNINGS
1181 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
1184 if (old_value != rc.display_graphics) {
1185 lyx::graphics::GCache & gc = lyx::graphics::GCache::get();
1191 rc.document_path = internal_path(pathsModule->workingDirED->text());
1192 rc.template_path = internal_path(pathsModule->templateDirED->text());
1193 rc.backupdir_path = internal_path(pathsModule->backupDirED->text());
1194 rc.tempdir_path = internal_path(pathsModule->tempDirED->text());
1195 rc.path_prefix = fromqstr(pathsModule->pathPrefixED->text());
1196 // FIXME: should be a checkbox only
1197 rc.lyxpipes = internal_path(pathsModule->lyxserverDirED->text());
1200 switch (spellcheckerModule->spellCommandCO->currentItem()) {
1204 rc.use_spell_lib = false;
1205 rc.isp_command = fromqstr(spellcheckerModule->spellCommandCO->currentText());
1208 rc.use_spell_lib = true;
1212 // FIXME: remove isp_use_alt_lang
1213 rc.isp_alt_lang = fromqstr(spellcheckerModule->altLanguageED->text());
1214 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
1215 // FIXME: remove isp_use_esc_chars
1216 rc.isp_esc_chars = fromqstr(spellcheckerModule->escapeCharactersED->text());
1217 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
1218 // FIXME: remove isp_use_pers_dict
1219 rc.isp_pers_dict = internal_path(spellcheckerModule->persDictionaryED->text());
1220 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
1221 rc.isp_accept_compound = spellcheckerModule->compoundWordCB->isChecked();
1222 rc.isp_use_input_encoding = spellcheckerModule->inputEncodingCB->isChecked();
1226 rc.print_adapt_output = printerModule->printerAdaptCB->isChecked();
1227 rc.print_command = fromqstr(printerModule->printerCommandED->text());
1228 rc.printer = fromqstr(printerModule->printerNameED->text());
1230 rc.print_pagerange_flag = fromqstr(printerModule->printerPageRangeED->text());
1231 rc.print_copies_flag = fromqstr(printerModule->printerCopiesED->text());
1232 rc.print_reverse_flag = fromqstr(printerModule->printerReverseED->text());
1233 rc.print_to_printer = fromqstr(printerModule->printerToPrinterED->text());
1234 rc.print_file_extension = fromqstr(printerModule->printerExtensionED->text());
1235 rc.print_spool_command = fromqstr(printerModule->printerSpoolCommandED->text());
1236 rc.print_paper_flag = fromqstr(printerModule->printerPaperTypeED->text());
1237 rc.print_evenpage_flag = fromqstr(printerModule->printerEvenED->text());
1238 rc.print_oddpage_flag = fromqstr(printerModule->printerOddED->text());
1239 rc.print_collcopies_flag = fromqstr(printerModule->printerCollatedED->text());
1240 rc.print_landscape_flag = fromqstr(printerModule->printerLandscapeED->text());
1241 rc.print_to_file = internal_path(printerModule->printerToFileED->text());
1242 rc.print_extra_options = fromqstr(printerModule->printerExtraED->text());
1243 rc.print_spool_printerprefix = fromqstr(printerModule->printerSpoolPrefixED->text());
1244 rc.print_paper_dimension_flag = fromqstr(printerModule->printerPaperSizeED->text());
1248 rc.user_name = fromqstr(identityModule->nameED->text());
1249 rc.user_email = fromqstr(identityModule->emailED->text());
1253 LyXRC const oldrc(rc);
1255 boost::tie(rc.roman_font_name, rc.roman_font_foundry)
1256 = parseFontName(fromqstr(screenfontsModule->screenRomanCO->currentText()));
1257 boost::tie(rc.sans_font_name, rc.sans_font_foundry) =
1258 parseFontName(fromqstr(screenfontsModule->screenSansCO->currentText()));
1259 boost::tie(rc.typewriter_font_name, rc.typewriter_font_foundry) =
1260 parseFontName(fromqstr(screenfontsModule->screenTypewriterCO->currentText()));
1262 rc.zoom = screenfontsModule->screenZoomSB->value();
1263 rc.dpi = screenfontsModule->screenDpiSB->value();
1264 rc.font_sizes[LyXFont::SIZE_TINY] = fromqstr(screenfontsModule->screenTinyED->text());
1265 rc.font_sizes[LyXFont::SIZE_SCRIPT] = fromqstr(screenfontsModule->screenSmallestED->text());
1266 rc.font_sizes[LyXFont::SIZE_FOOTNOTE] = fromqstr(screenfontsModule->screenSmallerED->text());
1267 rc.font_sizes[LyXFont::SIZE_SMALL] = fromqstr(screenfontsModule->screenSmallED->text());
1268 rc.font_sizes[LyXFont::SIZE_NORMAL] = fromqstr(screenfontsModule->screenNormalED->text());
1269 rc.font_sizes[LyXFont::SIZE_LARGE] = fromqstr(screenfontsModule->screenLargeED->text());
1270 rc.font_sizes[LyXFont::SIZE_LARGER] = fromqstr(screenfontsModule->screenLargerED->text());
1271 rc.font_sizes[LyXFont::SIZE_LARGEST] = fromqstr(screenfontsModule->screenLargestED->text());
1272 rc.font_sizes[LyXFont::SIZE_HUGE] = fromqstr(screenfontsModule->screenHugeED->text());
1273 rc.font_sizes[LyXFont::SIZE_HUGER] = fromqstr(screenfontsModule->screenHugerED->text());
1275 if (rc.font_sizes != oldrc.font_sizes
1276 || rc.roman_font_name != oldrc.roman_font_name
1277 || rc.sans_font_name != oldrc.sans_font_name
1278 || rc.typewriter_font_name != oldrc.typewriter_font_name
1279 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
1280 form_->controller().updateScreenFonts();
1287 for (i = 0; i < colorsModule->lyxObjectsLB->count(); ++i) {
1288 Q3ListBoxItem * ib(colorsModule->lyxObjectsLB->item(i));
1289 QColorItem * ci(static_cast<QColorItem*>(ib));
1291 LColor::color const col(colors_[i]);
1292 QColor const & qcol(lcolorcache.get(col));
1294 // FIXME: dubious, but it's what xforms does
1295 if (qcol != ci->color()) {
1298 ostr << '#' << std::setbase(16) << setfill('0')
1299 << setw(2) << ci->color().red()
1300 << setw(2) << ci->color().green()
1301 << setw(2) << ci->color().blue();
1303 string newhex(ostr.str());
1304 form_->controller().setColor(col, newhex);
1309 // FIXME: move to helper_funcs.h
1313 typename std::vector<A>::size_type
1314 findPos(std::vector<A> const & vec, A const & val)
1316 typedef typename std::vector<A>::const_iterator Cit;
1318 Cit it = std::find(vec.begin(), vec.end(), val);
1319 if (it == vec.end())
1321 return distance(vec.begin(), it);
1324 void setComboxFont(QComboBox * cb, string const & family, string const & foundry)
1326 string const name = makeFontName(family, foundry);
1327 for (int i = 0; i < cb->count(); ++i) {
1328 if (fromqstr(cb->text(i)) == name) {
1329 cb->setCurrentItem(i);
1334 // Try matching without foundry name
1336 // We count in reverse in order to prefer the Xft foundry
1337 for (int i = cb->count() - 1; i >= 0; --i) {
1338 pair<string, string> tmp = parseFontName(fromqstr(cb->text(i)));
1339 if (compare_no_case(tmp.first, family) == 0) {
1340 cb->setCurrentItem(i);
1345 // family alone can contain e.g. "Helvetica [Adobe]"
1346 pair<string, string> tmpfam = parseFontName(family);
1348 // We count in reverse in order to prefer the Xft foundry
1349 for (int i = cb->count() - 1; i >= 0; --i) {
1350 pair<string, string> tmp = parseFontName(fromqstr(cb->text(i)));
1351 if (compare_no_case(tmp.first, tmpfam.first) == 0) {
1352 cb->setCurrentItem(i);
1357 // Bleh, default fonts, and the names couldn't be found. Hack
1358 // for bug 1063. Qt makes baby Jesus cry.
1362 if (family == lyx_gui::roman_font_name()) {
1363 font.setStyleHint(QFont::Serif);
1364 font.setFamily(family.c_str());
1365 } else if (family == lyx_gui::sans_font_name()) {
1366 font.setStyleHint(QFont::SansSerif);
1367 font.setFamily(family.c_str());
1368 } else if (family == lyx_gui::typewriter_font_name()) {
1369 font.setStyleHint(QFont::TypeWriter);
1370 font.setFamily(family.c_str());
1372 lyxerr << "FAILED to find the default font: '"
1373 << foundry << "', '" << family << '\''<< endl;
1377 QFontInfo info(font);
1378 pair<string, string> tmp = parseFontName(fromqstr(info.family()));
1379 string const & default_font_name = tmp.first;
1380 lyxerr << "Apparent font is " << default_font_name << endl;
1382 for (int i = 0; i < cb->count(); ++i) {
1383 lyxerr << "Looking at " << fromqstr(cb->text(i)) << endl;
1384 if (compare_no_case(fromqstr(cb->text(i)),
1385 default_font_name) == 0) {
1386 cb->setCurrentItem(i);
1391 lyxerr << "FAILED to find the font: '"
1392 << foundry << "', '" << family << '\'' <<endl;
1395 } // end namespace anon
1399 QString const external_path(string const & input)
1401 return toqstr(lyx::support::os::external_path(input));
1406 void QPrefsDialog::update(LyXRC const & rc)
1408 // FIXME: remove rtl_support bool
1409 languageModule->rtlCB->setChecked(rc.rtl_support);
1410 languageModule->markForeignCB->setChecked(rc.mark_foreign_language);
1411 languageModule->autoBeginCB->setChecked(rc.language_auto_begin);
1412 languageModule->autoEndCB->setChecked(rc.language_auto_end);
1413 languageModule->useBabelCB->setChecked(rc.language_use_babel);
1414 languageModule->globalCB->setChecked(rc.language_global_options);
1415 languageModule->languagePackageED->setText(toqstr(rc.language_package));
1416 languageModule->startCommandED->setText(toqstr(rc.language_command_begin));
1417 languageModule->endCommandED->setText(toqstr(rc.language_command_end));
1419 int const pos = int(findPos(lang_, rc.default_language));
1420 languageModule->defaultLanguageCO->setCurrentItem(pos);
1422 uiModule->uiFileED->setText(external_path(rc.ui_file));
1423 uiModule->bindFileED->setText(external_path(rc.bind_file));
1424 uiModule->cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1425 // convert to minutes
1426 int mins(rc.autosave / 60);
1427 if (rc.autosave && !mins)
1429 uiModule->autoSaveSB->setValue(mins);
1430 uiModule->autoSaveCB->setChecked(rc.make_backup);
1431 uiModule->lastfilesSB->setValue(rc.num_lastfiles);
1434 identityModule->nameED->setText(toqstr(rc.user_name));
1435 identityModule->emailED->setText(toqstr(rc.user_email));
1438 // FIXME: can derive CB from the two EDs
1439 keyboardModule->keymapCB->setChecked(rc.use_kbmap);
1440 // no idea why we need these. Fscking Qt.
1441 keyboardModule->firstKeymapED->setEnabled(rc.use_kbmap);
1442 keyboardModule->firstKeymapPB->setEnabled(rc.use_kbmap);
1443 keyboardModule->firstKeymapLA->setEnabled(rc.use_kbmap);
1444 keyboardModule->secondKeymapED->setEnabled(rc.use_kbmap);
1445 keyboardModule->secondKeymapPB->setEnabled(rc.use_kbmap);
1446 keyboardModule->secondKeymapLA->setEnabled(rc.use_kbmap);
1447 keyboardModule->firstKeymapED->setText(external_path(rc.primary_kbmap));
1448 keyboardModule->secondKeymapED->setText(external_path(rc.secondary_kbmap));
1452 asciiModule->asciiLinelengthSB->setValue(rc.ascii_linelen);
1453 asciiModule->asciiRoffED->setText(toqstr(rc.ascii_roff_command));
1457 dateModule->DateED->setText(toqstr(rc.date_insert_format));
1461 #if defined(__CYGWIN__) || defined(__CYGWIN32__)
1462 cygwinpathModule->pathCB->setChecked(rc.cygwin_path_fix);
1467 latexModule->latexEncodingED->setText(toqstr(rc.fontenc));
1468 latexModule->latexChecktexED->setText(toqstr(rc.chktex_command));
1469 latexModule->latexBibtexED->setText(toqstr(rc.bibtex_command));
1470 latexModule->latexIndexED->setText(toqstr(rc.index_command));
1471 latexModule->latexAutoresetCB->setChecked(rc.auto_reset_options);
1472 latexModule->latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
1473 latexModule->latexPaperSizeCO->setCurrentItem(
1474 form_->controller().fromPaperSize(rc.default_papersize));
1478 switch (rc.preview) {
1479 case LyXRC::PREVIEW_OFF:
1480 displayModule->instantPreviewCO->setCurrentItem(0);
1482 case LyXRC::PREVIEW_NO_MATH :
1483 displayModule->instantPreviewCO->setCurrentItem(1);
1485 case LyXRC::PREVIEW_ON :
1486 displayModule->instantPreviewCO->setCurrentItem(2);
1491 switch (rc.display_graphics) {
1492 case lyx::graphics::NoDisplay: item = 3; break;
1493 case lyx::graphics::ColorDisplay: item = 2; break;
1494 case lyx::graphics::GrayscaleDisplay: item = 1; break;
1495 case lyx::graphics::MonochromeDisplay: item = 0; break;
1498 displayModule->displayGraphicsCO->setCurrentItem(item);
1502 pathsModule->workingDirED->setText(external_path(rc.document_path));
1503 pathsModule->templateDirED->setText(external_path(rc.template_path));
1504 pathsModule->backupDirED->setText(external_path(rc.backupdir_path));
1505 pathsModule->tempDirED->setText(external_path(rc.tempdir_path));
1506 pathsModule->pathPrefixED->setText(toqstr(rc.path_prefix));
1507 // FIXME: should be a checkbox only
1508 pathsModule->lyxserverDirED->setText(external_path(rc.lyxpipes));
1512 spellcheckerModule->spellCommandCO->setCurrentItem(0);
1514 if (rc.isp_command == "ispell") {
1515 spellcheckerModule->spellCommandCO->setCurrentItem(0);
1516 } else if (rc.isp_command == "aspell") {
1517 spellcheckerModule->spellCommandCO->setCurrentItem(1);
1518 } else if (rc.isp_command == "hspell") {
1519 spellcheckerModule->spellCommandCO->setCurrentItem(2);
1522 if (rc.use_spell_lib) {
1523 #if defined(USE_ASPELL) || defined(USE_PSPELL)
1524 spellcheckerModule->spellCommandCO->setCurrentItem(3);
1528 // FIXME: remove isp_use_alt_lang
1529 spellcheckerModule->altLanguageED->setText(toqstr(rc.isp_alt_lang));
1530 // FIXME: remove isp_use_esc_chars
1531 spellcheckerModule->escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
1532 // FIXME: remove isp_use_pers_dict
1533 spellcheckerModule->persDictionaryED->setText(external_path(rc.isp_pers_dict));
1534 spellcheckerModule->compoundWordCB->setChecked(rc.isp_accept_compound);
1535 spellcheckerModule->inputEncodingCB->setChecked(rc.isp_use_input_encoding);
1540 printerModule->printerAdaptCB->setChecked(rc.print_adapt_output);
1541 printerModule->printerCommandED->setText(toqstr(rc.print_command));
1542 printerModule->printerNameED->setText(toqstr(rc.printer));
1544 printerModule->printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1545 printerModule->printerCopiesED->setText(toqstr(rc.print_copies_flag));
1546 printerModule->printerReverseED->setText(toqstr(rc.print_reverse_flag));
1547 printerModule->printerToPrinterED->setText(toqstr(rc.print_to_printer));
1548 printerModule->printerExtensionED->setText(toqstr(rc.print_file_extension));
1549 printerModule->printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1550 printerModule->printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1551 printerModule->printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1552 printerModule->printerOddED->setText(toqstr(rc.print_oddpage_flag));
1553 printerModule->printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1554 printerModule->printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1555 printerModule->printerToFileED->setText(external_path(rc.print_to_file));
1556 printerModule->printerExtraED->setText(toqstr(rc.print_extra_options));
1557 printerModule->printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1558 printerModule->printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1563 setComboxFont(screenfontsModule->screenRomanCO, rc.roman_font_name,
1564 rc.roman_font_foundry);
1565 setComboxFont(screenfontsModule->screenSansCO, rc.sans_font_name,
1566 rc.sans_font_foundry);
1567 setComboxFont(screenfontsModule->screenTypewriterCO, rc.typewriter_font_name,
1568 rc.typewriter_font_foundry);
1570 select_roman(screenfontsModule->screenRomanCO->currentText());
1571 select_sans(screenfontsModule->screenSansCO->currentText());
1572 select_typewriter(screenfontsModule->screenTypewriterCO->currentText());
1574 screenfontsModule->screenZoomSB->setValue(rc.zoom);
1575 screenfontsModule->screenDpiSB->setValue(rc.dpi);
1576 screenfontsModule->screenTinyED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_TINY]));
1577 screenfontsModule->screenSmallestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SCRIPT]));
1578 screenfontsModule->screenSmallerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_FOOTNOTE]));
1579 screenfontsModule->screenSmallED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SMALL]));
1580 screenfontsModule->screenNormalED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_NORMAL]));
1581 screenfontsModule->screenLargeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGE]));
1582 screenfontsModule->screenLargerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGER]));
1583 screenfontsModule->screenLargestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGEST]));
1584 screenfontsModule->screenHugeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_HUGE]));
1585 screenfontsModule->screenHugerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_HUGER]));
1594 } // namespace frontend