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.
13 #include "qt_helpers.h"
15 #include "QPrefsDialog.h"
18 #include "panelstack.h"
19 #include "qcoloritem.h"
20 #include "qfontexample.h"
22 #include "ui/QPrefAsciiModule.h"
23 #include "ui/QPrefDateModule.h"
24 #include "ui/QPrefKeyboardModule.h"
25 #include "ui/QPrefLatexModule.h"
26 #include "ui/QPrefScreenFontsModule.h"
27 #include "ui/QPrefColorsModule.h"
28 #include "ui/QPrefDisplayModule.h"
29 #include "ui/QPrefPathsModule.h"
30 #include "ui/QPrefSpellcheckerModule.h"
31 #include "ui/QPrefConvertersModule.h"
32 #include "ui/QPrefCopiersModule.h"
33 #include "ui/QPrefFileformatsModule.h"
34 #include "ui/QPrefLanguageModule.h"
35 #include "ui/QPrefPrinterModule.h"
36 #include "ui/QPrefUIModule.h"
37 #include "ui/QPrefIdentityModule.h"
42 #include "controllers/ControlPrefs.h"
44 #include <qcheckbox.h>
45 #include <qcolordialog.h>
46 #include <qcombobox.h>
47 #include <qfontdatabase.h>
48 #include <qlineedit.h>
49 #include <qpushbutton.h>
58 QPrefsDialog::QPrefsDialog(QPrefs * form)
59 : QPrefsDialogBase(0, 0, false, 0), form_(form)
61 connect(savePB, SIGNAL(clicked()),
62 form, SLOT(slotOK()));
63 connect(applyPB, SIGNAL(clicked()),
64 form, SLOT(slotApply()));
65 connect(closePB, SIGNAL(clicked()),
66 form, SLOT(slotClose()));
67 connect(restorePB, SIGNAL(clicked()),
68 form, SLOT(slotRestore()));
70 asciiModule = new QPrefAsciiModule(this);
71 dateModule = new QPrefDateModule(this);
72 keyboardModule = new QPrefKeyboardModule(this);
73 latexModule = new QPrefLatexModule(this);
74 screenfontsModule = new QPrefScreenFontsModule(this);
75 colorsModule = new QPrefColorsModule(this);
76 displayModule = new QPrefDisplayModule(this);
77 pathsModule = new QPrefPathsModule(this);
78 spellcheckerModule = new QPrefSpellcheckerModule(this);
79 convertersModule = new QPrefConvertersModule(this);
80 copiersModule = new QPrefCopiersModule(this);
81 fileformatsModule = new QPrefFileformatsModule(this);
82 languageModule = new QPrefLanguageModule(this);
83 printerModule = new QPrefPrinterModule(this);
84 uiModule = new QPrefUIModule(this);
85 identityModule = new QPrefIdentityModule(this);
87 string const laf = _("Look and feel");
88 prefsPS->addCategory(laf);
89 prefsPS->addPanel(uiModule, _("User interface"), laf);
90 prefsPS->addPanel(screenfontsModule, _("Screen fonts"), laf);
91 prefsPS->addPanel(colorsModule, _("Colors"), laf);
92 prefsPS->addPanel(displayModule, _("Graphics"), laf);
93 prefsPS->addPanel(keyboardModule, _("Keyboard"), laf);
95 string const ls = _("Language settings");
96 prefsPS->addCategory(ls);
97 prefsPS->addPanel(languageModule, _("Language"), ls);
98 prefsPS->addPanel(spellcheckerModule, _("Spell-checker"), ls);
100 string const op = _("Outputs");
101 prefsPS->addCategory(op);
102 prefsPS->addPanel(asciiModule, _("ASCII"), op);
103 prefsPS->addPanel(dateModule, _("Date format"), op);
104 prefsPS->addPanel(latexModule, _("LaTeX"), op);
105 prefsPS->addPanel(printerModule, _("Printer"), op);
107 prefsPS->addPanel(identityModule, _("Identity"));
108 prefsPS->addPanel(pathsModule, _("Paths"));
109 prefsPS->addPanel(fileformatsModule, _("File formats"));
110 prefsPS->addPanel(convertersModule, _("Converters"));
111 prefsPS->addPanel(copiersModule, _("Copiers"));
113 prefsPS->setCurrentPanel(_("User interface"));
115 // FIXME: put in controller
116 for (int i = 0; i < LColor::ignore; ++i) {
117 LColor::color lc = static_cast<LColor::color>(i);
118 if (lc == LColor::none
119 || lc == LColor::black
120 || lc == LColor::white
122 || lc == LColor::green
123 || lc == LColor::blue
124 || lc == LColor::cyan
125 || lc == LColor::magenta
126 || lc == LColor::yellow
127 || lc == LColor::inherit
128 || lc == LColor::ignore) continue;
130 colors_.push_back(lc);
131 string const x11name(lcolor.getX11Name(lc));
132 string const guiname(lcolor.getGUIName(lc));
133 QColorItem * ci(new QColorItem(QColor(toqstr(x11name)),
135 colorsModule->lyxObjectsLB->insertItem(ci);
138 QFontDatabase fontdb;
139 QStringList families(fontdb.families());
141 connect(screenfontsModule->screenRomanCO, SIGNAL(activated(const QString&)), this, SLOT(select_roman(const QString&)));
142 connect(screenfontsModule->screenSansCO, SIGNAL(activated(const QString&)), this, SLOT(select_sans(const QString&)));
143 connect(screenfontsModule->screenTypewriterCO, SIGNAL(activated(const QString&)), this, SLOT(select_typewriter(const QString&)));
145 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
146 screenfontsModule->screenRomanCO->insertItem(*it);
147 screenfontsModule->screenSansCO->insertItem(*it);
148 screenfontsModule->screenTypewriterCO->insertItem(*it);
151 connect(uiModule->uiFilePB, SIGNAL(clicked()), this, SLOT(select_ui()));
152 connect(uiModule->bindFilePB, SIGNAL(clicked()), this, SLOT(select_bind()));
154 connect(keyboardModule->firstKeymapPB, SIGNAL(clicked()), this, SLOT(select_keymap1()));
155 connect(keyboardModule->secondKeymapPB, SIGNAL(clicked()), this, SLOT(select_keymap2()));
157 connect(spellcheckerModule->persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
159 connect(pathsModule->templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
160 connect(pathsModule->tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
161 connect(pathsModule->backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
162 connect(pathsModule->workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
163 connect(pathsModule->lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
165 connect(colorsModule->colorChangePB, SIGNAL(clicked()), this, SLOT(change_color()));
166 connect(colorsModule->lyxObjectsLB, SIGNAL(selected(int)), this, SLOT(change_color()));
168 connect(fileformatsModule->formatNewPB, SIGNAL(clicked()), this, SLOT(new_format()));
169 connect(fileformatsModule->formatRemovePB, SIGNAL(clicked()), this, SLOT(remove_format()));
170 connect(fileformatsModule->formatModifyPB, SIGNAL(clicked()), this, SLOT(modify_format()));
171 connect(fileformatsModule->formatsLB, SIGNAL(highlighted(int)), this, SLOT(switch_format(int)));
173 connect(convertersModule->converterNewPB, SIGNAL(clicked()), this, SLOT(new_converter()));
174 connect(convertersModule->converterRemovePB, SIGNAL(clicked()), this, SLOT(remove_converter()));
175 connect(convertersModule->converterModifyPB, SIGNAL(clicked()), this, SLOT(modify_converter()));
176 connect(convertersModule->convertersLB, SIGNAL(highlighted(int)), this, SLOT(switch_converter(int)));
177 connect(convertersModule->converterFromCO, SIGNAL(activated(const QString&)), this, SLOT(converter_changed()));
178 connect(convertersModule->converterToCO, SIGNAL(activated(const QString&)), this, SLOT(converter_changed()));
179 connect(convertersModule->converterED, SIGNAL(textChanged(const QString&)), this, SLOT(converter_changed()));
180 connect(convertersModule->converterFlagED, SIGNAL(textChanged(const QString&)), this, SLOT(converter_changed()));
182 // Qt really sucks. This is as ugly as it looks, but the alternative
183 // means having to derive every module == bloat
185 connect(convertersModule->converterNewPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
186 connect(convertersModule->converterRemovePB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
187 connect(convertersModule->converterModifyPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
189 connect(copiersModule->copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
190 connect(copiersModule->copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
191 connect(copiersModule->copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
192 connect(copiersModule->AllCopiersLB, SIGNAL(highlighted(int)), this, SLOT(switch_copierLB(int)));
193 connect(copiersModule->copierFormatCO, SIGNAL(activated(int)), this, SLOT(switch_copierCO(int)));
194 connect(copiersModule->copierNewPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
195 connect(copiersModule->copierRemovePB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
196 connect(copiersModule->copierModifyPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
198 connect(fileformatsModule->formatNewPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
199 connect(fileformatsModule->formatRemovePB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
200 connect(fileformatsModule->formatModifyPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
201 connect(languageModule->rtlCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
202 connect(languageModule->markForeignCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
203 connect(languageModule->autoBeginCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
204 connect(languageModule->autoEndCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
205 connect(languageModule->useBabelCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
206 connect(languageModule->globalCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
207 connect(languageModule->languagePackageED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
208 connect(languageModule->startCommandED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
209 connect(languageModule->endCommandED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
210 connect(languageModule->defaultLanguageCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
211 connect(uiModule->uiFileED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
212 connect(uiModule->bindFileED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
213 connect(uiModule->cursorFollowsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
214 connect(uiModule->wheelMouseSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
215 connect(uiModule->autoSaveSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
216 connect(uiModule->autoSaveCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
217 connect(uiModule->lastfilesSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
218 connect(keyboardModule->keymapCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
219 connect(keyboardModule->firstKeymapED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
220 connect(keyboardModule->secondKeymapED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
221 connect(asciiModule->asciiLinelengthSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
222 connect(asciiModule->asciiRoffED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
223 connect(dateModule->DateED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
224 connect(latexModule->latexEncodingED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
225 connect(latexModule->latexChecktexED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
226 connect(latexModule->latexBibtexED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
227 connect(latexModule->latexIndexED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
228 connect(latexModule->latexAutoresetCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
229 connect(latexModule->latexDviPaperED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
230 connect(latexModule->latexPaperSizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
231 connect(displayModule->instantPreviewCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
232 connect(displayModule->displayGraphicsCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
233 connect(pathsModule->workingDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
234 connect(pathsModule->templateDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
235 connect(pathsModule->backupDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
236 connect(pathsModule->tempDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
237 connect(pathsModule->lyxserverDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
238 connect(spellcheckerModule->spellCommandCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
239 connect(spellcheckerModule->altLanguageED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
240 connect(spellcheckerModule->escapeCharactersED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
241 connect(spellcheckerModule->persDictionaryED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
242 connect(spellcheckerModule->compoundWordCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
243 connect(spellcheckerModule->inputEncodingCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
244 connect(printerModule->printerAdaptCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
245 connect(printerModule->printerCommandED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
246 connect(printerModule->printerNameED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
247 connect(printerModule->printerPageRangeED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
248 connect(printerModule->printerCopiesED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
249 connect(printerModule->printerReverseED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
250 connect(printerModule->printerToPrinterED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
251 connect(printerModule->printerExtensionED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
252 connect(printerModule->printerSpoolCommandED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
253 connect(printerModule->printerPaperTypeED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
254 connect(printerModule->printerEvenED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
255 connect(printerModule->printerOddED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
256 connect(printerModule->printerCollatedED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
257 connect(printerModule->printerLandscapeED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
258 connect(printerModule->printerToFileED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
259 connect(printerModule->printerExtraED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
260 connect(printerModule->printerSpoolPrefixED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
261 connect(printerModule->printerPaperSizeED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
262 connect(screenfontsModule->screenRomanCO, SIGNAL(activated(const QString&)), this, SLOT(change_adaptor()));
263 connect(screenfontsModule->screenSansCO, SIGNAL(activated(const QString&)), this, SLOT(change_adaptor()));
264 connect(screenfontsModule->screenTypewriterCO, SIGNAL(activated(const QString&)), this, SLOT(change_adaptor()));
265 connect(screenfontsModule->screenZoomSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
266 connect(screenfontsModule->screenDpiSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
267 connect(screenfontsModule->screenTinyED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
268 connect(screenfontsModule->screenSmallestED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
269 connect(screenfontsModule->screenSmallerED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
270 connect(screenfontsModule->screenSmallED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
271 connect(screenfontsModule->screenNormalED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
272 connect(screenfontsModule->screenLargeED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
273 connect(screenfontsModule->screenLargerED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
274 connect(screenfontsModule->screenLargestED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
275 connect(screenfontsModule->screenHugeED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
276 connect(screenfontsModule->screenHugerED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
277 connect(identityModule->nameED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
278 connect(identityModule->emailED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
282 QPrefsDialog::~QPrefsDialog()
287 void QPrefsDialog::closeEvent(QCloseEvent * e)
294 void QPrefsDialog::change_adaptor()
300 void QPrefsDialog::updateConverters()
302 QPrefConvertersModule * convertmod(convertersModule);
304 convertmod->converterFromCO->clear();
305 convertmod->converterToCO->clear();
307 Formats::const_iterator cit = form_->formats().begin();
308 Formats::const_iterator end = form_->formats().end();
309 for (; cit != end; ++cit) {
310 convertmod->converterFromCO->insertItem(toqstr(cit->prettyname()));
311 convertmod->converterToCO->insertItem(toqstr(cit->prettyname()));
314 convertmod->convertersLB->clear();
316 Converters::const_iterator ccit = form_->converters().begin();
317 Converters::const_iterator cend = form_->converters().end();
318 for (; ccit != cend; ++ccit) {
319 std::string const name = ccit->From->prettyname() + " -> "
320 + ccit->To->prettyname();
321 convertmod->convertersLB->insertItem(toqstr(name));
324 if (convertmod->convertersLB->currentItem() == -1)
325 convertmod->convertersLB->setCurrentItem(0);
327 updateConverterButtons();
331 void QPrefsDialog::switch_converter(int nr)
333 Converter const & c(form_->converters().get(nr));
334 convertersModule->converterFromCO->setCurrentItem(form_->formats().getNumber(c.from));
335 convertersModule->converterToCO->setCurrentItem(form_->formats().getNumber(c.to));
336 convertersModule->converterED->setText(toqstr(c.command));
337 convertersModule->converterFlagED->setText(toqstr(c.flags));
339 updateConverterButtons();
343 void QPrefsDialog::converter_changed()
345 updateConverterButtons();
349 void QPrefsDialog::updateConverterButtons()
351 Format const & from(form_->formats().get(
352 convertersModule->converterFromCO->currentItem()));
353 Format const & to(form_->formats().get(
354 convertersModule->converterToCO->currentItem()));
355 int const sel = form_->converters().getNumber(from.name(), to.name());
356 bool const known = !(sel < 0);
357 bool const valid = !(convertersModule->converterED->text().isEmpty()
358 || from.name() == to.name());
360 Converter const & c(form_->converters().get(
361 convertersModule->convertersLB->currentItem()));
362 string const old_command = c.command;
363 string const old_flag = c.flags;
364 string const new_command(fromqstr(convertersModule->converterED->text()));
365 string const new_flag(fromqstr(convertersModule->converterFlagED->text()));
367 bool modified = ((old_command != new_command) || (old_flag != new_flag));
369 convertersModule->converterModifyPB->setEnabled(valid && known && modified);
370 convertersModule->converterNewPB->setEnabled(valid && !known);
371 convertersModule->converterRemovePB->setEnabled(known);
376 // specify unique from/to or it doesn't appear. This is really bad UI
377 void QPrefsDialog::new_converter()
379 Format const & from(form_->formats().get(convertersModule->converterFromCO->currentItem()));
380 Format const & to(form_->formats().get(convertersModule->converterToCO->currentItem()));
381 string const command(fromqstr(convertersModule->converterED->text()));
382 string const flags(fromqstr(convertersModule->converterFlagED->text()));
384 Converter const * old = form_->converters().getConverter(from.name(), to.name());
385 form_->converters().add(from.name(), to.name(), command, flags);
387 form_->converters().updateLast(form_->formats());
390 convertersModule->convertersLB->setCurrentItem(convertersModule->convertersLB->count() - 1);
394 void QPrefsDialog::modify_converter()
396 Format const & from(form_->formats().get(convertersModule->converterFromCO->currentItem()));
397 Format const & to(form_->formats().get(convertersModule->converterToCO->currentItem()));
398 string flags(fromqstr(convertersModule->converterFlagED->text()));
399 string name(fromqstr(convertersModule->converterED->text()));
401 Converter const * old = form_->converters().getConverter(from.name(), to.name());
402 form_->converters().add(from.name(), to.name(), name, flags);
404 form_->converters().updateLast(form_->formats());
410 void QPrefsDialog::remove_converter()
412 Format const & from(form_->formats().get(convertersModule->converterFromCO->currentItem()));
413 Format const & to(form_->formats().get(convertersModule->converterToCO->currentItem()));
414 form_->converters().erase(from.name(), to.name());
419 void QPrefsDialog::updateCopiers()
422 copiersModule->copierFormatCO->clear();
424 for (Formats::const_iterator it = form_->formats().begin(),
425 end = form_->formats().end();
427 copiersModule->copierFormatCO->insertItem(toqstr(it->prettyname()));
430 // The browser widget
431 copiersModule->AllCopiersLB->clear();
433 for (Movers::iterator it = form_->movers().begin(),
434 end = form_->movers().end();
436 std::string const & command = it->second.command();
439 std::string const & fmt = it->first;
440 std::string const & pretty = form_->formats().prettyName(fmt);
442 copiersModule->AllCopiersLB->insertItem(toqstr(pretty));
445 if (copiersModule->AllCopiersLB->currentItem() == -1)
446 copiersModule->AllCopiersLB->setCurrentItem(0);
452 struct SamePrettyName {
453 SamePrettyName(string const & n) : pretty_name_(n) {}
455 bool operator()(::Format const & fmt) const {
456 return fmt.prettyname() == pretty_name_;
460 string const pretty_name_;
464 Format const * getFormat(std::string const & prettyname)
466 Formats::const_iterator it = ::formats.begin();
467 Formats::const_iterator const end = ::formats.end();
468 it = std::find_if(it, end, SamePrettyName(prettyname));
469 return it == end ? 0 : &*it;
475 void QPrefsDialog::switch_copierLB(int nr)
477 std::string const browser_text =
478 fromqstr(copiersModule->AllCopiersLB->currentText());
479 lyxerr << "switch_copierLB(" << nr << ")\n"
480 << "browser_text " << browser_text << std::endl;
481 Format const * fmt = getFormat(browser_text);
485 string const & fmt_name = fmt->name();
486 string const & gui_name = fmt->prettyname();
487 string const & command = form_->movers().command(fmt_name);
489 lyxerr << "switch_copierLB(" << nr << ")\n"
490 << "fmt_name " << fmt_name << '\n'
491 << "gui_name " << gui_name << '\n'
492 << "command " << command << std::endl;
494 copiersModule->copierED->clear();
495 int const combo_size = copiersModule->copierFormatCO->count();
496 for (int i = 0; i < combo_size; ++i) {
497 QString const qtext = copiersModule->copierFormatCO->text(i);
498 std::string const text = fromqstr(qtext);
499 if (text == gui_name) {
500 copiersModule->copierFormatCO->setCurrentItem(i);
501 copiersModule->copierED->setText(toqstr(command));
502 lyxerr << "found combo item " << i << std::endl;
509 void QPrefsDialog::switch_copierCO(int nr)
511 std::string const combo_text =
512 fromqstr(copiersModule->copierFormatCO->currentText());
513 lyxerr << "switch_copierCO(" << nr << ")\n"
514 << "combo_text " << combo_text << std::endl;
515 Format const * fmt = getFormat(combo_text);
519 string const & fmt_name = fmt->name();
520 string const & gui_name = fmt->prettyname();
521 string const & command = form_->movers().command(fmt_name);
523 lyxerr << "switch_copierCO(" << nr << ")\n"
524 << "fmt_name " << fmt_name << '\n'
525 << "gui_name " << gui_name << '\n'
526 << "command " << command << std::endl;
528 copiersModule->copierED->setText(toqstr(command));
530 int const index = copiersModule->AllCopiersLB->currentItem();
532 copiersModule->AllCopiersLB->setSelected(index, false);
534 int const browser_size = copiersModule->AllCopiersLB->count();
535 for (int i = 0; i < browser_size; ++i) {
536 QString const qtext = copiersModule->AllCopiersLB->text(i);
537 std::string const text = fromqstr(qtext);
538 if (text == gui_name) {
539 copiersModule->AllCopiersLB->setSelected(i, true);
540 int top = std::max(i - 5, 0);
541 copiersModule->AllCopiersLB->setTopItem(top);
548 void QPrefsDialog::new_copier()
550 std::string const combo_text =
551 fromqstr(copiersModule->copierFormatCO->currentText());
552 Format const * fmt = getFormat(combo_text);
556 string const command = fromqstr(copiersModule->copierED->text());
560 form_->movers().set(fmt->name(), command);
563 int const last = copiersModule->AllCopiersLB->count() - 1;
564 copiersModule->AllCopiersLB->setCurrentItem(last);
568 void QPrefsDialog::modify_copier()
570 std::string const combo_text =
571 fromqstr(copiersModule->copierFormatCO->currentText());
572 Format const * fmt = getFormat(combo_text);
576 string const command = fromqstr(copiersModule->copierED->text());
577 form_->movers().set(fmt->name(), command);
583 void QPrefsDialog::remove_copier()
585 std::string const combo_text =
586 fromqstr(copiersModule->copierFormatCO->currentText());
587 Format const * fmt = getFormat(combo_text);
591 string const & fmt_name = fmt->name();
592 form_->movers().set(fmt_name, string());
598 void QPrefsDialog::updateFormats()
600 QPrefFileformatsModule * formatmod(fileformatsModule);
602 formatmod->formatsLB->clear();
604 Formats::const_iterator cit = form_->formats().begin();
605 Formats::const_iterator end = form_->formats().end();
606 for (; cit != end; ++cit) {
607 formatmod->formatsLB->insertItem(toqstr(cit->prettyname()));
610 if (formatmod->formatsLB->currentItem() == -1)
611 formatmod->formatsLB->setCurrentItem(0);
615 void QPrefsDialog::switch_format(int nr)
617 Format const & f(form_->formats().get(nr));
618 fileformatsModule->formatED->setText(toqstr(f.name()));
619 fileformatsModule->guiNameED->setText(toqstr(f.prettyname()));
620 fileformatsModule->extensionED->setText(toqstr(f.extension()));
621 fileformatsModule->shortcutED->setText(toqstr(f.shortcut()));
622 fileformatsModule->viewerED->setText(toqstr(f.viewer()));
623 fileformatsModule->editorED->setText(toqstr(f.editor()));
624 fileformatsModule->formatRemovePB->setEnabled(
625 !form_->converters().formatIsUsed(f.name()));
629 void QPrefsDialog::new_format()
631 form_->formats().add(_("New"));
632 form_->formats().sort();
634 fileformatsModule->formatsLB->setCurrentItem(form_->formats().getNumber(_("New")));
635 form_->converters().update(form_->formats());
640 void QPrefsDialog::modify_format()
642 Format const & oldformat(form_->formats().get(fileformatsModule->formatsLB->currentItem()));
643 string const oldpretty(oldformat.prettyname());
644 string const name(fromqstr(fileformatsModule->formatED->text()));
645 form_->formats().erase(oldformat.name());
647 string const prettyname = fromqstr(fileformatsModule->guiNameED->text());
648 string const extension = fromqstr(fileformatsModule->extensionED->text());
649 string const shortcut = fromqstr(fileformatsModule->shortcutED->text());
650 string const viewer = fromqstr(fileformatsModule->viewerED->text());
651 string const editor = fromqstr(fileformatsModule->editorED->text());
653 form_->formats().add(name, extension, prettyname, shortcut, viewer, editor);
654 form_->formats().sort();
656 fileformatsModule->formatsLB->setUpdatesEnabled(false);
658 fileformatsModule->formatsLB->setUpdatesEnabled(true);
659 fileformatsModule->formatsLB->update();
665 void QPrefsDialog::remove_format()
667 int const nr(fileformatsModule->formatsLB->currentItem());
670 form_->formats().erase(form_->formats().get(nr).name());
672 form_->converters().update(form_->formats());
677 void QPrefsDialog::change_color()
679 QListBox * lb(colorsModule->lyxObjectsLB);
680 if (lb->currentItem() < 0)
682 QListBoxItem * ib(lb->item(lb->currentItem()));
683 QColorItem * ci(static_cast<QColorItem*>(ib));
684 QColor c(QColorDialog::getColor(ci->color(), qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget()));
693 void QPrefsDialog::select_ui()
695 string file(form_->controller().browseUI(fromqstr(uiModule->uiFileED->text())));
697 uiModule->uiFileED->setText(toqstr(file));
701 void QPrefsDialog::select_bind()
703 string file(form_->controller().browsebind(fromqstr(uiModule->bindFileED->text())));
705 uiModule->bindFileED->setText(toqstr(file));
709 void QPrefsDialog::select_keymap1()
711 string file(form_->controller().browsekbmap(fromqstr(keyboardModule->firstKeymapED->text())));
713 keyboardModule->firstKeymapED->setText(toqstr(file));
717 void QPrefsDialog::select_keymap2()
719 string file(form_->controller().browsekbmap(fromqstr(keyboardModule->secondKeymapED->text())));
721 keyboardModule->secondKeymapED->setText(toqstr(file));
725 void QPrefsDialog::select_dict()
727 string file(form_->controller().browsedict(fromqstr(spellcheckerModule->persDictionaryED->text())));
729 spellcheckerModule->persDictionaryED->setText(toqstr(file));
733 // NB: the _() is OK here because it gets passed back and we toqstr() them
735 void QPrefsDialog::select_templatedir()
737 string file(form_->controller().browsedir(fromqstr(pathsModule->templateDirED->text()), _("Select a document templates directory")));
739 pathsModule->templateDirED->setText(toqstr(file));
743 void QPrefsDialog::select_tempdir()
745 string file(form_->controller().browsedir(fromqstr(pathsModule->tempDirED->text()), _("Select a temporary directory")));
747 pathsModule->tempDirED->setText(toqstr(file));
751 void QPrefsDialog::select_backupdir()
753 string file(form_->controller().browsedir(fromqstr(pathsModule->backupDirED->text()), _("Select a backups directory")));
755 pathsModule->backupDirED->setText(toqstr(file));
759 void QPrefsDialog::select_workingdir()
761 string file(form_->controller().browsedir(fromqstr(pathsModule->workingDirED->text()), _("Select a document directory")));
763 pathsModule->workingDirED->setText(toqstr(file));
767 void QPrefsDialog::select_lyxpipe()
769 string file(form_->controller().browse(fromqstr(pathsModule->lyxserverDirED->text()), _("Give a filename for the LyX server pipe")));
771 pathsModule->lyxserverDirED->setText(toqstr(file));
775 void QPrefsDialog::select_roman(const QString& name)
777 screenfontsModule->screenRomanFE->set(QFont(name), name);
781 void QPrefsDialog::select_sans(const QString& name)
783 screenfontsModule->screenSansFE->set(QFont(name), name);
787 void QPrefsDialog::select_typewriter(const QString& name)
789 screenfontsModule->screenTypewriterFE->set(QFont(name), name);
792 } // namespace frontend