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[LyXFont::SIZE_TINY] = fromqstr(screenTinyED->text());
441 rc.font_sizes[LyXFont::SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
442 rc.font_sizes[LyXFont::SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
443 rc.font_sizes[LyXFont::SIZE_SMALL] = fromqstr(screenSmallED->text());
444 rc.font_sizes[LyXFont::SIZE_NORMAL] = fromqstr(screenNormalED->text());
445 rc.font_sizes[LyXFont::SIZE_LARGE] = fromqstr(screenLargeED->text());
446 rc.font_sizes[LyXFont::SIZE_LARGER] = fromqstr(screenLargerED->text());
447 rc.font_sizes[LyXFont::SIZE_LARGEST] = fromqstr(screenLargestED->text());
448 rc.font_sizes[LyXFont::SIZE_HUGE] = fromqstr(screenHugeED->text());
449 rc.font_sizes[LyXFont::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[LyXFont::SIZE_TINY]));
477 screenSmallestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SCRIPT]));
478 screenSmallerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_FOOTNOTE]));
479 screenSmallED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SMALL]));
480 screenNormalED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_NORMAL]));
481 screenLargeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGE]));
482 screenLargerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGER]));
483 screenLargestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGEST]));
484 screenHugeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_HUGE]));
485 screenHugerED->setText(toqstr(rc.font_sizes[LyXFont::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 for (int i = 0; i < Color::ignore; ++i) {
521 Color::color lc = static_cast<Color::color>(i);
522 if (lc == Color::none
523 || lc == Color::black
524 || lc == Color::white
526 || lc == Color::green
529 || lc == Color::magenta
530 || lc == Color::yellow
531 || lc == Color::inherit
532 || lc == Color::ignore) continue;
534 lcolors_.push_back(lc);
535 QColor color = QColor(guiApp->colorCache().get(lc));
536 curcolors_.push_back(color.name());
537 QPixmap coloritem(32, 32);
538 coloritem.fill(color);
539 // This is not a memory leak:
540 /*QListWidgetItem * newItem =*/ new QListWidgetItem(QIcon(coloritem),
541 toqstr(lcolor.getGUIName(lc)), lyxObjectsLW);
543 newcolors_ = curcolors_;
544 // End initialization
546 connect(colorChangePB, SIGNAL(clicked()),
547 this, SLOT(change_color()));
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]));
559 // HACK The following line is needed because the values are not
560 // re-initialized in ControlPrefs::initialiseParams but are only
561 // initialized in the constructor. But the constructor is only called
562 // once, when the dialog if first created, and is not called again when
563 // Tools > Preferences is selected a second time: It's just called up
564 // from memory. [See QDialogView::show(): if (!form) { build(); }.]
565 curcolors_ = newcolors_;
569 // FIXME The fact that this method is empty is also a symptom of the
571 void PrefColors::update(LyXRC const & /*rc*/)
575 void PrefColors::change_color()
577 int const row = lyxObjectsLW->currentRow();
578 QString color = newcolors_[row];
579 QColor c(QColorDialog::getColor(QColor(color), qApp->focusWidget()));
581 if (c.name() != color) {
582 newcolors_[row] = c.name();
583 QPixmap coloritem(32, 32);
585 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
592 /////////////////////////////////////////////////////////////////////
596 /////////////////////////////////////////////////////////////////////
598 PrefCygwinPath::PrefCygwinPath(QWidget * parent)
599 : PrefModule(_(Outputs), _("Paths"), 0, parent)
602 connect(pathCB, SIGNAL(clicked()), this, SIGNAL(changed()));
606 void PrefCygwinPath::apply(LyXRC & rc) const
608 rc.windows_style_tex_paths = pathCB->isChecked();
612 void PrefCygwinPath::update(LyXRC const & rc)
614 pathCB->setChecked(rc.windows_style_tex_paths);
618 /////////////////////////////////////////////////////////////////////
622 /////////////////////////////////////////////////////////////////////
624 PrefDisplay::PrefDisplay(QWidget * parent)
625 : PrefModule(_(LookAndFeel), _("Graphics"), 0, parent)
628 connect(instantPreviewCO, SIGNAL(activated(int)),
629 this, SIGNAL(changed()));
630 connect(displayGraphicsCO, SIGNAL(activated(int)),
631 this, SIGNAL(changed()));
635 void PrefDisplay::apply(LyXRC & rc) const
637 switch (instantPreviewCO->currentIndex()) {
638 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
639 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
640 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
643 lyx::graphics::DisplayType dtype;
644 switch (displayGraphicsCO->currentIndex()) {
645 case 3: dtype = lyx::graphics::NoDisplay; break;
646 case 2: dtype = lyx::graphics::ColorDisplay; break;
647 case 1: dtype = lyx::graphics::GrayscaleDisplay; break;
648 case 0: dtype = lyx::graphics::MonochromeDisplay; break;
649 default: dtype = lyx::graphics::GrayscaleDisplay;
651 rc.display_graphics = dtype;
654 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
657 if (old_value != rc.display_graphics) {
658 lyx::graphics::GCache & gc = lyx::graphics::GCache::get();
665 void PrefDisplay::update(LyXRC const & rc)
667 switch (rc.preview) {
668 case LyXRC::PREVIEW_OFF:
669 instantPreviewCO->setCurrentIndex(0);
671 case LyXRC::PREVIEW_NO_MATH :
672 instantPreviewCO->setCurrentIndex(1);
674 case LyXRC::PREVIEW_ON :
675 instantPreviewCO->setCurrentIndex(2);
680 switch (rc.display_graphics) {
681 case lyx::graphics::NoDisplay: item = 3; break;
682 case lyx::graphics::ColorDisplay: item = 2; break;
683 case lyx::graphics::GrayscaleDisplay: item = 1; break;
684 case lyx::graphics::MonochromeDisplay: item = 0; break;
687 displayGraphicsCO->setCurrentIndex(item);
691 /////////////////////////////////////////////////////////////////////
695 /////////////////////////////////////////////////////////////////////
697 PrefPaths::PrefPaths(QPrefs * form, QWidget * parent)
698 : PrefModule(docstring(), _("Paths"), form, parent)
701 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
702 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
703 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
704 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
705 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
706 connect(workingDirED, SIGNAL(textChanged(const QString&)),
707 this, SIGNAL(changed()));
708 connect(templateDirED, SIGNAL(textChanged(const QString&)),
709 this, SIGNAL(changed()));
710 connect(backupDirED, SIGNAL(textChanged(const QString&)),
711 this, SIGNAL(changed()));
712 connect(tempDirED, SIGNAL(textChanged(const QString&)),
713 this, SIGNAL(changed()));
714 connect(lyxserverDirED, SIGNAL(textChanged(const QString&)),
715 this, SIGNAL(changed()));
716 connect(pathPrefixED, SIGNAL(textChanged(const QString&)),
717 this, SIGNAL(changed()));
721 void PrefPaths::apply(LyXRC & rc) const
723 rc.document_path = internal_path(fromqstr(workingDirED->text()));
724 rc.template_path = internal_path(fromqstr(templateDirED->text()));
725 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
726 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
727 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
728 // FIXME: should be a checkbox only
729 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
733 void PrefPaths::update(LyXRC const & rc)
735 workingDirED->setText(toqstr(external_path(rc.document_path)));
736 templateDirED->setText(toqstr(external_path(rc.template_path)));
737 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
738 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
739 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
740 // FIXME: should be a checkbox only
741 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
745 void PrefPaths::select_templatedir()
747 docstring file(form_->controller().browsedir(
748 from_utf8(internal_path(fromqstr(templateDirED->text()))),
749 _("Select a document templates directory")));
751 templateDirED->setText(toqstr(file));
755 void PrefPaths::select_tempdir()
757 docstring file(form_->controller().browsedir(
758 from_utf8(internal_path(fromqstr(tempDirED->text()))),
759 _("Select a temporary directory")));
761 tempDirED->setText(toqstr(file));
765 void PrefPaths::select_backupdir()
767 docstring file(form_->controller().browsedir(
768 from_utf8(internal_path(fromqstr(backupDirED->text()))),
769 _("Select a backups directory")));
771 backupDirED->setText(toqstr(file));
775 void PrefPaths::select_workingdir()
777 docstring file(form_->controller().browsedir(
778 from_utf8(internal_path(fromqstr(workingDirED->text()))),
779 _("Select a document directory")));
781 workingDirED->setText(toqstr(file));
785 void PrefPaths::select_lyxpipe()
787 docstring file(form_->controller().browse(
788 from_utf8(internal_path(fromqstr(lyxserverDirED->text()))),
789 _("Give a filename for the LyX server pipe")));
791 lyxserverDirED->setText(toqstr(file));
795 /////////////////////////////////////////////////////////////////////
799 /////////////////////////////////////////////////////////////////////
801 PrefSpellchecker::PrefSpellchecker(QPrefs * form, QWidget * parent)
802 : PrefModule(_(LanguageSettings), _("Spellchecker"), form, parent)
806 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
807 #if defined (USE_ISPELL)
808 connect(spellCommandCO, SIGNAL(activated(int)),
809 this, SIGNAL(changed()));
811 spellCommandCO->setEnabled(false);
813 connect(altLanguageED, SIGNAL(textChanged(const QString&)),
814 this, SIGNAL(changed()));
815 connect(escapeCharactersED, SIGNAL(textChanged(const QString&)),
816 this, SIGNAL(changed()));
817 connect(persDictionaryED, SIGNAL(textChanged(const QString&)),
818 this, SIGNAL(changed()));
819 connect(compoundWordCB, SIGNAL(clicked()),
820 this, SIGNAL(changed()));
821 connect(inputEncodingCB, SIGNAL(clicked()),
822 this, SIGNAL(changed()));
824 spellCommandCO->addItem(qt_("ispell"));
825 spellCommandCO->addItem(qt_("aspell"));
826 spellCommandCO->addItem(qt_("hspell"));
828 spellCommandCO->addItem(qt_("pspell (library)"));
831 spellCommandCO->addItem(qt_("aspell (library)"));
837 void PrefSpellchecker::apply(LyXRC & rc) const
839 switch (spellCommandCO->currentIndex()) {
843 rc.use_spell_lib = false;
844 rc.isp_command = fromqstr(spellCommandCO->currentText());
847 rc.use_spell_lib = true;
851 // FIXME: remove isp_use_alt_lang
852 rc.isp_alt_lang = fromqstr(altLanguageED->text());
853 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
854 // FIXME: remove isp_use_esc_chars
855 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
856 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
857 // FIXME: remove isp_use_pers_dict
858 rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
859 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
860 rc.isp_accept_compound = compoundWordCB->isChecked();
861 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
865 void PrefSpellchecker::update(LyXRC const & rc)
867 spellCommandCO->setCurrentIndex(0);
869 if (rc.isp_command == "ispell") {
870 spellCommandCO->setCurrentIndex(0);
871 } else if (rc.isp_command == "aspell") {
872 spellCommandCO->setCurrentIndex(1);
873 } else if (rc.isp_command == "hspell") {
874 spellCommandCO->setCurrentIndex(2);
877 if (rc.use_spell_lib) {
878 #if defined(USE_ASPELL) || defined(USE_PSPELL)
879 spellCommandCO->setCurrentIndex(3);
883 // FIXME: remove isp_use_alt_lang
884 altLanguageED->setText(toqstr(rc.isp_alt_lang));
885 // FIXME: remove isp_use_esc_chars
886 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
887 // FIXME: remove isp_use_pers_dict
888 persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
889 compoundWordCB->setChecked(rc.isp_accept_compound);
890 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
894 void PrefSpellchecker::select_dict()
896 docstring file(form_->controller().browsedict(
897 from_utf8(internal_path(fromqstr(persDictionaryED->text())))));
899 persDictionaryED->setText(toqstr(file));
904 /////////////////////////////////////////////////////////////////////
908 /////////////////////////////////////////////////////////////////////
911 PrefConverters::PrefConverters(QPrefs * form, QWidget * parent)
912 : PrefModule(docstring(), _("Converters"), form, parent)
916 connect(converterNewPB, SIGNAL(clicked()),
917 this, SLOT(update_converter()));
918 connect(converterRemovePB, SIGNAL(clicked()),
919 this, SLOT(remove_converter()));
920 connect(converterModifyPB, SIGNAL(clicked()),
921 this, SLOT(update_converter()));
922 connect(convertersLW, SIGNAL(currentRowChanged(int)),
923 this, SLOT(switch_converter()));
924 connect(converterFromCO, SIGNAL(activated(const QString&)),
925 this, SLOT(converter_changed()));
926 connect(converterToCO, SIGNAL(activated(const QString&)),
927 this, SLOT(converter_changed()));
928 connect(converterED, SIGNAL(textChanged(const QString&)),
929 this, SLOT(converter_changed()));
930 connect(converterFlagED, SIGNAL(textChanged(const QString&)),
931 this, SLOT(converter_changed()));
932 connect(converterNewPB, SIGNAL(clicked()),
933 this, SIGNAL(changed()));
934 connect(converterRemovePB, SIGNAL(clicked()),
935 this, SIGNAL(changed()));
936 connect(converterModifyPB, SIGNAL(clicked()),
937 this, SIGNAL(changed()));
938 connect(maxAgeLE, SIGNAL(textChanged(const QString&)),
939 this, SIGNAL(changed()));
941 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
942 converterDefGB->setFocusProxy(convertersLW);
946 void PrefConverters::apply(LyXRC & rc) const
948 rc.use_converter_cache = cacheCB->isChecked();
949 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
953 void PrefConverters::update(LyXRC const & rc)
955 cacheCB->setChecked(rc.use_converter_cache);
957 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
958 maxAgeLE->setText(max_age);
963 void PrefConverters::updateGui()
965 // save current selection
966 QString current = converterFromCO->currentText()
967 + " -> " + converterToCO->currentText();
969 converterFromCO->clear();
970 converterToCO->clear();
972 Formats::const_iterator cit = form_->formats().begin();
973 Formats::const_iterator end = form_->formats().end();
974 for (; cit != end; ++cit) {
975 converterFromCO->addItem(toqstr(cit->prettyname()));
976 converterToCO->addItem(toqstr(cit->prettyname()));
979 // currentRowChanged(int) is also triggered when updating the listwidget
980 // block signals to avoid unnecessary calls to switch_converter()
981 convertersLW->blockSignals(true);
982 convertersLW->clear();
984 Converters::const_iterator ccit = form_->converters().begin();
985 Converters::const_iterator cend = form_->converters().end();
986 for (; ccit != cend; ++ccit) {
987 std::string const name =
988 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
989 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
990 new QListWidgetItem(toqstr(name), convertersLW, type);
992 convertersLW->sortItems(Qt::AscendingOrder);
993 convertersLW->blockSignals(false);
996 if (!current.isEmpty()) {
997 QList<QListWidgetItem *> const item =
998 convertersLW->findItems(current, Qt::MatchExactly);
1000 convertersLW->setCurrentItem(item.at(0));
1003 // select first element if restoring failed
1004 if (convertersLW->currentRow() == -1)
1005 convertersLW->setCurrentRow(0);
1011 void PrefConverters::switch_converter()
1013 int const cnr = convertersLW->currentItem()->type();
1014 Converter const & c(form_->converters().get(cnr));
1015 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1016 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1017 converterED->setText(toqstr(c.command));
1018 converterFlagED->setText(toqstr(c.flags));
1024 void PrefConverters::converter_changed()
1030 void PrefConverters::updateButtons()
1032 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1033 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1034 int const sel = form_->converters().getNumber(from.name(), to.name());
1035 bool const known = !(sel < 0);
1036 bool const valid = !(converterED->text().isEmpty()
1037 || from.name() == to.name());
1039 int const cnr = convertersLW->currentItem()->type();
1040 Converter const & c(form_->converters().get(cnr));
1041 string const old_command = c.command;
1042 string const old_flag = c.flags;
1043 string const new_command(fromqstr(converterED->text()));
1044 string const new_flag(fromqstr(converterFlagED->text()));
1046 bool modified = ((old_command != new_command) || (old_flag != new_flag));
1048 converterModifyPB->setEnabled(valid && known && modified);
1049 converterNewPB->setEnabled(valid && !known);
1050 converterRemovePB->setEnabled(known);
1052 maxAgeLE->setEnabled(cacheCB->isChecked());
1053 maxAgeLA->setEnabled(cacheCB->isChecked());
1058 // specify unique from/to or it doesn't appear. This is really bad UI
1059 // this is why we can use the same function for both new and modify
1060 void PrefConverters::update_converter()
1062 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1063 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1064 string const flags = fromqstr(converterFlagED->text());
1065 string const command = fromqstr(converterED->text());
1067 Converter const * old = form_->converters().getConverter(from.name(), to.name());
1068 form_->converters().add(from.name(), to.name(), command, flags);
1070 form_->converters().updateLast(form_->formats());
1077 void PrefConverters::remove_converter()
1079 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1080 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1081 form_->converters().erase(from.name(), to.name());
1087 void PrefConverters::on_cacheCB_stateChanged(int state)
1089 maxAgeLE->setEnabled(state == Qt::Checked);
1090 maxAgeLA->setEnabled(state == Qt::Checked);
1095 /////////////////////////////////////////////////////////////////////
1099 /////////////////////////////////////////////////////////////////////
1101 PrefCopiers::PrefCopiers(QPrefs * form, QWidget * parent)
1102 : PrefModule(docstring(), _("Copiers"), form, parent)
1106 connect(copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
1107 connect(copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
1108 connect(copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
1109 connect(AllCopiersLW, SIGNAL(currentRowChanged(int)),
1110 this, SLOT(switch_copierLB(int)));
1111 connect(copierFormatCO, SIGNAL(activated(int)),
1112 this, SLOT(switch_copierCO(int)));
1113 connect(copierNewPB, SIGNAL(clicked()),
1114 this, SIGNAL(changed()));
1115 connect(copierRemovePB, SIGNAL(clicked()),
1116 this, SIGNAL(changed()));
1117 connect(copierModifyPB, SIGNAL(clicked()),
1118 this, SIGNAL(changed()));
1119 connect(copierFormatCO, SIGNAL(activated(const QString &)),
1120 this, SLOT(copiers_changed()));
1121 connect(copierED, SIGNAL(textChanged(const QString &)),
1122 this, SLOT(copiers_changed()));
1126 void PrefCopiers::apply(LyXRC & /*rc*/) const
1131 void PrefCopiers::update(LyXRC const & /*rc*/)
1137 void PrefCopiers::update()
1139 // The choice widget
1140 // save current selection
1141 QString current = copierFormatCO->currentText();
1142 copierFormatCO->clear();
1144 for (Formats::const_iterator it = form_->formats().begin(),
1145 end = form_->formats().end();
1147 copierFormatCO->addItem(toqstr(it->prettyname()));
1150 // The browser widget
1151 AllCopiersLW->clear();
1153 for (Movers::const_iterator it = form_->movers().begin(),
1154 end = form_->movers().end();
1156 std::string const & command = it->second.command();
1157 if (command.empty())
1159 QString const pretty = toqstr(form_->formats().prettyName(it->first));
1160 AllCopiersLW->addItem(pretty);
1162 AllCopiersLW->sortItems(Qt::AscendingOrder);
1164 // restore selection
1165 if (!current.isEmpty()) {
1166 QList<QListWidgetItem *> item =
1167 AllCopiersLW->findItems(current, Qt::MatchExactly);
1169 AllCopiersLW->setCurrentItem(item.at(0));
1171 // select first element if restoring failed
1172 if (AllCopiersLW->currentRow() == -1)
1173 AllCopiersLW->setCurrentRow(0);
1179 class SamePrettyName {
1181 SamePrettyName(string const & n) : pretty_name_(n) {}
1183 bool operator()(Format const & fmt) const {
1184 return fmt.prettyname() == pretty_name_;
1188 string const pretty_name_;
1192 Format const * getFormat(std::string const & prettyname)
1194 Formats::const_iterator it = formats.begin();
1195 Formats::const_iterator const end = formats.end();
1196 it = std::find_if(it, end, SamePrettyName(prettyname));
1197 return it == end ? 0 : &*it;
1203 void PrefCopiers::switch_copierLB(int row)
1209 std::string const browser_text =
1210 fromqstr(AllCopiersLW->currentItem()->text());
1211 Format const * fmt = getFormat(browser_text);
1215 QString const gui_name = toqstr(fmt->prettyname());
1216 QString const command = toqstr(form_->movers().command(fmt->name()));
1219 int const combo_size = copierFormatCO->count();
1220 for (int i = 0; i < combo_size; ++i) {
1221 QString const text = copierFormatCO->itemText(i);
1222 if (text == gui_name) {
1223 copierFormatCO->setCurrentIndex(i);
1224 copierED->setText(command);
1232 void PrefCopiers::switch_copierCO(int row)
1237 std::string const combo_text =
1238 fromqstr(copierFormatCO->currentText());
1239 Format const * fmt = getFormat(combo_text);
1243 QString const command = toqstr(form_->movers().command(fmt->name()));
1244 copierED->setText(command);
1246 QListWidgetItem * const index = AllCopiersLW->currentItem();
1248 AllCopiersLW->setItemSelected(index, false);
1250 QString const gui_name = toqstr(fmt->prettyname());
1251 int const browser_size = AllCopiersLW->count();
1252 for (int i = 0; i < browser_size; ++i) {
1253 QString const text = AllCopiersLW->item(i)->text();
1254 if (text == gui_name) {
1255 QListWidgetItem * item = AllCopiersLW->item(i);
1256 AllCopiersLW->setItemSelected(item, true);
1263 void PrefCopiers::copiers_changed()
1269 void PrefCopiers::updateButtons()
1271 QString selected = copierFormatCO->currentText();
1274 for (int i = 0; i < AllCopiersLW->count(); ++i) {
1275 if (AllCopiersLW->item(i)->text() == selected)
1279 bool const valid = !copierED->text().isEmpty();
1281 Format const * fmt = getFormat(fromqstr(selected));
1282 string const old_command = form_->movers().command(fmt->name());
1283 string const new_command(fromqstr(copierED->text()));
1285 bool modified = (old_command != new_command);
1287 copierModifyPB->setEnabled(valid && known && modified);
1288 copierNewPB->setEnabled(valid && !known);
1289 copierRemovePB->setEnabled(known);
1293 void PrefCopiers::new_copier()
1295 std::string const combo_text =
1296 fromqstr(copierFormatCO->currentText());
1297 Format const * fmt = getFormat(combo_text);
1301 string const command = fromqstr(copierED->text());
1302 if (command.empty())
1305 form_->movers().set(fmt->name(), command);
1308 int const last = AllCopiersLW->count() - 1;
1309 AllCopiersLW->setCurrentRow(last);
1315 void PrefCopiers::modify_copier()
1317 std::string const combo_text =
1318 fromqstr(copierFormatCO->currentText());
1319 Format const * fmt = getFormat(combo_text);
1323 string const command = fromqstr(copierED->text());
1324 form_->movers().set(fmt->name(), command);
1331 void PrefCopiers::remove_copier()
1333 std::string const combo_text =
1334 fromqstr(copierFormatCO->currentText());
1335 Format const * fmt = getFormat(combo_text);
1339 string const & fmt_name = fmt->name();
1340 form_->movers().set(fmt_name, string());
1348 /////////////////////////////////////////////////////////////////////
1352 /////////////////////////////////////////////////////////////////////
1354 PrefFileformats::PrefFileformats(QPrefs * form, QWidget * parent)
1355 : PrefModule(docstring(), _("File formats"), form, parent)
1359 connect(formatNewPB, SIGNAL(clicked()),
1360 this, SLOT(new_format()));
1361 connect(formatRemovePB, SIGNAL(clicked()),
1362 this, SLOT(remove_format()));
1363 connect(formatModifyPB, SIGNAL(clicked()),
1364 this, SLOT(modify_format()));
1365 connect(formatsLW, SIGNAL(currentRowChanged(int)),
1366 this, SLOT(switch_format(int)));
1367 connect(formatED, SIGNAL(textChanged(const QString&)),
1368 this, SLOT(fileformat_changed()));
1369 connect(guiNameED, SIGNAL(textChanged(const QString&)),
1370 this, SLOT(fileformat_changed()));
1371 connect(shortcutED, SIGNAL(textChanged(const QString&)),
1372 this, SLOT(fileformat_changed()));
1373 connect(extensionED, SIGNAL(textChanged(const QString&)),
1374 this, SLOT(fileformat_changed()));
1375 connect(viewerED, SIGNAL(textChanged(const QString&)),
1376 this, SLOT(fileformat_changed()));
1377 connect(editorED, SIGNAL(textChanged(const QString&)),
1378 this, SLOT(fileformat_changed()));
1379 connect(documentCB, SIGNAL(clicked()),
1380 this, SLOT(fileformat_changed()));
1381 connect(vectorCB, SIGNAL(clicked()),
1382 this, SLOT(fileformat_changed()));
1383 connect(formatNewPB, SIGNAL(clicked()),
1384 this, SIGNAL(changed()));
1385 connect(formatRemovePB, SIGNAL(clicked()),
1386 this, SIGNAL(changed()));
1387 connect(formatModifyPB, SIGNAL(clicked()),
1388 this, SIGNAL(changed()));
1392 void PrefFileformats::apply(LyXRC & /*rc*/) const
1397 void PrefFileformats::update(LyXRC const & /*rc*/)
1403 void PrefFileformats::update()
1405 // save current selection
1406 QString current = guiNameED->text();
1408 // update listwidget with formats
1409 formatsLW->blockSignals(true);
1411 Formats::const_iterator cit = form_->formats().begin();
1412 Formats::const_iterator end = form_->formats().end();
1413 for (; cit != end; ++cit) {
1414 new QListWidgetItem(toqstr(cit->prettyname()),
1416 form_->formats().getNumber(cit->name()) );
1418 formatsLW->sortItems(Qt::AscendingOrder);
1419 formatsLW->blockSignals(false);
1421 // restore selection
1422 if (!current.isEmpty()) {
1423 QList<QListWidgetItem *> item = formatsLW->findItems(current, Qt::MatchExactly);
1425 formatsLW->setCurrentItem(item.at(0));
1427 // select first element if restoring failed
1428 if (formatsLW->currentRow() == -1)
1429 formatsLW->setCurrentRow(0);
1433 void PrefFileformats::switch_format(int nr)
1435 int const ftype = formatsLW->item(nr)->type();
1436 Format const f = form_->formats().get(ftype);
1438 formatED->setText(toqstr(f.name()));
1439 guiNameED->setText(toqstr(f.prettyname()));
1440 extensionED->setText(toqstr(f.extension()));
1441 shortcutED->setText(toqstr(f.shortcut()));
1442 viewerED->setText(toqstr(f.viewer()));
1443 editorED->setText(toqstr(f.editor()));
1444 documentCB->setChecked((f.documentFormat()));
1445 vectorCB->setChecked((f.vectorFormat()));
1451 void PrefFileformats::fileformat_changed()
1457 void PrefFileformats::updateButtons()
1459 QString const format = formatED->text();
1460 QString const gui_name = guiNameED->text();
1461 int const sel = form_->formats().getNumber(fromqstr(format));
1462 bool gui_name_known = false;
1464 for (int i = 0; i < formatsLW->count(); ++i) {
1465 if (formatsLW->item(i)->text() == gui_name) {
1466 gui_name_known = true;
1467 where = formatsLW->item(i)->type();
1471 // assure that a gui name cannot be chosen twice
1472 bool const known_otherwise = gui_name_known && (where != sel);
1474 bool const known = !(sel < 0);
1475 bool const valid = (!formatED->text().isEmpty()
1476 && !guiNameED->text().isEmpty());
1478 int const ftype = formatsLW->currentItem()->type();
1479 Format const & f(form_->formats().get(ftype));
1480 string const old_pretty(f.prettyname());
1481 string const old_shortcut(f.shortcut());
1482 string const old_extension(f.extension());
1483 string const old_viewer(f.viewer());
1484 string const old_editor(f.editor());
1485 bool const old_document(f.documentFormat());
1486 bool const old_vector(f.vectorFormat());
1488 string const new_pretty(fromqstr(gui_name));
1489 string const new_shortcut(fromqstr(shortcutED->text()));
1490 string const new_extension(fromqstr(extensionED->text()));
1491 string const new_viewer(fromqstr(viewerED->text()));
1492 string const new_editor(fromqstr(editorED->text()));
1493 bool const new_document(documentCB->isChecked());
1494 bool const new_vector(vectorCB->isChecked());
1496 bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
1497 || (old_extension != new_extension) || (old_viewer != new_viewer)
1498 || old_editor != new_editor || old_document != new_document
1499 || old_vector != new_vector);
1501 formatModifyPB->setEnabled(valid && known && modified && !known_otherwise);
1502 formatNewPB->setEnabled(valid && !known && !gui_name_known);
1503 formatRemovePB->setEnabled(known);
1507 void PrefFileformats::new_format()
1509 string const name = fromqstr(formatED->text());
1510 string const prettyname = fromqstr(guiNameED->text());
1511 string const extension = fromqstr(extensionED->text());
1512 string const shortcut = fromqstr(shortcutED->text());
1513 string const viewer = fromqstr(viewerED->text());
1514 string const editor = fromqstr(editorED->text());
1515 int flags = Format::none;
1516 if (documentCB->isChecked())
1517 flags |= Format::document;
1518 if (vectorCB->isChecked())
1519 flags |= Format::vector;
1521 form_->formats().add(name, extension, prettyname, shortcut, viewer,
1523 form_->formats().sort();
1524 form_->converters().update(form_->formats());
1532 void PrefFileformats::modify_format()
1534 int const current_item = formatsLW->currentItem()->type();
1535 Format const & oldformat = form_->formats().get(current_item);
1536 form_->formats().erase(oldformat.name());
1542 void PrefFileformats::remove_format()
1544 int const nr = formatsLW->currentItem()->type();
1545 string const current_text = form_->formats().get(nr).name();
1546 if (form_->converters().formatIsUsed(current_text)) {
1547 Alert::error(_("Format in use"),
1548 _("Cannot remove a Format used by a Converter. "
1549 "Remove the converter first."));
1553 form_->formats().erase(current_text);
1554 form_->converters().update(form_->formats());
1562 /////////////////////////////////////////////////////////////////////
1566 /////////////////////////////////////////////////////////////////////
1568 PrefLanguage::PrefLanguage(QWidget * parent)
1569 : PrefModule(_(LanguageSettings), _("Language"), 0, parent)
1573 connect(rtlCB, SIGNAL(clicked()),
1574 this, SIGNAL(changed()));
1575 connect(markForeignCB, SIGNAL(clicked()),
1576 this, SIGNAL(changed()));
1577 connect(autoBeginCB, SIGNAL(clicked()),
1578 this, SIGNAL(changed()));
1579 connect(autoEndCB, SIGNAL(clicked()),
1580 this, SIGNAL(changed()));
1581 connect(useBabelCB, SIGNAL(clicked()),
1582 this, SIGNAL(changed()));
1583 connect(globalCB, SIGNAL(clicked()),
1584 this, SIGNAL(changed()));
1585 connect(languagePackageED, SIGNAL(textChanged(const QString&)),
1586 this, SIGNAL(changed()));
1587 connect(startCommandED, SIGNAL(textChanged(const QString&)),
1588 this, SIGNAL(changed()));
1589 connect(endCommandED, SIGNAL(textChanged(const QString&)),
1590 this, SIGNAL(changed()));
1591 connect(defaultLanguageCO, SIGNAL(activated(int)),
1592 this, SIGNAL(changed()));
1594 defaultLanguageCO->clear();
1596 // store the lang identifiers for later
1597 std::vector<LanguagePair> const langs = frontend::getLanguageData(false);
1598 lang_ = getSecond(langs);
1600 std::vector<LanguagePair>::const_iterator lit = langs.begin();
1601 std::vector<LanguagePair>::const_iterator lend = langs.end();
1602 for (; lit != lend; ++lit) {
1603 defaultLanguageCO->addItem(toqstr(lit->first));
1608 void PrefLanguage::apply(LyXRC & rc) const
1610 // FIXME: remove rtl_support bool
1611 rc.rtl_support = rtlCB->isChecked();
1612 rc.mark_foreign_language = markForeignCB->isChecked();
1613 rc.language_auto_begin = autoBeginCB->isChecked();
1614 rc.language_auto_end = autoEndCB->isChecked();
1615 rc.language_use_babel = useBabelCB->isChecked();
1616 rc.language_global_options = globalCB->isChecked();
1617 rc.language_package = fromqstr(languagePackageED->text());
1618 rc.language_command_begin = fromqstr(startCommandED->text());
1619 rc.language_command_end = fromqstr(endCommandED->text());
1620 rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1624 void PrefLanguage::update(LyXRC const & rc)
1626 // FIXME: remove rtl_support bool
1627 rtlCB->setChecked(rc.rtl_support);
1628 markForeignCB->setChecked(rc.mark_foreign_language);
1629 autoBeginCB->setChecked(rc.language_auto_begin);
1630 autoEndCB->setChecked(rc.language_auto_end);
1631 useBabelCB->setChecked(rc.language_use_babel);
1632 globalCB->setChecked(rc.language_global_options);
1633 languagePackageED->setText(toqstr(rc.language_package));
1634 startCommandED->setText(toqstr(rc.language_command_begin));
1635 endCommandED->setText(toqstr(rc.language_command_end));
1637 int const pos = int(findPos_helper(lang_, rc.default_language));
1638 defaultLanguageCO->setCurrentIndex(pos);
1642 /////////////////////////////////////////////////////////////////////
1646 /////////////////////////////////////////////////////////////////////
1648 PrefPrinter::PrefPrinter(QWidget * parent)
1649 : PrefModule(_(Outputs), _("Printer"), 0, parent)
1653 connect(printerAdaptCB, SIGNAL(clicked()),
1654 this, SIGNAL(changed()));
1655 connect(printerCommandED, SIGNAL(textChanged(const QString&)),
1656 this, SIGNAL(changed()));
1657 connect(printerNameED, SIGNAL(textChanged(const QString&)),
1658 this, SIGNAL(changed()));
1659 connect(printerPageRangeED, SIGNAL(textChanged(const QString&)),
1660 this, SIGNAL(changed()));
1661 connect(printerCopiesED, SIGNAL(textChanged(const QString&)),
1662 this, SIGNAL(changed()));
1663 connect(printerReverseED, SIGNAL(textChanged(const QString&)),
1664 this, SIGNAL(changed()));
1665 connect(printerToPrinterED, SIGNAL(textChanged(const QString&)),
1666 this, SIGNAL(changed()));
1667 connect(printerExtensionED, SIGNAL(textChanged(const QString&)),
1668 this, SIGNAL(changed()));
1669 connect(printerSpoolCommandED, SIGNAL(textChanged(const QString&)),
1670 this, SIGNAL(changed()));
1671 connect(printerPaperTypeED, SIGNAL(textChanged(const QString&)),
1672 this, SIGNAL(changed()));
1673 connect(printerEvenED, SIGNAL(textChanged(const QString&)),
1674 this, SIGNAL(changed()));
1675 connect(printerOddED, SIGNAL(textChanged(const QString&)),
1676 this, SIGNAL(changed()));
1677 connect(printerCollatedED, SIGNAL(textChanged(const QString&)),
1678 this, SIGNAL(changed()));
1679 connect(printerLandscapeED, SIGNAL(textChanged(const QString&)),
1680 this, SIGNAL(changed()));
1681 connect(printerToFileED, SIGNAL(textChanged(const QString&)),
1682 this, SIGNAL(changed()));
1683 connect(printerExtraED, SIGNAL(textChanged(const QString&)),
1684 this, SIGNAL(changed()));
1685 connect(printerSpoolPrefixED, SIGNAL(textChanged(const QString&)),
1686 this, SIGNAL(changed()));
1687 connect(printerPaperSizeED, SIGNAL(textChanged(const QString&)),
1688 this, SIGNAL(changed()));
1692 void PrefPrinter::apply(LyXRC & rc) const
1694 rc.print_adapt_output = printerAdaptCB->isChecked();
1695 rc.print_command = fromqstr(printerCommandED->text());
1696 rc.printer = fromqstr(printerNameED->text());
1698 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1699 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1700 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1701 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1702 rc.print_file_extension = fromqstr(printerExtensionED->text());
1703 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1704 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1705 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1706 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1707 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1708 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1709 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1710 rc.print_extra_options = fromqstr(printerExtraED->text());
1711 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1712 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1716 void PrefPrinter::update(LyXRC const & rc)
1718 printerAdaptCB->setChecked(rc.print_adapt_output);
1719 printerCommandED->setText(toqstr(rc.print_command));
1720 printerNameED->setText(toqstr(rc.printer));
1722 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1723 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1724 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1725 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1726 printerExtensionED->setText(toqstr(rc.print_file_extension));
1727 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1728 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1729 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1730 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1731 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1732 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1733 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1734 printerExtraED->setText(toqstr(rc.print_extra_options));
1735 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1736 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1740 /////////////////////////////////////////////////////////////////////
1742 // PrefUserInterface
1744 /////////////////////////////////////////////////////////////////////
1746 PrefUserInterface::PrefUserInterface(QPrefs * form, QWidget * parent)
1747 : PrefModule(_(LookAndFeel), _("User interface"), form, parent)
1751 connect(autoSaveCB, SIGNAL(toggled(bool)),
1752 autoSaveLA, SLOT(setEnabled(bool)));
1753 connect(autoSaveCB, SIGNAL(toggled(bool)),
1754 autoSaveSB, SLOT(setEnabled(bool)));
1755 connect(autoSaveCB, SIGNAL(toggled(bool)),
1756 TextLabel1, SLOT(setEnabled(bool)));
1757 connect(uiFilePB, SIGNAL(clicked()),
1758 this, SLOT(select_ui()));
1759 connect(bindFilePB, SIGNAL(clicked()),
1760 this, SLOT(select_bind()));
1761 connect(uiFileED, SIGNAL(textChanged(const QString &)),
1762 this, SIGNAL(changed()));
1763 connect(bindFileED, SIGNAL(textChanged(const QString &)),
1764 this, SIGNAL(changed()));
1765 connect(restoreCursorCB, SIGNAL(clicked()),
1766 this, SIGNAL(changed()));
1767 connect(loadSessionCB, SIGNAL(clicked()),
1768 this, SIGNAL(changed()));
1769 connect(loadWindowSizeCB, SIGNAL(clicked()),
1770 this, SIGNAL(changed()));
1771 connect(loadWindowLocationCB, SIGNAL(clicked()),
1772 this, SIGNAL(changed()));
1773 connect(windowWidthSB, SIGNAL(valueChanged(int)),
1774 this, SIGNAL(changed()));
1775 connect(windowHeightSB, SIGNAL(valueChanged(int)),
1776 this, SIGNAL(changed()));
1777 connect(cursorFollowsCB, SIGNAL(clicked()),
1778 this, SIGNAL(changed()));
1779 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1780 this, SIGNAL(changed()));
1781 connect(autoSaveCB, SIGNAL(clicked()),
1782 this, SIGNAL(changed()));
1783 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1784 this, SIGNAL(changed()));
1785 lastfilesSB->setMaximum(maxlastfiles);
1789 void PrefUserInterface::apply(LyXRC & rc) const
1791 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1792 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1793 rc.use_lastfilepos = restoreCursorCB->isChecked();
1794 rc.load_session = loadSessionCB->isChecked();
1795 if (loadWindowSizeCB->isChecked()) {
1796 rc.geometry_width = 0;
1797 rc.geometry_height = 0;
1799 rc.geometry_width = windowWidthSB->value();
1800 rc.geometry_height = windowHeightSB->value();
1802 rc.geometry_xysaved = loadWindowLocationCB->isChecked();
1803 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1804 rc.autosave = autoSaveSB->value() * 60;
1805 rc.make_backup = autoSaveCB->isChecked();
1806 rc.num_lastfiles = lastfilesSB->value();
1810 void PrefUserInterface::update(LyXRC const & rc)
1812 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1813 bindFileED->setText(toqstr(external_path(rc.bind_file)));
1814 restoreCursorCB->setChecked(rc.use_lastfilepos);
1815 loadSessionCB->setChecked(rc.load_session);
1816 bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
1817 loadWindowSizeCB->setChecked(loadWindowSize);
1818 if (!loadWindowSize) {
1819 windowWidthSB->setValue(rc.geometry_width);
1820 windowHeightSB->setValue(rc.geometry_height);
1822 loadWindowLocationCB->setChecked(rc.geometry_xysaved);
1823 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1824 // convert to minutes
1825 int mins(rc.autosave / 60);
1826 if (rc.autosave && !mins)
1828 autoSaveSB->setValue(mins);
1829 autoSaveCB->setChecked(rc.make_backup);
1830 lastfilesSB->setValue(rc.num_lastfiles);
1835 void PrefUserInterface::select_ui()
1837 docstring const name =
1838 from_utf8(internal_path(fromqstr(uiFileED->text())));
1839 docstring file(form_->controller().browseUI(name));
1841 uiFileED->setText(toqstr(file));
1845 void PrefUserInterface::select_bind()
1847 docstring const name =
1848 from_utf8(internal_path(fromqstr(bindFileED->text())));
1849 docstring file(form_->controller().browsebind(name));
1851 bindFileED->setText(toqstr(file));
1855 void PrefUserInterface::on_loadWindowSizeCB_toggled(bool loadwindowsize)
1857 windowWidthLA->setDisabled(loadwindowsize);
1858 windowHeightLA->setDisabled(loadwindowsize);
1859 windowWidthSB->setDisabled(loadwindowsize);
1860 windowHeightSB->setDisabled(loadwindowsize);
1864 PrefIdentity::PrefIdentity(QWidget * parent)
1865 : PrefModule(docstring(), _("Identity"), 0, parent)
1869 connect(nameED, SIGNAL(textChanged(const QString&)),
1870 this, SIGNAL(changed()));
1871 connect(emailED, SIGNAL(textChanged(const QString&)),
1872 this, SIGNAL(changed()));
1876 void PrefIdentity::apply(LyXRC & rc) const
1878 rc.user_name = fromqstr(nameED->text());
1879 rc.user_email = fromqstr(emailED->text());
1883 void PrefIdentity::update(LyXRC const & rc)
1885 nameED->setText(toqstr(rc.user_name));
1886 emailED->setText(toqstr(rc.user_email));
1891 /////////////////////////////////////////////////////////////////////
1895 /////////////////////////////////////////////////////////////////////
1897 QPrefsDialog::QPrefsDialog(QPrefs * form)
1901 QDialog::setModal(false);
1903 connect(savePB, SIGNAL(clicked()), form, SLOT(slotOK()));
1904 connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
1905 connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
1906 connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore()));
1908 add(new PrefUserInterface(form_));
1909 add(new PrefScreenFonts(form_));
1910 add(new PrefColors(form_));
1911 add(new PrefDisplay);
1912 add(new PrefKeyboard(form_));
1914 add(new PrefPaths(form_));
1916 add(new PrefIdentity);
1918 add(new PrefLanguage);
1919 add(new PrefSpellchecker(form_));
1921 add(new PrefPrinter);
1923 add(new PrefPlaintext);
1924 add(new PrefLatex(form_));
1926 #if defined(__CYGWIN__) || defined(_WIN32)
1927 add(new PrefCygwinPath);
1931 PrefConverters * converters = new PrefConverters(form_);
1932 PrefFileformats * formats = new PrefFileformats(form_);
1933 connect(formats, SIGNAL(formatsChanged()),
1934 converters, SLOT(updateGui()));
1938 add(new PrefCopiers(form_));
1941 prefsPS->setCurrentPanel(_("User interface"));
1942 // FIXME: hack to work around resizing bug in Qt >= 4.2
1943 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1944 #if QT_VERSION >= 0x040200
1945 prefsPS->updateGeometry();
1948 form_->bcview().setOK(savePB);
1949 form_->bcview().setApply(applyPB);
1950 form_->bcview().setCancel(closePB);
1951 form_->bcview().setRestore(restorePB);
1955 void QPrefsDialog::add(PrefModule * module)
1957 BOOST_ASSERT(module);
1959 // if (module->category().empty())
1960 // prefsPS->addPanel(module, module->title());
1962 prefsPS->addPanel(module, module->title(), module->category());
1964 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
1966 modules_.push_back(module);
1969 void QPrefsDialog::closeEvent(QCloseEvent * e)
1971 form_->slotWMHide();
1976 void QPrefsDialog::change_adaptor()
1982 void QPrefsDialog::apply(LyXRC & rc) const
1984 size_t end = modules_.size();
1985 for (size_t i = 0; i != end; ++i)
1986 modules_[i]->apply(rc);
1990 void QPrefsDialog::updateRc(LyXRC const & rc)
1992 size_t const end = modules_.size();
1993 for (size_t i = 0; i != end; ++i)
1994 modules_[i]->update(rc);
1998 /////////////////////////////////////////////////////////////////////
2002 /////////////////////////////////////////////////////////////////////
2004 typedef QController<ControlPrefs, QView<QPrefsDialog> > PrefsBase;
2006 QPrefs::QPrefs(Dialog & parent)
2007 : PrefsBase(parent, _("Preferences"))
2011 Converters & QPrefs::converters()
2013 return controller().converters();
2016 Formats & QPrefs::formats()
2018 return controller().formats();
2021 Movers & QPrefs::movers()
2023 return controller().movers();
2026 void QPrefs::build_dialog()
2028 dialog_.reset(new QPrefsDialog(this));
2031 void QPrefs::apply()
2033 dialog_->apply(controller().rc());
2036 void QPrefs::update_contents()
2038 dialog_->updateRc(controller().rc());
2041 } // namespace frontend
2044 #include "QPrefs_moc.cpp"