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.
16 #include "qt_helpers.h"
17 #include "GuiApplication.h"
19 #include "ConverterCache.h"
24 #include "PanelStack.h"
25 #include "QFontExample.h"
28 #include "support/lstrings.h"
29 #include "support/os.h"
31 #include "controllers/ControlPrefs.h"
32 #include "controllers/frontend_helpers.h"
34 #include "frontends/alert.h"
35 #include "frontends/Application.h"
38 #include <QColorDialog>
39 #include <QFontDatabase>
41 #include <QPushButton>
45 #include <QCloseEvent>
47 #include <boost/tuple/tuple.hpp>
53 using lyx::support::compare_ascii_no_case;
54 using lyx::support::os::external_path;
55 using lyx::support::os::external_path_list;
56 using lyx::support::os::internal_path;
57 using lyx::support::os::internal_path_list;
68 /////////////////////////////////////////////////////////////////////
72 /////////////////////////////////////////////////////////////////////
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 frontend_helpers.h
82 static size_t findPos_helper(std::vector<A> const & vec, A const & val)
84 typedef typename std::vector<A>::const_iterator Cit;
86 Cit it = std::find(vec.begin(), vec.end(), val);
89 return std::distance(vec.begin(), it);
93 static void setComboxFont(QComboBox * cb, string const & family,
94 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_ascii_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_ascii_no_case(tmp.first, tmpfam.first) == 0) {
122 cb->setCurrentIndex(i);
127 // Bleh, default fonts, and the names couldn't be found. Hack
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_ascii_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 /////////////////////////////////////////////////////////////////////
171 /////////////////////////////////////////////////////////////////////
173 PrefPlaintext::PrefPlaintext(QWidget * parent)
174 : PrefModule(_(Outputs), _("Plain text"), 0, parent)
177 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
178 this, SIGNAL(changed()));
179 connect(plaintextRoffED, SIGNAL(textChanged(const QString&)),
180 this, SIGNAL(changed()));
184 void PrefPlaintext::apply(LyXRC & rc) const
186 rc.plaintext_linelen = plaintextLinelengthSB->value();
187 rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
191 void PrefPlaintext::update(LyXRC const & rc)
193 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
194 plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
198 /////////////////////////////////////////////////////////////////////
202 /////////////////////////////////////////////////////////////////////
204 PrefDate::PrefDate(QWidget * parent)
205 : PrefModule(_(Outputs), _("Date format"), 0, parent)
208 connect(DateED, SIGNAL(textChanged(const QString &)),
209 this, SIGNAL(changed()));
213 void PrefDate::apply(LyXRC & rc) const
215 rc.date_insert_format = fromqstr(DateED->text());
219 void PrefDate::update(LyXRC const & rc)
221 DateED->setText(toqstr(rc.date_insert_format));
225 /////////////////////////////////////////////////////////////////////
229 /////////////////////////////////////////////////////////////////////
231 PrefKeyboard::PrefKeyboard(QPrefs * form, QWidget * parent)
232 : PrefModule(_(LookAndFeel), _("Keyboard"), form, parent)
236 connect(keymapCB, SIGNAL(clicked()),
237 this, SIGNAL(changed()));
238 connect(firstKeymapED, SIGNAL(textChanged(const QString&)),
239 this, SIGNAL(changed()));
240 connect(secondKeymapED, SIGNAL(textChanged(const QString&)),
241 this, SIGNAL(changed()));
245 void PrefKeyboard::apply(LyXRC & rc) const
247 // FIXME: can derive CB from the two EDs
248 rc.use_kbmap = keymapCB->isChecked();
249 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
250 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
254 void PrefKeyboard::update(LyXRC const & rc)
256 // FIXME: can derive CB from the two EDs
257 keymapCB->setChecked(rc.use_kbmap);
258 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
259 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
263 QString PrefKeyboard::testKeymap(QString keymap)
265 return toqstr(form_->controller().browsekbmap(from_utf8(internal_path(fromqstr(keymap)))));
269 void PrefKeyboard::on_firstKeymapPB_clicked(bool)
271 QString const file = testKeymap(firstKeymapED->text());
273 firstKeymapED->setText(file);
277 void PrefKeyboard::on_secondKeymapPB_clicked(bool)
279 QString const file = testKeymap(secondKeymapED->text());
281 secondKeymapED->setText(file);
285 void PrefKeyboard::on_keymapCB_toggled(bool keymap)
287 firstKeymapLA->setEnabled(keymap);
288 secondKeymapLA->setEnabled(keymap);
289 firstKeymapED->setEnabled(keymap);
290 secondKeymapED->setEnabled(keymap);
291 firstKeymapPB->setEnabled(keymap);
292 secondKeymapPB->setEnabled(keymap);
296 /////////////////////////////////////////////////////////////////////
300 /////////////////////////////////////////////////////////////////////
302 PrefLatex::PrefLatex(QPrefs * form, QWidget * parent)
303 : PrefModule(_(Outputs), _("LaTeX"), form, parent)
306 connect(latexEncodingED, SIGNAL(textChanged(const QString&)),
307 this, SIGNAL(changed()));
308 connect(latexChecktexED, SIGNAL(textChanged(const QString&)),
309 this, SIGNAL(changed()));
310 connect(latexBibtexED, SIGNAL(textChanged(const QString&)),
311 this, SIGNAL(changed()));
312 connect(latexIndexED, SIGNAL(textChanged(const QString&)),
313 this, SIGNAL(changed()));
314 connect(latexAutoresetCB, SIGNAL(clicked()),
315 this, SIGNAL(changed()));
316 connect(latexDviPaperED, SIGNAL(textChanged(const QString&)),
317 this, SIGNAL(changed()));
318 connect(latexPaperSizeCO, SIGNAL(activated(int)),
319 this, SIGNAL(changed()));
323 void PrefLatex::apply(LyXRC & rc) const
325 rc.fontenc = fromqstr(latexEncodingED->text());
326 rc.chktex_command = fromqstr(latexChecktexED->text());
327 rc.bibtex_command = fromqstr(latexBibtexED->text());
328 rc.index_command = fromqstr(latexIndexED->text());
329 rc.auto_reset_options = latexAutoresetCB->isChecked();
330 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
331 rc.default_papersize =
332 form_->controller().toPaperSize(latexPaperSizeCO->currentIndex());
336 void PrefLatex::update(LyXRC const & rc)
338 latexEncodingED->setText(toqstr(rc.fontenc));
339 latexChecktexED->setText(toqstr(rc.chktex_command));
340 latexBibtexED->setText(toqstr(rc.bibtex_command));
341 latexIndexED->setText(toqstr(rc.index_command));
342 latexAutoresetCB->setChecked(rc.auto_reset_options);
343 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
344 latexPaperSizeCO->setCurrentIndex(
345 form_->controller().fromPaperSize(rc.default_papersize));
349 /////////////////////////////////////////////////////////////////////
353 /////////////////////////////////////////////////////////////////////
355 PrefScreenFonts::PrefScreenFonts(QPrefs * form, QWidget * parent)
356 : PrefModule(_(LookAndFeel), _("Screen fonts"), form, parent)
360 connect(screenRomanCO, SIGNAL(activated(const QString&)),
361 this, SLOT(select_roman(const QString&)));
362 connect(screenSansCO, SIGNAL(activated(const QString&)),
363 this, SLOT(select_sans(const QString&)));
364 connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
365 this, SLOT(select_typewriter(const QString&)));
367 QFontDatabase fontdb;
368 QStringList families(fontdb.families());
369 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
370 screenRomanCO->addItem(*it);
371 screenSansCO->addItem(*it);
372 screenTypewriterCO->addItem(*it);
374 connect(screenRomanCO, SIGNAL(activated(const QString&)),
375 this, SIGNAL(changed()));
376 connect(screenSansCO, SIGNAL(activated(const QString&)),
377 this, SIGNAL(changed()));
378 connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
379 this, SIGNAL(changed()));
380 connect(screenZoomSB, SIGNAL(valueChanged(int)),
381 this, SIGNAL(changed()));
382 connect(screenDpiSB, SIGNAL(valueChanged(int)),
383 this, SIGNAL(changed()));
384 connect(screenTinyED, SIGNAL(textChanged(const QString&)),
385 this, SIGNAL(changed()));
386 connect(screenSmallestED, SIGNAL(textChanged(const QString&)),
387 this, SIGNAL(changed()));
388 connect(screenSmallerED, SIGNAL(textChanged(const QString&)),
389 this, SIGNAL(changed()));
390 connect(screenSmallED, SIGNAL(textChanged(const QString&)),
391 this, SIGNAL(changed()));
392 connect(screenNormalED, SIGNAL(textChanged(const QString&)),
393 this, SIGNAL(changed()));
394 connect(screenLargeED, SIGNAL(textChanged(const QString&)),
395 this, SIGNAL(changed()));
396 connect(screenLargerED, SIGNAL(textChanged(const QString&)),
397 this, SIGNAL(changed()));
398 connect(screenLargestED, SIGNAL(textChanged(const QString&)),
399 this, SIGNAL(changed()));
400 connect(screenHugeED, SIGNAL(textChanged(const QString&)),
401 this, SIGNAL(changed()));
402 connect(screenHugerED, SIGNAL(textChanged(const QString&)),
403 this, SIGNAL(changed()));
405 screenTinyED->setValidator(new QDoubleValidator(
407 screenSmallestED->setValidator(new QDoubleValidator(
409 screenSmallerED->setValidator(new QDoubleValidator(
411 screenSmallED->setValidator(new QDoubleValidator(
413 screenNormalED->setValidator(new QDoubleValidator(
415 screenLargeED->setValidator(new QDoubleValidator(
417 screenLargerED->setValidator(new QDoubleValidator(
419 screenLargestED->setValidator(new QDoubleValidator(
421 screenHugeED->setValidator(new QDoubleValidator(
423 screenHugerED->setValidator(new QDoubleValidator(
428 void PrefScreenFonts::apply(LyXRC & rc) const
430 LyXRC const oldrc(rc);
432 boost::tie(rc.roman_font_name, rc.roman_font_foundry)
433 = parseFontName(fromqstr(screenRomanCO->currentText()));
434 boost::tie(rc.sans_font_name, rc.sans_font_foundry) =
435 parseFontName(fromqstr(screenSansCO->currentText()));
436 boost::tie(rc.typewriter_font_name, rc.typewriter_font_foundry) =
437 parseFontName(fromqstr(screenTypewriterCO->currentText()));
439 rc.zoom = screenZoomSB->value();
440 rc.dpi = screenDpiSB->value();
441 rc.font_sizes[Font::SIZE_TINY] = fromqstr(screenTinyED->text());
442 rc.font_sizes[Font::SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
443 rc.font_sizes[Font::SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
444 rc.font_sizes[Font::SIZE_SMALL] = fromqstr(screenSmallED->text());
445 rc.font_sizes[Font::SIZE_NORMAL] = fromqstr(screenNormalED->text());
446 rc.font_sizes[Font::SIZE_LARGE] = fromqstr(screenLargeED->text());
447 rc.font_sizes[Font::SIZE_LARGER] = fromqstr(screenLargerED->text());
448 rc.font_sizes[Font::SIZE_LARGEST] = fromqstr(screenLargestED->text());
449 rc.font_sizes[Font::SIZE_HUGE] = fromqstr(screenHugeED->text());
450 rc.font_sizes[Font::SIZE_HUGER] = fromqstr(screenHugerED->text());
452 if (rc.font_sizes != oldrc.font_sizes
453 || rc.roman_font_name != oldrc.roman_font_name
454 || rc.sans_font_name != oldrc.sans_font_name
455 || rc.typewriter_font_name != oldrc.typewriter_font_name
456 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
457 form_->controller().updateScreenFonts();
462 void PrefScreenFonts::update(LyXRC const & rc)
464 setComboxFont(screenRomanCO, rc.roman_font_name,
465 rc.roman_font_foundry);
466 setComboxFont(screenSansCO, rc.sans_font_name,
467 rc.sans_font_foundry);
468 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
469 rc.typewriter_font_foundry);
471 select_roman(screenRomanCO->currentText());
472 select_sans(screenSansCO->currentText());
473 select_typewriter(screenTypewriterCO->currentText());
475 screenZoomSB->setValue(rc.zoom);
476 screenDpiSB->setValue(rc.dpi);
477 screenTinyED->setText(toqstr(rc.font_sizes[Font::SIZE_TINY]));
478 screenSmallestED->setText(toqstr(rc.font_sizes[Font::SIZE_SCRIPT]));
479 screenSmallerED->setText(toqstr(rc.font_sizes[Font::SIZE_FOOTNOTE]));
480 screenSmallED->setText(toqstr(rc.font_sizes[Font::SIZE_SMALL]));
481 screenNormalED->setText(toqstr(rc.font_sizes[Font::SIZE_NORMAL]));
482 screenLargeED->setText(toqstr(rc.font_sizes[Font::SIZE_LARGE]));
483 screenLargerED->setText(toqstr(rc.font_sizes[Font::SIZE_LARGER]));
484 screenLargestED->setText(toqstr(rc.font_sizes[Font::SIZE_LARGEST]));
485 screenHugeED->setText(toqstr(rc.font_sizes[Font::SIZE_HUGE]));
486 screenHugerED->setText(toqstr(rc.font_sizes[Font::SIZE_HUGER]));
489 void PrefScreenFonts::select_roman(const QString& name)
491 screenRomanFE->set(QFont(name), name);
495 void PrefScreenFonts::select_sans(const QString& name)
497 screenSansFE->set(QFont(name), name);
501 void PrefScreenFonts::select_typewriter(const QString& name)
503 screenTypewriterFE->set(QFont(name), name);
507 /////////////////////////////////////////////////////////////////////
511 /////////////////////////////////////////////////////////////////////
513 PrefColors::PrefColors(QPrefs * form, QWidget * parent)
514 : PrefModule(_(LookAndFeel), _("Colors"), form, parent)
518 // FIXME: all of this initialization should be put into the controller.
519 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
520 // for some discussion of why that is not trivial.
521 QPixmap icon(32, 32);
522 for (int i = 0; i < Color::ignore; ++i) {
523 Color::color lc = static_cast<Color::color>(i);
524 if (lc == Color::none
525 || lc == Color::black
526 || lc == Color::white
528 || lc == Color::green
531 || lc == Color::magenta
532 || lc == Color::yellow
533 || lc == Color::inherit
534 || lc == Color::ignore) continue;
536 lcolors_.push_back(lc);
537 // This is not a memory leak:
538 /*QListWidgetItem * newItem =*/ new QListWidgetItem(QIcon(icon),
539 toqstr(lcolor.getGUIName(lc)), lyxObjectsLW);
541 curcolors_.resize(lcolors_.size());
542 newcolors_.resize(lcolors_.size());
543 // End initialization
545 connect(colorChangePB, SIGNAL(clicked()),
546 this, SLOT(change_color()));
547 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
548 this, SLOT(change_lyxObjects_selection()));
549 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
550 this, SLOT(change_color()));
554 void PrefColors::apply(LyXRC & /*rc*/) const
556 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
557 if (curcolors_[i] != newcolors_[i]) {
558 form_->controller().setColor(lcolors_[i], fromqstr(newcolors_[i]));
564 void PrefColors::update(LyXRC const & /*rc*/)
566 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
567 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
568 QPixmap coloritem(32, 32);
569 coloritem.fill(color);
570 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
571 newcolors_[i] = curcolors_[i] = color.name();
573 change_lyxObjects_selection();
576 void PrefColors::change_color()
578 int const row = lyxObjectsLW->currentRow();
583 QString const color = newcolors_[row];
584 QColor c(QColorDialog::getColor(QColor(color), qApp->focusWidget()));
586 if (c.isValid() && c.name() != color) {
587 newcolors_[row] = c.name();
588 QPixmap coloritem(32, 32);
590 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
596 void PrefColors::change_lyxObjects_selection()
598 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
602 /////////////////////////////////////////////////////////////////////
606 /////////////////////////////////////////////////////////////////////
608 PrefCygwinPath::PrefCygwinPath(QWidget * parent)
609 : PrefModule(_(Outputs), _("Paths"), 0, parent)
612 connect(pathCB, SIGNAL(clicked()), this, SIGNAL(changed()));
616 void PrefCygwinPath::apply(LyXRC & rc) const
618 rc.windows_style_tex_paths = pathCB->isChecked();
622 void PrefCygwinPath::update(LyXRC const & rc)
624 pathCB->setChecked(rc.windows_style_tex_paths);
628 /////////////////////////////////////////////////////////////////////
632 /////////////////////////////////////////////////////////////////////
634 PrefDisplay::PrefDisplay(QWidget * parent)
635 : PrefModule(_(LookAndFeel), _("Graphics"), 0, parent)
638 connect(instantPreviewCO, SIGNAL(activated(int)),
639 this, SIGNAL(changed()));
640 connect(displayGraphicsCO, SIGNAL(activated(int)),
641 this, SIGNAL(changed()));
645 void PrefDisplay::apply(LyXRC & rc) const
647 switch (instantPreviewCO->currentIndex()) {
648 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
649 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
650 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
653 lyx::graphics::DisplayType dtype;
654 switch (displayGraphicsCO->currentIndex()) {
655 case 3: dtype = lyx::graphics::NoDisplay; break;
656 case 2: dtype = lyx::graphics::ColorDisplay; break;
657 case 1: dtype = lyx::graphics::GrayscaleDisplay; break;
658 case 0: dtype = lyx::graphics::MonochromeDisplay; break;
659 default: dtype = lyx::graphics::GrayscaleDisplay;
661 rc.display_graphics = dtype;
664 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
667 if (old_value != rc.display_graphics) {
668 lyx::graphics::GCache & gc = lyx::graphics::GCache::get();
675 void PrefDisplay::update(LyXRC const & rc)
677 switch (rc.preview) {
678 case LyXRC::PREVIEW_OFF:
679 instantPreviewCO->setCurrentIndex(0);
681 case LyXRC::PREVIEW_NO_MATH :
682 instantPreviewCO->setCurrentIndex(1);
684 case LyXRC::PREVIEW_ON :
685 instantPreviewCO->setCurrentIndex(2);
690 switch (rc.display_graphics) {
691 case lyx::graphics::NoDisplay: item = 3; break;
692 case lyx::graphics::ColorDisplay: item = 2; break;
693 case lyx::graphics::GrayscaleDisplay: item = 1; break;
694 case lyx::graphics::MonochromeDisplay: item = 0; break;
697 displayGraphicsCO->setCurrentIndex(item);
701 /////////////////////////////////////////////////////////////////////
705 /////////////////////////////////////////////////////////////////////
707 PrefPaths::PrefPaths(QPrefs * form, QWidget * parent)
708 : PrefModule(docstring(), _("Paths"), form, parent)
711 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
712 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
713 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
714 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
715 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
716 connect(workingDirED, SIGNAL(textChanged(const QString&)),
717 this, SIGNAL(changed()));
718 connect(templateDirED, SIGNAL(textChanged(const QString&)),
719 this, SIGNAL(changed()));
720 connect(backupDirED, SIGNAL(textChanged(const QString&)),
721 this, SIGNAL(changed()));
722 connect(tempDirED, SIGNAL(textChanged(const QString&)),
723 this, SIGNAL(changed()));
724 connect(lyxserverDirED, SIGNAL(textChanged(const QString&)),
725 this, SIGNAL(changed()));
726 connect(pathPrefixED, SIGNAL(textChanged(const QString&)),
727 this, SIGNAL(changed()));
731 void PrefPaths::apply(LyXRC & rc) const
733 rc.document_path = internal_path(fromqstr(workingDirED->text()));
734 rc.template_path = internal_path(fromqstr(templateDirED->text()));
735 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
736 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
737 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
738 // FIXME: should be a checkbox only
739 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
743 void PrefPaths::update(LyXRC const & rc)
745 workingDirED->setText(toqstr(external_path(rc.document_path)));
746 templateDirED->setText(toqstr(external_path(rc.template_path)));
747 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
748 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
749 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
750 // FIXME: should be a checkbox only
751 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
755 void PrefPaths::select_templatedir()
757 docstring file(form_->controller().browsedir(
758 from_utf8(internal_path(fromqstr(templateDirED->text()))),
759 _("Select a document templates directory")));
761 templateDirED->setText(toqstr(file));
765 void PrefPaths::select_tempdir()
767 docstring file(form_->controller().browsedir(
768 from_utf8(internal_path(fromqstr(tempDirED->text()))),
769 _("Select a temporary directory")));
771 tempDirED->setText(toqstr(file));
775 void PrefPaths::select_backupdir()
777 docstring file(form_->controller().browsedir(
778 from_utf8(internal_path(fromqstr(backupDirED->text()))),
779 _("Select a backups directory")));
781 backupDirED->setText(toqstr(file));
785 void PrefPaths::select_workingdir()
787 docstring file(form_->controller().browsedir(
788 from_utf8(internal_path(fromqstr(workingDirED->text()))),
789 _("Select a document directory")));
791 workingDirED->setText(toqstr(file));
795 void PrefPaths::select_lyxpipe()
797 docstring file(form_->controller().browse(
798 from_utf8(internal_path(fromqstr(lyxserverDirED->text()))),
799 _("Give a filename for the LyX server pipe")));
801 lyxserverDirED->setText(toqstr(file));
805 /////////////////////////////////////////////////////////////////////
809 /////////////////////////////////////////////////////////////////////
811 PrefSpellchecker::PrefSpellchecker(QPrefs * form, QWidget * parent)
812 : PrefModule(_(LanguageSettings), _("Spellchecker"), form, parent)
816 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
817 #if defined (USE_ISPELL)
818 connect(spellCommandCO, SIGNAL(activated(int)),
819 this, SIGNAL(changed()));
821 spellCommandCO->setEnabled(false);
823 connect(altLanguageED, SIGNAL(textChanged(const QString&)),
824 this, SIGNAL(changed()));
825 connect(escapeCharactersED, SIGNAL(textChanged(const QString&)),
826 this, SIGNAL(changed()));
827 connect(persDictionaryED, SIGNAL(textChanged(const QString&)),
828 this, SIGNAL(changed()));
829 connect(compoundWordCB, SIGNAL(clicked()),
830 this, SIGNAL(changed()));
831 connect(inputEncodingCB, SIGNAL(clicked()),
832 this, SIGNAL(changed()));
834 spellCommandCO->addItem(qt_("ispell"));
835 spellCommandCO->addItem(qt_("aspell"));
836 spellCommandCO->addItem(qt_("hspell"));
838 spellCommandCO->addItem(qt_("pspell (library)"));
841 spellCommandCO->addItem(qt_("aspell (library)"));
847 void PrefSpellchecker::apply(LyXRC & rc) const
849 switch (spellCommandCO->currentIndex()) {
853 rc.use_spell_lib = false;
854 rc.isp_command = fromqstr(spellCommandCO->currentText());
857 rc.use_spell_lib = true;
861 // FIXME: remove isp_use_alt_lang
862 rc.isp_alt_lang = fromqstr(altLanguageED->text());
863 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
864 // FIXME: remove isp_use_esc_chars
865 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
866 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
867 // FIXME: remove isp_use_pers_dict
868 rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
869 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
870 rc.isp_accept_compound = compoundWordCB->isChecked();
871 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
875 void PrefSpellchecker::update(LyXRC const & rc)
877 spellCommandCO->setCurrentIndex(0);
879 if (rc.isp_command == "ispell") {
880 spellCommandCO->setCurrentIndex(0);
881 } else if (rc.isp_command == "aspell") {
882 spellCommandCO->setCurrentIndex(1);
883 } else if (rc.isp_command == "hspell") {
884 spellCommandCO->setCurrentIndex(2);
887 if (rc.use_spell_lib) {
888 #if defined(USE_ASPELL) || defined(USE_PSPELL)
889 spellCommandCO->setCurrentIndex(3);
893 // FIXME: remove isp_use_alt_lang
894 altLanguageED->setText(toqstr(rc.isp_alt_lang));
895 // FIXME: remove isp_use_esc_chars
896 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
897 // FIXME: remove isp_use_pers_dict
898 persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
899 compoundWordCB->setChecked(rc.isp_accept_compound);
900 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
904 void PrefSpellchecker::select_dict()
906 docstring file(form_->controller().browsedict(
907 from_utf8(internal_path(fromqstr(persDictionaryED->text())))));
909 persDictionaryED->setText(toqstr(file));
914 /////////////////////////////////////////////////////////////////////
918 /////////////////////////////////////////////////////////////////////
921 PrefConverters::PrefConverters(QPrefs * form, QWidget * parent)
922 : PrefModule(docstring(), _("Converters"), form, parent)
926 connect(converterNewPB, SIGNAL(clicked()),
927 this, SLOT(update_converter()));
928 connect(converterRemovePB, SIGNAL(clicked()),
929 this, SLOT(remove_converter()));
930 connect(converterModifyPB, SIGNAL(clicked()),
931 this, SLOT(update_converter()));
932 connect(convertersLW, SIGNAL(currentRowChanged(int)),
933 this, SLOT(switch_converter()));
934 connect(converterFromCO, SIGNAL(activated(const QString&)),
935 this, SLOT(converter_changed()));
936 connect(converterToCO, SIGNAL(activated(const QString&)),
937 this, SLOT(converter_changed()));
938 connect(converterED, SIGNAL(textChanged(const QString&)),
939 this, SLOT(converter_changed()));
940 connect(converterFlagED, SIGNAL(textChanged(const QString&)),
941 this, SLOT(converter_changed()));
942 connect(converterNewPB, SIGNAL(clicked()),
943 this, SIGNAL(changed()));
944 connect(converterRemovePB, SIGNAL(clicked()),
945 this, SIGNAL(changed()));
946 connect(converterModifyPB, SIGNAL(clicked()),
947 this, SIGNAL(changed()));
948 connect(maxAgeLE, SIGNAL(textChanged(const QString&)),
949 this, SIGNAL(changed()));
951 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
952 converterDefGB->setFocusProxy(convertersLW);
956 void PrefConverters::apply(LyXRC & rc) const
958 rc.use_converter_cache = cacheCB->isChecked();
959 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
963 void PrefConverters::update(LyXRC const & rc)
965 cacheCB->setChecked(rc.use_converter_cache);
967 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
968 maxAgeLE->setText(max_age);
973 void PrefConverters::updateGui()
975 // save current selection
976 QString current = converterFromCO->currentText()
977 + " -> " + converterToCO->currentText();
979 converterFromCO->clear();
980 converterToCO->clear();
982 Formats::const_iterator cit = form_->formats().begin();
983 Formats::const_iterator end = form_->formats().end();
984 for (; cit != end; ++cit) {
985 converterFromCO->addItem(toqstr(cit->prettyname()));
986 converterToCO->addItem(toqstr(cit->prettyname()));
989 // currentRowChanged(int) is also triggered when updating the listwidget
990 // block signals to avoid unnecessary calls to switch_converter()
991 convertersLW->blockSignals(true);
992 convertersLW->clear();
994 Converters::const_iterator ccit = form_->converters().begin();
995 Converters::const_iterator cend = form_->converters().end();
996 for (; ccit != cend; ++ccit) {
997 std::string const name =
998 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
999 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1000 new QListWidgetItem(toqstr(name), convertersLW, type);
1002 convertersLW->sortItems(Qt::AscendingOrder);
1003 convertersLW->blockSignals(false);
1005 // restore selection
1006 if (!current.isEmpty()) {
1007 QList<QListWidgetItem *> const item =
1008 convertersLW->findItems(current, Qt::MatchExactly);
1010 convertersLW->setCurrentItem(item.at(0));
1013 // select first element if restoring failed
1014 if (convertersLW->currentRow() == -1)
1015 convertersLW->setCurrentRow(0);
1021 void PrefConverters::switch_converter()
1023 int const cnr = convertersLW->currentItem()->type();
1024 Converter const & c(form_->converters().get(cnr));
1025 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1026 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1027 converterED->setText(toqstr(c.command));
1028 converterFlagED->setText(toqstr(c.flags));
1034 void PrefConverters::converter_changed()
1040 void PrefConverters::updateButtons()
1042 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1043 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1044 int const sel = form_->converters().getNumber(from.name(), to.name());
1045 bool const known = !(sel < 0);
1046 bool const valid = !(converterED->text().isEmpty()
1047 || from.name() == to.name());
1049 int const cnr = convertersLW->currentItem()->type();
1050 Converter const & c(form_->converters().get(cnr));
1051 string const old_command = c.command;
1052 string const old_flag = c.flags;
1053 string const new_command(fromqstr(converterED->text()));
1054 string const new_flag(fromqstr(converterFlagED->text()));
1056 bool modified = ((old_command != new_command) || (old_flag != new_flag));
1058 converterModifyPB->setEnabled(valid && known && modified);
1059 converterNewPB->setEnabled(valid && !known);
1060 converterRemovePB->setEnabled(known);
1062 maxAgeLE->setEnabled(cacheCB->isChecked());
1063 maxAgeLA->setEnabled(cacheCB->isChecked());
1068 // specify unique from/to or it doesn't appear. This is really bad UI
1069 // this is why we can use the same function for both new and modify
1070 void PrefConverters::update_converter()
1072 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1073 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1074 string const flags = fromqstr(converterFlagED->text());
1075 string const command = fromqstr(converterED->text());
1077 Converter const * old = form_->converters().getConverter(from.name(), to.name());
1078 form_->converters().add(from.name(), to.name(), command, flags);
1080 form_->converters().updateLast(form_->formats());
1085 // Remove all files created by this converter from the cache, since
1086 // the modified converter might create different files.
1087 ConverterCache::get().remove_all(from.name(), to.name());
1091 void PrefConverters::remove_converter()
1093 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1094 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1095 form_->converters().erase(from.name(), to.name());
1099 // Remove all files created by this converter from the cache, since
1100 // a possible new converter might create different files.
1101 ConverterCache::get().remove_all(from.name(), to.name());
1105 void PrefConverters::on_cacheCB_stateChanged(int state)
1107 maxAgeLE->setEnabled(state == Qt::Checked);
1108 maxAgeLA->setEnabled(state == Qt::Checked);
1113 /////////////////////////////////////////////////////////////////////
1117 /////////////////////////////////////////////////////////////////////
1119 PrefCopiers::PrefCopiers(QPrefs * form, QWidget * parent)
1120 : PrefModule(docstring(), _("Copiers"), form, parent)
1124 connect(copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
1125 connect(copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
1126 connect(copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
1127 connect(AllCopiersLW, SIGNAL(currentRowChanged(int)),
1128 this, SLOT(switch_copierLB(int)));
1129 connect(copierFormatCO, SIGNAL(activated(int)),
1130 this, SLOT(switch_copierCO(int)));
1131 connect(copierNewPB, SIGNAL(clicked()),
1132 this, SIGNAL(changed()));
1133 connect(copierRemovePB, SIGNAL(clicked()),
1134 this, SIGNAL(changed()));
1135 connect(copierModifyPB, SIGNAL(clicked()),
1136 this, SIGNAL(changed()));
1137 connect(copierFormatCO, SIGNAL(activated(const QString &)),
1138 this, SLOT(copiers_changed()));
1139 connect(copierED, SIGNAL(textChanged(const QString &)),
1140 this, SLOT(copiers_changed()));
1144 void PrefCopiers::apply(LyXRC & /*rc*/) const
1149 void PrefCopiers::update(LyXRC const & /*rc*/)
1155 void PrefCopiers::update()
1157 // The choice widget
1158 // save current selection
1159 QString current = copierFormatCO->currentText();
1160 copierFormatCO->clear();
1162 for (Formats::const_iterator it = form_->formats().begin(),
1163 end = form_->formats().end();
1165 copierFormatCO->addItem(toqstr(it->prettyname()));
1168 // The browser widget
1169 AllCopiersLW->clear();
1171 for (Movers::const_iterator it = form_->movers().begin(),
1172 end = form_->movers().end();
1174 std::string const & command = it->second.command();
1175 if (command.empty())
1177 QString const pretty = toqstr(form_->formats().prettyName(it->first));
1178 AllCopiersLW->addItem(pretty);
1180 AllCopiersLW->sortItems(Qt::AscendingOrder);
1182 // restore selection
1183 if (!current.isEmpty()) {
1184 QList<QListWidgetItem *> item =
1185 AllCopiersLW->findItems(current, Qt::MatchExactly);
1187 AllCopiersLW->setCurrentItem(item.at(0));
1189 // select first element if restoring failed
1190 if (AllCopiersLW->currentRow() == -1)
1191 AllCopiersLW->setCurrentRow(0);
1197 class SamePrettyName {
1199 SamePrettyName(string const & n) : pretty_name_(n) {}
1201 bool operator()(Format const & fmt) const {
1202 return fmt.prettyname() == pretty_name_;
1206 string const pretty_name_;
1210 Format const * getFormat(std::string const & prettyname)
1212 Formats::const_iterator it = formats.begin();
1213 Formats::const_iterator const end = formats.end();
1214 it = std::find_if(it, end, SamePrettyName(prettyname));
1215 return it == end ? 0 : &*it;
1221 void PrefCopiers::switch_copierLB(int row)
1227 std::string const browser_text =
1228 fromqstr(AllCopiersLW->currentItem()->text());
1229 Format const * fmt = getFormat(browser_text);
1233 QString const gui_name = toqstr(fmt->prettyname());
1234 QString const command = toqstr(form_->movers().command(fmt->name()));
1237 int const combo_size = copierFormatCO->count();
1238 for (int i = 0; i < combo_size; ++i) {
1239 QString const text = copierFormatCO->itemText(i);
1240 if (text == gui_name) {
1241 copierFormatCO->setCurrentIndex(i);
1242 copierED->setText(command);
1250 void PrefCopiers::switch_copierCO(int row)
1255 std::string const combo_text =
1256 fromqstr(copierFormatCO->currentText());
1257 Format const * fmt = getFormat(combo_text);
1261 QString const command = toqstr(form_->movers().command(fmt->name()));
1262 copierED->setText(command);
1264 QListWidgetItem * const index = AllCopiersLW->currentItem();
1266 AllCopiersLW->setItemSelected(index, false);
1268 QString const gui_name = toqstr(fmt->prettyname());
1269 int const browser_size = AllCopiersLW->count();
1270 for (int i = 0; i < browser_size; ++i) {
1271 QString const text = AllCopiersLW->item(i)->text();
1272 if (text == gui_name) {
1273 QListWidgetItem * item = AllCopiersLW->item(i);
1274 AllCopiersLW->setItemSelected(item, true);
1281 void PrefCopiers::copiers_changed()
1287 void PrefCopiers::updateButtons()
1289 QString selected = copierFormatCO->currentText();
1292 for (int i = 0; i < AllCopiersLW->count(); ++i) {
1293 if (AllCopiersLW->item(i)->text() == selected)
1297 bool const valid = !copierED->text().isEmpty();
1299 Format const * fmt = getFormat(fromqstr(selected));
1300 string const old_command = form_->movers().command(fmt->name());
1301 string const new_command(fromqstr(copierED->text()));
1303 bool modified = (old_command != new_command);
1305 copierModifyPB->setEnabled(valid && known && modified);
1306 copierNewPB->setEnabled(valid && !known);
1307 copierRemovePB->setEnabled(known);
1311 void PrefCopiers::new_copier()
1313 std::string const combo_text =
1314 fromqstr(copierFormatCO->currentText());
1315 Format const * fmt = getFormat(combo_text);
1319 string const command = fromqstr(copierED->text());
1320 if (command.empty())
1323 form_->movers().set(fmt->name(), command);
1326 int const last = AllCopiersLW->count() - 1;
1327 AllCopiersLW->setCurrentRow(last);
1333 void PrefCopiers::modify_copier()
1335 std::string const combo_text =
1336 fromqstr(copierFormatCO->currentText());
1337 Format const * fmt = getFormat(combo_text);
1341 string const command = fromqstr(copierED->text());
1342 form_->movers().set(fmt->name(), command);
1349 void PrefCopiers::remove_copier()
1351 std::string const combo_text =
1352 fromqstr(copierFormatCO->currentText());
1353 Format const * fmt = getFormat(combo_text);
1357 string const & fmt_name = fmt->name();
1358 form_->movers().set(fmt_name, string());
1366 /////////////////////////////////////////////////////////////////////
1370 /////////////////////////////////////////////////////////////////////
1372 PrefFileformats::PrefFileformats(QPrefs * form, QWidget * parent)
1373 : PrefModule(docstring(), _("File formats"), form, parent)
1377 connect(formatNewPB, SIGNAL(clicked()),
1378 this, SLOT(new_format()));
1379 connect(formatRemovePB, SIGNAL(clicked()),
1380 this, SLOT(remove_format()));
1381 connect(formatModifyPB, SIGNAL(clicked()),
1382 this, SLOT(modify_format()));
1383 connect(formatsLW, SIGNAL(currentRowChanged(int)),
1384 this, SLOT(switch_format(int)));
1385 connect(formatED, SIGNAL(textChanged(const QString&)),
1386 this, SLOT(fileformat_changed()));
1387 connect(guiNameED, SIGNAL(textChanged(const QString&)),
1388 this, SLOT(fileformat_changed()));
1389 connect(shortcutED, SIGNAL(textChanged(const QString&)),
1390 this, SLOT(fileformat_changed()));
1391 connect(extensionED, SIGNAL(textChanged(const QString&)),
1392 this, SLOT(fileformat_changed()));
1393 connect(viewerED, SIGNAL(textChanged(const QString&)),
1394 this, SLOT(fileformat_changed()));
1395 connect(editorED, SIGNAL(textChanged(const QString&)),
1396 this, SLOT(fileformat_changed()));
1397 connect(documentCB, SIGNAL(clicked()),
1398 this, SLOT(fileformat_changed()));
1399 connect(vectorCB, SIGNAL(clicked()),
1400 this, SLOT(fileformat_changed()));
1401 connect(formatNewPB, SIGNAL(clicked()),
1402 this, SIGNAL(changed()));
1403 connect(formatRemovePB, SIGNAL(clicked()),
1404 this, SIGNAL(changed()));
1405 connect(formatModifyPB, SIGNAL(clicked()),
1406 this, SIGNAL(changed()));
1410 void PrefFileformats::apply(LyXRC & /*rc*/) const
1415 void PrefFileformats::update(LyXRC const & /*rc*/)
1421 void PrefFileformats::update()
1423 // save current selection
1424 QString current = guiNameED->text();
1426 // update listwidget with formats
1427 formatsLW->blockSignals(true);
1429 Formats::const_iterator cit = form_->formats().begin();
1430 Formats::const_iterator end = form_->formats().end();
1431 for (; cit != end; ++cit) {
1432 new QListWidgetItem(toqstr(cit->prettyname()),
1434 form_->formats().getNumber(cit->name()) );
1436 formatsLW->sortItems(Qt::AscendingOrder);
1437 formatsLW->blockSignals(false);
1439 // restore selection
1440 if (!current.isEmpty()) {
1441 QList<QListWidgetItem *> item = formatsLW->findItems(current, Qt::MatchExactly);
1443 formatsLW->setCurrentItem(item.at(0));
1445 // select first element if restoring failed
1446 if (formatsLW->currentRow() == -1)
1447 formatsLW->setCurrentRow(0);
1451 void PrefFileformats::switch_format(int nr)
1453 int const ftype = formatsLW->item(nr)->type();
1454 Format const f = form_->formats().get(ftype);
1456 formatED->setText(toqstr(f.name()));
1457 guiNameED->setText(toqstr(f.prettyname()));
1458 extensionED->setText(toqstr(f.extension()));
1459 shortcutED->setText(toqstr(f.shortcut()));
1460 viewerED->setText(toqstr(f.viewer()));
1461 editorED->setText(toqstr(f.editor()));
1462 documentCB->setChecked((f.documentFormat()));
1463 vectorCB->setChecked((f.vectorFormat()));
1469 void PrefFileformats::fileformat_changed()
1475 void PrefFileformats::updateButtons()
1477 QString const format = formatED->text();
1478 QString const gui_name = guiNameED->text();
1479 int const sel = form_->formats().getNumber(fromqstr(format));
1480 bool gui_name_known = false;
1482 for (int i = 0; i < formatsLW->count(); ++i) {
1483 if (formatsLW->item(i)->text() == gui_name) {
1484 gui_name_known = true;
1485 where = formatsLW->item(i)->type();
1489 // assure that a gui name cannot be chosen twice
1490 bool const known_otherwise = gui_name_known && (where != sel);
1492 bool const known = !(sel < 0);
1493 bool const valid = (!formatED->text().isEmpty()
1494 && !guiNameED->text().isEmpty());
1496 int const ftype = formatsLW->currentItem()->type();
1497 Format const & f(form_->formats().get(ftype));
1498 string const old_pretty(f.prettyname());
1499 string const old_shortcut(f.shortcut());
1500 string const old_extension(f.extension());
1501 string const old_viewer(f.viewer());
1502 string const old_editor(f.editor());
1503 bool const old_document(f.documentFormat());
1504 bool const old_vector(f.vectorFormat());
1506 string const new_pretty(fromqstr(gui_name));
1507 string const new_shortcut(fromqstr(shortcutED->text()));
1508 string const new_extension(fromqstr(extensionED->text()));
1509 string const new_viewer(fromqstr(viewerED->text()));
1510 string const new_editor(fromqstr(editorED->text()));
1511 bool const new_document(documentCB->isChecked());
1512 bool const new_vector(vectorCB->isChecked());
1514 bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
1515 || (old_extension != new_extension) || (old_viewer != new_viewer)
1516 || old_editor != new_editor || old_document != new_document
1517 || old_vector != new_vector);
1519 formatModifyPB->setEnabled(valid && known && modified && !known_otherwise);
1520 formatNewPB->setEnabled(valid && !known && !gui_name_known);
1521 formatRemovePB->setEnabled(known);
1525 void PrefFileformats::new_format()
1527 string const name = fromqstr(formatED->text());
1528 string const prettyname = fromqstr(guiNameED->text());
1529 string const extension = fromqstr(extensionED->text());
1530 string const shortcut = fromqstr(shortcutED->text());
1531 string const viewer = fromqstr(viewerED->text());
1532 string const editor = fromqstr(editorED->text());
1533 int flags = Format::none;
1534 if (documentCB->isChecked())
1535 flags |= Format::document;
1536 if (vectorCB->isChecked())
1537 flags |= Format::vector;
1539 form_->formats().add(name, extension, prettyname, shortcut, viewer,
1541 form_->formats().sort();
1542 form_->converters().update(form_->formats());
1550 void PrefFileformats::modify_format()
1552 int const current_item = formatsLW->currentItem()->type();
1553 Format const & oldformat = form_->formats().get(current_item);
1554 form_->formats().erase(oldformat.name());
1560 void PrefFileformats::remove_format()
1562 int const nr = formatsLW->currentItem()->type();
1563 string const current_text = form_->formats().get(nr).name();
1564 if (form_->converters().formatIsUsed(current_text)) {
1565 Alert::error(_("Format in use"),
1566 _("Cannot remove a Format used by a Converter. "
1567 "Remove the converter first."));
1571 form_->formats().erase(current_text);
1572 form_->converters().update(form_->formats());
1580 /////////////////////////////////////////////////////////////////////
1584 /////////////////////////////////////////////////////////////////////
1586 PrefLanguage::PrefLanguage(QWidget * parent)
1587 : PrefModule(_(LanguageSettings), _("Language"), 0, parent)
1591 connect(rtlCB, SIGNAL(clicked()),
1592 this, SIGNAL(changed()));
1593 connect(markForeignCB, SIGNAL(clicked()),
1594 this, SIGNAL(changed()));
1595 connect(autoBeginCB, SIGNAL(clicked()),
1596 this, SIGNAL(changed()));
1597 connect(autoEndCB, SIGNAL(clicked()),
1598 this, SIGNAL(changed()));
1599 connect(useBabelCB, SIGNAL(clicked()),
1600 this, SIGNAL(changed()));
1601 connect(globalCB, SIGNAL(clicked()),
1602 this, SIGNAL(changed()));
1603 connect(languagePackageED, SIGNAL(textChanged(const QString&)),
1604 this, SIGNAL(changed()));
1605 connect(startCommandED, SIGNAL(textChanged(const QString&)),
1606 this, SIGNAL(changed()));
1607 connect(endCommandED, SIGNAL(textChanged(const QString&)),
1608 this, SIGNAL(changed()));
1609 connect(defaultLanguageCO, SIGNAL(activated(int)),
1610 this, SIGNAL(changed()));
1612 defaultLanguageCO->clear();
1614 // store the lang identifiers for later
1615 std::vector<LanguagePair> const langs = frontend::getLanguageData(false);
1616 lang_ = getSecond(langs);
1618 std::vector<LanguagePair>::const_iterator lit = langs.begin();
1619 std::vector<LanguagePair>::const_iterator lend = langs.end();
1620 for (; lit != lend; ++lit) {
1621 defaultLanguageCO->addItem(toqstr(lit->first));
1626 void PrefLanguage::apply(LyXRC & rc) const
1628 // FIXME: remove rtl_support bool
1629 rc.rtl_support = rtlCB->isChecked();
1630 rc.mark_foreign_language = markForeignCB->isChecked();
1631 rc.language_auto_begin = autoBeginCB->isChecked();
1632 rc.language_auto_end = autoEndCB->isChecked();
1633 rc.language_use_babel = useBabelCB->isChecked();
1634 rc.language_global_options = globalCB->isChecked();
1635 rc.language_package = fromqstr(languagePackageED->text());
1636 rc.language_command_begin = fromqstr(startCommandED->text());
1637 rc.language_command_end = fromqstr(endCommandED->text());
1638 rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1642 void PrefLanguage::update(LyXRC const & rc)
1644 // FIXME: remove rtl_support bool
1645 rtlCB->setChecked(rc.rtl_support);
1646 markForeignCB->setChecked(rc.mark_foreign_language);
1647 autoBeginCB->setChecked(rc.language_auto_begin);
1648 autoEndCB->setChecked(rc.language_auto_end);
1649 useBabelCB->setChecked(rc.language_use_babel);
1650 globalCB->setChecked(rc.language_global_options);
1651 languagePackageED->setText(toqstr(rc.language_package));
1652 startCommandED->setText(toqstr(rc.language_command_begin));
1653 endCommandED->setText(toqstr(rc.language_command_end));
1655 int const pos = int(findPos_helper(lang_, rc.default_language));
1656 defaultLanguageCO->setCurrentIndex(pos);
1660 /////////////////////////////////////////////////////////////////////
1664 /////////////////////////////////////////////////////////////////////
1666 PrefPrinter::PrefPrinter(QWidget * parent)
1667 : PrefModule(_(Outputs), _("Printer"), 0, parent)
1671 connect(printerAdaptCB, SIGNAL(clicked()),
1672 this, SIGNAL(changed()));
1673 connect(printerCommandED, SIGNAL(textChanged(const QString&)),
1674 this, SIGNAL(changed()));
1675 connect(printerNameED, SIGNAL(textChanged(const QString&)),
1676 this, SIGNAL(changed()));
1677 connect(printerPageRangeED, SIGNAL(textChanged(const QString&)),
1678 this, SIGNAL(changed()));
1679 connect(printerCopiesED, SIGNAL(textChanged(const QString&)),
1680 this, SIGNAL(changed()));
1681 connect(printerReverseED, SIGNAL(textChanged(const QString&)),
1682 this, SIGNAL(changed()));
1683 connect(printerToPrinterED, SIGNAL(textChanged(const QString&)),
1684 this, SIGNAL(changed()));
1685 connect(printerExtensionED, SIGNAL(textChanged(const QString&)),
1686 this, SIGNAL(changed()));
1687 connect(printerSpoolCommandED, SIGNAL(textChanged(const QString&)),
1688 this, SIGNAL(changed()));
1689 connect(printerPaperTypeED, SIGNAL(textChanged(const QString&)),
1690 this, SIGNAL(changed()));
1691 connect(printerEvenED, SIGNAL(textChanged(const QString&)),
1692 this, SIGNAL(changed()));
1693 connect(printerOddED, SIGNAL(textChanged(const QString&)),
1694 this, SIGNAL(changed()));
1695 connect(printerCollatedED, SIGNAL(textChanged(const QString&)),
1696 this, SIGNAL(changed()));
1697 connect(printerLandscapeED, SIGNAL(textChanged(const QString&)),
1698 this, SIGNAL(changed()));
1699 connect(printerToFileED, SIGNAL(textChanged(const QString&)),
1700 this, SIGNAL(changed()));
1701 connect(printerExtraED, SIGNAL(textChanged(const QString&)),
1702 this, SIGNAL(changed()));
1703 connect(printerSpoolPrefixED, SIGNAL(textChanged(const QString&)),
1704 this, SIGNAL(changed()));
1705 connect(printerPaperSizeED, SIGNAL(textChanged(const QString&)),
1706 this, SIGNAL(changed()));
1710 void PrefPrinter::apply(LyXRC & rc) const
1712 rc.print_adapt_output = printerAdaptCB->isChecked();
1713 rc.print_command = fromqstr(printerCommandED->text());
1714 rc.printer = fromqstr(printerNameED->text());
1716 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1717 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1718 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1719 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1720 rc.print_file_extension = fromqstr(printerExtensionED->text());
1721 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1722 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1723 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1724 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1725 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1726 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1727 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1728 rc.print_extra_options = fromqstr(printerExtraED->text());
1729 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1730 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1734 void PrefPrinter::update(LyXRC const & rc)
1736 printerAdaptCB->setChecked(rc.print_adapt_output);
1737 printerCommandED->setText(toqstr(rc.print_command));
1738 printerNameED->setText(toqstr(rc.printer));
1740 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1741 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1742 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1743 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1744 printerExtensionED->setText(toqstr(rc.print_file_extension));
1745 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1746 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1747 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1748 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1749 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1750 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1751 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1752 printerExtraED->setText(toqstr(rc.print_extra_options));
1753 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1754 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1758 /////////////////////////////////////////////////////////////////////
1760 // PrefUserInterface
1762 /////////////////////////////////////////////////////////////////////
1764 PrefUserInterface::PrefUserInterface(QPrefs * form, QWidget * parent)
1765 : PrefModule(_(LookAndFeel), _("User interface"), form, parent)
1769 connect(autoSaveCB, SIGNAL(toggled(bool)),
1770 autoSaveLA, SLOT(setEnabled(bool)));
1771 connect(autoSaveCB, SIGNAL(toggled(bool)),
1772 autoSaveSB, SLOT(setEnabled(bool)));
1773 connect(autoSaveCB, SIGNAL(toggled(bool)),
1774 TextLabel1, SLOT(setEnabled(bool)));
1775 connect(uiFilePB, SIGNAL(clicked()),
1776 this, SLOT(select_ui()));
1777 connect(bindFilePB, SIGNAL(clicked()),
1778 this, SLOT(select_bind()));
1779 connect(uiFileED, SIGNAL(textChanged(const QString &)),
1780 this, SIGNAL(changed()));
1781 connect(bindFileED, SIGNAL(textChanged(const QString &)),
1782 this, SIGNAL(changed()));
1783 connect(restoreCursorCB, SIGNAL(clicked()),
1784 this, SIGNAL(changed()));
1785 connect(loadSessionCB, SIGNAL(clicked()),
1786 this, SIGNAL(changed()));
1787 connect(loadWindowSizeCB, SIGNAL(clicked()),
1788 this, SIGNAL(changed()));
1789 connect(loadWindowLocationCB, SIGNAL(clicked()),
1790 this, SIGNAL(changed()));
1791 connect(windowWidthSB, SIGNAL(valueChanged(int)),
1792 this, SIGNAL(changed()));
1793 connect(windowHeightSB, SIGNAL(valueChanged(int)),
1794 this, SIGNAL(changed()));
1795 connect(cursorFollowsCB, SIGNAL(clicked()),
1796 this, SIGNAL(changed()));
1797 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1798 this, SIGNAL(changed()));
1799 connect(autoSaveCB, SIGNAL(clicked()),
1800 this, SIGNAL(changed()));
1801 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1802 this, SIGNAL(changed()));
1803 lastfilesSB->setMaximum(maxlastfiles);
1807 void PrefUserInterface::apply(LyXRC & rc) const
1809 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1810 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1811 rc.use_lastfilepos = restoreCursorCB->isChecked();
1812 rc.load_session = loadSessionCB->isChecked();
1813 if (loadWindowSizeCB->isChecked()) {
1814 rc.geometry_width = 0;
1815 rc.geometry_height = 0;
1817 rc.geometry_width = windowWidthSB->value();
1818 rc.geometry_height = windowHeightSB->value();
1820 rc.geometry_xysaved = loadWindowLocationCB->isChecked();
1821 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1822 rc.autosave = autoSaveSB->value() * 60;
1823 rc.make_backup = autoSaveCB->isChecked();
1824 rc.num_lastfiles = lastfilesSB->value();
1828 void PrefUserInterface::update(LyXRC const & rc)
1830 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1831 bindFileED->setText(toqstr(external_path(rc.bind_file)));
1832 restoreCursorCB->setChecked(rc.use_lastfilepos);
1833 loadSessionCB->setChecked(rc.load_session);
1834 bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
1835 loadWindowSizeCB->setChecked(loadWindowSize);
1836 if (!loadWindowSize) {
1837 windowWidthSB->setValue(rc.geometry_width);
1838 windowHeightSB->setValue(rc.geometry_height);
1840 loadWindowLocationCB->setChecked(rc.geometry_xysaved);
1841 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1842 // convert to minutes
1843 int mins(rc.autosave / 60);
1844 if (rc.autosave && !mins)
1846 autoSaveSB->setValue(mins);
1847 autoSaveCB->setChecked(rc.make_backup);
1848 lastfilesSB->setValue(rc.num_lastfiles);
1853 void PrefUserInterface::select_ui()
1855 docstring const name =
1856 from_utf8(internal_path(fromqstr(uiFileED->text())));
1857 docstring file(form_->controller().browseUI(name));
1859 uiFileED->setText(toqstr(file));
1863 void PrefUserInterface::select_bind()
1865 docstring const name =
1866 from_utf8(internal_path(fromqstr(bindFileED->text())));
1867 docstring file(form_->controller().browsebind(name));
1869 bindFileED->setText(toqstr(file));
1873 void PrefUserInterface::on_loadWindowSizeCB_toggled(bool loadwindowsize)
1875 windowWidthLA->setDisabled(loadwindowsize);
1876 windowHeightLA->setDisabled(loadwindowsize);
1877 windowWidthSB->setDisabled(loadwindowsize);
1878 windowHeightSB->setDisabled(loadwindowsize);
1882 PrefIdentity::PrefIdentity(QWidget * parent)
1883 : PrefModule(docstring(), _("Identity"), 0, parent)
1887 connect(nameED, SIGNAL(textChanged(const QString&)),
1888 this, SIGNAL(changed()));
1889 connect(emailED, SIGNAL(textChanged(const QString&)),
1890 this, SIGNAL(changed()));
1894 void PrefIdentity::apply(LyXRC & rc) const
1896 rc.user_name = fromqstr(nameED->text());
1897 rc.user_email = fromqstr(emailED->text());
1901 void PrefIdentity::update(LyXRC const & rc)
1903 nameED->setText(toqstr(rc.user_name));
1904 emailED->setText(toqstr(rc.user_email));
1909 /////////////////////////////////////////////////////////////////////
1913 /////////////////////////////////////////////////////////////////////
1915 QPrefsDialog::QPrefsDialog(QPrefs * form)
1919 QDialog::setModal(false);
1921 connect(savePB, SIGNAL(clicked()), form, SLOT(slotOK()));
1922 connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
1923 connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
1924 connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore()));
1926 add(new PrefUserInterface(form_));
1927 add(new PrefScreenFonts(form_));
1928 add(new PrefColors(form_));
1929 add(new PrefDisplay);
1930 add(new PrefKeyboard(form_));
1932 add(new PrefPaths(form_));
1934 add(new PrefIdentity);
1936 add(new PrefLanguage);
1937 add(new PrefSpellchecker(form_));
1939 add(new PrefPrinter);
1941 add(new PrefPlaintext);
1942 add(new PrefLatex(form_));
1944 #if defined(__CYGWIN__) || defined(_WIN32)
1945 add(new PrefCygwinPath);
1949 PrefConverters * converters = new PrefConverters(form_);
1950 PrefFileformats * formats = new PrefFileformats(form_);
1951 connect(formats, SIGNAL(formatsChanged()),
1952 converters, SLOT(updateGui()));
1956 add(new PrefCopiers(form_));
1959 prefsPS->setCurrentPanel(_("User interface"));
1960 // FIXME: hack to work around resizing bug in Qt >= 4.2
1961 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1962 #if QT_VERSION >= 0x040200
1963 prefsPS->updateGeometry();
1966 form_->bcview().setOK(savePB);
1967 form_->bcview().setApply(applyPB);
1968 form_->bcview().setCancel(closePB);
1969 form_->bcview().setRestore(restorePB);
1973 void QPrefsDialog::add(PrefModule * module)
1975 BOOST_ASSERT(module);
1977 // if (module->category().empty())
1978 // prefsPS->addPanel(module, module->title());
1980 prefsPS->addPanel(module, module->title(), module->category());
1982 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
1984 modules_.push_back(module);
1987 void QPrefsDialog::closeEvent(QCloseEvent * e)
1989 form_->slotWMHide();
1994 void QPrefsDialog::change_adaptor()
2000 void QPrefsDialog::apply(LyXRC & rc) const
2002 size_t end = modules_.size();
2003 for (size_t i = 0; i != end; ++i)
2004 modules_[i]->apply(rc);
2008 void QPrefsDialog::updateRc(LyXRC const & rc)
2010 size_t const end = modules_.size();
2011 for (size_t i = 0; i != end; ++i)
2012 modules_[i]->update(rc);
2016 /////////////////////////////////////////////////////////////////////
2020 /////////////////////////////////////////////////////////////////////
2022 typedef QController<ControlPrefs, QView<QPrefsDialog> > PrefsBase;
2024 QPrefs::QPrefs(Dialog & parent)
2025 : PrefsBase(parent, _("Preferences"))
2029 Converters & QPrefs::converters()
2031 return controller().converters();
2034 Formats & QPrefs::formats()
2036 return controller().formats();
2039 Movers & QPrefs::movers()
2041 return controller().movers();
2044 void QPrefs::build_dialog()
2046 dialog_.reset(new QPrefsDialog(this));
2049 void QPrefs::apply()
2051 dialog_->apply(controller().rc());
2054 void QPrefs::update_contents()
2056 dialog_->updateRc(controller().rc());
2059 } // namespace frontend
2062 #include "QPrefs_moc.cpp"