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_ascii_no_case;
60 using lyx::support::os::external_path;
61 using lyx::support::os::external_path_list;
62 using lyx::support::os::internal_path;
63 using lyx::support::os::internal_path_list;
70 using std::ostringstream;
78 string const LookAndFeel = N_("Look and feel");
79 string const LanguageSettings = N_("Language settings");
80 string const Outputs = N_("Outputs");
83 // FIXME: move to helper_funcs.h
87 typename std::vector<A>::size_type
88 findPos(std::vector<A> const & vec, A const & val)
90 typedef typename std::vector<A>::const_iterator Cit;
92 Cit it = std::find(vec.begin(), vec.end(), val);
95 return distance(vec.begin(), it);
98 void setComboxFont(QComboBox * cb, string const & family, string const & foundry)
100 string const name = makeFontName(family, foundry);
101 for (int i = 0; i < cb->count(); ++i) {
102 if (fromqstr(cb->itemText(i)) == name) {
103 cb->setCurrentIndex(i);
108 // Try matching without foundry name
110 // We count in reverse in order to prefer the Xft foundry
111 for (int i = cb->count() - 1; i >= 0; --i) {
112 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
113 if (compare_ascii_no_case(tmp.first, family) == 0) {
114 cb->setCurrentIndex(i);
119 // family alone can contain e.g. "Helvetica [Adobe]"
120 pair<string, string> tmpfam = parseFontName(family);
122 // We count in reverse in order to prefer the Xft foundry
123 for (int i = cb->count() - 1; i >= 0; --i) {
124 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
125 if (compare_ascii_no_case(tmp.first, tmpfam.first) == 0) {
126 cb->setCurrentIndex(i);
131 // Bleh, default fonts, and the names couldn't be found. Hack
132 // for bug 1063. Qt makes baby Jesus cry.
135 font.setKerning(false);
137 if (family == theApp()->romanFontName()) {
138 font.setStyleHint(QFont::Serif);
139 font.setFamily(family.c_str());
140 } else if (family == theApp()->sansFontName()) {
141 font.setStyleHint(QFont::SansSerif);
142 font.setFamily(family.c_str());
143 } else if (family == theApp()->typewriterFontName()) {
144 font.setStyleHint(QFont::TypeWriter);
145 font.setFamily(family.c_str());
147 lyxerr << "FAILED to find the default font: '"
148 << foundry << "', '" << family << '\''<< endl;
152 QFontInfo info(font);
153 pair<string, string> tmp = parseFontName(fromqstr(info.family()));
154 string const & default_font_name = tmp.first;
155 lyxerr << "Apparent font is " << default_font_name << endl;
157 for (int i = 0; i < cb->count(); ++i) {
158 lyxerr << "Looking at " << fromqstr(cb->itemText(i)) << endl;
159 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
160 default_font_name) == 0) {
161 cb->setCurrentIndex(i);
166 lyxerr << "FAILED to find the font: '"
167 << foundry << "', '" << family << '\'' <<endl;
170 } // end namespace anon
173 PrefPlaintext::PrefPlaintext(QWidget * parent)
174 : PrefModule(_(Outputs), _("Plain text"), 0, parent)
177 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
178 this, SIGNAL(changed()));
179 connect(plaintextRoffED, SIGNAL(textChanged(const QString&)),
180 this, SIGNAL(changed()));
184 void PrefPlaintext::apply(LyXRC & rc) const
186 rc.plaintext_linelen = plaintextLinelengthSB->value();
187 rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
191 void PrefPlaintext::update(LyXRC const & rc)
193 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
194 plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
198 PrefDate::PrefDate(QWidget * parent)
199 : PrefModule(_(Outputs), _("Date format"), 0, parent)
202 connect(DateED, SIGNAL(textChanged(const QString&)),
203 this, SIGNAL(changed()));
207 void PrefDate::apply(LyXRC & rc) const
209 rc.date_insert_format = fromqstr(DateED->text());
213 void PrefDate::update(LyXRC const & rc)
215 DateED->setText(toqstr(rc.date_insert_format));
219 PrefKeyboard::PrefKeyboard(QPrefs * form, QWidget * parent)
220 : PrefModule(_(LookAndFeel), _("Keyboard"), form, parent)
224 connect(keymapCB, SIGNAL(clicked()),
225 this, SIGNAL(changed()));
226 connect(firstKeymapED, SIGNAL(textChanged(const QString&)),
227 this, SIGNAL(changed()));
228 connect(secondKeymapED, SIGNAL(textChanged(const QString&)),
229 this, SIGNAL(changed()));
233 void PrefKeyboard::apply(LyXRC & rc) const
235 // FIXME: can derive CB from the two EDs
236 rc.use_kbmap = keymapCB->isChecked();
238 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
239 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
243 void PrefKeyboard::update(LyXRC const & rc)
245 // FIXME: can derive CB from the two EDs
246 keymapCB->setChecked(rc.use_kbmap);
247 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
248 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
252 QString PrefKeyboard::testKeymap(QString keymap)
254 return toqstr(form_->controller().browsekbmap(from_utf8(internal_path(fromqstr(keymap)))));
258 void PrefKeyboard::on_firstKeymapPB_clicked(bool)
260 QString const file = testKeymap(firstKeymapED->text());
262 firstKeymapED->setText(file);
266 void PrefKeyboard::on_secondKeymapPB_clicked(bool)
268 QString const file = testKeymap(secondKeymapED->text());
270 secondKeymapED->setText(file);
274 void PrefKeyboard::on_keymapCB_toggled(bool keymap)
276 firstKeymapLA->setEnabled(keymap);
277 secondKeymapLA->setEnabled(keymap);
278 firstKeymapED->setEnabled(keymap);
279 secondKeymapED->setEnabled(keymap);
280 firstKeymapPB->setEnabled(keymap);
281 secondKeymapPB->setEnabled(keymap);
285 PrefLatex::PrefLatex(QPrefs * form, QWidget * parent)
286 : PrefModule(_(Outputs), _("LaTeX"), form, parent)
289 connect(latexEncodingED, SIGNAL(textChanged(const QString&)),
290 this, SIGNAL(changed()));
291 connect(latexChecktexED, SIGNAL(textChanged(const QString&)),
292 this, SIGNAL(changed()));
293 connect(latexBibtexED, SIGNAL(textChanged(const QString&)),
294 this, SIGNAL(changed()));
295 connect(latexIndexED, SIGNAL(textChanged(const QString&)),
296 this, SIGNAL(changed()));
297 connect(latexAutoresetCB, SIGNAL(clicked()),
298 this, SIGNAL(changed()));
299 connect(latexDviPaperED, SIGNAL(textChanged(const QString&)),
300 this, SIGNAL(changed()));
301 connect(latexPaperSizeCO, SIGNAL(activated(int)),
302 this, SIGNAL(changed()));
306 void PrefLatex::apply(LyXRC & rc) const
308 rc.fontenc = fromqstr(latexEncodingED->text());
309 rc.chktex_command = fromqstr(latexChecktexED->text());
310 rc.bibtex_command = fromqstr(latexBibtexED->text());
311 rc.index_command = fromqstr(latexIndexED->text());
312 rc.auto_reset_options = latexAutoresetCB->isChecked();
313 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
314 rc.default_papersize =
315 form_->controller().toPaperSize(latexPaperSizeCO->currentIndex());
319 void PrefLatex::update(LyXRC const & rc)
321 latexEncodingED->setText(toqstr(rc.fontenc));
322 latexChecktexED->setText(toqstr(rc.chktex_command));
323 latexBibtexED->setText(toqstr(rc.bibtex_command));
324 latexIndexED->setText(toqstr(rc.index_command));
325 latexAutoresetCB->setChecked(rc.auto_reset_options);
326 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
327 latexPaperSizeCO->setCurrentIndex(
328 form_->controller().fromPaperSize(rc.default_papersize));
332 PrefScreenFonts::PrefScreenFonts(QPrefs * form, QWidget * parent)
333 : PrefModule(_(LookAndFeel), _("Screen fonts"), form, parent)
337 connect(screenRomanCO, SIGNAL(activated(const QString&)),
338 this, SLOT(select_roman(const QString&)));
339 connect(screenSansCO, SIGNAL(activated(const QString&)),
340 this, SLOT(select_sans(const QString&)));
341 connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
342 this, SLOT(select_typewriter(const QString&)));
344 QFontDatabase fontdb;
345 QStringList families(fontdb.families());
346 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
347 screenRomanCO->addItem(*it);
348 screenSansCO->addItem(*it);
349 screenTypewriterCO->addItem(*it);
351 connect(screenRomanCO, SIGNAL(activated(const QString&)),
352 this, SIGNAL(changed()));
353 connect(screenSansCO, SIGNAL(activated(const QString&)),
354 this, SIGNAL(changed()));
355 connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
356 this, SIGNAL(changed()));
357 connect(screenZoomSB, SIGNAL(valueChanged(int)),
358 this, SIGNAL(changed()));
359 connect(screenDpiSB, SIGNAL(valueChanged(int)),
360 this, SIGNAL(changed()));
361 connect(screenTinyED, SIGNAL(textChanged(const QString&)),
362 this, SIGNAL(changed()));
363 connect(screenSmallestED, SIGNAL(textChanged(const QString&)),
364 this, SIGNAL(changed()));
365 connect(screenSmallerED, SIGNAL(textChanged(const QString&)),
366 this, SIGNAL(changed()));
367 connect(screenSmallED, SIGNAL(textChanged(const QString&)),
368 this, SIGNAL(changed()));
369 connect(screenNormalED, SIGNAL(textChanged(const QString&)),
370 this, SIGNAL(changed()));
371 connect(screenLargeED, SIGNAL(textChanged(const QString&)),
372 this, SIGNAL(changed()));
373 connect(screenLargerED, SIGNAL(textChanged(const QString&)),
374 this, SIGNAL(changed()));
375 connect(screenLargestED, SIGNAL(textChanged(const QString&)),
376 this, SIGNAL(changed()));
377 connect(screenHugeED, SIGNAL(textChanged(const QString&)),
378 this, SIGNAL(changed()));
379 connect(screenHugerED, SIGNAL(textChanged(const QString&)),
380 this, SIGNAL(changed()));
382 screenTinyED->setValidator(new QDoubleValidator(
384 screenSmallestED->setValidator(new QDoubleValidator(
386 screenSmallerED->setValidator(new QDoubleValidator(
388 screenSmallED->setValidator(new QDoubleValidator(
390 screenNormalED->setValidator(new QDoubleValidator(
392 screenLargeED->setValidator(new QDoubleValidator(
394 screenLargerED->setValidator(new QDoubleValidator(
396 screenLargestED->setValidator(new QDoubleValidator(
398 screenHugeED->setValidator(new QDoubleValidator(
400 screenHugerED->setValidator(new QDoubleValidator(
405 void PrefScreenFonts::apply(LyXRC & rc) const
407 LyXRC const oldrc(rc);
409 boost::tie(rc.roman_font_name, rc.roman_font_foundry)
410 = parseFontName(fromqstr(screenRomanCO->currentText()));
411 boost::tie(rc.sans_font_name, rc.sans_font_foundry) =
412 parseFontName(fromqstr(screenSansCO->currentText()));
413 boost::tie(rc.typewriter_font_name, rc.typewriter_font_foundry) =
414 parseFontName(fromqstr(screenTypewriterCO->currentText()));
416 rc.zoom = screenZoomSB->value();
417 rc.dpi = screenDpiSB->value();
418 rc.font_sizes[LyXFont::SIZE_TINY] = fromqstr(screenTinyED->text());
419 rc.font_sizes[LyXFont::SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
420 rc.font_sizes[LyXFont::SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
421 rc.font_sizes[LyXFont::SIZE_SMALL] = fromqstr(screenSmallED->text());
422 rc.font_sizes[LyXFont::SIZE_NORMAL] = fromqstr(screenNormalED->text());
423 rc.font_sizes[LyXFont::SIZE_LARGE] = fromqstr(screenLargeED->text());
424 rc.font_sizes[LyXFont::SIZE_LARGER] = fromqstr(screenLargerED->text());
425 rc.font_sizes[LyXFont::SIZE_LARGEST] = fromqstr(screenLargestED->text());
426 rc.font_sizes[LyXFont::SIZE_HUGE] = fromqstr(screenHugeED->text());
427 rc.font_sizes[LyXFont::SIZE_HUGER] = fromqstr(screenHugerED->text());
429 if (rc.font_sizes != oldrc.font_sizes
430 || rc.roman_font_name != oldrc.roman_font_name
431 || rc.sans_font_name != oldrc.sans_font_name
432 || rc.typewriter_font_name != oldrc.typewriter_font_name
433 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
434 form_->controller().updateScreenFonts();
439 void PrefScreenFonts::update(LyXRC const & rc)
441 setComboxFont(screenRomanCO, rc.roman_font_name,
442 rc.roman_font_foundry);
443 setComboxFont(screenSansCO, rc.sans_font_name,
444 rc.sans_font_foundry);
445 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
446 rc.typewriter_font_foundry);
448 select_roman(screenRomanCO->currentText());
449 select_sans(screenSansCO->currentText());
450 select_typewriter(screenTypewriterCO->currentText());
452 screenZoomSB->setValue(rc.zoom);
453 screenDpiSB->setValue(rc.dpi);
454 screenTinyED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_TINY]));
455 screenSmallestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SCRIPT]));
456 screenSmallerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_FOOTNOTE]));
457 screenSmallED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SMALL]));
458 screenNormalED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_NORMAL]));
459 screenLargeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGE]));
460 screenLargerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGER]));
461 screenLargestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGEST]));
462 screenHugeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_HUGE]));
463 screenHugerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_HUGER]));
466 void PrefScreenFonts::select_roman(const QString& name)
468 screenRomanFE->set(QFont(name), name);
472 void PrefScreenFonts::select_sans(const QString& name)
474 screenSansFE->set(QFont(name), name);
478 void PrefScreenFonts::select_typewriter(const QString& name)
480 screenTypewriterFE->set(QFont(name), name);
484 PrefColors::PrefColors(QPrefs * form, QWidget * parent)
485 : PrefModule(_(LookAndFeel), _("Colors"), form, parent)
489 // FIXME: put in controller
490 for (int i = 0; i < LColor::ignore; ++i) {
491 LColor::color lc = static_cast<LColor::color>(i);
492 if (lc == LColor::none
493 || lc == LColor::black
494 || lc == LColor::white
496 || lc == LColor::green
497 || lc == LColor::blue
498 || lc == LColor::cyan
499 || lc == LColor::magenta
500 || lc == LColor::yellow
501 || lc == LColor::inherit
502 || lc == LColor::ignore) continue;
504 lcolors_.push_back(lc);
505 QColor color = QColor(guiApp->colorCache().get(lc));
506 prefcolors_.push_back(color.name());
507 QPixmap coloritem(32, 32);
508 coloritem.fill(color);
509 // This is not a memory leak:
510 /*QListWidgetItem * newItem =*/ new QListWidgetItem(QIcon(coloritem),
511 toqstr(lcolor.getGUIName(lc)), lyxObjectsLW);
513 newcolors_ = prefcolors_;
515 connect(colorChangePB, SIGNAL(clicked()),
516 this, SLOT(change_color()));
517 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
518 this, SLOT(change_color()));
522 void PrefColors::apply(LyXRC & /*rc*/) const
524 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
525 if (prefcolors_[i]!=newcolors_[i])
526 form_->controller().setColor(lcolors_[i], fromqstr(newcolors_[i]));
531 void PrefColors::update(LyXRC const & /*rc*/)
535 void PrefColors::change_color()
537 int const row = lyxObjectsLW->currentRow();
538 QString color = newcolors_[row];
539 QColor c(QColorDialog::getColor(QColor(color),
540 qApp->focusWidget()));
542 if (c.name()!=color) {
543 newcolors_[row] = c.name();
544 QPixmap coloritem(32, 32);
546 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
553 PrefCygwinPath::PrefCygwinPath(QWidget * parent)
554 : PrefModule(_(Outputs), _("Paths"), 0, parent)
557 connect(pathCB, SIGNAL(clicked()),
558 this, SIGNAL(changed()));
562 void PrefCygwinPath::apply(LyXRC & rc) const
564 rc.windows_style_tex_paths = pathCB->isChecked();
568 void PrefCygwinPath::update(LyXRC const & rc)
570 pathCB->setChecked(rc.windows_style_tex_paths);
574 PrefDisplay::PrefDisplay(QWidget * parent)
575 : PrefModule(_(LookAndFeel), _("Graphics"), 0, parent)
578 connect(instantPreviewCO, SIGNAL(activated(int)),
579 this, SIGNAL(changed()));
580 connect(displayGraphicsCO, SIGNAL(activated(int)),
581 this, SIGNAL(changed()));
585 void PrefDisplay::apply(LyXRC & rc) const
587 switch (instantPreviewCO->currentIndex()) {
588 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
589 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
590 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
593 lyx::graphics::DisplayType dtype;
594 switch (displayGraphicsCO->currentIndex()) {
595 case 3: dtype = lyx::graphics::NoDisplay; break;
596 case 2: dtype = lyx::graphics::ColorDisplay; break;
597 case 1: dtype = lyx::graphics::GrayscaleDisplay; break;
598 case 0: dtype = lyx::graphics::MonochromeDisplay; break;
599 default: dtype = lyx::graphics::GrayscaleDisplay;
601 rc.display_graphics = dtype;
604 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
607 if (old_value != rc.display_graphics) {
608 lyx::graphics::GCache & gc = lyx::graphics::GCache::get();
615 void PrefDisplay::update(LyXRC const & rc)
617 switch (rc.preview) {
618 case LyXRC::PREVIEW_OFF:
619 instantPreviewCO->setCurrentIndex(0);
621 case LyXRC::PREVIEW_NO_MATH :
622 instantPreviewCO->setCurrentIndex(1);
624 case LyXRC::PREVIEW_ON :
625 instantPreviewCO->setCurrentIndex(2);
630 switch (rc.display_graphics) {
631 case lyx::graphics::NoDisplay: item = 3; break;
632 case lyx::graphics::ColorDisplay: item = 2; break;
633 case lyx::graphics::GrayscaleDisplay: item = 1; break;
634 case lyx::graphics::MonochromeDisplay: item = 0; break;
637 displayGraphicsCO->setCurrentIndex(item);
641 PrefPaths::PrefPaths(QPrefs * form, QWidget * parent)
642 : PrefModule(docstring(), _("Paths"), form, parent)
645 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
646 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
647 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
648 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
649 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
650 connect(workingDirED, SIGNAL(textChanged(const QString&)),
651 this, SIGNAL(changed()));
652 connect(templateDirED, SIGNAL(textChanged(const QString&)),
653 this, SIGNAL(changed()));
654 connect(backupDirED, SIGNAL(textChanged(const QString&)),
655 this, SIGNAL(changed()));
656 connect(tempDirED, SIGNAL(textChanged(const QString&)),
657 this, SIGNAL(changed()));
658 connect(lyxserverDirED, SIGNAL(textChanged(const QString&)),
659 this, SIGNAL(changed()));
660 connect(pathPrefixED, SIGNAL(textChanged(const QString&)),
661 this, SIGNAL(changed()));
665 void PrefPaths::apply(LyXRC & rc) const
667 rc.document_path = internal_path(fromqstr(workingDirED->text()));
668 rc.template_path = internal_path(fromqstr(templateDirED->text()));
669 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
670 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
671 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
672 // FIXME: should be a checkbox only
673 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
677 void PrefPaths::update(LyXRC const & rc)
679 workingDirED->setText(toqstr(external_path(rc.document_path)));
680 templateDirED->setText(toqstr(external_path(rc.template_path)));
681 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
682 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
683 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
684 // FIXME: should be a checkbox only
685 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
689 void PrefPaths::select_templatedir()
691 docstring file(form_->controller().browsedir(
692 from_utf8(internal_path(fromqstr(templateDirED->text()))),
693 _("Select a document templates directory")));
695 templateDirED->setText(toqstr(file));
699 void PrefPaths::select_tempdir()
701 docstring file(form_->controller().browsedir(
702 from_utf8(internal_path(fromqstr(tempDirED->text()))),
703 _("Select a temporary directory")));
705 tempDirED->setText(toqstr(file));
709 void PrefPaths::select_backupdir()
711 docstring file(form_->controller().browsedir(
712 from_utf8(internal_path(fromqstr(backupDirED->text()))),
713 _("Select a backups directory")));
715 backupDirED->setText(toqstr(file));
719 void PrefPaths::select_workingdir()
721 docstring file(form_->controller().browsedir(
722 from_utf8(internal_path(fromqstr(workingDirED->text()))),
723 _("Select a document directory")));
725 workingDirED->setText(toqstr(file));
729 void PrefPaths::select_lyxpipe()
731 docstring file(form_->controller().browse(
732 from_utf8(internal_path(fromqstr(lyxserverDirED->text()))),
733 _("Give a filename for the LyX server pipe")));
735 lyxserverDirED->setText(toqstr(file));
739 PrefSpellchecker::PrefSpellchecker(QPrefs * form, QWidget * parent)
740 : PrefModule(_(LanguageSettings), _("Spellchecker"), form, parent)
744 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
745 #if defined (USE_ISPELL)
746 connect(spellCommandCO, SIGNAL(activated(int)),
747 this, SIGNAL(changed()));
749 spellCommandCO->setEnabled(false);
751 connect(altLanguageED, SIGNAL(textChanged(const QString&)),
752 this, SIGNAL(changed()));
753 connect(escapeCharactersED, SIGNAL(textChanged(const QString&)),
754 this, SIGNAL(changed()));
755 connect(persDictionaryED, SIGNAL(textChanged(const QString&)),
756 this, SIGNAL(changed()));
757 connect(compoundWordCB, SIGNAL(clicked()),
758 this, SIGNAL(changed()));
759 connect(inputEncodingCB, SIGNAL(clicked()),
760 this, SIGNAL(changed()));
762 spellCommandCO->addItem(qt_("ispell"));
763 spellCommandCO->addItem(qt_("aspell"));
764 spellCommandCO->addItem(qt_("hspell"));
766 spellCommandCO->addItem(qt_("pspell (library)"));
769 spellCommandCO->addItem(qt_("aspell (library)"));
775 void PrefSpellchecker::apply(LyXRC & rc) const
777 switch (spellCommandCO->currentIndex()) {
781 rc.use_spell_lib = false;
782 rc.isp_command = fromqstr(spellCommandCO->currentText());
785 rc.use_spell_lib = true;
789 // FIXME: remove isp_use_alt_lang
790 rc.isp_alt_lang = fromqstr(altLanguageED->text());
791 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
792 // FIXME: remove isp_use_esc_chars
793 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
794 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
795 // FIXME: remove isp_use_pers_dict
796 rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
797 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
798 rc.isp_accept_compound = compoundWordCB->isChecked();
799 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
803 void PrefSpellchecker::update(LyXRC const & rc)
805 spellCommandCO->setCurrentIndex(0);
807 if (rc.isp_command == "ispell") {
808 spellCommandCO->setCurrentIndex(0);
809 } else if (rc.isp_command == "aspell") {
810 spellCommandCO->setCurrentIndex(1);
811 } else if (rc.isp_command == "hspell") {
812 spellCommandCO->setCurrentIndex(2);
815 if (rc.use_spell_lib) {
816 #if defined(USE_ASPELL) || defined(USE_PSPELL)
817 spellCommandCO->setCurrentIndex(3);
821 // FIXME: remove isp_use_alt_lang
822 altLanguageED->setText(toqstr(rc.isp_alt_lang));
823 // FIXME: remove isp_use_esc_chars
824 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
825 // FIXME: remove isp_use_pers_dict
826 persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
827 compoundWordCB->setChecked(rc.isp_accept_compound);
828 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
832 void PrefSpellchecker::select_dict()
834 docstring file(form_->controller().browsedict(
835 from_utf8(internal_path(fromqstr(persDictionaryED->text())))));
837 persDictionaryED->setText(toqstr(file));
841 PrefConverters::PrefConverters(QPrefs * form, QWidget * parent)
842 : PrefModule(docstring(), _("Converters"), form, parent)
846 connect(converterNewPB, SIGNAL(clicked()),
847 this, SLOT(update_converter()));
848 connect(converterRemovePB, SIGNAL(clicked()),
849 this, SLOT(remove_converter()));
850 connect(converterModifyPB, SIGNAL(clicked()),
851 this, SLOT(update_converter()));
852 connect(convertersLW, SIGNAL(currentRowChanged(int)),
853 this, SLOT(switch_converter()));
854 connect(converterFromCO, SIGNAL(activated(const QString&)),
855 this, SLOT(converter_changed()));
856 connect(converterToCO, SIGNAL(activated(const QString&)),
857 this, SLOT(converter_changed()));
858 connect(converterED, SIGNAL(textChanged(const QString&)),
859 this, SLOT(converter_changed()));
860 connect(converterFlagED, SIGNAL(textChanged(const QString&)),
861 this, SLOT(converter_changed()));
862 connect(converterNewPB, SIGNAL(clicked()),
863 this, SIGNAL(changed()));
864 connect(converterRemovePB, SIGNAL(clicked()),
865 this, SIGNAL(changed()));
866 connect(converterModifyPB, SIGNAL(clicked()),
867 this, SIGNAL(changed()));
871 void PrefConverters::apply(LyXRC & /*rc*/) const
876 void PrefConverters::update(LyXRC const & /*rc*/)
882 void PrefConverters::updateGui()
884 // save current selection
885 QString current = converterFromCO->currentText()
886 + " -> " + converterToCO->currentText();
888 converterFromCO->clear();
889 converterToCO->clear();
891 Formats::const_iterator cit = form_->formats().begin();
892 Formats::const_iterator end = form_->formats().end();
893 for (; cit != end; ++cit) {
894 converterFromCO->addItem(toqstr(cit->prettyname()));
895 converterToCO->addItem(toqstr(cit->prettyname()));
898 // currentRowChanged(int) is also triggered when updating the listwidget
899 // block signals to avoid unnecessary calls to switch_converter()
900 convertersLW->blockSignals(true);
901 convertersLW->clear();
903 Converters::const_iterator ccit = form_->converters().begin();
904 Converters::const_iterator cend = form_->converters().end();
905 for (; ccit != cend; ++ccit) {
906 std::string const name =
907 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
908 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
909 new QListWidgetItem(toqstr(name), convertersLW, type);
911 convertersLW->sortItems(Qt::AscendingOrder);
912 convertersLW->blockSignals(false);
915 if (!current.isEmpty()) {
916 QList<QListWidgetItem *> const item =
917 convertersLW->findItems(current, Qt::MatchExactly);
919 convertersLW->setCurrentItem(item.at(0));
922 // select first element if restoring failed
923 if (convertersLW->currentRow() == -1)
924 convertersLW->setCurrentRow(0);
930 void PrefConverters::switch_converter()
932 int const cnr = convertersLW->currentItem()->type();
933 Converter const & c(form_->converters().get(cnr));
934 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
935 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
936 converterED->setText(toqstr(c.command));
937 converterFlagED->setText(toqstr(c.flags));
943 void PrefConverters::converter_changed()
949 void PrefConverters::updateButtons()
951 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
952 Format const & to(form_->formats().get(converterToCO->currentIndex()));
953 int const sel = form_->converters().getNumber(from.name(), to.name());
954 bool const known = !(sel < 0);
955 bool const valid = !(converterED->text().isEmpty()
956 || from.name() == to.name());
958 int const cnr = convertersLW->currentItem()->type();
959 Converter const & c(form_->converters().get(cnr));
960 string const old_command = c.command;
961 string const old_flag = c.flags;
962 string const new_command(fromqstr(converterED->text()));
963 string const new_flag(fromqstr(converterFlagED->text()));
965 bool modified = ((old_command != new_command) || (old_flag != new_flag));
967 converterModifyPB->setEnabled(valid && known && modified);
968 converterNewPB->setEnabled(valid && !known);
969 converterRemovePB->setEnabled(known);
974 // specify unique from/to or it doesn't appear. This is really bad UI
975 // this is why we can use the same function for both new and modify
976 void PrefConverters::update_converter()
978 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
979 Format const & to(form_->formats().get(converterToCO->currentIndex()));
980 string const flags = fromqstr(converterFlagED->text());
981 string const command = fromqstr(converterED->text());
983 Converter const * old = form_->converters().getConverter(from.name(), to.name());
984 form_->converters().add(from.name(), to.name(), command, flags);
986 form_->converters().updateLast(form_->formats());
993 void PrefConverters::remove_converter()
995 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
996 Format const & to(form_->formats().get(converterToCO->currentIndex()));
997 form_->converters().erase(from.name(), to.name());
1003 PrefCopiers::PrefCopiers(QPrefs * form, QWidget * parent)
1004 : PrefModule(docstring(), _("Copiers"), form, parent)
1008 connect(copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
1009 connect(copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
1010 connect(copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
1011 connect(AllCopiersLW, SIGNAL(currentRowChanged(int)),
1012 this, SLOT(switch_copierLB(int)));
1013 connect(copierFormatCO, SIGNAL(activated(int)), this, SLOT(switch_copierCO(int)));
1014 connect(copierNewPB, SIGNAL(clicked()),
1015 this, SIGNAL(changed()));
1016 connect(copierRemovePB, SIGNAL(clicked()),
1017 this, SIGNAL(changed()));
1018 connect(copierModifyPB, SIGNAL(clicked()),
1019 this, SIGNAL(changed()));
1020 connect(copierFormatCO, SIGNAL(activated(const QString&)), this, SLOT(copiers_changed()));
1021 connect(copierED, SIGNAL(textChanged(const QString&)), this, SLOT(copiers_changed()));
1025 void PrefCopiers::apply(LyXRC & /*rc*/) const
1030 void PrefCopiers::update(LyXRC const & /*rc*/)
1036 void PrefCopiers::update()
1038 // The choice widget
1039 // save current selection
1040 QString current = copierFormatCO->currentText();
1041 copierFormatCO->clear();
1043 for (Formats::const_iterator it = form_->formats().begin(),
1044 end = form_->formats().end();
1046 copierFormatCO->addItem(toqstr(it->prettyname()));
1049 // The browser widget
1050 AllCopiersLW->clear();
1052 for (Movers::const_iterator it = form_->movers().begin(),
1053 end = form_->movers().end();
1055 std::string const & command = it->second.command();
1056 if (command.empty())
1058 QString const pretty = toqstr(form_->formats().prettyName(it->first));
1059 AllCopiersLW->addItem(pretty);
1061 AllCopiersLW->sortItems(Qt::AscendingOrder);
1063 // restore selection
1064 if (!current.isEmpty()) {
1065 QList<QListWidgetItem *> item =
1066 AllCopiersLW->findItems(current, Qt::MatchExactly);
1068 AllCopiersLW->setCurrentItem(item.at(0));
1070 // select first element if restoring failed
1071 if (AllCopiersLW->currentRow() == -1)
1072 AllCopiersLW->setCurrentRow(0);
1078 class SamePrettyName {
1080 SamePrettyName(string const & n) : pretty_name_(n) {}
1082 bool operator()(lyx::Format const & fmt) const {
1083 return fmt.prettyname() == pretty_name_;
1087 string const pretty_name_;
1091 Format const * getFormat(std::string const & prettyname)
1093 Formats::const_iterator it = lyx::formats.begin();
1094 Formats::const_iterator const end = lyx::formats.end();
1095 it = std::find_if(it, end, SamePrettyName(prettyname));
1096 return it == end ? 0 : &*it;
1102 void PrefCopiers::switch_copierLB(int row)
1108 std::string const browser_text =
1109 fromqstr(AllCopiersLW->currentItem()->text());
1110 Format const * fmt = getFormat(browser_text);
1114 QString const gui_name = toqstr(fmt->prettyname());
1115 QString const command = toqstr(form_->movers().command(fmt->name()));
1118 int const combo_size = copierFormatCO->count();
1119 for (int i = 0; i < combo_size; ++i) {
1120 QString const text = copierFormatCO->itemText(i);
1121 if (text == gui_name) {
1122 copierFormatCO->setCurrentIndex(i);
1123 copierED->setText(command);
1131 void PrefCopiers::switch_copierCO(int row)
1136 std::string const combo_text =
1137 fromqstr(copierFormatCO->currentText());
1138 Format const * fmt = getFormat(combo_text);
1142 QString const command = toqstr(form_->movers().command(fmt->name()));
1143 copierED->setText(command);
1145 QListWidgetItem * const index = AllCopiersLW->currentItem();
1147 AllCopiersLW->setItemSelected(index, false);
1149 QString const gui_name = toqstr(fmt->prettyname());
1150 int const browser_size = AllCopiersLW->count();
1151 for (int i = 0; i < browser_size; ++i) {
1152 QString const text = AllCopiersLW->item(i)->text();
1153 if (text == gui_name) {
1154 QListWidgetItem * item = AllCopiersLW->item(i);
1155 AllCopiersLW->setItemSelected(item, true);
1162 void PrefCopiers::copiers_changed()
1168 void PrefCopiers::updateButtons()
1170 QString selected = copierFormatCO->currentText();
1173 for (int i = 0; i < AllCopiersLW->count(); ++i) {
1174 if (AllCopiersLW->item(i)->text() == selected)
1178 bool const valid = !copierED->text().isEmpty();
1180 Format const * fmt = getFormat(fromqstr(selected));
1181 string const old_command = form_->movers().command(fmt->name());
1182 string const new_command(fromqstr(copierED->text()));
1184 bool modified = (old_command != new_command);
1186 copierModifyPB->setEnabled(valid && known && modified);
1187 copierNewPB->setEnabled(valid && !known);
1188 copierRemovePB->setEnabled(known);
1192 void PrefCopiers::new_copier()
1194 std::string const combo_text =
1195 fromqstr(copierFormatCO->currentText());
1196 Format const * fmt = getFormat(combo_text);
1200 string const command = fromqstr(copierED->text());
1201 if (command.empty())
1204 form_->movers().set(fmt->name(), command);
1207 int const last = AllCopiersLW->count() - 1;
1208 AllCopiersLW->setCurrentRow(last);
1214 void PrefCopiers::modify_copier()
1216 std::string const combo_text =
1217 fromqstr(copierFormatCO->currentText());
1218 Format const * fmt = getFormat(combo_text);
1222 string const command = fromqstr(copierED->text());
1223 form_->movers().set(fmt->name(), command);
1230 void PrefCopiers::remove_copier()
1232 std::string const combo_text =
1233 fromqstr(copierFormatCO->currentText());
1234 Format const * fmt = getFormat(combo_text);
1238 string const & fmt_name = fmt->name();
1239 form_->movers().set(fmt_name, string());
1247 PrefFileformats::PrefFileformats(QPrefs * form, QWidget * parent)
1248 : PrefModule(docstring(), _("File formats"), form, parent)
1252 connect(formatNewPB, SIGNAL(clicked()),
1253 this, SLOT(new_format()));
1254 connect(formatRemovePB, SIGNAL(clicked()),
1255 this, SLOT(remove_format()));
1256 connect(formatModifyPB, SIGNAL(clicked()),
1257 this, SLOT(modify_format()));
1258 connect(formatsLW, SIGNAL(currentRowChanged(int)),
1259 this, SLOT(switch_format(int)));
1260 connect(formatED, SIGNAL(textChanged(const QString&)),
1261 this, SLOT(fileformat_changed()));
1262 connect(guiNameED, SIGNAL(textChanged(const QString&)),
1263 this, SLOT(fileformat_changed()));
1264 connect(shortcutED, SIGNAL(textChanged(const QString&)),
1265 this, SLOT(fileformat_changed()));
1266 connect(extensionED, SIGNAL(textChanged(const QString&)),
1267 this, SLOT(fileformat_changed()));
1268 connect(viewerED, SIGNAL(textChanged(const QString&)),
1269 this, SLOT(fileformat_changed()));
1270 connect(editorED, SIGNAL(textChanged(const QString&)),
1271 this, SLOT(fileformat_changed()));
1272 connect(documentCB, SIGNAL(clicked()),
1273 this, SLOT(fileformat_changed()));
1274 connect(vectorCB, SIGNAL(clicked()),
1275 this, SLOT(fileformat_changed()));
1276 connect(formatNewPB, SIGNAL(clicked()),
1277 this, SIGNAL(changed()));
1278 connect(formatRemovePB, SIGNAL(clicked()),
1279 this, SIGNAL(changed()));
1280 connect(formatModifyPB, SIGNAL(clicked()),
1281 this, SIGNAL(changed()));
1285 void PrefFileformats::apply(LyXRC & /*rc*/) const
1290 void PrefFileformats::update(LyXRC const & /*rc*/)
1296 void PrefFileformats::update()
1298 // save current selection
1299 QString current = guiNameED->text();
1301 // update listwidget with formats
1302 formatsLW->blockSignals(true);
1304 Formats::const_iterator cit = form_->formats().begin();
1305 Formats::const_iterator end = form_->formats().end();
1306 for (; cit != end; ++cit) {
1307 new QListWidgetItem(toqstr(cit->prettyname()),
1309 form_->formats().getNumber(cit->name()) );
1311 formatsLW->sortItems(Qt::AscendingOrder);
1312 formatsLW->blockSignals(false);
1314 // restore selection
1315 if (!current.isEmpty()) {
1316 QList<QListWidgetItem *> item = formatsLW->findItems(current, Qt::MatchExactly);
1318 formatsLW->setCurrentItem(item.at(0));
1320 // select first element if restoring failed
1321 if (formatsLW->currentRow() == -1)
1322 formatsLW->setCurrentRow(0);
1326 void PrefFileformats::switch_format(int nr)
1328 int const ftype = formatsLW->item(nr)->type();
1329 Format const f = form_->formats().get(ftype);
1331 formatED->setText(toqstr(f.name()));
1332 guiNameED->setText(toqstr(f.prettyname()));
1333 extensionED->setText(toqstr(f.extension()));
1334 shortcutED->setText(toqstr(f.shortcut()));
1335 viewerED->setText(toqstr(f.viewer()));
1336 editorED->setText(toqstr(f.editor()));
1337 documentCB->setChecked((f.documentFormat()));
1338 vectorCB->setChecked((f.vectorFormat()));
1344 void PrefFileformats::fileformat_changed()
1350 void PrefFileformats::updateButtons()
1352 QString const format = formatED->text();
1353 QString const gui_name = guiNameED->text();
1354 int const sel = form_->formats().getNumber(fromqstr(format));
1355 bool gui_name_known = false;
1357 for (int i = 0; i < formatsLW->count(); ++i) {
1358 if (formatsLW->item(i)->text() == gui_name) {
1359 gui_name_known = true;
1360 where = formatsLW->item(i)->type();
1364 // assure that a gui name cannot be chosen twice
1365 bool const known_otherwise = gui_name_known && (where != sel);
1367 bool const known = !(sel < 0);
1368 bool const valid = (!formatED->text().isEmpty()
1369 && !guiNameED->text().isEmpty());
1371 int const ftype = formatsLW->currentItem()->type();
1372 Format const & f(form_->formats().get(ftype));
1373 string const old_pretty(f.prettyname());
1374 string const old_shortcut(f.shortcut());
1375 string const old_extension(f.extension());
1376 string const old_viewer(f.viewer());
1377 string const old_editor(f.editor());
1378 bool const old_document(f.documentFormat());
1379 bool const old_vector(f.vectorFormat());
1381 string const new_pretty(fromqstr(gui_name));
1382 string const new_shortcut(fromqstr(shortcutED->text()));
1383 string const new_extension(fromqstr(extensionED->text()));
1384 string const new_viewer(fromqstr(viewerED->text()));
1385 string const new_editor(fromqstr(editorED->text()));
1386 bool const new_document(documentCB->isChecked());
1387 bool const new_vector(vectorCB->isChecked());
1389 bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
1390 || (old_extension != new_extension) || (old_viewer != new_viewer)
1391 || old_editor != new_editor || old_document != new_document
1392 || old_vector != new_vector);
1394 formatModifyPB->setEnabled(valid && known && modified && !known_otherwise);
1395 formatNewPB->setEnabled(valid && !known && !gui_name_known);
1396 formatRemovePB->setEnabled(known);
1400 void PrefFileformats::new_format()
1402 string const name = fromqstr(formatED->text());
1403 string const prettyname = fromqstr(guiNameED->text());
1404 string const extension = fromqstr(extensionED->text());
1405 string const shortcut = fromqstr(shortcutED->text());
1406 string const viewer = fromqstr(viewerED->text());
1407 string const editor = fromqstr(editorED->text());
1408 int flags = Format::none;
1409 if (documentCB->isChecked())
1410 flags |= Format::document;
1411 if (vectorCB->isChecked())
1412 flags |= Format::vector;
1414 form_->formats().add(name, extension, prettyname, shortcut, viewer,
1416 form_->formats().sort();
1417 form_->converters().update(form_->formats());
1425 void PrefFileformats::modify_format()
1427 int const current_item = formatsLW->currentItem()->type();
1428 Format const & oldformat = form_->formats().get(current_item);
1429 form_->formats().erase(oldformat.name());
1435 void PrefFileformats::remove_format()
1437 int const nr = formatsLW->currentItem()->type();
1438 string const current_text = form_->formats().get(nr).name();
1439 if (form_->converters().formatIsUsed(current_text)) {
1440 Alert::error(_("Format in use"),
1441 _("Cannot remove a Format used by a Converter. "
1442 "Remove the converter first."));
1446 form_->formats().erase(current_text);
1447 form_->converters().update(form_->formats());
1456 PrefLanguage::PrefLanguage(QWidget * parent)
1457 : PrefModule(docstring(), _("Language"), 0, parent)
1461 connect(rtlCB, SIGNAL(clicked()),
1462 this, SIGNAL(changed()));
1463 connect(markForeignCB, SIGNAL(clicked()),
1464 this, SIGNAL(changed()));
1465 connect(autoBeginCB, SIGNAL(clicked()),
1466 this, SIGNAL(changed()));
1467 connect(autoEndCB, SIGNAL(clicked()),
1468 this, SIGNAL(changed()));
1469 connect(useBabelCB, SIGNAL(clicked()),
1470 this, SIGNAL(changed()));
1471 connect(globalCB, SIGNAL(clicked()),
1472 this, SIGNAL(changed()));
1473 connect(languagePackageED, SIGNAL(textChanged(const QString&)),
1474 this, SIGNAL(changed()));
1475 connect(startCommandED, SIGNAL(textChanged(const QString&)),
1476 this, SIGNAL(changed()));
1477 connect(endCommandED, SIGNAL(textChanged(const QString&)),
1478 this, SIGNAL(changed()));
1479 connect(defaultLanguageCO, SIGNAL(activated(int)),
1480 this, SIGNAL(changed()));
1482 defaultLanguageCO->clear();
1484 // store the lang identifiers for later
1485 std::vector<LanguagePair> const langs =
1486 lyx::frontend::getLanguageData(false);
1487 lang_ = getSecond(langs);
1489 std::vector<LanguagePair>::const_iterator lit = langs.begin();
1490 std::vector<LanguagePair>::const_iterator lend = langs.end();
1491 for (; lit != lend; ++lit) {
1492 defaultLanguageCO->addItem(toqstr(lit->first));
1497 void PrefLanguage::apply(LyXRC & rc) const
1499 // FIXME: remove rtl_support bool
1500 rc.rtl_support = rtlCB->isChecked();
1501 rc.mark_foreign_language = markForeignCB->isChecked();
1502 rc.language_auto_begin = autoBeginCB->isChecked();
1503 rc.language_auto_end = autoEndCB->isChecked();
1504 rc.language_use_babel = useBabelCB->isChecked();
1505 rc.language_global_options = globalCB->isChecked();
1506 rc.language_package = fromqstr(languagePackageED->text());
1507 rc.language_command_begin = fromqstr(startCommandED->text());
1508 rc.language_command_end = fromqstr(endCommandED->text());
1509 rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1513 void PrefLanguage::update(LyXRC const & rc)
1515 // FIXME: remove rtl_support bool
1516 rtlCB->setChecked(rc.rtl_support);
1517 markForeignCB->setChecked(rc.mark_foreign_language);
1518 autoBeginCB->setChecked(rc.language_auto_begin);
1519 autoEndCB->setChecked(rc.language_auto_end);
1520 useBabelCB->setChecked(rc.language_use_babel);
1521 globalCB->setChecked(rc.language_global_options);
1522 languagePackageED->setText(toqstr(rc.language_package));
1523 startCommandED->setText(toqstr(rc.language_command_begin));
1524 endCommandED->setText(toqstr(rc.language_command_end));
1526 int const pos = int(findPos(lang_, rc.default_language));
1527 defaultLanguageCO->setCurrentIndex(pos);
1531 PrefPrinter::PrefPrinter(QWidget * parent)
1532 : PrefModule(_(Outputs), _("Printer"), 0, parent)
1536 connect(printerAdaptCB, SIGNAL(clicked()),
1537 this, SIGNAL(changed()));
1538 connect(printerCommandED, SIGNAL(textChanged(const QString&)),
1539 this, SIGNAL(changed()));
1540 connect(printerNameED, SIGNAL(textChanged(const QString&)),
1541 this, SIGNAL(changed()));
1542 connect(printerPageRangeED, SIGNAL(textChanged(const QString&)),
1543 this, SIGNAL(changed()));
1544 connect(printerCopiesED, SIGNAL(textChanged(const QString&)),
1545 this, SIGNAL(changed()));
1546 connect(printerReverseED, SIGNAL(textChanged(const QString&)),
1547 this, SIGNAL(changed()));
1548 connect(printerToPrinterED, SIGNAL(textChanged(const QString&)),
1549 this, SIGNAL(changed()));
1550 connect(printerExtensionED, SIGNAL(textChanged(const QString&)),
1551 this, SIGNAL(changed()));
1552 connect(printerSpoolCommandED, SIGNAL(textChanged(const QString&)),
1553 this, SIGNAL(changed()));
1554 connect(printerPaperTypeED, SIGNAL(textChanged(const QString&)),
1555 this, SIGNAL(changed()));
1556 connect(printerEvenED, SIGNAL(textChanged(const QString&)),
1557 this, SIGNAL(changed()));
1558 connect(printerOddED, SIGNAL(textChanged(const QString&)),
1559 this, SIGNAL(changed()));
1560 connect(printerCollatedED, SIGNAL(textChanged(const QString&)),
1561 this, SIGNAL(changed()));
1562 connect(printerLandscapeED, SIGNAL(textChanged(const QString&)),
1563 this, SIGNAL(changed()));
1564 connect(printerToFileED, SIGNAL(textChanged(const QString&)),
1565 this, SIGNAL(changed()));
1566 connect(printerExtraED, SIGNAL(textChanged(const QString&)),
1567 this, SIGNAL(changed()));
1568 connect(printerSpoolPrefixED, SIGNAL(textChanged(const QString&)),
1569 this, SIGNAL(changed()));
1570 connect(printerPaperSizeED, SIGNAL(textChanged(const QString&)),
1571 this, SIGNAL(changed()));
1575 void PrefPrinter::apply(LyXRC & rc) const
1577 rc.print_adapt_output = printerAdaptCB->isChecked();
1578 rc.print_command = fromqstr(printerCommandED->text());
1579 rc.printer = fromqstr(printerNameED->text());
1581 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1582 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1583 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1584 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1585 rc.print_file_extension = fromqstr(printerExtensionED->text());
1586 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1587 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1588 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1589 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1590 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1591 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1592 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1593 rc.print_extra_options = fromqstr(printerExtraED->text());
1594 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1595 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1599 void PrefPrinter::update(LyXRC const & rc)
1601 printerAdaptCB->setChecked(rc.print_adapt_output);
1602 printerCommandED->setText(toqstr(rc.print_command));
1603 printerNameED->setText(toqstr(rc.printer));
1605 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1606 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1607 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1608 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1609 printerExtensionED->setText(toqstr(rc.print_file_extension));
1610 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1611 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1612 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1613 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1614 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1615 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1616 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1617 printerExtraED->setText(toqstr(rc.print_extra_options));
1618 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1619 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1623 PrefUserInterface::PrefUserInterface(QPrefs * form, QWidget * parent)
1624 : PrefModule(_(LookAndFeel), _("User interface"), form, parent)
1628 connect(autoSaveCB, SIGNAL( toggled(bool) ), autoSaveLA, SLOT( setEnabled(bool) ) );
1629 connect(autoSaveCB, SIGNAL( toggled(bool) ), autoSaveSB, SLOT( setEnabled(bool) ) );
1630 connect(autoSaveCB, SIGNAL( toggled(bool) ), TextLabel1, SLOT( setEnabled(bool) ) );
1631 connect(uiFilePB, SIGNAL(clicked()), this, SLOT(select_ui()));
1632 connect(bindFilePB, SIGNAL(clicked()), this, SLOT(select_bind()));
1633 connect(uiFileED, SIGNAL(textChanged(const QString&)),
1634 this, SIGNAL(changed()));
1635 connect(bindFileED, SIGNAL(textChanged(const QString&)),
1636 this, SIGNAL(changed()));
1637 connect(restoreCursorCB, SIGNAL(clicked()),
1638 this, SIGNAL(changed()));
1639 connect(loadSessionCB, SIGNAL(clicked()),
1640 this, SIGNAL(changed()));
1641 connect(loadWindowSizeCB, SIGNAL(clicked()),
1642 this, SIGNAL(changed()));
1643 connect(loadWindowLocationCB, SIGNAL(clicked()),
1644 this, SIGNAL(changed()));
1645 connect(windowWidthSB, SIGNAL(valueChanged(int)),
1646 this, SIGNAL(changed()));
1647 connect(windowHeightSB, SIGNAL(valueChanged(int)),
1648 this, SIGNAL(changed()));
1649 connect(cursorFollowsCB, SIGNAL(clicked()),
1650 this, SIGNAL(changed()));
1651 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1652 this, SIGNAL(changed()));
1653 connect(autoSaveCB, SIGNAL(clicked()),
1654 this, SIGNAL(changed()));
1655 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1656 this, SIGNAL(changed()));
1657 lastfilesSB->setMaximum(maxlastfiles);
1661 void PrefUserInterface::apply(LyXRC & rc) const
1663 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1664 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1665 rc.use_lastfilepos = restoreCursorCB->isChecked();
1666 rc.load_session = loadSessionCB->isChecked();
1667 if (loadWindowSizeCB->isChecked()) {
1668 rc.geometry_width = 0;
1669 rc.geometry_height = 0;
1671 rc.geometry_width = windowWidthSB->value();
1672 rc.geometry_height = windowHeightSB->value();
1674 rc.geometry_xysaved = loadWindowLocationCB->isChecked();
1675 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1676 rc.autosave = autoSaveSB->value() * 60;
1677 rc.make_backup = autoSaveCB->isChecked();
1678 rc.num_lastfiles = lastfilesSB->value();
1682 void PrefUserInterface::update(LyXRC const & rc)
1684 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1685 bindFileED->setText(toqstr(external_path(rc.bind_file)));
1686 restoreCursorCB->setChecked(rc.use_lastfilepos);
1687 loadSessionCB->setChecked(rc.load_session);
1688 bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
1689 loadWindowSizeCB->setChecked(loadWindowSize);
1690 if (!loadWindowSize) {
1691 windowWidthSB->setValue(rc.geometry_width);
1692 windowHeightSB->setValue(rc.geometry_height);
1694 loadWindowLocationCB->setChecked(rc.geometry_xysaved);
1695 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1696 // convert to minutes
1697 int mins(rc.autosave / 60);
1698 if (rc.autosave && !mins)
1700 autoSaveSB->setValue(mins);
1701 autoSaveCB->setChecked(rc.make_backup);
1702 lastfilesSB->setValue(rc.num_lastfiles);
1707 void PrefUserInterface::select_ui()
1709 docstring const name =
1710 from_utf8(internal_path(fromqstr(uiFileED->text())));
1711 docstring file(form_->controller().browseUI(name));
1713 uiFileED->setText(toqstr(file));
1717 void PrefUserInterface::select_bind()
1719 docstring const name =
1720 from_utf8(internal_path(fromqstr(bindFileED->text())));
1721 docstring file(form_->controller().browsebind(name));
1723 bindFileED->setText(toqstr(file));
1727 void PrefUserInterface::on_loadWindowSizeCB_toggled(bool loadwindowsize)
1729 windowWidthLA->setDisabled(loadwindowsize);
1730 windowHeightLA->setDisabled(loadwindowsize);
1731 windowWidthSB->setDisabled(loadwindowsize);
1732 windowHeightSB->setDisabled(loadwindowsize);
1736 PrefIdentity::PrefIdentity(QWidget * parent)
1737 : PrefModule(docstring(), _("Identity"), 0, parent)
1741 connect(nameED, SIGNAL(textChanged(const QString&)),
1742 this, SIGNAL(changed()));
1743 connect(emailED, SIGNAL(textChanged(const QString&)),
1744 this, SIGNAL(changed()));
1748 void PrefIdentity::apply(LyXRC & rc) const
1750 rc.user_name = fromqstr(nameED->text());
1751 rc.user_email = fromqstr(emailED->text());
1755 void PrefIdentity::update(LyXRC const & rc)
1757 nameED->setText(toqstr(rc.user_name));
1758 emailED->setText(toqstr(rc.user_email));
1763 QPrefsDialog::QPrefsDialog(QPrefs * form)
1767 QDialog::setModal(false);
1769 connect(savePB, SIGNAL(clicked()),
1770 form, SLOT(slotOK()));
1771 connect(applyPB, SIGNAL(clicked()),
1772 form, SLOT(slotApply()));
1773 connect(closePB, SIGNAL(clicked()),
1774 form, SLOT(slotClose()));
1775 connect(restorePB, SIGNAL(clicked()),
1776 form, SLOT(slotRestore()));
1778 add(new PrefPlaintext);
1780 add(new PrefKeyboard(form_));
1781 add(new PrefLatex(form_));
1782 add(new PrefScreenFonts(form_));
1783 add(new PrefColors(form_));
1785 #if defined(__CYGWIN__) || defined(_WIN32)
1786 add(new PrefCygwinPath);
1789 add(new PrefDisplay);
1790 add(new PrefPaths(form_));
1791 add(new PrefSpellchecker(form_));
1793 PrefConverters * converters = new PrefConverters(form_);
1794 PrefFileformats * formats = new PrefFileformats(form_);
1795 connect(formats, SIGNAL(formatsChanged()),
1796 converters, SLOT(updateGui()));
1800 add(new PrefCopiers(form_));
1802 add(new PrefLanguage);
1803 add(new PrefPrinter);
1804 add(new PrefUserInterface(form_));
1805 add(new PrefIdentity);
1807 prefsPS->setCurrentPanel(_("User interface"));
1808 // FIXME: hack to work around resizing bug in Qt >= 4.2
1809 // bug verified with Qt 4.2.{0-2} (JSpitzm)
1810 #if QT_VERSION >= 0x040200
1811 prefsPS->updateGeometry();
1814 form_->bcview().setOK(savePB);
1815 form_->bcview().setApply(applyPB);
1816 form_->bcview().setCancel(closePB);
1817 form_->bcview().setRestore(restorePB);
1821 QPrefsDialog::~QPrefsDialog()
1826 void QPrefsDialog::add(PrefModule * module)
1828 BOOST_ASSERT(module);
1830 // if (module->category().empty())
1831 // prefsPS->addPanel(module, module->title());
1833 prefsPS->addPanel(module, module->title(), module->category());
1835 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
1837 modules_.push_back(module);
1840 void QPrefsDialog::closeEvent(QCloseEvent * e)
1842 form_->slotWMHide();
1847 void QPrefsDialog::change_adaptor()
1853 void QPrefsDialog::apply(LyXRC & rc) const
1855 size_t end = modules_.size();
1856 for (size_t i = 0; i != end; ++i)
1857 modules_[i]->apply(rc);
1861 void QPrefsDialog::updateRc(LyXRC const & rc)
1863 size_t end = modules_.size();
1864 for (size_t i = 0; i != end; ++i)
1865 modules_[i]->update(rc);
1869 } // namespace frontend
1872 #include "QPrefsDialog_moc.cpp"