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: all of this initialization should be put into the controller.
489 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
490 // for some discussion of why that is not trivial.
491 for (int i = 0; i < LColor::ignore; ++i) {
492 LColor::color lc = static_cast<LColor::color>(i);
493 if (lc == LColor::none
494 || lc == LColor::black
495 || lc == LColor::white
497 || lc == LColor::green
498 || lc == LColor::blue
499 || lc == LColor::cyan
500 || lc == LColor::magenta
501 || lc == LColor::yellow
502 || lc == LColor::inherit
503 || lc == LColor::ignore) continue;
505 lcolors_.push_back(lc);
506 QColor color = QColor(guiApp->colorCache().get(lc));
507 curcolors_.push_back(color.name());
508 QPixmap coloritem(32, 32);
509 coloritem.fill(color);
510 // This is not a memory leak:
511 /*QListWidgetItem * newItem =*/ new QListWidgetItem(QIcon(coloritem),
512 toqstr(lcolor.getGUIName(lc)), lyxObjectsLW);
514 newcolors_ = curcolors_;
515 // End initialization
517 connect(colorChangePB, SIGNAL(clicked()),
518 this, SLOT(change_color()));
519 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
520 this, SLOT(change_color()));
524 void PrefColors::apply(LyXRC & /*rc*/) const
526 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
527 if (curcolors_[i]!=newcolors_[i])
528 form_->controller().setColor(lcolors_[i], fromqstr(newcolors_[i]));
530 // HACK The following line is needed because the values are not
531 // re-initialized in ControlPrefs::initialiseParams but are only
532 // initialized in the constructor. But the constructor is only called
533 // once, when the dialog if first created, and is not called again when
534 // Tools > Preferences is selected a second time: It's just called up
535 // from memory. [See QDialogView::show(): if (!form) { build(); }.]
536 curcolors_ = newcolors_;
540 // FIXME The fact that this method is empty is also a symptom of the
542 void PrefColors::update(LyXRC const & /*rc*/)
546 void PrefColors::change_color()
548 int const row = lyxObjectsLW->currentRow();
549 QString color = newcolors_[row];
550 QColor c(QColorDialog::getColor(QColor(color),
551 qApp->focusWidget()));
553 if (c.name()!=color) {
554 newcolors_[row] = c.name();
555 QPixmap coloritem(32, 32);
557 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
564 PrefCygwinPath::PrefCygwinPath(QWidget * parent)
565 : PrefModule(_(Outputs), _("Paths"), 0, parent)
568 connect(pathCB, SIGNAL(clicked()),
569 this, SIGNAL(changed()));
573 void PrefCygwinPath::apply(LyXRC & rc) const
575 rc.windows_style_tex_paths = pathCB->isChecked();
579 void PrefCygwinPath::update(LyXRC const & rc)
581 pathCB->setChecked(rc.windows_style_tex_paths);
585 PrefDisplay::PrefDisplay(QWidget * parent)
586 : PrefModule(_(LookAndFeel), _("Graphics"), 0, parent)
589 connect(instantPreviewCO, SIGNAL(activated(int)),
590 this, SIGNAL(changed()));
591 connect(displayGraphicsCO, SIGNAL(activated(int)),
592 this, SIGNAL(changed()));
596 void PrefDisplay::apply(LyXRC & rc) const
598 switch (instantPreviewCO->currentIndex()) {
599 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
600 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
601 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
604 lyx::graphics::DisplayType dtype;
605 switch (displayGraphicsCO->currentIndex()) {
606 case 3: dtype = lyx::graphics::NoDisplay; break;
607 case 2: dtype = lyx::graphics::ColorDisplay; break;
608 case 1: dtype = lyx::graphics::GrayscaleDisplay; break;
609 case 0: dtype = lyx::graphics::MonochromeDisplay; break;
610 default: dtype = lyx::graphics::GrayscaleDisplay;
612 rc.display_graphics = dtype;
615 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
618 if (old_value != rc.display_graphics) {
619 lyx::graphics::GCache & gc = lyx::graphics::GCache::get();
626 void PrefDisplay::update(LyXRC const & rc)
628 switch (rc.preview) {
629 case LyXRC::PREVIEW_OFF:
630 instantPreviewCO->setCurrentIndex(0);
632 case LyXRC::PREVIEW_NO_MATH :
633 instantPreviewCO->setCurrentIndex(1);
635 case LyXRC::PREVIEW_ON :
636 instantPreviewCO->setCurrentIndex(2);
641 switch (rc.display_graphics) {
642 case lyx::graphics::NoDisplay: item = 3; break;
643 case lyx::graphics::ColorDisplay: item = 2; break;
644 case lyx::graphics::GrayscaleDisplay: item = 1; break;
645 case lyx::graphics::MonochromeDisplay: item = 0; break;
648 displayGraphicsCO->setCurrentIndex(item);
652 PrefPaths::PrefPaths(QPrefs * form, QWidget * parent)
653 : PrefModule(docstring(), _("Paths"), form, parent)
656 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
657 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
658 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
659 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
660 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
661 connect(workingDirED, SIGNAL(textChanged(const QString&)),
662 this, SIGNAL(changed()));
663 connect(templateDirED, SIGNAL(textChanged(const QString&)),
664 this, SIGNAL(changed()));
665 connect(backupDirED, SIGNAL(textChanged(const QString&)),
666 this, SIGNAL(changed()));
667 connect(tempDirED, SIGNAL(textChanged(const QString&)),
668 this, SIGNAL(changed()));
669 connect(lyxserverDirED, SIGNAL(textChanged(const QString&)),
670 this, SIGNAL(changed()));
671 connect(pathPrefixED, SIGNAL(textChanged(const QString&)),
672 this, SIGNAL(changed()));
676 void PrefPaths::apply(LyXRC & rc) const
678 rc.document_path = internal_path(fromqstr(workingDirED->text()));
679 rc.template_path = internal_path(fromqstr(templateDirED->text()));
680 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
681 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
682 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
683 // FIXME: should be a checkbox only
684 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
688 void PrefPaths::update(LyXRC const & rc)
690 workingDirED->setText(toqstr(external_path(rc.document_path)));
691 templateDirED->setText(toqstr(external_path(rc.template_path)));
692 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
693 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
694 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
695 // FIXME: should be a checkbox only
696 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
700 void PrefPaths::select_templatedir()
702 docstring file(form_->controller().browsedir(
703 from_utf8(internal_path(fromqstr(templateDirED->text()))),
704 _("Select a document templates directory")));
706 templateDirED->setText(toqstr(file));
710 void PrefPaths::select_tempdir()
712 docstring file(form_->controller().browsedir(
713 from_utf8(internal_path(fromqstr(tempDirED->text()))),
714 _("Select a temporary directory")));
716 tempDirED->setText(toqstr(file));
720 void PrefPaths::select_backupdir()
722 docstring file(form_->controller().browsedir(
723 from_utf8(internal_path(fromqstr(backupDirED->text()))),
724 _("Select a backups directory")));
726 backupDirED->setText(toqstr(file));
730 void PrefPaths::select_workingdir()
732 docstring file(form_->controller().browsedir(
733 from_utf8(internal_path(fromqstr(workingDirED->text()))),
734 _("Select a document directory")));
736 workingDirED->setText(toqstr(file));
740 void PrefPaths::select_lyxpipe()
742 docstring file(form_->controller().browse(
743 from_utf8(internal_path(fromqstr(lyxserverDirED->text()))),
744 _("Give a filename for the LyX server pipe")));
746 lyxserverDirED->setText(toqstr(file));
750 PrefSpellchecker::PrefSpellchecker(QPrefs * form, QWidget * parent)
751 : PrefModule(_(LanguageSettings), _("Spellchecker"), form, parent)
755 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
756 #if defined (USE_ISPELL)
757 connect(spellCommandCO, SIGNAL(activated(int)),
758 this, SIGNAL(changed()));
760 spellCommandCO->setEnabled(false);
762 connect(altLanguageED, SIGNAL(textChanged(const QString&)),
763 this, SIGNAL(changed()));
764 connect(escapeCharactersED, SIGNAL(textChanged(const QString&)),
765 this, SIGNAL(changed()));
766 connect(persDictionaryED, SIGNAL(textChanged(const QString&)),
767 this, SIGNAL(changed()));
768 connect(compoundWordCB, SIGNAL(clicked()),
769 this, SIGNAL(changed()));
770 connect(inputEncodingCB, SIGNAL(clicked()),
771 this, SIGNAL(changed()));
773 spellCommandCO->addItem(qt_("ispell"));
774 spellCommandCO->addItem(qt_("aspell"));
775 spellCommandCO->addItem(qt_("hspell"));
777 spellCommandCO->addItem(qt_("pspell (library)"));
780 spellCommandCO->addItem(qt_("aspell (library)"));
786 void PrefSpellchecker::apply(LyXRC & rc) const
788 switch (spellCommandCO->currentIndex()) {
792 rc.use_spell_lib = false;
793 rc.isp_command = fromqstr(spellCommandCO->currentText());
796 rc.use_spell_lib = true;
800 // FIXME: remove isp_use_alt_lang
801 rc.isp_alt_lang = fromqstr(altLanguageED->text());
802 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
803 // FIXME: remove isp_use_esc_chars
804 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
805 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
806 // FIXME: remove isp_use_pers_dict
807 rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
808 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
809 rc.isp_accept_compound = compoundWordCB->isChecked();
810 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
814 void PrefSpellchecker::update(LyXRC const & rc)
816 spellCommandCO->setCurrentIndex(0);
818 if (rc.isp_command == "ispell") {
819 spellCommandCO->setCurrentIndex(0);
820 } else if (rc.isp_command == "aspell") {
821 spellCommandCO->setCurrentIndex(1);
822 } else if (rc.isp_command == "hspell") {
823 spellCommandCO->setCurrentIndex(2);
826 if (rc.use_spell_lib) {
827 #if defined(USE_ASPELL) || defined(USE_PSPELL)
828 spellCommandCO->setCurrentIndex(3);
832 // FIXME: remove isp_use_alt_lang
833 altLanguageED->setText(toqstr(rc.isp_alt_lang));
834 // FIXME: remove isp_use_esc_chars
835 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
836 // FIXME: remove isp_use_pers_dict
837 persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
838 compoundWordCB->setChecked(rc.isp_accept_compound);
839 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
843 void PrefSpellchecker::select_dict()
845 docstring file(form_->controller().browsedict(
846 from_utf8(internal_path(fromqstr(persDictionaryED->text())))));
848 persDictionaryED->setText(toqstr(file));
852 PrefConverters::PrefConverters(QPrefs * form, QWidget * parent)
853 : PrefModule(docstring(), _("Converters"), form, parent)
857 connect(converterNewPB, SIGNAL(clicked()),
858 this, SLOT(update_converter()));
859 connect(converterRemovePB, SIGNAL(clicked()),
860 this, SLOT(remove_converter()));
861 connect(converterModifyPB, SIGNAL(clicked()),
862 this, SLOT(update_converter()));
863 connect(convertersLW, SIGNAL(currentRowChanged(int)),
864 this, SLOT(switch_converter()));
865 connect(converterFromCO, SIGNAL(activated(const QString&)),
866 this, SLOT(converter_changed()));
867 connect(converterToCO, SIGNAL(activated(const QString&)),
868 this, SLOT(converter_changed()));
869 connect(converterED, SIGNAL(textChanged(const QString&)),
870 this, SLOT(converter_changed()));
871 connect(converterFlagED, SIGNAL(textChanged(const QString&)),
872 this, SLOT(converter_changed()));
873 connect(converterNewPB, SIGNAL(clicked()),
874 this, SIGNAL(changed()));
875 connect(converterRemovePB, SIGNAL(clicked()),
876 this, SIGNAL(changed()));
877 connect(converterModifyPB, SIGNAL(clicked()),
878 this, SIGNAL(changed()));
879 connect(maxAgeLE, SIGNAL(textChanged(const QString&)),
880 this, SIGNAL(changed()));
882 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
883 converterDefGB->setFocusProxy(convertersLW);
887 void PrefConverters::apply(LyXRC & rc) const
889 rc.use_converter_cache = cacheCB->isChecked();
890 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
894 void PrefConverters::update(LyXRC const & rc)
896 cacheCB->setChecked(rc.use_converter_cache);
898 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
899 maxAgeLE->setText(max_age);
904 void PrefConverters::updateGui()
906 // save current selection
907 QString current = converterFromCO->currentText()
908 + " -> " + converterToCO->currentText();
910 converterFromCO->clear();
911 converterToCO->clear();
913 Formats::const_iterator cit = form_->formats().begin();
914 Formats::const_iterator end = form_->formats().end();
915 for (; cit != end; ++cit) {
916 converterFromCO->addItem(toqstr(cit->prettyname()));
917 converterToCO->addItem(toqstr(cit->prettyname()));
920 // currentRowChanged(int) is also triggered when updating the listwidget
921 // block signals to avoid unnecessary calls to switch_converter()
922 convertersLW->blockSignals(true);
923 convertersLW->clear();
925 Converters::const_iterator ccit = form_->converters().begin();
926 Converters::const_iterator cend = form_->converters().end();
927 for (; ccit != cend; ++ccit) {
928 std::string const name =
929 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
930 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
931 new QListWidgetItem(toqstr(name), convertersLW, type);
933 convertersLW->sortItems(Qt::AscendingOrder);
934 convertersLW->blockSignals(false);
937 if (!current.isEmpty()) {
938 QList<QListWidgetItem *> const item =
939 convertersLW->findItems(current, Qt::MatchExactly);
941 convertersLW->setCurrentItem(item.at(0));
944 // select first element if restoring failed
945 if (convertersLW->currentRow() == -1)
946 convertersLW->setCurrentRow(0);
952 void PrefConverters::switch_converter()
954 int const cnr = convertersLW->currentItem()->type();
955 Converter const & c(form_->converters().get(cnr));
956 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
957 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
958 converterED->setText(toqstr(c.command));
959 converterFlagED->setText(toqstr(c.flags));
965 void PrefConverters::converter_changed()
971 void PrefConverters::updateButtons()
973 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
974 Format const & to(form_->formats().get(converterToCO->currentIndex()));
975 int const sel = form_->converters().getNumber(from.name(), to.name());
976 bool const known = !(sel < 0);
977 bool const valid = !(converterED->text().isEmpty()
978 || from.name() == to.name());
980 int const cnr = convertersLW->currentItem()->type();
981 Converter const & c(form_->converters().get(cnr));
982 string const old_command = c.command;
983 string const old_flag = c.flags;
984 string const new_command(fromqstr(converterED->text()));
985 string const new_flag(fromqstr(converterFlagED->text()));
987 bool modified = ((old_command != new_command) || (old_flag != new_flag));
989 converterModifyPB->setEnabled(valid && known && modified);
990 converterNewPB->setEnabled(valid && !known);
991 converterRemovePB->setEnabled(known);
993 maxAgeLE->setEnabled(cacheCB->isChecked());
994 maxAgeLA->setEnabled(cacheCB->isChecked());
999 // specify unique from/to or it doesn't appear. This is really bad UI
1000 // this is why we can use the same function for both new and modify
1001 void PrefConverters::update_converter()
1003 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1004 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1005 string const flags = fromqstr(converterFlagED->text());
1006 string const command = fromqstr(converterED->text());
1008 Converter const * old = form_->converters().getConverter(from.name(), to.name());
1009 form_->converters().add(from.name(), to.name(), command, flags);
1011 form_->converters().updateLast(form_->formats());
1018 void PrefConverters::remove_converter()
1020 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1021 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1022 form_->converters().erase(from.name(), to.name());
1028 void PrefConverters::on_cacheCB_stateChanged(int state)
1030 maxAgeLE->setEnabled(state == Qt::Checked);
1031 maxAgeLA->setEnabled(state == Qt::Checked);
1036 PrefCopiers::PrefCopiers(QPrefs * form, QWidget * parent)
1037 : PrefModule(docstring(), _("Copiers"), form, parent)
1041 connect(copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
1042 connect(copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
1043 connect(copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
1044 connect(AllCopiersLW, SIGNAL(currentRowChanged(int)),
1045 this, SLOT(switch_copierLB(int)));
1046 connect(copierFormatCO, SIGNAL(activated(int)), this, SLOT(switch_copierCO(int)));
1047 connect(copierNewPB, SIGNAL(clicked()),
1048 this, SIGNAL(changed()));
1049 connect(copierRemovePB, SIGNAL(clicked()),
1050 this, SIGNAL(changed()));
1051 connect(copierModifyPB, SIGNAL(clicked()),
1052 this, SIGNAL(changed()));
1053 connect(copierFormatCO, SIGNAL(activated(const QString&)), this, SLOT(copiers_changed()));
1054 connect(copierED, SIGNAL(textChanged(const QString&)), this, SLOT(copiers_changed()));
1058 void PrefCopiers::apply(LyXRC & /*rc*/) const
1063 void PrefCopiers::update(LyXRC const & /*rc*/)
1069 void PrefCopiers::update()
1071 // The choice widget
1072 // save current selection
1073 QString current = copierFormatCO->currentText();
1074 copierFormatCO->clear();
1076 for (Formats::const_iterator it = form_->formats().begin(),
1077 end = form_->formats().end();
1079 copierFormatCO->addItem(toqstr(it->prettyname()));
1082 // The browser widget
1083 AllCopiersLW->clear();
1085 for (Movers::const_iterator it = form_->movers().begin(),
1086 end = form_->movers().end();
1088 std::string const & command = it->second.command();
1089 if (command.empty())
1091 QString const pretty = toqstr(form_->formats().prettyName(it->first));
1092 AllCopiersLW->addItem(pretty);
1094 AllCopiersLW->sortItems(Qt::AscendingOrder);
1096 // restore selection
1097 if (!current.isEmpty()) {
1098 QList<QListWidgetItem *> item =
1099 AllCopiersLW->findItems(current, Qt::MatchExactly);
1101 AllCopiersLW->setCurrentItem(item.at(0));
1103 // select first element if restoring failed
1104 if (AllCopiersLW->currentRow() == -1)
1105 AllCopiersLW->setCurrentRow(0);
1111 class SamePrettyName {
1113 SamePrettyName(string const & n) : pretty_name_(n) {}
1115 bool operator()(lyx::Format const & fmt) const {
1116 return fmt.prettyname() == pretty_name_;
1120 string const pretty_name_;
1124 Format const * getFormat(std::string const & prettyname)
1126 Formats::const_iterator it = lyx::formats.begin();
1127 Formats::const_iterator const end = lyx::formats.end();
1128 it = std::find_if(it, end, SamePrettyName(prettyname));
1129 return it == end ? 0 : &*it;
1135 void PrefCopiers::switch_copierLB(int row)
1141 std::string const browser_text =
1142 fromqstr(AllCopiersLW->currentItem()->text());
1143 Format const * fmt = getFormat(browser_text);
1147 QString const gui_name = toqstr(fmt->prettyname());
1148 QString const command = toqstr(form_->movers().command(fmt->name()));
1151 int const combo_size = copierFormatCO->count();
1152 for (int i = 0; i < combo_size; ++i) {
1153 QString const text = copierFormatCO->itemText(i);
1154 if (text == gui_name) {
1155 copierFormatCO->setCurrentIndex(i);
1156 copierED->setText(command);
1164 void PrefCopiers::switch_copierCO(int row)
1169 std::string const combo_text =
1170 fromqstr(copierFormatCO->currentText());
1171 Format const * fmt = getFormat(combo_text);
1175 QString const command = toqstr(form_->movers().command(fmt->name()));
1176 copierED->setText(command);
1178 QListWidgetItem * const index = AllCopiersLW->currentItem();
1180 AllCopiersLW->setItemSelected(index, false);
1182 QString const gui_name = toqstr(fmt->prettyname());
1183 int const browser_size = AllCopiersLW->count();
1184 for (int i = 0; i < browser_size; ++i) {
1185 QString const text = AllCopiersLW->item(i)->text();
1186 if (text == gui_name) {
1187 QListWidgetItem * item = AllCopiersLW->item(i);
1188 AllCopiersLW->setItemSelected(item, true);
1195 void PrefCopiers::copiers_changed()
1201 void PrefCopiers::updateButtons()
1203 QString selected = copierFormatCO->currentText();
1206 for (int i = 0; i < AllCopiersLW->count(); ++i) {
1207 if (AllCopiersLW->item(i)->text() == selected)
1211 bool const valid = !copierED->text().isEmpty();
1213 Format const * fmt = getFormat(fromqstr(selected));
1214 string const old_command = form_->movers().command(fmt->name());
1215 string const new_command(fromqstr(copierED->text()));
1217 bool modified = (old_command != new_command);
1219 copierModifyPB->setEnabled(valid && known && modified);
1220 copierNewPB->setEnabled(valid && !known);
1221 copierRemovePB->setEnabled(known);
1225 void PrefCopiers::new_copier()
1227 std::string const combo_text =
1228 fromqstr(copierFormatCO->currentText());
1229 Format const * fmt = getFormat(combo_text);
1233 string const command = fromqstr(copierED->text());
1234 if (command.empty())
1237 form_->movers().set(fmt->name(), command);
1240 int const last = AllCopiersLW->count() - 1;
1241 AllCopiersLW->setCurrentRow(last);
1247 void PrefCopiers::modify_copier()
1249 std::string const combo_text =
1250 fromqstr(copierFormatCO->currentText());
1251 Format const * fmt = getFormat(combo_text);
1255 string const command = fromqstr(copierED->text());
1256 form_->movers().set(fmt->name(), command);
1263 void PrefCopiers::remove_copier()
1265 std::string const combo_text =
1266 fromqstr(copierFormatCO->currentText());
1267 Format const * fmt = getFormat(combo_text);
1271 string const & fmt_name = fmt->name();
1272 form_->movers().set(fmt_name, string());
1280 PrefFileformats::PrefFileformats(QPrefs * form, QWidget * parent)
1281 : PrefModule(docstring(), _("File formats"), form, parent)
1285 connect(formatNewPB, SIGNAL(clicked()),
1286 this, SLOT(new_format()));
1287 connect(formatRemovePB, SIGNAL(clicked()),
1288 this, SLOT(remove_format()));
1289 connect(formatModifyPB, SIGNAL(clicked()),
1290 this, SLOT(modify_format()));
1291 connect(formatsLW, SIGNAL(currentRowChanged(int)),
1292 this, SLOT(switch_format(int)));
1293 connect(formatED, SIGNAL(textChanged(const QString&)),
1294 this, SLOT(fileformat_changed()));
1295 connect(guiNameED, SIGNAL(textChanged(const QString&)),
1296 this, SLOT(fileformat_changed()));
1297 connect(shortcutED, SIGNAL(textChanged(const QString&)),
1298 this, SLOT(fileformat_changed()));
1299 connect(extensionED, SIGNAL(textChanged(const QString&)),
1300 this, SLOT(fileformat_changed()));
1301 connect(viewerED, SIGNAL(textChanged(const QString&)),
1302 this, SLOT(fileformat_changed()));
1303 connect(editorED, SIGNAL(textChanged(const QString&)),
1304 this, SLOT(fileformat_changed()));
1305 connect(documentCB, SIGNAL(clicked()),
1306 this, SLOT(fileformat_changed()));
1307 connect(vectorCB, SIGNAL(clicked()),
1308 this, SLOT(fileformat_changed()));
1309 connect(formatNewPB, SIGNAL(clicked()),
1310 this, SIGNAL(changed()));
1311 connect(formatRemovePB, SIGNAL(clicked()),
1312 this, SIGNAL(changed()));
1313 connect(formatModifyPB, SIGNAL(clicked()),
1314 this, SIGNAL(changed()));
1318 void PrefFileformats::apply(LyXRC & /*rc*/) const
1323 void PrefFileformats::update(LyXRC const & /*rc*/)
1329 void PrefFileformats::update()
1331 // save current selection
1332 QString current = guiNameED->text();
1334 // update listwidget with formats
1335 formatsLW->blockSignals(true);
1337 Formats::const_iterator cit = form_->formats().begin();
1338 Formats::const_iterator end = form_->formats().end();
1339 for (; cit != end; ++cit) {
1340 new QListWidgetItem(toqstr(cit->prettyname()),
1342 form_->formats().getNumber(cit->name()) );
1344 formatsLW->sortItems(Qt::AscendingOrder);
1345 formatsLW->blockSignals(false);
1347 // restore selection
1348 if (!current.isEmpty()) {
1349 QList<QListWidgetItem *> item = formatsLW->findItems(current, Qt::MatchExactly);
1351 formatsLW->setCurrentItem(item.at(0));
1353 // select first element if restoring failed
1354 if (formatsLW->currentRow() == -1)
1355 formatsLW->setCurrentRow(0);
1359 void PrefFileformats::switch_format(int nr)
1361 int const ftype = formatsLW->item(nr)->type();
1362 Format const f = form_->formats().get(ftype);
1364 formatED->setText(toqstr(f.name()));
1365 guiNameED->setText(toqstr(f.prettyname()));
1366 extensionED->setText(toqstr(f.extension()));
1367 shortcutED->setText(toqstr(f.shortcut()));
1368 viewerED->setText(toqstr(f.viewer()));
1369 editorED->setText(toqstr(f.editor()));
1370 documentCB->setChecked((f.documentFormat()));
1371 vectorCB->setChecked((f.vectorFormat()));
1377 void PrefFileformats::fileformat_changed()
1383 void PrefFileformats::updateButtons()
1385 QString const format = formatED->text();
1386 QString const gui_name = guiNameED->text();
1387 int const sel = form_->formats().getNumber(fromqstr(format));
1388 bool gui_name_known = false;
1390 for (int i = 0; i < formatsLW->count(); ++i) {
1391 if (formatsLW->item(i)->text() == gui_name) {
1392 gui_name_known = true;
1393 where = formatsLW->item(i)->type();
1397 // assure that a gui name cannot be chosen twice
1398 bool const known_otherwise = gui_name_known && (where != sel);
1400 bool const known = !(sel < 0);
1401 bool const valid = (!formatED->text().isEmpty()
1402 && !guiNameED->text().isEmpty());
1404 int const ftype = formatsLW->currentItem()->type();
1405 Format const & f(form_->formats().get(ftype));
1406 string const old_pretty(f.prettyname());
1407 string const old_shortcut(f.shortcut());
1408 string const old_extension(f.extension());
1409 string const old_viewer(f.viewer());
1410 string const old_editor(f.editor());
1411 bool const old_document(f.documentFormat());
1412 bool const old_vector(f.vectorFormat());
1414 string const new_pretty(fromqstr(gui_name));
1415 string const new_shortcut(fromqstr(shortcutED->text()));
1416 string const new_extension(fromqstr(extensionED->text()));
1417 string const new_viewer(fromqstr(viewerED->text()));
1418 string const new_editor(fromqstr(editorED->text()));
1419 bool const new_document(documentCB->isChecked());
1420 bool const new_vector(vectorCB->isChecked());
1422 bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
1423 || (old_extension != new_extension) || (old_viewer != new_viewer)
1424 || old_editor != new_editor || old_document != new_document
1425 || old_vector != new_vector);
1427 formatModifyPB->setEnabled(valid && known && modified && !known_otherwise);
1428 formatNewPB->setEnabled(valid && !known && !gui_name_known);
1429 formatRemovePB->setEnabled(known);
1433 void PrefFileformats::new_format()
1435 string const name = fromqstr(formatED->text());
1436 string const prettyname = fromqstr(guiNameED->text());
1437 string const extension = fromqstr(extensionED->text());
1438 string const shortcut = fromqstr(shortcutED->text());
1439 string const viewer = fromqstr(viewerED->text());
1440 string const editor = fromqstr(editorED->text());
1441 int flags = Format::none;
1442 if (documentCB->isChecked())
1443 flags |= Format::document;
1444 if (vectorCB->isChecked())
1445 flags |= Format::vector;
1447 form_->formats().add(name, extension, prettyname, shortcut, viewer,
1449 form_->formats().sort();
1450 form_->converters().update(form_->formats());
1458 void PrefFileformats::modify_format()
1460 int const current_item = formatsLW->currentItem()->type();
1461 Format const & oldformat = form_->formats().get(current_item);
1462 form_->formats().erase(oldformat.name());
1468 void PrefFileformats::remove_format()
1470 int const nr = formatsLW->currentItem()->type();
1471 string const current_text = form_->formats().get(nr).name();
1472 if (form_->converters().formatIsUsed(current_text)) {
1473 Alert::error(_("Format in use"),
1474 _("Cannot remove a Format used by a Converter. "
1475 "Remove the converter first."));
1479 form_->formats().erase(current_text);
1480 form_->converters().update(form_->formats());
1489 PrefLanguage::PrefLanguage(QWidget * parent)
1490 : PrefModule(_(LanguageSettings), _("Language"), 0, parent)
1494 connect(rtlCB, SIGNAL(clicked()),
1495 this, SIGNAL(changed()));
1496 connect(markForeignCB, SIGNAL(clicked()),
1497 this, SIGNAL(changed()));
1498 connect(autoBeginCB, SIGNAL(clicked()),
1499 this, SIGNAL(changed()));
1500 connect(autoEndCB, SIGNAL(clicked()),
1501 this, SIGNAL(changed()));
1502 connect(useBabelCB, SIGNAL(clicked()),
1503 this, SIGNAL(changed()));
1504 connect(globalCB, SIGNAL(clicked()),
1505 this, SIGNAL(changed()));
1506 connect(languagePackageED, SIGNAL(textChanged(const QString&)),
1507 this, SIGNAL(changed()));
1508 connect(startCommandED, SIGNAL(textChanged(const QString&)),
1509 this, SIGNAL(changed()));
1510 connect(endCommandED, SIGNAL(textChanged(const QString&)),
1511 this, SIGNAL(changed()));
1512 connect(defaultLanguageCO, SIGNAL(activated(int)),
1513 this, SIGNAL(changed()));
1515 defaultLanguageCO->clear();
1517 // store the lang identifiers for later
1518 std::vector<LanguagePair> const langs =
1519 lyx::frontend::getLanguageData(false);
1520 lang_ = getSecond(langs);
1522 std::vector<LanguagePair>::const_iterator lit = langs.begin();
1523 std::vector<LanguagePair>::const_iterator lend = langs.end();
1524 for (; lit != lend; ++lit) {
1525 defaultLanguageCO->addItem(toqstr(lit->first));
1530 void PrefLanguage::apply(LyXRC & rc) const
1532 // FIXME: remove rtl_support bool
1533 rc.rtl_support = rtlCB->isChecked();
1534 rc.mark_foreign_language = markForeignCB->isChecked();
1535 rc.language_auto_begin = autoBeginCB->isChecked();
1536 rc.language_auto_end = autoEndCB->isChecked();
1537 rc.language_use_babel = useBabelCB->isChecked();
1538 rc.language_global_options = globalCB->isChecked();
1539 rc.language_package = fromqstr(languagePackageED->text());
1540 rc.language_command_begin = fromqstr(startCommandED->text());
1541 rc.language_command_end = fromqstr(endCommandED->text());
1542 rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1546 void PrefLanguage::update(LyXRC const & rc)
1548 // FIXME: remove rtl_support bool
1549 rtlCB->setChecked(rc.rtl_support);
1550 markForeignCB->setChecked(rc.mark_foreign_language);
1551 autoBeginCB->setChecked(rc.language_auto_begin);
1552 autoEndCB->setChecked(rc.language_auto_end);
1553 useBabelCB->setChecked(rc.language_use_babel);
1554 globalCB->setChecked(rc.language_global_options);
1555 languagePackageED->setText(toqstr(rc.language_package));
1556 startCommandED->setText(toqstr(rc.language_command_begin));
1557 endCommandED->setText(toqstr(rc.language_command_end));
1559 int const pos = int(findPos_helper(lang_, rc.default_language));
1560 defaultLanguageCO->setCurrentIndex(pos);
1564 PrefPrinter::PrefPrinter(QWidget * parent)
1565 : PrefModule(_(Outputs), _("Printer"), 0, parent)
1569 connect(printerAdaptCB, SIGNAL(clicked()),
1570 this, SIGNAL(changed()));
1571 connect(printerCommandED, SIGNAL(textChanged(const QString&)),
1572 this, SIGNAL(changed()));
1573 connect(printerNameED, SIGNAL(textChanged(const QString&)),
1574 this, SIGNAL(changed()));
1575 connect(printerPageRangeED, SIGNAL(textChanged(const QString&)),
1576 this, SIGNAL(changed()));
1577 connect(printerCopiesED, SIGNAL(textChanged(const QString&)),
1578 this, SIGNAL(changed()));
1579 connect(printerReverseED, SIGNAL(textChanged(const QString&)),
1580 this, SIGNAL(changed()));
1581 connect(printerToPrinterED, SIGNAL(textChanged(const QString&)),
1582 this, SIGNAL(changed()));
1583 connect(printerExtensionED, SIGNAL(textChanged(const QString&)),
1584 this, SIGNAL(changed()));
1585 connect(printerSpoolCommandED, SIGNAL(textChanged(const QString&)),
1586 this, SIGNAL(changed()));
1587 connect(printerPaperTypeED, SIGNAL(textChanged(const QString&)),
1588 this, SIGNAL(changed()));
1589 connect(printerEvenED, SIGNAL(textChanged(const QString&)),
1590 this, SIGNAL(changed()));
1591 connect(printerOddED, SIGNAL(textChanged(const QString&)),
1592 this, SIGNAL(changed()));
1593 connect(printerCollatedED, SIGNAL(textChanged(const QString&)),
1594 this, SIGNAL(changed()));
1595 connect(printerLandscapeED, SIGNAL(textChanged(const QString&)),
1596 this, SIGNAL(changed()));
1597 connect(printerToFileED, SIGNAL(textChanged(const QString&)),
1598 this, SIGNAL(changed()));
1599 connect(printerExtraED, SIGNAL(textChanged(const QString&)),
1600 this, SIGNAL(changed()));
1601 connect(printerSpoolPrefixED, SIGNAL(textChanged(const QString&)),
1602 this, SIGNAL(changed()));
1603 connect(printerPaperSizeED, SIGNAL(textChanged(const QString&)),
1604 this, SIGNAL(changed()));
1608 void PrefPrinter::apply(LyXRC & rc) const
1610 rc.print_adapt_output = printerAdaptCB->isChecked();
1611 rc.print_command = fromqstr(printerCommandED->text());
1612 rc.printer = fromqstr(printerNameED->text());
1614 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1615 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1616 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1617 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1618 rc.print_file_extension = fromqstr(printerExtensionED->text());
1619 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1620 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1621 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1622 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1623 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1624 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1625 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1626 rc.print_extra_options = fromqstr(printerExtraED->text());
1627 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1628 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1632 void PrefPrinter::update(LyXRC const & rc)
1634 printerAdaptCB->setChecked(rc.print_adapt_output);
1635 printerCommandED->setText(toqstr(rc.print_command));
1636 printerNameED->setText(toqstr(rc.printer));
1638 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1639 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1640 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1641 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1642 printerExtensionED->setText(toqstr(rc.print_file_extension));
1643 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1644 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1645 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1646 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1647 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1648 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1649 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1650 printerExtraED->setText(toqstr(rc.print_extra_options));
1651 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1652 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1656 PrefUserInterface::PrefUserInterface(QPrefs * form, QWidget * parent)
1657 : PrefModule(_(LookAndFeel), _("User interface"), form, parent)
1661 connect(autoSaveCB, SIGNAL( toggled(bool) ), autoSaveLA, SLOT( setEnabled(bool) ) );
1662 connect(autoSaveCB, SIGNAL( toggled(bool) ), autoSaveSB, SLOT( setEnabled(bool) ) );
1663 connect(autoSaveCB, SIGNAL( toggled(bool) ), TextLabel1, SLOT( setEnabled(bool) ) );
1664 connect(uiFilePB, SIGNAL(clicked()), this, SLOT(select_ui()));
1665 connect(bindFilePB, SIGNAL(clicked()), this, SLOT(select_bind()));
1666 connect(uiFileED, SIGNAL(textChanged(const QString&)),
1667 this, SIGNAL(changed()));
1668 connect(bindFileED, SIGNAL(textChanged(const QString&)),
1669 this, SIGNAL(changed()));
1670 connect(restoreCursorCB, SIGNAL(clicked()),
1671 this, SIGNAL(changed()));
1672 connect(loadSessionCB, SIGNAL(clicked()),
1673 this, SIGNAL(changed()));
1674 connect(loadWindowSizeCB, SIGNAL(clicked()),
1675 this, SIGNAL(changed()));
1676 connect(loadWindowLocationCB, SIGNAL(clicked()),
1677 this, SIGNAL(changed()));
1678 connect(windowWidthSB, SIGNAL(valueChanged(int)),
1679 this, SIGNAL(changed()));
1680 connect(windowHeightSB, SIGNAL(valueChanged(int)),
1681 this, SIGNAL(changed()));
1682 connect(cursorFollowsCB, SIGNAL(clicked()),
1683 this, SIGNAL(changed()));
1684 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1685 this, SIGNAL(changed()));
1686 connect(autoSaveCB, SIGNAL(clicked()),
1687 this, SIGNAL(changed()));
1688 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1689 this, SIGNAL(changed()));
1690 lastfilesSB->setMaximum(maxlastfiles);
1694 void PrefUserInterface::apply(LyXRC & rc) const
1696 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1697 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1698 rc.use_lastfilepos = restoreCursorCB->isChecked();
1699 rc.load_session = loadSessionCB->isChecked();
1700 if (loadWindowSizeCB->isChecked()) {
1701 rc.geometry_width = 0;
1702 rc.geometry_height = 0;
1704 rc.geometry_width = windowWidthSB->value();
1705 rc.geometry_height = windowHeightSB->value();
1707 rc.geometry_xysaved = loadWindowLocationCB->isChecked();
1708 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1709 rc.autosave = autoSaveSB->value() * 60;
1710 rc.make_backup = autoSaveCB->isChecked();
1711 rc.num_lastfiles = lastfilesSB->value();
1715 void PrefUserInterface::update(LyXRC const & rc)
1717 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1718 bindFileED->setText(toqstr(external_path(rc.bind_file)));
1719 restoreCursorCB->setChecked(rc.use_lastfilepos);
1720 loadSessionCB->setChecked(rc.load_session);
1721 bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
1722 loadWindowSizeCB->setChecked(loadWindowSize);
1723 if (!loadWindowSize) {
1724 windowWidthSB->setValue(rc.geometry_width);
1725 windowHeightSB->setValue(rc.geometry_height);
1727 loadWindowLocationCB->setChecked(rc.geometry_xysaved);
1728 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1729 // convert to minutes
1730 int mins(rc.autosave / 60);
1731 if (rc.autosave && !mins)
1733 autoSaveSB->setValue(mins);
1734 autoSaveCB->setChecked(rc.make_backup);
1735 lastfilesSB->setValue(rc.num_lastfiles);
1740 void PrefUserInterface::select_ui()
1742 docstring const name =
1743 from_utf8(internal_path(fromqstr(uiFileED->text())));
1744 docstring file(form_->controller().browseUI(name));
1746 uiFileED->setText(toqstr(file));
1750 void PrefUserInterface::select_bind()
1752 docstring const name =
1753 from_utf8(internal_path(fromqstr(bindFileED->text())));
1754 docstring file(form_->controller().browsebind(name));
1756 bindFileED->setText(toqstr(file));
1760 void PrefUserInterface::on_loadWindowSizeCB_toggled(bool loadwindowsize)
1762 windowWidthLA->setDisabled(loadwindowsize);
1763 windowHeightLA->setDisabled(loadwindowsize);
1764 windowWidthSB->setDisabled(loadwindowsize);
1765 windowHeightSB->setDisabled(loadwindowsize);
1769 PrefIdentity::PrefIdentity(QWidget * parent)
1770 : PrefModule(docstring(), _("Identity"), 0, parent)
1774 connect(nameED, SIGNAL(textChanged(const QString&)),
1775 this, SIGNAL(changed()));
1776 connect(emailED, SIGNAL(textChanged(const QString&)),
1777 this, SIGNAL(changed()));
1781 void PrefIdentity::apply(LyXRC & rc) const
1783 rc.user_name = fromqstr(nameED->text());
1784 rc.user_email = fromqstr(emailED->text());
1788 void PrefIdentity::update(LyXRC const & rc)
1790 nameED->setText(toqstr(rc.user_name));
1791 emailED->setText(toqstr(rc.user_email));
1796 QPrefsDialog::QPrefsDialog(QPrefs * form)
1800 QDialog::setModal(false);
1802 connect(savePB, SIGNAL(clicked()),
1803 form, SLOT(slotOK()));
1804 connect(applyPB, SIGNAL(clicked()),
1805 form, SLOT(slotApply()));
1806 connect(closePB, SIGNAL(clicked()),
1807 form, SLOT(slotClose()));
1808 connect(restorePB, SIGNAL(clicked()),
1809 form, SLOT(slotRestore()));
1811 add(new PrefUserInterface(form_));
1812 add(new PrefScreenFonts(form_));
1813 add(new PrefColors(form_));
1814 add(new PrefDisplay);
1815 add(new PrefKeyboard(form_));
1817 add(new PrefPaths(form_));
1819 add(new PrefIdentity);
1821 add(new PrefLanguage);
1822 add(new PrefSpellchecker(form_));
1824 add(new PrefPrinter);
1826 add(new PrefPlaintext);
1827 add(new PrefLatex(form_));
1829 #if defined(__CYGWIN__) || defined(_WIN32)
1830 add(new PrefCygwinPath);
1834 PrefConverters * converters = new PrefConverters(form_);
1835 PrefFileformats * formats = new PrefFileformats(form_);
1836 connect(formats, SIGNAL(formatsChanged()),
1837 converters, SLOT(updateGui()));
1841 add(new PrefCopiers(form_));
1844 prefsPS->setCurrentPanel(_("User interface"));
1845 // FIXME: hack to work around resizing bug in Qt >= 4.2
1846 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1847 #if QT_VERSION >= 0x040200
1848 prefsPS->updateGeometry();
1851 form_->bcview().setOK(savePB);
1852 form_->bcview().setApply(applyPB);
1853 form_->bcview().setCancel(closePB);
1854 form_->bcview().setRestore(restorePB);
1858 QPrefsDialog::~QPrefsDialog()
1863 void QPrefsDialog::add(PrefModule * module)
1865 BOOST_ASSERT(module);
1867 // if (module->category().empty())
1868 // prefsPS->addPanel(module, module->title());
1870 prefsPS->addPanel(module, module->title(), module->category());
1872 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
1874 modules_.push_back(module);
1877 void QPrefsDialog::closeEvent(QCloseEvent * e)
1879 form_->slotWMHide();
1884 void QPrefsDialog::change_adaptor()
1890 void QPrefsDialog::apply(LyXRC & rc) const
1892 size_t end = modules_.size();
1893 for (size_t i = 0; i != end; ++i)
1894 modules_[i]->apply(rc);
1898 void QPrefsDialog::updateRc(LyXRC const & rc)
1900 size_t end = modules_.size();
1901 for (size_t i = 0; i != end; ++i)
1902 modules_[i]->update(rc);
1906 } // namespace frontend
1909 #include "QPrefsDialog_moc.cpp"