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"
23 #include "PanelStack.h"
24 #include "QFontExample.h"
27 #include "support/lstrings.h"
28 #include "support/os.h"
30 #include "controllers/ControlPrefs.h"
31 #include "controllers/frontend_helpers.h"
33 #include "frontends/alert.h"
34 #include "frontends/Application.h"
37 #include <QColorDialog>
38 #include <QFontDatabase>
40 #include <QPushButton>
44 #include <QCloseEvent>
46 #include <boost/tuple/tuple.hpp>
52 using lyx::support::compare_ascii_no_case;
53 using lyx::support::os::external_path;
54 using lyx::support::os::external_path_list;
55 using lyx::support::os::internal_path;
56 using lyx::support::os::internal_path_list;
67 /////////////////////////////////////////////////////////////////////
71 /////////////////////////////////////////////////////////////////////
73 string const LookAndFeel = N_("Look and feel");
74 string const LanguageSettings = N_("Language settings");
75 string const Outputs = N_("Outputs");
78 // FIXME: move to frontend_helpers.h
81 static size_t findPos_helper(std::vector<A> const & vec, A const & val)
83 typedef typename std::vector<A>::const_iterator Cit;
85 Cit it = std::find(vec.begin(), vec.end(), val);
88 return std::distance(vec.begin(), it);
92 static void setComboxFont(QComboBox * cb, string const & family,
93 string const & foundry)
95 string const name = makeFontName(family, foundry);
96 for (int i = 0; i < cb->count(); ++i) {
97 if (fromqstr(cb->itemText(i)) == name) {
98 cb->setCurrentIndex(i);
103 // Try matching without foundry name
105 // We count in reverse in order to prefer the Xft foundry
106 for (int i = cb->count() - 1; i >= 0; --i) {
107 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
108 if (compare_ascii_no_case(tmp.first, family) == 0) {
109 cb->setCurrentIndex(i);
114 // family alone can contain e.g. "Helvetica [Adobe]"
115 pair<string, string> tmpfam = parseFontName(family);
117 // We count in reverse in order to prefer the Xft foundry
118 for (int i = cb->count() - 1; i >= 0; --i) {
119 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
120 if (compare_ascii_no_case(tmp.first, tmpfam.first) == 0) {
121 cb->setCurrentIndex(i);
126 // Bleh, default fonts, and the names couldn't be found. Hack
130 font.setKerning(false);
132 if (family == theApp()->romanFontName()) {
133 font.setStyleHint(QFont::Serif);
134 font.setFamily(family.c_str());
135 } else if (family == theApp()->sansFontName()) {
136 font.setStyleHint(QFont::SansSerif);
137 font.setFamily(family.c_str());
138 } else if (family == theApp()->typewriterFontName()) {
139 font.setStyleHint(QFont::TypeWriter);
140 font.setFamily(family.c_str());
142 lyxerr << "FAILED to find the default font: '"
143 << foundry << "', '" << family << '\''<< endl;
147 QFontInfo info(font);
148 pair<string, string> tmp = parseFontName(fromqstr(info.family()));
149 string const & default_font_name = tmp.first;
150 lyxerr << "Apparent font is " << default_font_name << endl;
152 for (int i = 0; i < cb->count(); ++i) {
153 lyxerr << "Looking at " << fromqstr(cb->itemText(i)) << endl;
154 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
155 default_font_name) == 0) {
156 cb->setCurrentIndex(i);
161 lyxerr << "FAILED to find the font: '"
162 << foundry << "', '" << family << '\'' <<endl;
166 /////////////////////////////////////////////////////////////////////
170 /////////////////////////////////////////////////////////////////////
172 PrefPlaintext::PrefPlaintext(QWidget * parent)
173 : PrefModule(_(Outputs), _("Plain text"), 0, parent)
176 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
177 this, SIGNAL(changed()));
178 connect(plaintextRoffED, SIGNAL(textChanged(const QString&)),
179 this, SIGNAL(changed()));
183 void PrefPlaintext::apply(LyXRC & rc) const
185 rc.plaintext_linelen = plaintextLinelengthSB->value();
186 rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
190 void PrefPlaintext::update(LyXRC const & rc)
192 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
193 plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
197 /////////////////////////////////////////////////////////////////////
201 /////////////////////////////////////////////////////////////////////
203 PrefDate::PrefDate(QWidget * parent)
204 : PrefModule(_(Outputs), _("Date format"), 0, parent)
207 connect(DateED, SIGNAL(textChanged(const QString &)),
208 this, SIGNAL(changed()));
212 void PrefDate::apply(LyXRC & rc) const
214 rc.date_insert_format = fromqstr(DateED->text());
218 void PrefDate::update(LyXRC const & rc)
220 DateED->setText(toqstr(rc.date_insert_format));
224 /////////////////////////////////////////////////////////////////////
228 /////////////////////////////////////////////////////////////////////
230 PrefKeyboard::PrefKeyboard(QPrefs * form, QWidget * parent)
231 : PrefModule(_(LookAndFeel), _("Keyboard"), form, parent)
235 connect(keymapCB, SIGNAL(clicked()),
236 this, SIGNAL(changed()));
237 connect(firstKeymapED, SIGNAL(textChanged(const QString&)),
238 this, SIGNAL(changed()));
239 connect(secondKeymapED, SIGNAL(textChanged(const QString&)),
240 this, SIGNAL(changed()));
244 void PrefKeyboard::apply(LyXRC & rc) const
246 // FIXME: can derive CB from the two EDs
247 rc.use_kbmap = keymapCB->isChecked();
248 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
249 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
253 void PrefKeyboard::update(LyXRC const & rc)
255 // FIXME: can derive CB from the two EDs
256 keymapCB->setChecked(rc.use_kbmap);
257 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
258 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
262 QString PrefKeyboard::testKeymap(QString keymap)
264 return toqstr(form_->controller().browsekbmap(from_utf8(internal_path(fromqstr(keymap)))));
268 void PrefKeyboard::on_firstKeymapPB_clicked(bool)
270 QString const file = testKeymap(firstKeymapED->text());
272 firstKeymapED->setText(file);
276 void PrefKeyboard::on_secondKeymapPB_clicked(bool)
278 QString const file = testKeymap(secondKeymapED->text());
280 secondKeymapED->setText(file);
284 void PrefKeyboard::on_keymapCB_toggled(bool keymap)
286 firstKeymapLA->setEnabled(keymap);
287 secondKeymapLA->setEnabled(keymap);
288 firstKeymapED->setEnabled(keymap);
289 secondKeymapED->setEnabled(keymap);
290 firstKeymapPB->setEnabled(keymap);
291 secondKeymapPB->setEnabled(keymap);
295 /////////////////////////////////////////////////////////////////////
299 /////////////////////////////////////////////////////////////////////
301 PrefLatex::PrefLatex(QPrefs * form, QWidget * parent)
302 : PrefModule(_(Outputs), _("LaTeX"), form, parent)
305 connect(latexEncodingED, SIGNAL(textChanged(const QString&)),
306 this, SIGNAL(changed()));
307 connect(latexChecktexED, SIGNAL(textChanged(const QString&)),
308 this, SIGNAL(changed()));
309 connect(latexBibtexED, SIGNAL(textChanged(const QString&)),
310 this, SIGNAL(changed()));
311 connect(latexIndexED, SIGNAL(textChanged(const QString&)),
312 this, SIGNAL(changed()));
313 connect(latexAutoresetCB, SIGNAL(clicked()),
314 this, SIGNAL(changed()));
315 connect(latexDviPaperED, SIGNAL(textChanged(const QString&)),
316 this, SIGNAL(changed()));
317 connect(latexPaperSizeCO, SIGNAL(activated(int)),
318 this, SIGNAL(changed()));
322 void PrefLatex::apply(LyXRC & rc) const
324 rc.fontenc = fromqstr(latexEncodingED->text());
325 rc.chktex_command = fromqstr(latexChecktexED->text());
326 rc.bibtex_command = fromqstr(latexBibtexED->text());
327 rc.index_command = fromqstr(latexIndexED->text());
328 rc.auto_reset_options = latexAutoresetCB->isChecked();
329 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
330 rc.default_papersize =
331 form_->controller().toPaperSize(latexPaperSizeCO->currentIndex());
335 void PrefLatex::update(LyXRC const & rc)
337 latexEncodingED->setText(toqstr(rc.fontenc));
338 latexChecktexED->setText(toqstr(rc.chktex_command));
339 latexBibtexED->setText(toqstr(rc.bibtex_command));
340 latexIndexED->setText(toqstr(rc.index_command));
341 latexAutoresetCB->setChecked(rc.auto_reset_options);
342 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
343 latexPaperSizeCO->setCurrentIndex(
344 form_->controller().fromPaperSize(rc.default_papersize));
348 /////////////////////////////////////////////////////////////////////
352 /////////////////////////////////////////////////////////////////////
354 PrefScreenFonts::PrefScreenFonts(QPrefs * form, QWidget * parent)
355 : PrefModule(_(LookAndFeel), _("Screen fonts"), form, parent)
359 connect(screenRomanCO, SIGNAL(activated(const QString&)),
360 this, SLOT(select_roman(const QString&)));
361 connect(screenSansCO, SIGNAL(activated(const QString&)),
362 this, SLOT(select_sans(const QString&)));
363 connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
364 this, SLOT(select_typewriter(const QString&)));
366 QFontDatabase fontdb;
367 QStringList families(fontdb.families());
368 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
369 screenRomanCO->addItem(*it);
370 screenSansCO->addItem(*it);
371 screenTypewriterCO->addItem(*it);
373 connect(screenRomanCO, SIGNAL(activated(const QString&)),
374 this, SIGNAL(changed()));
375 connect(screenSansCO, SIGNAL(activated(const QString&)),
376 this, SIGNAL(changed()));
377 connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
378 this, SIGNAL(changed()));
379 connect(screenZoomSB, SIGNAL(valueChanged(int)),
380 this, SIGNAL(changed()));
381 connect(screenDpiSB, SIGNAL(valueChanged(int)),
382 this, SIGNAL(changed()));
383 connect(screenTinyED, SIGNAL(textChanged(const QString&)),
384 this, SIGNAL(changed()));
385 connect(screenSmallestED, SIGNAL(textChanged(const QString&)),
386 this, SIGNAL(changed()));
387 connect(screenSmallerED, SIGNAL(textChanged(const QString&)),
388 this, SIGNAL(changed()));
389 connect(screenSmallED, SIGNAL(textChanged(const QString&)),
390 this, SIGNAL(changed()));
391 connect(screenNormalED, SIGNAL(textChanged(const QString&)),
392 this, SIGNAL(changed()));
393 connect(screenLargeED, SIGNAL(textChanged(const QString&)),
394 this, SIGNAL(changed()));
395 connect(screenLargerED, SIGNAL(textChanged(const QString&)),
396 this, SIGNAL(changed()));
397 connect(screenLargestED, SIGNAL(textChanged(const QString&)),
398 this, SIGNAL(changed()));
399 connect(screenHugeED, SIGNAL(textChanged(const QString&)),
400 this, SIGNAL(changed()));
401 connect(screenHugerED, SIGNAL(textChanged(const QString&)),
402 this, SIGNAL(changed()));
404 screenTinyED->setValidator(new QDoubleValidator(
406 screenSmallestED->setValidator(new QDoubleValidator(
408 screenSmallerED->setValidator(new QDoubleValidator(
410 screenSmallED->setValidator(new QDoubleValidator(
412 screenNormalED->setValidator(new QDoubleValidator(
414 screenLargeED->setValidator(new QDoubleValidator(
416 screenLargerED->setValidator(new QDoubleValidator(
418 screenLargestED->setValidator(new QDoubleValidator(
420 screenHugeED->setValidator(new QDoubleValidator(
422 screenHugerED->setValidator(new QDoubleValidator(
427 void PrefScreenFonts::apply(LyXRC & rc) const
429 LyXRC const oldrc(rc);
431 boost::tie(rc.roman_font_name, rc.roman_font_foundry)
432 = parseFontName(fromqstr(screenRomanCO->currentText()));
433 boost::tie(rc.sans_font_name, rc.sans_font_foundry) =
434 parseFontName(fromqstr(screenSansCO->currentText()));
435 boost::tie(rc.typewriter_font_name, rc.typewriter_font_foundry) =
436 parseFontName(fromqstr(screenTypewriterCO->currentText()));
438 rc.zoom = screenZoomSB->value();
439 rc.dpi = screenDpiSB->value();
440 rc.font_sizes[Font::SIZE_TINY] = fromqstr(screenTinyED->text());
441 rc.font_sizes[Font::SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
442 rc.font_sizes[Font::SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
443 rc.font_sizes[Font::SIZE_SMALL] = fromqstr(screenSmallED->text());
444 rc.font_sizes[Font::SIZE_NORMAL] = fromqstr(screenNormalED->text());
445 rc.font_sizes[Font::SIZE_LARGE] = fromqstr(screenLargeED->text());
446 rc.font_sizes[Font::SIZE_LARGER] = fromqstr(screenLargerED->text());
447 rc.font_sizes[Font::SIZE_LARGEST] = fromqstr(screenLargestED->text());
448 rc.font_sizes[Font::SIZE_HUGE] = fromqstr(screenHugeED->text());
449 rc.font_sizes[Font::SIZE_HUGER] = fromqstr(screenHugerED->text());
451 if (rc.font_sizes != oldrc.font_sizes
452 || rc.roman_font_name != oldrc.roman_font_name
453 || rc.sans_font_name != oldrc.sans_font_name
454 || rc.typewriter_font_name != oldrc.typewriter_font_name
455 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
456 form_->controller().updateScreenFonts();
461 void PrefScreenFonts::update(LyXRC const & rc)
463 setComboxFont(screenRomanCO, rc.roman_font_name,
464 rc.roman_font_foundry);
465 setComboxFont(screenSansCO, rc.sans_font_name,
466 rc.sans_font_foundry);
467 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
468 rc.typewriter_font_foundry);
470 select_roman(screenRomanCO->currentText());
471 select_sans(screenSansCO->currentText());
472 select_typewriter(screenTypewriterCO->currentText());
474 screenZoomSB->setValue(rc.zoom);
475 screenDpiSB->setValue(rc.dpi);
476 screenTinyED->setText(toqstr(rc.font_sizes[Font::SIZE_TINY]));
477 screenSmallestED->setText(toqstr(rc.font_sizes[Font::SIZE_SCRIPT]));
478 screenSmallerED->setText(toqstr(rc.font_sizes[Font::SIZE_FOOTNOTE]));
479 screenSmallED->setText(toqstr(rc.font_sizes[Font::SIZE_SMALL]));
480 screenNormalED->setText(toqstr(rc.font_sizes[Font::SIZE_NORMAL]));
481 screenLargeED->setText(toqstr(rc.font_sizes[Font::SIZE_LARGE]));
482 screenLargerED->setText(toqstr(rc.font_sizes[Font::SIZE_LARGER]));
483 screenLargestED->setText(toqstr(rc.font_sizes[Font::SIZE_LARGEST]));
484 screenHugeED->setText(toqstr(rc.font_sizes[Font::SIZE_HUGE]));
485 screenHugerED->setText(toqstr(rc.font_sizes[Font::SIZE_HUGER]));
488 void PrefScreenFonts::select_roman(const QString& name)
490 screenRomanFE->set(QFont(name), name);
494 void PrefScreenFonts::select_sans(const QString& name)
496 screenSansFE->set(QFont(name), name);
500 void PrefScreenFonts::select_typewriter(const QString& name)
502 screenTypewriterFE->set(QFont(name), name);
506 /////////////////////////////////////////////////////////////////////
510 /////////////////////////////////////////////////////////////////////
512 PrefColors::PrefColors(QPrefs * form, QWidget * parent)
513 : PrefModule(_(LookAndFeel), _("Colors"), form, parent)
517 // FIXME: all of this initialization should be put into the controller.
518 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
519 // for some discussion of why that is not trivial.
520 QPixmap icon(32, 32);
521 for (int i = 0; i < Color::ignore; ++i) {
522 Color::color lc = static_cast<Color::color>(i);
523 if (lc == Color::none
524 || lc == Color::black
525 || lc == Color::white
527 || lc == Color::green
530 || lc == Color::magenta
531 || lc == Color::yellow
532 || lc == Color::inherit
533 || lc == Color::ignore) continue;
535 lcolors_.push_back(lc);
536 // This is not a memory leak:
537 /*QListWidgetItem * newItem =*/ new QListWidgetItem(QIcon(icon),
538 toqstr(lcolor.getGUIName(lc)), lyxObjectsLW);
540 curcolors_.resize(lcolors_.size());
541 newcolors_.resize(lcolors_.size());
542 // End initialization
544 connect(colorChangePB, SIGNAL(clicked()),
545 this, SLOT(change_color()));
546 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
547 this, SLOT(change_lyxObjects_selection()));
548 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
549 this, SLOT(change_color()));
553 void PrefColors::apply(LyXRC & /*rc*/) const
555 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
556 if (curcolors_[i] != newcolors_[i]) {
557 form_->controller().setColor(lcolors_[i], fromqstr(newcolors_[i]));
563 void PrefColors::update(LyXRC const & /*rc*/)
565 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
566 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
567 QPixmap coloritem(32, 32);
568 coloritem.fill(color);
569 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
570 newcolors_[i] = curcolors_[i] = color.name();
572 change_lyxObjects_selection();
575 void PrefColors::change_color()
577 int const row = lyxObjectsLW->currentRow();
582 QString const color = newcolors_[row];
583 QColor c(QColorDialog::getColor(QColor(color), qApp->focusWidget()));
585 if (c.isValid() && c.name() != color) {
586 newcolors_[row] = c.name();
587 QPixmap coloritem(32, 32);
589 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
595 void PrefColors::change_lyxObjects_selection()
597 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
601 /////////////////////////////////////////////////////////////////////
605 /////////////////////////////////////////////////////////////////////
607 PrefCygwinPath::PrefCygwinPath(QWidget * parent)
608 : PrefModule(_(Outputs), _("Paths"), 0, parent)
611 connect(pathCB, SIGNAL(clicked()), this, SIGNAL(changed()));
615 void PrefCygwinPath::apply(LyXRC & rc) const
617 rc.windows_style_tex_paths = pathCB->isChecked();
621 void PrefCygwinPath::update(LyXRC const & rc)
623 pathCB->setChecked(rc.windows_style_tex_paths);
627 /////////////////////////////////////////////////////////////////////
631 /////////////////////////////////////////////////////////////////////
633 PrefDisplay::PrefDisplay(QWidget * parent)
634 : PrefModule(_(LookAndFeel), _("Graphics"), 0, parent)
637 connect(instantPreviewCO, SIGNAL(activated(int)),
638 this, SIGNAL(changed()));
639 connect(displayGraphicsCO, SIGNAL(activated(int)),
640 this, SIGNAL(changed()));
644 void PrefDisplay::apply(LyXRC & rc) const
646 switch (instantPreviewCO->currentIndex()) {
647 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
648 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
649 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
652 lyx::graphics::DisplayType dtype;
653 switch (displayGraphicsCO->currentIndex()) {
654 case 3: dtype = lyx::graphics::NoDisplay; break;
655 case 2: dtype = lyx::graphics::ColorDisplay; break;
656 case 1: dtype = lyx::graphics::GrayscaleDisplay; break;
657 case 0: dtype = lyx::graphics::MonochromeDisplay; break;
658 default: dtype = lyx::graphics::GrayscaleDisplay;
660 rc.display_graphics = dtype;
663 #warning 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(docstring(), _("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(_(LanguageSettings), _("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(docstring(), _("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());
1086 void PrefConverters::remove_converter()
1088 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1089 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1090 form_->converters().erase(from.name(), to.name());
1096 void PrefConverters::on_cacheCB_stateChanged(int state)
1098 maxAgeLE->setEnabled(state == Qt::Checked);
1099 maxAgeLA->setEnabled(state == Qt::Checked);
1104 /////////////////////////////////////////////////////////////////////
1108 /////////////////////////////////////////////////////////////////////
1110 PrefCopiers::PrefCopiers(QPrefs * form, QWidget * parent)
1111 : PrefModule(docstring(), _("Copiers"), form, parent)
1115 connect(copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
1116 connect(copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
1117 connect(copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
1118 connect(AllCopiersLW, SIGNAL(currentRowChanged(int)),
1119 this, SLOT(switch_copierLB(int)));
1120 connect(copierFormatCO, SIGNAL(activated(int)),
1121 this, SLOT(switch_copierCO(int)));
1122 connect(copierNewPB, SIGNAL(clicked()),
1123 this, SIGNAL(changed()));
1124 connect(copierRemovePB, SIGNAL(clicked()),
1125 this, SIGNAL(changed()));
1126 connect(copierModifyPB, SIGNAL(clicked()),
1127 this, SIGNAL(changed()));
1128 connect(copierFormatCO, SIGNAL(activated(const QString &)),
1129 this, SLOT(copiers_changed()));
1130 connect(copierED, SIGNAL(textChanged(const QString &)),
1131 this, SLOT(copiers_changed()));
1135 void PrefCopiers::apply(LyXRC & /*rc*/) const
1140 void PrefCopiers::update(LyXRC const & /*rc*/)
1146 void PrefCopiers::update()
1148 // The choice widget
1149 // save current selection
1150 QString current = copierFormatCO->currentText();
1151 copierFormatCO->clear();
1153 for (Formats::const_iterator it = form_->formats().begin(),
1154 end = form_->formats().end();
1156 copierFormatCO->addItem(toqstr(it->prettyname()));
1159 // The browser widget
1160 AllCopiersLW->clear();
1162 for (Movers::const_iterator it = form_->movers().begin(),
1163 end = form_->movers().end();
1165 std::string const & command = it->second.command();
1166 if (command.empty())
1168 QString const pretty = toqstr(form_->formats().prettyName(it->first));
1169 AllCopiersLW->addItem(pretty);
1171 AllCopiersLW->sortItems(Qt::AscendingOrder);
1173 // restore selection
1174 if (!current.isEmpty()) {
1175 QList<QListWidgetItem *> item =
1176 AllCopiersLW->findItems(current, Qt::MatchExactly);
1178 AllCopiersLW->setCurrentItem(item.at(0));
1180 // select first element if restoring failed
1181 if (AllCopiersLW->currentRow() == -1)
1182 AllCopiersLW->setCurrentRow(0);
1188 class SamePrettyName {
1190 SamePrettyName(string const & n) : pretty_name_(n) {}
1192 bool operator()(Format const & fmt) const {
1193 return fmt.prettyname() == pretty_name_;
1197 string const pretty_name_;
1201 Format const * getFormat(std::string const & prettyname)
1203 Formats::const_iterator it = formats.begin();
1204 Formats::const_iterator const end = formats.end();
1205 it = std::find_if(it, end, SamePrettyName(prettyname));
1206 return it == end ? 0 : &*it;
1212 void PrefCopiers::switch_copierLB(int row)
1218 std::string const browser_text =
1219 fromqstr(AllCopiersLW->currentItem()->text());
1220 Format const * fmt = getFormat(browser_text);
1224 QString const gui_name = toqstr(fmt->prettyname());
1225 QString const command = toqstr(form_->movers().command(fmt->name()));
1228 int const combo_size = copierFormatCO->count();
1229 for (int i = 0; i < combo_size; ++i) {
1230 QString const text = copierFormatCO->itemText(i);
1231 if (text == gui_name) {
1232 copierFormatCO->setCurrentIndex(i);
1233 copierED->setText(command);
1241 void PrefCopiers::switch_copierCO(int row)
1246 std::string const combo_text =
1247 fromqstr(copierFormatCO->currentText());
1248 Format const * fmt = getFormat(combo_text);
1252 QString const command = toqstr(form_->movers().command(fmt->name()));
1253 copierED->setText(command);
1255 QListWidgetItem * const index = AllCopiersLW->currentItem();
1257 AllCopiersLW->setItemSelected(index, false);
1259 QString const gui_name = toqstr(fmt->prettyname());
1260 int const browser_size = AllCopiersLW->count();
1261 for (int i = 0; i < browser_size; ++i) {
1262 QString const text = AllCopiersLW->item(i)->text();
1263 if (text == gui_name) {
1264 QListWidgetItem * item = AllCopiersLW->item(i);
1265 AllCopiersLW->setItemSelected(item, true);
1272 void PrefCopiers::copiers_changed()
1278 void PrefCopiers::updateButtons()
1280 QString selected = copierFormatCO->currentText();
1283 for (int i = 0; i < AllCopiersLW->count(); ++i) {
1284 if (AllCopiersLW->item(i)->text() == selected)
1288 bool const valid = !copierED->text().isEmpty();
1290 Format const * fmt = getFormat(fromqstr(selected));
1291 string const old_command = form_->movers().command(fmt->name());
1292 string const new_command(fromqstr(copierED->text()));
1294 bool modified = (old_command != new_command);
1296 copierModifyPB->setEnabled(valid && known && modified);
1297 copierNewPB->setEnabled(valid && !known);
1298 copierRemovePB->setEnabled(known);
1302 void PrefCopiers::new_copier()
1304 std::string const combo_text =
1305 fromqstr(copierFormatCO->currentText());
1306 Format const * fmt = getFormat(combo_text);
1310 string const command = fromqstr(copierED->text());
1311 if (command.empty())
1314 form_->movers().set(fmt->name(), command);
1317 int const last = AllCopiersLW->count() - 1;
1318 AllCopiersLW->setCurrentRow(last);
1324 void PrefCopiers::modify_copier()
1326 std::string const combo_text =
1327 fromqstr(copierFormatCO->currentText());
1328 Format const * fmt = getFormat(combo_text);
1332 string const command = fromqstr(copierED->text());
1333 form_->movers().set(fmt->name(), command);
1340 void PrefCopiers::remove_copier()
1342 std::string const combo_text =
1343 fromqstr(copierFormatCO->currentText());
1344 Format const * fmt = getFormat(combo_text);
1348 string const & fmt_name = fmt->name();
1349 form_->movers().set(fmt_name, string());
1357 /////////////////////////////////////////////////////////////////////
1361 /////////////////////////////////////////////////////////////////////
1363 PrefFileformats::PrefFileformats(QPrefs * form, QWidget * parent)
1364 : PrefModule(docstring(), _("File formats"), form, parent)
1368 connect(formatNewPB, SIGNAL(clicked()),
1369 this, SLOT(new_format()));
1370 connect(formatRemovePB, SIGNAL(clicked()),
1371 this, SLOT(remove_format()));
1372 connect(formatModifyPB, SIGNAL(clicked()),
1373 this, SLOT(modify_format()));
1374 connect(formatsLW, SIGNAL(currentRowChanged(int)),
1375 this, SLOT(switch_format(int)));
1376 connect(formatED, SIGNAL(textChanged(const QString&)),
1377 this, SLOT(fileformat_changed()));
1378 connect(guiNameED, SIGNAL(textChanged(const QString&)),
1379 this, SLOT(fileformat_changed()));
1380 connect(shortcutED, SIGNAL(textChanged(const QString&)),
1381 this, SLOT(fileformat_changed()));
1382 connect(extensionED, SIGNAL(textChanged(const QString&)),
1383 this, SLOT(fileformat_changed()));
1384 connect(viewerED, SIGNAL(textChanged(const QString&)),
1385 this, SLOT(fileformat_changed()));
1386 connect(editorED, SIGNAL(textChanged(const QString&)),
1387 this, SLOT(fileformat_changed()));
1388 connect(documentCB, SIGNAL(clicked()),
1389 this, SLOT(fileformat_changed()));
1390 connect(vectorCB, SIGNAL(clicked()),
1391 this, SLOT(fileformat_changed()));
1392 connect(formatNewPB, SIGNAL(clicked()),
1393 this, SIGNAL(changed()));
1394 connect(formatRemovePB, SIGNAL(clicked()),
1395 this, SIGNAL(changed()));
1396 connect(formatModifyPB, SIGNAL(clicked()),
1397 this, SIGNAL(changed()));
1401 void PrefFileformats::apply(LyXRC & /*rc*/) const
1406 void PrefFileformats::update(LyXRC const & /*rc*/)
1412 void PrefFileformats::update()
1414 // save current selection
1415 QString current = guiNameED->text();
1417 // update listwidget with formats
1418 formatsLW->blockSignals(true);
1420 Formats::const_iterator cit = form_->formats().begin();
1421 Formats::const_iterator end = form_->formats().end();
1422 for (; cit != end; ++cit) {
1423 new QListWidgetItem(toqstr(cit->prettyname()),
1425 form_->formats().getNumber(cit->name()) );
1427 formatsLW->sortItems(Qt::AscendingOrder);
1428 formatsLW->blockSignals(false);
1430 // restore selection
1431 if (!current.isEmpty()) {
1432 QList<QListWidgetItem *> item = formatsLW->findItems(current, Qt::MatchExactly);
1434 formatsLW->setCurrentItem(item.at(0));
1436 // select first element if restoring failed
1437 if (formatsLW->currentRow() == -1)
1438 formatsLW->setCurrentRow(0);
1442 void PrefFileformats::switch_format(int nr)
1444 int const ftype = formatsLW->item(nr)->type();
1445 Format const f = form_->formats().get(ftype);
1447 formatED->setText(toqstr(f.name()));
1448 guiNameED->setText(toqstr(f.prettyname()));
1449 extensionED->setText(toqstr(f.extension()));
1450 shortcutED->setText(toqstr(f.shortcut()));
1451 viewerED->setText(toqstr(f.viewer()));
1452 editorED->setText(toqstr(f.editor()));
1453 documentCB->setChecked((f.documentFormat()));
1454 vectorCB->setChecked((f.vectorFormat()));
1460 void PrefFileformats::fileformat_changed()
1466 void PrefFileformats::updateButtons()
1468 QString const format = formatED->text();
1469 QString const gui_name = guiNameED->text();
1470 int const sel = form_->formats().getNumber(fromqstr(format));
1471 bool gui_name_known = false;
1473 for (int i = 0; i < formatsLW->count(); ++i) {
1474 if (formatsLW->item(i)->text() == gui_name) {
1475 gui_name_known = true;
1476 where = formatsLW->item(i)->type();
1480 // assure that a gui name cannot be chosen twice
1481 bool const known_otherwise = gui_name_known && (where != sel);
1483 bool const known = !(sel < 0);
1484 bool const valid = (!formatED->text().isEmpty()
1485 && !guiNameED->text().isEmpty());
1487 int const ftype = formatsLW->currentItem()->type();
1488 Format const & f(form_->formats().get(ftype));
1489 string const old_pretty(f.prettyname());
1490 string const old_shortcut(f.shortcut());
1491 string const old_extension(f.extension());
1492 string const old_viewer(f.viewer());
1493 string const old_editor(f.editor());
1494 bool const old_document(f.documentFormat());
1495 bool const old_vector(f.vectorFormat());
1497 string const new_pretty(fromqstr(gui_name));
1498 string const new_shortcut(fromqstr(shortcutED->text()));
1499 string const new_extension(fromqstr(extensionED->text()));
1500 string const new_viewer(fromqstr(viewerED->text()));
1501 string const new_editor(fromqstr(editorED->text()));
1502 bool const new_document(documentCB->isChecked());
1503 bool const new_vector(vectorCB->isChecked());
1505 bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
1506 || (old_extension != new_extension) || (old_viewer != new_viewer)
1507 || old_editor != new_editor || old_document != new_document
1508 || old_vector != new_vector);
1510 formatModifyPB->setEnabled(valid && known && modified && !known_otherwise);
1511 formatNewPB->setEnabled(valid && !known && !gui_name_known);
1512 formatRemovePB->setEnabled(known);
1516 void PrefFileformats::new_format()
1518 string const name = fromqstr(formatED->text());
1519 string const prettyname = fromqstr(guiNameED->text());
1520 string const extension = fromqstr(extensionED->text());
1521 string const shortcut = fromqstr(shortcutED->text());
1522 string const viewer = fromqstr(viewerED->text());
1523 string const editor = fromqstr(editorED->text());
1524 int flags = Format::none;
1525 if (documentCB->isChecked())
1526 flags |= Format::document;
1527 if (vectorCB->isChecked())
1528 flags |= Format::vector;
1530 form_->formats().add(name, extension, prettyname, shortcut, viewer,
1532 form_->formats().sort();
1533 form_->converters().update(form_->formats());
1541 void PrefFileformats::modify_format()
1543 int const current_item = formatsLW->currentItem()->type();
1544 Format const & oldformat = form_->formats().get(current_item);
1545 form_->formats().erase(oldformat.name());
1551 void PrefFileformats::remove_format()
1553 int const nr = formatsLW->currentItem()->type();
1554 string const current_text = form_->formats().get(nr).name();
1555 if (form_->converters().formatIsUsed(current_text)) {
1556 Alert::error(_("Format in use"),
1557 _("Cannot remove a Format used by a Converter. "
1558 "Remove the converter first."));
1562 form_->formats().erase(current_text);
1563 form_->converters().update(form_->formats());
1571 /////////////////////////////////////////////////////////////////////
1575 /////////////////////////////////////////////////////////////////////
1577 PrefLanguage::PrefLanguage(QWidget * parent)
1578 : PrefModule(_(LanguageSettings), _("Language"), 0, parent)
1582 connect(rtlCB, SIGNAL(clicked()),
1583 this, SIGNAL(changed()));
1584 connect(markForeignCB, SIGNAL(clicked()),
1585 this, SIGNAL(changed()));
1586 connect(autoBeginCB, SIGNAL(clicked()),
1587 this, SIGNAL(changed()));
1588 connect(autoEndCB, SIGNAL(clicked()),
1589 this, SIGNAL(changed()));
1590 connect(useBabelCB, SIGNAL(clicked()),
1591 this, SIGNAL(changed()));
1592 connect(globalCB, SIGNAL(clicked()),
1593 this, SIGNAL(changed()));
1594 connect(languagePackageED, SIGNAL(textChanged(const QString&)),
1595 this, SIGNAL(changed()));
1596 connect(startCommandED, SIGNAL(textChanged(const QString&)),
1597 this, SIGNAL(changed()));
1598 connect(endCommandED, SIGNAL(textChanged(const QString&)),
1599 this, SIGNAL(changed()));
1600 connect(defaultLanguageCO, SIGNAL(activated(int)),
1601 this, SIGNAL(changed()));
1603 defaultLanguageCO->clear();
1605 // store the lang identifiers for later
1606 std::vector<LanguagePair> const langs = frontend::getLanguageData(false);
1607 lang_ = getSecond(langs);
1609 std::vector<LanguagePair>::const_iterator lit = langs.begin();
1610 std::vector<LanguagePair>::const_iterator lend = langs.end();
1611 for (; lit != lend; ++lit) {
1612 defaultLanguageCO->addItem(toqstr(lit->first));
1617 void PrefLanguage::apply(LyXRC & rc) const
1619 // FIXME: remove rtl_support bool
1620 rc.rtl_support = rtlCB->isChecked();
1621 rc.mark_foreign_language = markForeignCB->isChecked();
1622 rc.language_auto_begin = autoBeginCB->isChecked();
1623 rc.language_auto_end = autoEndCB->isChecked();
1624 rc.language_use_babel = useBabelCB->isChecked();
1625 rc.language_global_options = globalCB->isChecked();
1626 rc.language_package = fromqstr(languagePackageED->text());
1627 rc.language_command_begin = fromqstr(startCommandED->text());
1628 rc.language_command_end = fromqstr(endCommandED->text());
1629 rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1633 void PrefLanguage::update(LyXRC const & rc)
1635 // FIXME: remove rtl_support bool
1636 rtlCB->setChecked(rc.rtl_support);
1637 markForeignCB->setChecked(rc.mark_foreign_language);
1638 autoBeginCB->setChecked(rc.language_auto_begin);
1639 autoEndCB->setChecked(rc.language_auto_end);
1640 useBabelCB->setChecked(rc.language_use_babel);
1641 globalCB->setChecked(rc.language_global_options);
1642 languagePackageED->setText(toqstr(rc.language_package));
1643 startCommandED->setText(toqstr(rc.language_command_begin));
1644 endCommandED->setText(toqstr(rc.language_command_end));
1646 int const pos = int(findPos_helper(lang_, rc.default_language));
1647 defaultLanguageCO->setCurrentIndex(pos);
1651 /////////////////////////////////////////////////////////////////////
1655 /////////////////////////////////////////////////////////////////////
1657 PrefPrinter::PrefPrinter(QWidget * parent)
1658 : PrefModule(_(Outputs), _("Printer"), 0, parent)
1662 connect(printerAdaptCB, SIGNAL(clicked()),
1663 this, SIGNAL(changed()));
1664 connect(printerCommandED, SIGNAL(textChanged(const QString&)),
1665 this, SIGNAL(changed()));
1666 connect(printerNameED, SIGNAL(textChanged(const QString&)),
1667 this, SIGNAL(changed()));
1668 connect(printerPageRangeED, SIGNAL(textChanged(const QString&)),
1669 this, SIGNAL(changed()));
1670 connect(printerCopiesED, SIGNAL(textChanged(const QString&)),
1671 this, SIGNAL(changed()));
1672 connect(printerReverseED, SIGNAL(textChanged(const QString&)),
1673 this, SIGNAL(changed()));
1674 connect(printerToPrinterED, SIGNAL(textChanged(const QString&)),
1675 this, SIGNAL(changed()));
1676 connect(printerExtensionED, SIGNAL(textChanged(const QString&)),
1677 this, SIGNAL(changed()));
1678 connect(printerSpoolCommandED, SIGNAL(textChanged(const QString&)),
1679 this, SIGNAL(changed()));
1680 connect(printerPaperTypeED, SIGNAL(textChanged(const QString&)),
1681 this, SIGNAL(changed()));
1682 connect(printerEvenED, SIGNAL(textChanged(const QString&)),
1683 this, SIGNAL(changed()));
1684 connect(printerOddED, SIGNAL(textChanged(const QString&)),
1685 this, SIGNAL(changed()));
1686 connect(printerCollatedED, SIGNAL(textChanged(const QString&)),
1687 this, SIGNAL(changed()));
1688 connect(printerLandscapeED, SIGNAL(textChanged(const QString&)),
1689 this, SIGNAL(changed()));
1690 connect(printerToFileED, SIGNAL(textChanged(const QString&)),
1691 this, SIGNAL(changed()));
1692 connect(printerExtraED, SIGNAL(textChanged(const QString&)),
1693 this, SIGNAL(changed()));
1694 connect(printerSpoolPrefixED, SIGNAL(textChanged(const QString&)),
1695 this, SIGNAL(changed()));
1696 connect(printerPaperSizeED, SIGNAL(textChanged(const QString&)),
1697 this, SIGNAL(changed()));
1701 void PrefPrinter::apply(LyXRC & rc) const
1703 rc.print_adapt_output = printerAdaptCB->isChecked();
1704 rc.print_command = fromqstr(printerCommandED->text());
1705 rc.printer = fromqstr(printerNameED->text());
1707 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1708 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1709 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1710 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1711 rc.print_file_extension = fromqstr(printerExtensionED->text());
1712 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1713 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1714 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1715 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1716 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1717 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1718 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1719 rc.print_extra_options = fromqstr(printerExtraED->text());
1720 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1721 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1725 void PrefPrinter::update(LyXRC const & rc)
1727 printerAdaptCB->setChecked(rc.print_adapt_output);
1728 printerCommandED->setText(toqstr(rc.print_command));
1729 printerNameED->setText(toqstr(rc.printer));
1731 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1732 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1733 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1734 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1735 printerExtensionED->setText(toqstr(rc.print_file_extension));
1736 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1737 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1738 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1739 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1740 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1741 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1742 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1743 printerExtraED->setText(toqstr(rc.print_extra_options));
1744 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1745 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1749 /////////////////////////////////////////////////////////////////////
1751 // PrefUserInterface
1753 /////////////////////////////////////////////////////////////////////
1755 PrefUserInterface::PrefUserInterface(QPrefs * form, QWidget * parent)
1756 : PrefModule(_(LookAndFeel), _("User interface"), form, parent)
1760 connect(autoSaveCB, SIGNAL(toggled(bool)),
1761 autoSaveLA, SLOT(setEnabled(bool)));
1762 connect(autoSaveCB, SIGNAL(toggled(bool)),
1763 autoSaveSB, SLOT(setEnabled(bool)));
1764 connect(autoSaveCB, SIGNAL(toggled(bool)),
1765 TextLabel1, SLOT(setEnabled(bool)));
1766 connect(uiFilePB, SIGNAL(clicked()),
1767 this, SLOT(select_ui()));
1768 connect(bindFilePB, SIGNAL(clicked()),
1769 this, SLOT(select_bind()));
1770 connect(uiFileED, SIGNAL(textChanged(const QString &)),
1771 this, SIGNAL(changed()));
1772 connect(bindFileED, SIGNAL(textChanged(const QString &)),
1773 this, SIGNAL(changed()));
1774 connect(restoreCursorCB, SIGNAL(clicked()),
1775 this, SIGNAL(changed()));
1776 connect(loadSessionCB, SIGNAL(clicked()),
1777 this, SIGNAL(changed()));
1778 connect(loadWindowSizeCB, SIGNAL(clicked()),
1779 this, SIGNAL(changed()));
1780 connect(loadWindowLocationCB, SIGNAL(clicked()),
1781 this, SIGNAL(changed()));
1782 connect(windowWidthSB, SIGNAL(valueChanged(int)),
1783 this, SIGNAL(changed()));
1784 connect(windowHeightSB, SIGNAL(valueChanged(int)),
1785 this, SIGNAL(changed()));
1786 connect(cursorFollowsCB, SIGNAL(clicked()),
1787 this, SIGNAL(changed()));
1788 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1789 this, SIGNAL(changed()));
1790 connect(autoSaveCB, SIGNAL(clicked()),
1791 this, SIGNAL(changed()));
1792 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1793 this, SIGNAL(changed()));
1794 lastfilesSB->setMaximum(maxlastfiles);
1798 void PrefUserInterface::apply(LyXRC & rc) const
1800 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1801 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1802 rc.use_lastfilepos = restoreCursorCB->isChecked();
1803 rc.load_session = loadSessionCB->isChecked();
1804 if (loadWindowSizeCB->isChecked()) {
1805 rc.geometry_width = 0;
1806 rc.geometry_height = 0;
1808 rc.geometry_width = windowWidthSB->value();
1809 rc.geometry_height = windowHeightSB->value();
1811 rc.geometry_xysaved = loadWindowLocationCB->isChecked();
1812 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1813 rc.autosave = autoSaveSB->value() * 60;
1814 rc.make_backup = autoSaveCB->isChecked();
1815 rc.num_lastfiles = lastfilesSB->value();
1819 void PrefUserInterface::update(LyXRC const & rc)
1821 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1822 bindFileED->setText(toqstr(external_path(rc.bind_file)));
1823 restoreCursorCB->setChecked(rc.use_lastfilepos);
1824 loadSessionCB->setChecked(rc.load_session);
1825 bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
1826 loadWindowSizeCB->setChecked(loadWindowSize);
1827 if (!loadWindowSize) {
1828 windowWidthSB->setValue(rc.geometry_width);
1829 windowHeightSB->setValue(rc.geometry_height);
1831 loadWindowLocationCB->setChecked(rc.geometry_xysaved);
1832 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1833 // convert to minutes
1834 int mins(rc.autosave / 60);
1835 if (rc.autosave && !mins)
1837 autoSaveSB->setValue(mins);
1838 autoSaveCB->setChecked(rc.make_backup);
1839 lastfilesSB->setValue(rc.num_lastfiles);
1844 void PrefUserInterface::select_ui()
1846 docstring const name =
1847 from_utf8(internal_path(fromqstr(uiFileED->text())));
1848 docstring file(form_->controller().browseUI(name));
1850 uiFileED->setText(toqstr(file));
1854 void PrefUserInterface::select_bind()
1856 docstring const name =
1857 from_utf8(internal_path(fromqstr(bindFileED->text())));
1858 docstring file(form_->controller().browsebind(name));
1860 bindFileED->setText(toqstr(file));
1864 void PrefUserInterface::on_loadWindowSizeCB_toggled(bool loadwindowsize)
1866 windowWidthLA->setDisabled(loadwindowsize);
1867 windowHeightLA->setDisabled(loadwindowsize);
1868 windowWidthSB->setDisabled(loadwindowsize);
1869 windowHeightSB->setDisabled(loadwindowsize);
1873 PrefIdentity::PrefIdentity(QWidget * parent)
1874 : PrefModule(docstring(), _("Identity"), 0, parent)
1878 connect(nameED, SIGNAL(textChanged(const QString&)),
1879 this, SIGNAL(changed()));
1880 connect(emailED, SIGNAL(textChanged(const QString&)),
1881 this, SIGNAL(changed()));
1885 void PrefIdentity::apply(LyXRC & rc) const
1887 rc.user_name = fromqstr(nameED->text());
1888 rc.user_email = fromqstr(emailED->text());
1892 void PrefIdentity::update(LyXRC const & rc)
1894 nameED->setText(toqstr(rc.user_name));
1895 emailED->setText(toqstr(rc.user_email));
1900 /////////////////////////////////////////////////////////////////////
1904 /////////////////////////////////////////////////////////////////////
1906 QPrefsDialog::QPrefsDialog(QPrefs * form)
1910 QDialog::setModal(false);
1912 connect(savePB, SIGNAL(clicked()), form, SLOT(slotOK()));
1913 connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
1914 connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
1915 connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore()));
1917 add(new PrefUserInterface(form_));
1918 add(new PrefScreenFonts(form_));
1919 add(new PrefColors(form_));
1920 add(new PrefDisplay);
1921 add(new PrefKeyboard(form_));
1923 add(new PrefPaths(form_));
1925 add(new PrefIdentity);
1927 add(new PrefLanguage);
1928 add(new PrefSpellchecker(form_));
1930 add(new PrefPrinter);
1932 add(new PrefPlaintext);
1933 add(new PrefLatex(form_));
1935 #if defined(__CYGWIN__) || defined(_WIN32)
1936 add(new PrefCygwinPath);
1940 PrefConverters * converters = new PrefConverters(form_);
1941 PrefFileformats * formats = new PrefFileformats(form_);
1942 connect(formats, SIGNAL(formatsChanged()),
1943 converters, SLOT(updateGui()));
1947 add(new PrefCopiers(form_));
1950 prefsPS->setCurrentPanel(_("User interface"));
1951 // FIXME: hack to work around resizing bug in Qt >= 4.2
1952 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1953 #if QT_VERSION >= 0x040200
1954 prefsPS->updateGeometry();
1957 form_->bcview().setOK(savePB);
1958 form_->bcview().setApply(applyPB);
1959 form_->bcview().setCancel(closePB);
1960 form_->bcview().setRestore(restorePB);
1964 void QPrefsDialog::add(PrefModule * module)
1966 BOOST_ASSERT(module);
1968 // if (module->category().empty())
1969 // prefsPS->addPanel(module, module->title());
1971 prefsPS->addPanel(module, module->title(), module->category());
1973 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
1975 modules_.push_back(module);
1978 void QPrefsDialog::closeEvent(QCloseEvent * e)
1980 form_->slotWMHide();
1985 void QPrefsDialog::change_adaptor()
1991 void QPrefsDialog::apply(LyXRC & rc) const
1993 size_t end = modules_.size();
1994 for (size_t i = 0; i != end; ++i)
1995 modules_[i]->apply(rc);
1999 void QPrefsDialog::updateRc(LyXRC const & rc)
2001 size_t const end = modules_.size();
2002 for (size_t i = 0; i != end; ++i)
2003 modules_[i]->update(rc);
2007 /////////////////////////////////////////////////////////////////////
2011 /////////////////////////////////////////////////////////////////////
2013 typedef QController<ControlPrefs, QView<QPrefsDialog> > PrefsBase;
2015 QPrefs::QPrefs(Dialog & parent)
2016 : PrefsBase(parent, _("Preferences"))
2020 Converters & QPrefs::converters()
2022 return controller().converters();
2025 Formats & QPrefs::formats()
2027 return controller().formats();
2030 Movers & QPrefs::movers()
2032 return controller().movers();
2035 void QPrefs::build_dialog()
2037 dialog_.reset(new QPrefsDialog(this));
2040 void QPrefs::apply()
2042 dialog_->apply(controller().rc());
2045 void QPrefs::update_contents()
2047 dialog_->updateRc(controller().rc());
2050 } // namespace frontend
2053 #include "QPrefs_moc.cpp"