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 // FIXME: move to frontend_helpers.h
77 static size_t findPos_helper(std::vector<A> const & vec, A const & val)
79 typedef typename std::vector<A>::const_iterator Cit;
81 Cit it = std::find(vec.begin(), vec.end(), val);
84 return std::distance(vec.begin(), it);
88 static void setComboxFont(QComboBox * cb, string const & family,
89 string const & foundry)
91 string const name = makeFontName(family, foundry);
92 for (int i = 0; i < cb->count(); ++i) {
93 if (fromqstr(cb->itemText(i)) == name) {
94 cb->setCurrentIndex(i);
99 // Try matching without foundry name
101 // We count in reverse in order to prefer the Xft foundry
102 for (int i = cb->count() - 1; i >= 0; --i) {
103 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
104 if (compare_ascii_no_case(tmp.first, family) == 0) {
105 cb->setCurrentIndex(i);
110 // family alone can contain e.g. "Helvetica [Adobe]"
111 pair<string, string> tmpfam = parseFontName(family);
113 // We count in reverse in order to prefer the Xft foundry
114 for (int i = cb->count() - 1; i >= 0; --i) {
115 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
116 if (compare_ascii_no_case(tmp.first, tmpfam.first) == 0) {
117 cb->setCurrentIndex(i);
122 // Bleh, default fonts, and the names couldn't be found. Hack
126 font.setKerning(false);
128 if (family == theApp()->romanFontName()) {
129 font.setStyleHint(QFont::Serif);
130 font.setFamily(family.c_str());
131 } else if (family == theApp()->sansFontName()) {
132 font.setStyleHint(QFont::SansSerif);
133 font.setFamily(family.c_str());
134 } else if (family == theApp()->typewriterFontName()) {
135 font.setStyleHint(QFont::TypeWriter);
136 font.setFamily(family.c_str());
138 lyxerr << "FAILED to find the default font: '"
139 << foundry << "', '" << family << '\''<< endl;
143 QFontInfo info(font);
144 pair<string, string> tmp = parseFontName(fromqstr(info.family()));
145 string const & default_font_name = tmp.first;
146 lyxerr << "Apparent font is " << default_font_name << endl;
148 for (int i = 0; i < cb->count(); ++i) {
149 lyxerr << "Looking at " << fromqstr(cb->itemText(i)) << endl;
150 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
151 default_font_name) == 0) {
152 cb->setCurrentIndex(i);
157 lyxerr << "FAILED to find the font: '"
158 << foundry << "', '" << family << '\'' <<endl;
162 /////////////////////////////////////////////////////////////////////
166 /////////////////////////////////////////////////////////////////////
168 PrefPlaintext::PrefPlaintext(QWidget * parent)
169 : PrefModule(_("Plain text"), 0, parent)
172 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
173 this, SIGNAL(changed()));
174 connect(plaintextRoffED, SIGNAL(textChanged(const QString&)),
175 this, SIGNAL(changed()));
179 void PrefPlaintext::apply(LyXRC & rc) const
181 rc.plaintext_linelen = plaintextLinelengthSB->value();
182 rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
186 void PrefPlaintext::update(LyXRC const & rc)
188 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
189 plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
193 /////////////////////////////////////////////////////////////////////
197 /////////////////////////////////////////////////////////////////////
199 PrefDate::PrefDate(QWidget * parent)
200 : PrefModule(_("Date format"), 0, parent)
203 connect(DateED, SIGNAL(textChanged(const QString &)),
204 this, SIGNAL(changed()));
208 void PrefDate::apply(LyXRC & rc) const
210 rc.date_insert_format = fromqstr(DateED->text());
214 void PrefDate::update(LyXRC const & rc)
216 DateED->setText(toqstr(rc.date_insert_format));
220 /////////////////////////////////////////////////////////////////////
224 /////////////////////////////////////////////////////////////////////
226 PrefKeyboard::PrefKeyboard(QPrefs * form, QWidget * parent)
227 : PrefModule(_("Keyboard"), form, parent)
231 connect(keymapCB, SIGNAL(clicked()),
232 this, SIGNAL(changed()));
233 connect(firstKeymapED, SIGNAL(textChanged(const QString&)),
234 this, SIGNAL(changed()));
235 connect(secondKeymapED, SIGNAL(textChanged(const QString&)),
236 this, SIGNAL(changed()));
240 void PrefKeyboard::apply(LyXRC & rc) const
242 // FIXME: can derive CB from the two EDs
243 rc.use_kbmap = keymapCB->isChecked();
244 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
245 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
249 void PrefKeyboard::update(LyXRC const & rc)
251 // FIXME: can derive CB from the two EDs
252 keymapCB->setChecked(rc.use_kbmap);
253 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
254 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
258 QString PrefKeyboard::testKeymap(QString keymap)
260 return toqstr(form_->controller().browsekbmap(from_utf8(internal_path(fromqstr(keymap)))));
264 void PrefKeyboard::on_firstKeymapPB_clicked(bool)
266 QString const file = testKeymap(firstKeymapED->text());
268 firstKeymapED->setText(file);
272 void PrefKeyboard::on_secondKeymapPB_clicked(bool)
274 QString const file = testKeymap(secondKeymapED->text());
276 secondKeymapED->setText(file);
280 void PrefKeyboard::on_keymapCB_toggled(bool keymap)
282 firstKeymapLA->setEnabled(keymap);
283 secondKeymapLA->setEnabled(keymap);
284 firstKeymapED->setEnabled(keymap);
285 secondKeymapED->setEnabled(keymap);
286 firstKeymapPB->setEnabled(keymap);
287 secondKeymapPB->setEnabled(keymap);
291 /////////////////////////////////////////////////////////////////////
295 /////////////////////////////////////////////////////////////////////
297 PrefLatex::PrefLatex(QPrefs * form, QWidget * parent)
298 : PrefModule(_("LaTeX"), form, parent)
301 connect(latexEncodingED, SIGNAL(textChanged(const QString&)),
302 this, SIGNAL(changed()));
303 connect(latexChecktexED, SIGNAL(textChanged(const QString&)),
304 this, SIGNAL(changed()));
305 connect(latexBibtexED, SIGNAL(textChanged(const QString&)),
306 this, SIGNAL(changed()));
307 connect(latexIndexED, SIGNAL(textChanged(const QString&)),
308 this, SIGNAL(changed()));
309 connect(latexAutoresetCB, SIGNAL(clicked()),
310 this, SIGNAL(changed()));
311 connect(latexDviPaperED, SIGNAL(textChanged(const QString&)),
312 this, SIGNAL(changed()));
313 connect(latexPaperSizeCO, SIGNAL(activated(int)),
314 this, SIGNAL(changed()));
318 void PrefLatex::apply(LyXRC & rc) const
320 rc.fontenc = fromqstr(latexEncodingED->text());
321 rc.chktex_command = fromqstr(latexChecktexED->text());
322 rc.bibtex_command = fromqstr(latexBibtexED->text());
323 rc.index_command = fromqstr(latexIndexED->text());
324 rc.auto_reset_options = latexAutoresetCB->isChecked();
325 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
326 rc.default_papersize =
327 form_->controller().toPaperSize(latexPaperSizeCO->currentIndex());
331 void PrefLatex::update(LyXRC const & rc)
333 latexEncodingED->setText(toqstr(rc.fontenc));
334 latexChecktexED->setText(toqstr(rc.chktex_command));
335 latexBibtexED->setText(toqstr(rc.bibtex_command));
336 latexIndexED->setText(toqstr(rc.index_command));
337 latexAutoresetCB->setChecked(rc.auto_reset_options);
338 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
339 latexPaperSizeCO->setCurrentIndex(
340 form_->controller().fromPaperSize(rc.default_papersize));
344 /////////////////////////////////////////////////////////////////////
348 /////////////////////////////////////////////////////////////////////
350 PrefScreenFonts::PrefScreenFonts(QPrefs * form, QWidget * parent)
351 : PrefModule(_("Screen fonts"), form, parent)
355 connect(screenRomanCO, SIGNAL(activated(const QString&)),
356 this, SLOT(select_roman(const QString&)));
357 connect(screenSansCO, SIGNAL(activated(const QString&)),
358 this, SLOT(select_sans(const QString&)));
359 connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
360 this, SLOT(select_typewriter(const QString&)));
362 QFontDatabase fontdb;
363 QStringList families(fontdb.families());
364 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
365 screenRomanCO->addItem(*it);
366 screenSansCO->addItem(*it);
367 screenTypewriterCO->addItem(*it);
369 connect(screenRomanCO, SIGNAL(activated(const QString&)),
370 this, SIGNAL(changed()));
371 connect(screenSansCO, SIGNAL(activated(const QString&)),
372 this, SIGNAL(changed()));
373 connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
374 this, SIGNAL(changed()));
375 connect(screenZoomSB, SIGNAL(valueChanged(int)),
376 this, SIGNAL(changed()));
377 connect(screenDpiSB, SIGNAL(valueChanged(int)),
378 this, SIGNAL(changed()));
379 connect(screenTinyED, SIGNAL(textChanged(const QString&)),
380 this, SIGNAL(changed()));
381 connect(screenSmallestED, SIGNAL(textChanged(const QString&)),
382 this, SIGNAL(changed()));
383 connect(screenSmallerED, SIGNAL(textChanged(const QString&)),
384 this, SIGNAL(changed()));
385 connect(screenSmallED, SIGNAL(textChanged(const QString&)),
386 this, SIGNAL(changed()));
387 connect(screenNormalED, SIGNAL(textChanged(const QString&)),
388 this, SIGNAL(changed()));
389 connect(screenLargeED, SIGNAL(textChanged(const QString&)),
390 this, SIGNAL(changed()));
391 connect(screenLargerED, SIGNAL(textChanged(const QString&)),
392 this, SIGNAL(changed()));
393 connect(screenLargestED, SIGNAL(textChanged(const QString&)),
394 this, SIGNAL(changed()));
395 connect(screenHugeED, SIGNAL(textChanged(const QString&)),
396 this, SIGNAL(changed()));
397 connect(screenHugerED, SIGNAL(textChanged(const QString&)),
398 this, SIGNAL(changed()));
400 screenTinyED->setValidator(new QDoubleValidator(
402 screenSmallestED->setValidator(new QDoubleValidator(
404 screenSmallerED->setValidator(new QDoubleValidator(
406 screenSmallED->setValidator(new QDoubleValidator(
408 screenNormalED->setValidator(new QDoubleValidator(
410 screenLargeED->setValidator(new QDoubleValidator(
412 screenLargerED->setValidator(new QDoubleValidator(
414 screenLargestED->setValidator(new QDoubleValidator(
416 screenHugeED->setValidator(new QDoubleValidator(
418 screenHugerED->setValidator(new QDoubleValidator(
423 void PrefScreenFonts::apply(LyXRC & rc) const
425 LyXRC const oldrc(rc);
427 boost::tie(rc.roman_font_name, rc.roman_font_foundry)
428 = parseFontName(fromqstr(screenRomanCO->currentText()));
429 boost::tie(rc.sans_font_name, rc.sans_font_foundry) =
430 parseFontName(fromqstr(screenSansCO->currentText()));
431 boost::tie(rc.typewriter_font_name, rc.typewriter_font_foundry) =
432 parseFontName(fromqstr(screenTypewriterCO->currentText()));
434 rc.zoom = screenZoomSB->value();
435 rc.dpi = screenDpiSB->value();
436 rc.font_sizes[Font::SIZE_TINY] = fromqstr(screenTinyED->text());
437 rc.font_sizes[Font::SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
438 rc.font_sizes[Font::SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
439 rc.font_sizes[Font::SIZE_SMALL] = fromqstr(screenSmallED->text());
440 rc.font_sizes[Font::SIZE_NORMAL] = fromqstr(screenNormalED->text());
441 rc.font_sizes[Font::SIZE_LARGE] = fromqstr(screenLargeED->text());
442 rc.font_sizes[Font::SIZE_LARGER] = fromqstr(screenLargerED->text());
443 rc.font_sizes[Font::SIZE_LARGEST] = fromqstr(screenLargestED->text());
444 rc.font_sizes[Font::SIZE_HUGE] = fromqstr(screenHugeED->text());
445 rc.font_sizes[Font::SIZE_HUGER] = fromqstr(screenHugerED->text());
447 if (rc.font_sizes != oldrc.font_sizes
448 || rc.roman_font_name != oldrc.roman_font_name
449 || rc.sans_font_name != oldrc.sans_font_name
450 || rc.typewriter_font_name != oldrc.typewriter_font_name
451 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
452 form_->controller().updateScreenFonts();
457 void PrefScreenFonts::update(LyXRC const & rc)
459 setComboxFont(screenRomanCO, rc.roman_font_name,
460 rc.roman_font_foundry);
461 setComboxFont(screenSansCO, rc.sans_font_name,
462 rc.sans_font_foundry);
463 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
464 rc.typewriter_font_foundry);
466 select_roman(screenRomanCO->currentText());
467 select_sans(screenSansCO->currentText());
468 select_typewriter(screenTypewriterCO->currentText());
470 screenZoomSB->setValue(rc.zoom);
471 screenDpiSB->setValue(rc.dpi);
472 screenTinyED->setText(toqstr(rc.font_sizes[Font::SIZE_TINY]));
473 screenSmallestED->setText(toqstr(rc.font_sizes[Font::SIZE_SCRIPT]));
474 screenSmallerED->setText(toqstr(rc.font_sizes[Font::SIZE_FOOTNOTE]));
475 screenSmallED->setText(toqstr(rc.font_sizes[Font::SIZE_SMALL]));
476 screenNormalED->setText(toqstr(rc.font_sizes[Font::SIZE_NORMAL]));
477 screenLargeED->setText(toqstr(rc.font_sizes[Font::SIZE_LARGE]));
478 screenLargerED->setText(toqstr(rc.font_sizes[Font::SIZE_LARGER]));
479 screenLargestED->setText(toqstr(rc.font_sizes[Font::SIZE_LARGEST]));
480 screenHugeED->setText(toqstr(rc.font_sizes[Font::SIZE_HUGE]));
481 screenHugerED->setText(toqstr(rc.font_sizes[Font::SIZE_HUGER]));
484 void PrefScreenFonts::select_roman(const QString& name)
486 screenRomanFE->set(QFont(name), name);
490 void PrefScreenFonts::select_sans(const QString& name)
492 screenSansFE->set(QFont(name), name);
496 void PrefScreenFonts::select_typewriter(const QString& name)
498 screenTypewriterFE->set(QFont(name), name);
502 /////////////////////////////////////////////////////////////////////
506 /////////////////////////////////////////////////////////////////////
508 PrefColors::PrefColors(QPrefs * form, QWidget * parent)
509 : PrefModule( _("Colors"), form, parent)
513 // FIXME: all of this initialization should be put into the controller.
514 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
515 // for some discussion of why that is not trivial.
516 QPixmap icon(32, 32);
517 for (int i = 0; i < Color::ignore; ++i) {
518 Color::color lc = static_cast<Color::color>(i);
519 if (lc == Color::none
520 || lc == Color::black
521 || lc == Color::white
523 || lc == Color::green
526 || lc == Color::magenta
527 || lc == Color::yellow
528 || lc == Color::inherit
529 || lc == Color::ignore) continue;
531 lcolors_.push_back(lc);
533 lcolors_ = frontend::getSortedColors(lcolors_);
534 vector<Color_color>::const_iterator cit = lcolors_.begin();
535 vector<Color_color>::const_iterator const end = lcolors_.end();
536 for (; cit != end; ++cit)
538 // This is not a memory leak:
539 /*QListWidgetItem * newItem =*/ new QListWidgetItem(QIcon(icon),
540 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
542 curcolors_.resize(lcolors_.size());
543 newcolors_.resize(lcolors_.size());
544 // End initialization
546 connect(colorChangePB, SIGNAL(clicked()),
547 this, SLOT(change_color()));
548 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
549 this, SLOT(change_lyxObjects_selection()));
550 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
551 this, SLOT(change_color()));
555 void PrefColors::apply(LyXRC & /*rc*/) const
557 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
558 if (curcolors_[i] != newcolors_[i]) {
559 form_->controller().setColor(lcolors_[i], fromqstr(newcolors_[i]));
565 void PrefColors::update(LyXRC const & /*rc*/)
567 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
568 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
569 QPixmap coloritem(32, 32);
570 coloritem.fill(color);
571 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
572 newcolors_[i] = curcolors_[i] = color.name();
574 change_lyxObjects_selection();
577 void PrefColors::change_color()
579 int const row = lyxObjectsLW->currentRow();
584 QString const color = newcolors_[row];
585 QColor c(QColorDialog::getColor(QColor(color), qApp->focusWidget()));
587 if (c.isValid() && c.name() != color) {
588 newcolors_[row] = c.name();
589 QPixmap coloritem(32, 32);
591 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
597 void PrefColors::change_lyxObjects_selection()
599 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
603 /////////////////////////////////////////////////////////////////////
607 /////////////////////////////////////////////////////////////////////
609 PrefCygwinPath::PrefCygwinPath(QWidget * parent)
610 : PrefModule(_("Paths"), 0, parent)
613 connect(pathCB, SIGNAL(clicked()), this, SIGNAL(changed()));
617 void PrefCygwinPath::apply(LyXRC & rc) const
619 rc.windows_style_tex_paths = pathCB->isChecked();
623 void PrefCygwinPath::update(LyXRC const & rc)
625 pathCB->setChecked(rc.windows_style_tex_paths);
629 /////////////////////////////////////////////////////////////////////
633 /////////////////////////////////////////////////////////////////////
635 PrefDisplay::PrefDisplay(QWidget * parent)
636 : PrefModule(_("Graphics"), 0, parent)
639 connect(instantPreviewCO, SIGNAL(activated(int)),
640 this, SIGNAL(changed()));
641 connect(displayGraphicsCO, SIGNAL(activated(int)),
642 this, SIGNAL(changed()));
646 void PrefDisplay::apply(LyXRC & rc) const
648 switch (instantPreviewCO->currentIndex()) {
649 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
650 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
651 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
654 lyx::graphics::DisplayType dtype;
655 switch (displayGraphicsCO->currentIndex()) {
656 case 3: dtype = lyx::graphics::NoDisplay; break;
657 case 2: dtype = lyx::graphics::ColorDisplay; break;
658 case 1: dtype = lyx::graphics::GrayscaleDisplay; break;
659 case 0: dtype = lyx::graphics::MonochromeDisplay; break;
660 default: dtype = lyx::graphics::GrayscaleDisplay;
662 rc.display_graphics = dtype;
664 // FIXME!! The graphics cache no longer has a changeDisplay method.
666 if (old_value != rc.display_graphics) {
667 lyx::graphics::GCache & gc = lyx::graphics::GCache::get();
674 void PrefDisplay::update(LyXRC const & rc)
676 switch (rc.preview) {
677 case LyXRC::PREVIEW_OFF:
678 instantPreviewCO->setCurrentIndex(0);
680 case LyXRC::PREVIEW_NO_MATH :
681 instantPreviewCO->setCurrentIndex(1);
683 case LyXRC::PREVIEW_ON :
684 instantPreviewCO->setCurrentIndex(2);
689 switch (rc.display_graphics) {
690 case lyx::graphics::NoDisplay: item = 3; break;
691 case lyx::graphics::ColorDisplay: item = 2; break;
692 case lyx::graphics::GrayscaleDisplay: item = 1; break;
693 case lyx::graphics::MonochromeDisplay: item = 0; break;
696 displayGraphicsCO->setCurrentIndex(item);
700 /////////////////////////////////////////////////////////////////////
704 /////////////////////////////////////////////////////////////////////
706 PrefPaths::PrefPaths(QPrefs * form, QWidget * parent)
707 : PrefModule(_("Paths"), form, parent)
710 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
711 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
712 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
713 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
714 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
715 connect(workingDirED, SIGNAL(textChanged(const QString&)),
716 this, SIGNAL(changed()));
717 connect(templateDirED, SIGNAL(textChanged(const QString&)),
718 this, SIGNAL(changed()));
719 connect(backupDirED, SIGNAL(textChanged(const QString&)),
720 this, SIGNAL(changed()));
721 connect(tempDirED, SIGNAL(textChanged(const QString&)),
722 this, SIGNAL(changed()));
723 connect(lyxserverDirED, SIGNAL(textChanged(const QString&)),
724 this, SIGNAL(changed()));
725 connect(pathPrefixED, SIGNAL(textChanged(const QString&)),
726 this, SIGNAL(changed()));
730 void PrefPaths::apply(LyXRC & rc) const
732 rc.document_path = internal_path(fromqstr(workingDirED->text()));
733 rc.template_path = internal_path(fromqstr(templateDirED->text()));
734 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
735 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
736 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
737 // FIXME: should be a checkbox only
738 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
742 void PrefPaths::update(LyXRC const & rc)
744 workingDirED->setText(toqstr(external_path(rc.document_path)));
745 templateDirED->setText(toqstr(external_path(rc.template_path)));
746 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
747 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
748 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
749 // FIXME: should be a checkbox only
750 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
754 void PrefPaths::select_templatedir()
756 docstring file(form_->controller().browsedir(
757 from_utf8(internal_path(fromqstr(templateDirED->text()))),
758 _("Select a document templates directory")));
760 templateDirED->setText(toqstr(file));
764 void PrefPaths::select_tempdir()
766 docstring file(form_->controller().browsedir(
767 from_utf8(internal_path(fromqstr(tempDirED->text()))),
768 _("Select a temporary directory")));
770 tempDirED->setText(toqstr(file));
774 void PrefPaths::select_backupdir()
776 docstring file(form_->controller().browsedir(
777 from_utf8(internal_path(fromqstr(backupDirED->text()))),
778 _("Select a backups directory")));
780 backupDirED->setText(toqstr(file));
784 void PrefPaths::select_workingdir()
786 docstring file(form_->controller().browsedir(
787 from_utf8(internal_path(fromqstr(workingDirED->text()))),
788 _("Select a document directory")));
790 workingDirED->setText(toqstr(file));
794 void PrefPaths::select_lyxpipe()
796 docstring file(form_->controller().browse(
797 from_utf8(internal_path(fromqstr(lyxserverDirED->text()))),
798 _("Give a filename for the LyX server pipe")));
800 lyxserverDirED->setText(toqstr(file));
804 /////////////////////////////////////////////////////////////////////
808 /////////////////////////////////////////////////////////////////////
810 PrefSpellchecker::PrefSpellchecker(QPrefs * form, QWidget * parent)
811 : PrefModule(_("Spellchecker"), form, parent)
815 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
816 #if defined (USE_ISPELL)
817 connect(spellCommandCO, SIGNAL(activated(int)),
818 this, SIGNAL(changed()));
820 spellCommandCO->setEnabled(false);
822 connect(altLanguageED, SIGNAL(textChanged(const QString&)),
823 this, SIGNAL(changed()));
824 connect(escapeCharactersED, SIGNAL(textChanged(const QString&)),
825 this, SIGNAL(changed()));
826 connect(persDictionaryED, SIGNAL(textChanged(const QString&)),
827 this, SIGNAL(changed()));
828 connect(compoundWordCB, SIGNAL(clicked()),
829 this, SIGNAL(changed()));
830 connect(inputEncodingCB, SIGNAL(clicked()),
831 this, SIGNAL(changed()));
833 spellCommandCO->addItem(qt_("ispell"));
834 spellCommandCO->addItem(qt_("aspell"));
835 spellCommandCO->addItem(qt_("hspell"));
837 spellCommandCO->addItem(qt_("pspell (library)"));
840 spellCommandCO->addItem(qt_("aspell (library)"));
846 void PrefSpellchecker::apply(LyXRC & rc) const
848 switch (spellCommandCO->currentIndex()) {
852 rc.use_spell_lib = false;
853 rc.isp_command = fromqstr(spellCommandCO->currentText());
856 rc.use_spell_lib = true;
860 // FIXME: remove isp_use_alt_lang
861 rc.isp_alt_lang = fromqstr(altLanguageED->text());
862 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
863 // FIXME: remove isp_use_esc_chars
864 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
865 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
866 // FIXME: remove isp_use_pers_dict
867 rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
868 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
869 rc.isp_accept_compound = compoundWordCB->isChecked();
870 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
874 void PrefSpellchecker::update(LyXRC const & rc)
876 spellCommandCO->setCurrentIndex(0);
878 if (rc.isp_command == "ispell") {
879 spellCommandCO->setCurrentIndex(0);
880 } else if (rc.isp_command == "aspell") {
881 spellCommandCO->setCurrentIndex(1);
882 } else if (rc.isp_command == "hspell") {
883 spellCommandCO->setCurrentIndex(2);
886 if (rc.use_spell_lib) {
887 #if defined(USE_ASPELL) || defined(USE_PSPELL)
888 spellCommandCO->setCurrentIndex(3);
892 // FIXME: remove isp_use_alt_lang
893 altLanguageED->setText(toqstr(rc.isp_alt_lang));
894 // FIXME: remove isp_use_esc_chars
895 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
896 // FIXME: remove isp_use_pers_dict
897 persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
898 compoundWordCB->setChecked(rc.isp_accept_compound);
899 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
903 void PrefSpellchecker::select_dict()
905 docstring file(form_->controller().browsedict(
906 from_utf8(internal_path(fromqstr(persDictionaryED->text())))));
908 persDictionaryED->setText(toqstr(file));
913 /////////////////////////////////////////////////////////////////////
917 /////////////////////////////////////////////////////////////////////
920 PrefConverters::PrefConverters(QPrefs * form, QWidget * parent)
921 : PrefModule(_("Converters"), form, parent)
925 connect(converterNewPB, SIGNAL(clicked()),
926 this, SLOT(update_converter()));
927 connect(converterRemovePB, SIGNAL(clicked()),
928 this, SLOT(remove_converter()));
929 connect(converterModifyPB, SIGNAL(clicked()),
930 this, SLOT(update_converter()));
931 connect(convertersLW, SIGNAL(currentRowChanged(int)),
932 this, SLOT(switch_converter()));
933 connect(converterFromCO, SIGNAL(activated(const QString&)),
934 this, SLOT(converter_changed()));
935 connect(converterToCO, SIGNAL(activated(const QString&)),
936 this, SLOT(converter_changed()));
937 connect(converterED, SIGNAL(textChanged(const QString&)),
938 this, SLOT(converter_changed()));
939 connect(converterFlagED, SIGNAL(textChanged(const QString&)),
940 this, SLOT(converter_changed()));
941 connect(converterNewPB, SIGNAL(clicked()),
942 this, SIGNAL(changed()));
943 connect(converterRemovePB, SIGNAL(clicked()),
944 this, SIGNAL(changed()));
945 connect(converterModifyPB, SIGNAL(clicked()),
946 this, SIGNAL(changed()));
947 connect(maxAgeLE, SIGNAL(textChanged(const QString&)),
948 this, SIGNAL(changed()));
950 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
951 converterDefGB->setFocusProxy(convertersLW);
955 void PrefConverters::apply(LyXRC & rc) const
957 rc.use_converter_cache = cacheCB->isChecked();
958 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
962 void PrefConverters::update(LyXRC const & rc)
964 cacheCB->setChecked(rc.use_converter_cache);
966 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
967 maxAgeLE->setText(max_age);
972 void PrefConverters::updateGui()
974 // save current selection
975 QString current = converterFromCO->currentText()
976 + " -> " + converterToCO->currentText();
978 converterFromCO->clear();
979 converterToCO->clear();
981 Formats::const_iterator cit = form_->formats().begin();
982 Formats::const_iterator end = form_->formats().end();
983 for (; cit != end; ++cit) {
984 converterFromCO->addItem(toqstr(cit->prettyname()));
985 converterToCO->addItem(toqstr(cit->prettyname()));
988 // currentRowChanged(int) is also triggered when updating the listwidget
989 // block signals to avoid unnecessary calls to switch_converter()
990 convertersLW->blockSignals(true);
991 convertersLW->clear();
993 Converters::const_iterator ccit = form_->converters().begin();
994 Converters::const_iterator cend = form_->converters().end();
995 for (; ccit != cend; ++ccit) {
996 std::string const name =
997 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
998 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
999 new QListWidgetItem(toqstr(name), convertersLW, type);
1001 convertersLW->sortItems(Qt::AscendingOrder);
1002 convertersLW->blockSignals(false);
1004 // restore selection
1005 if (!current.isEmpty()) {
1006 QList<QListWidgetItem *> const item =
1007 convertersLW->findItems(current, Qt::MatchExactly);
1009 convertersLW->setCurrentItem(item.at(0));
1012 // select first element if restoring failed
1013 if (convertersLW->currentRow() == -1)
1014 convertersLW->setCurrentRow(0);
1020 void PrefConverters::switch_converter()
1022 int const cnr = convertersLW->currentItem()->type();
1023 Converter const & c(form_->converters().get(cnr));
1024 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1025 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1026 converterED->setText(toqstr(c.command));
1027 converterFlagED->setText(toqstr(c.flags));
1033 void PrefConverters::converter_changed()
1039 void PrefConverters::updateButtons()
1041 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1042 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1043 int const sel = form_->converters().getNumber(from.name(), to.name());
1044 bool const known = !(sel < 0);
1045 bool const valid = !(converterED->text().isEmpty()
1046 || from.name() == to.name());
1048 int const cnr = convertersLW->currentItem()->type();
1049 Converter const & c(form_->converters().get(cnr));
1050 string const old_command = c.command;
1051 string const old_flag = c.flags;
1052 string const new_command(fromqstr(converterED->text()));
1053 string const new_flag(fromqstr(converterFlagED->text()));
1055 bool modified = ((old_command != new_command) || (old_flag != new_flag));
1057 converterModifyPB->setEnabled(valid && known && modified);
1058 converterNewPB->setEnabled(valid && !known);
1059 converterRemovePB->setEnabled(known);
1061 maxAgeLE->setEnabled(cacheCB->isChecked());
1062 maxAgeLA->setEnabled(cacheCB->isChecked());
1067 // specify unique from/to or it doesn't appear. This is really bad UI
1068 // this is why we can use the same function for both new and modify
1069 void PrefConverters::update_converter()
1071 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1072 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1073 string const flags = fromqstr(converterFlagED->text());
1074 string const command = fromqstr(converterED->text());
1076 Converter const * old = form_->converters().getConverter(from.name(), to.name());
1077 form_->converters().add(from.name(), to.name(), command, flags);
1079 form_->converters().updateLast(form_->formats());
1084 // Remove all files created by this converter from the cache, since
1085 // the modified converter might create different files.
1086 ConverterCache::get().remove_all(from.name(), to.name());
1090 void PrefConverters::remove_converter()
1092 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1093 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1094 form_->converters().erase(from.name(), to.name());
1098 // Remove all files created by this converter from the cache, since
1099 // a possible new converter might create different files.
1100 ConverterCache::get().remove_all(from.name(), to.name());
1104 void PrefConverters::on_cacheCB_stateChanged(int state)
1106 maxAgeLE->setEnabled(state == Qt::Checked);
1107 maxAgeLA->setEnabled(state == Qt::Checked);
1112 /////////////////////////////////////////////////////////////////////
1116 /////////////////////////////////////////////////////////////////////
1118 PrefCopiers::PrefCopiers(QPrefs * form, QWidget * parent)
1119 : PrefModule(_("Copiers"), form, parent)
1123 connect(copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
1124 connect(copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
1125 connect(copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
1126 connect(AllCopiersLW, SIGNAL(currentRowChanged(int)),
1127 this, SLOT(switch_copierLB(int)));
1128 connect(copierFormatCO, SIGNAL(activated(int)),
1129 this, SLOT(switch_copierCO(int)));
1130 connect(copierNewPB, SIGNAL(clicked()),
1131 this, SIGNAL(changed()));
1132 connect(copierRemovePB, SIGNAL(clicked()),
1133 this, SIGNAL(changed()));
1134 connect(copierModifyPB, SIGNAL(clicked()),
1135 this, SIGNAL(changed()));
1136 connect(copierFormatCO, SIGNAL(activated(const QString &)),
1137 this, SLOT(copiers_changed()));
1138 connect(copierED, SIGNAL(textChanged(const QString &)),
1139 this, SLOT(copiers_changed()));
1143 void PrefCopiers::apply(LyXRC & /*rc*/) const
1148 void PrefCopiers::update(LyXRC const & /*rc*/)
1154 void PrefCopiers::update()
1156 // The choice widget
1157 // save current selection
1158 QString current = copierFormatCO->currentText();
1159 copierFormatCO->clear();
1161 for (Formats::const_iterator it = form_->formats().begin(),
1162 end = form_->formats().end();
1164 copierFormatCO->addItem(toqstr(it->prettyname()));
1167 // The browser widget
1168 AllCopiersLW->clear();
1170 for (Movers::const_iterator it = form_->movers().begin(),
1171 end = form_->movers().end();
1173 std::string const & command = it->second.command();
1174 if (command.empty())
1176 QString const pretty = toqstr(form_->formats().prettyName(it->first));
1177 AllCopiersLW->addItem(pretty);
1179 AllCopiersLW->sortItems(Qt::AscendingOrder);
1181 // restore selection
1182 if (!current.isEmpty()) {
1183 QList<QListWidgetItem *> item =
1184 AllCopiersLW->findItems(current, Qt::MatchExactly);
1186 AllCopiersLW->setCurrentItem(item.at(0));
1188 // select first element if restoring failed
1189 if (AllCopiersLW->currentRow() == -1)
1190 AllCopiersLW->setCurrentRow(0);
1196 class SamePrettyName {
1198 SamePrettyName(string const & n) : pretty_name_(n) {}
1200 bool operator()(Format const & fmt) const {
1201 return fmt.prettyname() == pretty_name_;
1205 string const pretty_name_;
1209 Format const * getFormat(std::string const & prettyname)
1211 Formats::const_iterator it = formats.begin();
1212 Formats::const_iterator const end = formats.end();
1213 it = std::find_if(it, end, SamePrettyName(prettyname));
1214 return it == end ? 0 : &*it;
1220 void PrefCopiers::switch_copierLB(int row)
1226 std::string const browser_text =
1227 fromqstr(AllCopiersLW->currentItem()->text());
1228 Format const * fmt = getFormat(browser_text);
1232 QString const gui_name = toqstr(fmt->prettyname());
1233 QString const command = toqstr(form_->movers().command(fmt->name()));
1236 int const combo_size = copierFormatCO->count();
1237 for (int i = 0; i < combo_size; ++i) {
1238 QString const text = copierFormatCO->itemText(i);
1239 if (text == gui_name) {
1240 copierFormatCO->setCurrentIndex(i);
1241 copierED->setText(command);
1249 void PrefCopiers::switch_copierCO(int row)
1254 std::string const combo_text =
1255 fromqstr(copierFormatCO->currentText());
1256 Format const * fmt = getFormat(combo_text);
1260 QString const command = toqstr(form_->movers().command(fmt->name()));
1261 copierED->setText(command);
1263 QListWidgetItem * const index = AllCopiersLW->currentItem();
1265 AllCopiersLW->setItemSelected(index, false);
1267 QString const gui_name = toqstr(fmt->prettyname());
1268 int const browser_size = AllCopiersLW->count();
1269 for (int i = 0; i < browser_size; ++i) {
1270 QString const text = AllCopiersLW->item(i)->text();
1271 if (text == gui_name) {
1272 QListWidgetItem * item = AllCopiersLW->item(i);
1273 AllCopiersLW->setItemSelected(item, true);
1280 void PrefCopiers::copiers_changed()
1286 void PrefCopiers::updateButtons()
1288 QString selected = copierFormatCO->currentText();
1291 for (int i = 0; i < AllCopiersLW->count(); ++i) {
1292 if (AllCopiersLW->item(i)->text() == selected)
1296 bool const valid = !copierED->text().isEmpty();
1298 Format const * fmt = getFormat(fromqstr(selected));
1299 string const old_command = form_->movers().command(fmt->name());
1300 string const new_command(fromqstr(copierED->text()));
1302 bool modified = (old_command != new_command);
1304 copierModifyPB->setEnabled(valid && known && modified);
1305 copierNewPB->setEnabled(valid && !known);
1306 copierRemovePB->setEnabled(known);
1310 void PrefCopiers::new_copier()
1312 std::string const combo_text =
1313 fromqstr(copierFormatCO->currentText());
1314 Format const * fmt = getFormat(combo_text);
1318 string const command = fromqstr(copierED->text());
1319 if (command.empty())
1322 form_->movers().set(fmt->name(), command);
1325 int const last = AllCopiersLW->count() - 1;
1326 AllCopiersLW->setCurrentRow(last);
1332 void PrefCopiers::modify_copier()
1334 std::string const combo_text =
1335 fromqstr(copierFormatCO->currentText());
1336 Format const * fmt = getFormat(combo_text);
1340 string const command = fromqstr(copierED->text());
1341 form_->movers().set(fmt->name(), command);
1348 void PrefCopiers::remove_copier()
1350 std::string const combo_text =
1351 fromqstr(copierFormatCO->currentText());
1352 Format const * fmt = getFormat(combo_text);
1356 string const & fmt_name = fmt->name();
1357 form_->movers().set(fmt_name, string());
1365 /////////////////////////////////////////////////////////////////////
1369 /////////////////////////////////////////////////////////////////////
1371 PrefFileformats::PrefFileformats(QPrefs * form, QWidget * parent)
1372 : PrefModule(_("File formats"), form, parent)
1376 connect(formatNewPB, SIGNAL(clicked()),
1377 this, SLOT(new_format()));
1378 connect(formatRemovePB, SIGNAL(clicked()),
1379 this, SLOT(remove_format()));
1380 connect(formatModifyPB, SIGNAL(clicked()),
1381 this, SLOT(modify_format()));
1382 connect(formatsLW, SIGNAL(currentRowChanged(int)),
1383 this, SLOT(switch_format(int)));
1384 connect(formatED, SIGNAL(textChanged(const QString&)),
1385 this, SLOT(fileformat_changed()));
1386 connect(guiNameED, SIGNAL(textChanged(const QString&)),
1387 this, SLOT(fileformat_changed()));
1388 connect(shortcutED, SIGNAL(textChanged(const QString&)),
1389 this, SLOT(fileformat_changed()));
1390 connect(extensionED, SIGNAL(textChanged(const QString&)),
1391 this, SLOT(fileformat_changed()));
1392 connect(viewerED, SIGNAL(textChanged(const QString&)),
1393 this, SLOT(fileformat_changed()));
1394 connect(editorED, SIGNAL(textChanged(const QString&)),
1395 this, SLOT(fileformat_changed()));
1396 connect(documentCB, SIGNAL(clicked()),
1397 this, SLOT(fileformat_changed()));
1398 connect(vectorCB, SIGNAL(clicked()),
1399 this, SLOT(fileformat_changed()));
1400 connect(formatNewPB, SIGNAL(clicked()),
1401 this, SIGNAL(changed()));
1402 connect(formatRemovePB, SIGNAL(clicked()),
1403 this, SIGNAL(changed()));
1404 connect(formatModifyPB, SIGNAL(clicked()),
1405 this, SIGNAL(changed()));
1409 void PrefFileformats::apply(LyXRC & /*rc*/) const
1414 void PrefFileformats::update(LyXRC const & /*rc*/)
1420 void PrefFileformats::update()
1422 // save current selection
1423 QString current = guiNameED->text();
1425 // update listwidget with formats
1426 formatsLW->blockSignals(true);
1428 Formats::const_iterator cit = form_->formats().begin();
1429 Formats::const_iterator end = form_->formats().end();
1430 for (; cit != end; ++cit) {
1431 new QListWidgetItem(toqstr(cit->prettyname()),
1433 form_->formats().getNumber(cit->name()) );
1435 formatsLW->sortItems(Qt::AscendingOrder);
1436 formatsLW->blockSignals(false);
1438 // restore selection
1439 if (!current.isEmpty()) {
1440 QList<QListWidgetItem *> item = formatsLW->findItems(current, Qt::MatchExactly);
1442 formatsLW->setCurrentItem(item.at(0));
1444 // select first element if restoring failed
1445 if (formatsLW->currentRow() == -1)
1446 formatsLW->setCurrentRow(0);
1450 void PrefFileformats::switch_format(int nr)
1452 int const ftype = formatsLW->item(nr)->type();
1453 Format const f = form_->formats().get(ftype);
1455 formatED->setText(toqstr(f.name()));
1456 guiNameED->setText(toqstr(f.prettyname()));
1457 extensionED->setText(toqstr(f.extension()));
1458 shortcutED->setText(toqstr(f.shortcut()));
1459 viewerED->setText(toqstr(f.viewer()));
1460 editorED->setText(toqstr(f.editor()));
1461 documentCB->setChecked((f.documentFormat()));
1462 vectorCB->setChecked((f.vectorFormat()));
1468 void PrefFileformats::fileformat_changed()
1474 void PrefFileformats::updateButtons()
1476 QString const format = formatED->text();
1477 QString const gui_name = guiNameED->text();
1478 int const sel = form_->formats().getNumber(fromqstr(format));
1479 bool gui_name_known = false;
1481 for (int i = 0; i < formatsLW->count(); ++i) {
1482 if (formatsLW->item(i)->text() == gui_name) {
1483 gui_name_known = true;
1484 where = formatsLW->item(i)->type();
1488 // assure that a gui name cannot be chosen twice
1489 bool const known_otherwise = gui_name_known && (where != sel);
1491 bool const known = !(sel < 0);
1492 bool const valid = (!formatED->text().isEmpty()
1493 && !guiNameED->text().isEmpty());
1495 int const ftype = formatsLW->currentItem()->type();
1496 Format const & f(form_->formats().get(ftype));
1497 string const old_pretty(f.prettyname());
1498 string const old_shortcut(f.shortcut());
1499 string const old_extension(f.extension());
1500 string const old_viewer(f.viewer());
1501 string const old_editor(f.editor());
1502 bool const old_document(f.documentFormat());
1503 bool const old_vector(f.vectorFormat());
1505 string const new_pretty(fromqstr(gui_name));
1506 string const new_shortcut(fromqstr(shortcutED->text()));
1507 string const new_extension(fromqstr(extensionED->text()));
1508 string const new_viewer(fromqstr(viewerED->text()));
1509 string const new_editor(fromqstr(editorED->text()));
1510 bool const new_document(documentCB->isChecked());
1511 bool const new_vector(vectorCB->isChecked());
1513 bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
1514 || (old_extension != new_extension) || (old_viewer != new_viewer)
1515 || old_editor != new_editor || old_document != new_document
1516 || old_vector != new_vector);
1518 formatModifyPB->setEnabled(valid && known && modified && !known_otherwise);
1519 formatNewPB->setEnabled(valid && !known && !gui_name_known);
1520 formatRemovePB->setEnabled(known);
1524 void PrefFileformats::new_format()
1526 string const name = fromqstr(formatED->text());
1527 string const prettyname = fromqstr(guiNameED->text());
1528 string const extension = fromqstr(extensionED->text());
1529 string const shortcut = fromqstr(shortcutED->text());
1530 string const viewer = fromqstr(viewerED->text());
1531 string const editor = fromqstr(editorED->text());
1532 int flags = Format::none;
1533 if (documentCB->isChecked())
1534 flags |= Format::document;
1535 if (vectorCB->isChecked())
1536 flags |= Format::vector;
1538 form_->formats().add(name, extension, prettyname, shortcut, viewer,
1540 form_->formats().sort();
1541 form_->converters().update(form_->formats());
1549 void PrefFileformats::modify_format()
1551 int const current_item = formatsLW->currentItem()->type();
1552 Format const & oldformat = form_->formats().get(current_item);
1553 form_->formats().erase(oldformat.name());
1559 void PrefFileformats::remove_format()
1561 int const nr = formatsLW->currentItem()->type();
1562 string const current_text = form_->formats().get(nr).name();
1563 if (form_->converters().formatIsUsed(current_text)) {
1564 Alert::error(_("Format in use"),
1565 _("Cannot remove a Format used by a Converter. "
1566 "Remove the converter first."));
1570 form_->formats().erase(current_text);
1571 form_->converters().update(form_->formats());
1579 /////////////////////////////////////////////////////////////////////
1583 /////////////////////////////////////////////////////////////////////
1585 PrefLanguage::PrefLanguage(QWidget * parent)
1586 : PrefModule(_("Language"), 0, parent)
1590 connect(rtlCB, SIGNAL(clicked()),
1591 this, SIGNAL(changed()));
1592 connect(markForeignCB, SIGNAL(clicked()),
1593 this, SIGNAL(changed()));
1594 connect(autoBeginCB, SIGNAL(clicked()),
1595 this, SIGNAL(changed()));
1596 connect(autoEndCB, SIGNAL(clicked()),
1597 this, SIGNAL(changed()));
1598 connect(useBabelCB, SIGNAL(clicked()),
1599 this, SIGNAL(changed()));
1600 connect(globalCB, SIGNAL(clicked()),
1601 this, SIGNAL(changed()));
1602 connect(languagePackageED, SIGNAL(textChanged(const QString&)),
1603 this, SIGNAL(changed()));
1604 connect(startCommandED, SIGNAL(textChanged(const QString&)),
1605 this, SIGNAL(changed()));
1606 connect(endCommandED, SIGNAL(textChanged(const QString&)),
1607 this, SIGNAL(changed()));
1608 connect(defaultLanguageCO, SIGNAL(activated(int)),
1609 this, SIGNAL(changed()));
1611 defaultLanguageCO->clear();
1613 // store the lang identifiers for later
1614 std::vector<LanguagePair> const langs = frontend::getLanguageData(false);
1615 lang_ = getSecond(langs);
1617 std::vector<LanguagePair>::const_iterator lit = langs.begin();
1618 std::vector<LanguagePair>::const_iterator lend = langs.end();
1619 for (; lit != lend; ++lit) {
1620 defaultLanguageCO->addItem(toqstr(lit->first));
1625 void PrefLanguage::apply(LyXRC & rc) const
1627 // FIXME: remove rtl_support bool
1628 rc.rtl_support = rtlCB->isChecked();
1629 rc.mark_foreign_language = markForeignCB->isChecked();
1630 rc.language_auto_begin = autoBeginCB->isChecked();
1631 rc.language_auto_end = autoEndCB->isChecked();
1632 rc.language_use_babel = useBabelCB->isChecked();
1633 rc.language_global_options = globalCB->isChecked();
1634 rc.language_package = fromqstr(languagePackageED->text());
1635 rc.language_command_begin = fromqstr(startCommandED->text());
1636 rc.language_command_end = fromqstr(endCommandED->text());
1637 rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1641 void PrefLanguage::update(LyXRC const & rc)
1643 // FIXME: remove rtl_support bool
1644 rtlCB->setChecked(rc.rtl_support);
1645 markForeignCB->setChecked(rc.mark_foreign_language);
1646 autoBeginCB->setChecked(rc.language_auto_begin);
1647 autoEndCB->setChecked(rc.language_auto_end);
1648 useBabelCB->setChecked(rc.language_use_babel);
1649 globalCB->setChecked(rc.language_global_options);
1650 languagePackageED->setText(toqstr(rc.language_package));
1651 startCommandED->setText(toqstr(rc.language_command_begin));
1652 endCommandED->setText(toqstr(rc.language_command_end));
1654 int const pos = int(findPos_helper(lang_, rc.default_language));
1655 defaultLanguageCO->setCurrentIndex(pos);
1659 /////////////////////////////////////////////////////////////////////
1663 /////////////////////////////////////////////////////////////////////
1665 PrefPrinter::PrefPrinter(QWidget * parent)
1666 : PrefModule(_("Printer"), 0, parent)
1670 connect(printerAdaptCB, SIGNAL(clicked()),
1671 this, SIGNAL(changed()));
1672 connect(printerCommandED, SIGNAL(textChanged(const QString&)),
1673 this, SIGNAL(changed()));
1674 connect(printerNameED, SIGNAL(textChanged(const QString&)),
1675 this, SIGNAL(changed()));
1676 connect(printerPageRangeED, SIGNAL(textChanged(const QString&)),
1677 this, SIGNAL(changed()));
1678 connect(printerCopiesED, SIGNAL(textChanged(const QString&)),
1679 this, SIGNAL(changed()));
1680 connect(printerReverseED, SIGNAL(textChanged(const QString&)),
1681 this, SIGNAL(changed()));
1682 connect(printerToPrinterED, SIGNAL(textChanged(const QString&)),
1683 this, SIGNAL(changed()));
1684 connect(printerExtensionED, SIGNAL(textChanged(const QString&)),
1685 this, SIGNAL(changed()));
1686 connect(printerSpoolCommandED, SIGNAL(textChanged(const QString&)),
1687 this, SIGNAL(changed()));
1688 connect(printerPaperTypeED, SIGNAL(textChanged(const QString&)),
1689 this, SIGNAL(changed()));
1690 connect(printerEvenED, SIGNAL(textChanged(const QString&)),
1691 this, SIGNAL(changed()));
1692 connect(printerOddED, SIGNAL(textChanged(const QString&)),
1693 this, SIGNAL(changed()));
1694 connect(printerCollatedED, SIGNAL(textChanged(const QString&)),
1695 this, SIGNAL(changed()));
1696 connect(printerLandscapeED, SIGNAL(textChanged(const QString&)),
1697 this, SIGNAL(changed()));
1698 connect(printerToFileED, SIGNAL(textChanged(const QString&)),
1699 this, SIGNAL(changed()));
1700 connect(printerExtraED, SIGNAL(textChanged(const QString&)),
1701 this, SIGNAL(changed()));
1702 connect(printerSpoolPrefixED, SIGNAL(textChanged(const QString&)),
1703 this, SIGNAL(changed()));
1704 connect(printerPaperSizeED, SIGNAL(textChanged(const QString&)),
1705 this, SIGNAL(changed()));
1709 void PrefPrinter::apply(LyXRC & rc) const
1711 rc.print_adapt_output = printerAdaptCB->isChecked();
1712 rc.print_command = fromqstr(printerCommandED->text());
1713 rc.printer = fromqstr(printerNameED->text());
1715 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1716 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1717 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1718 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1719 rc.print_file_extension = fromqstr(printerExtensionED->text());
1720 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1721 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1722 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1723 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1724 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1725 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1726 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1727 rc.print_extra_options = fromqstr(printerExtraED->text());
1728 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1729 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1733 void PrefPrinter::update(LyXRC const & rc)
1735 printerAdaptCB->setChecked(rc.print_adapt_output);
1736 printerCommandED->setText(toqstr(rc.print_command));
1737 printerNameED->setText(toqstr(rc.printer));
1739 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1740 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1741 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1742 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1743 printerExtensionED->setText(toqstr(rc.print_file_extension));
1744 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1745 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1746 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1747 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1748 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1749 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1750 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1751 printerExtraED->setText(toqstr(rc.print_extra_options));
1752 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1753 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1757 /////////////////////////////////////////////////////////////////////
1759 // PrefUserInterface
1761 /////////////////////////////////////////////////////////////////////
1763 PrefUserInterface::PrefUserInterface(QPrefs * form, QWidget * parent)
1764 : PrefModule(_("User interface"), form, parent)
1768 connect(autoSaveCB, SIGNAL(toggled(bool)),
1769 autoSaveLA, SLOT(setEnabled(bool)));
1770 connect(autoSaveCB, SIGNAL(toggled(bool)),
1771 autoSaveSB, SLOT(setEnabled(bool)));
1772 connect(autoSaveCB, SIGNAL(toggled(bool)),
1773 TextLabel1, SLOT(setEnabled(bool)));
1774 connect(uiFilePB, SIGNAL(clicked()),
1775 this, SLOT(select_ui()));
1776 connect(bindFilePB, SIGNAL(clicked()),
1777 this, SLOT(select_bind()));
1778 connect(uiFileED, SIGNAL(textChanged(const QString &)),
1779 this, SIGNAL(changed()));
1780 connect(bindFileED, SIGNAL(textChanged(const QString &)),
1781 this, SIGNAL(changed()));
1782 connect(restoreCursorCB, SIGNAL(clicked()),
1783 this, SIGNAL(changed()));
1784 connect(loadSessionCB, SIGNAL(clicked()),
1785 this, SIGNAL(changed()));
1786 connect(loadWindowSizeCB, SIGNAL(clicked()),
1787 this, SIGNAL(changed()));
1788 connect(loadWindowLocationCB, SIGNAL(clicked()),
1789 this, SIGNAL(changed()));
1790 connect(windowWidthSB, SIGNAL(valueChanged(int)),
1791 this, SIGNAL(changed()));
1792 connect(windowHeightSB, SIGNAL(valueChanged(int)),
1793 this, SIGNAL(changed()));
1794 connect(cursorFollowsCB, SIGNAL(clicked()),
1795 this, SIGNAL(changed()));
1796 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1797 this, SIGNAL(changed()));
1798 connect(autoSaveCB, SIGNAL(clicked()),
1799 this, SIGNAL(changed()));
1800 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1801 this, SIGNAL(changed()));
1802 lastfilesSB->setMaximum(maxlastfiles);
1806 void PrefUserInterface::apply(LyXRC & rc) const
1808 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1809 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1810 rc.use_lastfilepos = restoreCursorCB->isChecked();
1811 rc.load_session = loadSessionCB->isChecked();
1812 if (loadWindowSizeCB->isChecked()) {
1813 rc.geometry_width = 0;
1814 rc.geometry_height = 0;
1816 rc.geometry_width = windowWidthSB->value();
1817 rc.geometry_height = windowHeightSB->value();
1819 rc.geometry_xysaved = loadWindowLocationCB->isChecked();
1820 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1821 rc.autosave = autoSaveSB->value() * 60;
1822 rc.make_backup = autoSaveCB->isChecked();
1823 rc.num_lastfiles = lastfilesSB->value();
1827 void PrefUserInterface::update(LyXRC const & rc)
1829 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1830 bindFileED->setText(toqstr(external_path(rc.bind_file)));
1831 restoreCursorCB->setChecked(rc.use_lastfilepos);
1832 loadSessionCB->setChecked(rc.load_session);
1833 bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
1834 loadWindowSizeCB->setChecked(loadWindowSize);
1835 if (!loadWindowSize) {
1836 windowWidthSB->setValue(rc.geometry_width);
1837 windowHeightSB->setValue(rc.geometry_height);
1839 loadWindowLocationCB->setChecked(rc.geometry_xysaved);
1840 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1841 // convert to minutes
1842 int mins(rc.autosave / 60);
1843 if (rc.autosave && !mins)
1845 autoSaveSB->setValue(mins);
1846 autoSaveCB->setChecked(rc.make_backup);
1847 lastfilesSB->setValue(rc.num_lastfiles);
1852 void PrefUserInterface::select_ui()
1854 docstring const name =
1855 from_utf8(internal_path(fromqstr(uiFileED->text())));
1856 docstring file(form_->controller().browseUI(name));
1858 uiFileED->setText(toqstr(file));
1862 void PrefUserInterface::select_bind()
1864 docstring const name =
1865 from_utf8(internal_path(fromqstr(bindFileED->text())));
1866 docstring file(form_->controller().browsebind(name));
1868 bindFileED->setText(toqstr(file));
1872 void PrefUserInterface::on_loadWindowSizeCB_toggled(bool loadwindowsize)
1874 windowWidthLA->setDisabled(loadwindowsize);
1875 windowHeightLA->setDisabled(loadwindowsize);
1876 windowWidthSB->setDisabled(loadwindowsize);
1877 windowHeightSB->setDisabled(loadwindowsize);
1881 PrefIdentity::PrefIdentity(QWidget * parent)
1882 : PrefModule(_("Identity"), 0, parent)
1886 connect(nameED, SIGNAL(textChanged(const QString&)),
1887 this, SIGNAL(changed()));
1888 connect(emailED, SIGNAL(textChanged(const QString&)),
1889 this, SIGNAL(changed()));
1893 void PrefIdentity::apply(LyXRC & rc) const
1895 rc.user_name = fromqstr(nameED->text());
1896 rc.user_email = fromqstr(emailED->text());
1900 void PrefIdentity::update(LyXRC const & rc)
1902 nameED->setText(toqstr(rc.user_name));
1903 emailED->setText(toqstr(rc.user_email));
1908 /////////////////////////////////////////////////////////////////////
1912 /////////////////////////////////////////////////////////////////////
1914 QPrefsDialog::QPrefsDialog(QPrefs * form)
1918 QDialog::setModal(false);
1920 connect(savePB, SIGNAL(clicked()), form, SLOT(slotOK()));
1921 connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
1922 connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
1923 connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore()));
1925 add(new PrefUserInterface(form_));
1926 add(new PrefScreenFonts(form_));
1927 add(new PrefColors(form_));
1928 add(new PrefDisplay);
1929 add(new PrefKeyboard(form_));
1931 add(new PrefPaths(form_));
1933 add(new PrefIdentity);
1935 add(new PrefLanguage);
1936 add(new PrefSpellchecker(form_));
1938 add(new PrefPrinter);
1940 add(new PrefPlaintext);
1941 add(new PrefLatex(form_));
1943 #if defined(__CYGWIN__) || defined(_WIN32)
1944 add(new PrefCygwinPath);
1948 PrefConverters * converters = new PrefConverters(form_);
1949 PrefFileformats * formats = new PrefFileformats(form_);
1950 connect(formats, SIGNAL(formatsChanged()),
1951 converters, SLOT(updateGui()));
1955 add(new PrefCopiers(form_));
1958 prefsPS->setCurrentPanel(_("User interface"));
1959 // FIXME: hack to work around resizing bug in Qt >= 4.2
1960 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1961 #if QT_VERSION >= 0x040200
1962 prefsPS->updateGeometry();
1965 form_->bcview().setOK(savePB);
1966 form_->bcview().setApply(applyPB);
1967 form_->bcview().setCancel(closePB);
1968 form_->bcview().setRestore(restorePB);
1972 void QPrefsDialog::add(PrefModule * module)
1974 BOOST_ASSERT(module);
1976 prefsPS->addPanel(module, module->title());
1978 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
1980 modules_.push_back(module);
1983 void QPrefsDialog::closeEvent(QCloseEvent * e)
1985 form_->slotWMHide();
1990 void QPrefsDialog::change_adaptor()
1996 void QPrefsDialog::apply(LyXRC & rc) const
1998 size_t end = modules_.size();
1999 for (size_t i = 0; i != end; ++i)
2000 modules_[i]->apply(rc);
2004 void QPrefsDialog::updateRc(LyXRC const & rc)
2006 size_t const end = modules_.size();
2007 for (size_t i = 0; i != end; ++i)
2008 modules_[i]->update(rc);
2012 /////////////////////////////////////////////////////////////////////
2016 /////////////////////////////////////////////////////////////////////
2018 typedef QController<ControlPrefs, QView<QPrefsDialog> > PrefsBase;
2020 QPrefs::QPrefs(Dialog & parent)
2021 : PrefsBase(parent, _("Preferences"))
2025 Converters & QPrefs::converters()
2027 return controller().converters();
2030 Formats & QPrefs::formats()
2032 return controller().formats();
2035 Movers & QPrefs::movers()
2037 return controller().movers();
2040 void QPrefs::build_dialog()
2042 dialog_.reset(new QPrefsDialog(this));
2045 void QPrefs::apply()
2047 dialog_->apply(controller().rc());
2050 void QPrefs::update_contents()
2052 dialog_->updateRc(controller().rc());
2055 } // namespace frontend
2058 #include "QPrefs_moc.cpp"