3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
14 #include "ControlPrefs.h"
16 #include "qt_helpers.h"
17 #include "GuiApplication.h"
19 #include "ConverterCache.h"
24 #include "PanelStack.h"
25 #include "GuiFontExample.h"
28 #include "support/lstrings.h"
29 #include "support/os.h"
31 #include "frontend_helpers.h"
33 #include "frontends/alert.h"
34 #include "frontends/Application.h"
37 #include <QColorDialog>
38 #include <QFontDatabase>
40 #include <QPushButton>
44 #include <QCloseEvent>
53 using lyx::support::compare_ascii_no_case;
54 using lyx::support::os::external_path;
55 using lyx::support::os::external_path_list;
56 using lyx::support::os::internal_path;
57 using lyx::support::os::internal_path_list;
68 /////////////////////////////////////////////////////////////////////
72 /////////////////////////////////////////////////////////////////////
75 static size_t findPos_helper(std::vector<A> const & vec, A const & val)
77 typedef typename std::vector<A>::const_iterator Cit;
79 Cit it = std::find(vec.begin(), vec.end(), val);
82 return std::distance(vec.begin(), it);
86 static std::pair<string, string> parseFontName(string const & name)
88 string::size_type const idx = name.find('[');
89 if (idx == string::npos || idx == 0)
90 return make_pair(name, string());
91 return make_pair(name.substr(0, idx - 1),
92 name.substr(idx + 1, name.size() - idx - 2));
96 static void setComboxFont(QComboBox * cb, string const & family,
97 string const & foundry)
99 QString fontname = toqstr(family);
100 if (!foundry.empty())
101 fontname += " [" + toqstr(foundry) + ']';
103 for (int i = 0; i < cb->count(); ++i) {
104 if (cb->itemText(i) == fontname) {
105 cb->setCurrentIndex(i);
110 // Try matching without foundry name
112 // We count in reverse in order to prefer the Xft foundry
113 for (int i = cb->count(); --i >= 0;) {
114 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
115 if (compare_ascii_no_case(tmp.first, family) == 0) {
116 cb->setCurrentIndex(i);
121 // family alone can contain e.g. "Helvetica [Adobe]"
122 pair<string, string> tmpfam = parseFontName(family);
124 // We count in reverse in order to prefer the Xft foundry
125 for (int i = cb->count() - 1; i >= 0; --i) {
126 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
127 if (compare_ascii_no_case(tmp.first, tmpfam.first) == 0) {
128 cb->setCurrentIndex(i);
133 // Bleh, default fonts, and the names couldn't be found. Hack
137 font.setKerning(false);
139 if (family == theApp()->romanFontName()) {
140 font.setStyleHint(QFont::Serif);
141 font.setFamily(family.c_str());
142 } else if (family == theApp()->sansFontName()) {
143 font.setStyleHint(QFont::SansSerif);
144 font.setFamily(family.c_str());
145 } else if (family == theApp()->typewriterFontName()) {
146 font.setStyleHint(QFont::TypeWriter);
147 font.setFamily(family.c_str());
149 lyxerr << "FAILED to find the default font: '"
150 << foundry << "', '" << family << '\''<< endl;
154 QFontInfo info(font);
155 pair<string, string> tmp = parseFontName(fromqstr(info.family()));
156 string const & default_font_name = tmp.first;
157 lyxerr << "Apparent font is " << default_font_name << endl;
159 for (int i = 0; i < cb->count(); ++i) {
160 lyxerr << "Looking at " << fromqstr(cb->itemText(i)) << endl;
161 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
162 default_font_name) == 0) {
163 cb->setCurrentIndex(i);
168 lyxerr << "FAILED to find the font: '"
169 << foundry << "', '" << family << '\'' <<endl;
173 /////////////////////////////////////////////////////////////////////
177 /////////////////////////////////////////////////////////////////////
179 PrefPlaintext::PrefPlaintext(QWidget * parent)
180 : PrefModule(_("Plain text"), 0, parent)
183 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
184 this, SIGNAL(changed()));
185 connect(plaintextRoffED, SIGNAL(textChanged(const QString&)),
186 this, SIGNAL(changed()));
190 void PrefPlaintext::apply(LyXRC & rc) const
192 rc.plaintext_linelen = plaintextLinelengthSB->value();
193 rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
197 void PrefPlaintext::update(LyXRC const & rc)
199 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
200 plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
204 /////////////////////////////////////////////////////////////////////
208 /////////////////////////////////////////////////////////////////////
210 PrefDate::PrefDate(QWidget * parent)
211 : PrefModule(_("Date format"), 0, parent)
214 connect(DateED, SIGNAL(textChanged(const QString &)),
215 this, SIGNAL(changed()));
219 void PrefDate::apply(LyXRC & rc) const
221 rc.date_insert_format = fromqstr(DateED->text());
225 void PrefDate::update(LyXRC const & rc)
227 DateED->setText(toqstr(rc.date_insert_format));
231 /////////////////////////////////////////////////////////////////////
235 /////////////////////////////////////////////////////////////////////
237 PrefKeyboard::PrefKeyboard(GuiPrefsDialog * form, QWidget * parent)
238 : PrefModule(_("Keyboard"), form, parent)
242 connect(keymapCB, SIGNAL(clicked()),
243 this, SIGNAL(changed()));
244 connect(firstKeymapED, SIGNAL(textChanged(const QString&)),
245 this, SIGNAL(changed()));
246 connect(secondKeymapED, SIGNAL(textChanged(const QString&)),
247 this, SIGNAL(changed()));
251 void PrefKeyboard::apply(LyXRC & rc) const
253 // FIXME: can derive CB from the two EDs
254 rc.use_kbmap = keymapCB->isChecked();
255 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
256 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
260 void PrefKeyboard::update(LyXRC const & rc)
262 // FIXME: can derive CB from the two EDs
263 keymapCB->setChecked(rc.use_kbmap);
264 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
265 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
269 QString PrefKeyboard::testKeymap(QString keymap)
271 return toqstr(form_->controller().browsekbmap(from_utf8(internal_path(fromqstr(keymap)))));
275 void PrefKeyboard::on_firstKeymapPB_clicked(bool)
277 QString const file = testKeymap(firstKeymapED->text());
279 firstKeymapED->setText(file);
283 void PrefKeyboard::on_secondKeymapPB_clicked(bool)
285 QString const file = testKeymap(secondKeymapED->text());
287 secondKeymapED->setText(file);
291 void PrefKeyboard::on_keymapCB_toggled(bool keymap)
293 firstKeymapLA->setEnabled(keymap);
294 secondKeymapLA->setEnabled(keymap);
295 firstKeymapED->setEnabled(keymap);
296 secondKeymapED->setEnabled(keymap);
297 firstKeymapPB->setEnabled(keymap);
298 secondKeymapPB->setEnabled(keymap);
302 /////////////////////////////////////////////////////////////////////
306 /////////////////////////////////////////////////////////////////////
308 PrefLatex::PrefLatex(GuiPrefsDialog * form, QWidget * parent)
309 : PrefModule(_("LaTeX"), form, parent)
312 connect(latexEncodingED, SIGNAL(textChanged(const QString&)),
313 this, SIGNAL(changed()));
314 connect(latexChecktexED, SIGNAL(textChanged(const QString&)),
315 this, SIGNAL(changed()));
316 connect(latexBibtexED, SIGNAL(textChanged(const QString&)),
317 this, SIGNAL(changed()));
318 connect(latexIndexED, SIGNAL(textChanged(const QString&)),
319 this, SIGNAL(changed()));
320 connect(latexAutoresetCB, SIGNAL(clicked()),
321 this, SIGNAL(changed()));
322 connect(latexDviPaperED, SIGNAL(textChanged(const QString&)),
323 this, SIGNAL(changed()));
324 connect(latexPaperSizeCO, SIGNAL(activated(int)),
325 this, SIGNAL(changed()));
327 #if defined(__CYGWIN__) || defined(_WIN32)
328 pathCB->setVisible(true);
329 connect(pathCB, SIGNAL(clicked()),
330 this, SIGNAL(changed()));
332 pathCB->setVisible(false);
337 void PrefLatex::apply(LyXRC & rc) const
339 rc.fontenc = fromqstr(latexEncodingED->text());
340 rc.chktex_command = fromqstr(latexChecktexED->text());
341 rc.bibtex_command = fromqstr(latexBibtexED->text());
342 rc.index_command = fromqstr(latexIndexED->text());
343 rc.auto_reset_options = latexAutoresetCB->isChecked();
344 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
345 rc.default_papersize =
346 form_->controller().toPaperSize(latexPaperSizeCO->currentIndex());
347 #if defined(__CYGWIN__) || defined(_WIN32)
348 rc.windows_style_tex_paths = pathCB->isChecked();
353 void PrefLatex::update(LyXRC const & rc)
355 latexEncodingED->setText(toqstr(rc.fontenc));
356 latexChecktexED->setText(toqstr(rc.chktex_command));
357 latexBibtexED->setText(toqstr(rc.bibtex_command));
358 latexIndexED->setText(toqstr(rc.index_command));
359 latexAutoresetCB->setChecked(rc.auto_reset_options);
360 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
361 latexPaperSizeCO->setCurrentIndex(
362 form_->controller().fromPaperSize(rc.default_papersize));
363 #if defined(__CYGWIN__) || defined(_WIN32)
364 pathCB->setChecked(rc.windows_style_tex_paths);
369 /////////////////////////////////////////////////////////////////////
373 /////////////////////////////////////////////////////////////////////
375 PrefScreenFonts::PrefScreenFonts(GuiPrefsDialog * form, QWidget * parent)
376 : PrefModule(_("Screen fonts"), form, parent)
380 connect(screenRomanCO, SIGNAL(activated(const QString&)),
381 this, SLOT(select_roman(const QString&)));
382 connect(screenSansCO, SIGNAL(activated(const QString&)),
383 this, SLOT(select_sans(const QString&)));
384 connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
385 this, SLOT(select_typewriter(const QString&)));
387 QFontDatabase fontdb;
388 QStringList families(fontdb.families());
389 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
390 screenRomanCO->addItem(*it);
391 screenSansCO->addItem(*it);
392 screenTypewriterCO->addItem(*it);
394 connect(screenRomanCO, SIGNAL(activated(const QString&)),
395 this, SIGNAL(changed()));
396 connect(screenSansCO, SIGNAL(activated(const QString&)),
397 this, SIGNAL(changed()));
398 connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
399 this, SIGNAL(changed()));
400 connect(screenZoomSB, SIGNAL(valueChanged(int)),
401 this, SIGNAL(changed()));
402 connect(screenDpiSB, SIGNAL(valueChanged(int)),
403 this, SIGNAL(changed()));
404 connect(screenTinyED, SIGNAL(textChanged(const QString&)),
405 this, SIGNAL(changed()));
406 connect(screenSmallestED, SIGNAL(textChanged(const QString&)),
407 this, SIGNAL(changed()));
408 connect(screenSmallerED, SIGNAL(textChanged(const QString&)),
409 this, SIGNAL(changed()));
410 connect(screenSmallED, SIGNAL(textChanged(const QString&)),
411 this, SIGNAL(changed()));
412 connect(screenNormalED, SIGNAL(textChanged(const QString&)),
413 this, SIGNAL(changed()));
414 connect(screenLargeED, SIGNAL(textChanged(const QString&)),
415 this, SIGNAL(changed()));
416 connect(screenLargerED, SIGNAL(textChanged(const QString&)),
417 this, SIGNAL(changed()));
418 connect(screenLargestED, SIGNAL(textChanged(const QString&)),
419 this, SIGNAL(changed()));
420 connect(screenHugeED, SIGNAL(textChanged(const QString&)),
421 this, SIGNAL(changed()));
422 connect(screenHugerED, SIGNAL(textChanged(const QString&)),
423 this, SIGNAL(changed()));
425 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
426 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
427 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
428 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
429 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
430 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
431 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
432 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
433 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
434 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
438 void PrefScreenFonts::apply(LyXRC & rc) const
440 LyXRC const oldrc(rc);
442 boost::tie(rc.roman_font_name, rc.roman_font_foundry)
443 = parseFontName(fromqstr(screenRomanCO->currentText()));
444 boost::tie(rc.sans_font_name, rc.sans_font_foundry) =
445 parseFontName(fromqstr(screenSansCO->currentText()));
446 boost::tie(rc.typewriter_font_name, rc.typewriter_font_foundry) =
447 parseFontName(fromqstr(screenTypewriterCO->currentText()));
449 rc.zoom = screenZoomSB->value();
450 rc.dpi = screenDpiSB->value();
451 rc.font_sizes[Font::SIZE_TINY] = fromqstr(screenTinyED->text());
452 rc.font_sizes[Font::SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
453 rc.font_sizes[Font::SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
454 rc.font_sizes[Font::SIZE_SMALL] = fromqstr(screenSmallED->text());
455 rc.font_sizes[Font::SIZE_NORMAL] = fromqstr(screenNormalED->text());
456 rc.font_sizes[Font::SIZE_LARGE] = fromqstr(screenLargeED->text());
457 rc.font_sizes[Font::SIZE_LARGER] = fromqstr(screenLargerED->text());
458 rc.font_sizes[Font::SIZE_LARGEST] = fromqstr(screenLargestED->text());
459 rc.font_sizes[Font::SIZE_HUGE] = fromqstr(screenHugeED->text());
460 rc.font_sizes[Font::SIZE_HUGER] = fromqstr(screenHugerED->text());
462 if (rc.font_sizes != oldrc.font_sizes
463 || rc.roman_font_name != oldrc.roman_font_name
464 || rc.sans_font_name != oldrc.sans_font_name
465 || rc.typewriter_font_name != oldrc.typewriter_font_name
466 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
467 form_->controller().updateScreenFonts();
472 void PrefScreenFonts::update(LyXRC const & rc)
474 setComboxFont(screenRomanCO, rc.roman_font_name,
475 rc.roman_font_foundry);
476 setComboxFont(screenSansCO, rc.sans_font_name,
477 rc.sans_font_foundry);
478 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
479 rc.typewriter_font_foundry);
481 select_roman(screenRomanCO->currentText());
482 select_sans(screenSansCO->currentText());
483 select_typewriter(screenTypewriterCO->currentText());
485 screenZoomSB->setValue(rc.zoom);
486 screenDpiSB->setValue(rc.dpi);
487 screenTinyED->setText(toqstr(rc.font_sizes[Font::SIZE_TINY]));
488 screenSmallestED->setText(toqstr(rc.font_sizes[Font::SIZE_SCRIPT]));
489 screenSmallerED->setText(toqstr(rc.font_sizes[Font::SIZE_FOOTNOTE]));
490 screenSmallED->setText(toqstr(rc.font_sizes[Font::SIZE_SMALL]));
491 screenNormalED->setText(toqstr(rc.font_sizes[Font::SIZE_NORMAL]));
492 screenLargeED->setText(toqstr(rc.font_sizes[Font::SIZE_LARGE]));
493 screenLargerED->setText(toqstr(rc.font_sizes[Font::SIZE_LARGER]));
494 screenLargestED->setText(toqstr(rc.font_sizes[Font::SIZE_LARGEST]));
495 screenHugeED->setText(toqstr(rc.font_sizes[Font::SIZE_HUGE]));
496 screenHugerED->setText(toqstr(rc.font_sizes[Font::SIZE_HUGER]));
499 void PrefScreenFonts::select_roman(const QString& name)
501 screenRomanFE->set(QFont(name), name);
505 void PrefScreenFonts::select_sans(const QString& name)
507 screenSansFE->set(QFont(name), name);
511 void PrefScreenFonts::select_typewriter(const QString& name)
513 screenTypewriterFE->set(QFont(name), name);
517 /////////////////////////////////////////////////////////////////////
521 /////////////////////////////////////////////////////////////////////
527 bool operator()(Color::color const & lhs, Color::color const & rhs) const {
528 return lcolor.getGUIName(lhs) < lcolor.getGUIName(rhs);
534 PrefColors::PrefColors(GuiPrefsDialog * form, QWidget * parent)
535 : PrefModule( _("Colors"), form, parent)
539 // FIXME: all of this initialization should be put into the controller.
540 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
541 // for some discussion of why that is not trivial.
542 QPixmap icon(32, 32);
543 for (int i = 0; i < Color::ignore; ++i) {
544 Color::color lc = static_cast<Color::color>(i);
545 if (lc == Color::none
546 || lc == Color::black
547 || lc == Color::white
549 || lc == Color::green
552 || lc == Color::magenta
553 || lc == Color::yellow
554 || lc == Color::inherit
555 || lc == Color::ignore) continue;
557 lcolors_.push_back(lc);
559 std::sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
560 vector<Color_color>::const_iterator cit = lcolors_.begin();
561 vector<Color_color>::const_iterator const end = lcolors_.end();
562 for (; cit != end; ++cit) {
563 (void) new QListWidgetItem(QIcon(icon),
564 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
566 curcolors_.resize(lcolors_.size());
567 newcolors_.resize(lcolors_.size());
568 // End initialization
570 connect(colorChangePB, SIGNAL(clicked()),
571 this, SLOT(change_color()));
572 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
573 this, SLOT(change_lyxObjects_selection()));
574 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
575 this, SLOT(change_color()));
579 void PrefColors::apply(LyXRC & /*rc*/) const
581 for (unsigned int i = 0; i < lcolors_.size(); ++i)
582 if (curcolors_[i] != newcolors_[i])
583 form_->controller().setColor(lcolors_[i], fromqstr(newcolors_[i]));
587 void PrefColors::update(LyXRC const & /*rc*/)
589 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
590 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
591 QPixmap coloritem(32, 32);
592 coloritem.fill(color);
593 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
594 newcolors_[i] = curcolors_[i] = color.name();
596 change_lyxObjects_selection();
599 void PrefColors::change_color()
601 int const row = lyxObjectsLW->currentRow();
607 QString const color = newcolors_[row];
608 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
610 if (c.isValid() && c.name() != color) {
611 newcolors_[row] = c.name();
612 QPixmap coloritem(32, 32);
614 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
620 void PrefColors::change_lyxObjects_selection()
622 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
626 /////////////////////////////////////////////////////////////////////
630 /////////////////////////////////////////////////////////////////////
632 PrefDisplay::PrefDisplay(QWidget * parent)
633 : PrefModule(_("Graphics"), 0, parent)
636 connect(instantPreviewCO, SIGNAL(activated(int)),
637 this, SIGNAL(changed()));
638 connect(displayGraphicsCO, SIGNAL(activated(int)),
639 this, SIGNAL(changed()));
643 void PrefDisplay::apply(LyXRC & rc) const
645 switch (instantPreviewCO->currentIndex()) {
646 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
647 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
648 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
651 lyx::graphics::DisplayType dtype;
652 switch (displayGraphicsCO->currentIndex()) {
653 case 3: dtype = lyx::graphics::NoDisplay; break;
654 case 2: dtype = lyx::graphics::ColorDisplay; break;
655 case 1: dtype = lyx::graphics::GrayscaleDisplay; break;
656 case 0: dtype = lyx::graphics::MonochromeDisplay; break;
657 default: dtype = lyx::graphics::GrayscaleDisplay;
659 rc.display_graphics = dtype;
661 // FIXME!! The graphics cache no longer has a changeDisplay method.
663 if (old_value != rc.display_graphics) {
664 lyx::graphics::GCache & gc = lyx::graphics::GCache::get();
671 void PrefDisplay::update(LyXRC const & rc)
673 switch (rc.preview) {
674 case LyXRC::PREVIEW_OFF:
675 instantPreviewCO->setCurrentIndex(0);
677 case LyXRC::PREVIEW_NO_MATH :
678 instantPreviewCO->setCurrentIndex(1);
680 case LyXRC::PREVIEW_ON :
681 instantPreviewCO->setCurrentIndex(2);
686 switch (rc.display_graphics) {
687 case lyx::graphics::NoDisplay: item = 3; break;
688 case lyx::graphics::ColorDisplay: item = 2; break;
689 case lyx::graphics::GrayscaleDisplay: item = 1; break;
690 case lyx::graphics::MonochromeDisplay: item = 0; break;
693 displayGraphicsCO->setCurrentIndex(item);
697 /////////////////////////////////////////////////////////////////////
701 /////////////////////////////////////////////////////////////////////
703 PrefPaths::PrefPaths(GuiPrefsDialog * form, QWidget * parent)
704 : PrefModule(_("Paths"), form, parent)
707 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
708 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
709 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
710 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
711 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
712 connect(workingDirED, SIGNAL(textChanged(const QString&)),
713 this, SIGNAL(changed()));
714 connect(templateDirED, SIGNAL(textChanged(const QString&)),
715 this, SIGNAL(changed()));
716 connect(backupDirED, SIGNAL(textChanged(const QString&)),
717 this, SIGNAL(changed()));
718 connect(tempDirED, SIGNAL(textChanged(const QString&)),
719 this, SIGNAL(changed()));
720 connect(lyxserverDirED, SIGNAL(textChanged(const QString&)),
721 this, SIGNAL(changed()));
722 connect(pathPrefixED, SIGNAL(textChanged(const QString&)),
723 this, SIGNAL(changed()));
727 void PrefPaths::apply(LyXRC & rc) const
729 rc.document_path = internal_path(fromqstr(workingDirED->text()));
730 rc.template_path = internal_path(fromqstr(templateDirED->text()));
731 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
732 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
733 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
734 // FIXME: should be a checkbox only
735 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
739 void PrefPaths::update(LyXRC const & rc)
741 workingDirED->setText(toqstr(external_path(rc.document_path)));
742 templateDirED->setText(toqstr(external_path(rc.template_path)));
743 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
744 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
745 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
746 // FIXME: should be a checkbox only
747 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
751 void PrefPaths::select_templatedir()
753 docstring file(form_->controller().browsedir(
754 from_utf8(internal_path(fromqstr(templateDirED->text()))),
755 _("Select a document templates directory")));
757 templateDirED->setText(toqstr(file));
761 void PrefPaths::select_tempdir()
763 docstring file(form_->controller().browsedir(
764 from_utf8(internal_path(fromqstr(tempDirED->text()))),
765 _("Select a temporary directory")));
767 tempDirED->setText(toqstr(file));
771 void PrefPaths::select_backupdir()
773 docstring file(form_->controller().browsedir(
774 from_utf8(internal_path(fromqstr(backupDirED->text()))),
775 _("Select a backups directory")));
777 backupDirED->setText(toqstr(file));
781 void PrefPaths::select_workingdir()
783 docstring file(form_->controller().browsedir(
784 from_utf8(internal_path(fromqstr(workingDirED->text()))),
785 _("Select a document directory")));
787 workingDirED->setText(toqstr(file));
791 void PrefPaths::select_lyxpipe()
793 docstring file(form_->controller().browse(
794 from_utf8(internal_path(fromqstr(lyxserverDirED->text()))),
795 _("Give a filename for the LyX server pipe")));
797 lyxserverDirED->setText(toqstr(file));
801 /////////////////////////////////////////////////////////////////////
805 /////////////////////////////////////////////////////////////////////
807 PrefSpellchecker::PrefSpellchecker(GuiPrefsDialog * form, QWidget * parent)
808 : PrefModule(_("Spellchecker"), form, parent)
812 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
813 #if defined (USE_ISPELL)
814 connect(spellCommandCO, SIGNAL(activated(int)),
815 this, SIGNAL(changed()));
817 spellCommandCO->setEnabled(false);
819 connect(altLanguageED, SIGNAL(textChanged(const QString&)),
820 this, SIGNAL(changed()));
821 connect(escapeCharactersED, SIGNAL(textChanged(const QString&)),
822 this, SIGNAL(changed()));
823 connect(persDictionaryED, SIGNAL(textChanged(const QString&)),
824 this, SIGNAL(changed()));
825 connect(compoundWordCB, SIGNAL(clicked()),
826 this, SIGNAL(changed()));
827 connect(inputEncodingCB, SIGNAL(clicked()),
828 this, SIGNAL(changed()));
830 spellCommandCO->addItem(qt_("ispell"));
831 spellCommandCO->addItem(qt_("aspell"));
832 spellCommandCO->addItem(qt_("hspell"));
834 spellCommandCO->addItem(qt_("pspell (library)"));
837 spellCommandCO->addItem(qt_("aspell (library)"));
843 void PrefSpellchecker::apply(LyXRC & rc) const
845 switch (spellCommandCO->currentIndex()) {
849 rc.use_spell_lib = false;
850 rc.isp_command = fromqstr(spellCommandCO->currentText());
853 rc.use_spell_lib = true;
857 // FIXME: remove isp_use_alt_lang
858 rc.isp_alt_lang = fromqstr(altLanguageED->text());
859 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
860 // FIXME: remove isp_use_esc_chars
861 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
862 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
863 // FIXME: remove isp_use_pers_dict
864 rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
865 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
866 rc.isp_accept_compound = compoundWordCB->isChecked();
867 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
871 void PrefSpellchecker::update(LyXRC const & rc)
873 spellCommandCO->setCurrentIndex(0);
875 if (rc.isp_command == "ispell") {
876 spellCommandCO->setCurrentIndex(0);
877 } else if (rc.isp_command == "aspell") {
878 spellCommandCO->setCurrentIndex(1);
879 } else if (rc.isp_command == "hspell") {
880 spellCommandCO->setCurrentIndex(2);
883 if (rc.use_spell_lib) {
884 #if defined(USE_ASPELL) || defined(USE_PSPELL)
885 spellCommandCO->setCurrentIndex(3);
889 // FIXME: remove isp_use_alt_lang
890 altLanguageED->setText(toqstr(rc.isp_alt_lang));
891 // FIXME: remove isp_use_esc_chars
892 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
893 // FIXME: remove isp_use_pers_dict
894 persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
895 compoundWordCB->setChecked(rc.isp_accept_compound);
896 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
900 void PrefSpellchecker::select_dict()
902 docstring file(form_->controller().browsedict(
903 from_utf8(internal_path(fromqstr(persDictionaryED->text())))));
905 persDictionaryED->setText(toqstr(file));
910 /////////////////////////////////////////////////////////////////////
914 /////////////////////////////////////////////////////////////////////
917 PrefConverters::PrefConverters(GuiPrefsDialog * form, QWidget * parent)
918 : PrefModule(_("Converters"), form, parent)
922 connect(converterNewPB, SIGNAL(clicked()),
923 this, SLOT(update_converter()));
924 connect(converterRemovePB, SIGNAL(clicked()),
925 this, SLOT(remove_converter()));
926 connect(converterModifyPB, SIGNAL(clicked()),
927 this, SLOT(update_converter()));
928 connect(convertersLW, SIGNAL(currentRowChanged(int)),
929 this, SLOT(switch_converter()));
930 connect(converterFromCO, SIGNAL(activated(const QString&)),
931 this, SLOT(converter_changed()));
932 connect(converterToCO, SIGNAL(activated(const QString&)),
933 this, SLOT(converter_changed()));
934 connect(converterED, SIGNAL(textChanged(const QString&)),
935 this, SLOT(converter_changed()));
936 connect(converterFlagED, SIGNAL(textChanged(const QString&)),
937 this, SLOT(converter_changed()));
938 connect(converterNewPB, SIGNAL(clicked()),
939 this, SIGNAL(changed()));
940 connect(converterRemovePB, SIGNAL(clicked()),
941 this, SIGNAL(changed()));
942 connect(converterModifyPB, SIGNAL(clicked()),
943 this, SIGNAL(changed()));
944 connect(maxAgeLE, SIGNAL(textChanged(const QString&)),
945 this, SIGNAL(changed()));
947 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
948 //converterDefGB->setFocusProxy(convertersLW);
952 void PrefConverters::apply(LyXRC & rc) const
954 rc.use_converter_cache = cacheCB->isChecked();
955 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
959 void PrefConverters::update(LyXRC const & rc)
961 cacheCB->setChecked(rc.use_converter_cache);
963 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
964 maxAgeLE->setText(max_age);
969 void PrefConverters::updateGui()
971 // save current selection
972 QString current = converterFromCO->currentText()
973 + " -> " + converterToCO->currentText();
975 converterFromCO->clear();
976 converterToCO->clear();
978 Formats::const_iterator cit = form_->formats().begin();
979 Formats::const_iterator end = form_->formats().end();
980 for (; cit != end; ++cit) {
981 converterFromCO->addItem(toqstr(cit->prettyname()));
982 converterToCO->addItem(toqstr(cit->prettyname()));
985 // currentRowChanged(int) is also triggered when updating the listwidget
986 // block signals to avoid unnecessary calls to switch_converter()
987 convertersLW->blockSignals(true);
988 convertersLW->clear();
990 Converters::const_iterator ccit = form_->converters().begin();
991 Converters::const_iterator cend = form_->converters().end();
992 for (; ccit != cend; ++ccit) {
993 std::string const name =
994 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
995 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
996 new QListWidgetItem(toqstr(name), convertersLW, type);
998 convertersLW->sortItems(Qt::AscendingOrder);
999 convertersLW->blockSignals(false);
1001 // restore selection
1002 if (!current.isEmpty()) {
1003 QList<QListWidgetItem *> const item =
1004 convertersLW->findItems(current, Qt::MatchExactly);
1005 if (!item.isEmpty())
1006 convertersLW->setCurrentItem(item.at(0));
1009 // select first element if restoring failed
1010 if (convertersLW->currentRow() == -1)
1011 convertersLW->setCurrentRow(0);
1017 void PrefConverters::switch_converter()
1019 int const cnr = convertersLW->currentItem()->type();
1020 Converter const & c(form_->converters().get(cnr));
1021 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1022 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1023 converterED->setText(toqstr(c.command));
1024 converterFlagED->setText(toqstr(c.flags));
1030 void PrefConverters::converter_changed()
1036 void PrefConverters::updateButtons()
1038 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1039 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1040 int const sel = form_->converters().getNumber(from.name(), to.name());
1041 bool const known = !(sel < 0);
1042 bool const valid = !(converterED->text().isEmpty()
1043 || from.name() == to.name());
1045 int const cnr = convertersLW->currentItem()->type();
1046 Converter const & c(form_->converters().get(cnr));
1047 string const old_command = c.command;
1048 string const old_flag = c.flags;
1049 string const new_command(fromqstr(converterED->text()));
1050 string const new_flag(fromqstr(converterFlagED->text()));
1052 bool modified = ((old_command != new_command) || (old_flag != new_flag));
1054 converterModifyPB->setEnabled(valid && known && modified);
1055 converterNewPB->setEnabled(valid && !known);
1056 converterRemovePB->setEnabled(known);
1058 maxAgeLE->setEnabled(cacheCB->isChecked());
1059 maxAgeLA->setEnabled(cacheCB->isChecked());
1064 // specify unique from/to or it doesn't appear. This is really bad UI
1065 // this is why we can use the same function for both new and modify
1066 void PrefConverters::update_converter()
1068 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1069 Format const & to = form_->formats().get(converterToCO->currentIndex());
1070 string const flags = fromqstr(converterFlagED->text());
1071 string const command = fromqstr(converterED->text());
1073 Converter const * old =
1074 form_->converters().getConverter(from.name(), to.name());
1075 form_->converters().add(from.name(), to.name(), command, flags);
1078 form_->converters().updateLast(form_->formats());
1082 // Remove all files created by this converter from the cache, since
1083 // the modified converter might create different files.
1084 ConverterCache::get().remove_all(from.name(), to.name());
1088 void PrefConverters::remove_converter()
1090 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1091 Format const & to = form_->formats().get(converterToCO->currentIndex());
1092 form_->converters().erase(from.name(), to.name());
1096 // Remove all files created by this converter from the cache, since
1097 // a possible new converter might create different files.
1098 ConverterCache::get().remove_all(from.name(), to.name());
1102 void PrefConverters::on_cacheCB_stateChanged(int state)
1104 maxAgeLE->setEnabled(state == Qt::Checked);
1105 maxAgeLA->setEnabled(state == Qt::Checked);
1110 /////////////////////////////////////////////////////////////////////
1114 /////////////////////////////////////////////////////////////////////
1116 PrefCopiers::PrefCopiers(GuiPrefsDialog * form, QWidget * parent)
1117 : PrefModule(_("Copiers"), form, parent)
1121 connect(copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
1122 connect(copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
1123 connect(copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
1124 connect(AllCopiersLW, SIGNAL(currentRowChanged(int)),
1125 this, SLOT(switch_copierLB(int)));
1126 connect(copierFormatCO, SIGNAL(activated(int)),
1127 this, SLOT(switch_copierCO(int)));
1128 connect(copierNewPB, SIGNAL(clicked()),
1129 this, SIGNAL(changed()));
1130 connect(copierRemovePB, SIGNAL(clicked()),
1131 this, SIGNAL(changed()));
1132 connect(copierModifyPB, SIGNAL(clicked()),
1133 this, SIGNAL(changed()));
1134 connect(copierFormatCO, SIGNAL(activated(const QString &)),
1135 this, SLOT(copiers_changed()));
1136 connect(copierED, SIGNAL(textChanged(const QString &)),
1137 this, SLOT(copiers_changed()));
1141 void PrefCopiers::apply(LyXRC & /*rc*/) const
1146 void PrefCopiers::update(LyXRC const & /*rc*/)
1152 void PrefCopiers::updateView()
1154 // The choice widget
1155 // save current selection
1156 QString current = copierFormatCO->currentText();
1157 copierFormatCO->clear();
1159 for (Formats::const_iterator it = form_->formats().begin(),
1160 end = form_->formats().end();
1162 copierFormatCO->addItem(toqstr(it->prettyname()));
1165 // The browser widget
1166 AllCopiersLW->clear();
1168 for (Movers::const_iterator it = form_->movers().begin(),
1169 end = form_->movers().end();
1171 std::string const & command = it->second.command();
1172 if (command.empty())
1174 QString const pretty = toqstr(form_->formats().prettyName(it->first));
1175 AllCopiersLW->addItem(pretty);
1177 AllCopiersLW->sortItems(Qt::AscendingOrder);
1179 // restore selection
1180 if (!current.isEmpty()) {
1181 QList<QListWidgetItem *> item =
1182 AllCopiersLW->findItems(current, Qt::MatchExactly);
1184 AllCopiersLW->setCurrentItem(item.at(0));
1186 // select first element if restoring failed
1187 if (AllCopiersLW->currentRow() == -1)
1188 AllCopiersLW->setCurrentRow(0);
1194 class SamePrettyName {
1196 SamePrettyName(string const & n) : pretty_name_(n) {}
1198 bool operator()(Format const & fmt) const {
1199 return fmt.prettyname() == pretty_name_;
1203 string const pretty_name_;
1207 Format const * getFormat(std::string const & prettyname)
1209 Formats::const_iterator it = formats.begin();
1210 Formats::const_iterator const end = formats.end();
1211 it = std::find_if(it, end, SamePrettyName(prettyname));
1212 return it == end ? 0 : &*it;
1218 void PrefCopiers::switch_copierLB(int row)
1224 std::string const browser_text =
1225 fromqstr(AllCopiersLW->currentItem()->text());
1226 Format const * fmt = getFormat(browser_text);
1230 QString const gui_name = toqstr(fmt->prettyname());
1231 QString const command = toqstr(form_->movers().command(fmt->name()));
1234 int const combo_size = copierFormatCO->count();
1235 for (int i = 0; i < combo_size; ++i) {
1236 QString const text = copierFormatCO->itemText(i);
1237 if (text == gui_name) {
1238 copierFormatCO->setCurrentIndex(i);
1239 copierED->setText(command);
1247 void PrefCopiers::switch_copierCO(int row)
1252 std::string const combo_text =
1253 fromqstr(copierFormatCO->currentText());
1254 Format const * fmt = getFormat(combo_text);
1258 QString const command = toqstr(form_->movers().command(fmt->name()));
1259 copierED->setText(command);
1261 QListWidgetItem * const index = AllCopiersLW->currentItem();
1263 AllCopiersLW->setItemSelected(index, false);
1265 QString const gui_name = toqstr(fmt->prettyname());
1266 int const browser_size = AllCopiersLW->count();
1267 for (int i = 0; i < browser_size; ++i) {
1268 QString const text = AllCopiersLW->item(i)->text();
1269 if (text == gui_name) {
1270 QListWidgetItem * item = AllCopiersLW->item(i);
1271 AllCopiersLW->setItemSelected(item, true);
1278 void PrefCopiers::copiers_changed()
1284 void PrefCopiers::updateButtons()
1286 QString selected = copierFormatCO->currentText();
1289 for (int i = 0; i < AllCopiersLW->count(); ++i) {
1290 if (AllCopiersLW->item(i)->text() == selected)
1294 bool const valid = !copierED->text().isEmpty();
1296 Format const * fmt = getFormat(fromqstr(selected));
1297 string const old_command = form_->movers().command(fmt->name());
1298 string const new_command(fromqstr(copierED->text()));
1300 bool modified = (old_command != new_command);
1302 copierModifyPB->setEnabled(valid && known && modified);
1303 copierNewPB->setEnabled(valid && !known);
1304 copierRemovePB->setEnabled(known);
1308 void PrefCopiers::new_copier()
1310 std::string const combo_text =
1311 fromqstr(copierFormatCO->currentText());
1312 Format const * fmt = getFormat(combo_text);
1316 string const command = fromqstr(copierED->text());
1317 if (command.empty())
1320 form_->movers().set(fmt->name(), command);
1323 int const last = AllCopiersLW->count() - 1;
1324 AllCopiersLW->setCurrentRow(last);
1330 void PrefCopiers::modify_copier()
1332 std::string const combo_text =
1333 fromqstr(copierFormatCO->currentText());
1334 Format const * fmt = getFormat(combo_text);
1338 string const command = fromqstr(copierED->text());
1339 form_->movers().set(fmt->name(), command);
1346 void PrefCopiers::remove_copier()
1348 std::string const combo_text =
1349 fromqstr(copierFormatCO->currentText());
1350 Format const * fmt = getFormat(combo_text);
1354 string const & fmt_name = fmt->name();
1355 form_->movers().set(fmt_name, string());
1363 /////////////////////////////////////////////////////////////////////
1367 /////////////////////////////////////////////////////////////////////
1369 PrefFileformats::PrefFileformats(GuiPrefsDialog * form, QWidget * parent)
1370 : PrefModule(_("File formats"), form, parent)
1374 connect(formatNewPB, SIGNAL(clicked()),
1375 this, SLOT(new_format()));
1376 connect(formatRemovePB, SIGNAL(clicked()),
1377 this, SLOT(remove_format()));
1378 connect(formatModifyPB, SIGNAL(clicked()),
1379 this, SLOT(modify_format()));
1380 connect(formatsLW, SIGNAL(currentRowChanged(int)),
1381 this, SLOT(switch_format(int)));
1382 connect(formatED, SIGNAL(textChanged(const QString&)),
1383 this, SLOT(fileformat_changed()));
1384 connect(guiNameED, SIGNAL(textChanged(const QString&)),
1385 this, SLOT(fileformat_changed()));
1386 connect(shortcutED, SIGNAL(textChanged(const QString&)),
1387 this, SLOT(fileformat_changed()));
1388 connect(extensionED, SIGNAL(textChanged(const QString&)),
1389 this, SLOT(fileformat_changed()));
1390 connect(viewerED, SIGNAL(textChanged(const QString&)),
1391 this, SLOT(fileformat_changed()));
1392 connect(editorED, SIGNAL(textChanged(const QString&)),
1393 this, SLOT(fileformat_changed()));
1394 connect(documentCB, SIGNAL(clicked()),
1395 this, SLOT(fileformat_changed()));
1396 connect(vectorCB, SIGNAL(clicked()),
1397 this, SLOT(fileformat_changed()));
1398 connect(formatNewPB, SIGNAL(clicked()),
1399 this, SIGNAL(changed()));
1400 connect(formatRemovePB, SIGNAL(clicked()),
1401 this, SIGNAL(changed()));
1402 connect(formatModifyPB, SIGNAL(clicked()),
1403 this, SIGNAL(changed()));
1407 void PrefFileformats::apply(LyXRC & /*rc*/) const
1412 void PrefFileformats::update(LyXRC const & /*rc*/)
1418 void PrefFileformats::updateView()
1420 // save current selection
1421 QString current = guiNameED->text();
1423 // update listwidget with formats
1424 formatsLW->blockSignals(true);
1426 Formats::const_iterator cit = form_->formats().begin();
1427 Formats::const_iterator end = form_->formats().end();
1428 for (; cit != end; ++cit) {
1429 new QListWidgetItem(toqstr(cit->prettyname()),
1431 form_->formats().getNumber(cit->name()) );
1433 formatsLW->sortItems(Qt::AscendingOrder);
1434 formatsLW->blockSignals(false);
1436 // restore selection
1437 if (!current.isEmpty()) {
1438 QList<QListWidgetItem *> item = formatsLW->findItems(current, Qt::MatchExactly);
1440 formatsLW->setCurrentItem(item.at(0));
1442 // select first element if restoring failed
1443 if (formatsLW->currentRow() == -1)
1444 formatsLW->setCurrentRow(0);
1448 void PrefFileformats::switch_format(int nr)
1450 int const ftype = formatsLW->item(nr)->type();
1451 Format const f = form_->formats().get(ftype);
1453 formatED->setText(toqstr(f.name()));
1454 guiNameED->setText(toqstr(f.prettyname()));
1455 extensionED->setText(toqstr(f.extension()));
1456 shortcutED->setText(toqstr(f.shortcut()));
1457 viewerED->setText(toqstr(f.viewer()));
1458 editorED->setText(toqstr(f.editor()));
1459 documentCB->setChecked((f.documentFormat()));
1460 vectorCB->setChecked((f.vectorFormat()));
1466 void PrefFileformats::fileformat_changed()
1472 void PrefFileformats::updateButtons()
1474 QString const format = formatED->text();
1475 QString const gui_name = guiNameED->text();
1476 int const sel = form_->formats().getNumber(fromqstr(format));
1477 bool gui_name_known = false;
1479 for (int i = 0; i < formatsLW->count(); ++i) {
1480 if (formatsLW->item(i)->text() == gui_name) {
1481 gui_name_known = true;
1482 where = formatsLW->item(i)->type();
1486 // assure that a gui name cannot be chosen twice
1487 bool const known_otherwise = gui_name_known && where != sel;
1489 bool const known = sel >= 0;
1490 bool const valid = !formatED->text().isEmpty()
1491 && !guiNameED->text().isEmpty();
1493 int const ftype = formatsLW->currentItem()->type();
1494 Format const & f = form_->formats().get(ftype);
1495 string const old_pretty = f.prettyname();
1496 string const old_shortcut = f.shortcut();
1497 string const old_extension = f.extension();
1498 string const old_viewer = f.viewer();
1499 string const old_editor = f.editor();
1500 bool const old_document = f.documentFormat();
1501 bool const old_vector = f.vectorFormat();
1503 string const new_pretty = fromqstr(gui_name);
1504 string const new_shortcut = fromqstr(shortcutED->text());
1505 string const new_extension = fromqstr(extensionED->text());
1506 string const new_viewer = fromqstr(viewerED->text());
1507 string const new_editor = fromqstr(editorED->text());
1508 bool const new_document = documentCB->isChecked();
1509 bool const new_vector = vectorCB->isChecked();
1511 bool modified = old_pretty != new_pretty
1512 || old_shortcut != new_shortcut
1513 || old_extension != new_extension
1514 || old_viewer != new_viewer
1515 || old_editor != new_editor
1516 || old_document != new_document
1517 || old_vector != new_vector;
1519 formatModifyPB->setEnabled(valid && known && modified && !known_otherwise);
1520 formatNewPB->setEnabled(valid && !known && !gui_name_known);
1521 formatRemovePB->setEnabled(known);
1525 void PrefFileformats::new_format()
1527 string const name = fromqstr(formatED->text());
1528 string const prettyname = fromqstr(guiNameED->text());
1529 string const extension = fromqstr(extensionED->text());
1530 string const shortcut = fromqstr(shortcutED->text());
1531 string const viewer = fromqstr(viewerED->text());
1532 string const editor = fromqstr(editorED->text());
1533 int flags = Format::none;
1534 if (documentCB->isChecked())
1535 flags |= Format::document;
1536 if (vectorCB->isChecked())
1537 flags |= Format::vector;
1539 form_->formats().add(name, extension, prettyname, shortcut, viewer,
1541 form_->formats().sort();
1542 form_->converters().update(form_->formats());
1550 void PrefFileformats::modify_format()
1552 int const current_item = formatsLW->currentItem()->type();
1553 Format const & oldformat = form_->formats().get(current_item);
1554 form_->formats().erase(oldformat.name());
1560 void PrefFileformats::remove_format()
1562 int const nr = formatsLW->currentItem()->type();
1563 string const current_text = form_->formats().get(nr).name();
1564 if (form_->converters().formatIsUsed(current_text)) {
1565 Alert::error(_("Format in use"),
1566 _("Cannot remove a Format used by a Converter. "
1567 "Remove the converter first."));
1571 form_->formats().erase(current_text);
1572 form_->converters().update(form_->formats());
1580 /////////////////////////////////////////////////////////////////////
1584 /////////////////////////////////////////////////////////////////////
1586 PrefLanguage::PrefLanguage(QWidget * parent)
1587 : PrefModule(_("Language"), 0, parent)
1591 connect(rtlCB, SIGNAL(clicked()),
1592 this, SIGNAL(changed()));
1593 connect(markForeignCB, SIGNAL(clicked()),
1594 this, SIGNAL(changed()));
1595 connect(autoBeginCB, SIGNAL(clicked()),
1596 this, SIGNAL(changed()));
1597 connect(autoEndCB, SIGNAL(clicked()),
1598 this, SIGNAL(changed()));
1599 connect(useBabelCB, SIGNAL(clicked()),
1600 this, SIGNAL(changed()));
1601 connect(globalCB, SIGNAL(clicked()),
1602 this, SIGNAL(changed()));
1603 connect(languagePackageED, SIGNAL(textChanged(const QString&)),
1604 this, SIGNAL(changed()));
1605 connect(startCommandED, SIGNAL(textChanged(const QString&)),
1606 this, SIGNAL(changed()));
1607 connect(endCommandED, SIGNAL(textChanged(const QString&)),
1608 this, SIGNAL(changed()));
1609 connect(defaultLanguageCO, SIGNAL(activated(int)),
1610 this, SIGNAL(changed()));
1612 defaultLanguageCO->clear();
1614 // store the lang identifiers for later
1615 std::vector<LanguagePair> const langs = frontend::getLanguageData(false);
1616 std::vector<LanguagePair>::const_iterator lit = langs.begin();
1617 std::vector<LanguagePair>::const_iterator lend = langs.end();
1619 for (; lit != lend; ++lit) {
1620 defaultLanguageCO->addItem(toqstr(lit->first));
1621 lang_.push_back(lit->second);
1626 void PrefLanguage::apply(LyXRC & rc) const
1628 // FIXME: remove rtl_support bool
1629 rc.rtl_support = rtlCB->isChecked();
1630 rc.mark_foreign_language = markForeignCB->isChecked();
1631 rc.language_auto_begin = autoBeginCB->isChecked();
1632 rc.language_auto_end = autoEndCB->isChecked();
1633 rc.language_use_babel = useBabelCB->isChecked();
1634 rc.language_global_options = globalCB->isChecked();
1635 rc.language_package = fromqstr(languagePackageED->text());
1636 rc.language_command_begin = fromqstr(startCommandED->text());
1637 rc.language_command_end = fromqstr(endCommandED->text());
1638 rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1642 void PrefLanguage::update(LyXRC const & rc)
1644 // FIXME: remove rtl_support bool
1645 rtlCB->setChecked(rc.rtl_support);
1646 markForeignCB->setChecked(rc.mark_foreign_language);
1647 autoBeginCB->setChecked(rc.language_auto_begin);
1648 autoEndCB->setChecked(rc.language_auto_end);
1649 useBabelCB->setChecked(rc.language_use_babel);
1650 globalCB->setChecked(rc.language_global_options);
1651 languagePackageED->setText(toqstr(rc.language_package));
1652 startCommandED->setText(toqstr(rc.language_command_begin));
1653 endCommandED->setText(toqstr(rc.language_command_end));
1655 int const pos = int(findPos_helper(lang_, rc.default_language));
1656 defaultLanguageCO->setCurrentIndex(pos);
1660 /////////////////////////////////////////////////////////////////////
1664 /////////////////////////////////////////////////////////////////////
1666 PrefPrinter::PrefPrinter(QWidget * parent)
1667 : PrefModule(_("Printer"), 0, parent)
1671 connect(printerAdaptCB, SIGNAL(clicked()),
1672 this, SIGNAL(changed()));
1673 connect(printerCommandED, SIGNAL(textChanged(const QString&)),
1674 this, SIGNAL(changed()));
1675 connect(printerNameED, SIGNAL(textChanged(const QString&)),
1676 this, SIGNAL(changed()));
1677 connect(printerPageRangeED, SIGNAL(textChanged(const QString&)),
1678 this, SIGNAL(changed()));
1679 connect(printerCopiesED, SIGNAL(textChanged(const QString&)),
1680 this, SIGNAL(changed()));
1681 connect(printerReverseED, SIGNAL(textChanged(const QString&)),
1682 this, SIGNAL(changed()));
1683 connect(printerToPrinterED, SIGNAL(textChanged(const QString&)),
1684 this, SIGNAL(changed()));
1685 connect(printerExtensionED, SIGNAL(textChanged(const QString&)),
1686 this, SIGNAL(changed()));
1687 connect(printerSpoolCommandED, SIGNAL(textChanged(const QString&)),
1688 this, SIGNAL(changed()));
1689 connect(printerPaperTypeED, SIGNAL(textChanged(const QString&)),
1690 this, SIGNAL(changed()));
1691 connect(printerEvenED, SIGNAL(textChanged(const QString&)),
1692 this, SIGNAL(changed()));
1693 connect(printerOddED, SIGNAL(textChanged(const QString&)),
1694 this, SIGNAL(changed()));
1695 connect(printerCollatedED, SIGNAL(textChanged(const QString&)),
1696 this, SIGNAL(changed()));
1697 connect(printerLandscapeED, SIGNAL(textChanged(const QString&)),
1698 this, SIGNAL(changed()));
1699 connect(printerToFileED, SIGNAL(textChanged(const QString&)),
1700 this, SIGNAL(changed()));
1701 connect(printerExtraED, SIGNAL(textChanged(const QString&)),
1702 this, SIGNAL(changed()));
1703 connect(printerSpoolPrefixED, SIGNAL(textChanged(const QString&)),
1704 this, SIGNAL(changed()));
1705 connect(printerPaperSizeED, SIGNAL(textChanged(const QString&)),
1706 this, SIGNAL(changed()));
1710 void PrefPrinter::apply(LyXRC & rc) const
1712 rc.print_adapt_output = printerAdaptCB->isChecked();
1713 rc.print_command = fromqstr(printerCommandED->text());
1714 rc.printer = fromqstr(printerNameED->text());
1716 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1717 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1718 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1719 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1720 rc.print_file_extension = fromqstr(printerExtensionED->text());
1721 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1722 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1723 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1724 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1725 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1726 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1727 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1728 rc.print_extra_options = fromqstr(printerExtraED->text());
1729 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1730 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1734 void PrefPrinter::update(LyXRC const & rc)
1736 printerAdaptCB->setChecked(rc.print_adapt_output);
1737 printerCommandED->setText(toqstr(rc.print_command));
1738 printerNameED->setText(toqstr(rc.printer));
1740 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1741 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1742 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1743 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1744 printerExtensionED->setText(toqstr(rc.print_file_extension));
1745 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1746 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1747 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1748 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1749 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1750 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1751 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1752 printerExtraED->setText(toqstr(rc.print_extra_options));
1753 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1754 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1758 /////////////////////////////////////////////////////////////////////
1760 // PrefUserInterface
1762 /////////////////////////////////////////////////////////////////////
1764 PrefUserInterface::PrefUserInterface(GuiPrefsDialog * form, QWidget * parent)
1765 : PrefModule(_("User interface"), form, parent)
1769 connect(autoSaveCB, SIGNAL(toggled(bool)),
1770 autoSaveLA, SLOT(setEnabled(bool)));
1771 connect(autoSaveCB, SIGNAL(toggled(bool)),
1772 autoSaveSB, SLOT(setEnabled(bool)));
1773 connect(autoSaveCB, SIGNAL(toggled(bool)),
1774 TextLabel1, SLOT(setEnabled(bool)));
1775 connect(uiFilePB, SIGNAL(clicked()),
1776 this, SLOT(select_ui()));
1777 connect(bindFilePB, SIGNAL(clicked()),
1778 this, SLOT(select_bind()));
1779 connect(uiFileED, SIGNAL(textChanged(const QString &)),
1780 this, SIGNAL(changed()));
1781 connect(bindFileED, SIGNAL(textChanged(const QString &)),
1782 this, SIGNAL(changed()));
1783 connect(restoreCursorCB, SIGNAL(clicked()),
1784 this, SIGNAL(changed()));
1785 connect(loadSessionCB, SIGNAL(clicked()),
1786 this, SIGNAL(changed()));
1787 connect(loadWindowSizeCB, SIGNAL(clicked()),
1788 this, SIGNAL(changed()));
1789 connect(loadWindowLocationCB, SIGNAL(clicked()),
1790 this, SIGNAL(changed()));
1791 connect(windowWidthSB, SIGNAL(valueChanged(int)),
1792 this, SIGNAL(changed()));
1793 connect(windowHeightSB, SIGNAL(valueChanged(int)),
1794 this, SIGNAL(changed()));
1795 connect(cursorFollowsCB, SIGNAL(clicked()),
1796 this, SIGNAL(changed()));
1797 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1798 this, SIGNAL(changed()));
1799 connect(autoSaveCB, SIGNAL(clicked()),
1800 this, SIGNAL(changed()));
1801 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1802 this, SIGNAL(changed()));
1803 lastfilesSB->setMaximum(maxlastfiles);
1807 void PrefUserInterface::apply(LyXRC & rc) const
1809 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1810 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1811 rc.use_lastfilepos = restoreCursorCB->isChecked();
1812 rc.load_session = loadSessionCB->isChecked();
1813 if (loadWindowSizeCB->isChecked()) {
1814 rc.geometry_width = 0;
1815 rc.geometry_height = 0;
1817 rc.geometry_width = windowWidthSB->value();
1818 rc.geometry_height = windowHeightSB->value();
1820 rc.geometry_xysaved = loadWindowLocationCB->isChecked();
1821 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1822 rc.autosave = autoSaveSB->value() * 60;
1823 rc.make_backup = autoSaveCB->isChecked();
1824 rc.num_lastfiles = lastfilesSB->value();
1828 void PrefUserInterface::update(LyXRC const & rc)
1830 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1831 bindFileED->setText(toqstr(external_path(rc.bind_file)));
1832 restoreCursorCB->setChecked(rc.use_lastfilepos);
1833 loadSessionCB->setChecked(rc.load_session);
1834 bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
1835 loadWindowSizeCB->setChecked(loadWindowSize);
1836 if (!loadWindowSize) {
1837 windowWidthSB->setValue(rc.geometry_width);
1838 windowHeightSB->setValue(rc.geometry_height);
1840 loadWindowLocationCB->setChecked(rc.geometry_xysaved);
1841 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1842 // convert to minutes
1843 int mins(rc.autosave / 60);
1844 if (rc.autosave && !mins)
1846 autoSaveSB->setValue(mins);
1847 autoSaveCB->setChecked(rc.make_backup);
1848 lastfilesSB->setValue(rc.num_lastfiles);
1852 void PrefUserInterface::select_ui()
1854 docstring const name =
1855 from_utf8(internal_path(fromqstr(uiFileED->text())));
1856 docstring file = form_->controller().browseUI(name);
1858 uiFileED->setText(toqstr(file));
1862 void PrefUserInterface::select_bind()
1864 docstring const name =
1865 from_utf8(internal_path(fromqstr(bindFileED->text())));
1866 docstring file = form_->controller().browsebind(name);
1868 bindFileED->setText(toqstr(file));
1872 void PrefUserInterface::on_loadWindowSizeCB_toggled(bool loadwindowsize)
1874 windowWidthLA->setDisabled(loadwindowsize);
1875 windowHeightLA->setDisabled(loadwindowsize);
1876 windowWidthSB->setDisabled(loadwindowsize);
1877 windowHeightSB->setDisabled(loadwindowsize);
1881 PrefIdentity::PrefIdentity(QWidget * parent)
1882 : PrefModule(_("Identity"), 0, parent)
1886 connect(nameED, SIGNAL(textChanged(const QString&)),
1887 this, SIGNAL(changed()));
1888 connect(emailED, SIGNAL(textChanged(const QString&)),
1889 this, SIGNAL(changed()));
1893 void PrefIdentity::apply(LyXRC & rc) const
1895 rc.user_name = fromqstr(nameED->text());
1896 rc.user_email = fromqstr(emailED->text());
1900 void PrefIdentity::update(LyXRC const & rc)
1902 nameED->setText(toqstr(rc.user_name));
1903 emailED->setText(toqstr(rc.user_email));
1908 /////////////////////////////////////////////////////////////////////
1912 /////////////////////////////////////////////////////////////////////
1914 GuiPrefsDialog::GuiPrefsDialog(LyXView & lv)
1915 : GuiDialog(lv, "prefs")
1918 setViewTitle(_("Preferences"));
1919 setController(new ControlPrefs(*this));
1921 QDialog::setModal(false);
1923 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
1924 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
1925 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
1926 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
1928 add(new PrefUserInterface(this));
1929 add(new PrefScreenFonts(this));
1930 add(new PrefColors(this));
1931 add(new PrefDisplay);
1932 add(new PrefKeyboard(this));
1934 add(new PrefPaths(this));
1936 add(new PrefIdentity);
1938 add(new PrefLanguage);
1939 add(new PrefSpellchecker(this));
1941 add(new PrefPrinter);
1943 add(new PrefPlaintext);
1944 add(new PrefLatex(this));
1946 PrefConverters * converters = new PrefConverters(this);
1947 PrefFileformats * formats = new PrefFileformats(this);
1948 connect(formats, SIGNAL(formatsChanged()),
1949 converters, SLOT(updateGui()));
1953 add(new PrefCopiers(this));
1956 prefsPS->setCurrentPanel(_("User interface"));
1957 // FIXME: hack to work around resizing bug in Qt >= 4.2
1958 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1959 #if QT_VERSION >= 0x040200
1960 prefsPS->updateGeometry();
1963 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
1965 bc().setApply(applyPB);
1966 bc().setCancel(closePB);
1967 bc().setRestore(restorePB);
1971 ControlPrefs & GuiPrefsDialog::controller()
1973 return static_cast<ControlPrefs &>(GuiDialog::controller());
1977 void GuiPrefsDialog::add(PrefModule * module)
1979 BOOST_ASSERT(module);
1980 prefsPS->addPanel(module, module->title());
1981 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
1982 modules_.push_back(module);
1986 void GuiPrefsDialog::closeEvent(QCloseEvent * e)
1993 void GuiPrefsDialog::change_adaptor()
1999 void GuiPrefsDialog::apply(LyXRC & rc) const
2001 size_t end = modules_.size();
2002 for (size_t i = 0; i != end; ++i)
2003 modules_[i]->apply(rc);
2007 void GuiPrefsDialog::updateRc(LyXRC const & rc)
2009 size_t const end = modules_.size();
2010 for (size_t i = 0; i != end; ++i)
2011 modules_[i]->update(rc);
2015 Converters & GuiPrefsDialog::converters()
2017 return controller().converters();
2021 Formats & GuiPrefsDialog::formats()
2023 return controller().formats();
2027 Movers & GuiPrefsDialog::movers()
2029 return controller().movers();
2033 void GuiPrefsDialog::applyView()
2035 apply(controller().rc());
2038 void GuiPrefsDialog::updateContents()
2040 updateRc(controller().rc());
2043 } // namespace frontend
2046 #include "GuiPrefs_moc.cpp"