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 "frontends/Alert.h"
24 #include "ui/QPrefAsciiModule.h"
25 #include "ui/QPrefDateModule.h"
26 #include "ui/QPrefKeyboardModule.h"
27 #include "ui/QPrefLatexModule.h"
28 #include "ui/QPrefScreenFontsModule.h"
29 #include "ui/QPrefColorsModule.h"
30 #if defined(__CYGWIN__) || defined(_WIN32)
31 #include "ui/QPrefCygwinPathModule.h"
33 #include "ui/QPrefDisplayModule.h"
34 #include "ui/QPrefPathsModule.h"
35 #include "ui/QPrefSpellcheckerModule.h"
36 #include "ui/QPrefConvertersModule.h"
37 #include "ui/QPrefCopiersModule.h"
38 #include "ui/QPrefFileformatsModule.h"
39 #include "ui/QPrefLanguageModule.h"
40 #include "ui/QPrefPrinterModule.h"
41 #include "ui/QPrefUIModule.h"
42 #include "ui/QPrefIdentityModule.h"
47 #include "controllers/ControlPrefs.h"
49 #include <qcheckbox.h>
50 #include <qcolordialog.h>
51 #include <qcombobox.h>
52 #include <qfontdatabase.h>
53 #include <qlineedit.h>
54 #include <qpushbutton.h>
57 #include <qvalidator.h>
64 QPrefsDialog::QPrefsDialog(QPrefs * form)
65 : QPrefsDialogBase(0, 0, false, 0), form_(form)
67 connect(savePB, SIGNAL(clicked()),
68 form, SLOT(slotOK()));
69 connect(applyPB, SIGNAL(clicked()),
70 form, SLOT(slotApply()));
71 connect(closePB, SIGNAL(clicked()),
72 form, SLOT(slotClose()));
73 connect(restorePB, SIGNAL(clicked()),
74 form, SLOT(slotRestore()));
76 asciiModule = new QPrefAsciiModule(this);
77 dateModule = new QPrefDateModule(this);
78 keyboardModule = new QPrefKeyboardModule(this);
79 latexModule = new QPrefLatexModule(this);
80 screenfontsModule = new QPrefScreenFontsModule(this);
81 colorsModule = new QPrefColorsModule(this);
82 #if defined(__CYGWIN__) || defined(_WIN32)
83 cygwinpathModule = new QPrefCygwinPathModule(this);
85 displayModule = new QPrefDisplayModule(this);
86 pathsModule = new QPrefPathsModule(this);
87 spellcheckerModule = new QPrefSpellcheckerModule(this);
88 convertersModule = new QPrefConvertersModule(this);
89 copiersModule = new QPrefCopiersModule(this);
90 fileformatsModule = new QPrefFileformatsModule(this);
91 languageModule = new QPrefLanguageModule(this);
92 printerModule = new QPrefPrinterModule(this);
93 uiModule = new QPrefUIModule(this);
94 identityModule = new QPrefIdentityModule(this);
96 string const laf = _("Look and feel");
97 prefsPS->addCategory(laf);
98 prefsPS->addPanel(uiModule, _("User interface"), laf);
99 prefsPS->addPanel(screenfontsModule, _("Screen fonts"), laf);
100 prefsPS->addPanel(colorsModule, _("Colors"), laf);
101 prefsPS->addPanel(displayModule, _("Graphics"), laf);
102 prefsPS->addPanel(keyboardModule, _("Keyboard"), laf);
104 string const ls = _("Language settings");
105 prefsPS->addCategory(ls);
106 prefsPS->addPanel(languageModule, _("Language"), ls);
107 prefsPS->addPanel(spellcheckerModule, _("Spellchecker"), ls);
109 string const op = _("Outputs");
110 prefsPS->addCategory(op);
111 prefsPS->addPanel(asciiModule, _("Plain text"), op);
112 prefsPS->addPanel(dateModule, _("Date format"), op);
113 prefsPS->addPanel(latexModule, _("LaTeX"), op);
114 #if defined(__CYGWIN__) || defined(_WIN32)
115 prefsPS->addPanel(cygwinpathModule, _("Paths"), op);
117 prefsPS->addPanel(printerModule, _("Printer"), op);
119 prefsPS->addPanel(identityModule, _("Identity"));
120 prefsPS->addPanel(pathsModule, _("Paths"));
121 prefsPS->addPanel(fileformatsModule, _("File formats"));
122 prefsPS->addPanel(convertersModule, _("Converters"));
123 prefsPS->addPanel(copiersModule, _("Copiers"));
125 prefsPS->setCurrentPanel(_("User interface"));
127 // FIXME: put in controller
128 for (int i = 0; i < LColor::ignore; ++i) {
129 LColor::color lc = static_cast<LColor::color>(i);
130 if (lc == LColor::none
131 || lc == LColor::black
132 || lc == LColor::white
134 || lc == LColor::green
135 || lc == LColor::blue
136 || lc == LColor::cyan
137 || lc == LColor::magenta
138 || lc == LColor::yellow
139 || lc == LColor::inherit
140 || lc == LColor::ignore) continue;
142 colors_.push_back(lc);
143 string const x11name(lcolor.getX11Name(lc));
144 string const guiname(lcolor.getGUIName(lc));
145 QColorItem * ci(new QColorItem(QColor(toqstr(x11name)),
147 colorsModule->lyxObjectsLB->insertItem(ci);
150 QFontDatabase fontdb;
151 QStringList families(fontdb.families());
153 connect(screenfontsModule->screenRomanCO, SIGNAL(activated(const QString&)), this, SLOT(select_roman(const QString&)));
154 connect(screenfontsModule->screenSansCO, SIGNAL(activated(const QString&)), this, SLOT(select_sans(const QString&)));
155 connect(screenfontsModule->screenTypewriterCO, SIGNAL(activated(const QString&)), this, SLOT(select_typewriter(const QString&)));
157 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
158 screenfontsModule->screenRomanCO->insertItem(*it);
159 screenfontsModule->screenSansCO->insertItem(*it);
160 screenfontsModule->screenTypewriterCO->insertItem(*it);
163 connect(uiModule->uiFilePB, SIGNAL(clicked()), this, SLOT(select_ui()));
164 connect(uiModule->bindFilePB, SIGNAL(clicked()), this, SLOT(select_bind()));
166 connect(keyboardModule->firstKeymapPB, SIGNAL(clicked()), this, SLOT(select_keymap1()));
167 connect(keyboardModule->secondKeymapPB, SIGNAL(clicked()), this, SLOT(select_keymap2()));
169 connect(spellcheckerModule->persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
171 connect(pathsModule->templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
172 connect(pathsModule->tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
173 connect(pathsModule->backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
174 connect(pathsModule->workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
175 connect(pathsModule->lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
177 connect(colorsModule->colorChangePB, SIGNAL(clicked()), this, SLOT(change_color()));
178 connect(colorsModule->lyxObjectsLB, SIGNAL(selected(int)), this, SLOT(change_color()));
180 connect(fileformatsModule->formatNewPB, SIGNAL(clicked()), this, SLOT(new_format()));
181 connect(fileformatsModule->formatRemovePB, SIGNAL(clicked()), this, SLOT(remove_format()));
182 connect(fileformatsModule->formatModifyPB, SIGNAL(clicked()), this, SLOT(modify_format()));
183 connect(fileformatsModule->formatsLB, SIGNAL(highlighted(int)), this, SLOT(switch_format(int)));
184 connect(fileformatsModule->formatED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
185 connect(fileformatsModule->guiNameED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
186 connect(fileformatsModule->shortcutED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
187 connect(fileformatsModule->extensionED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
188 connect(fileformatsModule->viewerED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
189 connect(fileformatsModule->editorED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
190 connect(fileformatsModule->documentCB, SIGNAL(toggled(bool)), this, SLOT(fileformat_changed()));
192 connect(convertersModule->converterNewPB, SIGNAL(clicked()), this, SLOT(new_converter()));
193 connect(convertersModule->converterRemovePB, SIGNAL(clicked()), this, SLOT(remove_converter()));
194 connect(convertersModule->converterModifyPB, SIGNAL(clicked()), this, SLOT(modify_converter()));
195 connect(convertersModule->convertersLB, SIGNAL(highlighted(int)), this, SLOT(switch_converter(int)));
196 connect(convertersModule->converterFromCO, SIGNAL(activated(const QString&)), this, SLOT(converter_changed()));
197 connect(convertersModule->converterToCO, SIGNAL(activated(const QString&)), this, SLOT(converter_changed()));
198 connect(convertersModule->converterED, SIGNAL(textChanged(const QString&)), this, SLOT(converter_changed()));
199 connect(convertersModule->converterFlagED, SIGNAL(textChanged(const QString&)), this, SLOT(converter_changed()));
201 // Qt really sucks. This is as ugly as it looks, but the alternative
202 // means having to derive every module == bloat
204 connect(convertersModule->converterNewPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
205 connect(convertersModule->converterRemovePB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
206 connect(convertersModule->converterModifyPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
208 connect(copiersModule->copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
209 connect(copiersModule->copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
210 connect(copiersModule->copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
211 connect(copiersModule->AllCopiersLB, SIGNAL(highlighted(int)), this, SLOT(switch_copierLB(int)));
212 connect(copiersModule->copierFormatCO, SIGNAL(activated(int)), this, SLOT(switch_copierCO(int)));
213 connect(copiersModule->copierNewPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
214 connect(copiersModule->copierRemovePB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
215 connect(copiersModule->copierModifyPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
216 connect(copiersModule->copierFormatCO, SIGNAL(activated(const QString&)), this, SLOT(copiers_changed()));
217 connect(copiersModule->copierED, SIGNAL(textChanged(const QString&)), this, SLOT(copiers_changed()));
219 connect(fileformatsModule->formatNewPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
220 connect(fileformatsModule->formatRemovePB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
221 connect(fileformatsModule->formatModifyPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
222 connect(languageModule->rtlCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
223 connect(languageModule->markForeignCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
224 connect(languageModule->autoBeginCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
225 connect(languageModule->autoEndCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
226 connect(languageModule->useBabelCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
227 connect(languageModule->globalCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
228 connect(languageModule->languagePackageED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
229 connect(languageModule->startCommandED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
230 connect(languageModule->endCommandED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
231 connect(languageModule->defaultLanguageCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
232 connect(uiModule->uiFileED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
233 connect(uiModule->bindFileED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
234 connect(uiModule->restoreCursorCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
235 connect(uiModule->loadSessionCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
236 connect(uiModule->cursorFollowsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
237 connect(uiModule->autoSaveSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
238 connect(uiModule->autoSaveCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
239 connect(uiModule->lastfilesSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
240 connect(keyboardModule->keymapCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
241 connect(keyboardModule->firstKeymapED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
242 connect(keyboardModule->secondKeymapED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
243 connect(asciiModule->asciiLinelengthSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
244 connect(asciiModule->asciiRoffED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
245 connect(dateModule->DateED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
246 #if defined(__CYGWIN__) || defined(_WIN32)
247 connect(cygwinpathModule->pathCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
249 connect(latexModule->latexEncodingED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
250 connect(latexModule->latexChecktexED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
251 connect(latexModule->latexBibtexED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
252 connect(latexModule->latexIndexED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
253 connect(latexModule->latexAutoresetCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
254 connect(latexModule->latexDviPaperED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
255 connect(latexModule->latexPaperSizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
256 connect(displayModule->instantPreviewCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
257 connect(displayModule->displayGraphicsCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
258 connect(pathsModule->workingDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
259 connect(pathsModule->templateDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
260 connect(pathsModule->backupDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
261 connect(pathsModule->tempDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
262 connect(pathsModule->lyxserverDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
263 connect(pathsModule->pathPrefixED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
264 #if defined (USE_ISPELL)
265 connect(spellcheckerModule->spellCommandCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
267 spellcheckerModule->spellCommandCO->setEnabled(false);
269 connect(spellcheckerModule->altLanguageED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
270 connect(spellcheckerModule->escapeCharactersED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
271 connect(spellcheckerModule->persDictionaryED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
272 connect(spellcheckerModule->compoundWordCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
273 connect(spellcheckerModule->inputEncodingCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
274 connect(printerModule->printerAdaptCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
275 connect(printerModule->printerCommandED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
276 connect(printerModule->printerNameED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
277 connect(printerModule->printerPageRangeED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
278 connect(printerModule->printerCopiesED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
279 connect(printerModule->printerReverseED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
280 connect(printerModule->printerToPrinterED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
281 connect(printerModule->printerExtensionED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
282 connect(printerModule->printerSpoolCommandED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
283 connect(printerModule->printerPaperTypeED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
284 connect(printerModule->printerEvenED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
285 connect(printerModule->printerOddED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
286 connect(printerModule->printerCollatedED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
287 connect(printerModule->printerLandscapeED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
288 connect(printerModule->printerToFileED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
289 connect(printerModule->printerExtraED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
290 connect(printerModule->printerSpoolPrefixED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
291 connect(printerModule->printerPaperSizeED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
292 connect(screenfontsModule->screenRomanCO, SIGNAL(activated(const QString&)), this, SLOT(change_adaptor()));
293 connect(screenfontsModule->screenSansCO, SIGNAL(activated(const QString&)), this, SLOT(change_adaptor()));
294 connect(screenfontsModule->screenTypewriterCO, SIGNAL(activated(const QString&)), this, SLOT(change_adaptor()));
295 connect(screenfontsModule->screenZoomSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
296 connect(screenfontsModule->screenDpiSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
297 connect(screenfontsModule->screenTinyED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
298 connect(screenfontsModule->screenSmallestED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
299 connect(screenfontsModule->screenSmallerED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
300 connect(screenfontsModule->screenSmallED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
301 connect(screenfontsModule->screenNormalED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
302 connect(screenfontsModule->screenLargeED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
303 connect(screenfontsModule->screenLargerED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
304 connect(screenfontsModule->screenLargestED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
305 connect(screenfontsModule->screenHugeED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
306 connect(screenfontsModule->screenHugerED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
307 connect(identityModule->nameED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
308 connect(identityModule->emailED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
310 // initialize the validators
311 screenfontsModule->screenTinyED->setValidator(new QDoubleValidator(
312 screenfontsModule->screenTinyED));
313 screenfontsModule->screenSmallestED->setValidator(new QDoubleValidator(
314 screenfontsModule->screenSmallestED));
315 screenfontsModule->screenSmallerED->setValidator(new QDoubleValidator(
316 screenfontsModule->screenSmallerED));
317 screenfontsModule->screenSmallED->setValidator(new QDoubleValidator(
318 screenfontsModule->screenSmallED));
319 screenfontsModule->screenNormalED->setValidator(new QDoubleValidator(
320 screenfontsModule->screenNormalED));
321 screenfontsModule->screenLargeED->setValidator(new QDoubleValidator(
322 screenfontsModule->screenLargeED));
323 screenfontsModule->screenLargerED->setValidator(new QDoubleValidator(
324 screenfontsModule->screenLargerED));
325 screenfontsModule->screenLargestED->setValidator(new QDoubleValidator(
326 screenfontsModule->screenLargestED));
327 screenfontsModule->screenHugeED->setValidator(new QDoubleValidator(
328 screenfontsModule->screenHugeED));
329 screenfontsModule->screenHugerED->setValidator(new QDoubleValidator(
330 screenfontsModule->screenHugerED));
334 QPrefsDialog::~QPrefsDialog()
339 void QPrefsDialog::closeEvent(QCloseEvent * e)
346 void QPrefsDialog::change_adaptor()
352 void QPrefsDialog::updateConverters()
354 QPrefConvertersModule * convertmod(convertersModule);
356 // save current selection
357 QString current = convertmod->converterFromCO->currentText()
358 + " -> " + convertmod->converterToCO->currentText();
360 convertmod->converterFromCO->clear();
361 convertmod->converterToCO->clear();
363 Formats::const_iterator cit = form_->formats().begin();
364 Formats::const_iterator end = form_->formats().end();
365 for (; cit != end; ++cit) {
366 convertmod->converterFromCO->insertItem(toqstr(cit->prettyname()));
367 convertmod->converterToCO->insertItem(toqstr(cit->prettyname()));
370 convertmod->convertersLB->clear();
372 Converters::const_iterator ccit = form_->converters().begin();
373 Converters::const_iterator cend = form_->converters().end();
374 for (; ccit != cend; ++ccit) {
375 std::string const name = ccit->From->prettyname() + " -> "
376 + ccit->To->prettyname();
377 convertmod->convertersLB->insertItem(toqstr(name));
381 if (!current.isEmpty()) {
382 QListBoxItem * item = convertmod->convertersLB->findItem(current);
383 convertmod->convertersLB->setCurrentItem(item);
385 // select first element if restoring failed
386 if (convertmod->convertersLB->currentItem() == -1)
387 convertmod->convertersLB->setCurrentItem(0);
389 updateConverterButtons();
393 void QPrefsDialog::switch_converter(int nr)
395 Converter const & c(form_->converters().get(nr));
396 convertersModule->converterFromCO->setCurrentItem(form_->formats().getNumber(c.from));
397 convertersModule->converterToCO->setCurrentItem(form_->formats().getNumber(c.to));
398 convertersModule->converterED->setText(toqstr(c.command));
399 convertersModule->converterFlagED->setText(toqstr(c.flags));
401 updateConverterButtons();
405 void QPrefsDialog::converter_changed()
407 updateConverterButtons();
411 void QPrefsDialog::updateConverterButtons()
413 Format const & from(form_->formats().get(
414 convertersModule->converterFromCO->currentItem()));
415 Format const & to(form_->formats().get(
416 convertersModule->converterToCO->currentItem()));
417 int const sel = form_->converters().getNumber(from.name(), to.name());
418 bool const known = !(sel < 0);
419 bool const valid = !(convertersModule->converterED->text().isEmpty()
420 || from.name() == to.name());
422 Converter const & c(form_->converters().get(
423 convertersModule->convertersLB->currentItem()));
424 string const old_command = c.command;
425 string const old_flag = c.flags;
426 string const new_command(fromqstr(convertersModule->converterED->text()));
427 string const new_flag(fromqstr(convertersModule->converterFlagED->text()));
429 bool modified = ((old_command != new_command) || (old_flag != new_flag));
431 convertersModule->converterModifyPB->setEnabled(valid && known && modified);
432 convertersModule->converterNewPB->setEnabled(valid && !known);
433 convertersModule->converterRemovePB->setEnabled(known);
438 // specify unique from/to or it doesn't appear. This is really bad UI
439 void QPrefsDialog::new_converter()
441 Format const & from(form_->formats().get(convertersModule->converterFromCO->currentItem()));
442 Format const & to(form_->formats().get(convertersModule->converterToCO->currentItem()));
443 string const command(fromqstr(convertersModule->converterED->text()));
444 string const flags(fromqstr(convertersModule->converterFlagED->text()));
446 Converter const * old = form_->converters().getConverter(from.name(), to.name());
447 form_->converters().add(from.name(), to.name(), command, flags);
449 form_->converters().updateLast(form_->formats());
452 convertersModule->convertersLB->setCurrentItem(convertersModule->convertersLB->count() - 1);
456 void QPrefsDialog::modify_converter()
458 int const top_item = convertersModule->convertersLB->topItem();
459 QString const current_text =
460 convertersModule->convertersLB->currentText();
462 Format const & from(form_->formats().get(convertersModule->converterFromCO->currentItem()));
463 Format const & to(form_->formats().get(convertersModule->converterToCO->currentItem()));
464 string flags(fromqstr(convertersModule->converterFlagED->text()));
465 string name(fromqstr(convertersModule->converterED->text()));
467 Converter const * old = form_->converters().getConverter(from.name(), to.name());
468 form_->converters().add(from.name(), to.name(), name, flags);
470 form_->converters().updateLast(form_->formats());
474 QListBoxItem * const item =
475 convertersModule->convertersLB->findItem(current_text);
476 convertersModule->convertersLB->setCurrentItem(item);
477 convertersModule->convertersLB->setTopItem(top_item);
481 void QPrefsDialog::remove_converter()
483 Format const & from(form_->formats().get(convertersModule->converterFromCO->currentItem()));
484 Format const & to(form_->formats().get(convertersModule->converterToCO->currentItem()));
485 form_->converters().erase(from.name(), to.name());
490 void QPrefsDialog::updateCopiers()
493 // save current selection
494 QString current = copiersModule->copierFormatCO->currentText();
495 copiersModule->copierFormatCO->clear();
497 for (Formats::const_iterator it = form_->formats().begin(),
498 end = form_->formats().end();
500 copiersModule->copierFormatCO->insertItem(toqstr(it->prettyname()));
503 // The browser widget
504 copiersModule->AllCopiersLB->clear();
506 for (Movers::iterator it = form_->movers().begin(),
507 end = form_->movers().end();
509 std::string const & command = it->second.command();
512 std::string const & fmt = it->first;
513 std::string const & pretty = form_->formats().prettyName(fmt);
515 copiersModule->AllCopiersLB->insertItem(toqstr(pretty));
519 if (!current.isEmpty()) {
520 QListBoxItem * item = copiersModule->AllCopiersLB->findItem(current);
521 copiersModule->AllCopiersLB->setCurrentItem(item);
523 // select first element if restoring failed
524 if (copiersModule->AllCopiersLB->currentItem() == -1)
525 copiersModule->AllCopiersLB->setCurrentItem(0);
531 class SamePrettyName {
533 SamePrettyName(string const & n) : pretty_name_(n) {}
535 bool operator()(::Format const & fmt) const {
536 return fmt.prettyname() == pretty_name_;
540 string const pretty_name_;
544 Format const * getFormat(std::string const & prettyname)
546 Formats::const_iterator it = ::formats.begin();
547 Formats::const_iterator const end = ::formats.end();
548 it = std::find_if(it, end, SamePrettyName(prettyname));
549 return it == end ? 0 : &*it;
555 void QPrefsDialog::switch_copierLB(int)
557 std::string const browser_text =
558 fromqstr(copiersModule->AllCopiersLB->currentText());
559 Format const * fmt = getFormat(browser_text);
563 string const & fmt_name = fmt->name();
564 string const & gui_name = fmt->prettyname();
565 string const & command = form_->movers().command(fmt_name);
567 copiersModule->copierED->clear();
568 int const combo_size = copiersModule->copierFormatCO->count();
569 for (int i = 0; i < combo_size; ++i) {
570 QString const qtext = copiersModule->copierFormatCO->text(i);
571 std::string const text = fromqstr(qtext);
572 if (text == gui_name) {
573 copiersModule->copierFormatCO->setCurrentItem(i);
574 copiersModule->copierED->setText(toqstr(command));
578 updateCopierButtons();
582 void QPrefsDialog::switch_copierCO(int)
584 std::string const combo_text =
585 fromqstr(copiersModule->copierFormatCO->currentText());
586 Format const * fmt = getFormat(combo_text);
590 string const & fmt_name = fmt->name();
591 string const & gui_name = fmt->prettyname();
592 string const & command = form_->movers().command(fmt_name);
594 copiersModule->copierED->setText(toqstr(command));
596 int const index = copiersModule->AllCopiersLB->currentItem();
598 copiersModule->AllCopiersLB->setSelected(index, false);
600 int const browser_size = copiersModule->AllCopiersLB->count();
601 for (int i = 0; i < browser_size; ++i) {
602 QString const qtext = copiersModule->AllCopiersLB->text(i);
603 std::string const text = fromqstr(qtext);
604 if (text == gui_name) {
605 copiersModule->AllCopiersLB->setSelected(i, true);
606 int top = std::max(i - 5, 0);
607 copiersModule->AllCopiersLB->setTopItem(top);
614 void QPrefsDialog::copiers_changed()
616 updateCopierButtons();
620 void QPrefsDialog::updateCopierButtons()
622 QString selected = copiersModule->copierFormatCO->currentText();
625 for (unsigned int i = 0; i != copiersModule->AllCopiersLB->count(); i++) {
626 if (copiersModule->AllCopiersLB->text(i) == selected)
630 bool const valid = !copiersModule->copierED->text().isEmpty();
632 Format const * fmt = getFormat(fromqstr(selected));
633 string const old_command = form_->movers().command(fmt->name());
634 string const new_command(fromqstr(copiersModule->copierED->text()));
636 bool modified = (old_command != new_command);
638 copiersModule->copierModifyPB->setEnabled(valid && known && modified);
639 copiersModule->copierNewPB->setEnabled(valid && !known);
640 copiersModule->copierRemovePB->setEnabled(known);
644 void QPrefsDialog::new_copier()
646 std::string const combo_text =
647 fromqstr(copiersModule->copierFormatCO->currentText());
648 Format const * fmt = getFormat(combo_text);
652 string const command = fromqstr(copiersModule->copierED->text());
656 form_->movers().set(fmt->name(), command);
659 int const last = copiersModule->AllCopiersLB->count() - 1;
660 copiersModule->AllCopiersLB->setCurrentItem(last);
662 updateCopierButtons();
666 void QPrefsDialog::modify_copier()
668 std::string const combo_text =
669 fromqstr(copiersModule->copierFormatCO->currentText());
670 Format const * fmt = getFormat(combo_text);
674 string const command = fromqstr(copiersModule->copierED->text());
675 form_->movers().set(fmt->name(), command);
678 updateCopierButtons();
682 void QPrefsDialog::remove_copier()
684 std::string const combo_text =
685 fromqstr(copiersModule->copierFormatCO->currentText());
686 Format const * fmt = getFormat(combo_text);
690 string const & fmt_name = fmt->name();
691 form_->movers().set(fmt_name, string());
694 updateCopierButtons();
698 void QPrefsDialog::updateFormats()
700 QPrefFileformatsModule * formatmod(fileformatsModule);
702 // save current selection
703 QString current = formatmod->guiNameED->text();
705 formatmod->formatsLB->clear();
707 Formats::const_iterator cit = form_->formats().begin();
708 Formats::const_iterator end = form_->formats().end();
709 for (; cit != end; ++cit) {
710 formatmod->formatsLB->insertItem(toqstr(cit->prettyname()));
714 if (!current.isEmpty()) {
715 QListBoxItem * item = formatmod->formatsLB->findItem(current);
716 formatmod->formatsLB->setCurrentItem(item);
718 // select first element if restoring failed
719 if (formatmod->formatsLB->currentItem() == -1)
720 formatmod->formatsLB->setCurrentItem(0);
724 void QPrefsDialog::switch_format(int nr)
726 Format const & f(form_->formats().get(nr));
727 fileformatsModule->formatED->setText(toqstr(f.name()));
728 fileformatsModule->guiNameED->setText(toqstr(f.prettyname()));
729 fileformatsModule->extensionED->setText(toqstr(f.extension()));
730 fileformatsModule->shortcutED->setText(toqstr(f.shortcut()));
731 fileformatsModule->viewerED->setText(toqstr(f.viewer()));
732 fileformatsModule->editorED->setText(toqstr(f.editor()));
733 fileformatsModule->documentCB->setChecked(f.documentFormat());
734 fileformatsModule->formatRemovePB->setEnabled(
735 !form_->converters().formatIsUsed(f.name()));
737 updateFormatsButtons();
741 void QPrefsDialog::fileformat_changed()
743 updateFormatsButtons();
747 void QPrefsDialog::updateFormatsButtons()
749 QString const format = fileformatsModule->formatED->text();
750 QString const gui_name = fileformatsModule->guiNameED->text();
751 int const sel = form_->formats().getNumber(fromqstr(format));
752 bool gui_name_known = false;
754 for (unsigned int i = 0; i != fileformatsModule->formatsLB->count(); i++) {
755 if (fileformatsModule->formatsLB->text(i) == gui_name) {
756 gui_name_known = true;
761 // assure that a gui name cannot be chosen twice
762 bool const known_otherwise = gui_name_known && (where != sel);
764 bool const known = !(sel < 0);
765 bool const valid = (!fileformatsModule->formatED->text().isEmpty()
766 && !fileformatsModule->guiNameED->text().isEmpty());
768 Format const & f(form_->formats().get(
769 fileformatsModule->formatsLB->currentItem()));
770 string const old_pretty(f.prettyname());
771 string const old_shortcut(f.shortcut());
772 string const old_extension(f.extension());
773 string const old_viewer(f.viewer());
774 string const old_editor(f.editor());
775 bool const old_document(f.documentFormat());
777 string const new_pretty(fromqstr(gui_name));
778 string const new_shortcut(fromqstr(fileformatsModule->shortcutED->text()));
779 string const new_extension(fromqstr(fileformatsModule->extensionED->text()));
780 string const new_viewer(fromqstr(fileformatsModule->viewerED->text()));
781 string const new_editor(fromqstr(fileformatsModule->editorED->text()));
782 bool const new_document(fileformatsModule->documentCB->isChecked());
784 bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
785 || (old_extension != new_extension) || (old_viewer != new_viewer)
786 || (old_editor != new_editor)) || old_document != new_document;
788 fileformatsModule->formatModifyPB->setEnabled(
789 valid && known && modified && !known_otherwise);
790 fileformatsModule->formatNewPB->setEnabled(valid && !known && !gui_name_known);
791 fileformatsModule->formatRemovePB->setEnabled(known);
795 void QPrefsDialog::new_format()
797 string const name = fromqstr(fileformatsModule->formatED->text());
798 string const prettyname = fromqstr(fileformatsModule->guiNameED->text());
799 string const extension = fromqstr(fileformatsModule->extensionED->text());
800 string const shortcut = fromqstr(fileformatsModule->shortcutED->text());
801 string const viewer = fromqstr(fileformatsModule->viewerED->text());
802 string const editor = fromqstr(fileformatsModule->editorED->text());
803 bool const document = fileformatsModule->documentCB->isChecked();
805 form_->formats().add(name, extension, prettyname, shortcut, viewer,
807 form_->formats().sort();
809 fileformatsModule->formatsLB->setCurrentItem(form_->formats().getNumber(name));
810 form_->converters().update(form_->formats());
813 updateFormatsButtons();
817 void QPrefsDialog::modify_format()
819 int const top_item = fileformatsModule->formatsLB->topItem();
820 int const current_item = fileformatsModule->formatsLB->currentItem();
821 QString const current_text =
822 fileformatsModule->formatsLB->currentText();
824 Format const & oldformat(form_->formats().get(current_item));
825 string const oldpretty(oldformat.prettyname());
826 string const name(fromqstr(fileformatsModule->formatED->text()));
827 form_->formats().erase(oldformat.name());
829 string const prettyname = fromqstr(fileformatsModule->guiNameED->text());
830 string const extension = fromqstr(fileformatsModule->extensionED->text());
831 string const shortcut = fromqstr(fileformatsModule->shortcutED->text());
832 string const viewer = fromqstr(fileformatsModule->viewerED->text());
833 string const editor = fromqstr(fileformatsModule->editorED->text());
834 bool const document = fileformatsModule->documentCB->isChecked();
836 form_->formats().add(name, extension, prettyname, shortcut, viewer,
838 form_->formats().sort();
840 fileformatsModule->formatsLB->setUpdatesEnabled(false);
842 fileformatsModule->formatsLB->setUpdatesEnabled(true);
843 fileformatsModule->formatsLB->update();
846 updateFormatsButtons();
848 QListBoxItem * const item =
849 fileformatsModule->formatsLB->findItem(current_text);
850 fileformatsModule->formatsLB->setCurrentItem(item);
851 fileformatsModule->formatsLB->setTopItem(top_item);
855 void QPrefsDialog::remove_format()
857 int const nr(fileformatsModule->formatsLB->currentItem());
860 string const current_text = form_->formats().get(nr).name();
861 if (form_->converters().formatIsUsed(current_text)) {
862 Alert::error(_("Format in use"),
863 _("Cannot remove a Format used by a Converter. "
864 "Remove the converter first."));
867 form_->formats().erase(current_text);
869 form_->converters().update(form_->formats());
872 updateFormatsButtons();
876 void QPrefsDialog::change_color()
878 QListBox * lb(colorsModule->lyxObjectsLB);
879 if (lb->currentItem() < 0)
881 QListBoxItem * ib(lb->item(lb->currentItem()));
882 QColorItem * ci(static_cast<QColorItem*>(ib));
883 QColor c(QColorDialog::getColor(ci->color(), qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget()));
892 void QPrefsDialog::select_ui()
894 string file(form_->controller().browseUI(fromqstr(uiModule->uiFileED->text())));
896 uiModule->uiFileED->setText(toqstr(file));
900 void QPrefsDialog::select_bind()
902 string file(form_->controller().browsebind(fromqstr(uiModule->bindFileED->text())));
904 uiModule->bindFileED->setText(toqstr(file));
908 void QPrefsDialog::select_keymap1()
910 string file(form_->controller().browsekbmap(fromqstr(keyboardModule->firstKeymapED->text())));
912 keyboardModule->firstKeymapED->setText(toqstr(file));
916 void QPrefsDialog::select_keymap2()
918 string file(form_->controller().browsekbmap(fromqstr(keyboardModule->secondKeymapED->text())));
920 keyboardModule->secondKeymapED->setText(toqstr(file));
924 void QPrefsDialog::select_dict()
926 string file(form_->controller().browsedict(fromqstr(spellcheckerModule->persDictionaryED->text())));
928 spellcheckerModule->persDictionaryED->setText(toqstr(file));
932 // NB: the _() is OK here because it gets passed back and we toqstr() them
934 void QPrefsDialog::select_templatedir()
936 string file(form_->controller().browsedir(fromqstr(pathsModule->templateDirED->text()), _("Select a document templates directory")));
938 pathsModule->templateDirED->setText(toqstr(file));
942 void QPrefsDialog::select_tempdir()
944 string file(form_->controller().browsedir(fromqstr(pathsModule->tempDirED->text()), _("Select a temporary directory")));
946 pathsModule->tempDirED->setText(toqstr(file));
950 void QPrefsDialog::select_backupdir()
952 string file(form_->controller().browsedir(fromqstr(pathsModule->backupDirED->text()), _("Select a backups directory")));
954 pathsModule->backupDirED->setText(toqstr(file));
958 void QPrefsDialog::select_workingdir()
960 string file(form_->controller().browsedir(fromqstr(pathsModule->workingDirED->text()), _("Select a document directory")));
962 pathsModule->workingDirED->setText(toqstr(file));
966 void QPrefsDialog::select_lyxpipe()
968 string file(form_->controller().browse(fromqstr(pathsModule->lyxserverDirED->text()), _("Give a filename for the LyX server pipe")));
970 pathsModule->lyxserverDirED->setText(toqstr(file));
974 void QPrefsDialog::select_roman(const QString& name)
976 screenfontsModule->screenRomanFE->set(QFont(name), name);
980 void QPrefsDialog::select_sans(const QString& name)
982 screenfontsModule->screenSansFE->set(QFont(name), name);
986 void QPrefsDialog::select_typewriter(const QString& name)
988 screenfontsModule->screenTypewriterFE->set(QFont(name), name);
991 } // namespace frontend