3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
14 #include "ControlPrefs.h"
16 #include "qt_helpers.h"
17 #include "GuiApplication.h"
19 #include "ConverterCache.h"
24 #include "PanelStack.h"
25 #include "GuiFontExample.h"
28 #include "support/lstrings.h"
29 #include "support/os.h"
31 #include "frontend_helpers.h"
33 #include "frontends/alert.h"
34 #include "frontends/Application.h"
37 #include <QColorDialog>
38 #include <QFontDatabase>
40 #include <QPushButton>
44 #include <QCloseEvent>
52 using lyx::support::compare_ascii_no_case;
53 using lyx::support::os::external_path;
54 using lyx::support::os::external_path_list;
55 using lyx::support::os::internal_path;
56 using lyx::support::os::internal_path_list;
67 /////////////////////////////////////////////////////////////////////
71 /////////////////////////////////////////////////////////////////////
74 static size_t findPos_helper(std::vector<A> const & vec, A const & val)
76 typedef typename std::vector<A>::const_iterator Cit;
78 Cit it = std::find(vec.begin(), vec.end(), val);
81 return std::distance(vec.begin(), it);
85 static void setComboxFont(QComboBox * cb, string const & family,
86 string const & foundry)
88 string const name = makeFontName(family, foundry);
89 for (int i = 0; i < cb->count(); ++i) {
90 if (fromqstr(cb->itemText(i)) == name) {
91 cb->setCurrentIndex(i);
96 // Try matching without foundry name
98 // We count in reverse in order to prefer the Xft foundry
99 for (int i = cb->count() - 1; i >= 0; --i) {
100 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
101 if (compare_ascii_no_case(tmp.first, family) == 0) {
102 cb->setCurrentIndex(i);
107 // family alone can contain e.g. "Helvetica [Adobe]"
108 pair<string, string> tmpfam = parseFontName(family);
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, tmpfam.first) == 0) {
114 cb->setCurrentIndex(i);
119 // Bleh, default fonts, and the names couldn't be found. Hack
123 font.setKerning(false);
125 if (family == theApp()->romanFontName()) {
126 font.setStyleHint(QFont::Serif);
127 font.setFamily(family.c_str());
128 } else if (family == theApp()->sansFontName()) {
129 font.setStyleHint(QFont::SansSerif);
130 font.setFamily(family.c_str());
131 } else if (family == theApp()->typewriterFontName()) {
132 font.setStyleHint(QFont::TypeWriter);
133 font.setFamily(family.c_str());
135 lyxerr << "FAILED to find the default font: '"
136 << foundry << "', '" << family << '\''<< endl;
140 QFontInfo info(font);
141 pair<string, string> tmp = parseFontName(fromqstr(info.family()));
142 string const & default_font_name = tmp.first;
143 lyxerr << "Apparent font is " << default_font_name << endl;
145 for (int i = 0; i < cb->count(); ++i) {
146 lyxerr << "Looking at " << fromqstr(cb->itemText(i)) << endl;
147 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
148 default_font_name) == 0) {
149 cb->setCurrentIndex(i);
154 lyxerr << "FAILED to find the font: '"
155 << foundry << "', '" << family << '\'' <<endl;
159 /////////////////////////////////////////////////////////////////////
163 /////////////////////////////////////////////////////////////////////
165 PrefPlaintext::PrefPlaintext(QWidget * parent)
166 : PrefModule(_("Plain text"), 0, parent)
169 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
170 this, SIGNAL(changed()));
171 connect(plaintextRoffED, SIGNAL(textChanged(const QString&)),
172 this, SIGNAL(changed()));
176 void PrefPlaintext::apply(LyXRC & rc) const
178 rc.plaintext_linelen = plaintextLinelengthSB->value();
179 rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
183 void PrefPlaintext::update(LyXRC const & rc)
185 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
186 plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
190 /////////////////////////////////////////////////////////////////////
194 /////////////////////////////////////////////////////////////////////
196 PrefDate::PrefDate(QWidget * parent)
197 : PrefModule(_("Date format"), 0, parent)
200 connect(DateED, SIGNAL(textChanged(const QString &)),
201 this, SIGNAL(changed()));
205 void PrefDate::apply(LyXRC & rc) const
207 rc.date_insert_format = fromqstr(DateED->text());
211 void PrefDate::update(LyXRC const & rc)
213 DateED->setText(toqstr(rc.date_insert_format));
217 /////////////////////////////////////////////////////////////////////
221 /////////////////////////////////////////////////////////////////////
223 PrefKeyboard::PrefKeyboard(GuiPrefsDialog * form, QWidget * parent)
224 : PrefModule(_("Keyboard"), form, parent)
228 connect(keymapCB, SIGNAL(clicked()),
229 this, SIGNAL(changed()));
230 connect(firstKeymapED, SIGNAL(textChanged(const QString&)),
231 this, SIGNAL(changed()));
232 connect(secondKeymapED, SIGNAL(textChanged(const QString&)),
233 this, SIGNAL(changed()));
237 void PrefKeyboard::apply(LyXRC & rc) const
239 // FIXME: can derive CB from the two EDs
240 rc.use_kbmap = keymapCB->isChecked();
241 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
242 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
246 void PrefKeyboard::update(LyXRC const & rc)
248 // FIXME: can derive CB from the two EDs
249 keymapCB->setChecked(rc.use_kbmap);
250 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
251 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
255 QString PrefKeyboard::testKeymap(QString keymap)
257 return toqstr(form_->controller().browsekbmap(from_utf8(internal_path(fromqstr(keymap)))));
261 void PrefKeyboard::on_firstKeymapPB_clicked(bool)
263 QString const file = testKeymap(firstKeymapED->text());
265 firstKeymapED->setText(file);
269 void PrefKeyboard::on_secondKeymapPB_clicked(bool)
271 QString const file = testKeymap(secondKeymapED->text());
273 secondKeymapED->setText(file);
277 void PrefKeyboard::on_keymapCB_toggled(bool keymap)
279 firstKeymapLA->setEnabled(keymap);
280 secondKeymapLA->setEnabled(keymap);
281 firstKeymapED->setEnabled(keymap);
282 secondKeymapED->setEnabled(keymap);
283 firstKeymapPB->setEnabled(keymap);
284 secondKeymapPB->setEnabled(keymap);
288 /////////////////////////////////////////////////////////////////////
292 /////////////////////////////////////////////////////////////////////
294 PrefLatex::PrefLatex(GuiPrefsDialog * form, QWidget * parent)
295 : PrefModule(_("LaTeX"), form, parent)
298 connect(latexEncodingED, SIGNAL(textChanged(const QString&)),
299 this, SIGNAL(changed()));
300 connect(latexChecktexED, SIGNAL(textChanged(const QString&)),
301 this, SIGNAL(changed()));
302 connect(latexBibtexED, SIGNAL(textChanged(const QString&)),
303 this, SIGNAL(changed()));
304 connect(latexIndexED, SIGNAL(textChanged(const QString&)),
305 this, SIGNAL(changed()));
306 connect(latexAutoresetCB, SIGNAL(clicked()),
307 this, SIGNAL(changed()));
308 connect(latexDviPaperED, SIGNAL(textChanged(const QString&)),
309 this, SIGNAL(changed()));
310 connect(latexPaperSizeCO, SIGNAL(activated(int)),
311 this, SIGNAL(changed()));
313 #if defined(__CYGWIN__) || defined(_WIN32)
314 pathCB->setVisible(true);
315 connect(pathCB, SIGNAL(clicked()),
316 this, SIGNAL(changed()));
318 pathCB->setVisible(false);
324 void PrefLatex::apply(LyXRC & rc) const
326 rc.fontenc = fromqstr(latexEncodingED->text());
327 rc.chktex_command = fromqstr(latexChecktexED->text());
328 rc.bibtex_command = fromqstr(latexBibtexED->text());
329 rc.index_command = fromqstr(latexIndexED->text());
330 rc.auto_reset_options = latexAutoresetCB->isChecked();
331 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
332 rc.default_papersize =
333 form_->controller().toPaperSize(latexPaperSizeCO->currentIndex());
334 #if defined(__CYGWIN__) || defined(_WIN32)
335 rc.windows_style_tex_paths = pathCB->isChecked();
340 void PrefLatex::update(LyXRC const & rc)
342 latexEncodingED->setText(toqstr(rc.fontenc));
343 latexChecktexED->setText(toqstr(rc.chktex_command));
344 latexBibtexED->setText(toqstr(rc.bibtex_command));
345 latexIndexED->setText(toqstr(rc.index_command));
346 latexAutoresetCB->setChecked(rc.auto_reset_options);
347 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
348 latexPaperSizeCO->setCurrentIndex(
349 form_->controller().fromPaperSize(rc.default_papersize));
350 #if defined(__CYGWIN__) || defined(_WIN32)
351 pathCB->setChecked(rc.windows_style_tex_paths);
356 /////////////////////////////////////////////////////////////////////
360 /////////////////////////////////////////////////////////////////////
362 PrefScreenFonts::PrefScreenFonts(GuiPrefsDialog * form, QWidget * parent)
363 : PrefModule(_("Screen fonts"), form, parent)
367 connect(screenRomanCO, SIGNAL(activated(const QString&)),
368 this, SLOT(select_roman(const QString&)));
369 connect(screenSansCO, SIGNAL(activated(const QString&)),
370 this, SLOT(select_sans(const QString&)));
371 connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
372 this, SLOT(select_typewriter(const QString&)));
374 QFontDatabase fontdb;
375 QStringList families(fontdb.families());
376 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
377 screenRomanCO->addItem(*it);
378 screenSansCO->addItem(*it);
379 screenTypewriterCO->addItem(*it);
381 connect(screenRomanCO, SIGNAL(activated(const QString&)),
382 this, SIGNAL(changed()));
383 connect(screenSansCO, SIGNAL(activated(const QString&)),
384 this, SIGNAL(changed()));
385 connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
386 this, SIGNAL(changed()));
387 connect(screenZoomSB, SIGNAL(valueChanged(int)),
388 this, SIGNAL(changed()));
389 connect(screenDpiSB, SIGNAL(valueChanged(int)),
390 this, SIGNAL(changed()));
391 connect(screenTinyED, SIGNAL(textChanged(const QString&)),
392 this, SIGNAL(changed()));
393 connect(screenSmallestED, SIGNAL(textChanged(const QString&)),
394 this, SIGNAL(changed()));
395 connect(screenSmallerED, SIGNAL(textChanged(const QString&)),
396 this, SIGNAL(changed()));
397 connect(screenSmallED, SIGNAL(textChanged(const QString&)),
398 this, SIGNAL(changed()));
399 connect(screenNormalED, SIGNAL(textChanged(const QString&)),
400 this, SIGNAL(changed()));
401 connect(screenLargeED, SIGNAL(textChanged(const QString&)),
402 this, SIGNAL(changed()));
403 connect(screenLargerED, SIGNAL(textChanged(const QString&)),
404 this, SIGNAL(changed()));
405 connect(screenLargestED, SIGNAL(textChanged(const QString&)),
406 this, SIGNAL(changed()));
407 connect(screenHugeED, SIGNAL(textChanged(const QString&)),
408 this, SIGNAL(changed()));
409 connect(screenHugerED, SIGNAL(textChanged(const QString&)),
410 this, SIGNAL(changed()));
412 screenTinyED->setValidator(new QDoubleValidator(
414 screenSmallestED->setValidator(new QDoubleValidator(
416 screenSmallerED->setValidator(new QDoubleValidator(
418 screenSmallED->setValidator(new QDoubleValidator(
420 screenNormalED->setValidator(new QDoubleValidator(
422 screenLargeED->setValidator(new QDoubleValidator(
424 screenLargerED->setValidator(new QDoubleValidator(
426 screenLargestED->setValidator(new QDoubleValidator(
428 screenHugeED->setValidator(new QDoubleValidator(
430 screenHugerED->setValidator(new QDoubleValidator(
435 void PrefScreenFonts::apply(LyXRC & rc) const
437 LyXRC const oldrc(rc);
439 boost::tie(rc.roman_font_name, rc.roman_font_foundry)
440 = parseFontName(fromqstr(screenRomanCO->currentText()));
441 boost::tie(rc.sans_font_name, rc.sans_font_foundry) =
442 parseFontName(fromqstr(screenSansCO->currentText()));
443 boost::tie(rc.typewriter_font_name, rc.typewriter_font_foundry) =
444 parseFontName(fromqstr(screenTypewriterCO->currentText()));
446 rc.zoom = screenZoomSB->value();
447 rc.dpi = screenDpiSB->value();
448 rc.font_sizes[Font::SIZE_TINY] = fromqstr(screenTinyED->text());
449 rc.font_sizes[Font::SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
450 rc.font_sizes[Font::SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
451 rc.font_sizes[Font::SIZE_SMALL] = fromqstr(screenSmallED->text());
452 rc.font_sizes[Font::SIZE_NORMAL] = fromqstr(screenNormalED->text());
453 rc.font_sizes[Font::SIZE_LARGE] = fromqstr(screenLargeED->text());
454 rc.font_sizes[Font::SIZE_LARGER] = fromqstr(screenLargerED->text());
455 rc.font_sizes[Font::SIZE_LARGEST] = fromqstr(screenLargestED->text());
456 rc.font_sizes[Font::SIZE_HUGE] = fromqstr(screenHugeED->text());
457 rc.font_sizes[Font::SIZE_HUGER] = fromqstr(screenHugerED->text());
459 if (rc.font_sizes != oldrc.font_sizes
460 || rc.roman_font_name != oldrc.roman_font_name
461 || rc.sans_font_name != oldrc.sans_font_name
462 || rc.typewriter_font_name != oldrc.typewriter_font_name
463 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
464 form_->controller().updateScreenFonts();
469 void PrefScreenFonts::update(LyXRC const & rc)
471 setComboxFont(screenRomanCO, rc.roman_font_name,
472 rc.roman_font_foundry);
473 setComboxFont(screenSansCO, rc.sans_font_name,
474 rc.sans_font_foundry);
475 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
476 rc.typewriter_font_foundry);
478 select_roman(screenRomanCO->currentText());
479 select_sans(screenSansCO->currentText());
480 select_typewriter(screenTypewriterCO->currentText());
482 screenZoomSB->setValue(rc.zoom);
483 screenDpiSB->setValue(rc.dpi);
484 screenTinyED->setText(toqstr(rc.font_sizes[Font::SIZE_TINY]));
485 screenSmallestED->setText(toqstr(rc.font_sizes[Font::SIZE_SCRIPT]));
486 screenSmallerED->setText(toqstr(rc.font_sizes[Font::SIZE_FOOTNOTE]));
487 screenSmallED->setText(toqstr(rc.font_sizes[Font::SIZE_SMALL]));
488 screenNormalED->setText(toqstr(rc.font_sizes[Font::SIZE_NORMAL]));
489 screenLargeED->setText(toqstr(rc.font_sizes[Font::SIZE_LARGE]));
490 screenLargerED->setText(toqstr(rc.font_sizes[Font::SIZE_LARGER]));
491 screenLargestED->setText(toqstr(rc.font_sizes[Font::SIZE_LARGEST]));
492 screenHugeED->setText(toqstr(rc.font_sizes[Font::SIZE_HUGE]));
493 screenHugerED->setText(toqstr(rc.font_sizes[Font::SIZE_HUGER]));
496 void PrefScreenFonts::select_roman(const QString& name)
498 screenRomanFE->set(QFont(name), name);
502 void PrefScreenFonts::select_sans(const QString& name)
504 screenSansFE->set(QFont(name), name);
508 void PrefScreenFonts::select_typewriter(const QString& name)
510 screenTypewriterFE->set(QFont(name), name);
514 /////////////////////////////////////////////////////////////////////
518 /////////////////////////////////////////////////////////////////////
524 bool operator()(Color::color const & lhs, Color::color const & rhs) const {
525 return lcolor.getGUIName(lhs) < lcolor.getGUIName(rhs);
531 PrefColors::PrefColors(GuiPrefsDialog * form, QWidget * parent)
532 : PrefModule( _("Colors"), form, parent)
536 // FIXME: all of this initialization should be put into the controller.
537 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
538 // for some discussion of why that is not trivial.
539 QPixmap icon(32, 32);
540 for (int i = 0; i < Color::ignore; ++i) {
541 Color::color lc = static_cast<Color::color>(i);
542 if (lc == Color::none
543 || lc == Color::black
544 || lc == Color::white
546 || lc == Color::green
549 || lc == Color::magenta
550 || lc == Color::yellow
551 || lc == Color::inherit
552 || lc == Color::ignore) continue;
554 lcolors_.push_back(lc);
556 std::sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
557 vector<Color_color>::const_iterator cit = lcolors_.begin();
558 vector<Color_color>::const_iterator const end = lcolors_.end();
559 for (; cit != end; ++cit) {
560 (void) new QListWidgetItem(QIcon(icon),
561 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
563 curcolors_.resize(lcolors_.size());
564 newcolors_.resize(lcolors_.size());
565 // End initialization
567 connect(colorChangePB, SIGNAL(clicked()),
568 this, SLOT(change_color()));
569 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
570 this, SLOT(change_lyxObjects_selection()));
571 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
572 this, SLOT(change_color()));
576 void PrefColors::apply(LyXRC & /*rc*/) const
578 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
579 if (curcolors_[i] != newcolors_[i]) {
580 form_->controller().setColor(lcolors_[i], fromqstr(newcolors_[i]));
586 void PrefColors::update(LyXRC const & /*rc*/)
588 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
589 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
590 QPixmap coloritem(32, 32);
591 coloritem.fill(color);
592 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
593 newcolors_[i] = curcolors_[i] = color.name();
595 change_lyxObjects_selection();
598 void PrefColors::change_color()
600 int const row = lyxObjectsLW->currentRow();
605 QString const color = newcolors_[row];
606 QColor c(QColorDialog::getColor(QColor(color), qApp->focusWidget()));
608 if (c.isValid() && c.name() != color) {
609 newcolors_[row] = c.name();
610 QPixmap coloritem(32, 32);
612 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
618 void PrefColors::change_lyxObjects_selection()
620 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
624 /////////////////////////////////////////////////////////////////////
628 /////////////////////////////////////////////////////////////////////
630 PrefDisplay::PrefDisplay(QWidget * parent)
631 : PrefModule(_("Graphics"), 0, parent)
634 connect(instantPreviewCO, SIGNAL(activated(int)),
635 this, SIGNAL(changed()));
636 connect(displayGraphicsCO, SIGNAL(activated(int)),
637 this, SIGNAL(changed()));
641 void PrefDisplay::apply(LyXRC & rc) const
643 switch (instantPreviewCO->currentIndex()) {
644 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
645 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
646 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
649 lyx::graphics::DisplayType dtype;
650 switch (displayGraphicsCO->currentIndex()) {
651 case 3: dtype = lyx::graphics::NoDisplay; break;
652 case 2: dtype = lyx::graphics::ColorDisplay; break;
653 case 1: dtype = lyx::graphics::GrayscaleDisplay; break;
654 case 0: dtype = lyx::graphics::MonochromeDisplay; break;
655 default: dtype = lyx::graphics::GrayscaleDisplay;
657 rc.display_graphics = dtype;
659 // FIXME!! The graphics cache no longer has a changeDisplay method.
661 if (old_value != rc.display_graphics) {
662 lyx::graphics::GCache & gc = lyx::graphics::GCache::get();
669 void PrefDisplay::update(LyXRC const & rc)
671 switch (rc.preview) {
672 case LyXRC::PREVIEW_OFF:
673 instantPreviewCO->setCurrentIndex(0);
675 case LyXRC::PREVIEW_NO_MATH :
676 instantPreviewCO->setCurrentIndex(1);
678 case LyXRC::PREVIEW_ON :
679 instantPreviewCO->setCurrentIndex(2);
684 switch (rc.display_graphics) {
685 case lyx::graphics::NoDisplay: item = 3; break;
686 case lyx::graphics::ColorDisplay: item = 2; break;
687 case lyx::graphics::GrayscaleDisplay: item = 1; break;
688 case lyx::graphics::MonochromeDisplay: item = 0; break;
691 displayGraphicsCO->setCurrentIndex(item);
695 /////////////////////////////////////////////////////////////////////
699 /////////////////////////////////////////////////////////////////////
701 PrefPaths::PrefPaths(GuiPrefsDialog * form, QWidget * parent)
702 : PrefModule(_("Paths"), form, parent)
705 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
706 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
707 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
708 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
709 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
710 connect(workingDirED, SIGNAL(textChanged(const QString&)),
711 this, SIGNAL(changed()));
712 connect(templateDirED, SIGNAL(textChanged(const QString&)),
713 this, SIGNAL(changed()));
714 connect(backupDirED, SIGNAL(textChanged(const QString&)),
715 this, SIGNAL(changed()));
716 connect(tempDirED, SIGNAL(textChanged(const QString&)),
717 this, SIGNAL(changed()));
718 connect(lyxserverDirED, SIGNAL(textChanged(const QString&)),
719 this, SIGNAL(changed()));
720 connect(pathPrefixED, SIGNAL(textChanged(const QString&)),
721 this, SIGNAL(changed()));
725 void PrefPaths::apply(LyXRC & rc) const
727 rc.document_path = internal_path(fromqstr(workingDirED->text()));
728 rc.template_path = internal_path(fromqstr(templateDirED->text()));
729 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
730 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
731 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
732 // FIXME: should be a checkbox only
733 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
737 void PrefPaths::update(LyXRC const & rc)
739 workingDirED->setText(toqstr(external_path(rc.document_path)));
740 templateDirED->setText(toqstr(external_path(rc.template_path)));
741 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
742 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
743 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
744 // FIXME: should be a checkbox only
745 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
749 void PrefPaths::select_templatedir()
751 docstring file(form_->controller().browsedir(
752 from_utf8(internal_path(fromqstr(templateDirED->text()))),
753 _("Select a document templates directory")));
755 templateDirED->setText(toqstr(file));
759 void PrefPaths::select_tempdir()
761 docstring file(form_->controller().browsedir(
762 from_utf8(internal_path(fromqstr(tempDirED->text()))),
763 _("Select a temporary directory")));
765 tempDirED->setText(toqstr(file));
769 void PrefPaths::select_backupdir()
771 docstring file(form_->controller().browsedir(
772 from_utf8(internal_path(fromqstr(backupDirED->text()))),
773 _("Select a backups directory")));
775 backupDirED->setText(toqstr(file));
779 void PrefPaths::select_workingdir()
781 docstring file(form_->controller().browsedir(
782 from_utf8(internal_path(fromqstr(workingDirED->text()))),
783 _("Select a document directory")));
785 workingDirED->setText(toqstr(file));
789 void PrefPaths::select_lyxpipe()
791 docstring file(form_->controller().browse(
792 from_utf8(internal_path(fromqstr(lyxserverDirED->text()))),
793 _("Give a filename for the LyX server pipe")));
795 lyxserverDirED->setText(toqstr(file));
799 /////////////////////////////////////////////////////////////////////
803 /////////////////////////////////////////////////////////////////////
805 PrefSpellchecker::PrefSpellchecker(GuiPrefsDialog * form, QWidget * parent)
806 : PrefModule(_("Spellchecker"), form, parent)
810 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
811 #if defined (USE_ISPELL)
812 connect(spellCommandCO, SIGNAL(activated(int)),
813 this, SIGNAL(changed()));
815 spellCommandCO->setEnabled(false);
817 connect(altLanguageED, SIGNAL(textChanged(const QString&)),
818 this, SIGNAL(changed()));
819 connect(escapeCharactersED, SIGNAL(textChanged(const QString&)),
820 this, SIGNAL(changed()));
821 connect(persDictionaryED, SIGNAL(textChanged(const QString&)),
822 this, SIGNAL(changed()));
823 connect(compoundWordCB, SIGNAL(clicked()),
824 this, SIGNAL(changed()));
825 connect(inputEncodingCB, SIGNAL(clicked()),
826 this, SIGNAL(changed()));
828 spellCommandCO->addItem(qt_("ispell"));
829 spellCommandCO->addItem(qt_("aspell"));
830 spellCommandCO->addItem(qt_("hspell"));
832 spellCommandCO->addItem(qt_("pspell (library)"));
835 spellCommandCO->addItem(qt_("aspell (library)"));
841 void PrefSpellchecker::apply(LyXRC & rc) const
843 switch (spellCommandCO->currentIndex()) {
847 rc.use_spell_lib = false;
848 rc.isp_command = fromqstr(spellCommandCO->currentText());
851 rc.use_spell_lib = true;
855 // FIXME: remove isp_use_alt_lang
856 rc.isp_alt_lang = fromqstr(altLanguageED->text());
857 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
858 // FIXME: remove isp_use_esc_chars
859 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
860 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
861 // FIXME: remove isp_use_pers_dict
862 rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
863 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
864 rc.isp_accept_compound = compoundWordCB->isChecked();
865 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
869 void PrefSpellchecker::update(LyXRC const & rc)
871 spellCommandCO->setCurrentIndex(0);
873 if (rc.isp_command == "ispell") {
874 spellCommandCO->setCurrentIndex(0);
875 } else if (rc.isp_command == "aspell") {
876 spellCommandCO->setCurrentIndex(1);
877 } else if (rc.isp_command == "hspell") {
878 spellCommandCO->setCurrentIndex(2);
881 if (rc.use_spell_lib) {
882 #if defined(USE_ASPELL) || defined(USE_PSPELL)
883 spellCommandCO->setCurrentIndex(3);
887 // FIXME: remove isp_use_alt_lang
888 altLanguageED->setText(toqstr(rc.isp_alt_lang));
889 // FIXME: remove isp_use_esc_chars
890 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
891 // FIXME: remove isp_use_pers_dict
892 persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
893 compoundWordCB->setChecked(rc.isp_accept_compound);
894 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
898 void PrefSpellchecker::select_dict()
900 docstring file(form_->controller().browsedict(
901 from_utf8(internal_path(fromqstr(persDictionaryED->text())))));
903 persDictionaryED->setText(toqstr(file));
908 /////////////////////////////////////////////////////////////////////
912 /////////////////////////////////////////////////////////////////////
915 PrefConverters::PrefConverters(GuiPrefsDialog * form, QWidget * parent)
916 : PrefModule(_("Converters"), form, parent)
920 connect(converterNewPB, SIGNAL(clicked()),
921 this, SLOT(update_converter()));
922 connect(converterRemovePB, SIGNAL(clicked()),
923 this, SLOT(remove_converter()));
924 connect(converterModifyPB, SIGNAL(clicked()),
925 this, SLOT(update_converter()));
926 connect(convertersLW, SIGNAL(currentRowChanged(int)),
927 this, SLOT(switch_converter()));
928 connect(converterFromCO, SIGNAL(activated(const QString&)),
929 this, SLOT(converter_changed()));
930 connect(converterToCO, SIGNAL(activated(const QString&)),
931 this, SLOT(converter_changed()));
932 connect(converterED, SIGNAL(textChanged(const QString&)),
933 this, SLOT(converter_changed()));
934 connect(converterFlagED, SIGNAL(textChanged(const QString&)),
935 this, SLOT(converter_changed()));
936 connect(converterNewPB, SIGNAL(clicked()),
937 this, SIGNAL(changed()));
938 connect(converterRemovePB, SIGNAL(clicked()),
939 this, SIGNAL(changed()));
940 connect(converterModifyPB, SIGNAL(clicked()),
941 this, SIGNAL(changed()));
942 connect(maxAgeLE, SIGNAL(textChanged(const QString&)),
943 this, SIGNAL(changed()));
945 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
946 //converterDefGB->setFocusProxy(convertersLW);
950 void PrefConverters::apply(LyXRC & rc) const
952 rc.use_converter_cache = cacheCB->isChecked();
953 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
957 void PrefConverters::update(LyXRC const & rc)
959 cacheCB->setChecked(rc.use_converter_cache);
961 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
962 maxAgeLE->setText(max_age);
967 void PrefConverters::updateGui()
969 // save current selection
970 QString current = converterFromCO->currentText()
971 + " -> " + converterToCO->currentText();
973 converterFromCO->clear();
974 converterToCO->clear();
976 Formats::const_iterator cit = form_->formats().begin();
977 Formats::const_iterator end = form_->formats().end();
978 for (; cit != end; ++cit) {
979 converterFromCO->addItem(toqstr(cit->prettyname()));
980 converterToCO->addItem(toqstr(cit->prettyname()));
983 // currentRowChanged(int) is also triggered when updating the listwidget
984 // block signals to avoid unnecessary calls to switch_converter()
985 convertersLW->blockSignals(true);
986 convertersLW->clear();
988 Converters::const_iterator ccit = form_->converters().begin();
989 Converters::const_iterator cend = form_->converters().end();
990 for (; ccit != cend; ++ccit) {
991 std::string const name =
992 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
993 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
994 new QListWidgetItem(toqstr(name), convertersLW, type);
996 convertersLW->sortItems(Qt::AscendingOrder);
997 convertersLW->blockSignals(false);
1000 if (!current.isEmpty()) {
1001 QList<QListWidgetItem *> const item =
1002 convertersLW->findItems(current, Qt::MatchExactly);
1004 convertersLW->setCurrentItem(item.at(0));
1007 // select first element if restoring failed
1008 if (convertersLW->currentRow() == -1)
1009 convertersLW->setCurrentRow(0);
1015 void PrefConverters::switch_converter()
1017 int const cnr = convertersLW->currentItem()->type();
1018 Converter const & c(form_->converters().get(cnr));
1019 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1020 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1021 converterED->setText(toqstr(c.command));
1022 converterFlagED->setText(toqstr(c.flags));
1028 void PrefConverters::converter_changed()
1034 void PrefConverters::updateButtons()
1036 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1037 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1038 int const sel = form_->converters().getNumber(from.name(), to.name());
1039 bool const known = !(sel < 0);
1040 bool const valid = !(converterED->text().isEmpty()
1041 || from.name() == to.name());
1043 int const cnr = convertersLW->currentItem()->type();
1044 Converter const & c(form_->converters().get(cnr));
1045 string const old_command = c.command;
1046 string const old_flag = c.flags;
1047 string const new_command(fromqstr(converterED->text()));
1048 string const new_flag(fromqstr(converterFlagED->text()));
1050 bool modified = ((old_command != new_command) || (old_flag != new_flag));
1052 converterModifyPB->setEnabled(valid && known && modified);
1053 converterNewPB->setEnabled(valid && !known);
1054 converterRemovePB->setEnabled(known);
1056 maxAgeLE->setEnabled(cacheCB->isChecked());
1057 maxAgeLA->setEnabled(cacheCB->isChecked());
1062 // specify unique from/to or it doesn't appear. This is really bad UI
1063 // this is why we can use the same function for both new and modify
1064 void PrefConverters::update_converter()
1066 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1067 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1068 string const flags = fromqstr(converterFlagED->text());
1069 string const command = fromqstr(converterED->text());
1071 Converter const * old = form_->converters().getConverter(from.name(), to.name());
1072 form_->converters().add(from.name(), to.name(), command, flags);
1074 form_->converters().updateLast(form_->formats());
1079 // Remove all files created by this converter from the cache, since
1080 // the modified converter might create different files.
1081 ConverterCache::get().remove_all(from.name(), to.name());
1085 void PrefConverters::remove_converter()
1087 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1088 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1089 form_->converters().erase(from.name(), to.name());
1093 // Remove all files created by this converter from the cache, since
1094 // a possible new converter might create different files.
1095 ConverterCache::get().remove_all(from.name(), to.name());
1099 void PrefConverters::on_cacheCB_stateChanged(int state)
1101 maxAgeLE->setEnabled(state == Qt::Checked);
1102 maxAgeLA->setEnabled(state == Qt::Checked);
1107 /////////////////////////////////////////////////////////////////////
1111 /////////////////////////////////////////////////////////////////////
1113 PrefCopiers::PrefCopiers(GuiPrefsDialog * form, QWidget * parent)
1114 : PrefModule(_("Copiers"), form, parent)
1118 connect(copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
1119 connect(copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
1120 connect(copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
1121 connect(AllCopiersLW, SIGNAL(currentRowChanged(int)),
1122 this, SLOT(switch_copierLB(int)));
1123 connect(copierFormatCO, SIGNAL(activated(int)),
1124 this, SLOT(switch_copierCO(int)));
1125 connect(copierNewPB, SIGNAL(clicked()),
1126 this, SIGNAL(changed()));
1127 connect(copierRemovePB, SIGNAL(clicked()),
1128 this, SIGNAL(changed()));
1129 connect(copierModifyPB, SIGNAL(clicked()),
1130 this, SIGNAL(changed()));
1131 connect(copierFormatCO, SIGNAL(activated(const QString &)),
1132 this, SLOT(copiers_changed()));
1133 connect(copierED, SIGNAL(textChanged(const QString &)),
1134 this, SLOT(copiers_changed()));
1138 void PrefCopiers::apply(LyXRC & /*rc*/) const
1143 void PrefCopiers::update(LyXRC const & /*rc*/)
1149 void PrefCopiers::updateView()
1151 // The choice widget
1152 // save current selection
1153 QString current = copierFormatCO->currentText();
1154 copierFormatCO->clear();
1156 for (Formats::const_iterator it = form_->formats().begin(),
1157 end = form_->formats().end();
1159 copierFormatCO->addItem(toqstr(it->prettyname()));
1162 // The browser widget
1163 AllCopiersLW->clear();
1165 for (Movers::const_iterator it = form_->movers().begin(),
1166 end = form_->movers().end();
1168 std::string const & command = it->second.command();
1169 if (command.empty())
1171 QString const pretty = toqstr(form_->formats().prettyName(it->first));
1172 AllCopiersLW->addItem(pretty);
1174 AllCopiersLW->sortItems(Qt::AscendingOrder);
1176 // restore selection
1177 if (!current.isEmpty()) {
1178 QList<QListWidgetItem *> item =
1179 AllCopiersLW->findItems(current, Qt::MatchExactly);
1181 AllCopiersLW->setCurrentItem(item.at(0));
1183 // select first element if restoring failed
1184 if (AllCopiersLW->currentRow() == -1)
1185 AllCopiersLW->setCurrentRow(0);
1191 class SamePrettyName {
1193 SamePrettyName(string const & n) : pretty_name_(n) {}
1195 bool operator()(Format const & fmt) const {
1196 return fmt.prettyname() == pretty_name_;
1200 string const pretty_name_;
1204 Format const * getFormat(std::string const & prettyname)
1206 Formats::const_iterator it = formats.begin();
1207 Formats::const_iterator const end = formats.end();
1208 it = std::find_if(it, end, SamePrettyName(prettyname));
1209 return it == end ? 0 : &*it;
1215 void PrefCopiers::switch_copierLB(int row)
1221 std::string const browser_text =
1222 fromqstr(AllCopiersLW->currentItem()->text());
1223 Format const * fmt = getFormat(browser_text);
1227 QString const gui_name = toqstr(fmt->prettyname());
1228 QString const command = toqstr(form_->movers().command(fmt->name()));
1231 int const combo_size = copierFormatCO->count();
1232 for (int i = 0; i < combo_size; ++i) {
1233 QString const text = copierFormatCO->itemText(i);
1234 if (text == gui_name) {
1235 copierFormatCO->setCurrentIndex(i);
1236 copierED->setText(command);
1244 void PrefCopiers::switch_copierCO(int row)
1249 std::string const combo_text =
1250 fromqstr(copierFormatCO->currentText());
1251 Format const * fmt = getFormat(combo_text);
1255 QString const command = toqstr(form_->movers().command(fmt->name()));
1256 copierED->setText(command);
1258 QListWidgetItem * const index = AllCopiersLW->currentItem();
1260 AllCopiersLW->setItemSelected(index, false);
1262 QString const gui_name = toqstr(fmt->prettyname());
1263 int const browser_size = AllCopiersLW->count();
1264 for (int i = 0; i < browser_size; ++i) {
1265 QString const text = AllCopiersLW->item(i)->text();
1266 if (text == gui_name) {
1267 QListWidgetItem * item = AllCopiersLW->item(i);
1268 AllCopiersLW->setItemSelected(item, true);
1275 void PrefCopiers::copiers_changed()
1281 void PrefCopiers::updateButtons()
1283 QString selected = copierFormatCO->currentText();
1286 for (int i = 0; i < AllCopiersLW->count(); ++i) {
1287 if (AllCopiersLW->item(i)->text() == selected)
1291 bool const valid = !copierED->text().isEmpty();
1293 Format const * fmt = getFormat(fromqstr(selected));
1294 string const old_command = form_->movers().command(fmt->name());
1295 string const new_command(fromqstr(copierED->text()));
1297 bool modified = (old_command != new_command);
1299 copierModifyPB->setEnabled(valid && known && modified);
1300 copierNewPB->setEnabled(valid && !known);
1301 copierRemovePB->setEnabled(known);
1305 void PrefCopiers::new_copier()
1307 std::string const combo_text =
1308 fromqstr(copierFormatCO->currentText());
1309 Format const * fmt = getFormat(combo_text);
1313 string const command = fromqstr(copierED->text());
1314 if (command.empty())
1317 form_->movers().set(fmt->name(), command);
1320 int const last = AllCopiersLW->count() - 1;
1321 AllCopiersLW->setCurrentRow(last);
1327 void PrefCopiers::modify_copier()
1329 std::string const combo_text =
1330 fromqstr(copierFormatCO->currentText());
1331 Format const * fmt = getFormat(combo_text);
1335 string const command = fromqstr(copierED->text());
1336 form_->movers().set(fmt->name(), command);
1343 void PrefCopiers::remove_copier()
1345 std::string const combo_text =
1346 fromqstr(copierFormatCO->currentText());
1347 Format const * fmt = getFormat(combo_text);
1351 string const & fmt_name = fmt->name();
1352 form_->movers().set(fmt_name, string());
1360 /////////////////////////////////////////////////////////////////////
1364 /////////////////////////////////////////////////////////////////////
1366 PrefFileformats::PrefFileformats(GuiPrefsDialog * form, QWidget * parent)
1367 : PrefModule(_("File formats"), form, parent)
1371 connect(formatNewPB, SIGNAL(clicked()),
1372 this, SLOT(new_format()));
1373 connect(formatRemovePB, SIGNAL(clicked()),
1374 this, SLOT(remove_format()));
1375 connect(formatModifyPB, SIGNAL(clicked()),
1376 this, SLOT(modify_format()));
1377 connect(formatsLW, SIGNAL(currentRowChanged(int)),
1378 this, SLOT(switch_format(int)));
1379 connect(formatED, SIGNAL(textChanged(const QString&)),
1380 this, SLOT(fileformat_changed()));
1381 connect(guiNameED, SIGNAL(textChanged(const QString&)),
1382 this, SLOT(fileformat_changed()));
1383 connect(shortcutED, SIGNAL(textChanged(const QString&)),
1384 this, SLOT(fileformat_changed()));
1385 connect(extensionED, SIGNAL(textChanged(const QString&)),
1386 this, SLOT(fileformat_changed()));
1387 connect(viewerED, SIGNAL(textChanged(const QString&)),
1388 this, SLOT(fileformat_changed()));
1389 connect(editorED, SIGNAL(textChanged(const QString&)),
1390 this, SLOT(fileformat_changed()));
1391 connect(documentCB, SIGNAL(clicked()),
1392 this, SLOT(fileformat_changed()));
1393 connect(vectorCB, SIGNAL(clicked()),
1394 this, SLOT(fileformat_changed()));
1395 connect(formatNewPB, SIGNAL(clicked()),
1396 this, SIGNAL(changed()));
1397 connect(formatRemovePB, SIGNAL(clicked()),
1398 this, SIGNAL(changed()));
1399 connect(formatModifyPB, SIGNAL(clicked()),
1400 this, SIGNAL(changed()));
1404 void PrefFileformats::apply(LyXRC & /*rc*/) const
1409 void PrefFileformats::update(LyXRC const & /*rc*/)
1415 void PrefFileformats::updateView()
1417 // save current selection
1418 QString current = guiNameED->text();
1420 // update listwidget with formats
1421 formatsLW->blockSignals(true);
1423 Formats::const_iterator cit = form_->formats().begin();
1424 Formats::const_iterator end = form_->formats().end();
1425 for (; cit != end; ++cit) {
1426 new QListWidgetItem(toqstr(cit->prettyname()),
1428 form_->formats().getNumber(cit->name()) );
1430 formatsLW->sortItems(Qt::AscendingOrder);
1431 formatsLW->blockSignals(false);
1433 // restore selection
1434 if (!current.isEmpty()) {
1435 QList<QListWidgetItem *> item = formatsLW->findItems(current, Qt::MatchExactly);
1437 formatsLW->setCurrentItem(item.at(0));
1439 // select first element if restoring failed
1440 if (formatsLW->currentRow() == -1)
1441 formatsLW->setCurrentRow(0);
1445 void PrefFileformats::switch_format(int nr)
1447 int const ftype = formatsLW->item(nr)->type();
1448 Format const f = form_->formats().get(ftype);
1450 formatED->setText(toqstr(f.name()));
1451 guiNameED->setText(toqstr(f.prettyname()));
1452 extensionED->setText(toqstr(f.extension()));
1453 shortcutED->setText(toqstr(f.shortcut()));
1454 viewerED->setText(toqstr(f.viewer()));
1455 editorED->setText(toqstr(f.editor()));
1456 documentCB->setChecked((f.documentFormat()));
1457 vectorCB->setChecked((f.vectorFormat()));
1463 void PrefFileformats::fileformat_changed()
1469 void PrefFileformats::updateButtons()
1471 QString const format = formatED->text();
1472 QString const gui_name = guiNameED->text();
1473 int const sel = form_->formats().getNumber(fromqstr(format));
1474 bool gui_name_known = false;
1476 for (int i = 0; i < formatsLW->count(); ++i) {
1477 if (formatsLW->item(i)->text() == gui_name) {
1478 gui_name_known = true;
1479 where = formatsLW->item(i)->type();
1483 // assure that a gui name cannot be chosen twice
1484 bool const known_otherwise = gui_name_known && (where != sel);
1486 bool const known = !(sel < 0);
1487 bool const valid = (!formatED->text().isEmpty()
1488 && !guiNameED->text().isEmpty());
1490 int const ftype = formatsLW->currentItem()->type();
1491 Format const & f(form_->formats().get(ftype));
1492 string const old_pretty(f.prettyname());
1493 string const old_shortcut(f.shortcut());
1494 string const old_extension(f.extension());
1495 string const old_viewer(f.viewer());
1496 string const old_editor(f.editor());
1497 bool const old_document(f.documentFormat());
1498 bool const old_vector(f.vectorFormat());
1500 string const new_pretty(fromqstr(gui_name));
1501 string const new_shortcut(fromqstr(shortcutED->text()));
1502 string const new_extension(fromqstr(extensionED->text()));
1503 string const new_viewer(fromqstr(viewerED->text()));
1504 string const new_editor(fromqstr(editorED->text()));
1505 bool const new_document(documentCB->isChecked());
1506 bool const new_vector(vectorCB->isChecked());
1508 bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
1509 || (old_extension != new_extension) || (old_viewer != new_viewer)
1510 || old_editor != new_editor || old_document != new_document
1511 || old_vector != new_vector);
1513 formatModifyPB->setEnabled(valid && known && modified && !known_otherwise);
1514 formatNewPB->setEnabled(valid && !known && !gui_name_known);
1515 formatRemovePB->setEnabled(known);
1519 void PrefFileformats::new_format()
1521 string const name = fromqstr(formatED->text());
1522 string const prettyname = fromqstr(guiNameED->text());
1523 string const extension = fromqstr(extensionED->text());
1524 string const shortcut = fromqstr(shortcutED->text());
1525 string const viewer = fromqstr(viewerED->text());
1526 string const editor = fromqstr(editorED->text());
1527 int flags = Format::none;
1528 if (documentCB->isChecked())
1529 flags |= Format::document;
1530 if (vectorCB->isChecked())
1531 flags |= Format::vector;
1533 form_->formats().add(name, extension, prettyname, shortcut, viewer,
1535 form_->formats().sort();
1536 form_->converters().update(form_->formats());
1544 void PrefFileformats::modify_format()
1546 int const current_item = formatsLW->currentItem()->type();
1547 Format const & oldformat = form_->formats().get(current_item);
1548 form_->formats().erase(oldformat.name());
1554 void PrefFileformats::remove_format()
1556 int const nr = formatsLW->currentItem()->type();
1557 string const current_text = form_->formats().get(nr).name();
1558 if (form_->converters().formatIsUsed(current_text)) {
1559 Alert::error(_("Format in use"),
1560 _("Cannot remove a Format used by a Converter. "
1561 "Remove the converter first."));
1565 form_->formats().erase(current_text);
1566 form_->converters().update(form_->formats());
1574 /////////////////////////////////////////////////////////////////////
1578 /////////////////////////////////////////////////////////////////////
1580 PrefLanguage::PrefLanguage(QWidget * parent)
1581 : PrefModule(_("Language"), 0, parent)
1585 connect(rtlCB, SIGNAL(clicked()),
1586 this, SIGNAL(changed()));
1587 connect(markForeignCB, SIGNAL(clicked()),
1588 this, SIGNAL(changed()));
1589 connect(autoBeginCB, SIGNAL(clicked()),
1590 this, SIGNAL(changed()));
1591 connect(autoEndCB, SIGNAL(clicked()),
1592 this, SIGNAL(changed()));
1593 connect(useBabelCB, SIGNAL(clicked()),
1594 this, SIGNAL(changed()));
1595 connect(globalCB, SIGNAL(clicked()),
1596 this, SIGNAL(changed()));
1597 connect(languagePackageED, SIGNAL(textChanged(const QString&)),
1598 this, SIGNAL(changed()));
1599 connect(startCommandED, SIGNAL(textChanged(const QString&)),
1600 this, SIGNAL(changed()));
1601 connect(endCommandED, SIGNAL(textChanged(const QString&)),
1602 this, SIGNAL(changed()));
1603 connect(defaultLanguageCO, SIGNAL(activated(int)),
1604 this, SIGNAL(changed()));
1606 defaultLanguageCO->clear();
1608 // store the lang identifiers for later
1609 std::vector<LanguagePair> const langs = frontend::getLanguageData(false);
1610 std::vector<LanguagePair>::const_iterator lit = langs.begin();
1611 std::vector<LanguagePair>::const_iterator lend = langs.end();
1613 for (; lit != lend; ++lit) {
1614 defaultLanguageCO->addItem(toqstr(lit->first));
1615 lang_.push_back(lit->second);
1620 void PrefLanguage::apply(LyXRC & rc) const
1622 // FIXME: remove rtl_support bool
1623 rc.rtl_support = rtlCB->isChecked();
1624 rc.mark_foreign_language = markForeignCB->isChecked();
1625 rc.language_auto_begin = autoBeginCB->isChecked();
1626 rc.language_auto_end = autoEndCB->isChecked();
1627 rc.language_use_babel = useBabelCB->isChecked();
1628 rc.language_global_options = globalCB->isChecked();
1629 rc.language_package = fromqstr(languagePackageED->text());
1630 rc.language_command_begin = fromqstr(startCommandED->text());
1631 rc.language_command_end = fromqstr(endCommandED->text());
1632 rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1636 void PrefLanguage::update(LyXRC const & rc)
1638 // FIXME: remove rtl_support bool
1639 rtlCB->setChecked(rc.rtl_support);
1640 markForeignCB->setChecked(rc.mark_foreign_language);
1641 autoBeginCB->setChecked(rc.language_auto_begin);
1642 autoEndCB->setChecked(rc.language_auto_end);
1643 useBabelCB->setChecked(rc.language_use_babel);
1644 globalCB->setChecked(rc.language_global_options);
1645 languagePackageED->setText(toqstr(rc.language_package));
1646 startCommandED->setText(toqstr(rc.language_command_begin));
1647 endCommandED->setText(toqstr(rc.language_command_end));
1649 int const pos = int(findPos_helper(lang_, rc.default_language));
1650 defaultLanguageCO->setCurrentIndex(pos);
1654 /////////////////////////////////////////////////////////////////////
1658 /////////////////////////////////////////////////////////////////////
1660 PrefPrinter::PrefPrinter(QWidget * parent)
1661 : PrefModule(_("Printer"), 0, parent)
1665 connect(printerAdaptCB, SIGNAL(clicked()),
1666 this, SIGNAL(changed()));
1667 connect(printerCommandED, SIGNAL(textChanged(const QString&)),
1668 this, SIGNAL(changed()));
1669 connect(printerNameED, SIGNAL(textChanged(const QString&)),
1670 this, SIGNAL(changed()));
1671 connect(printerPageRangeED, SIGNAL(textChanged(const QString&)),
1672 this, SIGNAL(changed()));
1673 connect(printerCopiesED, SIGNAL(textChanged(const QString&)),
1674 this, SIGNAL(changed()));
1675 connect(printerReverseED, SIGNAL(textChanged(const QString&)),
1676 this, SIGNAL(changed()));
1677 connect(printerToPrinterED, SIGNAL(textChanged(const QString&)),
1678 this, SIGNAL(changed()));
1679 connect(printerExtensionED, SIGNAL(textChanged(const QString&)),
1680 this, SIGNAL(changed()));
1681 connect(printerSpoolCommandED, SIGNAL(textChanged(const QString&)),
1682 this, SIGNAL(changed()));
1683 connect(printerPaperTypeED, SIGNAL(textChanged(const QString&)),
1684 this, SIGNAL(changed()));
1685 connect(printerEvenED, SIGNAL(textChanged(const QString&)),
1686 this, SIGNAL(changed()));
1687 connect(printerOddED, SIGNAL(textChanged(const QString&)),
1688 this, SIGNAL(changed()));
1689 connect(printerCollatedED, SIGNAL(textChanged(const QString&)),
1690 this, SIGNAL(changed()));
1691 connect(printerLandscapeED, SIGNAL(textChanged(const QString&)),
1692 this, SIGNAL(changed()));
1693 connect(printerToFileED, SIGNAL(textChanged(const QString&)),
1694 this, SIGNAL(changed()));
1695 connect(printerExtraED, SIGNAL(textChanged(const QString&)),
1696 this, SIGNAL(changed()));
1697 connect(printerSpoolPrefixED, SIGNAL(textChanged(const QString&)),
1698 this, SIGNAL(changed()));
1699 connect(printerPaperSizeED, SIGNAL(textChanged(const QString&)),
1700 this, SIGNAL(changed()));
1704 void PrefPrinter::apply(LyXRC & rc) const
1706 rc.print_adapt_output = printerAdaptCB->isChecked();
1707 rc.print_command = fromqstr(printerCommandED->text());
1708 rc.printer = fromqstr(printerNameED->text());
1710 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1711 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1712 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1713 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1714 rc.print_file_extension = fromqstr(printerExtensionED->text());
1715 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1716 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1717 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1718 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1719 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1720 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1721 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1722 rc.print_extra_options = fromqstr(printerExtraED->text());
1723 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1724 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1728 void PrefPrinter::update(LyXRC const & rc)
1730 printerAdaptCB->setChecked(rc.print_adapt_output);
1731 printerCommandED->setText(toqstr(rc.print_command));
1732 printerNameED->setText(toqstr(rc.printer));
1734 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1735 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1736 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1737 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1738 printerExtensionED->setText(toqstr(rc.print_file_extension));
1739 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1740 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1741 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1742 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1743 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1744 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1745 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1746 printerExtraED->setText(toqstr(rc.print_extra_options));
1747 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1748 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1752 /////////////////////////////////////////////////////////////////////
1754 // PrefUserInterface
1756 /////////////////////////////////////////////////////////////////////
1758 PrefUserInterface::PrefUserInterface(GuiPrefsDialog * form, QWidget * parent)
1759 : PrefModule(_("User interface"), form, parent)
1763 connect(autoSaveCB, SIGNAL(toggled(bool)),
1764 autoSaveLA, SLOT(setEnabled(bool)));
1765 connect(autoSaveCB, SIGNAL(toggled(bool)),
1766 autoSaveSB, SLOT(setEnabled(bool)));
1767 connect(autoSaveCB, SIGNAL(toggled(bool)),
1768 TextLabel1, SLOT(setEnabled(bool)));
1769 connect(uiFilePB, SIGNAL(clicked()),
1770 this, SLOT(select_ui()));
1771 connect(bindFilePB, SIGNAL(clicked()),
1772 this, SLOT(select_bind()));
1773 connect(uiFileED, SIGNAL(textChanged(const QString &)),
1774 this, SIGNAL(changed()));
1775 connect(bindFileED, SIGNAL(textChanged(const QString &)),
1776 this, SIGNAL(changed()));
1777 connect(restoreCursorCB, SIGNAL(clicked()),
1778 this, SIGNAL(changed()));
1779 connect(loadSessionCB, SIGNAL(clicked()),
1780 this, SIGNAL(changed()));
1781 connect(loadWindowSizeCB, SIGNAL(clicked()),
1782 this, SIGNAL(changed()));
1783 connect(loadWindowLocationCB, SIGNAL(clicked()),
1784 this, SIGNAL(changed()));
1785 connect(windowWidthSB, SIGNAL(valueChanged(int)),
1786 this, SIGNAL(changed()));
1787 connect(windowHeightSB, SIGNAL(valueChanged(int)),
1788 this, SIGNAL(changed()));
1789 connect(cursorFollowsCB, SIGNAL(clicked()),
1790 this, SIGNAL(changed()));
1791 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1792 this, SIGNAL(changed()));
1793 connect(autoSaveCB, SIGNAL(clicked()),
1794 this, SIGNAL(changed()));
1795 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1796 this, SIGNAL(changed()));
1797 lastfilesSB->setMaximum(maxlastfiles);
1801 void PrefUserInterface::apply(LyXRC & rc) const
1803 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1804 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1805 rc.use_lastfilepos = restoreCursorCB->isChecked();
1806 rc.load_session = loadSessionCB->isChecked();
1807 if (loadWindowSizeCB->isChecked()) {
1808 rc.geometry_width = 0;
1809 rc.geometry_height = 0;
1811 rc.geometry_width = windowWidthSB->value();
1812 rc.geometry_height = windowHeightSB->value();
1814 rc.geometry_xysaved = loadWindowLocationCB->isChecked();
1815 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1816 rc.autosave = autoSaveSB->value() * 60;
1817 rc.make_backup = autoSaveCB->isChecked();
1818 rc.num_lastfiles = lastfilesSB->value();
1822 void PrefUserInterface::update(LyXRC const & rc)
1824 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1825 bindFileED->setText(toqstr(external_path(rc.bind_file)));
1826 restoreCursorCB->setChecked(rc.use_lastfilepos);
1827 loadSessionCB->setChecked(rc.load_session);
1828 bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
1829 loadWindowSizeCB->setChecked(loadWindowSize);
1830 if (!loadWindowSize) {
1831 windowWidthSB->setValue(rc.geometry_width);
1832 windowHeightSB->setValue(rc.geometry_height);
1834 loadWindowLocationCB->setChecked(rc.geometry_xysaved);
1835 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1836 // convert to minutes
1837 int mins(rc.autosave / 60);
1838 if (rc.autosave && !mins)
1840 autoSaveSB->setValue(mins);
1841 autoSaveCB->setChecked(rc.make_backup);
1842 lastfilesSB->setValue(rc.num_lastfiles);
1847 void PrefUserInterface::select_ui()
1849 docstring const name =
1850 from_utf8(internal_path(fromqstr(uiFileED->text())));
1851 docstring file(form_->controller().browseUI(name));
1853 uiFileED->setText(toqstr(file));
1857 void PrefUserInterface::select_bind()
1859 docstring const name =
1860 from_utf8(internal_path(fromqstr(bindFileED->text())));
1861 docstring file(form_->controller().browsebind(name));
1863 bindFileED->setText(toqstr(file));
1867 void PrefUserInterface::on_loadWindowSizeCB_toggled(bool loadwindowsize)
1869 windowWidthLA->setDisabled(loadwindowsize);
1870 windowHeightLA->setDisabled(loadwindowsize);
1871 windowWidthSB->setDisabled(loadwindowsize);
1872 windowHeightSB->setDisabled(loadwindowsize);
1876 PrefIdentity::PrefIdentity(QWidget * parent)
1877 : PrefModule(_("Identity"), 0, parent)
1881 connect(nameED, SIGNAL(textChanged(const QString&)),
1882 this, SIGNAL(changed()));
1883 connect(emailED, SIGNAL(textChanged(const QString&)),
1884 this, SIGNAL(changed()));
1888 void PrefIdentity::apply(LyXRC & rc) const
1890 rc.user_name = fromqstr(nameED->text());
1891 rc.user_email = fromqstr(emailED->text());
1895 void PrefIdentity::update(LyXRC const & rc)
1897 nameED->setText(toqstr(rc.user_name));
1898 emailED->setText(toqstr(rc.user_email));
1903 /////////////////////////////////////////////////////////////////////
1907 /////////////////////////////////////////////////////////////////////
1909 GuiPrefsDialog::GuiPrefsDialog(LyXView & lv)
1910 : GuiDialog(lv, "prefs")
1913 setViewTitle(_("Preferences"));
1914 setController(new ControlPrefs(*this));
1916 QDialog::setModal(false);
1918 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
1919 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
1920 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
1921 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
1923 add(new PrefUserInterface(this));
1924 add(new PrefScreenFonts(this));
1925 add(new PrefColors(this));
1926 add(new PrefDisplay);
1927 add(new PrefKeyboard(this));
1929 add(new PrefPaths(this));
1931 add(new PrefIdentity);
1933 add(new PrefLanguage);
1934 add(new PrefSpellchecker(this));
1936 add(new PrefPrinter);
1938 add(new PrefPlaintext);
1939 add(new PrefLatex(this));
1941 PrefConverters * converters = new PrefConverters(this);
1942 PrefFileformats * formats = new PrefFileformats(this);
1943 connect(formats, SIGNAL(formatsChanged()),
1944 converters, SLOT(updateGui()));
1948 add(new PrefCopiers(this));
1951 prefsPS->setCurrentPanel(_("User interface"));
1952 // FIXME: hack to work around resizing bug in Qt >= 4.2
1953 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1954 #if QT_VERSION >= 0x040200
1955 prefsPS->updateGeometry();
1958 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
1960 bc().setApply(applyPB);
1961 bc().setCancel(closePB);
1962 bc().setRestore(restorePB);
1966 ControlPrefs & GuiPrefsDialog::controller()
1968 return static_cast<ControlPrefs &>(GuiDialog::controller());
1972 void GuiPrefsDialog::add(PrefModule * module)
1974 BOOST_ASSERT(module);
1975 prefsPS->addPanel(module, module->title());
1976 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
1977 modules_.push_back(module);
1981 void GuiPrefsDialog::closeEvent(QCloseEvent * e)
1988 void GuiPrefsDialog::change_adaptor()
1994 void GuiPrefsDialog::apply(LyXRC & rc) const
1996 size_t end = modules_.size();
1997 for (size_t i = 0; i != end; ++i)
1998 modules_[i]->apply(rc);
2002 void GuiPrefsDialog::updateRc(LyXRC const & rc)
2004 size_t const end = modules_.size();
2005 for (size_t i = 0; i != end; ++i)
2006 modules_[i]->update(rc);
2010 Converters & GuiPrefsDialog::converters()
2012 return controller().converters();
2015 Formats & GuiPrefsDialog::formats()
2017 return controller().formats();
2020 Movers & GuiPrefsDialog::movers()
2022 return controller().movers();
2025 void GuiPrefsDialog::applyView()
2027 apply(controller().rc());
2030 void GuiPrefsDialog::updateContents()
2032 updateRc(controller().rc());
2035 } // namespace frontend
2038 #include "GuiPrefs_moc.cpp"