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(autocorrectionCB, SIGNAL(clicked()),
520 this, SIGNAL(changed()));
521 connect(popupTextCB, SIGNAL(clicked()),
522 this, SIGNAL(changed()));
523 connect(popupAfterCompleteCB, SIGNAL(clicked()),
524 this, SIGNAL(changed()));
525 connect(cursorTextCB, SIGNAL(clicked()),
526 this, SIGNAL(changed()));
530 void PrefCompletion::on_inlineTextCB_clicked()
536 void PrefCompletion::on_popupTextCB_clicked()
542 void PrefCompletion::enableCB()
544 cursorTextCB->setEnabled(
545 popupTextCB->isChecked() || inlineTextCB->isChecked());
549 void PrefCompletion::apply(LyXRC & rc) const
551 rc.completion_inline_delay = inlineDelaySB->value();
552 rc.completion_inline_math = inlineMathCB->isChecked();
553 rc.completion_inline_text = inlineTextCB->isChecked();
554 rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
555 rc.completion_popup_delay = popupDelaySB->value();
556 rc.completion_popup_math = popupMathCB->isChecked();
557 rc.autocorrection_math = autocorrectionCB->isChecked();
558 rc.completion_popup_text = popupTextCB->isChecked();
559 rc.completion_cursor_text = cursorTextCB->isChecked();
560 rc.completion_popup_after_complete =
561 popupAfterCompleteCB->isChecked();
565 void PrefCompletion::update(LyXRC const & rc)
567 inlineDelaySB->setValue(rc.completion_inline_delay);
568 inlineMathCB->setChecked(rc.completion_inline_math);
569 inlineTextCB->setChecked(rc.completion_inline_text);
570 inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
571 popupDelaySB->setValue(rc.completion_popup_delay);
572 popupMathCB->setChecked(rc.completion_popup_math);
573 autocorrectionCB->setChecked(rc.autocorrection_math);
574 popupTextCB->setChecked(rc.completion_popup_text);
575 cursorTextCB->setChecked(rc.completion_cursor_text);
576 popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
582 /////////////////////////////////////////////////////////////////////
586 /////////////////////////////////////////////////////////////////////
588 PrefLatex::PrefLatex(GuiPreferences * form)
589 : PrefModule(qt_(catOutput), qt_("LaTeX"), form)
592 connect(latexEncodingED, SIGNAL(textChanged(QString)),
593 this, SIGNAL(changed()));
594 connect(latexChecktexED, SIGNAL(textChanged(QString)),
595 this, SIGNAL(changed()));
596 connect(latexBibtexCO, SIGNAL(activated(int)),
597 this, SIGNAL(changed()));
598 connect(latexBibtexED, SIGNAL(textChanged(QString)),
599 this, SIGNAL(changed()));
600 connect(latexJBibtexED, SIGNAL(textChanged(QString)),
601 this, SIGNAL(changed()));
602 connect(latexIndexCO, SIGNAL(activated(int)),
603 this, SIGNAL(changed()));
604 connect(latexIndexED, SIGNAL(textChanged(QString)),
605 this, SIGNAL(changed()));
606 connect(latexJIndexED, SIGNAL(textChanged(QString)),
607 this, SIGNAL(changed()));
608 connect(latexAutoresetCB, SIGNAL(clicked()),
609 this, SIGNAL(changed()));
610 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
611 this, SIGNAL(changed()));
612 connect(latexPaperSizeCO, SIGNAL(activated(int)),
613 this, SIGNAL(changed()));
615 #if defined(__CYGWIN__) || defined(_WIN32)
616 pathCB->setVisible(true);
617 connect(pathCB, SIGNAL(clicked()),
618 this, SIGNAL(changed()));
620 pathCB->setVisible(false);
625 void PrefLatex::on_latexBibtexCO_activated(int n)
627 QString const bibtex = latexBibtexCO->itemData(n).toString();
628 if (bibtex.isEmpty()) {
629 latexBibtexED->clear();
630 latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
633 for (set<string>::const_iterator it = bibtex_alternatives.begin();
634 it != bibtex_alternatives.end(); ++it) {
635 QString const bib = toqstr(*it);
636 int ind = bib.indexOf(" ");
637 QString sel_command = bib.left(ind);
638 QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
639 if (bibtex == sel_command) {
641 latexBibtexED->clear();
643 latexBibtexED->setText(sel_options.trimmed());
646 latexBibtexOptionsLA->setText(qt_("&Options:"));
650 void PrefLatex::on_latexIndexCO_activated(int n)
652 QString const index = latexIndexCO->itemData(n).toString();
653 if (index.isEmpty()) {
654 latexIndexED->clear();
655 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
658 for (set<string>::const_iterator it = index_alternatives.begin();
659 it != index_alternatives.end(); ++it) {
660 QString const idx = toqstr(*it);
661 int ind = idx.indexOf(" ");
662 QString sel_command = idx.left(ind);
663 QString sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
664 if (index == sel_command) {
666 latexIndexED->clear();
668 latexIndexED->setText(sel_options.trimmed());
671 latexIndexOptionsLA->setText(qt_("Op&tions:"));
675 void PrefLatex::apply(LyXRC & rc) const
677 // If bibtex is not empty, bibopt contains the options, otherwise
678 // it is a customized bibtex command with options.
679 QString const bibtex = latexBibtexCO->itemData(
680 latexBibtexCO->currentIndex()).toString();
681 QString const bibopt = latexBibtexED->text();
682 if (bibtex.isEmpty())
683 rc.bibtex_command = fromqstr(bibopt);
684 else if (bibopt.isEmpty())
685 rc.bibtex_command = fromqstr(bibtex);
687 rc.bibtex_command = fromqstr(bibtex) + " " + fromqstr(bibopt);
689 // If index is not empty, idxopt contains the options, otherwise
690 // it is a customized index command with options.
691 QString const index = latexIndexCO->itemData(
692 latexIndexCO->currentIndex()).toString();
693 QString const idxopt = latexIndexED->text();
695 rc.index_command = fromqstr(idxopt);
696 else if (idxopt.isEmpty())
697 rc.index_command = fromqstr(index);
699 rc.index_command = fromqstr(index) + " " + fromqstr(idxopt);
701 rc.fontenc = fromqstr(latexEncodingED->text());
702 rc.chktex_command = fromqstr(latexChecktexED->text());
703 rc.jbibtex_command = fromqstr(latexJBibtexED->text());
704 rc.jindex_command = fromqstr(latexJIndexED->text());
705 rc.nomencl_command = fromqstr(latexNomenclED->text());
706 rc.auto_reset_options = latexAutoresetCB->isChecked();
707 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
708 rc.default_papersize =
709 form_->toPaperSize(latexPaperSizeCO->currentIndex());
710 #if defined(__CYGWIN__) || defined(_WIN32)
711 rc.windows_style_tex_paths = pathCB->isChecked();
716 void PrefLatex::update(LyXRC const & rc)
718 latexBibtexCO->clear();
720 latexBibtexCO->addItem(qt_("Custom"), QString());
721 for (set<string>::const_iterator it = rc.bibtex_alternatives.begin();
722 it != rc.bibtex_alternatives.end(); ++it) {
723 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
724 latexBibtexCO->addItem(command, command);
727 bibtex_alternatives = rc.bibtex_alternatives;
729 QString const bib = toqstr(rc.bibtex_command);
730 int ind = bib.indexOf(" ");
731 QString sel_command = bib.left(ind);
732 QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
734 int pos = latexBibtexCO->findData(sel_command);
736 latexBibtexCO->setCurrentIndex(pos);
737 latexBibtexED->setText(sel_options.trimmed());
738 latexBibtexOptionsLA->setText(qt_("&Options:"));
740 latexBibtexED->setText(toqstr(rc.bibtex_command));
741 latexBibtexCO->setCurrentIndex(0);
742 latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
745 latexIndexCO->clear();
747 latexIndexCO->addItem(qt_("Custom"), QString());
748 for (set<string>::const_iterator it = rc.index_alternatives.begin();
749 it != rc.index_alternatives.end(); ++it) {
750 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
751 latexIndexCO->addItem(command, command);
754 index_alternatives = rc.index_alternatives;
756 QString const idx = toqstr(rc.index_command);
757 ind = idx.indexOf(" ");
758 sel_command = idx.left(ind);
759 sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
761 pos = latexIndexCO->findData(sel_command);
763 latexIndexCO->setCurrentIndex(pos);
764 latexIndexED->setText(sel_options.trimmed());
765 latexIndexOptionsLA->setText(qt_("Op&tions:"));
767 latexIndexED->setText(toqstr(rc.index_command));
768 latexIndexCO->setCurrentIndex(0);
769 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
772 latexEncodingED->setText(toqstr(rc.fontenc));
773 latexChecktexED->setText(toqstr(rc.chktex_command));
774 latexJBibtexED->setText(toqstr(rc.jbibtex_command));
775 latexJIndexED->setText(toqstr(rc.jindex_command));
776 latexNomenclED->setText(toqstr(rc.nomencl_command));
777 latexAutoresetCB->setChecked(rc.auto_reset_options);
778 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
779 latexPaperSizeCO->setCurrentIndex(
780 form_->fromPaperSize(rc.default_papersize));
781 #if defined(__CYGWIN__) || defined(_WIN32)
782 pathCB->setChecked(rc.windows_style_tex_paths);
787 /////////////////////////////////////////////////////////////////////
791 /////////////////////////////////////////////////////////////////////
793 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form)
794 : PrefModule(qt_(catLookAndFeel), qt_("Screen fonts"), form)
798 connect(screenRomanCO, SIGNAL(activated(QString)),
799 this, SLOT(selectRoman(QString)));
800 connect(screenSansCO, SIGNAL(activated(QString)),
801 this, SLOT(selectSans(QString)));
802 connect(screenTypewriterCO, SIGNAL(activated(QString)),
803 this, SLOT(selectTypewriter(QString)));
805 QFontDatabase fontdb;
806 QStringList families(fontdb.families());
807 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
808 screenRomanCO->addItem(*it);
809 screenSansCO->addItem(*it);
810 screenTypewriterCO->addItem(*it);
812 connect(screenRomanCO, SIGNAL(activated(QString)),
813 this, SIGNAL(changed()));
814 connect(screenSansCO, SIGNAL(activated(QString)),
815 this, SIGNAL(changed()));
816 connect(screenTypewriterCO, SIGNAL(activated(QString)),
817 this, SIGNAL(changed()));
818 connect(screenZoomSB, SIGNAL(valueChanged(int)),
819 this, SIGNAL(changed()));
820 connect(screenDpiSB, SIGNAL(valueChanged(int)),
821 this, SIGNAL(changed()));
822 connect(screenTinyED, SIGNAL(textChanged(QString)),
823 this, SIGNAL(changed()));
824 connect(screenSmallestED, SIGNAL(textChanged(QString)),
825 this, SIGNAL(changed()));
826 connect(screenSmallerED, SIGNAL(textChanged(QString)),
827 this, SIGNAL(changed()));
828 connect(screenSmallED, SIGNAL(textChanged(QString)),
829 this, SIGNAL(changed()));
830 connect(screenNormalED, SIGNAL(textChanged(QString)),
831 this, SIGNAL(changed()));
832 connect(screenLargeED, SIGNAL(textChanged(QString)),
833 this, SIGNAL(changed()));
834 connect(screenLargerED, SIGNAL(textChanged(QString)),
835 this, SIGNAL(changed()));
836 connect(screenLargestED, SIGNAL(textChanged(QString)),
837 this, SIGNAL(changed()));
838 connect(screenHugeED, SIGNAL(textChanged(QString)),
839 this, SIGNAL(changed()));
840 connect(screenHugerED, SIGNAL(textChanged(QString)),
841 this, SIGNAL(changed()));
842 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
843 this, SIGNAL(changed()));
845 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
846 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
847 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
848 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
849 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
850 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
851 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
852 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
853 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
854 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
858 void PrefScreenFonts::apply(LyXRC & rc) const
860 LyXRC const oldrc = rc;
862 parseFontName(screenRomanCO->currentText(),
863 rc.roman_font_name, rc.roman_font_foundry);
864 parseFontName(screenSansCO->currentText(),
865 rc.sans_font_name, rc.sans_font_foundry);
866 parseFontName(screenTypewriterCO->currentText(),
867 rc.typewriter_font_name, rc.typewriter_font_foundry);
869 rc.zoom = screenZoomSB->value();
870 rc.dpi = screenDpiSB->value();
871 rc.font_sizes[FONT_SIZE_TINY] = fromqstr(screenTinyED->text());
872 rc.font_sizes[FONT_SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
873 rc.font_sizes[FONT_SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
874 rc.font_sizes[FONT_SIZE_SMALL] = fromqstr(screenSmallED->text());
875 rc.font_sizes[FONT_SIZE_NORMAL] = fromqstr(screenNormalED->text());
876 rc.font_sizes[FONT_SIZE_LARGE] = fromqstr(screenLargeED->text());
877 rc.font_sizes[FONT_SIZE_LARGER] = fromqstr(screenLargerED->text());
878 rc.font_sizes[FONT_SIZE_LARGEST] = fromqstr(screenLargestED->text());
879 rc.font_sizes[FONT_SIZE_HUGE] = fromqstr(screenHugeED->text());
880 rc.font_sizes[FONT_SIZE_HUGER] = fromqstr(screenHugerED->text());
881 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
883 if (rc.font_sizes != oldrc.font_sizes
884 || rc.roman_font_name != oldrc.roman_font_name
885 || rc.sans_font_name != oldrc.sans_font_name
886 || rc.typewriter_font_name != oldrc.typewriter_font_name
887 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
888 // The global QPixmapCache is used in GuiPainter to cache text
889 // painting so we must reset it in case any of the above
890 // parameter is changed.
891 QPixmapCache::clear();
892 guiApp->fontLoader().update();
893 form_->updateScreenFonts();
898 void PrefScreenFonts::update(LyXRC const & rc)
900 setComboxFont(screenRomanCO, rc.roman_font_name,
901 rc.roman_font_foundry);
902 setComboxFont(screenSansCO, rc.sans_font_name,
903 rc.sans_font_foundry);
904 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
905 rc.typewriter_font_foundry);
907 selectRoman(screenRomanCO->currentText());
908 selectSans(screenSansCO->currentText());
909 selectTypewriter(screenTypewriterCO->currentText());
911 screenZoomSB->setValue(rc.zoom);
912 screenDpiSB->setValue(rc.dpi);
913 screenTinyED->setText(toqstr(rc.font_sizes[FONT_SIZE_TINY]));
914 screenSmallestED->setText(toqstr(rc.font_sizes[FONT_SIZE_SCRIPT]));
915 screenSmallerED->setText(toqstr(rc.font_sizes[FONT_SIZE_FOOTNOTE]));
916 screenSmallED->setText(toqstr(rc.font_sizes[FONT_SIZE_SMALL]));
917 screenNormalED->setText(toqstr(rc.font_sizes[FONT_SIZE_NORMAL]));
918 screenLargeED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGE]));
919 screenLargerED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGER]));
920 screenLargestED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGEST]));
921 screenHugeED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGE]));
922 screenHugerED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGER]));
924 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
925 #if defined(Q_WS_X11)
926 pixmapCacheCB->setEnabled(false);
932 void PrefScreenFonts::selectRoman(const QString & name)
934 screenRomanFE->set(QFont(name), name);
938 void PrefScreenFonts::selectSans(const QString & name)
940 screenSansFE->set(QFont(name), name);
944 void PrefScreenFonts::selectTypewriter(const QString & name)
946 screenTypewriterFE->set(QFont(name), name);
950 /////////////////////////////////////////////////////////////////////
954 /////////////////////////////////////////////////////////////////////
960 bool operator()(ColorCode lhs, ColorCode rhs) const {
962 compare_no_case(lcolor.getGUIName(lhs), lcolor.getGUIName(rhs)) < 0;
968 PrefColors::PrefColors(GuiPreferences * form)
969 : PrefModule(qt_(catLookAndFeel), qt_("Colors"), form)
973 // FIXME: all of this initialization should be put into the controller.
974 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
975 // for some discussion of why that is not trivial.
976 QPixmap icon(32, 32);
977 for (int i = 0; i < Color_ignore; ++i) {
978 ColorCode lc = static_cast<ColorCode>(i);
986 || lc == Color_magenta
987 || lc == Color_yellow
988 || lc == Color_inherit
989 || lc == Color_ignore) continue;
991 lcolors_.push_back(lc);
993 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
994 vector<ColorCode>::const_iterator cit = lcolors_.begin();
995 vector<ColorCode>::const_iterator const end = lcolors_.end();
996 for (; cit != end; ++cit) {
997 (void) new QListWidgetItem(QIcon(icon),
998 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
1000 curcolors_.resize(lcolors_.size());
1001 newcolors_.resize(lcolors_.size());
1002 // End initialization
1004 connect(colorChangePB, SIGNAL(clicked()),
1005 this, SLOT(changeColor()));
1006 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
1007 this, SLOT(changeLyxObjectsSelection()));
1008 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
1009 this, SLOT(changeColor()));
1013 void PrefColors::apply(LyXRC & /*rc*/) const
1015 for (unsigned int i = 0; i < lcolors_.size(); ++i)
1016 if (curcolors_[i] != newcolors_[i])
1017 form_->setColor(lcolors_[i], newcolors_[i]);
1021 void PrefColors::update(LyXRC const & /*rc*/)
1023 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
1024 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
1025 QPixmap coloritem(32, 32);
1026 coloritem.fill(color);
1027 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
1028 newcolors_[i] = curcolors_[i] = color.name();
1030 changeLyxObjectsSelection();
1034 void PrefColors::changeColor()
1036 int const row = lyxObjectsLW->currentRow();
1042 QString const color = newcolors_[row];
1043 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
1045 if (c.isValid() && c.name() != color) {
1046 newcolors_[row] = c.name();
1047 QPixmap coloritem(32, 32);
1049 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
1055 void PrefColors::changeLyxObjectsSelection()
1057 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
1061 /////////////////////////////////////////////////////////////////////
1065 /////////////////////////////////////////////////////////////////////
1067 PrefDisplay::PrefDisplay(GuiPreferences * form)
1068 : PrefModule(qt_(catLookAndFeel), qt_("Graphics"), form)
1071 connect(displayGraphicsCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
1072 connect(instantPreviewCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
1076 void PrefDisplay::apply(LyXRC & rc) const
1078 switch (instantPreviewCO->currentIndex()) {
1079 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
1080 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
1081 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
1084 rc.display_graphics = displayGraphicsCB->isChecked();
1086 // FIXME!! The graphics cache no longer has a changeDisplay method.
1088 if (old_value != rc.display_graphics) {
1089 graphics::GCache & gc = graphics::GCache::get();
1096 void PrefDisplay::update(LyXRC const & rc)
1098 switch (rc.preview) {
1099 case LyXRC::PREVIEW_OFF:
1100 instantPreviewCO->setCurrentIndex(0);
1102 case LyXRC::PREVIEW_NO_MATH :
1103 instantPreviewCO->setCurrentIndex(1);
1105 case LyXRC::PREVIEW_ON :
1106 instantPreviewCO->setCurrentIndex(2);
1110 displayGraphicsCB->setChecked(rc.display_graphics);
1111 instantPreviewCO->setEnabled(rc.display_graphics);
1115 /////////////////////////////////////////////////////////////////////
1119 /////////////////////////////////////////////////////////////////////
1121 PrefPaths::PrefPaths(GuiPreferences * form)
1122 : PrefModule(QString(), qt_("Paths"), form)
1125 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(selectExampledir()));
1126 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(selectTemplatedir()));
1127 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(selectTempdir()));
1128 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(selectBackupdir()));
1129 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(selectWorkingdir()));
1130 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(selectLyxPipe()));
1131 connect(thesaurusDirPB, SIGNAL(clicked()), this, SLOT(selectThesaurusdir()));
1132 connect(workingDirED, SIGNAL(textChanged(QString)),
1133 this, SIGNAL(changed()));
1134 connect(exampleDirED, SIGNAL(textChanged(QString)),
1135 this, SIGNAL(changed()));
1136 connect(templateDirED, SIGNAL(textChanged(QString)),
1137 this, SIGNAL(changed()));
1138 connect(backupDirED, SIGNAL(textChanged(QString)),
1139 this, SIGNAL(changed()));
1140 connect(tempDirED, SIGNAL(textChanged(QString)),
1141 this, SIGNAL(changed()));
1142 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
1143 this, SIGNAL(changed()));
1144 connect(thesaurusDirED, SIGNAL(textChanged(QString)),
1145 this, SIGNAL(changed()));
1146 connect(pathPrefixED, SIGNAL(textChanged(QString)),
1147 this, SIGNAL(changed()));
1151 void PrefPaths::apply(LyXRC & rc) const
1153 rc.document_path = internal_path(fromqstr(workingDirED->text()));
1154 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
1155 rc.template_path = internal_path(fromqstr(templateDirED->text()));
1156 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
1157 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
1158 rc.thesaurusdir_path = internal_path(fromqstr(thesaurusDirED->text()));
1159 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
1160 // FIXME: should be a checkbox only
1161 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
1165 void PrefPaths::update(LyXRC const & rc)
1167 workingDirED->setText(toqstr(external_path(rc.document_path)));
1168 exampleDirED->setText(toqstr(external_path(rc.example_path)));
1169 templateDirED->setText(toqstr(external_path(rc.template_path)));
1170 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
1171 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
1172 thesaurusDirED->setText(toqstr(external_path(rc.thesaurusdir_path)));
1173 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
1174 // FIXME: should be a checkbox only
1175 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
1179 void PrefPaths::selectExampledir()
1181 QString file = browseDir(internalPath(exampleDirED->text()),
1182 qt_("Select directory for example files"));
1183 if (!file.isEmpty())
1184 exampleDirED->setText(file);
1188 void PrefPaths::selectTemplatedir()
1190 QString file = browseDir(internalPath(templateDirED->text()),
1191 qt_("Select a document templates directory"));
1192 if (!file.isEmpty())
1193 templateDirED->setText(file);
1197 void PrefPaths::selectTempdir()
1199 QString file = browseDir(internalPath(tempDirED->text()),
1200 qt_("Select a temporary directory"));
1201 if (!file.isEmpty())
1202 tempDirED->setText(file);
1206 void PrefPaths::selectBackupdir()
1208 QString file = browseDir(internalPath(backupDirED->text()),
1209 qt_("Select a backups directory"));
1210 if (!file.isEmpty())
1211 backupDirED->setText(file);
1215 void PrefPaths::selectWorkingdir()
1217 QString file = browseDir(internalPath(workingDirED->text()),
1218 qt_("Select a document directory"));
1219 if (!file.isEmpty())
1220 workingDirED->setText(file);
1224 void PrefPaths::selectThesaurusdir()
1226 QString file = browseDir(internalPath(thesaurusDirED->text()),
1227 qt_("Set the path to the thesaurus dictionaries"));
1228 if (!file.isEmpty())
1229 thesaurusDirED->setText(file);
1233 void PrefPaths::selectLyxPipe()
1235 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1236 qt_("Give a filename for the LyX server pipe"));
1237 if (!file.isEmpty())
1238 lyxserverDirED->setText(file);
1242 /////////////////////////////////////////////////////////////////////
1246 /////////////////////////////////////////////////////////////////////
1248 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form)
1249 : PrefModule(qt_(catLanguage), qt_("Spellchecker"), form)
1253 connect(altLanguageED, SIGNAL(textChanged(QString)),
1254 this, SIGNAL(changed()));
1255 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1256 this, SIGNAL(changed()));
1257 connect(compoundWordCB, SIGNAL(clicked()),
1258 this, SIGNAL(changed()));
1259 connect(spellcheckContinuouslyCB, SIGNAL(clicked()),
1260 this, SIGNAL(changed()));
1264 void PrefSpellchecker::apply(LyXRC & rc) const
1266 rc.spellchecker_alt_lang = fromqstr(altLanguageED->text());
1267 // FIXME: remove spellchecker_use_esc_chars
1268 rc.spellchecker_esc_chars = fromqstr(escapeCharactersED->text());
1269 rc.spellchecker_use_esc_chars = !rc.spellchecker_esc_chars.empty();
1270 rc.spellchecker_accept_compound = compoundWordCB->isChecked();
1271 rc.spellcheck_continuously = spellcheckContinuouslyCB->isChecked();
1275 void PrefSpellchecker::update(LyXRC const & rc)
1277 altLanguageED->setText(toqstr(rc.spellchecker_alt_lang));
1278 // FIXME: remove spellchecker_use_esc_chars
1279 escapeCharactersED->setText(toqstr(rc.spellchecker_esc_chars));
1280 compoundWordCB->setChecked(rc.spellchecker_accept_compound);
1281 spellcheckContinuouslyCB->setChecked(rc.spellcheck_continuously);
1286 /////////////////////////////////////////////////////////////////////
1290 /////////////////////////////////////////////////////////////////////
1293 PrefConverters::PrefConverters(GuiPreferences * form)
1294 : PrefModule(qt_(catFiles), qt_("Converters"), form)
1298 connect(converterNewPB, SIGNAL(clicked()),
1299 this, SLOT(updateConverter()));
1300 connect(converterRemovePB, SIGNAL(clicked()),
1301 this, SLOT(removeConverter()));
1302 connect(converterModifyPB, SIGNAL(clicked()),
1303 this, SLOT(updateConverter()));
1304 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1305 this, SLOT(switchConverter()));
1306 connect(converterFromCO, SIGNAL(activated(QString)),
1307 this, SLOT(changeConverter()));
1308 connect(converterToCO, SIGNAL(activated(QString)),
1309 this, SLOT(changeConverter()));
1310 connect(converterED, SIGNAL(textEdited(QString)),
1311 this, SLOT(changeConverter()));
1312 connect(converterFlagED, SIGNAL(textEdited(QString)),
1313 this, SLOT(changeConverter()));
1314 connect(converterNewPB, SIGNAL(clicked()),
1315 this, SIGNAL(changed()));
1316 connect(converterRemovePB, SIGNAL(clicked()),
1317 this, SIGNAL(changed()));
1318 connect(converterModifyPB, SIGNAL(clicked()),
1319 this, SIGNAL(changed()));
1320 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1321 this, SIGNAL(changed()));
1323 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1324 //converterDefGB->setFocusProxy(convertersLW);
1328 void PrefConverters::apply(LyXRC & rc) const
1330 rc.use_converter_cache = cacheCB->isChecked();
1331 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
1335 void PrefConverters::update(LyXRC const & rc)
1337 cacheCB->setChecked(rc.use_converter_cache);
1339 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
1340 maxAgeLE->setText(max_age);
1345 void PrefConverters::updateGui()
1347 form_->formats().sort();
1348 form_->converters().update(form_->formats());
1349 // save current selection
1350 QString current = converterFromCO->currentText()
1351 + " -> " + converterToCO->currentText();
1353 converterFromCO->clear();
1354 converterToCO->clear();
1356 Formats::const_iterator cit = form_->formats().begin();
1357 Formats::const_iterator end = form_->formats().end();
1358 for (; cit != end; ++cit) {
1359 converterFromCO->addItem(qt_(cit->prettyname()));
1360 converterToCO->addItem(qt_(cit->prettyname()));
1363 // currentRowChanged(int) is also triggered when updating the listwidget
1364 // block signals to avoid unnecessary calls to switchConverter()
1365 convertersLW->blockSignals(true);
1366 convertersLW->clear();
1368 Converters::const_iterator ccit = form_->converters().begin();
1369 Converters::const_iterator cend = form_->converters().end();
1370 for (; ccit != cend; ++ccit) {
1371 QString const name =
1372 qt_(ccit->From->prettyname()) + " -> " + qt_(ccit->To->prettyname());
1373 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1374 new QListWidgetItem(name, convertersLW, type);
1376 convertersLW->sortItems(Qt::AscendingOrder);
1377 convertersLW->blockSignals(false);
1379 // restore selection
1380 if (!current.isEmpty()) {
1381 QList<QListWidgetItem *> const item =
1382 convertersLW->findItems(current, Qt::MatchExactly);
1383 if (!item.isEmpty())
1384 convertersLW->setCurrentItem(item.at(0));
1387 // select first element if restoring failed
1388 if (convertersLW->currentRow() == -1)
1389 convertersLW->setCurrentRow(0);
1395 void PrefConverters::switchConverter()
1397 int const cnr = convertersLW->currentItem()->type();
1398 Converter const & c(form_->converters().get(cnr));
1399 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1400 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1401 converterED->setText(toqstr(c.command));
1402 converterFlagED->setText(toqstr(c.flags));
1408 void PrefConverters::changeConverter()
1414 void PrefConverters::updateButtons()
1416 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1417 Format const & to = form_->formats().get(converterToCO->currentIndex());
1418 int const sel = form_->converters().getNumber(from.name(), to.name());
1419 bool const known = sel >= 0;
1420 bool const valid = !(converterED->text().isEmpty()
1421 || from.name() == to.name());
1423 int const cnr = convertersLW->currentItem()->type();
1424 Converter const & c = form_->converters().get(cnr);
1425 string const old_command = c.command;
1426 string const old_flag = c.flags;
1427 string const new_command = fromqstr(converterED->text());
1428 string const new_flag = fromqstr(converterFlagED->text());
1430 bool modified = (old_command != new_command || old_flag != new_flag);
1432 converterModifyPB->setEnabled(valid && known && modified);
1433 converterNewPB->setEnabled(valid && !known);
1434 converterRemovePB->setEnabled(known);
1436 maxAgeLE->setEnabled(cacheCB->isChecked());
1437 maxAgeLA->setEnabled(cacheCB->isChecked());
1442 // specify unique from/to or it doesn't appear. This is really bad UI
1443 // this is why we can use the same function for both new and modify
1444 void PrefConverters::updateConverter()
1446 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1447 Format const & to = form_->formats().get(converterToCO->currentIndex());
1448 string const flags = fromqstr(converterFlagED->text());
1449 string const command = fromqstr(converterED->text());
1451 Converter const * old =
1452 form_->converters().getConverter(from.name(), to.name());
1453 form_->converters().add(from.name(), to.name(), command, flags);
1456 form_->converters().updateLast(form_->formats());
1460 // Remove all files created by this converter from the cache, since
1461 // the modified converter might create different files.
1462 ConverterCache::get().remove_all(from.name(), to.name());
1466 void PrefConverters::removeConverter()
1468 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1469 Format const & to = form_->formats().get(converterToCO->currentIndex());
1470 form_->converters().erase(from.name(), to.name());
1474 // Remove all files created by this converter from the cache, since
1475 // a possible new converter might create different files.
1476 ConverterCache::get().remove_all(from.name(), to.name());
1480 void PrefConverters::on_cacheCB_stateChanged(int state)
1482 maxAgeLE->setEnabled(state == Qt::Checked);
1483 maxAgeLA->setEnabled(state == Qt::Checked);
1488 /////////////////////////////////////////////////////////////////////
1492 /////////////////////////////////////////////////////////////////////
1494 class FormatValidator : public QValidator
1497 FormatValidator(QWidget *, Formats const & f);
1498 void fixup(QString & input) const;
1499 QValidator::State validate(QString & input, int & pos) const;
1501 virtual QString toString(Format const & format) const = 0;
1503 Formats const & formats_;
1507 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1508 : QValidator(parent), formats_(f)
1513 void FormatValidator::fixup(QString & input) const
1515 Formats::const_iterator cit = formats_.begin();
1516 Formats::const_iterator end = formats_.end();
1517 for (; cit != end; ++cit) {
1518 QString const name = toString(*cit);
1519 if (distance(formats_.begin(), cit) == nr()) {
1527 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1529 Formats::const_iterator cit = formats_.begin();
1530 Formats::const_iterator end = formats_.end();
1531 bool unknown = true;
1532 for (; unknown && cit != end; ++cit) {
1533 QString const name = toString(*cit);
1534 if (distance(formats_.begin(), cit) != nr())
1535 unknown = name != input;
1538 if (unknown && !input.isEmpty())
1539 return QValidator::Acceptable;
1541 return QValidator::Intermediate;
1545 int FormatValidator::nr() const
1547 QComboBox * p = qobject_cast<QComboBox *>(parent());
1548 return p->itemData(p->currentIndex()).toInt();
1552 /////////////////////////////////////////////////////////////////////
1554 // FormatNameValidator
1556 /////////////////////////////////////////////////////////////////////
1558 class FormatNameValidator : public FormatValidator
1561 FormatNameValidator(QWidget * parent, Formats const & f)
1562 : FormatValidator(parent, f)
1565 QString toString(Format const & format) const
1567 return toqstr(format.name());
1572 /////////////////////////////////////////////////////////////////////
1574 // FormatPrettynameValidator
1576 /////////////////////////////////////////////////////////////////////
1578 class FormatPrettynameValidator : public FormatValidator
1581 FormatPrettynameValidator(QWidget * parent, Formats const & f)
1582 : FormatValidator(parent, f)
1585 QString toString(Format const & format) const
1587 return qt_(format.prettyname());
1592 /////////////////////////////////////////////////////////////////////
1596 /////////////////////////////////////////////////////////////////////
1598 PrefFileformats::PrefFileformats(GuiPreferences * form)
1599 : PrefModule(qt_(catFiles), qt_("File formats"), form)
1602 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1603 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1605 connect(documentCB, SIGNAL(clicked()),
1606 this, SLOT(setFlags()));
1607 connect(vectorCB, SIGNAL(clicked()),
1608 this, SLOT(setFlags()));
1609 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1610 this, SLOT(updatePrettyname()));
1611 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1612 this, SIGNAL(changed()));
1613 connect(defaultFormatCB, SIGNAL(activated(QString)),
1614 this, SIGNAL(changed()));
1620 string const l10n_shortcut(string const prettyname, string const shortcut)
1622 if (shortcut.empty())
1625 string l10n_format =
1626 to_utf8(_(prettyname + '|' + shortcut));
1627 return split(l10n_format, '|');
1630 }; // namespace anon
1633 void PrefFileformats::apply(LyXRC & rc) const
1635 QString const default_format = defaultFormatCB->itemData(
1636 defaultFormatCB->currentIndex()).toString();
1637 rc.default_view_format = fromqstr(default_format);
1641 void PrefFileformats::update(LyXRC const & rc)
1643 bool const init = defaultFormatCB->currentText().isEmpty();
1646 int const pos = defaultFormatCB->findData(toqstr(
1647 rc.default_view_format));
1648 defaultFormatCB->setCurrentIndex(pos);
1653 void PrefFileformats::updateView()
1655 QString const current = formatsCB->currentText();
1656 QString const current_def = defaultFormatCB->currentText();
1658 // update comboboxes with formats
1659 formatsCB->blockSignals(true);
1660 defaultFormatCB->blockSignals(true);
1662 defaultFormatCB->clear();
1663 form_->formats().sort();
1664 Formats::const_iterator cit = form_->formats().begin();
1665 Formats::const_iterator end = form_->formats().end();
1666 for (; cit != end; ++cit) {
1667 formatsCB->addItem(qt_(cit->prettyname()),
1668 QVariant(form_->formats().getNumber(cit->name())));
1669 if (form_->converters().isReachable("latex", cit->name())
1670 || form_->converters().isReachable("pdflatex", cit->name()))
1671 defaultFormatCB->addItem(qt_(cit->prettyname()),
1672 QVariant(toqstr(cit->name())));
1675 // restore selection
1676 int item = formatsCB->findText(current, Qt::MatchExactly);
1677 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1678 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1679 item = defaultFormatCB->findText(current_def, Qt::MatchExactly);
1680 defaultFormatCB->setCurrentIndex(item < 0 ? 0 : item);
1681 formatsCB->blockSignals(false);
1682 defaultFormatCB->blockSignals(false);
1686 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1688 int const nr = formatsCB->itemData(i).toInt();
1689 Format const f = form_->formats().get(nr);
1691 formatED->setText(toqstr(f.name()));
1692 copierED->setText(toqstr(form_->movers().command(f.name())));
1693 extensionED->setText(toqstr(f.extension()));
1694 shortcutED->setText(
1695 toqstr(l10n_shortcut(f.prettyname(), f.shortcut())));
1696 viewerED->setText(toqstr(f.viewer()));
1697 editorED->setText(toqstr(f.editor()));
1698 documentCB->setChecked((f.documentFormat()));
1699 vectorCB->setChecked((f.vectorFormat()));
1703 void PrefFileformats::setFlags()
1705 int flags = Format::none;
1706 if (documentCB->isChecked())
1707 flags |= Format::document;
1708 if (vectorCB->isChecked())
1709 flags |= Format::vector;
1710 currentFormat().setFlags(flags);
1715 void PrefFileformats::on_copierED_textEdited(const QString & s)
1717 string const fmt = fromqstr(formatED->text());
1718 form_->movers().set(fmt, fromqstr(s));
1723 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1725 currentFormat().setExtension(fromqstr(s));
1729 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1731 currentFormat().setViewer(fromqstr(s));
1736 void PrefFileformats::on_editorED_textEdited(const QString & s)
1738 currentFormat().setEditor(fromqstr(s));
1743 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1745 string const new_shortcut = fromqstr(s);
1746 if (new_shortcut == l10n_shortcut(currentFormat().prettyname(),
1747 currentFormat().shortcut()))
1749 currentFormat().setShortcut(new_shortcut);
1754 void PrefFileformats::on_formatED_editingFinished()
1756 string const newname = fromqstr(formatED->displayText());
1757 if (newname == currentFormat().name())
1760 currentFormat().setName(newname);
1765 void PrefFileformats::on_formatED_textChanged(const QString &)
1767 QString t = formatED->text();
1769 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1770 setValid(formatLA, valid);
1774 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1776 QString t = formatsCB->currentText();
1778 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1779 setValid(formatsLA, valid);
1783 void PrefFileformats::updatePrettyname()
1785 QString const newname = formatsCB->currentText();
1786 if (newname == qt_(currentFormat().prettyname()))
1789 currentFormat().setPrettyname(fromqstr(newname));
1796 Format & PrefFileformats::currentFormat()
1798 int const i = formatsCB->currentIndex();
1799 int const nr = formatsCB->itemData(i).toInt();
1800 return form_->formats().get(nr);
1804 void PrefFileformats::on_formatNewPB_clicked()
1806 form_->formats().add("", "", "", "", "", "", Format::none);
1808 formatsCB->setCurrentIndex(0);
1809 formatsCB->setFocus(Qt::OtherFocusReason);
1813 void PrefFileformats::on_formatRemovePB_clicked()
1815 int const i = formatsCB->currentIndex();
1816 int const nr = formatsCB->itemData(i).toInt();
1817 string const current_text = form_->formats().get(nr).name();
1818 if (form_->converters().formatIsUsed(current_text)) {
1819 Alert::error(_("Format in use"),
1820 _("Cannot remove a Format used by a Converter. "
1821 "Remove the converter first."));
1825 form_->formats().erase(current_text);
1828 on_formatsCB_editTextChanged(formatsCB->currentText());
1833 /////////////////////////////////////////////////////////////////////
1837 /////////////////////////////////////////////////////////////////////
1839 PrefLanguage::PrefLanguage(GuiPreferences * form)
1840 : PrefModule(qt_(catLanguage), qt_("Language"), form)
1844 connect(rtlGB, SIGNAL(clicked()),
1845 this, SIGNAL(changed()));
1846 connect(visualCursorRB, SIGNAL(clicked()),
1847 this, SIGNAL(changed()));
1848 connect(logicalCursorRB, SIGNAL(clicked()),
1849 this, SIGNAL(changed()));
1850 connect(markForeignCB, SIGNAL(clicked()),
1851 this, SIGNAL(changed()));
1852 connect(autoBeginCB, SIGNAL(clicked()),
1853 this, SIGNAL(changed()));
1854 connect(autoEndCB, SIGNAL(clicked()),
1855 this, SIGNAL(changed()));
1856 connect(useBabelCB, SIGNAL(clicked()),
1857 this, SIGNAL(changed()));
1858 connect(globalCB, SIGNAL(clicked()),
1859 this, SIGNAL(changed()));
1860 connect(languagePackageED, SIGNAL(textChanged(QString)),
1861 this, SIGNAL(changed()));
1862 connect(startCommandED, SIGNAL(textChanged(QString)),
1863 this, SIGNAL(changed()));
1864 connect(endCommandED, SIGNAL(textChanged(QString)),
1865 this, SIGNAL(changed()));
1866 connect(uiLanguageCO, SIGNAL(activated(int)),
1867 this, SIGNAL(changed()));
1869 uiLanguageCO->clear();
1871 QAbstractItemModel * language_model = guiApp->languageModel();
1872 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1873 language_model->sort(0);
1875 // FIXME: This is wrong, we need filter this list based on the available
1877 uiLanguageCO->blockSignals(true);
1878 uiLanguageCO->addItem(qt_("Default"), toqstr("auto"));
1879 for (int i = 0; i != language_model->rowCount(); ++i) {
1880 QModelIndex index = language_model->index(i, 0);
1881 uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
1882 index.data(Qt::UserRole).toString());
1884 uiLanguageCO->blockSignals(false);
1888 void PrefLanguage::on_uiLanguageCO_currentIndexChanged(int)
1890 QMessageBox::information(this, qt_("LyX needs to be restarted!"),
1891 qt_("The change of user interface language will be fully "
1892 "effective only after a restart."));
1896 void PrefLanguage::apply(LyXRC & rc) const
1898 // FIXME: remove rtl_support bool
1899 rc.rtl_support = rtlGB->isChecked();
1900 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
1901 rc.mark_foreign_language = markForeignCB->isChecked();
1902 rc.language_auto_begin = autoBeginCB->isChecked();
1903 rc.language_auto_end = autoEndCB->isChecked();
1904 rc.language_use_babel = useBabelCB->isChecked();
1905 rc.language_global_options = globalCB->isChecked();
1906 rc.language_package = fromqstr(languagePackageED->text());
1907 rc.language_command_begin = fromqstr(startCommandED->text());
1908 rc.language_command_end = fromqstr(endCommandED->text());
1909 rc.gui_language = fromqstr(
1910 uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString());
1914 void PrefLanguage::update(LyXRC const & rc)
1916 // FIXME: remove rtl_support bool
1917 rtlGB->setChecked(rc.rtl_support);
1918 if (rc.visual_cursor)
1919 visualCursorRB->setChecked(true);
1921 logicalCursorRB->setChecked(true);
1922 markForeignCB->setChecked(rc.mark_foreign_language);
1923 autoBeginCB->setChecked(rc.language_auto_begin);
1924 autoEndCB->setChecked(rc.language_auto_end);
1925 useBabelCB->setChecked(rc.language_use_babel);
1926 globalCB->setChecked(rc.language_global_options);
1927 languagePackageED->setText(toqstr(rc.language_package));
1928 startCommandED->setText(toqstr(rc.language_command_begin));
1929 endCommandED->setText(toqstr(rc.language_command_end));
1931 int pos = uiLanguageCO->findData(toqstr(rc.gui_language));
1932 uiLanguageCO->blockSignals(true);
1933 uiLanguageCO->setCurrentIndex(pos);
1934 uiLanguageCO->blockSignals(false);
1938 /////////////////////////////////////////////////////////////////////
1942 /////////////////////////////////////////////////////////////////////
1944 PrefPrinter::PrefPrinter(GuiPreferences * form)
1945 : PrefModule(qt_(catOutput), qt_("Printer"), form)
1949 connect(printerAdaptCB, SIGNAL(clicked()),
1950 this, SIGNAL(changed()));
1951 connect(printerCommandED, SIGNAL(textChanged(QString)),
1952 this, SIGNAL(changed()));
1953 connect(printerNameED, SIGNAL(textChanged(QString)),
1954 this, SIGNAL(changed()));
1955 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
1956 this, SIGNAL(changed()));
1957 connect(printerCopiesED, SIGNAL(textChanged(QString)),
1958 this, SIGNAL(changed()));
1959 connect(printerReverseED, SIGNAL(textChanged(QString)),
1960 this, SIGNAL(changed()));
1961 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
1962 this, SIGNAL(changed()));
1963 connect(printerExtensionED, SIGNAL(textChanged(QString)),
1964 this, SIGNAL(changed()));
1965 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
1966 this, SIGNAL(changed()));
1967 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
1968 this, SIGNAL(changed()));
1969 connect(printerEvenED, SIGNAL(textChanged(QString)),
1970 this, SIGNAL(changed()));
1971 connect(printerOddED, SIGNAL(textChanged(QString)),
1972 this, SIGNAL(changed()));
1973 connect(printerCollatedED, SIGNAL(textChanged(QString)),
1974 this, SIGNAL(changed()));
1975 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
1976 this, SIGNAL(changed()));
1977 connect(printerToFileED, SIGNAL(textChanged(QString)),
1978 this, SIGNAL(changed()));
1979 connect(printerExtraED, SIGNAL(textChanged(QString)),
1980 this, SIGNAL(changed()));
1981 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
1982 this, SIGNAL(changed()));
1983 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
1984 this, SIGNAL(changed()));
1988 void PrefPrinter::apply(LyXRC & rc) const
1990 rc.print_adapt_output = printerAdaptCB->isChecked();
1991 rc.print_command = fromqstr(printerCommandED->text());
1992 rc.printer = fromqstr(printerNameED->text());
1994 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1995 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1996 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1997 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1998 rc.print_file_extension = fromqstr(printerExtensionED->text());
1999 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
2000 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
2001 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
2002 rc.print_oddpage_flag = fromqstr(printerOddED->text());
2003 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
2004 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
2005 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
2006 rc.print_extra_options = fromqstr(printerExtraED->text());
2007 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
2008 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
2012 void PrefPrinter::update(LyXRC const & rc)
2014 printerAdaptCB->setChecked(rc.print_adapt_output);
2015 printerCommandED->setText(toqstr(rc.print_command));
2016 printerNameED->setText(toqstr(rc.printer));
2018 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
2019 printerCopiesED->setText(toqstr(rc.print_copies_flag));
2020 printerReverseED->setText(toqstr(rc.print_reverse_flag));
2021 printerToPrinterED->setText(toqstr(rc.print_to_printer));
2022 printerExtensionED->setText(toqstr(rc.print_file_extension));
2023 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
2024 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
2025 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
2026 printerOddED->setText(toqstr(rc.print_oddpage_flag));
2027 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
2028 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
2029 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
2030 printerExtraED->setText(toqstr(rc.print_extra_options));
2031 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
2032 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
2036 /////////////////////////////////////////////////////////////////////
2038 // PrefUserInterface
2040 /////////////////////////////////////////////////////////////////////
2042 PrefUserInterface::PrefUserInterface(GuiPreferences * form)
2043 : PrefModule(qt_(catLookAndFeel), qt_("User interface"), form)
2047 connect(autoSaveCB, SIGNAL(toggled(bool)),
2048 autoSaveSB, SLOT(setEnabled(bool)));
2049 connect(autoSaveCB, SIGNAL(toggled(bool)),
2050 TextLabel1, SLOT(setEnabled(bool)));
2051 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
2052 this, SIGNAL(changed()));
2053 connect(uiFilePB, SIGNAL(clicked()),
2054 this, SLOT(selectUi()));
2055 connect(uiFileED, SIGNAL(textChanged(QString)),
2056 this, SIGNAL(changed()));
2057 connect(restoreCursorCB, SIGNAL(clicked()),
2058 this, SIGNAL(changed()));
2059 connect(loadSessionCB, SIGNAL(clicked()),
2060 this, SIGNAL(changed()));
2061 connect(allowGeometrySessionCB, SIGNAL(clicked()),
2062 this, SIGNAL(changed()));
2063 connect(autoSaveSB, SIGNAL(valueChanged(int)),
2064 this, SIGNAL(changed()));
2065 connect(autoSaveCB, SIGNAL(clicked()),
2066 this, SIGNAL(changed()));
2067 connect(lastfilesSB, SIGNAL(valueChanged(int)),
2068 this, SIGNAL(changed()));
2069 connect(tooltipCB, SIGNAL(toggled(bool)),
2070 this, SIGNAL(changed()));
2071 lastfilesSB->setMaximum(maxlastfiles);
2075 void PrefUserInterface::apply(LyXRC & rc) const
2077 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
2078 rc.use_lastfilepos = restoreCursorCB->isChecked();
2079 rc.load_session = loadSessionCB->isChecked();
2080 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
2081 rc.autosave = autoSaveSB->value() * 60;
2082 rc.make_backup = autoSaveCB->isChecked();
2083 rc.num_lastfiles = lastfilesSB->value();
2084 rc.use_tooltip = tooltipCB->isChecked();
2085 rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
2089 void PrefUserInterface::update(LyXRC const & rc)
2091 uiFileED->setText(toqstr(external_path(rc.ui_file)));
2092 restoreCursorCB->setChecked(rc.use_lastfilepos);
2093 loadSessionCB->setChecked(rc.load_session);
2094 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
2095 // convert to minutes
2096 int mins(rc.autosave / 60);
2097 if (rc.autosave && !mins)
2099 autoSaveSB->setValue(mins);
2100 autoSaveCB->setChecked(rc.make_backup);
2101 lastfilesSB->setValue(rc.num_lastfiles);
2102 tooltipCB->setChecked(rc.use_tooltip);
2103 openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
2107 void PrefUserInterface::selectUi()
2109 QString file = form_->browseUI(internalPath(uiFileED->text()));
2110 if (!file.isEmpty())
2111 uiFileED->setText(file);
2115 void PrefUserInterface::on_clearSessionPB_clicked()
2117 guiApp->clearSession();
2122 /////////////////////////////////////////////////////////////////////
2126 /////////////////////////////////////////////////////////////////////
2128 PrefEdit::PrefEdit(GuiPreferences * form)
2129 : PrefModule(qt_(catEditing), qt_("Control"), form)
2133 connect(cursorFollowsCB, SIGNAL(clicked()),
2134 this, SIGNAL(changed()));
2135 connect(scrollBelowCB, SIGNAL(clicked()),
2136 this, SIGNAL(changed()));
2137 connect(sortEnvironmentsCB, SIGNAL(clicked()),
2138 this, SIGNAL(changed()));
2139 connect(groupEnvironmentsCB, SIGNAL(clicked()),
2140 this, SIGNAL(changed()));
2141 connect(macroEditStyleCO, SIGNAL(activated(int)),
2142 this, SIGNAL(changed()));
2143 connect(fullscreenLimitGB, SIGNAL(clicked()),
2144 this, SIGNAL(changed()));
2145 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
2146 this, SIGNAL(changed()));
2147 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
2148 this, SIGNAL(changed()));
2149 connect(toggleMenubarCB, SIGNAL(toggled(bool)),
2150 this, SIGNAL(changed()));
2151 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
2152 this, SIGNAL(changed()));
2153 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
2154 this, SIGNAL(changed()));
2158 void PrefEdit::apply(LyXRC & rc) const
2160 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
2161 rc.scroll_below_document = scrollBelowCB->isChecked();
2162 rc.sort_layouts = sortEnvironmentsCB->isChecked();
2163 rc.group_layouts = groupEnvironmentsCB->isChecked();
2164 switch (macroEditStyleCO->currentIndex()) {
2165 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
2166 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
2167 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
2169 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
2170 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
2171 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
2172 rc.full_screen_menubar = toggleMenubarCB->isChecked();
2173 rc.full_screen_width = fullscreenWidthSB->value();
2174 rc.full_screen_limit = fullscreenLimitGB->isChecked();
2178 void PrefEdit::update(LyXRC const & rc)
2180 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
2181 scrollBelowCB->setChecked(rc.scroll_below_document);
2182 sortEnvironmentsCB->setChecked(rc.sort_layouts);
2183 groupEnvironmentsCB->setChecked(rc.group_layouts);
2184 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
2185 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
2186 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
2187 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
2188 toggleMenubarCB->setChecked(rc.full_screen_menubar);
2189 fullscreenWidthSB->setValue(rc.full_screen_width);
2190 fullscreenLimitGB->setChecked(rc.full_screen_limit);
2194 /////////////////////////////////////////////////////////////////////
2198 /////////////////////////////////////////////////////////////////////
2201 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
2203 Ui::shortcutUi::setupUi(this);
2204 QDialog::setModal(true);
2208 PrefShortcuts::PrefShortcuts(GuiPreferences * form)
2209 : PrefModule(qt_(catEditing), qt_("Shortcuts"), form)
2213 shortcutsTW->setColumnCount(2);
2214 shortcutsTW->headerItem()->setText(0, qt_("Function"));
2215 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
2216 shortcutsTW->setSortingEnabled(true);
2217 // Multi-selection can be annoying.
2218 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
2220 connect(bindFilePB, SIGNAL(clicked()),
2221 this, SLOT(selectBind()));
2222 connect(bindFileED, SIGNAL(textChanged(QString)),
2223 this, SIGNAL(changed()));
2224 connect(removePB, SIGNAL(clicked()),
2225 this, SIGNAL(changed()));
2227 shortcut_ = new GuiShortcutDialog(this);
2228 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
2229 shortcut_bc_.setOK(shortcut_->okPB);
2230 shortcut_bc_.setCancel(shortcut_->cancelPB);
2232 connect(shortcut_->okPB, SIGNAL(clicked()),
2233 shortcut_, SLOT(accept()));
2234 connect(shortcut_->okPB, SIGNAL(clicked()),
2235 this, SIGNAL(changed()));
2236 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2237 shortcut_, SLOT(reject()));
2238 connect(shortcut_->clearPB, SIGNAL(clicked()),
2239 this, SLOT(shortcutClearPressed()));
2240 connect(shortcut_->removePB, SIGNAL(clicked()),
2241 this, SLOT(shortcutRemovePressed()));
2242 connect(shortcut_->okPB, SIGNAL(clicked()),
2243 this, SLOT(shortcutOkPressed()));
2244 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2245 this, SLOT(shortcutCancelPressed()));
2249 void PrefShortcuts::apply(LyXRC & rc) const
2251 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
2252 // write user_bind and user_unbind to .lyx/bind/user.bind
2253 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
2254 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
2255 lyxerr << "LyX could not create the user bind directory '"
2256 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2259 if (!bind_dir.isDirWritable()) {
2260 lyxerr << "LyX could not write to the user bind directory '"
2261 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2264 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
2265 user_unbind_.write(user_bind_file.toFilesystemEncoding(), false, true);
2266 user_bind_.write(user_bind_file.toFilesystemEncoding(), true, false);
2267 // immediately apply the keybindings. Why this is not done before?
2268 // The good thing is that the menus are updated automatically.
2269 theTopLevelKeymap().clear();
2270 theTopLevelKeymap().read("site");
2271 theTopLevelKeymap().read(rc.bind_file);
2272 theTopLevelKeymap().read("user");
2276 void PrefShortcuts::update(LyXRC const & rc)
2278 bindFileED->setText(toqstr(external_path(rc.bind_file)));
2280 system_bind_.clear();
2282 user_unbind_.clear();
2283 system_bind_.read("site");
2284 system_bind_.read(rc.bind_file);
2285 // \unbind in user.bind is added to user_unbind_
2286 user_bind_.read("user", &user_unbind_);
2287 updateShortcutsTW();
2291 void PrefShortcuts::updateShortcutsTW()
2293 shortcutsTW->clear();
2295 editItem_ = new QTreeWidgetItem(shortcutsTW);
2296 editItem_->setText(0, qt_("Cursor, Mouse and Editing functions"));
2297 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2299 mathItem_ = new QTreeWidgetItem(shortcutsTW);
2300 mathItem_->setText(0, qt_("Mathematical Symbols"));
2301 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2303 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2304 bufferItem_->setText(0, qt_("Document and Window"));
2305 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2307 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2308 layoutItem_->setText(0, qt_("Font, Layouts and Textclasses"));
2309 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2311 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2312 systemItem_->setText(0, qt_("System and Miscellaneous"));
2313 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2315 // listBindings(unbound=true) lists all bound and unbound lfuns
2316 // Items in this list is tagged by its source.
2317 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2319 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2321 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2322 KeyMap::UserUnbind);
2323 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2324 user_bindinglist.end());
2325 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2326 user_unbindinglist.end());
2328 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2329 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2330 for (; it != it_end; ++it)
2331 insertShortcutItem(it->request, it->sequence, KeyMap::ItemType(it->tag));
2333 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2334 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2335 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2336 modifyPB->setEnabled(!items.isEmpty());
2338 shortcutsTW->resizeColumnToContents(0);
2342 void PrefShortcuts::setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag)
2344 item->setData(0, Qt::UserRole, QVariant(tag));
2348 case KeyMap::System:
2350 case KeyMap::UserBind:
2353 case KeyMap::UserUnbind:
2354 font.setStrikeOut(true);
2356 // this item is not displayed now.
2357 case KeyMap::UserExtraUnbind:
2358 font.setStrikeOut(true);
2362 item->setFont(1, font);
2366 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2367 KeySequence const & seq, KeyMap::ItemType tag)
2369 FuncCode action = lfun.action;
2370 string const action_name = lyxaction.getActionName(action);
2371 QString const lfun_name = toqstr(from_utf8(action_name)
2372 + ' ' + lfun.argument());
2373 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2374 KeyMap::ItemType item_tag = tag;
2376 QTreeWidgetItem * newItem = 0;
2377 // for unbind items, try to find an existing item in the system bind list
2378 if (tag == KeyMap::UserUnbind) {
2379 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2380 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2381 for (int i = 0; i < items.size(); ++i) {
2382 if (items[i]->text(1) == shortcut)
2386 // if not found, this unbind item is KeyMap::UserExtraUnbind
2387 // Such an item is not displayed to avoid confusion (what is
2388 // unmatched removed?).
2390 item_tag = KeyMap::UserExtraUnbind;
2395 switch(lyxaction.getActionType(action)) {
2396 case LyXAction::Hidden:
2398 case LyXAction::Edit:
2399 newItem = new QTreeWidgetItem(editItem_);
2401 case LyXAction::Math:
2402 newItem = new QTreeWidgetItem(mathItem_);
2404 case LyXAction::Buffer:
2405 newItem = new QTreeWidgetItem(bufferItem_);
2407 case LyXAction::Layout:
2408 newItem = new QTreeWidgetItem(layoutItem_);
2410 case LyXAction::System:
2411 newItem = new QTreeWidgetItem(systemItem_);
2414 // this should not happen
2415 newItem = new QTreeWidgetItem(shortcutsTW);
2419 newItem->setText(0, lfun_name);
2420 newItem->setText(1, shortcut);
2421 // record BindFile representation to recover KeySequence when needed.
2422 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2423 setItemType(newItem, item_tag);
2428 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2430 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2431 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2432 modifyPB->setEnabled(!items.isEmpty());
2433 if (items.isEmpty())
2436 KeyMap::ItemType tag =
2437 static_cast<KeyMap::ItemType>(items[0]->data(0, Qt::UserRole).toInt());
2438 if (tag == KeyMap::UserUnbind)
2439 removePB->setText(qt_("Res&tore"));
2441 removePB->setText(qt_("Remo&ve"));
2445 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2451 void PrefShortcuts::modifyShortcut()
2453 QTreeWidgetItem * item = shortcutsTW->currentItem();
2454 if (item->flags() & Qt::ItemIsSelectable) {
2455 shortcut_->lfunLE->setText(item->text(0));
2456 save_lfun_ = item->text(0);
2457 shortcut_->shortcutWG->setText(item->text(1));
2459 seq.parse(fromqstr(item->data(1, Qt::UserRole).toString()));
2460 shortcut_->shortcutWG->setKeySequence(seq);
2461 shortcut_->shortcutWG->setFocus();
2467 void PrefShortcuts::removeShortcut()
2469 // it seems that only one item can be selected, but I am
2470 // removing all selected items anyway.
2471 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2472 for (int i = 0; i < items.size(); ++i) {
2473 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2474 string lfun = fromqstr(items[i]->text(0));
2475 FuncRequest func = lyxaction.lookupFunc(lfun);
2476 KeyMap::ItemType tag =
2477 static_cast<KeyMap::ItemType>(items[i]->data(0, Qt::UserRole).toInt());
2480 case KeyMap::System: {
2481 // for system bind, we do not touch the item
2482 // but add an user unbind item
2483 user_unbind_.bind(shortcut, func);
2484 setItemType(items[i], KeyMap::UserUnbind);
2485 removePB->setText(qt_("Res&tore"));
2488 case KeyMap::UserBind: {
2489 // for user_bind, we remove this bind
2490 QTreeWidgetItem * parent = items[i]->parent();
2491 int itemIdx = parent->indexOfChild(items[i]);
2492 parent->takeChild(itemIdx);
2494 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2496 shortcutsTW->scrollToItem(parent);
2497 user_bind_.unbind(shortcut, func);
2500 case KeyMap::UserUnbind: {
2501 // for user_unbind, we remove the unbind, and the item
2502 // become KeyMap::System again.
2503 user_unbind_.unbind(shortcut, func);
2504 setItemType(items[i], KeyMap::System);
2505 removePB->setText(qt_("Remo&ve"));
2508 case KeyMap::UserExtraUnbind: {
2509 // for user unbind that is not in system bind file,
2510 // remove this unbind file
2511 QTreeWidgetItem * parent = items[i]->parent();
2512 parent->takeChild(parent->indexOfChild(items[i]));
2513 user_unbind_.unbind(shortcut, func);
2520 void PrefShortcuts::selectBind()
2522 QString file = form_->browsebind(internalPath(bindFileED->text()));
2523 if (!file.isEmpty()) {
2524 bindFileED->setText(file);
2525 system_bind_ = KeyMap();
2526 system_bind_.read(fromqstr(file));
2527 updateShortcutsTW();
2532 void PrefShortcuts::on_modifyPB_pressed()
2538 void PrefShortcuts::on_newPB_pressed()
2540 shortcut_->lfunLE->clear();
2541 shortcut_->shortcutWG->reset();
2542 save_lfun_ = QString();
2547 void PrefShortcuts::on_removePB_pressed()
2553 void PrefShortcuts::on_searchLE_textEdited()
2555 if (searchLE->text().isEmpty()) {
2556 // show all hidden items
2557 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2559 shortcutsTW->setItemHidden(*it++, false);
2562 // search both columns
2563 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2564 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2565 matched += shortcutsTW->findItems(searchLE->text(),
2566 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2568 // hide everyone (to avoid searching in matched QList repeatedly
2569 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2571 shortcutsTW->setItemHidden(*it++, true);
2572 // show matched items
2573 for (int i = 0; i < matched.size(); ++i) {
2574 shortcutsTW->setItemHidden(matched[i], false);
2575 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2580 docstring makeCmdString(FuncRequest const & f)
2582 docstring actionStr = from_ascii(lyxaction.getActionName(f.action));
2583 if (!f.argument().empty())
2584 actionStr += " " + f.argument();
2589 void PrefShortcuts::shortcutOkPressed()
2591 QString const new_lfun = shortcut_->lfunLE->text();
2592 FuncRequest func = lyxaction.lookupFunc(fromqstr(new_lfun));
2594 if (func.action == LFUN_UNKNOWN_ACTION) {
2595 Alert::error(_("Failed to create shortcut"),
2596 _("Unknown or invalid LyX function"));
2600 KeySequence k = shortcut_->shortcutWG->getKeySequence();
2601 if (k.length() == 0) {
2602 Alert::error(_("Failed to create shortcut"),
2603 _("Invalid or empty key sequence"));
2607 // check to see if there's been any change
2608 FuncRequest oldBinding = system_bind_.getBinding(k);
2609 if (oldBinding.action == LFUN_UNKNOWN_ACTION)
2610 oldBinding = user_bind_.getBinding(k);
2611 if (oldBinding == func) {
2612 docstring const actionStr = makeCmdString(func);
2613 Alert::error(_("Failed to create shortcut"),
2614 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s"),
2615 k.print(KeySequence::ForGui), actionStr));
2619 // make sure this key isn't already bound---and, if so, not unbound
2620 FuncCode const unbind = user_unbind_.getBinding(k).action;
2621 if (oldBinding.action != LFUN_UNKNOWN_ACTION && unbind == LFUN_UNKNOWN_ACTION)
2623 // FIXME Perhaps we should offer to over-write the old shortcut?
2624 // If so, we'll need to remove it from our list, etc.
2625 docstring const actionStr = makeCmdString(oldBinding);
2626 Alert::error(_("Failed to create shortcut"),
2627 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s\n"
2628 "You need to remove that binding before creating a new one."),
2629 k.print(KeySequence::ForGui), actionStr));
2633 if (!save_lfun_.isEmpty() && new_lfun == save_lfun_)
2634 // real modification of the lfun's shortcut,
2635 // so remove the previous one
2638 QTreeWidgetItem * item = insertShortcutItem(func, k, KeyMap::UserBind);
2640 user_bind_.bind(&k, func);
2641 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2642 shortcutsTW->setItemExpanded(item->parent(), true);
2643 shortcutsTW->scrollToItem(item);
2645 Alert::error(_("Failed to create shortcut"),
2646 _("Can not insert shortcut to the list"));
2652 void PrefShortcuts::shortcutCancelPressed()
2654 shortcut_->shortcutWG->reset();
2658 void PrefShortcuts::shortcutClearPressed()
2660 shortcut_->shortcutWG->reset();
2664 void PrefShortcuts::shortcutRemovePressed()
2666 shortcut_->shortcutWG->removeFromSequence();
2670 /////////////////////////////////////////////////////////////////////
2674 /////////////////////////////////////////////////////////////////////
2676 PrefIdentity::PrefIdentity(GuiPreferences * form)
2677 : PrefModule(QString(), qt_("Identity"), form)
2681 connect(nameED, SIGNAL(textChanged(QString)),
2682 this, SIGNAL(changed()));
2683 connect(emailED, SIGNAL(textChanged(QString)),
2684 this, SIGNAL(changed()));
2688 void PrefIdentity::apply(LyXRC & rc) const
2690 rc.user_name = fromqstr(nameED->text());
2691 rc.user_email = fromqstr(emailED->text());
2695 void PrefIdentity::update(LyXRC const & rc)
2697 nameED->setText(toqstr(rc.user_name));
2698 emailED->setText(toqstr(rc.user_email));
2703 /////////////////////////////////////////////////////////////////////
2707 /////////////////////////////////////////////////////////////////////
2709 GuiPreferences::GuiPreferences(GuiView & lv)
2710 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2714 QDialog::setModal(false);
2716 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2717 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2718 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2719 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2721 addModule(new PrefUserInterface(this));
2722 addModule(new PrefEdit(this));
2723 addModule(new PrefShortcuts(this));
2724 addModule(new PrefScreenFonts(this));
2725 addModule(new PrefColors(this));
2726 addModule(new PrefDisplay(this));
2727 addModule(new PrefInput(this));
2728 addModule(new PrefCompletion(this));
2730 addModule(new PrefPaths(this));
2732 addModule(new PrefIdentity(this));
2734 addModule(new PrefLanguage(this));
2735 addModule(new PrefSpellchecker(this));
2737 addModule(new PrefPrinter(this));
2738 PrefDate * dateFormat = new PrefDate(this);
2739 addModule(dateFormat);
2740 addModule(new PrefPlaintext(this));
2741 addModule(new PrefLatex(this));
2743 PrefConverters * converters = new PrefConverters(this);
2744 PrefFileformats * formats = new PrefFileformats(this);
2745 connect(formats, SIGNAL(formatsChanged()),
2746 converters, SLOT(updateGui()));
2747 addModule(converters);
2750 prefsPS->setCurrentPanel(qt_("User interface"));
2751 // FIXME: hack to work around resizing bug in Qt >= 4.2
2752 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2753 #if QT_VERSION >= 0x040200
2754 prefsPS->updateGeometry();
2757 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2759 bc().setApply(applyPB);
2760 bc().setCancel(closePB);
2761 bc().setRestore(restorePB);
2763 // initialize the strftime validator
2764 bc().addCheckedLineEdit(dateFormat->DateED);
2768 void GuiPreferences::addModule(PrefModule * module)
2770 LASSERT(module, return);
2771 if (module->category().isEmpty())
2772 prefsPS->addPanel(module, module->title());
2774 prefsPS->addPanel(module, module->title(), module->category());
2775 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2776 modules_.push_back(module);
2780 void GuiPreferences::change_adaptor()
2786 void GuiPreferences::apply(LyXRC & rc) const
2788 size_t end = modules_.size();
2789 for (size_t i = 0; i != end; ++i)
2790 modules_[i]->apply(rc);
2794 void GuiPreferences::updateRc(LyXRC const & rc)
2796 size_t const end = modules_.size();
2797 for (size_t i = 0; i != end; ++i)
2798 modules_[i]->update(rc);
2802 void GuiPreferences::applyView()
2807 bool GuiPreferences::initialiseParams(string const &)
2810 formats_ = lyx::formats;
2811 converters_ = theConverters();
2812 converters_.update(formats_);
2813 movers_ = theMovers();
2815 update_screen_font_ = false;
2818 // Make sure that the bc is in the INITIAL state
2819 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
2826 void GuiPreferences::dispatchParams()
2829 rc_.write(ss, true);
2830 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
2831 // FIXME: these need lfuns
2833 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
2835 lyx::formats = formats_;
2837 theConverters() = converters_;
2838 theConverters().update(lyx::formats);
2839 theConverters().buildGraph();
2841 theMovers() = movers_;
2843 vector<string>::const_iterator it = colors_.begin();
2844 vector<string>::const_iterator const end = colors_.end();
2845 for (; it != end; ++it)
2846 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
2849 if (update_screen_font_) {
2850 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2851 update_screen_font_ = false;
2854 // The Save button has been pressed
2856 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
2860 void GuiPreferences::setColor(ColorCode col, QString const & hex)
2862 colors_.push_back(lcolor.getLyXName(col) + ' ' + fromqstr(hex));
2866 void GuiPreferences::updateScreenFonts()
2868 update_screen_font_ = true;
2872 QString GuiPreferences::browsebind(QString const & file) const
2874 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
2875 QStringList(qt_("LyX bind files (*.bind)")));
2879 QString GuiPreferences::browseUI(QString const & file) const
2881 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
2882 QStringList(qt_("LyX UI files (*.ui)")));
2886 QString GuiPreferences::browsekbmap(QString const & file) const
2888 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
2889 QStringList(qt_("LyX keyboard maps (*.kmap)")));
2893 QString GuiPreferences::browse(QString const & file,
2894 QString const & title) const
2896 return browseFile(file, title, QStringList(), true);
2900 // We support less paper sizes than the document dialog
2901 // Therefore this adjustment is needed.
2902 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
2906 return PAPER_DEFAULT;
2908 return PAPER_USLETTER;
2910 return PAPER_USLEGAL;
2912 return PAPER_USEXECUTIVE;
2922 // should not happen
2923 return PAPER_DEFAULT;
2928 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
2930 switch (papersize) {
2933 case PAPER_USLETTER:
2937 case PAPER_USEXECUTIVE:
2948 // should not happen
2954 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
2957 } // namespace frontend
2960 #include "moc_GuiPrefs.cpp"