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_helper(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();
237 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
238 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
242 void PrefKeyboard::update(LyXRC const & rc)
244 // FIXME: can derive CB from the two EDs
245 keymapCB->setChecked(rc.use_kbmap);
246 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
247 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
251 QString PrefKeyboard::testKeymap(QString keymap)
253 return toqstr(form_->controller().browsekbmap(from_utf8(internal_path(fromqstr(keymap)))));
257 void PrefKeyboard::on_firstKeymapPB_clicked(bool)
259 QString const file = testKeymap(firstKeymapED->text());
261 firstKeymapED->setText(file);
265 void PrefKeyboard::on_secondKeymapPB_clicked(bool)
267 QString const file = testKeymap(secondKeymapED->text());
269 secondKeymapED->setText(file);
273 void PrefKeyboard::on_keymapCB_toggled(bool keymap)
275 firstKeymapLA->setEnabled(keymap);
276 secondKeymapLA->setEnabled(keymap);
277 firstKeymapED->setEnabled(keymap);
278 secondKeymapED->setEnabled(keymap);
279 firstKeymapPB->setEnabled(keymap);
280 secondKeymapPB->setEnabled(keymap);
284 PrefLatex::PrefLatex(QPrefs * form, QWidget * parent)
285 : PrefModule(_(Outputs), _("LaTeX"), form, parent)
288 connect(latexEncodingED, SIGNAL(textChanged(const QString&)),
289 this, SIGNAL(changed()));
290 connect(latexChecktexED, SIGNAL(textChanged(const QString&)),
291 this, SIGNAL(changed()));
292 connect(latexBibtexED, SIGNAL(textChanged(const QString&)),
293 this, SIGNAL(changed()));
294 connect(latexIndexED, SIGNAL(textChanged(const QString&)),
295 this, SIGNAL(changed()));
296 connect(latexAutoresetCB, SIGNAL(clicked()),
297 this, SIGNAL(changed()));
298 connect(latexDviPaperED, SIGNAL(textChanged(const QString&)),
299 this, SIGNAL(changed()));
300 connect(latexPaperSizeCO, SIGNAL(activated(int)),
301 this, SIGNAL(changed()));
305 void PrefLatex::apply(LyXRC & rc) const
307 rc.fontenc = fromqstr(latexEncodingED->text());
308 rc.chktex_command = fromqstr(latexChecktexED->text());
309 rc.bibtex_command = fromqstr(latexBibtexED->text());
310 rc.index_command = fromqstr(latexIndexED->text());
311 rc.auto_reset_options = latexAutoresetCB->isChecked();
312 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
313 rc.default_papersize =
314 form_->controller().toPaperSize(latexPaperSizeCO->currentIndex());
318 void PrefLatex::update(LyXRC const & rc)
320 latexEncodingED->setText(toqstr(rc.fontenc));
321 latexChecktexED->setText(toqstr(rc.chktex_command));
322 latexBibtexED->setText(toqstr(rc.bibtex_command));
323 latexIndexED->setText(toqstr(rc.index_command));
324 latexAutoresetCB->setChecked(rc.auto_reset_options);
325 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
326 latexPaperSizeCO->setCurrentIndex(
327 form_->controller().fromPaperSize(rc.default_papersize));
331 PrefScreenFonts::PrefScreenFonts(QPrefs * form, QWidget * parent)
332 : PrefModule(_(LookAndFeel), _("Screen fonts"), form, parent)
336 connect(screenRomanCO, SIGNAL(activated(const QString&)),
337 this, SLOT(select_roman(const QString&)));
338 connect(screenSansCO, SIGNAL(activated(const QString&)),
339 this, SLOT(select_sans(const QString&)));
340 connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
341 this, SLOT(select_typewriter(const QString&)));
343 QFontDatabase fontdb;
344 QStringList families(fontdb.families());
345 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
346 screenRomanCO->addItem(*it);
347 screenSansCO->addItem(*it);
348 screenTypewriterCO->addItem(*it);
350 connect(screenRomanCO, SIGNAL(activated(const QString&)),
351 this, SIGNAL(changed()));
352 connect(screenSansCO, SIGNAL(activated(const QString&)),
353 this, SIGNAL(changed()));
354 connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
355 this, SIGNAL(changed()));
356 connect(screenZoomSB, SIGNAL(valueChanged(int)),
357 this, SIGNAL(changed()));
358 connect(screenDpiSB, SIGNAL(valueChanged(int)),
359 this, SIGNAL(changed()));
360 connect(screenTinyED, SIGNAL(textChanged(const QString&)),
361 this, SIGNAL(changed()));
362 connect(screenSmallestED, SIGNAL(textChanged(const QString&)),
363 this, SIGNAL(changed()));
364 connect(screenSmallerED, SIGNAL(textChanged(const QString&)),
365 this, SIGNAL(changed()));
366 connect(screenSmallED, SIGNAL(textChanged(const QString&)),
367 this, SIGNAL(changed()));
368 connect(screenNormalED, SIGNAL(textChanged(const QString&)),
369 this, SIGNAL(changed()));
370 connect(screenLargeED, SIGNAL(textChanged(const QString&)),
371 this, SIGNAL(changed()));
372 connect(screenLargerED, SIGNAL(textChanged(const QString&)),
373 this, SIGNAL(changed()));
374 connect(screenLargestED, SIGNAL(textChanged(const QString&)),
375 this, SIGNAL(changed()));
376 connect(screenHugeED, SIGNAL(textChanged(const QString&)),
377 this, SIGNAL(changed()));
378 connect(screenHugerED, SIGNAL(textChanged(const QString&)),
379 this, SIGNAL(changed()));
381 screenTinyED->setValidator(new QDoubleValidator(
383 screenSmallestED->setValidator(new QDoubleValidator(
385 screenSmallerED->setValidator(new QDoubleValidator(
387 screenSmallED->setValidator(new QDoubleValidator(
389 screenNormalED->setValidator(new QDoubleValidator(
391 screenLargeED->setValidator(new QDoubleValidator(
393 screenLargerED->setValidator(new QDoubleValidator(
395 screenLargestED->setValidator(new QDoubleValidator(
397 screenHugeED->setValidator(new QDoubleValidator(
399 screenHugerED->setValidator(new QDoubleValidator(
404 void PrefScreenFonts::apply(LyXRC & rc) const
406 LyXRC const oldrc(rc);
408 boost::tie(rc.roman_font_name, rc.roman_font_foundry)
409 = parseFontName(fromqstr(screenRomanCO->currentText()));
410 boost::tie(rc.sans_font_name, rc.sans_font_foundry) =
411 parseFontName(fromqstr(screenSansCO->currentText()));
412 boost::tie(rc.typewriter_font_name, rc.typewriter_font_foundry) =
413 parseFontName(fromqstr(screenTypewriterCO->currentText()));
415 rc.zoom = screenZoomSB->value();
416 rc.dpi = screenDpiSB->value();
417 rc.font_sizes[LyXFont::SIZE_TINY] = fromqstr(screenTinyED->text());
418 rc.font_sizes[LyXFont::SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
419 rc.font_sizes[LyXFont::SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
420 rc.font_sizes[LyXFont::SIZE_SMALL] = fromqstr(screenSmallED->text());
421 rc.font_sizes[LyXFont::SIZE_NORMAL] = fromqstr(screenNormalED->text());
422 rc.font_sizes[LyXFont::SIZE_LARGE] = fromqstr(screenLargeED->text());
423 rc.font_sizes[LyXFont::SIZE_LARGER] = fromqstr(screenLargerED->text());
424 rc.font_sizes[LyXFont::SIZE_LARGEST] = fromqstr(screenLargestED->text());
425 rc.font_sizes[LyXFont::SIZE_HUGE] = fromqstr(screenHugeED->text());
426 rc.font_sizes[LyXFont::SIZE_HUGER] = fromqstr(screenHugerED->text());
428 if (rc.font_sizes != oldrc.font_sizes
429 || rc.roman_font_name != oldrc.roman_font_name
430 || rc.sans_font_name != oldrc.sans_font_name
431 || rc.typewriter_font_name != oldrc.typewriter_font_name
432 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
433 form_->controller().updateScreenFonts();
438 void PrefScreenFonts::update(LyXRC const & rc)
440 setComboxFont(screenRomanCO, rc.roman_font_name,
441 rc.roman_font_foundry);
442 setComboxFont(screenSansCO, rc.sans_font_name,
443 rc.sans_font_foundry);
444 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
445 rc.typewriter_font_foundry);
447 select_roman(screenRomanCO->currentText());
448 select_sans(screenSansCO->currentText());
449 select_typewriter(screenTypewriterCO->currentText());
451 screenZoomSB->setValue(rc.zoom);
452 screenDpiSB->setValue(rc.dpi);
453 screenTinyED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_TINY]));
454 screenSmallestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SCRIPT]));
455 screenSmallerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_FOOTNOTE]));
456 screenSmallED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SMALL]));
457 screenNormalED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_NORMAL]));
458 screenLargeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGE]));
459 screenLargerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGER]));
460 screenLargestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGEST]));
461 screenHugeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_HUGE]));
462 screenHugerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_HUGER]));
465 void PrefScreenFonts::select_roman(const QString& name)
467 screenRomanFE->set(QFont(name), name);
471 void PrefScreenFonts::select_sans(const QString& name)
473 screenSansFE->set(QFont(name), name);
477 void PrefScreenFonts::select_typewriter(const QString& name)
479 screenTypewriterFE->set(QFont(name), name);
483 PrefColors::PrefColors(QPrefs * form, QWidget * parent)
484 : PrefModule(_(LookAndFeel), _("Colors"), form, parent)
488 // FIXME: put in controller
489 for (int i = 0; i < LColor::ignore; ++i) {
490 LColor::color lc = static_cast<LColor::color>(i);
491 if (lc == LColor::none
492 || lc == LColor::black
493 || lc == LColor::white
495 || lc == LColor::green
496 || lc == LColor::blue
497 || lc == LColor::cyan
498 || lc == LColor::magenta
499 || lc == LColor::yellow
500 || lc == LColor::inherit
501 || lc == LColor::ignore) continue;
503 lcolors_.push_back(lc);
504 QColor color = QColor(guiApp->colorCache().get(lc));
505 prefcolors_.push_back(color.name());
506 QPixmap coloritem(32, 32);
507 coloritem.fill(color);
508 // This is not a memory leak:
509 /*QListWidgetItem * newItem =*/ new QListWidgetItem(QIcon(coloritem),
510 toqstr(lcolor.getGUIName(lc)), lyxObjectsLW);
512 newcolors_ = prefcolors_;
514 connect(colorChangePB, SIGNAL(clicked()),
515 this, SLOT(change_color()));
516 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
517 this, SLOT(change_color()));
521 void PrefColors::apply(LyXRC & /*rc*/) const
523 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
524 if (prefcolors_[i]!=newcolors_[i])
525 form_->controller().setColor(lcolors_[i], fromqstr(newcolors_[i]));
530 void PrefColors::update(LyXRC const & /*rc*/)
534 void PrefColors::change_color()
536 int const row = lyxObjectsLW->currentRow();
537 QString color = newcolors_[row];
538 QColor c(QColorDialog::getColor(QColor(color),
539 qApp->focusWidget()));
541 if (c.name()!=color) {
542 newcolors_[row] = c.name();
543 QPixmap coloritem(32, 32);
545 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
552 PrefCygwinPath::PrefCygwinPath(QWidget * parent)
553 : PrefModule(_(Outputs), _("Paths"), 0, parent)
556 connect(pathCB, SIGNAL(clicked()),
557 this, SIGNAL(changed()));
561 void PrefCygwinPath::apply(LyXRC & rc) const
563 rc.windows_style_tex_paths = pathCB->isChecked();
567 void PrefCygwinPath::update(LyXRC const & rc)
569 pathCB->setChecked(rc.windows_style_tex_paths);
573 PrefDisplay::PrefDisplay(QWidget * parent)
574 : PrefModule(_(LookAndFeel), _("Graphics"), 0, parent)
577 connect(instantPreviewCO, SIGNAL(activated(int)),
578 this, SIGNAL(changed()));
579 connect(displayGraphicsCO, SIGNAL(activated(int)),
580 this, SIGNAL(changed()));
584 void PrefDisplay::apply(LyXRC & rc) const
586 switch (instantPreviewCO->currentIndex()) {
587 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
588 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
589 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
592 lyx::graphics::DisplayType dtype;
593 switch (displayGraphicsCO->currentIndex()) {
594 case 3: dtype = lyx::graphics::NoDisplay; break;
595 case 2: dtype = lyx::graphics::ColorDisplay; break;
596 case 1: dtype = lyx::graphics::GrayscaleDisplay; break;
597 case 0: dtype = lyx::graphics::MonochromeDisplay; break;
598 default: dtype = lyx::graphics::GrayscaleDisplay;
600 rc.display_graphics = dtype;
603 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
606 if (old_value != rc.display_graphics) {
607 lyx::graphics::GCache & gc = lyx::graphics::GCache::get();
614 void PrefDisplay::update(LyXRC const & rc)
616 switch (rc.preview) {
617 case LyXRC::PREVIEW_OFF:
618 instantPreviewCO->setCurrentIndex(0);
620 case LyXRC::PREVIEW_NO_MATH :
621 instantPreviewCO->setCurrentIndex(1);
623 case LyXRC::PREVIEW_ON :
624 instantPreviewCO->setCurrentIndex(2);
629 switch (rc.display_graphics) {
630 case lyx::graphics::NoDisplay: item = 3; break;
631 case lyx::graphics::ColorDisplay: item = 2; break;
632 case lyx::graphics::GrayscaleDisplay: item = 1; break;
633 case lyx::graphics::MonochromeDisplay: item = 0; break;
636 displayGraphicsCO->setCurrentIndex(item);
640 PrefPaths::PrefPaths(QPrefs * form, QWidget * parent)
641 : PrefModule(docstring(), _("Paths"), form, parent)
644 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
645 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
646 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
647 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
648 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
649 connect(workingDirED, SIGNAL(textChanged(const QString&)),
650 this, SIGNAL(changed()));
651 connect(templateDirED, SIGNAL(textChanged(const QString&)),
652 this, SIGNAL(changed()));
653 connect(backupDirED, SIGNAL(textChanged(const QString&)),
654 this, SIGNAL(changed()));
655 connect(tempDirED, SIGNAL(textChanged(const QString&)),
656 this, SIGNAL(changed()));
657 connect(lyxserverDirED, SIGNAL(textChanged(const QString&)),
658 this, SIGNAL(changed()));
659 connect(pathPrefixED, SIGNAL(textChanged(const QString&)),
660 this, SIGNAL(changed()));
664 void PrefPaths::apply(LyXRC & rc) const
666 rc.document_path = internal_path(fromqstr(workingDirED->text()));
667 rc.template_path = internal_path(fromqstr(templateDirED->text()));
668 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
669 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
670 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
671 // FIXME: should be a checkbox only
672 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
676 void PrefPaths::update(LyXRC const & rc)
678 workingDirED->setText(toqstr(external_path(rc.document_path)));
679 templateDirED->setText(toqstr(external_path(rc.template_path)));
680 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
681 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
682 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
683 // FIXME: should be a checkbox only
684 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
688 void PrefPaths::select_templatedir()
690 docstring file(form_->controller().browsedir(
691 from_utf8(internal_path(fromqstr(templateDirED->text()))),
692 _("Select a document templates directory")));
694 templateDirED->setText(toqstr(file));
698 void PrefPaths::select_tempdir()
700 docstring file(form_->controller().browsedir(
701 from_utf8(internal_path(fromqstr(tempDirED->text()))),
702 _("Select a temporary directory")));
704 tempDirED->setText(toqstr(file));
708 void PrefPaths::select_backupdir()
710 docstring file(form_->controller().browsedir(
711 from_utf8(internal_path(fromqstr(backupDirED->text()))),
712 _("Select a backups directory")));
714 backupDirED->setText(toqstr(file));
718 void PrefPaths::select_workingdir()
720 docstring file(form_->controller().browsedir(
721 from_utf8(internal_path(fromqstr(workingDirED->text()))),
722 _("Select a document directory")));
724 workingDirED->setText(toqstr(file));
728 void PrefPaths::select_lyxpipe()
730 docstring file(form_->controller().browse(
731 from_utf8(internal_path(fromqstr(lyxserverDirED->text()))),
732 _("Give a filename for the LyX server pipe")));
734 lyxserverDirED->setText(toqstr(file));
738 PrefSpellchecker::PrefSpellchecker(QPrefs * form, QWidget * parent)
739 : PrefModule(_(LanguageSettings), _("Spellchecker"), form, parent)
743 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
744 #if defined (USE_ISPELL)
745 connect(spellCommandCO, SIGNAL(activated(int)),
746 this, SIGNAL(changed()));
748 spellCommandCO->setEnabled(false);
750 connect(altLanguageED, SIGNAL(textChanged(const QString&)),
751 this, SIGNAL(changed()));
752 connect(escapeCharactersED, SIGNAL(textChanged(const QString&)),
753 this, SIGNAL(changed()));
754 connect(persDictionaryED, SIGNAL(textChanged(const QString&)),
755 this, SIGNAL(changed()));
756 connect(compoundWordCB, SIGNAL(clicked()),
757 this, SIGNAL(changed()));
758 connect(inputEncodingCB, SIGNAL(clicked()),
759 this, SIGNAL(changed()));
761 spellCommandCO->addItem(qt_("ispell"));
762 spellCommandCO->addItem(qt_("aspell"));
763 spellCommandCO->addItem(qt_("hspell"));
765 spellCommandCO->addItem(qt_("pspell (library)"));
768 spellCommandCO->addItem(qt_("aspell (library)"));
774 void PrefSpellchecker::apply(LyXRC & rc) const
776 switch (spellCommandCO->currentIndex()) {
780 rc.use_spell_lib = false;
781 rc.isp_command = fromqstr(spellCommandCO->currentText());
784 rc.use_spell_lib = true;
788 // FIXME: remove isp_use_alt_lang
789 rc.isp_alt_lang = fromqstr(altLanguageED->text());
790 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
791 // FIXME: remove isp_use_esc_chars
792 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
793 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
794 // FIXME: remove isp_use_pers_dict
795 rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
796 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
797 rc.isp_accept_compound = compoundWordCB->isChecked();
798 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
802 void PrefSpellchecker::update(LyXRC const & rc)
804 spellCommandCO->setCurrentIndex(0);
806 if (rc.isp_command == "ispell") {
807 spellCommandCO->setCurrentIndex(0);
808 } else if (rc.isp_command == "aspell") {
809 spellCommandCO->setCurrentIndex(1);
810 } else if (rc.isp_command == "hspell") {
811 spellCommandCO->setCurrentIndex(2);
814 if (rc.use_spell_lib) {
815 #if defined(USE_ASPELL) || defined(USE_PSPELL)
816 spellCommandCO->setCurrentIndex(3);
820 // FIXME: remove isp_use_alt_lang
821 altLanguageED->setText(toqstr(rc.isp_alt_lang));
822 // FIXME: remove isp_use_esc_chars
823 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
824 // FIXME: remove isp_use_pers_dict
825 persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
826 compoundWordCB->setChecked(rc.isp_accept_compound);
827 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
831 void PrefSpellchecker::select_dict()
833 docstring file(form_->controller().browsedict(
834 from_utf8(internal_path(fromqstr(persDictionaryED->text())))));
836 persDictionaryED->setText(toqstr(file));
840 PrefConverters::PrefConverters(QPrefs * form, QWidget * parent)
841 : PrefModule(docstring(), _("Converters"), form, parent)
845 connect(converterNewPB, SIGNAL(clicked()),
846 this, SLOT(update_converter()));
847 connect(converterRemovePB, SIGNAL(clicked()),
848 this, SLOT(remove_converter()));
849 connect(converterModifyPB, SIGNAL(clicked()),
850 this, SLOT(update_converter()));
851 connect(convertersLW, SIGNAL(currentRowChanged(int)),
852 this, SLOT(switch_converter()));
853 connect(converterFromCO, SIGNAL(activated(const QString&)),
854 this, SLOT(converter_changed()));
855 connect(converterToCO, SIGNAL(activated(const QString&)),
856 this, SLOT(converter_changed()));
857 connect(converterED, SIGNAL(textChanged(const QString&)),
858 this, SLOT(converter_changed()));
859 connect(converterFlagED, SIGNAL(textChanged(const QString&)),
860 this, SLOT(converter_changed()));
861 connect(converterNewPB, SIGNAL(clicked()),
862 this, SIGNAL(changed()));
863 connect(converterRemovePB, SIGNAL(clicked()),
864 this, SIGNAL(changed()));
865 connect(converterModifyPB, SIGNAL(clicked()),
866 this, SIGNAL(changed()));
870 void PrefConverters::apply(LyXRC & /*rc*/) const
875 void PrefConverters::update(LyXRC const & /*rc*/)
881 void PrefConverters::updateGui()
883 // save current selection
884 QString current = converterFromCO->currentText()
885 + " -> " + converterToCO->currentText();
887 converterFromCO->clear();
888 converterToCO->clear();
890 Formats::const_iterator cit = form_->formats().begin();
891 Formats::const_iterator end = form_->formats().end();
892 for (; cit != end; ++cit) {
893 converterFromCO->addItem(toqstr(cit->prettyname()));
894 converterToCO->addItem(toqstr(cit->prettyname()));
897 // currentRowChanged(int) is also triggered when updating the listwidget
898 // block signals to avoid unnecessary calls to switch_converter()
899 convertersLW->blockSignals(true);
900 convertersLW->clear();
902 Converters::const_iterator ccit = form_->converters().begin();
903 Converters::const_iterator cend = form_->converters().end();
904 for (; ccit != cend; ++ccit) {
905 std::string const name =
906 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
907 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
908 new QListWidgetItem(toqstr(name), convertersLW, type);
910 convertersLW->sortItems(Qt::AscendingOrder);
911 convertersLW->blockSignals(false);
914 if (!current.isEmpty()) {
915 QList<QListWidgetItem *> const item =
916 convertersLW->findItems(current, Qt::MatchExactly);
918 convertersLW->setCurrentItem(item.at(0));
921 // select first element if restoring failed
922 if (convertersLW->currentRow() == -1)
923 convertersLW->setCurrentRow(0);
929 void PrefConverters::switch_converter()
931 int const cnr = convertersLW->currentItem()->type();
932 Converter const & c(form_->converters().get(cnr));
933 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
934 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
935 converterED->setText(toqstr(c.command));
936 converterFlagED->setText(toqstr(c.flags));
942 void PrefConverters::converter_changed()
948 void PrefConverters::updateButtons()
950 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
951 Format const & to(form_->formats().get(converterToCO->currentIndex()));
952 int const sel = form_->converters().getNumber(from.name(), to.name());
953 bool const known = !(sel < 0);
954 bool const valid = !(converterED->text().isEmpty()
955 || from.name() == to.name());
957 int const cnr = convertersLW->currentItem()->type();
958 Converter const & c(form_->converters().get(cnr));
959 string const old_command = c.command;
960 string const old_flag = c.flags;
961 string const new_command(fromqstr(converterED->text()));
962 string const new_flag(fromqstr(converterFlagED->text()));
964 bool modified = ((old_command != new_command) || (old_flag != new_flag));
966 converterModifyPB->setEnabled(valid && known && modified);
967 converterNewPB->setEnabled(valid && !known);
968 converterRemovePB->setEnabled(known);
973 // specify unique from/to or it doesn't appear. This is really bad UI
974 // this is why we can use the same function for both new and modify
975 void PrefConverters::update_converter()
977 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
978 Format const & to(form_->formats().get(converterToCO->currentIndex()));
979 string const flags = fromqstr(converterFlagED->text());
980 string const command = fromqstr(converterED->text());
982 Converter const * old = form_->converters().getConverter(from.name(), to.name());
983 form_->converters().add(from.name(), to.name(), command, flags);
985 form_->converters().updateLast(form_->formats());
992 void PrefConverters::remove_converter()
994 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
995 Format const & to(form_->formats().get(converterToCO->currentIndex()));
996 form_->converters().erase(from.name(), to.name());
1002 PrefCopiers::PrefCopiers(QPrefs * form, QWidget * parent)
1003 : PrefModule(docstring(), _("Copiers"), form, parent)
1007 connect(copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
1008 connect(copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
1009 connect(copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
1010 connect(AllCopiersLW, SIGNAL(currentRowChanged(int)),
1011 this, SLOT(switch_copierLB(int)));
1012 connect(copierFormatCO, SIGNAL(activated(int)), this, SLOT(switch_copierCO(int)));
1013 connect(copierNewPB, SIGNAL(clicked()),
1014 this, SIGNAL(changed()));
1015 connect(copierRemovePB, SIGNAL(clicked()),
1016 this, SIGNAL(changed()));
1017 connect(copierModifyPB, SIGNAL(clicked()),
1018 this, SIGNAL(changed()));
1019 connect(copierFormatCO, SIGNAL(activated(const QString&)), this, SLOT(copiers_changed()));
1020 connect(copierED, SIGNAL(textChanged(const QString&)), this, SLOT(copiers_changed()));
1024 void PrefCopiers::apply(LyXRC & /*rc*/) const
1029 void PrefCopiers::update(LyXRC const & /*rc*/)
1035 void PrefCopiers::update()
1037 // The choice widget
1038 // save current selection
1039 QString current = copierFormatCO->currentText();
1040 copierFormatCO->clear();
1042 for (Formats::const_iterator it = form_->formats().begin(),
1043 end = form_->formats().end();
1045 copierFormatCO->addItem(toqstr(it->prettyname()));
1048 // The browser widget
1049 AllCopiersLW->clear();
1051 for (Movers::const_iterator it = form_->movers().begin(),
1052 end = form_->movers().end();
1054 std::string const & command = it->second.command();
1055 if (command.empty())
1057 QString const pretty = toqstr(form_->formats().prettyName(it->first));
1058 AllCopiersLW->addItem(pretty);
1060 AllCopiersLW->sortItems(Qt::AscendingOrder);
1062 // restore selection
1063 if (!current.isEmpty()) {
1064 QList<QListWidgetItem *> item =
1065 AllCopiersLW->findItems(current, Qt::MatchExactly);
1067 AllCopiersLW->setCurrentItem(item.at(0));
1069 // select first element if restoring failed
1070 if (AllCopiersLW->currentRow() == -1)
1071 AllCopiersLW->setCurrentRow(0);
1077 class SamePrettyName {
1079 SamePrettyName(string const & n) : pretty_name_(n) {}
1081 bool operator()(lyx::Format const & fmt) const {
1082 return fmt.prettyname() == pretty_name_;
1086 string const pretty_name_;
1090 Format const * getFormat(std::string const & prettyname)
1092 Formats::const_iterator it = lyx::formats.begin();
1093 Formats::const_iterator const end = lyx::formats.end();
1094 it = std::find_if(it, end, SamePrettyName(prettyname));
1095 return it == end ? 0 : &*it;
1101 void PrefCopiers::switch_copierLB(int row)
1107 std::string const browser_text =
1108 fromqstr(AllCopiersLW->currentItem()->text());
1109 Format const * fmt = getFormat(browser_text);
1113 QString const gui_name = toqstr(fmt->prettyname());
1114 QString const command = toqstr(form_->movers().command(fmt->name()));
1117 int const combo_size = copierFormatCO->count();
1118 for (int i = 0; i < combo_size; ++i) {
1119 QString const text = copierFormatCO->itemText(i);
1120 if (text == gui_name) {
1121 copierFormatCO->setCurrentIndex(i);
1122 copierED->setText(command);
1130 void PrefCopiers::switch_copierCO(int row)
1135 std::string const combo_text =
1136 fromqstr(copierFormatCO->currentText());
1137 Format const * fmt = getFormat(combo_text);
1141 QString const command = toqstr(form_->movers().command(fmt->name()));
1142 copierED->setText(command);
1144 QListWidgetItem * const index = AllCopiersLW->currentItem();
1146 AllCopiersLW->setItemSelected(index, false);
1148 QString const gui_name = toqstr(fmt->prettyname());
1149 int const browser_size = AllCopiersLW->count();
1150 for (int i = 0; i < browser_size; ++i) {
1151 QString const text = AllCopiersLW->item(i)->text();
1152 if (text == gui_name) {
1153 QListWidgetItem * item = AllCopiersLW->item(i);
1154 AllCopiersLW->setItemSelected(item, true);
1161 void PrefCopiers::copiers_changed()
1167 void PrefCopiers::updateButtons()
1169 QString selected = copierFormatCO->currentText();
1172 for (int i = 0; i < AllCopiersLW->count(); ++i) {
1173 if (AllCopiersLW->item(i)->text() == selected)
1177 bool const valid = !copierED->text().isEmpty();
1179 Format const * fmt = getFormat(fromqstr(selected));
1180 string const old_command = form_->movers().command(fmt->name());
1181 string const new_command(fromqstr(copierED->text()));
1183 bool modified = (old_command != new_command);
1185 copierModifyPB->setEnabled(valid && known && modified);
1186 copierNewPB->setEnabled(valid && !known);
1187 copierRemovePB->setEnabled(known);
1191 void PrefCopiers::new_copier()
1193 std::string const combo_text =
1194 fromqstr(copierFormatCO->currentText());
1195 Format const * fmt = getFormat(combo_text);
1199 string const command = fromqstr(copierED->text());
1200 if (command.empty())
1203 form_->movers().set(fmt->name(), command);
1206 int const last = AllCopiersLW->count() - 1;
1207 AllCopiersLW->setCurrentRow(last);
1213 void PrefCopiers::modify_copier()
1215 std::string const combo_text =
1216 fromqstr(copierFormatCO->currentText());
1217 Format const * fmt = getFormat(combo_text);
1221 string const command = fromqstr(copierED->text());
1222 form_->movers().set(fmt->name(), command);
1229 void PrefCopiers::remove_copier()
1231 std::string const combo_text =
1232 fromqstr(copierFormatCO->currentText());
1233 Format const * fmt = getFormat(combo_text);
1237 string const & fmt_name = fmt->name();
1238 form_->movers().set(fmt_name, string());
1246 PrefFileformats::PrefFileformats(QPrefs * form, QWidget * parent)
1247 : PrefModule(docstring(), _("File formats"), form, parent)
1251 connect(formatNewPB, SIGNAL(clicked()),
1252 this, SLOT(new_format()));
1253 connect(formatRemovePB, SIGNAL(clicked()),
1254 this, SLOT(remove_format()));
1255 connect(formatModifyPB, SIGNAL(clicked()),
1256 this, SLOT(modify_format()));
1257 connect(formatsLW, SIGNAL(currentRowChanged(int)),
1258 this, SLOT(switch_format(int)));
1259 connect(formatED, SIGNAL(textChanged(const QString&)),
1260 this, SLOT(fileformat_changed()));
1261 connect(guiNameED, SIGNAL(textChanged(const QString&)),
1262 this, SLOT(fileformat_changed()));
1263 connect(shortcutED, SIGNAL(textChanged(const QString&)),
1264 this, SLOT(fileformat_changed()));
1265 connect(extensionED, SIGNAL(textChanged(const QString&)),
1266 this, SLOT(fileformat_changed()));
1267 connect(viewerED, SIGNAL(textChanged(const QString&)),
1268 this, SLOT(fileformat_changed()));
1269 connect(editorED, SIGNAL(textChanged(const QString&)),
1270 this, SLOT(fileformat_changed()));
1271 connect(documentCB, SIGNAL(clicked()),
1272 this, SLOT(fileformat_changed()));
1273 connect(vectorCB, SIGNAL(clicked()),
1274 this, SLOT(fileformat_changed()));
1275 connect(formatNewPB, SIGNAL(clicked()),
1276 this, SIGNAL(changed()));
1277 connect(formatRemovePB, SIGNAL(clicked()),
1278 this, SIGNAL(changed()));
1279 connect(formatModifyPB, SIGNAL(clicked()),
1280 this, SIGNAL(changed()));
1284 void PrefFileformats::apply(LyXRC & /*rc*/) const
1289 void PrefFileformats::update(LyXRC const & /*rc*/)
1295 void PrefFileformats::update()
1297 // save current selection
1298 QString current = guiNameED->text();
1300 // update listwidget with formats
1301 formatsLW->blockSignals(true);
1303 Formats::const_iterator cit = form_->formats().begin();
1304 Formats::const_iterator end = form_->formats().end();
1305 for (; cit != end; ++cit) {
1306 new QListWidgetItem(toqstr(cit->prettyname()),
1308 form_->formats().getNumber(cit->name()) );
1310 formatsLW->sortItems(Qt::AscendingOrder);
1311 formatsLW->blockSignals(false);
1313 // restore selection
1314 if (!current.isEmpty()) {
1315 QList<QListWidgetItem *> item = formatsLW->findItems(current, Qt::MatchExactly);
1317 formatsLW->setCurrentItem(item.at(0));
1319 // select first element if restoring failed
1320 if (formatsLW->currentRow() == -1)
1321 formatsLW->setCurrentRow(0);
1325 void PrefFileformats::switch_format(int nr)
1327 int const ftype = formatsLW->item(nr)->type();
1328 Format const f = form_->formats().get(ftype);
1330 formatED->setText(toqstr(f.name()));
1331 guiNameED->setText(toqstr(f.prettyname()));
1332 extensionED->setText(toqstr(f.extension()));
1333 shortcutED->setText(toqstr(f.shortcut()));
1334 viewerED->setText(toqstr(f.viewer()));
1335 editorED->setText(toqstr(f.editor()));
1336 documentCB->setChecked((f.documentFormat()));
1337 vectorCB->setChecked((f.vectorFormat()));
1343 void PrefFileformats::fileformat_changed()
1349 void PrefFileformats::updateButtons()
1351 QString const format = formatED->text();
1352 QString const gui_name = guiNameED->text();
1353 int const sel = form_->formats().getNumber(fromqstr(format));
1354 bool gui_name_known = false;
1356 for (int i = 0; i < formatsLW->count(); ++i) {
1357 if (formatsLW->item(i)->text() == gui_name) {
1358 gui_name_known = true;
1359 where = formatsLW->item(i)->type();
1363 // assure that a gui name cannot be chosen twice
1364 bool const known_otherwise = gui_name_known && (where != sel);
1366 bool const known = !(sel < 0);
1367 bool const valid = (!formatED->text().isEmpty()
1368 && !guiNameED->text().isEmpty());
1370 int const ftype = formatsLW->currentItem()->type();
1371 Format const & f(form_->formats().get(ftype));
1372 string const old_pretty(f.prettyname());
1373 string const old_shortcut(f.shortcut());
1374 string const old_extension(f.extension());
1375 string const old_viewer(f.viewer());
1376 string const old_editor(f.editor());
1377 bool const old_document(f.documentFormat());
1378 bool const old_vector(f.vectorFormat());
1380 string const new_pretty(fromqstr(gui_name));
1381 string const new_shortcut(fromqstr(shortcutED->text()));
1382 string const new_extension(fromqstr(extensionED->text()));
1383 string const new_viewer(fromqstr(viewerED->text()));
1384 string const new_editor(fromqstr(editorED->text()));
1385 bool const new_document(documentCB->isChecked());
1386 bool const new_vector(vectorCB->isChecked());
1388 bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
1389 || (old_extension != new_extension) || (old_viewer != new_viewer)
1390 || old_editor != new_editor || old_document != new_document
1391 || old_vector != new_vector);
1393 formatModifyPB->setEnabled(valid && known && modified && !known_otherwise);
1394 formatNewPB->setEnabled(valid && !known && !gui_name_known);
1395 formatRemovePB->setEnabled(known);
1399 void PrefFileformats::new_format()
1401 string const name = fromqstr(formatED->text());
1402 string const prettyname = fromqstr(guiNameED->text());
1403 string const extension = fromqstr(extensionED->text());
1404 string const shortcut = fromqstr(shortcutED->text());
1405 string const viewer = fromqstr(viewerED->text());
1406 string const editor = fromqstr(editorED->text());
1407 int flags = Format::none;
1408 if (documentCB->isChecked())
1409 flags |= Format::document;
1410 if (vectorCB->isChecked())
1411 flags |= Format::vector;
1413 form_->formats().add(name, extension, prettyname, shortcut, viewer,
1415 form_->formats().sort();
1416 form_->converters().update(form_->formats());
1424 void PrefFileformats::modify_format()
1426 int const current_item = formatsLW->currentItem()->type();
1427 Format const & oldformat = form_->formats().get(current_item);
1428 form_->formats().erase(oldformat.name());
1434 void PrefFileformats::remove_format()
1436 int const nr = formatsLW->currentItem()->type();
1437 string const current_text = form_->formats().get(nr).name();
1438 if (form_->converters().formatIsUsed(current_text)) {
1439 Alert::error(_("Format in use"),
1440 _("Cannot remove a Format used by a Converter. "
1441 "Remove the converter first."));
1445 form_->formats().erase(current_text);
1446 form_->converters().update(form_->formats());
1455 PrefLanguage::PrefLanguage(QWidget * parent)
1456 : PrefModule(docstring(), _("Language"), 0, parent)
1460 connect(rtlCB, SIGNAL(clicked()),
1461 this, SIGNAL(changed()));
1462 connect(markForeignCB, SIGNAL(clicked()),
1463 this, SIGNAL(changed()));
1464 connect(autoBeginCB, SIGNAL(clicked()),
1465 this, SIGNAL(changed()));
1466 connect(autoEndCB, SIGNAL(clicked()),
1467 this, SIGNAL(changed()));
1468 connect(useBabelCB, SIGNAL(clicked()),
1469 this, SIGNAL(changed()));
1470 connect(globalCB, SIGNAL(clicked()),
1471 this, SIGNAL(changed()));
1472 connect(languagePackageED, SIGNAL(textChanged(const QString&)),
1473 this, SIGNAL(changed()));
1474 connect(startCommandED, SIGNAL(textChanged(const QString&)),
1475 this, SIGNAL(changed()));
1476 connect(endCommandED, SIGNAL(textChanged(const QString&)),
1477 this, SIGNAL(changed()));
1478 connect(defaultLanguageCO, SIGNAL(activated(int)),
1479 this, SIGNAL(changed()));
1481 defaultLanguageCO->clear();
1483 // store the lang identifiers for later
1484 std::vector<LanguagePair> const langs =
1485 lyx::frontend::getLanguageData(false);
1486 lang_ = getSecond(langs);
1488 std::vector<LanguagePair>::const_iterator lit = langs.begin();
1489 std::vector<LanguagePair>::const_iterator lend = langs.end();
1490 for (; lit != lend; ++lit) {
1491 defaultLanguageCO->addItem(toqstr(lit->first));
1496 void PrefLanguage::apply(LyXRC & rc) const
1498 // FIXME: remove rtl_support bool
1499 rc.rtl_support = rtlCB->isChecked();
1500 rc.mark_foreign_language = markForeignCB->isChecked();
1501 rc.language_auto_begin = autoBeginCB->isChecked();
1502 rc.language_auto_end = autoEndCB->isChecked();
1503 rc.language_use_babel = useBabelCB->isChecked();
1504 rc.language_global_options = globalCB->isChecked();
1505 rc.language_package = fromqstr(languagePackageED->text());
1506 rc.language_command_begin = fromqstr(startCommandED->text());
1507 rc.language_command_end = fromqstr(endCommandED->text());
1508 rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1512 void PrefLanguage::update(LyXRC const & rc)
1514 // FIXME: remove rtl_support bool
1515 rtlCB->setChecked(rc.rtl_support);
1516 markForeignCB->setChecked(rc.mark_foreign_language);
1517 autoBeginCB->setChecked(rc.language_auto_begin);
1518 autoEndCB->setChecked(rc.language_auto_end);
1519 useBabelCB->setChecked(rc.language_use_babel);
1520 globalCB->setChecked(rc.language_global_options);
1521 languagePackageED->setText(toqstr(rc.language_package));
1522 startCommandED->setText(toqstr(rc.language_command_begin));
1523 endCommandED->setText(toqstr(rc.language_command_end));
1525 int const pos = int(findPos_helper(lang_, rc.default_language));
1526 defaultLanguageCO->setCurrentIndex(pos);
1530 PrefPrinter::PrefPrinter(QWidget * parent)
1531 : PrefModule(_(Outputs), _("Printer"), 0, parent)
1535 connect(printerAdaptCB, SIGNAL(clicked()),
1536 this, SIGNAL(changed()));
1537 connect(printerCommandED, SIGNAL(textChanged(const QString&)),
1538 this, SIGNAL(changed()));
1539 connect(printerNameED, SIGNAL(textChanged(const QString&)),
1540 this, SIGNAL(changed()));
1541 connect(printerPageRangeED, SIGNAL(textChanged(const QString&)),
1542 this, SIGNAL(changed()));
1543 connect(printerCopiesED, SIGNAL(textChanged(const QString&)),
1544 this, SIGNAL(changed()));
1545 connect(printerReverseED, SIGNAL(textChanged(const QString&)),
1546 this, SIGNAL(changed()));
1547 connect(printerToPrinterED, SIGNAL(textChanged(const QString&)),
1548 this, SIGNAL(changed()));
1549 connect(printerExtensionED, SIGNAL(textChanged(const QString&)),
1550 this, SIGNAL(changed()));
1551 connect(printerSpoolCommandED, SIGNAL(textChanged(const QString&)),
1552 this, SIGNAL(changed()));
1553 connect(printerPaperTypeED, SIGNAL(textChanged(const QString&)),
1554 this, SIGNAL(changed()));
1555 connect(printerEvenED, SIGNAL(textChanged(const QString&)),
1556 this, SIGNAL(changed()));
1557 connect(printerOddED, SIGNAL(textChanged(const QString&)),
1558 this, SIGNAL(changed()));
1559 connect(printerCollatedED, SIGNAL(textChanged(const QString&)),
1560 this, SIGNAL(changed()));
1561 connect(printerLandscapeED, SIGNAL(textChanged(const QString&)),
1562 this, SIGNAL(changed()));
1563 connect(printerToFileED, SIGNAL(textChanged(const QString&)),
1564 this, SIGNAL(changed()));
1565 connect(printerExtraED, SIGNAL(textChanged(const QString&)),
1566 this, SIGNAL(changed()));
1567 connect(printerSpoolPrefixED, SIGNAL(textChanged(const QString&)),
1568 this, SIGNAL(changed()));
1569 connect(printerPaperSizeED, SIGNAL(textChanged(const QString&)),
1570 this, SIGNAL(changed()));
1574 void PrefPrinter::apply(LyXRC & rc) const
1576 rc.print_adapt_output = printerAdaptCB->isChecked();
1577 rc.print_command = fromqstr(printerCommandED->text());
1578 rc.printer = fromqstr(printerNameED->text());
1580 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1581 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1582 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1583 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1584 rc.print_file_extension = fromqstr(printerExtensionED->text());
1585 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1586 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1587 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1588 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1589 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1590 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1591 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1592 rc.print_extra_options = fromqstr(printerExtraED->text());
1593 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1594 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1598 void PrefPrinter::update(LyXRC const & rc)
1600 printerAdaptCB->setChecked(rc.print_adapt_output);
1601 printerCommandED->setText(toqstr(rc.print_command));
1602 printerNameED->setText(toqstr(rc.printer));
1604 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1605 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1606 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1607 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1608 printerExtensionED->setText(toqstr(rc.print_file_extension));
1609 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1610 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1611 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1612 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1613 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1614 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1615 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1616 printerExtraED->setText(toqstr(rc.print_extra_options));
1617 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1618 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1622 PrefUserInterface::PrefUserInterface(QPrefs * form, QWidget * parent)
1623 : PrefModule(_(LookAndFeel), _("User interface"), form, parent)
1627 connect(autoSaveCB, SIGNAL( toggled(bool) ), autoSaveLA, SLOT( setEnabled(bool) ) );
1628 connect(autoSaveCB, SIGNAL( toggled(bool) ), autoSaveSB, SLOT( setEnabled(bool) ) );
1629 connect(autoSaveCB, SIGNAL( toggled(bool) ), TextLabel1, SLOT( setEnabled(bool) ) );
1630 connect(uiFilePB, SIGNAL(clicked()), this, SLOT(select_ui()));
1631 connect(bindFilePB, SIGNAL(clicked()), this, SLOT(select_bind()));
1632 connect(uiFileED, SIGNAL(textChanged(const QString&)),
1633 this, SIGNAL(changed()));
1634 connect(bindFileED, SIGNAL(textChanged(const QString&)),
1635 this, SIGNAL(changed()));
1636 connect(restoreCursorCB, SIGNAL(clicked()),
1637 this, SIGNAL(changed()));
1638 connect(loadSessionCB, SIGNAL(clicked()),
1639 this, SIGNAL(changed()));
1640 connect(loadWindowSizeCB, SIGNAL(clicked()),
1641 this, SIGNAL(changed()));
1642 connect(loadWindowLocationCB, SIGNAL(clicked()),
1643 this, SIGNAL(changed()));
1644 connect(windowWidthSB, SIGNAL(valueChanged(int)),
1645 this, SIGNAL(changed()));
1646 connect(windowHeightSB, SIGNAL(valueChanged(int)),
1647 this, SIGNAL(changed()));
1648 connect(cursorFollowsCB, SIGNAL(clicked()),
1649 this, SIGNAL(changed()));
1650 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1651 this, SIGNAL(changed()));
1652 connect(autoSaveCB, SIGNAL(clicked()),
1653 this, SIGNAL(changed()));
1654 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1655 this, SIGNAL(changed()));
1656 lastfilesSB->setMaximum(maxlastfiles);
1660 void PrefUserInterface::apply(LyXRC & rc) const
1662 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1663 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1664 rc.use_lastfilepos = restoreCursorCB->isChecked();
1665 rc.load_session = loadSessionCB->isChecked();
1666 if (loadWindowSizeCB->isChecked()) {
1667 rc.geometry_width = 0;
1668 rc.geometry_height = 0;
1670 rc.geometry_width = windowWidthSB->value();
1671 rc.geometry_height = windowHeightSB->value();
1673 rc.geometry_xysaved = loadWindowLocationCB->isChecked();
1674 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1675 rc.autosave = autoSaveSB->value() * 60;
1676 rc.make_backup = autoSaveCB->isChecked();
1677 rc.num_lastfiles = lastfilesSB->value();
1681 void PrefUserInterface::update(LyXRC const & rc)
1683 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1684 bindFileED->setText(toqstr(external_path(rc.bind_file)));
1685 restoreCursorCB->setChecked(rc.use_lastfilepos);
1686 loadSessionCB->setChecked(rc.load_session);
1687 bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
1688 loadWindowSizeCB->setChecked(loadWindowSize);
1689 if (!loadWindowSize) {
1690 windowWidthSB->setValue(rc.geometry_width);
1691 windowHeightSB->setValue(rc.geometry_height);
1693 loadWindowLocationCB->setChecked(rc.geometry_xysaved);
1694 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1695 // convert to minutes
1696 int mins(rc.autosave / 60);
1697 if (rc.autosave && !mins)
1699 autoSaveSB->setValue(mins);
1700 autoSaveCB->setChecked(rc.make_backup);
1701 lastfilesSB->setValue(rc.num_lastfiles);
1706 void PrefUserInterface::select_ui()
1708 docstring const name =
1709 from_utf8(internal_path(fromqstr(uiFileED->text())));
1710 docstring file(form_->controller().browseUI(name));
1712 uiFileED->setText(toqstr(file));
1716 void PrefUserInterface::select_bind()
1718 docstring const name =
1719 from_utf8(internal_path(fromqstr(bindFileED->text())));
1720 docstring file(form_->controller().browsebind(name));
1722 bindFileED->setText(toqstr(file));
1726 void PrefUserInterface::on_loadWindowSizeCB_toggled(bool loadwindowsize)
1728 windowWidthLA->setDisabled(loadwindowsize);
1729 windowHeightLA->setDisabled(loadwindowsize);
1730 windowWidthSB->setDisabled(loadwindowsize);
1731 windowHeightSB->setDisabled(loadwindowsize);
1735 PrefIdentity::PrefIdentity(QWidget * parent)
1736 : PrefModule(docstring(), _("Identity"), 0, parent)
1740 connect(nameED, SIGNAL(textChanged(const QString&)),
1741 this, SIGNAL(changed()));
1742 connect(emailED, SIGNAL(textChanged(const QString&)),
1743 this, SIGNAL(changed()));
1747 void PrefIdentity::apply(LyXRC & rc) const
1749 rc.user_name = fromqstr(nameED->text());
1750 rc.user_email = fromqstr(emailED->text());
1754 void PrefIdentity::update(LyXRC const & rc)
1756 nameED->setText(toqstr(rc.user_name));
1757 emailED->setText(toqstr(rc.user_email));
1762 QPrefsDialog::QPrefsDialog(QPrefs * form)
1766 QDialog::setModal(false);
1768 connect(savePB, SIGNAL(clicked()),
1769 form, SLOT(slotOK()));
1770 connect(applyPB, SIGNAL(clicked()),
1771 form, SLOT(slotApply()));
1772 connect(closePB, SIGNAL(clicked()),
1773 form, SLOT(slotClose()));
1774 connect(restorePB, SIGNAL(clicked()),
1775 form, SLOT(slotRestore()));
1777 add(new PrefPlaintext);
1779 add(new PrefKeyboard(form_));
1780 add(new PrefLatex(form_));
1781 add(new PrefScreenFonts(form_));
1782 add(new PrefColors(form_));
1784 #if defined(__CYGWIN__) || defined(_WIN32)
1785 add(new PrefCygwinPath);
1788 add(new PrefDisplay);
1789 add(new PrefPaths(form_));
1790 add(new PrefSpellchecker(form_));
1792 PrefConverters * converters = new PrefConverters(form_);
1793 PrefFileformats * formats = new PrefFileformats(form_);
1794 connect(formats, SIGNAL(formatsChanged()),
1795 converters, SLOT(updateGui()));
1799 add(new PrefCopiers(form_));
1801 add(new PrefLanguage);
1802 add(new PrefPrinter);
1803 add(new PrefUserInterface(form_));
1804 add(new PrefIdentity);
1806 prefsPS->setCurrentPanel(_("User interface"));
1807 // FIXME: hack to work around resizing bug in Qt >= 4.2
1808 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1809 #if QT_VERSION >= 0x040200
1810 prefsPS->updateGeometry();
1813 form_->bcview().setOK(savePB);
1814 form_->bcview().setApply(applyPB);
1815 form_->bcview().setCancel(closePB);
1816 form_->bcview().setRestore(restorePB);
1820 QPrefsDialog::~QPrefsDialog()
1825 void QPrefsDialog::add(PrefModule * module)
1827 BOOST_ASSERT(module);
1829 // if (module->category().empty())
1830 // prefsPS->addPanel(module, module->title());
1832 prefsPS->addPanel(module, module->title(), module->category());
1834 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
1836 modules_.push_back(module);
1839 void QPrefsDialog::closeEvent(QCloseEvent * e)
1841 form_->slotWMHide();
1846 void QPrefsDialog::change_adaptor()
1852 void QPrefsDialog::apply(LyXRC & rc) const
1854 size_t end = modules_.size();
1855 for (size_t i = 0; i != end; ++i)
1856 modules_[i]->apply(rc);
1860 void QPrefsDialog::updateRc(LyXRC const & rc)
1862 size_t end = modules_.size();
1863 for (size_t i = 0; i != end; ++i)
1864 modules_[i]->update(rc);
1868 } // namespace frontend
1871 #include "QPrefsDialog_moc.cpp"