3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Abdelrazak Younes
9 * Full author contact details are available in file CREDITS.
16 #include "GuiApplication.h"
17 #include "qt_helpers.h"
24 #include "support/lstrings.h"
25 #include "support/os.h"
27 #include "controllers/ControlPrefs.h"
28 #include "controllers/frnt_lang.h"
29 #include "controllers/helper_funcs.h"
31 #include "frontends/Alert.h"
32 #include "frontends/Application.h"
34 #include "QPrefsDialog.h"
37 #include "panelstack.h"
38 #include "qfontexample.h"
43 #include "controllers/ControlPrefs.h"
46 #include <QColorDialog>
47 #include <QFontDatabase>
49 #include <QPushButton>
53 #include <QCloseEvent>
55 #include <boost/tuple/tuple.hpp>
59 using lyx::support::compare_no_case;
66 using std::ostringstream;
74 string const LookAndFeel = N_("Look and feel");
75 string const LanguageSettings = N_("Language settings");
76 string const Outputs = N_("Outputs");
79 // FIXME: move to helper_funcs.h
83 typename std::vector<A>::size_type
84 findPos(std::vector<A> const & vec, A const & val)
86 typedef typename std::vector<A>::const_iterator Cit;
88 Cit it = std::find(vec.begin(), vec.end(), val);
91 return distance(vec.begin(), it);
94 void setComboxFont(QComboBox * cb, string const & family, string const & foundry)
96 string const name = makeFontName(family, foundry);
97 for (int i = 0; i < cb->count(); ++i) {
98 if (fromqstr(cb->itemText(i)) == name) {
99 cb->setCurrentIndex(i);
104 // Try matching without foundry name
106 // We count in reverse in order to prefer the Xft foundry
107 for (int i = cb->count() - 1; i >= 0; --i) {
108 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
109 if (compare_no_case(tmp.first, family) == 0) {
110 cb->setCurrentIndex(i);
115 // family alone can contain e.g. "Helvetica [Adobe]"
116 pair<string, string> tmpfam = parseFontName(family);
118 // We count in reverse in order to prefer the Xft foundry
119 for (int i = cb->count() - 1; i >= 0; --i) {
120 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
121 if (compare_no_case(tmp.first, tmpfam.first) == 0) {
122 cb->setCurrentIndex(i);
127 // Bleh, default fonts, and the names couldn't be found. Hack
128 // for bug 1063. Qt makes baby Jesus cry.
131 font.setKerning(false);
133 if (family == theApp()->romanFontName()) {
134 font.setStyleHint(QFont::Serif);
135 font.setFamily(family.c_str());
136 } else if (family == theApp()->sansFontName()) {
137 font.setStyleHint(QFont::SansSerif);
138 font.setFamily(family.c_str());
139 } else if (family == theApp()->typewriterFontName()) {
140 font.setStyleHint(QFont::TypeWriter);
141 font.setFamily(family.c_str());
143 lyxerr << "FAILED to find the default font: '"
144 << foundry << "', '" << family << '\''<< endl;
148 QFontInfo info(font);
149 pair<string, string> tmp = parseFontName(fromqstr(info.family()));
150 string const & default_font_name = tmp.first;
151 lyxerr << "Apparent font is " << default_font_name << endl;
153 for (int i = 0; i < cb->count(); ++i) {
154 lyxerr << "Looking at " << fromqstr(cb->itemText(i)) << endl;
155 if (compare_no_case(fromqstr(cb->itemText(i)),
156 default_font_name) == 0) {
157 cb->setCurrentIndex(i);
162 lyxerr << "FAILED to find the font: '"
163 << foundry << "', '" << family << '\'' <<endl;
167 QString const external_path(string const & input)
169 return toqstr(lyx::support::os::external_path(input));
173 QString const external_path_list(string const & input)
175 return toqstr(lyx::support::os::external_path_list(input));
179 string const internal_path(QString const & input)
181 return lyx::support::os::internal_path(fromqstr(input));
185 string const internal_path_list(QString const & input)
187 return lyx::support::os::internal_path_list(fromqstr(input));
190 } // end namespace anon
193 PrefAscii::PrefAscii(QWidget * parent)
194 : PrefModule(_(Outputs), _("Plain text"), 0, parent)
197 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
198 this, SIGNAL(changed()));
199 connect(plaintextRoffED, SIGNAL(textChanged(const QString&)),
200 this, SIGNAL(changed()));
204 void PrefAscii::apply(LyXRC & rc) const
206 rc.plaintext_linelen = plaintextLinelengthSB->value();
207 rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
211 void PrefAscii::update(LyXRC const & rc)
213 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
214 plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
218 PrefDate::PrefDate(QWidget * parent)
219 : PrefModule(_(Outputs), _("Date format"), 0, parent)
222 connect(DateED, SIGNAL(textChanged(const QString&)),
223 this, SIGNAL(changed()));
227 void PrefDate::apply(LyXRC & rc) const
229 rc.date_insert_format = fromqstr(DateED->text());
233 void PrefDate::update(LyXRC const & rc)
235 DateED->setText(toqstr(rc.date_insert_format));
239 PrefKeyboard::PrefKeyboard(QPrefs * form, QWidget * parent)
240 : PrefModule(_(LookAndFeel), _("Keyboard"), form, parent)
244 connect(keymapCB, SIGNAL( toggled(bool) ),
245 firstKeymapLA, SLOT( setEnabled(bool) ) );
246 connect(keymapCB, SIGNAL( toggled(bool) ),
247 secondKeymapLA, SLOT( setEnabled(bool) ) );
248 connect(keymapCB, SIGNAL( toggled(bool) ),
249 firstKeymapED, SLOT( setEnabled(bool) ) );
250 connect(keymapCB, SIGNAL( toggled(bool) ),
251 secondKeymapED, SLOT( setEnabled(bool) ) );
252 connect(keymapCB, SIGNAL( toggled(bool) ),
253 firstKeymapPB, SLOT( setEnabled(bool) ) );
254 connect(keymapCB, SIGNAL( toggled(bool) ),
255 secondKeymapPB, SLOT( setEnabled(bool) ) );
257 connect(keymapCB, SIGNAL(toggled(bool)),
258 this, SIGNAL(changed()));
259 connect(firstKeymapED, SIGNAL(textChanged(const QString&)),
260 this, SIGNAL(changed()));
261 connect(secondKeymapED, SIGNAL(textChanged(const QString&)),
262 this, SIGNAL(changed()));
266 void PrefKeyboard::apply(LyXRC & rc) const
268 // FIXME: can derive CB from the two EDs
269 rc.use_kbmap = keymapCB->isChecked();
270 rc.primary_kbmap = internal_path(firstKeymapED->text());
271 rc.secondary_kbmap = internal_path(secondKeymapED->text());
275 void PrefKeyboard::update(LyXRC const & rc)
277 // FIXME: can derive CB from the two EDs
278 keymapCB->setChecked(rc.use_kbmap);
279 // no idea why we need these. Fscking Qt.
280 firstKeymapED->setEnabled(rc.use_kbmap);
281 firstKeymapPB->setEnabled(rc.use_kbmap);
282 firstKeymapLA->setEnabled(rc.use_kbmap);
283 secondKeymapED->setEnabled(rc.use_kbmap);
284 secondKeymapPB->setEnabled(rc.use_kbmap);
285 secondKeymapLA->setEnabled(rc.use_kbmap);
286 firstKeymapED->setText(external_path(rc.primary_kbmap));
287 secondKeymapED->setText(external_path(rc.secondary_kbmap));
291 QString PrefKeyboard::testKeymap(QString keymap)
293 return toqstr(form_->controller().browsekbmap(qstring_to_ucs4(keymap)));
297 void PrefKeyboard::on_firstKeymapPB_clicked(bool)
299 QString file = testKeymap(firstKeymapED->text());
301 firstKeymapED->setText(file);
305 void PrefKeyboard::on_secondKeymapPB_clicked(bool)
307 QString file = testKeymap(secondKeymapED->text());
309 secondKeymapED->setText(file);
313 PrefLatex::PrefLatex(QPrefs * form, QWidget * parent)
314 : PrefModule(_(Outputs), _("LaTeX"), form, parent)
317 connect(latexEncodingED, SIGNAL(textChanged(const QString&)),
318 this, SIGNAL(changed()));
319 connect(latexChecktexED, SIGNAL(textChanged(const QString&)),
320 this, SIGNAL(changed()));
321 connect(latexBibtexED, SIGNAL(textChanged(const QString&)),
322 this, SIGNAL(changed()));
323 connect(latexIndexED, SIGNAL(textChanged(const QString&)),
324 this, SIGNAL(changed()));
325 connect(latexAutoresetCB, SIGNAL(toggled(bool)),
326 this, SIGNAL(changed()));
327 connect(latexDviPaperED, SIGNAL(textChanged(const QString&)),
328 this, SIGNAL(changed()));
329 connect(latexPaperSizeCO, SIGNAL(activated(int)),
330 this, SIGNAL(changed()));
334 void PrefLatex::apply(LyXRC & rc) const
336 rc.fontenc = fromqstr(latexEncodingED->text());
337 rc.chktex_command = fromqstr(latexChecktexED->text());
338 rc.bibtex_command = fromqstr(latexBibtexED->text());
339 rc.index_command = fromqstr(latexIndexED->text());
340 rc.auto_reset_options = latexAutoresetCB->isChecked();
341 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
342 rc.default_papersize =
343 form_->controller().toPaperSize(latexPaperSizeCO->currentIndex());
347 void PrefLatex::update(LyXRC const & rc)
349 latexEncodingED->setText(toqstr(rc.fontenc));
350 latexChecktexED->setText(toqstr(rc.chktex_command));
351 latexBibtexED->setText(toqstr(rc.bibtex_command));
352 latexIndexED->setText(toqstr(rc.index_command));
353 latexAutoresetCB->setChecked(rc.auto_reset_options);
354 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
355 latexPaperSizeCO->setCurrentIndex(
356 form_->controller().fromPaperSize(rc.default_papersize));
360 PrefScreenFonts::PrefScreenFonts(QPrefs * form, QWidget * parent)
361 : PrefModule(_(LookAndFeel), _("Screen fonts"), form, parent)
365 connect(screenRomanCO, SIGNAL(activated(const QString&)),
366 this, SLOT(select_roman(const QString&)));
367 connect(screenSansCO, SIGNAL(activated(const QString&)),
368 this, SLOT(select_sans(const QString&)));
369 connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
370 this, SLOT(select_typewriter(const QString&)));
372 QFontDatabase fontdb;
373 QStringList families(fontdb.families());
374 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
375 screenRomanCO->addItem(*it);
376 screenSansCO->addItem(*it);
377 screenTypewriterCO->addItem(*it);
379 connect(screenRomanCO, SIGNAL(activated(const QString&)),
380 this, SIGNAL(changed()));
381 connect(screenSansCO, SIGNAL(activated(const QString&)),
382 this, SIGNAL(changed()));
383 connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
384 this, SIGNAL(changed()));
385 connect(screenZoomSB, SIGNAL(valueChanged(int)),
386 this, SIGNAL(changed()));
387 connect(screenDpiSB, SIGNAL(valueChanged(int)),
388 this, SIGNAL(changed()));
389 connect(screenTinyED, SIGNAL(textChanged(const QString&)),
390 this, SIGNAL(changed()));
391 connect(screenSmallestED, SIGNAL(textChanged(const QString&)),
392 this, SIGNAL(changed()));
393 connect(screenSmallerED, SIGNAL(textChanged(const QString&)),
394 this, SIGNAL(changed()));
395 connect(screenSmallED, SIGNAL(textChanged(const QString&)),
396 this, SIGNAL(changed()));
397 connect(screenNormalED, SIGNAL(textChanged(const QString&)),
398 this, SIGNAL(changed()));
399 connect(screenLargeED, SIGNAL(textChanged(const QString&)),
400 this, SIGNAL(changed()));
401 connect(screenLargerED, SIGNAL(textChanged(const QString&)),
402 this, SIGNAL(changed()));
403 connect(screenLargestED, SIGNAL(textChanged(const QString&)),
404 this, SIGNAL(changed()));
405 connect(screenHugeED, SIGNAL(textChanged(const QString&)),
406 this, SIGNAL(changed()));
407 connect(screenHugerED, SIGNAL(textChanged(const QString&)),
408 this, SIGNAL(changed()));
410 screenTinyED->setValidator(new QDoubleValidator(
412 screenSmallestED->setValidator(new QDoubleValidator(
414 screenSmallerED->setValidator(new QDoubleValidator(
416 screenSmallED->setValidator(new QDoubleValidator(
418 screenNormalED->setValidator(new QDoubleValidator(
420 screenLargeED->setValidator(new QDoubleValidator(
422 screenLargerED->setValidator(new QDoubleValidator(
424 screenLargestED->setValidator(new QDoubleValidator(
426 screenHugeED->setValidator(new QDoubleValidator(
428 screenHugerED->setValidator(new QDoubleValidator(
433 void PrefScreenFonts::apply(LyXRC & rc) const
435 LyXRC const oldrc(rc);
437 boost::tie(rc.roman_font_name, rc.roman_font_foundry)
438 = parseFontName(fromqstr(screenRomanCO->currentText()));
439 boost::tie(rc.sans_font_name, rc.sans_font_foundry) =
440 parseFontName(fromqstr(screenSansCO->currentText()));
441 boost::tie(rc.typewriter_font_name, rc.typewriter_font_foundry) =
442 parseFontName(fromqstr(screenTypewriterCO->currentText()));
444 rc.zoom = screenZoomSB->value();
445 rc.dpi = screenDpiSB->value();
446 rc.font_sizes[LyXFont::SIZE_TINY] = fromqstr(screenTinyED->text());
447 rc.font_sizes[LyXFont::SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
448 rc.font_sizes[LyXFont::SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
449 rc.font_sizes[LyXFont::SIZE_SMALL] = fromqstr(screenSmallED->text());
450 rc.font_sizes[LyXFont::SIZE_NORMAL] = fromqstr(screenNormalED->text());
451 rc.font_sizes[LyXFont::SIZE_LARGE] = fromqstr(screenLargeED->text());
452 rc.font_sizes[LyXFont::SIZE_LARGER] = fromqstr(screenLargerED->text());
453 rc.font_sizes[LyXFont::SIZE_LARGEST] = fromqstr(screenLargestED->text());
454 rc.font_sizes[LyXFont::SIZE_HUGE] = fromqstr(screenHugeED->text());
455 rc.font_sizes[LyXFont::SIZE_HUGER] = fromqstr(screenHugerED->text());
457 if (rc.font_sizes != oldrc.font_sizes
458 || rc.roman_font_name != oldrc.roman_font_name
459 || rc.sans_font_name != oldrc.sans_font_name
460 || rc.typewriter_font_name != oldrc.typewriter_font_name
461 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
462 form_->controller().updateScreenFonts();
467 void PrefScreenFonts::update(LyXRC const & rc)
469 setComboxFont(screenRomanCO, rc.roman_font_name,
470 rc.roman_font_foundry);
471 setComboxFont(screenSansCO, rc.sans_font_name,
472 rc.sans_font_foundry);
473 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
474 rc.typewriter_font_foundry);
476 select_roman(screenRomanCO->currentText());
477 select_sans(screenSansCO->currentText());
478 select_typewriter(screenTypewriterCO->currentText());
480 screenZoomSB->setValue(rc.zoom);
481 screenDpiSB->setValue(rc.dpi);
482 screenTinyED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_TINY]));
483 screenSmallestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SCRIPT]));
484 screenSmallerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_FOOTNOTE]));
485 screenSmallED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SMALL]));
486 screenNormalED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_NORMAL]));
487 screenLargeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGE]));
488 screenLargerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGER]));
489 screenLargestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGEST]));
490 screenHugeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_HUGE]));
491 screenHugerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_HUGER]));
494 void PrefScreenFonts::select_roman(const QString& name)
496 screenRomanFE->set(QFont(name), name);
500 void PrefScreenFonts::select_sans(const QString& name)
502 screenSansFE->set(QFont(name), name);
506 void PrefScreenFonts::select_typewriter(const QString& name)
508 screenTypewriterFE->set(QFont(name), name);
512 PrefColors::PrefColors(QPrefs * form, QWidget * parent)
513 : PrefModule(_(LookAndFeel), _("Colors"), form, parent)
517 // FIXME: put in controller
518 for (int i = 0; i < LColor::ignore; ++i) {
519 LColor::color lc = static_cast<LColor::color>(i);
520 if (lc == LColor::none
521 || lc == LColor::black
522 || lc == LColor::white
524 || lc == LColor::green
525 || lc == LColor::blue
526 || lc == LColor::cyan
527 || lc == LColor::magenta
528 || lc == LColor::yellow
529 || lc == LColor::inherit
530 || lc == LColor::ignore) continue;
532 lcolors_.push_back(lc);
533 QColor color = QColor(guiApp->colorCache().get(lc));
534 prefcolors_.push_back(color.name());
535 QPixmap coloritem(32, 32);
536 coloritem.fill(color);
537 // This is not a memory leak:
538 /*QListWidgetItem * newItem =*/ new QListWidgetItem(QIcon(coloritem),
539 toqstr(lcolor.getGUIName(lc)), lyxObjectsLW);
541 newcolors_ = prefcolors_;
543 connect(colorChangePB, SIGNAL(clicked()),
544 this, SLOT(change_color()));
545 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
546 this, SLOT(change_color()));
550 void PrefColors::apply(LyXRC & /*rc*/) const
552 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
553 if (prefcolors_[i]!=newcolors_[i])
554 form_->controller().setColor(lcolors_[i], fromqstr(newcolors_[i]));
559 void PrefColors::update(LyXRC const & /*rc*/)
563 void PrefColors::change_color()
565 int const row = lyxObjectsLW->currentRow();
566 QString color = newcolors_[row];
567 QColor c(QColorDialog::getColor(QColor(color),
568 qApp->focusWidget()));
570 if (c.name()!=color) {
571 newcolors_[row] = c.name();
572 QPixmap coloritem(32, 32);
574 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
581 PrefCygwinPath::PrefCygwinPath(QWidget * parent)
582 : PrefModule(_(Outputs), _("Paths"), 0, parent)
585 connect(pathCB, SIGNAL(toggled(bool)),
586 this, SIGNAL(changed()));
590 void PrefCygwinPath::apply(LyXRC & rc) const
592 rc.windows_style_tex_paths = pathCB->isChecked();
596 void PrefCygwinPath::update(LyXRC const & rc)
598 pathCB->setChecked(rc.windows_style_tex_paths);
602 PrefDisplay::PrefDisplay(QWidget * parent)
603 : PrefModule(_(LookAndFeel), _("Graphics"), 0, parent)
606 connect(instantPreviewCO, SIGNAL(activated(int)),
607 this, SIGNAL(changed()));
608 connect(displayGraphicsCO, SIGNAL(activated(int)),
609 this, SIGNAL(changed()));
613 void PrefDisplay::apply(LyXRC & rc) const
615 switch (instantPreviewCO->currentIndex()) {
616 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
617 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
618 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
621 lyx::graphics::DisplayType dtype;
622 switch (displayGraphicsCO->currentIndex()) {
623 case 3: dtype = lyx::graphics::NoDisplay; break;
624 case 2: dtype = lyx::graphics::ColorDisplay; break;
625 case 1: dtype = lyx::graphics::GrayscaleDisplay; break;
626 case 0: dtype = lyx::graphics::MonochromeDisplay; break;
627 default: dtype = lyx::graphics::GrayscaleDisplay;
629 rc.display_graphics = dtype;
632 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
635 if (old_value != rc.display_graphics) {
636 lyx::graphics::GCache & gc = lyx::graphics::GCache::get();
643 void PrefDisplay::update(LyXRC const & rc)
645 switch (rc.preview) {
646 case LyXRC::PREVIEW_OFF:
647 instantPreviewCO->setCurrentIndex(0);
649 case LyXRC::PREVIEW_NO_MATH :
650 instantPreviewCO->setCurrentIndex(1);
652 case LyXRC::PREVIEW_ON :
653 instantPreviewCO->setCurrentIndex(2);
658 switch (rc.display_graphics) {
659 case lyx::graphics::NoDisplay: item = 3; break;
660 case lyx::graphics::ColorDisplay: item = 2; break;
661 case lyx::graphics::GrayscaleDisplay: item = 1; break;
662 case lyx::graphics::MonochromeDisplay: item = 0; break;
665 displayGraphicsCO->setCurrentIndex(item);
669 PrefPaths::PrefPaths(QPrefs * form, QWidget * parent)
670 : PrefModule(docstring(), _("Paths"), form, parent)
673 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
674 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
675 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
676 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
677 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
678 connect(workingDirED, SIGNAL(textChanged(const QString&)),
679 this, SIGNAL(changed()));
680 connect(templateDirED, SIGNAL(textChanged(const QString&)),
681 this, SIGNAL(changed()));
682 connect(backupDirED, SIGNAL(textChanged(const QString&)),
683 this, SIGNAL(changed()));
684 connect(tempDirED, SIGNAL(textChanged(const QString&)),
685 this, SIGNAL(changed()));
686 connect(lyxserverDirED, SIGNAL(textChanged(const QString&)),
687 this, SIGNAL(changed()));
688 connect(pathPrefixED, SIGNAL(textChanged(const QString&)),
689 this, SIGNAL(changed()));
693 void PrefPaths::apply(LyXRC & rc) const
695 rc.document_path = internal_path(workingDirED->text());
696 rc.template_path = internal_path(templateDirED->text());
697 rc.backupdir_path = internal_path(backupDirED->text());
698 rc.tempdir_path = internal_path(tempDirED->text());
699 rc.path_prefix = internal_path_list(pathPrefixED->text());
700 // FIXME: should be a checkbox only
701 rc.lyxpipes = internal_path(lyxserverDirED->text());
705 void PrefPaths::update(LyXRC const & rc)
707 workingDirED->setText(external_path(rc.document_path));
708 templateDirED->setText(external_path(rc.template_path));
709 backupDirED->setText(external_path(rc.backupdir_path));
710 tempDirED->setText(external_path(rc.tempdir_path));
711 pathPrefixED->setText(external_path_list(rc.path_prefix));
712 // FIXME: should be a checkbox only
713 lyxserverDirED->setText(external_path(rc.lyxpipes));
716 void PrefPaths::select_templatedir()
718 docstring file(form_->controller().browsedir(
719 qstring_to_ucs4(templateDirED->text()),
720 _("Select a document templates directory")));
722 templateDirED->setText(toqstr(file));
726 void PrefPaths::select_tempdir()
728 docstring file(form_->controller().browsedir(
729 qstring_to_ucs4(tempDirED->text()),
730 _("Select a temporary directory")));
732 tempDirED->setText(toqstr(file));
736 void PrefPaths::select_backupdir()
738 docstring file(form_->controller().browsedir(
739 qstring_to_ucs4(backupDirED->text()),
740 _("Select a backups directory")));
742 backupDirED->setText(toqstr(file));
746 void PrefPaths::select_workingdir()
748 docstring file(form_->controller().browsedir(
749 qstring_to_ucs4(workingDirED->text()),
750 _("Select a document directory")));
752 workingDirED->setText(toqstr(file));
756 void PrefPaths::select_lyxpipe()
758 docstring file(form_->controller().browse(
759 qstring_to_ucs4(lyxserverDirED->text()),
760 _("Give a filename for the LyX server pipe")));
762 lyxserverDirED->setText(toqstr(file));
766 PrefSpellchecker::PrefSpellchecker(QPrefs * form, QWidget * parent)
767 : PrefModule(_(LanguageSettings), _("Spellchecker"), form, parent)
771 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
772 #if defined (USE_ISPELL)
773 connect(spellCommandCO, SIGNAL(activated(int)),
774 this, SIGNAL(changed()));
776 spellCommandCO->setEnabled(false);
778 connect(altLanguageED, SIGNAL(textChanged(const QString&)),
779 this, SIGNAL(changed()));
780 connect(escapeCharactersED, SIGNAL(textChanged(const QString&)),
781 this, SIGNAL(changed()));
782 connect(persDictionaryED, SIGNAL(textChanged(const QString&)),
783 this, SIGNAL(changed()));
784 connect(compoundWordCB, SIGNAL(toggled(bool)),
785 this, SIGNAL(changed()));
786 connect(inputEncodingCB, SIGNAL(toggled(bool)),
787 this, SIGNAL(changed()));
789 spellCommandCO->addItem(qt_("ispell"));
790 spellCommandCO->addItem(qt_("aspell"));
791 spellCommandCO->addItem(qt_("hspell"));
793 spellCommandCO->addItem(qt_("pspell (library)"));
796 spellCommandCO->addItem(qt_("aspell (library)"));
802 void PrefSpellchecker::apply(LyXRC & rc) const
804 switch (spellCommandCO->currentIndex()) {
808 rc.use_spell_lib = false;
809 rc.isp_command = fromqstr(spellCommandCO->currentText());
812 rc.use_spell_lib = true;
816 // FIXME: remove isp_use_alt_lang
817 rc.isp_alt_lang = fromqstr(altLanguageED->text());
818 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
819 // FIXME: remove isp_use_esc_chars
820 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
821 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
822 // FIXME: remove isp_use_pers_dict
823 rc.isp_pers_dict = internal_path(persDictionaryED->text());
824 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
825 rc.isp_accept_compound = compoundWordCB->isChecked();
826 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
830 void PrefSpellchecker::update(LyXRC const & rc)
832 spellCommandCO->setCurrentIndex(0);
834 if (rc.isp_command == "ispell") {
835 spellCommandCO->setCurrentIndex(0);
836 } else if (rc.isp_command == "aspell") {
837 spellCommandCO->setCurrentIndex(1);
838 } else if (rc.isp_command == "hspell") {
839 spellCommandCO->setCurrentIndex(2);
842 if (rc.use_spell_lib) {
843 #if defined(USE_ASPELL) || defined(USE_PSPELL)
844 spellCommandCO->setCurrentIndex(3);
848 // FIXME: remove isp_use_alt_lang
849 altLanguageED->setText(toqstr(rc.isp_alt_lang));
850 // FIXME: remove isp_use_esc_chars
851 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
852 // FIXME: remove isp_use_pers_dict
853 persDictionaryED->setText(external_path(rc.isp_pers_dict));
854 compoundWordCB->setChecked(rc.isp_accept_compound);
855 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
859 void PrefSpellchecker::select_dict()
861 docstring file(form_->controller().browsedict(qstring_to_ucs4(persDictionaryED->text())));
863 persDictionaryED->setText(toqstr(file));
867 PrefConverters::PrefConverters(QPrefs * form, QWidget * parent)
868 : PrefModule(docstring(), _("Converters"), form, parent)
872 connect(converterNewPB, SIGNAL(clicked()),
873 this, SLOT(update_converter()));
874 connect(converterRemovePB, SIGNAL(clicked()),
875 this, SLOT(remove_converter()));
876 connect(converterModifyPB, SIGNAL(clicked()),
877 this, SLOT(update_converter()));
878 connect(convertersLW, SIGNAL(currentRowChanged(int)),
879 this, SLOT(switch_converter()));
880 connect(converterFromCO, SIGNAL(activated(const QString&)),
881 this, SLOT(converter_changed()));
882 connect(converterToCO, SIGNAL(activated(const QString&)),
883 this, SLOT(converter_changed()));
884 connect(converterED, SIGNAL(textChanged(const QString&)),
885 this, SLOT(converter_changed()));
886 connect(converterFlagED, SIGNAL(textChanged(const QString&)),
887 this, SLOT(converter_changed()));
888 connect(converterNewPB, SIGNAL(clicked()),
889 this, SIGNAL(changed()));
890 connect(converterRemovePB, SIGNAL(clicked()),
891 this, SIGNAL(changed()));
892 connect(converterModifyPB, SIGNAL(clicked()),
893 this, SIGNAL(changed()));
897 void PrefConverters::apply(LyXRC & /*rc*/) const
902 void PrefConverters::update(LyXRC const & /*rc*/)
908 void PrefConverters::updateGui()
910 // save current selection
911 QString current = converterFromCO->currentText()
912 + " -> " + converterToCO->currentText();
914 converterFromCO->clear();
915 converterToCO->clear();
917 Formats::const_iterator cit = form_->formats().begin();
918 Formats::const_iterator end = form_->formats().end();
919 for (; cit != end; ++cit) {
920 converterFromCO->addItem(toqstr(cit->prettyname()));
921 converterToCO->addItem(toqstr(cit->prettyname()));
924 // currentRowChanged(int) is also triggered when updating the listwidget
925 // block signals to avoid unnecessary calls to switch_converter()
926 convertersLW->blockSignals(true);
927 convertersLW->clear();
929 Converters::const_iterator ccit = form_->converters().begin();
930 Converters::const_iterator cend = form_->converters().end();
931 for (; ccit != cend; ++ccit) {
932 std::string const name =
933 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
934 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
935 new QListWidgetItem(toqstr(name), convertersLW, type);
937 convertersLW->sortItems(Qt::AscendingOrder);
938 convertersLW->blockSignals(false);
941 if (!current.isEmpty()) {
942 QList<QListWidgetItem *> const item =
943 convertersLW->findItems(current, Qt::MatchExactly);
945 convertersLW->setCurrentItem(item.at(0));
948 // select first element if restoring failed
949 if (convertersLW->currentRow() == -1)
950 convertersLW->setCurrentRow(0);
956 void PrefConverters::switch_converter()
958 int const cnr = convertersLW->currentItem()->type();
959 Converter const & c(form_->converters().get(cnr));
960 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
961 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
962 converterED->setText(toqstr(c.command));
963 converterFlagED->setText(toqstr(c.flags));
969 void PrefConverters::converter_changed()
975 void PrefConverters::updateButtons()
977 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
978 Format const & to(form_->formats().get(converterToCO->currentIndex()));
979 int const sel = form_->converters().getNumber(from.name(), to.name());
980 bool const known = !(sel < 0);
981 bool const valid = !(converterED->text().isEmpty()
982 || from.name() == to.name());
984 int const cnr = convertersLW->currentItem()->type();
985 Converter const & c(form_->converters().get(cnr));
986 string const old_command = c.command;
987 string const old_flag = c.flags;
988 string const new_command(fromqstr(converterED->text()));
989 string const new_flag(fromqstr(converterFlagED->text()));
991 bool modified = ((old_command != new_command) || (old_flag != new_flag));
993 converterModifyPB->setEnabled(valid && known && modified);
994 converterNewPB->setEnabled(valid && !known);
995 converterRemovePB->setEnabled(known);
1000 // specify unique from/to or it doesn't appear. This is really bad UI
1001 // this is why we can use the same function for both new and modify
1002 void PrefConverters::update_converter()
1004 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1005 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1006 string const flags = fromqstr(converterFlagED->text());
1007 string const command = fromqstr(converterED->text());
1009 Converter const * old = form_->converters().getConverter(from.name(), to.name());
1010 form_->converters().add(from.name(), to.name(), command, flags);
1012 form_->converters().updateLast(form_->formats());
1019 void PrefConverters::remove_converter()
1021 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1022 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1023 form_->converters().erase(from.name(), to.name());
1029 PrefCopiers::PrefCopiers(QPrefs * form, QWidget * parent)
1030 : PrefModule(docstring(), _("Copiers"), form, parent)
1034 connect(copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
1035 connect(copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
1036 connect(copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
1037 connect(AllCopiersLW, SIGNAL(currentRowChanged(int)),
1038 this, SLOT(switch_copierLB(int)));
1039 connect(copierFormatCO, SIGNAL(activated(int)), this, SLOT(switch_copierCO(int)));
1040 connect(copierNewPB, SIGNAL(clicked()),
1041 this, SIGNAL(changed()));
1042 connect(copierRemovePB, SIGNAL(clicked()),
1043 this, SIGNAL(changed()));
1044 connect(copierModifyPB, SIGNAL(clicked()),
1045 this, SIGNAL(changed()));
1046 connect(copierFormatCO, SIGNAL(activated(const QString&)), this, SLOT(copiers_changed()));
1047 connect(copierED, SIGNAL(textChanged(const QString&)), this, SLOT(copiers_changed()));
1051 void PrefCopiers::apply(LyXRC & /*rc*/) const
1056 void PrefCopiers::update(LyXRC const & /*rc*/)
1062 void PrefCopiers::update()
1064 // The choice widget
1065 // save current selection
1066 QString current = copierFormatCO->currentText();
1067 copierFormatCO->clear();
1069 for (Formats::const_iterator it = form_->formats().begin(),
1070 end = form_->formats().end();
1072 copierFormatCO->addItem(toqstr(it->prettyname()));
1075 // The browser widget
1076 AllCopiersLW->clear();
1078 for (Movers::iterator it = form_->movers().begin(),
1079 end = form_->movers().end();
1081 std::string const & command = it->second.command();
1082 if (command.empty())
1084 QString const pretty = toqstr(form_->formats().prettyName(it->first));
1085 AllCopiersLW->addItem(pretty);
1087 AllCopiersLW->sortItems(Qt::AscendingOrder);
1089 // restore selection
1090 if (!current.isEmpty()) {
1091 QList<QListWidgetItem *> item =
1092 AllCopiersLW->findItems(current, Qt::MatchExactly);
1094 AllCopiersLW->setCurrentItem(item.at(0));
1096 // select first element if restoring failed
1097 if (AllCopiersLW->currentRow() == -1)
1098 AllCopiersLW->setCurrentRow(0);
1104 class SamePrettyName {
1106 SamePrettyName(string const & n) : pretty_name_(n) {}
1108 bool operator()(lyx::Format const & fmt) const {
1109 return fmt.prettyname() == pretty_name_;
1113 string const pretty_name_;
1117 Format const * getFormat(std::string const & prettyname)
1119 Formats::const_iterator it = lyx::formats.begin();
1120 Formats::const_iterator const end = lyx::formats.end();
1121 it = std::find_if(it, end, SamePrettyName(prettyname));
1122 return it == end ? 0 : &*it;
1128 void PrefCopiers::switch_copierLB(int row)
1134 std::string const browser_text =
1135 fromqstr(AllCopiersLW->currentItem()->text());
1136 Format const * fmt = getFormat(browser_text);
1140 QString const gui_name = toqstr(fmt->prettyname());
1141 QString const command = toqstr(form_->movers().command(fmt->name()));
1144 int const combo_size = copierFormatCO->count();
1145 for (int i = 0; i < combo_size; ++i) {
1146 QString const text = copierFormatCO->itemText(i);
1147 if (text == gui_name) {
1148 copierFormatCO->setCurrentIndex(i);
1149 copierED->setText(command);
1157 void PrefCopiers::switch_copierCO(int row)
1162 std::string const combo_text =
1163 fromqstr(copierFormatCO->currentText());
1164 Format const * fmt = getFormat(combo_text);
1168 QString const command = toqstr(form_->movers().command(fmt->name()));
1169 copierED->setText(command);
1171 QListWidgetItem * const index = AllCopiersLW->currentItem();
1173 AllCopiersLW->setItemSelected(index, false);
1175 QString const gui_name = toqstr(fmt->prettyname());
1176 int const browser_size = AllCopiersLW->count();
1177 for (int i = 0; i < browser_size; ++i) {
1178 QString const text = AllCopiersLW->item(i)->text();
1179 if (text == gui_name) {
1180 QListWidgetItem * item = AllCopiersLW->item(i);
1181 AllCopiersLW->setItemSelected(item, true);
1188 void PrefCopiers::copiers_changed()
1194 void PrefCopiers::updateButtons()
1196 QString selected = copierFormatCO->currentText();
1199 for (int i = 0; i < AllCopiersLW->count(); ++i) {
1200 if (AllCopiersLW->item(i)->text() == selected)
1204 bool const valid = !copierED->text().isEmpty();
1206 Format const * fmt = getFormat(fromqstr(selected));
1207 string const old_command = form_->movers().command(fmt->name());
1208 string const new_command(fromqstr(copierED->text()));
1210 bool modified = (old_command != new_command);
1212 copierModifyPB->setEnabled(valid && known && modified);
1213 copierNewPB->setEnabled(valid && !known);
1214 copierRemovePB->setEnabled(known);
1218 void PrefCopiers::new_copier()
1220 std::string const combo_text =
1221 fromqstr(copierFormatCO->currentText());
1222 Format const * fmt = getFormat(combo_text);
1226 string const command = fromqstr(copierED->text());
1227 if (command.empty())
1230 form_->movers().set(fmt->name(), command);
1233 int const last = AllCopiersLW->count() - 1;
1234 AllCopiersLW->setCurrentRow(last);
1240 void PrefCopiers::modify_copier()
1242 std::string const combo_text =
1243 fromqstr(copierFormatCO->currentText());
1244 Format const * fmt = getFormat(combo_text);
1248 string const command = fromqstr(copierED->text());
1249 form_->movers().set(fmt->name(), command);
1256 void PrefCopiers::remove_copier()
1258 std::string const combo_text =
1259 fromqstr(copierFormatCO->currentText());
1260 Format const * fmt = getFormat(combo_text);
1264 string const & fmt_name = fmt->name();
1265 form_->movers().set(fmt_name, string());
1273 PrefFileformats::PrefFileformats(QPrefs * form, QWidget * parent)
1274 : PrefModule(docstring(), _("File formats"), form, parent)
1278 connect(formatNewPB, SIGNAL(clicked()),
1279 this, SLOT(new_format()));
1280 connect(formatRemovePB, SIGNAL(clicked()),
1281 this, SLOT(remove_format()));
1282 connect(formatModifyPB, SIGNAL(clicked()),
1283 this, SLOT(modify_format()));
1284 connect(formatsLW, SIGNAL(currentRowChanged(int)),
1285 this, SLOT(switch_format(int)));
1286 connect(formatED, SIGNAL(textChanged(const QString&)),
1287 this, SLOT(fileformat_changed()));
1288 connect(guiNameED, SIGNAL(textChanged(const QString&)),
1289 this, SLOT(fileformat_changed()));
1290 connect(shortcutED, SIGNAL(textChanged(const QString&)),
1291 this, SLOT(fileformat_changed()));
1292 connect(extensionED, SIGNAL(textChanged(const QString&)),
1293 this, SLOT(fileformat_changed()));
1294 connect(viewerED, SIGNAL(textChanged(const QString&)),
1295 this, SLOT(fileformat_changed()));
1296 connect(editorED, SIGNAL(textChanged(const QString&)),
1297 this, SLOT(fileformat_changed()));
1298 connect(documentCB, SIGNAL(toggled(bool)),
1299 this, SLOT(fileformat_changed()));
1300 connect(vectorCB, SIGNAL(toggled(bool)),
1301 this, SLOT(fileformat_changed()));
1302 connect(formatNewPB, SIGNAL(clicked()),
1303 this, SIGNAL(changed()));
1304 connect(formatRemovePB, SIGNAL(clicked()),
1305 this, SIGNAL(changed()));
1306 connect(formatModifyPB, SIGNAL(clicked()),
1307 this, SIGNAL(changed()));
1311 void PrefFileformats::apply(LyXRC & /*rc*/) const
1316 void PrefFileformats::update(LyXRC const & /*rc*/)
1322 void PrefFileformats::update()
1324 // save current selection
1325 QString current = guiNameED->text();
1327 // update listwidget with formats
1328 formatsLW->blockSignals(true);
1330 Formats::const_iterator cit = form_->formats().begin();
1331 Formats::const_iterator end = form_->formats().end();
1332 for (; cit != end; ++cit) {
1333 new QListWidgetItem(toqstr(cit->prettyname()),
1335 form_->formats().getNumber(cit->name()) );
1337 formatsLW->sortItems(Qt::AscendingOrder);
1338 formatsLW->blockSignals(false);
1340 // restore selection
1341 if (!current.isEmpty()) {
1342 QList<QListWidgetItem *> item = formatsLW->findItems(current, Qt::MatchExactly);
1344 formatsLW->setCurrentItem(item.at(0));
1346 // select first element if restoring failed
1347 if (formatsLW->currentRow() == -1)
1348 formatsLW->setCurrentRow(0);
1352 void PrefFileformats::switch_format(int nr)
1354 int const ftype = formatsLW->item(nr)->type();
1355 Format const f = form_->formats().get(ftype);
1357 formatED->setText(toqstr(f.name()));
1358 guiNameED->setText(toqstr(f.prettyname()));
1359 extensionED->setText(toqstr(f.extension()));
1360 shortcutED->setText(toqstr(f.shortcut()));
1361 viewerED->setText(toqstr(f.viewer()));
1362 editorED->setText(toqstr(f.editor()));
1363 documentCB->setChecked((f.documentFormat()));
1364 vectorCB->setChecked((f.vectorFormat()));
1370 void PrefFileformats::fileformat_changed()
1376 void PrefFileformats::updateButtons()
1378 QString const format = formatED->text();
1379 QString const gui_name = guiNameED->text();
1380 int const sel = form_->formats().getNumber(fromqstr(format));
1381 bool gui_name_known = false;
1383 for (int i = 0; i < formatsLW->count(); ++i) {
1384 if (formatsLW->item(i)->text() == gui_name) {
1385 gui_name_known = true;
1386 where = formatsLW->item(i)->type();
1390 // assure that a gui name cannot be chosen twice
1391 bool const known_otherwise = gui_name_known && (where != sel);
1393 bool const known = !(sel < 0);
1394 bool const valid = (!formatED->text().isEmpty()
1395 && !guiNameED->text().isEmpty());
1397 int const ftype = formatsLW->currentItem()->type();
1398 Format const & f(form_->formats().get(ftype));
1399 string const old_pretty(f.prettyname());
1400 string const old_shortcut(f.shortcut());
1401 string const old_extension(f.extension());
1402 string const old_viewer(f.viewer());
1403 string const old_editor(f.editor());
1404 bool const old_document(f.documentFormat());
1405 bool const old_vector(f.vectorFormat());
1407 string const new_pretty(fromqstr(gui_name));
1408 string const new_shortcut(fromqstr(shortcutED->text()));
1409 string const new_extension(fromqstr(extensionED->text()));
1410 string const new_viewer(fromqstr(viewerED->text()));
1411 string const new_editor(fromqstr(editorED->text()));
1412 bool const new_document(documentCB->isChecked());
1413 bool const new_vector(vectorCB->isChecked());
1415 bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
1416 || (old_extension != new_extension) || (old_viewer != new_viewer)
1417 || old_editor != new_editor || old_document != new_document
1418 || old_vector != new_vector);
1420 formatModifyPB->setEnabled(valid && known && modified && !known_otherwise);
1421 formatNewPB->setEnabled(valid && !known && !gui_name_known);
1422 formatRemovePB->setEnabled(known);
1426 void PrefFileformats::new_format()
1428 string const name = fromqstr(formatED->text());
1429 string const prettyname = fromqstr(guiNameED->text());
1430 string const extension = fromqstr(extensionED->text());
1431 string const shortcut = fromqstr(shortcutED->text());
1432 string const viewer = fromqstr(viewerED->text());
1433 string const editor = fromqstr(editorED->text());
1434 int flags = Format::none;
1435 if (documentCB->isChecked())
1436 flags |= Format::document;
1437 if (vectorCB->isChecked())
1438 flags |= Format::vector;
1440 form_->formats().add(name, extension, prettyname, shortcut, viewer,
1442 form_->formats().sort();
1443 form_->converters().update(form_->formats());
1451 void PrefFileformats::modify_format()
1453 int const current_item = formatsLW->currentItem()->type();
1454 Format const & oldformat = form_->formats().get(current_item);
1455 form_->formats().erase(oldformat.name());
1461 void PrefFileformats::remove_format()
1463 int const nr = formatsLW->currentItem()->type();
1464 string const current_text = form_->formats().get(nr).name();
1465 if (form_->converters().formatIsUsed(current_text)) {
1466 Alert::error(_("Format in use"),
1467 _("Cannot remove a Format used by a Converter. "
1468 "Remove the converter first."));
1472 form_->formats().erase(current_text);
1473 form_->converters().update(form_->formats());
1482 PrefLanguage::PrefLanguage(QWidget * parent)
1483 : PrefModule(docstring(), _("Language"), 0, parent)
1487 connect(rtlCB, SIGNAL(toggled(bool)),
1488 this, SIGNAL(changed()));
1489 connect(markForeignCB, SIGNAL(toggled(bool)),
1490 this, SIGNAL(changed()));
1491 connect(autoBeginCB, SIGNAL(toggled(bool)),
1492 this, SIGNAL(changed()));
1493 connect(autoEndCB, SIGNAL(toggled(bool)),
1494 this, SIGNAL(changed()));
1495 connect(useBabelCB, SIGNAL(toggled(bool)),
1496 this, SIGNAL(changed()));
1497 connect(globalCB, SIGNAL(toggled(bool)),
1498 this, SIGNAL(changed()));
1499 connect(languagePackageED, SIGNAL(textChanged(const QString&)),
1500 this, SIGNAL(changed()));
1501 connect(startCommandED, SIGNAL(textChanged(const QString&)),
1502 this, SIGNAL(changed()));
1503 connect(endCommandED, SIGNAL(textChanged(const QString&)),
1504 this, SIGNAL(changed()));
1505 connect(defaultLanguageCO, SIGNAL(activated(int)),
1506 this, SIGNAL(changed()));
1508 defaultLanguageCO->clear();
1510 // store the lang identifiers for later
1511 std::vector<LanguagePair> const langs =
1512 lyx::frontend::getLanguageData(false);
1513 lang_ = getSecond(langs);
1515 std::vector<LanguagePair>::const_iterator lit = langs.begin();
1516 std::vector<LanguagePair>::const_iterator lend = langs.end();
1517 for (; lit != lend; ++lit) {
1518 defaultLanguageCO->addItem(toqstr(lit->first));
1523 void PrefLanguage::apply(LyXRC & rc) const
1525 // FIXME: remove rtl_support bool
1526 rc.rtl_support = rtlCB->isChecked();
1527 rc.mark_foreign_language = markForeignCB->isChecked();
1528 rc.language_auto_begin = autoBeginCB->isChecked();
1529 rc.language_auto_end = autoEndCB->isChecked();
1530 rc.language_use_babel = useBabelCB->isChecked();
1531 rc.language_global_options = globalCB->isChecked();
1532 rc.language_package = fromqstr(languagePackageED->text());
1533 rc.language_command_begin = fromqstr(startCommandED->text());
1534 rc.language_command_end = fromqstr(endCommandED->text());
1535 rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1539 void PrefLanguage::update(LyXRC const & rc)
1541 // FIXME: remove rtl_support bool
1542 rtlCB->setChecked(rc.rtl_support);
1543 markForeignCB->setChecked(rc.mark_foreign_language);
1544 autoBeginCB->setChecked(rc.language_auto_begin);
1545 autoEndCB->setChecked(rc.language_auto_end);
1546 useBabelCB->setChecked(rc.language_use_babel);
1547 globalCB->setChecked(rc.language_global_options);
1548 languagePackageED->setText(toqstr(rc.language_package));
1549 startCommandED->setText(toqstr(rc.language_command_begin));
1550 endCommandED->setText(toqstr(rc.language_command_end));
1552 int const pos = int(findPos(lang_, rc.default_language));
1553 defaultLanguageCO->setCurrentIndex(pos);
1557 PrefPrinter::PrefPrinter(QWidget * parent)
1558 : PrefModule(_(Outputs), _("Printer"), 0, parent)
1562 connect(printerAdaptCB, SIGNAL(toggled(bool)),
1563 this, SIGNAL(changed()));
1564 connect(printerCommandED, SIGNAL(textChanged(const QString&)),
1565 this, SIGNAL(changed()));
1566 connect(printerNameED, SIGNAL(textChanged(const QString&)),
1567 this, SIGNAL(changed()));
1568 connect(printerPageRangeED, SIGNAL(textChanged(const QString&)),
1569 this, SIGNAL(changed()));
1570 connect(printerCopiesED, SIGNAL(textChanged(const QString&)),
1571 this, SIGNAL(changed()));
1572 connect(printerReverseED, SIGNAL(textChanged(const QString&)),
1573 this, SIGNAL(changed()));
1574 connect(printerToPrinterED, SIGNAL(textChanged(const QString&)),
1575 this, SIGNAL(changed()));
1576 connect(printerExtensionED, SIGNAL(textChanged(const QString&)),
1577 this, SIGNAL(changed()));
1578 connect(printerSpoolCommandED, SIGNAL(textChanged(const QString&)),
1579 this, SIGNAL(changed()));
1580 connect(printerPaperTypeED, SIGNAL(textChanged(const QString&)),
1581 this, SIGNAL(changed()));
1582 connect(printerEvenED, SIGNAL(textChanged(const QString&)),
1583 this, SIGNAL(changed()));
1584 connect(printerOddED, SIGNAL(textChanged(const QString&)),
1585 this, SIGNAL(changed()));
1586 connect(printerCollatedED, SIGNAL(textChanged(const QString&)),
1587 this, SIGNAL(changed()));
1588 connect(printerLandscapeED, SIGNAL(textChanged(const QString&)),
1589 this, SIGNAL(changed()));
1590 connect(printerToFileED, SIGNAL(textChanged(const QString&)),
1591 this, SIGNAL(changed()));
1592 connect(printerExtraED, SIGNAL(textChanged(const QString&)),
1593 this, SIGNAL(changed()));
1594 connect(printerSpoolPrefixED, SIGNAL(textChanged(const QString&)),
1595 this, SIGNAL(changed()));
1596 connect(printerPaperSizeED, SIGNAL(textChanged(const QString&)),
1597 this, SIGNAL(changed()));
1601 void PrefPrinter::apply(LyXRC & rc) const
1603 rc.print_adapt_output = printerAdaptCB->isChecked();
1604 rc.print_command = fromqstr(printerCommandED->text());
1605 rc.printer = fromqstr(printerNameED->text());
1607 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1608 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1609 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1610 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1611 rc.print_file_extension = fromqstr(printerExtensionED->text());
1612 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1613 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1614 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1615 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1616 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1617 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1618 rc.print_to_file = internal_path(printerToFileED->text());
1619 rc.print_extra_options = fromqstr(printerExtraED->text());
1620 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1621 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1625 void PrefPrinter::update(LyXRC const & rc)
1627 printerAdaptCB->setChecked(rc.print_adapt_output);
1628 printerCommandED->setText(toqstr(rc.print_command));
1629 printerNameED->setText(toqstr(rc.printer));
1631 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1632 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1633 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1634 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1635 printerExtensionED->setText(toqstr(rc.print_file_extension));
1636 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1637 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1638 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1639 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1640 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1641 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1642 printerToFileED->setText(external_path(rc.print_to_file));
1643 printerExtraED->setText(toqstr(rc.print_extra_options));
1644 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1645 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1649 PrefUserInterface::PrefUserInterface(QPrefs * form, QWidget * parent)
1650 : PrefModule(_(LookAndFeel), _("User interface"), form, parent)
1654 connect(autoSaveCB, SIGNAL( toggled(bool) ), autoSaveLA, SLOT( setEnabled(bool) ) );
1655 connect(autoSaveCB, SIGNAL( toggled(bool) ), autoSaveSB, SLOT( setEnabled(bool) ) );
1656 connect(autoSaveCB, SIGNAL( toggled(bool) ), TextLabel1, SLOT( setEnabled(bool) ) );
1657 connect(uiFilePB, SIGNAL(clicked()), this, SLOT(select_ui()));
1658 connect(bindFilePB, SIGNAL(clicked()), this, SLOT(select_bind()));
1659 connect(uiFileED, SIGNAL(textChanged(const QString&)),
1660 this, SIGNAL(changed()));
1661 connect(bindFileED, SIGNAL(textChanged(const QString&)),
1662 this, SIGNAL(changed()));
1663 connect(restoreCursorCB, SIGNAL(toggled(bool)),
1664 this, SIGNAL(changed()));
1665 connect(loadSessionCB, SIGNAL(toggled(bool)),
1666 this, SIGNAL(changed()));
1667 connect(loadWindowSizeCB, SIGNAL(toggled(bool)),
1668 this, SIGNAL(changed()));
1669 connect(loadWindowSizeCB, SIGNAL(toggled(bool)),
1670 windowWidthLA, SLOT(setDisabled(bool)));
1671 connect(loadWindowSizeCB, SIGNAL(toggled(bool)),
1672 windowHeightLA, SLOT(setDisabled(bool)));
1673 connect(loadWindowSizeCB, SIGNAL(toggled(bool)),
1674 windowWidthSB, SLOT(setDisabled(bool)));
1675 connect(loadWindowSizeCB, SIGNAL(toggled(bool)),
1676 windowHeightSB, SLOT(setDisabled(bool)));
1677 connect(loadWindowLocationCB, SIGNAL(toggled(bool)),
1678 this, SIGNAL(changed()));
1679 connect(windowWidthSB, SIGNAL(valueChanged(int)),
1680 this, SIGNAL(changed()));
1681 connect(windowHeightSB, SIGNAL(valueChanged(int)),
1682 this, SIGNAL(changed()));
1683 connect(cursorFollowsCB, SIGNAL(toggled(bool)),
1684 this, SIGNAL(changed()));
1685 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1686 this, SIGNAL(changed()));
1687 connect(autoSaveCB, SIGNAL(toggled(bool)),
1688 this, SIGNAL(changed()));
1689 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1690 this, SIGNAL(changed()));
1691 lastfilesSB->setMaximum(maxlastfiles);
1695 void PrefUserInterface::apply(LyXRC & rc) const
1697 rc.ui_file = internal_path(uiFileED->text());
1698 rc.bind_file = internal_path(bindFileED->text());
1699 rc.use_lastfilepos = restoreCursorCB->isChecked();
1700 rc.load_session = loadSessionCB->isChecked();
1701 if (loadWindowSizeCB->isChecked()) {
1702 rc.geometry_width = 0;
1703 rc.geometry_height = 0;
1705 rc.geometry_width = windowWidthSB->value();
1706 rc.geometry_height = windowHeightSB->value();
1708 rc.geometry_xysaved = loadWindowLocationCB->isChecked();
1709 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1710 rc.autosave = autoSaveSB->value() * 60;
1711 rc.make_backup = autoSaveCB->isChecked();
1712 rc.num_lastfiles = lastfilesSB->value();
1716 void PrefUserInterface::update(LyXRC const & rc)
1718 uiFileED->setText(external_path(rc.ui_file));
1719 bindFileED->setText(external_path(rc.bind_file));
1720 restoreCursorCB->setChecked(rc.use_lastfilepos);
1721 loadSessionCB->setChecked(rc.load_session);
1722 bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
1723 loadWindowSizeCB->setChecked(loadWindowSize);
1724 windowWidthSB->setEnabled(!loadWindowSize);
1725 windowHeightSB->setEnabled(!loadWindowSize);
1726 windowWidthLA->setEnabled(!loadWindowSize);
1727 windowHeightLA->setEnabled(!loadWindowSize);
1728 if (!loadWindowSize) {
1729 windowWidthSB->setValue(rc.geometry_width);
1730 windowHeightSB->setValue(rc.geometry_height);
1732 loadWindowLocationCB->setChecked(rc.geometry_xysaved);
1733 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1734 // convert to minutes
1735 int mins(rc.autosave / 60);
1736 if (rc.autosave && !mins)
1738 autoSaveSB->setValue(mins);
1739 autoSaveCB->setChecked(rc.make_backup);
1740 lastfilesSB->setValue(rc.num_lastfiles);
1745 void PrefUserInterface::select_ui()
1747 docstring file(form_->controller().browseUI(qstring_to_ucs4(uiFileED->text())));
1749 uiFileED->setText(toqstr(file));
1753 void PrefUserInterface::select_bind()
1755 docstring file(form_->controller().browsebind(qstring_to_ucs4(bindFileED->text())));
1757 bindFileED->setText(toqstr(file));
1761 PrefIdentity::PrefIdentity(QWidget * parent)
1762 : PrefModule(docstring(), _("Identity"), 0, parent)
1766 connect(nameED, SIGNAL(textChanged(const QString&)),
1767 this, SIGNAL(changed()));
1768 connect(emailED, SIGNAL(textChanged(const QString&)),
1769 this, SIGNAL(changed()));
1773 void PrefIdentity::apply(LyXRC & rc) const
1775 rc.user_name = fromqstr(nameED->text());
1776 rc.user_email = fromqstr(emailED->text());
1780 void PrefIdentity::update(LyXRC const & rc)
1782 nameED->setText(toqstr(rc.user_name));
1783 emailED->setText(toqstr(rc.user_email));
1788 QPrefsDialog::QPrefsDialog(QPrefs * form)
1792 QDialog::setModal(true);
1794 connect(savePB, SIGNAL(clicked()),
1795 form, SLOT(slotOK()));
1796 connect(applyPB, SIGNAL(clicked()),
1797 form, SLOT(slotApply()));
1798 connect(closePB, SIGNAL(clicked()),
1799 form, SLOT(slotClose()));
1800 connect(restorePB, SIGNAL(clicked()),
1801 form, SLOT(slotRestore()));
1805 add(new PrefKeyboard(form_));
1806 add(new PrefLatex(form_));
1807 add(new PrefScreenFonts(form_));
1808 add(new PrefColors(form_));
1810 #if defined(__CYGWIN__) || defined(_WIN32)
1811 add(new PrefCygwinPath);
1814 add(new PrefDisplay);
1815 add(new PrefPaths(form_));
1816 add(new PrefSpellchecker(form_));
1818 PrefConverters * converters = new PrefConverters(form_);
1819 PrefFileformats * formats = new PrefFileformats(form_);
1820 connect(formats, SIGNAL(formatsChanged()),
1821 converters, SLOT(updateGui()));
1825 add(new PrefCopiers(form_));
1827 add(new PrefLanguage);
1828 add(new PrefPrinter);
1829 add(new PrefUserInterface(form_));
1830 add(new PrefIdentity);
1832 prefsPS->setCurrentPanel(_("User interface"));
1833 // FIXME: hack to work around resizing bug in Qt >= 4.2
1834 // bug verified with Qt 4.2.{0-2} (JSpitzm)
1835 #if QT_VERSION >= 0x040200
1836 prefsPS->updateGeometry();
1839 form_->bcview().setOK(savePB);
1840 form_->bcview().setApply(applyPB);
1841 form_->bcview().setCancel(closePB);
1842 form_->bcview().setRestore(restorePB);
1846 QPrefsDialog::~QPrefsDialog()
1851 void QPrefsDialog::add(PrefModule * module)
1853 BOOST_ASSERT(module);
1855 // if (module->category().empty())
1856 // prefsPS->addPanel(module, module->title());
1858 prefsPS->addPanel(module, module->title(), module->category());
1860 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
1862 modules_.push_back(module);
1865 void QPrefsDialog::closeEvent(QCloseEvent * e)
1867 form_->slotWMHide();
1872 void QPrefsDialog::change_adaptor()
1878 void QPrefsDialog::apply(LyXRC & rc) const
1880 size_t end = modules_.size();
1881 for (size_t i = 0; i != end; ++i)
1882 modules_[i]->apply(rc);
1886 void QPrefsDialog::update(LyXRC const & rc)
1888 size_t end = modules_.size();
1889 for (size_t i = 0; i != end; ++i)
1890 modules_[i]->update(rc);
1894 } // namespace frontend
1897 #include "QPrefsDialog_moc.cpp"