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 extensionsED->setValidator(new NoNewLineValidator(extensionsED));
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 extensionsED->setText(toqstr(f.extensions()));
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_extensionsED_textEdited(const QString & s)
2050 currentFormat().setExtensions(fromqstr(s));
2055 void PrefFileformats::on_viewerED_textEdited(const QString & s)
2057 currentFormat().setViewer(fromqstr(s));
2062 void PrefFileformats::on_editorED_textEdited(const QString & s)
2064 currentFormat().setEditor(fromqstr(s));
2069 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
2071 string const new_shortcut = fromqstr(s);
2072 if (new_shortcut == l10n_shortcut(currentFormat().prettyname(),
2073 currentFormat().shortcut()))
2075 currentFormat().setShortcut(new_shortcut);
2080 void PrefFileformats::on_formatED_editingFinished()
2082 string const newname = fromqstr(formatED->displayText());
2083 string const oldname = currentFormat().name();
2084 if (newname == oldname)
2086 if (form_->converters().formatIsUsed(oldname)) {
2087 Alert::error(_("Format in use"),
2088 _("You cannot change a format's short name "
2089 "if the format is used by a converter. "
2090 "Please remove the converter first."));
2095 currentFormat().setName(newname);
2100 void PrefFileformats::on_formatED_textChanged(const QString &)
2102 QString t = formatED->text();
2104 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
2105 setValid(formatLA, valid);
2109 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
2111 QString t = formatsCB->currentText();
2113 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
2114 setValid(formatsLA, valid);
2118 void PrefFileformats::updatePrettyname()
2120 QString const newname = formatsCB->currentText();
2121 if (newname == qt_(currentFormat().prettyname()))
2124 currentFormat().setPrettyname(fromqstr(newname));
2132 void updateComboBox(LyXRC::Alternatives const & alts,
2133 string const & fmt, QComboBox * combo)
2135 LyXRC::Alternatives::const_iterator it =
2137 if (it != alts.end()) {
2138 LyXRC::CommandSet const & cmds = it->second;
2139 LyXRC::CommandSet::const_iterator sit =
2141 LyXRC::CommandSet::const_iterator const sen =
2143 for (; sit != sen; ++sit) {
2144 QString const qcmd = toqstr(*sit);
2145 combo->addItem(qcmd, qcmd);
2152 void PrefFileformats::updateViewers()
2154 Format const f = currentFormat();
2155 viewerCO->blockSignals(true);
2157 viewerCO->addItem(qt_("None"), QString());
2158 updateComboBox(viewer_alternatives, f.name(), viewerCO);
2159 viewerCO->addItem(qt_("Custom"), QString("custom viewer"));
2160 viewerCO->blockSignals(false);
2162 int pos = viewerCO->findData(toqstr(f.viewer()));
2165 viewerED->setEnabled(false);
2166 viewerCO->setCurrentIndex(pos);
2168 viewerED->setEnabled(true);
2169 viewerED->setText(toqstr(f.viewer()));
2170 viewerCO->setCurrentIndex(viewerCO->findData(toqstr("custom viewer")));
2175 void PrefFileformats::updateEditors()
2177 Format const f = currentFormat();
2178 editorCO->blockSignals(true);
2180 editorCO->addItem(qt_("None"), QString());
2181 updateComboBox(editor_alternatives, f.name(), editorCO);
2182 editorCO->addItem(qt_("Custom"), QString("custom editor"));
2183 editorCO->blockSignals(false);
2185 int pos = editorCO->findData(toqstr(f.editor()));
2188 editorED->setEnabled(false);
2189 editorCO->setCurrentIndex(pos);
2191 editorED->setEnabled(true);
2192 editorED->setText(toqstr(f.editor()));
2193 editorCO->setCurrentIndex(editorCO->findData(toqstr("custom editor")));
2198 void PrefFileformats::on_viewerCO_currentIndexChanged(int i)
2200 bool const custom = viewerCO->itemData(i).toString() == "custom viewer";
2201 viewerED->setEnabled(custom);
2203 currentFormat().setViewer(fromqstr(viewerCO->itemData(i).toString()));
2207 void PrefFileformats::on_editorCO_currentIndexChanged(int i)
2209 bool const custom = editorCO->itemData(i).toString() == "custom editor";
2210 editorED->setEnabled(custom);
2212 currentFormat().setEditor(fromqstr(editorCO->itemData(i).toString()));
2216 Format & PrefFileformats::currentFormat()
2218 int const i = formatsCB->currentIndex();
2219 int const nr = formatsCB->itemData(i).toInt();
2220 return form_->formats().get(nr);
2224 void PrefFileformats::on_formatNewPB_clicked()
2226 form_->formats().add("", "", "", "", "", "", Format::none);
2228 formatsCB->setCurrentIndex(0);
2229 formatsCB->setFocus(Qt::OtherFocusReason);
2233 void PrefFileformats::on_formatRemovePB_clicked()
2235 int const i = formatsCB->currentIndex();
2236 int const nr = formatsCB->itemData(i).toInt();
2237 string const current_text = form_->formats().get(nr).name();
2238 if (form_->converters().formatIsUsed(current_text)) {
2239 Alert::error(_("Format in use"),
2240 _("Cannot remove a Format used by a Converter. "
2241 "Remove the converter first."));
2245 form_->formats().erase(current_text);
2248 on_formatsCB_editTextChanged(formatsCB->currentText());
2253 /////////////////////////////////////////////////////////////////////
2257 /////////////////////////////////////////////////////////////////////
2259 PrefLanguage::PrefLanguage(GuiPreferences * form)
2260 : PrefModule(qt_(catLanguage), qt_("Language"), form)
2264 connect(rtlGB, SIGNAL(clicked()),
2265 this, SIGNAL(changed()));
2266 connect(visualCursorRB, SIGNAL(clicked()),
2267 this, SIGNAL(changed()));
2268 connect(logicalCursorRB, SIGNAL(clicked()),
2269 this, SIGNAL(changed()));
2270 connect(markForeignCB, SIGNAL(clicked()),
2271 this, SIGNAL(changed()));
2272 connect(autoBeginCB, SIGNAL(clicked()),
2273 this, SIGNAL(changed()));
2274 connect(autoEndCB, SIGNAL(clicked()),
2275 this, SIGNAL(changed()));
2276 connect(languagePackageCO, SIGNAL(activated(int)),
2277 this, SIGNAL(changed()));
2278 connect(languagePackageED, SIGNAL(textChanged(QString)),
2279 this, SIGNAL(changed()));
2280 connect(globalCB, SIGNAL(clicked()),
2281 this, SIGNAL(changed()));
2282 connect(startCommandED, SIGNAL(textChanged(QString)),
2283 this, SIGNAL(changed()));
2284 connect(endCommandED, SIGNAL(textChanged(QString)),
2285 this, SIGNAL(changed()));
2286 connect(uiLanguageCO, SIGNAL(activated(int)),
2287 this, SIGNAL(changed()));
2288 connect(defaultDecimalPointLE, SIGNAL(textChanged(QString)),
2289 this, SIGNAL(changed()));
2291 languagePackageED->setValidator(new NoNewLineValidator(languagePackageED));
2292 startCommandED->setValidator(new NoNewLineValidator(startCommandED));
2293 endCommandED->setValidator(new NoNewLineValidator(endCommandED));
2295 uiLanguageCO->clear();
2297 QAbstractItemModel * language_model = guiApp->languageModel();
2298 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
2299 language_model->sort(0);
2300 defaultDecimalPointLE->setInputMask("X; ");
2301 defaultDecimalPointLE->setMaxLength(1);
2304 uiLanguageCO->blockSignals(true);
2305 uiLanguageCO->addItem(qt_("Default"), toqstr("auto"));
2306 for (int i = 0; i != language_model->rowCount(); ++i) {
2307 QModelIndex index = language_model->index(i, 0);
2308 // Filter the list based on the available translation and add
2309 // each language code only once
2310 string const name = fromqstr(index.data(Qt::UserRole).toString());
2311 Language const * lang = languages.getLanguage(name);
2312 // never remove the currently selected language
2313 if (lang && name != form->rc().gui_language && name != lyxrc.gui_language)
2314 if (!lang->translated() || added.find(lang->code()) != added.end())
2316 added.insert(lang->code());
2317 uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
2318 index.data(Qt::UserRole).toString());
2320 uiLanguageCO->blockSignals(false);
2324 void PrefLanguage::on_uiLanguageCO_currentIndexChanged(int)
2326 QMessageBox::information(this, qt_("LyX needs to be restarted!"),
2327 qt_("The change of user interface language will be fully "
2328 "effective only after a restart."));
2332 void PrefLanguage::on_languagePackageCO_currentIndexChanged(int i)
2334 languagePackageED->setEnabled(i == 2);
2338 void PrefLanguage::apply(LyXRC & rc) const
2340 // FIXME: remove rtl_support bool
2341 rc.rtl_support = rtlGB->isChecked();
2342 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
2343 rc.mark_foreign_language = markForeignCB->isChecked();
2344 rc.language_auto_begin = autoBeginCB->isChecked();
2345 rc.language_auto_end = autoEndCB->isChecked();
2346 int const p = languagePackageCO->currentIndex();
2348 rc.language_package_selection = LyXRC::LP_AUTO;
2350 rc.language_package_selection = LyXRC::LP_BABEL;
2352 rc.language_package_selection = LyXRC::LP_CUSTOM;
2354 rc.language_package_selection = LyXRC::LP_NONE;
2355 rc.language_custom_package = fromqstr(languagePackageED->text());
2356 rc.language_global_options = globalCB->isChecked();
2357 rc.language_command_begin = fromqstr(startCommandED->text());
2358 rc.language_command_end = fromqstr(endCommandED->text());
2359 rc.gui_language = fromqstr(
2360 uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString());
2361 rc.default_decimal_point = fromqstr(defaultDecimalPointLE->text());
2365 void PrefLanguage::update(LyXRC const & rc)
2367 // FIXME: remove rtl_support bool
2368 rtlGB->setChecked(rc.rtl_support);
2369 if (rc.visual_cursor)
2370 visualCursorRB->setChecked(true);
2372 logicalCursorRB->setChecked(true);
2373 markForeignCB->setChecked(rc.mark_foreign_language);
2374 autoBeginCB->setChecked(rc.language_auto_begin);
2375 autoEndCB->setChecked(rc.language_auto_end);
2376 languagePackageCO->setCurrentIndex(rc.language_package_selection);
2377 languagePackageED->setText(toqstr(rc.language_custom_package));
2378 languagePackageED->setEnabled(languagePackageCO->currentIndex() == 2);
2379 globalCB->setChecked(rc.language_global_options);
2380 startCommandED->setText(toqstr(rc.language_command_begin));
2381 endCommandED->setText(toqstr(rc.language_command_end));
2382 defaultDecimalPointLE->setText(toqstr(rc.default_decimal_point));
2384 int pos = uiLanguageCO->findData(toqstr(rc.gui_language));
2385 uiLanguageCO->blockSignals(true);
2386 uiLanguageCO->setCurrentIndex(pos);
2387 uiLanguageCO->blockSignals(false);
2391 /////////////////////////////////////////////////////////////////////
2395 /////////////////////////////////////////////////////////////////////
2397 PrefPrinter::PrefPrinter(GuiPreferences * form)
2398 : PrefModule(qt_(catOutput), qt_("Printer"), form)
2402 connect(printerAdaptCB, SIGNAL(clicked()),
2403 this, SIGNAL(changed()));
2404 connect(printerCommandED, SIGNAL(textChanged(QString)),
2405 this, SIGNAL(changed()));
2406 connect(printerNameED, SIGNAL(textChanged(QString)),
2407 this, SIGNAL(changed()));
2408 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
2409 this, SIGNAL(changed()));
2410 connect(printerCopiesED, SIGNAL(textChanged(QString)),
2411 this, SIGNAL(changed()));
2412 connect(printerReverseED, SIGNAL(textChanged(QString)),
2413 this, SIGNAL(changed()));
2414 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
2415 this, SIGNAL(changed()));
2416 connect(printerExtensionED, SIGNAL(textChanged(QString)),
2417 this, SIGNAL(changed()));
2418 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
2419 this, SIGNAL(changed()));
2420 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
2421 this, SIGNAL(changed()));
2422 connect(printerEvenED, SIGNAL(textChanged(QString)),
2423 this, SIGNAL(changed()));
2424 connect(printerOddED, SIGNAL(textChanged(QString)),
2425 this, SIGNAL(changed()));
2426 connect(printerCollatedED, SIGNAL(textChanged(QString)),
2427 this, SIGNAL(changed()));
2428 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
2429 this, SIGNAL(changed()));
2430 connect(printerToFileED, SIGNAL(textChanged(QString)),
2431 this, SIGNAL(changed()));
2432 connect(printerExtraED, SIGNAL(textChanged(QString)),
2433 this, SIGNAL(changed()));
2434 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
2435 this, SIGNAL(changed()));
2436 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
2437 this, SIGNAL(changed()));
2439 printerNameED->setValidator(new NoNewLineValidator(printerNameED));
2440 printerCommandED->setValidator(new NoNewLineValidator(printerCommandED));
2441 printerEvenED->setValidator(new NoNewLineValidator(printerEvenED));
2442 printerPageRangeED->setValidator(new NoNewLineValidator(printerPageRangeED));
2443 printerCopiesED->setValidator(new NoNewLineValidator(printerCopiesED));
2444 printerReverseED->setValidator(new NoNewLineValidator(printerReverseED));
2445 printerToFileED->setValidator(new NoNewLineValidator(printerToFileED));
2446 printerPaperTypeED->setValidator(new NoNewLineValidator(printerPaperTypeED));
2447 printerExtraED->setValidator(new NoNewLineValidator(printerExtraED));
2448 printerOddED->setValidator(new NoNewLineValidator(printerOddED));
2449 printerCollatedED->setValidator(new NoNewLineValidator(printerCollatedED));
2450 printerLandscapeED->setValidator(new NoNewLineValidator(printerLandscapeED));
2451 printerToPrinterED->setValidator(new NoNewLineValidator(printerToPrinterED));
2452 printerExtensionED->setValidator(new NoNewLineValidator(printerExtensionED));
2453 printerPaperSizeED->setValidator(new NoNewLineValidator(printerPaperSizeED));
2454 printerSpoolCommandED->setValidator(new NoNewLineValidator(printerSpoolCommandED));
2455 printerSpoolPrefixED->setValidator(new NoNewLineValidator(printerSpoolPrefixED));
2459 void PrefPrinter::apply(LyXRC & rc) const
2461 rc.print_adapt_output = printerAdaptCB->isChecked();
2462 rc.print_command = fromqstr(printerCommandED->text());
2463 rc.printer = fromqstr(printerNameED->text());
2465 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
2466 rc.print_copies_flag = fromqstr(printerCopiesED->text());
2467 rc.print_reverse_flag = fromqstr(printerReverseED->text());
2468 rc.print_to_printer = fromqstr(printerToPrinterED->text());
2469 rc.print_file_extension = fromqstr(printerExtensionED->text());
2470 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
2471 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
2472 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
2473 rc.print_oddpage_flag = fromqstr(printerOddED->text());
2474 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
2475 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
2476 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
2477 rc.print_extra_options = fromqstr(printerExtraED->text());
2478 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
2479 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
2483 void PrefPrinter::update(LyXRC const & rc)
2485 printerAdaptCB->setChecked(rc.print_adapt_output);
2486 printerCommandED->setText(toqstr(rc.print_command));
2487 printerNameED->setText(toqstr(rc.printer));
2489 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
2490 printerCopiesED->setText(toqstr(rc.print_copies_flag));
2491 printerReverseED->setText(toqstr(rc.print_reverse_flag));
2492 printerToPrinterED->setText(toqstr(rc.print_to_printer));
2493 printerExtensionED->setText(toqstr(rc.print_file_extension));
2494 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
2495 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
2496 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
2497 printerOddED->setText(toqstr(rc.print_oddpage_flag));
2498 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
2499 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
2500 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
2501 printerExtraED->setText(toqstr(rc.print_extra_options));
2502 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
2503 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
2507 /////////////////////////////////////////////////////////////////////
2509 // PrefUserInterface
2511 /////////////////////////////////////////////////////////////////////
2513 PrefUserInterface::PrefUserInterface(GuiPreferences * form)
2514 : PrefModule(qt_(catLookAndFeel), qt_("User Interface"), form)
2518 connect(autoSaveCB, SIGNAL(toggled(bool)),
2519 autoSaveSB, SLOT(setEnabled(bool)));
2520 connect(autoSaveCB, SIGNAL(toggled(bool)),
2521 TextLabel1, SLOT(setEnabled(bool)));
2522 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
2523 this, SIGNAL(changed()));
2524 connect(singleInstanceCB, SIGNAL(clicked()),
2525 this, SIGNAL(changed()));
2526 #if QT_VERSION < 0x040500
2527 singleCloseTabButtonCB->setEnabled(false);
2529 connect(singleCloseTabButtonCB, SIGNAL(clicked()),
2530 this, SIGNAL(changed()));
2531 connect(uiFilePB, SIGNAL(clicked()),
2532 this, SLOT(selectUi()));
2533 connect(uiFileED, SIGNAL(textChanged(QString)),
2534 this, SIGNAL(changed()));
2535 connect(iconSetCO, SIGNAL(activated(int)),
2536 this, SIGNAL(changed()));
2537 connect(restoreCursorCB, SIGNAL(clicked()),
2538 this, SIGNAL(changed()));
2539 connect(loadSessionCB, SIGNAL(clicked()),
2540 this, SIGNAL(changed()));
2541 connect(allowGeometrySessionCB, SIGNAL(clicked()),
2542 this, SIGNAL(changed()));
2543 connect(autoSaveSB, SIGNAL(valueChanged(int)),
2544 this, SIGNAL(changed()));
2545 connect(autoSaveCB, SIGNAL(clicked()),
2546 this, SIGNAL(changed()));
2547 connect(backupCB, SIGNAL(clicked()),
2548 this, SIGNAL(changed()));
2549 connect(saveCompressedCB, SIGNAL(clicked()),
2550 this, SIGNAL(changed()));
2551 connect(lastfilesSB, SIGNAL(valueChanged(int)),
2552 this, SIGNAL(changed()));
2553 connect(tooltipCB, SIGNAL(toggled(bool)),
2554 this, SIGNAL(changed()));
2555 lastfilesSB->setMaximum(maxlastfiles);
2557 iconSetCO->addItem(qt_("Default"), QString());
2558 iconSetCO->addItem(qt_("Classic"), "classic");
2559 iconSetCO->addItem(qt_("Oxygen"), "oxygen");
2563 void PrefUserInterface::apply(LyXRC & rc) const
2565 rc.icon_set = fromqstr(iconSetCO->itemData(
2566 iconSetCO->currentIndex()).toString());
2568 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
2569 rc.use_lastfilepos = restoreCursorCB->isChecked();
2570 rc.load_session = loadSessionCB->isChecked();
2571 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
2572 rc.autosave = autoSaveCB->isChecked() ? autoSaveSB->value() * 60 : 0;
2573 rc.make_backup = backupCB->isChecked();
2574 rc.save_compressed = saveCompressedCB->isChecked();
2575 rc.num_lastfiles = lastfilesSB->value();
2576 rc.use_tooltip = tooltipCB->isChecked();
2577 rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
2578 rc.single_instance = singleInstanceCB->isChecked();
2579 rc.single_close_tab_button = singleCloseTabButtonCB->isChecked();
2580 #if QT_VERSION < 0x040500
2581 rc.single_close_tab_button = true;
2586 void PrefUserInterface::update(LyXRC const & rc)
2588 int iconset = iconSetCO->findData(toqstr(rc.icon_set));
2591 iconSetCO->setCurrentIndex(iconset);
2592 uiFileED->setText(toqstr(external_path(rc.ui_file)));
2593 restoreCursorCB->setChecked(rc.use_lastfilepos);
2594 loadSessionCB->setChecked(rc.load_session);
2595 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
2596 // convert to minutes
2597 bool autosave = rc.autosave > 0;
2598 int mins = rc.autosave / 60;
2601 autoSaveSB->setValue(mins);
2602 autoSaveCB->setChecked(autosave);
2603 autoSaveSB->setEnabled(autosave);
2604 backupCB->setChecked(rc.make_backup);
2605 saveCompressedCB->setChecked(rc.save_compressed);
2606 lastfilesSB->setValue(rc.num_lastfiles);
2607 tooltipCB->setChecked(rc.use_tooltip);
2608 openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
2609 singleInstanceCB->setChecked(rc.single_instance && !rc.lyxpipes.empty());
2610 singleInstanceCB->setEnabled(!rc.lyxpipes.empty());
2611 singleCloseTabButtonCB->setChecked(rc.single_close_tab_button);
2615 void PrefUserInterface::selectUi()
2617 QString file = form_->browseUI(internalPath(uiFileED->text()));
2618 if (!file.isEmpty())
2619 uiFileED->setText(file);
2623 void PrefUserInterface::on_clearSessionPB_clicked()
2625 guiApp->clearSession();
2630 /////////////////////////////////////////////////////////////////////
2634 /////////////////////////////////////////////////////////////////////
2636 PrefEdit::PrefEdit(GuiPreferences * form)
2637 : PrefModule(qt_(catEditing), qt_("Control"), form)
2641 connect(cursorFollowsCB, SIGNAL(clicked()),
2642 this, SIGNAL(changed()));
2643 connect(scrollBelowCB, SIGNAL(clicked()),
2644 this, SIGNAL(changed()));
2645 connect(macLikeWordMovementCB, SIGNAL(clicked()),
2646 this, SIGNAL(changed()));
2647 connect(sortEnvironmentsCB, SIGNAL(clicked()),
2648 this, SIGNAL(changed()));
2649 connect(groupEnvironmentsCB, SIGNAL(clicked()),
2650 this, SIGNAL(changed()));
2651 connect(macroEditStyleCO, SIGNAL(activated(int)),
2652 this, SIGNAL(changed()));
2653 connect(cursorWidthSB, SIGNAL(valueChanged(int)),
2654 this, SIGNAL(changed()));
2655 connect(fullscreenLimitGB, SIGNAL(clicked()),
2656 this, SIGNAL(changed()));
2657 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
2658 this, SIGNAL(changed()));
2659 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
2660 this, SIGNAL(changed()));
2661 connect(toggleMenubarCB, SIGNAL(toggled(bool)),
2662 this, SIGNAL(changed()));
2663 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
2664 this, SIGNAL(changed()));
2665 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
2666 this, SIGNAL(changed()));
2670 void PrefEdit::apply(LyXRC & rc) const
2672 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
2673 rc.scroll_below_document = scrollBelowCB->isChecked();
2674 rc.mac_like_word_movement = macLikeWordMovementCB->isChecked();
2675 rc.sort_layouts = sortEnvironmentsCB->isChecked();
2676 rc.group_layouts = groupEnvironmentsCB->isChecked();
2677 switch (macroEditStyleCO->currentIndex()) {
2678 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
2679 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
2680 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
2682 rc.cursor_width = cursorWidthSB->value();
2683 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
2684 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
2685 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
2686 rc.full_screen_menubar = toggleMenubarCB->isChecked();
2687 rc.full_screen_width = fullscreenWidthSB->value();
2688 rc.full_screen_limit = fullscreenLimitGB->isChecked();
2692 void PrefEdit::update(LyXRC const & rc)
2694 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
2695 scrollBelowCB->setChecked(rc.scroll_below_document);
2696 macLikeWordMovementCB->setChecked(rc.mac_like_word_movement);
2697 sortEnvironmentsCB->setChecked(rc.sort_layouts);
2698 groupEnvironmentsCB->setChecked(rc.group_layouts);
2699 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
2700 cursorWidthSB->setValue(rc.cursor_width);
2701 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
2702 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
2703 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
2704 toggleMenubarCB->setChecked(rc.full_screen_menubar);
2705 fullscreenWidthSB->setValue(rc.full_screen_width);
2706 fullscreenLimitGB->setChecked(rc.full_screen_limit);
2710 /////////////////////////////////////////////////////////////////////
2714 /////////////////////////////////////////////////////////////////////
2717 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
2719 Ui::shortcutUi::setupUi(this);
2720 QDialog::setModal(true);
2724 PrefShortcuts::PrefShortcuts(GuiPreferences * form)
2725 : PrefModule(qt_(catEditing), qt_("Shortcuts"), form)
2729 shortcutsTW->setColumnCount(2);
2730 shortcutsTW->headerItem()->setText(0, qt_("Function"));
2731 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
2732 shortcutsTW->setSortingEnabled(true);
2733 // Multi-selection can be annoying.
2734 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
2736 connect(bindFilePB, SIGNAL(clicked()),
2737 this, SLOT(selectBind()));
2738 connect(bindFileED, SIGNAL(textChanged(QString)),
2739 this, SIGNAL(changed()));
2741 shortcut_ = new GuiShortcutDialog(this);
2742 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
2743 shortcut_bc_.setOK(shortcut_->okPB);
2744 shortcut_bc_.setCancel(shortcut_->cancelPB);
2746 connect(shortcut_->okPB, SIGNAL(clicked()),
2747 shortcut_, SLOT(accept()));
2748 connect(shortcut_->okPB, SIGNAL(clicked()),
2749 this, SIGNAL(changed()));
2750 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2751 shortcut_, SLOT(reject()));
2752 connect(shortcut_->clearPB, SIGNAL(clicked()),
2753 this, SLOT(shortcutClearPressed()));
2754 connect(shortcut_->removePB, SIGNAL(clicked()),
2755 this, SLOT(shortcutRemovePressed()));
2756 connect(shortcut_->okPB, SIGNAL(clicked()),
2757 this, SLOT(shortcutOkPressed()));
2758 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2759 this, SLOT(shortcutCancelPressed()));
2763 void PrefShortcuts::apply(LyXRC & rc) const
2765 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
2766 // write user_bind and user_unbind to .lyx/bind/user.bind
2767 FileName bind_dir(addPath(package().user_support().absFileName(), "bind"));
2768 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
2769 lyxerr << "LyX could not create the user bind directory '"
2770 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2773 if (!bind_dir.isDirWritable()) {
2774 lyxerr << "LyX could not write to the user bind directory '"
2775 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2778 FileName user_bind_file(bind_dir.absFileName() + "/user.bind");
2779 user_unbind_.write(user_bind_file.toFilesystemEncoding(), false, true);
2780 user_bind_.write(user_bind_file.toFilesystemEncoding(), true, false);
2781 // immediately apply the keybindings. Why this is not done before?
2782 // The good thing is that the menus are updated automatically.
2783 theTopLevelKeymap().clear();
2784 theTopLevelKeymap().read("site");
2785 theTopLevelKeymap().read(rc.bind_file, 0, KeyMap::Fallback);
2786 theTopLevelKeymap().read("user", 0, KeyMap::MissingOK);
2790 void PrefShortcuts::update(LyXRC const & rc)
2792 bindFileED->setText(toqstr(external_path(rc.bind_file)));
2794 system_bind_.clear();
2796 user_unbind_.clear();
2797 system_bind_.read("site");
2798 system_bind_.read(rc.bind_file);
2799 // \unbind in user.bind is added to user_unbind_
2800 user_bind_.read("user", &user_unbind_, KeyMap::MissingOK);
2801 updateShortcutsTW();
2805 void PrefShortcuts::updateShortcutsTW()
2807 shortcutsTW->clear();
2809 editItem_ = new QTreeWidgetItem(shortcutsTW);
2810 editItem_->setText(0, qt_("Cursor, Mouse and Editing Functions"));
2811 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2813 mathItem_ = new QTreeWidgetItem(shortcutsTW);
2814 mathItem_->setText(0, qt_("Mathematical Symbols"));
2815 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2817 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2818 bufferItem_->setText(0, qt_("Document and Window"));
2819 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2821 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2822 layoutItem_->setText(0, qt_("Font, Layouts and Textclasses"));
2823 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2825 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2826 systemItem_->setText(0, qt_("System and Miscellaneous"));
2827 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2829 // listBindings(unbound=true) lists all bound and unbound lfuns
2830 // Items in this list is tagged by its source.
2831 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2833 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2835 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2836 KeyMap::UserUnbind);
2837 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2838 user_bindinglist.end());
2839 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2840 user_unbindinglist.end());
2842 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2843 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2844 for (; it != it_end; ++it)
2845 insertShortcutItem(it->request, it->sequence, KeyMap::ItemType(it->tag));
2847 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2848 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2849 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2850 modifyPB->setEnabled(!items.isEmpty());
2852 shortcutsTW->resizeColumnToContents(0);
2856 void PrefShortcuts::setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag)
2858 item->setData(0, Qt::UserRole, QVariant(tag));
2862 case KeyMap::System:
2864 case KeyMap::UserBind:
2867 case KeyMap::UserUnbind:
2868 font.setStrikeOut(true);
2870 // this item is not displayed now.
2871 case KeyMap::UserExtraUnbind:
2872 font.setStrikeOut(true);
2876 item->setFont(1, font);
2880 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2881 KeySequence const & seq, KeyMap::ItemType tag)
2883 FuncCode const action = lfun.action();
2884 string const action_name = lyxaction.getActionName(action);
2885 QString const lfun_name = toqstr(from_utf8(action_name)
2886 + ' ' + lfun.argument());
2887 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2888 KeyMap::ItemType item_tag = tag;
2890 QTreeWidgetItem * newItem = 0;
2891 // for unbind items, try to find an existing item in the system bind list
2892 if (tag == KeyMap::UserUnbind) {
2893 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2894 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2895 for (int i = 0; i < items.size(); ++i) {
2896 if (items[i]->text(1) == shortcut)
2900 // if not found, this unbind item is KeyMap::UserExtraUnbind
2901 // Such an item is not displayed to avoid confusion (what is
2902 // unmatched removed?).
2904 item_tag = KeyMap::UserExtraUnbind;
2909 switch(lyxaction.getActionType(action)) {
2910 case LyXAction::Hidden:
2912 case LyXAction::Edit:
2913 newItem = new QTreeWidgetItem(editItem_);
2915 case LyXAction::Math:
2916 newItem = new QTreeWidgetItem(mathItem_);
2918 case LyXAction::Buffer:
2919 newItem = new QTreeWidgetItem(bufferItem_);
2921 case LyXAction::Layout:
2922 newItem = new QTreeWidgetItem(layoutItem_);
2924 case LyXAction::System:
2925 newItem = new QTreeWidgetItem(systemItem_);
2928 // this should not happen
2929 newItem = new QTreeWidgetItem(shortcutsTW);
2933 newItem->setText(0, lfun_name);
2934 newItem->setText(1, shortcut);
2935 // record BindFile representation to recover KeySequence when needed.
2936 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2937 setItemType(newItem, item_tag);
2942 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2944 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2945 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2946 modifyPB->setEnabled(!items.isEmpty());
2947 if (items.isEmpty())
2950 KeyMap::ItemType tag =
2951 static_cast<KeyMap::ItemType>(items[0]->data(0, Qt::UserRole).toInt());
2952 if (tag == KeyMap::UserUnbind)
2953 removePB->setText(qt_("Res&tore"));
2955 removePB->setText(qt_("Remo&ve"));
2959 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2965 void PrefShortcuts::modifyShortcut()
2967 QTreeWidgetItem * item = shortcutsTW->currentItem();
2968 if (item->flags() & Qt::ItemIsSelectable) {
2969 shortcut_->lfunLE->setText(item->text(0));
2970 save_lfun_ = item->text(0).trimmed();
2971 shortcut_->shortcutWG->setText(item->text(1));
2973 seq.parse(fromqstr(item->data(1, Qt::UserRole).toString()));
2974 shortcut_->shortcutWG->setKeySequence(seq);
2975 shortcut_->shortcutWG->setFocus();
2981 void PrefShortcuts::removeShortcut()
2983 // it seems that only one item can be selected, but I am
2984 // removing all selected items anyway.
2985 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2986 for (int i = 0; i < items.size(); ++i) {
2987 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2988 string lfun = fromqstr(items[i]->text(0));
2989 FuncRequest func = lyxaction.lookupFunc(lfun);
2990 KeyMap::ItemType tag =
2991 static_cast<KeyMap::ItemType>(items[i]->data(0, Qt::UserRole).toInt());
2994 case KeyMap::System: {
2995 // for system bind, we do not touch the item
2996 // but add an user unbind item
2997 user_unbind_.bind(shortcut, func);
2998 setItemType(items[i], KeyMap::UserUnbind);
2999 removePB->setText(qt_("Res&tore"));
3002 case KeyMap::UserBind: {
3003 // for user_bind, we remove this bind
3004 QTreeWidgetItem * parent = items[i]->parent();
3005 int itemIdx = parent->indexOfChild(items[i]);
3006 parent->takeChild(itemIdx);
3008 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
3010 shortcutsTW->scrollToItem(parent);
3011 user_bind_.unbind(shortcut, func);
3014 case KeyMap::UserUnbind: {
3015 // for user_unbind, we remove the unbind, and the item
3016 // become KeyMap::System again.
3017 user_unbind_.unbind(shortcut, func);
3018 setItemType(items[i], KeyMap::System);
3019 removePB->setText(qt_("Remo&ve"));
3022 case KeyMap::UserExtraUnbind: {
3023 // for user unbind that is not in system bind file,
3024 // remove this unbind file
3025 QTreeWidgetItem * parent = items[i]->parent();
3026 parent->takeChild(parent->indexOfChild(items[i]));
3027 user_unbind_.unbind(shortcut, func);
3034 void PrefShortcuts::selectBind()
3036 QString file = form_->browsebind(internalPath(bindFileED->text()));
3037 if (!file.isEmpty()) {
3038 bindFileED->setText(file);
3039 system_bind_ = KeyMap();
3040 system_bind_.read(fromqstr(file));
3041 updateShortcutsTW();
3046 void PrefShortcuts::on_modifyPB_pressed()
3052 void PrefShortcuts::on_newPB_pressed()
3054 shortcut_->lfunLE->clear();
3055 shortcut_->shortcutWG->reset();
3056 save_lfun_ = QString();
3061 void PrefShortcuts::on_removePB_pressed()
3068 void PrefShortcuts::on_searchLE_textEdited()
3070 if (searchLE->text().isEmpty()) {
3071 // show all hidden items
3072 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
3074 shortcutsTW->setItemHidden(*it++, false);
3077 // search both columns
3078 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
3079 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
3080 matched += shortcutsTW->findItems(searchLE->text(),
3081 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
3083 // hide everyone (to avoid searching in matched QList repeatedly
3084 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
3086 shortcutsTW->setItemHidden(*it++, true);
3087 // show matched items
3088 for (int i = 0; i < matched.size(); ++i) {
3089 shortcutsTW->setItemHidden(matched[i], false);
3090 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
3095 docstring makeCmdString(FuncRequest const & f)
3097 docstring actionStr = from_ascii(lyxaction.getActionName(f.action()));
3098 if (!f.argument().empty())
3099 actionStr += " " + f.argument();
3104 void PrefShortcuts::shortcutOkPressed()
3106 QString const new_lfun = shortcut_->lfunLE->text();
3107 FuncRequest func = lyxaction.lookupFunc(fromqstr(new_lfun));
3109 if (func.action() == LFUN_UNKNOWN_ACTION) {
3110 Alert::error(_("Failed to create shortcut"),
3111 _("Unknown or invalid LyX function"));
3115 KeySequence k = shortcut_->shortcutWG->getKeySequence();
3116 if (k.length() == 0) {
3117 Alert::error(_("Failed to create shortcut"),
3118 _("Invalid or empty key sequence"));
3122 // check to see if there's been any change
3123 FuncRequest oldBinding = system_bind_.getBinding(k);
3124 if (oldBinding.action() == LFUN_UNKNOWN_ACTION)
3125 oldBinding = user_bind_.getBinding(k);
3126 if (oldBinding == func)
3127 // nothing has changed
3130 // make sure this key isn't already bound---and, if so, not unbound
3131 FuncCode const unbind = user_unbind_.getBinding(k).action();
3132 docstring const action_string = makeCmdString(oldBinding);
3133 if (oldBinding.action() > LFUN_NOACTION && unbind == LFUN_UNKNOWN_ACTION
3134 && save_lfun_ != toqstr(action_string)) {
3135 // FIXME Perhaps we should offer to over-write the old shortcut?
3136 // If so, we'll need to remove it from our list, etc.
3137 Alert::error(_("Failed to create shortcut"),
3138 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s\n"
3139 "You need to remove that binding before creating a new one."),
3140 k.print(KeySequence::ForGui), action_string));
3144 if (!save_lfun_.isEmpty())
3145 // real modification of the lfun's shortcut,
3146 // so remove the previous one
3149 QTreeWidgetItem * item = insertShortcutItem(func, k, KeyMap::UserBind);
3151 user_bind_.bind(&k, func);
3152 shortcutsTW->sortItems(0, Qt::AscendingOrder);
3153 shortcutsTW->setItemExpanded(item->parent(), true);
3154 shortcutsTW->scrollToItem(item);
3156 Alert::error(_("Failed to create shortcut"),
3157 _("Can not insert shortcut to the list"));
3163 void PrefShortcuts::shortcutCancelPressed()
3165 shortcut_->shortcutWG->reset();
3169 void PrefShortcuts::shortcutClearPressed()
3171 shortcut_->shortcutWG->reset();
3175 void PrefShortcuts::shortcutRemovePressed()
3177 shortcut_->shortcutWG->removeFromSequence();
3181 /////////////////////////////////////////////////////////////////////
3185 /////////////////////////////////////////////////////////////////////
3187 PrefIdentity::PrefIdentity(GuiPreferences * form)
3188 : PrefModule(QString(), qt_("Identity"), form)
3192 connect(nameED, SIGNAL(textChanged(QString)),
3193 this, SIGNAL(changed()));
3194 connect(emailED, SIGNAL(textChanged(QString)),
3195 this, SIGNAL(changed()));
3197 nameED->setValidator(new NoNewLineValidator(nameED));
3198 emailED->setValidator(new NoNewLineValidator(emailED));
3202 void PrefIdentity::apply(LyXRC & rc) const
3204 rc.user_name = fromqstr(nameED->text());
3205 rc.user_email = fromqstr(emailED->text());
3209 void PrefIdentity::update(LyXRC const & rc)
3211 nameED->setText(toqstr(rc.user_name));
3212 emailED->setText(toqstr(rc.user_email));
3217 /////////////////////////////////////////////////////////////////////
3221 /////////////////////////////////////////////////////////////////////
3223 GuiPreferences::GuiPreferences(GuiView & lv)
3224 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
3228 QDialog::setModal(false);
3230 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
3231 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
3232 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
3233 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
3235 addModule(new PrefUserInterface(this));
3236 addModule(new PrefEdit(this));
3237 addModule(new PrefShortcuts(this));
3238 PrefScreenFonts * screenfonts = new PrefScreenFonts(this);
3239 connect(this, SIGNAL(prefsApplied(LyXRC const &)),
3240 screenfonts, SLOT(updateScreenFontSizes(LyXRC const &)));
3241 addModule(screenfonts);
3242 addModule(new PrefColors(this));
3243 addModule(new PrefDisplay(this));
3244 addModule(new PrefInput(this));
3245 addModule(new PrefCompletion(this));
3247 addModule(new PrefPaths(this));
3249 addModule(new PrefIdentity(this));
3251 addModule(new PrefLanguage(this));
3252 addModule(new PrefSpellchecker(this));
3254 //for strftime validator
3255 PrefOutput * output = new PrefOutput(this);
3257 addModule(new PrefPrinter(this));
3258 addModule(new PrefLatex(this));
3260 PrefConverters * converters = new PrefConverters(this);
3261 PrefFileformats * formats = new PrefFileformats(this);
3262 connect(formats, SIGNAL(formatsChanged()),
3263 converters, SLOT(updateGui()));
3264 addModule(converters);
3267 prefsPS->setCurrentPanel(qt_("User Interface"));
3268 // FIXME: hack to work around resizing bug in Qt >= 4.2
3269 // bug verified with Qt 4.2.{0-3} (JSpitzm)
3270 #if QT_VERSION >= 0x040200
3271 prefsPS->updateGeometry();
3274 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
3276 bc().setApply(applyPB);
3277 bc().setCancel(closePB);
3278 bc().setRestore(restorePB);
3280 // initialize the strftime validator
3281 bc().addCheckedLineEdit(output->DateED);
3285 void GuiPreferences::addModule(PrefModule * module)
3287 LASSERT(module, return);
3288 if (module->category().isEmpty())
3289 prefsPS->addPanel(module, module->title());
3291 prefsPS->addPanel(module, module->title(), module->category());
3292 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
3293 modules_.push_back(module);
3297 void GuiPreferences::change_adaptor()
3303 void GuiPreferences::apply(LyXRC & rc) const
3305 size_t end = modules_.size();
3306 for (size_t i = 0; i != end; ++i)
3307 modules_[i]->apply(rc);
3311 void GuiPreferences::updateRc(LyXRC const & rc)
3313 size_t const end = modules_.size();
3314 for (size_t i = 0; i != end; ++i)
3315 modules_[i]->update(rc);
3319 void GuiPreferences::applyView()
3325 bool GuiPreferences::initialiseParams(string const &)
3328 formats_ = lyx::formats;
3329 converters_ = theConverters();
3330 converters_.update(formats_);
3331 movers_ = theMovers();
3333 update_screen_font_ = false;
3336 // Make sure that the bc is in the INITIAL state
3337 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3344 void GuiPreferences::dispatchParams()
3347 rc_.write(ss, true);
3348 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
3349 // issue prefsApplied signal. This will update the
3350 // localized screen font sizes.
3352 // FIXME: these need lfuns
3354 Author const & author =
3355 Author(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
3356 theBufferList().recordCurrentAuthor(author);
3358 lyx::formats = formats_;
3360 theConverters() = converters_;
3361 theConverters().update(lyx::formats);
3362 theConverters().buildGraph();
3364 theMovers() = movers_;
3366 vector<string>::const_iterator it = colors_.begin();
3367 vector<string>::const_iterator const end = colors_.end();
3368 for (; it != end; ++it)
3369 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
3372 if (update_screen_font_) {
3373 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
3374 update_screen_font_ = false;
3377 // The Save button has been pressed
3379 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
3383 void GuiPreferences::setColor(ColorCode col, QString const & hex)
3385 colors_.push_back(lcolor.getLyXName(col) + ' ' + fromqstr(hex));
3389 void GuiPreferences::updateScreenFonts()
3391 update_screen_font_ = true;
3395 QString GuiPreferences::browsebind(QString const & file) const
3397 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
3398 QStringList(qt_("LyX bind files (*.bind)")));
3402 QString GuiPreferences::browseUI(QString const & file) const
3404 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
3405 QStringList(qt_("LyX UI files (*.ui)")));
3409 QString GuiPreferences::browsekbmap(QString const & file) const
3411 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
3412 QStringList(qt_("LyX keyboard maps (*.kmap)")));
3416 QString GuiPreferences::browse(QString const & file,
3417 QString const & title) const
3419 return browseFile(file, title, QStringList(), true);
3423 // We support less paper sizes than the document dialog
3424 // Therefore this adjustment is needed.
3425 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
3429 return PAPER_DEFAULT;
3431 return PAPER_USLETTER;
3433 return PAPER_USLEGAL;
3435 return PAPER_USEXECUTIVE;
3445 // should not happen
3446 return PAPER_DEFAULT;
3451 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
3453 switch (papersize) {
3456 case PAPER_USLETTER:
3460 case PAPER_USEXECUTIVE:
3471 // should not happen
3477 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
3480 } // namespace frontend
3483 #include "moc_GuiPrefs.cpp"