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"
25 #include "BufferList.h"
28 #include "ConverterCache.h"
29 #include "FontEnums.h"
30 #include "FuncRequest.h"
32 #include "KeySequence.h"
34 #include "LyXAction.h"
36 #include "PanelStack.h"
39 #include "SpellChecker.h"
41 #include "support/debug.h"
42 #include "support/FileName.h"
43 #include "support/filetools.h"
44 #include "support/foreach.h"
45 #include "support/gettext.h"
46 #include "support/lassert.h"
47 #include "support/lstrings.h"
48 #include "support/os.h"
49 #include "support/Package.h"
51 #include "graphics/GraphicsTypes.h"
53 #include "frontends/alert.h"
54 #include "frontends/Application.h"
55 #include "frontends/FontLoader.h"
57 #include <QAbstractItemModel>
59 #include <QColorDialog>
60 #include <QFontDatabase>
61 #include <QHeaderView>
63 #include <QMessageBox>
64 #include <QPixmapCache>
65 #include <QPushButton>
68 #include <QTreeWidget>
69 #include <QTreeWidgetItem>
79 using namespace lyx::support;
80 using namespace lyx::support::os;
85 /////////////////////////////////////////////////////////////////////
89 /////////////////////////////////////////////////////////////////////
91 /** Launch a file dialog and return the chosen file.
92 filename: a suggested filename.
93 title: the title of the dialog.
95 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
97 QString browseFile(QString const & filename,
98 QString const & title,
99 QStringList const & filters,
101 QString const & label1 = QString(),
102 QString const & dir1 = QString(),
103 QString const & label2 = QString(),
104 QString const & dir2 = QString(),
105 QString const & fallback_dir = QString())
107 QString lastPath = ".";
108 if (!filename.isEmpty())
109 lastPath = onlyPath(filename);
110 else if(!fallback_dir.isEmpty())
111 lastPath = fallback_dir;
113 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
114 dlg.setButton2(label1, dir1);
115 dlg.setButton2(label2, dir2);
117 FileDialog::Result result;
120 result = dlg.save(lastPath, filters, onlyFileName(filename));
122 result = dlg.open(lastPath, filters, onlyFileName(filename));
124 return result.second;
128 /** Wrapper around browseFile which tries to provide a filename
129 * relative to the user or system directory. The dir, name and ext
130 * parameters have the same meaning as in the
131 * support::LibFileSearch function.
133 QString browseLibFile(QString const & dir,
134 QString const & name,
136 QString const & title,
137 QStringList const & filters)
140 QString const label1 = qt_("System files|#S#s");
142 toqstr(addName(package().system_support().absFileName(), fromqstr(dir)));
144 QString const label2 = qt_("User files|#U#u");
146 toqstr(addName(package().user_support().absFileName(), fromqstr(dir)));
148 QString const result = browseFile(toqstr(
149 libFileSearch(dir, name, ext).absFileName()),
150 title, filters, false, dir1, dir2, QString(), QString(), dir1);
152 // remove the extension if it is the default one
154 if (getExtension(result) == ext)
155 noextresult = removeExtension(result);
157 noextresult = result;
159 // remove the directory, if it is the default one
160 QString const file = onlyFileName(noextresult);
161 if (toqstr(libFileSearch(dir, file, ext).absFileName()) == result)
168 /** Launch a file dialog and return the chosen directory.
169 pathname: a suggested pathname.
170 title: the title of the dialog.
171 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
173 QString browseDir(QString const & pathname,
174 QString const & title,
175 QString const & label1 = QString(),
176 QString const & dir1 = QString(),
177 QString const & label2 = QString(),
178 QString const & dir2 = QString())
180 QString lastPath = ".";
181 if (!pathname.isEmpty())
182 lastPath = onlyPath(pathname);
184 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
185 dlg.setButton1(label1, dir1);
186 dlg.setButton2(label2, dir2);
188 FileDialog::Result const result =
189 dlg.opendir(lastPath, onlyFileName(pathname));
191 return result.second;
195 } // namespace frontend
198 QString browseRelToParent(QString const & filename, QString const & relpath,
199 QString const & title, QStringList const & filters, bool save,
200 QString const & label1, QString const & dir1,
201 QString const & label2, QString const & dir2)
203 QString const fname = makeAbsPath(filename, relpath);
205 QString const outname =
206 frontend::browseFile(fname, title, filters, save, label1, dir1, label2, dir2);
208 QString const reloutname =
209 toqstr(makeRelPath(qstring_to_ucs4(outname), qstring_to_ucs4(relpath)));
211 if (reloutname.startsWith("../"))
218 QString browseRelToSub(QString const & filename, QString const & relpath,
219 QString const & title, QStringList const & filters, bool save,
220 QString const & label1, QString const & dir1,
221 QString const & label2, QString const & dir2)
223 QString const fname = makeAbsPath(filename, relpath);
225 QString const outname =
226 frontend::browseFile(fname, title, filters, save, label1, dir1, label2, dir2);
228 QString const reloutname =
229 toqstr(makeRelPath(qstring_to_ucs4(outname), qstring_to_ucs4(relpath)));
231 QString testname = reloutname;
232 testname.remove(QRegExp("^(\\.\\./)+"));
234 if (testname.contains("/"))
242 /////////////////////////////////////////////////////////////////////
246 /////////////////////////////////////////////////////////////////////
250 string const catLookAndFeel = N_("Look & Feel");
251 string const catEditing = N_("Editing");
252 string const catLanguage = N_("Language Settings");
253 string const catOutput = N_("Output");
254 string const catFiles = N_("File Handling");
256 static void parseFontName(QString const & mangled0,
257 string & name, string & foundry)
259 string mangled = fromqstr(mangled0);
260 size_t const idx = mangled.find('[');
261 if (idx == string::npos || idx == 0) {
265 name = mangled.substr(0, idx - 1),
266 foundry = mangled.substr(idx + 1, mangled.size() - idx - 2);
271 static void setComboxFont(QComboBox * cb, string const & family,
272 string const & foundry)
274 QString fontname = toqstr(family);
275 if (!foundry.empty())
276 fontname += " [" + toqstr(foundry) + ']';
278 for (int i = 0; i != cb->count(); ++i) {
279 if (cb->itemText(i) == fontname) {
280 cb->setCurrentIndex(i);
285 // Try matching without foundry name
287 // We count in reverse in order to prefer the Xft foundry
288 for (int i = cb->count(); --i >= 0;) {
289 string name, foundry;
290 parseFontName(cb->itemText(i), name, foundry);
291 if (compare_ascii_no_case(name, family) == 0) {
292 cb->setCurrentIndex(i);
297 // family alone can contain e.g. "Helvetica [Adobe]"
298 string tmpname, tmpfoundry;
299 parseFontName(toqstr(family), tmpname, tmpfoundry);
301 // We count in reverse in order to prefer the Xft foundry
302 for (int i = cb->count(); --i >= 0; ) {
303 string name, foundry;
304 parseFontName(cb->itemText(i), name, foundry);
305 if (compare_ascii_no_case(name, foundry) == 0) {
306 cb->setCurrentIndex(i);
311 // Bleh, default fonts, and the names couldn't be found. Hack
315 font.setKerning(false);
317 QString const font_family = toqstr(family);
318 if (font_family == guiApp->romanFontName()) {
319 font.setStyleHint(QFont::Serif);
320 font.setFamily(font_family);
321 } else if (font_family == guiApp->sansFontName()) {
322 font.setStyleHint(QFont::SansSerif);
323 font.setFamily(font_family);
324 } else if (font_family == guiApp->typewriterFontName()) {
325 font.setStyleHint(QFont::TypeWriter);
326 font.setFamily(font_family);
328 LYXERR0("FAILED to find the default font: '"
329 << foundry << "', '" << family << '\'');
333 QFontInfo info(font);
334 string default_font_name, dummyfoundry;
335 parseFontName(info.family(), default_font_name, dummyfoundry);
336 LYXERR0("Apparent font is " << default_font_name);
338 for (int i = 0; i < cb->count(); ++i) {
339 LYXERR0("Looking at " << cb->itemText(i));
340 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
341 default_font_name) == 0) {
342 cb->setCurrentIndex(i);
347 LYXERR0("FAILED to find the font: '"
348 << foundry << "', '" << family << '\'');
352 /////////////////////////////////////////////////////////////////////
354 // NoNewLineValidator
356 /////////////////////////////////////////////////////////////////////
358 class NoNewLineValidator : public QValidator
361 NoNewLineValidator(QWidget *);
362 QValidator::State validate(QString & input, int & pos) const;
366 NoNewLineValidator::NoNewLineValidator(QWidget * parent)
372 QValidator::State NoNewLineValidator::validate(QString & input, int & /*pos*/) const
374 input.remove(QRegExp("[\\n\\r]"));
375 return QValidator::Acceptable;
379 /////////////////////////////////////////////////////////////////////
383 /////////////////////////////////////////////////////////////////////
385 class StrftimeValidator : public QValidator
388 StrftimeValidator(QWidget *);
389 QValidator::State validate(QString & input, int & pos) const;
393 StrftimeValidator::StrftimeValidator(QWidget * parent)
399 QValidator::State StrftimeValidator::validate(QString & input, int & /*pos*/) const
401 if (is_valid_strftime(fromqstr(input)))
402 return QValidator::Acceptable;
404 return QValidator::Intermediate;
408 /////////////////////////////////////////////////////////////////////
412 /////////////////////////////////////////////////////////////////////
414 PrefOutput::PrefOutput(GuiPreferences * form)
415 : PrefModule(qt_(catOutput), qt_("General"), form)
419 DateED->setValidator(new StrftimeValidator(DateED));
420 dviCB->setValidator(new NoNewLineValidator(dviCB));
421 pdfCB->setValidator(new NoNewLineValidator(pdfCB));
423 connect(DateED, SIGNAL(textChanged(QString)),
424 this, SIGNAL(changed()));
425 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
426 this, SIGNAL(changed()));
427 connect(overwriteCO, SIGNAL(activated(int)),
428 this, SIGNAL(changed()));
429 connect(dviCB, SIGNAL(editTextChanged(QString)),
430 this, SIGNAL(changed()));
431 connect(pdfCB, SIGNAL(editTextChanged(QString)),
432 this, SIGNAL(changed()));
434 dviCB->addItem("xdvi -sourceposition '$$n:\\ $$t' $$o");
435 dviCB->addItem("yap -1 -s \"$$n $$t\" $$o");
436 dviCB->addItem("okular --unique \"file:$$o#src:$$n $$t\"");
437 dviCB->addItem("synctex view -i $$n:0:$$t -o $$o -x \"evince -i %{page+1} $$o\"");
439 pdfCB->addItem("CMCDDE SUMATRA control [ForwardSearch(\\\"$$o\\\",\\\"$$t\\\",$$n,0,0,1)]");
440 pdfCB->addItem("synctex view -i $$n:0:$$t -o $$o -x \"xpdf -raise -remote $$t.tmp $$o %{page+1}\"");
441 pdfCB->addItem("okular --unique \"file:$$o#src:$$n $$t\"");
442 pdfCB->addItem("synctex view -i $$n:0:$$t -o $$o -x \"evince -i %{page+1} $$o\"");
443 pdfCB->addItem("/Applications/Skim.app/Contents/SharedSupport/displayline $$n $$o $$t");
447 void PrefOutput::on_DateED_textChanged(const QString &)
449 QString t = DateED->text();
451 bool valid = DateED->validator()->validate(t, p)
452 == QValidator::Acceptable;
453 setValid(DateLA, valid);
457 void PrefOutput::apply(LyXRC & rc) const
459 rc.date_insert_format = fromqstr(DateED->text());
460 rc.plaintext_linelen = plaintextLinelengthSB->value();
461 rc.forward_search_dvi = fromqstr(dviCB->currentText());
462 rc.forward_search_pdf = fromqstr(pdfCB->currentText());
464 switch (overwriteCO->currentIndex()) {
466 rc.export_overwrite = NO_FILES;
469 rc.export_overwrite = MAIN_FILE;
472 rc.export_overwrite = ALL_FILES;
478 void PrefOutput::update(LyXRC const & rc)
480 DateED->setText(toqstr(rc.date_insert_format));
481 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
482 dviCB->setEditText(toqstr(rc.forward_search_dvi));
483 pdfCB->setEditText(toqstr(rc.forward_search_pdf));
485 switch (rc.export_overwrite) {
487 overwriteCO->setCurrentIndex(0);
490 overwriteCO->setCurrentIndex(1);
493 overwriteCO->setCurrentIndex(2);
499 /////////////////////////////////////////////////////////////////////
503 /////////////////////////////////////////////////////////////////////
505 PrefInput::PrefInput(GuiPreferences * form)
506 : PrefModule(qt_(catEditing), qt_("Keyboard/Mouse"), form)
510 connect(keymapCB, SIGNAL(clicked()),
511 this, SIGNAL(changed()));
512 connect(firstKeymapED, SIGNAL(textChanged(QString)),
513 this, SIGNAL(changed()));
514 connect(secondKeymapED, SIGNAL(textChanged(QString)),
515 this, SIGNAL(changed()));
516 connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
517 this, SIGNAL(changed()));
518 connect(scrollzoomEnableCB, SIGNAL(clicked()),
519 this, SIGNAL(changed()));
520 connect(scrollzoomValueCO, SIGNAL(activated(int)),
521 this, SIGNAL(changed()));
522 connect(dontswapCB, SIGNAL(toggled(bool)),
523 this, SIGNAL(changed()));
525 // reveal checkbox for switching Ctrl and Meta on Mac:
528 #if QT_VERSION > 0x040600
532 dontswapCB->setVisible(swapcb);
536 void PrefInput::apply(LyXRC & rc) const
538 // FIXME: can derive CB from the two EDs
539 rc.use_kbmap = keymapCB->isChecked();
540 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
541 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
542 rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
543 if (scrollzoomEnableCB->isChecked()) {
544 switch (scrollzoomValueCO->currentIndex()) {
546 rc.scroll_wheel_zoom = LyXRC::SCROLL_WHEEL_ZOOM_CTRL;
549 rc.scroll_wheel_zoom = LyXRC::SCROLL_WHEEL_ZOOM_SHIFT;
552 rc.scroll_wheel_zoom = LyXRC::SCROLL_WHEEL_ZOOM_ALT;
556 rc.scroll_wheel_zoom = LyXRC::SCROLL_WHEEL_ZOOM_OFF;
558 rc.mac_dontswap_ctrl_meta = dontswapCB->isChecked();
562 void PrefInput::update(LyXRC const & rc)
564 // FIXME: can derive CB from the two EDs
565 keymapCB->setChecked(rc.use_kbmap);
566 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
567 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
568 mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
569 switch (rc.scroll_wheel_zoom) {
570 case LyXRC::SCROLL_WHEEL_ZOOM_OFF:
571 scrollzoomEnableCB->setChecked(false);
573 case LyXRC::SCROLL_WHEEL_ZOOM_CTRL:
574 scrollzoomEnableCB->setChecked(true);
575 scrollzoomValueCO->setCurrentIndex(0);
577 case LyXRC::SCROLL_WHEEL_ZOOM_SHIFT:
578 scrollzoomEnableCB->setChecked(true);
579 scrollzoomValueCO->setCurrentIndex(1);
581 case LyXRC::SCROLL_WHEEL_ZOOM_ALT:
582 scrollzoomEnableCB->setChecked(true);
583 scrollzoomValueCO->setCurrentIndex(2);
586 dontswapCB->setChecked(rc.mac_dontswap_ctrl_meta);
590 QString PrefInput::testKeymap(QString const & keymap)
592 return form_->browsekbmap(internalPath(keymap));
596 void PrefInput::on_firstKeymapPB_clicked(bool)
598 QString const file = testKeymap(firstKeymapED->text());
600 firstKeymapED->setText(file);
604 void PrefInput::on_secondKeymapPB_clicked(bool)
606 QString const file = testKeymap(secondKeymapED->text());
608 secondKeymapED->setText(file);
612 void PrefInput::on_keymapCB_toggled(bool keymap)
614 firstKeymapLA->setEnabled(keymap);
615 secondKeymapLA->setEnabled(keymap);
616 firstKeymapED->setEnabled(keymap);
617 secondKeymapED->setEnabled(keymap);
618 firstKeymapPB->setEnabled(keymap);
619 secondKeymapPB->setEnabled(keymap);
623 void PrefInput::on_scrollzoomEnableCB_toggled(bool enabled)
625 scrollzoomValueCO->setEnabled(enabled);
629 /////////////////////////////////////////////////////////////////////
633 /////////////////////////////////////////////////////////////////////
635 PrefCompletion::PrefCompletion(GuiPreferences * form)
636 : PrefModule(qt_(catEditing), qt_("Input Completion"), form)
640 connect(inlineDelaySB, SIGNAL(valueChanged(double)),
641 this, SIGNAL(changed()));
642 connect(inlineMathCB, SIGNAL(clicked()),
643 this, SIGNAL(changed()));
644 connect(inlineTextCB, SIGNAL(clicked()),
645 this, SIGNAL(changed()));
646 connect(inlineDotsCB, SIGNAL(clicked()),
647 this, SIGNAL(changed()));
648 connect(popupDelaySB, SIGNAL(valueChanged(double)),
649 this, SIGNAL(changed()));
650 connect(popupMathCB, SIGNAL(clicked()),
651 this, SIGNAL(changed()));
652 connect(autocorrectionCB, SIGNAL(clicked()),
653 this, SIGNAL(changed()));
654 connect(popupTextCB, SIGNAL(clicked()),
655 this, SIGNAL(changed()));
656 connect(popupAfterCompleteCB, SIGNAL(clicked()),
657 this, SIGNAL(changed()));
658 connect(cursorTextCB, SIGNAL(clicked()),
659 this, SIGNAL(changed()));
663 void PrefCompletion::on_inlineTextCB_clicked()
669 void PrefCompletion::on_popupTextCB_clicked()
675 void PrefCompletion::enableCB()
677 cursorTextCB->setEnabled(
678 popupTextCB->isChecked() || inlineTextCB->isChecked());
682 void PrefCompletion::apply(LyXRC & rc) const
684 rc.completion_inline_delay = inlineDelaySB->value();
685 rc.completion_inline_math = inlineMathCB->isChecked();
686 rc.completion_inline_text = inlineTextCB->isChecked();
687 rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
688 rc.completion_popup_delay = popupDelaySB->value();
689 rc.completion_popup_math = popupMathCB->isChecked();
690 rc.autocorrection_math = autocorrectionCB->isChecked();
691 rc.completion_popup_text = popupTextCB->isChecked();
692 rc.completion_cursor_text = cursorTextCB->isChecked();
693 rc.completion_popup_after_complete =
694 popupAfterCompleteCB->isChecked();
698 void PrefCompletion::update(LyXRC const & rc)
700 inlineDelaySB->setValue(rc.completion_inline_delay);
701 inlineMathCB->setChecked(rc.completion_inline_math);
702 inlineTextCB->setChecked(rc.completion_inline_text);
703 inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
704 popupDelaySB->setValue(rc.completion_popup_delay);
705 popupMathCB->setChecked(rc.completion_popup_math);
706 autocorrectionCB->setChecked(rc.autocorrection_math);
707 popupTextCB->setChecked(rc.completion_popup_text);
708 cursorTextCB->setChecked(rc.completion_cursor_text);
709 popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
715 /////////////////////////////////////////////////////////////////////
719 /////////////////////////////////////////////////////////////////////
721 PrefLatex::PrefLatex(GuiPreferences * form)
722 : PrefModule(qt_(catOutput), qt_("LaTeX"), form)
726 latexEncodingED->setValidator(new NoNewLineValidator(latexEncodingED));
727 latexDviPaperED->setValidator(new NoNewLineValidator(latexDviPaperED));
728 latexBibtexED->setValidator(new NoNewLineValidator(latexBibtexED));
729 latexJBibtexED->setValidator(new NoNewLineValidator(latexJBibtexED));
730 latexIndexED->setValidator(new NoNewLineValidator(latexIndexED));
731 latexJIndexED->setValidator(new NoNewLineValidator(latexJIndexED));
732 latexNomenclED->setValidator(new NoNewLineValidator(latexNomenclED));
733 latexChecktexED->setValidator(new NoNewLineValidator(latexChecktexED));
735 connect(latexEncodingCB, SIGNAL(clicked()),
736 this, SIGNAL(changed()));
737 connect(latexEncodingED, SIGNAL(textChanged(QString)),
738 this, SIGNAL(changed()));
739 connect(latexChecktexED, SIGNAL(textChanged(QString)),
740 this, SIGNAL(changed()));
741 connect(latexBibtexCO, SIGNAL(activated(int)),
742 this, SIGNAL(changed()));
743 connect(latexBibtexED, SIGNAL(textChanged(QString)),
744 this, SIGNAL(changed()));
745 connect(latexJBibtexED, SIGNAL(textChanged(QString)),
746 this, SIGNAL(changed()));
747 connect(latexIndexCO, SIGNAL(activated(int)),
748 this, SIGNAL(changed()));
749 connect(latexIndexED, SIGNAL(textChanged(QString)),
750 this, SIGNAL(changed()));
751 connect(latexJIndexED, SIGNAL(textChanged(QString)),
752 this, SIGNAL(changed()));
753 connect(latexAutoresetCB, SIGNAL(clicked()),
754 this, SIGNAL(changed()));
755 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
756 this, SIGNAL(changed()));
757 connect(latexPaperSizeCO, SIGNAL(activated(int)),
758 this, SIGNAL(changed()));
759 connect(latexNomenclED, SIGNAL(textChanged(QString)),
760 this, SIGNAL(changed()));
762 #if defined(__CYGWIN__) || defined(_WIN32)
763 pathCB->setVisible(true);
764 connect(pathCB, SIGNAL(clicked()),
765 this, SIGNAL(changed()));
767 pathCB->setVisible(false);
772 void PrefLatex::on_latexEncodingCB_stateChanged(int state)
774 latexEncodingED->setEnabled(state == Qt::Checked);
778 void PrefLatex::on_latexBibtexCO_activated(int n)
780 QString const bibtex = latexBibtexCO->itemData(n).toString();
781 if (bibtex.isEmpty()) {
782 latexBibtexED->clear();
783 latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
786 for (LyXRC::CommandSet::const_iterator it = bibtex_alternatives.begin();
787 it != bibtex_alternatives.end(); ++it) {
788 QString const bib = toqstr(*it);
789 int ind = bib.indexOf(" ");
790 QString sel_command = bib.left(ind);
791 QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
792 if (bibtex == sel_command) {
794 latexBibtexED->clear();
796 latexBibtexED->setText(sel_options.trimmed());
799 latexBibtexOptionsLA->setText(qt_("&Options:"));
803 void PrefLatex::on_latexIndexCO_activated(int n)
805 QString const index = latexIndexCO->itemData(n).toString();
806 if (index.isEmpty()) {
807 latexIndexED->clear();
808 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
811 for (LyXRC::CommandSet::const_iterator it = index_alternatives.begin();
812 it != index_alternatives.end(); ++it) {
813 QString const idx = toqstr(*it);
814 int ind = idx.indexOf(" ");
815 QString sel_command = idx.left(ind);
816 QString sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
817 if (index == sel_command) {
819 latexIndexED->clear();
821 latexIndexED->setText(sel_options.trimmed());
824 latexIndexOptionsLA->setText(qt_("Op&tions:"));
828 void PrefLatex::apply(LyXRC & rc) const
830 // If bibtex is not empty, bibopt contains the options, otherwise
831 // it is a customized bibtex command with options.
832 QString const bibtex = latexBibtexCO->itemData(
833 latexBibtexCO->currentIndex()).toString();
834 QString const bibopt = latexBibtexED->text();
835 if (bibtex.isEmpty())
836 rc.bibtex_command = fromqstr(bibopt);
837 else if (bibopt.isEmpty())
838 rc.bibtex_command = fromqstr(bibtex);
840 rc.bibtex_command = fromqstr(bibtex) + " " + fromqstr(bibopt);
842 // If index is not empty, idxopt contains the options, otherwise
843 // it is a customized index command with options.
844 QString const index = latexIndexCO->itemData(
845 latexIndexCO->currentIndex()).toString();
846 QString const idxopt = latexIndexED->text();
848 rc.index_command = fromqstr(idxopt);
849 else if (idxopt.isEmpty())
850 rc.index_command = fromqstr(index);
852 rc.index_command = fromqstr(index) + " " + fromqstr(idxopt);
854 if (latexEncodingCB->isChecked())
855 rc.fontenc = fromqstr(latexEncodingED->text());
857 rc.fontenc = "default";
858 rc.chktex_command = fromqstr(latexChecktexED->text());
859 rc.jbibtex_command = fromqstr(latexJBibtexED->text());
860 rc.jindex_command = fromqstr(latexJIndexED->text());
861 rc.nomencl_command = fromqstr(latexNomenclED->text());
862 rc.auto_reset_options = latexAutoresetCB->isChecked();
863 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
864 rc.default_papersize =
865 form_->toPaperSize(latexPaperSizeCO->currentIndex());
866 #if defined(__CYGWIN__) || defined(_WIN32)
867 rc.windows_style_tex_paths = pathCB->isChecked();
872 void PrefLatex::update(LyXRC const & rc)
874 latexBibtexCO->clear();
876 latexBibtexCO->addItem(qt_("Custom"), QString());
877 for (LyXRC::CommandSet::const_iterator it = rc.bibtex_alternatives.begin();
878 it != rc.bibtex_alternatives.end(); ++it) {
879 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
880 latexBibtexCO->addItem(command, command);
883 bibtex_alternatives = rc.bibtex_alternatives;
885 QString const bib = toqstr(rc.bibtex_command);
886 int ind = bib.indexOf(" ");
887 QString sel_command = bib.left(ind);
888 QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
890 int pos = latexBibtexCO->findData(sel_command);
892 latexBibtexCO->setCurrentIndex(pos);
893 latexBibtexED->setText(sel_options.trimmed());
894 latexBibtexOptionsLA->setText(qt_("&Options:"));
896 latexBibtexED->setText(toqstr(rc.bibtex_command));
897 latexBibtexCO->setCurrentIndex(0);
898 latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
901 latexIndexCO->clear();
903 latexIndexCO->addItem(qt_("Custom"), QString());
904 for (LyXRC::CommandSet::const_iterator it = rc.index_alternatives.begin();
905 it != rc.index_alternatives.end(); ++it) {
906 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
907 latexIndexCO->addItem(command, command);
910 index_alternatives = rc.index_alternatives;
912 QString const idx = toqstr(rc.index_command);
913 ind = idx.indexOf(" ");
914 sel_command = idx.left(ind);
915 sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
917 pos = latexIndexCO->findData(sel_command);
919 latexIndexCO->setCurrentIndex(pos);
920 latexIndexED->setText(sel_options.trimmed());
921 latexIndexOptionsLA->setText(qt_("Op&tions:"));
923 latexIndexED->setText(toqstr(rc.index_command));
924 latexIndexCO->setCurrentIndex(0);
925 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
928 if (rc.fontenc == "default") {
929 latexEncodingCB->setChecked(false);
930 latexEncodingED->setEnabled(false);
932 latexEncodingCB->setChecked(true);
933 latexEncodingED->setEnabled(true);
934 latexEncodingED->setText(toqstr(rc.fontenc));
936 latexChecktexED->setText(toqstr(rc.chktex_command));
937 latexJBibtexED->setText(toqstr(rc.jbibtex_command));
938 latexJIndexED->setText(toqstr(rc.jindex_command));
939 latexNomenclED->setText(toqstr(rc.nomencl_command));
940 latexAutoresetCB->setChecked(rc.auto_reset_options);
941 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
942 latexPaperSizeCO->setCurrentIndex(
943 form_->fromPaperSize(rc.default_papersize));
944 #if defined(__CYGWIN__) || defined(_WIN32)
945 pathCB->setChecked(rc.windows_style_tex_paths);
950 /////////////////////////////////////////////////////////////////////
954 /////////////////////////////////////////////////////////////////////
956 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form)
957 : PrefModule(qt_(catLookAndFeel), qt_("Screen Fonts"), form)
961 connect(screenRomanCO, SIGNAL(activated(QString)),
962 this, SLOT(selectRoman(QString)));
963 connect(screenSansCO, SIGNAL(activated(QString)),
964 this, SLOT(selectSans(QString)));
965 connect(screenTypewriterCO, SIGNAL(activated(QString)),
966 this, SLOT(selectTypewriter(QString)));
968 QFontDatabase fontdb;
969 QStringList families(fontdb.families());
970 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
971 screenRomanCO->addItem(*it);
972 screenSansCO->addItem(*it);
973 screenTypewriterCO->addItem(*it);
975 connect(screenRomanCO, SIGNAL(activated(QString)),
976 this, SIGNAL(changed()));
977 connect(screenSansCO, SIGNAL(activated(QString)),
978 this, SIGNAL(changed()));
979 connect(screenTypewriterCO, SIGNAL(activated(QString)),
980 this, SIGNAL(changed()));
981 connect(screenZoomSB, SIGNAL(valueChanged(int)),
982 this, SIGNAL(changed()));
983 connect(screenTinyED, SIGNAL(textChanged(QString)),
984 this, SIGNAL(changed()));
985 connect(screenSmallestED, SIGNAL(textChanged(QString)),
986 this, SIGNAL(changed()));
987 connect(screenSmallerED, SIGNAL(textChanged(QString)),
988 this, SIGNAL(changed()));
989 connect(screenSmallED, SIGNAL(textChanged(QString)),
990 this, SIGNAL(changed()));
991 connect(screenNormalED, SIGNAL(textChanged(QString)),
992 this, SIGNAL(changed()));
993 connect(screenLargeED, SIGNAL(textChanged(QString)),
994 this, SIGNAL(changed()));
995 connect(screenLargerED, SIGNAL(textChanged(QString)),
996 this, SIGNAL(changed()));
997 connect(screenLargestED, SIGNAL(textChanged(QString)),
998 this, SIGNAL(changed()));
999 connect(screenHugeED, SIGNAL(textChanged(QString)),
1000 this, SIGNAL(changed()));
1001 connect(screenHugerED, SIGNAL(textChanged(QString)),
1002 this, SIGNAL(changed()));
1003 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
1004 this, SIGNAL(changed()));
1006 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
1007 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
1008 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
1009 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
1010 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
1011 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
1012 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
1013 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
1014 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
1015 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
1019 void PrefScreenFonts::apply(LyXRC & rc) const
1021 LyXRC const oldrc = rc;
1023 parseFontName(screenRomanCO->currentText(),
1024 rc.roman_font_name, rc.roman_font_foundry);
1025 parseFontName(screenSansCO->currentText(),
1026 rc.sans_font_name, rc.sans_font_foundry);
1027 parseFontName(screenTypewriterCO->currentText(),
1028 rc.typewriter_font_name, rc.typewriter_font_foundry);
1030 rc.zoom = screenZoomSB->value();
1031 rc.font_sizes[FONT_SIZE_TINY] = widgetToDoubleStr(screenTinyED);
1032 rc.font_sizes[FONT_SIZE_SCRIPT] = widgetToDoubleStr(screenSmallestED);
1033 rc.font_sizes[FONT_SIZE_FOOTNOTE] = widgetToDoubleStr(screenSmallerED);
1034 rc.font_sizes[FONT_SIZE_SMALL] = widgetToDoubleStr(screenSmallED);
1035 rc.font_sizes[FONT_SIZE_NORMAL] = widgetToDoubleStr(screenNormalED);
1036 rc.font_sizes[FONT_SIZE_LARGE] = widgetToDoubleStr(screenLargeED);
1037 rc.font_sizes[FONT_SIZE_LARGER] = widgetToDoubleStr(screenLargerED);
1038 rc.font_sizes[FONT_SIZE_LARGEST] = widgetToDoubleStr(screenLargestED);
1039 rc.font_sizes[FONT_SIZE_HUGE] = widgetToDoubleStr(screenHugeED);
1040 rc.font_sizes[FONT_SIZE_HUGER] = widgetToDoubleStr(screenHugerED);
1041 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
1043 if (rc.font_sizes != oldrc.font_sizes
1044 || rc.roman_font_name != oldrc.roman_font_name
1045 || rc.sans_font_name != oldrc.sans_font_name
1046 || rc.typewriter_font_name != oldrc.typewriter_font_name
1047 || rc.zoom != oldrc.zoom) {
1048 // The global QPixmapCache is used in GuiPainter to cache text
1049 // painting so we must reset it in case any of the above
1050 // parameter is changed.
1051 QPixmapCache::clear();
1052 guiApp->fontLoader().update();
1053 form_->updateScreenFonts();
1058 void PrefScreenFonts::update(LyXRC const & rc)
1060 setComboxFont(screenRomanCO, rc.roman_font_name,
1061 rc.roman_font_foundry);
1062 setComboxFont(screenSansCO, rc.sans_font_name,
1063 rc.sans_font_foundry);
1064 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
1065 rc.typewriter_font_foundry);
1067 selectRoman(screenRomanCO->currentText());
1068 selectSans(screenSansCO->currentText());
1069 selectTypewriter(screenTypewriterCO->currentText());
1071 screenZoomSB->setValue(rc.zoom);
1072 updateScreenFontSizes(rc);
1074 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
1075 #if defined(Q_WS_X11)
1076 pixmapCacheCB->setEnabled(false);
1082 void PrefScreenFonts::updateScreenFontSizes(LyXRC const & rc)
1084 doubleToWidget(screenTinyED, rc.font_sizes[FONT_SIZE_TINY]);
1085 doubleToWidget(screenSmallestED, rc.font_sizes[FONT_SIZE_SCRIPT]);
1086 doubleToWidget(screenSmallerED, rc.font_sizes[FONT_SIZE_FOOTNOTE]);
1087 doubleToWidget(screenSmallED, rc.font_sizes[FONT_SIZE_SMALL]);
1088 doubleToWidget(screenNormalED, rc.font_sizes[FONT_SIZE_NORMAL]);
1089 doubleToWidget(screenLargeED, rc.font_sizes[FONT_SIZE_LARGE]);
1090 doubleToWidget(screenLargerED, rc.font_sizes[FONT_SIZE_LARGER]);
1091 doubleToWidget(screenLargestED, rc.font_sizes[FONT_SIZE_LARGEST]);
1092 doubleToWidget(screenHugeED, rc.font_sizes[FONT_SIZE_HUGE]);
1093 doubleToWidget(screenHugerED, rc.font_sizes[FONT_SIZE_HUGER]);
1097 void PrefScreenFonts::selectRoman(const QString & name)
1099 screenRomanFE->set(QFont(name), name);
1103 void PrefScreenFonts::selectSans(const QString & name)
1105 screenSansFE->set(QFont(name), name);
1109 void PrefScreenFonts::selectTypewriter(const QString & name)
1111 screenTypewriterFE->set(QFont(name), name);
1115 /////////////////////////////////////////////////////////////////////
1119 /////////////////////////////////////////////////////////////////////
1125 bool operator()(ColorCode lhs, ColorCode rhs) const {
1127 compare_no_case(lcolor.getGUIName(lhs), lcolor.getGUIName(rhs)) < 0;
1133 PrefColors::PrefColors(GuiPreferences * form)
1134 : PrefModule(qt_(catLookAndFeel), qt_("Colors"), form)
1138 // FIXME: all of this initialization should be put into the controller.
1139 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
1140 // for some discussion of why that is not trivial.
1141 QPixmap icon(32, 32);
1142 for (int i = 0; i < Color_ignore; ++i) {
1143 ColorCode lc = static_cast<ColorCode>(i);
1144 if (lc == Color_none
1145 || lc == Color_black
1146 || lc == Color_white
1148 || lc == Color_green
1151 || lc == Color_magenta
1152 || lc == Color_yellow
1153 || lc == Color_inherit
1154 || lc == Color_ignore)
1156 lcolors_.push_back(lc);
1158 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
1159 vector<ColorCode>::const_iterator cit = lcolors_.begin();
1160 vector<ColorCode>::const_iterator const end = lcolors_.end();
1161 for (; cit != end; ++cit) {
1162 (void) new QListWidgetItem(QIcon(icon),
1163 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
1165 curcolors_.resize(lcolors_.size());
1166 newcolors_.resize(lcolors_.size());
1167 // End initialization
1169 connect(colorChangePB, SIGNAL(clicked()),
1170 this, SLOT(changeColor()));
1171 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
1172 this, SLOT(changeLyxObjectsSelection()));
1173 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
1174 this, SLOT(changeColor()));
1175 connect(syscolorsCB, SIGNAL(toggled(bool)),
1176 this, SIGNAL(changed()));
1177 connect(syscolorsCB, SIGNAL(toggled(bool)),
1178 this, SLOT(changeSysColor()));
1182 void PrefColors::apply(LyXRC & rc) const
1186 for (unsigned int i = 0; i < lcolors_.size(); ++i)
1187 if (curcolors_[i] != newcolors_[i])
1188 form_->setColor(lcolors_[i], newcolors_[i]);
1189 rc.use_system_colors = syscolorsCB->isChecked();
1191 if (oldrc.use_system_colors != rc.use_system_colors)
1192 guiApp->colorCache().clear();
1196 void PrefColors::update(LyXRC const & rc)
1198 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
1199 QColor color = QColor(guiApp->colorCache().get(lcolors_[i], false));
1200 QPixmap coloritem(32, 32);
1201 coloritem.fill(color);
1202 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
1203 newcolors_[i] = curcolors_[i] = color.name();
1205 syscolorsCB->setChecked(rc.use_system_colors);
1206 changeLyxObjectsSelection();
1210 void PrefColors::changeColor()
1212 int const row = lyxObjectsLW->currentRow();
1218 QString const color = newcolors_[row];
1219 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
1221 if (c.isValid() && c.name() != color) {
1222 newcolors_[row] = c.name();
1223 QPixmap coloritem(32, 32);
1225 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
1231 void PrefColors::changeSysColor()
1233 for (int row = 0 ; row < lyxObjectsLW->count() ; ++row) {
1234 // skip colors that are taken from system palette
1235 bool const hide = syscolorsCB->isChecked()
1236 && guiApp->colorCache().isSystem(lcolors_[row]);
1238 lyxObjectsLW->item(row)->setHidden(hide);
1243 void PrefColors::changeLyxObjectsSelection()
1245 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
1249 /////////////////////////////////////////////////////////////////////
1253 /////////////////////////////////////////////////////////////////////
1255 PrefDisplay::PrefDisplay(GuiPreferences * form)
1256 : PrefModule(qt_(catLookAndFeel), qt_("Display"), form)
1259 connect(displayGraphicsCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
1260 connect(instantPreviewCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
1261 connect(previewSizeSB, SIGNAL(valueChanged(double)), this, SIGNAL(changed()));
1262 connect(paragraphMarkerCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
1266 void PrefDisplay::on_instantPreviewCO_currentIndexChanged(int index)
1268 previewSizeSB->setEnabled(index != 0);
1272 void PrefDisplay::on_displayGraphicsCB_toggled(bool on)
1274 instantPreviewCO->setEnabled(on);
1275 previewSizeSB->setEnabled(on && instantPreviewCO->currentIndex() > 0);
1279 void PrefDisplay::apply(LyXRC & rc) const
1281 switch (instantPreviewCO->currentIndex()) {
1283 rc.preview = LyXRC::PREVIEW_OFF;
1286 rc.preview = LyXRC::PREVIEW_NO_MATH;
1289 rc.preview = LyXRC::PREVIEW_ON;
1293 rc.display_graphics = displayGraphicsCB->isChecked();
1294 rc.preview_scale_factor = previewSizeSB->value();
1295 rc.paragraph_markers = paragraphMarkerCB->isChecked();
1297 // FIXME!! The graphics cache no longer has a changeDisplay method.
1299 if (old_value != rc.display_graphics) {
1300 graphics::GCache & gc = graphics::GCache::get();
1307 void PrefDisplay::update(LyXRC const & rc)
1309 switch (rc.preview) {
1310 case LyXRC::PREVIEW_OFF:
1311 instantPreviewCO->setCurrentIndex(0);
1313 case LyXRC::PREVIEW_NO_MATH :
1314 instantPreviewCO->setCurrentIndex(1);
1316 case LyXRC::PREVIEW_ON :
1317 instantPreviewCO->setCurrentIndex(2);
1321 displayGraphicsCB->setChecked(rc.display_graphics);
1322 instantPreviewCO->setEnabled(rc.display_graphics);
1323 previewSizeSB->setValue(rc.preview_scale_factor);
1324 paragraphMarkerCB->setChecked(rc.paragraph_markers);
1325 previewSizeSB->setEnabled(
1327 && rc.preview != LyXRC::PREVIEW_OFF);
1331 /////////////////////////////////////////////////////////////////////
1335 /////////////////////////////////////////////////////////////////////
1337 PrefPaths::PrefPaths(GuiPreferences * form)
1338 : PrefModule(QString(), qt_("Paths"), form)
1342 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(selectWorkingdir()));
1343 connect(workingDirED, SIGNAL(textChanged(QString)),
1344 this, SIGNAL(changed()));
1346 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(selectTemplatedir()));
1347 connect(templateDirED, SIGNAL(textChanged(QString)),
1348 this, SIGNAL(changed()));
1350 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(selectExampledir()));
1351 connect(exampleDirED, SIGNAL(textChanged(QString)),
1352 this, SIGNAL(changed()));
1354 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(selectBackupdir()));
1355 connect(backupDirED, SIGNAL(textChanged(QString)),
1356 this, SIGNAL(changed()));
1358 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(selectLyxPipe()));
1359 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
1360 this, SIGNAL(changed()));
1362 connect(thesaurusDirPB, SIGNAL(clicked()), this, SLOT(selectThesaurusdir()));
1363 connect(thesaurusDirED, SIGNAL(textChanged(QString)),
1364 this, SIGNAL(changed()));
1366 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(selectTempdir()));
1367 connect(tempDirED, SIGNAL(textChanged(QString)),
1368 this, SIGNAL(changed()));
1370 #if defined(USE_HUNSPELL)
1371 connect(hunspellDirPB, SIGNAL(clicked()), this, SLOT(selectHunspelldir()));
1372 connect(hunspellDirED, SIGNAL(textChanged(QString)),
1373 this, SIGNAL(changed()));
1375 hunspellDirPB->setEnabled(false);
1376 hunspellDirED->setEnabled(false);
1379 connect(pathPrefixED, SIGNAL(textChanged(QString)),
1380 this, SIGNAL(changed()));
1382 connect(texinputsPrefixED, SIGNAL(textChanged(QString)),
1383 this, SIGNAL(changed()));
1385 pathPrefixED->setValidator(new NoNewLineValidator(pathPrefixED));
1386 texinputsPrefixED->setValidator(new NoNewLineValidator(texinputsPrefixED));
1390 void PrefPaths::apply(LyXRC & rc) const
1392 rc.document_path = internal_path(fromqstr(workingDirED->text()));
1393 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
1394 rc.template_path = internal_path(fromqstr(templateDirED->text()));
1395 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
1396 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
1397 rc.thesaurusdir_path = internal_path(fromqstr(thesaurusDirED->text()));
1398 rc.hunspelldir_path = internal_path(fromqstr(hunspellDirED->text()));
1399 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
1400 rc.texinputs_prefix = internal_path_list(fromqstr(texinputsPrefixED->text()));
1401 // FIXME: should be a checkbox only
1402 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
1406 void PrefPaths::update(LyXRC const & rc)
1408 workingDirED->setText(toqstr(external_path(rc.document_path)));
1409 exampleDirED->setText(toqstr(external_path(rc.example_path)));
1410 templateDirED->setText(toqstr(external_path(rc.template_path)));
1411 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
1412 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
1413 thesaurusDirED->setText(toqstr(external_path(rc.thesaurusdir_path)));
1414 hunspellDirED->setText(toqstr(external_path(rc.hunspelldir_path)));
1415 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
1416 texinputsPrefixED->setText(toqstr(external_path_list(rc.texinputs_prefix)));
1417 // FIXME: should be a checkbox only
1418 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
1422 void PrefPaths::selectExampledir()
1424 QString file = browseDir(internalPath(exampleDirED->text()),
1425 qt_("Select directory for example files"));
1426 if (!file.isEmpty())
1427 exampleDirED->setText(file);
1431 void PrefPaths::selectTemplatedir()
1433 QString file = browseDir(internalPath(templateDirED->text()),
1434 qt_("Select a document templates directory"));
1435 if (!file.isEmpty())
1436 templateDirED->setText(file);
1440 void PrefPaths::selectTempdir()
1442 QString file = browseDir(internalPath(tempDirED->text()),
1443 qt_("Select a temporary directory"));
1444 if (!file.isEmpty())
1445 tempDirED->setText(file);
1449 void PrefPaths::selectBackupdir()
1451 QString file = browseDir(internalPath(backupDirED->text()),
1452 qt_("Select a backups directory"));
1453 if (!file.isEmpty())
1454 backupDirED->setText(file);
1458 void PrefPaths::selectWorkingdir()
1460 QString file = browseDir(internalPath(workingDirED->text()),
1461 qt_("Select a document directory"));
1462 if (!file.isEmpty())
1463 workingDirED->setText(file);
1467 void PrefPaths::selectThesaurusdir()
1469 QString file = browseDir(internalPath(thesaurusDirED->text()),
1470 qt_("Set the path to the thesaurus dictionaries"));
1471 if (!file.isEmpty())
1472 thesaurusDirED->setText(file);
1476 void PrefPaths::selectHunspelldir()
1478 QString file = browseDir(internalPath(hunspellDirED->text()),
1479 qt_("Set the path to the Hunspell dictionaries"));
1480 if (!file.isEmpty())
1481 hunspellDirED->setText(file);
1485 void PrefPaths::selectLyxPipe()
1487 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1488 qt_("Give a filename for the LyX server pipe"));
1489 if (!file.isEmpty())
1490 lyxserverDirED->setText(file);
1494 /////////////////////////////////////////////////////////////////////
1498 /////////////////////////////////////////////////////////////////////
1500 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form)
1501 : PrefModule(qt_(catLanguage), qt_("Spellchecker"), form)
1505 // FIXME: this check should test the target platform (darwin)
1506 #if defined(USE_MACOSX_PACKAGING)
1507 spellcheckerCB->addItem(qt_("Native"), QString("native"));
1508 #define CONNECT_APPLESPELL
1510 #undef CONNECT_APPLESPELL
1512 #if defined(USE_ASPELL)
1513 spellcheckerCB->addItem(qt_("Aspell"), QString("aspell"));
1515 #if defined(USE_ENCHANT)
1516 spellcheckerCB->addItem(qt_("Enchant"), QString("enchant"));
1518 #if defined(USE_HUNSPELL)
1519 spellcheckerCB->addItem(qt_("Hunspell"), QString("hunspell"));
1522 #if defined(CONNECT_APPLESPELL) || defined(USE_ASPELL) || defined(USE_ENCHANT) || defined(USE_HUNSPELL)
1523 connect(spellcheckerCB, SIGNAL(currentIndexChanged(int)),
1524 this, SIGNAL(changed()));
1525 connect(altLanguageED, SIGNAL(textChanged(QString)),
1526 this, SIGNAL(changed()));
1527 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1528 this, SIGNAL(changed()));
1529 connect(compoundWordCB, SIGNAL(clicked()),
1530 this, SIGNAL(changed()));
1531 connect(spellcheckContinuouslyCB, SIGNAL(clicked()),
1532 this, SIGNAL(changed()));
1533 connect(spellcheckNotesCB, SIGNAL(clicked()),
1534 this, SIGNAL(changed()));
1536 altLanguageED->setValidator(new NoNewLineValidator(altLanguageED));
1537 escapeCharactersED->setValidator(new NoNewLineValidator(escapeCharactersED));
1539 spellcheckerCB->setEnabled(false);
1540 altLanguageED->setEnabled(false);
1541 escapeCharactersED->setEnabled(false);
1542 compoundWordCB->setEnabled(false);
1543 spellcheckContinuouslyCB->setEnabled(false);
1544 spellcheckNotesCB->setEnabled(false);
1549 void PrefSpellchecker::apply(LyXRC & rc) const
1551 string const speller = fromqstr(spellcheckerCB->
1552 itemData(spellcheckerCB->currentIndex()).toString());
1553 if (!speller.empty())
1554 rc.spellchecker = speller;
1555 rc.spellchecker_alt_lang = fromqstr(altLanguageED->text());
1556 rc.spellchecker_esc_chars = fromqstr(escapeCharactersED->text());
1557 rc.spellchecker_accept_compound = compoundWordCB->isChecked();
1558 rc.spellcheck_continuously = spellcheckContinuouslyCB->isChecked();
1559 rc.spellcheck_notes = spellcheckNotesCB->isChecked();
1563 void PrefSpellchecker::update(LyXRC const & rc)
1565 spellcheckerCB->setCurrentIndex(
1566 spellcheckerCB->findData(toqstr(rc.spellchecker)));
1567 altLanguageED->setText(toqstr(rc.spellchecker_alt_lang));
1568 escapeCharactersED->setText(toqstr(rc.spellchecker_esc_chars));
1569 compoundWordCB->setChecked(rc.spellchecker_accept_compound);
1570 spellcheckContinuouslyCB->setChecked(rc.spellcheck_continuously);
1571 spellcheckNotesCB->setChecked(rc.spellcheck_notes);
1575 void PrefSpellchecker::on_spellcheckerCB_currentIndexChanged(int index)
1577 QString spellchecker = spellcheckerCB->itemData(index).toString();
1579 compoundWordCB->setEnabled(spellchecker == QString("aspell"));
1584 /////////////////////////////////////////////////////////////////////
1588 /////////////////////////////////////////////////////////////////////
1591 PrefConverters::PrefConverters(GuiPreferences * form)
1592 : PrefModule(qt_(catFiles), qt_("Converters"), form)
1596 connect(converterNewPB, SIGNAL(clicked()),
1597 this, SLOT(updateConverter()));
1598 connect(converterRemovePB, SIGNAL(clicked()),
1599 this, SLOT(removeConverter()));
1600 connect(converterModifyPB, SIGNAL(clicked()),
1601 this, SLOT(updateConverter()));
1602 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1603 this, SLOT(switchConverter()));
1604 connect(converterFromCO, SIGNAL(activated(QString)),
1605 this, SLOT(changeConverter()));
1606 connect(converterToCO, SIGNAL(activated(QString)),
1607 this, SLOT(changeConverter()));
1608 connect(converterED, SIGNAL(textEdited(QString)),
1609 this, SLOT(changeConverter()));
1610 connect(converterFlagED, SIGNAL(textEdited(QString)),
1611 this, SLOT(changeConverter()));
1612 connect(converterNewPB, SIGNAL(clicked()),
1613 this, SIGNAL(changed()));
1614 connect(converterRemovePB, SIGNAL(clicked()),
1615 this, SIGNAL(changed()));
1616 connect(converterModifyPB, SIGNAL(clicked()),
1617 this, SIGNAL(changed()));
1618 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1619 this, SIGNAL(changed()));
1621 converterED->setValidator(new NoNewLineValidator(converterED));
1622 converterFlagED->setValidator(new NoNewLineValidator(converterFlagED));
1623 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1624 //converterDefGB->setFocusProxy(convertersLW);
1628 void PrefConverters::apply(LyXRC & rc) const
1630 rc.use_converter_cache = cacheCB->isChecked();
1631 rc.converter_cache_maxage = int(widgetToDouble(maxAgeLE) * 86400.0);
1635 void PrefConverters::update(LyXRC const & rc)
1637 cacheCB->setChecked(rc.use_converter_cache);
1639 doubleToWidget(maxAgeLE, (double(rc.converter_cache_maxage) / 86400.0), 'g', 6);
1644 void PrefConverters::updateGui()
1646 form_->formats().sort();
1647 form_->converters().update(form_->formats());
1648 // save current selection
1649 QString current = converterFromCO->currentText()
1650 + " -> " + converterToCO->currentText();
1652 converterFromCO->clear();
1653 converterToCO->clear();
1655 Formats::const_iterator cit = form_->formats().begin();
1656 Formats::const_iterator end = form_->formats().end();
1657 for (; cit != end; ++cit) {
1658 converterFromCO->addItem(qt_(cit->prettyname()));
1659 converterToCO->addItem(qt_(cit->prettyname()));
1662 // currentRowChanged(int) is also triggered when updating the listwidget
1663 // block signals to avoid unnecessary calls to switchConverter()
1664 convertersLW->blockSignals(true);
1665 convertersLW->clear();
1667 Converters::const_iterator ccit = form_->converters().begin();
1668 Converters::const_iterator cend = form_->converters().end();
1669 for (; ccit != cend; ++ccit) {
1670 QString const name =
1671 qt_(ccit->From->prettyname()) + " -> " + qt_(ccit->To->prettyname());
1672 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1673 new QListWidgetItem(name, convertersLW, type);
1675 convertersLW->sortItems(Qt::AscendingOrder);
1676 convertersLW->blockSignals(false);
1678 // restore selection
1679 if (!current.isEmpty()) {
1680 QList<QListWidgetItem *> const item =
1681 convertersLW->findItems(current, Qt::MatchExactly);
1682 if (!item.isEmpty())
1683 convertersLW->setCurrentItem(item.at(0));
1686 // select first element if restoring failed
1687 if (convertersLW->currentRow() == -1)
1688 convertersLW->setCurrentRow(0);
1694 void PrefConverters::switchConverter()
1696 int const cnr = convertersLW->currentItem()->type();
1697 Converter const & c(form_->converters().get(cnr));
1698 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1699 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1700 converterED->setText(toqstr(c.command));
1701 converterFlagED->setText(toqstr(c.flags));
1707 void PrefConverters::changeConverter()
1713 void PrefConverters::updateButtons()
1715 if (form_->formats().size() == 0)
1717 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1718 Format const & to = form_->formats().get(converterToCO->currentIndex());
1719 int const sel = form_->converters().getNumber(from.name(), to.name());
1720 bool const known = sel >= 0;
1721 bool const valid = !(converterED->text().isEmpty()
1722 || from.name() == to.name());
1724 int const cnr = convertersLW->currentItem()->type();
1725 Converter const & c = form_->converters().get(cnr);
1726 string const old_command = c.command;
1727 string const old_flag = c.flags;
1728 string const new_command = fromqstr(converterED->text());
1729 string const new_flag = fromqstr(converterFlagED->text());
1731 bool modified = (old_command != new_command || old_flag != new_flag);
1733 converterModifyPB->setEnabled(valid && known && modified);
1734 converterNewPB->setEnabled(valid && !known);
1735 converterRemovePB->setEnabled(known);
1737 maxAgeLE->setEnabled(cacheCB->isChecked());
1738 maxAgeLA->setEnabled(cacheCB->isChecked());
1743 // specify unique from/to or it doesn't appear. This is really bad UI
1744 // this is why we can use the same function for both new and modify
1745 void PrefConverters::updateConverter()
1747 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1748 Format const & to = form_->formats().get(converterToCO->currentIndex());
1749 string const flags = fromqstr(converterFlagED->text());
1750 string const command = fromqstr(converterED->text());
1752 Converter const * old =
1753 form_->converters().getConverter(from.name(), to.name());
1754 form_->converters().add(from.name(), to.name(), command, flags);
1757 form_->converters().updateLast(form_->formats());
1761 // Remove all files created by this converter from the cache, since
1762 // the modified converter might create different files.
1763 ConverterCache::get().remove_all(from.name(), to.name());
1767 void PrefConverters::removeConverter()
1769 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1770 Format const & to = form_->formats().get(converterToCO->currentIndex());
1771 form_->converters().erase(from.name(), to.name());
1775 // Remove all files created by this converter from the cache, since
1776 // a possible new converter might create different files.
1777 ConverterCache::get().remove_all(from.name(), to.name());
1781 void PrefConverters::on_cacheCB_stateChanged(int state)
1783 maxAgeLE->setEnabled(state == Qt::Checked);
1784 maxAgeLA->setEnabled(state == Qt::Checked);
1789 /////////////////////////////////////////////////////////////////////
1793 /////////////////////////////////////////////////////////////////////
1795 class FormatValidator : public QValidator
1798 FormatValidator(QWidget *, Formats const & f);
1799 void fixup(QString & input) const;
1800 QValidator::State validate(QString & input, int & pos) const;
1802 virtual QString toString(Format const & format) const = 0;
1804 Formats const & formats_;
1808 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1809 : QValidator(parent), formats_(f)
1814 void FormatValidator::fixup(QString & input) const
1816 Formats::const_iterator cit = formats_.begin();
1817 Formats::const_iterator end = formats_.end();
1818 for (; cit != end; ++cit) {
1819 QString const name = toString(*cit);
1820 if (distance(formats_.begin(), cit) == nr()) {
1828 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1830 Formats::const_iterator cit = formats_.begin();
1831 Formats::const_iterator end = formats_.end();
1832 bool unknown = true;
1833 for (; unknown && cit != end; ++cit) {
1834 QString const name = toString(*cit);
1835 if (distance(formats_.begin(), cit) != nr())
1836 unknown = name != input;
1839 if (unknown && !input.isEmpty())
1840 return QValidator::Acceptable;
1842 return QValidator::Intermediate;
1846 int FormatValidator::nr() const
1848 QComboBox * p = qobject_cast<QComboBox *>(parent());
1849 return p->itemData(p->currentIndex()).toInt();
1853 /////////////////////////////////////////////////////////////////////
1855 // FormatNameValidator
1857 /////////////////////////////////////////////////////////////////////
1859 class FormatNameValidator : public FormatValidator
1862 FormatNameValidator(QWidget * parent, Formats const & f)
1863 : FormatValidator(parent, f)
1866 QString toString(Format const & format) const
1868 return toqstr(format.name());
1873 /////////////////////////////////////////////////////////////////////
1875 // FormatPrettynameValidator
1877 /////////////////////////////////////////////////////////////////////
1879 class FormatPrettynameValidator : public FormatValidator
1882 FormatPrettynameValidator(QWidget * parent, Formats const & f)
1883 : FormatValidator(parent, f)
1886 QString toString(Format const & format) const
1888 return qt_(format.prettyname());
1893 /////////////////////////////////////////////////////////////////////
1897 /////////////////////////////////////////////////////////////////////
1899 PrefFileformats::PrefFileformats(GuiPreferences * form)
1900 : PrefModule(qt_(catFiles), qt_("File Formats"), form)
1904 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1905 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1906 extensionED->setValidator(new NoNewLineValidator(extensionED));
1907 shortcutED->setValidator(new NoNewLineValidator(shortcutED));
1908 editorED->setValidator(new NoNewLineValidator(editorED));
1909 viewerED->setValidator(new NoNewLineValidator(viewerED));
1910 copierED->setValidator(new NoNewLineValidator(copierED));
1912 connect(documentCB, SIGNAL(clicked()),
1913 this, SLOT(setFlags()));
1914 connect(vectorCB, SIGNAL(clicked()),
1915 this, SLOT(setFlags()));
1916 connect(exportMenuCB, SIGNAL(clicked()),
1917 this, SLOT(setFlags()));
1918 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1919 this, SLOT(updatePrettyname()));
1920 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1921 this, SIGNAL(changed()));
1922 connect(defaultFormatCB, SIGNAL(activated(QString)),
1923 this, SIGNAL(changed()));
1924 connect(viewerCO, SIGNAL(activated(int)),
1925 this, SIGNAL(changed()));
1926 connect(editorCO, SIGNAL(activated(int)),
1927 this, SIGNAL(changed()));
1933 string const l10n_shortcut(string const prettyname, string const shortcut)
1935 if (shortcut.empty())
1938 string l10n_format =
1939 to_utf8(_(prettyname + '|' + shortcut));
1940 return split(l10n_format, '|');
1946 void PrefFileformats::apply(LyXRC & rc) const
1948 QString const default_format = defaultFormatCB->itemData(
1949 defaultFormatCB->currentIndex()).toString();
1950 rc.default_view_format = fromqstr(default_format);
1954 void PrefFileformats::update(LyXRC const & rc)
1956 viewer_alternatives = rc.viewer_alternatives;
1957 editor_alternatives = rc.editor_alternatives;
1958 bool const init = defaultFormatCB->currentText().isEmpty();
1962 defaultFormatCB->findData(toqstr(rc.default_view_format));
1963 defaultFormatCB->setCurrentIndex(pos);
1968 void PrefFileformats::updateView()
1970 QString const current = formatsCB->currentText();
1971 QString const current_def = defaultFormatCB->currentText();
1973 // update comboboxes with formats
1974 formatsCB->blockSignals(true);
1975 defaultFormatCB->blockSignals(true);
1977 defaultFormatCB->clear();
1978 form_->formats().sort();
1979 Formats::const_iterator cit = form_->formats().begin();
1980 Formats::const_iterator end = form_->formats().end();
1981 for (; cit != end; ++cit) {
1982 formatsCB->addItem(qt_(cit->prettyname()),
1983 QVariant(form_->formats().getNumber(cit->name())));
1984 if (form_->converters().isReachable("latex", cit->name())
1985 || form_->converters().isReachable("dviluatex", cit->name())
1986 || form_->converters().isReachable("pdflatex", cit->name())
1987 || form_->converters().isReachable("luatex", cit->name())
1988 || form_->converters().isReachable("xetex", cit->name()))
1989 defaultFormatCB->addItem(qt_(cit->prettyname()),
1990 QVariant(toqstr(cit->name())));
1993 // restore selection
1994 int item = formatsCB->findText(current, Qt::MatchExactly);
1995 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1996 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1997 item = defaultFormatCB->findText(current_def, Qt::MatchExactly);
1998 defaultFormatCB->setCurrentIndex(item < 0 ? 0 : item);
1999 formatsCB->blockSignals(false);
2000 defaultFormatCB->blockSignals(false);
2004 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
2006 if (form_->formats().size() == 0)
2008 int const nr = formatsCB->itemData(i).toInt();
2009 Format const f = form_->formats().get(nr);
2011 formatED->setText(toqstr(f.name()));
2012 copierED->setText(toqstr(form_->movers().command(f.name())));
2013 extensionED->setText(toqstr(f.extension()));
2014 shortcutED->setText(
2015 toqstr(l10n_shortcut(f.prettyname(), f.shortcut())));
2016 documentCB->setChecked((f.documentFormat()));
2017 vectorCB->setChecked((f.vectorFormat()));
2018 exportMenuCB->setChecked((f.inExportMenu()));
2019 exportMenuCB->setEnabled((f.documentFormat()));
2025 void PrefFileformats::setFlags()
2027 int flags = Format::none;
2028 if (documentCB->isChecked())
2029 flags |= Format::document;
2030 if (vectorCB->isChecked())
2031 flags |= Format::vector;
2032 if (exportMenuCB->isChecked())
2033 flags |= Format::export_menu;
2034 currentFormat().setFlags(flags);
2035 exportMenuCB->setEnabled(documentCB->isChecked());
2040 void PrefFileformats::on_copierED_textEdited(const QString & s)
2042 string const fmt = fromqstr(formatED->text());
2043 form_->movers().set(fmt, fromqstr(s));
2048 void PrefFileformats::on_extensionED_textEdited(const QString & s)
2050 currentFormat().setExtension(fromqstr(s));
2054 void PrefFileformats::on_viewerED_textEdited(const QString & s)
2056 currentFormat().setViewer(fromqstr(s));
2061 void PrefFileformats::on_editorED_textEdited(const QString & s)
2063 currentFormat().setEditor(fromqstr(s));
2068 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
2070 string const new_shortcut = fromqstr(s);
2071 if (new_shortcut == l10n_shortcut(currentFormat().prettyname(),
2072 currentFormat().shortcut()))
2074 currentFormat().setShortcut(new_shortcut);
2079 void PrefFileformats::on_formatED_editingFinished()
2081 string const newname = fromqstr(formatED->displayText());
2082 string const oldname = currentFormat().name();
2083 if (newname == oldname)
2085 if (form_->converters().formatIsUsed(oldname)) {
2086 Alert::error(_("Format in use"),
2087 _("You cannot change a format's short name "
2088 "if the format is used by a converter. "
2089 "Please remove the converter first."));
2094 currentFormat().setName(newname);
2099 void PrefFileformats::on_formatED_textChanged(const QString &)
2101 QString t = formatED->text();
2103 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
2104 setValid(formatLA, valid);
2108 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
2110 QString t = formatsCB->currentText();
2112 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
2113 setValid(formatsLA, valid);
2117 void PrefFileformats::updatePrettyname()
2119 QString const newname = formatsCB->currentText();
2120 if (newname == qt_(currentFormat().prettyname()))
2123 currentFormat().setPrettyname(fromqstr(newname));
2131 void updateComboBox(LyXRC::Alternatives const & alts,
2132 string const & fmt, QComboBox * combo)
2134 LyXRC::Alternatives::const_iterator it =
2136 if (it != alts.end()) {
2137 LyXRC::CommandSet const & cmds = it->second;
2138 LyXRC::CommandSet::const_iterator sit =
2140 LyXRC::CommandSet::const_iterator const sen =
2142 for (; sit != sen; ++sit) {
2143 QString const qcmd = toqstr(*sit);
2144 combo->addItem(qcmd, qcmd);
2151 void PrefFileformats::updateViewers()
2153 Format const f = currentFormat();
2154 viewerCO->blockSignals(true);
2156 viewerCO->addItem(qt_("None"), QString());
2157 updateComboBox(viewer_alternatives, f.name(), viewerCO);
2158 viewerCO->addItem(qt_("Custom"), QString("custom viewer"));
2159 viewerCO->blockSignals(false);
2161 int pos = viewerCO->findData(toqstr(f.viewer()));
2164 viewerED->setEnabled(false);
2165 viewerCO->setCurrentIndex(pos);
2167 viewerED->setEnabled(true);
2168 viewerED->setText(toqstr(f.viewer()));
2169 viewerCO->setCurrentIndex(viewerCO->findData(toqstr("custom viewer")));
2174 void PrefFileformats::updateEditors()
2176 Format const f = currentFormat();
2177 editorCO->blockSignals(true);
2179 editorCO->addItem(qt_("None"), QString());
2180 updateComboBox(editor_alternatives, f.name(), editorCO);
2181 editorCO->addItem(qt_("Custom"), QString("custom editor"));
2182 editorCO->blockSignals(false);
2184 int pos = editorCO->findData(toqstr(f.editor()));
2187 editorED->setEnabled(false);
2188 editorCO->setCurrentIndex(pos);
2190 editorED->setEnabled(true);
2191 editorED->setText(toqstr(f.editor()));
2192 editorCO->setCurrentIndex(editorCO->findData(toqstr("custom editor")));
2197 void PrefFileformats::on_viewerCO_currentIndexChanged(int i)
2199 bool const custom = viewerCO->itemData(i).toString() == "custom viewer";
2200 viewerED->setEnabled(custom);
2202 currentFormat().setViewer(fromqstr(viewerCO->itemData(i).toString()));
2206 void PrefFileformats::on_editorCO_currentIndexChanged(int i)
2208 bool const custom = editorCO->itemData(i).toString() == "custom editor";
2209 editorED->setEnabled(custom);
2211 currentFormat().setEditor(fromqstr(editorCO->itemData(i).toString()));
2215 Format & PrefFileformats::currentFormat()
2217 int const i = formatsCB->currentIndex();
2218 int const nr = formatsCB->itemData(i).toInt();
2219 return form_->formats().get(nr);
2223 void PrefFileformats::on_formatNewPB_clicked()
2225 form_->formats().add("", "", "", "", "", "", Format::none);
2227 formatsCB->setCurrentIndex(0);
2228 formatsCB->setFocus(Qt::OtherFocusReason);
2232 void PrefFileformats::on_formatRemovePB_clicked()
2234 int const i = formatsCB->currentIndex();
2235 int const nr = formatsCB->itemData(i).toInt();
2236 string const current_text = form_->formats().get(nr).name();
2237 if (form_->converters().formatIsUsed(current_text)) {
2238 Alert::error(_("Format in use"),
2239 _("Cannot remove a Format used by a Converter. "
2240 "Remove the converter first."));
2244 form_->formats().erase(current_text);
2247 on_formatsCB_editTextChanged(formatsCB->currentText());
2252 /////////////////////////////////////////////////////////////////////
2256 /////////////////////////////////////////////////////////////////////
2258 PrefLanguage::PrefLanguage(GuiPreferences * form)
2259 : PrefModule(qt_(catLanguage), qt_("Language"), form)
2263 connect(rtlGB, SIGNAL(clicked()),
2264 this, SIGNAL(changed()));
2265 connect(visualCursorRB, SIGNAL(clicked()),
2266 this, SIGNAL(changed()));
2267 connect(logicalCursorRB, SIGNAL(clicked()),
2268 this, SIGNAL(changed()));
2269 connect(markForeignCB, SIGNAL(clicked()),
2270 this, SIGNAL(changed()));
2271 connect(autoBeginCB, SIGNAL(clicked()),
2272 this, SIGNAL(changed()));
2273 connect(autoEndCB, SIGNAL(clicked()),
2274 this, SIGNAL(changed()));
2275 connect(languagePackageCO, SIGNAL(activated(int)),
2276 this, SIGNAL(changed()));
2277 connect(languagePackageED, SIGNAL(textChanged(QString)),
2278 this, SIGNAL(changed()));
2279 connect(globalCB, SIGNAL(clicked()),
2280 this, SIGNAL(changed()));
2281 connect(startCommandED, SIGNAL(textChanged(QString)),
2282 this, SIGNAL(changed()));
2283 connect(endCommandED, SIGNAL(textChanged(QString)),
2284 this, SIGNAL(changed()));
2285 connect(uiLanguageCO, SIGNAL(activated(int)),
2286 this, SIGNAL(changed()));
2287 connect(defaultDecimalPointLE, SIGNAL(textChanged(QString)),
2288 this, SIGNAL(changed()));
2290 languagePackageED->setValidator(new NoNewLineValidator(languagePackageED));
2291 startCommandED->setValidator(new NoNewLineValidator(startCommandED));
2292 endCommandED->setValidator(new NoNewLineValidator(endCommandED));
2294 uiLanguageCO->clear();
2296 QAbstractItemModel * language_model = guiApp->languageModel();
2297 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
2298 language_model->sort(0);
2299 defaultDecimalPointLE->setInputMask("X; ");
2300 defaultDecimalPointLE->setMaxLength(1);
2303 uiLanguageCO->blockSignals(true);
2304 uiLanguageCO->addItem(qt_("Default"), toqstr("auto"));
2305 for (int i = 0; i != language_model->rowCount(); ++i) {
2306 QModelIndex index = language_model->index(i, 0);
2307 // Filter the list based on the available translation and add
2308 // each language code only once
2309 string const name = fromqstr(index.data(Qt::UserRole).toString());
2310 Language const * lang = languages.getLanguage(name);
2311 // never remove the currently selected language
2312 if (lang && name != form->rc().gui_language && name != lyxrc.gui_language)
2313 if (!lang->translated() || added.find(lang->code()) != added.end())
2315 added.insert(lang->code());
2316 uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
2317 index.data(Qt::UserRole).toString());
2319 uiLanguageCO->blockSignals(false);
2323 void PrefLanguage::on_uiLanguageCO_currentIndexChanged(int)
2325 QMessageBox::information(this, qt_("LyX needs to be restarted!"),
2326 qt_("The change of user interface language will be fully "
2327 "effective only after a restart."));
2331 void PrefLanguage::on_languagePackageCO_currentIndexChanged(int i)
2333 languagePackageED->setEnabled(i == 2);
2337 void PrefLanguage::apply(LyXRC & rc) const
2339 // FIXME: remove rtl_support bool
2340 rc.rtl_support = rtlGB->isChecked();
2341 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
2342 rc.mark_foreign_language = markForeignCB->isChecked();
2343 rc.language_auto_begin = autoBeginCB->isChecked();
2344 rc.language_auto_end = autoEndCB->isChecked();
2345 int const p = languagePackageCO->currentIndex();
2347 rc.language_package_selection = LyXRC::LP_AUTO;
2349 rc.language_package_selection = LyXRC::LP_BABEL;
2351 rc.language_package_selection = LyXRC::LP_CUSTOM;
2353 rc.language_package_selection = LyXRC::LP_NONE;
2354 rc.language_custom_package = fromqstr(languagePackageED->text());
2355 rc.language_global_options = globalCB->isChecked();
2356 rc.language_command_begin = fromqstr(startCommandED->text());
2357 rc.language_command_end = fromqstr(endCommandED->text());
2358 rc.gui_language = fromqstr(
2359 uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString());
2360 rc.default_decimal_point = fromqstr(defaultDecimalPointLE->text());
2364 void PrefLanguage::update(LyXRC const & rc)
2366 // FIXME: remove rtl_support bool
2367 rtlGB->setChecked(rc.rtl_support);
2368 if (rc.visual_cursor)
2369 visualCursorRB->setChecked(true);
2371 logicalCursorRB->setChecked(true);
2372 markForeignCB->setChecked(rc.mark_foreign_language);
2373 autoBeginCB->setChecked(rc.language_auto_begin);
2374 autoEndCB->setChecked(rc.language_auto_end);
2375 languagePackageCO->setCurrentIndex(rc.language_package_selection);
2376 languagePackageED->setText(toqstr(rc.language_custom_package));
2377 languagePackageED->setEnabled(languagePackageCO->currentIndex() == 2);
2378 globalCB->setChecked(rc.language_global_options);
2379 startCommandED->setText(toqstr(rc.language_command_begin));
2380 endCommandED->setText(toqstr(rc.language_command_end));
2381 defaultDecimalPointLE->setText(toqstr(rc.default_decimal_point));
2383 int pos = uiLanguageCO->findData(toqstr(rc.gui_language));
2384 uiLanguageCO->blockSignals(true);
2385 uiLanguageCO->setCurrentIndex(pos);
2386 uiLanguageCO->blockSignals(false);
2390 /////////////////////////////////////////////////////////////////////
2394 /////////////////////////////////////////////////////////////////////
2396 PrefPrinter::PrefPrinter(GuiPreferences * form)
2397 : PrefModule(qt_(catOutput), qt_("Printer"), form)
2401 connect(printerAdaptCB, SIGNAL(clicked()),
2402 this, SIGNAL(changed()));
2403 connect(printerCommandED, SIGNAL(textChanged(QString)),
2404 this, SIGNAL(changed()));
2405 connect(printerNameED, SIGNAL(textChanged(QString)),
2406 this, SIGNAL(changed()));
2407 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
2408 this, SIGNAL(changed()));
2409 connect(printerCopiesED, SIGNAL(textChanged(QString)),
2410 this, SIGNAL(changed()));
2411 connect(printerReverseED, SIGNAL(textChanged(QString)),
2412 this, SIGNAL(changed()));
2413 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
2414 this, SIGNAL(changed()));
2415 connect(printerExtensionED, SIGNAL(textChanged(QString)),
2416 this, SIGNAL(changed()));
2417 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
2418 this, SIGNAL(changed()));
2419 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
2420 this, SIGNAL(changed()));
2421 connect(printerEvenED, SIGNAL(textChanged(QString)),
2422 this, SIGNAL(changed()));
2423 connect(printerOddED, SIGNAL(textChanged(QString)),
2424 this, SIGNAL(changed()));
2425 connect(printerCollatedED, SIGNAL(textChanged(QString)),
2426 this, SIGNAL(changed()));
2427 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
2428 this, SIGNAL(changed()));
2429 connect(printerToFileED, SIGNAL(textChanged(QString)),
2430 this, SIGNAL(changed()));
2431 connect(printerExtraED, SIGNAL(textChanged(QString)),
2432 this, SIGNAL(changed()));
2433 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
2434 this, SIGNAL(changed()));
2435 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
2436 this, SIGNAL(changed()));
2438 printerNameED->setValidator(new NoNewLineValidator(printerNameED));
2439 printerCommandED->setValidator(new NoNewLineValidator(printerCommandED));
2440 printerEvenED->setValidator(new NoNewLineValidator(printerEvenED));
2441 printerPageRangeED->setValidator(new NoNewLineValidator(printerPageRangeED));
2442 printerCopiesED->setValidator(new NoNewLineValidator(printerCopiesED));
2443 printerReverseED->setValidator(new NoNewLineValidator(printerReverseED));
2444 printerToFileED->setValidator(new NoNewLineValidator(printerToFileED));
2445 printerPaperTypeED->setValidator(new NoNewLineValidator(printerPaperTypeED));
2446 printerExtraED->setValidator(new NoNewLineValidator(printerExtraED));
2447 printerOddED->setValidator(new NoNewLineValidator(printerOddED));
2448 printerCollatedED->setValidator(new NoNewLineValidator(printerCollatedED));
2449 printerLandscapeED->setValidator(new NoNewLineValidator(printerLandscapeED));
2450 printerToPrinterED->setValidator(new NoNewLineValidator(printerToPrinterED));
2451 printerExtensionED->setValidator(new NoNewLineValidator(printerExtensionED));
2452 printerPaperSizeED->setValidator(new NoNewLineValidator(printerPaperSizeED));
2453 printerSpoolCommandED->setValidator(new NoNewLineValidator(printerSpoolCommandED));
2454 printerSpoolPrefixED->setValidator(new NoNewLineValidator(printerSpoolPrefixED));
2458 void PrefPrinter::apply(LyXRC & rc) const
2460 rc.print_adapt_output = printerAdaptCB->isChecked();
2461 rc.print_command = fromqstr(printerCommandED->text());
2462 rc.printer = fromqstr(printerNameED->text());
2464 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
2465 rc.print_copies_flag = fromqstr(printerCopiesED->text());
2466 rc.print_reverse_flag = fromqstr(printerReverseED->text());
2467 rc.print_to_printer = fromqstr(printerToPrinterED->text());
2468 rc.print_file_extension = fromqstr(printerExtensionED->text());
2469 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
2470 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
2471 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
2472 rc.print_oddpage_flag = fromqstr(printerOddED->text());
2473 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
2474 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
2475 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
2476 rc.print_extra_options = fromqstr(printerExtraED->text());
2477 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
2478 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
2482 void PrefPrinter::update(LyXRC const & rc)
2484 printerAdaptCB->setChecked(rc.print_adapt_output);
2485 printerCommandED->setText(toqstr(rc.print_command));
2486 printerNameED->setText(toqstr(rc.printer));
2488 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
2489 printerCopiesED->setText(toqstr(rc.print_copies_flag));
2490 printerReverseED->setText(toqstr(rc.print_reverse_flag));
2491 printerToPrinterED->setText(toqstr(rc.print_to_printer));
2492 printerExtensionED->setText(toqstr(rc.print_file_extension));
2493 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
2494 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
2495 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
2496 printerOddED->setText(toqstr(rc.print_oddpage_flag));
2497 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
2498 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
2499 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
2500 printerExtraED->setText(toqstr(rc.print_extra_options));
2501 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
2502 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
2506 /////////////////////////////////////////////////////////////////////
2508 // PrefUserInterface
2510 /////////////////////////////////////////////////////////////////////
2512 PrefUserInterface::PrefUserInterface(GuiPreferences * form)
2513 : PrefModule(qt_(catLookAndFeel), qt_("User Interface"), form)
2517 connect(autoSaveCB, SIGNAL(toggled(bool)),
2518 autoSaveSB, SLOT(setEnabled(bool)));
2519 connect(autoSaveCB, SIGNAL(toggled(bool)),
2520 TextLabel1, SLOT(setEnabled(bool)));
2521 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
2522 this, SIGNAL(changed()));
2523 connect(singleInstanceCB, SIGNAL(clicked()),
2524 this, SIGNAL(changed()));
2525 #if QT_VERSION < 0x040500
2526 singleCloseTabButtonCB->setEnabled(false);
2528 connect(singleCloseTabButtonCB, SIGNAL(clicked()),
2529 this, SIGNAL(changed()));
2530 connect(uiFilePB, SIGNAL(clicked()),
2531 this, SLOT(selectUi()));
2532 connect(uiFileED, SIGNAL(textChanged(QString)),
2533 this, SIGNAL(changed()));
2534 connect(iconSetCO, SIGNAL(activated(int)),
2535 this, SIGNAL(changed()));
2536 connect(restoreCursorCB, SIGNAL(clicked()),
2537 this, SIGNAL(changed()));
2538 connect(loadSessionCB, SIGNAL(clicked()),
2539 this, SIGNAL(changed()));
2540 connect(allowGeometrySessionCB, SIGNAL(clicked()),
2541 this, SIGNAL(changed()));
2542 connect(autoSaveSB, SIGNAL(valueChanged(int)),
2543 this, SIGNAL(changed()));
2544 connect(autoSaveCB, SIGNAL(clicked()),
2545 this, SIGNAL(changed()));
2546 connect(backupCB, SIGNAL(clicked()),
2547 this, SIGNAL(changed()));
2548 connect(saveCompressedCB, SIGNAL(clicked()),
2549 this, SIGNAL(changed()));
2550 connect(lastfilesSB, SIGNAL(valueChanged(int)),
2551 this, SIGNAL(changed()));
2552 connect(tooltipCB, SIGNAL(toggled(bool)),
2553 this, SIGNAL(changed()));
2554 lastfilesSB->setMaximum(maxlastfiles);
2556 iconSetCO->addItem(qt_("Default"), QString());
2557 iconSetCO->addItem(qt_("Classic"), "classic");
2558 iconSetCO->addItem(qt_("Oxygen"), "oxygen");
2562 void PrefUserInterface::apply(LyXRC & rc) const
2564 rc.icon_set = fromqstr(iconSetCO->itemData(
2565 iconSetCO->currentIndex()).toString());
2567 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
2568 rc.use_lastfilepos = restoreCursorCB->isChecked();
2569 rc.load_session = loadSessionCB->isChecked();
2570 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
2571 rc.autosave = autoSaveCB->isChecked() ? autoSaveSB->value() * 60 : 0;
2572 rc.make_backup = backupCB->isChecked();
2573 rc.save_compressed = saveCompressedCB->isChecked();
2574 rc.num_lastfiles = lastfilesSB->value();
2575 rc.use_tooltip = tooltipCB->isChecked();
2576 rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
2577 rc.single_instance = singleInstanceCB->isChecked();
2578 rc.single_close_tab_button = singleCloseTabButtonCB->isChecked();
2579 #if QT_VERSION < 0x040500
2580 rc.single_close_tab_button = true;
2585 void PrefUserInterface::update(LyXRC const & rc)
2587 int iconset = iconSetCO->findData(toqstr(rc.icon_set));
2590 iconSetCO->setCurrentIndex(iconset);
2591 uiFileED->setText(toqstr(external_path(rc.ui_file)));
2592 restoreCursorCB->setChecked(rc.use_lastfilepos);
2593 loadSessionCB->setChecked(rc.load_session);
2594 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
2595 // convert to minutes
2596 bool autosave = rc.autosave > 0;
2597 int mins = rc.autosave / 60;
2600 autoSaveSB->setValue(mins);
2601 autoSaveCB->setChecked(autosave);
2602 autoSaveSB->setEnabled(autosave);
2603 backupCB->setChecked(rc.make_backup);
2604 saveCompressedCB->setChecked(rc.save_compressed);
2605 lastfilesSB->setValue(rc.num_lastfiles);
2606 tooltipCB->setChecked(rc.use_tooltip);
2607 openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
2608 singleInstanceCB->setChecked(rc.single_instance && !rc.lyxpipes.empty());
2609 singleInstanceCB->setEnabled(!rc.lyxpipes.empty());
2610 singleCloseTabButtonCB->setChecked(rc.single_close_tab_button);
2614 void PrefUserInterface::selectUi()
2616 QString file = form_->browseUI(internalPath(uiFileED->text()));
2617 if (!file.isEmpty())
2618 uiFileED->setText(file);
2622 void PrefUserInterface::on_clearSessionPB_clicked()
2624 guiApp->clearSession();
2629 /////////////////////////////////////////////////////////////////////
2633 /////////////////////////////////////////////////////////////////////
2635 PrefEdit::PrefEdit(GuiPreferences * form)
2636 : PrefModule(qt_(catEditing), qt_("Control"), form)
2640 connect(cursorFollowsCB, SIGNAL(clicked()),
2641 this, SIGNAL(changed()));
2642 connect(scrollBelowCB, SIGNAL(clicked()),
2643 this, SIGNAL(changed()));
2644 connect(macLikeWordMovementCB, SIGNAL(clicked()),
2645 this, SIGNAL(changed()));
2646 connect(sortEnvironmentsCB, SIGNAL(clicked()),
2647 this, SIGNAL(changed()));
2648 connect(groupEnvironmentsCB, SIGNAL(clicked()),
2649 this, SIGNAL(changed()));
2650 connect(macroEditStyleCO, SIGNAL(activated(int)),
2651 this, SIGNAL(changed()));
2652 connect(cursorWidthSB, SIGNAL(valueChanged(int)),
2653 this, SIGNAL(changed()));
2654 connect(fullscreenLimitGB, SIGNAL(clicked()),
2655 this, SIGNAL(changed()));
2656 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
2657 this, SIGNAL(changed()));
2658 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
2659 this, SIGNAL(changed()));
2660 connect(toggleMenubarCB, SIGNAL(toggled(bool)),
2661 this, SIGNAL(changed()));
2662 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
2663 this, SIGNAL(changed()));
2664 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
2665 this, SIGNAL(changed()));
2669 void PrefEdit::apply(LyXRC & rc) const
2671 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
2672 rc.scroll_below_document = scrollBelowCB->isChecked();
2673 rc.mac_like_word_movement = macLikeWordMovementCB->isChecked();
2674 rc.sort_layouts = sortEnvironmentsCB->isChecked();
2675 rc.group_layouts = groupEnvironmentsCB->isChecked();
2676 switch (macroEditStyleCO->currentIndex()) {
2677 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
2678 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
2679 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
2681 rc.cursor_width = cursorWidthSB->value();
2682 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
2683 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
2684 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
2685 rc.full_screen_menubar = toggleMenubarCB->isChecked();
2686 rc.full_screen_width = fullscreenWidthSB->value();
2687 rc.full_screen_limit = fullscreenLimitGB->isChecked();
2691 void PrefEdit::update(LyXRC const & rc)
2693 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
2694 scrollBelowCB->setChecked(rc.scroll_below_document);
2695 macLikeWordMovementCB->setChecked(rc.mac_like_word_movement);
2696 sortEnvironmentsCB->setChecked(rc.sort_layouts);
2697 groupEnvironmentsCB->setChecked(rc.group_layouts);
2698 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
2699 cursorWidthSB->setValue(rc.cursor_width);
2700 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
2701 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
2702 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
2703 toggleMenubarCB->setChecked(rc.full_screen_menubar);
2704 fullscreenWidthSB->setValue(rc.full_screen_width);
2705 fullscreenLimitGB->setChecked(rc.full_screen_limit);
2709 /////////////////////////////////////////////////////////////////////
2713 /////////////////////////////////////////////////////////////////////
2716 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
2718 Ui::shortcutUi::setupUi(this);
2719 QDialog::setModal(true);
2723 PrefShortcuts::PrefShortcuts(GuiPreferences * form)
2724 : PrefModule(qt_(catEditing), qt_("Shortcuts"), form)
2728 shortcutsTW->setColumnCount(2);
2729 shortcutsTW->headerItem()->setText(0, qt_("Function"));
2730 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
2731 shortcutsTW->setSortingEnabled(true);
2732 // Multi-selection can be annoying.
2733 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
2735 connect(bindFilePB, SIGNAL(clicked()),
2736 this, SLOT(selectBind()));
2737 connect(bindFileED, SIGNAL(textChanged(QString)),
2738 this, SIGNAL(changed()));
2740 shortcut_ = new GuiShortcutDialog(this);
2741 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
2742 shortcut_bc_.setOK(shortcut_->okPB);
2743 shortcut_bc_.setCancel(shortcut_->cancelPB);
2745 connect(shortcut_->okPB, SIGNAL(clicked()),
2746 shortcut_, SLOT(accept()));
2747 connect(shortcut_->okPB, SIGNAL(clicked()),
2748 this, SIGNAL(changed()));
2749 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2750 shortcut_, SLOT(reject()));
2751 connect(shortcut_->clearPB, SIGNAL(clicked()),
2752 this, SLOT(shortcutClearPressed()));
2753 connect(shortcut_->removePB, SIGNAL(clicked()),
2754 this, SLOT(shortcutRemovePressed()));
2755 connect(shortcut_->okPB, SIGNAL(clicked()),
2756 this, SLOT(shortcutOkPressed()));
2757 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2758 this, SLOT(shortcutCancelPressed()));
2762 void PrefShortcuts::apply(LyXRC & rc) const
2764 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
2765 // write user_bind and user_unbind to .lyx/bind/user.bind
2766 FileName bind_dir(addPath(package().user_support().absFileName(), "bind"));
2767 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
2768 lyxerr << "LyX could not create the user bind directory '"
2769 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2772 if (!bind_dir.isDirWritable()) {
2773 lyxerr << "LyX could not write to the user bind directory '"
2774 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2777 FileName user_bind_file(bind_dir.absFileName() + "/user.bind");
2778 user_unbind_.write(user_bind_file.toFilesystemEncoding(), false, true);
2779 user_bind_.write(user_bind_file.toFilesystemEncoding(), true, false);
2780 // immediately apply the keybindings. Why this is not done before?
2781 // The good thing is that the menus are updated automatically.
2782 theTopLevelKeymap().clear();
2783 theTopLevelKeymap().read("site");
2784 theTopLevelKeymap().read(rc.bind_file, 0, KeyMap::Fallback);
2785 theTopLevelKeymap().read("user", 0, KeyMap::MissingOK);
2789 void PrefShortcuts::update(LyXRC const & rc)
2791 bindFileED->setText(toqstr(external_path(rc.bind_file)));
2793 system_bind_.clear();
2795 user_unbind_.clear();
2796 system_bind_.read("site");
2797 system_bind_.read(rc.bind_file);
2798 // \unbind in user.bind is added to user_unbind_
2799 user_bind_.read("user", &user_unbind_, KeyMap::MissingOK);
2800 updateShortcutsTW();
2804 void PrefShortcuts::updateShortcutsTW()
2806 shortcutsTW->clear();
2808 editItem_ = new QTreeWidgetItem(shortcutsTW);
2809 editItem_->setText(0, qt_("Cursor, Mouse and Editing Functions"));
2810 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2812 mathItem_ = new QTreeWidgetItem(shortcutsTW);
2813 mathItem_->setText(0, qt_("Mathematical Symbols"));
2814 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2816 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2817 bufferItem_->setText(0, qt_("Document and Window"));
2818 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2820 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2821 layoutItem_->setText(0, qt_("Font, Layouts and Textclasses"));
2822 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2824 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2825 systemItem_->setText(0, qt_("System and Miscellaneous"));
2826 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2828 // listBindings(unbound=true) lists all bound and unbound lfuns
2829 // Items in this list is tagged by its source.
2830 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2832 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2834 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2835 KeyMap::UserUnbind);
2836 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2837 user_bindinglist.end());
2838 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2839 user_unbindinglist.end());
2841 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2842 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2843 for (; it != it_end; ++it)
2844 insertShortcutItem(it->request, it->sequence, KeyMap::ItemType(it->tag));
2846 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2847 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2848 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2849 modifyPB->setEnabled(!items.isEmpty());
2851 shortcutsTW->resizeColumnToContents(0);
2855 void PrefShortcuts::setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag)
2857 item->setData(0, Qt::UserRole, QVariant(tag));
2861 case KeyMap::System:
2863 case KeyMap::UserBind:
2866 case KeyMap::UserUnbind:
2867 font.setStrikeOut(true);
2869 // this item is not displayed now.
2870 case KeyMap::UserExtraUnbind:
2871 font.setStrikeOut(true);
2875 item->setFont(1, font);
2879 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2880 KeySequence const & seq, KeyMap::ItemType tag)
2882 FuncCode const action = lfun.action();
2883 string const action_name = lyxaction.getActionName(action);
2884 QString const lfun_name = toqstr(from_utf8(action_name)
2885 + ' ' + lfun.argument());
2886 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2887 KeyMap::ItemType item_tag = tag;
2889 QTreeWidgetItem * newItem = 0;
2890 // for unbind items, try to find an existing item in the system bind list
2891 if (tag == KeyMap::UserUnbind) {
2892 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2893 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2894 for (int i = 0; i < items.size(); ++i) {
2895 if (items[i]->text(1) == shortcut)
2899 // if not found, this unbind item is KeyMap::UserExtraUnbind
2900 // Such an item is not displayed to avoid confusion (what is
2901 // unmatched removed?).
2903 item_tag = KeyMap::UserExtraUnbind;
2908 switch(lyxaction.getActionType(action)) {
2909 case LyXAction::Hidden:
2911 case LyXAction::Edit:
2912 newItem = new QTreeWidgetItem(editItem_);
2914 case LyXAction::Math:
2915 newItem = new QTreeWidgetItem(mathItem_);
2917 case LyXAction::Buffer:
2918 newItem = new QTreeWidgetItem(bufferItem_);
2920 case LyXAction::Layout:
2921 newItem = new QTreeWidgetItem(layoutItem_);
2923 case LyXAction::System:
2924 newItem = new QTreeWidgetItem(systemItem_);
2927 // this should not happen
2928 newItem = new QTreeWidgetItem(shortcutsTW);
2932 newItem->setText(0, lfun_name);
2933 newItem->setText(1, shortcut);
2934 // record BindFile representation to recover KeySequence when needed.
2935 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2936 setItemType(newItem, item_tag);
2941 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2943 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2944 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2945 modifyPB->setEnabled(!items.isEmpty());
2946 if (items.isEmpty())
2949 KeyMap::ItemType tag =
2950 static_cast<KeyMap::ItemType>(items[0]->data(0, Qt::UserRole).toInt());
2951 if (tag == KeyMap::UserUnbind)
2952 removePB->setText(qt_("Res&tore"));
2954 removePB->setText(qt_("Remo&ve"));
2958 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2964 void PrefShortcuts::modifyShortcut()
2966 QTreeWidgetItem * item = shortcutsTW->currentItem();
2967 if (item->flags() & Qt::ItemIsSelectable) {
2968 shortcut_->lfunLE->setText(item->text(0));
2969 save_lfun_ = item->text(0).trimmed();
2970 shortcut_->shortcutWG->setText(item->text(1));
2972 seq.parse(fromqstr(item->data(1, Qt::UserRole).toString()));
2973 shortcut_->shortcutWG->setKeySequence(seq);
2974 shortcut_->shortcutWG->setFocus();
2980 void PrefShortcuts::removeShortcut()
2982 // it seems that only one item can be selected, but I am
2983 // removing all selected items anyway.
2984 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2985 for (int i = 0; i < items.size(); ++i) {
2986 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2987 string lfun = fromqstr(items[i]->text(0));
2988 FuncRequest func = lyxaction.lookupFunc(lfun);
2989 KeyMap::ItemType tag =
2990 static_cast<KeyMap::ItemType>(items[i]->data(0, Qt::UserRole).toInt());
2993 case KeyMap::System: {
2994 // for system bind, we do not touch the item
2995 // but add an user unbind item
2996 user_unbind_.bind(shortcut, func);
2997 setItemType(items[i], KeyMap::UserUnbind);
2998 removePB->setText(qt_("Res&tore"));
3001 case KeyMap::UserBind: {
3002 // for user_bind, we remove this bind
3003 QTreeWidgetItem * parent = items[i]->parent();
3004 int itemIdx = parent->indexOfChild(items[i]);
3005 parent->takeChild(itemIdx);
3007 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
3009 shortcutsTW->scrollToItem(parent);
3010 user_bind_.unbind(shortcut, func);
3013 case KeyMap::UserUnbind: {
3014 // for user_unbind, we remove the unbind, and the item
3015 // become KeyMap::System again.
3016 user_unbind_.unbind(shortcut, func);
3017 setItemType(items[i], KeyMap::System);
3018 removePB->setText(qt_("Remo&ve"));
3021 case KeyMap::UserExtraUnbind: {
3022 // for user unbind that is not in system bind file,
3023 // remove this unbind file
3024 QTreeWidgetItem * parent = items[i]->parent();
3025 parent->takeChild(parent->indexOfChild(items[i]));
3026 user_unbind_.unbind(shortcut, func);
3033 void PrefShortcuts::selectBind()
3035 QString file = form_->browsebind(internalPath(bindFileED->text()));
3036 if (!file.isEmpty()) {
3037 bindFileED->setText(file);
3038 system_bind_ = KeyMap();
3039 system_bind_.read(fromqstr(file));
3040 updateShortcutsTW();
3045 void PrefShortcuts::on_modifyPB_pressed()
3051 void PrefShortcuts::on_newPB_pressed()
3053 shortcut_->lfunLE->clear();
3054 shortcut_->shortcutWG->reset();
3055 save_lfun_ = QString();
3060 void PrefShortcuts::on_removePB_pressed()
3067 void PrefShortcuts::on_searchLE_textEdited()
3069 if (searchLE->text().isEmpty()) {
3070 // show all hidden items
3071 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
3073 shortcutsTW->setItemHidden(*it++, false);
3076 // search both columns
3077 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
3078 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
3079 matched += shortcutsTW->findItems(searchLE->text(),
3080 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
3082 // hide everyone (to avoid searching in matched QList repeatedly
3083 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
3085 shortcutsTW->setItemHidden(*it++, true);
3086 // show matched items
3087 for (int i = 0; i < matched.size(); ++i) {
3088 shortcutsTW->setItemHidden(matched[i], false);
3089 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
3094 docstring makeCmdString(FuncRequest const & f)
3096 docstring actionStr = from_ascii(lyxaction.getActionName(f.action()));
3097 if (!f.argument().empty())
3098 actionStr += " " + f.argument();
3103 void PrefShortcuts::shortcutOkPressed()
3105 QString const new_lfun = shortcut_->lfunLE->text();
3106 FuncRequest func = lyxaction.lookupFunc(fromqstr(new_lfun));
3108 if (func.action() == LFUN_UNKNOWN_ACTION) {
3109 Alert::error(_("Failed to create shortcut"),
3110 _("Unknown or invalid LyX function"));
3114 KeySequence k = shortcut_->shortcutWG->getKeySequence();
3115 if (k.length() == 0) {
3116 Alert::error(_("Failed to create shortcut"),
3117 _("Invalid or empty key sequence"));
3121 // check to see if there's been any change
3122 FuncRequest oldBinding = system_bind_.getBinding(k);
3123 if (oldBinding.action() == LFUN_UNKNOWN_ACTION)
3124 oldBinding = user_bind_.getBinding(k);
3125 if (oldBinding == func)
3126 // nothing has changed
3129 // make sure this key isn't already bound---and, if so, not unbound
3130 FuncCode const unbind = user_unbind_.getBinding(k).action();
3131 docstring const action_string = makeCmdString(oldBinding);
3132 if (oldBinding.action() > LFUN_NOACTION && unbind == LFUN_UNKNOWN_ACTION
3133 && save_lfun_ != toqstr(action_string)) {
3134 // FIXME Perhaps we should offer to over-write the old shortcut?
3135 // If so, we'll need to remove it from our list, etc.
3136 Alert::error(_("Failed to create shortcut"),
3137 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s\n"
3138 "You need to remove that binding before creating a new one."),
3139 k.print(KeySequence::ForGui), action_string));
3143 if (!save_lfun_.isEmpty())
3144 // real modification of the lfun's shortcut,
3145 // so remove the previous one
3148 QTreeWidgetItem * item = insertShortcutItem(func, k, KeyMap::UserBind);
3150 user_bind_.bind(&k, func);
3151 shortcutsTW->sortItems(0, Qt::AscendingOrder);
3152 shortcutsTW->setItemExpanded(item->parent(), true);
3153 shortcutsTW->scrollToItem(item);
3155 Alert::error(_("Failed to create shortcut"),
3156 _("Can not insert shortcut to the list"));
3162 void PrefShortcuts::shortcutCancelPressed()
3164 shortcut_->shortcutWG->reset();
3168 void PrefShortcuts::shortcutClearPressed()
3170 shortcut_->shortcutWG->reset();
3174 void PrefShortcuts::shortcutRemovePressed()
3176 shortcut_->shortcutWG->removeFromSequence();
3180 /////////////////////////////////////////////////////////////////////
3184 /////////////////////////////////////////////////////////////////////
3186 PrefIdentity::PrefIdentity(GuiPreferences * form)
3187 : PrefModule(QString(), qt_("Identity"), form)
3191 connect(nameED, SIGNAL(textChanged(QString)),
3192 this, SIGNAL(changed()));
3193 connect(emailED, SIGNAL(textChanged(QString)),
3194 this, SIGNAL(changed()));
3196 nameED->setValidator(new NoNewLineValidator(nameED));
3197 emailED->setValidator(new NoNewLineValidator(emailED));
3201 void PrefIdentity::apply(LyXRC & rc) const
3203 rc.user_name = fromqstr(nameED->text());
3204 rc.user_email = fromqstr(emailED->text());
3208 void PrefIdentity::update(LyXRC const & rc)
3210 nameED->setText(toqstr(rc.user_name));
3211 emailED->setText(toqstr(rc.user_email));
3216 /////////////////////////////////////////////////////////////////////
3220 /////////////////////////////////////////////////////////////////////
3222 GuiPreferences::GuiPreferences(GuiView & lv)
3223 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
3227 QDialog::setModal(false);
3229 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
3230 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
3231 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
3232 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
3234 addModule(new PrefUserInterface(this));
3235 addModule(new PrefEdit(this));
3236 addModule(new PrefShortcuts(this));
3237 PrefScreenFonts * screenfonts = new PrefScreenFonts(this);
3238 connect(this, SIGNAL(prefsApplied(LyXRC const &)),
3239 screenfonts, SLOT(updateScreenFontSizes(LyXRC const &)));
3240 addModule(screenfonts);
3241 addModule(new PrefColors(this));
3242 addModule(new PrefDisplay(this));
3243 addModule(new PrefInput(this));
3244 addModule(new PrefCompletion(this));
3246 addModule(new PrefPaths(this));
3248 addModule(new PrefIdentity(this));
3250 addModule(new PrefLanguage(this));
3251 addModule(new PrefSpellchecker(this));
3253 //for strftime validator
3254 PrefOutput * output = new PrefOutput(this);
3256 addModule(new PrefPrinter(this));
3257 addModule(new PrefLatex(this));
3259 PrefConverters * converters = new PrefConverters(this);
3260 PrefFileformats * formats = new PrefFileformats(this);
3261 connect(formats, SIGNAL(formatsChanged()),
3262 converters, SLOT(updateGui()));
3263 addModule(converters);
3266 prefsPS->setCurrentPanel(qt_("User Interface"));
3267 // FIXME: hack to work around resizing bug in Qt >= 4.2
3268 // bug verified with Qt 4.2.{0-3} (JSpitzm)
3269 #if QT_VERSION >= 0x040200
3270 prefsPS->updateGeometry();
3273 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
3275 bc().setApply(applyPB);
3276 bc().setCancel(closePB);
3277 bc().setRestore(restorePB);
3279 // initialize the strftime validator
3280 bc().addCheckedLineEdit(output->DateED);
3284 void GuiPreferences::addModule(PrefModule * module)
3286 LASSERT(module, return);
3287 if (module->category().isEmpty())
3288 prefsPS->addPanel(module, module->title());
3290 prefsPS->addPanel(module, module->title(), module->category());
3291 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
3292 modules_.push_back(module);
3296 void GuiPreferences::change_adaptor()
3302 void GuiPreferences::apply(LyXRC & rc) const
3304 size_t end = modules_.size();
3305 for (size_t i = 0; i != end; ++i)
3306 modules_[i]->apply(rc);
3310 void GuiPreferences::updateRc(LyXRC const & rc)
3312 size_t const end = modules_.size();
3313 for (size_t i = 0; i != end; ++i)
3314 modules_[i]->update(rc);
3318 void GuiPreferences::applyView()
3324 bool GuiPreferences::initialiseParams(string const &)
3327 formats_ = lyx::formats;
3328 converters_ = theConverters();
3329 converters_.update(formats_);
3330 movers_ = theMovers();
3332 update_screen_font_ = false;
3335 // Make sure that the bc is in the INITIAL state
3336 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3343 void GuiPreferences::dispatchParams()
3346 rc_.write(ss, true);
3347 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
3348 // issue prefsApplied signal. This will update the
3349 // localized screen font sizes.
3351 // FIXME: these need lfuns
3353 Author const & author =
3354 Author(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
3355 theBufferList().recordCurrentAuthor(author);
3357 lyx::formats = formats_;
3359 theConverters() = converters_;
3360 theConverters().update(lyx::formats);
3361 theConverters().buildGraph();
3363 theMovers() = movers_;
3365 vector<string>::const_iterator it = colors_.begin();
3366 vector<string>::const_iterator const end = colors_.end();
3367 for (; it != end; ++it)
3368 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
3371 if (update_screen_font_) {
3372 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
3373 update_screen_font_ = false;
3376 // The Save button has been pressed
3378 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
3382 void GuiPreferences::setColor(ColorCode col, QString const & hex)
3384 colors_.push_back(lcolor.getLyXName(col) + ' ' + fromqstr(hex));
3388 void GuiPreferences::updateScreenFonts()
3390 update_screen_font_ = true;
3394 QString GuiPreferences::browsebind(QString const & file) const
3396 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
3397 QStringList(qt_("LyX bind files (*.bind)")));
3401 QString GuiPreferences::browseUI(QString const & file) const
3403 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
3404 QStringList(qt_("LyX UI files (*.ui)")));
3408 QString GuiPreferences::browsekbmap(QString const & file) const
3410 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
3411 QStringList(qt_("LyX keyboard maps (*.kmap)")));
3415 QString GuiPreferences::browse(QString const & file,
3416 QString const & title) const
3418 return browseFile(file, title, QStringList(), true);
3422 // We support less paper sizes than the document dialog
3423 // Therefore this adjustment is needed.
3424 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
3428 return PAPER_DEFAULT;
3430 return PAPER_USLETTER;
3432 return PAPER_USLEGAL;
3434 return PAPER_USEXECUTIVE;
3444 // should not happen
3445 return PAPER_DEFAULT;
3450 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
3452 switch (papersize) {
3455 case PAPER_USLETTER:
3459 case PAPER_USEXECUTIVE:
3470 // should not happen
3476 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
3479 } // namespace frontend
3482 #include "moc_GuiPrefs.cpp"