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 << '\'');
327 /////////////////////////////////////////////////////////////////////
331 /////////////////////////////////////////////////////////////////////
333 class StrftimeValidator : public QValidator
336 StrftimeValidator(QWidget *);
337 QValidator::State validate(QString & input, int & pos) const;
341 StrftimeValidator::StrftimeValidator(QWidget * parent)
347 QValidator::State StrftimeValidator::validate(QString & input, int & /*pos*/) const
349 if (is_valid_strftime(fromqstr(input)))
350 return QValidator::Acceptable;
352 return QValidator::Intermediate;
356 /////////////////////////////////////////////////////////////////////
360 /////////////////////////////////////////////////////////////////////
362 PrefOutput::PrefOutput(GuiPreferences * form)
363 : PrefModule(qt_(catOutput), qt_("General"), form)
366 DateED->setValidator(new StrftimeValidator(DateED));
367 connect(DateED, SIGNAL(textChanged(QString)),
368 this, SIGNAL(changed()));
369 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
370 this, SIGNAL(changed()));
371 connect(dviCB, SIGNAL(textChanged(QString)),
372 this, SIGNAL(changed()));
373 connect(pdfCB, SIGNAL(textChanged(QString)),
374 this, SIGNAL(changed()));
376 dviCB->addItem("xdvi -sourceposition $$n:$$t $$o");
377 dviCB->addItem("yap -1 -s $$n$$t $$o");
379 pdfCB->addItem("CMCDDE SUMATRA control [ForwardSearch(\\\"$$o\\\",\\\"$$t\\\",$$n,0,0,1)]");
383 void PrefOutput::on_DateED_textChanged(const QString &)
385 QString t = DateED->text();
387 bool valid = DateED->validator()->validate(t, p)
388 == QValidator::Acceptable;
389 setValid(DateLA, valid);
393 void PrefOutput::apply(LyXRC & rc) const
395 rc.date_insert_format = fromqstr(DateED->text());
396 rc.plaintext_linelen = plaintextLinelengthSB->value();
397 rc.forward_search_dvi = fromqstr(dviCB->currentText());
398 rc.forward_search_pdf = fromqstr(pdfCB->currentText());
402 void PrefOutput::update(LyXRC const & rc)
404 DateED->setText(toqstr(rc.date_insert_format));
405 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
406 dviCB->setEditText(toqstr(rc.forward_search_dvi));
407 pdfCB->setEditText(toqstr(rc.forward_search_pdf));
411 /////////////////////////////////////////////////////////////////////
415 /////////////////////////////////////////////////////////////////////
417 PrefInput::PrefInput(GuiPreferences * form)
418 : PrefModule(qt_(catEditing), qt_("Keyboard/Mouse"), form)
422 connect(keymapCB, SIGNAL(clicked()),
423 this, SIGNAL(changed()));
424 connect(firstKeymapED, SIGNAL(textChanged(QString)),
425 this, SIGNAL(changed()));
426 connect(secondKeymapED, SIGNAL(textChanged(QString)),
427 this, SIGNAL(changed()));
428 connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
429 this, SIGNAL(changed()));
433 void PrefInput::apply(LyXRC & rc) const
435 // FIXME: can derive CB from the two EDs
436 rc.use_kbmap = keymapCB->isChecked();
437 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
438 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
439 rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
443 void PrefInput::update(LyXRC const & rc)
445 // FIXME: can derive CB from the two EDs
446 keymapCB->setChecked(rc.use_kbmap);
447 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
448 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
449 mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
453 QString PrefInput::testKeymap(QString const & keymap)
455 return form_->browsekbmap(internalPath(keymap));
459 void PrefInput::on_firstKeymapPB_clicked(bool)
461 QString const file = testKeymap(firstKeymapED->text());
463 firstKeymapED->setText(file);
467 void PrefInput::on_secondKeymapPB_clicked(bool)
469 QString const file = testKeymap(secondKeymapED->text());
471 secondKeymapED->setText(file);
475 void PrefInput::on_keymapCB_toggled(bool keymap)
477 firstKeymapLA->setEnabled(keymap);
478 secondKeymapLA->setEnabled(keymap);
479 firstKeymapED->setEnabled(keymap);
480 secondKeymapED->setEnabled(keymap);
481 firstKeymapPB->setEnabled(keymap);
482 secondKeymapPB->setEnabled(keymap);
486 /////////////////////////////////////////////////////////////////////
490 /////////////////////////////////////////////////////////////////////
492 PrefCompletion::PrefCompletion(GuiPreferences * form)
493 : PrefModule(qt_(catEditing), qt_("Input Completion"), form)
497 connect(inlineDelaySB, SIGNAL(valueChanged(double)),
498 this, SIGNAL(changed()));
499 connect(inlineMathCB, SIGNAL(clicked()),
500 this, SIGNAL(changed()));
501 connect(inlineTextCB, SIGNAL(clicked()),
502 this, SIGNAL(changed()));
503 connect(inlineDotsCB, SIGNAL(clicked()),
504 this, SIGNAL(changed()));
505 connect(popupDelaySB, SIGNAL(valueChanged(double)),
506 this, SIGNAL(changed()));
507 connect(popupMathCB, SIGNAL(clicked()),
508 this, SIGNAL(changed()));
509 connect(autocorrectionCB, SIGNAL(clicked()),
510 this, SIGNAL(changed()));
511 connect(popupTextCB, SIGNAL(clicked()),
512 this, SIGNAL(changed()));
513 connect(popupAfterCompleteCB, SIGNAL(clicked()),
514 this, SIGNAL(changed()));
515 connect(cursorTextCB, SIGNAL(clicked()),
516 this, SIGNAL(changed()));
520 void PrefCompletion::on_inlineTextCB_clicked()
526 void PrefCompletion::on_popupTextCB_clicked()
532 void PrefCompletion::enableCB()
534 cursorTextCB->setEnabled(
535 popupTextCB->isChecked() || inlineTextCB->isChecked());
539 void PrefCompletion::apply(LyXRC & rc) const
541 rc.completion_inline_delay = inlineDelaySB->value();
542 rc.completion_inline_math = inlineMathCB->isChecked();
543 rc.completion_inline_text = inlineTextCB->isChecked();
544 rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
545 rc.completion_popup_delay = popupDelaySB->value();
546 rc.completion_popup_math = popupMathCB->isChecked();
547 rc.autocorrection_math = autocorrectionCB->isChecked();
548 rc.completion_popup_text = popupTextCB->isChecked();
549 rc.completion_cursor_text = cursorTextCB->isChecked();
550 rc.completion_popup_after_complete =
551 popupAfterCompleteCB->isChecked();
555 void PrefCompletion::update(LyXRC const & rc)
557 inlineDelaySB->setValue(rc.completion_inline_delay);
558 inlineMathCB->setChecked(rc.completion_inline_math);
559 inlineTextCB->setChecked(rc.completion_inline_text);
560 inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
561 popupDelaySB->setValue(rc.completion_popup_delay);
562 popupMathCB->setChecked(rc.completion_popup_math);
563 autocorrectionCB->setChecked(rc.autocorrection_math);
564 popupTextCB->setChecked(rc.completion_popup_text);
565 cursorTextCB->setChecked(rc.completion_cursor_text);
566 popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
572 /////////////////////////////////////////////////////////////////////
576 /////////////////////////////////////////////////////////////////////
578 PrefLatex::PrefLatex(GuiPreferences * form)
579 : PrefModule(qt_(catOutput), qt_("LaTeX"), form)
582 connect(latexEncodingCB, SIGNAL(clicked()),
583 this, SIGNAL(changed()));
584 connect(latexEncodingED, SIGNAL(textChanged(QString)),
585 this, SIGNAL(changed()));
586 connect(latexChecktexED, SIGNAL(textChanged(QString)),
587 this, SIGNAL(changed()));
588 connect(latexBibtexCO, SIGNAL(activated(int)),
589 this, SIGNAL(changed()));
590 connect(latexBibtexED, SIGNAL(textChanged(QString)),
591 this, SIGNAL(changed()));
592 connect(latexJBibtexED, SIGNAL(textChanged(QString)),
593 this, SIGNAL(changed()));
594 connect(latexIndexCO, SIGNAL(activated(int)),
595 this, SIGNAL(changed()));
596 connect(latexIndexED, SIGNAL(textChanged(QString)),
597 this, SIGNAL(changed()));
598 connect(latexJIndexED, SIGNAL(textChanged(QString)),
599 this, SIGNAL(changed()));
600 connect(latexAutoresetCB, SIGNAL(clicked()),
601 this, SIGNAL(changed()));
602 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
603 this, SIGNAL(changed()));
604 connect(latexPaperSizeCO, SIGNAL(activated(int)),
605 this, SIGNAL(changed()));
607 #if defined(__CYGWIN__) || defined(_WIN32)
608 pathCB->setVisible(true);
609 connect(pathCB, SIGNAL(clicked()),
610 this, SIGNAL(changed()));
612 pathCB->setVisible(false);
617 void PrefLatex::on_latexEncodingCB_stateChanged(int state)
619 latexEncodingED->setEnabled(state == Qt::Checked);
623 void PrefLatex::on_latexBibtexCO_activated(int n)
625 QString const bibtex = latexBibtexCO->itemData(n).toString();
626 if (bibtex.isEmpty()) {
627 latexBibtexED->clear();
628 latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
631 for (LyXRC::CommandSet::const_iterator it = bibtex_alternatives.begin();
632 it != bibtex_alternatives.end(); ++it) {
633 QString const bib = toqstr(*it);
634 int ind = bib.indexOf(" ");
635 QString sel_command = bib.left(ind);
636 QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
637 if (bibtex == sel_command) {
639 latexBibtexED->clear();
641 latexBibtexED->setText(sel_options.trimmed());
644 latexBibtexOptionsLA->setText(qt_("&Options:"));
648 void PrefLatex::on_latexIndexCO_activated(int n)
650 QString const index = latexIndexCO->itemData(n).toString();
651 if (index.isEmpty()) {
652 latexIndexED->clear();
653 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
656 for (LyXRC::CommandSet::const_iterator it = index_alternatives.begin();
657 it != index_alternatives.end(); ++it) {
658 QString const idx = toqstr(*it);
659 int ind = idx.indexOf(" ");
660 QString sel_command = idx.left(ind);
661 QString sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
662 if (index == sel_command) {
664 latexIndexED->clear();
666 latexIndexED->setText(sel_options.trimmed());
669 latexIndexOptionsLA->setText(qt_("Op&tions:"));
673 void PrefLatex::apply(LyXRC & rc) const
675 // If bibtex is not empty, bibopt contains the options, otherwise
676 // it is a customized bibtex command with options.
677 QString const bibtex = latexBibtexCO->itemData(
678 latexBibtexCO->currentIndex()).toString();
679 QString const bibopt = latexBibtexED->text();
680 if (bibtex.isEmpty())
681 rc.bibtex_command = fromqstr(bibopt);
682 else if (bibopt.isEmpty())
683 rc.bibtex_command = fromqstr(bibtex);
685 rc.bibtex_command = fromqstr(bibtex) + " " + fromqstr(bibopt);
687 // If index is not empty, idxopt contains the options, otherwise
688 // it is a customized index command with options.
689 QString const index = latexIndexCO->itemData(
690 latexIndexCO->currentIndex()).toString();
691 QString const idxopt = latexIndexED->text();
693 rc.index_command = fromqstr(idxopt);
694 else if (idxopt.isEmpty())
695 rc.index_command = fromqstr(index);
697 rc.index_command = fromqstr(index) + " " + fromqstr(idxopt);
699 if (latexEncodingCB->isChecked())
700 rc.fontenc = fromqstr(latexEncodingED->text());
702 rc.fontenc = "default";
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 if (rc.fontenc == "default") {
774 latexEncodingCB->setChecked(false);
775 latexEncodingED->setEnabled(false);
777 latexEncodingCB->setChecked(true);
778 latexEncodingED->setEnabled(true);
779 latexEncodingED->setText(toqstr(rc.fontenc));
781 latexChecktexED->setText(toqstr(rc.chktex_command));
782 latexJBibtexED->setText(toqstr(rc.jbibtex_command));
783 latexJIndexED->setText(toqstr(rc.jindex_command));
784 latexNomenclED->setText(toqstr(rc.nomencl_command));
785 latexAutoresetCB->setChecked(rc.auto_reset_options);
786 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
787 latexPaperSizeCO->setCurrentIndex(
788 form_->fromPaperSize(rc.default_papersize));
789 #if defined(__CYGWIN__) || defined(_WIN32)
790 pathCB->setChecked(rc.windows_style_tex_paths);
795 /////////////////////////////////////////////////////////////////////
799 /////////////////////////////////////////////////////////////////////
801 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form)
802 : PrefModule(qt_(catLookAndFeel), qt_("Screen fonts"), form)
806 connect(screenRomanCO, SIGNAL(activated(QString)),
807 this, SLOT(selectRoman(QString)));
808 connect(screenSansCO, SIGNAL(activated(QString)),
809 this, SLOT(selectSans(QString)));
810 connect(screenTypewriterCO, SIGNAL(activated(QString)),
811 this, SLOT(selectTypewriter(QString)));
813 QFontDatabase fontdb;
814 QStringList families(fontdb.families());
815 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
816 screenRomanCO->addItem(*it);
817 screenSansCO->addItem(*it);
818 screenTypewriterCO->addItem(*it);
820 connect(screenRomanCO, SIGNAL(activated(QString)),
821 this, SIGNAL(changed()));
822 connect(screenSansCO, SIGNAL(activated(QString)),
823 this, SIGNAL(changed()));
824 connect(screenTypewriterCO, SIGNAL(activated(QString)),
825 this, SIGNAL(changed()));
826 connect(screenZoomSB, SIGNAL(valueChanged(int)),
827 this, SIGNAL(changed()));
828 connect(screenDpiSB, SIGNAL(valueChanged(int)),
829 this, SIGNAL(changed()));
830 connect(screenTinyED, SIGNAL(textChanged(QString)),
831 this, SIGNAL(changed()));
832 connect(screenSmallestED, SIGNAL(textChanged(QString)),
833 this, SIGNAL(changed()));
834 connect(screenSmallerED, SIGNAL(textChanged(QString)),
835 this, SIGNAL(changed()));
836 connect(screenSmallED, SIGNAL(textChanged(QString)),
837 this, SIGNAL(changed()));
838 connect(screenNormalED, SIGNAL(textChanged(QString)),
839 this, SIGNAL(changed()));
840 connect(screenLargeED, SIGNAL(textChanged(QString)),
841 this, SIGNAL(changed()));
842 connect(screenLargerED, SIGNAL(textChanged(QString)),
843 this, SIGNAL(changed()));
844 connect(screenLargestED, SIGNAL(textChanged(QString)),
845 this, SIGNAL(changed()));
846 connect(screenHugeED, SIGNAL(textChanged(QString)),
847 this, SIGNAL(changed()));
848 connect(screenHugerED, SIGNAL(textChanged(QString)),
849 this, SIGNAL(changed()));
850 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
851 this, SIGNAL(changed()));
853 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
854 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
855 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
856 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
857 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
858 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
859 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
860 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
861 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
862 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
866 void PrefScreenFonts::apply(LyXRC & rc) const
868 LyXRC const oldrc = rc;
870 parseFontName(screenRomanCO->currentText(),
871 rc.roman_font_name, rc.roman_font_foundry);
872 parseFontName(screenSansCO->currentText(),
873 rc.sans_font_name, rc.sans_font_foundry);
874 parseFontName(screenTypewriterCO->currentText(),
875 rc.typewriter_font_name, rc.typewriter_font_foundry);
877 rc.zoom = screenZoomSB->value();
878 rc.dpi = screenDpiSB->value();
879 rc.font_sizes[FONT_SIZE_TINY] = widgetToDoubleStr(screenTinyED);
880 rc.font_sizes[FONT_SIZE_SCRIPT] = widgetToDoubleStr(screenSmallestED);
881 rc.font_sizes[FONT_SIZE_FOOTNOTE] = widgetToDoubleStr(screenSmallerED);
882 rc.font_sizes[FONT_SIZE_SMALL] = widgetToDoubleStr(screenSmallED);
883 rc.font_sizes[FONT_SIZE_NORMAL] = widgetToDoubleStr(screenNormalED);
884 rc.font_sizes[FONT_SIZE_LARGE] = widgetToDoubleStr(screenLargeED);
885 rc.font_sizes[FONT_SIZE_LARGER] = widgetToDoubleStr(screenLargerED);
886 rc.font_sizes[FONT_SIZE_LARGEST] = widgetToDoubleStr(screenLargestED);
887 rc.font_sizes[FONT_SIZE_HUGE] = widgetToDoubleStr(screenHugeED);
888 rc.font_sizes[FONT_SIZE_HUGER] = widgetToDoubleStr(screenHugerED);
889 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
891 if (rc.font_sizes != oldrc.font_sizes
892 || rc.roman_font_name != oldrc.roman_font_name
893 || rc.sans_font_name != oldrc.sans_font_name
894 || rc.typewriter_font_name != oldrc.typewriter_font_name
895 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
896 // The global QPixmapCache is used in GuiPainter to cache text
897 // painting so we must reset it in case any of the above
898 // parameter is changed.
899 QPixmapCache::clear();
900 guiApp->fontLoader().update();
901 form_->updateScreenFonts();
906 void PrefScreenFonts::update(LyXRC const & rc)
908 setComboxFont(screenRomanCO, rc.roman_font_name,
909 rc.roman_font_foundry);
910 setComboxFont(screenSansCO, rc.sans_font_name,
911 rc.sans_font_foundry);
912 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
913 rc.typewriter_font_foundry);
915 selectRoman(screenRomanCO->currentText());
916 selectSans(screenSansCO->currentText());
917 selectTypewriter(screenTypewriterCO->currentText());
919 screenZoomSB->setValue(rc.zoom);
920 screenDpiSB->setValue(rc.dpi);
921 doubleToWidget(screenTinyED, rc.font_sizes[FONT_SIZE_TINY]);
922 doubleToWidget(screenSmallestED, rc.font_sizes[FONT_SIZE_SCRIPT]);
923 doubleToWidget(screenSmallerED, rc.font_sizes[FONT_SIZE_FOOTNOTE]);
924 doubleToWidget(screenSmallED, rc.font_sizes[FONT_SIZE_SMALL]);
925 doubleToWidget(screenNormalED, rc.font_sizes[FONT_SIZE_NORMAL]);
926 doubleToWidget(screenLargeED, rc.font_sizes[FONT_SIZE_LARGE]);
927 doubleToWidget(screenLargerED, rc.font_sizes[FONT_SIZE_LARGER]);
928 doubleToWidget(screenLargestED, rc.font_sizes[FONT_SIZE_LARGEST]);
929 doubleToWidget(screenHugeED, rc.font_sizes[FONT_SIZE_HUGE]);
930 doubleToWidget(screenHugerED, rc.font_sizes[FONT_SIZE_HUGER]);
932 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
933 #if defined(Q_WS_X11)
934 pixmapCacheCB->setEnabled(false);
940 void PrefScreenFonts::selectRoman(const QString & name)
942 screenRomanFE->set(QFont(name), name);
946 void PrefScreenFonts::selectSans(const QString & name)
948 screenSansFE->set(QFont(name), name);
952 void PrefScreenFonts::selectTypewriter(const QString & name)
954 screenTypewriterFE->set(QFont(name), name);
958 /////////////////////////////////////////////////////////////////////
962 /////////////////////////////////////////////////////////////////////
968 bool operator()(ColorCode lhs, ColorCode rhs) const {
970 compare_no_case(lcolor.getGUIName(lhs), lcolor.getGUIName(rhs)) < 0;
976 PrefColors::PrefColors(GuiPreferences * form)
977 : PrefModule(qt_(catLookAndFeel), qt_("Colors"), form)
981 // FIXME: all of this initialization should be put into the controller.
982 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
983 // for some discussion of why that is not trivial.
984 QPixmap icon(32, 32);
985 for (int i = 0; i < Color_ignore; ++i) {
986 ColorCode lc = static_cast<ColorCode>(i);
994 || lc == Color_magenta
995 || lc == Color_yellow
996 || lc == Color_inherit
997 || lc == Color_ignore
998 || lc == Color_greyedouttext
999 || lc == Color_shadedbg) continue;
1001 lcolors_.push_back(lc);
1003 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
1004 vector<ColorCode>::const_iterator cit = lcolors_.begin();
1005 vector<ColorCode>::const_iterator const end = lcolors_.end();
1006 for (; cit != end; ++cit) {
1007 (void) new QListWidgetItem(QIcon(icon),
1008 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
1010 curcolors_.resize(lcolors_.size());
1011 newcolors_.resize(lcolors_.size());
1012 // End initialization
1014 connect(colorChangePB, SIGNAL(clicked()),
1015 this, SLOT(changeColor()));
1016 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
1017 this, SLOT(changeLyxObjectsSelection()));
1018 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
1019 this, SLOT(changeColor()));
1023 void PrefColors::apply(LyXRC & /*rc*/) const
1025 for (unsigned int i = 0; i < lcolors_.size(); ++i)
1026 if (curcolors_[i] != newcolors_[i])
1027 form_->setColor(lcolors_[i], newcolors_[i]);
1031 void PrefColors::update(LyXRC const & /*rc*/)
1033 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
1034 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
1035 QPixmap coloritem(32, 32);
1036 coloritem.fill(color);
1037 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
1038 newcolors_[i] = curcolors_[i] = color.name();
1040 changeLyxObjectsSelection();
1044 void PrefColors::changeColor()
1046 int const row = lyxObjectsLW->currentRow();
1052 QString const color = newcolors_[row];
1053 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
1055 if (c.isValid() && c.name() != color) {
1056 newcolors_[row] = c.name();
1057 QPixmap coloritem(32, 32);
1059 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
1065 void PrefColors::changeLyxObjectsSelection()
1067 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
1071 /////////////////////////////////////////////////////////////////////
1075 /////////////////////////////////////////////////////////////////////
1077 PrefDisplay::PrefDisplay(GuiPreferences * form)
1078 : PrefModule(qt_(catLookAndFeel), qt_("Display"), form)
1081 connect(displayGraphicsCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
1082 connect(instantPreviewCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
1083 connect(previewSizeSB, SIGNAL(valueChanged(double)), this, SIGNAL(changed()));
1084 connect(paragraphMarkerCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
1085 if (instantPreviewCO->currentIndex() == 0)
1086 previewSizeSB->setEnabled(false);
1088 previewSizeSB->setEnabled(true);
1092 void PrefDisplay::on_instantPreviewCO_currentIndexChanged(int index)
1095 previewSizeSB->setEnabled(false);
1097 previewSizeSB->setEnabled(true);
1101 void PrefDisplay::apply(LyXRC & rc) const
1103 switch (instantPreviewCO->currentIndex()) {
1104 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
1105 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
1106 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
1109 rc.display_graphics = displayGraphicsCB->isChecked();
1110 rc.preview_scale_factor = previewSizeSB->value();
1111 rc.paragraph_markers = paragraphMarkerCB->isChecked();
1113 // FIXME!! The graphics cache no longer has a changeDisplay method.
1115 if (old_value != rc.display_graphics) {
1116 graphics::GCache & gc = graphics::GCache::get();
1123 void PrefDisplay::update(LyXRC const & rc)
1125 switch (rc.preview) {
1126 case LyXRC::PREVIEW_OFF:
1127 instantPreviewCO->setCurrentIndex(0);
1129 case LyXRC::PREVIEW_NO_MATH :
1130 instantPreviewCO->setCurrentIndex(1);
1132 case LyXRC::PREVIEW_ON :
1133 instantPreviewCO->setCurrentIndex(2);
1137 displayGraphicsCB->setChecked(rc.display_graphics);
1138 instantPreviewCO->setEnabled(rc.display_graphics);
1139 previewSizeSB->setValue(rc.preview_scale_factor);
1140 paragraphMarkerCB->setChecked(rc.paragraph_markers);
1144 /////////////////////////////////////////////////////////////////////
1148 /////////////////////////////////////////////////////////////////////
1150 PrefPaths::PrefPaths(GuiPreferences * form)
1151 : PrefModule(QString(), qt_("Paths"), form)
1155 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(selectWorkingdir()));
1156 connect(workingDirED, SIGNAL(textChanged(QString)),
1157 this, SIGNAL(changed()));
1159 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(selectTemplatedir()));
1160 connect(templateDirED, SIGNAL(textChanged(QString)),
1161 this, SIGNAL(changed()));
1163 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(selectExampledir()));
1164 connect(exampleDirED, SIGNAL(textChanged(QString)),
1165 this, SIGNAL(changed()));
1167 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(selectBackupdir()));
1168 connect(backupDirED, SIGNAL(textChanged(QString)),
1169 this, SIGNAL(changed()));
1171 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(selectLyxPipe()));
1172 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
1173 this, SIGNAL(changed()));
1175 connect(thesaurusDirPB, SIGNAL(clicked()), this, SLOT(selectThesaurusdir()));
1176 connect(thesaurusDirED, SIGNAL(textChanged(QString)),
1177 this, SIGNAL(changed()));
1179 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(selectTempdir()));
1180 connect(tempDirED, SIGNAL(textChanged(QString)),
1181 this, SIGNAL(changed()));
1183 connect(hunspellDirPB, SIGNAL(clicked()), this, SLOT(selectHunspelldir()));
1184 connect(hunspellDirED, SIGNAL(textChanged(QString)),
1185 this, SIGNAL(changed()));
1187 connect(pathPrefixED, SIGNAL(textChanged(QString)),
1188 this, SIGNAL(changed()));
1192 void PrefPaths::apply(LyXRC & rc) const
1194 rc.document_path = internal_path(fromqstr(workingDirED->text()));
1195 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
1196 rc.template_path = internal_path(fromqstr(templateDirED->text()));
1197 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
1198 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
1199 rc.thesaurusdir_path = internal_path(fromqstr(thesaurusDirED->text()));
1200 rc.hunspelldir_path = internal_path(fromqstr(hunspellDirED->text()));
1201 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
1202 // FIXME: should be a checkbox only
1203 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
1207 void PrefPaths::update(LyXRC const & rc)
1209 workingDirED->setText(toqstr(external_path(rc.document_path)));
1210 exampleDirED->setText(toqstr(external_path(rc.example_path)));
1211 templateDirED->setText(toqstr(external_path(rc.template_path)));
1212 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
1213 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
1214 thesaurusDirED->setText(toqstr(external_path(rc.thesaurusdir_path)));
1215 hunspellDirED->setText(toqstr(external_path(rc.hunspelldir_path)));
1216 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
1217 // FIXME: should be a checkbox only
1218 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
1222 void PrefPaths::selectExampledir()
1224 QString file = browseDir(internalPath(exampleDirED->text()),
1225 qt_("Select directory for example files"));
1226 if (!file.isEmpty())
1227 exampleDirED->setText(file);
1231 void PrefPaths::selectTemplatedir()
1233 QString file = browseDir(internalPath(templateDirED->text()),
1234 qt_("Select a document templates directory"));
1235 if (!file.isEmpty())
1236 templateDirED->setText(file);
1240 void PrefPaths::selectTempdir()
1242 QString file = browseDir(internalPath(tempDirED->text()),
1243 qt_("Select a temporary directory"));
1244 if (!file.isEmpty())
1245 tempDirED->setText(file);
1249 void PrefPaths::selectBackupdir()
1251 QString file = browseDir(internalPath(backupDirED->text()),
1252 qt_("Select a backups directory"));
1253 if (!file.isEmpty())
1254 backupDirED->setText(file);
1258 void PrefPaths::selectWorkingdir()
1260 QString file = browseDir(internalPath(workingDirED->text()),
1261 qt_("Select a document directory"));
1262 if (!file.isEmpty())
1263 workingDirED->setText(file);
1267 void PrefPaths::selectThesaurusdir()
1269 QString file = browseDir(internalPath(thesaurusDirED->text()),
1270 qt_("Set the path to the thesaurus dictionaries"));
1271 if (!file.isEmpty())
1272 thesaurusDirED->setText(file);
1276 void PrefPaths::selectHunspelldir()
1278 QString file = browseDir(internalPath(hunspellDirED->text()),
1279 qt_("Set the path to the Hunspell dictionaries"));
1280 if (!file.isEmpty())
1281 hunspellDirED->setText(file);
1285 void PrefPaths::selectLyxPipe()
1287 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1288 qt_("Give a filename for the LyX server pipe"));
1289 if (!file.isEmpty())
1290 lyxserverDirED->setText(file);
1294 /////////////////////////////////////////////////////////////////////
1298 /////////////////////////////////////////////////////////////////////
1300 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form)
1301 : PrefModule(qt_(catLanguage), qt_("Spellchecker"), form)
1305 #if defined(USE_ASPELL)
1306 spellcheckerCB->addItem(qt_("aspell"), QString("aspell"));
1308 #if defined(USE_ENCHANT)
1309 spellcheckerCB->addItem(qt_("enchant"), QString("enchant"));
1311 #if defined(USE_HUNSPELL)
1312 spellcheckerCB->addItem(qt_("hunspell"), QString("hunspell"));
1315 #if defined(USE_ASPELL) || defined(USE_ENCHANT) || defined(USE_HUNSPELL)
1316 connect(spellcheckerCB, SIGNAL(currentIndexChanged(int)),
1317 this, SIGNAL(changed()));
1318 connect(altLanguageED, SIGNAL(textChanged(QString)),
1319 this, SIGNAL(changed()));
1320 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1321 this, SIGNAL(changed()));
1322 connect(compoundWordCB, SIGNAL(clicked()),
1323 this, SIGNAL(changed()));
1324 connect(spellcheckContinuouslyCB, SIGNAL(clicked()),
1325 this, SIGNAL(changed()));
1326 connect(spellcheckNotesCB, SIGNAL(clicked()),
1327 this, SIGNAL(changed()));
1329 spellcheckerCB->setEnabled(false);
1330 altLanguageED->setEnabled(false);
1331 escapeCharactersED->setEnabled(false);
1332 compoundWordCB->setEnabled(false);
1333 spellcheckContinuouslyCB->setEnabled(false);
1334 spellcheckNotesCB->setEnabled(false);
1339 void PrefSpellchecker::apply(LyXRC & rc) const
1341 rc.spellchecker = fromqstr(spellcheckerCB->itemData(
1342 spellcheckerCB->currentIndex()).toString());
1343 rc.spellchecker_alt_lang = fromqstr(altLanguageED->text());
1344 rc.spellchecker_esc_chars = fromqstr(escapeCharactersED->text());
1345 rc.spellchecker_accept_compound = compoundWordCB->isChecked();
1346 rc.spellcheck_continuously = spellcheckContinuouslyCB->isChecked();
1347 rc.spellcheck_notes = spellcheckNotesCB->isChecked();
1351 void PrefSpellchecker::update(LyXRC const & rc)
1353 spellcheckerCB->setCurrentIndex(
1354 spellcheckerCB->findData(toqstr(rc.spellchecker)));
1355 altLanguageED->setText(toqstr(rc.spellchecker_alt_lang));
1356 escapeCharactersED->setText(toqstr(rc.spellchecker_esc_chars));
1357 compoundWordCB->setChecked(rc.spellchecker_accept_compound);
1358 spellcheckContinuouslyCB->setChecked(rc.spellcheck_continuously);
1359 spellcheckNotesCB->setChecked(rc.spellcheck_notes);
1364 /////////////////////////////////////////////////////////////////////
1368 /////////////////////////////////////////////////////////////////////
1371 PrefConverters::PrefConverters(GuiPreferences * form)
1372 : PrefModule(qt_(catFiles), qt_("Converters"), form)
1376 connect(converterNewPB, SIGNAL(clicked()),
1377 this, SLOT(updateConverter()));
1378 connect(converterRemovePB, SIGNAL(clicked()),
1379 this, SLOT(removeConverter()));
1380 connect(converterModifyPB, SIGNAL(clicked()),
1381 this, SLOT(updateConverter()));
1382 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1383 this, SLOT(switchConverter()));
1384 connect(converterFromCO, SIGNAL(activated(QString)),
1385 this, SLOT(changeConverter()));
1386 connect(converterToCO, SIGNAL(activated(QString)),
1387 this, SLOT(changeConverter()));
1388 connect(converterED, SIGNAL(textEdited(QString)),
1389 this, SLOT(changeConverter()));
1390 connect(converterFlagED, SIGNAL(textEdited(QString)),
1391 this, SLOT(changeConverter()));
1392 connect(converterNewPB, SIGNAL(clicked()),
1393 this, SIGNAL(changed()));
1394 connect(converterRemovePB, SIGNAL(clicked()),
1395 this, SIGNAL(changed()));
1396 connect(converterModifyPB, SIGNAL(clicked()),
1397 this, SIGNAL(changed()));
1398 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1399 this, SIGNAL(changed()));
1401 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1402 //converterDefGB->setFocusProxy(convertersLW);
1406 void PrefConverters::apply(LyXRC & rc) const
1408 rc.use_converter_cache = cacheCB->isChecked();
1409 rc.converter_cache_maxage = int(widgetToDouble(maxAgeLE) * 86400.0);
1413 void PrefConverters::update(LyXRC const & rc)
1415 cacheCB->setChecked(rc.use_converter_cache);
1417 doubleToWidget(maxAgeLE, (double(rc.converter_cache_maxage) / 86400.0), 'g', 6);
1422 void PrefConverters::updateGui()
1424 form_->formats().sort();
1425 form_->converters().update(form_->formats());
1426 // save current selection
1427 QString current = converterFromCO->currentText()
1428 + " -> " + converterToCO->currentText();
1430 converterFromCO->clear();
1431 converterToCO->clear();
1433 Formats::const_iterator cit = form_->formats().begin();
1434 Formats::const_iterator end = form_->formats().end();
1435 for (; cit != end; ++cit) {
1436 converterFromCO->addItem(qt_(cit->prettyname()));
1437 converterToCO->addItem(qt_(cit->prettyname()));
1440 // currentRowChanged(int) is also triggered when updating the listwidget
1441 // block signals to avoid unnecessary calls to switchConverter()
1442 convertersLW->blockSignals(true);
1443 convertersLW->clear();
1445 Converters::const_iterator ccit = form_->converters().begin();
1446 Converters::const_iterator cend = form_->converters().end();
1447 for (; ccit != cend; ++ccit) {
1448 QString const name =
1449 qt_(ccit->From->prettyname()) + " -> " + qt_(ccit->To->prettyname());
1450 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1451 new QListWidgetItem(name, convertersLW, type);
1453 convertersLW->sortItems(Qt::AscendingOrder);
1454 convertersLW->blockSignals(false);
1456 // restore selection
1457 if (!current.isEmpty()) {
1458 QList<QListWidgetItem *> const item =
1459 convertersLW->findItems(current, Qt::MatchExactly);
1460 if (!item.isEmpty())
1461 convertersLW->setCurrentItem(item.at(0));
1464 // select first element if restoring failed
1465 if (convertersLW->currentRow() == -1)
1466 convertersLW->setCurrentRow(0);
1472 void PrefConverters::switchConverter()
1474 int const cnr = convertersLW->currentItem()->type();
1475 Converter const & c(form_->converters().get(cnr));
1476 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1477 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1478 converterED->setText(toqstr(c.command));
1479 converterFlagED->setText(toqstr(c.flags));
1485 void PrefConverters::changeConverter()
1491 void PrefConverters::updateButtons()
1493 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1494 Format const & to = form_->formats().get(converterToCO->currentIndex());
1495 int const sel = form_->converters().getNumber(from.name(), to.name());
1496 bool const known = sel >= 0;
1497 bool const valid = !(converterED->text().isEmpty()
1498 || from.name() == to.name());
1500 int const cnr = convertersLW->currentItem()->type();
1501 Converter const & c = form_->converters().get(cnr);
1502 string const old_command = c.command;
1503 string const old_flag = c.flags;
1504 string const new_command = fromqstr(converterED->text());
1505 string const new_flag = fromqstr(converterFlagED->text());
1507 bool modified = (old_command != new_command || old_flag != new_flag);
1509 converterModifyPB->setEnabled(valid && known && modified);
1510 converterNewPB->setEnabled(valid && !known);
1511 converterRemovePB->setEnabled(known);
1513 maxAgeLE->setEnabled(cacheCB->isChecked());
1514 maxAgeLA->setEnabled(cacheCB->isChecked());
1519 // specify unique from/to or it doesn't appear. This is really bad UI
1520 // this is why we can use the same function for both new and modify
1521 void PrefConverters::updateConverter()
1523 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1524 Format const & to = form_->formats().get(converterToCO->currentIndex());
1525 string const flags = fromqstr(converterFlagED->text());
1526 string const command = fromqstr(converterED->text());
1528 Converter const * old =
1529 form_->converters().getConverter(from.name(), to.name());
1530 form_->converters().add(from.name(), to.name(), command, flags);
1533 form_->converters().updateLast(form_->formats());
1537 // Remove all files created by this converter from the cache, since
1538 // the modified converter might create different files.
1539 ConverterCache::get().remove_all(from.name(), to.name());
1543 void PrefConverters::removeConverter()
1545 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1546 Format const & to = form_->formats().get(converterToCO->currentIndex());
1547 form_->converters().erase(from.name(), to.name());
1551 // Remove all files created by this converter from the cache, since
1552 // a possible new converter might create different files.
1553 ConverterCache::get().remove_all(from.name(), to.name());
1557 void PrefConverters::on_cacheCB_stateChanged(int state)
1559 maxAgeLE->setEnabled(state == Qt::Checked);
1560 maxAgeLA->setEnabled(state == Qt::Checked);
1565 /////////////////////////////////////////////////////////////////////
1569 /////////////////////////////////////////////////////////////////////
1571 class FormatValidator : public QValidator
1574 FormatValidator(QWidget *, Formats const & f);
1575 void fixup(QString & input) const;
1576 QValidator::State validate(QString & input, int & pos) const;
1578 virtual QString toString(Format const & format) const = 0;
1580 Formats const & formats_;
1584 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1585 : QValidator(parent), formats_(f)
1590 void FormatValidator::fixup(QString & input) const
1592 Formats::const_iterator cit = formats_.begin();
1593 Formats::const_iterator end = formats_.end();
1594 for (; cit != end; ++cit) {
1595 QString const name = toString(*cit);
1596 if (distance(formats_.begin(), cit) == nr()) {
1604 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1606 Formats::const_iterator cit = formats_.begin();
1607 Formats::const_iterator end = formats_.end();
1608 bool unknown = true;
1609 for (; unknown && cit != end; ++cit) {
1610 QString const name = toString(*cit);
1611 if (distance(formats_.begin(), cit) != nr())
1612 unknown = name != input;
1615 if (unknown && !input.isEmpty())
1616 return QValidator::Acceptable;
1618 return QValidator::Intermediate;
1622 int FormatValidator::nr() const
1624 QComboBox * p = qobject_cast<QComboBox *>(parent());
1625 return p->itemData(p->currentIndex()).toInt();
1629 /////////////////////////////////////////////////////////////////////
1631 // FormatNameValidator
1633 /////////////////////////////////////////////////////////////////////
1635 class FormatNameValidator : public FormatValidator
1638 FormatNameValidator(QWidget * parent, Formats const & f)
1639 : FormatValidator(parent, f)
1642 QString toString(Format const & format) const
1644 return toqstr(format.name());
1649 /////////////////////////////////////////////////////////////////////
1651 // FormatPrettynameValidator
1653 /////////////////////////////////////////////////////////////////////
1655 class FormatPrettynameValidator : public FormatValidator
1658 FormatPrettynameValidator(QWidget * parent, Formats const & f)
1659 : FormatValidator(parent, f)
1662 QString toString(Format const & format) const
1664 return qt_(format.prettyname());
1669 /////////////////////////////////////////////////////////////////////
1673 /////////////////////////////////////////////////////////////////////
1675 PrefFileformats::PrefFileformats(GuiPreferences * form)
1676 : PrefModule(qt_(catFiles), qt_("File formats"), form)
1679 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1680 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1682 connect(documentCB, SIGNAL(clicked()),
1683 this, SLOT(setFlags()));
1684 connect(vectorCB, SIGNAL(clicked()),
1685 this, SLOT(setFlags()));
1686 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1687 this, SLOT(updatePrettyname()));
1688 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1689 this, SIGNAL(changed()));
1690 connect(defaultFormatCB, SIGNAL(activated(QString)),
1691 this, SIGNAL(changed()));
1692 connect(viewerCO, SIGNAL(activated(int)),
1693 this, SIGNAL(changed()));
1694 connect(editorCO, SIGNAL(activated(int)),
1695 this, SIGNAL(changed()));
1701 string const l10n_shortcut(string const prettyname, string const shortcut)
1703 if (shortcut.empty())
1706 string l10n_format =
1707 to_utf8(_(prettyname + '|' + shortcut));
1708 return split(l10n_format, '|');
1711 }; // namespace anon
1714 void PrefFileformats::apply(LyXRC & rc) const
1716 QString const default_format = defaultFormatCB->itemData(
1717 defaultFormatCB->currentIndex()).toString();
1718 rc.default_view_format = fromqstr(default_format);
1722 void PrefFileformats::update(LyXRC const & rc)
1724 viewer_alternatives = rc.viewer_alternatives;
1725 editor_alternatives = rc.editor_alternatives;
1726 bool const init = defaultFormatCB->currentText().isEmpty();
1730 defaultFormatCB->findData(toqstr(rc.default_view_format));
1731 defaultFormatCB->setCurrentIndex(pos);
1736 void PrefFileformats::updateView()
1738 QString const current = formatsCB->currentText();
1739 QString const current_def = defaultFormatCB->currentText();
1741 // update comboboxes with formats
1742 formatsCB->blockSignals(true);
1743 defaultFormatCB->blockSignals(true);
1745 defaultFormatCB->clear();
1746 form_->formats().sort();
1747 Formats::const_iterator cit = form_->formats().begin();
1748 Formats::const_iterator end = form_->formats().end();
1749 for (; cit != end; ++cit) {
1750 formatsCB->addItem(qt_(cit->prettyname()),
1751 QVariant(form_->formats().getNumber(cit->name())));
1752 if (form_->converters().isReachable("latex", cit->name())
1753 || form_->converters().isReachable("pdflatex", cit->name()))
1754 defaultFormatCB->addItem(qt_(cit->prettyname()),
1755 QVariant(toqstr(cit->name())));
1758 // restore selection
1759 int item = formatsCB->findText(current, Qt::MatchExactly);
1760 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1761 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1762 item = defaultFormatCB->findText(current_def, Qt::MatchExactly);
1763 defaultFormatCB->setCurrentIndex(item < 0 ? 0 : item);
1764 formatsCB->blockSignals(false);
1765 defaultFormatCB->blockSignals(false);
1769 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1771 int const nr = formatsCB->itemData(i).toInt();
1772 Format const f = form_->formats().get(nr);
1774 formatED->setText(toqstr(f.name()));
1775 copierED->setText(toqstr(form_->movers().command(f.name())));
1776 extensionED->setText(toqstr(f.extension()));
1777 shortcutED->setText(
1778 toqstr(l10n_shortcut(f.prettyname(), f.shortcut())));
1779 documentCB->setChecked((f.documentFormat()));
1780 vectorCB->setChecked((f.vectorFormat()));
1786 void PrefFileformats::setFlags()
1788 int flags = Format::none;
1789 if (documentCB->isChecked())
1790 flags |= Format::document;
1791 if (vectorCB->isChecked())
1792 flags |= Format::vector;
1793 currentFormat().setFlags(flags);
1798 void PrefFileformats::on_copierED_textEdited(const QString & s)
1800 string const fmt = fromqstr(formatED->text());
1801 form_->movers().set(fmt, fromqstr(s));
1806 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1808 currentFormat().setExtension(fromqstr(s));
1812 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1814 currentFormat().setViewer(fromqstr(s));
1819 void PrefFileformats::on_editorED_textEdited(const QString & s)
1821 currentFormat().setEditor(fromqstr(s));
1826 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1828 string const new_shortcut = fromqstr(s);
1829 if (new_shortcut == l10n_shortcut(currentFormat().prettyname(),
1830 currentFormat().shortcut()))
1832 currentFormat().setShortcut(new_shortcut);
1837 void PrefFileformats::on_formatED_editingFinished()
1839 string const newname = fromqstr(formatED->displayText());
1840 if (newname == currentFormat().name())
1843 currentFormat().setName(newname);
1848 void PrefFileformats::on_formatED_textChanged(const QString &)
1850 QString t = formatED->text();
1852 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1853 setValid(formatLA, valid);
1857 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1859 QString t = formatsCB->currentText();
1861 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1862 setValid(formatsLA, valid);
1866 void PrefFileformats::updatePrettyname()
1868 QString const newname = formatsCB->currentText();
1869 if (newname == qt_(currentFormat().prettyname()))
1872 currentFormat().setPrettyname(fromqstr(newname));
1880 void updateComboBox(LyXRC::Alternatives const & alts,
1881 string const & fmt, QComboBox * combo)
1883 LyXRC::Alternatives::const_iterator it =
1885 if (it != alts.end()) {
1886 LyXRC::CommandSet const & cmds = it->second;
1887 LyXRC::CommandSet::const_iterator sit =
1889 LyXRC::CommandSet::const_iterator const sen =
1891 for (; sit != sen; ++sit) {
1892 QString const qcmd = toqstr(*sit);
1893 combo->addItem(qcmd, qcmd);
1900 void PrefFileformats::updateViewers()
1902 Format const f = currentFormat();
1903 viewerCO->blockSignals(true);
1905 viewerCO->addItem(qt_("None"), QString());
1906 updateComboBox(viewer_alternatives, f.name(), viewerCO);
1907 viewerCO->addItem(qt_("Custom"), QString("custom viewer"));
1908 viewerCO->blockSignals(false);
1910 int pos = viewerCO->findData(toqstr(f.viewer()));
1913 viewerED->setEnabled(false);
1914 viewerCO->setCurrentIndex(pos);
1916 viewerED->setEnabled(true);
1917 viewerED->setText(toqstr(f.viewer()));
1918 viewerCO->setCurrentIndex(viewerCO->findData(toqstr("custom viewer")));
1923 void PrefFileformats::updateEditors()
1925 Format const f = currentFormat();
1926 editorCO->blockSignals(true);
1928 editorCO->addItem(qt_("None"), QString());
1929 updateComboBox(editor_alternatives, f.name(), editorCO);
1930 editorCO->addItem(qt_("Custom"), QString("custom editor"));
1931 editorCO->blockSignals(false);
1933 int pos = editorCO->findData(toqstr(f.editor()));
1936 editorED->setEnabled(false);
1937 editorCO->setCurrentIndex(pos);
1939 editorED->setEnabled(true);
1940 editorED->setText(toqstr(f.editor()));
1941 editorCO->setCurrentIndex(editorCO->findData(toqstr("custom editor")));
1946 void PrefFileformats::on_viewerCO_currentIndexChanged(int i)
1948 bool const custom = viewerCO->itemData(i).toString() == "custom viewer";
1949 viewerED->setEnabled(custom);
1951 currentFormat().setViewer(fromqstr(viewerCO->itemData(i).toString()));
1955 void PrefFileformats::on_editorCO_currentIndexChanged(int i)
1957 bool const custom = editorCO->itemData(i).toString() == "custom editor";
1958 editorED->setEnabled(custom);
1960 currentFormat().setEditor(fromqstr(editorCO->itemData(i).toString()));
1964 Format & PrefFileformats::currentFormat()
1966 int const i = formatsCB->currentIndex();
1967 int const nr = formatsCB->itemData(i).toInt();
1968 return form_->formats().get(nr);
1972 void PrefFileformats::on_formatNewPB_clicked()
1974 form_->formats().add("", "", "", "", "", "", Format::none);
1976 formatsCB->setCurrentIndex(0);
1977 formatsCB->setFocus(Qt::OtherFocusReason);
1981 void PrefFileformats::on_formatRemovePB_clicked()
1983 int const i = formatsCB->currentIndex();
1984 int const nr = formatsCB->itemData(i).toInt();
1985 string const current_text = form_->formats().get(nr).name();
1986 if (form_->converters().formatIsUsed(current_text)) {
1987 Alert::error(_("Format in use"),
1988 _("Cannot remove a Format used by a Converter. "
1989 "Remove the converter first."));
1993 form_->formats().erase(current_text);
1996 on_formatsCB_editTextChanged(formatsCB->currentText());
2001 /////////////////////////////////////////////////////////////////////
2005 /////////////////////////////////////////////////////////////////////
2007 PrefLanguage::PrefLanguage(GuiPreferences * form)
2008 : PrefModule(qt_(catLanguage), qt_("Language"), form)
2012 connect(rtlGB, SIGNAL(clicked()),
2013 this, SIGNAL(changed()));
2014 connect(visualCursorRB, SIGNAL(clicked()),
2015 this, SIGNAL(changed()));
2016 connect(logicalCursorRB, SIGNAL(clicked()),
2017 this, SIGNAL(changed()));
2018 connect(markForeignCB, SIGNAL(clicked()),
2019 this, SIGNAL(changed()));
2020 connect(autoBeginCB, SIGNAL(clicked()),
2021 this, SIGNAL(changed()));
2022 connect(autoEndCB, SIGNAL(clicked()),
2023 this, SIGNAL(changed()));
2024 connect(useBabelCB, SIGNAL(clicked()),
2025 this, SIGNAL(changed()));
2026 connect(globalCB, SIGNAL(clicked()),
2027 this, SIGNAL(changed()));
2028 connect(languagePackageED, SIGNAL(textChanged(QString)),
2029 this, SIGNAL(changed()));
2030 connect(startCommandED, SIGNAL(textChanged(QString)),
2031 this, SIGNAL(changed()));
2032 connect(endCommandED, SIGNAL(textChanged(QString)),
2033 this, SIGNAL(changed()));
2034 connect(uiLanguageCO, SIGNAL(activated(int)),
2035 this, SIGNAL(changed()));
2037 uiLanguageCO->clear();
2039 QAbstractItemModel * language_model = guiApp->languageModel();
2040 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
2041 language_model->sort(0);
2043 // FIXME: This is wrong, we need filter this list based on the available
2045 uiLanguageCO->blockSignals(true);
2046 uiLanguageCO->addItem(qt_("Default"), toqstr("auto"));
2047 for (int i = 0; i != language_model->rowCount(); ++i) {
2048 QModelIndex index = language_model->index(i, 0);
2049 uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
2050 index.data(Qt::UserRole).toString());
2052 uiLanguageCO->blockSignals(false);
2056 void PrefLanguage::on_uiLanguageCO_currentIndexChanged(int)
2058 QMessageBox::information(this, qt_("LyX needs to be restarted!"),
2059 qt_("The change of user interface language will be fully "
2060 "effective only after a restart."));
2064 void PrefLanguage::apply(LyXRC & rc) const
2066 // FIXME: remove rtl_support bool
2067 rc.rtl_support = rtlGB->isChecked();
2068 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
2069 rc.mark_foreign_language = markForeignCB->isChecked();
2070 rc.language_auto_begin = autoBeginCB->isChecked();
2071 rc.language_auto_end = autoEndCB->isChecked();
2072 rc.language_use_babel = useBabelCB->isChecked();
2073 rc.language_global_options = globalCB->isChecked();
2074 rc.language_package = fromqstr(languagePackageED->text());
2075 rc.language_command_begin = fromqstr(startCommandED->text());
2076 rc.language_command_end = fromqstr(endCommandED->text());
2077 rc.gui_language = fromqstr(
2078 uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString());
2082 void PrefLanguage::update(LyXRC const & rc)
2084 // FIXME: remove rtl_support bool
2085 rtlGB->setChecked(rc.rtl_support);
2086 if (rc.visual_cursor)
2087 visualCursorRB->setChecked(true);
2089 logicalCursorRB->setChecked(true);
2090 markForeignCB->setChecked(rc.mark_foreign_language);
2091 autoBeginCB->setChecked(rc.language_auto_begin);
2092 autoEndCB->setChecked(rc.language_auto_end);
2093 useBabelCB->setChecked(rc.language_use_babel);
2094 globalCB->setChecked(rc.language_global_options);
2095 languagePackageED->setText(toqstr(rc.language_package));
2096 startCommandED->setText(toqstr(rc.language_command_begin));
2097 endCommandED->setText(toqstr(rc.language_command_end));
2099 int pos = uiLanguageCO->findData(toqstr(rc.gui_language));
2100 uiLanguageCO->blockSignals(true);
2101 uiLanguageCO->setCurrentIndex(pos);
2102 uiLanguageCO->blockSignals(false);
2106 /////////////////////////////////////////////////////////////////////
2110 /////////////////////////////////////////////////////////////////////
2112 PrefPrinter::PrefPrinter(GuiPreferences * form)
2113 : PrefModule(qt_(catOutput), qt_("Printer"), form)
2117 connect(printerAdaptCB, SIGNAL(clicked()),
2118 this, SIGNAL(changed()));
2119 connect(printerCommandED, SIGNAL(textChanged(QString)),
2120 this, SIGNAL(changed()));
2121 connect(printerNameED, SIGNAL(textChanged(QString)),
2122 this, SIGNAL(changed()));
2123 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
2124 this, SIGNAL(changed()));
2125 connect(printerCopiesED, SIGNAL(textChanged(QString)),
2126 this, SIGNAL(changed()));
2127 connect(printerReverseED, SIGNAL(textChanged(QString)),
2128 this, SIGNAL(changed()));
2129 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
2130 this, SIGNAL(changed()));
2131 connect(printerExtensionED, SIGNAL(textChanged(QString)),
2132 this, SIGNAL(changed()));
2133 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
2134 this, SIGNAL(changed()));
2135 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
2136 this, SIGNAL(changed()));
2137 connect(printerEvenED, SIGNAL(textChanged(QString)),
2138 this, SIGNAL(changed()));
2139 connect(printerOddED, SIGNAL(textChanged(QString)),
2140 this, SIGNAL(changed()));
2141 connect(printerCollatedED, SIGNAL(textChanged(QString)),
2142 this, SIGNAL(changed()));
2143 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
2144 this, SIGNAL(changed()));
2145 connect(printerToFileED, SIGNAL(textChanged(QString)),
2146 this, SIGNAL(changed()));
2147 connect(printerExtraED, SIGNAL(textChanged(QString)),
2148 this, SIGNAL(changed()));
2149 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
2150 this, SIGNAL(changed()));
2151 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
2152 this, SIGNAL(changed()));
2156 void PrefPrinter::apply(LyXRC & rc) const
2158 rc.print_adapt_output = printerAdaptCB->isChecked();
2159 rc.print_command = fromqstr(printerCommandED->text());
2160 rc.printer = fromqstr(printerNameED->text());
2162 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
2163 rc.print_copies_flag = fromqstr(printerCopiesED->text());
2164 rc.print_reverse_flag = fromqstr(printerReverseED->text());
2165 rc.print_to_printer = fromqstr(printerToPrinterED->text());
2166 rc.print_file_extension = fromqstr(printerExtensionED->text());
2167 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
2168 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
2169 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
2170 rc.print_oddpage_flag = fromqstr(printerOddED->text());
2171 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
2172 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
2173 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
2174 rc.print_extra_options = fromqstr(printerExtraED->text());
2175 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
2176 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
2180 void PrefPrinter::update(LyXRC const & rc)
2182 printerAdaptCB->setChecked(rc.print_adapt_output);
2183 printerCommandED->setText(toqstr(rc.print_command));
2184 printerNameED->setText(toqstr(rc.printer));
2186 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
2187 printerCopiesED->setText(toqstr(rc.print_copies_flag));
2188 printerReverseED->setText(toqstr(rc.print_reverse_flag));
2189 printerToPrinterED->setText(toqstr(rc.print_to_printer));
2190 printerExtensionED->setText(toqstr(rc.print_file_extension));
2191 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
2192 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
2193 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
2194 printerOddED->setText(toqstr(rc.print_oddpage_flag));
2195 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
2196 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
2197 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
2198 printerExtraED->setText(toqstr(rc.print_extra_options));
2199 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
2200 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
2204 /////////////////////////////////////////////////////////////////////
2206 // PrefUserInterface
2208 /////////////////////////////////////////////////////////////////////
2210 PrefUserInterface::PrefUserInterface(GuiPreferences * form)
2211 : PrefModule(qt_(catLookAndFeel), qt_("User interface"), form)
2215 connect(autoSaveCB, SIGNAL(toggled(bool)),
2216 autoSaveSB, SLOT(setEnabled(bool)));
2217 connect(autoSaveCB, SIGNAL(toggled(bool)),
2218 TextLabel1, SLOT(setEnabled(bool)));
2219 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
2220 this, SIGNAL(changed()));
2221 #if QT_VERSION < 0x040500
2222 singleCloseTabButtonCB->setEnabled(false);
2224 connect(singleCloseTabButtonCB, SIGNAL(clicked()),
2225 this, SIGNAL(changed()));
2226 connect(uiFilePB, SIGNAL(clicked()),
2227 this, SLOT(selectUi()));
2228 connect(uiFileED, SIGNAL(textChanged(QString)),
2229 this, SIGNAL(changed()));
2230 connect(restoreCursorCB, SIGNAL(clicked()),
2231 this, SIGNAL(changed()));
2232 connect(loadSessionCB, SIGNAL(clicked()),
2233 this, SIGNAL(changed()));
2234 connect(allowGeometrySessionCB, SIGNAL(clicked()),
2235 this, SIGNAL(changed()));
2236 connect(autoSaveSB, SIGNAL(valueChanged(int)),
2237 this, SIGNAL(changed()));
2238 connect(autoSaveCB, SIGNAL(clicked()),
2239 this, SIGNAL(changed()));
2240 connect(backupCB, SIGNAL(clicked()),
2241 this, SIGNAL(changed()));
2242 connect(saveCompressedCB, SIGNAL(clicked()),
2243 this, SIGNAL(changed()));
2244 connect(lastfilesSB, SIGNAL(valueChanged(int)),
2245 this, SIGNAL(changed()));
2246 connect(tooltipCB, SIGNAL(toggled(bool)),
2247 this, SIGNAL(changed()));
2248 lastfilesSB->setMaximum(maxlastfiles);
2252 void PrefUserInterface::apply(LyXRC & rc) const
2254 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
2255 rc.use_lastfilepos = restoreCursorCB->isChecked();
2256 rc.load_session = loadSessionCB->isChecked();
2257 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
2258 rc.autosave = autoSaveCB->isChecked() ? autoSaveSB->value() * 60 : 0;
2259 rc.make_backup = backupCB->isChecked();
2260 rc.save_compressed = saveCompressedCB->isChecked();
2261 rc.num_lastfiles = lastfilesSB->value();
2262 rc.use_tooltip = tooltipCB->isChecked();
2263 rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
2264 rc.single_close_tab_button = singleCloseTabButtonCB->isChecked();
2265 #if QT_VERSION < 0x040500
2266 rc.single_close_tab_button = true;
2271 void PrefUserInterface::update(LyXRC const & rc)
2273 uiFileED->setText(toqstr(external_path(rc.ui_file)));
2274 restoreCursorCB->setChecked(rc.use_lastfilepos);
2275 loadSessionCB->setChecked(rc.load_session);
2276 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
2277 // convert to minutes
2278 bool autosave = rc.autosave > 0;
2279 int mins = rc.autosave / 60;
2282 autoSaveSB->setValue(mins);
2283 autoSaveCB->setChecked(autosave);
2284 autoSaveSB->setEnabled(autosave);
2285 backupCB->setChecked(rc.make_backup);
2286 saveCompressedCB->setChecked(rc.save_compressed);
2287 lastfilesSB->setValue(rc.num_lastfiles);
2288 tooltipCB->setChecked(rc.use_tooltip);
2289 openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
2290 singleCloseTabButtonCB->setChecked(rc.single_close_tab_button);
2294 void PrefUserInterface::selectUi()
2296 QString file = form_->browseUI(internalPath(uiFileED->text()));
2297 if (!file.isEmpty())
2298 uiFileED->setText(file);
2302 void PrefUserInterface::on_clearSessionPB_clicked()
2304 guiApp->clearSession();
2309 /////////////////////////////////////////////////////////////////////
2313 /////////////////////////////////////////////////////////////////////
2315 PrefEdit::PrefEdit(GuiPreferences * form)
2316 : PrefModule(qt_(catEditing), qt_("Control"), form)
2320 connect(cursorFollowsCB, SIGNAL(clicked()),
2321 this, SIGNAL(changed()));
2322 connect(scrollBelowCB, SIGNAL(clicked()),
2323 this, SIGNAL(changed()));
2324 connect(sortEnvironmentsCB, SIGNAL(clicked()),
2325 this, SIGNAL(changed()));
2326 connect(groupEnvironmentsCB, SIGNAL(clicked()),
2327 this, SIGNAL(changed()));
2328 connect(macroEditStyleCO, SIGNAL(activated(int)),
2329 this, SIGNAL(changed()));
2330 connect(fullscreenLimitGB, SIGNAL(clicked()),
2331 this, SIGNAL(changed()));
2332 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
2333 this, SIGNAL(changed()));
2334 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
2335 this, SIGNAL(changed()));
2336 connect(toggleMenubarCB, SIGNAL(toggled(bool)),
2337 this, SIGNAL(changed()));
2338 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
2339 this, SIGNAL(changed()));
2340 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
2341 this, SIGNAL(changed()));
2345 void PrefEdit::apply(LyXRC & rc) const
2347 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
2348 rc.scroll_below_document = scrollBelowCB->isChecked();
2349 rc.sort_layouts = sortEnvironmentsCB->isChecked();
2350 rc.group_layouts = groupEnvironmentsCB->isChecked();
2351 switch (macroEditStyleCO->currentIndex()) {
2352 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
2353 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
2354 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
2356 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
2357 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
2358 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
2359 rc.full_screen_menubar = toggleMenubarCB->isChecked();
2360 rc.full_screen_width = fullscreenWidthSB->value();
2361 rc.full_screen_limit = fullscreenLimitGB->isChecked();
2365 void PrefEdit::update(LyXRC const & rc)
2367 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
2368 scrollBelowCB->setChecked(rc.scroll_below_document);
2369 sortEnvironmentsCB->setChecked(rc.sort_layouts);
2370 groupEnvironmentsCB->setChecked(rc.group_layouts);
2371 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
2372 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
2373 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
2374 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
2375 toggleMenubarCB->setChecked(rc.full_screen_menubar);
2376 fullscreenWidthSB->setValue(rc.full_screen_width);
2377 fullscreenLimitGB->setChecked(rc.full_screen_limit);
2381 /////////////////////////////////////////////////////////////////////
2385 /////////////////////////////////////////////////////////////////////
2388 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
2390 Ui::shortcutUi::setupUi(this);
2391 QDialog::setModal(true);
2395 PrefShortcuts::PrefShortcuts(GuiPreferences * form)
2396 : PrefModule(qt_(catEditing), qt_("Shortcuts"), form)
2400 shortcutsTW->setColumnCount(2);
2401 shortcutsTW->headerItem()->setText(0, qt_("Function"));
2402 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
2403 shortcutsTW->setSortingEnabled(true);
2404 // Multi-selection can be annoying.
2405 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
2407 connect(bindFilePB, SIGNAL(clicked()),
2408 this, SLOT(selectBind()));
2409 connect(bindFileED, SIGNAL(textChanged(QString)),
2410 this, SIGNAL(changed()));
2412 shortcut_ = new GuiShortcutDialog(this);
2413 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
2414 shortcut_bc_.setOK(shortcut_->okPB);
2415 shortcut_bc_.setCancel(shortcut_->cancelPB);
2417 connect(shortcut_->okPB, SIGNAL(clicked()),
2418 shortcut_, SLOT(accept()));
2419 connect(shortcut_->okPB, SIGNAL(clicked()),
2420 this, SIGNAL(changed()));
2421 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2422 shortcut_, SLOT(reject()));
2423 connect(shortcut_->clearPB, SIGNAL(clicked()),
2424 this, SLOT(shortcutClearPressed()));
2425 connect(shortcut_->removePB, SIGNAL(clicked()),
2426 this, SLOT(shortcutRemovePressed()));
2427 connect(shortcut_->okPB, SIGNAL(clicked()),
2428 this, SLOT(shortcutOkPressed()));
2429 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2430 this, SLOT(shortcutCancelPressed()));
2434 void PrefShortcuts::apply(LyXRC & rc) const
2436 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
2437 // write user_bind and user_unbind to .lyx/bind/user.bind
2438 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
2439 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
2440 lyxerr << "LyX could not create the user bind directory '"
2441 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2444 if (!bind_dir.isDirWritable()) {
2445 lyxerr << "LyX could not write to the user bind directory '"
2446 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2449 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
2450 user_unbind_.write(user_bind_file.toFilesystemEncoding(), false, true);
2451 user_bind_.write(user_bind_file.toFilesystemEncoding(), true, false);
2452 // immediately apply the keybindings. Why this is not done before?
2453 // The good thing is that the menus are updated automatically.
2454 theTopLevelKeymap().clear();
2455 theTopLevelKeymap().read("site");
2456 theTopLevelKeymap().read(rc.bind_file, 0, KeyMap::Fallback);
2457 theTopLevelKeymap().read("user", 0, KeyMap::MissingOK);
2461 void PrefShortcuts::update(LyXRC const & rc)
2463 bindFileED->setText(toqstr(external_path(rc.bind_file)));
2465 system_bind_.clear();
2467 user_unbind_.clear();
2468 system_bind_.read("site");
2469 system_bind_.read(rc.bind_file);
2470 // \unbind in user.bind is added to user_unbind_
2471 user_bind_.read("user", &user_unbind_, KeyMap::MissingOK);
2472 updateShortcutsTW();
2476 void PrefShortcuts::updateShortcutsTW()
2478 shortcutsTW->clear();
2480 editItem_ = new QTreeWidgetItem(shortcutsTW);
2481 editItem_->setText(0, qt_("Cursor, Mouse and Editing functions"));
2482 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2484 mathItem_ = new QTreeWidgetItem(shortcutsTW);
2485 mathItem_->setText(0, qt_("Mathematical Symbols"));
2486 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2488 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2489 bufferItem_->setText(0, qt_("Document and Window"));
2490 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2492 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2493 layoutItem_->setText(0, qt_("Font, Layouts and Textclasses"));
2494 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2496 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2497 systemItem_->setText(0, qt_("System and Miscellaneous"));
2498 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2500 // listBindings(unbound=true) lists all bound and unbound lfuns
2501 // Items in this list is tagged by its source.
2502 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2504 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2506 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2507 KeyMap::UserUnbind);
2508 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2509 user_bindinglist.end());
2510 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2511 user_unbindinglist.end());
2513 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2514 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2515 for (; it != it_end; ++it)
2516 insertShortcutItem(it->request, it->sequence, KeyMap::ItemType(it->tag));
2518 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2519 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2520 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2521 modifyPB->setEnabled(!items.isEmpty());
2523 shortcutsTW->resizeColumnToContents(0);
2527 void PrefShortcuts::setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag)
2529 item->setData(0, Qt::UserRole, QVariant(tag));
2533 case KeyMap::System:
2535 case KeyMap::UserBind:
2538 case KeyMap::UserUnbind:
2539 font.setStrikeOut(true);
2541 // this item is not displayed now.
2542 case KeyMap::UserExtraUnbind:
2543 font.setStrikeOut(true);
2547 item->setFont(1, font);
2551 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2552 KeySequence const & seq, KeyMap::ItemType tag)
2554 FuncCode const action = lfun.action();
2555 string const action_name = lyxaction.getActionName(action);
2556 QString const lfun_name = toqstr(from_utf8(action_name)
2557 + ' ' + lfun.argument());
2558 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2559 KeyMap::ItemType item_tag = tag;
2561 QTreeWidgetItem * newItem = 0;
2562 // for unbind items, try to find an existing item in the system bind list
2563 if (tag == KeyMap::UserUnbind) {
2564 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2565 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2566 for (int i = 0; i < items.size(); ++i) {
2567 if (items[i]->text(1) == shortcut)
2571 // if not found, this unbind item is KeyMap::UserExtraUnbind
2572 // Such an item is not displayed to avoid confusion (what is
2573 // unmatched removed?).
2575 item_tag = KeyMap::UserExtraUnbind;
2580 switch(lyxaction.getActionType(action)) {
2581 case LyXAction::Hidden:
2583 case LyXAction::Edit:
2584 newItem = new QTreeWidgetItem(editItem_);
2586 case LyXAction::Math:
2587 newItem = new QTreeWidgetItem(mathItem_);
2589 case LyXAction::Buffer:
2590 newItem = new QTreeWidgetItem(bufferItem_);
2592 case LyXAction::Layout:
2593 newItem = new QTreeWidgetItem(layoutItem_);
2595 case LyXAction::System:
2596 newItem = new QTreeWidgetItem(systemItem_);
2599 // this should not happen
2600 newItem = new QTreeWidgetItem(shortcutsTW);
2604 newItem->setText(0, lfun_name);
2605 newItem->setText(1, shortcut);
2606 // record BindFile representation to recover KeySequence when needed.
2607 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2608 setItemType(newItem, item_tag);
2613 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2615 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2616 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2617 modifyPB->setEnabled(!items.isEmpty());
2618 if (items.isEmpty())
2621 KeyMap::ItemType tag =
2622 static_cast<KeyMap::ItemType>(items[0]->data(0, Qt::UserRole).toInt());
2623 if (tag == KeyMap::UserUnbind)
2624 removePB->setText(qt_("Res&tore"));
2626 removePB->setText(qt_("Remo&ve"));
2630 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2636 void PrefShortcuts::modifyShortcut()
2638 QTreeWidgetItem * item = shortcutsTW->currentItem();
2639 if (item->flags() & Qt::ItemIsSelectable) {
2640 shortcut_->lfunLE->setText(item->text(0));
2641 save_lfun_ = item->text(0).trimmed();
2642 shortcut_->shortcutWG->setText(item->text(1));
2644 seq.parse(fromqstr(item->data(1, Qt::UserRole).toString()));
2645 shortcut_->shortcutWG->setKeySequence(seq);
2646 shortcut_->shortcutWG->setFocus();
2652 void PrefShortcuts::removeShortcut()
2654 // it seems that only one item can be selected, but I am
2655 // removing all selected items anyway.
2656 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2657 for (int i = 0; i < items.size(); ++i) {
2658 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2659 string lfun = fromqstr(items[i]->text(0));
2660 FuncRequest func = lyxaction.lookupFunc(lfun);
2661 KeyMap::ItemType tag =
2662 static_cast<KeyMap::ItemType>(items[i]->data(0, Qt::UserRole).toInt());
2665 case KeyMap::System: {
2666 // for system bind, we do not touch the item
2667 // but add an user unbind item
2668 user_unbind_.bind(shortcut, func);
2669 setItemType(items[i], KeyMap::UserUnbind);
2670 removePB->setText(qt_("Res&tore"));
2673 case KeyMap::UserBind: {
2674 // for user_bind, we remove this bind
2675 QTreeWidgetItem * parent = items[i]->parent();
2676 int itemIdx = parent->indexOfChild(items[i]);
2677 parent->takeChild(itemIdx);
2679 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2681 shortcutsTW->scrollToItem(parent);
2682 user_bind_.unbind(shortcut, func);
2685 case KeyMap::UserUnbind: {
2686 // for user_unbind, we remove the unbind, and the item
2687 // become KeyMap::System again.
2688 user_unbind_.unbind(shortcut, func);
2689 setItemType(items[i], KeyMap::System);
2690 removePB->setText(qt_("Remo&ve"));
2693 case KeyMap::UserExtraUnbind: {
2694 // for user unbind that is not in system bind file,
2695 // remove this unbind file
2696 QTreeWidgetItem * parent = items[i]->parent();
2697 parent->takeChild(parent->indexOfChild(items[i]));
2698 user_unbind_.unbind(shortcut, func);
2705 void PrefShortcuts::selectBind()
2707 QString file = form_->browsebind(internalPath(bindFileED->text()));
2708 if (!file.isEmpty()) {
2709 bindFileED->setText(file);
2710 system_bind_ = KeyMap();
2711 system_bind_.read(fromqstr(file));
2712 updateShortcutsTW();
2717 void PrefShortcuts::on_modifyPB_pressed()
2723 void PrefShortcuts::on_newPB_pressed()
2725 shortcut_->lfunLE->clear();
2726 shortcut_->shortcutWG->reset();
2727 save_lfun_ = QString();
2732 void PrefShortcuts::on_removePB_pressed()
2739 void PrefShortcuts::on_searchLE_textEdited()
2741 if (searchLE->text().isEmpty()) {
2742 // show all hidden items
2743 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2745 shortcutsTW->setItemHidden(*it++, false);
2748 // search both columns
2749 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2750 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2751 matched += shortcutsTW->findItems(searchLE->text(),
2752 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2754 // hide everyone (to avoid searching in matched QList repeatedly
2755 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2757 shortcutsTW->setItemHidden(*it++, true);
2758 // show matched items
2759 for (int i = 0; i < matched.size(); ++i) {
2760 shortcutsTW->setItemHidden(matched[i], false);
2761 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2766 docstring makeCmdString(FuncRequest const & f)
2768 docstring actionStr = from_ascii(lyxaction.getActionName(f.action()));
2769 if (!f.argument().empty())
2770 actionStr += " " + f.argument();
2775 void PrefShortcuts::shortcutOkPressed()
2777 QString const new_lfun = shortcut_->lfunLE->text();
2778 FuncRequest func = lyxaction.lookupFunc(fromqstr(new_lfun));
2780 if (func.action() == LFUN_UNKNOWN_ACTION) {
2781 Alert::error(_("Failed to create shortcut"),
2782 _("Unknown or invalid LyX function"));
2786 KeySequence k = shortcut_->shortcutWG->getKeySequence();
2787 if (k.length() == 0) {
2788 Alert::error(_("Failed to create shortcut"),
2789 _("Invalid or empty key sequence"));
2793 // check to see if there's been any change
2794 FuncRequest oldBinding = system_bind_.getBinding(k);
2795 if (oldBinding.action() == LFUN_UNKNOWN_ACTION)
2796 oldBinding = user_bind_.getBinding(k);
2797 if (oldBinding == func)
2798 // nothing has changed
2801 // make sure this key isn't already bound---and, if so, not unbound
2802 FuncCode const unbind = user_unbind_.getBinding(k).action();
2803 docstring const action_string = makeCmdString(oldBinding);
2804 if (oldBinding.action() > LFUN_NOACTION && unbind == LFUN_UNKNOWN_ACTION
2805 && save_lfun_ != toqstr(action_string)) {
2806 // FIXME Perhaps we should offer to over-write the old shortcut?
2807 // If so, we'll need to remove it from our list, etc.
2808 Alert::error(_("Failed to create shortcut"),
2809 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s\n"
2810 "You need to remove that binding before creating a new one."),
2811 k.print(KeySequence::ForGui), action_string));
2815 if (!save_lfun_.isEmpty())
2816 // real modification of the lfun's shortcut,
2817 // so remove the previous one
2820 QTreeWidgetItem * item = insertShortcutItem(func, k, KeyMap::UserBind);
2822 user_bind_.bind(&k, func);
2823 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2824 shortcutsTW->setItemExpanded(item->parent(), true);
2825 shortcutsTW->scrollToItem(item);
2827 Alert::error(_("Failed to create shortcut"),
2828 _("Can not insert shortcut to the list"));
2834 void PrefShortcuts::shortcutCancelPressed()
2836 shortcut_->shortcutWG->reset();
2840 void PrefShortcuts::shortcutClearPressed()
2842 shortcut_->shortcutWG->reset();
2846 void PrefShortcuts::shortcutRemovePressed()
2848 shortcut_->shortcutWG->removeFromSequence();
2852 /////////////////////////////////////////////////////////////////////
2856 /////////////////////////////////////////////////////////////////////
2858 PrefIdentity::PrefIdentity(GuiPreferences * form)
2859 : PrefModule(QString(), qt_("Identity"), form)
2863 connect(nameED, SIGNAL(textChanged(QString)),
2864 this, SIGNAL(changed()));
2865 connect(emailED, SIGNAL(textChanged(QString)),
2866 this, SIGNAL(changed()));
2870 void PrefIdentity::apply(LyXRC & rc) const
2872 rc.user_name = fromqstr(nameED->text());
2873 rc.user_email = fromqstr(emailED->text());
2877 void PrefIdentity::update(LyXRC const & rc)
2879 nameED->setText(toqstr(rc.user_name));
2880 emailED->setText(toqstr(rc.user_email));
2885 /////////////////////////////////////////////////////////////////////
2889 /////////////////////////////////////////////////////////////////////
2891 GuiPreferences::GuiPreferences(GuiView & lv)
2892 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2896 QDialog::setModal(false);
2898 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2899 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2900 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2901 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2903 addModule(new PrefUserInterface(this));
2904 addModule(new PrefEdit(this));
2905 addModule(new PrefShortcuts(this));
2906 addModule(new PrefScreenFonts(this));
2907 addModule(new PrefColors(this));
2908 addModule(new PrefDisplay(this));
2909 addModule(new PrefInput(this));
2910 addModule(new PrefCompletion(this));
2912 addModule(new PrefPaths(this));
2914 addModule(new PrefIdentity(this));
2916 addModule(new PrefLanguage(this));
2917 addModule(new PrefSpellchecker(this));
2919 //for strftime validator
2920 PrefOutput * output = new PrefOutput(this);
2922 addModule(new PrefPrinter(this));
2923 addModule(new PrefLatex(this));
2925 PrefConverters * converters = new PrefConverters(this);
2926 PrefFileformats * formats = new PrefFileformats(this);
2927 connect(formats, SIGNAL(formatsChanged()),
2928 converters, SLOT(updateGui()));
2929 addModule(converters);
2932 prefsPS->setCurrentPanel(qt_("User interface"));
2933 // FIXME: hack to work around resizing bug in Qt >= 4.2
2934 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2935 #if QT_VERSION >= 0x040200
2936 prefsPS->updateGeometry();
2939 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2941 bc().setApply(applyPB);
2942 bc().setCancel(closePB);
2943 bc().setRestore(restorePB);
2945 // initialize the strftime validator
2946 bc().addCheckedLineEdit(output->DateED);
2950 void GuiPreferences::addModule(PrefModule * module)
2952 LASSERT(module, return);
2953 if (module->category().isEmpty())
2954 prefsPS->addPanel(module, module->title());
2956 prefsPS->addPanel(module, module->title(), module->category());
2957 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2958 modules_.push_back(module);
2962 void GuiPreferences::change_adaptor()
2968 void GuiPreferences::apply(LyXRC & rc) const
2970 size_t end = modules_.size();
2971 for (size_t i = 0; i != end; ++i)
2972 modules_[i]->apply(rc);
2976 void GuiPreferences::updateRc(LyXRC const & rc)
2978 size_t const end = modules_.size();
2979 for (size_t i = 0; i != end; ++i)
2980 modules_[i]->update(rc);
2984 void GuiPreferences::applyView()
2989 bool GuiPreferences::initialiseParams(string const &)
2992 formats_ = lyx::formats;
2993 converters_ = theConverters();
2994 converters_.update(formats_);
2995 movers_ = theMovers();
2997 update_screen_font_ = false;
3000 // Make sure that the bc is in the INITIAL state
3001 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3008 void GuiPreferences::dispatchParams()
3011 rc_.write(ss, true);
3012 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
3013 // FIXME: these need lfuns
3015 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
3017 lyx::formats = formats_;
3019 theConverters() = converters_;
3020 theConverters().update(lyx::formats);
3021 theConverters().buildGraph();
3023 theMovers() = movers_;
3025 vector<string>::const_iterator it = colors_.begin();
3026 vector<string>::const_iterator const end = colors_.end();
3027 for (; it != end; ++it)
3028 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
3031 if (update_screen_font_) {
3032 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
3033 update_screen_font_ = false;
3036 // The Save button has been pressed
3038 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
3042 void GuiPreferences::setColor(ColorCode col, QString const & hex)
3044 colors_.push_back(lcolor.getLyXName(col) + ' ' + fromqstr(hex));
3048 void GuiPreferences::updateScreenFonts()
3050 update_screen_font_ = true;
3054 QString GuiPreferences::browsebind(QString const & file) const
3056 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
3057 QStringList(qt_("LyX bind files (*.bind)")));
3061 QString GuiPreferences::browseUI(QString const & file) const
3063 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
3064 QStringList(qt_("LyX UI files (*.ui)")));
3068 QString GuiPreferences::browsekbmap(QString const & file) const
3070 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
3071 QStringList(qt_("LyX keyboard maps (*.kmap)")));
3075 QString GuiPreferences::browse(QString const & file,
3076 QString const & title) const
3078 return browseFile(file, title, QStringList(), true);
3082 // We support less paper sizes than the document dialog
3083 // Therefore this adjustment is needed.
3084 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
3088 return PAPER_DEFAULT;
3090 return PAPER_USLETTER;
3092 return PAPER_USLEGAL;
3094 return PAPER_USEXECUTIVE;
3104 // should not happen
3105 return PAPER_DEFAULT;
3110 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
3112 switch (papersize) {
3115 case PAPER_USLETTER:
3119 case PAPER_USEXECUTIVE:
3130 // should not happen
3136 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
3139 } // namespace frontend
3142 #include "moc_GuiPrefs.cpp"