3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
16 #include "ColorCache.h"
17 #include "FileDialog.h"
18 #include "GuiApplication.h"
19 #include "GuiFontExample.h"
20 #include "GuiFontLoader.h"
21 #include "GuiKeySymbol.h"
22 #include "qt_helpers.h"
24 #include "BufferList.h"
27 #include "ConverterCache.h"
28 #include "FontEnums.h"
29 #include "FuncRequest.h"
31 #include "KeySequence.h"
33 #include "LyXAction.h"
34 #include "PanelStack.h"
38 #include "support/debug.h"
39 #include "support/FileName.h"
40 #include "support/filetools.h"
41 #include "support/foreach.h"
42 #include "support/gettext.h"
43 #include "support/lstrings.h"
44 #include "support/os.h"
45 #include "support/Package.h"
47 #include "graphics/GraphicsTypes.h"
49 #include "frontends/alert.h"
50 #include "frontends/Application.h"
51 #include "frontends/FontLoader.h"
53 #include <QAbstractItemModel>
55 #include <QColorDialog>
56 #include <QFontDatabase>
57 #include <QHeaderView>
59 #include <QMessageBox>
60 #include <QPixmapCache>
61 #include <QPushButton>
64 #include <QTreeWidget>
65 #include <QTreeWidgetItem>
75 using namespace lyx::support;
76 using namespace lyx::support::os;
81 /////////////////////////////////////////////////////////////////////
85 /////////////////////////////////////////////////////////////////////
87 /** Launch a file dialog and return the chosen file.
88 filename: a suggested filename.
89 title: the title of the dialog.
91 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
93 QString browseFile(QString const & filename,
94 QString const & title,
95 QStringList const & filters,
97 QString const & label1 = QString(),
98 QString const & dir1 = QString(),
99 QString const & label2 = QString(),
100 QString const & dir2 = QString(),
101 QString const & fallback_dir = QString())
103 QString lastPath = ".";
104 if (!filename.isEmpty())
105 lastPath = onlyPath(filename);
106 else if(!fallback_dir.isEmpty())
107 lastPath = fallback_dir;
109 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
110 dlg.setButton2(label1, dir1);
111 dlg.setButton2(label2, dir2);
113 FileDialog::Result result;
116 result = dlg.save(lastPath, filters, onlyFilename(filename));
118 result = dlg.open(lastPath, filters, onlyFilename(filename));
120 return result.second;
124 /** Wrapper around browseFile which tries to provide a filename
125 * relative to the user or system directory. The dir, name and ext
126 * parameters have the same meaning as in the
127 * support::LibFileSearch function.
129 QString browseLibFile(QString const & dir,
130 QString const & name,
132 QString const & title,
133 QStringList const & filters)
136 QString const label1 = qt_("System files|#S#s");
138 toqstr(addName(package().system_support().absFilename(), fromqstr(dir)));
140 QString const label2 = qt_("User files|#U#u");
142 toqstr(addName(package().user_support().absFilename(), fromqstr(dir)));
144 QString const result = browseFile(toqstr(
145 libFileSearch(dir, name, ext).absFilename()),
146 title, filters, false, dir1, dir2, QString(), QString(), dir1);
148 // remove the extension if it is the default one
150 if (getExtension(result) == ext)
151 noextresult = removeExtension(result);
153 noextresult = result;
155 // remove the directory, if it is the default one
156 QString const file = onlyFilename(noextresult);
157 if (toqstr(libFileSearch(dir, file, ext).absFilename()) == result)
164 /** Launch a file dialog and return the chosen directory.
165 pathname: a suggested pathname.
166 title: the title of the dialog.
167 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
169 QString browseDir(QString const & pathname,
170 QString const & title,
171 QString const & label1 = QString(),
172 QString const & dir1 = QString(),
173 QString const & label2 = QString(),
174 QString const & dir2 = QString())
176 QString lastPath = ".";
177 if (!pathname.isEmpty())
178 lastPath = onlyPath(pathname);
180 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
181 dlg.setButton1(label1, dir1);
182 dlg.setButton2(label2, dir2);
184 FileDialog::Result const result =
185 dlg.opendir(lastPath, onlyFilename(pathname));
187 return result.second;
191 } // namespace frontend
194 QString browseRelFile(QString const & filename, QString const & refpath,
195 QString const & title, QStringList const & filters, bool save,
196 QString const & label1, QString const & dir1,
197 QString const & label2, QString const & dir2)
199 QString const fname = makeAbsPath(filename, refpath);
202 QString const outname =
203 frontend::browseFile(fname, title, filters, save, label1, dir1, label2, dir2);
205 QString const reloutname =
206 toqstr(makeRelPath(qstring_to_ucs4(outname), qstring_to_ucs4(refpath)));
208 if (reloutname.startsWith("../"))
216 /////////////////////////////////////////////////////////////////////
220 /////////////////////////////////////////////////////////////////////
224 string const catLookAndFeel = N_("Look & Feel");
225 string const catEditing = N_("Editing");
226 string const catLanguage = N_("Language Settings");
227 string const catOutput = N_("Output");
228 string const catFiles = N_("File Handling");
230 static void parseFontName(QString const & mangled0,
231 string & name, string & foundry)
233 string mangled = fromqstr(mangled0);
234 size_t const idx = mangled.find('[');
235 if (idx == string::npos || idx == 0) {
239 name = mangled.substr(0, idx - 1),
240 foundry = mangled.substr(idx + 1, mangled.size() - idx - 2);
245 static void setComboxFont(QComboBox * cb, string const & family,
246 string const & foundry)
248 QString fontname = toqstr(family);
249 if (!foundry.empty())
250 fontname += " [" + toqstr(foundry) + ']';
252 for (int i = 0; i != cb->count(); ++i) {
253 if (cb->itemText(i) == fontname) {
254 cb->setCurrentIndex(i);
259 // Try matching without foundry name
261 // We count in reverse in order to prefer the Xft foundry
262 for (int i = cb->count(); --i >= 0;) {
263 string name, foundry;
264 parseFontName(cb->itemText(i), name, foundry);
265 if (compare_ascii_no_case(name, family) == 0) {
266 cb->setCurrentIndex(i);
271 // family alone can contain e.g. "Helvetica [Adobe]"
272 string tmpname, tmpfoundry;
273 parseFontName(toqstr(family), tmpname, tmpfoundry);
275 // We count in reverse in order to prefer the Xft foundry
276 for (int i = cb->count(); --i >= 0; ) {
277 string name, foundry;
278 parseFontName(cb->itemText(i), name, foundry);
279 if (compare_ascii_no_case(name, foundry) == 0) {
280 cb->setCurrentIndex(i);
285 // Bleh, default fonts, and the names couldn't be found. Hack
289 font.setKerning(false);
291 QString const font_family = toqstr(family);
292 if (font_family == guiApp->romanFontName()) {
293 font.setStyleHint(QFont::Serif);
294 font.setFamily(font_family);
295 } else if (font_family == guiApp->sansFontName()) {
296 font.setStyleHint(QFont::SansSerif);
297 font.setFamily(font_family);
298 } else if (font_family == guiApp->typewriterFontName()) {
299 font.setStyleHint(QFont::TypeWriter);
300 font.setFamily(font_family);
302 LYXERR0("FAILED to find the default font: '"
303 << foundry << "', '" << family << '\'');
307 QFontInfo info(font);
308 string default_font_name, dummyfoundry;
309 parseFontName(info.family(), default_font_name, dummyfoundry);
310 LYXERR0("Apparent font is " << default_font_name);
312 for (int i = 0; i < cb->count(); ++i) {
313 LYXERR0("Looking at " << cb->itemText(i));
314 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
315 default_font_name) == 0) {
316 cb->setCurrentIndex(i);
321 LYXERR0("FAILED to find the font: '"
322 << foundry << "', '" << family << '\'');
327 /////////////////////////////////////////////////////////////////////
331 /////////////////////////////////////////////////////////////////////
333 PrefPlaintext::PrefPlaintext(GuiPreferences * form)
334 : PrefModule(qt_(catOutput), qt_("Plain text"), form)
337 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
338 this, SIGNAL(changed()));
342 void PrefPlaintext::apply(LyXRC & rc) const
344 rc.plaintext_linelen = plaintextLinelengthSB->value();
348 void PrefPlaintext::update(LyXRC const & rc)
350 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
354 /////////////////////////////////////////////////////////////////////
358 /////////////////////////////////////////////////////////////////////
360 class StrftimeValidator : public QValidator
363 StrftimeValidator(QWidget *);
364 QValidator::State validate(QString & input, int & pos) const;
368 StrftimeValidator::StrftimeValidator(QWidget * parent)
374 QValidator::State StrftimeValidator::validate(QString & input, int & /*pos*/) const
376 if (is_valid_strftime(fromqstr(input)))
377 return QValidator::Acceptable;
379 return QValidator::Intermediate;
383 /////////////////////////////////////////////////////////////////////
387 /////////////////////////////////////////////////////////////////////
389 PrefDate::PrefDate(GuiPreferences * form)
390 : PrefModule(qt_(catOutput), qt_("Date format"), form)
393 DateED->setValidator(new StrftimeValidator(DateED));
394 connect(DateED, SIGNAL(textChanged(QString)),
395 this, SIGNAL(changed()));
399 void PrefDate::on_DateED_textChanged(const QString &)
401 QString t = DateED->text();
403 bool valid = DateED->validator()->validate(t, p)
404 == QValidator::Acceptable;
405 setValid(DateLA, valid);
409 void PrefDate::apply(LyXRC & rc) const
411 rc.date_insert_format = fromqstr(DateED->text());
415 void PrefDate::update(LyXRC const & rc)
417 DateED->setText(toqstr(rc.date_insert_format));
421 /////////////////////////////////////////////////////////////////////
425 /////////////////////////////////////////////////////////////////////
427 PrefInput::PrefInput(GuiPreferences * form)
428 : PrefModule(qt_(catEditing), qt_("Keyboard/Mouse"), form)
432 connect(keymapCB, SIGNAL(clicked()),
433 this, SIGNAL(changed()));
434 connect(firstKeymapED, SIGNAL(textChanged(QString)),
435 this, SIGNAL(changed()));
436 connect(secondKeymapED, SIGNAL(textChanged(QString)),
437 this, SIGNAL(changed()));
438 connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
439 this, SIGNAL(changed()));
443 void PrefInput::apply(LyXRC & rc) const
445 // FIXME: can derive CB from the two EDs
446 rc.use_kbmap = keymapCB->isChecked();
447 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
448 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
449 rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
453 void PrefInput::update(LyXRC const & rc)
455 // FIXME: can derive CB from the two EDs
456 keymapCB->setChecked(rc.use_kbmap);
457 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
458 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
459 mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
463 QString PrefInput::testKeymap(QString const & keymap)
465 return form_->browsekbmap(internalPath(keymap));
469 void PrefInput::on_firstKeymapPB_clicked(bool)
471 QString const file = testKeymap(firstKeymapED->text());
473 firstKeymapED->setText(file);
477 void PrefInput::on_secondKeymapPB_clicked(bool)
479 QString const file = testKeymap(secondKeymapED->text());
481 secondKeymapED->setText(file);
485 void PrefInput::on_keymapCB_toggled(bool keymap)
487 firstKeymapLA->setEnabled(keymap);
488 secondKeymapLA->setEnabled(keymap);
489 firstKeymapED->setEnabled(keymap);
490 secondKeymapED->setEnabled(keymap);
491 firstKeymapPB->setEnabled(keymap);
492 secondKeymapPB->setEnabled(keymap);
496 /////////////////////////////////////////////////////////////////////
500 /////////////////////////////////////////////////////////////////////
502 PrefCompletion::PrefCompletion(GuiPreferences * form)
503 : PrefModule(qt_(catEditing), qt_("Input Completion"), form)
507 connect(inlineDelaySB, SIGNAL(valueChanged(double)),
508 this, SIGNAL(changed()));
509 connect(inlineMathCB, SIGNAL(clicked()),
510 this, SIGNAL(changed()));
511 connect(inlineTextCB, SIGNAL(clicked()),
512 this, SIGNAL(changed()));
513 connect(inlineDotsCB, SIGNAL(clicked()),
514 this, SIGNAL(changed()));
515 connect(popupDelaySB, SIGNAL(valueChanged(double)),
516 this, SIGNAL(changed()));
517 connect(popupMathCB, SIGNAL(clicked()),
518 this, SIGNAL(changed()));
519 connect(popupTextCB, SIGNAL(clicked()),
520 this, SIGNAL(changed()));
521 connect(popupAfterCompleteCB, SIGNAL(clicked()),
522 this, SIGNAL(changed()));
523 connect(cursorTextCB, SIGNAL(clicked()),
524 this, SIGNAL(changed()));
528 void PrefCompletion::on_inlineTextCB_clicked()
534 void PrefCompletion::on_popupTextCB_clicked()
540 void PrefCompletion::enableCB()
542 cursorTextCB->setEnabled(
543 popupTextCB->isChecked() || inlineTextCB->isChecked());
547 void PrefCompletion::apply(LyXRC & rc) const
549 rc.completion_inline_delay = inlineDelaySB->value();
550 rc.completion_inline_math = inlineMathCB->isChecked();
551 rc.completion_inline_text = inlineTextCB->isChecked();
552 rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
553 rc.completion_popup_delay = popupDelaySB->value();
554 rc.completion_popup_math = popupMathCB->isChecked();
555 rc.completion_popup_text = popupTextCB->isChecked();
556 rc.completion_cursor_text = cursorTextCB->isChecked();
557 rc.completion_popup_after_complete =
558 popupAfterCompleteCB->isChecked();
562 void PrefCompletion::update(LyXRC const & rc)
564 inlineDelaySB->setValue(rc.completion_inline_delay);
565 inlineMathCB->setChecked(rc.completion_inline_math);
566 inlineTextCB->setChecked(rc.completion_inline_text);
567 inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
568 popupDelaySB->setValue(rc.completion_popup_delay);
569 popupMathCB->setChecked(rc.completion_popup_math);
570 popupTextCB->setChecked(rc.completion_popup_text);
571 cursorTextCB->setChecked(rc.completion_cursor_text);
572 popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
578 /////////////////////////////////////////////////////////////////////
582 /////////////////////////////////////////////////////////////////////
584 PrefLatex::PrefLatex(GuiPreferences * form)
585 : PrefModule(qt_(catOutput), qt_("LaTeX"), form)
588 connect(latexEncodingED, SIGNAL(textChanged(QString)),
589 this, SIGNAL(changed()));
590 connect(latexChecktexED, SIGNAL(textChanged(QString)),
591 this, SIGNAL(changed()));
592 connect(latexBibtexCO, SIGNAL(activated(int)),
593 this, SIGNAL(changed()));
594 connect(latexBibtexED, SIGNAL(textChanged(QString)),
595 this, SIGNAL(changed()));
596 connect(latexJBibtexED, SIGNAL(textChanged(QString)),
597 this, SIGNAL(changed()));
598 connect(latexIndexCO, SIGNAL(activated(int)),
599 this, SIGNAL(changed()));
600 connect(latexIndexED, SIGNAL(textChanged(QString)),
601 this, SIGNAL(changed()));
602 connect(latexJIndexED, SIGNAL(textChanged(QString)),
603 this, SIGNAL(changed()));
604 connect(latexAutoresetCB, SIGNAL(clicked()),
605 this, SIGNAL(changed()));
606 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
607 this, SIGNAL(changed()));
608 connect(latexPaperSizeCO, SIGNAL(activated(int)),
609 this, SIGNAL(changed()));
611 #if defined(__CYGWIN__) || defined(_WIN32)
612 pathCB->setVisible(true);
613 connect(pathCB, SIGNAL(clicked()),
614 this, SIGNAL(changed()));
616 pathCB->setVisible(false);
621 void PrefLatex::on_latexBibtexCO_activated(int n)
623 QString const bibtex = latexBibtexCO->itemData(n).toString();
624 if (bibtex.isEmpty()) {
625 latexBibtexED->clear();
626 latexBibtexOptionsLA->setText(qt_("C&ommand:"));
629 for (set<string>::const_iterator it = bibtex_alternatives.begin();
630 it != bibtex_alternatives.end(); ++it) {
631 QString const bib = toqstr(*it);
632 int ind = bib.indexOf(" ");
633 QString sel_command = bib.left(ind);
634 QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
635 if (bibtex == sel_command) {
637 latexBibtexED->clear();
639 latexBibtexED->setText(sel_options.trimmed());
642 latexBibtexOptionsLA->setText(qt_("&Options:"));
646 void PrefLatex::on_latexIndexCO_activated(int n)
648 QString const index = latexIndexCO->itemData(n).toString();
649 if (index.isEmpty()) {
650 latexIndexED->clear();
651 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
654 for (set<string>::const_iterator it = index_alternatives.begin();
655 it != index_alternatives.end(); ++it) {
656 QString const idx = toqstr(*it);
657 int ind = idx.indexOf(" ");
658 QString sel_command = idx.left(ind);
659 QString sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
660 if (index == sel_command) {
662 latexIndexED->clear();
664 latexIndexED->setText(sel_options.trimmed());
667 latexIndexOptionsLA->setText(qt_("Op&tions:"));
671 void PrefLatex::apply(LyXRC & rc) const
673 // If bibtex is not empty, bibopt contains the options, otherwise
674 // it is a customized bibtex command with options.
675 QString const bibtex = latexBibtexCO->itemData(
676 latexBibtexCO->currentIndex()).toString();
677 QString const bibopt = latexBibtexED->text();
678 if (bibtex.isEmpty())
679 rc.bibtex_command = fromqstr(bibopt);
680 else if (bibopt.isEmpty())
681 rc.bibtex_command = fromqstr(bibtex);
683 rc.bibtex_command = fromqstr(bibtex) + " " + fromqstr(bibopt);
685 // If index is not empty, idxopt contains the options, otherwise
686 // it is a customized index command with options.
687 QString const index = latexIndexCO->itemData(
688 latexIndexCO->currentIndex()).toString();
689 QString const idxopt = latexIndexED->text();
691 rc.index_command = fromqstr(idxopt);
692 else if (idxopt.isEmpty())
693 rc.index_command = fromqstr(index);
695 rc.index_command = fromqstr(index) + " " + fromqstr(idxopt);
697 rc.fontenc = fromqstr(latexEncodingED->text());
698 rc.chktex_command = fromqstr(latexChecktexED->text());
699 rc.jbibtex_command = fromqstr(latexJBibtexED->text());
700 rc.jindex_command = fromqstr(latexJIndexED->text());
701 rc.nomencl_command = fromqstr(latexNomenclED->text());
702 rc.auto_reset_options = latexAutoresetCB->isChecked();
703 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
704 rc.default_papersize =
705 form_->toPaperSize(latexPaperSizeCO->currentIndex());
706 #if defined(__CYGWIN__) || defined(_WIN32)
707 rc.windows_style_tex_paths = pathCB->isChecked();
712 void PrefLatex::update(LyXRC const & rc)
714 latexBibtexCO->clear();
716 latexBibtexCO->addItem(qt_("Custom"), QString());
717 for (set<string>::const_iterator it = rc.bibtex_alternatives.begin();
718 it != rc.bibtex_alternatives.end(); ++it) {
719 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
720 latexBibtexCO->addItem(command, command);
723 bibtex_alternatives = rc.bibtex_alternatives;
725 QString const bib = toqstr(rc.bibtex_command);
726 int ind = bib.indexOf(" ");
727 QString sel_command = bib.left(ind);
728 QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
730 int pos = latexBibtexCO->findData(sel_command);
732 latexBibtexCO->setCurrentIndex(pos);
733 latexBibtexED->setText(sel_options.trimmed());
734 latexBibtexOptionsLA->setText(qt_("&Options:"));
736 latexBibtexED->setText(toqstr(rc.bibtex_command));
737 latexBibtexCO->setCurrentIndex(0);
738 latexBibtexOptionsLA->setText(qt_("C&ommand:"));
741 latexIndexCO->clear();
743 latexIndexCO->addItem(qt_("Custom"), QString());
744 for (set<string>::const_iterator it = rc.index_alternatives.begin();
745 it != rc.index_alternatives.end(); ++it) {
746 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
747 latexIndexCO->addItem(command, command);
750 index_alternatives = rc.index_alternatives;
752 QString const idx = toqstr(rc.index_command);
753 ind = idx.indexOf(" ");
754 sel_command = idx.left(ind);
755 sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
757 pos = latexIndexCO->findData(sel_command);
759 latexIndexCO->setCurrentIndex(pos);
760 latexIndexED->setText(sel_options.trimmed());
761 latexIndexOptionsLA->setText(qt_("Op&tions:"));
763 latexIndexED->setText(toqstr(rc.index_command));
764 latexIndexCO->setCurrentIndex(0);
765 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
768 latexEncodingED->setText(toqstr(rc.fontenc));
769 latexChecktexED->setText(toqstr(rc.chktex_command));
770 latexJBibtexED->setText(toqstr(rc.jbibtex_command));
771 latexJIndexED->setText(toqstr(rc.jindex_command));
772 latexNomenclED->setText(toqstr(rc.nomencl_command));
773 latexAutoresetCB->setChecked(rc.auto_reset_options);
774 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
775 latexPaperSizeCO->setCurrentIndex(
776 form_->fromPaperSize(rc.default_papersize));
777 #if defined(__CYGWIN__) || defined(_WIN32)
778 pathCB->setChecked(rc.windows_style_tex_paths);
783 /////////////////////////////////////////////////////////////////////
787 /////////////////////////////////////////////////////////////////////
789 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form)
790 : PrefModule(qt_(catLookAndFeel), qt_("Screen fonts"), form)
794 connect(screenRomanCO, SIGNAL(activated(QString)),
795 this, SLOT(selectRoman(QString)));
796 connect(screenSansCO, SIGNAL(activated(QString)),
797 this, SLOT(selectSans(QString)));
798 connect(screenTypewriterCO, SIGNAL(activated(QString)),
799 this, SLOT(selectTypewriter(QString)));
801 QFontDatabase fontdb;
802 QStringList families(fontdb.families());
803 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
804 screenRomanCO->addItem(*it);
805 screenSansCO->addItem(*it);
806 screenTypewriterCO->addItem(*it);
808 connect(screenRomanCO, SIGNAL(activated(QString)),
809 this, SIGNAL(changed()));
810 connect(screenSansCO, SIGNAL(activated(QString)),
811 this, SIGNAL(changed()));
812 connect(screenTypewriterCO, SIGNAL(activated(QString)),
813 this, SIGNAL(changed()));
814 connect(screenZoomSB, SIGNAL(valueChanged(int)),
815 this, SIGNAL(changed()));
816 connect(screenDpiSB, SIGNAL(valueChanged(int)),
817 this, SIGNAL(changed()));
818 connect(screenTinyED, SIGNAL(textChanged(QString)),
819 this, SIGNAL(changed()));
820 connect(screenSmallestED, SIGNAL(textChanged(QString)),
821 this, SIGNAL(changed()));
822 connect(screenSmallerED, SIGNAL(textChanged(QString)),
823 this, SIGNAL(changed()));
824 connect(screenSmallED, SIGNAL(textChanged(QString)),
825 this, SIGNAL(changed()));
826 connect(screenNormalED, SIGNAL(textChanged(QString)),
827 this, SIGNAL(changed()));
828 connect(screenLargeED, SIGNAL(textChanged(QString)),
829 this, SIGNAL(changed()));
830 connect(screenLargerED, SIGNAL(textChanged(QString)),
831 this, SIGNAL(changed()));
832 connect(screenLargestED, SIGNAL(textChanged(QString)),
833 this, SIGNAL(changed()));
834 connect(screenHugeED, SIGNAL(textChanged(QString)),
835 this, SIGNAL(changed()));
836 connect(screenHugerED, SIGNAL(textChanged(QString)),
837 this, SIGNAL(changed()));
838 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
839 this, SIGNAL(changed()));
841 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
842 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
843 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
844 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
845 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
846 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
847 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
848 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
849 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
850 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
854 void PrefScreenFonts::apply(LyXRC & rc) const
856 LyXRC const oldrc = rc;
858 parseFontName(screenRomanCO->currentText(),
859 rc.roman_font_name, rc.roman_font_foundry);
860 parseFontName(screenSansCO->currentText(),
861 rc.sans_font_name, rc.sans_font_foundry);
862 parseFontName(screenTypewriterCO->currentText(),
863 rc.typewriter_font_name, rc.typewriter_font_foundry);
865 rc.zoom = screenZoomSB->value();
866 rc.dpi = screenDpiSB->value();
867 rc.font_sizes[FONT_SIZE_TINY] = fromqstr(screenTinyED->text());
868 rc.font_sizes[FONT_SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
869 rc.font_sizes[FONT_SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
870 rc.font_sizes[FONT_SIZE_SMALL] = fromqstr(screenSmallED->text());
871 rc.font_sizes[FONT_SIZE_NORMAL] = fromqstr(screenNormalED->text());
872 rc.font_sizes[FONT_SIZE_LARGE] = fromqstr(screenLargeED->text());
873 rc.font_sizes[FONT_SIZE_LARGER] = fromqstr(screenLargerED->text());
874 rc.font_sizes[FONT_SIZE_LARGEST] = fromqstr(screenLargestED->text());
875 rc.font_sizes[FONT_SIZE_HUGE] = fromqstr(screenHugeED->text());
876 rc.font_sizes[FONT_SIZE_HUGER] = fromqstr(screenHugerED->text());
877 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
879 if (rc.font_sizes != oldrc.font_sizes
880 || rc.roman_font_name != oldrc.roman_font_name
881 || rc.sans_font_name != oldrc.sans_font_name
882 || rc.typewriter_font_name != oldrc.typewriter_font_name
883 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
884 // The global QPixmapCache is used in GuiPainter to cache text
885 // painting so we must reset it in case any of the above
886 // parameter is changed.
887 QPixmapCache::clear();
888 guiApp->fontLoader().update();
889 form_->updateScreenFonts();
894 void PrefScreenFonts::update(LyXRC const & rc)
896 setComboxFont(screenRomanCO, rc.roman_font_name,
897 rc.roman_font_foundry);
898 setComboxFont(screenSansCO, rc.sans_font_name,
899 rc.sans_font_foundry);
900 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
901 rc.typewriter_font_foundry);
903 selectRoman(screenRomanCO->currentText());
904 selectSans(screenSansCO->currentText());
905 selectTypewriter(screenTypewriterCO->currentText());
907 screenZoomSB->setValue(rc.zoom);
908 screenDpiSB->setValue(rc.dpi);
909 screenTinyED->setText(toqstr(rc.font_sizes[FONT_SIZE_TINY]));
910 screenSmallestED->setText(toqstr(rc.font_sizes[FONT_SIZE_SCRIPT]));
911 screenSmallerED->setText(toqstr(rc.font_sizes[FONT_SIZE_FOOTNOTE]));
912 screenSmallED->setText(toqstr(rc.font_sizes[FONT_SIZE_SMALL]));
913 screenNormalED->setText(toqstr(rc.font_sizes[FONT_SIZE_NORMAL]));
914 screenLargeED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGE]));
915 screenLargerED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGER]));
916 screenLargestED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGEST]));
917 screenHugeED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGE]));
918 screenHugerED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGER]));
920 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
921 #if defined(Q_WS_X11)
922 pixmapCacheCB->setEnabled(false);
928 void PrefScreenFonts::selectRoman(const QString & name)
930 screenRomanFE->set(QFont(name), name);
934 void PrefScreenFonts::selectSans(const QString & name)
936 screenSansFE->set(QFont(name), name);
940 void PrefScreenFonts::selectTypewriter(const QString & name)
942 screenTypewriterFE->set(QFont(name), name);
946 /////////////////////////////////////////////////////////////////////
950 /////////////////////////////////////////////////////////////////////
956 bool operator()(ColorCode lhs, ColorCode rhs) const {
958 compare_no_case(lcolor.getGUIName(lhs), lcolor.getGUIName(rhs)) < 0;
964 PrefColors::PrefColors(GuiPreferences * form)
965 : PrefModule(qt_(catLookAndFeel), qt_("Colors"), form)
969 // FIXME: all of this initialization should be put into the controller.
970 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
971 // for some discussion of why that is not trivial.
972 QPixmap icon(32, 32);
973 for (int i = 0; i < Color_ignore; ++i) {
974 ColorCode lc = static_cast<ColorCode>(i);
982 || lc == Color_magenta
983 || lc == Color_yellow
984 || lc == Color_inherit
985 || lc == Color_ignore) continue;
987 lcolors_.push_back(lc);
989 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
990 vector<ColorCode>::const_iterator cit = lcolors_.begin();
991 vector<ColorCode>::const_iterator const end = lcolors_.end();
992 for (; cit != end; ++cit) {
993 (void) new QListWidgetItem(QIcon(icon),
994 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
996 curcolors_.resize(lcolors_.size());
997 newcolors_.resize(lcolors_.size());
998 // End initialization
1000 connect(colorChangePB, SIGNAL(clicked()),
1001 this, SLOT(changeColor()));
1002 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
1003 this, SLOT(changeLyxObjectsSelection()));
1004 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
1005 this, SLOT(changeColor()));
1009 void PrefColors::apply(LyXRC & /*rc*/) const
1011 for (unsigned int i = 0; i < lcolors_.size(); ++i)
1012 if (curcolors_[i] != newcolors_[i])
1013 form_->setColor(lcolors_[i], newcolors_[i]);
1017 void PrefColors::update(LyXRC const & /*rc*/)
1019 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
1020 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
1021 QPixmap coloritem(32, 32);
1022 coloritem.fill(color);
1023 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
1024 newcolors_[i] = curcolors_[i] = color.name();
1026 changeLyxObjectsSelection();
1030 void PrefColors::changeColor()
1032 int const row = lyxObjectsLW->currentRow();
1038 QString const color = newcolors_[row];
1039 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
1041 if (c.isValid() && c.name() != color) {
1042 newcolors_[row] = c.name();
1043 QPixmap coloritem(32, 32);
1045 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
1051 void PrefColors::changeLyxObjectsSelection()
1053 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
1057 /////////////////////////////////////////////////////////////////////
1061 /////////////////////////////////////////////////////////////////////
1063 PrefDisplay::PrefDisplay(GuiPreferences * form)
1064 : PrefModule(qt_(catLookAndFeel), qt_("Graphics"), form)
1067 connect(displayGraphicsCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
1068 connect(instantPreviewCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
1072 void PrefDisplay::apply(LyXRC & rc) const
1074 switch (instantPreviewCO->currentIndex()) {
1075 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
1076 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
1077 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
1080 rc.display_graphics = displayGraphicsCB->isChecked();
1082 // FIXME!! The graphics cache no longer has a changeDisplay method.
1084 if (old_value != rc.display_graphics) {
1085 graphics::GCache & gc = graphics::GCache::get();
1092 void PrefDisplay::update(LyXRC const & rc)
1094 switch (rc.preview) {
1095 case LyXRC::PREVIEW_OFF:
1096 instantPreviewCO->setCurrentIndex(0);
1098 case LyXRC::PREVIEW_NO_MATH :
1099 instantPreviewCO->setCurrentIndex(1);
1101 case LyXRC::PREVIEW_ON :
1102 instantPreviewCO->setCurrentIndex(2);
1106 displayGraphicsCB->setChecked(rc.display_graphics);
1107 instantPreviewCO->setEnabled(rc.display_graphics);
1111 /////////////////////////////////////////////////////////////////////
1115 /////////////////////////////////////////////////////////////////////
1117 PrefPaths::PrefPaths(GuiPreferences * form)
1118 : PrefModule(QString(), qt_("Paths"), form)
1121 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(selectExampledir()));
1122 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(selectTemplatedir()));
1123 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(selectTempdir()));
1124 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(selectBackupdir()));
1125 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(selectWorkingdir()));
1126 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(selectLyxPipe()));
1127 connect(thesaurusDirPB, SIGNAL(clicked()), this, SLOT(selectThesaurusdir()));
1128 connect(workingDirED, SIGNAL(textChanged(QString)),
1129 this, SIGNAL(changed()));
1130 connect(exampleDirED, SIGNAL(textChanged(QString)),
1131 this, SIGNAL(changed()));
1132 connect(templateDirED, SIGNAL(textChanged(QString)),
1133 this, SIGNAL(changed()));
1134 connect(backupDirED, SIGNAL(textChanged(QString)),
1135 this, SIGNAL(changed()));
1136 connect(tempDirED, SIGNAL(textChanged(QString)),
1137 this, SIGNAL(changed()));
1138 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
1139 this, SIGNAL(changed()));
1140 connect(thesaurusDirED, SIGNAL(textChanged(QString)),
1141 this, SIGNAL(changed()));
1142 connect(pathPrefixED, SIGNAL(textChanged(QString)),
1143 this, SIGNAL(changed()));
1147 void PrefPaths::apply(LyXRC & rc) const
1149 rc.document_path = internal_path(fromqstr(workingDirED->text()));
1150 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
1151 rc.template_path = internal_path(fromqstr(templateDirED->text()));
1152 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
1153 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
1154 rc.thesaurusdir_path = internal_path(fromqstr(thesaurusDirED->text()));
1155 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
1156 // FIXME: should be a checkbox only
1157 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
1161 void PrefPaths::update(LyXRC const & rc)
1163 workingDirED->setText(toqstr(external_path(rc.document_path)));
1164 exampleDirED->setText(toqstr(external_path(rc.example_path)));
1165 templateDirED->setText(toqstr(external_path(rc.template_path)));
1166 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
1167 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
1168 thesaurusDirED->setText(toqstr(external_path(rc.thesaurusdir_path)));
1169 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
1170 // FIXME: should be a checkbox only
1171 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
1175 void PrefPaths::selectExampledir()
1177 QString file = browseDir(internalPath(exampleDirED->text()),
1178 qt_("Select directory for example files"));
1179 if (!file.isEmpty())
1180 exampleDirED->setText(file);
1184 void PrefPaths::selectTemplatedir()
1186 QString file = browseDir(internalPath(templateDirED->text()),
1187 qt_("Select a document templates directory"));
1188 if (!file.isEmpty())
1189 templateDirED->setText(file);
1193 void PrefPaths::selectTempdir()
1195 QString file = browseDir(internalPath(tempDirED->text()),
1196 qt_("Select a temporary directory"));
1197 if (!file.isEmpty())
1198 tempDirED->setText(file);
1202 void PrefPaths::selectBackupdir()
1204 QString file = browseDir(internalPath(backupDirED->text()),
1205 qt_("Select a backups directory"));
1206 if (!file.isEmpty())
1207 backupDirED->setText(file);
1211 void PrefPaths::selectWorkingdir()
1213 QString file = browseDir(internalPath(workingDirED->text()),
1214 qt_("Select a document directory"));
1215 if (!file.isEmpty())
1216 workingDirED->setText(file);
1220 void PrefPaths::selectThesaurusdir()
1222 QString file = browseDir(internalPath(thesaurusDirED->text()),
1223 qt_("Set the path to the thesaurus dictionaries"));
1224 if (!file.isEmpty())
1225 thesaurusDirED->setText(file);
1229 void PrefPaths::selectLyxPipe()
1231 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1232 qt_("Give a filename for the LyX server pipe"));
1233 if (!file.isEmpty())
1234 lyxserverDirED->setText(file);
1238 /////////////////////////////////////////////////////////////////////
1242 /////////////////////////////////////////////////////////////////////
1244 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form)
1245 : PrefModule(qt_(catLanguage), qt_("Spellchecker"), form)
1249 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(selectDict()));
1251 connect(altLanguageED, SIGNAL(textChanged(QString)),
1252 this, SIGNAL(changed()));
1253 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1254 this, SIGNAL(changed()));
1255 connect(persDictionaryED, SIGNAL(textChanged(QString)),
1256 this, SIGNAL(changed()));
1257 connect(compoundWordCB, SIGNAL(clicked()),
1258 this, SIGNAL(changed()));
1259 connect(inputEncodingCB, SIGNAL(clicked()),
1260 this, SIGNAL(changed()));
1261 connect(spellcheckContinuouslyCB, SIGNAL(clicked()),
1262 this, SIGNAL(changed()));
1266 void PrefSpellchecker::apply(LyXRC & rc) const
1268 // FIXME: remove spellchecker_use_alt_lang
1269 rc.spellchecker_alt_lang = fromqstr(altLanguageED->text());
1270 rc.spellchecker_use_alt_lang = !rc.spellchecker_alt_lang.empty();
1271 // FIXME: remove spellchecker_use_esc_chars
1272 rc.spellchecker_esc_chars = fromqstr(escapeCharactersED->text());
1273 rc.spellchecker_use_esc_chars = !rc.spellchecker_esc_chars.empty();
1274 // FIXME: remove spellchecker_use_pers_dict
1275 rc.spellchecker_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
1276 rc.spellchecker_use_pers_dict = !rc.spellchecker_pers_dict.empty();
1277 rc.spellchecker_accept_compound = compoundWordCB->isChecked();
1278 rc.spellchecker_use_input_encoding = inputEncodingCB->isChecked();
1279 rc.spellcheck_continuously = spellcheckContinuouslyCB->isChecked();
1283 void PrefSpellchecker::update(LyXRC const & rc)
1285 // FIXME: remove spellchecker_use_alt_lang
1286 altLanguageED->setText(toqstr(rc.spellchecker_alt_lang));
1287 // FIXME: remove spellchecker_use_esc_chars
1288 escapeCharactersED->setText(toqstr(rc.spellchecker_esc_chars));
1289 // FIXME: remove spellchecker_use_pers_dict
1290 persDictionaryED->setText(toqstr(external_path(rc.spellchecker_pers_dict)));
1291 compoundWordCB->setChecked(rc.spellchecker_accept_compound);
1292 inputEncodingCB->setChecked(rc.spellchecker_use_input_encoding);
1293 spellcheckContinuouslyCB->setChecked(rc.spellcheck_continuously);
1297 void PrefSpellchecker::selectDict()
1299 QString file = form_->browsedict(internalPath(persDictionaryED->text()));
1300 if (!file.isEmpty())
1301 persDictionaryED->setText(file);
1306 /////////////////////////////////////////////////////////////////////
1310 /////////////////////////////////////////////////////////////////////
1313 PrefConverters::PrefConverters(GuiPreferences * form)
1314 : PrefModule(qt_(catFiles), qt_("Converters"), form)
1318 connect(converterNewPB, SIGNAL(clicked()),
1319 this, SLOT(updateConverter()));
1320 connect(converterRemovePB, SIGNAL(clicked()),
1321 this, SLOT(removeConverter()));
1322 connect(converterModifyPB, SIGNAL(clicked()),
1323 this, SLOT(updateConverter()));
1324 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1325 this, SLOT(switchConverter()));
1326 connect(converterFromCO, SIGNAL(activated(QString)),
1327 this, SLOT(changeConverter()));
1328 connect(converterToCO, SIGNAL(activated(QString)),
1329 this, SLOT(changeConverter()));
1330 connect(converterED, SIGNAL(textEdited(QString)),
1331 this, SLOT(changeConverter()));
1332 connect(converterFlagED, SIGNAL(textEdited(QString)),
1333 this, SLOT(changeConverter()));
1334 connect(converterNewPB, SIGNAL(clicked()),
1335 this, SIGNAL(changed()));
1336 connect(converterRemovePB, SIGNAL(clicked()),
1337 this, SIGNAL(changed()));
1338 connect(converterModifyPB, SIGNAL(clicked()),
1339 this, SIGNAL(changed()));
1340 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1341 this, SIGNAL(changed()));
1343 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1344 //converterDefGB->setFocusProxy(convertersLW);
1348 void PrefConverters::apply(LyXRC & rc) const
1350 rc.use_converter_cache = cacheCB->isChecked();
1351 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
1355 void PrefConverters::update(LyXRC const & rc)
1357 cacheCB->setChecked(rc.use_converter_cache);
1359 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
1360 maxAgeLE->setText(max_age);
1365 void PrefConverters::updateGui()
1367 form_->formats().sort();
1368 form_->converters().update(form_->formats());
1369 // save current selection
1370 QString current = converterFromCO->currentText()
1371 + " -> " + converterToCO->currentText();
1373 converterFromCO->clear();
1374 converterToCO->clear();
1376 Formats::const_iterator cit = form_->formats().begin();
1377 Formats::const_iterator end = form_->formats().end();
1378 for (; cit != end; ++cit) {
1379 converterFromCO->addItem(qt_(cit->prettyname()));
1380 converterToCO->addItem(qt_(cit->prettyname()));
1383 // currentRowChanged(int) is also triggered when updating the listwidget
1384 // block signals to avoid unnecessary calls to switchConverter()
1385 convertersLW->blockSignals(true);
1386 convertersLW->clear();
1388 Converters::const_iterator ccit = form_->converters().begin();
1389 Converters::const_iterator cend = form_->converters().end();
1390 for (; ccit != cend; ++ccit) {
1391 QString const name =
1392 qt_(ccit->From->prettyname()) + " -> " + qt_(ccit->To->prettyname());
1393 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1394 new QListWidgetItem(name, convertersLW, type);
1396 convertersLW->sortItems(Qt::AscendingOrder);
1397 convertersLW->blockSignals(false);
1399 // restore selection
1400 if (!current.isEmpty()) {
1401 QList<QListWidgetItem *> const item =
1402 convertersLW->findItems(current, Qt::MatchExactly);
1403 if (!item.isEmpty())
1404 convertersLW->setCurrentItem(item.at(0));
1407 // select first element if restoring failed
1408 if (convertersLW->currentRow() == -1)
1409 convertersLW->setCurrentRow(0);
1415 void PrefConverters::switchConverter()
1417 int const cnr = convertersLW->currentItem()->type();
1418 Converter const & c(form_->converters().get(cnr));
1419 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1420 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1421 converterED->setText(toqstr(c.command));
1422 converterFlagED->setText(toqstr(c.flags));
1428 void PrefConverters::changeConverter()
1434 void PrefConverters::updateButtons()
1436 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1437 Format const & to = form_->formats().get(converterToCO->currentIndex());
1438 int const sel = form_->converters().getNumber(from.name(), to.name());
1439 bool const known = sel >= 0;
1440 bool const valid = !(converterED->text().isEmpty()
1441 || from.name() == to.name());
1443 int const cnr = convertersLW->currentItem()->type();
1444 Converter const & c = form_->converters().get(cnr);
1445 string const old_command = c.command;
1446 string const old_flag = c.flags;
1447 string const new_command = fromqstr(converterED->text());
1448 string const new_flag = fromqstr(converterFlagED->text());
1450 bool modified = (old_command != new_command || old_flag != new_flag);
1452 converterModifyPB->setEnabled(valid && known && modified);
1453 converterNewPB->setEnabled(valid && !known);
1454 converterRemovePB->setEnabled(known);
1456 maxAgeLE->setEnabled(cacheCB->isChecked());
1457 maxAgeLA->setEnabled(cacheCB->isChecked());
1462 // specify unique from/to or it doesn't appear. This is really bad UI
1463 // this is why we can use the same function for both new and modify
1464 void PrefConverters::updateConverter()
1466 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1467 Format const & to = form_->formats().get(converterToCO->currentIndex());
1468 string const flags = fromqstr(converterFlagED->text());
1469 string const command = fromqstr(converterED->text());
1471 Converter const * old =
1472 form_->converters().getConverter(from.name(), to.name());
1473 form_->converters().add(from.name(), to.name(), command, flags);
1476 form_->converters().updateLast(form_->formats());
1480 // Remove all files created by this converter from the cache, since
1481 // the modified converter might create different files.
1482 ConverterCache::get().remove_all(from.name(), to.name());
1486 void PrefConverters::removeConverter()
1488 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1489 Format const & to = form_->formats().get(converterToCO->currentIndex());
1490 form_->converters().erase(from.name(), to.name());
1494 // Remove all files created by this converter from the cache, since
1495 // a possible new converter might create different files.
1496 ConverterCache::get().remove_all(from.name(), to.name());
1500 void PrefConverters::on_cacheCB_stateChanged(int state)
1502 maxAgeLE->setEnabled(state == Qt::Checked);
1503 maxAgeLA->setEnabled(state == Qt::Checked);
1508 /////////////////////////////////////////////////////////////////////
1512 /////////////////////////////////////////////////////////////////////
1514 class FormatValidator : public QValidator
1517 FormatValidator(QWidget *, Formats const & f);
1518 void fixup(QString & input) const;
1519 QValidator::State validate(QString & input, int & pos) const;
1521 virtual QString toString(Format const & format) const = 0;
1523 Formats const & formats_;
1527 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1528 : QValidator(parent), formats_(f)
1533 void FormatValidator::fixup(QString & input) const
1535 Formats::const_iterator cit = formats_.begin();
1536 Formats::const_iterator end = formats_.end();
1537 for (; cit != end; ++cit) {
1538 QString const name = toString(*cit);
1539 if (distance(formats_.begin(), cit) == nr()) {
1547 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1549 Formats::const_iterator cit = formats_.begin();
1550 Formats::const_iterator end = formats_.end();
1551 bool unknown = true;
1552 for (; unknown && cit != end; ++cit) {
1553 QString const name = toString(*cit);
1554 if (distance(formats_.begin(), cit) != nr())
1555 unknown = name != input;
1558 if (unknown && !input.isEmpty())
1559 return QValidator::Acceptable;
1561 return QValidator::Intermediate;
1565 int FormatValidator::nr() const
1567 QComboBox * p = qobject_cast<QComboBox *>(parent());
1568 return p->itemData(p->currentIndex()).toInt();
1572 /////////////////////////////////////////////////////////////////////
1574 // FormatNameValidator
1576 /////////////////////////////////////////////////////////////////////
1578 class FormatNameValidator : public FormatValidator
1581 FormatNameValidator(QWidget * parent, Formats const & f)
1582 : FormatValidator(parent, f)
1585 QString toString(Format const & format) const
1587 return toqstr(format.name());
1592 /////////////////////////////////////////////////////////////////////
1594 // FormatPrettynameValidator
1596 /////////////////////////////////////////////////////////////////////
1598 class FormatPrettynameValidator : public FormatValidator
1601 FormatPrettynameValidator(QWidget * parent, Formats const & f)
1602 : FormatValidator(parent, f)
1605 QString toString(Format const & format) const
1607 return qt_(format.prettyname());
1612 /////////////////////////////////////////////////////////////////////
1616 /////////////////////////////////////////////////////////////////////
1618 PrefFileformats::PrefFileformats(GuiPreferences * form)
1619 : PrefModule(qt_(catFiles), qt_("File formats"), form)
1622 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1623 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1625 connect(documentCB, SIGNAL(clicked()),
1626 this, SLOT(setFlags()));
1627 connect(vectorCB, SIGNAL(clicked()),
1628 this, SLOT(setFlags()));
1629 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1630 this, SLOT(updatePrettyname()));
1631 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1632 this, SIGNAL(changed()));
1633 connect(defaultFormatCB, SIGNAL(activated(QString)),
1634 this, SIGNAL(changed()));
1640 string const l10n_shortcut(string const prettyname, string const shortcut)
1642 if (shortcut.empty())
1645 string l10n_format =
1646 to_utf8(_(prettyname + '|' + shortcut));
1647 return split(l10n_format, '|');
1650 }; // namespace anon
1653 void PrefFileformats::apply(LyXRC & rc) const
1655 QString const default_format = defaultFormatCB->itemData(
1656 defaultFormatCB->currentIndex()).toString();
1657 rc.default_view_format = fromqstr(default_format);
1661 void PrefFileformats::update(LyXRC const & rc)
1663 bool const init = defaultFormatCB->currentText().isEmpty();
1666 int const pos = defaultFormatCB->findData(toqstr(
1667 rc.default_view_format));
1668 defaultFormatCB->setCurrentIndex(pos);
1673 void PrefFileformats::updateView()
1675 QString const current = formatsCB->currentText();
1676 QString const current_def = defaultFormatCB->currentText();
1678 // update comboboxes with formats
1679 formatsCB->blockSignals(true);
1680 defaultFormatCB->blockSignals(true);
1682 defaultFormatCB->clear();
1683 form_->formats().sort();
1684 Formats::const_iterator cit = form_->formats().begin();
1685 Formats::const_iterator end = form_->formats().end();
1686 for (; cit != end; ++cit) {
1687 formatsCB->addItem(qt_(cit->prettyname()),
1688 QVariant(form_->formats().getNumber(cit->name())));
1689 if (form_->converters().isReachable("latex", cit->name())
1690 || form_->converters().isReachable("pdflatex", cit->name()))
1691 defaultFormatCB->addItem(qt_(cit->prettyname()),
1692 QVariant(toqstr(cit->name())));
1695 // restore selection
1696 int item = formatsCB->findText(current, Qt::MatchExactly);
1697 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1698 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1699 item = defaultFormatCB->findText(current_def, Qt::MatchExactly);
1700 defaultFormatCB->setCurrentIndex(item < 0 ? 0 : item);
1701 formatsCB->blockSignals(false);
1702 defaultFormatCB->blockSignals(false);
1706 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1708 int const nr = formatsCB->itemData(i).toInt();
1709 Format const f = form_->formats().get(nr);
1711 formatED->setText(toqstr(f.name()));
1712 copierED->setText(toqstr(form_->movers().command(f.name())));
1713 extensionED->setText(toqstr(f.extension()));
1714 shortcutED->setText(
1715 toqstr(l10n_shortcut(f.prettyname(), f.shortcut())));
1716 viewerED->setText(toqstr(f.viewer()));
1717 editorED->setText(toqstr(f.editor()));
1718 documentCB->setChecked((f.documentFormat()));
1719 vectorCB->setChecked((f.vectorFormat()));
1723 void PrefFileformats::setFlags()
1725 int flags = Format::none;
1726 if (documentCB->isChecked())
1727 flags |= Format::document;
1728 if (vectorCB->isChecked())
1729 flags |= Format::vector;
1730 currentFormat().setFlags(flags);
1735 void PrefFileformats::on_copierED_textEdited(const QString & s)
1737 string const fmt = fromqstr(formatED->text());
1738 form_->movers().set(fmt, fromqstr(s));
1743 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1745 currentFormat().setExtension(fromqstr(s));
1749 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1751 currentFormat().setViewer(fromqstr(s));
1756 void PrefFileformats::on_editorED_textEdited(const QString & s)
1758 currentFormat().setEditor(fromqstr(s));
1763 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1765 string const new_shortcut = fromqstr(s);
1766 if (new_shortcut == l10n_shortcut(currentFormat().prettyname(),
1767 currentFormat().shortcut()))
1769 currentFormat().setShortcut(new_shortcut);
1774 void PrefFileformats::on_formatED_editingFinished()
1776 string const newname = fromqstr(formatED->displayText());
1777 if (newname == currentFormat().name())
1780 currentFormat().setName(newname);
1785 void PrefFileformats::on_formatED_textChanged(const QString &)
1787 QString t = formatED->text();
1789 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1790 setValid(formatLA, valid);
1794 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1796 QString t = formatsCB->currentText();
1798 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1799 setValid(formatsLA, valid);
1803 void PrefFileformats::updatePrettyname()
1805 QString const newname = formatsCB->currentText();
1806 if (newname == qt_(currentFormat().prettyname()))
1809 currentFormat().setPrettyname(fromqstr(newname));
1816 Format & PrefFileformats::currentFormat()
1818 int const i = formatsCB->currentIndex();
1819 int const nr = formatsCB->itemData(i).toInt();
1820 return form_->formats().get(nr);
1824 void PrefFileformats::on_formatNewPB_clicked()
1826 form_->formats().add("", "", "", "", "", "", Format::none);
1828 formatsCB->setCurrentIndex(0);
1829 formatsCB->setFocus(Qt::OtherFocusReason);
1833 void PrefFileformats::on_formatRemovePB_clicked()
1835 int const i = formatsCB->currentIndex();
1836 int const nr = formatsCB->itemData(i).toInt();
1837 string const current_text = form_->formats().get(nr).name();
1838 if (form_->converters().formatIsUsed(current_text)) {
1839 Alert::error(_("Format in use"),
1840 _("Cannot remove a Format used by a Converter. "
1841 "Remove the converter first."));
1845 form_->formats().erase(current_text);
1848 on_formatsCB_editTextChanged(formatsCB->currentText());
1853 /////////////////////////////////////////////////////////////////////
1857 /////////////////////////////////////////////////////////////////////
1859 PrefLanguage::PrefLanguage(GuiPreferences * form)
1860 : PrefModule(qt_(catLanguage), qt_("Language"), form)
1864 connect(rtlGB, SIGNAL(clicked()),
1865 this, SIGNAL(changed()));
1866 connect(visualCursorRB, SIGNAL(clicked()),
1867 this, SIGNAL(changed()));
1868 connect(logicalCursorRB, SIGNAL(clicked()),
1869 this, SIGNAL(changed()));
1870 connect(markForeignCB, SIGNAL(clicked()),
1871 this, SIGNAL(changed()));
1872 connect(autoBeginCB, SIGNAL(clicked()),
1873 this, SIGNAL(changed()));
1874 connect(autoEndCB, SIGNAL(clicked()),
1875 this, SIGNAL(changed()));
1876 connect(useBabelCB, SIGNAL(clicked()),
1877 this, SIGNAL(changed()));
1878 connect(globalCB, SIGNAL(clicked()),
1879 this, SIGNAL(changed()));
1880 connect(languagePackageED, SIGNAL(textChanged(QString)),
1881 this, SIGNAL(changed()));
1882 connect(startCommandED, SIGNAL(textChanged(QString)),
1883 this, SIGNAL(changed()));
1884 connect(endCommandED, SIGNAL(textChanged(QString)),
1885 this, SIGNAL(changed()));
1886 connect(uiLanguageCO, SIGNAL(activated(int)),
1887 this, SIGNAL(changed()));
1889 uiLanguageCO->clear();
1891 QAbstractItemModel * language_model = guiApp->languageModel();
1892 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1893 language_model->sort(0);
1895 // FIXME: This is wrong, we need filter this list based on the available
1897 uiLanguageCO->blockSignals(true);
1898 uiLanguageCO->addItem(qt_("Default"), toqstr("auto"));
1899 for (int i = 0; i != language_model->rowCount(); ++i) {
1900 QModelIndex index = language_model->index(i, 0);
1901 uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
1902 index.data(Qt::UserRole).toString());
1904 uiLanguageCO->blockSignals(false);
1908 void PrefLanguage::on_uiLanguageCO_currentIndexChanged(int)
1910 QMessageBox::information(this, qt_("LyX needs to be restarted!"),
1911 qt_("The change of user interface language will be fully "
1912 "effective only after a restart."));
1916 void PrefLanguage::apply(LyXRC & rc) const
1918 // FIXME: remove rtl_support bool
1919 rc.rtl_support = rtlGB->isChecked();
1920 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
1921 rc.mark_foreign_language = markForeignCB->isChecked();
1922 rc.language_auto_begin = autoBeginCB->isChecked();
1923 rc.language_auto_end = autoEndCB->isChecked();
1924 rc.language_use_babel = useBabelCB->isChecked();
1925 rc.language_global_options = globalCB->isChecked();
1926 rc.language_package = fromqstr(languagePackageED->text());
1927 rc.language_command_begin = fromqstr(startCommandED->text());
1928 rc.language_command_end = fromqstr(endCommandED->text());
1929 rc.gui_language = fromqstr(
1930 uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString());
1934 void PrefLanguage::update(LyXRC const & rc)
1936 // FIXME: remove rtl_support bool
1937 rtlGB->setChecked(rc.rtl_support);
1938 if (rc.visual_cursor)
1939 visualCursorRB->setChecked(true);
1941 logicalCursorRB->setChecked(true);
1942 markForeignCB->setChecked(rc.mark_foreign_language);
1943 autoBeginCB->setChecked(rc.language_auto_begin);
1944 autoEndCB->setChecked(rc.language_auto_end);
1945 useBabelCB->setChecked(rc.language_use_babel);
1946 globalCB->setChecked(rc.language_global_options);
1947 languagePackageED->setText(toqstr(rc.language_package));
1948 startCommandED->setText(toqstr(rc.language_command_begin));
1949 endCommandED->setText(toqstr(rc.language_command_end));
1951 int pos = uiLanguageCO->findData(toqstr(rc.gui_language));
1952 uiLanguageCO->blockSignals(true);
1953 uiLanguageCO->setCurrentIndex(pos);
1954 uiLanguageCO->blockSignals(false);
1958 /////////////////////////////////////////////////////////////////////
1962 /////////////////////////////////////////////////////////////////////
1964 PrefPrinter::PrefPrinter(GuiPreferences * form)
1965 : PrefModule(qt_(catOutput), qt_("Printer"), form)
1969 connect(printerAdaptCB, SIGNAL(clicked()),
1970 this, SIGNAL(changed()));
1971 connect(printerCommandED, SIGNAL(textChanged(QString)),
1972 this, SIGNAL(changed()));
1973 connect(printerNameED, SIGNAL(textChanged(QString)),
1974 this, SIGNAL(changed()));
1975 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
1976 this, SIGNAL(changed()));
1977 connect(printerCopiesED, SIGNAL(textChanged(QString)),
1978 this, SIGNAL(changed()));
1979 connect(printerReverseED, SIGNAL(textChanged(QString)),
1980 this, SIGNAL(changed()));
1981 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
1982 this, SIGNAL(changed()));
1983 connect(printerExtensionED, SIGNAL(textChanged(QString)),
1984 this, SIGNAL(changed()));
1985 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
1986 this, SIGNAL(changed()));
1987 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
1988 this, SIGNAL(changed()));
1989 connect(printerEvenED, SIGNAL(textChanged(QString)),
1990 this, SIGNAL(changed()));
1991 connect(printerOddED, SIGNAL(textChanged(QString)),
1992 this, SIGNAL(changed()));
1993 connect(printerCollatedED, SIGNAL(textChanged(QString)),
1994 this, SIGNAL(changed()));
1995 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
1996 this, SIGNAL(changed()));
1997 connect(printerToFileED, SIGNAL(textChanged(QString)),
1998 this, SIGNAL(changed()));
1999 connect(printerExtraED, SIGNAL(textChanged(QString)),
2000 this, SIGNAL(changed()));
2001 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
2002 this, SIGNAL(changed()));
2003 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
2004 this, SIGNAL(changed()));
2008 void PrefPrinter::apply(LyXRC & rc) const
2010 rc.print_adapt_output = printerAdaptCB->isChecked();
2011 rc.print_command = fromqstr(printerCommandED->text());
2012 rc.printer = fromqstr(printerNameED->text());
2014 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
2015 rc.print_copies_flag = fromqstr(printerCopiesED->text());
2016 rc.print_reverse_flag = fromqstr(printerReverseED->text());
2017 rc.print_to_printer = fromqstr(printerToPrinterED->text());
2018 rc.print_file_extension = fromqstr(printerExtensionED->text());
2019 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
2020 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
2021 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
2022 rc.print_oddpage_flag = fromqstr(printerOddED->text());
2023 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
2024 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
2025 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
2026 rc.print_extra_options = fromqstr(printerExtraED->text());
2027 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
2028 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
2032 void PrefPrinter::update(LyXRC const & rc)
2034 printerAdaptCB->setChecked(rc.print_adapt_output);
2035 printerCommandED->setText(toqstr(rc.print_command));
2036 printerNameED->setText(toqstr(rc.printer));
2038 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
2039 printerCopiesED->setText(toqstr(rc.print_copies_flag));
2040 printerReverseED->setText(toqstr(rc.print_reverse_flag));
2041 printerToPrinterED->setText(toqstr(rc.print_to_printer));
2042 printerExtensionED->setText(toqstr(rc.print_file_extension));
2043 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
2044 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
2045 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
2046 printerOddED->setText(toqstr(rc.print_oddpage_flag));
2047 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
2048 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
2049 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
2050 printerExtraED->setText(toqstr(rc.print_extra_options));
2051 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
2052 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
2056 /////////////////////////////////////////////////////////////////////
2058 // PrefUserInterface
2060 /////////////////////////////////////////////////////////////////////
2062 PrefUserInterface::PrefUserInterface(GuiPreferences * form)
2063 : PrefModule(qt_(catLookAndFeel), qt_("User interface"), form)
2067 connect(autoSaveCB, SIGNAL(toggled(bool)),
2068 autoSaveSB, SLOT(setEnabled(bool)));
2069 connect(autoSaveCB, SIGNAL(toggled(bool)),
2070 TextLabel1, SLOT(setEnabled(bool)));
2071 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
2072 this, SIGNAL(changed()));
2073 connect(uiFilePB, SIGNAL(clicked()),
2074 this, SLOT(selectUi()));
2075 connect(uiFileED, SIGNAL(textChanged(QString)),
2076 this, SIGNAL(changed()));
2077 connect(restoreCursorCB, SIGNAL(clicked()),
2078 this, SIGNAL(changed()));
2079 connect(loadSessionCB, SIGNAL(clicked()),
2080 this, SIGNAL(changed()));
2081 connect(allowGeometrySessionCB, SIGNAL(clicked()),
2082 this, SIGNAL(changed()));
2083 connect(autoSaveSB, SIGNAL(valueChanged(int)),
2084 this, SIGNAL(changed()));
2085 connect(autoSaveCB, SIGNAL(clicked()),
2086 this, SIGNAL(changed()));
2087 connect(lastfilesSB, SIGNAL(valueChanged(int)),
2088 this, SIGNAL(changed()));
2089 connect(tooltipCB, SIGNAL(toggled(bool)),
2090 this, SIGNAL(changed()));
2091 lastfilesSB->setMaximum(maxlastfiles);
2095 void PrefUserInterface::apply(LyXRC & rc) const
2097 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
2098 rc.use_lastfilepos = restoreCursorCB->isChecked();
2099 rc.load_session = loadSessionCB->isChecked();
2100 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
2101 rc.autosave = autoSaveSB->value() * 60;
2102 rc.make_backup = autoSaveCB->isChecked();
2103 rc.num_lastfiles = lastfilesSB->value();
2104 rc.use_tooltip = tooltipCB->isChecked();
2105 rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
2109 void PrefUserInterface::update(LyXRC const & rc)
2111 uiFileED->setText(toqstr(external_path(rc.ui_file)));
2112 restoreCursorCB->setChecked(rc.use_lastfilepos);
2113 loadSessionCB->setChecked(rc.load_session);
2114 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
2115 // convert to minutes
2116 int mins(rc.autosave / 60);
2117 if (rc.autosave && !mins)
2119 autoSaveSB->setValue(mins);
2120 autoSaveCB->setChecked(rc.make_backup);
2121 lastfilesSB->setValue(rc.num_lastfiles);
2122 tooltipCB->setChecked(rc.use_tooltip);
2123 openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
2127 void PrefUserInterface::selectUi()
2129 QString file = form_->browseUI(internalPath(uiFileED->text()));
2130 if (!file.isEmpty())
2131 uiFileED->setText(file);
2135 void PrefUserInterface::on_clearSessionPB_clicked()
2137 guiApp->clearSession();
2142 /////////////////////////////////////////////////////////////////////
2146 /////////////////////////////////////////////////////////////////////
2148 PrefEdit::PrefEdit(GuiPreferences * form)
2149 : PrefModule(qt_(catEditing), qt_("Control"), form)
2153 connect(cursorFollowsCB, SIGNAL(clicked()),
2154 this, SIGNAL(changed()));
2155 connect(scrollBelowCB, SIGNAL(clicked()),
2156 this, SIGNAL(changed()));
2157 connect(sortEnvironmentsCB, SIGNAL(clicked()),
2158 this, SIGNAL(changed()));
2159 connect(groupEnvironmentsCB, SIGNAL(clicked()),
2160 this, SIGNAL(changed()));
2161 connect(macroEditStyleCO, SIGNAL(activated(int)),
2162 this, SIGNAL(changed()));
2163 connect(fullscreenLimitGB, SIGNAL(clicked()),
2164 this, SIGNAL(changed()));
2165 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
2166 this, SIGNAL(changed()));
2167 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
2168 this, SIGNAL(changed()));
2169 connect(toggleMenubarCB, SIGNAL(toggled(bool)),
2170 this, SIGNAL(changed()));
2171 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
2172 this, SIGNAL(changed()));
2173 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
2174 this, SIGNAL(changed()));
2178 void PrefEdit::apply(LyXRC & rc) const
2180 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
2181 rc.scroll_below_document = scrollBelowCB->isChecked();
2182 rc.sort_layouts = sortEnvironmentsCB->isChecked();
2183 rc.group_layouts = groupEnvironmentsCB->isChecked();
2184 switch (macroEditStyleCO->currentIndex()) {
2185 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
2186 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
2187 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
2189 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
2190 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
2191 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
2192 rc.full_screen_menubar = toggleMenubarCB->isChecked();
2193 rc.full_screen_width = fullscreenWidthSB->value();
2194 rc.full_screen_limit = fullscreenLimitGB->isChecked();
2198 void PrefEdit::update(LyXRC const & rc)
2200 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
2201 scrollBelowCB->setChecked(rc.scroll_below_document);
2202 sortEnvironmentsCB->setChecked(rc.sort_layouts);
2203 groupEnvironmentsCB->setChecked(rc.group_layouts);
2204 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
2205 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
2206 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
2207 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
2208 toggleMenubarCB->setChecked(rc.full_screen_menubar);
2209 fullscreenWidthSB->setValue(rc.full_screen_width);
2210 fullscreenLimitGB->setChecked(rc.full_screen_limit);
2214 /////////////////////////////////////////////////////////////////////
2218 /////////////////////////////////////////////////////////////////////
2221 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
2223 Ui::shortcutUi::setupUi(this);
2224 QDialog::setModal(true);
2228 PrefShortcuts::PrefShortcuts(GuiPreferences * form)
2229 : PrefModule(qt_(catEditing), qt_("Shortcuts"), form)
2233 shortcutsTW->setColumnCount(2);
2234 shortcutsTW->headerItem()->setText(0, qt_("Function"));
2235 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
2236 shortcutsTW->setSortingEnabled(true);
2237 // Multi-selection can be annoying.
2238 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
2240 connect(bindFilePB, SIGNAL(clicked()),
2241 this, SLOT(selectBind()));
2242 connect(bindFileED, SIGNAL(textChanged(QString)),
2243 this, SIGNAL(changed()));
2244 connect(removePB, SIGNAL(clicked()),
2245 this, SIGNAL(changed()));
2247 shortcut_ = new GuiShortcutDialog(this);
2248 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
2249 shortcut_bc_.setOK(shortcut_->okPB);
2250 shortcut_bc_.setCancel(shortcut_->cancelPB);
2252 connect(shortcut_->okPB, SIGNAL(clicked()),
2253 shortcut_, SLOT(accept()));
2254 connect(shortcut_->okPB, SIGNAL(clicked()),
2255 this, SIGNAL(changed()));
2256 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2257 shortcut_, SLOT(reject()));
2258 connect(shortcut_->clearPB, SIGNAL(clicked()),
2259 this, SLOT(shortcutClearPressed()));
2260 connect(shortcut_->removePB, SIGNAL(clicked()),
2261 this, SLOT(shortcutRemovePressed()));
2262 connect(shortcut_->okPB, SIGNAL(clicked()),
2263 this, SLOT(shortcutOkPressed()));
2264 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2265 this, SLOT(shortcutCancelPressed()));
2269 void PrefShortcuts::apply(LyXRC & rc) const
2271 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
2272 // write user_bind and user_unbind to .lyx/bind/user.bind
2273 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
2274 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
2275 lyxerr << "LyX could not create the user bind directory '"
2276 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2279 if (!bind_dir.isDirWritable()) {
2280 lyxerr << "LyX could not write to the user bind directory '"
2281 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2284 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
2285 user_unbind_.write(user_bind_file.toFilesystemEncoding(), false, true);
2286 user_bind_.write(user_bind_file.toFilesystemEncoding(), true, false);
2287 // immediately apply the keybindings. Why this is not done before?
2288 // The good thing is that the menus are updated automatically.
2289 theTopLevelKeymap().clear();
2290 theTopLevelKeymap().read("site");
2291 theTopLevelKeymap().read(rc.bind_file);
2292 theTopLevelKeymap().read("user");
2296 void PrefShortcuts::update(LyXRC const & rc)
2298 bindFileED->setText(toqstr(external_path(rc.bind_file)));
2300 system_bind_.clear();
2302 user_unbind_.clear();
2303 system_bind_.read("site");
2304 system_bind_.read(rc.bind_file);
2305 // \unbind in user.bind is added to user_unbind_
2306 user_bind_.read("user", &user_unbind_);
2307 updateShortcutsTW();
2311 void PrefShortcuts::updateShortcutsTW()
2313 shortcutsTW->clear();
2315 editItem_ = new QTreeWidgetItem(shortcutsTW);
2316 editItem_->setText(0, qt_("Cursor, Mouse and Editing functions"));
2317 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2319 mathItem_ = new QTreeWidgetItem(shortcutsTW);
2320 mathItem_->setText(0, qt_("Mathematical Symbols"));
2321 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2323 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2324 bufferItem_->setText(0, qt_("Document and Window"));
2325 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2327 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2328 layoutItem_->setText(0, qt_("Font, Layouts and Textclasses"));
2329 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2331 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2332 systemItem_->setText(0, qt_("System and Miscellaneous"));
2333 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2335 // listBindings(unbound=true) lists all bound and unbound lfuns
2336 // Items in this list is tagged by its source.
2337 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2339 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2341 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2342 KeyMap::UserUnbind);
2343 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2344 user_bindinglist.end());
2345 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2346 user_unbindinglist.end());
2348 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2349 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2350 for (; it != it_end; ++it)
2351 insertShortcutItem(it->request, it->sequence, KeyMap::ItemType(it->tag));
2353 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2354 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2355 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2356 modifyPB->setEnabled(!items.isEmpty());
2358 shortcutsTW->resizeColumnToContents(0);
2362 void PrefShortcuts::setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag)
2364 item->setData(0, Qt::UserRole, QVariant(tag));
2368 case KeyMap::System:
2370 case KeyMap::UserBind:
2373 case KeyMap::UserUnbind:
2374 font.setStrikeOut(true);
2376 // this item is not displayed now.
2377 case KeyMap::UserExtraUnbind:
2378 font.setStrikeOut(true);
2382 item->setFont(1, font);
2386 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2387 KeySequence const & seq, KeyMap::ItemType tag)
2389 FuncCode action = lfun.action;
2390 string const action_name = lyxaction.getActionName(action);
2391 QString const lfun_name = toqstr(from_utf8(action_name)
2392 + ' ' + lfun.argument());
2393 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2394 KeyMap::ItemType item_tag = tag;
2396 QTreeWidgetItem * newItem = 0;
2397 // for unbind items, try to find an existing item in the system bind list
2398 if (tag == KeyMap::UserUnbind) {
2399 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2400 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2401 for (int i = 0; i < items.size(); ++i) {
2402 if (items[i]->text(1) == shortcut)
2406 // if not found, this unbind item is KeyMap::UserExtraUnbind
2407 // Such an item is not displayed to avoid confusion (what is
2408 // unmatched removed?).
2410 item_tag = KeyMap::UserExtraUnbind;
2415 switch(lyxaction.getActionType(action)) {
2416 case LyXAction::Hidden:
2418 case LyXAction::Edit:
2419 newItem = new QTreeWidgetItem(editItem_);
2421 case LyXAction::Math:
2422 newItem = new QTreeWidgetItem(mathItem_);
2424 case LyXAction::Buffer:
2425 newItem = new QTreeWidgetItem(bufferItem_);
2427 case LyXAction::Layout:
2428 newItem = new QTreeWidgetItem(layoutItem_);
2430 case LyXAction::System:
2431 newItem = new QTreeWidgetItem(systemItem_);
2434 // this should not happen
2435 newItem = new QTreeWidgetItem(shortcutsTW);
2439 newItem->setText(0, lfun_name);
2440 newItem->setText(1, shortcut);
2441 // record BindFile representation to recover KeySequence when needed.
2442 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2443 setItemType(newItem, item_tag);
2448 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2450 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2451 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2452 modifyPB->setEnabled(!items.isEmpty());
2453 if (items.isEmpty())
2456 KeyMap::ItemType tag =
2457 static_cast<KeyMap::ItemType>(items[0]->data(0, Qt::UserRole).toInt());
2458 if (tag == KeyMap::UserUnbind)
2459 removePB->setText(qt_("Res&tore"));
2461 removePB->setText(qt_("Remo&ve"));
2465 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2471 void PrefShortcuts::modifyShortcut()
2473 QTreeWidgetItem * item = shortcutsTW->currentItem();
2474 if (item->flags() & Qt::ItemIsSelectable) {
2475 shortcut_->lfunLE->setText(item->text(0));
2476 save_lfun_ = item->text(0);
2477 shortcut_->shortcutWG->setText(item->text(1));
2479 seq.parse(fromqstr(item->data(1, Qt::UserRole).toString()));
2480 shortcut_->shortcutWG->setKeySequence(seq);
2481 shortcut_->shortcutWG->setFocus();
2487 void PrefShortcuts::removeShortcut()
2489 // it seems that only one item can be selected, but I am
2490 // removing all selected items anyway.
2491 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2492 for (int i = 0; i < items.size(); ++i) {
2493 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2494 string lfun = fromqstr(items[i]->text(0));
2495 FuncRequest func = lyxaction.lookupFunc(lfun);
2496 KeyMap::ItemType tag =
2497 static_cast<KeyMap::ItemType>(items[i]->data(0, Qt::UserRole).toInt());
2500 case KeyMap::System: {
2501 // for system bind, we do not touch the item
2502 // but add an user unbind item
2503 user_unbind_.bind(shortcut, func);
2504 setItemType(items[i], KeyMap::UserUnbind);
2505 removePB->setText(qt_("Res&tore"));
2508 case KeyMap::UserBind: {
2509 // for user_bind, we remove this bind
2510 QTreeWidgetItem * parent = items[i]->parent();
2511 int itemIdx = parent->indexOfChild(items[i]);
2512 parent->takeChild(itemIdx);
2514 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2516 shortcutsTW->scrollToItem(parent);
2517 user_bind_.unbind(shortcut, func);
2520 case KeyMap::UserUnbind: {
2521 // for user_unbind, we remove the unbind, and the item
2522 // become KeyMap::System again.
2523 user_unbind_.unbind(shortcut, func);
2524 setItemType(items[i], KeyMap::System);
2525 removePB->setText(qt_("Remo&ve"));
2528 case KeyMap::UserExtraUnbind: {
2529 // for user unbind that is not in system bind file,
2530 // remove this unbind file
2531 QTreeWidgetItem * parent = items[i]->parent();
2532 parent->takeChild(parent->indexOfChild(items[i]));
2533 user_unbind_.unbind(shortcut, func);
2540 void PrefShortcuts::selectBind()
2542 QString file = form_->browsebind(internalPath(bindFileED->text()));
2543 if (!file.isEmpty()) {
2544 bindFileED->setText(file);
2545 system_bind_ = KeyMap();
2546 system_bind_.read(fromqstr(file));
2547 updateShortcutsTW();
2552 void PrefShortcuts::on_modifyPB_pressed()
2558 void PrefShortcuts::on_newPB_pressed()
2560 shortcut_->lfunLE->clear();
2561 shortcut_->shortcutWG->reset();
2562 save_lfun_ = QString();
2567 void PrefShortcuts::on_removePB_pressed()
2573 void PrefShortcuts::on_searchLE_textEdited()
2575 if (searchLE->text().isEmpty()) {
2576 // show all hidden items
2577 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2579 shortcutsTW->setItemHidden(*it++, false);
2582 // search both columns
2583 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2584 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2585 matched += shortcutsTW->findItems(searchLE->text(),
2586 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2588 // hide everyone (to avoid searching in matched QList repeatedly
2589 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2591 shortcutsTW->setItemHidden(*it++, true);
2592 // show matched items
2593 for (int i = 0; i < matched.size(); ++i) {
2594 shortcutsTW->setItemHidden(matched[i], false);
2595 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2600 docstring makeCmdString(FuncRequest const & f)
2602 docstring actionStr = from_ascii(lyxaction.getActionName(f.action));
2603 if (!f.argument().empty())
2604 actionStr += " " + f.argument();
2609 void PrefShortcuts::shortcutOkPressed()
2611 QString const new_lfun = shortcut_->lfunLE->text();
2612 FuncRequest func = lyxaction.lookupFunc(fromqstr(new_lfun));
2614 if (func.action == LFUN_UNKNOWN_ACTION) {
2615 Alert::error(_("Failed to create shortcut"),
2616 _("Unknown or invalid LyX function"));
2620 KeySequence k = shortcut_->shortcutWG->getKeySequence();
2621 if (k.length() == 0) {
2622 Alert::error(_("Failed to create shortcut"),
2623 _("Invalid or empty key sequence"));
2627 // check to see if there's been any change
2628 FuncRequest oldBinding = system_bind_.getBinding(k);
2629 if (oldBinding.action == LFUN_UNKNOWN_ACTION)
2630 oldBinding = user_bind_.getBinding(k);
2631 if (oldBinding == func) {
2632 docstring const actionStr = makeCmdString(func);
2633 Alert::error(_("Failed to create shortcut"),
2634 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s"),
2635 k.print(KeySequence::ForGui), actionStr));
2639 // make sure this key isn't already bound---and, if so, not unbound
2640 FuncCode const unbind = user_unbind_.getBinding(k).action;
2641 if (oldBinding.action != LFUN_UNKNOWN_ACTION && unbind == LFUN_UNKNOWN_ACTION)
2643 // FIXME Perhaps we should offer to over-write the old shortcut?
2644 // If so, we'll need to remove it from our list, etc.
2645 docstring const actionStr = makeCmdString(oldBinding);
2646 Alert::error(_("Failed to create shortcut"),
2647 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s\n"
2648 "You need to remove that binding before creating a new one."),
2649 k.print(KeySequence::ForGui), actionStr));
2653 if (!save_lfun_.isEmpty() && new_lfun == save_lfun_)
2654 // real modification of the lfun's shortcut,
2655 // so remove the previous one
2658 QTreeWidgetItem * item = insertShortcutItem(func, k, KeyMap::UserBind);
2660 user_bind_.bind(&k, func);
2661 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2662 shortcutsTW->setItemExpanded(item->parent(), true);
2663 shortcutsTW->scrollToItem(item);
2665 Alert::error(_("Failed to create shortcut"),
2666 _("Can not insert shortcut to the list"));
2672 void PrefShortcuts::shortcutCancelPressed()
2674 shortcut_->shortcutWG->reset();
2678 void PrefShortcuts::shortcutClearPressed()
2680 shortcut_->shortcutWG->reset();
2684 void PrefShortcuts::shortcutRemovePressed()
2686 shortcut_->shortcutWG->removeFromSequence();
2690 /////////////////////////////////////////////////////////////////////
2694 /////////////////////////////////////////////////////////////////////
2696 PrefIdentity::PrefIdentity(GuiPreferences * form)
2697 : PrefModule(QString(), qt_("Identity"), form)
2701 connect(nameED, SIGNAL(textChanged(QString)),
2702 this, SIGNAL(changed()));
2703 connect(emailED, SIGNAL(textChanged(QString)),
2704 this, SIGNAL(changed()));
2708 void PrefIdentity::apply(LyXRC & rc) const
2710 rc.user_name = fromqstr(nameED->text());
2711 rc.user_email = fromqstr(emailED->text());
2715 void PrefIdentity::update(LyXRC const & rc)
2717 nameED->setText(toqstr(rc.user_name));
2718 emailED->setText(toqstr(rc.user_email));
2723 /////////////////////////////////////////////////////////////////////
2727 /////////////////////////////////////////////////////////////////////
2729 GuiPreferences::GuiPreferences(GuiView & lv)
2730 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2734 QDialog::setModal(false);
2736 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2737 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2738 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2739 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2741 addModule(new PrefUserInterface(this));
2742 addModule(new PrefEdit(this));
2743 addModule(new PrefShortcuts(this));
2744 addModule(new PrefScreenFonts(this));
2745 addModule(new PrefColors(this));
2746 addModule(new PrefDisplay(this));
2747 addModule(new PrefInput(this));
2748 addModule(new PrefCompletion(this));
2750 addModule(new PrefPaths(this));
2752 addModule(new PrefIdentity(this));
2754 addModule(new PrefLanguage(this));
2755 addModule(new PrefSpellchecker(this));
2757 addModule(new PrefPrinter(this));
2758 PrefDate * dateFormat = new PrefDate(this);
2759 addModule(dateFormat);
2760 addModule(new PrefPlaintext(this));
2761 addModule(new PrefLatex(this));
2763 PrefConverters * converters = new PrefConverters(this);
2764 PrefFileformats * formats = new PrefFileformats(this);
2765 connect(formats, SIGNAL(formatsChanged()),
2766 converters, SLOT(updateGui()));
2767 addModule(converters);
2770 prefsPS->setCurrentPanel(qt_("User interface"));
2771 // FIXME: hack to work around resizing bug in Qt >= 4.2
2772 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2773 #if QT_VERSION >= 0x040200
2774 prefsPS->updateGeometry();
2777 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2779 bc().setApply(applyPB);
2780 bc().setCancel(closePB);
2781 bc().setRestore(restorePB);
2783 // initialize the strftime validator
2784 bc().addCheckedLineEdit(dateFormat->DateED);
2788 void GuiPreferences::addModule(PrefModule * module)
2790 LASSERT(module, return);
2791 if (module->category().isEmpty())
2792 prefsPS->addPanel(module, module->title());
2794 prefsPS->addPanel(module, module->title(), module->category());
2795 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2796 modules_.push_back(module);
2800 void GuiPreferences::change_adaptor()
2806 void GuiPreferences::apply(LyXRC & rc) const
2808 size_t end = modules_.size();
2809 for (size_t i = 0; i != end; ++i)
2810 modules_[i]->apply(rc);
2814 void GuiPreferences::updateRc(LyXRC const & rc)
2816 size_t const end = modules_.size();
2817 for (size_t i = 0; i != end; ++i)
2818 modules_[i]->update(rc);
2822 void GuiPreferences::applyView()
2827 bool GuiPreferences::initialiseParams(string const &)
2830 formats_ = lyx::formats;
2831 converters_ = theConverters();
2832 converters_.update(formats_);
2833 movers_ = theMovers();
2835 update_screen_font_ = false;
2838 // Make sure that the bc is in the INITIAL state
2839 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
2846 void GuiPreferences::dispatchParams()
2849 rc_.write(ss, true);
2850 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
2851 // FIXME: these need lfuns
2853 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
2855 lyx::formats = formats_;
2857 theConverters() = converters_;
2858 theConverters().update(lyx::formats);
2859 theConverters().buildGraph();
2861 theMovers() = movers_;
2863 vector<string>::const_iterator it = colors_.begin();
2864 vector<string>::const_iterator const end = colors_.end();
2865 for (; it != end; ++it)
2866 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
2869 if (update_screen_font_) {
2870 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2871 update_screen_font_ = false;
2874 // The Save button has been pressed
2876 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
2880 void GuiPreferences::setColor(ColorCode col, QString const & hex)
2882 colors_.push_back(lcolor.getLyXName(col) + ' ' + fromqstr(hex));
2886 void GuiPreferences::updateScreenFonts()
2888 update_screen_font_ = true;
2892 QString GuiPreferences::browsebind(QString const & file) const
2894 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
2895 QStringList(qt_("LyX bind files (*.bind)")));
2899 QString GuiPreferences::browseUI(QString const & file) const
2901 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
2902 QStringList(qt_("LyX UI files (*.ui)")));
2906 QString GuiPreferences::browsekbmap(QString const & file) const
2908 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
2909 QStringList(qt_("LyX keyboard maps (*.kmap)")));
2913 QString GuiPreferences::browsedict(QString const & file) const
2915 return browseFile(file, qt_("Choose personal dictionary"),
2916 QStringList(qt_("*.pws")));
2920 QString GuiPreferences::browse(QString const & file,
2921 QString const & title) const
2923 return browseFile(file, title, QStringList(), true);
2927 // We support less paper sizes than the document dialog
2928 // Therefore this adjustment is needed.
2929 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
2933 return PAPER_DEFAULT;
2935 return PAPER_USLETTER;
2937 return PAPER_USLEGAL;
2939 return PAPER_USEXECUTIVE;
2949 // should not happen
2950 return PAPER_DEFAULT;
2955 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
2957 switch (papersize) {
2960 case PAPER_USLETTER:
2964 case PAPER_USEXECUTIVE:
2975 // should not happen
2981 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
2984 } // namespace frontend
2987 #include "moc_GuiPrefs.cpp"