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"
37 #include "SpellChecker.h"
39 #include "support/debug.h"
40 #include "support/FileName.h"
41 #include "support/filetools.h"
42 #include "support/foreach.h"
43 #include "support/gettext.h"
44 #include "support/lstrings.h"
45 #include "support/os.h"
46 #include "support/Package.h"
48 #include "graphics/GraphicsTypes.h"
50 #include "frontends/alert.h"
51 #include "frontends/Application.h"
52 #include "frontends/FontLoader.h"
54 #include <QAbstractItemModel>
56 #include <QColorDialog>
57 #include <QFontDatabase>
58 #include <QHeaderView>
60 #include <QMessageBox>
61 #include <QPixmapCache>
62 #include <QPushButton>
65 #include <QTreeWidget>
66 #include <QTreeWidgetItem>
76 using namespace lyx::support;
77 using namespace lyx::support::os;
82 /////////////////////////////////////////////////////////////////////
86 /////////////////////////////////////////////////////////////////////
88 /** Launch a file dialog and return the chosen file.
89 filename: a suggested filename.
90 title: the title of the dialog.
92 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
94 QString browseFile(QString const & filename,
95 QString const & title,
96 QStringList const & filters,
98 QString const & label1 = QString(),
99 QString const & dir1 = QString(),
100 QString const & label2 = QString(),
101 QString const & dir2 = QString(),
102 QString const & fallback_dir = QString())
104 QString lastPath = ".";
105 if (!filename.isEmpty())
106 lastPath = onlyPath(filename);
107 else if(!fallback_dir.isEmpty())
108 lastPath = fallback_dir;
110 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
111 dlg.setButton2(label1, dir1);
112 dlg.setButton2(label2, dir2);
114 FileDialog::Result result;
117 result = dlg.save(lastPath, filters, onlyFilename(filename));
119 result = dlg.open(lastPath, filters, onlyFilename(filename));
121 return result.second;
125 /** Wrapper around browseFile which tries to provide a filename
126 * relative to the user or system directory. The dir, name and ext
127 * parameters have the same meaning as in the
128 * support::LibFileSearch function.
130 QString browseLibFile(QString const & dir,
131 QString const & name,
133 QString const & title,
134 QStringList const & filters)
137 QString const label1 = qt_("System files|#S#s");
139 toqstr(addName(package().system_support().absFilename(), fromqstr(dir)));
141 QString const label2 = qt_("User files|#U#u");
143 toqstr(addName(package().user_support().absFilename(), fromqstr(dir)));
145 QString const result = browseFile(toqstr(
146 libFileSearch(dir, name, ext).absFilename()),
147 title, filters, false, dir1, dir2, QString(), QString(), dir1);
149 // remove the extension if it is the default one
151 if (getExtension(result) == ext)
152 noextresult = removeExtension(result);
154 noextresult = result;
156 // remove the directory, if it is the default one
157 QString const file = onlyFilename(noextresult);
158 if (toqstr(libFileSearch(dir, file, ext).absFilename()) == result)
165 /** Launch a file dialog and return the chosen directory.
166 pathname: a suggested pathname.
167 title: the title of the dialog.
168 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
170 QString browseDir(QString const & pathname,
171 QString const & title,
172 QString const & label1 = QString(),
173 QString const & dir1 = QString(),
174 QString const & label2 = QString(),
175 QString const & dir2 = QString())
177 QString lastPath = ".";
178 if (!pathname.isEmpty())
179 lastPath = onlyPath(pathname);
181 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
182 dlg.setButton1(label1, dir1);
183 dlg.setButton2(label2, dir2);
185 FileDialog::Result const result =
186 dlg.opendir(lastPath, onlyFilename(pathname));
188 return result.second;
192 } // namespace frontend
195 QString browseRelFile(QString const & filename, QString const & refpath,
196 QString const & title, QStringList const & filters, bool save,
197 QString const & label1, QString const & dir1,
198 QString const & label2, QString const & dir2)
200 QString const fname = makeAbsPath(filename, refpath);
203 QString const outname =
204 frontend::browseFile(fname, title, filters, save, label1, dir1, label2, dir2);
206 QString const reloutname =
207 toqstr(makeRelPath(qstring_to_ucs4(outname), qstring_to_ucs4(refpath)));
209 if (reloutname.startsWith("../"))
217 /////////////////////////////////////////////////////////////////////
221 /////////////////////////////////////////////////////////////////////
225 string const catLookAndFeel = N_("Look & Feel");
226 string const catEditing = N_("Editing");
227 string const catLanguage = N_("Language Settings");
228 string const catOutput = N_("Output");
229 string const catFiles = N_("File Handling");
231 static void parseFontName(QString const & mangled0,
232 string & name, string & foundry)
234 string mangled = fromqstr(mangled0);
235 size_t const idx = mangled.find('[');
236 if (idx == string::npos || idx == 0) {
240 name = mangled.substr(0, idx - 1),
241 foundry = mangled.substr(idx + 1, mangled.size() - idx - 2);
246 static void setComboxFont(QComboBox * cb, string const & family,
247 string const & foundry)
249 QString fontname = toqstr(family);
250 if (!foundry.empty())
251 fontname += " [" + toqstr(foundry) + ']';
253 for (int i = 0; i != cb->count(); ++i) {
254 if (cb->itemText(i) == fontname) {
255 cb->setCurrentIndex(i);
260 // Try matching without foundry name
262 // We count in reverse in order to prefer the Xft foundry
263 for (int i = cb->count(); --i >= 0;) {
264 string name, foundry;
265 parseFontName(cb->itemText(i), name, foundry);
266 if (compare_ascii_no_case(name, family) == 0) {
267 cb->setCurrentIndex(i);
272 // family alone can contain e.g. "Helvetica [Adobe]"
273 string tmpname, tmpfoundry;
274 parseFontName(toqstr(family), tmpname, tmpfoundry);
276 // We count in reverse in order to prefer the Xft foundry
277 for (int i = cb->count(); --i >= 0; ) {
278 string name, foundry;
279 parseFontName(cb->itemText(i), name, foundry);
280 if (compare_ascii_no_case(name, foundry) == 0) {
281 cb->setCurrentIndex(i);
286 // Bleh, default fonts, and the names couldn't be found. Hack
290 font.setKerning(false);
292 QString const font_family = toqstr(family);
293 if (font_family == guiApp->romanFontName()) {
294 font.setStyleHint(QFont::Serif);
295 font.setFamily(font_family);
296 } else if (font_family == guiApp->sansFontName()) {
297 font.setStyleHint(QFont::SansSerif);
298 font.setFamily(font_family);
299 } else if (font_family == guiApp->typewriterFontName()) {
300 font.setStyleHint(QFont::TypeWriter);
301 font.setFamily(font_family);
303 LYXERR0("FAILED to find the default font: '"
304 << foundry << "', '" << family << '\'');
308 QFontInfo info(font);
309 string default_font_name, dummyfoundry;
310 parseFontName(info.family(), default_font_name, dummyfoundry);
311 LYXERR0("Apparent font is " << default_font_name);
313 for (int i = 0; i < cb->count(); ++i) {
314 LYXERR0("Looking at " << cb->itemText(i));
315 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
316 default_font_name) == 0) {
317 cb->setCurrentIndex(i);
322 LYXERR0("FAILED to find the font: '"
323 << foundry << "', '" << family << '\'');
328 /////////////////////////////////////////////////////////////////////
332 /////////////////////////////////////////////////////////////////////
334 PrefPlaintext::PrefPlaintext(GuiPreferences * form)
335 : PrefModule(qt_(catOutput), qt_("Plain text"), form)
338 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
339 this, SIGNAL(changed()));
343 void PrefPlaintext::apply(LyXRC & rc) const
345 rc.plaintext_linelen = plaintextLinelengthSB->value();
349 void PrefPlaintext::update(LyXRC const & rc)
351 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
355 /////////////////////////////////////////////////////////////////////
359 /////////////////////////////////////////////////////////////////////
361 class StrftimeValidator : public QValidator
364 StrftimeValidator(QWidget *);
365 QValidator::State validate(QString & input, int & pos) const;
369 StrftimeValidator::StrftimeValidator(QWidget * parent)
375 QValidator::State StrftimeValidator::validate(QString & input, int & /*pos*/) const
377 if (is_valid_strftime(fromqstr(input)))
378 return QValidator::Acceptable;
380 return QValidator::Intermediate;
384 /////////////////////////////////////////////////////////////////////
388 /////////////////////////////////////////////////////////////////////
390 PrefDate::PrefDate(GuiPreferences * form)
391 : PrefModule(qt_(catOutput), qt_("Date format"), form)
394 DateED->setValidator(new StrftimeValidator(DateED));
395 connect(DateED, SIGNAL(textChanged(QString)),
396 this, SIGNAL(changed()));
400 void PrefDate::on_DateED_textChanged(const QString &)
402 QString t = DateED->text();
404 bool valid = DateED->validator()->validate(t, p)
405 == QValidator::Acceptable;
406 setValid(DateLA, valid);
410 void PrefDate::apply(LyXRC & rc) const
412 rc.date_insert_format = fromqstr(DateED->text());
416 void PrefDate::update(LyXRC const & rc)
418 DateED->setText(toqstr(rc.date_insert_format));
422 /////////////////////////////////////////////////////////////////////
426 /////////////////////////////////////////////////////////////////////
428 PrefInput::PrefInput(GuiPreferences * form)
429 : PrefModule(qt_(catEditing), qt_("Keyboard/Mouse"), form)
433 connect(keymapCB, SIGNAL(clicked()),
434 this, SIGNAL(changed()));
435 connect(firstKeymapED, SIGNAL(textChanged(QString)),
436 this, SIGNAL(changed()));
437 connect(secondKeymapED, SIGNAL(textChanged(QString)),
438 this, SIGNAL(changed()));
439 connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
440 this, SIGNAL(changed()));
444 void PrefInput::apply(LyXRC & rc) const
446 // FIXME: can derive CB from the two EDs
447 rc.use_kbmap = keymapCB->isChecked();
448 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
449 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
450 rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
454 void PrefInput::update(LyXRC const & rc)
456 // FIXME: can derive CB from the two EDs
457 keymapCB->setChecked(rc.use_kbmap);
458 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
459 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
460 mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
464 QString PrefInput::testKeymap(QString const & keymap)
466 return form_->browsekbmap(internalPath(keymap));
470 void PrefInput::on_firstKeymapPB_clicked(bool)
472 QString const file = testKeymap(firstKeymapED->text());
474 firstKeymapED->setText(file);
478 void PrefInput::on_secondKeymapPB_clicked(bool)
480 QString const file = testKeymap(secondKeymapED->text());
482 secondKeymapED->setText(file);
486 void PrefInput::on_keymapCB_toggled(bool keymap)
488 firstKeymapLA->setEnabled(keymap);
489 secondKeymapLA->setEnabled(keymap);
490 firstKeymapED->setEnabled(keymap);
491 secondKeymapED->setEnabled(keymap);
492 firstKeymapPB->setEnabled(keymap);
493 secondKeymapPB->setEnabled(keymap);
497 /////////////////////////////////////////////////////////////////////
501 /////////////////////////////////////////////////////////////////////
503 PrefCompletion::PrefCompletion(GuiPreferences * form)
504 : PrefModule(qt_(catEditing), qt_("Input Completion"), form)
508 connect(inlineDelaySB, SIGNAL(valueChanged(double)),
509 this, SIGNAL(changed()));
510 connect(inlineMathCB, SIGNAL(clicked()),
511 this, SIGNAL(changed()));
512 connect(inlineTextCB, SIGNAL(clicked()),
513 this, SIGNAL(changed()));
514 connect(inlineDotsCB, SIGNAL(clicked()),
515 this, SIGNAL(changed()));
516 connect(popupDelaySB, SIGNAL(valueChanged(double)),
517 this, SIGNAL(changed()));
518 connect(popupMathCB, SIGNAL(clicked()),
519 this, SIGNAL(changed()));
520 connect(autocorrectionCB, SIGNAL(clicked()),
521 this, SIGNAL(changed()));
522 connect(popupTextCB, SIGNAL(clicked()),
523 this, SIGNAL(changed()));
524 connect(popupAfterCompleteCB, SIGNAL(clicked()),
525 this, SIGNAL(changed()));
526 connect(cursorTextCB, SIGNAL(clicked()),
527 this, SIGNAL(changed()));
531 void PrefCompletion::on_inlineTextCB_clicked()
537 void PrefCompletion::on_popupTextCB_clicked()
543 void PrefCompletion::enableCB()
545 cursorTextCB->setEnabled(
546 popupTextCB->isChecked() || inlineTextCB->isChecked());
550 void PrefCompletion::apply(LyXRC & rc) const
552 rc.completion_inline_delay = inlineDelaySB->value();
553 rc.completion_inline_math = inlineMathCB->isChecked();
554 rc.completion_inline_text = inlineTextCB->isChecked();
555 rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
556 rc.completion_popup_delay = popupDelaySB->value();
557 rc.completion_popup_math = popupMathCB->isChecked();
558 rc.autocorrection_math = autocorrectionCB->isChecked();
559 rc.completion_popup_text = popupTextCB->isChecked();
560 rc.completion_cursor_text = cursorTextCB->isChecked();
561 rc.completion_popup_after_complete =
562 popupAfterCompleteCB->isChecked();
566 void PrefCompletion::update(LyXRC const & rc)
568 inlineDelaySB->setValue(rc.completion_inline_delay);
569 inlineMathCB->setChecked(rc.completion_inline_math);
570 inlineTextCB->setChecked(rc.completion_inline_text);
571 inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
572 popupDelaySB->setValue(rc.completion_popup_delay);
573 popupMathCB->setChecked(rc.completion_popup_math);
574 autocorrectionCB->setChecked(rc.autocorrection_math);
575 popupTextCB->setChecked(rc.completion_popup_text);
576 cursorTextCB->setChecked(rc.completion_cursor_text);
577 popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
583 /////////////////////////////////////////////////////////////////////
587 /////////////////////////////////////////////////////////////////////
589 PrefLatex::PrefLatex(GuiPreferences * form)
590 : PrefModule(qt_(catOutput), qt_("LaTeX"), form)
593 connect(latexEncodingCB, SIGNAL(clicked()),
594 this, SIGNAL(changed()));
595 connect(latexEncodingED, SIGNAL(textChanged(QString)),
596 this, SIGNAL(changed()));
597 connect(latexChecktexED, SIGNAL(textChanged(QString)),
598 this, SIGNAL(changed()));
599 connect(latexBibtexCO, SIGNAL(activated(int)),
600 this, SIGNAL(changed()));
601 connect(latexBibtexED, SIGNAL(textChanged(QString)),
602 this, SIGNAL(changed()));
603 connect(latexJBibtexED, SIGNAL(textChanged(QString)),
604 this, SIGNAL(changed()));
605 connect(latexIndexCO, SIGNAL(activated(int)),
606 this, SIGNAL(changed()));
607 connect(latexIndexED, SIGNAL(textChanged(QString)),
608 this, SIGNAL(changed()));
609 connect(latexJIndexED, SIGNAL(textChanged(QString)),
610 this, SIGNAL(changed()));
611 connect(latexAutoresetCB, SIGNAL(clicked()),
612 this, SIGNAL(changed()));
613 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
614 this, SIGNAL(changed()));
615 connect(latexPaperSizeCO, SIGNAL(activated(int)),
616 this, SIGNAL(changed()));
618 #if defined(__CYGWIN__) || defined(_WIN32)
619 pathCB->setVisible(true);
620 connect(pathCB, SIGNAL(clicked()),
621 this, SIGNAL(changed()));
623 pathCB->setVisible(false);
628 void PrefLatex::on_latexEncodingCB_stateChanged(int state)
630 latexEncodingED->setEnabled(state == Qt::Checked);
634 void PrefLatex::on_latexBibtexCO_activated(int n)
636 QString const bibtex = latexBibtexCO->itemData(n).toString();
637 if (bibtex.isEmpty()) {
638 latexBibtexED->clear();
639 latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
642 for (LyXRC::CommandSet::const_iterator it = bibtex_alternatives.begin();
643 it != bibtex_alternatives.end(); ++it) {
644 QString const bib = toqstr(*it);
645 int ind = bib.indexOf(" ");
646 QString sel_command = bib.left(ind);
647 QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
648 if (bibtex == sel_command) {
650 latexBibtexED->clear();
652 latexBibtexED->setText(sel_options.trimmed());
655 latexBibtexOptionsLA->setText(qt_("&Options:"));
659 void PrefLatex::on_latexIndexCO_activated(int n)
661 QString const index = latexIndexCO->itemData(n).toString();
662 if (index.isEmpty()) {
663 latexIndexED->clear();
664 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
667 for (LyXRC::CommandSet::const_iterator it = index_alternatives.begin();
668 it != index_alternatives.end(); ++it) {
669 QString const idx = toqstr(*it);
670 int ind = idx.indexOf(" ");
671 QString sel_command = idx.left(ind);
672 QString sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
673 if (index == sel_command) {
675 latexIndexED->clear();
677 latexIndexED->setText(sel_options.trimmed());
680 latexIndexOptionsLA->setText(qt_("Op&tions:"));
684 void PrefLatex::apply(LyXRC & rc) const
686 // If bibtex is not empty, bibopt contains the options, otherwise
687 // it is a customized bibtex command with options.
688 QString const bibtex = latexBibtexCO->itemData(
689 latexBibtexCO->currentIndex()).toString();
690 QString const bibopt = latexBibtexED->text();
691 if (bibtex.isEmpty())
692 rc.bibtex_command = fromqstr(bibopt);
693 else if (bibopt.isEmpty())
694 rc.bibtex_command = fromqstr(bibtex);
696 rc.bibtex_command = fromqstr(bibtex) + " " + fromqstr(bibopt);
698 // If index is not empty, idxopt contains the options, otherwise
699 // it is a customized index command with options.
700 QString const index = latexIndexCO->itemData(
701 latexIndexCO->currentIndex()).toString();
702 QString const idxopt = latexIndexED->text();
704 rc.index_command = fromqstr(idxopt);
705 else if (idxopt.isEmpty())
706 rc.index_command = fromqstr(index);
708 rc.index_command = fromqstr(index) + " " + fromqstr(idxopt);
710 if (latexEncodingCB->isChecked())
711 rc.fontenc = fromqstr(latexEncodingED->text());
713 rc.fontenc = "default";
714 rc.chktex_command = fromqstr(latexChecktexED->text());
715 rc.jbibtex_command = fromqstr(latexJBibtexED->text());
716 rc.jindex_command = fromqstr(latexJIndexED->text());
717 rc.nomencl_command = fromqstr(latexNomenclED->text());
718 rc.auto_reset_options = latexAutoresetCB->isChecked();
719 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
720 rc.default_papersize =
721 form_->toPaperSize(latexPaperSizeCO->currentIndex());
722 #if defined(__CYGWIN__) || defined(_WIN32)
723 rc.windows_style_tex_paths = pathCB->isChecked();
728 void PrefLatex::update(LyXRC const & rc)
730 latexBibtexCO->clear();
732 latexBibtexCO->addItem(qt_("Custom"), QString());
733 for (LyXRC::CommandSet::const_iterator it = rc.bibtex_alternatives.begin();
734 it != rc.bibtex_alternatives.end(); ++it) {
735 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
736 latexBibtexCO->addItem(command, command);
739 bibtex_alternatives = rc.bibtex_alternatives;
741 QString const bib = toqstr(rc.bibtex_command);
742 int ind = bib.indexOf(" ");
743 QString sel_command = bib.left(ind);
744 QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
746 int pos = latexBibtexCO->findData(sel_command);
748 latexBibtexCO->setCurrentIndex(pos);
749 latexBibtexED->setText(sel_options.trimmed());
750 latexBibtexOptionsLA->setText(qt_("&Options:"));
752 latexBibtexED->setText(toqstr(rc.bibtex_command));
753 latexBibtexCO->setCurrentIndex(0);
754 latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
757 latexIndexCO->clear();
759 latexIndexCO->addItem(qt_("Custom"), QString());
760 for (LyXRC::CommandSet::const_iterator it = rc.index_alternatives.begin();
761 it != rc.index_alternatives.end(); ++it) {
762 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
763 latexIndexCO->addItem(command, command);
766 index_alternatives = rc.index_alternatives;
768 QString const idx = toqstr(rc.index_command);
769 ind = idx.indexOf(" ");
770 sel_command = idx.left(ind);
771 sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
773 pos = latexIndexCO->findData(sel_command);
775 latexIndexCO->setCurrentIndex(pos);
776 latexIndexED->setText(sel_options.trimmed());
777 latexIndexOptionsLA->setText(qt_("Op&tions:"));
779 latexIndexED->setText(toqstr(rc.index_command));
780 latexIndexCO->setCurrentIndex(0);
781 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
784 if (rc.fontenc == "default") {
785 latexEncodingCB->setChecked(false);
786 latexEncodingED->setEnabled(false);
788 latexEncodingCB->setChecked(true);
789 latexEncodingED->setEnabled(true);
790 latexEncodingED->setText(toqstr(rc.fontenc));
792 latexChecktexED->setText(toqstr(rc.chktex_command));
793 latexJBibtexED->setText(toqstr(rc.jbibtex_command));
794 latexJIndexED->setText(toqstr(rc.jindex_command));
795 latexNomenclED->setText(toqstr(rc.nomencl_command));
796 latexAutoresetCB->setChecked(rc.auto_reset_options);
797 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
798 latexPaperSizeCO->setCurrentIndex(
799 form_->fromPaperSize(rc.default_papersize));
800 #if defined(__CYGWIN__) || defined(_WIN32)
801 pathCB->setChecked(rc.windows_style_tex_paths);
806 /////////////////////////////////////////////////////////////////////
810 /////////////////////////////////////////////////////////////////////
812 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form)
813 : PrefModule(qt_(catLookAndFeel), qt_("Screen fonts"), form)
817 connect(screenRomanCO, SIGNAL(activated(QString)),
818 this, SLOT(selectRoman(QString)));
819 connect(screenSansCO, SIGNAL(activated(QString)),
820 this, SLOT(selectSans(QString)));
821 connect(screenTypewriterCO, SIGNAL(activated(QString)),
822 this, SLOT(selectTypewriter(QString)));
824 QFontDatabase fontdb;
825 QStringList families(fontdb.families());
826 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
827 screenRomanCO->addItem(*it);
828 screenSansCO->addItem(*it);
829 screenTypewriterCO->addItem(*it);
831 connect(screenRomanCO, SIGNAL(activated(QString)),
832 this, SIGNAL(changed()));
833 connect(screenSansCO, SIGNAL(activated(QString)),
834 this, SIGNAL(changed()));
835 connect(screenTypewriterCO, SIGNAL(activated(QString)),
836 this, SIGNAL(changed()));
837 connect(screenZoomSB, SIGNAL(valueChanged(int)),
838 this, SIGNAL(changed()));
839 connect(screenDpiSB, SIGNAL(valueChanged(int)),
840 this, SIGNAL(changed()));
841 connect(screenTinyED, SIGNAL(textChanged(QString)),
842 this, SIGNAL(changed()));
843 connect(screenSmallestED, SIGNAL(textChanged(QString)),
844 this, SIGNAL(changed()));
845 connect(screenSmallerED, SIGNAL(textChanged(QString)),
846 this, SIGNAL(changed()));
847 connect(screenSmallED, SIGNAL(textChanged(QString)),
848 this, SIGNAL(changed()));
849 connect(screenNormalED, SIGNAL(textChanged(QString)),
850 this, SIGNAL(changed()));
851 connect(screenLargeED, SIGNAL(textChanged(QString)),
852 this, SIGNAL(changed()));
853 connect(screenLargerED, SIGNAL(textChanged(QString)),
854 this, SIGNAL(changed()));
855 connect(screenLargestED, SIGNAL(textChanged(QString)),
856 this, SIGNAL(changed()));
857 connect(screenHugeED, SIGNAL(textChanged(QString)),
858 this, SIGNAL(changed()));
859 connect(screenHugerED, SIGNAL(textChanged(QString)),
860 this, SIGNAL(changed()));
861 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
862 this, SIGNAL(changed()));
864 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
865 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
866 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
867 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
868 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
869 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
870 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
871 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
872 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
873 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
877 void PrefScreenFonts::apply(LyXRC & rc) const
879 LyXRC const oldrc = rc;
881 parseFontName(screenRomanCO->currentText(),
882 rc.roman_font_name, rc.roman_font_foundry);
883 parseFontName(screenSansCO->currentText(),
884 rc.sans_font_name, rc.sans_font_foundry);
885 parseFontName(screenTypewriterCO->currentText(),
886 rc.typewriter_font_name, rc.typewriter_font_foundry);
888 rc.zoom = screenZoomSB->value();
889 rc.dpi = screenDpiSB->value();
890 rc.font_sizes[FONT_SIZE_TINY] = widgetToDoubleStr(screenTinyED);
891 rc.font_sizes[FONT_SIZE_SCRIPT] = widgetToDoubleStr(screenSmallestED);
892 rc.font_sizes[FONT_SIZE_FOOTNOTE] = widgetToDoubleStr(screenSmallerED);
893 rc.font_sizes[FONT_SIZE_SMALL] = widgetToDoubleStr(screenSmallED);
894 rc.font_sizes[FONT_SIZE_NORMAL] = widgetToDoubleStr(screenNormalED);
895 rc.font_sizes[FONT_SIZE_LARGE] = widgetToDoubleStr(screenLargeED);
896 rc.font_sizes[FONT_SIZE_LARGER] = widgetToDoubleStr(screenLargerED);
897 rc.font_sizes[FONT_SIZE_LARGEST] = widgetToDoubleStr(screenLargestED);
898 rc.font_sizes[FONT_SIZE_HUGE] = widgetToDoubleStr(screenHugeED);
899 rc.font_sizes[FONT_SIZE_HUGER] = widgetToDoubleStr(screenHugerED);
900 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
902 if (rc.font_sizes != oldrc.font_sizes
903 || rc.roman_font_name != oldrc.roman_font_name
904 || rc.sans_font_name != oldrc.sans_font_name
905 || rc.typewriter_font_name != oldrc.typewriter_font_name
906 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
907 // The global QPixmapCache is used in GuiPainter to cache text
908 // painting so we must reset it in case any of the above
909 // parameter is changed.
910 QPixmapCache::clear();
911 guiApp->fontLoader().update();
912 form_->updateScreenFonts();
917 void PrefScreenFonts::update(LyXRC const & rc)
919 setComboxFont(screenRomanCO, rc.roman_font_name,
920 rc.roman_font_foundry);
921 setComboxFont(screenSansCO, rc.sans_font_name,
922 rc.sans_font_foundry);
923 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
924 rc.typewriter_font_foundry);
926 selectRoman(screenRomanCO->currentText());
927 selectSans(screenSansCO->currentText());
928 selectTypewriter(screenTypewriterCO->currentText());
930 screenZoomSB->setValue(rc.zoom);
931 screenDpiSB->setValue(rc.dpi);
932 doubleToWidget(screenTinyED, rc.font_sizes[FONT_SIZE_TINY]);
933 doubleToWidget(screenSmallestED, rc.font_sizes[FONT_SIZE_SCRIPT]);
934 doubleToWidget(screenSmallerED, rc.font_sizes[FONT_SIZE_FOOTNOTE]);
935 doubleToWidget(screenSmallED, rc.font_sizes[FONT_SIZE_SMALL]);
936 doubleToWidget(screenNormalED, rc.font_sizes[FONT_SIZE_NORMAL]);
937 doubleToWidget(screenLargeED, rc.font_sizes[FONT_SIZE_LARGE]);
938 doubleToWidget(screenLargerED, rc.font_sizes[FONT_SIZE_LARGER]);
939 doubleToWidget(screenLargestED, rc.font_sizes[FONT_SIZE_LARGEST]);
940 doubleToWidget(screenHugeED, rc.font_sizes[FONT_SIZE_HUGE]);
941 doubleToWidget(screenHugerED, rc.font_sizes[FONT_SIZE_HUGER]);
943 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
944 #if defined(Q_WS_X11)
945 pixmapCacheCB->setEnabled(false);
951 void PrefScreenFonts::selectRoman(const QString & name)
953 screenRomanFE->set(QFont(name), name);
957 void PrefScreenFonts::selectSans(const QString & name)
959 screenSansFE->set(QFont(name), name);
963 void PrefScreenFonts::selectTypewriter(const QString & name)
965 screenTypewriterFE->set(QFont(name), name);
969 /////////////////////////////////////////////////////////////////////
973 /////////////////////////////////////////////////////////////////////
979 bool operator()(ColorCode lhs, ColorCode rhs) const {
981 compare_no_case(lcolor.getGUIName(lhs), lcolor.getGUIName(rhs)) < 0;
987 PrefColors::PrefColors(GuiPreferences * form)
988 : PrefModule(qt_(catLookAndFeel), qt_("Colors"), form)
992 // FIXME: all of this initialization should be put into the controller.
993 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
994 // for some discussion of why that is not trivial.
995 QPixmap icon(32, 32);
996 for (int i = 0; i < Color_ignore; ++i) {
997 ColorCode lc = static_cast<ColorCode>(i);
1000 || lc == Color_white
1002 || lc == Color_green
1005 || lc == Color_magenta
1006 || lc == Color_yellow
1007 || lc == Color_inherit
1008 || lc == Color_ignore) continue;
1010 lcolors_.push_back(lc);
1012 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
1013 vector<ColorCode>::const_iterator cit = lcolors_.begin();
1014 vector<ColorCode>::const_iterator const end = lcolors_.end();
1015 for (; cit != end; ++cit) {
1016 (void) new QListWidgetItem(QIcon(icon),
1017 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
1019 curcolors_.resize(lcolors_.size());
1020 newcolors_.resize(lcolors_.size());
1021 // End initialization
1023 connect(colorChangePB, SIGNAL(clicked()),
1024 this, SLOT(changeColor()));
1025 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
1026 this, SLOT(changeLyxObjectsSelection()));
1027 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
1028 this, SLOT(changeColor()));
1032 void PrefColors::apply(LyXRC & /*rc*/) const
1034 for (unsigned int i = 0; i < lcolors_.size(); ++i)
1035 if (curcolors_[i] != newcolors_[i])
1036 form_->setColor(lcolors_[i], newcolors_[i]);
1040 void PrefColors::update(LyXRC const & /*rc*/)
1042 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
1043 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
1044 QPixmap coloritem(32, 32);
1045 coloritem.fill(color);
1046 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
1047 newcolors_[i] = curcolors_[i] = color.name();
1049 changeLyxObjectsSelection();
1053 void PrefColors::changeColor()
1055 int const row = lyxObjectsLW->currentRow();
1061 QString const color = newcolors_[row];
1062 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
1064 if (c.isValid() && c.name() != color) {
1065 newcolors_[row] = c.name();
1066 QPixmap coloritem(32, 32);
1068 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
1074 void PrefColors::changeLyxObjectsSelection()
1076 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
1080 /////////////////////////////////////////////////////////////////////
1084 /////////////////////////////////////////////////////////////////////
1086 PrefDisplay::PrefDisplay(GuiPreferences * form)
1087 : PrefModule(qt_(catLookAndFeel), qt_("Display"), form)
1090 connect(displayGraphicsCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
1091 connect(instantPreviewCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
1092 connect(previewSizeSB, SIGNAL(valueChanged(double)), this, SIGNAL(changed()));
1093 connect(paragraphMarkerCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
1094 if (instantPreviewCO->currentIndex() == 0)
1095 previewSizeSB->setEnabled(false);
1097 previewSizeSB->setEnabled(true);
1101 void PrefDisplay::on_instantPreviewCO_currentIndexChanged(int index)
1104 previewSizeSB->setEnabled(false);
1106 previewSizeSB->setEnabled(true);
1110 void PrefDisplay::apply(LyXRC & rc) const
1112 switch (instantPreviewCO->currentIndex()) {
1113 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
1114 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
1115 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
1118 rc.display_graphics = displayGraphicsCB->isChecked();
1119 rc.preview_scale_factor = previewSizeSB->value();
1120 rc.paragraph_markers = paragraphMarkerCB->isChecked();
1122 // FIXME!! The graphics cache no longer has a changeDisplay method.
1124 if (old_value != rc.display_graphics) {
1125 graphics::GCache & gc = graphics::GCache::get();
1132 void PrefDisplay::update(LyXRC const & rc)
1134 switch (rc.preview) {
1135 case LyXRC::PREVIEW_OFF:
1136 instantPreviewCO->setCurrentIndex(0);
1138 case LyXRC::PREVIEW_NO_MATH :
1139 instantPreviewCO->setCurrentIndex(1);
1141 case LyXRC::PREVIEW_ON :
1142 instantPreviewCO->setCurrentIndex(2);
1146 displayGraphicsCB->setChecked(rc.display_graphics);
1147 instantPreviewCO->setEnabled(rc.display_graphics);
1148 previewSizeSB->setValue(rc.preview_scale_factor);
1149 paragraphMarkerCB->setChecked(rc.paragraph_markers);
1153 /////////////////////////////////////////////////////////////////////
1157 /////////////////////////////////////////////////////////////////////
1159 PrefPaths::PrefPaths(GuiPreferences * form)
1160 : PrefModule(QString(), qt_("Paths"), form)
1164 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(selectWorkingdir()));
1165 connect(workingDirED, SIGNAL(textChanged(QString)),
1166 this, SIGNAL(changed()));
1168 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(selectTemplatedir()));
1169 connect(templateDirED, SIGNAL(textChanged(QString)),
1170 this, SIGNAL(changed()));
1172 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(selectExampledir()));
1173 connect(exampleDirED, SIGNAL(textChanged(QString)),
1174 this, SIGNAL(changed()));
1176 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(selectBackupdir()));
1177 connect(backupDirED, SIGNAL(textChanged(QString)),
1178 this, SIGNAL(changed()));
1180 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(selectLyxPipe()));
1181 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
1182 this, SIGNAL(changed()));
1184 connect(thesaurusDirPB, SIGNAL(clicked()), this, SLOT(selectThesaurusdir()));
1185 connect(thesaurusDirED, SIGNAL(textChanged(QString)),
1186 this, SIGNAL(changed()));
1188 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(selectTempdir()));
1189 connect(tempDirED, SIGNAL(textChanged(QString)),
1190 this, SIGNAL(changed()));
1192 connect(hunspellDirPB, SIGNAL(clicked()), this, SLOT(selectHunspelldir()));
1193 connect(hunspellDirED, SIGNAL(textChanged(QString)),
1194 this, SIGNAL(changed()));
1196 connect(pathPrefixED, SIGNAL(textChanged(QString)),
1197 this, SIGNAL(changed()));
1201 void PrefPaths::apply(LyXRC & rc) const
1203 rc.document_path = internal_path(fromqstr(workingDirED->text()));
1204 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
1205 rc.template_path = internal_path(fromqstr(templateDirED->text()));
1206 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
1207 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
1208 rc.thesaurusdir_path = internal_path(fromqstr(thesaurusDirED->text()));
1209 rc.hunspelldir_path = internal_path(fromqstr(hunspellDirED->text()));
1210 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
1211 // FIXME: should be a checkbox only
1212 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
1216 void PrefPaths::update(LyXRC const & rc)
1218 workingDirED->setText(toqstr(external_path(rc.document_path)));
1219 exampleDirED->setText(toqstr(external_path(rc.example_path)));
1220 templateDirED->setText(toqstr(external_path(rc.template_path)));
1221 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
1222 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
1223 thesaurusDirED->setText(toqstr(external_path(rc.thesaurusdir_path)));
1224 hunspellDirED->setText(toqstr(external_path(rc.hunspelldir_path)));
1225 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
1226 // FIXME: should be a checkbox only
1227 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
1231 void PrefPaths::selectExampledir()
1233 QString file = browseDir(internalPath(exampleDirED->text()),
1234 qt_("Select directory for example files"));
1235 if (!file.isEmpty())
1236 exampleDirED->setText(file);
1240 void PrefPaths::selectTemplatedir()
1242 QString file = browseDir(internalPath(templateDirED->text()),
1243 qt_("Select a document templates directory"));
1244 if (!file.isEmpty())
1245 templateDirED->setText(file);
1249 void PrefPaths::selectTempdir()
1251 QString file = browseDir(internalPath(tempDirED->text()),
1252 qt_("Select a temporary directory"));
1253 if (!file.isEmpty())
1254 tempDirED->setText(file);
1258 void PrefPaths::selectBackupdir()
1260 QString file = browseDir(internalPath(backupDirED->text()),
1261 qt_("Select a backups directory"));
1262 if (!file.isEmpty())
1263 backupDirED->setText(file);
1267 void PrefPaths::selectWorkingdir()
1269 QString file = browseDir(internalPath(workingDirED->text()),
1270 qt_("Select a document directory"));
1271 if (!file.isEmpty())
1272 workingDirED->setText(file);
1276 void PrefPaths::selectThesaurusdir()
1278 QString file = browseDir(internalPath(thesaurusDirED->text()),
1279 qt_("Set the path to the thesaurus dictionaries"));
1280 if (!file.isEmpty())
1281 thesaurusDirED->setText(file);
1285 void PrefPaths::selectHunspelldir()
1287 QString file = browseDir(internalPath(hunspellDirED->text()),
1288 qt_("Set the path to the Hunspell dictionaries"));
1289 if (!file.isEmpty())
1290 hunspellDirED->setText(file);
1294 void PrefPaths::selectLyxPipe()
1296 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1297 qt_("Give a filename for the LyX server pipe"));
1298 if (!file.isEmpty())
1299 lyxserverDirED->setText(file);
1303 /////////////////////////////////////////////////////////////////////
1307 /////////////////////////////////////////////////////////////////////
1309 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form)
1310 : PrefModule(qt_(catLanguage), qt_("Spellchecker"), form)
1314 #if defined(USE_ASPELL)
1315 spellcheckerCB->addItem(qt_("aspell"), QString("aspell"));
1317 #if defined(USE_ENCHANT)
1318 spellcheckerCB->addItem(qt_("enchant"), QString("enchant"));
1320 #if defined(USE_HUNSPELL)
1321 spellcheckerCB->addItem(qt_("hunspell"), QString("hunspell"));
1324 if (theSpellChecker()) {
1325 connect(spellcheckerCB, SIGNAL(currentIndexChanged(int)),
1326 this, SIGNAL(changed()));
1327 connect(altLanguageED, SIGNAL(textChanged(QString)),
1328 this, SIGNAL(changed()));
1329 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1330 this, SIGNAL(changed()));
1331 connect(compoundWordCB, SIGNAL(clicked()),
1332 this, SIGNAL(changed()));
1333 connect(spellcheckContinuouslyCB, SIGNAL(clicked()),
1334 this, SIGNAL(changed()));
1336 spellcheckerCB->setEnabled(false);
1337 altLanguageED->setEnabled(false);
1338 escapeCharactersED->setEnabled(false);
1339 compoundWordCB->setEnabled(false);
1340 spellcheckContinuouslyCB->setEnabled(false);
1345 void PrefSpellchecker::apply(LyXRC & rc) const
1347 rc.spellchecker = fromqstr(spellcheckerCB->itemData(
1348 spellcheckerCB->currentIndex()).toString());
1349 rc.spellchecker_alt_lang = fromqstr(altLanguageED->text());
1350 rc.spellchecker_esc_chars = fromqstr(escapeCharactersED->text());
1351 rc.spellchecker_accept_compound = compoundWordCB->isChecked();
1352 rc.spellcheck_continuously = spellcheckContinuouslyCB->isChecked();
1356 void PrefSpellchecker::update(LyXRC const & rc)
1358 spellcheckerCB->setCurrentIndex(
1359 spellcheckerCB->findData(toqstr(rc.spellchecker)));
1360 altLanguageED->setText(toqstr(rc.spellchecker_alt_lang));
1361 escapeCharactersED->setText(toqstr(rc.spellchecker_esc_chars));
1362 compoundWordCB->setChecked(rc.spellchecker_accept_compound);
1363 spellcheckContinuouslyCB->setChecked(rc.spellcheck_continuously);
1368 /////////////////////////////////////////////////////////////////////
1372 /////////////////////////////////////////////////////////////////////
1375 PrefConverters::PrefConverters(GuiPreferences * form)
1376 : PrefModule(qt_(catFiles), qt_("Converters"), form)
1380 connect(converterNewPB, SIGNAL(clicked()),
1381 this, SLOT(updateConverter()));
1382 connect(converterRemovePB, SIGNAL(clicked()),
1383 this, SLOT(removeConverter()));
1384 connect(converterModifyPB, SIGNAL(clicked()),
1385 this, SLOT(updateConverter()));
1386 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1387 this, SLOT(switchConverter()));
1388 connect(converterFromCO, SIGNAL(activated(QString)),
1389 this, SLOT(changeConverter()));
1390 connect(converterToCO, SIGNAL(activated(QString)),
1391 this, SLOT(changeConverter()));
1392 connect(converterED, SIGNAL(textEdited(QString)),
1393 this, SLOT(changeConverter()));
1394 connect(converterFlagED, SIGNAL(textEdited(QString)),
1395 this, SLOT(changeConverter()));
1396 connect(converterNewPB, SIGNAL(clicked()),
1397 this, SIGNAL(changed()));
1398 connect(converterRemovePB, SIGNAL(clicked()),
1399 this, SIGNAL(changed()));
1400 connect(converterModifyPB, SIGNAL(clicked()),
1401 this, SIGNAL(changed()));
1402 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1403 this, SIGNAL(changed()));
1405 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1406 //converterDefGB->setFocusProxy(convertersLW);
1410 void PrefConverters::apply(LyXRC & rc) const
1412 rc.use_converter_cache = cacheCB->isChecked();
1413 rc.converter_cache_maxage = int(widgetToDouble(maxAgeLE) * 86400.0);
1417 void PrefConverters::update(LyXRC const & rc)
1419 cacheCB->setChecked(rc.use_converter_cache);
1421 doubleToWidget(maxAgeLE, (double(rc.converter_cache_maxage) / 86400.0), 'g', 6);
1426 void PrefConverters::updateGui()
1428 form_->formats().sort();
1429 form_->converters().update(form_->formats());
1430 // save current selection
1431 QString current = converterFromCO->currentText()
1432 + " -> " + converterToCO->currentText();
1434 converterFromCO->clear();
1435 converterToCO->clear();
1437 Formats::const_iterator cit = form_->formats().begin();
1438 Formats::const_iterator end = form_->formats().end();
1439 for (; cit != end; ++cit) {
1440 converterFromCO->addItem(qt_(cit->prettyname()));
1441 converterToCO->addItem(qt_(cit->prettyname()));
1444 // currentRowChanged(int) is also triggered when updating the listwidget
1445 // block signals to avoid unnecessary calls to switchConverter()
1446 convertersLW->blockSignals(true);
1447 convertersLW->clear();
1449 Converters::const_iterator ccit = form_->converters().begin();
1450 Converters::const_iterator cend = form_->converters().end();
1451 for (; ccit != cend; ++ccit) {
1452 QString const name =
1453 qt_(ccit->From->prettyname()) + " -> " + qt_(ccit->To->prettyname());
1454 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1455 new QListWidgetItem(name, convertersLW, type);
1457 convertersLW->sortItems(Qt::AscendingOrder);
1458 convertersLW->blockSignals(false);
1460 // restore selection
1461 if (!current.isEmpty()) {
1462 QList<QListWidgetItem *> const item =
1463 convertersLW->findItems(current, Qt::MatchExactly);
1464 if (!item.isEmpty())
1465 convertersLW->setCurrentItem(item.at(0));
1468 // select first element if restoring failed
1469 if (convertersLW->currentRow() == -1)
1470 convertersLW->setCurrentRow(0);
1476 void PrefConverters::switchConverter()
1478 int const cnr = convertersLW->currentItem()->type();
1479 Converter const & c(form_->converters().get(cnr));
1480 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1481 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1482 converterED->setText(toqstr(c.command));
1483 converterFlagED->setText(toqstr(c.flags));
1489 void PrefConverters::changeConverter()
1495 void PrefConverters::updateButtons()
1497 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1498 Format const & to = form_->formats().get(converterToCO->currentIndex());
1499 int const sel = form_->converters().getNumber(from.name(), to.name());
1500 bool const known = sel >= 0;
1501 bool const valid = !(converterED->text().isEmpty()
1502 || from.name() == to.name());
1504 int const cnr = convertersLW->currentItem()->type();
1505 Converter const & c = form_->converters().get(cnr);
1506 string const old_command = c.command;
1507 string const old_flag = c.flags;
1508 string const new_command = fromqstr(converterED->text());
1509 string const new_flag = fromqstr(converterFlagED->text());
1511 bool modified = (old_command != new_command || old_flag != new_flag);
1513 converterModifyPB->setEnabled(valid && known && modified);
1514 converterNewPB->setEnabled(valid && !known);
1515 converterRemovePB->setEnabled(known);
1517 maxAgeLE->setEnabled(cacheCB->isChecked());
1518 maxAgeLA->setEnabled(cacheCB->isChecked());
1523 // specify unique from/to or it doesn't appear. This is really bad UI
1524 // this is why we can use the same function for both new and modify
1525 void PrefConverters::updateConverter()
1527 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1528 Format const & to = form_->formats().get(converterToCO->currentIndex());
1529 string const flags = fromqstr(converterFlagED->text());
1530 string const command = fromqstr(converterED->text());
1532 Converter const * old =
1533 form_->converters().getConverter(from.name(), to.name());
1534 form_->converters().add(from.name(), to.name(), command, flags);
1537 form_->converters().updateLast(form_->formats());
1541 // Remove all files created by this converter from the cache, since
1542 // the modified converter might create different files.
1543 ConverterCache::get().remove_all(from.name(), to.name());
1547 void PrefConverters::removeConverter()
1549 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1550 Format const & to = form_->formats().get(converterToCO->currentIndex());
1551 form_->converters().erase(from.name(), to.name());
1555 // Remove all files created by this converter from the cache, since
1556 // a possible new converter might create different files.
1557 ConverterCache::get().remove_all(from.name(), to.name());
1561 void PrefConverters::on_cacheCB_stateChanged(int state)
1563 maxAgeLE->setEnabled(state == Qt::Checked);
1564 maxAgeLA->setEnabled(state == Qt::Checked);
1569 /////////////////////////////////////////////////////////////////////
1573 /////////////////////////////////////////////////////////////////////
1575 class FormatValidator : public QValidator
1578 FormatValidator(QWidget *, Formats const & f);
1579 void fixup(QString & input) const;
1580 QValidator::State validate(QString & input, int & pos) const;
1582 virtual QString toString(Format const & format) const = 0;
1584 Formats const & formats_;
1588 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1589 : QValidator(parent), formats_(f)
1594 void FormatValidator::fixup(QString & input) const
1596 Formats::const_iterator cit = formats_.begin();
1597 Formats::const_iterator end = formats_.end();
1598 for (; cit != end; ++cit) {
1599 QString const name = toString(*cit);
1600 if (distance(formats_.begin(), cit) == nr()) {
1608 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1610 Formats::const_iterator cit = formats_.begin();
1611 Formats::const_iterator end = formats_.end();
1612 bool unknown = true;
1613 for (; unknown && cit != end; ++cit) {
1614 QString const name = toString(*cit);
1615 if (distance(formats_.begin(), cit) != nr())
1616 unknown = name != input;
1619 if (unknown && !input.isEmpty())
1620 return QValidator::Acceptable;
1622 return QValidator::Intermediate;
1626 int FormatValidator::nr() const
1628 QComboBox * p = qobject_cast<QComboBox *>(parent());
1629 return p->itemData(p->currentIndex()).toInt();
1633 /////////////////////////////////////////////////////////////////////
1635 // FormatNameValidator
1637 /////////////////////////////////////////////////////////////////////
1639 class FormatNameValidator : public FormatValidator
1642 FormatNameValidator(QWidget * parent, Formats const & f)
1643 : FormatValidator(parent, f)
1646 QString toString(Format const & format) const
1648 return toqstr(format.name());
1653 /////////////////////////////////////////////////////////////////////
1655 // FormatPrettynameValidator
1657 /////////////////////////////////////////////////////////////////////
1659 class FormatPrettynameValidator : public FormatValidator
1662 FormatPrettynameValidator(QWidget * parent, Formats const & f)
1663 : FormatValidator(parent, f)
1666 QString toString(Format const & format) const
1668 return qt_(format.prettyname());
1673 /////////////////////////////////////////////////////////////////////
1677 /////////////////////////////////////////////////////////////////////
1679 PrefFileformats::PrefFileformats(GuiPreferences * form)
1680 : PrefModule(qt_(catFiles), qt_("File formats"), form)
1683 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1684 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1686 connect(documentCB, SIGNAL(clicked()),
1687 this, SLOT(setFlags()));
1688 connect(vectorCB, SIGNAL(clicked()),
1689 this, SLOT(setFlags()));
1690 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1691 this, SLOT(updatePrettyname()));
1692 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1693 this, SIGNAL(changed()));
1694 connect(defaultFormatCB, SIGNAL(activated(QString)),
1695 this, SIGNAL(changed()));
1696 connect(viewerCO, SIGNAL(activated(int)),
1697 this, SIGNAL(changed()));
1698 connect(editorCO, SIGNAL(activated(int)),
1699 this, SIGNAL(changed()));
1705 string const l10n_shortcut(string const prettyname, string const shortcut)
1707 if (shortcut.empty())
1710 string l10n_format =
1711 to_utf8(_(prettyname + '|' + shortcut));
1712 return split(l10n_format, '|');
1715 }; // namespace anon
1718 void PrefFileformats::apply(LyXRC & rc) const
1720 QString const default_format = defaultFormatCB->itemData(
1721 defaultFormatCB->currentIndex()).toString();
1722 rc.default_view_format = fromqstr(default_format);
1726 void PrefFileformats::update(LyXRC const & rc)
1728 viewer_alternatives = rc.viewer_alternatives;
1729 editor_alternatives = rc.editor_alternatives;
1730 bool const init = defaultFormatCB->currentText().isEmpty();
1734 defaultFormatCB->findData(toqstr(rc.default_view_format));
1735 defaultFormatCB->setCurrentIndex(pos);
1740 void PrefFileformats::updateView()
1742 QString const current = formatsCB->currentText();
1743 QString const current_def = defaultFormatCB->currentText();
1745 // update comboboxes with formats
1746 formatsCB->blockSignals(true);
1747 defaultFormatCB->blockSignals(true);
1749 defaultFormatCB->clear();
1750 form_->formats().sort();
1751 Formats::const_iterator cit = form_->formats().begin();
1752 Formats::const_iterator end = form_->formats().end();
1753 for (; cit != end; ++cit) {
1754 formatsCB->addItem(qt_(cit->prettyname()),
1755 QVariant(form_->formats().getNumber(cit->name())));
1756 if (form_->converters().isReachable("latex", cit->name())
1757 || form_->converters().isReachable("pdflatex", cit->name()))
1758 defaultFormatCB->addItem(qt_(cit->prettyname()),
1759 QVariant(toqstr(cit->name())));
1762 // restore selection
1763 int item = formatsCB->findText(current, Qt::MatchExactly);
1764 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1765 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1766 item = defaultFormatCB->findText(current_def, Qt::MatchExactly);
1767 defaultFormatCB->setCurrentIndex(item < 0 ? 0 : item);
1768 formatsCB->blockSignals(false);
1769 defaultFormatCB->blockSignals(false);
1773 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1775 int const nr = formatsCB->itemData(i).toInt();
1776 Format const f = form_->formats().get(nr);
1778 formatED->setText(toqstr(f.name()));
1779 copierED->setText(toqstr(form_->movers().command(f.name())));
1780 extensionED->setText(toqstr(f.extension()));
1781 shortcutED->setText(
1782 toqstr(l10n_shortcut(f.prettyname(), f.shortcut())));
1783 documentCB->setChecked((f.documentFormat()));
1784 vectorCB->setChecked((f.vectorFormat()));
1790 void PrefFileformats::setFlags()
1792 int flags = Format::none;
1793 if (documentCB->isChecked())
1794 flags |= Format::document;
1795 if (vectorCB->isChecked())
1796 flags |= Format::vector;
1797 currentFormat().setFlags(flags);
1802 void PrefFileformats::on_copierED_textEdited(const QString & s)
1804 string const fmt = fromqstr(formatED->text());
1805 form_->movers().set(fmt, fromqstr(s));
1810 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1812 currentFormat().setExtension(fromqstr(s));
1816 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1818 currentFormat().setViewer(fromqstr(s));
1823 void PrefFileformats::on_editorED_textEdited(const QString & s)
1825 currentFormat().setEditor(fromqstr(s));
1830 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1832 string const new_shortcut = fromqstr(s);
1833 if (new_shortcut == l10n_shortcut(currentFormat().prettyname(),
1834 currentFormat().shortcut()))
1836 currentFormat().setShortcut(new_shortcut);
1841 void PrefFileformats::on_formatED_editingFinished()
1843 string const newname = fromqstr(formatED->displayText());
1844 if (newname == currentFormat().name())
1847 currentFormat().setName(newname);
1852 void PrefFileformats::on_formatED_textChanged(const QString &)
1854 QString t = formatED->text();
1856 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1857 setValid(formatLA, valid);
1861 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1863 QString t = formatsCB->currentText();
1865 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1866 setValid(formatsLA, valid);
1870 void PrefFileformats::updatePrettyname()
1872 QString const newname = formatsCB->currentText();
1873 if (newname == qt_(currentFormat().prettyname()))
1876 currentFormat().setPrettyname(fromqstr(newname));
1884 void updateComboBox(LyXRC::Alternatives const & alts,
1885 string const & fmt, QComboBox * combo)
1887 LyXRC::Alternatives::const_iterator it =
1889 if (it != alts.end()) {
1890 LyXRC::CommandSet const & cmds = it->second;
1891 LyXRC::CommandSet::const_iterator sit =
1893 LyXRC::CommandSet::const_iterator const sen =
1895 for (; sit != sen; ++sit) {
1896 QString const qcmd = toqstr(*sit);
1897 combo->addItem(qcmd, qcmd);
1904 void PrefFileformats::updateViewers()
1906 Format const f = currentFormat();
1907 viewerCO->blockSignals(true);
1909 viewerCO->addItem(qt_("None"), QString());
1910 updateComboBox(viewer_alternatives, f.name(), viewerCO);
1911 viewerCO->addItem(qt_("Custom"), QString("custom viewer"));
1912 viewerCO->blockSignals(false);
1914 int pos = viewerCO->findData(toqstr(f.viewer()));
1917 viewerED->setEnabled(false);
1918 viewerCO->setCurrentIndex(pos);
1920 viewerED->setEnabled(true);
1921 viewerED->setText(toqstr(f.viewer()));
1922 viewerCO->setCurrentIndex(viewerCO->findData(toqstr("custom viewer")));
1927 void PrefFileformats::updateEditors()
1929 Format const f = currentFormat();
1930 editorCO->blockSignals(true);
1932 editorCO->addItem(qt_("None"), QString());
1933 updateComboBox(editor_alternatives, f.name(), editorCO);
1934 editorCO->addItem(qt_("Custom"), QString("custom editor"));
1935 editorCO->blockSignals(false);
1937 int pos = editorCO->findData(toqstr(f.editor()));
1940 editorED->setEnabled(false);
1941 editorCO->setCurrentIndex(pos);
1943 editorED->setEnabled(true);
1944 editorED->setText(toqstr(f.editor()));
1945 editorCO->setCurrentIndex(editorCO->findData(toqstr("custom editor")));
1950 void PrefFileformats::on_viewerCO_currentIndexChanged(int i)
1952 bool const custom = viewerCO->itemData(i).toString() == "custom viewer";
1953 viewerED->setEnabled(custom);
1955 currentFormat().setViewer(fromqstr(viewerCO->itemData(i).toString()));
1959 void PrefFileformats::on_editorCO_currentIndexChanged(int i)
1961 bool const custom = editorCO->itemData(i).toString() == "custom editor";
1962 editorED->setEnabled(custom);
1964 currentFormat().setEditor(fromqstr(editorCO->itemData(i).toString()));
1968 Format & PrefFileformats::currentFormat()
1970 int const i = formatsCB->currentIndex();
1971 int const nr = formatsCB->itemData(i).toInt();
1972 return form_->formats().get(nr);
1976 void PrefFileformats::on_formatNewPB_clicked()
1978 form_->formats().add("", "", "", "", "", "", Format::none);
1980 formatsCB->setCurrentIndex(0);
1981 formatsCB->setFocus(Qt::OtherFocusReason);
1985 void PrefFileformats::on_formatRemovePB_clicked()
1987 int const i = formatsCB->currentIndex();
1988 int const nr = formatsCB->itemData(i).toInt();
1989 string const current_text = form_->formats().get(nr).name();
1990 if (form_->converters().formatIsUsed(current_text)) {
1991 Alert::error(_("Format in use"),
1992 _("Cannot remove a Format used by a Converter. "
1993 "Remove the converter first."));
1997 form_->formats().erase(current_text);
2000 on_formatsCB_editTextChanged(formatsCB->currentText());
2005 /////////////////////////////////////////////////////////////////////
2009 /////////////////////////////////////////////////////////////////////
2011 PrefLanguage::PrefLanguage(GuiPreferences * form)
2012 : PrefModule(qt_(catLanguage), qt_("Language"), form)
2016 connect(rtlGB, SIGNAL(clicked()),
2017 this, SIGNAL(changed()));
2018 connect(visualCursorRB, SIGNAL(clicked()),
2019 this, SIGNAL(changed()));
2020 connect(logicalCursorRB, SIGNAL(clicked()),
2021 this, SIGNAL(changed()));
2022 connect(markForeignCB, SIGNAL(clicked()),
2023 this, SIGNAL(changed()));
2024 connect(autoBeginCB, SIGNAL(clicked()),
2025 this, SIGNAL(changed()));
2026 connect(autoEndCB, SIGNAL(clicked()),
2027 this, SIGNAL(changed()));
2028 connect(useBabelCB, SIGNAL(clicked()),
2029 this, SIGNAL(changed()));
2030 connect(globalCB, SIGNAL(clicked()),
2031 this, SIGNAL(changed()));
2032 connect(languagePackageED, SIGNAL(textChanged(QString)),
2033 this, SIGNAL(changed()));
2034 connect(startCommandED, SIGNAL(textChanged(QString)),
2035 this, SIGNAL(changed()));
2036 connect(endCommandED, SIGNAL(textChanged(QString)),
2037 this, SIGNAL(changed()));
2038 connect(uiLanguageCO, SIGNAL(activated(int)),
2039 this, SIGNAL(changed()));
2041 uiLanguageCO->clear();
2043 QAbstractItemModel * language_model = guiApp->languageModel();
2044 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
2045 language_model->sort(0);
2047 // FIXME: This is wrong, we need filter this list based on the available
2049 uiLanguageCO->blockSignals(true);
2050 uiLanguageCO->addItem(qt_("Default"), toqstr("auto"));
2051 for (int i = 0; i != language_model->rowCount(); ++i) {
2052 QModelIndex index = language_model->index(i, 0);
2053 uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
2054 index.data(Qt::UserRole).toString());
2056 uiLanguageCO->blockSignals(false);
2060 void PrefLanguage::on_uiLanguageCO_currentIndexChanged(int)
2062 QMessageBox::information(this, qt_("LyX needs to be restarted!"),
2063 qt_("The change of user interface language will be fully "
2064 "effective only after a restart."));
2068 void PrefLanguage::apply(LyXRC & rc) const
2070 // FIXME: remove rtl_support bool
2071 rc.rtl_support = rtlGB->isChecked();
2072 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
2073 rc.mark_foreign_language = markForeignCB->isChecked();
2074 rc.language_auto_begin = autoBeginCB->isChecked();
2075 rc.language_auto_end = autoEndCB->isChecked();
2076 rc.language_use_babel = useBabelCB->isChecked();
2077 rc.language_global_options = globalCB->isChecked();
2078 rc.language_package = fromqstr(languagePackageED->text());
2079 rc.language_command_begin = fromqstr(startCommandED->text());
2080 rc.language_command_end = fromqstr(endCommandED->text());
2081 rc.gui_language = fromqstr(
2082 uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString());
2086 void PrefLanguage::update(LyXRC const & rc)
2088 // FIXME: remove rtl_support bool
2089 rtlGB->setChecked(rc.rtl_support);
2090 if (rc.visual_cursor)
2091 visualCursorRB->setChecked(true);
2093 logicalCursorRB->setChecked(true);
2094 markForeignCB->setChecked(rc.mark_foreign_language);
2095 autoBeginCB->setChecked(rc.language_auto_begin);
2096 autoEndCB->setChecked(rc.language_auto_end);
2097 useBabelCB->setChecked(rc.language_use_babel);
2098 globalCB->setChecked(rc.language_global_options);
2099 languagePackageED->setText(toqstr(rc.language_package));
2100 startCommandED->setText(toqstr(rc.language_command_begin));
2101 endCommandED->setText(toqstr(rc.language_command_end));
2103 int pos = uiLanguageCO->findData(toqstr(rc.gui_language));
2104 uiLanguageCO->blockSignals(true);
2105 uiLanguageCO->setCurrentIndex(pos);
2106 uiLanguageCO->blockSignals(false);
2110 /////////////////////////////////////////////////////////////////////
2114 /////////////////////////////////////////////////////////////////////
2116 PrefPrinter::PrefPrinter(GuiPreferences * form)
2117 : PrefModule(qt_(catOutput), qt_("Printer"), form)
2121 connect(printerAdaptCB, SIGNAL(clicked()),
2122 this, SIGNAL(changed()));
2123 connect(printerCommandED, SIGNAL(textChanged(QString)),
2124 this, SIGNAL(changed()));
2125 connect(printerNameED, SIGNAL(textChanged(QString)),
2126 this, SIGNAL(changed()));
2127 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
2128 this, SIGNAL(changed()));
2129 connect(printerCopiesED, SIGNAL(textChanged(QString)),
2130 this, SIGNAL(changed()));
2131 connect(printerReverseED, SIGNAL(textChanged(QString)),
2132 this, SIGNAL(changed()));
2133 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
2134 this, SIGNAL(changed()));
2135 connect(printerExtensionED, SIGNAL(textChanged(QString)),
2136 this, SIGNAL(changed()));
2137 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
2138 this, SIGNAL(changed()));
2139 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
2140 this, SIGNAL(changed()));
2141 connect(printerEvenED, SIGNAL(textChanged(QString)),
2142 this, SIGNAL(changed()));
2143 connect(printerOddED, SIGNAL(textChanged(QString)),
2144 this, SIGNAL(changed()));
2145 connect(printerCollatedED, SIGNAL(textChanged(QString)),
2146 this, SIGNAL(changed()));
2147 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
2148 this, SIGNAL(changed()));
2149 connect(printerToFileED, SIGNAL(textChanged(QString)),
2150 this, SIGNAL(changed()));
2151 connect(printerExtraED, SIGNAL(textChanged(QString)),
2152 this, SIGNAL(changed()));
2153 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
2154 this, SIGNAL(changed()));
2155 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
2156 this, SIGNAL(changed()));
2160 void PrefPrinter::apply(LyXRC & rc) const
2162 rc.print_adapt_output = printerAdaptCB->isChecked();
2163 rc.print_command = fromqstr(printerCommandED->text());
2164 rc.printer = fromqstr(printerNameED->text());
2166 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
2167 rc.print_copies_flag = fromqstr(printerCopiesED->text());
2168 rc.print_reverse_flag = fromqstr(printerReverseED->text());
2169 rc.print_to_printer = fromqstr(printerToPrinterED->text());
2170 rc.print_file_extension = fromqstr(printerExtensionED->text());
2171 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
2172 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
2173 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
2174 rc.print_oddpage_flag = fromqstr(printerOddED->text());
2175 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
2176 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
2177 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
2178 rc.print_extra_options = fromqstr(printerExtraED->text());
2179 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
2180 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
2184 void PrefPrinter::update(LyXRC const & rc)
2186 printerAdaptCB->setChecked(rc.print_adapt_output);
2187 printerCommandED->setText(toqstr(rc.print_command));
2188 printerNameED->setText(toqstr(rc.printer));
2190 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
2191 printerCopiesED->setText(toqstr(rc.print_copies_flag));
2192 printerReverseED->setText(toqstr(rc.print_reverse_flag));
2193 printerToPrinterED->setText(toqstr(rc.print_to_printer));
2194 printerExtensionED->setText(toqstr(rc.print_file_extension));
2195 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
2196 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
2197 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
2198 printerOddED->setText(toqstr(rc.print_oddpage_flag));
2199 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
2200 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
2201 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
2202 printerExtraED->setText(toqstr(rc.print_extra_options));
2203 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
2204 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
2208 /////////////////////////////////////////////////////////////////////
2210 // PrefUserInterface
2212 /////////////////////////////////////////////////////////////////////
2214 PrefUserInterface::PrefUserInterface(GuiPreferences * form)
2215 : PrefModule(qt_(catLookAndFeel), qt_("User interface"), form)
2219 connect(autoSaveCB, SIGNAL(toggled(bool)),
2220 autoSaveSB, SLOT(setEnabled(bool)));
2221 connect(autoSaveCB, SIGNAL(toggled(bool)),
2222 TextLabel1, SLOT(setEnabled(bool)));
2223 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
2224 this, SIGNAL(changed()));
2225 #if QT_VERSION < 0x040500
2226 singleCloseTabButtonCB->setEnabled(false);
2228 connect(singleCloseTabButtonCB, SIGNAL(clicked()),
2229 this, SIGNAL(changed()));
2230 connect(uiFilePB, SIGNAL(clicked()),
2231 this, SLOT(selectUi()));
2232 connect(uiFileED, SIGNAL(textChanged(QString)),
2233 this, SIGNAL(changed()));
2234 connect(restoreCursorCB, SIGNAL(clicked()),
2235 this, SIGNAL(changed()));
2236 connect(loadSessionCB, SIGNAL(clicked()),
2237 this, SIGNAL(changed()));
2238 connect(allowGeometrySessionCB, SIGNAL(clicked()),
2239 this, SIGNAL(changed()));
2240 connect(autoSaveSB, SIGNAL(valueChanged(int)),
2241 this, SIGNAL(changed()));
2242 connect(autoSaveCB, SIGNAL(clicked()),
2243 this, SIGNAL(changed()));
2244 connect(backupCB, SIGNAL(clicked()),
2245 this, SIGNAL(changed()));
2246 connect(lastfilesSB, SIGNAL(valueChanged(int)),
2247 this, SIGNAL(changed()));
2248 connect(tooltipCB, SIGNAL(toggled(bool)),
2249 this, SIGNAL(changed()));
2250 lastfilesSB->setMaximum(maxlastfiles);
2254 void PrefUserInterface::apply(LyXRC & rc) const
2256 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
2257 rc.use_lastfilepos = restoreCursorCB->isChecked();
2258 rc.load_session = loadSessionCB->isChecked();
2259 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
2260 rc.autosave = autoSaveCB->isChecked()? autoSaveSB->value() * 60 : 0;
2261 rc.make_backup = backupCB->isChecked();
2262 rc.num_lastfiles = lastfilesSB->value();
2263 rc.use_tooltip = tooltipCB->isChecked();
2264 rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
2265 rc.single_close_tab_button = singleCloseTabButtonCB->isChecked();
2266 #if QT_VERSION < 0x040500
2267 rc.single_close_tab_button = true;
2272 void PrefUserInterface::update(LyXRC const & rc)
2274 uiFileED->setText(toqstr(external_path(rc.ui_file)));
2275 restoreCursorCB->setChecked(rc.use_lastfilepos);
2276 loadSessionCB->setChecked(rc.load_session);
2277 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
2278 // convert to minutes
2279 bool autosave = rc.autosave > 0;
2280 int mins = rc.autosave / 60;
2283 autoSaveSB->setValue(mins);
2284 autoSaveCB->setChecked(autosave);
2285 autoSaveSB->setEnabled(autosave);
2286 backupCB->setChecked(rc.make_backup);
2287 lastfilesSB->setValue(rc.num_lastfiles);
2288 tooltipCB->setChecked(rc.use_tooltip);
2289 openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
2290 singleCloseTabButtonCB->setChecked(rc.single_close_tab_button);
2294 void PrefUserInterface::selectUi()
2296 QString file = form_->browseUI(internalPath(uiFileED->text()));
2297 if (!file.isEmpty())
2298 uiFileED->setText(file);
2302 void PrefUserInterface::on_clearSessionPB_clicked()
2304 guiApp->clearSession();
2309 /////////////////////////////////////////////////////////////////////
2313 /////////////////////////////////////////////////////////////////////
2315 PrefEdit::PrefEdit(GuiPreferences * form)
2316 : PrefModule(qt_(catEditing), qt_("Control"), form)
2320 connect(cursorFollowsCB, SIGNAL(clicked()),
2321 this, SIGNAL(changed()));
2322 connect(scrollBelowCB, SIGNAL(clicked()),
2323 this, SIGNAL(changed()));
2324 connect(sortEnvironmentsCB, SIGNAL(clicked()),
2325 this, SIGNAL(changed()));
2326 connect(groupEnvironmentsCB, SIGNAL(clicked()),
2327 this, SIGNAL(changed()));
2328 connect(macroEditStyleCO, SIGNAL(activated(int)),
2329 this, SIGNAL(changed()));
2330 connect(fullscreenLimitGB, SIGNAL(clicked()),
2331 this, SIGNAL(changed()));
2332 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
2333 this, SIGNAL(changed()));
2334 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
2335 this, SIGNAL(changed()));
2336 connect(toggleMenubarCB, SIGNAL(toggled(bool)),
2337 this, SIGNAL(changed()));
2338 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
2339 this, SIGNAL(changed()));
2340 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
2341 this, SIGNAL(changed()));
2345 void PrefEdit::apply(LyXRC & rc) const
2347 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
2348 rc.scroll_below_document = scrollBelowCB->isChecked();
2349 rc.sort_layouts = sortEnvironmentsCB->isChecked();
2350 rc.group_layouts = groupEnvironmentsCB->isChecked();
2351 switch (macroEditStyleCO->currentIndex()) {
2352 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
2353 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
2354 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
2356 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
2357 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
2358 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
2359 rc.full_screen_menubar = toggleMenubarCB->isChecked();
2360 rc.full_screen_width = fullscreenWidthSB->value();
2361 rc.full_screen_limit = fullscreenLimitGB->isChecked();
2365 void PrefEdit::update(LyXRC const & rc)
2367 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
2368 scrollBelowCB->setChecked(rc.scroll_below_document);
2369 sortEnvironmentsCB->setChecked(rc.sort_layouts);
2370 groupEnvironmentsCB->setChecked(rc.group_layouts);
2371 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
2372 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
2373 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
2374 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
2375 toggleMenubarCB->setChecked(rc.full_screen_menubar);
2376 fullscreenWidthSB->setValue(rc.full_screen_width);
2377 fullscreenLimitGB->setChecked(rc.full_screen_limit);
2381 /////////////////////////////////////////////////////////////////////
2385 /////////////////////////////////////////////////////////////////////
2388 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
2390 Ui::shortcutUi::setupUi(this);
2391 QDialog::setModal(true);
2395 PrefShortcuts::PrefShortcuts(GuiPreferences * form)
2396 : PrefModule(qt_(catEditing), qt_("Shortcuts"), form)
2400 shortcutsTW->setColumnCount(2);
2401 shortcutsTW->headerItem()->setText(0, qt_("Function"));
2402 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
2403 shortcutsTW->setSortingEnabled(true);
2404 // Multi-selection can be annoying.
2405 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
2407 connect(bindFilePB, SIGNAL(clicked()),
2408 this, SLOT(selectBind()));
2409 connect(bindFileED, SIGNAL(textChanged(QString)),
2410 this, SIGNAL(changed()));
2411 connect(removePB, SIGNAL(clicked()),
2412 this, SIGNAL(changed()));
2414 shortcut_ = new GuiShortcutDialog(this);
2415 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
2416 shortcut_bc_.setOK(shortcut_->okPB);
2417 shortcut_bc_.setCancel(shortcut_->cancelPB);
2419 connect(shortcut_->okPB, SIGNAL(clicked()),
2420 shortcut_, SLOT(accept()));
2421 connect(shortcut_->okPB, SIGNAL(clicked()),
2422 this, SIGNAL(changed()));
2423 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2424 shortcut_, SLOT(reject()));
2425 connect(shortcut_->clearPB, SIGNAL(clicked()),
2426 this, SLOT(shortcutClearPressed()));
2427 connect(shortcut_->removePB, SIGNAL(clicked()),
2428 this, SLOT(shortcutRemovePressed()));
2429 connect(shortcut_->okPB, SIGNAL(clicked()),
2430 this, SLOT(shortcutOkPressed()));
2431 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2432 this, SLOT(shortcutCancelPressed()));
2436 void PrefShortcuts::apply(LyXRC & rc) const
2438 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
2439 // write user_bind and user_unbind to .lyx/bind/user.bind
2440 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
2441 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
2442 lyxerr << "LyX could not create the user bind directory '"
2443 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2446 if (!bind_dir.isDirWritable()) {
2447 lyxerr << "LyX could not write to the user bind directory '"
2448 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2451 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
2452 user_unbind_.write(user_bind_file.toFilesystemEncoding(), false, true);
2453 user_bind_.write(user_bind_file.toFilesystemEncoding(), true, false);
2454 // immediately apply the keybindings. Why this is not done before?
2455 // The good thing is that the menus are updated automatically.
2456 theTopLevelKeymap().clear();
2457 theTopLevelKeymap().read("site");
2458 theTopLevelKeymap().read(rc.bind_file, 0, KeyMap::Fallback);
2459 theTopLevelKeymap().read("user", 0, KeyMap::MissingOK);
2463 void PrefShortcuts::update(LyXRC const & rc)
2465 bindFileED->setText(toqstr(external_path(rc.bind_file)));
2467 system_bind_.clear();
2469 user_unbind_.clear();
2470 system_bind_.read("site");
2471 system_bind_.read(rc.bind_file);
2472 // \unbind in user.bind is added to user_unbind_
2473 user_bind_.read("user", &user_unbind_, KeyMap::MissingOK);
2474 updateShortcutsTW();
2478 void PrefShortcuts::updateShortcutsTW()
2480 shortcutsTW->clear();
2482 editItem_ = new QTreeWidgetItem(shortcutsTW);
2483 editItem_->setText(0, qt_("Cursor, Mouse and Editing functions"));
2484 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2486 mathItem_ = new QTreeWidgetItem(shortcutsTW);
2487 mathItem_->setText(0, qt_("Mathematical Symbols"));
2488 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2490 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2491 bufferItem_->setText(0, qt_("Document and Window"));
2492 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2494 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2495 layoutItem_->setText(0, qt_("Font, Layouts and Textclasses"));
2496 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2498 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2499 systemItem_->setText(0, qt_("System and Miscellaneous"));
2500 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2502 // listBindings(unbound=true) lists all bound and unbound lfuns
2503 // Items in this list is tagged by its source.
2504 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2506 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2508 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2509 KeyMap::UserUnbind);
2510 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2511 user_bindinglist.end());
2512 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2513 user_unbindinglist.end());
2515 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2516 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2517 for (; it != it_end; ++it)
2518 insertShortcutItem(it->request, it->sequence, KeyMap::ItemType(it->tag));
2520 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2521 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2522 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2523 modifyPB->setEnabled(!items.isEmpty());
2525 shortcutsTW->resizeColumnToContents(0);
2529 void PrefShortcuts::setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag)
2531 item->setData(0, Qt::UserRole, QVariant(tag));
2535 case KeyMap::System:
2537 case KeyMap::UserBind:
2540 case KeyMap::UserUnbind:
2541 font.setStrikeOut(true);
2543 // this item is not displayed now.
2544 case KeyMap::UserExtraUnbind:
2545 font.setStrikeOut(true);
2549 item->setFont(1, font);
2553 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2554 KeySequence const & seq, KeyMap::ItemType tag)
2556 FuncCode action = lfun.action;
2557 string const action_name = lyxaction.getActionName(action);
2558 QString const lfun_name = toqstr(from_utf8(action_name)
2559 + ' ' + lfun.argument());
2560 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2561 KeyMap::ItemType item_tag = tag;
2563 QTreeWidgetItem * newItem = 0;
2564 // for unbind items, try to find an existing item in the system bind list
2565 if (tag == KeyMap::UserUnbind) {
2566 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2567 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2568 for (int i = 0; i < items.size(); ++i) {
2569 if (items[i]->text(1) == shortcut)
2573 // if not found, this unbind item is KeyMap::UserExtraUnbind
2574 // Such an item is not displayed to avoid confusion (what is
2575 // unmatched removed?).
2577 item_tag = KeyMap::UserExtraUnbind;
2582 switch(lyxaction.getActionType(action)) {
2583 case LyXAction::Hidden:
2585 case LyXAction::Edit:
2586 newItem = new QTreeWidgetItem(editItem_);
2588 case LyXAction::Math:
2589 newItem = new QTreeWidgetItem(mathItem_);
2591 case LyXAction::Buffer:
2592 newItem = new QTreeWidgetItem(bufferItem_);
2594 case LyXAction::Layout:
2595 newItem = new QTreeWidgetItem(layoutItem_);
2597 case LyXAction::System:
2598 newItem = new QTreeWidgetItem(systemItem_);
2601 // this should not happen
2602 newItem = new QTreeWidgetItem(shortcutsTW);
2606 newItem->setText(0, lfun_name);
2607 newItem->setText(1, shortcut);
2608 // record BindFile representation to recover KeySequence when needed.
2609 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2610 setItemType(newItem, item_tag);
2615 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2617 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2618 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2619 modifyPB->setEnabled(!items.isEmpty());
2620 if (items.isEmpty())
2623 KeyMap::ItemType tag =
2624 static_cast<KeyMap::ItemType>(items[0]->data(0, Qt::UserRole).toInt());
2625 if (tag == KeyMap::UserUnbind)
2626 removePB->setText(qt_("Res&tore"));
2628 removePB->setText(qt_("Remo&ve"));
2632 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2638 void PrefShortcuts::modifyShortcut()
2640 QTreeWidgetItem * item = shortcutsTW->currentItem();
2641 if (item->flags() & Qt::ItemIsSelectable) {
2642 shortcut_->lfunLE->setText(item->text(0));
2643 save_lfun_ = item->text(0);
2644 shortcut_->shortcutWG->setText(item->text(1));
2646 seq.parse(fromqstr(item->data(1, Qt::UserRole).toString()));
2647 shortcut_->shortcutWG->setKeySequence(seq);
2648 shortcut_->shortcutWG->setFocus();
2654 void PrefShortcuts::removeShortcut()
2656 // it seems that only one item can be selected, but I am
2657 // removing all selected items anyway.
2658 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2659 for (int i = 0; i < items.size(); ++i) {
2660 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2661 string lfun = fromqstr(items[i]->text(0));
2662 FuncRequest func = lyxaction.lookupFunc(lfun);
2663 KeyMap::ItemType tag =
2664 static_cast<KeyMap::ItemType>(items[i]->data(0, Qt::UserRole).toInt());
2667 case KeyMap::System: {
2668 // for system bind, we do not touch the item
2669 // but add an user unbind item
2670 user_unbind_.bind(shortcut, func);
2671 setItemType(items[i], KeyMap::UserUnbind);
2672 removePB->setText(qt_("Res&tore"));
2675 case KeyMap::UserBind: {
2676 // for user_bind, we remove this bind
2677 QTreeWidgetItem * parent = items[i]->parent();
2678 int itemIdx = parent->indexOfChild(items[i]);
2679 parent->takeChild(itemIdx);
2681 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2683 shortcutsTW->scrollToItem(parent);
2684 user_bind_.unbind(shortcut, func);
2687 case KeyMap::UserUnbind: {
2688 // for user_unbind, we remove the unbind, and the item
2689 // become KeyMap::System again.
2690 user_unbind_.unbind(shortcut, func);
2691 setItemType(items[i], KeyMap::System);
2692 removePB->setText(qt_("Remo&ve"));
2695 case KeyMap::UserExtraUnbind: {
2696 // for user unbind that is not in system bind file,
2697 // remove this unbind file
2698 QTreeWidgetItem * parent = items[i]->parent();
2699 parent->takeChild(parent->indexOfChild(items[i]));
2700 user_unbind_.unbind(shortcut, func);
2707 void PrefShortcuts::selectBind()
2709 QString file = form_->browsebind(internalPath(bindFileED->text()));
2710 if (!file.isEmpty()) {
2711 bindFileED->setText(file);
2712 system_bind_ = KeyMap();
2713 system_bind_.read(fromqstr(file));
2714 updateShortcutsTW();
2719 void PrefShortcuts::on_modifyPB_pressed()
2725 void PrefShortcuts::on_newPB_pressed()
2727 shortcut_->lfunLE->clear();
2728 shortcut_->shortcutWG->reset();
2729 save_lfun_ = QString();
2734 void PrefShortcuts::on_removePB_pressed()
2740 void PrefShortcuts::on_searchLE_textEdited()
2742 if (searchLE->text().isEmpty()) {
2743 // show all hidden items
2744 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2746 shortcutsTW->setItemHidden(*it++, false);
2749 // search both columns
2750 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2751 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2752 matched += shortcutsTW->findItems(searchLE->text(),
2753 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2755 // hide everyone (to avoid searching in matched QList repeatedly
2756 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2758 shortcutsTW->setItemHidden(*it++, true);
2759 // show matched items
2760 for (int i = 0; i < matched.size(); ++i) {
2761 shortcutsTW->setItemHidden(matched[i], false);
2762 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2767 docstring makeCmdString(FuncRequest const & f)
2769 docstring actionStr = from_ascii(lyxaction.getActionName(f.action));
2770 if (!f.argument().empty())
2771 actionStr += " " + f.argument();
2776 void PrefShortcuts::shortcutOkPressed()
2778 QString const new_lfun = shortcut_->lfunLE->text();
2779 FuncRequest func = lyxaction.lookupFunc(fromqstr(new_lfun));
2781 if (func.action == LFUN_UNKNOWN_ACTION) {
2782 Alert::error(_("Failed to create shortcut"),
2783 _("Unknown or invalid LyX function"));
2787 KeySequence k = shortcut_->shortcutWG->getKeySequence();
2788 if (k.length() == 0) {
2789 Alert::error(_("Failed to create shortcut"),
2790 _("Invalid or empty key sequence"));
2794 // check to see if there's been any change
2795 FuncRequest oldBinding = system_bind_.getBinding(k);
2796 if (oldBinding.action == LFUN_UNKNOWN_ACTION)
2797 oldBinding = user_bind_.getBinding(k);
2798 if (oldBinding == func) {
2799 docstring const actionStr = makeCmdString(func);
2800 Alert::error(_("Failed to create shortcut"),
2801 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s"),
2802 k.print(KeySequence::ForGui), actionStr));
2806 // make sure this key isn't already bound---and, if so, not unbound
2807 FuncCode const unbind = user_unbind_.getBinding(k).action;
2808 if (oldBinding.action != LFUN_UNKNOWN_ACTION && unbind == LFUN_UNKNOWN_ACTION)
2810 // FIXME Perhaps we should offer to over-write the old shortcut?
2811 // If so, we'll need to remove it from our list, etc.
2812 docstring const actionStr = makeCmdString(oldBinding);
2813 Alert::error(_("Failed to create shortcut"),
2814 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s\n"
2815 "You need to remove that binding before creating a new one."),
2816 k.print(KeySequence::ForGui), actionStr));
2820 if (!save_lfun_.isEmpty() && new_lfun == save_lfun_)
2821 // real modification of the lfun's shortcut,
2822 // so remove the previous one
2825 QTreeWidgetItem * item = insertShortcutItem(func, k, KeyMap::UserBind);
2827 user_bind_.bind(&k, func);
2828 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2829 shortcutsTW->setItemExpanded(item->parent(), true);
2830 shortcutsTW->scrollToItem(item);
2832 Alert::error(_("Failed to create shortcut"),
2833 _("Can not insert shortcut to the list"));
2839 void PrefShortcuts::shortcutCancelPressed()
2841 shortcut_->shortcutWG->reset();
2845 void PrefShortcuts::shortcutClearPressed()
2847 shortcut_->shortcutWG->reset();
2851 void PrefShortcuts::shortcutRemovePressed()
2853 shortcut_->shortcutWG->removeFromSequence();
2857 /////////////////////////////////////////////////////////////////////
2861 /////////////////////////////////////////////////////////////////////
2863 PrefIdentity::PrefIdentity(GuiPreferences * form)
2864 : PrefModule(QString(), qt_("Identity"), form)
2868 connect(nameED, SIGNAL(textChanged(QString)),
2869 this, SIGNAL(changed()));
2870 connect(emailED, SIGNAL(textChanged(QString)),
2871 this, SIGNAL(changed()));
2875 void PrefIdentity::apply(LyXRC & rc) const
2877 rc.user_name = fromqstr(nameED->text());
2878 rc.user_email = fromqstr(emailED->text());
2882 void PrefIdentity::update(LyXRC const & rc)
2884 nameED->setText(toqstr(rc.user_name));
2885 emailED->setText(toqstr(rc.user_email));
2890 /////////////////////////////////////////////////////////////////////
2894 /////////////////////////////////////////////////////////////////////
2896 GuiPreferences::GuiPreferences(GuiView & lv)
2897 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2901 QDialog::setModal(false);
2903 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2904 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2905 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2906 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2908 addModule(new PrefUserInterface(this));
2909 addModule(new PrefEdit(this));
2910 addModule(new PrefShortcuts(this));
2911 addModule(new PrefScreenFonts(this));
2912 addModule(new PrefColors(this));
2913 addModule(new PrefDisplay(this));
2914 addModule(new PrefInput(this));
2915 addModule(new PrefCompletion(this));
2917 addModule(new PrefPaths(this));
2919 addModule(new PrefIdentity(this));
2921 addModule(new PrefLanguage(this));
2922 addModule(new PrefSpellchecker(this));
2924 addModule(new PrefPrinter(this));
2925 PrefDate * dateFormat = new PrefDate(this);
2926 addModule(dateFormat);
2927 addModule(new PrefPlaintext(this));
2928 addModule(new PrefLatex(this));
2930 PrefConverters * converters = new PrefConverters(this);
2931 PrefFileformats * formats = new PrefFileformats(this);
2932 connect(formats, SIGNAL(formatsChanged()),
2933 converters, SLOT(updateGui()));
2934 addModule(converters);
2937 prefsPS->setCurrentPanel(qt_("User interface"));
2938 // FIXME: hack to work around resizing bug in Qt >= 4.2
2939 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2940 #if QT_VERSION >= 0x040200
2941 prefsPS->updateGeometry();
2944 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2946 bc().setApply(applyPB);
2947 bc().setCancel(closePB);
2948 bc().setRestore(restorePB);
2950 // initialize the strftime validator
2951 bc().addCheckedLineEdit(dateFormat->DateED);
2955 void GuiPreferences::addModule(PrefModule * module)
2957 LASSERT(module, return);
2958 if (module->category().isEmpty())
2959 prefsPS->addPanel(module, module->title());
2961 prefsPS->addPanel(module, module->title(), module->category());
2962 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2963 modules_.push_back(module);
2967 void GuiPreferences::change_adaptor()
2973 void GuiPreferences::apply(LyXRC & rc) const
2975 size_t end = modules_.size();
2976 for (size_t i = 0; i != end; ++i)
2977 modules_[i]->apply(rc);
2981 void GuiPreferences::updateRc(LyXRC const & rc)
2983 size_t const end = modules_.size();
2984 for (size_t i = 0; i != end; ++i)
2985 modules_[i]->update(rc);
2989 void GuiPreferences::applyView()
2994 bool GuiPreferences::initialiseParams(string const &)
2997 formats_ = lyx::formats;
2998 converters_ = theConverters();
2999 converters_.update(formats_);
3000 movers_ = theMovers();
3002 update_screen_font_ = false;
3005 // Make sure that the bc is in the INITIAL state
3006 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3013 void GuiPreferences::dispatchParams()
3016 rc_.write(ss, true);
3017 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
3018 // FIXME: these need lfuns
3020 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
3022 lyx::formats = formats_;
3024 theConverters() = converters_;
3025 theConverters().update(lyx::formats);
3026 theConverters().buildGraph();
3028 theMovers() = movers_;
3030 vector<string>::const_iterator it = colors_.begin();
3031 vector<string>::const_iterator const end = colors_.end();
3032 for (; it != end; ++it)
3033 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
3036 if (update_screen_font_) {
3037 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
3038 update_screen_font_ = false;
3041 // The Save button has been pressed
3043 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
3047 void GuiPreferences::setColor(ColorCode col, QString const & hex)
3049 colors_.push_back(lcolor.getLyXName(col) + ' ' + fromqstr(hex));
3053 void GuiPreferences::updateScreenFonts()
3055 update_screen_font_ = true;
3059 QString GuiPreferences::browsebind(QString const & file) const
3061 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
3062 QStringList(qt_("LyX bind files (*.bind)")));
3066 QString GuiPreferences::browseUI(QString const & file) const
3068 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
3069 QStringList(qt_("LyX UI files (*.ui)")));
3073 QString GuiPreferences::browsekbmap(QString const & file) const
3075 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
3076 QStringList(qt_("LyX keyboard maps (*.kmap)")));
3080 QString GuiPreferences::browse(QString const & file,
3081 QString const & title) const
3083 return browseFile(file, title, QStringList(), true);
3087 // We support less paper sizes than the document dialog
3088 // Therefore this adjustment is needed.
3089 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
3093 return PAPER_DEFAULT;
3095 return PAPER_USLETTER;
3097 return PAPER_USLEGAL;
3099 return PAPER_USEXECUTIVE;
3109 // should not happen
3110 return PAPER_DEFAULT;
3115 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
3117 switch (papersize) {
3120 case PAPER_USLETTER:
3124 case PAPER_USEXECUTIVE:
3135 // should not happen
3141 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
3144 } // namespace frontend
3147 #include "moc_GuiPrefs.cpp"