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.
16 #include "GuiApplication.h"
17 #include "qt_helpers.h"
24 #include "support/lstrings.h"
25 #include "support/os.h"
27 #include "controllers/ControlPrefs.h"
28 #include "controllers/frnt_lang.h"
29 #include "controllers/helper_funcs.h"
31 #include "frontends/Alert.h"
32 #include "frontends/Application.h"
34 #include "QPrefsDialog.h"
37 #include "panelstack.h"
38 #include "qfontexample.h"
43 #include "controllers/ControlPrefs.h"
46 #include <QColorDialog>
47 #include <QFontDatabase>
49 #include <QPushButton>
53 #include <QCloseEvent>
55 #include <boost/tuple/tuple.hpp>
59 using lyx::support::compare_no_case;
66 using std::ostringstream;
74 string const LookAndFeel = N_("Look and feel");
75 string const LanguageSettings = N_("Language settings");
76 string const Outputs = N_("Outputs");
79 // FIXME: move to helper_funcs.h
83 typename std::vector<A>::size_type
84 findPos(std::vector<A> const & vec, A const & val)
86 typedef typename std::vector<A>::const_iterator Cit;
88 Cit it = std::find(vec.begin(), vec.end(), val);
91 return distance(vec.begin(), it);
94 void setComboxFont(QComboBox * cb, string const & family, string const & foundry)
96 string const name = makeFontName(family, foundry);
97 for (int i = 0; i < cb->count(); ++i) {
98 if (fromqstr(cb->itemText(i)) == name) {
99 cb->setCurrentIndex(i);
104 // Try matching without foundry name
106 // We count in reverse in order to prefer the Xft foundry
107 for (int i = cb->count() - 1; i >= 0; --i) {
108 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
109 if (compare_no_case(tmp.first, family) == 0) {
110 cb->setCurrentIndex(i);
115 // family alone can contain e.g. "Helvetica [Adobe]"
116 pair<string, string> tmpfam = parseFontName(family);
118 // We count in reverse in order to prefer the Xft foundry
119 for (int i = cb->count() - 1; i >= 0; --i) {
120 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
121 if (compare_no_case(tmp.first, tmpfam.first) == 0) {
122 cb->setCurrentIndex(i);
127 // Bleh, default fonts, and the names couldn't be found. Hack
128 // for bug 1063. Qt makes baby Jesus cry.
131 font.setKerning(false);
133 if (family == theApp()->romanFontName()) {
134 font.setStyleHint(QFont::Serif);
135 font.setFamily(family.c_str());
136 } else if (family == theApp()->sansFontName()) {
137 font.setStyleHint(QFont::SansSerif);
138 font.setFamily(family.c_str());
139 } else if (family == theApp()->typewriterFontName()) {
140 font.setStyleHint(QFont::TypeWriter);
141 font.setFamily(family.c_str());
143 lyxerr << "FAILED to find the default font: '"
144 << foundry << "', '" << family << '\''<< endl;
148 QFontInfo info(font);
149 pair<string, string> tmp = parseFontName(fromqstr(info.family()));
150 string const & default_font_name = tmp.first;
151 lyxerr << "Apparent font is " << default_font_name << endl;
153 for (int i = 0; i < cb->count(); ++i) {
154 lyxerr << "Looking at " << fromqstr(cb->itemText(i)) << endl;
155 if (compare_no_case(fromqstr(cb->itemText(i)),
156 default_font_name) == 0) {
157 cb->setCurrentIndex(i);
162 lyxerr << "FAILED to find the font: '"
163 << foundry << "', '" << family << '\'' <<endl;
167 QString const external_path(string const & input)
169 return toqstr(lyx::support::os::external_path(input));
173 string const internal_path(QString const & input)
175 return lyx::support::os::internal_path(fromqstr(input));
178 } // end namespace anon
181 PrefAscii::PrefAscii(QWidget * parent)
182 : PrefModule(_(Outputs), _("Plain text"), 0, parent)
185 connect(asciiLinelengthSB, SIGNAL(valueChanged(int)),
186 this, SIGNAL(changed()));
187 connect(asciiRoffED, SIGNAL(textChanged(const QString&)),
188 this, SIGNAL(changed()));
192 void PrefAscii::apply(LyXRC & rc) const
194 rc.ascii_linelen = asciiLinelengthSB->value();
195 rc.ascii_roff_command = fromqstr(asciiRoffED->text());
199 void PrefAscii::update(LyXRC const & rc)
201 asciiLinelengthSB->setValue(rc.ascii_linelen);
202 asciiRoffED->setText(toqstr(rc.ascii_roff_command));
206 PrefDate::PrefDate(QWidget * parent)
207 : PrefModule(_(Outputs), _("Date format"), 0, parent)
210 connect(DateED, SIGNAL(textChanged(const QString&)),
211 this, SIGNAL(changed()));
215 void PrefDate::apply(LyXRC & rc) const
217 rc.date_insert_format = fromqstr(DateED->text());
221 void PrefDate::update(LyXRC const & rc)
223 DateED->setText(toqstr(rc.date_insert_format));
227 PrefKeyboard::PrefKeyboard(QPrefs * form, QWidget * parent)
228 : PrefModule(_(LookAndFeel), _("Keyboard"), form, parent)
232 connect(keymapCB, SIGNAL( toggled(bool) ),
233 firstKeymapLA, SLOT( setEnabled(bool) ) );
234 connect(keymapCB, SIGNAL( toggled(bool) ),
235 secondKeymapLA, SLOT( setEnabled(bool) ) );
236 connect(keymapCB, SIGNAL( toggled(bool) ),
237 firstKeymapED, SLOT( setEnabled(bool) ) );
238 connect(keymapCB, SIGNAL( toggled(bool) ),
239 secondKeymapED, SLOT( setEnabled(bool) ) );
240 connect(keymapCB, SIGNAL( toggled(bool) ),
241 firstKeymapPB, SLOT( setEnabled(bool) ) );
242 connect(keymapCB, SIGNAL( toggled(bool) ),
243 secondKeymapPB, SLOT( setEnabled(bool) ) );
245 connect(keymapCB, SIGNAL(toggled(bool)),
246 this, SIGNAL(changed()));
247 connect(firstKeymapED, SIGNAL(textChanged(const QString&)),
248 this, SIGNAL(changed()));
249 connect(secondKeymapED, SIGNAL(textChanged(const QString&)),
250 this, SIGNAL(changed()));
254 void PrefKeyboard::apply(LyXRC & rc) const
256 // FIXME: can derive CB from the two EDs
257 rc.use_kbmap = keymapCB->isChecked();
258 rc.primary_kbmap = internal_path(firstKeymapED->text());
259 rc.secondary_kbmap = internal_path(secondKeymapED->text());
263 void PrefKeyboard::update(LyXRC const & rc)
265 // FIXME: can derive CB from the two EDs
266 keymapCB->setChecked(rc.use_kbmap);
267 // no idea why we need these. Fscking Qt.
268 firstKeymapED->setEnabled(rc.use_kbmap);
269 firstKeymapPB->setEnabled(rc.use_kbmap);
270 firstKeymapLA->setEnabled(rc.use_kbmap);
271 secondKeymapED->setEnabled(rc.use_kbmap);
272 secondKeymapPB->setEnabled(rc.use_kbmap);
273 secondKeymapLA->setEnabled(rc.use_kbmap);
274 firstKeymapED->setText(external_path(rc.primary_kbmap));
275 secondKeymapED->setText(external_path(rc.secondary_kbmap));
279 QString PrefKeyboard::testKeymap(QString keymap)
281 return toqstr(form_->controller().browsekbmap(qstring_to_ucs4(keymap)));
285 void PrefKeyboard::on_firstKeymapPB_clicked(bool)
287 QString file = testKeymap(firstKeymapED->text());
289 firstKeymapED->setText(file);
293 void PrefKeyboard::on_secondKeymapPB_clicked(bool)
295 QString file = testKeymap(secondKeymapED->text());
297 secondKeymapED->setText(file);
301 PrefLatex::PrefLatex(QPrefs * form, QWidget * parent)
302 : PrefModule(_(Outputs), _("LaTeX"), form, parent)
305 connect(latexEncodingED, SIGNAL(textChanged(const QString&)),
306 this, SIGNAL(changed()));
307 connect(latexChecktexED, SIGNAL(textChanged(const QString&)),
308 this, SIGNAL(changed()));
309 connect(latexBibtexED, SIGNAL(textChanged(const QString&)),
310 this, SIGNAL(changed()));
311 connect(latexIndexED, SIGNAL(textChanged(const QString&)),
312 this, SIGNAL(changed()));
313 connect(latexAutoresetCB, SIGNAL(toggled(bool)),
314 this, SIGNAL(changed()));
315 connect(latexDviPaperED, SIGNAL(textChanged(const QString&)),
316 this, SIGNAL(changed()));
317 connect(latexPaperSizeCO, SIGNAL(activated(int)),
318 this, SIGNAL(changed()));
322 void PrefLatex::apply(LyXRC & rc) const
324 rc.fontenc = fromqstr(latexEncodingED->text());
325 rc.chktex_command = fromqstr(latexChecktexED->text());
326 rc.bibtex_command = fromqstr(latexBibtexED->text());
327 rc.index_command = fromqstr(latexIndexED->text());
328 rc.auto_reset_options = latexAutoresetCB->isChecked();
329 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
330 rc.default_papersize =
331 form_->controller().toPaperSize(latexPaperSizeCO->currentIndex());
335 void PrefLatex::update(LyXRC const & rc)
337 latexEncodingED->setText(toqstr(rc.fontenc));
338 latexChecktexED->setText(toqstr(rc.chktex_command));
339 latexBibtexED->setText(toqstr(rc.bibtex_command));
340 latexIndexED->setText(toqstr(rc.index_command));
341 latexAutoresetCB->setChecked(rc.auto_reset_options);
342 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
343 latexPaperSizeCO->setCurrentIndex(
344 form_->controller().fromPaperSize(rc.default_papersize));
348 PrefScreenFonts::PrefScreenFonts(QPrefs * form, QWidget * parent)
349 : PrefModule(_(LookAndFeel), _("Screen fonts"), form, parent)
353 connect(screenRomanCO, SIGNAL(activated(const QString&)),
354 this, SLOT(select_roman(const QString&)));
355 connect(screenSansCO, SIGNAL(activated(const QString&)),
356 this, SLOT(select_sans(const QString&)));
357 connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
358 this, SLOT(select_typewriter(const QString&)));
360 QFontDatabase fontdb;
361 QStringList families(fontdb.families());
362 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
363 screenRomanCO->addItem(*it);
364 screenSansCO->addItem(*it);
365 screenTypewriterCO->addItem(*it);
367 connect(screenRomanCO, SIGNAL(activated(const QString&)),
368 this, SIGNAL(changed()));
369 connect(screenSansCO, SIGNAL(activated(const QString&)),
370 this, SIGNAL(changed()));
371 connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
372 this, SIGNAL(changed()));
373 connect(screenZoomSB, SIGNAL(valueChanged(int)),
374 this, SIGNAL(changed()));
375 connect(screenDpiSB, SIGNAL(valueChanged(int)),
376 this, SIGNAL(changed()));
377 connect(screenTinyED, SIGNAL(textChanged(const QString&)),
378 this, SIGNAL(changed()));
379 connect(screenSmallestED, SIGNAL(textChanged(const QString&)),
380 this, SIGNAL(changed()));
381 connect(screenSmallerED, SIGNAL(textChanged(const QString&)),
382 this, SIGNAL(changed()));
383 connect(screenSmallED, SIGNAL(textChanged(const QString&)),
384 this, SIGNAL(changed()));
385 connect(screenNormalED, SIGNAL(textChanged(const QString&)),
386 this, SIGNAL(changed()));
387 connect(screenLargeED, SIGNAL(textChanged(const QString&)),
388 this, SIGNAL(changed()));
389 connect(screenLargerED, SIGNAL(textChanged(const QString&)),
390 this, SIGNAL(changed()));
391 connect(screenLargestED, SIGNAL(textChanged(const QString&)),
392 this, SIGNAL(changed()));
393 connect(screenHugeED, SIGNAL(textChanged(const QString&)),
394 this, SIGNAL(changed()));
395 connect(screenHugerED, SIGNAL(textChanged(const QString&)),
396 this, SIGNAL(changed()));
398 screenTinyED->setValidator(new QDoubleValidator(
400 screenSmallestED->setValidator(new QDoubleValidator(
402 screenSmallerED->setValidator(new QDoubleValidator(
404 screenSmallED->setValidator(new QDoubleValidator(
406 screenNormalED->setValidator(new QDoubleValidator(
408 screenLargeED->setValidator(new QDoubleValidator(
410 screenLargerED->setValidator(new QDoubleValidator(
412 screenLargestED->setValidator(new QDoubleValidator(
414 screenHugeED->setValidator(new QDoubleValidator(
416 screenHugerED->setValidator(new QDoubleValidator(
421 void PrefScreenFonts::apply(LyXRC & rc) const
423 LyXRC const oldrc(rc);
425 boost::tie(rc.roman_font_name, rc.roman_font_foundry)
426 = parseFontName(fromqstr(screenRomanCO->currentText()));
427 boost::tie(rc.sans_font_name, rc.sans_font_foundry) =
428 parseFontName(fromqstr(screenSansCO->currentText()));
429 boost::tie(rc.typewriter_font_name, rc.typewriter_font_foundry) =
430 parseFontName(fromqstr(screenTypewriterCO->currentText()));
432 rc.zoom = screenZoomSB->value();
433 rc.dpi = screenDpiSB->value();
434 rc.font_sizes[LyXFont::SIZE_TINY] = fromqstr(screenTinyED->text());
435 rc.font_sizes[LyXFont::SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
436 rc.font_sizes[LyXFont::SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
437 rc.font_sizes[LyXFont::SIZE_SMALL] = fromqstr(screenSmallED->text());
438 rc.font_sizes[LyXFont::SIZE_NORMAL] = fromqstr(screenNormalED->text());
439 rc.font_sizes[LyXFont::SIZE_LARGE] = fromqstr(screenLargeED->text());
440 rc.font_sizes[LyXFont::SIZE_LARGER] = fromqstr(screenLargerED->text());
441 rc.font_sizes[LyXFont::SIZE_LARGEST] = fromqstr(screenLargestED->text());
442 rc.font_sizes[LyXFont::SIZE_HUGE] = fromqstr(screenHugeED->text());
443 rc.font_sizes[LyXFont::SIZE_HUGER] = fromqstr(screenHugerED->text());
445 if (rc.font_sizes != oldrc.font_sizes
446 || rc.roman_font_name != oldrc.roman_font_name
447 || rc.sans_font_name != oldrc.sans_font_name
448 || rc.typewriter_font_name != oldrc.typewriter_font_name
449 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
450 form_->controller().updateScreenFonts();
455 void PrefScreenFonts::update(LyXRC const & rc)
457 setComboxFont(screenRomanCO, rc.roman_font_name,
458 rc.roman_font_foundry);
459 setComboxFont(screenSansCO, rc.sans_font_name,
460 rc.sans_font_foundry);
461 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
462 rc.typewriter_font_foundry);
464 select_roman(screenRomanCO->currentText());
465 select_sans(screenSansCO->currentText());
466 select_typewriter(screenTypewriterCO->currentText());
468 screenZoomSB->setValue(rc.zoom);
469 screenDpiSB->setValue(rc.dpi);
470 screenTinyED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_TINY]));
471 screenSmallestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SCRIPT]));
472 screenSmallerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_FOOTNOTE]));
473 screenSmallED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SMALL]));
474 screenNormalED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_NORMAL]));
475 screenLargeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGE]));
476 screenLargerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGER]));
477 screenLargestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGEST]));
478 screenHugeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_HUGE]));
479 screenHugerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_HUGER]));
482 void PrefScreenFonts::select_roman(const QString& name)
484 screenRomanFE->set(QFont(name), name);
488 void PrefScreenFonts::select_sans(const QString& name)
490 screenSansFE->set(QFont(name), name);
494 void PrefScreenFonts::select_typewriter(const QString& name)
496 screenTypewriterFE->set(QFont(name), name);
500 PrefColors::PrefColors(QPrefs * form, QWidget * parent)
501 : PrefModule(_(LookAndFeel), _("Colors"), form, parent)
505 // FIXME: put in controller
506 for (int i = 0; i < LColor::ignore; ++i) {
507 LColor::color lc = static_cast<LColor::color>(i);
508 if (lc == LColor::none
509 || lc == LColor::black
510 || lc == LColor::white
512 || lc == LColor::green
513 || lc == LColor::blue
514 || lc == LColor::cyan
515 || lc == LColor::magenta
516 || lc == LColor::yellow
517 || lc == LColor::inherit
518 || lc == LColor::ignore) continue;
520 lcolors_.push_back(lc);
521 QColor color = QColor(guiApp->colorCache().get(lc));
522 prefcolors_.push_back(color.name());
523 QPixmap coloritem(32, 32);
524 coloritem.fill(color);
525 // This is not a memory leak:
526 /*QListWidgetItem * newItem =*/ new QListWidgetItem(QIcon(coloritem),
527 toqstr(lcolor.getGUIName(lc)), lyxObjectsLW);
529 newcolors_ = prefcolors_;
531 connect(colorChangePB, SIGNAL(clicked()),
532 this, SLOT(change_color()));
533 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
534 this, SLOT(change_color()));
538 void PrefColors::apply(LyXRC & /*rc*/) const
540 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
541 if (prefcolors_[i]!=newcolors_[i])
542 form_->controller().setColor(lcolors_[i], fromqstr(newcolors_[i]));
547 void PrefColors::update(LyXRC const & /*rc*/)
551 void PrefColors::change_color()
553 int const row = lyxObjectsLW->currentRow();
554 QString color = newcolors_[row];
555 QColor c(QColorDialog::getColor(QColor(color),
556 qApp->focusWidget()));
558 if (c.name()!=color) {
559 newcolors_[row] = c.name();
560 QPixmap coloritem(32, 32);
562 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
569 PrefCygwinPath::PrefCygwinPath(QWidget * parent)
570 : PrefModule(_(Outputs), _("Paths"), 0, parent)
573 connect(pathCB, SIGNAL(toggled(bool)),
574 this, SIGNAL(changed()));
578 void PrefCygwinPath::apply(LyXRC & rc) const
580 rc.windows_style_tex_paths = pathCB->isChecked();
584 void PrefCygwinPath::update(LyXRC const & rc)
586 pathCB->setChecked(rc.windows_style_tex_paths);
590 PrefDisplay::PrefDisplay(QWidget * parent)
591 : PrefModule(_(LookAndFeel), _("Graphics"), 0, parent)
594 connect(instantPreviewCO, SIGNAL(activated(int)),
595 this, SIGNAL(changed()));
596 connect(displayGraphicsCO, SIGNAL(activated(int)),
597 this, SIGNAL(changed()));
601 void PrefDisplay::apply(LyXRC & rc) const
603 switch (instantPreviewCO->currentIndex()) {
604 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
605 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
606 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
609 lyx::graphics::DisplayType dtype;
610 switch (displayGraphicsCO->currentIndex()) {
611 case 3: dtype = lyx::graphics::NoDisplay; break;
612 case 2: dtype = lyx::graphics::ColorDisplay; break;
613 case 1: dtype = lyx::graphics::GrayscaleDisplay; break;
614 case 0: dtype = lyx::graphics::MonochromeDisplay; break;
615 default: dtype = lyx::graphics::GrayscaleDisplay;
617 rc.display_graphics = dtype;
620 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
623 if (old_value != rc.display_graphics) {
624 lyx::graphics::GCache & gc = lyx::graphics::GCache::get();
631 void PrefDisplay::update(LyXRC const & rc)
633 switch (rc.preview) {
634 case LyXRC::PREVIEW_OFF:
635 instantPreviewCO->setCurrentIndex(0);
637 case LyXRC::PREVIEW_NO_MATH :
638 instantPreviewCO->setCurrentIndex(1);
640 case LyXRC::PREVIEW_ON :
641 instantPreviewCO->setCurrentIndex(2);
646 switch (rc.display_graphics) {
647 case lyx::graphics::NoDisplay: item = 3; break;
648 case lyx::graphics::ColorDisplay: item = 2; break;
649 case lyx::graphics::GrayscaleDisplay: item = 1; break;
650 case lyx::graphics::MonochromeDisplay: item = 0; break;
653 displayGraphicsCO->setCurrentIndex(item);
657 PrefPaths::PrefPaths(QPrefs * form, QWidget * parent)
658 : PrefModule(docstring(), _("Paths"), form, parent)
661 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
662 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
663 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
664 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
665 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
666 connect(workingDirED, SIGNAL(textChanged(const QString&)),
667 this, SIGNAL(changed()));
668 connect(templateDirED, SIGNAL(textChanged(const QString&)),
669 this, SIGNAL(changed()));
670 connect(backupDirED, SIGNAL(textChanged(const QString&)),
671 this, SIGNAL(changed()));
672 connect(tempDirED, SIGNAL(textChanged(const QString&)),
673 this, SIGNAL(changed()));
674 connect(lyxserverDirED, SIGNAL(textChanged(const QString&)),
675 this, SIGNAL(changed()));
676 connect(pathPrefixED, SIGNAL(textChanged(const QString&)),
677 this, SIGNAL(changed()));
681 void PrefPaths::apply(LyXRC & rc) const
683 rc.document_path = internal_path(workingDirED->text());
684 rc.template_path = internal_path(templateDirED->text());
685 rc.backupdir_path = internal_path(backupDirED->text());
686 rc.tempdir_path = internal_path(tempDirED->text());
687 rc.path_prefix = fromqstr(pathPrefixED->text());
688 // FIXME: should be a checkbox only
689 rc.lyxpipes = internal_path(lyxserverDirED->text());
693 void PrefPaths::update(LyXRC const & rc)
695 workingDirED->setText(external_path(rc.document_path));
696 templateDirED->setText(external_path(rc.template_path));
697 backupDirED->setText(external_path(rc.backupdir_path));
698 tempDirED->setText(external_path(rc.tempdir_path));
699 pathPrefixED->setText(toqstr(rc.path_prefix));
700 // FIXME: should be a checkbox only
701 lyxserverDirED->setText(external_path(rc.lyxpipes));
704 void PrefPaths::select_templatedir()
706 docstring file(form_->controller().browsedir(
707 qstring_to_ucs4(templateDirED->text()),
708 _("Select a document templates directory")));
710 templateDirED->setText(toqstr(file));
714 void PrefPaths::select_tempdir()
716 docstring file(form_->controller().browsedir(
717 qstring_to_ucs4(tempDirED->text()),
718 _("Select a temporary directory")));
720 tempDirED->setText(toqstr(file));
724 void PrefPaths::select_backupdir()
726 docstring file(form_->controller().browsedir(
727 qstring_to_ucs4(backupDirED->text()),
728 _("Select a backups directory")));
730 backupDirED->setText(toqstr(file));
734 void PrefPaths::select_workingdir()
736 docstring file(form_->controller().browsedir(
737 qstring_to_ucs4(workingDirED->text()),
738 _("Select a document directory")));
740 workingDirED->setText(toqstr(file));
744 void PrefPaths::select_lyxpipe()
746 docstring file(form_->controller().browse(
747 qstring_to_ucs4(lyxserverDirED->text()),
748 _("Give a filename for the LyX server pipe")));
750 lyxserverDirED->setText(toqstr(file));
754 PrefSpellchecker::PrefSpellchecker(QPrefs * form, QWidget * parent)
755 : PrefModule(_(LanguageSettings), _("Spellchecker"), form, parent)
759 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
760 #if defined (USE_ISPELL)
761 connect(spellCommandCO, SIGNAL(activated(int)),
762 this, SIGNAL(changed()));
764 spellCommandCO->setEnabled(false);
766 connect(altLanguageED, SIGNAL(textChanged(const QString&)),
767 this, SIGNAL(changed()));
768 connect(escapeCharactersED, SIGNAL(textChanged(const QString&)),
769 this, SIGNAL(changed()));
770 connect(persDictionaryED, SIGNAL(textChanged(const QString&)),
771 this, SIGNAL(changed()));
772 connect(compoundWordCB, SIGNAL(toggled(bool)),
773 this, SIGNAL(changed()));
774 connect(inputEncodingCB, SIGNAL(toggled(bool)),
775 this, SIGNAL(changed()));
777 spellCommandCO->addItem(qt_("ispell"));
778 spellCommandCO->addItem(qt_("aspell"));
779 spellCommandCO->addItem(qt_("hspell"));
781 spellCommandCO->addItem(qt_("pspell (library)"));
784 spellCommandCO->addItem(qt_("aspell (library)"));
790 void PrefSpellchecker::apply(LyXRC & rc) const
792 switch (spellCommandCO->currentIndex()) {
796 rc.use_spell_lib = false;
797 rc.isp_command = fromqstr(spellCommandCO->currentText());
800 rc.use_spell_lib = true;
804 // FIXME: remove isp_use_alt_lang
805 rc.isp_alt_lang = fromqstr(altLanguageED->text());
806 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
807 // FIXME: remove isp_use_esc_chars
808 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
809 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
810 // FIXME: remove isp_use_pers_dict
811 rc.isp_pers_dict = internal_path(persDictionaryED->text());
812 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
813 rc.isp_accept_compound = compoundWordCB->isChecked();
814 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
818 void PrefSpellchecker::update(LyXRC const & rc)
820 spellCommandCO->setCurrentIndex(0);
822 if (rc.isp_command == "ispell") {
823 spellCommandCO->setCurrentIndex(0);
824 } else if (rc.isp_command == "aspell") {
825 spellCommandCO->setCurrentIndex(1);
826 } else if (rc.isp_command == "hspell") {
827 spellCommandCO->setCurrentIndex(2);
830 if (rc.use_spell_lib) {
831 #if defined(USE_ASPELL) || defined(USE_PSPELL)
832 spellCommandCO->setCurrentIndex(3);
836 // FIXME: remove isp_use_alt_lang
837 altLanguageED->setText(toqstr(rc.isp_alt_lang));
838 // FIXME: remove isp_use_esc_chars
839 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
840 // FIXME: remove isp_use_pers_dict
841 persDictionaryED->setText(external_path(rc.isp_pers_dict));
842 compoundWordCB->setChecked(rc.isp_accept_compound);
843 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
847 void PrefSpellchecker::select_dict()
849 docstring file(form_->controller().browsedict(qstring_to_ucs4(persDictionaryED->text())));
851 persDictionaryED->setText(toqstr(file));
855 PrefConverters::PrefConverters(QPrefs * form, QWidget * parent)
856 : PrefModule(docstring(), _("Converters"), form, parent)
860 connect(converterNewPB, SIGNAL(clicked()),
861 this, SLOT(update_converter()));
862 connect(converterRemovePB, SIGNAL(clicked()),
863 this, SLOT(remove_converter()));
864 connect(converterModifyPB, SIGNAL(clicked()),
865 this, SLOT(update_converter()));
866 connect(convertersLW, SIGNAL(currentRowChanged(int)),
867 this, SLOT(switch_converter(int)));
868 connect(converterFromCO, SIGNAL(activated(const QString&)),
869 this, SLOT(converter_changed()));
870 connect(converterToCO, SIGNAL(activated(const QString&)),
871 this, SLOT(converter_changed()));
872 connect(converterED, SIGNAL(textChanged(const QString&)),
873 this, SLOT(converter_changed()));
874 connect(converterFlagED, SIGNAL(textChanged(const QString&)),
875 this, SLOT(converter_changed()));
876 connect(converterNewPB, SIGNAL(clicked()),
877 this, SIGNAL(changed()));
878 connect(converterRemovePB, SIGNAL(clicked()),
879 this, SIGNAL(changed()));
880 connect(converterModifyPB, SIGNAL(clicked()),
881 this, SIGNAL(changed()));
885 void PrefConverters::apply(LyXRC & /*rc*/) const
890 void PrefConverters::update(LyXRC const & /*rc*/)
896 void PrefConverters::updateGui()
898 // save current selection
899 QString current = converterFromCO->currentText()
900 + " -> " + converterToCO->currentText();
902 converterFromCO->clear();
903 converterToCO->clear();
905 Formats::const_iterator cit = form_->formats().begin();
906 Formats::const_iterator end = form_->formats().end();
907 for (; cit != end; ++cit) {
908 converterFromCO->addItem(toqstr(cit->prettyname()));
909 converterToCO->addItem(toqstr(cit->prettyname()));
912 // currentRowChanged(int) is also triggered when updating the listwidget
913 // block signals to avoid unnecessary calls to switch_converter(int nr)
914 convertersLW->blockSignals(true);
915 convertersLW->clear();
917 Converters::const_iterator ccit = form_->converters().begin();
918 Converters::const_iterator cend = form_->converters().end();
919 for (; ccit != cend; ++ccit) {
920 std::string const name =
921 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
922 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
923 new QListWidgetItem(toqstr(name), convertersLW, type);
925 convertersLW->sortItems(Qt::AscendingOrder);
926 convertersLW->blockSignals(false);
929 if (!current.isEmpty()) {
930 QList<QListWidgetItem *> const item =
931 convertersLW->findItems(current, Qt::MatchExactly);
933 convertersLW->setCurrentItem(item.at(0));
936 // select first element if restoring failed
937 if (convertersLW->currentRow() == -1)
938 convertersLW->setCurrentRow(0);
944 void PrefConverters::switch_converter(int nr)
946 int const cnr = convertersLW->currentItem()->type();
947 Converter const & c(form_->converters().get(cnr));
948 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
949 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
950 converterED->setText(toqstr(c.command));
951 converterFlagED->setText(toqstr(c.flags));
957 void PrefConverters::converter_changed()
963 void PrefConverters::updateButtons()
965 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
966 Format const & to(form_->formats().get(converterToCO->currentIndex()));
967 int const sel = form_->converters().getNumber(from.name(), to.name());
968 bool const known = !(sel < 0);
969 bool const valid = !(converterED->text().isEmpty()
970 || from.name() == to.name());
972 int const cnr = convertersLW->currentItem()->type();
973 Converter const & c(form_->converters().get(cnr));
974 string const old_command = c.command;
975 string const old_flag = c.flags;
976 string const new_command(fromqstr(converterED->text()));
977 string const new_flag(fromqstr(converterFlagED->text()));
979 bool modified = ((old_command != new_command) || (old_flag != new_flag));
981 converterModifyPB->setEnabled(valid && known && modified);
982 converterNewPB->setEnabled(valid && !known);
983 converterRemovePB->setEnabled(known);
988 // specify unique from/to or it doesn't appear. This is really bad UI
989 // this is why we can use the same function for both new and modify
990 void PrefConverters::update_converter()
992 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
993 Format const & to(form_->formats().get(converterToCO->currentIndex()));
994 string const flags = fromqstr(converterFlagED->text());
995 string const command = fromqstr(converterED->text());
997 Converter const * old = form_->converters().getConverter(from.name(), to.name());
998 form_->converters().add(from.name(), to.name(), command, flags);
1000 form_->converters().updateLast(form_->formats());
1007 void PrefConverters::remove_converter()
1009 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1010 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1011 form_->converters().erase(from.name(), to.name());
1017 PrefCopiers::PrefCopiers(QPrefs * form, QWidget * parent)
1018 : PrefModule(docstring(), _("Copiers"), form, parent)
1022 connect(copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
1023 connect(copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
1024 connect(copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
1025 connect(AllCopiersLW, SIGNAL(currentRowChanged(int)),
1026 this, SLOT(switch_copierLB(int)));
1027 connect(copierFormatCO, SIGNAL(activated(int)), this, SLOT(switch_copierCO(int)));
1028 connect(copierNewPB, SIGNAL(clicked()),
1029 this, SIGNAL(changed()));
1030 connect(copierRemovePB, SIGNAL(clicked()),
1031 this, SIGNAL(changed()));
1032 connect(copierModifyPB, SIGNAL(clicked()),
1033 this, SIGNAL(changed()));
1034 connect(copierFormatCO, SIGNAL(activated(const QString&)), this, SLOT(copiers_changed()));
1035 connect(copierED, SIGNAL(textChanged(const QString&)), this, SLOT(copiers_changed()));
1039 void PrefCopiers::apply(LyXRC & /*rc*/) const
1044 void PrefCopiers::update(LyXRC const & /*rc*/)
1050 void PrefCopiers::update()
1052 // The choice widget
1053 // save current selection
1054 QString current = copierFormatCO->currentText();
1055 copierFormatCO->clear();
1057 for (Formats::const_iterator it = form_->formats().begin(),
1058 end = form_->formats().end();
1060 copierFormatCO->addItem(toqstr(it->prettyname()));
1063 // The browser widget
1064 AllCopiersLW->clear();
1066 for (Movers::iterator it = form_->movers().begin(),
1067 end = form_->movers().end();
1069 std::string const & command = it->second.command();
1070 if (command.empty())
1072 QString const pretty = toqstr(form_->formats().prettyName(it->first));
1073 AllCopiersLW->addItem(pretty);
1075 AllCopiersLW->sortItems(Qt::AscendingOrder);
1077 // restore selection
1078 if (!current.isEmpty()) {
1079 QList<QListWidgetItem *> item =
1080 AllCopiersLW->findItems(current, Qt::MatchExactly);
1082 AllCopiersLW->setCurrentItem(item.at(0));
1084 // select first element if restoring failed
1085 if (AllCopiersLW->currentRow() == -1)
1086 AllCopiersLW->setCurrentRow(0);
1092 class SamePrettyName {
1094 SamePrettyName(string const & n) : pretty_name_(n) {}
1096 bool operator()(lyx::Format const & fmt) const {
1097 return fmt.prettyname() == pretty_name_;
1101 string const pretty_name_;
1105 Format const * getFormat(std::string const & prettyname)
1107 Formats::const_iterator it = lyx::formats.begin();
1108 Formats::const_iterator const end = lyx::formats.end();
1109 it = std::find_if(it, end, SamePrettyName(prettyname));
1110 return it == end ? 0 : &*it;
1116 void PrefCopiers::switch_copierLB(int row)
1122 std::string const browser_text =
1123 fromqstr(AllCopiersLW->currentItem()->text());
1124 Format const * fmt = getFormat(browser_text);
1128 QString const gui_name = toqstr(fmt->prettyname());
1129 QString const command = toqstr(form_->movers().command(fmt->name()));
1132 int const combo_size = copierFormatCO->count();
1133 for (int i = 0; i < combo_size; ++i) {
1134 QString const text = copierFormatCO->itemText(i);
1135 if (text == gui_name) {
1136 copierFormatCO->setCurrentIndex(i);
1137 copierED->setText(command);
1145 void PrefCopiers::switch_copierCO(int row)
1150 std::string const combo_text =
1151 fromqstr(copierFormatCO->currentText());
1152 Format const * fmt = getFormat(combo_text);
1156 QString const command = toqstr(form_->movers().command(fmt->name()));
1157 copierED->setText(command);
1159 QListWidgetItem * const index = AllCopiersLW->currentItem();
1161 AllCopiersLW->setItemSelected(index, false);
1163 QString const gui_name = toqstr(fmt->prettyname());
1164 int const browser_size = AllCopiersLW->count();
1165 for (int i = 0; i < browser_size; ++i) {
1166 QString const text = AllCopiersLW->item(i)->text();
1167 if (text == gui_name) {
1168 QListWidgetItem * item = AllCopiersLW->item(i);
1169 AllCopiersLW->setItemSelected(item, true);
1176 void PrefCopiers::copiers_changed()
1182 void PrefCopiers::updateButtons()
1184 QString selected = copierFormatCO->currentText();
1187 for (int i = 0; i < AllCopiersLW->count(); ++i) {
1188 if (AllCopiersLW->item(i)->text() == selected)
1192 bool const valid = !copierED->text().isEmpty();
1194 Format const * fmt = getFormat(fromqstr(selected));
1195 string const old_command = form_->movers().command(fmt->name());
1196 string const new_command(fromqstr(copierED->text()));
1198 bool modified = (old_command != new_command);
1200 copierModifyPB->setEnabled(valid && known && modified);
1201 copierNewPB->setEnabled(valid && !known);
1202 copierRemovePB->setEnabled(known);
1206 void PrefCopiers::new_copier()
1208 std::string const combo_text =
1209 fromqstr(copierFormatCO->currentText());
1210 Format const * fmt = getFormat(combo_text);
1214 string const command = fromqstr(copierED->text());
1215 if (command.empty())
1218 form_->movers().set(fmt->name(), command);
1221 int const last = AllCopiersLW->count() - 1;
1222 AllCopiersLW->setCurrentRow(last);
1228 void PrefCopiers::modify_copier()
1230 std::string const combo_text =
1231 fromqstr(copierFormatCO->currentText());
1232 Format const * fmt = getFormat(combo_text);
1236 string const command = fromqstr(copierED->text());
1237 form_->movers().set(fmt->name(), command);
1244 void PrefCopiers::remove_copier()
1246 std::string const combo_text =
1247 fromqstr(copierFormatCO->currentText());
1248 Format const * fmt = getFormat(combo_text);
1252 string const & fmt_name = fmt->name();
1253 form_->movers().set(fmt_name, string());
1261 PrefFileformats::PrefFileformats(QPrefs * form, QWidget * parent)
1262 : PrefModule(docstring(), _("File formats"), form, parent)
1266 connect(formatNewPB, SIGNAL(clicked()),
1267 this, SLOT(new_format()));
1268 connect(formatRemovePB, SIGNAL(clicked()),
1269 this, SLOT(remove_format()));
1270 connect(formatModifyPB, SIGNAL(clicked()),
1271 this, SLOT(modify_format()));
1272 connect(formatsLW, SIGNAL(currentRowChanged(int)),
1273 this, SLOT(switch_format(int)));
1274 connect(formatED, SIGNAL(textChanged(const QString&)),
1275 this, SLOT(fileformat_changed()));
1276 connect(guiNameED, SIGNAL(textChanged(const QString&)),
1277 this, SLOT(fileformat_changed()));
1278 connect(shortcutED, SIGNAL(textChanged(const QString&)),
1279 this, SLOT(fileformat_changed()));
1280 connect(extensionED, SIGNAL(textChanged(const QString&)),
1281 this, SLOT(fileformat_changed()));
1282 connect(viewerED, SIGNAL(textChanged(const QString&)),
1283 this, SLOT(fileformat_changed()));
1284 connect(editorED, SIGNAL(textChanged(const QString&)),
1285 this, SLOT(fileformat_changed()));
1286 connect(documentCB, SIGNAL(toggled(bool)),
1287 this, SLOT(fileformat_changed()));
1288 connect(vectorCB, SIGNAL(toggled(bool)),
1289 this, SLOT(fileformat_changed()));
1290 connect(formatNewPB, SIGNAL(clicked()),
1291 this, SIGNAL(changed()));
1292 connect(formatRemovePB, SIGNAL(clicked()),
1293 this, SIGNAL(changed()));
1294 connect(formatModifyPB, SIGNAL(clicked()),
1295 this, SIGNAL(changed()));
1299 void PrefFileformats::apply(LyXRC & /*rc*/) const
1304 void PrefFileformats::update(LyXRC const & /*rc*/)
1310 void PrefFileformats::update()
1312 // save current selection
1313 QString current = guiNameED->text();
1315 // update listwidget with formats
1316 formatsLW->blockSignals(true);
1318 Formats::const_iterator cit = form_->formats().begin();
1319 Formats::const_iterator end = form_->formats().end();
1320 for (; cit != end; ++cit) {
1321 new QListWidgetItem(toqstr(cit->prettyname()),
1323 form_->formats().getNumber(cit->name()) );
1325 formatsLW->sortItems(Qt::AscendingOrder);
1326 formatsLW->blockSignals(false);
1328 // restore selection
1329 if (!current.isEmpty()) {
1330 QList<QListWidgetItem *> item = formatsLW->findItems(current, Qt::MatchExactly);
1332 formatsLW->setCurrentItem(item.at(0));
1334 // select first element if restoring failed
1335 if (formatsLW->currentRow() == -1)
1336 formatsLW->setCurrentRow(0);
1340 void PrefFileformats::switch_format(int nr)
1342 int const ftype = formatsLW->item(nr)->type();
1343 Format const f = form_->formats().get(ftype);
1345 formatED->setText(toqstr(f.name()));
1346 guiNameED->setText(toqstr(f.prettyname()));
1347 extensionED->setText(toqstr(f.extension()));
1348 shortcutED->setText(toqstr(f.shortcut()));
1349 viewerED->setText(toqstr(f.viewer()));
1350 editorED->setText(toqstr(f.editor()));
1351 documentCB->setChecked((f.documentFormat()));
1352 vectorCB->setChecked((f.vectorFormat()));
1358 void PrefFileformats::fileformat_changed()
1364 void PrefFileformats::updateButtons()
1366 QString const format = formatED->text();
1367 QString const gui_name = guiNameED->text();
1368 int const sel = form_->formats().getNumber(fromqstr(format));
1369 bool gui_name_known = false;
1371 for (int i = 0; i < formatsLW->count(); ++i) {
1372 if (formatsLW->item(i)->text() == gui_name) {
1373 gui_name_known = true;
1374 where = formatsLW->item(i)->type();
1378 // assure that a gui name cannot be chosen twice
1379 bool const known_otherwise = gui_name_known && (where != sel);
1381 bool const known = !(sel < 0);
1382 bool const valid = (!formatED->text().isEmpty()
1383 && !guiNameED->text().isEmpty());
1385 int const ftype = formatsLW->currentItem()->type();
1386 Format const & f(form_->formats().get(ftype));
1387 string const old_pretty(f.prettyname());
1388 string const old_shortcut(f.shortcut());
1389 string const old_extension(f.extension());
1390 string const old_viewer(f.viewer());
1391 string const old_editor(f.editor());
1392 bool const old_document(f.documentFormat());
1393 bool const old_vector(f.vectorFormat());
1395 string const new_pretty(fromqstr(gui_name));
1396 string const new_shortcut(fromqstr(shortcutED->text()));
1397 string const new_extension(fromqstr(extensionED->text()));
1398 string const new_viewer(fromqstr(viewerED->text()));
1399 string const new_editor(fromqstr(editorED->text()));
1400 bool const new_document(documentCB->isChecked());
1401 bool const new_vector(vectorCB->isChecked());
1403 bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
1404 || (old_extension != new_extension) || (old_viewer != new_viewer)
1405 || old_editor != new_editor || old_document != new_document
1406 || old_vector != new_vector);
1408 formatModifyPB->setEnabled(valid && known && modified && !known_otherwise);
1409 formatNewPB->setEnabled(valid && !known && !gui_name_known);
1410 formatRemovePB->setEnabled(known);
1414 void PrefFileformats::new_format()
1416 string const name = fromqstr(formatED->text());
1417 string const prettyname = fromqstr(guiNameED->text());
1418 string const extension = fromqstr(extensionED->text());
1419 string const shortcut = fromqstr(shortcutED->text());
1420 string const viewer = fromqstr(viewerED->text());
1421 string const editor = fromqstr(editorED->text());
1422 int flags = Format::none;
1423 if (documentCB->isChecked())
1424 flags |= Format::document;
1425 if (vectorCB->isChecked())
1426 flags |= Format::vector;
1428 form_->formats().add(name, extension, prettyname, shortcut, viewer,
1430 form_->formats().sort();
1431 form_->converters().update(form_->formats());
1439 void PrefFileformats::modify_format()
1441 int const current_item = formatsLW->currentItem()->type();
1442 Format const & oldformat = form_->formats().get(current_item);
1443 form_->formats().erase(oldformat.name());
1449 void PrefFileformats::remove_format()
1451 int const nr = formatsLW->currentItem()->type();
1452 string const current_text = form_->formats().get(nr).name();
1453 if (form_->converters().formatIsUsed(current_text)) {
1454 Alert::error(_("Format in use"),
1455 _("Cannot remove a Format used by a Converter. "
1456 "Remove the converter first."));
1460 form_->formats().erase(current_text);
1461 form_->converters().update(form_->formats());
1470 PrefLanguage::PrefLanguage(QWidget * parent)
1471 : PrefModule(docstring(), _("Language"), 0, parent)
1475 connect(rtlCB, SIGNAL(toggled(bool)),
1476 this, SIGNAL(changed()));
1477 connect(markForeignCB, SIGNAL(toggled(bool)),
1478 this, SIGNAL(changed()));
1479 connect(autoBeginCB, SIGNAL(toggled(bool)),
1480 this, SIGNAL(changed()));
1481 connect(autoEndCB, SIGNAL(toggled(bool)),
1482 this, SIGNAL(changed()));
1483 connect(useBabelCB, SIGNAL(toggled(bool)),
1484 this, SIGNAL(changed()));
1485 connect(globalCB, SIGNAL(toggled(bool)),
1486 this, SIGNAL(changed()));
1487 connect(languagePackageED, SIGNAL(textChanged(const QString&)),
1488 this, SIGNAL(changed()));
1489 connect(startCommandED, SIGNAL(textChanged(const QString&)),
1490 this, SIGNAL(changed()));
1491 connect(endCommandED, SIGNAL(textChanged(const QString&)),
1492 this, SIGNAL(changed()));
1493 connect(defaultLanguageCO, SIGNAL(activated(int)),
1494 this, SIGNAL(changed()));
1496 defaultLanguageCO->clear();
1498 // store the lang identifiers for later
1499 using lyx::frontend::LanguagePair;
1500 std::vector<LanguagePair> const langs =
1501 lyx::frontend::getLanguageData(false);
1502 lang_ = getSecond(langs);
1504 std::vector<LanguagePair>::const_iterator lit = langs.begin();
1505 std::vector<LanguagePair>::const_iterator lend = langs.end();
1506 for (; lit != lend; ++lit) {
1507 defaultLanguageCO->addItem(toqstr(lit->first));
1512 void PrefLanguage::apply(LyXRC & rc) const
1514 // FIXME: remove rtl_support bool
1515 rc.rtl_support = rtlCB->isChecked();
1516 rc.mark_foreign_language = markForeignCB->isChecked();
1517 rc.language_auto_begin = autoBeginCB->isChecked();
1518 rc.language_auto_end = autoEndCB->isChecked();
1519 rc.language_use_babel = useBabelCB->isChecked();
1520 rc.language_global_options = globalCB->isChecked();
1521 rc.language_package = fromqstr(languagePackageED->text());
1522 rc.language_command_begin = fromqstr(startCommandED->text());
1523 rc.language_command_end = fromqstr(endCommandED->text());
1524 rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1528 void PrefLanguage::update(LyXRC const & rc)
1530 // FIXME: remove rtl_support bool
1531 rtlCB->setChecked(rc.rtl_support);
1532 markForeignCB->setChecked(rc.mark_foreign_language);
1533 autoBeginCB->setChecked(rc.language_auto_begin);
1534 autoEndCB->setChecked(rc.language_auto_end);
1535 useBabelCB->setChecked(rc.language_use_babel);
1536 globalCB->setChecked(rc.language_global_options);
1537 languagePackageED->setText(toqstr(rc.language_package));
1538 startCommandED->setText(toqstr(rc.language_command_begin));
1539 endCommandED->setText(toqstr(rc.language_command_end));
1541 int const pos = int(findPos(lang_, rc.default_language));
1542 defaultLanguageCO->setCurrentIndex(pos);
1546 PrefPrinter::PrefPrinter(QWidget * parent)
1547 : PrefModule(_(Outputs), _("Printer"), 0, parent)
1551 connect(printerAdaptCB, SIGNAL(toggled(bool)),
1552 this, SIGNAL(changed()));
1553 connect(printerCommandED, SIGNAL(textChanged(const QString&)),
1554 this, SIGNAL(changed()));
1555 connect(printerNameED, SIGNAL(textChanged(const QString&)),
1556 this, SIGNAL(changed()));
1557 connect(printerPageRangeED, SIGNAL(textChanged(const QString&)),
1558 this, SIGNAL(changed()));
1559 connect(printerCopiesED, SIGNAL(textChanged(const QString&)),
1560 this, SIGNAL(changed()));
1561 connect(printerReverseED, SIGNAL(textChanged(const QString&)),
1562 this, SIGNAL(changed()));
1563 connect(printerToPrinterED, SIGNAL(textChanged(const QString&)),
1564 this, SIGNAL(changed()));
1565 connect(printerExtensionED, SIGNAL(textChanged(const QString&)),
1566 this, SIGNAL(changed()));
1567 connect(printerSpoolCommandED, SIGNAL(textChanged(const QString&)),
1568 this, SIGNAL(changed()));
1569 connect(printerPaperTypeED, SIGNAL(textChanged(const QString&)),
1570 this, SIGNAL(changed()));
1571 connect(printerEvenED, SIGNAL(textChanged(const QString&)),
1572 this, SIGNAL(changed()));
1573 connect(printerOddED, SIGNAL(textChanged(const QString&)),
1574 this, SIGNAL(changed()));
1575 connect(printerCollatedED, SIGNAL(textChanged(const QString&)),
1576 this, SIGNAL(changed()));
1577 connect(printerLandscapeED, SIGNAL(textChanged(const QString&)),
1578 this, SIGNAL(changed()));
1579 connect(printerToFileED, SIGNAL(textChanged(const QString&)),
1580 this, SIGNAL(changed()));
1581 connect(printerExtraED, SIGNAL(textChanged(const QString&)),
1582 this, SIGNAL(changed()));
1583 connect(printerSpoolPrefixED, SIGNAL(textChanged(const QString&)),
1584 this, SIGNAL(changed()));
1585 connect(printerPaperSizeED, SIGNAL(textChanged(const QString&)),
1586 this, SIGNAL(changed()));
1590 void PrefPrinter::apply(LyXRC & rc) const
1592 rc.print_adapt_output = printerAdaptCB->isChecked();
1593 rc.print_command = fromqstr(printerCommandED->text());
1594 rc.printer = fromqstr(printerNameED->text());
1596 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1597 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1598 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1599 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1600 rc.print_file_extension = fromqstr(printerExtensionED->text());
1601 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1602 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1603 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1604 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1605 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1606 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1607 rc.print_to_file = internal_path(printerToFileED->text());
1608 rc.print_extra_options = fromqstr(printerExtraED->text());
1609 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1610 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1614 void PrefPrinter::update(LyXRC const & rc)
1616 printerAdaptCB->setChecked(rc.print_adapt_output);
1617 printerCommandED->setText(toqstr(rc.print_command));
1618 printerNameED->setText(toqstr(rc.printer));
1620 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1621 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1622 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1623 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1624 printerExtensionED->setText(toqstr(rc.print_file_extension));
1625 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1626 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1627 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1628 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1629 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1630 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1631 printerToFileED->setText(external_path(rc.print_to_file));
1632 printerExtraED->setText(toqstr(rc.print_extra_options));
1633 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1634 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1638 PrefUserInterface::PrefUserInterface(QPrefs * form, QWidget * parent)
1639 : PrefModule(_(LookAndFeel), _("User interface"), form, parent)
1643 connect(autoSaveCB, SIGNAL( toggled(bool) ), autoSaveLA, SLOT( setEnabled(bool) ) );
1644 connect(autoSaveCB, SIGNAL( toggled(bool) ), autoSaveSB, SLOT( setEnabled(bool) ) );
1645 connect(autoSaveCB, SIGNAL( toggled(bool) ), TextLabel1, SLOT( setEnabled(bool) ) );
1646 connect(uiFilePB, SIGNAL(clicked()), this, SLOT(select_ui()));
1647 connect(bindFilePB, SIGNAL(clicked()), this, SLOT(select_bind()));
1648 connect(uiFileED, SIGNAL(textChanged(const QString&)),
1649 this, SIGNAL(changed()));
1650 connect(bindFileED, SIGNAL(textChanged(const QString&)),
1651 this, SIGNAL(changed()));
1652 connect(restoreCursorCB, SIGNAL(toggled(bool)),
1653 this, SIGNAL(changed()));
1654 connect(loadSessionCB, SIGNAL(toggled(bool)),
1655 this, SIGNAL(changed()));
1656 connect(loadWindowSizeCB, SIGNAL(toggled(bool)),
1657 this, SIGNAL(changed()));
1658 connect(loadWindowSizeCB, SIGNAL(toggled(bool)),
1659 windowWidthLA, SLOT(setDisabled(bool)));
1660 connect(loadWindowSizeCB, SIGNAL(toggled(bool)),
1661 windowHeightLA, SLOT(setDisabled(bool)));
1662 connect(loadWindowSizeCB, SIGNAL(toggled(bool)),
1663 windowWidthSB, SLOT(setDisabled(bool)));
1664 connect(loadWindowSizeCB, SIGNAL(toggled(bool)),
1665 windowHeightSB, SLOT(setDisabled(bool)));
1666 connect(loadWindowLocationCB, SIGNAL(toggled(bool)),
1667 this, SIGNAL(changed()));
1668 connect(windowWidthSB, SIGNAL(valueChanged(int)),
1669 this, SIGNAL(changed()));
1670 connect(windowHeightSB, SIGNAL(valueChanged(int)),
1671 this, SIGNAL(changed()));
1672 connect(cursorFollowsCB, SIGNAL(toggled(bool)),
1673 this, SIGNAL(changed()));
1674 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1675 this, SIGNAL(changed()));
1676 connect(autoSaveCB, SIGNAL(toggled(bool)),
1677 this, SIGNAL(changed()));
1678 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1679 this, SIGNAL(changed()));
1680 lastfilesSB->setMaximum(maxlastfiles);
1684 void PrefUserInterface::apply(LyXRC & rc) const
1686 rc.ui_file = internal_path(uiFileED->text());
1687 rc.bind_file = internal_path(bindFileED->text());
1688 rc.use_lastfilepos = restoreCursorCB->isChecked();
1689 rc.load_session = loadSessionCB->isChecked();
1690 if (loadWindowSizeCB->isChecked()) {
1691 rc.geometry_width = 0;
1692 rc.geometry_height = 0;
1694 rc.geometry_width = windowWidthSB->value();
1695 rc.geometry_height = windowHeightSB->value();
1697 rc.geometry_xysaved = loadWindowLocationCB->isChecked();
1698 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1699 rc.autosave = autoSaveSB->value() * 60;
1700 rc.make_backup = autoSaveCB->isChecked();
1701 rc.num_lastfiles = lastfilesSB->value();
1705 void PrefUserInterface::update(LyXRC const & rc)
1707 uiFileED->setText(external_path(rc.ui_file));
1708 bindFileED->setText(external_path(rc.bind_file));
1709 restoreCursorCB->setChecked(rc.use_lastfilepos);
1710 loadSessionCB->setChecked(rc.load_session);
1711 bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
1712 loadWindowSizeCB->setChecked(loadWindowSize);
1713 windowWidthSB->setEnabled(!loadWindowSize);
1714 windowHeightSB->setEnabled(!loadWindowSize);
1715 windowWidthLA->setEnabled(!loadWindowSize);
1716 windowHeightLA->setEnabled(!loadWindowSize);
1717 if (!loadWindowSize) {
1718 windowWidthSB->setValue(rc.geometry_width);
1719 windowHeightSB->setValue(rc.geometry_height);
1721 loadWindowLocationCB->setChecked(rc.geometry_xysaved);
1722 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1723 // convert to minutes
1724 int mins(rc.autosave / 60);
1725 if (rc.autosave && !mins)
1727 autoSaveSB->setValue(mins);
1728 autoSaveCB->setChecked(rc.make_backup);
1729 lastfilesSB->setValue(rc.num_lastfiles);
1734 void PrefUserInterface::select_ui()
1736 docstring file(form_->controller().browseUI(qstring_to_ucs4(uiFileED->text())));
1738 uiFileED->setText(toqstr(file));
1742 void PrefUserInterface::select_bind()
1744 docstring file(form_->controller().browsebind(qstring_to_ucs4(bindFileED->text())));
1746 bindFileED->setText(toqstr(file));
1750 PrefIdentity::PrefIdentity(QWidget * parent)
1751 : PrefModule(docstring(), _("Identity"), 0, parent)
1755 connect(nameED, SIGNAL(textChanged(const QString&)),
1756 this, SIGNAL(changed()));
1757 connect(emailED, SIGNAL(textChanged(const QString&)),
1758 this, SIGNAL(changed()));
1762 void PrefIdentity::apply(LyXRC & rc) const
1764 rc.user_name = fromqstr(nameED->text());
1765 rc.user_email = fromqstr(emailED->text());
1769 void PrefIdentity::update(LyXRC const & rc)
1771 nameED->setText(toqstr(rc.user_name));
1772 emailED->setText(toqstr(rc.user_email));
1777 QPrefsDialog::QPrefsDialog(QPrefs * form)
1781 QDialog::setModal(true);
1783 connect(savePB, SIGNAL(clicked()),
1784 form, SLOT(slotOK()));
1785 connect(applyPB, SIGNAL(clicked()),
1786 form, SLOT(slotApply()));
1787 connect(closePB, SIGNAL(clicked()),
1788 form, SLOT(slotClose()));
1789 connect(restorePB, SIGNAL(clicked()),
1790 form, SLOT(slotRestore()));
1794 add(new PrefKeyboard(form_));
1795 add(new PrefLatex(form_));
1796 add(new PrefScreenFonts(form_));
1797 add(new PrefColors(form_));
1799 #if defined(__CYGWIN__) || defined(_WIN32)
1800 add(new PrefCygwinPath);
1803 add(new PrefDisplay);
1804 add(new PrefPaths(form_));
1805 add(new PrefSpellchecker(form_));
1807 PrefConverters * converters = new PrefConverters(form_);
1808 PrefFileformats * formats = new PrefFileformats(form_);
1809 connect(formats, SIGNAL(formatsChanged()),
1810 converters, SLOT(updateGui()));
1814 add(new PrefCopiers(form_));
1816 add(new PrefLanguage);
1817 add(new PrefPrinter);
1818 add(new PrefUserInterface(form_));
1819 add(new PrefIdentity);
1821 prefsPS->setCurrentPanel(_("User interface"));
1822 // FIXME: hack to work around resizing bug in Qt >= 4.2
1823 #if QT_VERSION >= 0x040200
1824 prefsPS->updateGeometry();
1827 form_->bcview().setOK(savePB);
1828 form_->bcview().setApply(applyPB);
1829 form_->bcview().setCancel(closePB);
1830 form_->bcview().setRestore(restorePB);
1834 QPrefsDialog::~QPrefsDialog()
1839 void QPrefsDialog::add(PrefModule * module)
1841 BOOST_ASSERT(module);
1843 // if (module->category().empty())
1844 // prefsPS->addPanel(module, module->title());
1846 prefsPS->addPanel(module, module->title(), module->category());
1848 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
1850 modules_.push_back(module);
1853 void QPrefsDialog::closeEvent(QCloseEvent * e)
1855 form_->slotWMHide();
1860 void QPrefsDialog::change_adaptor()
1866 void QPrefsDialog::apply(LyXRC & rc) const
1868 size_t end = modules_.size();
1869 for (size_t i = 0; i != end; ++i)
1870 modules_[i]->apply(rc);
1874 void QPrefsDialog::update(LyXRC const & rc)
1876 size_t end = modules_.size();
1877 for (size_t i = 0; i != end; ++i)
1878 modules_[i]->update(rc);
1882 } // namespace frontend
1885 #include "QPrefsDialog_moc.cpp"