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 (vector<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 (vector<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 QString const bibtex = latexBibtexCO->itemData(
674 latexBibtexCO->currentIndex()).toString();
675 if (bibtex.isEmpty())
676 rc.bibtex_command = fromqstr(latexBibtexED->text());
678 rc.bibtex_command = fromqstr(bibtex) + " " + fromqstr(latexBibtexED->text());
680 QString const index = latexIndexCO->itemData(
681 latexIndexCO->currentIndex()).toString();
683 rc.index_command = fromqstr(latexIndexED->text());
685 rc.index_command = fromqstr(index) + " " + fromqstr(latexIndexED->text());
687 rc.fontenc = fromqstr(latexEncodingED->text());
688 rc.chktex_command = fromqstr(latexChecktexED->text());
689 rc.jbibtex_command = fromqstr(latexJBibtexED->text());
690 rc.jindex_command = fromqstr(latexJIndexED->text());
691 rc.nomencl_command = fromqstr(latexNomenclED->text());
692 rc.auto_reset_options = latexAutoresetCB->isChecked();
693 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
694 rc.default_papersize =
695 form_->toPaperSize(latexPaperSizeCO->currentIndex());
696 #if defined(__CYGWIN__) || defined(_WIN32)
697 rc.windows_style_tex_paths = pathCB->isChecked();
702 void PrefLatex::update(LyXRC const & rc)
704 latexBibtexCO->clear();
706 latexBibtexCO->addItem(qt_("Custom"), QString());
707 for (vector<string>::const_iterator it = rc.bibtex_alternatives.begin();
708 it != rc.bibtex_alternatives.end(); ++it) {
709 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
710 latexBibtexCO->addItem(command, command);
713 bibtex_alternatives = rc.bibtex_alternatives;
715 QString const bib = toqstr(rc.bibtex_command);
716 int ind = bib.indexOf(" ");
717 QString sel_command = bib.left(ind);
718 QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
720 int pos = latexBibtexCO->findData(sel_command);
722 latexBibtexCO->setCurrentIndex(pos);
723 latexBibtexED->setText(sel_options.trimmed());
724 latexBibtexOptionsLA->setText(qt_("&Options:"));
726 latexBibtexED->setText(toqstr(rc.bibtex_command));
727 latexBibtexCO->setCurrentIndex(0);
728 latexBibtexOptionsLA->setText(qt_("C&ommand:"));
731 latexIndexCO->clear();
733 latexIndexCO->addItem(qt_("Custom"), QString());
734 for (vector<string>::const_iterator it = rc.index_alternatives.begin();
735 it != rc.index_alternatives.end(); ++it) {
736 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
737 latexIndexCO->addItem(command, command);
740 index_alternatives = rc.index_alternatives;
742 QString const idx = toqstr(rc.index_command);
743 ind = idx.indexOf(" ");
744 sel_command = idx.left(ind);
745 sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
747 pos = latexIndexCO->findData(sel_command);
749 latexIndexCO->setCurrentIndex(pos);
750 latexIndexED->setText(sel_options.trimmed());
751 latexIndexOptionsLA->setText(qt_("Op&tions:"));
753 latexIndexED->setText(toqstr(rc.index_command));
754 latexIndexCO->setCurrentIndex(0);
755 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
758 latexEncodingED->setText(toqstr(rc.fontenc));
759 latexChecktexED->setText(toqstr(rc.chktex_command));
760 latexJBibtexED->setText(toqstr(rc.jbibtex_command));
761 latexJIndexED->setText(toqstr(rc.jindex_command));
762 latexNomenclED->setText(toqstr(rc.nomencl_command));
763 latexAutoresetCB->setChecked(rc.auto_reset_options);
764 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
765 latexPaperSizeCO->setCurrentIndex(
766 form_->fromPaperSize(rc.default_papersize));
767 #if defined(__CYGWIN__) || defined(_WIN32)
768 pathCB->setChecked(rc.windows_style_tex_paths);
773 /////////////////////////////////////////////////////////////////////
777 /////////////////////////////////////////////////////////////////////
779 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form)
780 : PrefModule(qt_(catLookAndFeel), qt_("Screen fonts"), form)
784 connect(screenRomanCO, SIGNAL(activated(QString)),
785 this, SLOT(selectRoman(QString)));
786 connect(screenSansCO, SIGNAL(activated(QString)),
787 this, SLOT(selectSans(QString)));
788 connect(screenTypewriterCO, SIGNAL(activated(QString)),
789 this, SLOT(selectTypewriter(QString)));
791 QFontDatabase fontdb;
792 QStringList families(fontdb.families());
793 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
794 screenRomanCO->addItem(*it);
795 screenSansCO->addItem(*it);
796 screenTypewriterCO->addItem(*it);
798 connect(screenRomanCO, SIGNAL(activated(QString)),
799 this, SIGNAL(changed()));
800 connect(screenSansCO, SIGNAL(activated(QString)),
801 this, SIGNAL(changed()));
802 connect(screenTypewriterCO, SIGNAL(activated(QString)),
803 this, SIGNAL(changed()));
804 connect(screenZoomSB, SIGNAL(valueChanged(int)),
805 this, SIGNAL(changed()));
806 connect(screenDpiSB, SIGNAL(valueChanged(int)),
807 this, SIGNAL(changed()));
808 connect(screenTinyED, SIGNAL(textChanged(QString)),
809 this, SIGNAL(changed()));
810 connect(screenSmallestED, SIGNAL(textChanged(QString)),
811 this, SIGNAL(changed()));
812 connect(screenSmallerED, SIGNAL(textChanged(QString)),
813 this, SIGNAL(changed()));
814 connect(screenSmallED, SIGNAL(textChanged(QString)),
815 this, SIGNAL(changed()));
816 connect(screenNormalED, SIGNAL(textChanged(QString)),
817 this, SIGNAL(changed()));
818 connect(screenLargeED, SIGNAL(textChanged(QString)),
819 this, SIGNAL(changed()));
820 connect(screenLargerED, SIGNAL(textChanged(QString)),
821 this, SIGNAL(changed()));
822 connect(screenLargestED, SIGNAL(textChanged(QString)),
823 this, SIGNAL(changed()));
824 connect(screenHugeED, SIGNAL(textChanged(QString)),
825 this, SIGNAL(changed()));
826 connect(screenHugerED, SIGNAL(textChanged(QString)),
827 this, SIGNAL(changed()));
828 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
829 this, SIGNAL(changed()));
831 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
832 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
833 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
834 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
835 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
836 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
837 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
838 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
839 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
840 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
844 void PrefScreenFonts::apply(LyXRC & rc) const
846 LyXRC const oldrc = rc;
848 parseFontName(screenRomanCO->currentText(),
849 rc.roman_font_name, rc.roman_font_foundry);
850 parseFontName(screenSansCO->currentText(),
851 rc.sans_font_name, rc.sans_font_foundry);
852 parseFontName(screenTypewriterCO->currentText(),
853 rc.typewriter_font_name, rc.typewriter_font_foundry);
855 rc.zoom = screenZoomSB->value();
856 rc.dpi = screenDpiSB->value();
857 rc.font_sizes[FONT_SIZE_TINY] = fromqstr(screenTinyED->text());
858 rc.font_sizes[FONT_SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
859 rc.font_sizes[FONT_SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
860 rc.font_sizes[FONT_SIZE_SMALL] = fromqstr(screenSmallED->text());
861 rc.font_sizes[FONT_SIZE_NORMAL] = fromqstr(screenNormalED->text());
862 rc.font_sizes[FONT_SIZE_LARGE] = fromqstr(screenLargeED->text());
863 rc.font_sizes[FONT_SIZE_LARGER] = fromqstr(screenLargerED->text());
864 rc.font_sizes[FONT_SIZE_LARGEST] = fromqstr(screenLargestED->text());
865 rc.font_sizes[FONT_SIZE_HUGE] = fromqstr(screenHugeED->text());
866 rc.font_sizes[FONT_SIZE_HUGER] = fromqstr(screenHugerED->text());
867 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
869 if (rc.font_sizes != oldrc.font_sizes
870 || rc.roman_font_name != oldrc.roman_font_name
871 || rc.sans_font_name != oldrc.sans_font_name
872 || rc.typewriter_font_name != oldrc.typewriter_font_name
873 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
874 // The global QPixmapCache is used in GuiPainter to cache text
875 // painting so we must reset it in case any of the above
876 // parameter is changed.
877 QPixmapCache::clear();
878 guiApp->fontLoader().update();
879 form_->updateScreenFonts();
884 void PrefScreenFonts::update(LyXRC const & rc)
886 setComboxFont(screenRomanCO, rc.roman_font_name,
887 rc.roman_font_foundry);
888 setComboxFont(screenSansCO, rc.sans_font_name,
889 rc.sans_font_foundry);
890 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
891 rc.typewriter_font_foundry);
893 selectRoman(screenRomanCO->currentText());
894 selectSans(screenSansCO->currentText());
895 selectTypewriter(screenTypewriterCO->currentText());
897 screenZoomSB->setValue(rc.zoom);
898 screenDpiSB->setValue(rc.dpi);
899 screenTinyED->setText(toqstr(rc.font_sizes[FONT_SIZE_TINY]));
900 screenSmallestED->setText(toqstr(rc.font_sizes[FONT_SIZE_SCRIPT]));
901 screenSmallerED->setText(toqstr(rc.font_sizes[FONT_SIZE_FOOTNOTE]));
902 screenSmallED->setText(toqstr(rc.font_sizes[FONT_SIZE_SMALL]));
903 screenNormalED->setText(toqstr(rc.font_sizes[FONT_SIZE_NORMAL]));
904 screenLargeED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGE]));
905 screenLargerED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGER]));
906 screenLargestED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGEST]));
907 screenHugeED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGE]));
908 screenHugerED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGER]));
910 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
911 #if defined(Q_WS_X11)
912 pixmapCacheCB->setEnabled(false);
918 void PrefScreenFonts::selectRoman(const QString & name)
920 screenRomanFE->set(QFont(name), name);
924 void PrefScreenFonts::selectSans(const QString & name)
926 screenSansFE->set(QFont(name), name);
930 void PrefScreenFonts::selectTypewriter(const QString & name)
932 screenTypewriterFE->set(QFont(name), name);
936 /////////////////////////////////////////////////////////////////////
940 /////////////////////////////////////////////////////////////////////
946 bool operator()(ColorCode lhs, ColorCode rhs) const {
948 compare_no_case(lcolor.getGUIName(lhs), lcolor.getGUIName(rhs)) < 0;
954 PrefColors::PrefColors(GuiPreferences * form)
955 : PrefModule(qt_(catLookAndFeel), qt_("Colors"), form)
959 // FIXME: all of this initialization should be put into the controller.
960 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
961 // for some discussion of why that is not trivial.
962 QPixmap icon(32, 32);
963 for (int i = 0; i < Color_ignore; ++i) {
964 ColorCode lc = static_cast<ColorCode>(i);
972 || lc == Color_magenta
973 || lc == Color_yellow
974 || lc == Color_inherit
975 || lc == Color_ignore) continue;
977 lcolors_.push_back(lc);
979 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
980 vector<ColorCode>::const_iterator cit = lcolors_.begin();
981 vector<ColorCode>::const_iterator const end = lcolors_.end();
982 for (; cit != end; ++cit) {
983 (void) new QListWidgetItem(QIcon(icon),
984 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
986 curcolors_.resize(lcolors_.size());
987 newcolors_.resize(lcolors_.size());
988 // End initialization
990 connect(colorChangePB, SIGNAL(clicked()),
991 this, SLOT(changeColor()));
992 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
993 this, SLOT(changeLyxObjectsSelection()));
994 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
995 this, SLOT(changeColor()));
999 void PrefColors::apply(LyXRC & /*rc*/) const
1001 for (unsigned int i = 0; i < lcolors_.size(); ++i)
1002 if (curcolors_[i] != newcolors_[i])
1003 form_->setColor(lcolors_[i], newcolors_[i]);
1007 void PrefColors::update(LyXRC const & /*rc*/)
1009 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
1010 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
1011 QPixmap coloritem(32, 32);
1012 coloritem.fill(color);
1013 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
1014 newcolors_[i] = curcolors_[i] = color.name();
1016 changeLyxObjectsSelection();
1020 void PrefColors::changeColor()
1022 int const row = lyxObjectsLW->currentRow();
1028 QString const color = newcolors_[row];
1029 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
1031 if (c.isValid() && c.name() != color) {
1032 newcolors_[row] = c.name();
1033 QPixmap coloritem(32, 32);
1035 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
1041 void PrefColors::changeLyxObjectsSelection()
1043 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
1047 /////////////////////////////////////////////////////////////////////
1051 /////////////////////////////////////////////////////////////////////
1053 PrefDisplay::PrefDisplay(GuiPreferences * form)
1054 : PrefModule(qt_(catLookAndFeel), qt_("Graphics"), form)
1057 connect(displayGraphicsCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
1058 connect(instantPreviewCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
1062 void PrefDisplay::apply(LyXRC & rc) const
1064 switch (instantPreviewCO->currentIndex()) {
1065 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
1066 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
1067 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
1070 rc.display_graphics = displayGraphicsCB->isChecked();
1072 // FIXME!! The graphics cache no longer has a changeDisplay method.
1074 if (old_value != rc.display_graphics) {
1075 graphics::GCache & gc = graphics::GCache::get();
1082 void PrefDisplay::update(LyXRC const & rc)
1084 switch (rc.preview) {
1085 case LyXRC::PREVIEW_OFF:
1086 instantPreviewCO->setCurrentIndex(0);
1088 case LyXRC::PREVIEW_NO_MATH :
1089 instantPreviewCO->setCurrentIndex(1);
1091 case LyXRC::PREVIEW_ON :
1092 instantPreviewCO->setCurrentIndex(2);
1096 displayGraphicsCB->setChecked(rc.display_graphics);
1097 instantPreviewCO->setEnabled(rc.display_graphics);
1101 /////////////////////////////////////////////////////////////////////
1105 /////////////////////////////////////////////////////////////////////
1107 PrefPaths::PrefPaths(GuiPreferences * form)
1108 : PrefModule(QString(), qt_("Paths"), form)
1111 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(selectExampledir()));
1112 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(selectTemplatedir()));
1113 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(selectTempdir()));
1114 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(selectBackupdir()));
1115 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(selectWorkingdir()));
1116 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(selectLyxPipe()));
1117 connect(thesaurusDirPB, SIGNAL(clicked()), this, SLOT(selectThesaurusdir()));
1118 connect(workingDirED, SIGNAL(textChanged(QString)),
1119 this, SIGNAL(changed()));
1120 connect(exampleDirED, SIGNAL(textChanged(QString)),
1121 this, SIGNAL(changed()));
1122 connect(templateDirED, SIGNAL(textChanged(QString)),
1123 this, SIGNAL(changed()));
1124 connect(backupDirED, SIGNAL(textChanged(QString)),
1125 this, SIGNAL(changed()));
1126 connect(tempDirED, SIGNAL(textChanged(QString)),
1127 this, SIGNAL(changed()));
1128 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
1129 this, SIGNAL(changed()));
1130 connect(thesaurusDirED, SIGNAL(textChanged(QString)),
1131 this, SIGNAL(changed()));
1132 connect(pathPrefixED, SIGNAL(textChanged(QString)),
1133 this, SIGNAL(changed()));
1137 void PrefPaths::apply(LyXRC & rc) const
1139 rc.document_path = internal_path(fromqstr(workingDirED->text()));
1140 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
1141 rc.template_path = internal_path(fromqstr(templateDirED->text()));
1142 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
1143 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
1144 rc.thesaurusdir_path = internal_path(fromqstr(thesaurusDirED->text()));
1145 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
1146 // FIXME: should be a checkbox only
1147 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
1151 void PrefPaths::update(LyXRC const & rc)
1153 workingDirED->setText(toqstr(external_path(rc.document_path)));
1154 exampleDirED->setText(toqstr(external_path(rc.example_path)));
1155 templateDirED->setText(toqstr(external_path(rc.template_path)));
1156 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
1157 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
1158 thesaurusDirED->setText(toqstr(external_path(rc.thesaurusdir_path)));
1159 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
1160 // FIXME: should be a checkbox only
1161 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
1165 void PrefPaths::selectExampledir()
1167 QString file = browseDir(internalPath(exampleDirED->text()),
1168 qt_("Select directory for example files"));
1169 if (!file.isEmpty())
1170 exampleDirED->setText(file);
1174 void PrefPaths::selectTemplatedir()
1176 QString file = browseDir(internalPath(templateDirED->text()),
1177 qt_("Select a document templates directory"));
1178 if (!file.isEmpty())
1179 templateDirED->setText(file);
1183 void PrefPaths::selectTempdir()
1185 QString file = browseDir(internalPath(tempDirED->text()),
1186 qt_("Select a temporary directory"));
1187 if (!file.isEmpty())
1188 tempDirED->setText(file);
1192 void PrefPaths::selectBackupdir()
1194 QString file = browseDir(internalPath(backupDirED->text()),
1195 qt_("Select a backups directory"));
1196 if (!file.isEmpty())
1197 backupDirED->setText(file);
1201 void PrefPaths::selectWorkingdir()
1203 QString file = browseDir(internalPath(workingDirED->text()),
1204 qt_("Select a document directory"));
1205 if (!file.isEmpty())
1206 workingDirED->setText(file);
1210 void PrefPaths::selectThesaurusdir()
1212 QString file = browseDir(internalPath(thesaurusDirED->text()),
1213 qt_("Set the path to the thesaurus dictionaries"));
1214 if (!file.isEmpty())
1215 thesaurusDirED->setText(file);
1219 void PrefPaths::selectLyxPipe()
1221 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1222 qt_("Give a filename for the LyX server pipe"));
1223 if (!file.isEmpty())
1224 lyxserverDirED->setText(file);
1228 /////////////////////////////////////////////////////////////////////
1232 /////////////////////////////////////////////////////////////////////
1234 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form)
1235 : PrefModule(qt_(catLanguage), qt_("Spellchecker"), form)
1239 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(selectDict()));
1241 connect(altLanguageED, SIGNAL(textChanged(QString)),
1242 this, SIGNAL(changed()));
1243 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1244 this, SIGNAL(changed()));
1245 connect(persDictionaryED, SIGNAL(textChanged(QString)),
1246 this, SIGNAL(changed()));
1247 connect(compoundWordCB, SIGNAL(clicked()),
1248 this, SIGNAL(changed()));
1249 connect(inputEncodingCB, SIGNAL(clicked()),
1250 this, SIGNAL(changed()));
1251 connect(spellcheckContinuouslyCB, SIGNAL(clicked()),
1252 this, SIGNAL(changed()));
1256 void PrefSpellchecker::apply(LyXRC & rc) const
1258 // FIXME: remove spellchecker_use_alt_lang
1259 rc.spellchecker_alt_lang = fromqstr(altLanguageED->text());
1260 rc.spellchecker_use_alt_lang = !rc.spellchecker_alt_lang.empty();
1261 // FIXME: remove spellchecker_use_esc_chars
1262 rc.spellchecker_esc_chars = fromqstr(escapeCharactersED->text());
1263 rc.spellchecker_use_esc_chars = !rc.spellchecker_esc_chars.empty();
1264 // FIXME: remove spellchecker_use_pers_dict
1265 rc.spellchecker_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
1266 rc.spellchecker_use_pers_dict = !rc.spellchecker_pers_dict.empty();
1267 rc.spellchecker_accept_compound = compoundWordCB->isChecked();
1268 rc.spellchecker_use_input_encoding = inputEncodingCB->isChecked();
1269 rc.spellcheck_continuously = spellcheckContinuouslyCB->isChecked();
1273 void PrefSpellchecker::update(LyXRC const & rc)
1275 // FIXME: remove spellchecker_use_alt_lang
1276 altLanguageED->setText(toqstr(rc.spellchecker_alt_lang));
1277 // FIXME: remove spellchecker_use_esc_chars
1278 escapeCharactersED->setText(toqstr(rc.spellchecker_esc_chars));
1279 // FIXME: remove spellchecker_use_pers_dict
1280 persDictionaryED->setText(toqstr(external_path(rc.spellchecker_pers_dict)));
1281 compoundWordCB->setChecked(rc.spellchecker_accept_compound);
1282 inputEncodingCB->setChecked(rc.spellchecker_use_input_encoding);
1283 spellcheckContinuouslyCB->setChecked(rc.spellcheck_continuously);
1287 void PrefSpellchecker::selectDict()
1289 QString file = form_->browsedict(internalPath(persDictionaryED->text()));
1290 if (!file.isEmpty())
1291 persDictionaryED->setText(file);
1296 /////////////////////////////////////////////////////////////////////
1300 /////////////////////////////////////////////////////////////////////
1303 PrefConverters::PrefConverters(GuiPreferences * form)
1304 : PrefModule(qt_(catFiles), qt_("Converters"), form)
1308 connect(converterNewPB, SIGNAL(clicked()),
1309 this, SLOT(updateConverter()));
1310 connect(converterRemovePB, SIGNAL(clicked()),
1311 this, SLOT(removeConverter()));
1312 connect(converterModifyPB, SIGNAL(clicked()),
1313 this, SLOT(updateConverter()));
1314 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1315 this, SLOT(switchConverter()));
1316 connect(converterFromCO, SIGNAL(activated(QString)),
1317 this, SLOT(changeConverter()));
1318 connect(converterToCO, SIGNAL(activated(QString)),
1319 this, SLOT(changeConverter()));
1320 connect(converterED, SIGNAL(textEdited(QString)),
1321 this, SLOT(changeConverter()));
1322 connect(converterFlagED, SIGNAL(textEdited(QString)),
1323 this, SLOT(changeConverter()));
1324 connect(converterNewPB, SIGNAL(clicked()),
1325 this, SIGNAL(changed()));
1326 connect(converterRemovePB, SIGNAL(clicked()),
1327 this, SIGNAL(changed()));
1328 connect(converterModifyPB, SIGNAL(clicked()),
1329 this, SIGNAL(changed()));
1330 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1331 this, SIGNAL(changed()));
1333 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1334 //converterDefGB->setFocusProxy(convertersLW);
1338 void PrefConverters::apply(LyXRC & rc) const
1340 rc.use_converter_cache = cacheCB->isChecked();
1341 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
1345 void PrefConverters::update(LyXRC const & rc)
1347 cacheCB->setChecked(rc.use_converter_cache);
1349 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
1350 maxAgeLE->setText(max_age);
1355 void PrefConverters::updateGui()
1357 form_->formats().sort();
1358 form_->converters().update(form_->formats());
1359 // save current selection
1360 QString current = converterFromCO->currentText()
1361 + " -> " + converterToCO->currentText();
1363 converterFromCO->clear();
1364 converterToCO->clear();
1366 Formats::const_iterator cit = form_->formats().begin();
1367 Formats::const_iterator end = form_->formats().end();
1368 for (; cit != end; ++cit) {
1369 converterFromCO->addItem(qt_(cit->prettyname()));
1370 converterToCO->addItem(qt_(cit->prettyname()));
1373 // currentRowChanged(int) is also triggered when updating the listwidget
1374 // block signals to avoid unnecessary calls to switchConverter()
1375 convertersLW->blockSignals(true);
1376 convertersLW->clear();
1378 Converters::const_iterator ccit = form_->converters().begin();
1379 Converters::const_iterator cend = form_->converters().end();
1380 for (; ccit != cend; ++ccit) {
1381 QString const name =
1382 qt_(ccit->From->prettyname()) + " -> " + qt_(ccit->To->prettyname());
1383 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1384 new QListWidgetItem(name, convertersLW, type);
1386 convertersLW->sortItems(Qt::AscendingOrder);
1387 convertersLW->blockSignals(false);
1389 // restore selection
1390 if (!current.isEmpty()) {
1391 QList<QListWidgetItem *> const item =
1392 convertersLW->findItems(current, Qt::MatchExactly);
1393 if (!item.isEmpty())
1394 convertersLW->setCurrentItem(item.at(0));
1397 // select first element if restoring failed
1398 if (convertersLW->currentRow() == -1)
1399 convertersLW->setCurrentRow(0);
1405 void PrefConverters::switchConverter()
1407 int const cnr = convertersLW->currentItem()->type();
1408 Converter const & c(form_->converters().get(cnr));
1409 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1410 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1411 converterED->setText(toqstr(c.command));
1412 converterFlagED->setText(toqstr(c.flags));
1418 void PrefConverters::changeConverter()
1424 void PrefConverters::updateButtons()
1426 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1427 Format const & to = form_->formats().get(converterToCO->currentIndex());
1428 int const sel = form_->converters().getNumber(from.name(), to.name());
1429 bool const known = sel >= 0;
1430 bool const valid = !(converterED->text().isEmpty()
1431 || from.name() == to.name());
1433 int const cnr = convertersLW->currentItem()->type();
1434 Converter const & c = form_->converters().get(cnr);
1435 string const old_command = c.command;
1436 string const old_flag = c.flags;
1437 string const new_command = fromqstr(converterED->text());
1438 string const new_flag = fromqstr(converterFlagED->text());
1440 bool modified = (old_command != new_command || old_flag != new_flag);
1442 converterModifyPB->setEnabled(valid && known && modified);
1443 converterNewPB->setEnabled(valid && !known);
1444 converterRemovePB->setEnabled(known);
1446 maxAgeLE->setEnabled(cacheCB->isChecked());
1447 maxAgeLA->setEnabled(cacheCB->isChecked());
1452 // specify unique from/to or it doesn't appear. This is really bad UI
1453 // this is why we can use the same function for both new and modify
1454 void PrefConverters::updateConverter()
1456 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1457 Format const & to = form_->formats().get(converterToCO->currentIndex());
1458 string const flags = fromqstr(converterFlagED->text());
1459 string const command = fromqstr(converterED->text());
1461 Converter const * old =
1462 form_->converters().getConverter(from.name(), to.name());
1463 form_->converters().add(from.name(), to.name(), command, flags);
1466 form_->converters().updateLast(form_->formats());
1470 // Remove all files created by this converter from the cache, since
1471 // the modified converter might create different files.
1472 ConverterCache::get().remove_all(from.name(), to.name());
1476 void PrefConverters::removeConverter()
1478 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1479 Format const & to = form_->formats().get(converterToCO->currentIndex());
1480 form_->converters().erase(from.name(), to.name());
1484 // Remove all files created by this converter from the cache, since
1485 // a possible new converter might create different files.
1486 ConverterCache::get().remove_all(from.name(), to.name());
1490 void PrefConverters::on_cacheCB_stateChanged(int state)
1492 maxAgeLE->setEnabled(state == Qt::Checked);
1493 maxAgeLA->setEnabled(state == Qt::Checked);
1498 /////////////////////////////////////////////////////////////////////
1502 /////////////////////////////////////////////////////////////////////
1504 class FormatValidator : public QValidator
1507 FormatValidator(QWidget *, Formats const & f);
1508 void fixup(QString & input) const;
1509 QValidator::State validate(QString & input, int & pos) const;
1511 virtual QString toString(Format const & format) const = 0;
1513 Formats const & formats_;
1517 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1518 : QValidator(parent), formats_(f)
1523 void FormatValidator::fixup(QString & input) const
1525 Formats::const_iterator cit = formats_.begin();
1526 Formats::const_iterator end = formats_.end();
1527 for (; cit != end; ++cit) {
1528 QString const name = toString(*cit);
1529 if (distance(formats_.begin(), cit) == nr()) {
1537 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1539 Formats::const_iterator cit = formats_.begin();
1540 Formats::const_iterator end = formats_.end();
1541 bool unknown = true;
1542 for (; unknown && cit != end; ++cit) {
1543 QString const name = toString(*cit);
1544 if (distance(formats_.begin(), cit) != nr())
1545 unknown = name != input;
1548 if (unknown && !input.isEmpty())
1549 return QValidator::Acceptable;
1551 return QValidator::Intermediate;
1555 int FormatValidator::nr() const
1557 QComboBox * p = qobject_cast<QComboBox *>(parent());
1558 return p->itemData(p->currentIndex()).toInt();
1562 /////////////////////////////////////////////////////////////////////
1564 // FormatNameValidator
1566 /////////////////////////////////////////////////////////////////////
1568 class FormatNameValidator : public FormatValidator
1571 FormatNameValidator(QWidget * parent, Formats const & f)
1572 : FormatValidator(parent, f)
1575 QString toString(Format const & format) const
1577 return toqstr(format.name());
1582 /////////////////////////////////////////////////////////////////////
1584 // FormatPrettynameValidator
1586 /////////////////////////////////////////////////////////////////////
1588 class FormatPrettynameValidator : public FormatValidator
1591 FormatPrettynameValidator(QWidget * parent, Formats const & f)
1592 : FormatValidator(parent, f)
1595 QString toString(Format const & format) const
1597 return qt_(format.prettyname());
1602 /////////////////////////////////////////////////////////////////////
1606 /////////////////////////////////////////////////////////////////////
1608 PrefFileformats::PrefFileformats(GuiPreferences * form)
1609 : PrefModule(qt_(catFiles), qt_("File formats"), form)
1612 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1613 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1615 connect(documentCB, SIGNAL(clicked()),
1616 this, SLOT(setFlags()));
1617 connect(vectorCB, SIGNAL(clicked()),
1618 this, SLOT(setFlags()));
1619 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1620 this, SLOT(updatePrettyname()));
1621 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1622 this, SIGNAL(changed()));
1623 connect(defaultFormatCB, SIGNAL(activated(QString)),
1624 this, SIGNAL(changed()));
1630 string const l10n_shortcut(string const prettyname, string const shortcut)
1632 if (shortcut.empty())
1635 string l10n_format =
1636 to_utf8(_(prettyname + '|' + shortcut));
1637 return split(l10n_format, '|');
1640 }; // namespace anon
1643 void PrefFileformats::apply(LyXRC & rc) const
1645 QString const default_format = defaultFormatCB->itemData(
1646 defaultFormatCB->currentIndex()).toString();
1647 rc.default_view_format = fromqstr(default_format);
1651 void PrefFileformats::update(LyXRC const & rc)
1653 bool const init = defaultFormatCB->currentText().isEmpty();
1656 int const pos = defaultFormatCB->findData(toqstr(
1657 rc.default_view_format));
1658 defaultFormatCB->setCurrentIndex(pos);
1663 void PrefFileformats::updateView()
1665 QString const current = formatsCB->currentText();
1666 QString const current_def = defaultFormatCB->currentText();
1668 // update comboboxes with formats
1669 formatsCB->blockSignals(true);
1670 defaultFormatCB->blockSignals(true);
1672 defaultFormatCB->clear();
1673 form_->formats().sort();
1674 Formats::const_iterator cit = form_->formats().begin();
1675 Formats::const_iterator end = form_->formats().end();
1676 for (; cit != end; ++cit) {
1677 formatsCB->addItem(qt_(cit->prettyname()),
1678 QVariant(form_->formats().getNumber(cit->name())));
1679 if (form_->converters().isReachable("latex", cit->name())
1680 || form_->converters().isReachable("pdflatex", cit->name()))
1681 defaultFormatCB->addItem(qt_(cit->prettyname()),
1682 QVariant(toqstr(cit->name())));
1685 // restore selection
1686 int item = formatsCB->findText(current, Qt::MatchExactly);
1687 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1688 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1689 item = defaultFormatCB->findText(current_def, Qt::MatchExactly);
1690 defaultFormatCB->setCurrentIndex(item < 0 ? 0 : item);
1691 formatsCB->blockSignals(false);
1692 defaultFormatCB->blockSignals(false);
1696 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1698 int const nr = formatsCB->itemData(i).toInt();
1699 Format const f = form_->formats().get(nr);
1701 formatED->setText(toqstr(f.name()));
1702 copierED->setText(toqstr(form_->movers().command(f.name())));
1703 extensionED->setText(toqstr(f.extension()));
1704 shortcutED->setText(
1705 toqstr(l10n_shortcut(f.prettyname(), f.shortcut())));
1706 viewerED->setText(toqstr(f.viewer()));
1707 editorED->setText(toqstr(f.editor()));
1708 documentCB->setChecked((f.documentFormat()));
1709 vectorCB->setChecked((f.vectorFormat()));
1713 void PrefFileformats::setFlags()
1715 int flags = Format::none;
1716 if (documentCB->isChecked())
1717 flags |= Format::document;
1718 if (vectorCB->isChecked())
1719 flags |= Format::vector;
1720 currentFormat().setFlags(flags);
1725 void PrefFileformats::on_copierED_textEdited(const QString & s)
1727 string const fmt = fromqstr(formatED->text());
1728 form_->movers().set(fmt, fromqstr(s));
1733 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1735 currentFormat().setExtension(fromqstr(s));
1739 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1741 currentFormat().setViewer(fromqstr(s));
1746 void PrefFileformats::on_editorED_textEdited(const QString & s)
1748 currentFormat().setEditor(fromqstr(s));
1753 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1755 string const new_shortcut = fromqstr(s);
1756 if (new_shortcut == l10n_shortcut(currentFormat().prettyname(),
1757 currentFormat().shortcut()))
1759 currentFormat().setShortcut(new_shortcut);
1764 void PrefFileformats::on_formatED_editingFinished()
1766 string const newname = fromqstr(formatED->displayText());
1767 if (newname == currentFormat().name())
1770 currentFormat().setName(newname);
1775 void PrefFileformats::on_formatED_textChanged(const QString &)
1777 QString t = formatED->text();
1779 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1780 setValid(formatLA, valid);
1784 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1786 QString t = formatsCB->currentText();
1788 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1789 setValid(formatsLA, valid);
1793 void PrefFileformats::updatePrettyname()
1795 QString const newname = formatsCB->currentText();
1796 if (newname == qt_(currentFormat().prettyname()))
1799 currentFormat().setPrettyname(fromqstr(newname));
1806 Format & PrefFileformats::currentFormat()
1808 int const i = formatsCB->currentIndex();
1809 int const nr = formatsCB->itemData(i).toInt();
1810 return form_->formats().get(nr);
1814 void PrefFileformats::on_formatNewPB_clicked()
1816 form_->formats().add("", "", "", "", "", "", Format::none);
1818 formatsCB->setCurrentIndex(0);
1819 formatsCB->setFocus(Qt::OtherFocusReason);
1823 void PrefFileformats::on_formatRemovePB_clicked()
1825 int const i = formatsCB->currentIndex();
1826 int const nr = formatsCB->itemData(i).toInt();
1827 string const current_text = form_->formats().get(nr).name();
1828 if (form_->converters().formatIsUsed(current_text)) {
1829 Alert::error(_("Format in use"),
1830 _("Cannot remove a Format used by a Converter. "
1831 "Remove the converter first."));
1835 form_->formats().erase(current_text);
1838 on_formatsCB_editTextChanged(formatsCB->currentText());
1843 /////////////////////////////////////////////////////////////////////
1847 /////////////////////////////////////////////////////////////////////
1849 PrefLanguage::PrefLanguage(GuiPreferences * form)
1850 : PrefModule(qt_(catLanguage), qt_("Language"), form)
1854 connect(rtlGB, SIGNAL(clicked()),
1855 this, SIGNAL(changed()));
1856 connect(visualCursorRB, SIGNAL(clicked()),
1857 this, SIGNAL(changed()));
1858 connect(logicalCursorRB, SIGNAL(clicked()),
1859 this, SIGNAL(changed()));
1860 connect(markForeignCB, SIGNAL(clicked()),
1861 this, SIGNAL(changed()));
1862 connect(autoBeginCB, SIGNAL(clicked()),
1863 this, SIGNAL(changed()));
1864 connect(autoEndCB, SIGNAL(clicked()),
1865 this, SIGNAL(changed()));
1866 connect(useBabelCB, SIGNAL(clicked()),
1867 this, SIGNAL(changed()));
1868 connect(globalCB, SIGNAL(clicked()),
1869 this, SIGNAL(changed()));
1870 connect(languagePackageED, SIGNAL(textChanged(QString)),
1871 this, SIGNAL(changed()));
1872 connect(startCommandED, SIGNAL(textChanged(QString)),
1873 this, SIGNAL(changed()));
1874 connect(endCommandED, SIGNAL(textChanged(QString)),
1875 this, SIGNAL(changed()));
1876 connect(uiLanguageCO, SIGNAL(activated(int)),
1877 this, SIGNAL(changed()));
1879 uiLanguageCO->clear();
1881 QAbstractItemModel * language_model = guiApp->languageModel();
1882 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1883 language_model->sort(0);
1885 // FIXME: This is wrong, we need filter this list based on the available
1887 uiLanguageCO->blockSignals(true);
1888 uiLanguageCO->addItem(qt_("Default"), toqstr("auto"));
1889 for (int i = 0; i != language_model->rowCount(); ++i) {
1890 QModelIndex index = language_model->index(i, 0);
1891 uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
1892 index.data(Qt::UserRole).toString());
1894 uiLanguageCO->blockSignals(false);
1898 void PrefLanguage::on_uiLanguageCO_currentIndexChanged(int)
1900 QMessageBox::information(this, qt_("LyX needs to be restarted!"),
1901 qt_("The change of user interface language will be fully "
1902 "effective only after a restart."));
1906 void PrefLanguage::apply(LyXRC & rc) const
1908 // FIXME: remove rtl_support bool
1909 rc.rtl_support = rtlGB->isChecked();
1910 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
1911 rc.mark_foreign_language = markForeignCB->isChecked();
1912 rc.language_auto_begin = autoBeginCB->isChecked();
1913 rc.language_auto_end = autoEndCB->isChecked();
1914 rc.language_use_babel = useBabelCB->isChecked();
1915 rc.language_global_options = globalCB->isChecked();
1916 rc.language_package = fromqstr(languagePackageED->text());
1917 rc.language_command_begin = fromqstr(startCommandED->text());
1918 rc.language_command_end = fromqstr(endCommandED->text());
1919 rc.gui_language = fromqstr(
1920 uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString());
1924 void PrefLanguage::update(LyXRC const & rc)
1926 // FIXME: remove rtl_support bool
1927 rtlGB->setChecked(rc.rtl_support);
1928 if (rc.visual_cursor)
1929 visualCursorRB->setChecked(true);
1931 logicalCursorRB->setChecked(true);
1932 markForeignCB->setChecked(rc.mark_foreign_language);
1933 autoBeginCB->setChecked(rc.language_auto_begin);
1934 autoEndCB->setChecked(rc.language_auto_end);
1935 useBabelCB->setChecked(rc.language_use_babel);
1936 globalCB->setChecked(rc.language_global_options);
1937 languagePackageED->setText(toqstr(rc.language_package));
1938 startCommandED->setText(toqstr(rc.language_command_begin));
1939 endCommandED->setText(toqstr(rc.language_command_end));
1941 int pos = uiLanguageCO->findData(toqstr(rc.gui_language));
1942 uiLanguageCO->blockSignals(true);
1943 uiLanguageCO->setCurrentIndex(pos);
1944 uiLanguageCO->blockSignals(false);
1948 /////////////////////////////////////////////////////////////////////
1952 /////////////////////////////////////////////////////////////////////
1954 PrefPrinter::PrefPrinter(GuiPreferences * form)
1955 : PrefModule(qt_(catOutput), qt_("Printer"), form)
1959 connect(printerAdaptCB, SIGNAL(clicked()),
1960 this, SIGNAL(changed()));
1961 connect(printerCommandED, SIGNAL(textChanged(QString)),
1962 this, SIGNAL(changed()));
1963 connect(printerNameED, SIGNAL(textChanged(QString)),
1964 this, SIGNAL(changed()));
1965 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
1966 this, SIGNAL(changed()));
1967 connect(printerCopiesED, SIGNAL(textChanged(QString)),
1968 this, SIGNAL(changed()));
1969 connect(printerReverseED, SIGNAL(textChanged(QString)),
1970 this, SIGNAL(changed()));
1971 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
1972 this, SIGNAL(changed()));
1973 connect(printerExtensionED, SIGNAL(textChanged(QString)),
1974 this, SIGNAL(changed()));
1975 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
1976 this, SIGNAL(changed()));
1977 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
1978 this, SIGNAL(changed()));
1979 connect(printerEvenED, SIGNAL(textChanged(QString)),
1980 this, SIGNAL(changed()));
1981 connect(printerOddED, SIGNAL(textChanged(QString)),
1982 this, SIGNAL(changed()));
1983 connect(printerCollatedED, SIGNAL(textChanged(QString)),
1984 this, SIGNAL(changed()));
1985 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
1986 this, SIGNAL(changed()));
1987 connect(printerToFileED, SIGNAL(textChanged(QString)),
1988 this, SIGNAL(changed()));
1989 connect(printerExtraED, SIGNAL(textChanged(QString)),
1990 this, SIGNAL(changed()));
1991 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
1992 this, SIGNAL(changed()));
1993 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
1994 this, SIGNAL(changed()));
1998 void PrefPrinter::apply(LyXRC & rc) const
2000 rc.print_adapt_output = printerAdaptCB->isChecked();
2001 rc.print_command = fromqstr(printerCommandED->text());
2002 rc.printer = fromqstr(printerNameED->text());
2004 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
2005 rc.print_copies_flag = fromqstr(printerCopiesED->text());
2006 rc.print_reverse_flag = fromqstr(printerReverseED->text());
2007 rc.print_to_printer = fromqstr(printerToPrinterED->text());
2008 rc.print_file_extension = fromqstr(printerExtensionED->text());
2009 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
2010 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
2011 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
2012 rc.print_oddpage_flag = fromqstr(printerOddED->text());
2013 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
2014 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
2015 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
2016 rc.print_extra_options = fromqstr(printerExtraED->text());
2017 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
2018 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
2022 void PrefPrinter::update(LyXRC const & rc)
2024 printerAdaptCB->setChecked(rc.print_adapt_output);
2025 printerCommandED->setText(toqstr(rc.print_command));
2026 printerNameED->setText(toqstr(rc.printer));
2028 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
2029 printerCopiesED->setText(toqstr(rc.print_copies_flag));
2030 printerReverseED->setText(toqstr(rc.print_reverse_flag));
2031 printerToPrinterED->setText(toqstr(rc.print_to_printer));
2032 printerExtensionED->setText(toqstr(rc.print_file_extension));
2033 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
2034 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
2035 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
2036 printerOddED->setText(toqstr(rc.print_oddpage_flag));
2037 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
2038 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
2039 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
2040 printerExtraED->setText(toqstr(rc.print_extra_options));
2041 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
2042 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
2046 /////////////////////////////////////////////////////////////////////
2048 // PrefUserInterface
2050 /////////////////////////////////////////////////////////////////////
2052 PrefUserInterface::PrefUserInterface(GuiPreferences * form)
2053 : PrefModule(qt_(catLookAndFeel), qt_("User interface"), form)
2057 connect(autoSaveCB, SIGNAL(toggled(bool)),
2058 autoSaveSB, SLOT(setEnabled(bool)));
2059 connect(autoSaveCB, SIGNAL(toggled(bool)),
2060 TextLabel1, SLOT(setEnabled(bool)));
2061 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
2062 this, SIGNAL(changed()));
2063 connect(uiFilePB, SIGNAL(clicked()),
2064 this, SLOT(selectUi()));
2065 connect(uiFileED, SIGNAL(textChanged(QString)),
2066 this, SIGNAL(changed()));
2067 connect(restoreCursorCB, SIGNAL(clicked()),
2068 this, SIGNAL(changed()));
2069 connect(loadSessionCB, SIGNAL(clicked()),
2070 this, SIGNAL(changed()));
2071 connect(allowGeometrySessionCB, SIGNAL(clicked()),
2072 this, SIGNAL(changed()));
2073 connect(autoSaveSB, SIGNAL(valueChanged(int)),
2074 this, SIGNAL(changed()));
2075 connect(autoSaveCB, SIGNAL(clicked()),
2076 this, SIGNAL(changed()));
2077 connect(lastfilesSB, SIGNAL(valueChanged(int)),
2078 this, SIGNAL(changed()));
2079 connect(tooltipCB, SIGNAL(toggled(bool)),
2080 this, SIGNAL(changed()));
2081 lastfilesSB->setMaximum(maxlastfiles);
2085 void PrefUserInterface::apply(LyXRC & rc) const
2087 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
2088 rc.use_lastfilepos = restoreCursorCB->isChecked();
2089 rc.load_session = loadSessionCB->isChecked();
2090 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
2091 rc.autosave = autoSaveSB->value() * 60;
2092 rc.make_backup = autoSaveCB->isChecked();
2093 rc.num_lastfiles = lastfilesSB->value();
2094 rc.use_tooltip = tooltipCB->isChecked();
2095 rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
2099 void PrefUserInterface::update(LyXRC const & rc)
2101 uiFileED->setText(toqstr(external_path(rc.ui_file)));
2102 restoreCursorCB->setChecked(rc.use_lastfilepos);
2103 loadSessionCB->setChecked(rc.load_session);
2104 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
2105 // convert to minutes
2106 int mins(rc.autosave / 60);
2107 if (rc.autosave && !mins)
2109 autoSaveSB->setValue(mins);
2110 autoSaveCB->setChecked(rc.make_backup);
2111 lastfilesSB->setValue(rc.num_lastfiles);
2112 tooltipCB->setChecked(rc.use_tooltip);
2113 openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
2117 void PrefUserInterface::selectUi()
2119 QString file = form_->browseUI(internalPath(uiFileED->text()));
2120 if (!file.isEmpty())
2121 uiFileED->setText(file);
2125 void PrefUserInterface::on_clearSessionPB_clicked()
2127 guiApp->clearSession();
2132 /////////////////////////////////////////////////////////////////////
2136 /////////////////////////////////////////////////////////////////////
2138 PrefEdit::PrefEdit(GuiPreferences * form)
2139 : PrefModule(qt_(catEditing), qt_("Control"), form)
2143 connect(cursorFollowsCB, SIGNAL(clicked()),
2144 this, SIGNAL(changed()));
2145 connect(scrollBelowCB, SIGNAL(clicked()),
2146 this, SIGNAL(changed()));
2147 connect(sortEnvironmentsCB, SIGNAL(clicked()),
2148 this, SIGNAL(changed()));
2149 connect(groupEnvironmentsCB, SIGNAL(clicked()),
2150 this, SIGNAL(changed()));
2151 connect(macroEditStyleCO, SIGNAL(activated(int)),
2152 this, SIGNAL(changed()));
2153 connect(fullscreenLimitGB, SIGNAL(clicked()),
2154 this, SIGNAL(changed()));
2155 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
2156 this, SIGNAL(changed()));
2157 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
2158 this, SIGNAL(changed()));
2159 connect(toggleMenubarCB, SIGNAL(toggled(bool)),
2160 this, SIGNAL(changed()));
2161 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
2162 this, SIGNAL(changed()));
2163 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
2164 this, SIGNAL(changed()));
2168 void PrefEdit::apply(LyXRC & rc) const
2170 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
2171 rc.scroll_below_document = scrollBelowCB->isChecked();
2172 rc.sort_layouts = sortEnvironmentsCB->isChecked();
2173 rc.group_layouts = groupEnvironmentsCB->isChecked();
2174 switch (macroEditStyleCO->currentIndex()) {
2175 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
2176 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
2177 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
2179 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
2180 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
2181 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
2182 rc.full_screen_menubar = toggleMenubarCB->isChecked();
2183 rc.full_screen_width = fullscreenWidthSB->value();
2184 rc.full_screen_limit = fullscreenLimitGB->isChecked();
2188 void PrefEdit::update(LyXRC const & rc)
2190 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
2191 scrollBelowCB->setChecked(rc.scroll_below_document);
2192 sortEnvironmentsCB->setChecked(rc.sort_layouts);
2193 groupEnvironmentsCB->setChecked(rc.group_layouts);
2194 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
2195 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
2196 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
2197 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
2198 toggleMenubarCB->setChecked(rc.full_screen_menubar);
2199 fullscreenWidthSB->setValue(rc.full_screen_width);
2200 fullscreenLimitGB->setChecked(rc.full_screen_limit);
2204 /////////////////////////////////////////////////////////////////////
2208 /////////////////////////////////////////////////////////////////////
2211 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
2213 Ui::shortcutUi::setupUi(this);
2214 QDialog::setModal(true);
2218 PrefShortcuts::PrefShortcuts(GuiPreferences * form)
2219 : PrefModule(qt_(catEditing), qt_("Shortcuts"), form)
2223 shortcutsTW->setColumnCount(2);
2224 shortcutsTW->headerItem()->setText(0, qt_("Function"));
2225 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
2226 shortcutsTW->setSortingEnabled(true);
2227 // Multi-selection can be annoying.
2228 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
2230 connect(bindFilePB, SIGNAL(clicked()),
2231 this, SLOT(selectBind()));
2232 connect(bindFileED, SIGNAL(textChanged(QString)),
2233 this, SIGNAL(changed()));
2234 connect(removePB, SIGNAL(clicked()),
2235 this, SIGNAL(changed()));
2237 shortcut_ = new GuiShortcutDialog(this);
2238 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
2239 shortcut_bc_.setOK(shortcut_->okPB);
2240 shortcut_bc_.setCancel(shortcut_->cancelPB);
2242 connect(shortcut_->okPB, SIGNAL(clicked()),
2243 shortcut_, SLOT(accept()));
2244 connect(shortcut_->okPB, SIGNAL(clicked()),
2245 this, SIGNAL(changed()));
2246 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2247 shortcut_, SLOT(reject()));
2248 connect(shortcut_->clearPB, SIGNAL(clicked()),
2249 this, SLOT(shortcutClearPressed()));
2250 connect(shortcut_->removePB, SIGNAL(clicked()),
2251 this, SLOT(shortcutRemovePressed()));
2252 connect(shortcut_->okPB, SIGNAL(clicked()),
2253 this, SLOT(shortcutOkPressed()));
2254 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2255 this, SLOT(shortcutCancelPressed()));
2259 void PrefShortcuts::apply(LyXRC & rc) const
2261 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
2262 // write user_bind and user_unbind to .lyx/bind/user.bind
2263 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
2264 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
2265 lyxerr << "LyX could not create the user bind directory '"
2266 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2269 if (!bind_dir.isDirWritable()) {
2270 lyxerr << "LyX could not write to the user bind directory '"
2271 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2274 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
2275 user_unbind_.write(user_bind_file.toFilesystemEncoding(), false, true);
2276 user_bind_.write(user_bind_file.toFilesystemEncoding(), true, false);
2277 // immediately apply the keybindings. Why this is not done before?
2278 // The good thing is that the menus are updated automatically.
2279 theTopLevelKeymap().clear();
2280 theTopLevelKeymap().read("site");
2281 theTopLevelKeymap().read(rc.bind_file);
2282 theTopLevelKeymap().read("user");
2286 void PrefShortcuts::update(LyXRC const & rc)
2288 bindFileED->setText(toqstr(external_path(rc.bind_file)));
2290 system_bind_.clear();
2292 user_unbind_.clear();
2293 system_bind_.read("site");
2294 system_bind_.read(rc.bind_file);
2295 // \unbind in user.bind is added to user_unbind_
2296 user_bind_.read("user", &user_unbind_);
2297 updateShortcutsTW();
2301 void PrefShortcuts::updateShortcutsTW()
2303 shortcutsTW->clear();
2305 editItem_ = new QTreeWidgetItem(shortcutsTW);
2306 editItem_->setText(0, qt_("Cursor, Mouse and Editing functions"));
2307 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2309 mathItem_ = new QTreeWidgetItem(shortcutsTW);
2310 mathItem_->setText(0, qt_("Mathematical Symbols"));
2311 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2313 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2314 bufferItem_->setText(0, qt_("Document and Window"));
2315 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2317 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2318 layoutItem_->setText(0, qt_("Font, Layouts and Textclasses"));
2319 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2321 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2322 systemItem_->setText(0, qt_("System and Miscellaneous"));
2323 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2325 // listBindings(unbound=true) lists all bound and unbound lfuns
2326 // Items in this list is tagged by its source.
2327 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2329 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2331 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2332 KeyMap::UserUnbind);
2333 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2334 user_bindinglist.end());
2335 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2336 user_unbindinglist.end());
2338 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2339 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2340 for (; it != it_end; ++it)
2341 insertShortcutItem(it->request, it->sequence, KeyMap::ItemType(it->tag));
2343 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2344 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2345 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2346 modifyPB->setEnabled(!items.isEmpty());
2348 shortcutsTW->resizeColumnToContents(0);
2352 void PrefShortcuts::setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag)
2354 item->setData(0, Qt::UserRole, QVariant(tag));
2358 case KeyMap::System:
2360 case KeyMap::UserBind:
2363 case KeyMap::UserUnbind:
2364 font.setStrikeOut(true);
2366 // this item is not displayed now.
2367 case KeyMap::UserExtraUnbind:
2368 font.setStrikeOut(true);
2372 item->setFont(1, font);
2376 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2377 KeySequence const & seq, KeyMap::ItemType tag)
2379 FuncCode action = lfun.action;
2380 string const action_name = lyxaction.getActionName(action);
2381 QString const lfun_name = toqstr(from_utf8(action_name)
2382 + ' ' + lfun.argument());
2383 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2384 KeyMap::ItemType item_tag = tag;
2386 QTreeWidgetItem * newItem = 0;
2387 // for unbind items, try to find an existing item in the system bind list
2388 if (tag == KeyMap::UserUnbind) {
2389 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2390 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2391 for (int i = 0; i < items.size(); ++i) {
2392 if (items[i]->text(1) == shortcut)
2396 // if not found, this unbind item is KeyMap::UserExtraUnbind
2397 // Such an item is not displayed to avoid confusion (what is
2398 // unmatched removed?).
2400 item_tag = KeyMap::UserExtraUnbind;
2405 switch(lyxaction.getActionType(action)) {
2406 case LyXAction::Hidden:
2408 case LyXAction::Edit:
2409 newItem = new QTreeWidgetItem(editItem_);
2411 case LyXAction::Math:
2412 newItem = new QTreeWidgetItem(mathItem_);
2414 case LyXAction::Buffer:
2415 newItem = new QTreeWidgetItem(bufferItem_);
2417 case LyXAction::Layout:
2418 newItem = new QTreeWidgetItem(layoutItem_);
2420 case LyXAction::System:
2421 newItem = new QTreeWidgetItem(systemItem_);
2424 // this should not happen
2425 newItem = new QTreeWidgetItem(shortcutsTW);
2429 newItem->setText(0, lfun_name);
2430 newItem->setText(1, shortcut);
2431 // record BindFile representation to recover KeySequence when needed.
2432 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2433 setItemType(newItem, item_tag);
2438 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2440 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2441 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2442 modifyPB->setEnabled(!items.isEmpty());
2443 if (items.isEmpty())
2446 KeyMap::ItemType tag =
2447 static_cast<KeyMap::ItemType>(items[0]->data(0, Qt::UserRole).toInt());
2448 if (tag == KeyMap::UserUnbind)
2449 removePB->setText(qt_("Res&tore"));
2451 removePB->setText(qt_("Remo&ve"));
2455 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2461 void PrefShortcuts::modifyShortcut()
2463 QTreeWidgetItem * item = shortcutsTW->currentItem();
2464 if (item->flags() & Qt::ItemIsSelectable) {
2465 shortcut_->lfunLE->setText(item->text(0));
2466 save_lfun_ = item->text(0);
2467 shortcut_->shortcutWG->setText(item->text(1));
2469 seq.parse(fromqstr(item->data(1, Qt::UserRole).toString()));
2470 shortcut_->shortcutWG->setKeySequence(seq);
2471 shortcut_->shortcutWG->setFocus();
2477 void PrefShortcuts::removeShortcut()
2479 // it seems that only one item can be selected, but I am
2480 // removing all selected items anyway.
2481 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2482 for (int i = 0; i < items.size(); ++i) {
2483 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2484 string lfun = fromqstr(items[i]->text(0));
2485 FuncRequest func = lyxaction.lookupFunc(lfun);
2486 KeyMap::ItemType tag =
2487 static_cast<KeyMap::ItemType>(items[i]->data(0, Qt::UserRole).toInt());
2490 case KeyMap::System: {
2491 // for system bind, we do not touch the item
2492 // but add an user unbind item
2493 user_unbind_.bind(shortcut, func);
2494 setItemType(items[i], KeyMap::UserUnbind);
2495 removePB->setText(qt_("Res&tore"));
2498 case KeyMap::UserBind: {
2499 // for user_bind, we remove this bind
2500 QTreeWidgetItem * parent = items[i]->parent();
2501 int itemIdx = parent->indexOfChild(items[i]);
2502 parent->takeChild(itemIdx);
2504 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2506 shortcutsTW->scrollToItem(parent);
2507 user_bind_.unbind(shortcut, func);
2510 case KeyMap::UserUnbind: {
2511 // for user_unbind, we remove the unbind, and the item
2512 // become KeyMap::System again.
2513 user_unbind_.unbind(shortcut, func);
2514 setItemType(items[i], KeyMap::System);
2515 removePB->setText(qt_("Remo&ve"));
2518 case KeyMap::UserExtraUnbind: {
2519 // for user unbind that is not in system bind file,
2520 // remove this unbind file
2521 QTreeWidgetItem * parent = items[i]->parent();
2522 parent->takeChild(parent->indexOfChild(items[i]));
2523 user_unbind_.unbind(shortcut, func);
2530 void PrefShortcuts::selectBind()
2532 QString file = form_->browsebind(internalPath(bindFileED->text()));
2533 if (!file.isEmpty()) {
2534 bindFileED->setText(file);
2535 system_bind_ = KeyMap();
2536 system_bind_.read(fromqstr(file));
2537 updateShortcutsTW();
2542 void PrefShortcuts::on_modifyPB_pressed()
2548 void PrefShortcuts::on_newPB_pressed()
2550 shortcut_->lfunLE->clear();
2551 shortcut_->shortcutWG->reset();
2552 save_lfun_ = QString();
2557 void PrefShortcuts::on_removePB_pressed()
2563 void PrefShortcuts::on_searchLE_textEdited()
2565 if (searchLE->text().isEmpty()) {
2566 // show all hidden items
2567 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2569 shortcutsTW->setItemHidden(*it++, false);
2572 // search both columns
2573 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2574 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2575 matched += shortcutsTW->findItems(searchLE->text(),
2576 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2578 // hide everyone (to avoid searching in matched QList repeatedly
2579 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2581 shortcutsTW->setItemHidden(*it++, true);
2582 // show matched items
2583 for (int i = 0; i < matched.size(); ++i) {
2584 shortcutsTW->setItemHidden(matched[i], false);
2585 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2590 docstring makeCmdString(FuncRequest const & f)
2592 docstring actionStr = from_ascii(lyxaction.getActionName(f.action));
2593 if (!f.argument().empty())
2594 actionStr += " " + f.argument();
2599 void PrefShortcuts::shortcutOkPressed()
2601 QString const new_lfun = shortcut_->lfunLE->text();
2602 FuncRequest func = lyxaction.lookupFunc(fromqstr(new_lfun));
2604 if (func.action == LFUN_UNKNOWN_ACTION) {
2605 Alert::error(_("Failed to create shortcut"),
2606 _("Unknown or invalid LyX function"));
2610 KeySequence k = shortcut_->shortcutWG->getKeySequence();
2611 if (k.length() == 0) {
2612 Alert::error(_("Failed to create shortcut"),
2613 _("Invalid or empty key sequence"));
2617 // check to see if there's been any change
2618 FuncRequest oldBinding = system_bind_.getBinding(k);
2619 if (oldBinding.action == LFUN_UNKNOWN_ACTION)
2620 oldBinding = user_bind_.getBinding(k);
2621 if (oldBinding == func) {
2622 docstring const actionStr = makeCmdString(func);
2623 Alert::error(_("Failed to create shortcut"),
2624 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s"),
2625 k.print(KeySequence::ForGui), actionStr));
2629 // make sure this key isn't already bound---and, if so, not unbound
2630 FuncCode const unbind = user_unbind_.getBinding(k).action;
2631 if (oldBinding.action != LFUN_UNKNOWN_ACTION && unbind == LFUN_UNKNOWN_ACTION)
2633 // FIXME Perhaps we should offer to over-write the old shortcut?
2634 // If so, we'll need to remove it from our list, etc.
2635 docstring const actionStr = makeCmdString(oldBinding);
2636 Alert::error(_("Failed to create shortcut"),
2637 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s\n"
2638 "You need to remove that binding before creating a new one."),
2639 k.print(KeySequence::ForGui), actionStr));
2643 if (!save_lfun_.isEmpty() && new_lfun == save_lfun_)
2644 // real modification of the lfun's shortcut,
2645 // so remove the previous one
2648 QTreeWidgetItem * item = insertShortcutItem(func, k, KeyMap::UserBind);
2650 user_bind_.bind(&k, func);
2651 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2652 shortcutsTW->setItemExpanded(item->parent(), true);
2653 shortcutsTW->scrollToItem(item);
2655 Alert::error(_("Failed to create shortcut"),
2656 _("Can not insert shortcut to the list"));
2662 void PrefShortcuts::shortcutCancelPressed()
2664 shortcut_->shortcutWG->reset();
2668 void PrefShortcuts::shortcutClearPressed()
2670 shortcut_->shortcutWG->reset();
2674 void PrefShortcuts::shortcutRemovePressed()
2676 shortcut_->shortcutWG->removeFromSequence();
2680 /////////////////////////////////////////////////////////////////////
2684 /////////////////////////////////////////////////////////////////////
2686 PrefIdentity::PrefIdentity(GuiPreferences * form)
2687 : PrefModule(QString(), qt_("Identity"), form)
2691 connect(nameED, SIGNAL(textChanged(QString)),
2692 this, SIGNAL(changed()));
2693 connect(emailED, SIGNAL(textChanged(QString)),
2694 this, SIGNAL(changed()));
2698 void PrefIdentity::apply(LyXRC & rc) const
2700 rc.user_name = fromqstr(nameED->text());
2701 rc.user_email = fromqstr(emailED->text());
2705 void PrefIdentity::update(LyXRC const & rc)
2707 nameED->setText(toqstr(rc.user_name));
2708 emailED->setText(toqstr(rc.user_email));
2713 /////////////////////////////////////////////////////////////////////
2717 /////////////////////////////////////////////////////////////////////
2719 GuiPreferences::GuiPreferences(GuiView & lv)
2720 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2724 QDialog::setModal(false);
2726 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2727 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2728 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2729 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2731 addModule(new PrefUserInterface(this));
2732 addModule(new PrefEdit(this));
2733 addModule(new PrefShortcuts(this));
2734 addModule(new PrefScreenFonts(this));
2735 addModule(new PrefColors(this));
2736 addModule(new PrefDisplay(this));
2737 addModule(new PrefInput(this));
2738 addModule(new PrefCompletion(this));
2740 addModule(new PrefPaths(this));
2742 addModule(new PrefIdentity(this));
2744 addModule(new PrefLanguage(this));
2745 addModule(new PrefSpellchecker(this));
2747 addModule(new PrefPrinter(this));
2748 PrefDate * dateFormat = new PrefDate(this);
2749 addModule(dateFormat);
2750 addModule(new PrefPlaintext(this));
2751 addModule(new PrefLatex(this));
2753 PrefConverters * converters = new PrefConverters(this);
2754 PrefFileformats * formats = new PrefFileformats(this);
2755 connect(formats, SIGNAL(formatsChanged()),
2756 converters, SLOT(updateGui()));
2757 addModule(converters);
2760 prefsPS->setCurrentPanel(qt_("User interface"));
2761 // FIXME: hack to work around resizing bug in Qt >= 4.2
2762 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2763 #if QT_VERSION >= 0x040200
2764 prefsPS->updateGeometry();
2767 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2769 bc().setApply(applyPB);
2770 bc().setCancel(closePB);
2771 bc().setRestore(restorePB);
2773 // initialize the strftime validator
2774 bc().addCheckedLineEdit(dateFormat->DateED);
2778 void GuiPreferences::addModule(PrefModule * module)
2780 LASSERT(module, return);
2781 if (module->category().isEmpty())
2782 prefsPS->addPanel(module, module->title());
2784 prefsPS->addPanel(module, module->title(), module->category());
2785 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2786 modules_.push_back(module);
2790 void GuiPreferences::change_adaptor()
2796 void GuiPreferences::apply(LyXRC & rc) const
2798 size_t end = modules_.size();
2799 for (size_t i = 0; i != end; ++i)
2800 modules_[i]->apply(rc);
2804 void GuiPreferences::updateRc(LyXRC const & rc)
2806 size_t const end = modules_.size();
2807 for (size_t i = 0; i != end; ++i)
2808 modules_[i]->update(rc);
2812 void GuiPreferences::applyView()
2817 bool GuiPreferences::initialiseParams(string const &)
2820 formats_ = lyx::formats;
2821 converters_ = theConverters();
2822 converters_.update(formats_);
2823 movers_ = theMovers();
2825 update_screen_font_ = false;
2828 // Make sure that the bc is in the INITIAL state
2829 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
2836 void GuiPreferences::dispatchParams()
2839 rc_.write(ss, true);
2840 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
2841 // FIXME: these need lfuns
2843 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
2845 lyx::formats = formats_;
2847 theConverters() = converters_;
2848 theConverters().update(lyx::formats);
2849 theConverters().buildGraph();
2851 theMovers() = movers_;
2853 vector<string>::const_iterator it = colors_.begin();
2854 vector<string>::const_iterator const end = colors_.end();
2855 for (; it != end; ++it)
2856 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
2859 if (update_screen_font_) {
2860 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2861 update_screen_font_ = false;
2864 // The Save button has been pressed
2866 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
2870 void GuiPreferences::setColor(ColorCode col, QString const & hex)
2872 colors_.push_back(lcolor.getLyXName(col) + ' ' + fromqstr(hex));
2876 void GuiPreferences::updateScreenFonts()
2878 update_screen_font_ = true;
2882 QString GuiPreferences::browsebind(QString const & file) const
2884 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
2885 QStringList(qt_("LyX bind files (*.bind)")));
2889 QString GuiPreferences::browseUI(QString const & file) const
2891 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
2892 QStringList(qt_("LyX UI files (*.ui)")));
2896 QString GuiPreferences::browsekbmap(QString const & file) const
2898 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
2899 QStringList(qt_("LyX keyboard maps (*.kmap)")));
2903 QString GuiPreferences::browsedict(QString const & file) const
2905 return browseFile(file, qt_("Choose personal dictionary"),
2906 QStringList(qt_("*.pws")));
2910 QString GuiPreferences::browse(QString const & file,
2911 QString const & title) const
2913 return browseFile(file, title, QStringList(), true);
2917 // We support less paper sizes than the document dialog
2918 // Therefore this adjustment is needed.
2919 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
2923 return PAPER_DEFAULT;
2925 return PAPER_USLETTER;
2927 return PAPER_USLEGAL;
2929 return PAPER_USEXECUTIVE;
2939 // should not happen
2940 return PAPER_DEFAULT;
2945 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
2947 switch (papersize) {
2950 case PAPER_USLETTER:
2954 case PAPER_USEXECUTIVE:
2965 // should not happen
2971 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
2974 } // namespace frontend
2977 #include "moc_GuiPrefs.cpp"