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("aspell");
1317 #if defined(USE_HUNSPELL)
1318 spellcheckerCB->addItem("hunspell");
1321 if (theSpellChecker()) {
1322 connect(spellcheckerCB, SIGNAL(currentIndexChanged(int)),
1323 this, SIGNAL(changed()));
1324 connect(altLanguageED, SIGNAL(textChanged(QString)),
1325 this, SIGNAL(changed()));
1326 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1327 this, SIGNAL(changed()));
1328 connect(compoundWordCB, SIGNAL(clicked()),
1329 this, SIGNAL(changed()));
1330 connect(spellcheckContinuouslyCB, SIGNAL(clicked()),
1331 this, SIGNAL(changed()));
1333 spellcheckerCB->setEnabled(false);
1334 altLanguageED->setEnabled(false);
1335 escapeCharactersED->setEnabled(false);
1336 compoundWordCB->setEnabled(false);
1337 spellcheckContinuouslyCB->setEnabled(false);
1342 void PrefSpellchecker::apply(LyXRC & rc) const
1344 rc.spellchecker = fromqstr(spellcheckerCB->currentText());
1345 rc.spellchecker_alt_lang = fromqstr(altLanguageED->text());
1346 rc.spellchecker_esc_chars = fromqstr(escapeCharactersED->text());
1347 rc.spellchecker_accept_compound = compoundWordCB->isChecked();
1348 rc.spellcheck_continuously = spellcheckContinuouslyCB->isChecked();
1352 void PrefSpellchecker::update(LyXRC const & rc)
1354 spellcheckerCB->setCurrentIndex(spellcheckerCB->findText(
1355 toqstr(rc.spellchecker)));
1356 altLanguageED->setText(toqstr(rc.spellchecker_alt_lang));
1357 escapeCharactersED->setText(toqstr(rc.spellchecker_esc_chars));
1358 compoundWordCB->setChecked(rc.spellchecker_accept_compound);
1359 spellcheckContinuouslyCB->setChecked(rc.spellcheck_continuously);
1364 /////////////////////////////////////////////////////////////////////
1368 /////////////////////////////////////////////////////////////////////
1371 PrefConverters::PrefConverters(GuiPreferences * form)
1372 : PrefModule(qt_(catFiles), qt_("Converters"), form)
1376 connect(converterNewPB, SIGNAL(clicked()),
1377 this, SLOT(updateConverter()));
1378 connect(converterRemovePB, SIGNAL(clicked()),
1379 this, SLOT(removeConverter()));
1380 connect(converterModifyPB, SIGNAL(clicked()),
1381 this, SLOT(updateConverter()));
1382 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1383 this, SLOT(switchConverter()));
1384 connect(converterFromCO, SIGNAL(activated(QString)),
1385 this, SLOT(changeConverter()));
1386 connect(converterToCO, SIGNAL(activated(QString)),
1387 this, SLOT(changeConverter()));
1388 connect(converterED, SIGNAL(textEdited(QString)),
1389 this, SLOT(changeConverter()));
1390 connect(converterFlagED, SIGNAL(textEdited(QString)),
1391 this, SLOT(changeConverter()));
1392 connect(converterNewPB, SIGNAL(clicked()),
1393 this, SIGNAL(changed()));
1394 connect(converterRemovePB, SIGNAL(clicked()),
1395 this, SIGNAL(changed()));
1396 connect(converterModifyPB, SIGNAL(clicked()),
1397 this, SIGNAL(changed()));
1398 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1399 this, SIGNAL(changed()));
1401 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1402 //converterDefGB->setFocusProxy(convertersLW);
1406 void PrefConverters::apply(LyXRC & rc) const
1408 rc.use_converter_cache = cacheCB->isChecked();
1409 rc.converter_cache_maxage = int(widgetToDouble(maxAgeLE) * 86400.0);
1413 void PrefConverters::update(LyXRC const & rc)
1415 cacheCB->setChecked(rc.use_converter_cache);
1417 doubleToWidget(maxAgeLE, (double(rc.converter_cache_maxage) / 86400.0), 'g', 6);
1422 void PrefConverters::updateGui()
1424 form_->formats().sort();
1425 form_->converters().update(form_->formats());
1426 // save current selection
1427 QString current = converterFromCO->currentText()
1428 + " -> " + converterToCO->currentText();
1430 converterFromCO->clear();
1431 converterToCO->clear();
1433 Formats::const_iterator cit = form_->formats().begin();
1434 Formats::const_iterator end = form_->formats().end();
1435 for (; cit != end; ++cit) {
1436 converterFromCO->addItem(qt_(cit->prettyname()));
1437 converterToCO->addItem(qt_(cit->prettyname()));
1440 // currentRowChanged(int) is also triggered when updating the listwidget
1441 // block signals to avoid unnecessary calls to switchConverter()
1442 convertersLW->blockSignals(true);
1443 convertersLW->clear();
1445 Converters::const_iterator ccit = form_->converters().begin();
1446 Converters::const_iterator cend = form_->converters().end();
1447 for (; ccit != cend; ++ccit) {
1448 QString const name =
1449 qt_(ccit->From->prettyname()) + " -> " + qt_(ccit->To->prettyname());
1450 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1451 new QListWidgetItem(name, convertersLW, type);
1453 convertersLW->sortItems(Qt::AscendingOrder);
1454 convertersLW->blockSignals(false);
1456 // restore selection
1457 if (!current.isEmpty()) {
1458 QList<QListWidgetItem *> const item =
1459 convertersLW->findItems(current, Qt::MatchExactly);
1460 if (!item.isEmpty())
1461 convertersLW->setCurrentItem(item.at(0));
1464 // select first element if restoring failed
1465 if (convertersLW->currentRow() == -1)
1466 convertersLW->setCurrentRow(0);
1472 void PrefConverters::switchConverter()
1474 int const cnr = convertersLW->currentItem()->type();
1475 Converter const & c(form_->converters().get(cnr));
1476 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1477 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1478 converterED->setText(toqstr(c.command));
1479 converterFlagED->setText(toqstr(c.flags));
1485 void PrefConverters::changeConverter()
1491 void PrefConverters::updateButtons()
1493 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1494 Format const & to = form_->formats().get(converterToCO->currentIndex());
1495 int const sel = form_->converters().getNumber(from.name(), to.name());
1496 bool const known = sel >= 0;
1497 bool const valid = !(converterED->text().isEmpty()
1498 || from.name() == to.name());
1500 int const cnr = convertersLW->currentItem()->type();
1501 Converter const & c = form_->converters().get(cnr);
1502 string const old_command = c.command;
1503 string const old_flag = c.flags;
1504 string const new_command = fromqstr(converterED->text());
1505 string const new_flag = fromqstr(converterFlagED->text());
1507 bool modified = (old_command != new_command || old_flag != new_flag);
1509 converterModifyPB->setEnabled(valid && known && modified);
1510 converterNewPB->setEnabled(valid && !known);
1511 converterRemovePB->setEnabled(known);
1513 maxAgeLE->setEnabled(cacheCB->isChecked());
1514 maxAgeLA->setEnabled(cacheCB->isChecked());
1519 // specify unique from/to or it doesn't appear. This is really bad UI
1520 // this is why we can use the same function for both new and modify
1521 void PrefConverters::updateConverter()
1523 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1524 Format const & to = form_->formats().get(converterToCO->currentIndex());
1525 string const flags = fromqstr(converterFlagED->text());
1526 string const command = fromqstr(converterED->text());
1528 Converter const * old =
1529 form_->converters().getConverter(from.name(), to.name());
1530 form_->converters().add(from.name(), to.name(), command, flags);
1533 form_->converters().updateLast(form_->formats());
1537 // Remove all files created by this converter from the cache, since
1538 // the modified converter might create different files.
1539 ConverterCache::get().remove_all(from.name(), to.name());
1543 void PrefConverters::removeConverter()
1545 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1546 Format const & to = form_->formats().get(converterToCO->currentIndex());
1547 form_->converters().erase(from.name(), to.name());
1551 // Remove all files created by this converter from the cache, since
1552 // a possible new converter might create different files.
1553 ConverterCache::get().remove_all(from.name(), to.name());
1557 void PrefConverters::on_cacheCB_stateChanged(int state)
1559 maxAgeLE->setEnabled(state == Qt::Checked);
1560 maxAgeLA->setEnabled(state == Qt::Checked);
1565 /////////////////////////////////////////////////////////////////////
1569 /////////////////////////////////////////////////////////////////////
1571 class FormatValidator : public QValidator
1574 FormatValidator(QWidget *, Formats const & f);
1575 void fixup(QString & input) const;
1576 QValidator::State validate(QString & input, int & pos) const;
1578 virtual QString toString(Format const & format) const = 0;
1580 Formats const & formats_;
1584 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1585 : QValidator(parent), formats_(f)
1590 void FormatValidator::fixup(QString & input) const
1592 Formats::const_iterator cit = formats_.begin();
1593 Formats::const_iterator end = formats_.end();
1594 for (; cit != end; ++cit) {
1595 QString const name = toString(*cit);
1596 if (distance(formats_.begin(), cit) == nr()) {
1604 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1606 Formats::const_iterator cit = formats_.begin();
1607 Formats::const_iterator end = formats_.end();
1608 bool unknown = true;
1609 for (; unknown && cit != end; ++cit) {
1610 QString const name = toString(*cit);
1611 if (distance(formats_.begin(), cit) != nr())
1612 unknown = name != input;
1615 if (unknown && !input.isEmpty())
1616 return QValidator::Acceptable;
1618 return QValidator::Intermediate;
1622 int FormatValidator::nr() const
1624 QComboBox * p = qobject_cast<QComboBox *>(parent());
1625 return p->itemData(p->currentIndex()).toInt();
1629 /////////////////////////////////////////////////////////////////////
1631 // FormatNameValidator
1633 /////////////////////////////////////////////////////////////////////
1635 class FormatNameValidator : public FormatValidator
1638 FormatNameValidator(QWidget * parent, Formats const & f)
1639 : FormatValidator(parent, f)
1642 QString toString(Format const & format) const
1644 return toqstr(format.name());
1649 /////////////////////////////////////////////////////////////////////
1651 // FormatPrettynameValidator
1653 /////////////////////////////////////////////////////////////////////
1655 class FormatPrettynameValidator : public FormatValidator
1658 FormatPrettynameValidator(QWidget * parent, Formats const & f)
1659 : FormatValidator(parent, f)
1662 QString toString(Format const & format) const
1664 return qt_(format.prettyname());
1669 /////////////////////////////////////////////////////////////////////
1673 /////////////////////////////////////////////////////////////////////
1675 PrefFileformats::PrefFileformats(GuiPreferences * form)
1676 : PrefModule(qt_(catFiles), qt_("File formats"), form)
1679 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1680 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1682 connect(documentCB, SIGNAL(clicked()),
1683 this, SLOT(setFlags()));
1684 connect(vectorCB, SIGNAL(clicked()),
1685 this, SLOT(setFlags()));
1686 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1687 this, SLOT(updatePrettyname()));
1688 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1689 this, SIGNAL(changed()));
1690 connect(defaultFormatCB, SIGNAL(activated(QString)),
1691 this, SIGNAL(changed()));
1692 connect(viewerCO, SIGNAL(activated(int)),
1693 this, SIGNAL(changed()));
1694 connect(editorCO, SIGNAL(activated(int)),
1695 this, SIGNAL(changed()));
1701 string const l10n_shortcut(string const prettyname, string const shortcut)
1703 if (shortcut.empty())
1706 string l10n_format =
1707 to_utf8(_(prettyname + '|' + shortcut));
1708 return split(l10n_format, '|');
1711 }; // namespace anon
1714 void PrefFileformats::apply(LyXRC & rc) const
1716 QString const default_format = defaultFormatCB->itemData(
1717 defaultFormatCB->currentIndex()).toString();
1718 rc.default_view_format = fromqstr(default_format);
1722 void PrefFileformats::update(LyXRC const & rc)
1724 viewer_alternatives = rc.viewer_alternatives;
1725 editor_alternatives = rc.editor_alternatives;
1726 bool const init = defaultFormatCB->currentText().isEmpty();
1730 defaultFormatCB->findData(toqstr(rc.default_view_format));
1731 defaultFormatCB->setCurrentIndex(pos);
1736 void PrefFileformats::updateView()
1738 QString const current = formatsCB->currentText();
1739 QString const current_def = defaultFormatCB->currentText();
1741 // update comboboxes with formats
1742 formatsCB->blockSignals(true);
1743 defaultFormatCB->blockSignals(true);
1745 defaultFormatCB->clear();
1746 form_->formats().sort();
1747 Formats::const_iterator cit = form_->formats().begin();
1748 Formats::const_iterator end = form_->formats().end();
1749 for (; cit != end; ++cit) {
1750 formatsCB->addItem(qt_(cit->prettyname()),
1751 QVariant(form_->formats().getNumber(cit->name())));
1752 if (form_->converters().isReachable("latex", cit->name())
1753 || form_->converters().isReachable("pdflatex", cit->name()))
1754 defaultFormatCB->addItem(qt_(cit->prettyname()),
1755 QVariant(toqstr(cit->name())));
1758 // restore selection
1759 int item = formatsCB->findText(current, Qt::MatchExactly);
1760 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1761 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1762 item = defaultFormatCB->findText(current_def, Qt::MatchExactly);
1763 defaultFormatCB->setCurrentIndex(item < 0 ? 0 : item);
1764 formatsCB->blockSignals(false);
1765 defaultFormatCB->blockSignals(false);
1769 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1771 int const nr = formatsCB->itemData(i).toInt();
1772 Format const f = form_->formats().get(nr);
1774 formatED->setText(toqstr(f.name()));
1775 copierED->setText(toqstr(form_->movers().command(f.name())));
1776 extensionED->setText(toqstr(f.extension()));
1777 shortcutED->setText(
1778 toqstr(l10n_shortcut(f.prettyname(), f.shortcut())));
1779 documentCB->setChecked((f.documentFormat()));
1780 vectorCB->setChecked((f.vectorFormat()));
1786 void PrefFileformats::setFlags()
1788 int flags = Format::none;
1789 if (documentCB->isChecked())
1790 flags |= Format::document;
1791 if (vectorCB->isChecked())
1792 flags |= Format::vector;
1793 currentFormat().setFlags(flags);
1798 void PrefFileformats::on_copierED_textEdited(const QString & s)
1800 string const fmt = fromqstr(formatED->text());
1801 form_->movers().set(fmt, fromqstr(s));
1806 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1808 currentFormat().setExtension(fromqstr(s));
1812 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1814 currentFormat().setViewer(fromqstr(s));
1819 void PrefFileformats::on_editorED_textEdited(const QString & s)
1821 currentFormat().setEditor(fromqstr(s));
1826 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1828 string const new_shortcut = fromqstr(s);
1829 if (new_shortcut == l10n_shortcut(currentFormat().prettyname(),
1830 currentFormat().shortcut()))
1832 currentFormat().setShortcut(new_shortcut);
1837 void PrefFileformats::on_formatED_editingFinished()
1839 string const newname = fromqstr(formatED->displayText());
1840 if (newname == currentFormat().name())
1843 currentFormat().setName(newname);
1848 void PrefFileformats::on_formatED_textChanged(const QString &)
1850 QString t = formatED->text();
1852 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1853 setValid(formatLA, valid);
1857 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1859 QString t = formatsCB->currentText();
1861 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1862 setValid(formatsLA, valid);
1866 void PrefFileformats::updatePrettyname()
1868 QString const newname = formatsCB->currentText();
1869 if (newname == qt_(currentFormat().prettyname()))
1872 currentFormat().setPrettyname(fromqstr(newname));
1880 void updateComboBox(LyXRC::Alternatives const & alts,
1881 string const & fmt, QComboBox * combo)
1883 LyXRC::Alternatives::const_iterator it =
1885 if (it != alts.end()) {
1886 LyXRC::CommandSet const & cmds = it->second;
1887 LyXRC::CommandSet::const_iterator sit =
1889 LyXRC::CommandSet::const_iterator const sen =
1891 for (; sit != sen; ++sit) {
1892 QString const qcmd = toqstr(*sit);
1893 combo->addItem(qcmd, qcmd);
1900 void PrefFileformats::updateViewers()
1902 Format const f = currentFormat();
1903 viewerCO->blockSignals(true);
1905 viewerCO->addItem(qt_("None"), QString());
1906 updateComboBox(viewer_alternatives, f.name(), viewerCO);
1907 viewerCO->addItem(qt_("Custom"), QString("custom viewer"));
1908 viewerCO->blockSignals(false);
1910 int pos = viewerCO->findData(toqstr(f.viewer()));
1913 viewerED->setEnabled(false);
1914 viewerCO->setCurrentIndex(pos);
1916 viewerED->setEnabled(true);
1917 viewerED->setText(toqstr(f.viewer()));
1918 viewerCO->setCurrentIndex(viewerCO->findData(toqstr("custom viewer")));
1923 void PrefFileformats::updateEditors()
1925 Format const f = currentFormat();
1926 editorCO->blockSignals(true);
1928 editorCO->addItem(qt_("None"), QString());
1929 updateComboBox(editor_alternatives, f.name(), editorCO);
1930 editorCO->addItem(qt_("Custom"), QString("custom editor"));
1931 editorCO->blockSignals(false);
1933 int pos = editorCO->findData(toqstr(f.editor()));
1936 editorED->setEnabled(false);
1937 editorCO->setCurrentIndex(pos);
1939 editorED->setEnabled(true);
1940 editorED->setText(toqstr(f.editor()));
1941 editorCO->setCurrentIndex(editorCO->findData(toqstr("custom editor")));
1946 void PrefFileformats::on_viewerCO_currentIndexChanged(int i)
1948 bool const custom = viewerCO->itemData(i).toString() == "custom viewer";
1949 viewerED->setEnabled(custom);
1951 currentFormat().setViewer(fromqstr(viewerCO->itemData(i).toString()));
1955 void PrefFileformats::on_editorCO_currentIndexChanged(int i)
1957 bool const custom = editorCO->itemData(i).toString() == "custom editor";
1958 editorED->setEnabled(custom);
1960 currentFormat().setEditor(fromqstr(editorCO->itemData(i).toString()));
1964 Format & PrefFileformats::currentFormat()
1966 int const i = formatsCB->currentIndex();
1967 int const nr = formatsCB->itemData(i).toInt();
1968 return form_->formats().get(nr);
1972 void PrefFileformats::on_formatNewPB_clicked()
1974 form_->formats().add("", "", "", "", "", "", Format::none);
1976 formatsCB->setCurrentIndex(0);
1977 formatsCB->setFocus(Qt::OtherFocusReason);
1981 void PrefFileformats::on_formatRemovePB_clicked()
1983 int const i = formatsCB->currentIndex();
1984 int const nr = formatsCB->itemData(i).toInt();
1985 string const current_text = form_->formats().get(nr).name();
1986 if (form_->converters().formatIsUsed(current_text)) {
1987 Alert::error(_("Format in use"),
1988 _("Cannot remove a Format used by a Converter. "
1989 "Remove the converter first."));
1993 form_->formats().erase(current_text);
1996 on_formatsCB_editTextChanged(formatsCB->currentText());
2001 /////////////////////////////////////////////////////////////////////
2005 /////////////////////////////////////////////////////////////////////
2007 PrefLanguage::PrefLanguage(GuiPreferences * form)
2008 : PrefModule(qt_(catLanguage), qt_("Language"), form)
2012 connect(rtlGB, SIGNAL(clicked()),
2013 this, SIGNAL(changed()));
2014 connect(visualCursorRB, SIGNAL(clicked()),
2015 this, SIGNAL(changed()));
2016 connect(logicalCursorRB, SIGNAL(clicked()),
2017 this, SIGNAL(changed()));
2018 connect(markForeignCB, SIGNAL(clicked()),
2019 this, SIGNAL(changed()));
2020 connect(autoBeginCB, SIGNAL(clicked()),
2021 this, SIGNAL(changed()));
2022 connect(autoEndCB, SIGNAL(clicked()),
2023 this, SIGNAL(changed()));
2024 connect(useBabelCB, SIGNAL(clicked()),
2025 this, SIGNAL(changed()));
2026 connect(globalCB, SIGNAL(clicked()),
2027 this, SIGNAL(changed()));
2028 connect(languagePackageED, SIGNAL(textChanged(QString)),
2029 this, SIGNAL(changed()));
2030 connect(startCommandED, SIGNAL(textChanged(QString)),
2031 this, SIGNAL(changed()));
2032 connect(endCommandED, SIGNAL(textChanged(QString)),
2033 this, SIGNAL(changed()));
2034 connect(uiLanguageCO, SIGNAL(activated(int)),
2035 this, SIGNAL(changed()));
2037 uiLanguageCO->clear();
2039 QAbstractItemModel * language_model = guiApp->languageModel();
2040 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
2041 language_model->sort(0);
2043 // FIXME: This is wrong, we need filter this list based on the available
2045 uiLanguageCO->blockSignals(true);
2046 uiLanguageCO->addItem(qt_("Default"), toqstr("auto"));
2047 for (int i = 0; i != language_model->rowCount(); ++i) {
2048 QModelIndex index = language_model->index(i, 0);
2049 uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
2050 index.data(Qt::UserRole).toString());
2052 uiLanguageCO->blockSignals(false);
2056 void PrefLanguage::on_uiLanguageCO_currentIndexChanged(int)
2058 QMessageBox::information(this, qt_("LyX needs to be restarted!"),
2059 qt_("The change of user interface language will be fully "
2060 "effective only after a restart."));
2064 void PrefLanguage::apply(LyXRC & rc) const
2066 // FIXME: remove rtl_support bool
2067 rc.rtl_support = rtlGB->isChecked();
2068 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
2069 rc.mark_foreign_language = markForeignCB->isChecked();
2070 rc.language_auto_begin = autoBeginCB->isChecked();
2071 rc.language_auto_end = autoEndCB->isChecked();
2072 rc.language_use_babel = useBabelCB->isChecked();
2073 rc.language_global_options = globalCB->isChecked();
2074 rc.language_package = fromqstr(languagePackageED->text());
2075 rc.language_command_begin = fromqstr(startCommandED->text());
2076 rc.language_command_end = fromqstr(endCommandED->text());
2077 rc.gui_language = fromqstr(
2078 uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString());
2082 void PrefLanguage::update(LyXRC const & rc)
2084 // FIXME: remove rtl_support bool
2085 rtlGB->setChecked(rc.rtl_support);
2086 if (rc.visual_cursor)
2087 visualCursorRB->setChecked(true);
2089 logicalCursorRB->setChecked(true);
2090 markForeignCB->setChecked(rc.mark_foreign_language);
2091 autoBeginCB->setChecked(rc.language_auto_begin);
2092 autoEndCB->setChecked(rc.language_auto_end);
2093 useBabelCB->setChecked(rc.language_use_babel);
2094 globalCB->setChecked(rc.language_global_options);
2095 languagePackageED->setText(toqstr(rc.language_package));
2096 startCommandED->setText(toqstr(rc.language_command_begin));
2097 endCommandED->setText(toqstr(rc.language_command_end));
2099 int pos = uiLanguageCO->findData(toqstr(rc.gui_language));
2100 uiLanguageCO->blockSignals(true);
2101 uiLanguageCO->setCurrentIndex(pos);
2102 uiLanguageCO->blockSignals(false);
2106 /////////////////////////////////////////////////////////////////////
2110 /////////////////////////////////////////////////////////////////////
2112 PrefPrinter::PrefPrinter(GuiPreferences * form)
2113 : PrefModule(qt_(catOutput), qt_("Printer"), form)
2117 connect(printerAdaptCB, SIGNAL(clicked()),
2118 this, SIGNAL(changed()));
2119 connect(printerCommandED, SIGNAL(textChanged(QString)),
2120 this, SIGNAL(changed()));
2121 connect(printerNameED, SIGNAL(textChanged(QString)),
2122 this, SIGNAL(changed()));
2123 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
2124 this, SIGNAL(changed()));
2125 connect(printerCopiesED, SIGNAL(textChanged(QString)),
2126 this, SIGNAL(changed()));
2127 connect(printerReverseED, SIGNAL(textChanged(QString)),
2128 this, SIGNAL(changed()));
2129 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
2130 this, SIGNAL(changed()));
2131 connect(printerExtensionED, SIGNAL(textChanged(QString)),
2132 this, SIGNAL(changed()));
2133 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
2134 this, SIGNAL(changed()));
2135 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
2136 this, SIGNAL(changed()));
2137 connect(printerEvenED, SIGNAL(textChanged(QString)),
2138 this, SIGNAL(changed()));
2139 connect(printerOddED, SIGNAL(textChanged(QString)),
2140 this, SIGNAL(changed()));
2141 connect(printerCollatedED, SIGNAL(textChanged(QString)),
2142 this, SIGNAL(changed()));
2143 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
2144 this, SIGNAL(changed()));
2145 connect(printerToFileED, SIGNAL(textChanged(QString)),
2146 this, SIGNAL(changed()));
2147 connect(printerExtraED, SIGNAL(textChanged(QString)),
2148 this, SIGNAL(changed()));
2149 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
2150 this, SIGNAL(changed()));
2151 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
2152 this, SIGNAL(changed()));
2156 void PrefPrinter::apply(LyXRC & rc) const
2158 rc.print_adapt_output = printerAdaptCB->isChecked();
2159 rc.print_command = fromqstr(printerCommandED->text());
2160 rc.printer = fromqstr(printerNameED->text());
2162 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
2163 rc.print_copies_flag = fromqstr(printerCopiesED->text());
2164 rc.print_reverse_flag = fromqstr(printerReverseED->text());
2165 rc.print_to_printer = fromqstr(printerToPrinterED->text());
2166 rc.print_file_extension = fromqstr(printerExtensionED->text());
2167 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
2168 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
2169 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
2170 rc.print_oddpage_flag = fromqstr(printerOddED->text());
2171 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
2172 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
2173 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
2174 rc.print_extra_options = fromqstr(printerExtraED->text());
2175 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
2176 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
2180 void PrefPrinter::update(LyXRC const & rc)
2182 printerAdaptCB->setChecked(rc.print_adapt_output);
2183 printerCommandED->setText(toqstr(rc.print_command));
2184 printerNameED->setText(toqstr(rc.printer));
2186 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
2187 printerCopiesED->setText(toqstr(rc.print_copies_flag));
2188 printerReverseED->setText(toqstr(rc.print_reverse_flag));
2189 printerToPrinterED->setText(toqstr(rc.print_to_printer));
2190 printerExtensionED->setText(toqstr(rc.print_file_extension));
2191 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
2192 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
2193 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
2194 printerOddED->setText(toqstr(rc.print_oddpage_flag));
2195 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
2196 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
2197 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
2198 printerExtraED->setText(toqstr(rc.print_extra_options));
2199 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
2200 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
2204 /////////////////////////////////////////////////////////////////////
2206 // PrefUserInterface
2208 /////////////////////////////////////////////////////////////////////
2210 PrefUserInterface::PrefUserInterface(GuiPreferences * form)
2211 : PrefModule(qt_(catLookAndFeel), qt_("User interface"), form)
2215 connect(autoSaveCB, SIGNAL(toggled(bool)),
2216 autoSaveSB, SLOT(setEnabled(bool)));
2217 connect(autoSaveCB, SIGNAL(toggled(bool)),
2218 TextLabel1, SLOT(setEnabled(bool)));
2219 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
2220 this, SIGNAL(changed()));
2221 #if QT_VERSION < 0x040500
2222 singleCloseTabButtonCB->setEnabled(false);
2224 connect(singleCloseTabButtonCB, SIGNAL(clicked()),
2225 this, SIGNAL(changed()));
2226 connect(uiFilePB, SIGNAL(clicked()),
2227 this, SLOT(selectUi()));
2228 connect(uiFileED, SIGNAL(textChanged(QString)),
2229 this, SIGNAL(changed()));
2230 connect(restoreCursorCB, SIGNAL(clicked()),
2231 this, SIGNAL(changed()));
2232 connect(loadSessionCB, SIGNAL(clicked()),
2233 this, SIGNAL(changed()));
2234 connect(allowGeometrySessionCB, SIGNAL(clicked()),
2235 this, SIGNAL(changed()));
2236 connect(autoSaveSB, SIGNAL(valueChanged(int)),
2237 this, SIGNAL(changed()));
2238 connect(autoSaveCB, SIGNAL(clicked()),
2239 this, SIGNAL(changed()));
2240 connect(backupCB, SIGNAL(clicked()),
2241 this, SIGNAL(changed()));
2242 connect(lastfilesSB, SIGNAL(valueChanged(int)),
2243 this, SIGNAL(changed()));
2244 connect(tooltipCB, SIGNAL(toggled(bool)),
2245 this, SIGNAL(changed()));
2246 lastfilesSB->setMaximum(maxlastfiles);
2250 void PrefUserInterface::apply(LyXRC & rc) const
2252 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
2253 rc.use_lastfilepos = restoreCursorCB->isChecked();
2254 rc.load_session = loadSessionCB->isChecked();
2255 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
2256 rc.autosave = autoSaveCB->isChecked()? autoSaveSB->value() * 60 : 0;
2257 rc.make_backup = backupCB->isChecked();
2258 rc.num_lastfiles = lastfilesSB->value();
2259 rc.use_tooltip = tooltipCB->isChecked();
2260 rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
2261 rc.single_close_tab_button = singleCloseTabButtonCB->isChecked();
2262 #if QT_VERSION < 0x040500
2263 rc.single_close_tab_button = true;
2268 void PrefUserInterface::update(LyXRC const & rc)
2270 uiFileED->setText(toqstr(external_path(rc.ui_file)));
2271 restoreCursorCB->setChecked(rc.use_lastfilepos);
2272 loadSessionCB->setChecked(rc.load_session);
2273 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
2274 // convert to minutes
2275 bool autosave = rc.autosave > 0;
2276 int mins = rc.autosave / 60;
2279 autoSaveSB->setValue(mins);
2280 autoSaveCB->setChecked(autosave);
2281 autoSaveSB->setEnabled(autosave);
2282 backupCB->setChecked(rc.make_backup);
2283 lastfilesSB->setValue(rc.num_lastfiles);
2284 tooltipCB->setChecked(rc.use_tooltip);
2285 openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
2286 singleCloseTabButtonCB->setChecked(rc.single_close_tab_button);
2290 void PrefUserInterface::selectUi()
2292 QString file = form_->browseUI(internalPath(uiFileED->text()));
2293 if (!file.isEmpty())
2294 uiFileED->setText(file);
2298 void PrefUserInterface::on_clearSessionPB_clicked()
2300 guiApp->clearSession();
2305 /////////////////////////////////////////////////////////////////////
2309 /////////////////////////////////////////////////////////////////////
2311 PrefEdit::PrefEdit(GuiPreferences * form)
2312 : PrefModule(qt_(catEditing), qt_("Control"), form)
2316 connect(cursorFollowsCB, SIGNAL(clicked()),
2317 this, SIGNAL(changed()));
2318 connect(scrollBelowCB, SIGNAL(clicked()),
2319 this, SIGNAL(changed()));
2320 connect(sortEnvironmentsCB, SIGNAL(clicked()),
2321 this, SIGNAL(changed()));
2322 connect(groupEnvironmentsCB, SIGNAL(clicked()),
2323 this, SIGNAL(changed()));
2324 connect(macroEditStyleCO, SIGNAL(activated(int)),
2325 this, SIGNAL(changed()));
2326 connect(fullscreenLimitGB, SIGNAL(clicked()),
2327 this, SIGNAL(changed()));
2328 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
2329 this, SIGNAL(changed()));
2330 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
2331 this, SIGNAL(changed()));
2332 connect(toggleMenubarCB, SIGNAL(toggled(bool)),
2333 this, SIGNAL(changed()));
2334 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
2335 this, SIGNAL(changed()));
2336 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
2337 this, SIGNAL(changed()));
2341 void PrefEdit::apply(LyXRC & rc) const
2343 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
2344 rc.scroll_below_document = scrollBelowCB->isChecked();
2345 rc.sort_layouts = sortEnvironmentsCB->isChecked();
2346 rc.group_layouts = groupEnvironmentsCB->isChecked();
2347 switch (macroEditStyleCO->currentIndex()) {
2348 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
2349 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
2350 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
2352 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
2353 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
2354 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
2355 rc.full_screen_menubar = toggleMenubarCB->isChecked();
2356 rc.full_screen_width = fullscreenWidthSB->value();
2357 rc.full_screen_limit = fullscreenLimitGB->isChecked();
2361 void PrefEdit::update(LyXRC const & rc)
2363 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
2364 scrollBelowCB->setChecked(rc.scroll_below_document);
2365 sortEnvironmentsCB->setChecked(rc.sort_layouts);
2366 groupEnvironmentsCB->setChecked(rc.group_layouts);
2367 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
2368 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
2369 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
2370 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
2371 toggleMenubarCB->setChecked(rc.full_screen_menubar);
2372 fullscreenWidthSB->setValue(rc.full_screen_width);
2373 fullscreenLimitGB->setChecked(rc.full_screen_limit);
2377 /////////////////////////////////////////////////////////////////////
2381 /////////////////////////////////////////////////////////////////////
2384 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
2386 Ui::shortcutUi::setupUi(this);
2387 QDialog::setModal(true);
2391 PrefShortcuts::PrefShortcuts(GuiPreferences * form)
2392 : PrefModule(qt_(catEditing), qt_("Shortcuts"), form)
2396 shortcutsTW->setColumnCount(2);
2397 shortcutsTW->headerItem()->setText(0, qt_("Function"));
2398 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
2399 shortcutsTW->setSortingEnabled(true);
2400 // Multi-selection can be annoying.
2401 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
2403 connect(bindFilePB, SIGNAL(clicked()),
2404 this, SLOT(selectBind()));
2405 connect(bindFileED, SIGNAL(textChanged(QString)),
2406 this, SIGNAL(changed()));
2407 connect(removePB, SIGNAL(clicked()),
2408 this, SIGNAL(changed()));
2410 shortcut_ = new GuiShortcutDialog(this);
2411 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
2412 shortcut_bc_.setOK(shortcut_->okPB);
2413 shortcut_bc_.setCancel(shortcut_->cancelPB);
2415 connect(shortcut_->okPB, SIGNAL(clicked()),
2416 shortcut_, SLOT(accept()));
2417 connect(shortcut_->okPB, SIGNAL(clicked()),
2418 this, SIGNAL(changed()));
2419 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2420 shortcut_, SLOT(reject()));
2421 connect(shortcut_->clearPB, SIGNAL(clicked()),
2422 this, SLOT(shortcutClearPressed()));
2423 connect(shortcut_->removePB, SIGNAL(clicked()),
2424 this, SLOT(shortcutRemovePressed()));
2425 connect(shortcut_->okPB, SIGNAL(clicked()),
2426 this, SLOT(shortcutOkPressed()));
2427 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2428 this, SLOT(shortcutCancelPressed()));
2432 void PrefShortcuts::apply(LyXRC & rc) const
2434 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
2435 // write user_bind and user_unbind to .lyx/bind/user.bind
2436 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
2437 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
2438 lyxerr << "LyX could not create the user bind directory '"
2439 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2442 if (!bind_dir.isDirWritable()) {
2443 lyxerr << "LyX could not write to the user bind directory '"
2444 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2447 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
2448 user_unbind_.write(user_bind_file.toFilesystemEncoding(), false, true);
2449 user_bind_.write(user_bind_file.toFilesystemEncoding(), true, false);
2450 // immediately apply the keybindings. Why this is not done before?
2451 // The good thing is that the menus are updated automatically.
2452 theTopLevelKeymap().clear();
2453 theTopLevelKeymap().read("site");
2454 theTopLevelKeymap().read(rc.bind_file, 0, KeyMap::Fallback);
2455 theTopLevelKeymap().read("user", 0, KeyMap::MissingOK);
2459 void PrefShortcuts::update(LyXRC const & rc)
2461 bindFileED->setText(toqstr(external_path(rc.bind_file)));
2463 system_bind_.clear();
2465 user_unbind_.clear();
2466 system_bind_.read("site");
2467 system_bind_.read(rc.bind_file);
2468 // \unbind in user.bind is added to user_unbind_
2469 user_bind_.read("user", &user_unbind_, KeyMap::MissingOK);
2470 updateShortcutsTW();
2474 void PrefShortcuts::updateShortcutsTW()
2476 shortcutsTW->clear();
2478 editItem_ = new QTreeWidgetItem(shortcutsTW);
2479 editItem_->setText(0, qt_("Cursor, Mouse and Editing functions"));
2480 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2482 mathItem_ = new QTreeWidgetItem(shortcutsTW);
2483 mathItem_->setText(0, qt_("Mathematical Symbols"));
2484 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2486 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2487 bufferItem_->setText(0, qt_("Document and Window"));
2488 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2490 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2491 layoutItem_->setText(0, qt_("Font, Layouts and Textclasses"));
2492 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2494 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2495 systemItem_->setText(0, qt_("System and Miscellaneous"));
2496 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2498 // listBindings(unbound=true) lists all bound and unbound lfuns
2499 // Items in this list is tagged by its source.
2500 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2502 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2504 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2505 KeyMap::UserUnbind);
2506 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2507 user_bindinglist.end());
2508 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2509 user_unbindinglist.end());
2511 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2512 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2513 for (; it != it_end; ++it)
2514 insertShortcutItem(it->request, it->sequence, KeyMap::ItemType(it->tag));
2516 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2517 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2518 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2519 modifyPB->setEnabled(!items.isEmpty());
2521 shortcutsTW->resizeColumnToContents(0);
2525 void PrefShortcuts::setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag)
2527 item->setData(0, Qt::UserRole, QVariant(tag));
2531 case KeyMap::System:
2533 case KeyMap::UserBind:
2536 case KeyMap::UserUnbind:
2537 font.setStrikeOut(true);
2539 // this item is not displayed now.
2540 case KeyMap::UserExtraUnbind:
2541 font.setStrikeOut(true);
2545 item->setFont(1, font);
2549 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2550 KeySequence const & seq, KeyMap::ItemType tag)
2552 FuncCode action = lfun.action;
2553 string const action_name = lyxaction.getActionName(action);
2554 QString const lfun_name = toqstr(from_utf8(action_name)
2555 + ' ' + lfun.argument());
2556 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2557 KeyMap::ItemType item_tag = tag;
2559 QTreeWidgetItem * newItem = 0;
2560 // for unbind items, try to find an existing item in the system bind list
2561 if (tag == KeyMap::UserUnbind) {
2562 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2563 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2564 for (int i = 0; i < items.size(); ++i) {
2565 if (items[i]->text(1) == shortcut)
2569 // if not found, this unbind item is KeyMap::UserExtraUnbind
2570 // Such an item is not displayed to avoid confusion (what is
2571 // unmatched removed?).
2573 item_tag = KeyMap::UserExtraUnbind;
2578 switch(lyxaction.getActionType(action)) {
2579 case LyXAction::Hidden:
2581 case LyXAction::Edit:
2582 newItem = new QTreeWidgetItem(editItem_);
2584 case LyXAction::Math:
2585 newItem = new QTreeWidgetItem(mathItem_);
2587 case LyXAction::Buffer:
2588 newItem = new QTreeWidgetItem(bufferItem_);
2590 case LyXAction::Layout:
2591 newItem = new QTreeWidgetItem(layoutItem_);
2593 case LyXAction::System:
2594 newItem = new QTreeWidgetItem(systemItem_);
2597 // this should not happen
2598 newItem = new QTreeWidgetItem(shortcutsTW);
2602 newItem->setText(0, lfun_name);
2603 newItem->setText(1, shortcut);
2604 // record BindFile representation to recover KeySequence when needed.
2605 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2606 setItemType(newItem, item_tag);
2611 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2613 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2614 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2615 modifyPB->setEnabled(!items.isEmpty());
2616 if (items.isEmpty())
2619 KeyMap::ItemType tag =
2620 static_cast<KeyMap::ItemType>(items[0]->data(0, Qt::UserRole).toInt());
2621 if (tag == KeyMap::UserUnbind)
2622 removePB->setText(qt_("Res&tore"));
2624 removePB->setText(qt_("Remo&ve"));
2628 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2634 void PrefShortcuts::modifyShortcut()
2636 QTreeWidgetItem * item = shortcutsTW->currentItem();
2637 if (item->flags() & Qt::ItemIsSelectable) {
2638 shortcut_->lfunLE->setText(item->text(0));
2639 save_lfun_ = item->text(0);
2640 shortcut_->shortcutWG->setText(item->text(1));
2642 seq.parse(fromqstr(item->data(1, Qt::UserRole).toString()));
2643 shortcut_->shortcutWG->setKeySequence(seq);
2644 shortcut_->shortcutWG->setFocus();
2650 void PrefShortcuts::removeShortcut()
2652 // it seems that only one item can be selected, but I am
2653 // removing all selected items anyway.
2654 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2655 for (int i = 0; i < items.size(); ++i) {
2656 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2657 string lfun = fromqstr(items[i]->text(0));
2658 FuncRequest func = lyxaction.lookupFunc(lfun);
2659 KeyMap::ItemType tag =
2660 static_cast<KeyMap::ItemType>(items[i]->data(0, Qt::UserRole).toInt());
2663 case KeyMap::System: {
2664 // for system bind, we do not touch the item
2665 // but add an user unbind item
2666 user_unbind_.bind(shortcut, func);
2667 setItemType(items[i], KeyMap::UserUnbind);
2668 removePB->setText(qt_("Res&tore"));
2671 case KeyMap::UserBind: {
2672 // for user_bind, we remove this bind
2673 QTreeWidgetItem * parent = items[i]->parent();
2674 int itemIdx = parent->indexOfChild(items[i]);
2675 parent->takeChild(itemIdx);
2677 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2679 shortcutsTW->scrollToItem(parent);
2680 user_bind_.unbind(shortcut, func);
2683 case KeyMap::UserUnbind: {
2684 // for user_unbind, we remove the unbind, and the item
2685 // become KeyMap::System again.
2686 user_unbind_.unbind(shortcut, func);
2687 setItemType(items[i], KeyMap::System);
2688 removePB->setText(qt_("Remo&ve"));
2691 case KeyMap::UserExtraUnbind: {
2692 // for user unbind that is not in system bind file,
2693 // remove this unbind file
2694 QTreeWidgetItem * parent = items[i]->parent();
2695 parent->takeChild(parent->indexOfChild(items[i]));
2696 user_unbind_.unbind(shortcut, func);
2703 void PrefShortcuts::selectBind()
2705 QString file = form_->browsebind(internalPath(bindFileED->text()));
2706 if (!file.isEmpty()) {
2707 bindFileED->setText(file);
2708 system_bind_ = KeyMap();
2709 system_bind_.read(fromqstr(file));
2710 updateShortcutsTW();
2715 void PrefShortcuts::on_modifyPB_pressed()
2721 void PrefShortcuts::on_newPB_pressed()
2723 shortcut_->lfunLE->clear();
2724 shortcut_->shortcutWG->reset();
2725 save_lfun_ = QString();
2730 void PrefShortcuts::on_removePB_pressed()
2736 void PrefShortcuts::on_searchLE_textEdited()
2738 if (searchLE->text().isEmpty()) {
2739 // show all hidden items
2740 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2742 shortcutsTW->setItemHidden(*it++, false);
2745 // search both columns
2746 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2747 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2748 matched += shortcutsTW->findItems(searchLE->text(),
2749 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2751 // hide everyone (to avoid searching in matched QList repeatedly
2752 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2754 shortcutsTW->setItemHidden(*it++, true);
2755 // show matched items
2756 for (int i = 0; i < matched.size(); ++i) {
2757 shortcutsTW->setItemHidden(matched[i], false);
2758 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2763 docstring makeCmdString(FuncRequest const & f)
2765 docstring actionStr = from_ascii(lyxaction.getActionName(f.action));
2766 if (!f.argument().empty())
2767 actionStr += " " + f.argument();
2772 void PrefShortcuts::shortcutOkPressed()
2774 QString const new_lfun = shortcut_->lfunLE->text();
2775 FuncRequest func = lyxaction.lookupFunc(fromqstr(new_lfun));
2777 if (func.action == LFUN_UNKNOWN_ACTION) {
2778 Alert::error(_("Failed to create shortcut"),
2779 _("Unknown or invalid LyX function"));
2783 KeySequence k = shortcut_->shortcutWG->getKeySequence();
2784 if (k.length() == 0) {
2785 Alert::error(_("Failed to create shortcut"),
2786 _("Invalid or empty key sequence"));
2790 // check to see if there's been any change
2791 FuncRequest oldBinding = system_bind_.getBinding(k);
2792 if (oldBinding.action == LFUN_UNKNOWN_ACTION)
2793 oldBinding = user_bind_.getBinding(k);
2794 if (oldBinding == func) {
2795 docstring const actionStr = makeCmdString(func);
2796 Alert::error(_("Failed to create shortcut"),
2797 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s"),
2798 k.print(KeySequence::ForGui), actionStr));
2802 // make sure this key isn't already bound---and, if so, not unbound
2803 FuncCode const unbind = user_unbind_.getBinding(k).action;
2804 if (oldBinding.action != LFUN_UNKNOWN_ACTION && unbind == LFUN_UNKNOWN_ACTION)
2806 // FIXME Perhaps we should offer to over-write the old shortcut?
2807 // If so, we'll need to remove it from our list, etc.
2808 docstring const actionStr = makeCmdString(oldBinding);
2809 Alert::error(_("Failed to create shortcut"),
2810 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s\n"
2811 "You need to remove that binding before creating a new one."),
2812 k.print(KeySequence::ForGui), actionStr));
2816 if (!save_lfun_.isEmpty() && new_lfun == save_lfun_)
2817 // real modification of the lfun's shortcut,
2818 // so remove the previous one
2821 QTreeWidgetItem * item = insertShortcutItem(func, k, KeyMap::UserBind);
2823 user_bind_.bind(&k, func);
2824 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2825 shortcutsTW->setItemExpanded(item->parent(), true);
2826 shortcutsTW->scrollToItem(item);
2828 Alert::error(_("Failed to create shortcut"),
2829 _("Can not insert shortcut to the list"));
2835 void PrefShortcuts::shortcutCancelPressed()
2837 shortcut_->shortcutWG->reset();
2841 void PrefShortcuts::shortcutClearPressed()
2843 shortcut_->shortcutWG->reset();
2847 void PrefShortcuts::shortcutRemovePressed()
2849 shortcut_->shortcutWG->removeFromSequence();
2853 /////////////////////////////////////////////////////////////////////
2857 /////////////////////////////////////////////////////////////////////
2859 PrefIdentity::PrefIdentity(GuiPreferences * form)
2860 : PrefModule(QString(), qt_("Identity"), form)
2864 connect(nameED, SIGNAL(textChanged(QString)),
2865 this, SIGNAL(changed()));
2866 connect(emailED, SIGNAL(textChanged(QString)),
2867 this, SIGNAL(changed()));
2871 void PrefIdentity::apply(LyXRC & rc) const
2873 rc.user_name = fromqstr(nameED->text());
2874 rc.user_email = fromqstr(emailED->text());
2878 void PrefIdentity::update(LyXRC const & rc)
2880 nameED->setText(toqstr(rc.user_name));
2881 emailED->setText(toqstr(rc.user_email));
2886 /////////////////////////////////////////////////////////////////////
2890 /////////////////////////////////////////////////////////////////////
2892 GuiPreferences::GuiPreferences(GuiView & lv)
2893 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2897 QDialog::setModal(false);
2899 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2900 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2901 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2902 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2904 addModule(new PrefUserInterface(this));
2905 addModule(new PrefEdit(this));
2906 addModule(new PrefShortcuts(this));
2907 addModule(new PrefScreenFonts(this));
2908 addModule(new PrefColors(this));
2909 addModule(new PrefDisplay(this));
2910 addModule(new PrefInput(this));
2911 addModule(new PrefCompletion(this));
2913 addModule(new PrefPaths(this));
2915 addModule(new PrefIdentity(this));
2917 addModule(new PrefLanguage(this));
2918 addModule(new PrefSpellchecker(this));
2920 addModule(new PrefPrinter(this));
2921 PrefDate * dateFormat = new PrefDate(this);
2922 addModule(dateFormat);
2923 addModule(new PrefPlaintext(this));
2924 addModule(new PrefLatex(this));
2926 PrefConverters * converters = new PrefConverters(this);
2927 PrefFileformats * formats = new PrefFileformats(this);
2928 connect(formats, SIGNAL(formatsChanged()),
2929 converters, SLOT(updateGui()));
2930 addModule(converters);
2933 prefsPS->setCurrentPanel(qt_("User interface"));
2934 // FIXME: hack to work around resizing bug in Qt >= 4.2
2935 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2936 #if QT_VERSION >= 0x040200
2937 prefsPS->updateGeometry();
2940 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2942 bc().setApply(applyPB);
2943 bc().setCancel(closePB);
2944 bc().setRestore(restorePB);
2946 // initialize the strftime validator
2947 bc().addCheckedLineEdit(dateFormat->DateED);
2951 void GuiPreferences::addModule(PrefModule * module)
2953 LASSERT(module, return);
2954 if (module->category().isEmpty())
2955 prefsPS->addPanel(module, module->title());
2957 prefsPS->addPanel(module, module->title(), module->category());
2958 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2959 modules_.push_back(module);
2963 void GuiPreferences::change_adaptor()
2969 void GuiPreferences::apply(LyXRC & rc) const
2971 size_t end = modules_.size();
2972 for (size_t i = 0; i != end; ++i)
2973 modules_[i]->apply(rc);
2977 void GuiPreferences::updateRc(LyXRC const & rc)
2979 size_t const end = modules_.size();
2980 for (size_t i = 0; i != end; ++i)
2981 modules_[i]->update(rc);
2985 void GuiPreferences::applyView()
2990 bool GuiPreferences::initialiseParams(string const &)
2993 formats_ = lyx::formats;
2994 converters_ = theConverters();
2995 converters_.update(formats_);
2996 movers_ = theMovers();
2998 update_screen_font_ = false;
3001 // Make sure that the bc is in the INITIAL state
3002 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3009 void GuiPreferences::dispatchParams()
3012 rc_.write(ss, true);
3013 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
3014 // FIXME: these need lfuns
3016 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
3018 lyx::formats = formats_;
3020 theConverters() = converters_;
3021 theConverters().update(lyx::formats);
3022 theConverters().buildGraph();
3024 theMovers() = movers_;
3026 vector<string>::const_iterator it = colors_.begin();
3027 vector<string>::const_iterator const end = colors_.end();
3028 for (; it != end; ++it)
3029 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
3032 if (update_screen_font_) {
3033 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
3034 update_screen_font_ = false;
3037 // The Save button has been pressed
3039 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
3043 void GuiPreferences::setColor(ColorCode col, QString const & hex)
3045 colors_.push_back(lcolor.getLyXName(col) + ' ' + fromqstr(hex));
3049 void GuiPreferences::updateScreenFonts()
3051 update_screen_font_ = true;
3055 QString GuiPreferences::browsebind(QString const & file) const
3057 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
3058 QStringList(qt_("LyX bind files (*.bind)")));
3062 QString GuiPreferences::browseUI(QString const & file) const
3064 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
3065 QStringList(qt_("LyX UI files (*.ui)")));
3069 QString GuiPreferences::browsekbmap(QString const & file) const
3071 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
3072 QStringList(qt_("LyX keyboard maps (*.kmap)")));
3076 QString GuiPreferences::browse(QString const & file,
3077 QString const & title) const
3079 return browseFile(file, title, QStringList(), true);
3083 // We support less paper sizes than the document dialog
3084 // Therefore this adjustment is needed.
3085 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
3089 return PAPER_DEFAULT;
3091 return PAPER_USLETTER;
3093 return PAPER_USLEGAL;
3095 return PAPER_USEXECUTIVE;
3105 // should not happen
3106 return PAPER_DEFAULT;
3111 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
3113 switch (papersize) {
3116 case PAPER_USLETTER:
3120 case PAPER_USEXECUTIVE:
3131 // should not happen
3137 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
3140 } // namespace frontend
3143 #include "moc_GuiPrefs.cpp"