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(latexEncodingED, SIGNAL(textChanged(QString)),
594 this, SIGNAL(changed()));
595 connect(latexChecktexED, SIGNAL(textChanged(QString)),
596 this, SIGNAL(changed()));
597 connect(latexBibtexCO, SIGNAL(activated(int)),
598 this, SIGNAL(changed()));
599 connect(latexBibtexED, SIGNAL(textChanged(QString)),
600 this, SIGNAL(changed()));
601 connect(latexJBibtexED, SIGNAL(textChanged(QString)),
602 this, SIGNAL(changed()));
603 connect(latexIndexCO, SIGNAL(activated(int)),
604 this, SIGNAL(changed()));
605 connect(latexIndexED, SIGNAL(textChanged(QString)),
606 this, SIGNAL(changed()));
607 connect(latexJIndexED, SIGNAL(textChanged(QString)),
608 this, SIGNAL(changed()));
609 connect(latexAutoresetCB, SIGNAL(clicked()),
610 this, SIGNAL(changed()));
611 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
612 this, SIGNAL(changed()));
613 connect(latexPaperSizeCO, SIGNAL(activated(int)),
614 this, SIGNAL(changed()));
616 #if defined(__CYGWIN__) || defined(_WIN32)
617 pathCB->setVisible(true);
618 connect(pathCB, SIGNAL(clicked()),
619 this, SIGNAL(changed()));
621 pathCB->setVisible(false);
626 void PrefLatex::on_latexBibtexCO_activated(int n)
628 QString const bibtex = latexBibtexCO->itemData(n).toString();
629 if (bibtex.isEmpty()) {
630 latexBibtexED->clear();
631 latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
634 for (LyXRC::CommandSet::const_iterator it = bibtex_alternatives.begin();
635 it != bibtex_alternatives.end(); ++it) {
636 QString const bib = toqstr(*it);
637 int ind = bib.indexOf(" ");
638 QString sel_command = bib.left(ind);
639 QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
640 if (bibtex == sel_command) {
642 latexBibtexED->clear();
644 latexBibtexED->setText(sel_options.trimmed());
647 latexBibtexOptionsLA->setText(qt_("&Options:"));
651 void PrefLatex::on_latexIndexCO_activated(int n)
653 QString const index = latexIndexCO->itemData(n).toString();
654 if (index.isEmpty()) {
655 latexIndexED->clear();
656 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
659 for (LyXRC::CommandSet::const_iterator it = index_alternatives.begin();
660 it != index_alternatives.end(); ++it) {
661 QString const idx = toqstr(*it);
662 int ind = idx.indexOf(" ");
663 QString sel_command = idx.left(ind);
664 QString sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
665 if (index == sel_command) {
667 latexIndexED->clear();
669 latexIndexED->setText(sel_options.trimmed());
672 latexIndexOptionsLA->setText(qt_("Op&tions:"));
676 void PrefLatex::apply(LyXRC & rc) const
678 // If bibtex is not empty, bibopt contains the options, otherwise
679 // it is a customized bibtex command with options.
680 QString const bibtex = latexBibtexCO->itemData(
681 latexBibtexCO->currentIndex()).toString();
682 QString const bibopt = latexBibtexED->text();
683 if (bibtex.isEmpty())
684 rc.bibtex_command = fromqstr(bibopt);
685 else if (bibopt.isEmpty())
686 rc.bibtex_command = fromqstr(bibtex);
688 rc.bibtex_command = fromqstr(bibtex) + " " + fromqstr(bibopt);
690 // If index is not empty, idxopt contains the options, otherwise
691 // it is a customized index command with options.
692 QString const index = latexIndexCO->itemData(
693 latexIndexCO->currentIndex()).toString();
694 QString const idxopt = latexIndexED->text();
696 rc.index_command = fromqstr(idxopt);
697 else if (idxopt.isEmpty())
698 rc.index_command = fromqstr(index);
700 rc.index_command = fromqstr(index) + " " + fromqstr(idxopt);
702 rc.fontenc = fromqstr(latexEncodingED->text());
703 rc.chktex_command = fromqstr(latexChecktexED->text());
704 rc.jbibtex_command = fromqstr(latexJBibtexED->text());
705 rc.jindex_command = fromqstr(latexJIndexED->text());
706 rc.nomencl_command = fromqstr(latexNomenclED->text());
707 rc.auto_reset_options = latexAutoresetCB->isChecked();
708 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
709 rc.default_papersize =
710 form_->toPaperSize(latexPaperSizeCO->currentIndex());
711 #if defined(__CYGWIN__) || defined(_WIN32)
712 rc.windows_style_tex_paths = pathCB->isChecked();
717 void PrefLatex::update(LyXRC const & rc)
719 latexBibtexCO->clear();
721 latexBibtexCO->addItem(qt_("Custom"), QString());
722 for (LyXRC::CommandSet::const_iterator it = rc.bibtex_alternatives.begin();
723 it != rc.bibtex_alternatives.end(); ++it) {
724 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
725 latexBibtexCO->addItem(command, command);
728 bibtex_alternatives = rc.bibtex_alternatives;
730 QString const bib = toqstr(rc.bibtex_command);
731 int ind = bib.indexOf(" ");
732 QString sel_command = bib.left(ind);
733 QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
735 int pos = latexBibtexCO->findData(sel_command);
737 latexBibtexCO->setCurrentIndex(pos);
738 latexBibtexED->setText(sel_options.trimmed());
739 latexBibtexOptionsLA->setText(qt_("&Options:"));
741 latexBibtexED->setText(toqstr(rc.bibtex_command));
742 latexBibtexCO->setCurrentIndex(0);
743 latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
746 latexIndexCO->clear();
748 latexIndexCO->addItem(qt_("Custom"), QString());
749 for (LyXRC::CommandSet::const_iterator it = rc.index_alternatives.begin();
750 it != rc.index_alternatives.end(); ++it) {
751 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
752 latexIndexCO->addItem(command, command);
755 index_alternatives = rc.index_alternatives;
757 QString const idx = toqstr(rc.index_command);
758 ind = idx.indexOf(" ");
759 sel_command = idx.left(ind);
760 sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
762 pos = latexIndexCO->findData(sel_command);
764 latexIndexCO->setCurrentIndex(pos);
765 latexIndexED->setText(sel_options.trimmed());
766 latexIndexOptionsLA->setText(qt_("Op&tions:"));
768 latexIndexED->setText(toqstr(rc.index_command));
769 latexIndexCO->setCurrentIndex(0);
770 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
773 latexEncodingED->setText(toqstr(rc.fontenc));
774 latexChecktexED->setText(toqstr(rc.chktex_command));
775 latexJBibtexED->setText(toqstr(rc.jbibtex_command));
776 latexJIndexED->setText(toqstr(rc.jindex_command));
777 latexNomenclED->setText(toqstr(rc.nomencl_command));
778 latexAutoresetCB->setChecked(rc.auto_reset_options);
779 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
780 latexPaperSizeCO->setCurrentIndex(
781 form_->fromPaperSize(rc.default_papersize));
782 #if defined(__CYGWIN__) || defined(_WIN32)
783 pathCB->setChecked(rc.windows_style_tex_paths);
788 /////////////////////////////////////////////////////////////////////
792 /////////////////////////////////////////////////////////////////////
794 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form)
795 : PrefModule(qt_(catLookAndFeel), qt_("Screen fonts"), form)
799 connect(screenRomanCO, SIGNAL(activated(QString)),
800 this, SLOT(selectRoman(QString)));
801 connect(screenSansCO, SIGNAL(activated(QString)),
802 this, SLOT(selectSans(QString)));
803 connect(screenTypewriterCO, SIGNAL(activated(QString)),
804 this, SLOT(selectTypewriter(QString)));
806 QFontDatabase fontdb;
807 QStringList families(fontdb.families());
808 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
809 screenRomanCO->addItem(*it);
810 screenSansCO->addItem(*it);
811 screenTypewriterCO->addItem(*it);
813 connect(screenRomanCO, SIGNAL(activated(QString)),
814 this, SIGNAL(changed()));
815 connect(screenSansCO, SIGNAL(activated(QString)),
816 this, SIGNAL(changed()));
817 connect(screenTypewriterCO, SIGNAL(activated(QString)),
818 this, SIGNAL(changed()));
819 connect(screenZoomSB, SIGNAL(valueChanged(int)),
820 this, SIGNAL(changed()));
821 connect(screenDpiSB, SIGNAL(valueChanged(int)),
822 this, SIGNAL(changed()));
823 connect(screenTinyED, SIGNAL(textChanged(QString)),
824 this, SIGNAL(changed()));
825 connect(screenSmallestED, SIGNAL(textChanged(QString)),
826 this, SIGNAL(changed()));
827 connect(screenSmallerED, SIGNAL(textChanged(QString)),
828 this, SIGNAL(changed()));
829 connect(screenSmallED, SIGNAL(textChanged(QString)),
830 this, SIGNAL(changed()));
831 connect(screenNormalED, SIGNAL(textChanged(QString)),
832 this, SIGNAL(changed()));
833 connect(screenLargeED, SIGNAL(textChanged(QString)),
834 this, SIGNAL(changed()));
835 connect(screenLargerED, SIGNAL(textChanged(QString)),
836 this, SIGNAL(changed()));
837 connect(screenLargestED, SIGNAL(textChanged(QString)),
838 this, SIGNAL(changed()));
839 connect(screenHugeED, SIGNAL(textChanged(QString)),
840 this, SIGNAL(changed()));
841 connect(screenHugerED, SIGNAL(textChanged(QString)),
842 this, SIGNAL(changed()));
843 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
844 this, SIGNAL(changed()));
846 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
847 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
848 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
849 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
850 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
851 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
852 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
853 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
854 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
855 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
859 void PrefScreenFonts::apply(LyXRC & rc) const
861 LyXRC const oldrc = rc;
863 parseFontName(screenRomanCO->currentText(),
864 rc.roman_font_name, rc.roman_font_foundry);
865 parseFontName(screenSansCO->currentText(),
866 rc.sans_font_name, rc.sans_font_foundry);
867 parseFontName(screenTypewriterCO->currentText(),
868 rc.typewriter_font_name, rc.typewriter_font_foundry);
870 rc.zoom = screenZoomSB->value();
871 rc.dpi = screenDpiSB->value();
872 rc.font_sizes[FONT_SIZE_TINY] = widgetToDoubleStr(screenTinyED);
873 rc.font_sizes[FONT_SIZE_SCRIPT] = widgetToDoubleStr(screenSmallestED);
874 rc.font_sizes[FONT_SIZE_FOOTNOTE] = widgetToDoubleStr(screenSmallerED);
875 rc.font_sizes[FONT_SIZE_SMALL] = widgetToDoubleStr(screenSmallED);
876 rc.font_sizes[FONT_SIZE_NORMAL] = widgetToDoubleStr(screenNormalED);
877 rc.font_sizes[FONT_SIZE_LARGE] = widgetToDoubleStr(screenLargeED);
878 rc.font_sizes[FONT_SIZE_LARGER] = widgetToDoubleStr(screenLargerED);
879 rc.font_sizes[FONT_SIZE_LARGEST] = widgetToDoubleStr(screenLargestED);
880 rc.font_sizes[FONT_SIZE_HUGE] = widgetToDoubleStr(screenHugeED);
881 rc.font_sizes[FONT_SIZE_HUGER] = widgetToDoubleStr(screenHugerED);
882 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
884 if (rc.font_sizes != oldrc.font_sizes
885 || rc.roman_font_name != oldrc.roman_font_name
886 || rc.sans_font_name != oldrc.sans_font_name
887 || rc.typewriter_font_name != oldrc.typewriter_font_name
888 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
889 // The global QPixmapCache is used in GuiPainter to cache text
890 // painting so we must reset it in case any of the above
891 // parameter is changed.
892 QPixmapCache::clear();
893 guiApp->fontLoader().update();
894 form_->updateScreenFonts();
899 void PrefScreenFonts::update(LyXRC const & rc)
901 setComboxFont(screenRomanCO, rc.roman_font_name,
902 rc.roman_font_foundry);
903 setComboxFont(screenSansCO, rc.sans_font_name,
904 rc.sans_font_foundry);
905 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
906 rc.typewriter_font_foundry);
908 selectRoman(screenRomanCO->currentText());
909 selectSans(screenSansCO->currentText());
910 selectTypewriter(screenTypewriterCO->currentText());
912 screenZoomSB->setValue(rc.zoom);
913 screenDpiSB->setValue(rc.dpi);
914 doubleToWidget(screenTinyED, rc.font_sizes[FONT_SIZE_TINY]);
915 doubleToWidget(screenSmallestED, rc.font_sizes[FONT_SIZE_SCRIPT]);
916 doubleToWidget(screenSmallerED, rc.font_sizes[FONT_SIZE_FOOTNOTE]);
917 doubleToWidget(screenSmallED, rc.font_sizes[FONT_SIZE_SMALL]);
918 doubleToWidget(screenNormalED, rc.font_sizes[FONT_SIZE_NORMAL]);
919 doubleToWidget(screenLargeED, rc.font_sizes[FONT_SIZE_LARGE]);
920 doubleToWidget(screenLargerED, rc.font_sizes[FONT_SIZE_LARGER]);
921 doubleToWidget(screenLargestED, rc.font_sizes[FONT_SIZE_LARGEST]);
922 doubleToWidget(screenHugeED, rc.font_sizes[FONT_SIZE_HUGE]);
923 doubleToWidget(screenHugerED, rc.font_sizes[FONT_SIZE_HUGER]);
925 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
926 #if defined(Q_WS_X11)
927 pixmapCacheCB->setEnabled(false);
933 void PrefScreenFonts::selectRoman(const QString & name)
935 screenRomanFE->set(QFont(name), name);
939 void PrefScreenFonts::selectSans(const QString & name)
941 screenSansFE->set(QFont(name), name);
945 void PrefScreenFonts::selectTypewriter(const QString & name)
947 screenTypewriterFE->set(QFont(name), name);
951 /////////////////////////////////////////////////////////////////////
955 /////////////////////////////////////////////////////////////////////
961 bool operator()(ColorCode lhs, ColorCode rhs) const {
963 compare_no_case(lcolor.getGUIName(lhs), lcolor.getGUIName(rhs)) < 0;
969 PrefColors::PrefColors(GuiPreferences * form)
970 : PrefModule(qt_(catLookAndFeel), qt_("Colors"), form)
974 // FIXME: all of this initialization should be put into the controller.
975 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
976 // for some discussion of why that is not trivial.
977 QPixmap icon(32, 32);
978 for (int i = 0; i < Color_ignore; ++i) {
979 ColorCode lc = static_cast<ColorCode>(i);
987 || lc == Color_magenta
988 || lc == Color_yellow
989 || lc == Color_inherit
990 || lc == Color_ignore) continue;
992 lcolors_.push_back(lc);
994 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
995 vector<ColorCode>::const_iterator cit = lcolors_.begin();
996 vector<ColorCode>::const_iterator const end = lcolors_.end();
997 for (; cit != end; ++cit) {
998 (void) new QListWidgetItem(QIcon(icon),
999 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
1001 curcolors_.resize(lcolors_.size());
1002 newcolors_.resize(lcolors_.size());
1003 // End initialization
1005 connect(colorChangePB, SIGNAL(clicked()),
1006 this, SLOT(changeColor()));
1007 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
1008 this, SLOT(changeLyxObjectsSelection()));
1009 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
1010 this, SLOT(changeColor()));
1014 void PrefColors::apply(LyXRC & /*rc*/) const
1016 for (unsigned int i = 0; i < lcolors_.size(); ++i)
1017 if (curcolors_[i] != newcolors_[i])
1018 form_->setColor(lcolors_[i], newcolors_[i]);
1022 void PrefColors::update(LyXRC const & /*rc*/)
1024 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
1025 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
1026 QPixmap coloritem(32, 32);
1027 coloritem.fill(color);
1028 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
1029 newcolors_[i] = curcolors_[i] = color.name();
1031 changeLyxObjectsSelection();
1035 void PrefColors::changeColor()
1037 int const row = lyxObjectsLW->currentRow();
1043 QString const color = newcolors_[row];
1044 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
1046 if (c.isValid() && c.name() != color) {
1047 newcolors_[row] = c.name();
1048 QPixmap coloritem(32, 32);
1050 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
1056 void PrefColors::changeLyxObjectsSelection()
1058 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
1062 /////////////////////////////////////////////////////////////////////
1066 /////////////////////////////////////////////////////////////////////
1068 PrefDisplay::PrefDisplay(GuiPreferences * form)
1069 : PrefModule(qt_(catLookAndFeel), qt_("Display"), form)
1072 connect(displayGraphicsCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
1073 connect(instantPreviewCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
1074 connect(previewSizeSB, SIGNAL(valueChanged(double)), this, SIGNAL(changed()));
1075 connect(paragraphMarkerCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
1076 if (instantPreviewCO->currentIndex() == 0)
1077 previewSizeSB->setEnabled(false);
1079 previewSizeSB->setEnabled(true);
1083 void PrefDisplay::on_instantPreviewCO_currentIndexChanged(int index)
1086 previewSizeSB->setEnabled(false);
1088 previewSizeSB->setEnabled(true);
1092 void PrefDisplay::apply(LyXRC & rc) const
1094 switch (instantPreviewCO->currentIndex()) {
1095 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
1096 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
1097 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
1100 rc.display_graphics = displayGraphicsCB->isChecked();
1101 rc.preview_scale_factor = previewSizeSB->value();
1102 rc.paragraph_markers = paragraphMarkerCB->isChecked();
1104 // FIXME!! The graphics cache no longer has a changeDisplay method.
1106 if (old_value != rc.display_graphics) {
1107 graphics::GCache & gc = graphics::GCache::get();
1114 void PrefDisplay::update(LyXRC const & rc)
1116 switch (rc.preview) {
1117 case LyXRC::PREVIEW_OFF:
1118 instantPreviewCO->setCurrentIndex(0);
1120 case LyXRC::PREVIEW_NO_MATH :
1121 instantPreviewCO->setCurrentIndex(1);
1123 case LyXRC::PREVIEW_ON :
1124 instantPreviewCO->setCurrentIndex(2);
1128 displayGraphicsCB->setChecked(rc.display_graphics);
1129 instantPreviewCO->setEnabled(rc.display_graphics);
1130 previewSizeSB->setValue(rc.preview_scale_factor);
1131 paragraphMarkerCB->setChecked(rc.paragraph_markers);
1135 /////////////////////////////////////////////////////////////////////
1139 /////////////////////////////////////////////////////////////////////
1141 PrefPaths::PrefPaths(GuiPreferences * form)
1142 : PrefModule(QString(), qt_("Paths"), form)
1145 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(selectExampledir()));
1146 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(selectTemplatedir()));
1147 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(selectTempdir()));
1148 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(selectBackupdir()));
1149 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(selectWorkingdir()));
1150 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(selectLyxPipe()));
1151 connect(thesaurusDirPB, SIGNAL(clicked()), this, SLOT(selectThesaurusdir()));
1152 connect(hunspellDirPB, SIGNAL(clicked()), this, SLOT(selectHunspelldir()));
1153 connect(workingDirED, SIGNAL(textChanged(QString)),
1154 this, SIGNAL(changed()));
1155 connect(exampleDirED, SIGNAL(textChanged(QString)),
1156 this, SIGNAL(changed()));
1157 connect(templateDirED, SIGNAL(textChanged(QString)),
1158 this, SIGNAL(changed()));
1159 connect(backupDirED, SIGNAL(textChanged(QString)),
1160 this, SIGNAL(changed()));
1161 connect(tempDirED, SIGNAL(textChanged(QString)),
1162 this, SIGNAL(changed()));
1163 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
1164 this, SIGNAL(changed()));
1165 connect(thesaurusDirED, SIGNAL(textChanged(QString)),
1166 this, SIGNAL(changed()));
1167 connect(pathPrefixED, SIGNAL(textChanged(QString)),
1168 this, SIGNAL(changed()));
1169 connect(hunspellDirED, SIGNAL(textChanged(QString)),
1170 this, SIGNAL(changed()));
1174 void PrefPaths::apply(LyXRC & rc) const
1176 rc.document_path = internal_path(fromqstr(workingDirED->text()));
1177 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
1178 rc.template_path = internal_path(fromqstr(templateDirED->text()));
1179 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
1180 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
1181 rc.thesaurusdir_path = internal_path(fromqstr(thesaurusDirED->text()));
1182 rc.hunspelldir_path = internal_path(fromqstr(hunspellDirED->text()));
1183 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
1184 // FIXME: should be a checkbox only
1185 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
1189 void PrefPaths::update(LyXRC const & rc)
1191 workingDirED->setText(toqstr(external_path(rc.document_path)));
1192 exampleDirED->setText(toqstr(external_path(rc.example_path)));
1193 templateDirED->setText(toqstr(external_path(rc.template_path)));
1194 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
1195 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
1196 thesaurusDirED->setText(toqstr(external_path(rc.thesaurusdir_path)));
1197 hunspellDirED->setText(toqstr(external_path(rc.hunspelldir_path)));
1198 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
1199 // FIXME: should be a checkbox only
1200 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
1204 void PrefPaths::selectExampledir()
1206 QString file = browseDir(internalPath(exampleDirED->text()),
1207 qt_("Select directory for example files"));
1208 if (!file.isEmpty())
1209 exampleDirED->setText(file);
1213 void PrefPaths::selectTemplatedir()
1215 QString file = browseDir(internalPath(templateDirED->text()),
1216 qt_("Select a document templates directory"));
1217 if (!file.isEmpty())
1218 templateDirED->setText(file);
1222 void PrefPaths::selectTempdir()
1224 QString file = browseDir(internalPath(tempDirED->text()),
1225 qt_("Select a temporary directory"));
1226 if (!file.isEmpty())
1227 tempDirED->setText(file);
1231 void PrefPaths::selectBackupdir()
1233 QString file = browseDir(internalPath(backupDirED->text()),
1234 qt_("Select a backups directory"));
1235 if (!file.isEmpty())
1236 backupDirED->setText(file);
1240 void PrefPaths::selectWorkingdir()
1242 QString file = browseDir(internalPath(workingDirED->text()),
1243 qt_("Select a document directory"));
1244 if (!file.isEmpty())
1245 workingDirED->setText(file);
1249 void PrefPaths::selectThesaurusdir()
1251 QString file = browseDir(internalPath(thesaurusDirED->text()),
1252 qt_("Set the path to the thesaurus dictionaries"));
1253 if (!file.isEmpty())
1254 thesaurusDirED->setText(file);
1258 void PrefPaths::selectHunspelldir()
1260 QString file = browseDir(internalPath(hunspellDirED->text()),
1261 qt_("Set the path to the Hunspell dictionaries"));
1262 if (!file.isEmpty())
1263 hunspellDirED->setText(file);
1267 void PrefPaths::selectLyxPipe()
1269 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1270 qt_("Give a filename for the LyX server pipe"));
1271 if (!file.isEmpty())
1272 lyxserverDirED->setText(file);
1276 /////////////////////////////////////////////////////////////////////
1280 /////////////////////////////////////////////////////////////////////
1282 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form)
1283 : PrefModule(qt_(catLanguage), qt_("Spellchecker"), form)
1287 spellcheckerCB->addItem("aspell");
1288 spellcheckerCB->addItem("hunspell");
1290 connect(spellcheckerCB, SIGNAL(currentIndexChanged(int)),
1291 this, SIGNAL(changed()));
1292 connect(altLanguageED, SIGNAL(textChanged(QString)),
1293 this, SIGNAL(changed()));
1294 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1295 this, SIGNAL(changed()));
1296 connect(compoundWordCB, SIGNAL(clicked()),
1297 this, SIGNAL(changed()));
1298 connect(spellcheckContinuouslyCB, SIGNAL(clicked()),
1299 this, SIGNAL(changed()));
1303 void PrefSpellchecker::apply(LyXRC & rc) const
1305 rc.spellchecker = fromqstr(spellcheckerCB->currentText());
1306 rc.spellchecker_alt_lang = fromqstr(altLanguageED->text());
1307 rc.spellchecker_esc_chars = fromqstr(escapeCharactersED->text());
1308 rc.spellchecker_accept_compound = compoundWordCB->isChecked();
1309 rc.spellcheck_continuously = spellcheckContinuouslyCB->isChecked();
1313 void PrefSpellchecker::update(LyXRC const & rc)
1315 spellcheckerCB->setCurrentIndex(spellcheckerCB->findText(
1316 toqstr(rc.spellchecker)));
1317 altLanguageED->setText(toqstr(rc.spellchecker_alt_lang));
1318 escapeCharactersED->setText(toqstr(rc.spellchecker_esc_chars));
1319 compoundWordCB->setChecked(rc.spellchecker_accept_compound);
1320 spellcheckContinuouslyCB->setChecked(rc.spellcheck_continuously);
1325 /////////////////////////////////////////////////////////////////////
1329 /////////////////////////////////////////////////////////////////////
1332 PrefConverters::PrefConverters(GuiPreferences * form)
1333 : PrefModule(qt_(catFiles), qt_("Converters"), form)
1337 connect(converterNewPB, SIGNAL(clicked()),
1338 this, SLOT(updateConverter()));
1339 connect(converterRemovePB, SIGNAL(clicked()),
1340 this, SLOT(removeConverter()));
1341 connect(converterModifyPB, SIGNAL(clicked()),
1342 this, SLOT(updateConverter()));
1343 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1344 this, SLOT(switchConverter()));
1345 connect(converterFromCO, SIGNAL(activated(QString)),
1346 this, SLOT(changeConverter()));
1347 connect(converterToCO, SIGNAL(activated(QString)),
1348 this, SLOT(changeConverter()));
1349 connect(converterED, SIGNAL(textEdited(QString)),
1350 this, SLOT(changeConverter()));
1351 connect(converterFlagED, SIGNAL(textEdited(QString)),
1352 this, SLOT(changeConverter()));
1353 connect(converterNewPB, SIGNAL(clicked()),
1354 this, SIGNAL(changed()));
1355 connect(converterRemovePB, SIGNAL(clicked()),
1356 this, SIGNAL(changed()));
1357 connect(converterModifyPB, SIGNAL(clicked()),
1358 this, SIGNAL(changed()));
1359 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1360 this, SIGNAL(changed()));
1362 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1363 //converterDefGB->setFocusProxy(convertersLW);
1367 void PrefConverters::apply(LyXRC & rc) const
1369 rc.use_converter_cache = cacheCB->isChecked();
1370 rc.converter_cache_maxage = int(widgetToDouble(maxAgeLE) * 86400.0);
1374 void PrefConverters::update(LyXRC const & rc)
1376 cacheCB->setChecked(rc.use_converter_cache);
1378 doubleToWidget(maxAgeLE, (double(rc.converter_cache_maxage) / 86400.0), 'g', 6);
1383 void PrefConverters::updateGui()
1385 form_->formats().sort();
1386 form_->converters().update(form_->formats());
1387 // save current selection
1388 QString current = converterFromCO->currentText()
1389 + " -> " + converterToCO->currentText();
1391 converterFromCO->clear();
1392 converterToCO->clear();
1394 Formats::const_iterator cit = form_->formats().begin();
1395 Formats::const_iterator end = form_->formats().end();
1396 for (; cit != end; ++cit) {
1397 converterFromCO->addItem(qt_(cit->prettyname()));
1398 converterToCO->addItem(qt_(cit->prettyname()));
1401 // currentRowChanged(int) is also triggered when updating the listwidget
1402 // block signals to avoid unnecessary calls to switchConverter()
1403 convertersLW->blockSignals(true);
1404 convertersLW->clear();
1406 Converters::const_iterator ccit = form_->converters().begin();
1407 Converters::const_iterator cend = form_->converters().end();
1408 for (; ccit != cend; ++ccit) {
1409 QString const name =
1410 qt_(ccit->From->prettyname()) + " -> " + qt_(ccit->To->prettyname());
1411 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1412 new QListWidgetItem(name, convertersLW, type);
1414 convertersLW->sortItems(Qt::AscendingOrder);
1415 convertersLW->blockSignals(false);
1417 // restore selection
1418 if (!current.isEmpty()) {
1419 QList<QListWidgetItem *> const item =
1420 convertersLW->findItems(current, Qt::MatchExactly);
1421 if (!item.isEmpty())
1422 convertersLW->setCurrentItem(item.at(0));
1425 // select first element if restoring failed
1426 if (convertersLW->currentRow() == -1)
1427 convertersLW->setCurrentRow(0);
1433 void PrefConverters::switchConverter()
1435 int const cnr = convertersLW->currentItem()->type();
1436 Converter const & c(form_->converters().get(cnr));
1437 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1438 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1439 converterED->setText(toqstr(c.command));
1440 converterFlagED->setText(toqstr(c.flags));
1446 void PrefConverters::changeConverter()
1452 void PrefConverters::updateButtons()
1454 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1455 Format const & to = form_->formats().get(converterToCO->currentIndex());
1456 int const sel = form_->converters().getNumber(from.name(), to.name());
1457 bool const known = sel >= 0;
1458 bool const valid = !(converterED->text().isEmpty()
1459 || from.name() == to.name());
1461 int const cnr = convertersLW->currentItem()->type();
1462 Converter const & c = form_->converters().get(cnr);
1463 string const old_command = c.command;
1464 string const old_flag = c.flags;
1465 string const new_command = fromqstr(converterED->text());
1466 string const new_flag = fromqstr(converterFlagED->text());
1468 bool modified = (old_command != new_command || old_flag != new_flag);
1470 converterModifyPB->setEnabled(valid && known && modified);
1471 converterNewPB->setEnabled(valid && !known);
1472 converterRemovePB->setEnabled(known);
1474 maxAgeLE->setEnabled(cacheCB->isChecked());
1475 maxAgeLA->setEnabled(cacheCB->isChecked());
1480 // specify unique from/to or it doesn't appear. This is really bad UI
1481 // this is why we can use the same function for both new and modify
1482 void PrefConverters::updateConverter()
1484 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1485 Format const & to = form_->formats().get(converterToCO->currentIndex());
1486 string const flags = fromqstr(converterFlagED->text());
1487 string const command = fromqstr(converterED->text());
1489 Converter const * old =
1490 form_->converters().getConverter(from.name(), to.name());
1491 form_->converters().add(from.name(), to.name(), command, flags);
1494 form_->converters().updateLast(form_->formats());
1498 // Remove all files created by this converter from the cache, since
1499 // the modified converter might create different files.
1500 ConverterCache::get().remove_all(from.name(), to.name());
1504 void PrefConverters::removeConverter()
1506 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1507 Format const & to = form_->formats().get(converterToCO->currentIndex());
1508 form_->converters().erase(from.name(), to.name());
1512 // Remove all files created by this converter from the cache, since
1513 // a possible new converter might create different files.
1514 ConverterCache::get().remove_all(from.name(), to.name());
1518 void PrefConverters::on_cacheCB_stateChanged(int state)
1520 maxAgeLE->setEnabled(state == Qt::Checked);
1521 maxAgeLA->setEnabled(state == Qt::Checked);
1526 /////////////////////////////////////////////////////////////////////
1530 /////////////////////////////////////////////////////////////////////
1532 class FormatValidator : public QValidator
1535 FormatValidator(QWidget *, Formats const & f);
1536 void fixup(QString & input) const;
1537 QValidator::State validate(QString & input, int & pos) const;
1539 virtual QString toString(Format const & format) const = 0;
1541 Formats const & formats_;
1545 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1546 : QValidator(parent), formats_(f)
1551 void FormatValidator::fixup(QString & input) const
1553 Formats::const_iterator cit = formats_.begin();
1554 Formats::const_iterator end = formats_.end();
1555 for (; cit != end; ++cit) {
1556 QString const name = toString(*cit);
1557 if (distance(formats_.begin(), cit) == nr()) {
1565 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1567 Formats::const_iterator cit = formats_.begin();
1568 Formats::const_iterator end = formats_.end();
1569 bool unknown = true;
1570 for (; unknown && cit != end; ++cit) {
1571 QString const name = toString(*cit);
1572 if (distance(formats_.begin(), cit) != nr())
1573 unknown = name != input;
1576 if (unknown && !input.isEmpty())
1577 return QValidator::Acceptable;
1579 return QValidator::Intermediate;
1583 int FormatValidator::nr() const
1585 QComboBox * p = qobject_cast<QComboBox *>(parent());
1586 return p->itemData(p->currentIndex()).toInt();
1590 /////////////////////////////////////////////////////////////////////
1592 // FormatNameValidator
1594 /////////////////////////////////////////////////////////////////////
1596 class FormatNameValidator : public FormatValidator
1599 FormatNameValidator(QWidget * parent, Formats const & f)
1600 : FormatValidator(parent, f)
1603 QString toString(Format const & format) const
1605 return toqstr(format.name());
1610 /////////////////////////////////////////////////////////////////////
1612 // FormatPrettynameValidator
1614 /////////////////////////////////////////////////////////////////////
1616 class FormatPrettynameValidator : public FormatValidator
1619 FormatPrettynameValidator(QWidget * parent, Formats const & f)
1620 : FormatValidator(parent, f)
1623 QString toString(Format const & format) const
1625 return qt_(format.prettyname());
1630 /////////////////////////////////////////////////////////////////////
1634 /////////////////////////////////////////////////////////////////////
1636 PrefFileformats::PrefFileformats(GuiPreferences * form)
1637 : PrefModule(qt_(catFiles), qt_("File formats"), form)
1640 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1641 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1643 connect(documentCB, SIGNAL(clicked()),
1644 this, SLOT(setFlags()));
1645 connect(vectorCB, SIGNAL(clicked()),
1646 this, SLOT(setFlags()));
1647 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1648 this, SLOT(updatePrettyname()));
1649 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1650 this, SIGNAL(changed()));
1651 connect(defaultFormatCB, SIGNAL(activated(QString)),
1652 this, SIGNAL(changed()));
1653 connect(viewerCO, SIGNAL(activated(int)),
1654 this, SIGNAL(changed()));
1655 connect(editorCO, SIGNAL(activated(int)),
1656 this, SIGNAL(changed()));
1662 string const l10n_shortcut(string const prettyname, string const shortcut)
1664 if (shortcut.empty())
1667 string l10n_format =
1668 to_utf8(_(prettyname + '|' + shortcut));
1669 return split(l10n_format, '|');
1672 }; // namespace anon
1675 void PrefFileformats::apply(LyXRC & rc) const
1677 QString const default_format = defaultFormatCB->itemData(
1678 defaultFormatCB->currentIndex()).toString();
1679 rc.default_view_format = fromqstr(default_format);
1683 void PrefFileformats::update(LyXRC const & rc)
1685 viewer_alternatives = rc.viewer_alternatives;
1686 editor_alternatives = rc.editor_alternatives;
1687 bool const init = defaultFormatCB->currentText().isEmpty();
1691 defaultFormatCB->findData(toqstr(rc.default_view_format));
1692 defaultFormatCB->setCurrentIndex(pos);
1697 void PrefFileformats::updateView()
1699 QString const current = formatsCB->currentText();
1700 QString const current_def = defaultFormatCB->currentText();
1702 // update comboboxes with formats
1703 formatsCB->blockSignals(true);
1704 defaultFormatCB->blockSignals(true);
1706 defaultFormatCB->clear();
1707 form_->formats().sort();
1708 Formats::const_iterator cit = form_->formats().begin();
1709 Formats::const_iterator end = form_->formats().end();
1710 for (; cit != end; ++cit) {
1711 formatsCB->addItem(qt_(cit->prettyname()),
1712 QVariant(form_->formats().getNumber(cit->name())));
1713 if (form_->converters().isReachable("latex", cit->name())
1714 || form_->converters().isReachable("pdflatex", cit->name()))
1715 defaultFormatCB->addItem(qt_(cit->prettyname()),
1716 QVariant(toqstr(cit->name())));
1719 // restore selection
1720 int item = formatsCB->findText(current, Qt::MatchExactly);
1721 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1722 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1723 item = defaultFormatCB->findText(current_def, Qt::MatchExactly);
1724 defaultFormatCB->setCurrentIndex(item < 0 ? 0 : item);
1725 formatsCB->blockSignals(false);
1726 defaultFormatCB->blockSignals(false);
1730 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1732 int const nr = formatsCB->itemData(i).toInt();
1733 Format const f = form_->formats().get(nr);
1735 formatED->setText(toqstr(f.name()));
1736 copierED->setText(toqstr(form_->movers().command(f.name())));
1737 extensionED->setText(toqstr(f.extension()));
1738 shortcutED->setText(
1739 toqstr(l10n_shortcut(f.prettyname(), f.shortcut())));
1740 documentCB->setChecked((f.documentFormat()));
1741 vectorCB->setChecked((f.vectorFormat()));
1747 void PrefFileformats::setFlags()
1749 int flags = Format::none;
1750 if (documentCB->isChecked())
1751 flags |= Format::document;
1752 if (vectorCB->isChecked())
1753 flags |= Format::vector;
1754 currentFormat().setFlags(flags);
1759 void PrefFileformats::on_copierED_textEdited(const QString & s)
1761 string const fmt = fromqstr(formatED->text());
1762 form_->movers().set(fmt, fromqstr(s));
1767 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1769 currentFormat().setExtension(fromqstr(s));
1773 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1775 currentFormat().setViewer(fromqstr(s));
1780 void PrefFileformats::on_editorED_textEdited(const QString & s)
1782 currentFormat().setEditor(fromqstr(s));
1787 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1789 string const new_shortcut = fromqstr(s);
1790 if (new_shortcut == l10n_shortcut(currentFormat().prettyname(),
1791 currentFormat().shortcut()))
1793 currentFormat().setShortcut(new_shortcut);
1798 void PrefFileformats::on_formatED_editingFinished()
1800 string const newname = fromqstr(formatED->displayText());
1801 if (newname == currentFormat().name())
1804 currentFormat().setName(newname);
1809 void PrefFileformats::on_formatED_textChanged(const QString &)
1811 QString t = formatED->text();
1813 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1814 setValid(formatLA, valid);
1818 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1820 QString t = formatsCB->currentText();
1822 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1823 setValid(formatsLA, valid);
1827 void PrefFileformats::updatePrettyname()
1829 QString const newname = formatsCB->currentText();
1830 if (newname == qt_(currentFormat().prettyname()))
1833 currentFormat().setPrettyname(fromqstr(newname));
1841 void updateComboBox(LyXRC::Alternatives const & alts,
1842 string const & fmt, QComboBox * combo)
1844 LyXRC::Alternatives::const_iterator it =
1846 if (it != alts.end()) {
1847 LyXRC::CommandSet const & cmds = it->second;
1848 LyXRC::CommandSet::const_iterator sit =
1850 LyXRC::CommandSet::const_iterator const sen =
1852 for (; sit != sen; ++sit) {
1853 QString const qcmd = toqstr(*sit);
1854 combo->addItem(qcmd, qcmd);
1861 void PrefFileformats::updateViewers()
1863 Format const f = currentFormat();
1864 viewerCO->blockSignals(true);
1866 viewerCO->addItem(qt_("None"), QString());
1867 updateComboBox(viewer_alternatives, f.name(), viewerCO);
1868 viewerCO->addItem(qt_("Custom"), QString("custom viewer"));
1869 viewerCO->blockSignals(false);
1871 int pos = viewerCO->findData(toqstr(f.viewer()));
1874 viewerED->setEnabled(false);
1875 viewerCO->setCurrentIndex(pos);
1877 viewerED->setEnabled(true);
1878 viewerED->setText(toqstr(f.viewer()));
1879 viewerCO->setCurrentIndex(viewerCO->findData(toqstr("custom viewer")));
1884 void PrefFileformats::updateEditors()
1886 Format const f = currentFormat();
1887 editorCO->blockSignals(true);
1889 editorCO->addItem(qt_("None"), QString());
1890 updateComboBox(editor_alternatives, f.name(), editorCO);
1891 editorCO->addItem(qt_("Custom"), QString("custom editor"));
1892 editorCO->blockSignals(false);
1894 int pos = editorCO->findData(toqstr(f.editor()));
1897 editorED->setEnabled(false);
1898 editorCO->setCurrentIndex(pos);
1900 editorED->setEnabled(true);
1901 editorED->setText(toqstr(f.editor()));
1902 editorCO->setCurrentIndex(editorCO->findData(toqstr("custom editor")));
1907 void PrefFileformats::on_viewerCO_currentIndexChanged(int i)
1909 bool const custom = viewerCO->itemData(i).toString() == "custom viewer";
1910 viewerED->setEnabled(custom);
1912 currentFormat().setViewer(fromqstr(viewerCO->itemData(i).toString()));
1916 void PrefFileformats::on_editorCO_currentIndexChanged(int i)
1918 bool const custom = editorCO->itemData(i).toString() == "custom editor";
1919 editorED->setEnabled(custom);
1921 currentFormat().setEditor(fromqstr(editorCO->itemData(i).toString()));
1925 Format & PrefFileformats::currentFormat()
1927 int const i = formatsCB->currentIndex();
1928 int const nr = formatsCB->itemData(i).toInt();
1929 return form_->formats().get(nr);
1933 void PrefFileformats::on_formatNewPB_clicked()
1935 form_->formats().add("", "", "", "", "", "", Format::none);
1937 formatsCB->setCurrentIndex(0);
1938 formatsCB->setFocus(Qt::OtherFocusReason);
1942 void PrefFileformats::on_formatRemovePB_clicked()
1944 int const i = formatsCB->currentIndex();
1945 int const nr = formatsCB->itemData(i).toInt();
1946 string const current_text = form_->formats().get(nr).name();
1947 if (form_->converters().formatIsUsed(current_text)) {
1948 Alert::error(_("Format in use"),
1949 _("Cannot remove a Format used by a Converter. "
1950 "Remove the converter first."));
1954 form_->formats().erase(current_text);
1957 on_formatsCB_editTextChanged(formatsCB->currentText());
1962 /////////////////////////////////////////////////////////////////////
1966 /////////////////////////////////////////////////////////////////////
1968 PrefLanguage::PrefLanguage(GuiPreferences * form)
1969 : PrefModule(qt_(catLanguage), qt_("Language"), form)
1973 connect(rtlGB, SIGNAL(clicked()),
1974 this, SIGNAL(changed()));
1975 connect(visualCursorRB, SIGNAL(clicked()),
1976 this, SIGNAL(changed()));
1977 connect(logicalCursorRB, SIGNAL(clicked()),
1978 this, SIGNAL(changed()));
1979 connect(markForeignCB, SIGNAL(clicked()),
1980 this, SIGNAL(changed()));
1981 connect(autoBeginCB, SIGNAL(clicked()),
1982 this, SIGNAL(changed()));
1983 connect(autoEndCB, SIGNAL(clicked()),
1984 this, SIGNAL(changed()));
1985 connect(useBabelCB, SIGNAL(clicked()),
1986 this, SIGNAL(changed()));
1987 connect(globalCB, SIGNAL(clicked()),
1988 this, SIGNAL(changed()));
1989 connect(languagePackageED, SIGNAL(textChanged(QString)),
1990 this, SIGNAL(changed()));
1991 connect(startCommandED, SIGNAL(textChanged(QString)),
1992 this, SIGNAL(changed()));
1993 connect(endCommandED, SIGNAL(textChanged(QString)),
1994 this, SIGNAL(changed()));
1995 connect(uiLanguageCO, SIGNAL(activated(int)),
1996 this, SIGNAL(changed()));
1998 uiLanguageCO->clear();
2000 QAbstractItemModel * language_model = guiApp->languageModel();
2001 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
2002 language_model->sort(0);
2004 // FIXME: This is wrong, we need filter this list based on the available
2006 uiLanguageCO->blockSignals(true);
2007 uiLanguageCO->addItem(qt_("Default"), toqstr("auto"));
2008 for (int i = 0; i != language_model->rowCount(); ++i) {
2009 QModelIndex index = language_model->index(i, 0);
2010 uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
2011 index.data(Qt::UserRole).toString());
2013 uiLanguageCO->blockSignals(false);
2017 void PrefLanguage::on_uiLanguageCO_currentIndexChanged(int)
2019 QMessageBox::information(this, qt_("LyX needs to be restarted!"),
2020 qt_("The change of user interface language will be fully "
2021 "effective only after a restart."));
2025 void PrefLanguage::apply(LyXRC & rc) const
2027 // FIXME: remove rtl_support bool
2028 rc.rtl_support = rtlGB->isChecked();
2029 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
2030 rc.mark_foreign_language = markForeignCB->isChecked();
2031 rc.language_auto_begin = autoBeginCB->isChecked();
2032 rc.language_auto_end = autoEndCB->isChecked();
2033 rc.language_use_babel = useBabelCB->isChecked();
2034 rc.language_global_options = globalCB->isChecked();
2035 rc.language_package = fromqstr(languagePackageED->text());
2036 rc.language_command_begin = fromqstr(startCommandED->text());
2037 rc.language_command_end = fromqstr(endCommandED->text());
2038 rc.gui_language = fromqstr(
2039 uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString());
2043 void PrefLanguage::update(LyXRC const & rc)
2045 // FIXME: remove rtl_support bool
2046 rtlGB->setChecked(rc.rtl_support);
2047 if (rc.visual_cursor)
2048 visualCursorRB->setChecked(true);
2050 logicalCursorRB->setChecked(true);
2051 markForeignCB->setChecked(rc.mark_foreign_language);
2052 autoBeginCB->setChecked(rc.language_auto_begin);
2053 autoEndCB->setChecked(rc.language_auto_end);
2054 useBabelCB->setChecked(rc.language_use_babel);
2055 globalCB->setChecked(rc.language_global_options);
2056 languagePackageED->setText(toqstr(rc.language_package));
2057 startCommandED->setText(toqstr(rc.language_command_begin));
2058 endCommandED->setText(toqstr(rc.language_command_end));
2060 int pos = uiLanguageCO->findData(toqstr(rc.gui_language));
2061 uiLanguageCO->blockSignals(true);
2062 uiLanguageCO->setCurrentIndex(pos);
2063 uiLanguageCO->blockSignals(false);
2067 /////////////////////////////////////////////////////////////////////
2071 /////////////////////////////////////////////////////////////////////
2073 PrefPrinter::PrefPrinter(GuiPreferences * form)
2074 : PrefModule(qt_(catOutput), qt_("Printer"), form)
2078 connect(printerAdaptCB, SIGNAL(clicked()),
2079 this, SIGNAL(changed()));
2080 connect(printerCommandED, SIGNAL(textChanged(QString)),
2081 this, SIGNAL(changed()));
2082 connect(printerNameED, SIGNAL(textChanged(QString)),
2083 this, SIGNAL(changed()));
2084 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
2085 this, SIGNAL(changed()));
2086 connect(printerCopiesED, SIGNAL(textChanged(QString)),
2087 this, SIGNAL(changed()));
2088 connect(printerReverseED, SIGNAL(textChanged(QString)),
2089 this, SIGNAL(changed()));
2090 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
2091 this, SIGNAL(changed()));
2092 connect(printerExtensionED, SIGNAL(textChanged(QString)),
2093 this, SIGNAL(changed()));
2094 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
2095 this, SIGNAL(changed()));
2096 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
2097 this, SIGNAL(changed()));
2098 connect(printerEvenED, SIGNAL(textChanged(QString)),
2099 this, SIGNAL(changed()));
2100 connect(printerOddED, SIGNAL(textChanged(QString)),
2101 this, SIGNAL(changed()));
2102 connect(printerCollatedED, SIGNAL(textChanged(QString)),
2103 this, SIGNAL(changed()));
2104 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
2105 this, SIGNAL(changed()));
2106 connect(printerToFileED, SIGNAL(textChanged(QString)),
2107 this, SIGNAL(changed()));
2108 connect(printerExtraED, SIGNAL(textChanged(QString)),
2109 this, SIGNAL(changed()));
2110 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
2111 this, SIGNAL(changed()));
2112 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
2113 this, SIGNAL(changed()));
2117 void PrefPrinter::apply(LyXRC & rc) const
2119 rc.print_adapt_output = printerAdaptCB->isChecked();
2120 rc.print_command = fromqstr(printerCommandED->text());
2121 rc.printer = fromqstr(printerNameED->text());
2123 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
2124 rc.print_copies_flag = fromqstr(printerCopiesED->text());
2125 rc.print_reverse_flag = fromqstr(printerReverseED->text());
2126 rc.print_to_printer = fromqstr(printerToPrinterED->text());
2127 rc.print_file_extension = fromqstr(printerExtensionED->text());
2128 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
2129 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
2130 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
2131 rc.print_oddpage_flag = fromqstr(printerOddED->text());
2132 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
2133 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
2134 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
2135 rc.print_extra_options = fromqstr(printerExtraED->text());
2136 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
2137 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
2141 void PrefPrinter::update(LyXRC const & rc)
2143 printerAdaptCB->setChecked(rc.print_adapt_output);
2144 printerCommandED->setText(toqstr(rc.print_command));
2145 printerNameED->setText(toqstr(rc.printer));
2147 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
2148 printerCopiesED->setText(toqstr(rc.print_copies_flag));
2149 printerReverseED->setText(toqstr(rc.print_reverse_flag));
2150 printerToPrinterED->setText(toqstr(rc.print_to_printer));
2151 printerExtensionED->setText(toqstr(rc.print_file_extension));
2152 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
2153 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
2154 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
2155 printerOddED->setText(toqstr(rc.print_oddpage_flag));
2156 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
2157 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
2158 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
2159 printerExtraED->setText(toqstr(rc.print_extra_options));
2160 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
2161 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
2165 /////////////////////////////////////////////////////////////////////
2167 // PrefUserInterface
2169 /////////////////////////////////////////////////////////////////////
2171 PrefUserInterface::PrefUserInterface(GuiPreferences * form)
2172 : PrefModule(qt_(catLookAndFeel), qt_("User interface"), form)
2176 connect(autoSaveCB, SIGNAL(toggled(bool)),
2177 autoSaveSB, SLOT(setEnabled(bool)));
2178 connect(autoSaveCB, SIGNAL(toggled(bool)),
2179 TextLabel1, SLOT(setEnabled(bool)));
2180 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
2181 this, SIGNAL(changed()));
2182 #if QT_VERSION < 0x040500
2183 singleCloseTabButtonCB->setEnabled(false);
2185 connect(singleCloseTabButtonCB, SIGNAL(clicked()),
2186 this, SIGNAL(changed()));
2187 connect(uiFilePB, SIGNAL(clicked()),
2188 this, SLOT(selectUi()));
2189 connect(uiFileED, SIGNAL(textChanged(QString)),
2190 this, SIGNAL(changed()));
2191 connect(restoreCursorCB, SIGNAL(clicked()),
2192 this, SIGNAL(changed()));
2193 connect(loadSessionCB, SIGNAL(clicked()),
2194 this, SIGNAL(changed()));
2195 connect(allowGeometrySessionCB, SIGNAL(clicked()),
2196 this, SIGNAL(changed()));
2197 connect(autoSaveSB, SIGNAL(valueChanged(int)),
2198 this, SIGNAL(changed()));
2199 connect(autoSaveCB, SIGNAL(clicked()),
2200 this, SIGNAL(changed()));
2201 connect(backupCB, SIGNAL(clicked()),
2202 this, SIGNAL(changed()));
2203 connect(lastfilesSB, SIGNAL(valueChanged(int)),
2204 this, SIGNAL(changed()));
2205 connect(tooltipCB, SIGNAL(toggled(bool)),
2206 this, SIGNAL(changed()));
2207 lastfilesSB->setMaximum(maxlastfiles);
2211 void PrefUserInterface::apply(LyXRC & rc) const
2213 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
2214 rc.use_lastfilepos = restoreCursorCB->isChecked();
2215 rc.load_session = loadSessionCB->isChecked();
2216 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
2217 rc.autosave = autoSaveCB->isChecked()? autoSaveSB->value() * 60 : 0;
2218 rc.make_backup = backupCB->isChecked();
2219 rc.num_lastfiles = lastfilesSB->value();
2220 rc.use_tooltip = tooltipCB->isChecked();
2221 rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
2222 rc.single_close_tab_button = singleCloseTabButtonCB->isChecked();
2223 #if QT_VERSION < 0x040500
2224 rc.single_close_tab_button = true;
2229 void PrefUserInterface::update(LyXRC const & rc)
2231 uiFileED->setText(toqstr(external_path(rc.ui_file)));
2232 restoreCursorCB->setChecked(rc.use_lastfilepos);
2233 loadSessionCB->setChecked(rc.load_session);
2234 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
2235 // convert to minutes
2236 bool autosave = rc.autosave > 0;
2237 int mins = rc.autosave / 60;
2240 autoSaveSB->setValue(mins);
2241 autoSaveCB->setChecked(autosave);
2242 autoSaveSB->setEnabled(autosave);
2243 backupCB->setChecked(rc.make_backup);
2244 lastfilesSB->setValue(rc.num_lastfiles);
2245 tooltipCB->setChecked(rc.use_tooltip);
2246 openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
2247 singleCloseTabButtonCB->setChecked(rc.single_close_tab_button);
2251 void PrefUserInterface::selectUi()
2253 QString file = form_->browseUI(internalPath(uiFileED->text()));
2254 if (!file.isEmpty())
2255 uiFileED->setText(file);
2259 void PrefUserInterface::on_clearSessionPB_clicked()
2261 guiApp->clearSession();
2266 /////////////////////////////////////////////////////////////////////
2270 /////////////////////////////////////////////////////////////////////
2272 PrefEdit::PrefEdit(GuiPreferences * form)
2273 : PrefModule(qt_(catEditing), qt_("Control"), form)
2277 connect(cursorFollowsCB, SIGNAL(clicked()),
2278 this, SIGNAL(changed()));
2279 connect(scrollBelowCB, SIGNAL(clicked()),
2280 this, SIGNAL(changed()));
2281 connect(sortEnvironmentsCB, SIGNAL(clicked()),
2282 this, SIGNAL(changed()));
2283 connect(groupEnvironmentsCB, SIGNAL(clicked()),
2284 this, SIGNAL(changed()));
2285 connect(macroEditStyleCO, SIGNAL(activated(int)),
2286 this, SIGNAL(changed()));
2287 connect(fullscreenLimitGB, SIGNAL(clicked()),
2288 this, SIGNAL(changed()));
2289 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
2290 this, SIGNAL(changed()));
2291 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
2292 this, SIGNAL(changed()));
2293 connect(toggleMenubarCB, SIGNAL(toggled(bool)),
2294 this, SIGNAL(changed()));
2295 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
2296 this, SIGNAL(changed()));
2297 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
2298 this, SIGNAL(changed()));
2302 void PrefEdit::apply(LyXRC & rc) const
2304 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
2305 rc.scroll_below_document = scrollBelowCB->isChecked();
2306 rc.sort_layouts = sortEnvironmentsCB->isChecked();
2307 rc.group_layouts = groupEnvironmentsCB->isChecked();
2308 switch (macroEditStyleCO->currentIndex()) {
2309 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
2310 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
2311 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
2313 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
2314 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
2315 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
2316 rc.full_screen_menubar = toggleMenubarCB->isChecked();
2317 rc.full_screen_width = fullscreenWidthSB->value();
2318 rc.full_screen_limit = fullscreenLimitGB->isChecked();
2322 void PrefEdit::update(LyXRC const & rc)
2324 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
2325 scrollBelowCB->setChecked(rc.scroll_below_document);
2326 sortEnvironmentsCB->setChecked(rc.sort_layouts);
2327 groupEnvironmentsCB->setChecked(rc.group_layouts);
2328 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
2329 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
2330 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
2331 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
2332 toggleMenubarCB->setChecked(rc.full_screen_menubar);
2333 fullscreenWidthSB->setValue(rc.full_screen_width);
2334 fullscreenLimitGB->setChecked(rc.full_screen_limit);
2338 /////////////////////////////////////////////////////////////////////
2342 /////////////////////////////////////////////////////////////////////
2345 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
2347 Ui::shortcutUi::setupUi(this);
2348 QDialog::setModal(true);
2352 PrefShortcuts::PrefShortcuts(GuiPreferences * form)
2353 : PrefModule(qt_(catEditing), qt_("Shortcuts"), form)
2357 shortcutsTW->setColumnCount(2);
2358 shortcutsTW->headerItem()->setText(0, qt_("Function"));
2359 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
2360 shortcutsTW->setSortingEnabled(true);
2361 // Multi-selection can be annoying.
2362 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
2364 connect(bindFilePB, SIGNAL(clicked()),
2365 this, SLOT(selectBind()));
2366 connect(bindFileED, SIGNAL(textChanged(QString)),
2367 this, SIGNAL(changed()));
2368 connect(removePB, SIGNAL(clicked()),
2369 this, SIGNAL(changed()));
2371 shortcut_ = new GuiShortcutDialog(this);
2372 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
2373 shortcut_bc_.setOK(shortcut_->okPB);
2374 shortcut_bc_.setCancel(shortcut_->cancelPB);
2376 connect(shortcut_->okPB, SIGNAL(clicked()),
2377 shortcut_, SLOT(accept()));
2378 connect(shortcut_->okPB, SIGNAL(clicked()),
2379 this, SIGNAL(changed()));
2380 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2381 shortcut_, SLOT(reject()));
2382 connect(shortcut_->clearPB, SIGNAL(clicked()),
2383 this, SLOT(shortcutClearPressed()));
2384 connect(shortcut_->removePB, SIGNAL(clicked()),
2385 this, SLOT(shortcutRemovePressed()));
2386 connect(shortcut_->okPB, SIGNAL(clicked()),
2387 this, SLOT(shortcutOkPressed()));
2388 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2389 this, SLOT(shortcutCancelPressed()));
2393 void PrefShortcuts::apply(LyXRC & rc) const
2395 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
2396 // write user_bind and user_unbind to .lyx/bind/user.bind
2397 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
2398 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
2399 lyxerr << "LyX could not create the user bind directory '"
2400 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2403 if (!bind_dir.isDirWritable()) {
2404 lyxerr << "LyX could not write to the user bind directory '"
2405 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2408 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
2409 user_unbind_.write(user_bind_file.toFilesystemEncoding(), false, true);
2410 user_bind_.write(user_bind_file.toFilesystemEncoding(), true, false);
2411 // immediately apply the keybindings. Why this is not done before?
2412 // The good thing is that the menus are updated automatically.
2413 theTopLevelKeymap().clear();
2414 theTopLevelKeymap().read("site");
2415 theTopLevelKeymap().read(rc.bind_file, 0, KeyMap::Fallback);
2416 theTopLevelKeymap().read("user", 0, KeyMap::MissingOK);
2420 void PrefShortcuts::update(LyXRC const & rc)
2422 bindFileED->setText(toqstr(external_path(rc.bind_file)));
2424 system_bind_.clear();
2426 user_unbind_.clear();
2427 system_bind_.read("site");
2428 system_bind_.read(rc.bind_file);
2429 // \unbind in user.bind is added to user_unbind_
2430 user_bind_.read("user", &user_unbind_, KeyMap::MissingOK);
2431 updateShortcutsTW();
2435 void PrefShortcuts::updateShortcutsTW()
2437 shortcutsTW->clear();
2439 editItem_ = new QTreeWidgetItem(shortcutsTW);
2440 editItem_->setText(0, qt_("Cursor, Mouse and Editing functions"));
2441 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2443 mathItem_ = new QTreeWidgetItem(shortcutsTW);
2444 mathItem_->setText(0, qt_("Mathematical Symbols"));
2445 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2447 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2448 bufferItem_->setText(0, qt_("Document and Window"));
2449 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2451 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2452 layoutItem_->setText(0, qt_("Font, Layouts and Textclasses"));
2453 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2455 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2456 systemItem_->setText(0, qt_("System and Miscellaneous"));
2457 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2459 // listBindings(unbound=true) lists all bound and unbound lfuns
2460 // Items in this list is tagged by its source.
2461 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2463 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2465 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2466 KeyMap::UserUnbind);
2467 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2468 user_bindinglist.end());
2469 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2470 user_unbindinglist.end());
2472 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2473 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2474 for (; it != it_end; ++it)
2475 insertShortcutItem(it->request, it->sequence, KeyMap::ItemType(it->tag));
2477 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2478 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2479 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2480 modifyPB->setEnabled(!items.isEmpty());
2482 shortcutsTW->resizeColumnToContents(0);
2486 void PrefShortcuts::setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag)
2488 item->setData(0, Qt::UserRole, QVariant(tag));
2492 case KeyMap::System:
2494 case KeyMap::UserBind:
2497 case KeyMap::UserUnbind:
2498 font.setStrikeOut(true);
2500 // this item is not displayed now.
2501 case KeyMap::UserExtraUnbind:
2502 font.setStrikeOut(true);
2506 item->setFont(1, font);
2510 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2511 KeySequence const & seq, KeyMap::ItemType tag)
2513 FuncCode action = lfun.action;
2514 string const action_name = lyxaction.getActionName(action);
2515 QString const lfun_name = toqstr(from_utf8(action_name)
2516 + ' ' + lfun.argument());
2517 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2518 KeyMap::ItemType item_tag = tag;
2520 QTreeWidgetItem * newItem = 0;
2521 // for unbind items, try to find an existing item in the system bind list
2522 if (tag == KeyMap::UserUnbind) {
2523 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2524 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2525 for (int i = 0; i < items.size(); ++i) {
2526 if (items[i]->text(1) == shortcut)
2530 // if not found, this unbind item is KeyMap::UserExtraUnbind
2531 // Such an item is not displayed to avoid confusion (what is
2532 // unmatched removed?).
2534 item_tag = KeyMap::UserExtraUnbind;
2539 switch(lyxaction.getActionType(action)) {
2540 case LyXAction::Hidden:
2542 case LyXAction::Edit:
2543 newItem = new QTreeWidgetItem(editItem_);
2545 case LyXAction::Math:
2546 newItem = new QTreeWidgetItem(mathItem_);
2548 case LyXAction::Buffer:
2549 newItem = new QTreeWidgetItem(bufferItem_);
2551 case LyXAction::Layout:
2552 newItem = new QTreeWidgetItem(layoutItem_);
2554 case LyXAction::System:
2555 newItem = new QTreeWidgetItem(systemItem_);
2558 // this should not happen
2559 newItem = new QTreeWidgetItem(shortcutsTW);
2563 newItem->setText(0, lfun_name);
2564 newItem->setText(1, shortcut);
2565 // record BindFile representation to recover KeySequence when needed.
2566 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2567 setItemType(newItem, item_tag);
2572 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2574 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2575 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2576 modifyPB->setEnabled(!items.isEmpty());
2577 if (items.isEmpty())
2580 KeyMap::ItemType tag =
2581 static_cast<KeyMap::ItemType>(items[0]->data(0, Qt::UserRole).toInt());
2582 if (tag == KeyMap::UserUnbind)
2583 removePB->setText(qt_("Res&tore"));
2585 removePB->setText(qt_("Remo&ve"));
2589 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2595 void PrefShortcuts::modifyShortcut()
2597 QTreeWidgetItem * item = shortcutsTW->currentItem();
2598 if (item->flags() & Qt::ItemIsSelectable) {
2599 shortcut_->lfunLE->setText(item->text(0));
2600 save_lfun_ = item->text(0);
2601 shortcut_->shortcutWG->setText(item->text(1));
2603 seq.parse(fromqstr(item->data(1, Qt::UserRole).toString()));
2604 shortcut_->shortcutWG->setKeySequence(seq);
2605 shortcut_->shortcutWG->setFocus();
2611 void PrefShortcuts::removeShortcut()
2613 // it seems that only one item can be selected, but I am
2614 // removing all selected items anyway.
2615 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2616 for (int i = 0; i < items.size(); ++i) {
2617 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2618 string lfun = fromqstr(items[i]->text(0));
2619 FuncRequest func = lyxaction.lookupFunc(lfun);
2620 KeyMap::ItemType tag =
2621 static_cast<KeyMap::ItemType>(items[i]->data(0, Qt::UserRole).toInt());
2624 case KeyMap::System: {
2625 // for system bind, we do not touch the item
2626 // but add an user unbind item
2627 user_unbind_.bind(shortcut, func);
2628 setItemType(items[i], KeyMap::UserUnbind);
2629 removePB->setText(qt_("Res&tore"));
2632 case KeyMap::UserBind: {
2633 // for user_bind, we remove this bind
2634 QTreeWidgetItem * parent = items[i]->parent();
2635 int itemIdx = parent->indexOfChild(items[i]);
2636 parent->takeChild(itemIdx);
2638 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2640 shortcutsTW->scrollToItem(parent);
2641 user_bind_.unbind(shortcut, func);
2644 case KeyMap::UserUnbind: {
2645 // for user_unbind, we remove the unbind, and the item
2646 // become KeyMap::System again.
2647 user_unbind_.unbind(shortcut, func);
2648 setItemType(items[i], KeyMap::System);
2649 removePB->setText(qt_("Remo&ve"));
2652 case KeyMap::UserExtraUnbind: {
2653 // for user unbind that is not in system bind file,
2654 // remove this unbind file
2655 QTreeWidgetItem * parent = items[i]->parent();
2656 parent->takeChild(parent->indexOfChild(items[i]));
2657 user_unbind_.unbind(shortcut, func);
2664 void PrefShortcuts::selectBind()
2666 QString file = form_->browsebind(internalPath(bindFileED->text()));
2667 if (!file.isEmpty()) {
2668 bindFileED->setText(file);
2669 system_bind_ = KeyMap();
2670 system_bind_.read(fromqstr(file));
2671 updateShortcutsTW();
2676 void PrefShortcuts::on_modifyPB_pressed()
2682 void PrefShortcuts::on_newPB_pressed()
2684 shortcut_->lfunLE->clear();
2685 shortcut_->shortcutWG->reset();
2686 save_lfun_ = QString();
2691 void PrefShortcuts::on_removePB_pressed()
2697 void PrefShortcuts::on_searchLE_textEdited()
2699 if (searchLE->text().isEmpty()) {
2700 // show all hidden items
2701 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2703 shortcutsTW->setItemHidden(*it++, false);
2706 // search both columns
2707 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2708 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2709 matched += shortcutsTW->findItems(searchLE->text(),
2710 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2712 // hide everyone (to avoid searching in matched QList repeatedly
2713 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2715 shortcutsTW->setItemHidden(*it++, true);
2716 // show matched items
2717 for (int i = 0; i < matched.size(); ++i) {
2718 shortcutsTW->setItemHidden(matched[i], false);
2719 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2724 docstring makeCmdString(FuncRequest const & f)
2726 docstring actionStr = from_ascii(lyxaction.getActionName(f.action));
2727 if (!f.argument().empty())
2728 actionStr += " " + f.argument();
2733 void PrefShortcuts::shortcutOkPressed()
2735 QString const new_lfun = shortcut_->lfunLE->text();
2736 FuncRequest func = lyxaction.lookupFunc(fromqstr(new_lfun));
2738 if (func.action == LFUN_UNKNOWN_ACTION) {
2739 Alert::error(_("Failed to create shortcut"),
2740 _("Unknown or invalid LyX function"));
2744 KeySequence k = shortcut_->shortcutWG->getKeySequence();
2745 if (k.length() == 0) {
2746 Alert::error(_("Failed to create shortcut"),
2747 _("Invalid or empty key sequence"));
2751 // check to see if there's been any change
2752 FuncRequest oldBinding = system_bind_.getBinding(k);
2753 if (oldBinding.action == LFUN_UNKNOWN_ACTION)
2754 oldBinding = user_bind_.getBinding(k);
2755 if (oldBinding == func) {
2756 docstring const actionStr = makeCmdString(func);
2757 Alert::error(_("Failed to create shortcut"),
2758 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s"),
2759 k.print(KeySequence::ForGui), actionStr));
2763 // make sure this key isn't already bound---and, if so, not unbound
2764 FuncCode const unbind = user_unbind_.getBinding(k).action;
2765 if (oldBinding.action != LFUN_UNKNOWN_ACTION && unbind == LFUN_UNKNOWN_ACTION)
2767 // FIXME Perhaps we should offer to over-write the old shortcut?
2768 // If so, we'll need to remove it from our list, etc.
2769 docstring const actionStr = makeCmdString(oldBinding);
2770 Alert::error(_("Failed to create shortcut"),
2771 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s\n"
2772 "You need to remove that binding before creating a new one."),
2773 k.print(KeySequence::ForGui), actionStr));
2777 if (!save_lfun_.isEmpty() && new_lfun == save_lfun_)
2778 // real modification of the lfun's shortcut,
2779 // so remove the previous one
2782 QTreeWidgetItem * item = insertShortcutItem(func, k, KeyMap::UserBind);
2784 user_bind_.bind(&k, func);
2785 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2786 shortcutsTW->setItemExpanded(item->parent(), true);
2787 shortcutsTW->scrollToItem(item);
2789 Alert::error(_("Failed to create shortcut"),
2790 _("Can not insert shortcut to the list"));
2796 void PrefShortcuts::shortcutCancelPressed()
2798 shortcut_->shortcutWG->reset();
2802 void PrefShortcuts::shortcutClearPressed()
2804 shortcut_->shortcutWG->reset();
2808 void PrefShortcuts::shortcutRemovePressed()
2810 shortcut_->shortcutWG->removeFromSequence();
2814 /////////////////////////////////////////////////////////////////////
2818 /////////////////////////////////////////////////////////////////////
2820 PrefIdentity::PrefIdentity(GuiPreferences * form)
2821 : PrefModule(QString(), qt_("Identity"), form)
2825 connect(nameED, SIGNAL(textChanged(QString)),
2826 this, SIGNAL(changed()));
2827 connect(emailED, SIGNAL(textChanged(QString)),
2828 this, SIGNAL(changed()));
2832 void PrefIdentity::apply(LyXRC & rc) const
2834 rc.user_name = fromqstr(nameED->text());
2835 rc.user_email = fromqstr(emailED->text());
2839 void PrefIdentity::update(LyXRC const & rc)
2841 nameED->setText(toqstr(rc.user_name));
2842 emailED->setText(toqstr(rc.user_email));
2847 /////////////////////////////////////////////////////////////////////
2851 /////////////////////////////////////////////////////////////////////
2853 GuiPreferences::GuiPreferences(GuiView & lv)
2854 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2858 QDialog::setModal(false);
2860 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2861 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2862 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2863 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2865 addModule(new PrefUserInterface(this));
2866 addModule(new PrefEdit(this));
2867 addModule(new PrefShortcuts(this));
2868 addModule(new PrefScreenFonts(this));
2869 addModule(new PrefColors(this));
2870 addModule(new PrefDisplay(this));
2871 addModule(new PrefInput(this));
2872 addModule(new PrefCompletion(this));
2874 addModule(new PrefPaths(this));
2876 addModule(new PrefIdentity(this));
2878 addModule(new PrefLanguage(this));
2879 addModule(new PrefSpellchecker(this));
2881 addModule(new PrefPrinter(this));
2882 PrefDate * dateFormat = new PrefDate(this);
2883 addModule(dateFormat);
2884 addModule(new PrefPlaintext(this));
2885 addModule(new PrefLatex(this));
2887 PrefConverters * converters = new PrefConverters(this);
2888 PrefFileformats * formats = new PrefFileformats(this);
2889 connect(formats, SIGNAL(formatsChanged()),
2890 converters, SLOT(updateGui()));
2891 addModule(converters);
2894 prefsPS->setCurrentPanel(qt_("User interface"));
2895 // FIXME: hack to work around resizing bug in Qt >= 4.2
2896 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2897 #if QT_VERSION >= 0x040200
2898 prefsPS->updateGeometry();
2901 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2903 bc().setApply(applyPB);
2904 bc().setCancel(closePB);
2905 bc().setRestore(restorePB);
2907 // initialize the strftime validator
2908 bc().addCheckedLineEdit(dateFormat->DateED);
2912 void GuiPreferences::addModule(PrefModule * module)
2914 LASSERT(module, return);
2915 if (module->category().isEmpty())
2916 prefsPS->addPanel(module, module->title());
2918 prefsPS->addPanel(module, module->title(), module->category());
2919 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2920 modules_.push_back(module);
2924 void GuiPreferences::change_adaptor()
2930 void GuiPreferences::apply(LyXRC & rc) const
2932 size_t end = modules_.size();
2933 for (size_t i = 0; i != end; ++i)
2934 modules_[i]->apply(rc);
2938 void GuiPreferences::updateRc(LyXRC const & rc)
2940 size_t const end = modules_.size();
2941 for (size_t i = 0; i != end; ++i)
2942 modules_[i]->update(rc);
2946 void GuiPreferences::applyView()
2951 bool GuiPreferences::initialiseParams(string const &)
2954 formats_ = lyx::formats;
2955 converters_ = theConverters();
2956 converters_.update(formats_);
2957 movers_ = theMovers();
2959 update_screen_font_ = false;
2962 // Make sure that the bc is in the INITIAL state
2963 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
2970 void GuiPreferences::dispatchParams()
2973 rc_.write(ss, true);
2974 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
2975 // FIXME: these need lfuns
2977 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
2979 lyx::formats = formats_;
2981 theConverters() = converters_;
2982 theConverters().update(lyx::formats);
2983 theConverters().buildGraph();
2985 theMovers() = movers_;
2987 vector<string>::const_iterator it = colors_.begin();
2988 vector<string>::const_iterator const end = colors_.end();
2989 for (; it != end; ++it)
2990 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
2993 if (update_screen_font_) {
2994 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2995 update_screen_font_ = false;
2998 // The Save button has been pressed
3000 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
3004 void GuiPreferences::setColor(ColorCode col, QString const & hex)
3006 colors_.push_back(lcolor.getLyXName(col) + ' ' + fromqstr(hex));
3010 void GuiPreferences::updateScreenFonts()
3012 update_screen_font_ = true;
3016 QString GuiPreferences::browsebind(QString const & file) const
3018 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
3019 QStringList(qt_("LyX bind files (*.bind)")));
3023 QString GuiPreferences::browseUI(QString const & file) const
3025 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
3026 QStringList(qt_("LyX UI files (*.ui)")));
3030 QString GuiPreferences::browsekbmap(QString const & file) const
3032 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
3033 QStringList(qt_("LyX keyboard maps (*.kmap)")));
3037 QString GuiPreferences::browse(QString const & file,
3038 QString const & title) const
3040 return browseFile(file, title, QStringList(), true);
3044 // We support less paper sizes than the document dialog
3045 // Therefore this adjustment is needed.
3046 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
3050 return PAPER_DEFAULT;
3052 return PAPER_USLETTER;
3054 return PAPER_USLEGAL;
3056 return PAPER_USEXECUTIVE;
3066 // should not happen
3067 return PAPER_DEFAULT;
3072 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
3074 switch (papersize) {
3077 case PAPER_USLETTER:
3081 case PAPER_USEXECUTIVE:
3092 // should not happen
3098 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
3101 } // namespace frontend
3104 #include "moc_GuiPrefs.cpp"