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/lstrings.h"
47 #include "support/os.h"
48 #include "support/Package.h"
50 #include "graphics/GraphicsTypes.h"
52 #include "frontends/alert.h"
53 #include "frontends/Application.h"
54 #include "frontends/FontLoader.h"
56 #include <QAbstractItemModel>
58 #include <QColorDialog>
59 #include <QFontDatabase>
60 #include <QHeaderView>
62 #include <QMessageBox>
63 #include <QPixmapCache>
64 #include <QPushButton>
67 #include <QTreeWidget>
68 #include <QTreeWidgetItem>
78 using namespace lyx::support;
79 using namespace lyx::support::os;
84 /////////////////////////////////////////////////////////////////////
88 /////////////////////////////////////////////////////////////////////
90 /** Launch a file dialog and return the chosen file.
91 filename: a suggested filename.
92 title: the title of the dialog.
94 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
96 QString browseFile(QString const & filename,
97 QString const & title,
98 QStringList const & filters,
100 QString const & label1 = QString(),
101 QString const & dir1 = QString(),
102 QString const & label2 = QString(),
103 QString const & dir2 = QString(),
104 QString const & fallback_dir = QString())
106 QString lastPath = ".";
107 if (!filename.isEmpty())
108 lastPath = onlyPath(filename);
109 else if(!fallback_dir.isEmpty())
110 lastPath = fallback_dir;
112 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
113 dlg.setButton2(label1, dir1);
114 dlg.setButton2(label2, dir2);
116 FileDialog::Result result;
119 result = dlg.save(lastPath, filters, onlyFileName(filename));
121 result = dlg.open(lastPath, filters, onlyFileName(filename));
123 return result.second;
127 /** Wrapper around browseFile which tries to provide a filename
128 * relative to the user or system directory. The dir, name and ext
129 * parameters have the same meaning as in the
130 * support::LibFileSearch function.
132 QString browseLibFile(QString const & dir,
133 QString const & name,
135 QString const & title,
136 QStringList const & filters)
139 QString const label1 = qt_("System files|#S#s");
141 toqstr(addName(package().system_support().absFileName(), fromqstr(dir)));
143 QString const label2 = qt_("User files|#U#u");
145 toqstr(addName(package().user_support().absFileName(), fromqstr(dir)));
147 QString const result = browseFile(toqstr(
148 libFileSearch(dir, name, ext).absFileName()),
149 title, filters, false, dir1, dir2, QString(), QString(), dir1);
151 // remove the extension if it is the default one
153 if (getExtension(result) == ext)
154 noextresult = removeExtension(result);
156 noextresult = result;
158 // remove the directory, if it is the default one
159 QString const file = onlyFileName(noextresult);
160 if (toqstr(libFileSearch(dir, file, ext).absFileName()) == result)
167 /** Launch a file dialog and return the chosen directory.
168 pathname: a suggested pathname.
169 title: the title of the dialog.
170 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
172 QString browseDir(QString const & pathname,
173 QString const & title,
174 QString const & label1 = QString(),
175 QString const & dir1 = QString(),
176 QString const & label2 = QString(),
177 QString const & dir2 = QString())
179 QString lastPath = ".";
180 if (!pathname.isEmpty())
181 lastPath = onlyPath(pathname);
183 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
184 dlg.setButton1(label1, dir1);
185 dlg.setButton2(label2, dir2);
187 FileDialog::Result const result =
188 dlg.opendir(lastPath, onlyFileName(pathname));
190 return result.second;
194 } // namespace frontend
197 QString browseRelFile(QString const & filename, QString const & refpath,
198 QString const & title, QStringList const & filters, bool save,
199 QString const & label1, QString const & dir1,
200 QString const & label2, QString const & dir2)
202 QString const fname = makeAbsPath(filename, refpath);
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(refpath)));
211 if (reloutname.startsWith("../"))
219 /////////////////////////////////////////////////////////////////////
223 /////////////////////////////////////////////////////////////////////
227 string const catLookAndFeel = N_("Look & Feel");
228 string const catEditing = N_("Editing");
229 string const catLanguage = N_("Language Settings");
230 string const catOutput = N_("Output");
231 string const catFiles = N_("File Handling");
233 static void parseFontName(QString const & mangled0,
234 string & name, string & foundry)
236 string mangled = fromqstr(mangled0);
237 size_t const idx = mangled.find('[');
238 if (idx == string::npos || idx == 0) {
242 name = mangled.substr(0, idx - 1),
243 foundry = mangled.substr(idx + 1, mangled.size() - idx - 2);
248 static void setComboxFont(QComboBox * cb, string const & family,
249 string const & foundry)
251 QString fontname = toqstr(family);
252 if (!foundry.empty())
253 fontname += " [" + toqstr(foundry) + ']';
255 for (int i = 0; i != cb->count(); ++i) {
256 if (cb->itemText(i) == fontname) {
257 cb->setCurrentIndex(i);
262 // Try matching without foundry name
264 // We count in reverse in order to prefer the Xft foundry
265 for (int i = cb->count(); --i >= 0;) {
266 string name, foundry;
267 parseFontName(cb->itemText(i), name, foundry);
268 if (compare_ascii_no_case(name, family) == 0) {
269 cb->setCurrentIndex(i);
274 // family alone can contain e.g. "Helvetica [Adobe]"
275 string tmpname, tmpfoundry;
276 parseFontName(toqstr(family), tmpname, tmpfoundry);
278 // We count in reverse in order to prefer the Xft foundry
279 for (int i = cb->count(); --i >= 0; ) {
280 string name, foundry;
281 parseFontName(cb->itemText(i), name, foundry);
282 if (compare_ascii_no_case(name, foundry) == 0) {
283 cb->setCurrentIndex(i);
288 // Bleh, default fonts, and the names couldn't be found. Hack
292 font.setKerning(false);
294 QString const font_family = toqstr(family);
295 if (font_family == guiApp->romanFontName()) {
296 font.setStyleHint(QFont::Serif);
297 font.setFamily(font_family);
298 } else if (font_family == guiApp->sansFontName()) {
299 font.setStyleHint(QFont::SansSerif);
300 font.setFamily(font_family);
301 } else if (font_family == guiApp->typewriterFontName()) {
302 font.setStyleHint(QFont::TypeWriter);
303 font.setFamily(font_family);
305 LYXERR0("FAILED to find the default font: '"
306 << foundry << "', '" << family << '\'');
310 QFontInfo info(font);
311 string default_font_name, dummyfoundry;
312 parseFontName(info.family(), default_font_name, dummyfoundry);
313 LYXERR0("Apparent font is " << default_font_name);
315 for (int i = 0; i < cb->count(); ++i) {
316 LYXERR0("Looking at " << cb->itemText(i));
317 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
318 default_font_name) == 0) {
319 cb->setCurrentIndex(i);
324 LYXERR0("FAILED to find the font: '"
325 << foundry << "', '" << family << '\'');
329 /////////////////////////////////////////////////////////////////////
333 /////////////////////////////////////////////////////////////////////
335 class StrftimeValidator : public QValidator
338 StrftimeValidator(QWidget *);
339 QValidator::State validate(QString & input, int & pos) const;
343 StrftimeValidator::StrftimeValidator(QWidget * parent)
349 QValidator::State StrftimeValidator::validate(QString & input, int & /*pos*/) const
351 if (is_valid_strftime(fromqstr(input)))
352 return QValidator::Acceptable;
354 return QValidator::Intermediate;
358 /////////////////////////////////////////////////////////////////////
362 /////////////////////////////////////////////////////////////////////
364 PrefOutput::PrefOutput(GuiPreferences * form)
365 : PrefModule(qt_(catOutput), qt_("General"), form)
368 DateED->setValidator(new StrftimeValidator(DateED));
369 connect(DateED, SIGNAL(textChanged(QString)),
370 this, SIGNAL(changed()));
371 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
372 this, SIGNAL(changed()));
373 connect(overwriteCO, SIGNAL(activated(int)),
374 this, SIGNAL(changed()));
375 connect(dviCB, SIGNAL(editTextChanged(QString)),
376 this, SIGNAL(changed()));
377 connect(pdfCB, SIGNAL(editTextChanged(QString)),
378 this, SIGNAL(changed()));
380 dviCB->addItem("xdvi -sourceposition $$n:$$t $$o");
381 dviCB->addItem("yap -1 -s $$n$$t $$o");
382 dviCB->addItem("okular --unique $$o#src:$$n$$t");
383 dviCB->addItem("synctex view -i $$n:0:$$t -o $$o -x \"evince -p %{page+1} $$o\"");
385 pdfCB->addItem("CMCDDE SUMATRA control [ForwardSearch(\\\"$$o\\\",\\\"$$t\\\",$$n,0,0,1)]");
386 pdfCB->addItem("synctex view -i $$n:0:$$t -o $$o -x \"xpdf -raise -remote $$t.tmp $$o %{page+1}\"");
387 pdfCB->addItem("okular --unique $$o#src:$$n$$t");
388 pdfCB->addItem("synctex view -i $$n:0:$$t -o $$o -x \"evince -p %{page+1} $$o\"");
389 pdfCB->addItem("/Applications/Skim.app/Contents/SharedSupport/displayline $$n $$o $$t");
393 void PrefOutput::on_DateED_textChanged(const QString &)
395 QString t = DateED->text();
397 bool valid = DateED->validator()->validate(t, p)
398 == QValidator::Acceptable;
399 setValid(DateLA, valid);
403 void PrefOutput::apply(LyXRC & rc) const
405 rc.date_insert_format = fromqstr(DateED->text());
406 rc.plaintext_linelen = plaintextLinelengthSB->value();
407 rc.forward_search_dvi = fromqstr(dviCB->currentText());
408 rc.forward_search_pdf = fromqstr(pdfCB->currentText());
410 switch (overwriteCO->currentIndex()) {
412 rc.export_overwrite = NO_FILES;
415 rc.export_overwrite = MAIN_FILE;
418 rc.export_overwrite = ALL_FILES;
424 void PrefOutput::update(LyXRC const & rc)
426 DateED->setText(toqstr(rc.date_insert_format));
427 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
428 dviCB->setEditText(toqstr(rc.forward_search_dvi));
429 pdfCB->setEditText(toqstr(rc.forward_search_pdf));
431 switch (rc.export_overwrite) {
433 overwriteCO->setCurrentIndex(0);
436 overwriteCO->setCurrentIndex(1);
439 overwriteCO->setCurrentIndex(2);
445 /////////////////////////////////////////////////////////////////////
449 /////////////////////////////////////////////////////////////////////
451 PrefInput::PrefInput(GuiPreferences * form)
452 : PrefModule(qt_(catEditing), qt_("Keyboard/Mouse"), form)
456 connect(keymapCB, SIGNAL(clicked()),
457 this, SIGNAL(changed()));
458 connect(firstKeymapED, SIGNAL(textChanged(QString)),
459 this, SIGNAL(changed()));
460 connect(secondKeymapED, SIGNAL(textChanged(QString)),
461 this, SIGNAL(changed()));
462 connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
463 this, SIGNAL(changed()));
464 connect(scrollzoomEnableCB, SIGNAL(clicked()),
465 this, SIGNAL(changed()));
466 connect(scrollzoomValueCO, SIGNAL(activated(int)),
467 this, SIGNAL(changed()));
468 connect(dontswapCB, SIGNAL(toggled(bool)),
469 this, SIGNAL(changed()));
471 // reveal checkbox for switching Ctrl and Meta on Mac:
474 #if QT_VERSION > 0x040600
478 dontswapCB->setVisible(swapcb);
482 void PrefInput::apply(LyXRC & rc) const
484 // FIXME: can derive CB from the two EDs
485 rc.use_kbmap = keymapCB->isChecked();
486 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
487 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
488 rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
489 if (scrollzoomEnableCB->isChecked()) {
490 switch (scrollzoomValueCO->currentIndex()) {
492 rc.scroll_wheel_zoom = LyXRC::SCROLL_WHEEL_ZOOM_CTRL;
495 rc.scroll_wheel_zoom = LyXRC::SCROLL_WHEEL_ZOOM_SHIFT;
498 rc.scroll_wheel_zoom = LyXRC::SCROLL_WHEEL_ZOOM_ALT;
502 rc.scroll_wheel_zoom = LyXRC::SCROLL_WHEEL_ZOOM_OFF;
504 rc.mac_dontswap_ctrl_meta = dontswapCB->isChecked();
508 void PrefInput::update(LyXRC const & rc)
510 // FIXME: can derive CB from the two EDs
511 keymapCB->setChecked(rc.use_kbmap);
512 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
513 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
514 mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
515 switch (rc.scroll_wheel_zoom) {
516 case LyXRC::SCROLL_WHEEL_ZOOM_OFF:
517 scrollzoomEnableCB->setChecked(false);
519 case LyXRC::SCROLL_WHEEL_ZOOM_CTRL:
520 scrollzoomEnableCB->setChecked(true);
521 scrollzoomValueCO->setCurrentIndex(0);
523 case LyXRC::SCROLL_WHEEL_ZOOM_SHIFT:
524 scrollzoomEnableCB->setChecked(true);
525 scrollzoomValueCO->setCurrentIndex(1);
527 case LyXRC::SCROLL_WHEEL_ZOOM_ALT:
528 scrollzoomEnableCB->setChecked(true);
529 scrollzoomValueCO->setCurrentIndex(2);
532 dontswapCB->setChecked(rc.mac_dontswap_ctrl_meta);
536 QString PrefInput::testKeymap(QString const & keymap)
538 return form_->browsekbmap(internalPath(keymap));
542 void PrefInput::on_firstKeymapPB_clicked(bool)
544 QString const file = testKeymap(firstKeymapED->text());
546 firstKeymapED->setText(file);
550 void PrefInput::on_secondKeymapPB_clicked(bool)
552 QString const file = testKeymap(secondKeymapED->text());
554 secondKeymapED->setText(file);
558 void PrefInput::on_keymapCB_toggled(bool keymap)
560 firstKeymapLA->setEnabled(keymap);
561 secondKeymapLA->setEnabled(keymap);
562 firstKeymapED->setEnabled(keymap);
563 secondKeymapED->setEnabled(keymap);
564 firstKeymapPB->setEnabled(keymap);
565 secondKeymapPB->setEnabled(keymap);
569 void PrefInput::on_scrollzoomEnableCB_toggled(bool enabled)
571 scrollzoomValueCO->setEnabled(enabled);
575 /////////////////////////////////////////////////////////////////////
579 /////////////////////////////////////////////////////////////////////
581 PrefCompletion::PrefCompletion(GuiPreferences * form)
582 : PrefModule(qt_(catEditing), qt_("Input Completion"), form)
586 connect(inlineDelaySB, SIGNAL(valueChanged(double)),
587 this, SIGNAL(changed()));
588 connect(inlineMathCB, SIGNAL(clicked()),
589 this, SIGNAL(changed()));
590 connect(inlineTextCB, SIGNAL(clicked()),
591 this, SIGNAL(changed()));
592 connect(inlineDotsCB, SIGNAL(clicked()),
593 this, SIGNAL(changed()));
594 connect(popupDelaySB, SIGNAL(valueChanged(double)),
595 this, SIGNAL(changed()));
596 connect(popupMathCB, SIGNAL(clicked()),
597 this, SIGNAL(changed()));
598 connect(autocorrectionCB, SIGNAL(clicked()),
599 this, SIGNAL(changed()));
600 connect(popupTextCB, SIGNAL(clicked()),
601 this, SIGNAL(changed()));
602 connect(popupAfterCompleteCB, SIGNAL(clicked()),
603 this, SIGNAL(changed()));
604 connect(cursorTextCB, SIGNAL(clicked()),
605 this, SIGNAL(changed()));
609 void PrefCompletion::on_inlineTextCB_clicked()
615 void PrefCompletion::on_popupTextCB_clicked()
621 void PrefCompletion::enableCB()
623 cursorTextCB->setEnabled(
624 popupTextCB->isChecked() || inlineTextCB->isChecked());
628 void PrefCompletion::apply(LyXRC & rc) const
630 rc.completion_inline_delay = inlineDelaySB->value();
631 rc.completion_inline_math = inlineMathCB->isChecked();
632 rc.completion_inline_text = inlineTextCB->isChecked();
633 rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
634 rc.completion_popup_delay = popupDelaySB->value();
635 rc.completion_popup_math = popupMathCB->isChecked();
636 rc.autocorrection_math = autocorrectionCB->isChecked();
637 rc.completion_popup_text = popupTextCB->isChecked();
638 rc.completion_cursor_text = cursorTextCB->isChecked();
639 rc.completion_popup_after_complete =
640 popupAfterCompleteCB->isChecked();
644 void PrefCompletion::update(LyXRC const & rc)
646 inlineDelaySB->setValue(rc.completion_inline_delay);
647 inlineMathCB->setChecked(rc.completion_inline_math);
648 inlineTextCB->setChecked(rc.completion_inline_text);
649 inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
650 popupDelaySB->setValue(rc.completion_popup_delay);
651 popupMathCB->setChecked(rc.completion_popup_math);
652 autocorrectionCB->setChecked(rc.autocorrection_math);
653 popupTextCB->setChecked(rc.completion_popup_text);
654 cursorTextCB->setChecked(rc.completion_cursor_text);
655 popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
661 /////////////////////////////////////////////////////////////////////
665 /////////////////////////////////////////////////////////////////////
667 PrefLatex::PrefLatex(GuiPreferences * form)
668 : PrefModule(qt_(catOutput), qt_("LaTeX"), form)
671 connect(latexEncodingCB, SIGNAL(clicked()),
672 this, SIGNAL(changed()));
673 connect(latexEncodingED, SIGNAL(textChanged(QString)),
674 this, SIGNAL(changed()));
675 connect(latexChecktexED, SIGNAL(textChanged(QString)),
676 this, SIGNAL(changed()));
677 connect(latexBibtexCO, SIGNAL(activated(int)),
678 this, SIGNAL(changed()));
679 connect(latexBibtexED, SIGNAL(textChanged(QString)),
680 this, SIGNAL(changed()));
681 connect(latexJBibtexED, SIGNAL(textChanged(QString)),
682 this, SIGNAL(changed()));
683 connect(latexIndexCO, SIGNAL(activated(int)),
684 this, SIGNAL(changed()));
685 connect(latexIndexED, SIGNAL(textChanged(QString)),
686 this, SIGNAL(changed()));
687 connect(latexJIndexED, SIGNAL(textChanged(QString)),
688 this, SIGNAL(changed()));
689 connect(latexAutoresetCB, SIGNAL(clicked()),
690 this, SIGNAL(changed()));
691 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
692 this, SIGNAL(changed()));
693 connect(latexPaperSizeCO, SIGNAL(activated(int)),
694 this, SIGNAL(changed()));
696 #if defined(__CYGWIN__) || defined(_WIN32)
697 pathCB->setVisible(true);
698 connect(pathCB, SIGNAL(clicked()),
699 this, SIGNAL(changed()));
701 pathCB->setVisible(false);
706 void PrefLatex::on_latexEncodingCB_stateChanged(int state)
708 latexEncodingED->setEnabled(state == Qt::Checked);
712 void PrefLatex::on_latexBibtexCO_activated(int n)
714 QString const bibtex = latexBibtexCO->itemData(n).toString();
715 if (bibtex.isEmpty()) {
716 latexBibtexED->clear();
717 latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
720 for (LyXRC::CommandSet::const_iterator it = bibtex_alternatives.begin();
721 it != bibtex_alternatives.end(); ++it) {
722 QString const bib = toqstr(*it);
723 int ind = bib.indexOf(" ");
724 QString sel_command = bib.left(ind);
725 QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
726 if (bibtex == sel_command) {
728 latexBibtexED->clear();
730 latexBibtexED->setText(sel_options.trimmed());
733 latexBibtexOptionsLA->setText(qt_("&Options:"));
737 void PrefLatex::on_latexIndexCO_activated(int n)
739 QString const index = latexIndexCO->itemData(n).toString();
740 if (index.isEmpty()) {
741 latexIndexED->clear();
742 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
745 for (LyXRC::CommandSet::const_iterator it = index_alternatives.begin();
746 it != index_alternatives.end(); ++it) {
747 QString const idx = toqstr(*it);
748 int ind = idx.indexOf(" ");
749 QString sel_command = idx.left(ind);
750 QString sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
751 if (index == sel_command) {
753 latexIndexED->clear();
755 latexIndexED->setText(sel_options.trimmed());
758 latexIndexOptionsLA->setText(qt_("Op&tions:"));
762 void PrefLatex::apply(LyXRC & rc) const
764 // If bibtex is not empty, bibopt contains the options, otherwise
765 // it is a customized bibtex command with options.
766 QString const bibtex = latexBibtexCO->itemData(
767 latexBibtexCO->currentIndex()).toString();
768 QString const bibopt = latexBibtexED->text();
769 if (bibtex.isEmpty())
770 rc.bibtex_command = fromqstr(bibopt);
771 else if (bibopt.isEmpty())
772 rc.bibtex_command = fromqstr(bibtex);
774 rc.bibtex_command = fromqstr(bibtex) + " " + fromqstr(bibopt);
776 // If index is not empty, idxopt contains the options, otherwise
777 // it is a customized index command with options.
778 QString const index = latexIndexCO->itemData(
779 latexIndexCO->currentIndex()).toString();
780 QString const idxopt = latexIndexED->text();
782 rc.index_command = fromqstr(idxopt);
783 else if (idxopt.isEmpty())
784 rc.index_command = fromqstr(index);
786 rc.index_command = fromqstr(index) + " " + fromqstr(idxopt);
788 if (latexEncodingCB->isChecked())
789 rc.fontenc = fromqstr(latexEncodingED->text());
791 rc.fontenc = "default";
792 rc.chktex_command = fromqstr(latexChecktexED->text());
793 rc.jbibtex_command = fromqstr(latexJBibtexED->text());
794 rc.jindex_command = fromqstr(latexJIndexED->text());
795 rc.nomencl_command = fromqstr(latexNomenclED->text());
796 rc.auto_reset_options = latexAutoresetCB->isChecked();
797 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
798 rc.default_papersize =
799 form_->toPaperSize(latexPaperSizeCO->currentIndex());
800 #if defined(__CYGWIN__) || defined(_WIN32)
801 rc.windows_style_tex_paths = pathCB->isChecked();
806 void PrefLatex::update(LyXRC const & rc)
808 latexBibtexCO->clear();
810 latexBibtexCO->addItem(qt_("Custom"), QString());
811 for (LyXRC::CommandSet::const_iterator it = rc.bibtex_alternatives.begin();
812 it != rc.bibtex_alternatives.end(); ++it) {
813 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
814 latexBibtexCO->addItem(command, command);
817 bibtex_alternatives = rc.bibtex_alternatives;
819 QString const bib = toqstr(rc.bibtex_command);
820 int ind = bib.indexOf(" ");
821 QString sel_command = bib.left(ind);
822 QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
824 int pos = latexBibtexCO->findData(sel_command);
826 latexBibtexCO->setCurrentIndex(pos);
827 latexBibtexED->setText(sel_options.trimmed());
828 latexBibtexOptionsLA->setText(qt_("&Options:"));
830 latexBibtexED->setText(toqstr(rc.bibtex_command));
831 latexBibtexCO->setCurrentIndex(0);
832 latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
835 latexIndexCO->clear();
837 latexIndexCO->addItem(qt_("Custom"), QString());
838 for (LyXRC::CommandSet::const_iterator it = rc.index_alternatives.begin();
839 it != rc.index_alternatives.end(); ++it) {
840 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
841 latexIndexCO->addItem(command, command);
844 index_alternatives = rc.index_alternatives;
846 QString const idx = toqstr(rc.index_command);
847 ind = idx.indexOf(" ");
848 sel_command = idx.left(ind);
849 sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
851 pos = latexIndexCO->findData(sel_command);
853 latexIndexCO->setCurrentIndex(pos);
854 latexIndexED->setText(sel_options.trimmed());
855 latexIndexOptionsLA->setText(qt_("Op&tions:"));
857 latexIndexED->setText(toqstr(rc.index_command));
858 latexIndexCO->setCurrentIndex(0);
859 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
862 if (rc.fontenc == "default") {
863 latexEncodingCB->setChecked(false);
864 latexEncodingED->setEnabled(false);
866 latexEncodingCB->setChecked(true);
867 latexEncodingED->setEnabled(true);
868 latexEncodingED->setText(toqstr(rc.fontenc));
870 latexChecktexED->setText(toqstr(rc.chktex_command));
871 latexJBibtexED->setText(toqstr(rc.jbibtex_command));
872 latexJIndexED->setText(toqstr(rc.jindex_command));
873 latexNomenclED->setText(toqstr(rc.nomencl_command));
874 latexAutoresetCB->setChecked(rc.auto_reset_options);
875 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
876 latexPaperSizeCO->setCurrentIndex(
877 form_->fromPaperSize(rc.default_papersize));
878 #if defined(__CYGWIN__) || defined(_WIN32)
879 pathCB->setChecked(rc.windows_style_tex_paths);
884 /////////////////////////////////////////////////////////////////////
888 /////////////////////////////////////////////////////////////////////
890 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form)
891 : PrefModule(qt_(catLookAndFeel), qt_("Screen Fonts"), form)
895 connect(screenRomanCO, SIGNAL(activated(QString)),
896 this, SLOT(selectRoman(QString)));
897 connect(screenSansCO, SIGNAL(activated(QString)),
898 this, SLOT(selectSans(QString)));
899 connect(screenTypewriterCO, SIGNAL(activated(QString)),
900 this, SLOT(selectTypewriter(QString)));
902 QFontDatabase fontdb;
903 QStringList families(fontdb.families());
904 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
905 screenRomanCO->addItem(*it);
906 screenSansCO->addItem(*it);
907 screenTypewriterCO->addItem(*it);
909 connect(screenRomanCO, SIGNAL(activated(QString)),
910 this, SIGNAL(changed()));
911 connect(screenSansCO, SIGNAL(activated(QString)),
912 this, SIGNAL(changed()));
913 connect(screenTypewriterCO, SIGNAL(activated(QString)),
914 this, SIGNAL(changed()));
915 connect(screenZoomSB, SIGNAL(valueChanged(int)),
916 this, SIGNAL(changed()));
917 connect(screenTinyED, SIGNAL(textChanged(QString)),
918 this, SIGNAL(changed()));
919 connect(screenSmallestED, SIGNAL(textChanged(QString)),
920 this, SIGNAL(changed()));
921 connect(screenSmallerED, SIGNAL(textChanged(QString)),
922 this, SIGNAL(changed()));
923 connect(screenSmallED, SIGNAL(textChanged(QString)),
924 this, SIGNAL(changed()));
925 connect(screenNormalED, SIGNAL(textChanged(QString)),
926 this, SIGNAL(changed()));
927 connect(screenLargeED, SIGNAL(textChanged(QString)),
928 this, SIGNAL(changed()));
929 connect(screenLargerED, SIGNAL(textChanged(QString)),
930 this, SIGNAL(changed()));
931 connect(screenLargestED, SIGNAL(textChanged(QString)),
932 this, SIGNAL(changed()));
933 connect(screenHugeED, SIGNAL(textChanged(QString)),
934 this, SIGNAL(changed()));
935 connect(screenHugerED, SIGNAL(textChanged(QString)),
936 this, SIGNAL(changed()));
937 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
938 this, SIGNAL(changed()));
940 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
941 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
942 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
943 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
944 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
945 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
946 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
947 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
948 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
949 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
953 void PrefScreenFonts::apply(LyXRC & rc) const
955 LyXRC const oldrc = rc;
957 parseFontName(screenRomanCO->currentText(),
958 rc.roman_font_name, rc.roman_font_foundry);
959 parseFontName(screenSansCO->currentText(),
960 rc.sans_font_name, rc.sans_font_foundry);
961 parseFontName(screenTypewriterCO->currentText(),
962 rc.typewriter_font_name, rc.typewriter_font_foundry);
964 rc.zoom = screenZoomSB->value();
965 rc.font_sizes[FONT_SIZE_TINY] = widgetToDoubleStr(screenTinyED);
966 rc.font_sizes[FONT_SIZE_SCRIPT] = widgetToDoubleStr(screenSmallestED);
967 rc.font_sizes[FONT_SIZE_FOOTNOTE] = widgetToDoubleStr(screenSmallerED);
968 rc.font_sizes[FONT_SIZE_SMALL] = widgetToDoubleStr(screenSmallED);
969 rc.font_sizes[FONT_SIZE_NORMAL] = widgetToDoubleStr(screenNormalED);
970 rc.font_sizes[FONT_SIZE_LARGE] = widgetToDoubleStr(screenLargeED);
971 rc.font_sizes[FONT_SIZE_LARGER] = widgetToDoubleStr(screenLargerED);
972 rc.font_sizes[FONT_SIZE_LARGEST] = widgetToDoubleStr(screenLargestED);
973 rc.font_sizes[FONT_SIZE_HUGE] = widgetToDoubleStr(screenHugeED);
974 rc.font_sizes[FONT_SIZE_HUGER] = widgetToDoubleStr(screenHugerED);
975 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
977 if (rc.font_sizes != oldrc.font_sizes
978 || rc.roman_font_name != oldrc.roman_font_name
979 || rc.sans_font_name != oldrc.sans_font_name
980 || rc.typewriter_font_name != oldrc.typewriter_font_name
981 || rc.zoom != oldrc.zoom) {
982 // The global QPixmapCache is used in GuiPainter to cache text
983 // painting so we must reset it in case any of the above
984 // parameter is changed.
985 QPixmapCache::clear();
986 guiApp->fontLoader().update();
987 form_->updateScreenFonts();
992 void PrefScreenFonts::update(LyXRC const & rc)
994 setComboxFont(screenRomanCO, rc.roman_font_name,
995 rc.roman_font_foundry);
996 setComboxFont(screenSansCO, rc.sans_font_name,
997 rc.sans_font_foundry);
998 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
999 rc.typewriter_font_foundry);
1001 selectRoman(screenRomanCO->currentText());
1002 selectSans(screenSansCO->currentText());
1003 selectTypewriter(screenTypewriterCO->currentText());
1005 screenZoomSB->setValue(rc.zoom);
1006 updateScreenFontSizes(rc);
1008 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
1009 #if defined(Q_WS_X11)
1010 pixmapCacheCB->setEnabled(false);
1016 void PrefScreenFonts::updateScreenFontSizes(LyXRC const & rc)
1018 doubleToWidget(screenTinyED, rc.font_sizes[FONT_SIZE_TINY]);
1019 doubleToWidget(screenSmallestED, rc.font_sizes[FONT_SIZE_SCRIPT]);
1020 doubleToWidget(screenSmallerED, rc.font_sizes[FONT_SIZE_FOOTNOTE]);
1021 doubleToWidget(screenSmallED, rc.font_sizes[FONT_SIZE_SMALL]);
1022 doubleToWidget(screenNormalED, rc.font_sizes[FONT_SIZE_NORMAL]);
1023 doubleToWidget(screenLargeED, rc.font_sizes[FONT_SIZE_LARGE]);
1024 doubleToWidget(screenLargerED, rc.font_sizes[FONT_SIZE_LARGER]);
1025 doubleToWidget(screenLargestED, rc.font_sizes[FONT_SIZE_LARGEST]);
1026 doubleToWidget(screenHugeED, rc.font_sizes[FONT_SIZE_HUGE]);
1027 doubleToWidget(screenHugerED, rc.font_sizes[FONT_SIZE_HUGER]);
1031 void PrefScreenFonts::selectRoman(const QString & name)
1033 screenRomanFE->set(QFont(name), name);
1037 void PrefScreenFonts::selectSans(const QString & name)
1039 screenSansFE->set(QFont(name), name);
1043 void PrefScreenFonts::selectTypewriter(const QString & name)
1045 screenTypewriterFE->set(QFont(name), name);
1049 /////////////////////////////////////////////////////////////////////
1053 /////////////////////////////////////////////////////////////////////
1059 bool operator()(ColorCode lhs, ColorCode rhs) const {
1061 compare_no_case(lcolor.getGUIName(lhs), lcolor.getGUIName(rhs)) < 0;
1067 PrefColors::PrefColors(GuiPreferences * form)
1068 : PrefModule(qt_(catLookAndFeel), qt_("Colors"), form)
1072 // FIXME: all of this initialization should be put into the controller.
1073 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
1074 // for some discussion of why that is not trivial.
1075 QPixmap icon(32, 32);
1076 for (int i = 0; i < Color_ignore; ++i) {
1077 ColorCode lc = static_cast<ColorCode>(i);
1078 if (lc == Color_none
1079 || lc == Color_black
1080 || lc == Color_white
1082 || lc == Color_green
1085 || lc == Color_magenta
1086 || lc == Color_yellow
1087 || lc == Color_inherit
1088 || lc == Color_ignore
1089 || lc == Color_greyedouttext
1090 || lc == Color_shadedbg) continue;
1092 lcolors_.push_back(lc);
1094 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
1095 vector<ColorCode>::const_iterator cit = lcolors_.begin();
1096 vector<ColorCode>::const_iterator const end = lcolors_.end();
1097 for (; cit != end; ++cit) {
1098 (void) new QListWidgetItem(QIcon(icon),
1099 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
1101 curcolors_.resize(lcolors_.size());
1102 newcolors_.resize(lcolors_.size());
1103 // End initialization
1105 connect(colorChangePB, SIGNAL(clicked()),
1106 this, SLOT(changeColor()));
1107 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
1108 this, SLOT(changeLyxObjectsSelection()));
1109 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
1110 this, SLOT(changeColor()));
1111 connect(syscolorsCB, SIGNAL(toggled(bool)),
1112 this, SIGNAL(changed()));
1113 connect(syscolorsCB, SIGNAL(toggled(bool)),
1114 this, SLOT(changeSysColor()));
1118 void PrefColors::apply(LyXRC & rc) const
1122 for (unsigned int i = 0; i < lcolors_.size(); ++i)
1123 if (curcolors_[i] != newcolors_[i])
1124 form_->setColor(lcolors_[i], newcolors_[i]);
1125 rc.use_system_colors = syscolorsCB->isChecked();
1127 if (oldrc.use_system_colors != rc.use_system_colors)
1128 guiApp->colorCache().clear();
1132 void PrefColors::update(LyXRC const & rc)
1134 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
1135 QColor color = QColor(guiApp->colorCache().get(lcolors_[i], false));
1136 QPixmap coloritem(32, 32);
1137 coloritem.fill(color);
1138 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
1139 newcolors_[i] = curcolors_[i] = color.name();
1141 syscolorsCB->setChecked(rc.use_system_colors);
1142 changeLyxObjectsSelection();
1146 void PrefColors::changeColor()
1148 int const row = lyxObjectsLW->currentRow();
1154 QString const color = newcolors_[row];
1155 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
1157 if (c.isValid() && c.name() != color) {
1158 newcolors_[row] = c.name();
1159 QPixmap coloritem(32, 32);
1161 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
1167 void PrefColors::changeSysColor()
1169 for (int row = 0 ; row < lyxObjectsLW->count() ; ++row) {
1170 // skip colors that are taken from system palette
1171 bool const hide = syscolorsCB->isChecked()
1172 && guiApp->colorCache().isSystem(lcolors_[row]);
1174 lyxObjectsLW->item(row)->setHidden(hide);
1179 void PrefColors::changeLyxObjectsSelection()
1181 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
1185 /////////////////////////////////////////////////////////////////////
1189 /////////////////////////////////////////////////////////////////////
1191 PrefDisplay::PrefDisplay(GuiPreferences * form)
1192 : PrefModule(qt_(catLookAndFeel), qt_("Display"), form)
1195 connect(displayGraphicsCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
1196 connect(instantPreviewCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
1197 connect(previewSizeSB, SIGNAL(valueChanged(double)), this, SIGNAL(changed()));
1198 connect(paragraphMarkerCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
1202 void PrefDisplay::on_instantPreviewCO_currentIndexChanged(int index)
1204 previewSizeSB->setEnabled(index != 0);
1208 void PrefDisplay::on_displayGraphicsCB_toggled(bool on)
1210 instantPreviewCO->setEnabled(on);
1211 previewSizeSB->setEnabled(on && instantPreviewCO->currentIndex() > 0);
1215 void PrefDisplay::apply(LyXRC & rc) const
1217 switch (instantPreviewCO->currentIndex()) {
1219 rc.preview = LyXRC::PREVIEW_OFF;
1222 rc.preview = LyXRC::PREVIEW_NO_MATH;
1225 rc.preview = LyXRC::PREVIEW_ON;
1229 rc.display_graphics = displayGraphicsCB->isChecked();
1230 rc.preview_scale_factor = previewSizeSB->value();
1231 rc.paragraph_markers = paragraphMarkerCB->isChecked();
1233 // FIXME!! The graphics cache no longer has a changeDisplay method.
1235 if (old_value != rc.display_graphics) {
1236 graphics::GCache & gc = graphics::GCache::get();
1243 void PrefDisplay::update(LyXRC const & rc)
1245 switch (rc.preview) {
1246 case LyXRC::PREVIEW_OFF:
1247 instantPreviewCO->setCurrentIndex(0);
1249 case LyXRC::PREVIEW_NO_MATH :
1250 instantPreviewCO->setCurrentIndex(1);
1252 case LyXRC::PREVIEW_ON :
1253 instantPreviewCO->setCurrentIndex(2);
1257 displayGraphicsCB->setChecked(rc.display_graphics);
1258 instantPreviewCO->setEnabled(rc.display_graphics);
1259 previewSizeSB->setValue(rc.preview_scale_factor);
1260 paragraphMarkerCB->setChecked(rc.paragraph_markers);
1261 previewSizeSB->setEnabled(
1263 && rc.preview != LyXRC::PREVIEW_OFF);
1267 /////////////////////////////////////////////////////////////////////
1271 /////////////////////////////////////////////////////////////////////
1273 PrefPaths::PrefPaths(GuiPreferences * form)
1274 : PrefModule(QString(), qt_("Paths"), form)
1278 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(selectWorkingdir()));
1279 connect(workingDirED, SIGNAL(textChanged(QString)),
1280 this, SIGNAL(changed()));
1282 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(selectTemplatedir()));
1283 connect(templateDirED, SIGNAL(textChanged(QString)),
1284 this, SIGNAL(changed()));
1286 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(selectExampledir()));
1287 connect(exampleDirED, SIGNAL(textChanged(QString)),
1288 this, SIGNAL(changed()));
1290 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(selectBackupdir()));
1291 connect(backupDirED, SIGNAL(textChanged(QString)),
1292 this, SIGNAL(changed()));
1294 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(selectLyxPipe()));
1295 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
1296 this, SIGNAL(changed()));
1298 connect(thesaurusDirPB, SIGNAL(clicked()), this, SLOT(selectThesaurusdir()));
1299 connect(thesaurusDirED, SIGNAL(textChanged(QString)),
1300 this, SIGNAL(changed()));
1302 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(selectTempdir()));
1303 connect(tempDirED, SIGNAL(textChanged(QString)),
1304 this, SIGNAL(changed()));
1306 connect(hunspellDirPB, SIGNAL(clicked()), this, SLOT(selectHunspelldir()));
1307 connect(hunspellDirED, SIGNAL(textChanged(QString)),
1308 this, SIGNAL(changed()));
1310 connect(pathPrefixED, SIGNAL(textChanged(QString)),
1311 this, SIGNAL(changed()));
1315 void PrefPaths::apply(LyXRC & rc) const
1317 rc.document_path = internal_path(fromqstr(workingDirED->text()));
1318 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
1319 rc.template_path = internal_path(fromqstr(templateDirED->text()));
1320 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
1321 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
1322 rc.thesaurusdir_path = internal_path(fromqstr(thesaurusDirED->text()));
1323 rc.hunspelldir_path = internal_path(fromqstr(hunspellDirED->text()));
1324 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
1325 // FIXME: should be a checkbox only
1326 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
1330 void PrefPaths::update(LyXRC const & rc)
1332 workingDirED->setText(toqstr(external_path(rc.document_path)));
1333 exampleDirED->setText(toqstr(external_path(rc.example_path)));
1334 templateDirED->setText(toqstr(external_path(rc.template_path)));
1335 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
1336 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
1337 thesaurusDirED->setText(toqstr(external_path(rc.thesaurusdir_path)));
1338 hunspellDirED->setText(toqstr(external_path(rc.hunspelldir_path)));
1339 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
1340 // FIXME: should be a checkbox only
1341 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
1345 void PrefPaths::selectExampledir()
1347 QString file = browseDir(internalPath(exampleDirED->text()),
1348 qt_("Select directory for example files"));
1349 if (!file.isEmpty())
1350 exampleDirED->setText(file);
1354 void PrefPaths::selectTemplatedir()
1356 QString file = browseDir(internalPath(templateDirED->text()),
1357 qt_("Select a document templates directory"));
1358 if (!file.isEmpty())
1359 templateDirED->setText(file);
1363 void PrefPaths::selectTempdir()
1365 QString file = browseDir(internalPath(tempDirED->text()),
1366 qt_("Select a temporary directory"));
1367 if (!file.isEmpty())
1368 tempDirED->setText(file);
1372 void PrefPaths::selectBackupdir()
1374 QString file = browseDir(internalPath(backupDirED->text()),
1375 qt_("Select a backups directory"));
1376 if (!file.isEmpty())
1377 backupDirED->setText(file);
1381 void PrefPaths::selectWorkingdir()
1383 QString file = browseDir(internalPath(workingDirED->text()),
1384 qt_("Select a document directory"));
1385 if (!file.isEmpty())
1386 workingDirED->setText(file);
1390 void PrefPaths::selectThesaurusdir()
1392 QString file = browseDir(internalPath(thesaurusDirED->text()),
1393 qt_("Set the path to the thesaurus dictionaries"));
1394 if (!file.isEmpty())
1395 thesaurusDirED->setText(file);
1399 void PrefPaths::selectHunspelldir()
1401 QString file = browseDir(internalPath(hunspellDirED->text()),
1402 qt_("Set the path to the Hunspell dictionaries"));
1403 if (!file.isEmpty())
1404 hunspellDirED->setText(file);
1408 void PrefPaths::selectLyxPipe()
1410 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1411 qt_("Give a filename for the LyX server pipe"));
1412 if (!file.isEmpty())
1413 lyxserverDirED->setText(file);
1417 /////////////////////////////////////////////////////////////////////
1421 /////////////////////////////////////////////////////////////////////
1423 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form)
1424 : PrefModule(qt_(catLanguage), qt_("Spellchecker"), form)
1428 // FIXME: this check should test the target platform (darwin)
1429 #if defined(USE_MACOSX_PACKAGING)
1430 spellcheckerCB->addItem(qt_("Native"), QString("native"));
1431 #define CONNECT_APPLESPELL
1433 #undef CONNECT_APPLESPELL
1435 #if defined(USE_ASPELL)
1436 spellcheckerCB->addItem(qt_("Aspell"), QString("aspell"));
1438 #if defined(USE_ENCHANT)
1439 spellcheckerCB->addItem(qt_("Enchant"), QString("enchant"));
1441 #if defined(USE_HUNSPELL)
1442 spellcheckerCB->addItem(qt_("Hunspell"), QString("hunspell"));
1445 #if defined(CONNECT_APPLESPELL) || defined(USE_ASPELL) || defined(USE_ENCHANT) || defined(USE_HUNSPELL)
1446 connect(spellcheckerCB, SIGNAL(currentIndexChanged(int)),
1447 this, SIGNAL(changed()));
1448 connect(altLanguageED, SIGNAL(textChanged(QString)),
1449 this, SIGNAL(changed()));
1450 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1451 this, SIGNAL(changed()));
1452 connect(compoundWordCB, SIGNAL(clicked()),
1453 this, SIGNAL(changed()));
1454 connect(spellcheckContinuouslyCB, SIGNAL(clicked()),
1455 this, SIGNAL(changed()));
1456 connect(spellcheckNotesCB, SIGNAL(clicked()),
1457 this, SIGNAL(changed()));
1459 spellcheckerCB->setEnabled(false);
1460 altLanguageED->setEnabled(false);
1461 escapeCharactersED->setEnabled(false);
1462 compoundWordCB->setEnabled(false);
1463 spellcheckContinuouslyCB->setEnabled(false);
1464 spellcheckNotesCB->setEnabled(false);
1469 void PrefSpellchecker::apply(LyXRC & rc) const
1471 string const speller = fromqstr(spellcheckerCB->
1472 itemData(spellcheckerCB->currentIndex()).toString());
1473 if (!speller.empty())
1474 rc.spellchecker = speller;
1475 rc.spellchecker_alt_lang = fromqstr(altLanguageED->text());
1476 rc.spellchecker_esc_chars = fromqstr(escapeCharactersED->text());
1477 rc.spellchecker_accept_compound = compoundWordCB->isChecked();
1478 rc.spellcheck_continuously = spellcheckContinuouslyCB->isChecked();
1479 rc.spellcheck_notes = spellcheckNotesCB->isChecked();
1483 void PrefSpellchecker::update(LyXRC const & rc)
1485 spellcheckerCB->setCurrentIndex(
1486 spellcheckerCB->findData(toqstr(rc.spellchecker)));
1487 altLanguageED->setText(toqstr(rc.spellchecker_alt_lang));
1488 escapeCharactersED->setText(toqstr(rc.spellchecker_esc_chars));
1489 compoundWordCB->setChecked(rc.spellchecker_accept_compound);
1490 spellcheckContinuouslyCB->setChecked(rc.spellcheck_continuously);
1491 spellcheckNotesCB->setChecked(rc.spellcheck_notes);
1495 void PrefSpellchecker::on_spellcheckerCB_currentIndexChanged(int index)
1497 QString spellchecker = spellcheckerCB->itemData(index).toString();
1499 compoundWordCB->setEnabled(spellchecker != QString("native"));
1504 /////////////////////////////////////////////////////////////////////
1508 /////////////////////////////////////////////////////////////////////
1511 PrefConverters::PrefConverters(GuiPreferences * form)
1512 : PrefModule(qt_(catFiles), qt_("Converters"), form)
1516 connect(converterNewPB, SIGNAL(clicked()),
1517 this, SLOT(updateConverter()));
1518 connect(converterRemovePB, SIGNAL(clicked()),
1519 this, SLOT(removeConverter()));
1520 connect(converterModifyPB, SIGNAL(clicked()),
1521 this, SLOT(updateConverter()));
1522 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1523 this, SLOT(switchConverter()));
1524 connect(converterFromCO, SIGNAL(activated(QString)),
1525 this, SLOT(changeConverter()));
1526 connect(converterToCO, SIGNAL(activated(QString)),
1527 this, SLOT(changeConverter()));
1528 connect(converterED, SIGNAL(textEdited(QString)),
1529 this, SLOT(changeConverter()));
1530 connect(converterFlagED, SIGNAL(textEdited(QString)),
1531 this, SLOT(changeConverter()));
1532 connect(converterNewPB, SIGNAL(clicked()),
1533 this, SIGNAL(changed()));
1534 connect(converterRemovePB, SIGNAL(clicked()),
1535 this, SIGNAL(changed()));
1536 connect(converterModifyPB, SIGNAL(clicked()),
1537 this, SIGNAL(changed()));
1538 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1539 this, SIGNAL(changed()));
1541 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1542 //converterDefGB->setFocusProxy(convertersLW);
1546 void PrefConverters::apply(LyXRC & rc) const
1548 rc.use_converter_cache = cacheCB->isChecked();
1549 rc.converter_cache_maxage = int(widgetToDouble(maxAgeLE) * 86400.0);
1553 void PrefConverters::update(LyXRC const & rc)
1555 cacheCB->setChecked(rc.use_converter_cache);
1557 doubleToWidget(maxAgeLE, (double(rc.converter_cache_maxage) / 86400.0), 'g', 6);
1562 void PrefConverters::updateGui()
1564 form_->formats().sort();
1565 form_->converters().update(form_->formats());
1566 // save current selection
1567 QString current = converterFromCO->currentText()
1568 + " -> " + converterToCO->currentText();
1570 converterFromCO->clear();
1571 converterToCO->clear();
1573 Formats::const_iterator cit = form_->formats().begin();
1574 Formats::const_iterator end = form_->formats().end();
1575 for (; cit != end; ++cit) {
1576 converterFromCO->addItem(qt_(cit->prettyname()));
1577 converterToCO->addItem(qt_(cit->prettyname()));
1580 // currentRowChanged(int) is also triggered when updating the listwidget
1581 // block signals to avoid unnecessary calls to switchConverter()
1582 convertersLW->blockSignals(true);
1583 convertersLW->clear();
1585 Converters::const_iterator ccit = form_->converters().begin();
1586 Converters::const_iterator cend = form_->converters().end();
1587 for (; ccit != cend; ++ccit) {
1588 QString const name =
1589 qt_(ccit->From->prettyname()) + " -> " + qt_(ccit->To->prettyname());
1590 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1591 new QListWidgetItem(name, convertersLW, type);
1593 convertersLW->sortItems(Qt::AscendingOrder);
1594 convertersLW->blockSignals(false);
1596 // restore selection
1597 if (!current.isEmpty()) {
1598 QList<QListWidgetItem *> const item =
1599 convertersLW->findItems(current, Qt::MatchExactly);
1600 if (!item.isEmpty())
1601 convertersLW->setCurrentItem(item.at(0));
1604 // select first element if restoring failed
1605 if (convertersLW->currentRow() == -1)
1606 convertersLW->setCurrentRow(0);
1612 void PrefConverters::switchConverter()
1614 int const cnr = convertersLW->currentItem()->type();
1615 Converter const & c(form_->converters().get(cnr));
1616 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1617 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1618 converterED->setText(toqstr(c.command));
1619 converterFlagED->setText(toqstr(c.flags));
1625 void PrefConverters::changeConverter()
1631 void PrefConverters::updateButtons()
1633 if (form_->formats().size() == 0)
1635 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1636 Format const & to = form_->formats().get(converterToCO->currentIndex());
1637 int const sel = form_->converters().getNumber(from.name(), to.name());
1638 bool const known = sel >= 0;
1639 bool const valid = !(converterED->text().isEmpty()
1640 || from.name() == to.name());
1642 int const cnr = convertersLW->currentItem()->type();
1643 Converter const & c = form_->converters().get(cnr);
1644 string const old_command = c.command;
1645 string const old_flag = c.flags;
1646 string const new_command = fromqstr(converterED->text());
1647 string const new_flag = fromqstr(converterFlagED->text());
1649 bool modified = (old_command != new_command || old_flag != new_flag);
1651 converterModifyPB->setEnabled(valid && known && modified);
1652 converterNewPB->setEnabled(valid && !known);
1653 converterRemovePB->setEnabled(known);
1655 maxAgeLE->setEnabled(cacheCB->isChecked());
1656 maxAgeLA->setEnabled(cacheCB->isChecked());
1661 // specify unique from/to or it doesn't appear. This is really bad UI
1662 // this is why we can use the same function for both new and modify
1663 void PrefConverters::updateConverter()
1665 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1666 Format const & to = form_->formats().get(converterToCO->currentIndex());
1667 string const flags = fromqstr(converterFlagED->text());
1668 string const command = fromqstr(converterED->text());
1670 Converter const * old =
1671 form_->converters().getConverter(from.name(), to.name());
1672 form_->converters().add(from.name(), to.name(), command, flags);
1675 form_->converters().updateLast(form_->formats());
1679 // Remove all files created by this converter from the cache, since
1680 // the modified converter might create different files.
1681 ConverterCache::get().remove_all(from.name(), to.name());
1685 void PrefConverters::removeConverter()
1687 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1688 Format const & to = form_->formats().get(converterToCO->currentIndex());
1689 form_->converters().erase(from.name(), to.name());
1693 // Remove all files created by this converter from the cache, since
1694 // a possible new converter might create different files.
1695 ConverterCache::get().remove_all(from.name(), to.name());
1699 void PrefConverters::on_cacheCB_stateChanged(int state)
1701 maxAgeLE->setEnabled(state == Qt::Checked);
1702 maxAgeLA->setEnabled(state == Qt::Checked);
1707 /////////////////////////////////////////////////////////////////////
1711 /////////////////////////////////////////////////////////////////////
1713 class FormatValidator : public QValidator
1716 FormatValidator(QWidget *, Formats const & f);
1717 void fixup(QString & input) const;
1718 QValidator::State validate(QString & input, int & pos) const;
1720 virtual QString toString(Format const & format) const = 0;
1722 Formats const & formats_;
1726 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1727 : QValidator(parent), formats_(f)
1732 void FormatValidator::fixup(QString & input) const
1734 Formats::const_iterator cit = formats_.begin();
1735 Formats::const_iterator end = formats_.end();
1736 for (; cit != end; ++cit) {
1737 QString const name = toString(*cit);
1738 if (distance(formats_.begin(), cit) == nr()) {
1746 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1748 Formats::const_iterator cit = formats_.begin();
1749 Formats::const_iterator end = formats_.end();
1750 bool unknown = true;
1751 for (; unknown && cit != end; ++cit) {
1752 QString const name = toString(*cit);
1753 if (distance(formats_.begin(), cit) != nr())
1754 unknown = name != input;
1757 if (unknown && !input.isEmpty())
1758 return QValidator::Acceptable;
1760 return QValidator::Intermediate;
1764 int FormatValidator::nr() const
1766 QComboBox * p = qobject_cast<QComboBox *>(parent());
1767 return p->itemData(p->currentIndex()).toInt();
1771 /////////////////////////////////////////////////////////////////////
1773 // FormatNameValidator
1775 /////////////////////////////////////////////////////////////////////
1777 class FormatNameValidator : public FormatValidator
1780 FormatNameValidator(QWidget * parent, Formats const & f)
1781 : FormatValidator(parent, f)
1784 QString toString(Format const & format) const
1786 return toqstr(format.name());
1791 /////////////////////////////////////////////////////////////////////
1793 // FormatPrettynameValidator
1795 /////////////////////////////////////////////////////////////////////
1797 class FormatPrettynameValidator : public FormatValidator
1800 FormatPrettynameValidator(QWidget * parent, Formats const & f)
1801 : FormatValidator(parent, f)
1804 QString toString(Format const & format) const
1806 return qt_(format.prettyname());
1811 /////////////////////////////////////////////////////////////////////
1815 /////////////////////////////////////////////////////////////////////
1817 PrefFileformats::PrefFileformats(GuiPreferences * form)
1818 : PrefModule(qt_(catFiles), qt_("File Formats"), form)
1821 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1822 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1824 connect(documentCB, SIGNAL(clicked()),
1825 this, SLOT(setFlags()));
1826 connect(vectorCB, SIGNAL(clicked()),
1827 this, SLOT(setFlags()));
1828 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1829 this, SLOT(updatePrettyname()));
1830 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1831 this, SIGNAL(changed()));
1832 connect(defaultFormatCB, SIGNAL(activated(QString)),
1833 this, SIGNAL(changed()));
1834 connect(viewerCO, SIGNAL(activated(int)),
1835 this, SIGNAL(changed()));
1836 connect(editorCO, SIGNAL(activated(int)),
1837 this, SIGNAL(changed()));
1843 string const l10n_shortcut(string const prettyname, string const shortcut)
1845 if (shortcut.empty())
1848 string l10n_format =
1849 to_utf8(_(prettyname + '|' + shortcut));
1850 return split(l10n_format, '|');
1856 void PrefFileformats::apply(LyXRC & rc) const
1858 QString const default_format = defaultFormatCB->itemData(
1859 defaultFormatCB->currentIndex()).toString();
1860 rc.default_view_format = fromqstr(default_format);
1864 void PrefFileformats::update(LyXRC const & rc)
1866 viewer_alternatives = rc.viewer_alternatives;
1867 editor_alternatives = rc.editor_alternatives;
1868 bool const init = defaultFormatCB->currentText().isEmpty();
1872 defaultFormatCB->findData(toqstr(rc.default_view_format));
1873 defaultFormatCB->setCurrentIndex(pos);
1878 void PrefFileformats::updateView()
1880 QString const current = formatsCB->currentText();
1881 QString const current_def = defaultFormatCB->currentText();
1883 // update comboboxes with formats
1884 formatsCB->blockSignals(true);
1885 defaultFormatCB->blockSignals(true);
1887 defaultFormatCB->clear();
1888 form_->formats().sort();
1889 Formats::const_iterator cit = form_->formats().begin();
1890 Formats::const_iterator end = form_->formats().end();
1891 for (; cit != end; ++cit) {
1892 formatsCB->addItem(qt_(cit->prettyname()),
1893 QVariant(form_->formats().getNumber(cit->name())));
1894 if (form_->converters().isReachable("latex", cit->name())
1895 || form_->converters().isReachable("pdflatex", cit->name()))
1896 defaultFormatCB->addItem(qt_(cit->prettyname()),
1897 QVariant(toqstr(cit->name())));
1900 // restore selection
1901 int item = formatsCB->findText(current, Qt::MatchExactly);
1902 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1903 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1904 item = defaultFormatCB->findText(current_def, Qt::MatchExactly);
1905 defaultFormatCB->setCurrentIndex(item < 0 ? 0 : item);
1906 formatsCB->blockSignals(false);
1907 defaultFormatCB->blockSignals(false);
1911 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1913 if (form_->formats().size() == 0)
1915 int const nr = formatsCB->itemData(i).toInt();
1916 Format const f = form_->formats().get(nr);
1918 formatED->setText(toqstr(f.name()));
1919 copierED->setText(toqstr(form_->movers().command(f.name())));
1920 extensionED->setText(toqstr(f.extension()));
1921 shortcutED->setText(
1922 toqstr(l10n_shortcut(f.prettyname(), f.shortcut())));
1923 documentCB->setChecked((f.documentFormat()));
1924 vectorCB->setChecked((f.vectorFormat()));
1930 void PrefFileformats::setFlags()
1932 int flags = Format::none;
1933 if (documentCB->isChecked())
1934 flags |= Format::document;
1935 if (vectorCB->isChecked())
1936 flags |= Format::vector;
1937 currentFormat().setFlags(flags);
1942 void PrefFileformats::on_copierED_textEdited(const QString & s)
1944 string const fmt = fromqstr(formatED->text());
1945 form_->movers().set(fmt, fromqstr(s));
1950 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1952 currentFormat().setExtension(fromqstr(s));
1956 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1958 currentFormat().setViewer(fromqstr(s));
1963 void PrefFileformats::on_editorED_textEdited(const QString & s)
1965 currentFormat().setEditor(fromqstr(s));
1970 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1972 string const new_shortcut = fromqstr(s);
1973 if (new_shortcut == l10n_shortcut(currentFormat().prettyname(),
1974 currentFormat().shortcut()))
1976 currentFormat().setShortcut(new_shortcut);
1981 void PrefFileformats::on_formatED_editingFinished()
1983 string const newname = fromqstr(formatED->displayText());
1984 string const oldname = currentFormat().name();
1985 if (newname == oldname)
1987 if (form_->converters().formatIsUsed(oldname)) {
1988 Alert::error(_("Format in use"),
1989 _("You cannot change a format's short name "
1990 "if the format is used by a converter. "
1991 "Please remove the converter first."));
1996 currentFormat().setName(newname);
2001 void PrefFileformats::on_formatED_textChanged(const QString &)
2003 QString t = formatED->text();
2005 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
2006 setValid(formatLA, valid);
2010 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
2012 QString t = formatsCB->currentText();
2014 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
2015 setValid(formatsLA, valid);
2019 void PrefFileformats::updatePrettyname()
2021 QString const newname = formatsCB->currentText();
2022 if (newname == qt_(currentFormat().prettyname()))
2025 currentFormat().setPrettyname(fromqstr(newname));
2033 void updateComboBox(LyXRC::Alternatives const & alts,
2034 string const & fmt, QComboBox * combo)
2036 LyXRC::Alternatives::const_iterator it =
2038 if (it != alts.end()) {
2039 LyXRC::CommandSet const & cmds = it->second;
2040 LyXRC::CommandSet::const_iterator sit =
2042 LyXRC::CommandSet::const_iterator const sen =
2044 for (; sit != sen; ++sit) {
2045 QString const qcmd = toqstr(*sit);
2046 combo->addItem(qcmd, qcmd);
2053 void PrefFileformats::updateViewers()
2055 Format const f = currentFormat();
2056 viewerCO->blockSignals(true);
2058 viewerCO->addItem(qt_("None"), QString());
2059 updateComboBox(viewer_alternatives, f.name(), viewerCO);
2060 viewerCO->addItem(qt_("Custom"), QString("custom viewer"));
2061 viewerCO->blockSignals(false);
2063 int pos = viewerCO->findData(toqstr(f.viewer()));
2066 viewerED->setEnabled(false);
2067 viewerCO->setCurrentIndex(pos);
2069 viewerED->setEnabled(true);
2070 viewerED->setText(toqstr(f.viewer()));
2071 viewerCO->setCurrentIndex(viewerCO->findData(toqstr("custom viewer")));
2076 void PrefFileformats::updateEditors()
2078 Format const f = currentFormat();
2079 editorCO->blockSignals(true);
2081 editorCO->addItem(qt_("None"), QString());
2082 updateComboBox(editor_alternatives, f.name(), editorCO);
2083 editorCO->addItem(qt_("Custom"), QString("custom editor"));
2084 editorCO->blockSignals(false);
2086 int pos = editorCO->findData(toqstr(f.editor()));
2089 editorED->setEnabled(false);
2090 editorCO->setCurrentIndex(pos);
2092 editorED->setEnabled(true);
2093 editorED->setText(toqstr(f.editor()));
2094 editorCO->setCurrentIndex(editorCO->findData(toqstr("custom editor")));
2099 void PrefFileformats::on_viewerCO_currentIndexChanged(int i)
2101 bool const custom = viewerCO->itemData(i).toString() == "custom viewer";
2102 viewerED->setEnabled(custom);
2104 currentFormat().setViewer(fromqstr(viewerCO->itemData(i).toString()));
2108 void PrefFileformats::on_editorCO_currentIndexChanged(int i)
2110 bool const custom = editorCO->itemData(i).toString() == "custom editor";
2111 editorED->setEnabled(custom);
2113 currentFormat().setEditor(fromqstr(editorCO->itemData(i).toString()));
2117 Format & PrefFileformats::currentFormat()
2119 int const i = formatsCB->currentIndex();
2120 int const nr = formatsCB->itemData(i).toInt();
2121 return form_->formats().get(nr);
2125 void PrefFileformats::on_formatNewPB_clicked()
2127 form_->formats().add("", "", "", "", "", "", Format::none);
2129 formatsCB->setCurrentIndex(0);
2130 formatsCB->setFocus(Qt::OtherFocusReason);
2134 void PrefFileformats::on_formatRemovePB_clicked()
2136 int const i = formatsCB->currentIndex();
2137 int const nr = formatsCB->itemData(i).toInt();
2138 string const current_text = form_->formats().get(nr).name();
2139 if (form_->converters().formatIsUsed(current_text)) {
2140 Alert::error(_("Format in use"),
2141 _("Cannot remove a Format used by a Converter. "
2142 "Remove the converter first."));
2146 form_->formats().erase(current_text);
2149 on_formatsCB_editTextChanged(formatsCB->currentText());
2154 /////////////////////////////////////////////////////////////////////
2158 /////////////////////////////////////////////////////////////////////
2160 PrefLanguage::PrefLanguage(GuiPreferences * form)
2161 : PrefModule(qt_(catLanguage), qt_("Language"), form)
2165 connect(rtlGB, SIGNAL(clicked()),
2166 this, SIGNAL(changed()));
2167 connect(visualCursorRB, SIGNAL(clicked()),
2168 this, SIGNAL(changed()));
2169 connect(logicalCursorRB, SIGNAL(clicked()),
2170 this, SIGNAL(changed()));
2171 connect(markForeignCB, SIGNAL(clicked()),
2172 this, SIGNAL(changed()));
2173 connect(autoBeginCB, SIGNAL(clicked()),
2174 this, SIGNAL(changed()));
2175 connect(autoEndCB, SIGNAL(clicked()),
2176 this, SIGNAL(changed()));
2177 connect(languagePackageCO, SIGNAL(activated(int)),
2178 this, SIGNAL(changed()));
2179 connect(languagePackageED, SIGNAL(textChanged(QString)),
2180 this, SIGNAL(changed()));
2181 connect(globalCB, SIGNAL(clicked()),
2182 this, SIGNAL(changed()));
2183 connect(startCommandED, SIGNAL(textChanged(QString)),
2184 this, SIGNAL(changed()));
2185 connect(endCommandED, SIGNAL(textChanged(QString)),
2186 this, SIGNAL(changed()));
2187 connect(uiLanguageCO, SIGNAL(activated(int)),
2188 this, SIGNAL(changed()));
2189 connect(defaultDecimalPointLE, SIGNAL(textChanged(QString)),
2190 this, SIGNAL(changed()));
2192 uiLanguageCO->clear();
2194 QAbstractItemModel * language_model = guiApp->languageModel();
2195 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
2196 language_model->sort(0);
2197 defaultDecimalPointLE->setInputMask("X; ");
2198 defaultDecimalPointLE->setMaxLength(1);
2201 uiLanguageCO->blockSignals(true);
2202 uiLanguageCO->addItem(qt_("Default"), toqstr("auto"));
2203 for (int i = 0; i != language_model->rowCount(); ++i) {
2204 QModelIndex index = language_model->index(i, 0);
2205 // Filter the list based on the available translation and add
2206 // each language code only once
2207 string const name = fromqstr(index.data(Qt::UserRole).toString());
2208 Language const * lang = languages.getLanguage(name);
2209 // never remove the currently selected language
2210 if (lang && name != form->rc().gui_language && name != lyxrc.gui_language)
2211 if (!lang->translated() || added.find(lang->code()) != added.end())
2213 added.insert(lang->code());
2214 uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
2215 index.data(Qt::UserRole).toString());
2217 uiLanguageCO->blockSignals(false);
2221 void PrefLanguage::on_uiLanguageCO_currentIndexChanged(int)
2223 QMessageBox::information(this, qt_("LyX needs to be restarted!"),
2224 qt_("The change of user interface language will be fully "
2225 "effective only after a restart."));
2229 void PrefLanguage::on_languagePackageCO_currentIndexChanged(int i)
2231 languagePackageED->setEnabled(i == 2);
2235 void PrefLanguage::apply(LyXRC & rc) const
2237 // FIXME: remove rtl_support bool
2238 rc.rtl_support = rtlGB->isChecked();
2239 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
2240 rc.mark_foreign_language = markForeignCB->isChecked();
2241 rc.language_auto_begin = autoBeginCB->isChecked();
2242 rc.language_auto_end = autoEndCB->isChecked();
2243 int const p = languagePackageCO->currentIndex();
2245 rc.language_package_selection = LyXRC::LP_AUTO;
2247 rc.language_package_selection = LyXRC::LP_BABEL;
2249 rc.language_package_selection = LyXRC::LP_CUSTOM;
2251 rc.language_package_selection = LyXRC::LP_NONE;
2252 rc.language_custom_package = fromqstr(languagePackageED->text());
2253 rc.language_global_options = globalCB->isChecked();
2254 rc.language_command_begin = fromqstr(startCommandED->text());
2255 rc.language_command_end = fromqstr(endCommandED->text());
2256 rc.gui_language = fromqstr(
2257 uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString());
2258 rc.default_decimal_point = fromqstr(defaultDecimalPointLE->text());
2262 void PrefLanguage::update(LyXRC const & rc)
2264 // FIXME: remove rtl_support bool
2265 rtlGB->setChecked(rc.rtl_support);
2266 if (rc.visual_cursor)
2267 visualCursorRB->setChecked(true);
2269 logicalCursorRB->setChecked(true);
2270 markForeignCB->setChecked(rc.mark_foreign_language);
2271 autoBeginCB->setChecked(rc.language_auto_begin);
2272 autoEndCB->setChecked(rc.language_auto_end);
2273 languagePackageCO->setCurrentIndex(rc.language_package_selection);
2274 languagePackageED->setText(toqstr(rc.language_custom_package));
2275 languagePackageED->setEnabled(languagePackageCO->currentIndex() == 2);
2276 globalCB->setChecked(rc.language_global_options);
2277 startCommandED->setText(toqstr(rc.language_command_begin));
2278 endCommandED->setText(toqstr(rc.language_command_end));
2279 defaultDecimalPointLE->setText(toqstr(rc.default_decimal_point));
2281 int pos = uiLanguageCO->findData(toqstr(rc.gui_language));
2282 uiLanguageCO->blockSignals(true);
2283 uiLanguageCO->setCurrentIndex(pos);
2284 uiLanguageCO->blockSignals(false);
2288 /////////////////////////////////////////////////////////////////////
2292 /////////////////////////////////////////////////////////////////////
2294 PrefPrinter::PrefPrinter(GuiPreferences * form)
2295 : PrefModule(qt_(catOutput), qt_("Printer"), form)
2299 connect(printerAdaptCB, SIGNAL(clicked()),
2300 this, SIGNAL(changed()));
2301 connect(printerCommandED, SIGNAL(textChanged(QString)),
2302 this, SIGNAL(changed()));
2303 connect(printerNameED, SIGNAL(textChanged(QString)),
2304 this, SIGNAL(changed()));
2305 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
2306 this, SIGNAL(changed()));
2307 connect(printerCopiesED, SIGNAL(textChanged(QString)),
2308 this, SIGNAL(changed()));
2309 connect(printerReverseED, SIGNAL(textChanged(QString)),
2310 this, SIGNAL(changed()));
2311 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
2312 this, SIGNAL(changed()));
2313 connect(printerExtensionED, SIGNAL(textChanged(QString)),
2314 this, SIGNAL(changed()));
2315 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
2316 this, SIGNAL(changed()));
2317 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
2318 this, SIGNAL(changed()));
2319 connect(printerEvenED, SIGNAL(textChanged(QString)),
2320 this, SIGNAL(changed()));
2321 connect(printerOddED, SIGNAL(textChanged(QString)),
2322 this, SIGNAL(changed()));
2323 connect(printerCollatedED, SIGNAL(textChanged(QString)),
2324 this, SIGNAL(changed()));
2325 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
2326 this, SIGNAL(changed()));
2327 connect(printerToFileED, SIGNAL(textChanged(QString)),
2328 this, SIGNAL(changed()));
2329 connect(printerExtraED, SIGNAL(textChanged(QString)),
2330 this, SIGNAL(changed()));
2331 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
2332 this, SIGNAL(changed()));
2333 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
2334 this, SIGNAL(changed()));
2338 void PrefPrinter::apply(LyXRC & rc) const
2340 rc.print_adapt_output = printerAdaptCB->isChecked();
2341 rc.print_command = fromqstr(printerCommandED->text());
2342 rc.printer = fromqstr(printerNameED->text());
2344 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
2345 rc.print_copies_flag = fromqstr(printerCopiesED->text());
2346 rc.print_reverse_flag = fromqstr(printerReverseED->text());
2347 rc.print_to_printer = fromqstr(printerToPrinterED->text());
2348 rc.print_file_extension = fromqstr(printerExtensionED->text());
2349 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
2350 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
2351 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
2352 rc.print_oddpage_flag = fromqstr(printerOddED->text());
2353 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
2354 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
2355 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
2356 rc.print_extra_options = fromqstr(printerExtraED->text());
2357 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
2358 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
2362 void PrefPrinter::update(LyXRC const & rc)
2364 printerAdaptCB->setChecked(rc.print_adapt_output);
2365 printerCommandED->setText(toqstr(rc.print_command));
2366 printerNameED->setText(toqstr(rc.printer));
2368 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
2369 printerCopiesED->setText(toqstr(rc.print_copies_flag));
2370 printerReverseED->setText(toqstr(rc.print_reverse_flag));
2371 printerToPrinterED->setText(toqstr(rc.print_to_printer));
2372 printerExtensionED->setText(toqstr(rc.print_file_extension));
2373 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
2374 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
2375 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
2376 printerOddED->setText(toqstr(rc.print_oddpage_flag));
2377 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
2378 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
2379 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
2380 printerExtraED->setText(toqstr(rc.print_extra_options));
2381 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
2382 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
2386 /////////////////////////////////////////////////////////////////////
2388 // PrefUserInterface
2390 /////////////////////////////////////////////////////////////////////
2392 PrefUserInterface::PrefUserInterface(GuiPreferences * form)
2393 : PrefModule(qt_(catLookAndFeel), qt_("User Interface"), form)
2397 connect(autoSaveCB, SIGNAL(toggled(bool)),
2398 autoSaveSB, SLOT(setEnabled(bool)));
2399 connect(autoSaveCB, SIGNAL(toggled(bool)),
2400 TextLabel1, SLOT(setEnabled(bool)));
2401 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
2402 this, SIGNAL(changed()));
2403 connect(singleInstanceCB, SIGNAL(clicked()),
2404 this, SIGNAL(changed()));
2405 #if QT_VERSION < 0x040500
2406 singleCloseTabButtonCB->setEnabled(false);
2408 connect(singleCloseTabButtonCB, SIGNAL(clicked()),
2409 this, SIGNAL(changed()));
2410 connect(uiFilePB, SIGNAL(clicked()),
2411 this, SLOT(selectUi()));
2412 connect(uiFileED, SIGNAL(textChanged(QString)),
2413 this, SIGNAL(changed()));
2414 connect(restoreCursorCB, SIGNAL(clicked()),
2415 this, SIGNAL(changed()));
2416 connect(loadSessionCB, SIGNAL(clicked()),
2417 this, SIGNAL(changed()));
2418 connect(allowGeometrySessionCB, SIGNAL(clicked()),
2419 this, SIGNAL(changed()));
2420 connect(autoSaveSB, SIGNAL(valueChanged(int)),
2421 this, SIGNAL(changed()));
2422 connect(autoSaveCB, SIGNAL(clicked()),
2423 this, SIGNAL(changed()));
2424 connect(backupCB, SIGNAL(clicked()),
2425 this, SIGNAL(changed()));
2426 connect(saveCompressedCB, SIGNAL(clicked()),
2427 this, SIGNAL(changed()));
2428 connect(lastfilesSB, SIGNAL(valueChanged(int)),
2429 this, SIGNAL(changed()));
2430 connect(tooltipCB, SIGNAL(toggled(bool)),
2431 this, SIGNAL(changed()));
2432 lastfilesSB->setMaximum(maxlastfiles);
2436 void PrefUserInterface::apply(LyXRC & rc) const
2438 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
2439 rc.use_lastfilepos = restoreCursorCB->isChecked();
2440 rc.load_session = loadSessionCB->isChecked();
2441 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
2442 rc.autosave = autoSaveCB->isChecked() ? autoSaveSB->value() * 60 : 0;
2443 rc.make_backup = backupCB->isChecked();
2444 rc.save_compressed = saveCompressedCB->isChecked();
2445 rc.num_lastfiles = lastfilesSB->value();
2446 rc.use_tooltip = tooltipCB->isChecked();
2447 rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
2448 rc.single_instance = singleInstanceCB->isChecked();
2449 rc.single_close_tab_button = singleCloseTabButtonCB->isChecked();
2450 #if QT_VERSION < 0x040500
2451 rc.single_close_tab_button = true;
2456 void PrefUserInterface::update(LyXRC const & rc)
2458 uiFileED->setText(toqstr(external_path(rc.ui_file)));
2459 restoreCursorCB->setChecked(rc.use_lastfilepos);
2460 loadSessionCB->setChecked(rc.load_session);
2461 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
2462 // convert to minutes
2463 bool autosave = rc.autosave > 0;
2464 int mins = rc.autosave / 60;
2467 autoSaveSB->setValue(mins);
2468 autoSaveCB->setChecked(autosave);
2469 autoSaveSB->setEnabled(autosave);
2470 backupCB->setChecked(rc.make_backup);
2471 saveCompressedCB->setChecked(rc.save_compressed);
2472 lastfilesSB->setValue(rc.num_lastfiles);
2473 tooltipCB->setChecked(rc.use_tooltip);
2474 openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
2475 singleInstanceCB->setChecked(rc.single_instance && !rc.lyxpipes.empty());
2476 singleInstanceCB->setEnabled(!rc.lyxpipes.empty());
2477 singleCloseTabButtonCB->setChecked(rc.single_close_tab_button);
2481 void PrefUserInterface::selectUi()
2483 QString file = form_->browseUI(internalPath(uiFileED->text()));
2484 if (!file.isEmpty())
2485 uiFileED->setText(file);
2489 void PrefUserInterface::on_clearSessionPB_clicked()
2491 guiApp->clearSession();
2496 /////////////////////////////////////////////////////////////////////
2500 /////////////////////////////////////////////////////////////////////
2502 PrefEdit::PrefEdit(GuiPreferences * form)
2503 : PrefModule(qt_(catEditing), qt_("Control"), form)
2507 connect(cursorFollowsCB, SIGNAL(clicked()),
2508 this, SIGNAL(changed()));
2509 connect(scrollBelowCB, SIGNAL(clicked()),
2510 this, SIGNAL(changed()));
2511 connect(macLikeWordMovementCB, SIGNAL(clicked()),
2512 this, SIGNAL(changed()));
2513 connect(sortEnvironmentsCB, SIGNAL(clicked()),
2514 this, SIGNAL(changed()));
2515 connect(groupEnvironmentsCB, SIGNAL(clicked()),
2516 this, SIGNAL(changed()));
2517 connect(macroEditStyleCO, SIGNAL(activated(int)),
2518 this, SIGNAL(changed()));
2519 connect(fullscreenLimitGB, SIGNAL(clicked()),
2520 this, SIGNAL(changed()));
2521 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
2522 this, SIGNAL(changed()));
2523 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
2524 this, SIGNAL(changed()));
2525 connect(toggleMenubarCB, SIGNAL(toggled(bool)),
2526 this, SIGNAL(changed()));
2527 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
2528 this, SIGNAL(changed()));
2529 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
2530 this, SIGNAL(changed()));
2534 void PrefEdit::apply(LyXRC & rc) const
2536 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
2537 rc.scroll_below_document = scrollBelowCB->isChecked();
2538 rc.mac_like_word_movement = macLikeWordMovementCB->isChecked();
2539 rc.sort_layouts = sortEnvironmentsCB->isChecked();
2540 rc.group_layouts = groupEnvironmentsCB->isChecked();
2541 switch (macroEditStyleCO->currentIndex()) {
2542 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
2543 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
2544 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
2546 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
2547 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
2548 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
2549 rc.full_screen_menubar = toggleMenubarCB->isChecked();
2550 rc.full_screen_width = fullscreenWidthSB->value();
2551 rc.full_screen_limit = fullscreenLimitGB->isChecked();
2555 void PrefEdit::update(LyXRC const & rc)
2557 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
2558 scrollBelowCB->setChecked(rc.scroll_below_document);
2559 macLikeWordMovementCB->setChecked(rc.mac_like_word_movement);
2560 sortEnvironmentsCB->setChecked(rc.sort_layouts);
2561 groupEnvironmentsCB->setChecked(rc.group_layouts);
2562 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
2563 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
2564 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
2565 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
2566 toggleMenubarCB->setChecked(rc.full_screen_menubar);
2567 fullscreenWidthSB->setValue(rc.full_screen_width);
2568 fullscreenLimitGB->setChecked(rc.full_screen_limit);
2572 /////////////////////////////////////////////////////////////////////
2576 /////////////////////////////////////////////////////////////////////
2579 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
2581 Ui::shortcutUi::setupUi(this);
2582 QDialog::setModal(true);
2586 PrefShortcuts::PrefShortcuts(GuiPreferences * form)
2587 : PrefModule(qt_(catEditing), qt_("Shortcuts"), form)
2591 shortcutsTW->setColumnCount(2);
2592 shortcutsTW->headerItem()->setText(0, qt_("Function"));
2593 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
2594 shortcutsTW->setSortingEnabled(true);
2595 // Multi-selection can be annoying.
2596 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
2598 connect(bindFilePB, SIGNAL(clicked()),
2599 this, SLOT(selectBind()));
2600 connect(bindFileED, SIGNAL(textChanged(QString)),
2601 this, SIGNAL(changed()));
2603 shortcut_ = new GuiShortcutDialog(this);
2604 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
2605 shortcut_bc_.setOK(shortcut_->okPB);
2606 shortcut_bc_.setCancel(shortcut_->cancelPB);
2608 connect(shortcut_->okPB, SIGNAL(clicked()),
2609 shortcut_, SLOT(accept()));
2610 connect(shortcut_->okPB, SIGNAL(clicked()),
2611 this, SIGNAL(changed()));
2612 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2613 shortcut_, SLOT(reject()));
2614 connect(shortcut_->clearPB, SIGNAL(clicked()),
2615 this, SLOT(shortcutClearPressed()));
2616 connect(shortcut_->removePB, SIGNAL(clicked()),
2617 this, SLOT(shortcutRemovePressed()));
2618 connect(shortcut_->okPB, SIGNAL(clicked()),
2619 this, SLOT(shortcutOkPressed()));
2620 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2621 this, SLOT(shortcutCancelPressed()));
2625 void PrefShortcuts::apply(LyXRC & rc) const
2627 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
2628 // write user_bind and user_unbind to .lyx/bind/user.bind
2629 FileName bind_dir(addPath(package().user_support().absFileName(), "bind"));
2630 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
2631 lyxerr << "LyX could not create the user bind directory '"
2632 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2635 if (!bind_dir.isDirWritable()) {
2636 lyxerr << "LyX could not write to the user bind directory '"
2637 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2640 FileName user_bind_file(bind_dir.absFileName() + "/user.bind");
2641 user_unbind_.write(user_bind_file.toFilesystemEncoding(), false, true);
2642 user_bind_.write(user_bind_file.toFilesystemEncoding(), true, false);
2643 // immediately apply the keybindings. Why this is not done before?
2644 // The good thing is that the menus are updated automatically.
2645 theTopLevelKeymap().clear();
2646 theTopLevelKeymap().read("site");
2647 theTopLevelKeymap().read(rc.bind_file, 0, KeyMap::Fallback);
2648 theTopLevelKeymap().read("user", 0, KeyMap::MissingOK);
2652 void PrefShortcuts::update(LyXRC const & rc)
2654 bindFileED->setText(toqstr(external_path(rc.bind_file)));
2656 system_bind_.clear();
2658 user_unbind_.clear();
2659 system_bind_.read("site");
2660 system_bind_.read(rc.bind_file);
2661 // \unbind in user.bind is added to user_unbind_
2662 user_bind_.read("user", &user_unbind_, KeyMap::MissingOK);
2663 updateShortcutsTW();
2667 void PrefShortcuts::updateShortcutsTW()
2669 shortcutsTW->clear();
2671 editItem_ = new QTreeWidgetItem(shortcutsTW);
2672 editItem_->setText(0, qt_("Cursor, Mouse and Editing Functions"));
2673 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2675 mathItem_ = new QTreeWidgetItem(shortcutsTW);
2676 mathItem_->setText(0, qt_("Mathematical Symbols"));
2677 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2679 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2680 bufferItem_->setText(0, qt_("Document and Window"));
2681 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2683 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2684 layoutItem_->setText(0, qt_("Font, Layouts and Textclasses"));
2685 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2687 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2688 systemItem_->setText(0, qt_("System and Miscellaneous"));
2689 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2691 // listBindings(unbound=true) lists all bound and unbound lfuns
2692 // Items in this list is tagged by its source.
2693 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2695 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2697 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2698 KeyMap::UserUnbind);
2699 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2700 user_bindinglist.end());
2701 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2702 user_unbindinglist.end());
2704 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2705 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2706 for (; it != it_end; ++it)
2707 insertShortcutItem(it->request, it->sequence, KeyMap::ItemType(it->tag));
2709 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2710 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2711 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2712 modifyPB->setEnabled(!items.isEmpty());
2714 shortcutsTW->resizeColumnToContents(0);
2718 void PrefShortcuts::setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag)
2720 item->setData(0, Qt::UserRole, QVariant(tag));
2724 case KeyMap::System:
2726 case KeyMap::UserBind:
2729 case KeyMap::UserUnbind:
2730 font.setStrikeOut(true);
2732 // this item is not displayed now.
2733 case KeyMap::UserExtraUnbind:
2734 font.setStrikeOut(true);
2738 item->setFont(1, font);
2742 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2743 KeySequence const & seq, KeyMap::ItemType tag)
2745 FuncCode const action = lfun.action();
2746 string const action_name = lyxaction.getActionName(action);
2747 QString const lfun_name = toqstr(from_utf8(action_name)
2748 + ' ' + lfun.argument());
2749 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2750 KeyMap::ItemType item_tag = tag;
2752 QTreeWidgetItem * newItem = 0;
2753 // for unbind items, try to find an existing item in the system bind list
2754 if (tag == KeyMap::UserUnbind) {
2755 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2756 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2757 for (int i = 0; i < items.size(); ++i) {
2758 if (items[i]->text(1) == shortcut)
2762 // if not found, this unbind item is KeyMap::UserExtraUnbind
2763 // Such an item is not displayed to avoid confusion (what is
2764 // unmatched removed?).
2766 item_tag = KeyMap::UserExtraUnbind;
2771 switch(lyxaction.getActionType(action)) {
2772 case LyXAction::Hidden:
2774 case LyXAction::Edit:
2775 newItem = new QTreeWidgetItem(editItem_);
2777 case LyXAction::Math:
2778 newItem = new QTreeWidgetItem(mathItem_);
2780 case LyXAction::Buffer:
2781 newItem = new QTreeWidgetItem(bufferItem_);
2783 case LyXAction::Layout:
2784 newItem = new QTreeWidgetItem(layoutItem_);
2786 case LyXAction::System:
2787 newItem = new QTreeWidgetItem(systemItem_);
2790 // this should not happen
2791 newItem = new QTreeWidgetItem(shortcutsTW);
2795 newItem->setText(0, lfun_name);
2796 newItem->setText(1, shortcut);
2797 // record BindFile representation to recover KeySequence when needed.
2798 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2799 setItemType(newItem, item_tag);
2804 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2806 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2807 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2808 modifyPB->setEnabled(!items.isEmpty());
2809 if (items.isEmpty())
2812 KeyMap::ItemType tag =
2813 static_cast<KeyMap::ItemType>(items[0]->data(0, Qt::UserRole).toInt());
2814 if (tag == KeyMap::UserUnbind)
2815 removePB->setText(qt_("Res&tore"));
2817 removePB->setText(qt_("Remo&ve"));
2821 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2827 void PrefShortcuts::modifyShortcut()
2829 QTreeWidgetItem * item = shortcutsTW->currentItem();
2830 if (item->flags() & Qt::ItemIsSelectable) {
2831 shortcut_->lfunLE->setText(item->text(0));
2832 save_lfun_ = item->text(0).trimmed();
2833 shortcut_->shortcutWG->setText(item->text(1));
2835 seq.parse(fromqstr(item->data(1, Qt::UserRole).toString()));
2836 shortcut_->shortcutWG->setKeySequence(seq);
2837 shortcut_->shortcutWG->setFocus();
2843 void PrefShortcuts::removeShortcut()
2845 // it seems that only one item can be selected, but I am
2846 // removing all selected items anyway.
2847 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2848 for (int i = 0; i < items.size(); ++i) {
2849 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2850 string lfun = fromqstr(items[i]->text(0));
2851 FuncRequest func = lyxaction.lookupFunc(lfun);
2852 KeyMap::ItemType tag =
2853 static_cast<KeyMap::ItemType>(items[i]->data(0, Qt::UserRole).toInt());
2856 case KeyMap::System: {
2857 // for system bind, we do not touch the item
2858 // but add an user unbind item
2859 user_unbind_.bind(shortcut, func);
2860 setItemType(items[i], KeyMap::UserUnbind);
2861 removePB->setText(qt_("Res&tore"));
2864 case KeyMap::UserBind: {
2865 // for user_bind, we remove this bind
2866 QTreeWidgetItem * parent = items[i]->parent();
2867 int itemIdx = parent->indexOfChild(items[i]);
2868 parent->takeChild(itemIdx);
2870 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2872 shortcutsTW->scrollToItem(parent);
2873 user_bind_.unbind(shortcut, func);
2876 case KeyMap::UserUnbind: {
2877 // for user_unbind, we remove the unbind, and the item
2878 // become KeyMap::System again.
2879 user_unbind_.unbind(shortcut, func);
2880 setItemType(items[i], KeyMap::System);
2881 removePB->setText(qt_("Remo&ve"));
2884 case KeyMap::UserExtraUnbind: {
2885 // for user unbind that is not in system bind file,
2886 // remove this unbind file
2887 QTreeWidgetItem * parent = items[i]->parent();
2888 parent->takeChild(parent->indexOfChild(items[i]));
2889 user_unbind_.unbind(shortcut, func);
2896 void PrefShortcuts::selectBind()
2898 QString file = form_->browsebind(internalPath(bindFileED->text()));
2899 if (!file.isEmpty()) {
2900 bindFileED->setText(file);
2901 system_bind_ = KeyMap();
2902 system_bind_.read(fromqstr(file));
2903 updateShortcutsTW();
2908 void PrefShortcuts::on_modifyPB_pressed()
2914 void PrefShortcuts::on_newPB_pressed()
2916 shortcut_->lfunLE->clear();
2917 shortcut_->shortcutWG->reset();
2918 save_lfun_ = QString();
2923 void PrefShortcuts::on_removePB_pressed()
2930 void PrefShortcuts::on_searchLE_textEdited()
2932 if (searchLE->text().isEmpty()) {
2933 // show all hidden items
2934 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2936 shortcutsTW->setItemHidden(*it++, false);
2939 // search both columns
2940 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2941 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2942 matched += shortcutsTW->findItems(searchLE->text(),
2943 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2945 // hide everyone (to avoid searching in matched QList repeatedly
2946 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2948 shortcutsTW->setItemHidden(*it++, true);
2949 // show matched items
2950 for (int i = 0; i < matched.size(); ++i) {
2951 shortcutsTW->setItemHidden(matched[i], false);
2952 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2957 docstring makeCmdString(FuncRequest const & f)
2959 docstring actionStr = from_ascii(lyxaction.getActionName(f.action()));
2960 if (!f.argument().empty())
2961 actionStr += " " + f.argument();
2966 void PrefShortcuts::shortcutOkPressed()
2968 QString const new_lfun = shortcut_->lfunLE->text();
2969 FuncRequest func = lyxaction.lookupFunc(fromqstr(new_lfun));
2971 if (func.action() == LFUN_UNKNOWN_ACTION) {
2972 Alert::error(_("Failed to create shortcut"),
2973 _("Unknown or invalid LyX function"));
2977 KeySequence k = shortcut_->shortcutWG->getKeySequence();
2978 if (k.length() == 0) {
2979 Alert::error(_("Failed to create shortcut"),
2980 _("Invalid or empty key sequence"));
2984 // check to see if there's been any change
2985 FuncRequest oldBinding = system_bind_.getBinding(k);
2986 if (oldBinding.action() == LFUN_UNKNOWN_ACTION)
2987 oldBinding = user_bind_.getBinding(k);
2988 if (oldBinding == func)
2989 // nothing has changed
2992 // make sure this key isn't already bound---and, if so, not unbound
2993 FuncCode const unbind = user_unbind_.getBinding(k).action();
2994 docstring const action_string = makeCmdString(oldBinding);
2995 if (oldBinding.action() > LFUN_NOACTION && unbind == LFUN_UNKNOWN_ACTION
2996 && save_lfun_ != toqstr(action_string)) {
2997 // FIXME Perhaps we should offer to over-write the old shortcut?
2998 // If so, we'll need to remove it from our list, etc.
2999 Alert::error(_("Failed to create shortcut"),
3000 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s\n"
3001 "You need to remove that binding before creating a new one."),
3002 k.print(KeySequence::ForGui), action_string));
3006 if (!save_lfun_.isEmpty())
3007 // real modification of the lfun's shortcut,
3008 // so remove the previous one
3011 QTreeWidgetItem * item = insertShortcutItem(func, k, KeyMap::UserBind);
3013 user_bind_.bind(&k, func);
3014 shortcutsTW->sortItems(0, Qt::AscendingOrder);
3015 shortcutsTW->setItemExpanded(item->parent(), true);
3016 shortcutsTW->scrollToItem(item);
3018 Alert::error(_("Failed to create shortcut"),
3019 _("Can not insert shortcut to the list"));
3025 void PrefShortcuts::shortcutCancelPressed()
3027 shortcut_->shortcutWG->reset();
3031 void PrefShortcuts::shortcutClearPressed()
3033 shortcut_->shortcutWG->reset();
3037 void PrefShortcuts::shortcutRemovePressed()
3039 shortcut_->shortcutWG->removeFromSequence();
3043 /////////////////////////////////////////////////////////////////////
3047 /////////////////////////////////////////////////////////////////////
3049 PrefIdentity::PrefIdentity(GuiPreferences * form)
3050 : PrefModule(QString(), qt_("Identity"), form)
3054 connect(nameED, SIGNAL(textChanged(QString)),
3055 this, SIGNAL(changed()));
3056 connect(emailED, SIGNAL(textChanged(QString)),
3057 this, SIGNAL(changed()));
3061 void PrefIdentity::apply(LyXRC & rc) const
3063 rc.user_name = fromqstr(nameED->text());
3064 rc.user_email = fromqstr(emailED->text());
3068 void PrefIdentity::update(LyXRC const & rc)
3070 nameED->setText(toqstr(rc.user_name));
3071 emailED->setText(toqstr(rc.user_email));
3076 /////////////////////////////////////////////////////////////////////
3080 /////////////////////////////////////////////////////////////////////
3082 GuiPreferences::GuiPreferences(GuiView & lv)
3083 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
3087 QDialog::setModal(false);
3089 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
3090 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
3091 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
3092 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
3094 addModule(new PrefUserInterface(this));
3095 addModule(new PrefEdit(this));
3096 addModule(new PrefShortcuts(this));
3097 PrefScreenFonts * screenfonts = new PrefScreenFonts(this);
3098 connect(this, SIGNAL(prefsApplied(LyXRC const &)),
3099 screenfonts, SLOT(updateScreenFontSizes(LyXRC const &)));
3100 addModule(screenfonts);
3101 addModule(new PrefColors(this));
3102 addModule(new PrefDisplay(this));
3103 addModule(new PrefInput(this));
3104 addModule(new PrefCompletion(this));
3106 addModule(new PrefPaths(this));
3108 addModule(new PrefIdentity(this));
3110 addModule(new PrefLanguage(this));
3111 addModule(new PrefSpellchecker(this));
3113 //for strftime validator
3114 PrefOutput * output = new PrefOutput(this);
3116 addModule(new PrefPrinter(this));
3117 addModule(new PrefLatex(this));
3119 PrefConverters * converters = new PrefConverters(this);
3120 PrefFileformats * formats = new PrefFileformats(this);
3121 connect(formats, SIGNAL(formatsChanged()),
3122 converters, SLOT(updateGui()));
3123 addModule(converters);
3126 prefsPS->setCurrentPanel(qt_("User Interface"));
3127 // FIXME: hack to work around resizing bug in Qt >= 4.2
3128 // bug verified with Qt 4.2.{0-3} (JSpitzm)
3129 #if QT_VERSION >= 0x040200
3130 prefsPS->updateGeometry();
3133 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
3135 bc().setApply(applyPB);
3136 bc().setCancel(closePB);
3137 bc().setRestore(restorePB);
3139 // initialize the strftime validator
3140 bc().addCheckedLineEdit(output->DateED);
3144 void GuiPreferences::addModule(PrefModule * module)
3146 LASSERT(module, return);
3147 if (module->category().isEmpty())
3148 prefsPS->addPanel(module, module->title());
3150 prefsPS->addPanel(module, module->title(), module->category());
3151 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
3152 modules_.push_back(module);
3156 void GuiPreferences::change_adaptor()
3162 void GuiPreferences::apply(LyXRC & rc) const
3164 size_t end = modules_.size();
3165 for (size_t i = 0; i != end; ++i)
3166 modules_[i]->apply(rc);
3170 void GuiPreferences::updateRc(LyXRC const & rc)
3172 size_t const end = modules_.size();
3173 for (size_t i = 0; i != end; ++i)
3174 modules_[i]->update(rc);
3178 void GuiPreferences::applyView()
3184 bool GuiPreferences::initialiseParams(string const &)
3187 formats_ = lyx::formats;
3188 converters_ = theConverters();
3189 converters_.update(formats_);
3190 movers_ = theMovers();
3192 update_screen_font_ = false;
3195 // Make sure that the bc is in the INITIAL state
3196 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3203 void GuiPreferences::dispatchParams()
3206 rc_.write(ss, true);
3207 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
3208 // issue prefsApplied signal. This will update the
3209 // localized screen font sizes.
3211 // FIXME: these need lfuns
3213 Author const & author =
3214 Author(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
3215 theBufferList().recordCurrentAuthor(author);
3217 lyx::formats = formats_;
3219 theConverters() = converters_;
3220 theConverters().update(lyx::formats);
3221 theConverters().buildGraph();
3223 theMovers() = movers_;
3225 vector<string>::const_iterator it = colors_.begin();
3226 vector<string>::const_iterator const end = colors_.end();
3227 for (; it != end; ++it)
3228 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
3231 if (update_screen_font_) {
3232 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
3233 update_screen_font_ = false;
3236 // The Save button has been pressed
3238 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
3242 void GuiPreferences::setColor(ColorCode col, QString const & hex)
3244 colors_.push_back(lcolor.getLyXName(col) + ' ' + fromqstr(hex));
3248 void GuiPreferences::updateScreenFonts()
3250 update_screen_font_ = true;
3254 QString GuiPreferences::browsebind(QString const & file) const
3256 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
3257 QStringList(qt_("LyX bind files (*.bind)")));
3261 QString GuiPreferences::browseUI(QString const & file) const
3263 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
3264 QStringList(qt_("LyX UI files (*.ui)")));
3268 QString GuiPreferences::browsekbmap(QString const & file) const
3270 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
3271 QStringList(qt_("LyX keyboard maps (*.kmap)")));
3275 QString GuiPreferences::browse(QString const & file,
3276 QString const & title) const
3278 return browseFile(file, title, QStringList(), true);
3282 // We support less paper sizes than the document dialog
3283 // Therefore this adjustment is needed.
3284 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
3288 return PAPER_DEFAULT;
3290 return PAPER_USLETTER;
3292 return PAPER_USLEGAL;
3294 return PAPER_USEXECUTIVE;
3304 // should not happen
3305 return PAPER_DEFAULT;
3310 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
3312 switch (papersize) {
3315 case PAPER_USLETTER:
3319 case PAPER_USEXECUTIVE:
3330 // should not happen
3336 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
3339 } // namespace frontend
3342 #include "moc_GuiPrefs.cpp"