3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
16 #include "ColorCache.h"
17 #include "FileDialog.h"
18 #include "GuiApplication.h"
19 #include "GuiFontExample.h"
20 #include "GuiFontLoader.h"
21 #include "GuiKeySymbol.h"
22 #include "qt_helpers.h"
24 #include "BufferList.h"
27 #include "ConverterCache.h"
28 #include "FontEnums.h"
29 #include "FuncRequest.h"
31 #include "KeySequence.h"
33 #include "LyXAction.h"
34 #include "PanelStack.h"
37 #include "SpellChecker.h"
39 #include "support/debug.h"
40 #include "support/FileName.h"
41 #include "support/filetools.h"
42 #include "support/foreach.h"
43 #include "support/gettext.h"
44 #include "support/lstrings.h"
45 #include "support/os.h"
46 #include "support/Package.h"
48 #include "graphics/GraphicsTypes.h"
50 #include "frontends/alert.h"
51 #include "frontends/Application.h"
52 #include "frontends/FontLoader.h"
54 #include <QAbstractItemModel>
56 #include <QColorDialog>
57 #include <QFontDatabase>
58 #include <QHeaderView>
60 #include <QMessageBox>
61 #include <QPixmapCache>
62 #include <QPushButton>
65 #include <QTreeWidget>
66 #include <QTreeWidgetItem>
76 using namespace lyx::support;
77 using namespace lyx::support::os;
82 /////////////////////////////////////////////////////////////////////
86 /////////////////////////////////////////////////////////////////////
88 /** Launch a file dialog and return the chosen file.
89 filename: a suggested filename.
90 title: the title of the dialog.
92 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
94 QString browseFile(QString const & filename,
95 QString const & title,
96 QStringList const & filters,
98 QString const & label1 = QString(),
99 QString const & dir1 = QString(),
100 QString const & label2 = QString(),
101 QString const & dir2 = QString(),
102 QString const & fallback_dir = QString())
104 QString lastPath = ".";
105 if (!filename.isEmpty())
106 lastPath = onlyPath(filename);
107 else if(!fallback_dir.isEmpty())
108 lastPath = fallback_dir;
110 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
111 dlg.setButton2(label1, dir1);
112 dlg.setButton2(label2, dir2);
114 FileDialog::Result result;
117 result = dlg.save(lastPath, filters, onlyFilename(filename));
119 result = dlg.open(lastPath, filters, onlyFilename(filename));
121 return result.second;
125 /** Wrapper around browseFile which tries to provide a filename
126 * relative to the user or system directory. The dir, name and ext
127 * parameters have the same meaning as in the
128 * support::LibFileSearch function.
130 QString browseLibFile(QString const & dir,
131 QString const & name,
133 QString const & title,
134 QStringList const & filters)
137 QString const label1 = qt_("System files|#S#s");
139 toqstr(addName(package().system_support().absFilename(), fromqstr(dir)));
141 QString const label2 = qt_("User files|#U#u");
143 toqstr(addName(package().user_support().absFilename(), fromqstr(dir)));
145 QString const result = browseFile(toqstr(
146 libFileSearch(dir, name, ext).absFilename()),
147 title, filters, false, dir1, dir2, QString(), QString(), dir1);
149 // remove the extension if it is the default one
151 if (getExtension(result) == ext)
152 noextresult = removeExtension(result);
154 noextresult = result;
156 // remove the directory, if it is the default one
157 QString const file = onlyFilename(noextresult);
158 if (toqstr(libFileSearch(dir, file, ext).absFilename()) == result)
165 /** Launch a file dialog and return the chosen directory.
166 pathname: a suggested pathname.
167 title: the title of the dialog.
168 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
170 QString browseDir(QString const & pathname,
171 QString const & title,
172 QString const & label1 = QString(),
173 QString const & dir1 = QString(),
174 QString const & label2 = QString(),
175 QString const & dir2 = QString())
177 QString lastPath = ".";
178 if (!pathname.isEmpty())
179 lastPath = onlyPath(pathname);
181 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
182 dlg.setButton1(label1, dir1);
183 dlg.setButton2(label2, dir2);
185 FileDialog::Result const result =
186 dlg.opendir(lastPath, onlyFilename(pathname));
188 return result.second;
192 } // namespace frontend
195 QString browseRelFile(QString const & filename, QString const & refpath,
196 QString const & title, QStringList const & filters, bool save,
197 QString const & label1, QString const & dir1,
198 QString const & label2, QString const & dir2)
200 QString const fname = makeAbsPath(filename, refpath);
203 QString const outname =
204 frontend::browseFile(fname, title, filters, save, label1, dir1, label2, dir2);
206 QString const reloutname =
207 toqstr(makeRelPath(qstring_to_ucs4(outname), qstring_to_ucs4(refpath)));
209 if (reloutname.startsWith("../"))
217 /////////////////////////////////////////////////////////////////////
221 /////////////////////////////////////////////////////////////////////
225 string const catLookAndFeel = N_("Look & Feel");
226 string const catEditing = N_("Editing");
227 string const catLanguage = N_("Language Settings");
228 string const catOutput = N_("Output");
229 string const catFiles = N_("File Handling");
231 static void parseFontName(QString const & mangled0,
232 string & name, string & foundry)
234 string mangled = fromqstr(mangled0);
235 size_t const idx = mangled.find('[');
236 if (idx == string::npos || idx == 0) {
240 name = mangled.substr(0, idx - 1),
241 foundry = mangled.substr(idx + 1, mangled.size() - idx - 2);
246 static void setComboxFont(QComboBox * cb, string const & family,
247 string const & foundry)
249 QString fontname = toqstr(family);
250 if (!foundry.empty())
251 fontname += " [" + toqstr(foundry) + ']';
253 for (int i = 0; i != cb->count(); ++i) {
254 if (cb->itemText(i) == fontname) {
255 cb->setCurrentIndex(i);
260 // Try matching without foundry name
262 // We count in reverse in order to prefer the Xft foundry
263 for (int i = cb->count(); --i >= 0;) {
264 string name, foundry;
265 parseFontName(cb->itemText(i), name, foundry);
266 if (compare_ascii_no_case(name, family) == 0) {
267 cb->setCurrentIndex(i);
272 // family alone can contain e.g. "Helvetica [Adobe]"
273 string tmpname, tmpfoundry;
274 parseFontName(toqstr(family), tmpname, tmpfoundry);
276 // We count in reverse in order to prefer the Xft foundry
277 for (int i = cb->count(); --i >= 0; ) {
278 string name, foundry;
279 parseFontName(cb->itemText(i), name, foundry);
280 if (compare_ascii_no_case(name, foundry) == 0) {
281 cb->setCurrentIndex(i);
286 // Bleh, default fonts, and the names couldn't be found. Hack
290 font.setKerning(false);
292 QString const font_family = toqstr(family);
293 if (font_family == guiApp->romanFontName()) {
294 font.setStyleHint(QFont::Serif);
295 font.setFamily(font_family);
296 } else if (font_family == guiApp->sansFontName()) {
297 font.setStyleHint(QFont::SansSerif);
298 font.setFamily(font_family);
299 } else if (font_family == guiApp->typewriterFontName()) {
300 font.setStyleHint(QFont::TypeWriter);
301 font.setFamily(font_family);
303 LYXERR0("FAILED to find the default font: '"
304 << foundry << "', '" << family << '\'');
308 QFontInfo info(font);
309 string default_font_name, dummyfoundry;
310 parseFontName(info.family(), default_font_name, dummyfoundry);
311 LYXERR0("Apparent font is " << default_font_name);
313 for (int i = 0; i < cb->count(); ++i) {
314 LYXERR0("Looking at " << cb->itemText(i));
315 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
316 default_font_name) == 0) {
317 cb->setCurrentIndex(i);
322 LYXERR0("FAILED to find the font: '"
323 << foundry << "', '" << family << '\'');
328 /////////////////////////////////////////////////////////////////////
332 /////////////////////////////////////////////////////////////////////
334 PrefPlaintext::PrefPlaintext(GuiPreferences * form)
335 : PrefModule(qt_(catOutput), qt_("Plain text"), form)
338 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
339 this, SIGNAL(changed()));
343 void PrefPlaintext::apply(LyXRC & rc) const
345 rc.plaintext_linelen = plaintextLinelengthSB->value();
349 void PrefPlaintext::update(LyXRC const & rc)
351 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
355 /////////////////////////////////////////////////////////////////////
359 /////////////////////////////////////////////////////////////////////
361 class StrftimeValidator : public QValidator
364 StrftimeValidator(QWidget *);
365 QValidator::State validate(QString & input, int & pos) const;
369 StrftimeValidator::StrftimeValidator(QWidget * parent)
375 QValidator::State StrftimeValidator::validate(QString & input, int & /*pos*/) const
377 if (is_valid_strftime(fromqstr(input)))
378 return QValidator::Acceptable;
380 return QValidator::Intermediate;
384 /////////////////////////////////////////////////////////////////////
388 /////////////////////////////////////////////////////////////////////
390 PrefDate::PrefDate(GuiPreferences * form)
391 : PrefModule(qt_(catOutput), qt_("Date format"), form)
394 DateED->setValidator(new StrftimeValidator(DateED));
395 connect(DateED, SIGNAL(textChanged(QString)),
396 this, SIGNAL(changed()));
400 void PrefDate::on_DateED_textChanged(const QString &)
402 QString t = DateED->text();
404 bool valid = DateED->validator()->validate(t, p)
405 == QValidator::Acceptable;
406 setValid(DateLA, valid);
410 void PrefDate::apply(LyXRC & rc) const
412 rc.date_insert_format = fromqstr(DateED->text());
416 void PrefDate::update(LyXRC const & rc)
418 DateED->setText(toqstr(rc.date_insert_format));
422 /////////////////////////////////////////////////////////////////////
426 /////////////////////////////////////////////////////////////////////
428 PrefInput::PrefInput(GuiPreferences * form)
429 : PrefModule(qt_(catEditing), qt_("Keyboard/Mouse"), form)
433 connect(keymapCB, SIGNAL(clicked()),
434 this, SIGNAL(changed()));
435 connect(firstKeymapED, SIGNAL(textChanged(QString)),
436 this, SIGNAL(changed()));
437 connect(secondKeymapED, SIGNAL(textChanged(QString)),
438 this, SIGNAL(changed()));
439 connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
440 this, SIGNAL(changed()));
444 void PrefInput::apply(LyXRC & rc) const
446 // FIXME: can derive CB from the two EDs
447 rc.use_kbmap = keymapCB->isChecked();
448 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
449 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
450 rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
454 void PrefInput::update(LyXRC const & rc)
456 // FIXME: can derive CB from the two EDs
457 keymapCB->setChecked(rc.use_kbmap);
458 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
459 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
460 mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
464 QString PrefInput::testKeymap(QString const & keymap)
466 return form_->browsekbmap(internalPath(keymap));
470 void PrefInput::on_firstKeymapPB_clicked(bool)
472 QString const file = testKeymap(firstKeymapED->text());
474 firstKeymapED->setText(file);
478 void PrefInput::on_secondKeymapPB_clicked(bool)
480 QString const file = testKeymap(secondKeymapED->text());
482 secondKeymapED->setText(file);
486 void PrefInput::on_keymapCB_toggled(bool keymap)
488 firstKeymapLA->setEnabled(keymap);
489 secondKeymapLA->setEnabled(keymap);
490 firstKeymapED->setEnabled(keymap);
491 secondKeymapED->setEnabled(keymap);
492 firstKeymapPB->setEnabled(keymap);
493 secondKeymapPB->setEnabled(keymap);
497 /////////////////////////////////////////////////////////////////////
501 /////////////////////////////////////////////////////////////////////
503 PrefCompletion::PrefCompletion(GuiPreferences * form)
504 : PrefModule(qt_(catEditing), qt_("Input Completion"), form)
508 connect(inlineDelaySB, SIGNAL(valueChanged(double)),
509 this, SIGNAL(changed()));
510 connect(inlineMathCB, SIGNAL(clicked()),
511 this, SIGNAL(changed()));
512 connect(inlineTextCB, SIGNAL(clicked()),
513 this, SIGNAL(changed()));
514 connect(inlineDotsCB, SIGNAL(clicked()),
515 this, SIGNAL(changed()));
516 connect(popupDelaySB, SIGNAL(valueChanged(double)),
517 this, SIGNAL(changed()));
518 connect(popupMathCB, SIGNAL(clicked()),
519 this, SIGNAL(changed()));
520 connect(autocorrectionCB, SIGNAL(clicked()),
521 this, SIGNAL(changed()));
522 connect(popupTextCB, SIGNAL(clicked()),
523 this, SIGNAL(changed()));
524 connect(popupAfterCompleteCB, SIGNAL(clicked()),
525 this, SIGNAL(changed()));
526 connect(cursorTextCB, SIGNAL(clicked()),
527 this, SIGNAL(changed()));
531 void PrefCompletion::on_inlineTextCB_clicked()
537 void PrefCompletion::on_popupTextCB_clicked()
543 void PrefCompletion::enableCB()
545 cursorTextCB->setEnabled(
546 popupTextCB->isChecked() || inlineTextCB->isChecked());
550 void PrefCompletion::apply(LyXRC & rc) const
552 rc.completion_inline_delay = inlineDelaySB->value();
553 rc.completion_inline_math = inlineMathCB->isChecked();
554 rc.completion_inline_text = inlineTextCB->isChecked();
555 rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
556 rc.completion_popup_delay = popupDelaySB->value();
557 rc.completion_popup_math = popupMathCB->isChecked();
558 rc.autocorrection_math = autocorrectionCB->isChecked();
559 rc.completion_popup_text = popupTextCB->isChecked();
560 rc.completion_cursor_text = cursorTextCB->isChecked();
561 rc.completion_popup_after_complete =
562 popupAfterCompleteCB->isChecked();
566 void PrefCompletion::update(LyXRC const & rc)
568 inlineDelaySB->setValue(rc.completion_inline_delay);
569 inlineMathCB->setChecked(rc.completion_inline_math);
570 inlineTextCB->setChecked(rc.completion_inline_text);
571 inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
572 popupDelaySB->setValue(rc.completion_popup_delay);
573 popupMathCB->setChecked(rc.completion_popup_math);
574 autocorrectionCB->setChecked(rc.autocorrection_math);
575 popupTextCB->setChecked(rc.completion_popup_text);
576 cursorTextCB->setChecked(rc.completion_cursor_text);
577 popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
583 /////////////////////////////////////////////////////////////////////
587 /////////////////////////////////////////////////////////////////////
589 PrefLatex::PrefLatex(GuiPreferences * form)
590 : PrefModule(qt_(catOutput), qt_("LaTeX"), form)
593 connect(latexEncodingCB, SIGNAL(clicked()),
594 this, SIGNAL(changed()));
595 connect(latexEncodingED, SIGNAL(textChanged(QString)),
596 this, SIGNAL(changed()));
597 connect(latexChecktexED, SIGNAL(textChanged(QString)),
598 this, SIGNAL(changed()));
599 connect(latexBibtexCO, SIGNAL(activated(int)),
600 this, SIGNAL(changed()));
601 connect(latexBibtexED, SIGNAL(textChanged(QString)),
602 this, SIGNAL(changed()));
603 connect(latexJBibtexED, SIGNAL(textChanged(QString)),
604 this, SIGNAL(changed()));
605 connect(latexIndexCO, SIGNAL(activated(int)),
606 this, SIGNAL(changed()));
607 connect(latexIndexED, SIGNAL(textChanged(QString)),
608 this, SIGNAL(changed()));
609 connect(latexJIndexED, SIGNAL(textChanged(QString)),
610 this, SIGNAL(changed()));
611 connect(latexAutoresetCB, SIGNAL(clicked()),
612 this, SIGNAL(changed()));
613 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
614 this, SIGNAL(changed()));
615 connect(latexPaperSizeCO, SIGNAL(activated(int)),
616 this, SIGNAL(changed()));
618 #if defined(__CYGWIN__) || defined(_WIN32)
619 pathCB->setVisible(true);
620 connect(pathCB, SIGNAL(clicked()),
621 this, SIGNAL(changed()));
623 pathCB->setVisible(false);
628 void PrefLatex::on_latexEncodingCB_stateChanged(int state)
630 latexEncodingED->setEnabled(state == Qt::Checked);
634 void PrefLatex::on_latexBibtexCO_activated(int n)
636 QString const bibtex = latexBibtexCO->itemData(n).toString();
637 if (bibtex.isEmpty()) {
638 latexBibtexED->clear();
639 latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
642 for (LyXRC::CommandSet::const_iterator it = bibtex_alternatives.begin();
643 it != bibtex_alternatives.end(); ++it) {
644 QString const bib = toqstr(*it);
645 int ind = bib.indexOf(" ");
646 QString sel_command = bib.left(ind);
647 QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
648 if (bibtex == sel_command) {
650 latexBibtexED->clear();
652 latexBibtexED->setText(sel_options.trimmed());
655 latexBibtexOptionsLA->setText(qt_("&Options:"));
659 void PrefLatex::on_latexIndexCO_activated(int n)
661 QString const index = latexIndexCO->itemData(n).toString();
662 if (index.isEmpty()) {
663 latexIndexED->clear();
664 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
667 for (LyXRC::CommandSet::const_iterator it = index_alternatives.begin();
668 it != index_alternatives.end(); ++it) {
669 QString const idx = toqstr(*it);
670 int ind = idx.indexOf(" ");
671 QString sel_command = idx.left(ind);
672 QString sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
673 if (index == sel_command) {
675 latexIndexED->clear();
677 latexIndexED->setText(sel_options.trimmed());
680 latexIndexOptionsLA->setText(qt_("Op&tions:"));
684 void PrefLatex::apply(LyXRC & rc) const
686 // If bibtex is not empty, bibopt contains the options, otherwise
687 // it is a customized bibtex command with options.
688 QString const bibtex = latexBibtexCO->itemData(
689 latexBibtexCO->currentIndex()).toString();
690 QString const bibopt = latexBibtexED->text();
691 if (bibtex.isEmpty())
692 rc.bibtex_command = fromqstr(bibopt);
693 else if (bibopt.isEmpty())
694 rc.bibtex_command = fromqstr(bibtex);
696 rc.bibtex_command = fromqstr(bibtex) + " " + fromqstr(bibopt);
698 // If index is not empty, idxopt contains the options, otherwise
699 // it is a customized index command with options.
700 QString const index = latexIndexCO->itemData(
701 latexIndexCO->currentIndex()).toString();
702 QString const idxopt = latexIndexED->text();
704 rc.index_command = fromqstr(idxopt);
705 else if (idxopt.isEmpty())
706 rc.index_command = fromqstr(index);
708 rc.index_command = fromqstr(index) + " " + fromqstr(idxopt);
710 if (latexEncodingCB->isChecked())
711 rc.fontenc = fromqstr(latexEncodingED->text());
713 rc.fontenc = "default";
714 rc.chktex_command = fromqstr(latexChecktexED->text());
715 rc.jbibtex_command = fromqstr(latexJBibtexED->text());
716 rc.jindex_command = fromqstr(latexJIndexED->text());
717 rc.nomencl_command = fromqstr(latexNomenclED->text());
718 rc.auto_reset_options = latexAutoresetCB->isChecked();
719 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
720 rc.default_papersize =
721 form_->toPaperSize(latexPaperSizeCO->currentIndex());
722 #if defined(__CYGWIN__) || defined(_WIN32)
723 rc.windows_style_tex_paths = pathCB->isChecked();
728 void PrefLatex::update(LyXRC const & rc)
730 latexBibtexCO->clear();
732 latexBibtexCO->addItem(qt_("Custom"), QString());
733 for (LyXRC::CommandSet::const_iterator it = rc.bibtex_alternatives.begin();
734 it != rc.bibtex_alternatives.end(); ++it) {
735 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
736 latexBibtexCO->addItem(command, command);
739 bibtex_alternatives = rc.bibtex_alternatives;
741 QString const bib = toqstr(rc.bibtex_command);
742 int ind = bib.indexOf(" ");
743 QString sel_command = bib.left(ind);
744 QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
746 int pos = latexBibtexCO->findData(sel_command);
748 latexBibtexCO->setCurrentIndex(pos);
749 latexBibtexED->setText(sel_options.trimmed());
750 latexBibtexOptionsLA->setText(qt_("&Options:"));
752 latexBibtexED->setText(toqstr(rc.bibtex_command));
753 latexBibtexCO->setCurrentIndex(0);
754 latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
757 latexIndexCO->clear();
759 latexIndexCO->addItem(qt_("Custom"), QString());
760 for (LyXRC::CommandSet::const_iterator it = rc.index_alternatives.begin();
761 it != rc.index_alternatives.end(); ++it) {
762 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
763 latexIndexCO->addItem(command, command);
766 index_alternatives = rc.index_alternatives;
768 QString const idx = toqstr(rc.index_command);
769 ind = idx.indexOf(" ");
770 sel_command = idx.left(ind);
771 sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
773 pos = latexIndexCO->findData(sel_command);
775 latexIndexCO->setCurrentIndex(pos);
776 latexIndexED->setText(sel_options.trimmed());
777 latexIndexOptionsLA->setText(qt_("Op&tions:"));
779 latexIndexED->setText(toqstr(rc.index_command));
780 latexIndexCO->setCurrentIndex(0);
781 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
784 if (rc.fontenc == "default") {
785 latexEncodingCB->setChecked(false);
786 latexEncodingED->setEnabled(false);
788 latexEncodingCB->setChecked(true);
789 latexEncodingED->setEnabled(true);
790 latexEncodingED->setText(toqstr(rc.fontenc));
792 latexChecktexED->setText(toqstr(rc.chktex_command));
793 latexJBibtexED->setText(toqstr(rc.jbibtex_command));
794 latexJIndexED->setText(toqstr(rc.jindex_command));
795 latexNomenclED->setText(toqstr(rc.nomencl_command));
796 latexAutoresetCB->setChecked(rc.auto_reset_options);
797 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
798 latexPaperSizeCO->setCurrentIndex(
799 form_->fromPaperSize(rc.default_papersize));
800 #if defined(__CYGWIN__) || defined(_WIN32)
801 pathCB->setChecked(rc.windows_style_tex_paths);
806 /////////////////////////////////////////////////////////////////////
810 /////////////////////////////////////////////////////////////////////
812 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form)
813 : PrefModule(qt_(catLookAndFeel), qt_("Screen fonts"), form)
817 connect(screenRomanCO, SIGNAL(activated(QString)),
818 this, SLOT(selectRoman(QString)));
819 connect(screenSansCO, SIGNAL(activated(QString)),
820 this, SLOT(selectSans(QString)));
821 connect(screenTypewriterCO, SIGNAL(activated(QString)),
822 this, SLOT(selectTypewriter(QString)));
824 QFontDatabase fontdb;
825 QStringList families(fontdb.families());
826 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
827 screenRomanCO->addItem(*it);
828 screenSansCO->addItem(*it);
829 screenTypewriterCO->addItem(*it);
831 connect(screenRomanCO, SIGNAL(activated(QString)),
832 this, SIGNAL(changed()));
833 connect(screenSansCO, SIGNAL(activated(QString)),
834 this, SIGNAL(changed()));
835 connect(screenTypewriterCO, SIGNAL(activated(QString)),
836 this, SIGNAL(changed()));
837 connect(screenZoomSB, SIGNAL(valueChanged(int)),
838 this, SIGNAL(changed()));
839 connect(screenDpiSB, SIGNAL(valueChanged(int)),
840 this, SIGNAL(changed()));
841 connect(screenTinyED, SIGNAL(textChanged(QString)),
842 this, SIGNAL(changed()));
843 connect(screenSmallestED, SIGNAL(textChanged(QString)),
844 this, SIGNAL(changed()));
845 connect(screenSmallerED, SIGNAL(textChanged(QString)),
846 this, SIGNAL(changed()));
847 connect(screenSmallED, SIGNAL(textChanged(QString)),
848 this, SIGNAL(changed()));
849 connect(screenNormalED, SIGNAL(textChanged(QString)),
850 this, SIGNAL(changed()));
851 connect(screenLargeED, SIGNAL(textChanged(QString)),
852 this, SIGNAL(changed()));
853 connect(screenLargerED, SIGNAL(textChanged(QString)),
854 this, SIGNAL(changed()));
855 connect(screenLargestED, SIGNAL(textChanged(QString)),
856 this, SIGNAL(changed()));
857 connect(screenHugeED, SIGNAL(textChanged(QString)),
858 this, SIGNAL(changed()));
859 connect(screenHugerED, SIGNAL(textChanged(QString)),
860 this, SIGNAL(changed()));
861 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
862 this, SIGNAL(changed()));
864 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
865 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
866 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
867 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
868 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
869 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
870 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
871 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
872 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
873 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
877 void PrefScreenFonts::apply(LyXRC & rc) const
879 LyXRC const oldrc = rc;
881 parseFontName(screenRomanCO->currentText(),
882 rc.roman_font_name, rc.roman_font_foundry);
883 parseFontName(screenSansCO->currentText(),
884 rc.sans_font_name, rc.sans_font_foundry);
885 parseFontName(screenTypewriterCO->currentText(),
886 rc.typewriter_font_name, rc.typewriter_font_foundry);
888 rc.zoom = screenZoomSB->value();
889 rc.dpi = screenDpiSB->value();
890 rc.font_sizes[FONT_SIZE_TINY] = widgetToDoubleStr(screenTinyED);
891 rc.font_sizes[FONT_SIZE_SCRIPT] = widgetToDoubleStr(screenSmallestED);
892 rc.font_sizes[FONT_SIZE_FOOTNOTE] = widgetToDoubleStr(screenSmallerED);
893 rc.font_sizes[FONT_SIZE_SMALL] = widgetToDoubleStr(screenSmallED);
894 rc.font_sizes[FONT_SIZE_NORMAL] = widgetToDoubleStr(screenNormalED);
895 rc.font_sizes[FONT_SIZE_LARGE] = widgetToDoubleStr(screenLargeED);
896 rc.font_sizes[FONT_SIZE_LARGER] = widgetToDoubleStr(screenLargerED);
897 rc.font_sizes[FONT_SIZE_LARGEST] = widgetToDoubleStr(screenLargestED);
898 rc.font_sizes[FONT_SIZE_HUGE] = widgetToDoubleStr(screenHugeED);
899 rc.font_sizes[FONT_SIZE_HUGER] = widgetToDoubleStr(screenHugerED);
900 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
902 if (rc.font_sizes != oldrc.font_sizes
903 || rc.roman_font_name != oldrc.roman_font_name
904 || rc.sans_font_name != oldrc.sans_font_name
905 || rc.typewriter_font_name != oldrc.typewriter_font_name
906 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
907 // The global QPixmapCache is used in GuiPainter to cache text
908 // painting so we must reset it in case any of the above
909 // parameter is changed.
910 QPixmapCache::clear();
911 guiApp->fontLoader().update();
912 form_->updateScreenFonts();
917 void PrefScreenFonts::update(LyXRC const & rc)
919 setComboxFont(screenRomanCO, rc.roman_font_name,
920 rc.roman_font_foundry);
921 setComboxFont(screenSansCO, rc.sans_font_name,
922 rc.sans_font_foundry);
923 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
924 rc.typewriter_font_foundry);
926 selectRoman(screenRomanCO->currentText());
927 selectSans(screenSansCO->currentText());
928 selectTypewriter(screenTypewriterCO->currentText());
930 screenZoomSB->setValue(rc.zoom);
931 screenDpiSB->setValue(rc.dpi);
932 doubleToWidget(screenTinyED, rc.font_sizes[FONT_SIZE_TINY]);
933 doubleToWidget(screenSmallestED, rc.font_sizes[FONT_SIZE_SCRIPT]);
934 doubleToWidget(screenSmallerED, rc.font_sizes[FONT_SIZE_FOOTNOTE]);
935 doubleToWidget(screenSmallED, rc.font_sizes[FONT_SIZE_SMALL]);
936 doubleToWidget(screenNormalED, rc.font_sizes[FONT_SIZE_NORMAL]);
937 doubleToWidget(screenLargeED, rc.font_sizes[FONT_SIZE_LARGE]);
938 doubleToWidget(screenLargerED, rc.font_sizes[FONT_SIZE_LARGER]);
939 doubleToWidget(screenLargestED, rc.font_sizes[FONT_SIZE_LARGEST]);
940 doubleToWidget(screenHugeED, rc.font_sizes[FONT_SIZE_HUGE]);
941 doubleToWidget(screenHugerED, rc.font_sizes[FONT_SIZE_HUGER]);
943 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
944 #if defined(Q_WS_X11)
945 pixmapCacheCB->setEnabled(false);
951 void PrefScreenFonts::selectRoman(const QString & name)
953 screenRomanFE->set(QFont(name), name);
957 void PrefScreenFonts::selectSans(const QString & name)
959 screenSansFE->set(QFont(name), name);
963 void PrefScreenFonts::selectTypewriter(const QString & name)
965 screenTypewriterFE->set(QFont(name), name);
969 /////////////////////////////////////////////////////////////////////
973 /////////////////////////////////////////////////////////////////////
979 bool operator()(ColorCode lhs, ColorCode rhs) const {
981 compare_no_case(lcolor.getGUIName(lhs), lcolor.getGUIName(rhs)) < 0;
987 PrefColors::PrefColors(GuiPreferences * form)
988 : PrefModule(qt_(catLookAndFeel), qt_("Colors"), form)
992 // FIXME: all of this initialization should be put into the controller.
993 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
994 // for some discussion of why that is not trivial.
995 QPixmap icon(32, 32);
996 for (int i = 0; i < Color_ignore; ++i) {
997 ColorCode lc = static_cast<ColorCode>(i);
1000 || lc == Color_white
1002 || lc == Color_green
1005 || lc == Color_magenta
1006 || lc == Color_yellow
1007 || lc == Color_inherit
1008 || lc == Color_ignore) continue;
1010 lcolors_.push_back(lc);
1012 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
1013 vector<ColorCode>::const_iterator cit = lcolors_.begin();
1014 vector<ColorCode>::const_iterator const end = lcolors_.end();
1015 for (; cit != end; ++cit) {
1016 (void) new QListWidgetItem(QIcon(icon),
1017 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
1019 curcolors_.resize(lcolors_.size());
1020 newcolors_.resize(lcolors_.size());
1021 // End initialization
1023 connect(colorChangePB, SIGNAL(clicked()),
1024 this, SLOT(changeColor()));
1025 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
1026 this, SLOT(changeLyxObjectsSelection()));
1027 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
1028 this, SLOT(changeColor()));
1032 void PrefColors::apply(LyXRC & /*rc*/) const
1034 for (unsigned int i = 0; i < lcolors_.size(); ++i)
1035 if (curcolors_[i] != newcolors_[i])
1036 form_->setColor(lcolors_[i], newcolors_[i]);
1040 void PrefColors::update(LyXRC const & /*rc*/)
1042 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
1043 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
1044 QPixmap coloritem(32, 32);
1045 coloritem.fill(color);
1046 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
1047 newcolors_[i] = curcolors_[i] = color.name();
1049 changeLyxObjectsSelection();
1053 void PrefColors::changeColor()
1055 int const row = lyxObjectsLW->currentRow();
1061 QString const color = newcolors_[row];
1062 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
1064 if (c.isValid() && c.name() != color) {
1065 newcolors_[row] = c.name();
1066 QPixmap coloritem(32, 32);
1068 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
1074 void PrefColors::changeLyxObjectsSelection()
1076 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
1080 /////////////////////////////////////////////////////////////////////
1084 /////////////////////////////////////////////////////////////////////
1086 PrefDisplay::PrefDisplay(GuiPreferences * form)
1087 : PrefModule(qt_(catLookAndFeel), qt_("Display"), form)
1090 connect(displayGraphicsCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
1091 connect(instantPreviewCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
1092 connect(previewSizeSB, SIGNAL(valueChanged(double)), this, SIGNAL(changed()));
1093 connect(paragraphMarkerCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
1094 if (instantPreviewCO->currentIndex() == 0)
1095 previewSizeSB->setEnabled(false);
1097 previewSizeSB->setEnabled(true);
1101 void PrefDisplay::on_instantPreviewCO_currentIndexChanged(int index)
1104 previewSizeSB->setEnabled(false);
1106 previewSizeSB->setEnabled(true);
1110 void PrefDisplay::apply(LyXRC & rc) const
1112 switch (instantPreviewCO->currentIndex()) {
1113 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
1114 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
1115 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
1118 rc.display_graphics = displayGraphicsCB->isChecked();
1119 rc.preview_scale_factor = previewSizeSB->value();
1120 rc.paragraph_markers = paragraphMarkerCB->isChecked();
1122 // FIXME!! The graphics cache no longer has a changeDisplay method.
1124 if (old_value != rc.display_graphics) {
1125 graphics::GCache & gc = graphics::GCache::get();
1132 void PrefDisplay::update(LyXRC const & rc)
1134 switch (rc.preview) {
1135 case LyXRC::PREVIEW_OFF:
1136 instantPreviewCO->setCurrentIndex(0);
1138 case LyXRC::PREVIEW_NO_MATH :
1139 instantPreviewCO->setCurrentIndex(1);
1141 case LyXRC::PREVIEW_ON :
1142 instantPreviewCO->setCurrentIndex(2);
1146 displayGraphicsCB->setChecked(rc.display_graphics);
1147 instantPreviewCO->setEnabled(rc.display_graphics);
1148 previewSizeSB->setValue(rc.preview_scale_factor);
1149 paragraphMarkerCB->setChecked(rc.paragraph_markers);
1153 /////////////////////////////////////////////////////////////////////
1157 /////////////////////////////////////////////////////////////////////
1159 PrefPaths::PrefPaths(GuiPreferences * form)
1160 : PrefModule(QString(), qt_("Paths"), form)
1164 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(selectWorkingdir()));
1165 connect(workingDirED, SIGNAL(textChanged(QString)),
1166 this, SIGNAL(changed()));
1168 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(selectTemplatedir()));
1169 connect(templateDirED, SIGNAL(textChanged(QString)),
1170 this, SIGNAL(changed()));
1172 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(selectExampledir()));
1173 connect(exampleDirED, SIGNAL(textChanged(QString)),
1174 this, SIGNAL(changed()));
1176 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(selectBackupdir()));
1177 connect(backupDirED, SIGNAL(textChanged(QString)),
1178 this, SIGNAL(changed()));
1180 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(selectLyxPipe()));
1181 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
1182 this, SIGNAL(changed()));
1184 connect(thesaurusDirPB, SIGNAL(clicked()), this, SLOT(selectThesaurusdir()));
1185 connect(thesaurusDirED, SIGNAL(textChanged(QString)),
1186 this, SIGNAL(changed()));
1188 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(selectTempdir()));
1189 connect(tempDirED, SIGNAL(textChanged(QString)),
1190 this, SIGNAL(changed()));
1192 connect(hunspellDirPB, SIGNAL(clicked()), this, SLOT(selectHunspelldir()));
1193 connect(hunspellDirED, SIGNAL(textChanged(QString)),
1194 this, SIGNAL(changed()));
1196 connect(pathPrefixED, SIGNAL(textChanged(QString)),
1197 this, SIGNAL(changed()));
1201 void PrefPaths::apply(LyXRC & rc) const
1203 rc.document_path = internal_path(fromqstr(workingDirED->text()));
1204 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
1205 rc.template_path = internal_path(fromqstr(templateDirED->text()));
1206 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
1207 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
1208 rc.thesaurusdir_path = internal_path(fromqstr(thesaurusDirED->text()));
1209 rc.hunspelldir_path = internal_path(fromqstr(hunspellDirED->text()));
1210 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
1211 // FIXME: should be a checkbox only
1212 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
1216 void PrefPaths::update(LyXRC const & rc)
1218 workingDirED->setText(toqstr(external_path(rc.document_path)));
1219 exampleDirED->setText(toqstr(external_path(rc.example_path)));
1220 templateDirED->setText(toqstr(external_path(rc.template_path)));
1221 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
1222 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
1223 thesaurusDirED->setText(toqstr(external_path(rc.thesaurusdir_path)));
1224 hunspellDirED->setText(toqstr(external_path(rc.hunspelldir_path)));
1225 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
1226 // FIXME: should be a checkbox only
1227 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
1231 void PrefPaths::selectExampledir()
1233 QString file = browseDir(internalPath(exampleDirED->text()),
1234 qt_("Select directory for example files"));
1235 if (!file.isEmpty())
1236 exampleDirED->setText(file);
1240 void PrefPaths::selectTemplatedir()
1242 QString file = browseDir(internalPath(templateDirED->text()),
1243 qt_("Select a document templates directory"));
1244 if (!file.isEmpty())
1245 templateDirED->setText(file);
1249 void PrefPaths::selectTempdir()
1251 QString file = browseDir(internalPath(tempDirED->text()),
1252 qt_("Select a temporary directory"));
1253 if (!file.isEmpty())
1254 tempDirED->setText(file);
1258 void PrefPaths::selectBackupdir()
1260 QString file = browseDir(internalPath(backupDirED->text()),
1261 qt_("Select a backups directory"));
1262 if (!file.isEmpty())
1263 backupDirED->setText(file);
1267 void PrefPaths::selectWorkingdir()
1269 QString file = browseDir(internalPath(workingDirED->text()),
1270 qt_("Select a document directory"));
1271 if (!file.isEmpty())
1272 workingDirED->setText(file);
1276 void PrefPaths::selectThesaurusdir()
1278 QString file = browseDir(internalPath(thesaurusDirED->text()),
1279 qt_("Set the path to the thesaurus dictionaries"));
1280 if (!file.isEmpty())
1281 thesaurusDirED->setText(file);
1285 void PrefPaths::selectHunspelldir()
1287 QString file = browseDir(internalPath(hunspellDirED->text()),
1288 qt_("Set the path to the Hunspell dictionaries"));
1289 if (!file.isEmpty())
1290 hunspellDirED->setText(file);
1294 void PrefPaths::selectLyxPipe()
1296 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1297 qt_("Give a filename for the LyX server pipe"));
1298 if (!file.isEmpty())
1299 lyxserverDirED->setText(file);
1303 /////////////////////////////////////////////////////////////////////
1307 /////////////////////////////////////////////////////////////////////
1309 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form)
1310 : PrefModule(qt_(catLanguage), qt_("Spellchecker"), form)
1314 #if defined(USE_ASPELL)
1315 spellcheckerCB->addItem(qt_("aspell"), QString("aspell"));
1317 #if defined(USE_ENCHANT)
1318 spellcheckerCB->addItem(qt_("enchant"), QString("enchant"));
1320 #if defined(USE_HUNSPELL)
1321 spellcheckerCB->addItem(qt_("hunspell"), QString("hunspell"));
1324 #if defined(USE_ASPELL) || defined(USE_ENCHANT) || defined(USE_HUNSPELL)
1325 connect(spellcheckerCB, SIGNAL(currentIndexChanged(int)),
1326 this, SIGNAL(changed()));
1327 connect(altLanguageED, SIGNAL(textChanged(QString)),
1328 this, SIGNAL(changed()));
1329 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1330 this, SIGNAL(changed()));
1331 connect(compoundWordCB, SIGNAL(clicked()),
1332 this, SIGNAL(changed()));
1333 connect(spellcheckContinuouslyCB, SIGNAL(clicked()),
1334 this, SIGNAL(changed()));
1335 connect(spellcheckNotesCB, SIGNAL(clicked()),
1336 this, SIGNAL(changed()));
1338 spellcheckerCB->setEnabled(false);
1339 altLanguageED->setEnabled(false);
1340 escapeCharactersED->setEnabled(false);
1341 compoundWordCB->setEnabled(false);
1342 spellcheckContinuouslyCB->setEnabled(false);
1343 spellcheckNotesCB->setEnabled(false);
1348 void PrefSpellchecker::apply(LyXRC & rc) const
1350 rc.spellchecker = fromqstr(spellcheckerCB->itemData(
1351 spellcheckerCB->currentIndex()).toString());
1352 rc.spellchecker_alt_lang = fromqstr(altLanguageED->text());
1353 rc.spellchecker_esc_chars = fromqstr(escapeCharactersED->text());
1354 rc.spellchecker_accept_compound = compoundWordCB->isChecked();
1355 rc.spellcheck_continuously = spellcheckContinuouslyCB->isChecked();
1356 rc.spellcheck_notes = spellcheckNotesCB->isChecked();
1360 void PrefSpellchecker::update(LyXRC const & rc)
1362 spellcheckerCB->setCurrentIndex(
1363 spellcheckerCB->findData(toqstr(rc.spellchecker)));
1364 altLanguageED->setText(toqstr(rc.spellchecker_alt_lang));
1365 escapeCharactersED->setText(toqstr(rc.spellchecker_esc_chars));
1366 compoundWordCB->setChecked(rc.spellchecker_accept_compound);
1367 spellcheckContinuouslyCB->setChecked(rc.spellcheck_continuously);
1368 spellcheckNotesCB->setChecked(rc.spellcheck_notes);
1373 /////////////////////////////////////////////////////////////////////
1377 /////////////////////////////////////////////////////////////////////
1380 PrefConverters::PrefConverters(GuiPreferences * form)
1381 : PrefModule(qt_(catFiles), qt_("Converters"), form)
1385 connect(converterNewPB, SIGNAL(clicked()),
1386 this, SLOT(updateConverter()));
1387 connect(converterRemovePB, SIGNAL(clicked()),
1388 this, SLOT(removeConverter()));
1389 connect(converterModifyPB, SIGNAL(clicked()),
1390 this, SLOT(updateConverter()));
1391 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1392 this, SLOT(switchConverter()));
1393 connect(converterFromCO, SIGNAL(activated(QString)),
1394 this, SLOT(changeConverter()));
1395 connect(converterToCO, SIGNAL(activated(QString)),
1396 this, SLOT(changeConverter()));
1397 connect(converterED, SIGNAL(textEdited(QString)),
1398 this, SLOT(changeConverter()));
1399 connect(converterFlagED, SIGNAL(textEdited(QString)),
1400 this, SLOT(changeConverter()));
1401 connect(converterNewPB, SIGNAL(clicked()),
1402 this, SIGNAL(changed()));
1403 connect(converterRemovePB, SIGNAL(clicked()),
1404 this, SIGNAL(changed()));
1405 connect(converterModifyPB, SIGNAL(clicked()),
1406 this, SIGNAL(changed()));
1407 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1408 this, SIGNAL(changed()));
1410 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1411 //converterDefGB->setFocusProxy(convertersLW);
1415 void PrefConverters::apply(LyXRC & rc) const
1417 rc.use_converter_cache = cacheCB->isChecked();
1418 rc.converter_cache_maxage = int(widgetToDouble(maxAgeLE) * 86400.0);
1422 void PrefConverters::update(LyXRC const & rc)
1424 cacheCB->setChecked(rc.use_converter_cache);
1426 doubleToWidget(maxAgeLE, (double(rc.converter_cache_maxage) / 86400.0), 'g', 6);
1431 void PrefConverters::updateGui()
1433 form_->formats().sort();
1434 form_->converters().update(form_->formats());
1435 // save current selection
1436 QString current = converterFromCO->currentText()
1437 + " -> " + converterToCO->currentText();
1439 converterFromCO->clear();
1440 converterToCO->clear();
1442 Formats::const_iterator cit = form_->formats().begin();
1443 Formats::const_iterator end = form_->formats().end();
1444 for (; cit != end; ++cit) {
1445 converterFromCO->addItem(qt_(cit->prettyname()));
1446 converterToCO->addItem(qt_(cit->prettyname()));
1449 // currentRowChanged(int) is also triggered when updating the listwidget
1450 // block signals to avoid unnecessary calls to switchConverter()
1451 convertersLW->blockSignals(true);
1452 convertersLW->clear();
1454 Converters::const_iterator ccit = form_->converters().begin();
1455 Converters::const_iterator cend = form_->converters().end();
1456 for (; ccit != cend; ++ccit) {
1457 QString const name =
1458 qt_(ccit->From->prettyname()) + " -> " + qt_(ccit->To->prettyname());
1459 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1460 new QListWidgetItem(name, convertersLW, type);
1462 convertersLW->sortItems(Qt::AscendingOrder);
1463 convertersLW->blockSignals(false);
1465 // restore selection
1466 if (!current.isEmpty()) {
1467 QList<QListWidgetItem *> const item =
1468 convertersLW->findItems(current, Qt::MatchExactly);
1469 if (!item.isEmpty())
1470 convertersLW->setCurrentItem(item.at(0));
1473 // select first element if restoring failed
1474 if (convertersLW->currentRow() == -1)
1475 convertersLW->setCurrentRow(0);
1481 void PrefConverters::switchConverter()
1483 int const cnr = convertersLW->currentItem()->type();
1484 Converter const & c(form_->converters().get(cnr));
1485 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1486 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1487 converterED->setText(toqstr(c.command));
1488 converterFlagED->setText(toqstr(c.flags));
1494 void PrefConverters::changeConverter()
1500 void PrefConverters::updateButtons()
1502 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1503 Format const & to = form_->formats().get(converterToCO->currentIndex());
1504 int const sel = form_->converters().getNumber(from.name(), to.name());
1505 bool const known = sel >= 0;
1506 bool const valid = !(converterED->text().isEmpty()
1507 || from.name() == to.name());
1509 int const cnr = convertersLW->currentItem()->type();
1510 Converter const & c = form_->converters().get(cnr);
1511 string const old_command = c.command;
1512 string const old_flag = c.flags;
1513 string const new_command = fromqstr(converterED->text());
1514 string const new_flag = fromqstr(converterFlagED->text());
1516 bool modified = (old_command != new_command || old_flag != new_flag);
1518 converterModifyPB->setEnabled(valid && known && modified);
1519 converterNewPB->setEnabled(valid && !known);
1520 converterRemovePB->setEnabled(known);
1522 maxAgeLE->setEnabled(cacheCB->isChecked());
1523 maxAgeLA->setEnabled(cacheCB->isChecked());
1528 // specify unique from/to or it doesn't appear. This is really bad UI
1529 // this is why we can use the same function for both new and modify
1530 void PrefConverters::updateConverter()
1532 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1533 Format const & to = form_->formats().get(converterToCO->currentIndex());
1534 string const flags = fromqstr(converterFlagED->text());
1535 string const command = fromqstr(converterED->text());
1537 Converter const * old =
1538 form_->converters().getConverter(from.name(), to.name());
1539 form_->converters().add(from.name(), to.name(), command, flags);
1542 form_->converters().updateLast(form_->formats());
1546 // Remove all files created by this converter from the cache, since
1547 // the modified converter might create different files.
1548 ConverterCache::get().remove_all(from.name(), to.name());
1552 void PrefConverters::removeConverter()
1554 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1555 Format const & to = form_->formats().get(converterToCO->currentIndex());
1556 form_->converters().erase(from.name(), to.name());
1560 // Remove all files created by this converter from the cache, since
1561 // a possible new converter might create different files.
1562 ConverterCache::get().remove_all(from.name(), to.name());
1566 void PrefConverters::on_cacheCB_stateChanged(int state)
1568 maxAgeLE->setEnabled(state == Qt::Checked);
1569 maxAgeLA->setEnabled(state == Qt::Checked);
1574 /////////////////////////////////////////////////////////////////////
1578 /////////////////////////////////////////////////////////////////////
1580 class FormatValidator : public QValidator
1583 FormatValidator(QWidget *, Formats const & f);
1584 void fixup(QString & input) const;
1585 QValidator::State validate(QString & input, int & pos) const;
1587 virtual QString toString(Format const & format) const = 0;
1589 Formats const & formats_;
1593 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1594 : QValidator(parent), formats_(f)
1599 void FormatValidator::fixup(QString & input) const
1601 Formats::const_iterator cit = formats_.begin();
1602 Formats::const_iterator end = formats_.end();
1603 for (; cit != end; ++cit) {
1604 QString const name = toString(*cit);
1605 if (distance(formats_.begin(), cit) == nr()) {
1613 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1615 Formats::const_iterator cit = formats_.begin();
1616 Formats::const_iterator end = formats_.end();
1617 bool unknown = true;
1618 for (; unknown && cit != end; ++cit) {
1619 QString const name = toString(*cit);
1620 if (distance(formats_.begin(), cit) != nr())
1621 unknown = name != input;
1624 if (unknown && !input.isEmpty())
1625 return QValidator::Acceptable;
1627 return QValidator::Intermediate;
1631 int FormatValidator::nr() const
1633 QComboBox * p = qobject_cast<QComboBox *>(parent());
1634 return p->itemData(p->currentIndex()).toInt();
1638 /////////////////////////////////////////////////////////////////////
1640 // FormatNameValidator
1642 /////////////////////////////////////////////////////////////////////
1644 class FormatNameValidator : public FormatValidator
1647 FormatNameValidator(QWidget * parent, Formats const & f)
1648 : FormatValidator(parent, f)
1651 QString toString(Format const & format) const
1653 return toqstr(format.name());
1658 /////////////////////////////////////////////////////////////////////
1660 // FormatPrettynameValidator
1662 /////////////////////////////////////////////////////////////////////
1664 class FormatPrettynameValidator : public FormatValidator
1667 FormatPrettynameValidator(QWidget * parent, Formats const & f)
1668 : FormatValidator(parent, f)
1671 QString toString(Format const & format) const
1673 return qt_(format.prettyname());
1678 /////////////////////////////////////////////////////////////////////
1682 /////////////////////////////////////////////////////////////////////
1684 PrefFileformats::PrefFileformats(GuiPreferences * form)
1685 : PrefModule(qt_(catFiles), qt_("File formats"), form)
1688 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1689 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1691 connect(documentCB, SIGNAL(clicked()),
1692 this, SLOT(setFlags()));
1693 connect(vectorCB, SIGNAL(clicked()),
1694 this, SLOT(setFlags()));
1695 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1696 this, SLOT(updatePrettyname()));
1697 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1698 this, SIGNAL(changed()));
1699 connect(defaultFormatCB, SIGNAL(activated(QString)),
1700 this, SIGNAL(changed()));
1701 connect(viewerCO, SIGNAL(activated(int)),
1702 this, SIGNAL(changed()));
1703 connect(editorCO, SIGNAL(activated(int)),
1704 this, SIGNAL(changed()));
1710 string const l10n_shortcut(string const prettyname, string const shortcut)
1712 if (shortcut.empty())
1715 string l10n_format =
1716 to_utf8(_(prettyname + '|' + shortcut));
1717 return split(l10n_format, '|');
1720 }; // namespace anon
1723 void PrefFileformats::apply(LyXRC & rc) const
1725 QString const default_format = defaultFormatCB->itemData(
1726 defaultFormatCB->currentIndex()).toString();
1727 rc.default_view_format = fromqstr(default_format);
1731 void PrefFileformats::update(LyXRC const & rc)
1733 viewer_alternatives = rc.viewer_alternatives;
1734 editor_alternatives = rc.editor_alternatives;
1735 bool const init = defaultFormatCB->currentText().isEmpty();
1739 defaultFormatCB->findData(toqstr(rc.default_view_format));
1740 defaultFormatCB->setCurrentIndex(pos);
1745 void PrefFileformats::updateView()
1747 QString const current = formatsCB->currentText();
1748 QString const current_def = defaultFormatCB->currentText();
1750 // update comboboxes with formats
1751 formatsCB->blockSignals(true);
1752 defaultFormatCB->blockSignals(true);
1754 defaultFormatCB->clear();
1755 form_->formats().sort();
1756 Formats::const_iterator cit = form_->formats().begin();
1757 Formats::const_iterator end = form_->formats().end();
1758 for (; cit != end; ++cit) {
1759 formatsCB->addItem(qt_(cit->prettyname()),
1760 QVariant(form_->formats().getNumber(cit->name())));
1761 if (form_->converters().isReachable("latex", cit->name())
1762 || form_->converters().isReachable("pdflatex", cit->name()))
1763 defaultFormatCB->addItem(qt_(cit->prettyname()),
1764 QVariant(toqstr(cit->name())));
1767 // restore selection
1768 int item = formatsCB->findText(current, Qt::MatchExactly);
1769 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1770 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1771 item = defaultFormatCB->findText(current_def, Qt::MatchExactly);
1772 defaultFormatCB->setCurrentIndex(item < 0 ? 0 : item);
1773 formatsCB->blockSignals(false);
1774 defaultFormatCB->blockSignals(false);
1778 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1780 int const nr = formatsCB->itemData(i).toInt();
1781 Format const f = form_->formats().get(nr);
1783 formatED->setText(toqstr(f.name()));
1784 copierED->setText(toqstr(form_->movers().command(f.name())));
1785 extensionED->setText(toqstr(f.extension()));
1786 shortcutED->setText(
1787 toqstr(l10n_shortcut(f.prettyname(), f.shortcut())));
1788 documentCB->setChecked((f.documentFormat()));
1789 vectorCB->setChecked((f.vectorFormat()));
1795 void PrefFileformats::setFlags()
1797 int flags = Format::none;
1798 if (documentCB->isChecked())
1799 flags |= Format::document;
1800 if (vectorCB->isChecked())
1801 flags |= Format::vector;
1802 currentFormat().setFlags(flags);
1807 void PrefFileformats::on_copierED_textEdited(const QString & s)
1809 string const fmt = fromqstr(formatED->text());
1810 form_->movers().set(fmt, fromqstr(s));
1815 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1817 currentFormat().setExtension(fromqstr(s));
1821 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1823 currentFormat().setViewer(fromqstr(s));
1828 void PrefFileformats::on_editorED_textEdited(const QString & s)
1830 currentFormat().setEditor(fromqstr(s));
1835 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1837 string const new_shortcut = fromqstr(s);
1838 if (new_shortcut == l10n_shortcut(currentFormat().prettyname(),
1839 currentFormat().shortcut()))
1841 currentFormat().setShortcut(new_shortcut);
1846 void PrefFileformats::on_formatED_editingFinished()
1848 string const newname = fromqstr(formatED->displayText());
1849 if (newname == currentFormat().name())
1852 currentFormat().setName(newname);
1857 void PrefFileformats::on_formatED_textChanged(const QString &)
1859 QString t = formatED->text();
1861 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1862 setValid(formatLA, valid);
1866 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1868 QString t = formatsCB->currentText();
1870 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1871 setValid(formatsLA, valid);
1875 void PrefFileformats::updatePrettyname()
1877 QString const newname = formatsCB->currentText();
1878 if (newname == qt_(currentFormat().prettyname()))
1881 currentFormat().setPrettyname(fromqstr(newname));
1889 void updateComboBox(LyXRC::Alternatives const & alts,
1890 string const & fmt, QComboBox * combo)
1892 LyXRC::Alternatives::const_iterator it =
1894 if (it != alts.end()) {
1895 LyXRC::CommandSet const & cmds = it->second;
1896 LyXRC::CommandSet::const_iterator sit =
1898 LyXRC::CommandSet::const_iterator const sen =
1900 for (; sit != sen; ++sit) {
1901 QString const qcmd = toqstr(*sit);
1902 combo->addItem(qcmd, qcmd);
1909 void PrefFileformats::updateViewers()
1911 Format const f = currentFormat();
1912 viewerCO->blockSignals(true);
1914 viewerCO->addItem(qt_("None"), QString());
1915 updateComboBox(viewer_alternatives, f.name(), viewerCO);
1916 viewerCO->addItem(qt_("Custom"), QString("custom viewer"));
1917 viewerCO->blockSignals(false);
1919 int pos = viewerCO->findData(toqstr(f.viewer()));
1922 viewerED->setEnabled(false);
1923 viewerCO->setCurrentIndex(pos);
1925 viewerED->setEnabled(true);
1926 viewerED->setText(toqstr(f.viewer()));
1927 viewerCO->setCurrentIndex(viewerCO->findData(toqstr("custom viewer")));
1932 void PrefFileformats::updateEditors()
1934 Format const f = currentFormat();
1935 editorCO->blockSignals(true);
1937 editorCO->addItem(qt_("None"), QString());
1938 updateComboBox(editor_alternatives, f.name(), editorCO);
1939 editorCO->addItem(qt_("Custom"), QString("custom editor"));
1940 editorCO->blockSignals(false);
1942 int pos = editorCO->findData(toqstr(f.editor()));
1945 editorED->setEnabled(false);
1946 editorCO->setCurrentIndex(pos);
1948 editorED->setEnabled(true);
1949 editorED->setText(toqstr(f.editor()));
1950 editorCO->setCurrentIndex(editorCO->findData(toqstr("custom editor")));
1955 void PrefFileformats::on_viewerCO_currentIndexChanged(int i)
1957 bool const custom = viewerCO->itemData(i).toString() == "custom viewer";
1958 viewerED->setEnabled(custom);
1960 currentFormat().setViewer(fromqstr(viewerCO->itemData(i).toString()));
1964 void PrefFileformats::on_editorCO_currentIndexChanged(int i)
1966 bool const custom = editorCO->itemData(i).toString() == "custom editor";
1967 editorED->setEnabled(custom);
1969 currentFormat().setEditor(fromqstr(editorCO->itemData(i).toString()));
1973 Format & PrefFileformats::currentFormat()
1975 int const i = formatsCB->currentIndex();
1976 int const nr = formatsCB->itemData(i).toInt();
1977 return form_->formats().get(nr);
1981 void PrefFileformats::on_formatNewPB_clicked()
1983 form_->formats().add("", "", "", "", "", "", Format::none);
1985 formatsCB->setCurrentIndex(0);
1986 formatsCB->setFocus(Qt::OtherFocusReason);
1990 void PrefFileformats::on_formatRemovePB_clicked()
1992 int const i = formatsCB->currentIndex();
1993 int const nr = formatsCB->itemData(i).toInt();
1994 string const current_text = form_->formats().get(nr).name();
1995 if (form_->converters().formatIsUsed(current_text)) {
1996 Alert::error(_("Format in use"),
1997 _("Cannot remove a Format used by a Converter. "
1998 "Remove the converter first."));
2002 form_->formats().erase(current_text);
2005 on_formatsCB_editTextChanged(formatsCB->currentText());
2010 /////////////////////////////////////////////////////////////////////
2014 /////////////////////////////////////////////////////////////////////
2016 PrefLanguage::PrefLanguage(GuiPreferences * form)
2017 : PrefModule(qt_(catLanguage), qt_("Language"), form)
2021 connect(rtlGB, SIGNAL(clicked()),
2022 this, SIGNAL(changed()));
2023 connect(visualCursorRB, SIGNAL(clicked()),
2024 this, SIGNAL(changed()));
2025 connect(logicalCursorRB, SIGNAL(clicked()),
2026 this, SIGNAL(changed()));
2027 connect(markForeignCB, SIGNAL(clicked()),
2028 this, SIGNAL(changed()));
2029 connect(autoBeginCB, SIGNAL(clicked()),
2030 this, SIGNAL(changed()));
2031 connect(autoEndCB, SIGNAL(clicked()),
2032 this, SIGNAL(changed()));
2033 connect(useBabelCB, SIGNAL(clicked()),
2034 this, SIGNAL(changed()));
2035 connect(globalCB, SIGNAL(clicked()),
2036 this, SIGNAL(changed()));
2037 connect(languagePackageED, SIGNAL(textChanged(QString)),
2038 this, SIGNAL(changed()));
2039 connect(startCommandED, SIGNAL(textChanged(QString)),
2040 this, SIGNAL(changed()));
2041 connect(endCommandED, SIGNAL(textChanged(QString)),
2042 this, SIGNAL(changed()));
2043 connect(uiLanguageCO, SIGNAL(activated(int)),
2044 this, SIGNAL(changed()));
2046 uiLanguageCO->clear();
2048 QAbstractItemModel * language_model = guiApp->languageModel();
2049 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
2050 language_model->sort(0);
2052 // FIXME: This is wrong, we need filter this list based on the available
2054 uiLanguageCO->blockSignals(true);
2055 uiLanguageCO->addItem(qt_("Default"), toqstr("auto"));
2056 for (int i = 0; i != language_model->rowCount(); ++i) {
2057 QModelIndex index = language_model->index(i, 0);
2058 uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
2059 index.data(Qt::UserRole).toString());
2061 uiLanguageCO->blockSignals(false);
2065 void PrefLanguage::on_uiLanguageCO_currentIndexChanged(int)
2067 QMessageBox::information(this, qt_("LyX needs to be restarted!"),
2068 qt_("The change of user interface language will be fully "
2069 "effective only after a restart."));
2073 void PrefLanguage::apply(LyXRC & rc) const
2075 // FIXME: remove rtl_support bool
2076 rc.rtl_support = rtlGB->isChecked();
2077 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
2078 rc.mark_foreign_language = markForeignCB->isChecked();
2079 rc.language_auto_begin = autoBeginCB->isChecked();
2080 rc.language_auto_end = autoEndCB->isChecked();
2081 rc.language_use_babel = useBabelCB->isChecked();
2082 rc.language_global_options = globalCB->isChecked();
2083 rc.language_package = fromqstr(languagePackageED->text());
2084 rc.language_command_begin = fromqstr(startCommandED->text());
2085 rc.language_command_end = fromqstr(endCommandED->text());
2086 rc.gui_language = fromqstr(
2087 uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString());
2091 void PrefLanguage::update(LyXRC const & rc)
2093 // FIXME: remove rtl_support bool
2094 rtlGB->setChecked(rc.rtl_support);
2095 if (rc.visual_cursor)
2096 visualCursorRB->setChecked(true);
2098 logicalCursorRB->setChecked(true);
2099 markForeignCB->setChecked(rc.mark_foreign_language);
2100 autoBeginCB->setChecked(rc.language_auto_begin);
2101 autoEndCB->setChecked(rc.language_auto_end);
2102 useBabelCB->setChecked(rc.language_use_babel);
2103 globalCB->setChecked(rc.language_global_options);
2104 languagePackageED->setText(toqstr(rc.language_package));
2105 startCommandED->setText(toqstr(rc.language_command_begin));
2106 endCommandED->setText(toqstr(rc.language_command_end));
2108 int pos = uiLanguageCO->findData(toqstr(rc.gui_language));
2109 uiLanguageCO->blockSignals(true);
2110 uiLanguageCO->setCurrentIndex(pos);
2111 uiLanguageCO->blockSignals(false);
2115 /////////////////////////////////////////////////////////////////////
2119 /////////////////////////////////////////////////////////////////////
2121 PrefPrinter::PrefPrinter(GuiPreferences * form)
2122 : PrefModule(qt_(catOutput), qt_("Printer"), form)
2126 connect(printerAdaptCB, SIGNAL(clicked()),
2127 this, SIGNAL(changed()));
2128 connect(printerCommandED, SIGNAL(textChanged(QString)),
2129 this, SIGNAL(changed()));
2130 connect(printerNameED, SIGNAL(textChanged(QString)),
2131 this, SIGNAL(changed()));
2132 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
2133 this, SIGNAL(changed()));
2134 connect(printerCopiesED, SIGNAL(textChanged(QString)),
2135 this, SIGNAL(changed()));
2136 connect(printerReverseED, SIGNAL(textChanged(QString)),
2137 this, SIGNAL(changed()));
2138 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
2139 this, SIGNAL(changed()));
2140 connect(printerExtensionED, SIGNAL(textChanged(QString)),
2141 this, SIGNAL(changed()));
2142 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
2143 this, SIGNAL(changed()));
2144 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
2145 this, SIGNAL(changed()));
2146 connect(printerEvenED, SIGNAL(textChanged(QString)),
2147 this, SIGNAL(changed()));
2148 connect(printerOddED, SIGNAL(textChanged(QString)),
2149 this, SIGNAL(changed()));
2150 connect(printerCollatedED, SIGNAL(textChanged(QString)),
2151 this, SIGNAL(changed()));
2152 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
2153 this, SIGNAL(changed()));
2154 connect(printerToFileED, SIGNAL(textChanged(QString)),
2155 this, SIGNAL(changed()));
2156 connect(printerExtraED, SIGNAL(textChanged(QString)),
2157 this, SIGNAL(changed()));
2158 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
2159 this, SIGNAL(changed()));
2160 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
2161 this, SIGNAL(changed()));
2165 void PrefPrinter::apply(LyXRC & rc) const
2167 rc.print_adapt_output = printerAdaptCB->isChecked();
2168 rc.print_command = fromqstr(printerCommandED->text());
2169 rc.printer = fromqstr(printerNameED->text());
2171 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
2172 rc.print_copies_flag = fromqstr(printerCopiesED->text());
2173 rc.print_reverse_flag = fromqstr(printerReverseED->text());
2174 rc.print_to_printer = fromqstr(printerToPrinterED->text());
2175 rc.print_file_extension = fromqstr(printerExtensionED->text());
2176 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
2177 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
2178 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
2179 rc.print_oddpage_flag = fromqstr(printerOddED->text());
2180 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
2181 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
2182 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
2183 rc.print_extra_options = fromqstr(printerExtraED->text());
2184 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
2185 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
2189 void PrefPrinter::update(LyXRC const & rc)
2191 printerAdaptCB->setChecked(rc.print_adapt_output);
2192 printerCommandED->setText(toqstr(rc.print_command));
2193 printerNameED->setText(toqstr(rc.printer));
2195 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
2196 printerCopiesED->setText(toqstr(rc.print_copies_flag));
2197 printerReverseED->setText(toqstr(rc.print_reverse_flag));
2198 printerToPrinterED->setText(toqstr(rc.print_to_printer));
2199 printerExtensionED->setText(toqstr(rc.print_file_extension));
2200 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
2201 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
2202 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
2203 printerOddED->setText(toqstr(rc.print_oddpage_flag));
2204 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
2205 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
2206 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
2207 printerExtraED->setText(toqstr(rc.print_extra_options));
2208 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
2209 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
2213 /////////////////////////////////////////////////////////////////////
2215 // PrefUserInterface
2217 /////////////////////////////////////////////////////////////////////
2219 PrefUserInterface::PrefUserInterface(GuiPreferences * form)
2220 : PrefModule(qt_(catLookAndFeel), qt_("User interface"), form)
2224 connect(autoSaveCB, SIGNAL(toggled(bool)),
2225 autoSaveSB, SLOT(setEnabled(bool)));
2226 connect(autoSaveCB, SIGNAL(toggled(bool)),
2227 TextLabel1, SLOT(setEnabled(bool)));
2228 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
2229 this, SIGNAL(changed()));
2230 #if QT_VERSION < 0x040500
2231 singleCloseTabButtonCB->setEnabled(false);
2233 connect(singleCloseTabButtonCB, SIGNAL(clicked()),
2234 this, SIGNAL(changed()));
2235 connect(uiFilePB, SIGNAL(clicked()),
2236 this, SLOT(selectUi()));
2237 connect(uiFileED, SIGNAL(textChanged(QString)),
2238 this, SIGNAL(changed()));
2239 connect(restoreCursorCB, SIGNAL(clicked()),
2240 this, SIGNAL(changed()));
2241 connect(loadSessionCB, SIGNAL(clicked()),
2242 this, SIGNAL(changed()));
2243 connect(allowGeometrySessionCB, SIGNAL(clicked()),
2244 this, SIGNAL(changed()));
2245 connect(autoSaveSB, SIGNAL(valueChanged(int)),
2246 this, SIGNAL(changed()));
2247 connect(autoSaveCB, SIGNAL(clicked()),
2248 this, SIGNAL(changed()));
2249 connect(backupCB, SIGNAL(clicked()),
2250 this, SIGNAL(changed()));
2251 connect(lastfilesSB, SIGNAL(valueChanged(int)),
2252 this, SIGNAL(changed()));
2253 connect(tooltipCB, SIGNAL(toggled(bool)),
2254 this, SIGNAL(changed()));
2255 lastfilesSB->setMaximum(maxlastfiles);
2259 void PrefUserInterface::apply(LyXRC & rc) const
2261 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
2262 rc.use_lastfilepos = restoreCursorCB->isChecked();
2263 rc.load_session = loadSessionCB->isChecked();
2264 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
2265 rc.autosave = autoSaveCB->isChecked()? autoSaveSB->value() * 60 : 0;
2266 rc.make_backup = backupCB->isChecked();
2267 rc.num_lastfiles = lastfilesSB->value();
2268 rc.use_tooltip = tooltipCB->isChecked();
2269 rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
2270 rc.single_close_tab_button = singleCloseTabButtonCB->isChecked();
2271 #if QT_VERSION < 0x040500
2272 rc.single_close_tab_button = true;
2277 void PrefUserInterface::update(LyXRC const & rc)
2279 uiFileED->setText(toqstr(external_path(rc.ui_file)));
2280 restoreCursorCB->setChecked(rc.use_lastfilepos);
2281 loadSessionCB->setChecked(rc.load_session);
2282 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
2283 // convert to minutes
2284 bool autosave = rc.autosave > 0;
2285 int mins = rc.autosave / 60;
2288 autoSaveSB->setValue(mins);
2289 autoSaveCB->setChecked(autosave);
2290 autoSaveSB->setEnabled(autosave);
2291 backupCB->setChecked(rc.make_backup);
2292 lastfilesSB->setValue(rc.num_lastfiles);
2293 tooltipCB->setChecked(rc.use_tooltip);
2294 openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
2295 singleCloseTabButtonCB->setChecked(rc.single_close_tab_button);
2299 void PrefUserInterface::selectUi()
2301 QString file = form_->browseUI(internalPath(uiFileED->text()));
2302 if (!file.isEmpty())
2303 uiFileED->setText(file);
2307 void PrefUserInterface::on_clearSessionPB_clicked()
2309 guiApp->clearSession();
2314 /////////////////////////////////////////////////////////////////////
2318 /////////////////////////////////////////////////////////////////////
2320 PrefEdit::PrefEdit(GuiPreferences * form)
2321 : PrefModule(qt_(catEditing), qt_("Control"), form)
2325 connect(cursorFollowsCB, SIGNAL(clicked()),
2326 this, SIGNAL(changed()));
2327 connect(scrollBelowCB, SIGNAL(clicked()),
2328 this, SIGNAL(changed()));
2329 connect(sortEnvironmentsCB, SIGNAL(clicked()),
2330 this, SIGNAL(changed()));
2331 connect(groupEnvironmentsCB, SIGNAL(clicked()),
2332 this, SIGNAL(changed()));
2333 connect(macroEditStyleCO, SIGNAL(activated(int)),
2334 this, SIGNAL(changed()));
2335 connect(fullscreenLimitGB, SIGNAL(clicked()),
2336 this, SIGNAL(changed()));
2337 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
2338 this, SIGNAL(changed()));
2339 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
2340 this, SIGNAL(changed()));
2341 connect(toggleMenubarCB, SIGNAL(toggled(bool)),
2342 this, SIGNAL(changed()));
2343 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
2344 this, SIGNAL(changed()));
2345 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
2346 this, SIGNAL(changed()));
2350 void PrefEdit::apply(LyXRC & rc) const
2352 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
2353 rc.scroll_below_document = scrollBelowCB->isChecked();
2354 rc.sort_layouts = sortEnvironmentsCB->isChecked();
2355 rc.group_layouts = groupEnvironmentsCB->isChecked();
2356 switch (macroEditStyleCO->currentIndex()) {
2357 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
2358 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
2359 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
2361 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
2362 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
2363 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
2364 rc.full_screen_menubar = toggleMenubarCB->isChecked();
2365 rc.full_screen_width = fullscreenWidthSB->value();
2366 rc.full_screen_limit = fullscreenLimitGB->isChecked();
2370 void PrefEdit::update(LyXRC const & rc)
2372 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
2373 scrollBelowCB->setChecked(rc.scroll_below_document);
2374 sortEnvironmentsCB->setChecked(rc.sort_layouts);
2375 groupEnvironmentsCB->setChecked(rc.group_layouts);
2376 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
2377 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
2378 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
2379 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
2380 toggleMenubarCB->setChecked(rc.full_screen_menubar);
2381 fullscreenWidthSB->setValue(rc.full_screen_width);
2382 fullscreenLimitGB->setChecked(rc.full_screen_limit);
2386 /////////////////////////////////////////////////////////////////////
2390 /////////////////////////////////////////////////////////////////////
2393 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
2395 Ui::shortcutUi::setupUi(this);
2396 QDialog::setModal(true);
2400 PrefShortcuts::PrefShortcuts(GuiPreferences * form)
2401 : PrefModule(qt_(catEditing), qt_("Shortcuts"), form)
2405 shortcutsTW->setColumnCount(2);
2406 shortcutsTW->headerItem()->setText(0, qt_("Function"));
2407 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
2408 shortcutsTW->setSortingEnabled(true);
2409 // Multi-selection can be annoying.
2410 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
2412 connect(bindFilePB, SIGNAL(clicked()),
2413 this, SLOT(selectBind()));
2414 connect(bindFileED, SIGNAL(textChanged(QString)),
2415 this, SIGNAL(changed()));
2416 connect(removePB, SIGNAL(clicked()),
2417 this, SIGNAL(changed()));
2419 shortcut_ = new GuiShortcutDialog(this);
2420 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
2421 shortcut_bc_.setOK(shortcut_->okPB);
2422 shortcut_bc_.setCancel(shortcut_->cancelPB);
2424 connect(shortcut_->okPB, SIGNAL(clicked()),
2425 shortcut_, SLOT(accept()));
2426 connect(shortcut_->okPB, SIGNAL(clicked()),
2427 this, SIGNAL(changed()));
2428 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2429 shortcut_, SLOT(reject()));
2430 connect(shortcut_->clearPB, SIGNAL(clicked()),
2431 this, SLOT(shortcutClearPressed()));
2432 connect(shortcut_->removePB, SIGNAL(clicked()),
2433 this, SLOT(shortcutRemovePressed()));
2434 connect(shortcut_->okPB, SIGNAL(clicked()),
2435 this, SLOT(shortcutOkPressed()));
2436 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2437 this, SLOT(shortcutCancelPressed()));
2441 void PrefShortcuts::apply(LyXRC & rc) const
2443 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
2444 // write user_bind and user_unbind to .lyx/bind/user.bind
2445 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
2446 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
2447 lyxerr << "LyX could not create the user bind directory '"
2448 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2451 if (!bind_dir.isDirWritable()) {
2452 lyxerr << "LyX could not write to the user bind directory '"
2453 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2456 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
2457 user_unbind_.write(user_bind_file.toFilesystemEncoding(), false, true);
2458 user_bind_.write(user_bind_file.toFilesystemEncoding(), true, false);
2459 // immediately apply the keybindings. Why this is not done before?
2460 // The good thing is that the menus are updated automatically.
2461 theTopLevelKeymap().clear();
2462 theTopLevelKeymap().read("site");
2463 theTopLevelKeymap().read(rc.bind_file, 0, KeyMap::Fallback);
2464 theTopLevelKeymap().read("user", 0, KeyMap::MissingOK);
2468 void PrefShortcuts::update(LyXRC const & rc)
2470 bindFileED->setText(toqstr(external_path(rc.bind_file)));
2472 system_bind_.clear();
2474 user_unbind_.clear();
2475 system_bind_.read("site");
2476 system_bind_.read(rc.bind_file);
2477 // \unbind in user.bind is added to user_unbind_
2478 user_bind_.read("user", &user_unbind_, KeyMap::MissingOK);
2479 updateShortcutsTW();
2483 void PrefShortcuts::updateShortcutsTW()
2485 shortcutsTW->clear();
2487 editItem_ = new QTreeWidgetItem(shortcutsTW);
2488 editItem_->setText(0, qt_("Cursor, Mouse and Editing functions"));
2489 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2491 mathItem_ = new QTreeWidgetItem(shortcutsTW);
2492 mathItem_->setText(0, qt_("Mathematical Symbols"));
2493 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2495 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2496 bufferItem_->setText(0, qt_("Document and Window"));
2497 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2499 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2500 layoutItem_->setText(0, qt_("Font, Layouts and Textclasses"));
2501 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2503 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2504 systemItem_->setText(0, qt_("System and Miscellaneous"));
2505 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2507 // listBindings(unbound=true) lists all bound and unbound lfuns
2508 // Items in this list is tagged by its source.
2509 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2511 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2513 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2514 KeyMap::UserUnbind);
2515 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2516 user_bindinglist.end());
2517 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2518 user_unbindinglist.end());
2520 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2521 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2522 for (; it != it_end; ++it)
2523 insertShortcutItem(it->request, it->sequence, KeyMap::ItemType(it->tag));
2525 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2526 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2527 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2528 modifyPB->setEnabled(!items.isEmpty());
2530 shortcutsTW->resizeColumnToContents(0);
2534 void PrefShortcuts::setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag)
2536 item->setData(0, Qt::UserRole, QVariant(tag));
2540 case KeyMap::System:
2542 case KeyMap::UserBind:
2545 case KeyMap::UserUnbind:
2546 font.setStrikeOut(true);
2548 // this item is not displayed now.
2549 case KeyMap::UserExtraUnbind:
2550 font.setStrikeOut(true);
2554 item->setFont(1, font);
2558 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2559 KeySequence const & seq, KeyMap::ItemType tag)
2561 FuncCode action = lfun.action;
2562 string const action_name = lyxaction.getActionName(action);
2563 QString const lfun_name = toqstr(from_utf8(action_name)
2564 + ' ' + lfun.argument());
2565 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2566 KeyMap::ItemType item_tag = tag;
2568 QTreeWidgetItem * newItem = 0;
2569 // for unbind items, try to find an existing item in the system bind list
2570 if (tag == KeyMap::UserUnbind) {
2571 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2572 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2573 for (int i = 0; i < items.size(); ++i) {
2574 if (items[i]->text(1) == shortcut)
2578 // if not found, this unbind item is KeyMap::UserExtraUnbind
2579 // Such an item is not displayed to avoid confusion (what is
2580 // unmatched removed?).
2582 item_tag = KeyMap::UserExtraUnbind;
2587 switch(lyxaction.getActionType(action)) {
2588 case LyXAction::Hidden:
2590 case LyXAction::Edit:
2591 newItem = new QTreeWidgetItem(editItem_);
2593 case LyXAction::Math:
2594 newItem = new QTreeWidgetItem(mathItem_);
2596 case LyXAction::Buffer:
2597 newItem = new QTreeWidgetItem(bufferItem_);
2599 case LyXAction::Layout:
2600 newItem = new QTreeWidgetItem(layoutItem_);
2602 case LyXAction::System:
2603 newItem = new QTreeWidgetItem(systemItem_);
2606 // this should not happen
2607 newItem = new QTreeWidgetItem(shortcutsTW);
2611 newItem->setText(0, lfun_name);
2612 newItem->setText(1, shortcut);
2613 // record BindFile representation to recover KeySequence when needed.
2614 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2615 setItemType(newItem, item_tag);
2620 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2622 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2623 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2624 modifyPB->setEnabled(!items.isEmpty());
2625 if (items.isEmpty())
2628 KeyMap::ItemType tag =
2629 static_cast<KeyMap::ItemType>(items[0]->data(0, Qt::UserRole).toInt());
2630 if (tag == KeyMap::UserUnbind)
2631 removePB->setText(qt_("Res&tore"));
2633 removePB->setText(qt_("Remo&ve"));
2637 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2643 void PrefShortcuts::modifyShortcut()
2645 QTreeWidgetItem * item = shortcutsTW->currentItem();
2646 if (item->flags() & Qt::ItemIsSelectable) {
2647 shortcut_->lfunLE->setText(item->text(0));
2648 save_lfun_ = item->text(0);
2649 shortcut_->shortcutWG->setText(item->text(1));
2651 seq.parse(fromqstr(item->data(1, Qt::UserRole).toString()));
2652 shortcut_->shortcutWG->setKeySequence(seq);
2653 shortcut_->shortcutWG->setFocus();
2659 void PrefShortcuts::removeShortcut()
2661 // it seems that only one item can be selected, but I am
2662 // removing all selected items anyway.
2663 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2664 for (int i = 0; i < items.size(); ++i) {
2665 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2666 string lfun = fromqstr(items[i]->text(0));
2667 FuncRequest func = lyxaction.lookupFunc(lfun);
2668 KeyMap::ItemType tag =
2669 static_cast<KeyMap::ItemType>(items[i]->data(0, Qt::UserRole).toInt());
2672 case KeyMap::System: {
2673 // for system bind, we do not touch the item
2674 // but add an user unbind item
2675 user_unbind_.bind(shortcut, func);
2676 setItemType(items[i], KeyMap::UserUnbind);
2677 removePB->setText(qt_("Res&tore"));
2680 case KeyMap::UserBind: {
2681 // for user_bind, we remove this bind
2682 QTreeWidgetItem * parent = items[i]->parent();
2683 int itemIdx = parent->indexOfChild(items[i]);
2684 parent->takeChild(itemIdx);
2686 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2688 shortcutsTW->scrollToItem(parent);
2689 user_bind_.unbind(shortcut, func);
2692 case KeyMap::UserUnbind: {
2693 // for user_unbind, we remove the unbind, and the item
2694 // become KeyMap::System again.
2695 user_unbind_.unbind(shortcut, func);
2696 setItemType(items[i], KeyMap::System);
2697 removePB->setText(qt_("Remo&ve"));
2700 case KeyMap::UserExtraUnbind: {
2701 // for user unbind that is not in system bind file,
2702 // remove this unbind file
2703 QTreeWidgetItem * parent = items[i]->parent();
2704 parent->takeChild(parent->indexOfChild(items[i]));
2705 user_unbind_.unbind(shortcut, func);
2712 void PrefShortcuts::selectBind()
2714 QString file = form_->browsebind(internalPath(bindFileED->text()));
2715 if (!file.isEmpty()) {
2716 bindFileED->setText(file);
2717 system_bind_ = KeyMap();
2718 system_bind_.read(fromqstr(file));
2719 updateShortcutsTW();
2724 void PrefShortcuts::on_modifyPB_pressed()
2730 void PrefShortcuts::on_newPB_pressed()
2732 shortcut_->lfunLE->clear();
2733 shortcut_->shortcutWG->reset();
2734 save_lfun_ = QString();
2739 void PrefShortcuts::on_removePB_pressed()
2745 void PrefShortcuts::on_searchLE_textEdited()
2747 if (searchLE->text().isEmpty()) {
2748 // show all hidden items
2749 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2751 shortcutsTW->setItemHidden(*it++, false);
2754 // search both columns
2755 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2756 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2757 matched += shortcutsTW->findItems(searchLE->text(),
2758 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2760 // hide everyone (to avoid searching in matched QList repeatedly
2761 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2763 shortcutsTW->setItemHidden(*it++, true);
2764 // show matched items
2765 for (int i = 0; i < matched.size(); ++i) {
2766 shortcutsTW->setItemHidden(matched[i], false);
2767 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2772 docstring makeCmdString(FuncRequest const & f)
2774 docstring actionStr = from_ascii(lyxaction.getActionName(f.action));
2775 if (!f.argument().empty())
2776 actionStr += " " + f.argument();
2781 void PrefShortcuts::shortcutOkPressed()
2783 QString const new_lfun = shortcut_->lfunLE->text();
2784 FuncRequest func = lyxaction.lookupFunc(fromqstr(new_lfun));
2786 if (func.action == LFUN_UNKNOWN_ACTION) {
2787 Alert::error(_("Failed to create shortcut"),
2788 _("Unknown or invalid LyX function"));
2792 KeySequence k = shortcut_->shortcutWG->getKeySequence();
2793 if (k.length() == 0) {
2794 Alert::error(_("Failed to create shortcut"),
2795 _("Invalid or empty key sequence"));
2799 // check to see if there's been any change
2800 FuncRequest oldBinding = system_bind_.getBinding(k);
2801 if (oldBinding.action == LFUN_UNKNOWN_ACTION)
2802 oldBinding = user_bind_.getBinding(k);
2803 if (oldBinding == func) {
2804 docstring const actionStr = makeCmdString(func);
2805 Alert::error(_("Failed to create shortcut"),
2806 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s"),
2807 k.print(KeySequence::ForGui), actionStr));
2811 // make sure this key isn't already bound---and, if so, not unbound
2812 FuncCode const unbind = user_unbind_.getBinding(k).action;
2813 if (oldBinding.action != LFUN_UNKNOWN_ACTION && unbind == LFUN_UNKNOWN_ACTION)
2815 // FIXME Perhaps we should offer to over-write the old shortcut?
2816 // If so, we'll need to remove it from our list, etc.
2817 docstring const actionStr = makeCmdString(oldBinding);
2818 Alert::error(_("Failed to create shortcut"),
2819 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s\n"
2820 "You need to remove that binding before creating a new one."),
2821 k.print(KeySequence::ForGui), actionStr));
2825 if (!save_lfun_.isEmpty() && new_lfun == save_lfun_)
2826 // real modification of the lfun's shortcut,
2827 // so remove the previous one
2830 QTreeWidgetItem * item = insertShortcutItem(func, k, KeyMap::UserBind);
2832 user_bind_.bind(&k, func);
2833 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2834 shortcutsTW->setItemExpanded(item->parent(), true);
2835 shortcutsTW->scrollToItem(item);
2837 Alert::error(_("Failed to create shortcut"),
2838 _("Can not insert shortcut to the list"));
2844 void PrefShortcuts::shortcutCancelPressed()
2846 shortcut_->shortcutWG->reset();
2850 void PrefShortcuts::shortcutClearPressed()
2852 shortcut_->shortcutWG->reset();
2856 void PrefShortcuts::shortcutRemovePressed()
2858 shortcut_->shortcutWG->removeFromSequence();
2862 /////////////////////////////////////////////////////////////////////
2866 /////////////////////////////////////////////////////////////////////
2868 PrefIdentity::PrefIdentity(GuiPreferences * form)
2869 : PrefModule(QString(), qt_("Identity"), form)
2873 connect(nameED, SIGNAL(textChanged(QString)),
2874 this, SIGNAL(changed()));
2875 connect(emailED, SIGNAL(textChanged(QString)),
2876 this, SIGNAL(changed()));
2880 void PrefIdentity::apply(LyXRC & rc) const
2882 rc.user_name = fromqstr(nameED->text());
2883 rc.user_email = fromqstr(emailED->text());
2887 void PrefIdentity::update(LyXRC const & rc)
2889 nameED->setText(toqstr(rc.user_name));
2890 emailED->setText(toqstr(rc.user_email));
2895 /////////////////////////////////////////////////////////////////////
2899 /////////////////////////////////////////////////////////////////////
2901 GuiPreferences::GuiPreferences(GuiView & lv)
2902 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2906 QDialog::setModal(false);
2908 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2909 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2910 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2911 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2913 addModule(new PrefUserInterface(this));
2914 addModule(new PrefEdit(this));
2915 addModule(new PrefShortcuts(this));
2916 addModule(new PrefScreenFonts(this));
2917 addModule(new PrefColors(this));
2918 addModule(new PrefDisplay(this));
2919 addModule(new PrefInput(this));
2920 addModule(new PrefCompletion(this));
2922 addModule(new PrefPaths(this));
2924 addModule(new PrefIdentity(this));
2926 addModule(new PrefLanguage(this));
2927 addModule(new PrefSpellchecker(this));
2929 addModule(new PrefPrinter(this));
2930 PrefDate * dateFormat = new PrefDate(this);
2931 addModule(dateFormat);
2932 addModule(new PrefPlaintext(this));
2933 addModule(new PrefLatex(this));
2935 PrefConverters * converters = new PrefConverters(this);
2936 PrefFileformats * formats = new PrefFileformats(this);
2937 connect(formats, SIGNAL(formatsChanged()),
2938 converters, SLOT(updateGui()));
2939 addModule(converters);
2942 prefsPS->setCurrentPanel(qt_("User interface"));
2943 // FIXME: hack to work around resizing bug in Qt >= 4.2
2944 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2945 #if QT_VERSION >= 0x040200
2946 prefsPS->updateGeometry();
2949 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2951 bc().setApply(applyPB);
2952 bc().setCancel(closePB);
2953 bc().setRestore(restorePB);
2955 // initialize the strftime validator
2956 bc().addCheckedLineEdit(dateFormat->DateED);
2960 void GuiPreferences::addModule(PrefModule * module)
2962 LASSERT(module, return);
2963 if (module->category().isEmpty())
2964 prefsPS->addPanel(module, module->title());
2966 prefsPS->addPanel(module, module->title(), module->category());
2967 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2968 modules_.push_back(module);
2972 void GuiPreferences::change_adaptor()
2978 void GuiPreferences::apply(LyXRC & rc) const
2980 size_t end = modules_.size();
2981 for (size_t i = 0; i != end; ++i)
2982 modules_[i]->apply(rc);
2986 void GuiPreferences::updateRc(LyXRC const & rc)
2988 size_t const end = modules_.size();
2989 for (size_t i = 0; i != end; ++i)
2990 modules_[i]->update(rc);
2994 void GuiPreferences::applyView()
2999 bool GuiPreferences::initialiseParams(string const &)
3002 formats_ = lyx::formats;
3003 converters_ = theConverters();
3004 converters_.update(formats_);
3005 movers_ = theMovers();
3007 update_screen_font_ = false;
3010 // Make sure that the bc is in the INITIAL state
3011 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3018 void GuiPreferences::dispatchParams()
3021 rc_.write(ss, true);
3022 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
3023 // FIXME: these need lfuns
3025 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
3027 lyx::formats = formats_;
3029 theConverters() = converters_;
3030 theConverters().update(lyx::formats);
3031 theConverters().buildGraph();
3033 theMovers() = movers_;
3035 vector<string>::const_iterator it = colors_.begin();
3036 vector<string>::const_iterator const end = colors_.end();
3037 for (; it != end; ++it)
3038 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
3041 if (update_screen_font_) {
3042 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
3043 update_screen_font_ = false;
3046 // The Save button has been pressed
3048 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
3052 void GuiPreferences::setColor(ColorCode col, QString const & hex)
3054 colors_.push_back(lcolor.getLyXName(col) + ' ' + fromqstr(hex));
3058 void GuiPreferences::updateScreenFonts()
3060 update_screen_font_ = true;
3064 QString GuiPreferences::browsebind(QString const & file) const
3066 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
3067 QStringList(qt_("LyX bind files (*.bind)")));
3071 QString GuiPreferences::browseUI(QString const & file) const
3073 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
3074 QStringList(qt_("LyX UI files (*.ui)")));
3078 QString GuiPreferences::browsekbmap(QString const & file) const
3080 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
3081 QStringList(qt_("LyX keyboard maps (*.kmap)")));
3085 QString GuiPreferences::browse(QString const & file,
3086 QString const & title) const
3088 return browseFile(file, title, QStringList(), true);
3092 // We support less paper sizes than the document dialog
3093 // Therefore this adjustment is needed.
3094 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
3098 return PAPER_DEFAULT;
3100 return PAPER_USLETTER;
3102 return PAPER_USLEGAL;
3104 return PAPER_USEXECUTIVE;
3114 // should not happen
3115 return PAPER_DEFAULT;
3120 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
3122 switch (papersize) {
3125 case PAPER_USLETTER:
3129 case PAPER_USEXECUTIVE:
3140 // should not happen
3146 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
3149 } // namespace frontend
3152 #include "moc_GuiPrefs.cpp"