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()));
882 void PrefConverters::apply(LyXRC & /*rc*/) const
887 void PrefConverters::update(LyXRC const & /*rc*/)
893 void PrefConverters::updateGui()
895 // save current selection
896 QString current = converterFromCO->currentText()
897 + " -> " + converterToCO->currentText();
899 converterFromCO->clear();
900 converterToCO->clear();
902 Formats::const_iterator cit = form_->formats().begin();
903 Formats::const_iterator end = form_->formats().end();
904 for (; cit != end; ++cit) {
905 converterFromCO->addItem(toqstr(cit->prettyname()));
906 converterToCO->addItem(toqstr(cit->prettyname()));
909 // currentRowChanged(int) is also triggered when updating the listwidget
910 // block signals to avoid unnecessary calls to switch_converter()
911 convertersLW->blockSignals(true);
912 convertersLW->clear();
914 Converters::const_iterator ccit = form_->converters().begin();
915 Converters::const_iterator cend = form_->converters().end();
916 for (; ccit != cend; ++ccit) {
917 std::string const name =
918 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
919 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
920 new QListWidgetItem(toqstr(name), convertersLW, type);
922 convertersLW->sortItems(Qt::AscendingOrder);
923 convertersLW->blockSignals(false);
926 if (!current.isEmpty()) {
927 QList<QListWidgetItem *> const item =
928 convertersLW->findItems(current, Qt::MatchExactly);
930 convertersLW->setCurrentItem(item.at(0));
933 // select first element if restoring failed
934 if (convertersLW->currentRow() == -1)
935 convertersLW->setCurrentRow(0);
941 void PrefConverters::switch_converter()
943 int const cnr = convertersLW->currentItem()->type();
944 Converter const & c(form_->converters().get(cnr));
945 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
946 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
947 converterED->setText(toqstr(c.command));
948 converterFlagED->setText(toqstr(c.flags));
954 void PrefConverters::converter_changed()
960 void PrefConverters::updateButtons()
962 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
963 Format const & to(form_->formats().get(converterToCO->currentIndex()));
964 int const sel = form_->converters().getNumber(from.name(), to.name());
965 bool const known = !(sel < 0);
966 bool const valid = !(converterED->text().isEmpty()
967 || from.name() == to.name());
969 int const cnr = convertersLW->currentItem()->type();
970 Converter const & c(form_->converters().get(cnr));
971 string const old_command = c.command;
972 string const old_flag = c.flags;
973 string const new_command(fromqstr(converterED->text()));
974 string const new_flag(fromqstr(converterFlagED->text()));
976 bool modified = ((old_command != new_command) || (old_flag != new_flag));
978 converterModifyPB->setEnabled(valid && known && modified);
979 converterNewPB->setEnabled(valid && !known);
980 converterRemovePB->setEnabled(known);
985 // specify unique from/to or it doesn't appear. This is really bad UI
986 // this is why we can use the same function for both new and modify
987 void PrefConverters::update_converter()
989 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
990 Format const & to(form_->formats().get(converterToCO->currentIndex()));
991 string const flags = fromqstr(converterFlagED->text());
992 string const command = fromqstr(converterED->text());
994 Converter const * old = form_->converters().getConverter(from.name(), to.name());
995 form_->converters().add(from.name(), to.name(), command, flags);
997 form_->converters().updateLast(form_->formats());
1004 void PrefConverters::remove_converter()
1006 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1007 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1008 form_->converters().erase(from.name(), to.name());
1014 PrefCopiers::PrefCopiers(QPrefs * form, QWidget * parent)
1015 : PrefModule(docstring(), _("Copiers"), form, parent)
1019 connect(copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
1020 connect(copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
1021 connect(copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
1022 connect(AllCopiersLW, SIGNAL(currentRowChanged(int)),
1023 this, SLOT(switch_copierLB(int)));
1024 connect(copierFormatCO, SIGNAL(activated(int)), this, SLOT(switch_copierCO(int)));
1025 connect(copierNewPB, SIGNAL(clicked()),
1026 this, SIGNAL(changed()));
1027 connect(copierRemovePB, SIGNAL(clicked()),
1028 this, SIGNAL(changed()));
1029 connect(copierModifyPB, SIGNAL(clicked()),
1030 this, SIGNAL(changed()));
1031 connect(copierFormatCO, SIGNAL(activated(const QString&)), this, SLOT(copiers_changed()));
1032 connect(copierED, SIGNAL(textChanged(const QString&)), this, SLOT(copiers_changed()));
1036 void PrefCopiers::apply(LyXRC & /*rc*/) const
1041 void PrefCopiers::update(LyXRC const & /*rc*/)
1047 void PrefCopiers::update()
1049 // The choice widget
1050 // save current selection
1051 QString current = copierFormatCO->currentText();
1052 copierFormatCO->clear();
1054 for (Formats::const_iterator it = form_->formats().begin(),
1055 end = form_->formats().end();
1057 copierFormatCO->addItem(toqstr(it->prettyname()));
1060 // The browser widget
1061 AllCopiersLW->clear();
1063 for (Movers::const_iterator it = form_->movers().begin(),
1064 end = form_->movers().end();
1066 std::string const & command = it->second.command();
1067 if (command.empty())
1069 QString const pretty = toqstr(form_->formats().prettyName(it->first));
1070 AllCopiersLW->addItem(pretty);
1072 AllCopiersLW->sortItems(Qt::AscendingOrder);
1074 // restore selection
1075 if (!current.isEmpty()) {
1076 QList<QListWidgetItem *> item =
1077 AllCopiersLW->findItems(current, Qt::MatchExactly);
1079 AllCopiersLW->setCurrentItem(item.at(0));
1081 // select first element if restoring failed
1082 if (AllCopiersLW->currentRow() == -1)
1083 AllCopiersLW->setCurrentRow(0);
1089 class SamePrettyName {
1091 SamePrettyName(string const & n) : pretty_name_(n) {}
1093 bool operator()(lyx::Format const & fmt) const {
1094 return fmt.prettyname() == pretty_name_;
1098 string const pretty_name_;
1102 Format const * getFormat(std::string const & prettyname)
1104 Formats::const_iterator it = lyx::formats.begin();
1105 Formats::const_iterator const end = lyx::formats.end();
1106 it = std::find_if(it, end, SamePrettyName(prettyname));
1107 return it == end ? 0 : &*it;
1113 void PrefCopiers::switch_copierLB(int row)
1119 std::string const browser_text =
1120 fromqstr(AllCopiersLW->currentItem()->text());
1121 Format const * fmt = getFormat(browser_text);
1125 QString const gui_name = toqstr(fmt->prettyname());
1126 QString const command = toqstr(form_->movers().command(fmt->name()));
1129 int const combo_size = copierFormatCO->count();
1130 for (int i = 0; i < combo_size; ++i) {
1131 QString const text = copierFormatCO->itemText(i);
1132 if (text == gui_name) {
1133 copierFormatCO->setCurrentIndex(i);
1134 copierED->setText(command);
1142 void PrefCopiers::switch_copierCO(int row)
1147 std::string const combo_text =
1148 fromqstr(copierFormatCO->currentText());
1149 Format const * fmt = getFormat(combo_text);
1153 QString const command = toqstr(form_->movers().command(fmt->name()));
1154 copierED->setText(command);
1156 QListWidgetItem * const index = AllCopiersLW->currentItem();
1158 AllCopiersLW->setItemSelected(index, false);
1160 QString const gui_name = toqstr(fmt->prettyname());
1161 int const browser_size = AllCopiersLW->count();
1162 for (int i = 0; i < browser_size; ++i) {
1163 QString const text = AllCopiersLW->item(i)->text();
1164 if (text == gui_name) {
1165 QListWidgetItem * item = AllCopiersLW->item(i);
1166 AllCopiersLW->setItemSelected(item, true);
1173 void PrefCopiers::copiers_changed()
1179 void PrefCopiers::updateButtons()
1181 QString selected = copierFormatCO->currentText();
1184 for (int i = 0; i < AllCopiersLW->count(); ++i) {
1185 if (AllCopiersLW->item(i)->text() == selected)
1189 bool const valid = !copierED->text().isEmpty();
1191 Format const * fmt = getFormat(fromqstr(selected));
1192 string const old_command = form_->movers().command(fmt->name());
1193 string const new_command(fromqstr(copierED->text()));
1195 bool modified = (old_command != new_command);
1197 copierModifyPB->setEnabled(valid && known && modified);
1198 copierNewPB->setEnabled(valid && !known);
1199 copierRemovePB->setEnabled(known);
1203 void PrefCopiers::new_copier()
1205 std::string const combo_text =
1206 fromqstr(copierFormatCO->currentText());
1207 Format const * fmt = getFormat(combo_text);
1211 string const command = fromqstr(copierED->text());
1212 if (command.empty())
1215 form_->movers().set(fmt->name(), command);
1218 int const last = AllCopiersLW->count() - 1;
1219 AllCopiersLW->setCurrentRow(last);
1225 void PrefCopiers::modify_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 form_->movers().set(fmt->name(), command);
1241 void PrefCopiers::remove_copier()
1243 std::string const combo_text =
1244 fromqstr(copierFormatCO->currentText());
1245 Format const * fmt = getFormat(combo_text);
1249 string const & fmt_name = fmt->name();
1250 form_->movers().set(fmt_name, string());
1258 PrefFileformats::PrefFileformats(QPrefs * form, QWidget * parent)
1259 : PrefModule(docstring(), _("File formats"), form, parent)
1263 connect(formatNewPB, SIGNAL(clicked()),
1264 this, SLOT(new_format()));
1265 connect(formatRemovePB, SIGNAL(clicked()),
1266 this, SLOT(remove_format()));
1267 connect(formatModifyPB, SIGNAL(clicked()),
1268 this, SLOT(modify_format()));
1269 connect(formatsLW, SIGNAL(currentRowChanged(int)),
1270 this, SLOT(switch_format(int)));
1271 connect(formatED, SIGNAL(textChanged(const QString&)),
1272 this, SLOT(fileformat_changed()));
1273 connect(guiNameED, SIGNAL(textChanged(const QString&)),
1274 this, SLOT(fileformat_changed()));
1275 connect(shortcutED, SIGNAL(textChanged(const QString&)),
1276 this, SLOT(fileformat_changed()));
1277 connect(extensionED, SIGNAL(textChanged(const QString&)),
1278 this, SLOT(fileformat_changed()));
1279 connect(viewerED, SIGNAL(textChanged(const QString&)),
1280 this, SLOT(fileformat_changed()));
1281 connect(editorED, SIGNAL(textChanged(const QString&)),
1282 this, SLOT(fileformat_changed()));
1283 connect(documentCB, SIGNAL(clicked()),
1284 this, SLOT(fileformat_changed()));
1285 connect(vectorCB, SIGNAL(clicked()),
1286 this, SLOT(fileformat_changed()));
1287 connect(formatNewPB, SIGNAL(clicked()),
1288 this, SIGNAL(changed()));
1289 connect(formatRemovePB, SIGNAL(clicked()),
1290 this, SIGNAL(changed()));
1291 connect(formatModifyPB, SIGNAL(clicked()),
1292 this, SIGNAL(changed()));
1296 void PrefFileformats::apply(LyXRC & /*rc*/) const
1301 void PrefFileformats::update(LyXRC const & /*rc*/)
1307 void PrefFileformats::update()
1309 // save current selection
1310 QString current = guiNameED->text();
1312 // update listwidget with formats
1313 formatsLW->blockSignals(true);
1315 Formats::const_iterator cit = form_->formats().begin();
1316 Formats::const_iterator end = form_->formats().end();
1317 for (; cit != end; ++cit) {
1318 new QListWidgetItem(toqstr(cit->prettyname()),
1320 form_->formats().getNumber(cit->name()) );
1322 formatsLW->sortItems(Qt::AscendingOrder);
1323 formatsLW->blockSignals(false);
1325 // restore selection
1326 if (!current.isEmpty()) {
1327 QList<QListWidgetItem *> item = formatsLW->findItems(current, Qt::MatchExactly);
1329 formatsLW->setCurrentItem(item.at(0));
1331 // select first element if restoring failed
1332 if (formatsLW->currentRow() == -1)
1333 formatsLW->setCurrentRow(0);
1337 void PrefFileformats::switch_format(int nr)
1339 int const ftype = formatsLW->item(nr)->type();
1340 Format const f = form_->formats().get(ftype);
1342 formatED->setText(toqstr(f.name()));
1343 guiNameED->setText(toqstr(f.prettyname()));
1344 extensionED->setText(toqstr(f.extension()));
1345 shortcutED->setText(toqstr(f.shortcut()));
1346 viewerED->setText(toqstr(f.viewer()));
1347 editorED->setText(toqstr(f.editor()));
1348 documentCB->setChecked((f.documentFormat()));
1349 vectorCB->setChecked((f.vectorFormat()));
1355 void PrefFileformats::fileformat_changed()
1361 void PrefFileformats::updateButtons()
1363 QString const format = formatED->text();
1364 QString const gui_name = guiNameED->text();
1365 int const sel = form_->formats().getNumber(fromqstr(format));
1366 bool gui_name_known = false;
1368 for (int i = 0; i < formatsLW->count(); ++i) {
1369 if (formatsLW->item(i)->text() == gui_name) {
1370 gui_name_known = true;
1371 where = formatsLW->item(i)->type();
1375 // assure that a gui name cannot be chosen twice
1376 bool const known_otherwise = gui_name_known && (where != sel);
1378 bool const known = !(sel < 0);
1379 bool const valid = (!formatED->text().isEmpty()
1380 && !guiNameED->text().isEmpty());
1382 int const ftype = formatsLW->currentItem()->type();
1383 Format const & f(form_->formats().get(ftype));
1384 string const old_pretty(f.prettyname());
1385 string const old_shortcut(f.shortcut());
1386 string const old_extension(f.extension());
1387 string const old_viewer(f.viewer());
1388 string const old_editor(f.editor());
1389 bool const old_document(f.documentFormat());
1390 bool const old_vector(f.vectorFormat());
1392 string const new_pretty(fromqstr(gui_name));
1393 string const new_shortcut(fromqstr(shortcutED->text()));
1394 string const new_extension(fromqstr(extensionED->text()));
1395 string const new_viewer(fromqstr(viewerED->text()));
1396 string const new_editor(fromqstr(editorED->text()));
1397 bool const new_document(documentCB->isChecked());
1398 bool const new_vector(vectorCB->isChecked());
1400 bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
1401 || (old_extension != new_extension) || (old_viewer != new_viewer)
1402 || old_editor != new_editor || old_document != new_document
1403 || old_vector != new_vector);
1405 formatModifyPB->setEnabled(valid && known && modified && !known_otherwise);
1406 formatNewPB->setEnabled(valid && !known && !gui_name_known);
1407 formatRemovePB->setEnabled(known);
1411 void PrefFileformats::new_format()
1413 string const name = fromqstr(formatED->text());
1414 string const prettyname = fromqstr(guiNameED->text());
1415 string const extension = fromqstr(extensionED->text());
1416 string const shortcut = fromqstr(shortcutED->text());
1417 string const viewer = fromqstr(viewerED->text());
1418 string const editor = fromqstr(editorED->text());
1419 int flags = Format::none;
1420 if (documentCB->isChecked())
1421 flags |= Format::document;
1422 if (vectorCB->isChecked())
1423 flags |= Format::vector;
1425 form_->formats().add(name, extension, prettyname, shortcut, viewer,
1427 form_->formats().sort();
1428 form_->converters().update(form_->formats());
1436 void PrefFileformats::modify_format()
1438 int const current_item = formatsLW->currentItem()->type();
1439 Format const & oldformat = form_->formats().get(current_item);
1440 form_->formats().erase(oldformat.name());
1446 void PrefFileformats::remove_format()
1448 int const nr = formatsLW->currentItem()->type();
1449 string const current_text = form_->formats().get(nr).name();
1450 if (form_->converters().formatIsUsed(current_text)) {
1451 Alert::error(_("Format in use"),
1452 _("Cannot remove a Format used by a Converter. "
1453 "Remove the converter first."));
1457 form_->formats().erase(current_text);
1458 form_->converters().update(form_->formats());
1467 PrefLanguage::PrefLanguage(QWidget * parent)
1468 : PrefModule(docstring(), _("Language"), 0, parent)
1472 connect(rtlCB, SIGNAL(clicked()),
1473 this, SIGNAL(changed()));
1474 connect(markForeignCB, SIGNAL(clicked()),
1475 this, SIGNAL(changed()));
1476 connect(autoBeginCB, SIGNAL(clicked()),
1477 this, SIGNAL(changed()));
1478 connect(autoEndCB, SIGNAL(clicked()),
1479 this, SIGNAL(changed()));
1480 connect(useBabelCB, SIGNAL(clicked()),
1481 this, SIGNAL(changed()));
1482 connect(globalCB, SIGNAL(clicked()),
1483 this, SIGNAL(changed()));
1484 connect(languagePackageED, SIGNAL(textChanged(const QString&)),
1485 this, SIGNAL(changed()));
1486 connect(startCommandED, SIGNAL(textChanged(const QString&)),
1487 this, SIGNAL(changed()));
1488 connect(endCommandED, SIGNAL(textChanged(const QString&)),
1489 this, SIGNAL(changed()));
1490 connect(defaultLanguageCO, SIGNAL(activated(int)),
1491 this, SIGNAL(changed()));
1493 defaultLanguageCO->clear();
1495 // store the lang identifiers for later
1496 std::vector<LanguagePair> const langs =
1497 lyx::frontend::getLanguageData(false);
1498 lang_ = getSecond(langs);
1500 std::vector<LanguagePair>::const_iterator lit = langs.begin();
1501 std::vector<LanguagePair>::const_iterator lend = langs.end();
1502 for (; lit != lend; ++lit) {
1503 defaultLanguageCO->addItem(toqstr(lit->first));
1508 void PrefLanguage::apply(LyXRC & rc) const
1510 // FIXME: remove rtl_support bool
1511 rc.rtl_support = rtlCB->isChecked();
1512 rc.mark_foreign_language = markForeignCB->isChecked();
1513 rc.language_auto_begin = autoBeginCB->isChecked();
1514 rc.language_auto_end = autoEndCB->isChecked();
1515 rc.language_use_babel = useBabelCB->isChecked();
1516 rc.language_global_options = globalCB->isChecked();
1517 rc.language_package = fromqstr(languagePackageED->text());
1518 rc.language_command_begin = fromqstr(startCommandED->text());
1519 rc.language_command_end = fromqstr(endCommandED->text());
1520 rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1524 void PrefLanguage::update(LyXRC const & rc)
1526 // FIXME: remove rtl_support bool
1527 rtlCB->setChecked(rc.rtl_support);
1528 markForeignCB->setChecked(rc.mark_foreign_language);
1529 autoBeginCB->setChecked(rc.language_auto_begin);
1530 autoEndCB->setChecked(rc.language_auto_end);
1531 useBabelCB->setChecked(rc.language_use_babel);
1532 globalCB->setChecked(rc.language_global_options);
1533 languagePackageED->setText(toqstr(rc.language_package));
1534 startCommandED->setText(toqstr(rc.language_command_begin));
1535 endCommandED->setText(toqstr(rc.language_command_end));
1537 int const pos = int(findPos_helper(lang_, rc.default_language));
1538 defaultLanguageCO->setCurrentIndex(pos);
1542 PrefPrinter::PrefPrinter(QWidget * parent)
1543 : PrefModule(_(Outputs), _("Printer"), 0, parent)
1547 connect(printerAdaptCB, SIGNAL(clicked()),
1548 this, SIGNAL(changed()));
1549 connect(printerCommandED, SIGNAL(textChanged(const QString&)),
1550 this, SIGNAL(changed()));
1551 connect(printerNameED, SIGNAL(textChanged(const QString&)),
1552 this, SIGNAL(changed()));
1553 connect(printerPageRangeED, SIGNAL(textChanged(const QString&)),
1554 this, SIGNAL(changed()));
1555 connect(printerCopiesED, SIGNAL(textChanged(const QString&)),
1556 this, SIGNAL(changed()));
1557 connect(printerReverseED, SIGNAL(textChanged(const QString&)),
1558 this, SIGNAL(changed()));
1559 connect(printerToPrinterED, SIGNAL(textChanged(const QString&)),
1560 this, SIGNAL(changed()));
1561 connect(printerExtensionED, SIGNAL(textChanged(const QString&)),
1562 this, SIGNAL(changed()));
1563 connect(printerSpoolCommandED, SIGNAL(textChanged(const QString&)),
1564 this, SIGNAL(changed()));
1565 connect(printerPaperTypeED, SIGNAL(textChanged(const QString&)),
1566 this, SIGNAL(changed()));
1567 connect(printerEvenED, SIGNAL(textChanged(const QString&)),
1568 this, SIGNAL(changed()));
1569 connect(printerOddED, SIGNAL(textChanged(const QString&)),
1570 this, SIGNAL(changed()));
1571 connect(printerCollatedED, SIGNAL(textChanged(const QString&)),
1572 this, SIGNAL(changed()));
1573 connect(printerLandscapeED, SIGNAL(textChanged(const QString&)),
1574 this, SIGNAL(changed()));
1575 connect(printerToFileED, SIGNAL(textChanged(const QString&)),
1576 this, SIGNAL(changed()));
1577 connect(printerExtraED, SIGNAL(textChanged(const QString&)),
1578 this, SIGNAL(changed()));
1579 connect(printerSpoolPrefixED, SIGNAL(textChanged(const QString&)),
1580 this, SIGNAL(changed()));
1581 connect(printerPaperSizeED, SIGNAL(textChanged(const QString&)),
1582 this, SIGNAL(changed()));
1586 void PrefPrinter::apply(LyXRC & rc) const
1588 rc.print_adapt_output = printerAdaptCB->isChecked();
1589 rc.print_command = fromqstr(printerCommandED->text());
1590 rc.printer = fromqstr(printerNameED->text());
1592 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1593 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1594 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1595 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1596 rc.print_file_extension = fromqstr(printerExtensionED->text());
1597 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1598 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1599 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1600 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1601 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1602 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1603 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1604 rc.print_extra_options = fromqstr(printerExtraED->text());
1605 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1606 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1610 void PrefPrinter::update(LyXRC const & rc)
1612 printerAdaptCB->setChecked(rc.print_adapt_output);
1613 printerCommandED->setText(toqstr(rc.print_command));
1614 printerNameED->setText(toqstr(rc.printer));
1616 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1617 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1618 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1619 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1620 printerExtensionED->setText(toqstr(rc.print_file_extension));
1621 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1622 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1623 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1624 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1625 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1626 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1627 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1628 printerExtraED->setText(toqstr(rc.print_extra_options));
1629 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1630 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1634 PrefUserInterface::PrefUserInterface(QPrefs * form, QWidget * parent)
1635 : PrefModule(_(LookAndFeel), _("User interface"), form, parent)
1639 connect(autoSaveCB, SIGNAL( toggled(bool) ), autoSaveLA, SLOT( setEnabled(bool) ) );
1640 connect(autoSaveCB, SIGNAL( toggled(bool) ), autoSaveSB, SLOT( setEnabled(bool) ) );
1641 connect(autoSaveCB, SIGNAL( toggled(bool) ), TextLabel1, SLOT( setEnabled(bool) ) );
1642 connect(uiFilePB, SIGNAL(clicked()), this, SLOT(select_ui()));
1643 connect(bindFilePB, SIGNAL(clicked()), this, SLOT(select_bind()));
1644 connect(uiFileED, SIGNAL(textChanged(const QString&)),
1645 this, SIGNAL(changed()));
1646 connect(bindFileED, SIGNAL(textChanged(const QString&)),
1647 this, SIGNAL(changed()));
1648 connect(restoreCursorCB, SIGNAL(clicked()),
1649 this, SIGNAL(changed()));
1650 connect(loadSessionCB, SIGNAL(clicked()),
1651 this, SIGNAL(changed()));
1652 connect(loadWindowSizeCB, SIGNAL(clicked()),
1653 this, SIGNAL(changed()));
1654 connect(loadWindowLocationCB, SIGNAL(clicked()),
1655 this, SIGNAL(changed()));
1656 connect(windowWidthSB, SIGNAL(valueChanged(int)),
1657 this, SIGNAL(changed()));
1658 connect(windowHeightSB, SIGNAL(valueChanged(int)),
1659 this, SIGNAL(changed()));
1660 connect(cursorFollowsCB, SIGNAL(clicked()),
1661 this, SIGNAL(changed()));
1662 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1663 this, SIGNAL(changed()));
1664 connect(autoSaveCB, SIGNAL(clicked()),
1665 this, SIGNAL(changed()));
1666 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1667 this, SIGNAL(changed()));
1668 lastfilesSB->setMaximum(maxlastfiles);
1672 void PrefUserInterface::apply(LyXRC & rc) const
1674 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1675 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1676 rc.use_lastfilepos = restoreCursorCB->isChecked();
1677 rc.load_session = loadSessionCB->isChecked();
1678 if (loadWindowSizeCB->isChecked()) {
1679 rc.geometry_width = 0;
1680 rc.geometry_height = 0;
1682 rc.geometry_width = windowWidthSB->value();
1683 rc.geometry_height = windowHeightSB->value();
1685 rc.geometry_xysaved = loadWindowLocationCB->isChecked();
1686 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1687 rc.autosave = autoSaveSB->value() * 60;
1688 rc.make_backup = autoSaveCB->isChecked();
1689 rc.num_lastfiles = lastfilesSB->value();
1693 void PrefUserInterface::update(LyXRC const & rc)
1695 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1696 bindFileED->setText(toqstr(external_path(rc.bind_file)));
1697 restoreCursorCB->setChecked(rc.use_lastfilepos);
1698 loadSessionCB->setChecked(rc.load_session);
1699 bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
1700 loadWindowSizeCB->setChecked(loadWindowSize);
1701 if (!loadWindowSize) {
1702 windowWidthSB->setValue(rc.geometry_width);
1703 windowHeightSB->setValue(rc.geometry_height);
1705 loadWindowLocationCB->setChecked(rc.geometry_xysaved);
1706 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1707 // convert to minutes
1708 int mins(rc.autosave / 60);
1709 if (rc.autosave && !mins)
1711 autoSaveSB->setValue(mins);
1712 autoSaveCB->setChecked(rc.make_backup);
1713 lastfilesSB->setValue(rc.num_lastfiles);
1718 void PrefUserInterface::select_ui()
1720 docstring const name =
1721 from_utf8(internal_path(fromqstr(uiFileED->text())));
1722 docstring file(form_->controller().browseUI(name));
1724 uiFileED->setText(toqstr(file));
1728 void PrefUserInterface::select_bind()
1730 docstring const name =
1731 from_utf8(internal_path(fromqstr(bindFileED->text())));
1732 docstring file(form_->controller().browsebind(name));
1734 bindFileED->setText(toqstr(file));
1738 void PrefUserInterface::on_loadWindowSizeCB_toggled(bool loadwindowsize)
1740 windowWidthLA->setDisabled(loadwindowsize);
1741 windowHeightLA->setDisabled(loadwindowsize);
1742 windowWidthSB->setDisabled(loadwindowsize);
1743 windowHeightSB->setDisabled(loadwindowsize);
1747 PrefIdentity::PrefIdentity(QWidget * parent)
1748 : PrefModule(docstring(), _("Identity"), 0, parent)
1752 connect(nameED, SIGNAL(textChanged(const QString&)),
1753 this, SIGNAL(changed()));
1754 connect(emailED, SIGNAL(textChanged(const QString&)),
1755 this, SIGNAL(changed()));
1759 void PrefIdentity::apply(LyXRC & rc) const
1761 rc.user_name = fromqstr(nameED->text());
1762 rc.user_email = fromqstr(emailED->text());
1766 void PrefIdentity::update(LyXRC const & rc)
1768 nameED->setText(toqstr(rc.user_name));
1769 emailED->setText(toqstr(rc.user_email));
1774 QPrefsDialog::QPrefsDialog(QPrefs * form)
1778 QDialog::setModal(false);
1780 connect(savePB, SIGNAL(clicked()),
1781 form, SLOT(slotOK()));
1782 connect(applyPB, SIGNAL(clicked()),
1783 form, SLOT(slotApply()));
1784 connect(closePB, SIGNAL(clicked()),
1785 form, SLOT(slotClose()));
1786 connect(restorePB, SIGNAL(clicked()),
1787 form, SLOT(slotRestore()));
1789 add(new PrefPlaintext);
1791 add(new PrefKeyboard(form_));
1792 add(new PrefLatex(form_));
1793 add(new PrefScreenFonts(form_));
1794 add(new PrefColors(form_));
1796 #if defined(__CYGWIN__) || defined(_WIN32)
1797 add(new PrefCygwinPath);
1800 add(new PrefDisplay);
1801 add(new PrefPaths(form_));
1802 add(new PrefSpellchecker(form_));
1804 PrefConverters * converters = new PrefConverters(form_);
1805 PrefFileformats * formats = new PrefFileformats(form_);
1806 connect(formats, SIGNAL(formatsChanged()),
1807 converters, SLOT(updateGui()));
1811 add(new PrefCopiers(form_));
1813 add(new PrefLanguage);
1814 add(new PrefPrinter);
1815 add(new PrefUserInterface(form_));
1816 add(new PrefIdentity);
1818 prefsPS->setCurrentPanel(_("User interface"));
1819 // FIXME: hack to work around resizing bug in Qt >= 4.2
1820 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1821 #if QT_VERSION >= 0x040200
1822 prefsPS->updateGeometry();
1825 form_->bcview().setOK(savePB);
1826 form_->bcview().setApply(applyPB);
1827 form_->bcview().setCancel(closePB);
1828 form_->bcview().setRestore(restorePB);
1832 QPrefsDialog::~QPrefsDialog()
1837 void QPrefsDialog::add(PrefModule * module)
1839 BOOST_ASSERT(module);
1841 // if (module->category().empty())
1842 // prefsPS->addPanel(module, module->title());
1844 prefsPS->addPanel(module, module->title(), module->category());
1846 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
1848 modules_.push_back(module);
1851 void QPrefsDialog::closeEvent(QCloseEvent * e)
1853 form_->slotWMHide();
1858 void QPrefsDialog::change_adaptor()
1864 void QPrefsDialog::apply(LyXRC & rc) const
1866 size_t end = modules_.size();
1867 for (size_t i = 0; i != end; ++i)
1868 modules_[i]->apply(rc);
1872 void QPrefsDialog::updateRc(LyXRC const & rc)
1874 size_t end = modules_.size();
1875 for (size_t i = 0; i != end; ++i)
1876 modules_[i]->update(rc);
1880 } // namespace frontend
1883 #include "QPrefsDialog_moc.cpp"