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(editTextChanged(QString)),
372 this, SIGNAL(changed()));
373 connect(pdfCB, SIGNAL(editTextChanged(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)]");
380 pdfCB->addItem("synctex view -i $$n:1:$$t -o $$o -x \"xpdf -raise -remote $$t.tmp $$o %{page+1}\"");
384 void PrefOutput::on_DateED_textChanged(const QString &)
386 QString t = DateED->text();
388 bool valid = DateED->validator()->validate(t, p)
389 == QValidator::Acceptable;
390 setValid(DateLA, valid);
394 void PrefOutput::apply(LyXRC & rc) const
396 rc.date_insert_format = fromqstr(DateED->text());
397 rc.plaintext_linelen = plaintextLinelengthSB->value();
398 rc.forward_search_dvi = fromqstr(dviCB->currentText());
399 rc.forward_search_pdf = fromqstr(pdfCB->currentText());
403 void PrefOutput::update(LyXRC const & rc)
405 DateED->setText(toqstr(rc.date_insert_format));
406 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
407 dviCB->setEditText(toqstr(rc.forward_search_dvi));
408 pdfCB->setEditText(toqstr(rc.forward_search_pdf));
412 /////////////////////////////////////////////////////////////////////
416 /////////////////////////////////////////////////////////////////////
418 PrefInput::PrefInput(GuiPreferences * form)
419 : PrefModule(qt_(catEditing), qt_("Keyboard/Mouse"), form)
423 connect(keymapCB, SIGNAL(clicked()),
424 this, SIGNAL(changed()));
425 connect(firstKeymapED, SIGNAL(textChanged(QString)),
426 this, SIGNAL(changed()));
427 connect(secondKeymapED, SIGNAL(textChanged(QString)),
428 this, SIGNAL(changed()));
429 connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
430 this, SIGNAL(changed()));
434 void PrefInput::apply(LyXRC & rc) const
436 // FIXME: can derive CB from the two EDs
437 rc.use_kbmap = keymapCB->isChecked();
438 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
439 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
440 rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
444 void PrefInput::update(LyXRC const & rc)
446 // FIXME: can derive CB from the two EDs
447 keymapCB->setChecked(rc.use_kbmap);
448 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
449 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
450 mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
454 QString PrefInput::testKeymap(QString const & keymap)
456 return form_->browsekbmap(internalPath(keymap));
460 void PrefInput::on_firstKeymapPB_clicked(bool)
462 QString const file = testKeymap(firstKeymapED->text());
464 firstKeymapED->setText(file);
468 void PrefInput::on_secondKeymapPB_clicked(bool)
470 QString const file = testKeymap(secondKeymapED->text());
472 secondKeymapED->setText(file);
476 void PrefInput::on_keymapCB_toggled(bool keymap)
478 firstKeymapLA->setEnabled(keymap);
479 secondKeymapLA->setEnabled(keymap);
480 firstKeymapED->setEnabled(keymap);
481 secondKeymapED->setEnabled(keymap);
482 firstKeymapPB->setEnabled(keymap);
483 secondKeymapPB->setEnabled(keymap);
487 /////////////////////////////////////////////////////////////////////
491 /////////////////////////////////////////////////////////////////////
493 PrefCompletion::PrefCompletion(GuiPreferences * form)
494 : PrefModule(qt_(catEditing), qt_("Input Completion"), form)
498 connect(inlineDelaySB, SIGNAL(valueChanged(double)),
499 this, SIGNAL(changed()));
500 connect(inlineMathCB, SIGNAL(clicked()),
501 this, SIGNAL(changed()));
502 connect(inlineTextCB, SIGNAL(clicked()),
503 this, SIGNAL(changed()));
504 connect(inlineDotsCB, SIGNAL(clicked()),
505 this, SIGNAL(changed()));
506 connect(popupDelaySB, SIGNAL(valueChanged(double)),
507 this, SIGNAL(changed()));
508 connect(popupMathCB, SIGNAL(clicked()),
509 this, SIGNAL(changed()));
510 connect(autocorrectionCB, SIGNAL(clicked()),
511 this, SIGNAL(changed()));
512 connect(popupTextCB, SIGNAL(clicked()),
513 this, SIGNAL(changed()));
514 connect(popupAfterCompleteCB, SIGNAL(clicked()),
515 this, SIGNAL(changed()));
516 connect(cursorTextCB, SIGNAL(clicked()),
517 this, SIGNAL(changed()));
521 void PrefCompletion::on_inlineTextCB_clicked()
527 void PrefCompletion::on_popupTextCB_clicked()
533 void PrefCompletion::enableCB()
535 cursorTextCB->setEnabled(
536 popupTextCB->isChecked() || inlineTextCB->isChecked());
540 void PrefCompletion::apply(LyXRC & rc) const
542 rc.completion_inline_delay = inlineDelaySB->value();
543 rc.completion_inline_math = inlineMathCB->isChecked();
544 rc.completion_inline_text = inlineTextCB->isChecked();
545 rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
546 rc.completion_popup_delay = popupDelaySB->value();
547 rc.completion_popup_math = popupMathCB->isChecked();
548 rc.autocorrection_math = autocorrectionCB->isChecked();
549 rc.completion_popup_text = popupTextCB->isChecked();
550 rc.completion_cursor_text = cursorTextCB->isChecked();
551 rc.completion_popup_after_complete =
552 popupAfterCompleteCB->isChecked();
556 void PrefCompletion::update(LyXRC const & rc)
558 inlineDelaySB->setValue(rc.completion_inline_delay);
559 inlineMathCB->setChecked(rc.completion_inline_math);
560 inlineTextCB->setChecked(rc.completion_inline_text);
561 inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
562 popupDelaySB->setValue(rc.completion_popup_delay);
563 popupMathCB->setChecked(rc.completion_popup_math);
564 autocorrectionCB->setChecked(rc.autocorrection_math);
565 popupTextCB->setChecked(rc.completion_popup_text);
566 cursorTextCB->setChecked(rc.completion_cursor_text);
567 popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
573 /////////////////////////////////////////////////////////////////////
577 /////////////////////////////////////////////////////////////////////
579 PrefLatex::PrefLatex(GuiPreferences * form)
580 : PrefModule(qt_(catOutput), qt_("LaTeX"), form)
583 connect(latexEncodingCB, SIGNAL(clicked()),
584 this, SIGNAL(changed()));
585 connect(latexEncodingED, SIGNAL(textChanged(QString)),
586 this, SIGNAL(changed()));
587 connect(latexChecktexED, SIGNAL(textChanged(QString)),
588 this, SIGNAL(changed()));
589 connect(latexBibtexCO, SIGNAL(activated(int)),
590 this, SIGNAL(changed()));
591 connect(latexBibtexED, SIGNAL(textChanged(QString)),
592 this, SIGNAL(changed()));
593 connect(latexJBibtexED, SIGNAL(textChanged(QString)),
594 this, SIGNAL(changed()));
595 connect(latexIndexCO, SIGNAL(activated(int)),
596 this, SIGNAL(changed()));
597 connect(latexIndexED, SIGNAL(textChanged(QString)),
598 this, SIGNAL(changed()));
599 connect(latexJIndexED, SIGNAL(textChanged(QString)),
600 this, SIGNAL(changed()));
601 connect(latexAutoresetCB, SIGNAL(clicked()),
602 this, SIGNAL(changed()));
603 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
604 this, SIGNAL(changed()));
605 connect(latexPaperSizeCO, SIGNAL(activated(int)),
606 this, SIGNAL(changed()));
608 #if defined(__CYGWIN__) || defined(_WIN32)
609 pathCB->setVisible(true);
610 connect(pathCB, SIGNAL(clicked()),
611 this, SIGNAL(changed()));
613 pathCB->setVisible(false);
618 void PrefLatex::on_latexEncodingCB_stateChanged(int state)
620 latexEncodingED->setEnabled(state == Qt::Checked);
624 void PrefLatex::on_latexBibtexCO_activated(int n)
626 QString const bibtex = latexBibtexCO->itemData(n).toString();
627 if (bibtex.isEmpty()) {
628 latexBibtexED->clear();
629 latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
632 for (LyXRC::CommandSet::const_iterator it = bibtex_alternatives.begin();
633 it != bibtex_alternatives.end(); ++it) {
634 QString const bib = toqstr(*it);
635 int ind = bib.indexOf(" ");
636 QString sel_command = bib.left(ind);
637 QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
638 if (bibtex == sel_command) {
640 latexBibtexED->clear();
642 latexBibtexED->setText(sel_options.trimmed());
645 latexBibtexOptionsLA->setText(qt_("&Options:"));
649 void PrefLatex::on_latexIndexCO_activated(int n)
651 QString const index = latexIndexCO->itemData(n).toString();
652 if (index.isEmpty()) {
653 latexIndexED->clear();
654 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
657 for (LyXRC::CommandSet::const_iterator it = index_alternatives.begin();
658 it != index_alternatives.end(); ++it) {
659 QString const idx = toqstr(*it);
660 int ind = idx.indexOf(" ");
661 QString sel_command = idx.left(ind);
662 QString sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
663 if (index == sel_command) {
665 latexIndexED->clear();
667 latexIndexED->setText(sel_options.trimmed());
670 latexIndexOptionsLA->setText(qt_("Op&tions:"));
674 void PrefLatex::apply(LyXRC & rc) const
676 // If bibtex is not empty, bibopt contains the options, otherwise
677 // it is a customized bibtex command with options.
678 QString const bibtex = latexBibtexCO->itemData(
679 latexBibtexCO->currentIndex()).toString();
680 QString const bibopt = latexBibtexED->text();
681 if (bibtex.isEmpty())
682 rc.bibtex_command = fromqstr(bibopt);
683 else if (bibopt.isEmpty())
684 rc.bibtex_command = fromqstr(bibtex);
686 rc.bibtex_command = fromqstr(bibtex) + " " + fromqstr(bibopt);
688 // If index is not empty, idxopt contains the options, otherwise
689 // it is a customized index command with options.
690 QString const index = latexIndexCO->itemData(
691 latexIndexCO->currentIndex()).toString();
692 QString const idxopt = latexIndexED->text();
694 rc.index_command = fromqstr(idxopt);
695 else if (idxopt.isEmpty())
696 rc.index_command = fromqstr(index);
698 rc.index_command = fromqstr(index) + " " + fromqstr(idxopt);
700 if (latexEncodingCB->isChecked())
701 rc.fontenc = fromqstr(latexEncodingED->text());
703 rc.fontenc = "default";
704 rc.chktex_command = fromqstr(latexChecktexED->text());
705 rc.jbibtex_command = fromqstr(latexJBibtexED->text());
706 rc.jindex_command = fromqstr(latexJIndexED->text());
707 rc.nomencl_command = fromqstr(latexNomenclED->text());
708 rc.auto_reset_options = latexAutoresetCB->isChecked();
709 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
710 rc.default_papersize =
711 form_->toPaperSize(latexPaperSizeCO->currentIndex());
712 #if defined(__CYGWIN__) || defined(_WIN32)
713 rc.windows_style_tex_paths = pathCB->isChecked();
718 void PrefLatex::update(LyXRC const & rc)
720 latexBibtexCO->clear();
722 latexBibtexCO->addItem(qt_("Custom"), QString());
723 for (LyXRC::CommandSet::const_iterator it = rc.bibtex_alternatives.begin();
724 it != rc.bibtex_alternatives.end(); ++it) {
725 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
726 latexBibtexCO->addItem(command, command);
729 bibtex_alternatives = rc.bibtex_alternatives;
731 QString const bib = toqstr(rc.bibtex_command);
732 int ind = bib.indexOf(" ");
733 QString sel_command = bib.left(ind);
734 QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
736 int pos = latexBibtexCO->findData(sel_command);
738 latexBibtexCO->setCurrentIndex(pos);
739 latexBibtexED->setText(sel_options.trimmed());
740 latexBibtexOptionsLA->setText(qt_("&Options:"));
742 latexBibtexED->setText(toqstr(rc.bibtex_command));
743 latexBibtexCO->setCurrentIndex(0);
744 latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
747 latexIndexCO->clear();
749 latexIndexCO->addItem(qt_("Custom"), QString());
750 for (LyXRC::CommandSet::const_iterator it = rc.index_alternatives.begin();
751 it != rc.index_alternatives.end(); ++it) {
752 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
753 latexIndexCO->addItem(command, command);
756 index_alternatives = rc.index_alternatives;
758 QString const idx = toqstr(rc.index_command);
759 ind = idx.indexOf(" ");
760 sel_command = idx.left(ind);
761 sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
763 pos = latexIndexCO->findData(sel_command);
765 latexIndexCO->setCurrentIndex(pos);
766 latexIndexED->setText(sel_options.trimmed());
767 latexIndexOptionsLA->setText(qt_("Op&tions:"));
769 latexIndexED->setText(toqstr(rc.index_command));
770 latexIndexCO->setCurrentIndex(0);
771 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
774 if (rc.fontenc == "default") {
775 latexEncodingCB->setChecked(false);
776 latexEncodingED->setEnabled(false);
778 latexEncodingCB->setChecked(true);
779 latexEncodingED->setEnabled(true);
780 latexEncodingED->setText(toqstr(rc.fontenc));
782 latexChecktexED->setText(toqstr(rc.chktex_command));
783 latexJBibtexED->setText(toqstr(rc.jbibtex_command));
784 latexJIndexED->setText(toqstr(rc.jindex_command));
785 latexNomenclED->setText(toqstr(rc.nomencl_command));
786 latexAutoresetCB->setChecked(rc.auto_reset_options);
787 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
788 latexPaperSizeCO->setCurrentIndex(
789 form_->fromPaperSize(rc.default_papersize));
790 #if defined(__CYGWIN__) || defined(_WIN32)
791 pathCB->setChecked(rc.windows_style_tex_paths);
796 /////////////////////////////////////////////////////////////////////
800 /////////////////////////////////////////////////////////////////////
802 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form)
803 : PrefModule(qt_(catLookAndFeel), qt_("Screen fonts"), form)
807 connect(screenRomanCO, SIGNAL(activated(QString)),
808 this, SLOT(selectRoman(QString)));
809 connect(screenSansCO, SIGNAL(activated(QString)),
810 this, SLOT(selectSans(QString)));
811 connect(screenTypewriterCO, SIGNAL(activated(QString)),
812 this, SLOT(selectTypewriter(QString)));
814 QFontDatabase fontdb;
815 QStringList families(fontdb.families());
816 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
817 screenRomanCO->addItem(*it);
818 screenSansCO->addItem(*it);
819 screenTypewriterCO->addItem(*it);
821 connect(screenRomanCO, SIGNAL(activated(QString)),
822 this, SIGNAL(changed()));
823 connect(screenSansCO, SIGNAL(activated(QString)),
824 this, SIGNAL(changed()));
825 connect(screenTypewriterCO, SIGNAL(activated(QString)),
826 this, SIGNAL(changed()));
827 connect(screenZoomSB, SIGNAL(valueChanged(int)),
828 this, SIGNAL(changed()));
829 connect(screenDpiSB, SIGNAL(valueChanged(int)),
830 this, SIGNAL(changed()));
831 connect(screenTinyED, SIGNAL(textChanged(QString)),
832 this, SIGNAL(changed()));
833 connect(screenSmallestED, SIGNAL(textChanged(QString)),
834 this, SIGNAL(changed()));
835 connect(screenSmallerED, SIGNAL(textChanged(QString)),
836 this, SIGNAL(changed()));
837 connect(screenSmallED, SIGNAL(textChanged(QString)),
838 this, SIGNAL(changed()));
839 connect(screenNormalED, SIGNAL(textChanged(QString)),
840 this, SIGNAL(changed()));
841 connect(screenLargeED, SIGNAL(textChanged(QString)),
842 this, SIGNAL(changed()));
843 connect(screenLargerED, SIGNAL(textChanged(QString)),
844 this, SIGNAL(changed()));
845 connect(screenLargestED, SIGNAL(textChanged(QString)),
846 this, SIGNAL(changed()));
847 connect(screenHugeED, SIGNAL(textChanged(QString)),
848 this, SIGNAL(changed()));
849 connect(screenHugerED, SIGNAL(textChanged(QString)),
850 this, SIGNAL(changed()));
851 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
852 this, SIGNAL(changed()));
854 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
855 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
856 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
857 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
858 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
859 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
860 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
861 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
862 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
863 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
867 void PrefScreenFonts::apply(LyXRC & rc) const
869 LyXRC const oldrc = rc;
871 parseFontName(screenRomanCO->currentText(),
872 rc.roman_font_name, rc.roman_font_foundry);
873 parseFontName(screenSansCO->currentText(),
874 rc.sans_font_name, rc.sans_font_foundry);
875 parseFontName(screenTypewriterCO->currentText(),
876 rc.typewriter_font_name, rc.typewriter_font_foundry);
878 rc.zoom = screenZoomSB->value();
879 rc.dpi = screenDpiSB->value();
880 rc.font_sizes[FONT_SIZE_TINY] = widgetToDoubleStr(screenTinyED);
881 rc.font_sizes[FONT_SIZE_SCRIPT] = widgetToDoubleStr(screenSmallestED);
882 rc.font_sizes[FONT_SIZE_FOOTNOTE] = widgetToDoubleStr(screenSmallerED);
883 rc.font_sizes[FONT_SIZE_SMALL] = widgetToDoubleStr(screenSmallED);
884 rc.font_sizes[FONT_SIZE_NORMAL] = widgetToDoubleStr(screenNormalED);
885 rc.font_sizes[FONT_SIZE_LARGE] = widgetToDoubleStr(screenLargeED);
886 rc.font_sizes[FONT_SIZE_LARGER] = widgetToDoubleStr(screenLargerED);
887 rc.font_sizes[FONT_SIZE_LARGEST] = widgetToDoubleStr(screenLargestED);
888 rc.font_sizes[FONT_SIZE_HUGE] = widgetToDoubleStr(screenHugeED);
889 rc.font_sizes[FONT_SIZE_HUGER] = widgetToDoubleStr(screenHugerED);
890 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
892 if (rc.font_sizes != oldrc.font_sizes
893 || rc.roman_font_name != oldrc.roman_font_name
894 || rc.sans_font_name != oldrc.sans_font_name
895 || rc.typewriter_font_name != oldrc.typewriter_font_name
896 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
897 // The global QPixmapCache is used in GuiPainter to cache text
898 // painting so we must reset it in case any of the above
899 // parameter is changed.
900 QPixmapCache::clear();
901 guiApp->fontLoader().update();
902 form_->updateScreenFonts();
907 void PrefScreenFonts::update(LyXRC const & rc)
909 setComboxFont(screenRomanCO, rc.roman_font_name,
910 rc.roman_font_foundry);
911 setComboxFont(screenSansCO, rc.sans_font_name,
912 rc.sans_font_foundry);
913 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
914 rc.typewriter_font_foundry);
916 selectRoman(screenRomanCO->currentText());
917 selectSans(screenSansCO->currentText());
918 selectTypewriter(screenTypewriterCO->currentText());
920 screenZoomSB->setValue(rc.zoom);
921 screenDpiSB->setValue(rc.dpi);
922 doubleToWidget(screenTinyED, rc.font_sizes[FONT_SIZE_TINY]);
923 doubleToWidget(screenSmallestED, rc.font_sizes[FONT_SIZE_SCRIPT]);
924 doubleToWidget(screenSmallerED, rc.font_sizes[FONT_SIZE_FOOTNOTE]);
925 doubleToWidget(screenSmallED, rc.font_sizes[FONT_SIZE_SMALL]);
926 doubleToWidget(screenNormalED, rc.font_sizes[FONT_SIZE_NORMAL]);
927 doubleToWidget(screenLargeED, rc.font_sizes[FONT_SIZE_LARGE]);
928 doubleToWidget(screenLargerED, rc.font_sizes[FONT_SIZE_LARGER]);
929 doubleToWidget(screenLargestED, rc.font_sizes[FONT_SIZE_LARGEST]);
930 doubleToWidget(screenHugeED, rc.font_sizes[FONT_SIZE_HUGE]);
931 doubleToWidget(screenHugerED, rc.font_sizes[FONT_SIZE_HUGER]);
933 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
934 #if defined(Q_WS_X11)
935 pixmapCacheCB->setEnabled(false);
941 void PrefScreenFonts::selectRoman(const QString & name)
943 screenRomanFE->set(QFont(name), name);
947 void PrefScreenFonts::selectSans(const QString & name)
949 screenSansFE->set(QFont(name), name);
953 void PrefScreenFonts::selectTypewriter(const QString & name)
955 screenTypewriterFE->set(QFont(name), name);
959 /////////////////////////////////////////////////////////////////////
963 /////////////////////////////////////////////////////////////////////
969 bool operator()(ColorCode lhs, ColorCode rhs) const {
971 compare_no_case(lcolor.getGUIName(lhs), lcolor.getGUIName(rhs)) < 0;
977 PrefColors::PrefColors(GuiPreferences * form)
978 : PrefModule(qt_(catLookAndFeel), qt_("Colors"), form)
982 // FIXME: all of this initialization should be put into the controller.
983 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
984 // for some discussion of why that is not trivial.
985 QPixmap icon(32, 32);
986 for (int i = 0; i < Color_ignore; ++i) {
987 ColorCode lc = static_cast<ColorCode>(i);
995 || lc == Color_magenta
996 || lc == Color_yellow
997 || lc == Color_inherit
998 || lc == Color_ignore
999 || lc == Color_greyedouttext
1000 || lc == Color_shadedbg) continue;
1002 lcolors_.push_back(lc);
1004 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
1005 vector<ColorCode>::const_iterator cit = lcolors_.begin();
1006 vector<ColorCode>::const_iterator const end = lcolors_.end();
1007 for (; cit != end; ++cit) {
1008 (void) new QListWidgetItem(QIcon(icon),
1009 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
1011 curcolors_.resize(lcolors_.size());
1012 newcolors_.resize(lcolors_.size());
1013 // End initialization
1015 connect(colorChangePB, SIGNAL(clicked()),
1016 this, SLOT(changeColor()));
1017 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
1018 this, SLOT(changeLyxObjectsSelection()));
1019 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
1020 this, SLOT(changeColor()));
1024 void PrefColors::apply(LyXRC & /*rc*/) const
1026 for (unsigned int i = 0; i < lcolors_.size(); ++i)
1027 if (curcolors_[i] != newcolors_[i])
1028 form_->setColor(lcolors_[i], newcolors_[i]);
1032 void PrefColors::update(LyXRC const & /*rc*/)
1034 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
1035 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
1036 QPixmap coloritem(32, 32);
1037 coloritem.fill(color);
1038 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
1039 newcolors_[i] = curcolors_[i] = color.name();
1041 changeLyxObjectsSelection();
1045 void PrefColors::changeColor()
1047 int const row = lyxObjectsLW->currentRow();
1053 QString const color = newcolors_[row];
1054 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
1056 if (c.isValid() && c.name() != color) {
1057 newcolors_[row] = c.name();
1058 QPixmap coloritem(32, 32);
1060 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
1066 void PrefColors::changeLyxObjectsSelection()
1068 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
1072 /////////////////////////////////////////////////////////////////////
1076 /////////////////////////////////////////////////////////////////////
1078 PrefDisplay::PrefDisplay(GuiPreferences * form)
1079 : PrefModule(qt_(catLookAndFeel), qt_("Display"), form)
1082 connect(displayGraphicsCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
1083 connect(instantPreviewCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
1084 connect(previewSizeSB, SIGNAL(valueChanged(double)), this, SIGNAL(changed()));
1085 connect(paragraphMarkerCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
1086 if (instantPreviewCO->currentIndex() == 0)
1087 previewSizeSB->setEnabled(false);
1089 previewSizeSB->setEnabled(true);
1093 void PrefDisplay::on_instantPreviewCO_currentIndexChanged(int index)
1096 previewSizeSB->setEnabled(false);
1098 previewSizeSB->setEnabled(true);
1102 void PrefDisplay::apply(LyXRC & rc) const
1104 switch (instantPreviewCO->currentIndex()) {
1105 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
1106 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
1107 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
1110 rc.display_graphics = displayGraphicsCB->isChecked();
1111 rc.preview_scale_factor = previewSizeSB->value();
1112 rc.paragraph_markers = paragraphMarkerCB->isChecked();
1114 // FIXME!! The graphics cache no longer has a changeDisplay method.
1116 if (old_value != rc.display_graphics) {
1117 graphics::GCache & gc = graphics::GCache::get();
1124 void PrefDisplay::update(LyXRC const & rc)
1126 switch (rc.preview) {
1127 case LyXRC::PREVIEW_OFF:
1128 instantPreviewCO->setCurrentIndex(0);
1130 case LyXRC::PREVIEW_NO_MATH :
1131 instantPreviewCO->setCurrentIndex(1);
1133 case LyXRC::PREVIEW_ON :
1134 instantPreviewCO->setCurrentIndex(2);
1138 displayGraphicsCB->setChecked(rc.display_graphics);
1139 instantPreviewCO->setEnabled(rc.display_graphics);
1140 previewSizeSB->setValue(rc.preview_scale_factor);
1141 paragraphMarkerCB->setChecked(rc.paragraph_markers);
1145 /////////////////////////////////////////////////////////////////////
1149 /////////////////////////////////////////////////////////////////////
1151 PrefPaths::PrefPaths(GuiPreferences * form)
1152 : PrefModule(QString(), qt_("Paths"), form)
1156 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(selectWorkingdir()));
1157 connect(workingDirED, SIGNAL(textChanged(QString)),
1158 this, SIGNAL(changed()));
1160 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(selectTemplatedir()));
1161 connect(templateDirED, SIGNAL(textChanged(QString)),
1162 this, SIGNAL(changed()));
1164 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(selectExampledir()));
1165 connect(exampleDirED, SIGNAL(textChanged(QString)),
1166 this, SIGNAL(changed()));
1168 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(selectBackupdir()));
1169 connect(backupDirED, SIGNAL(textChanged(QString)),
1170 this, SIGNAL(changed()));
1172 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(selectLyxPipe()));
1173 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
1174 this, SIGNAL(changed()));
1176 connect(thesaurusDirPB, SIGNAL(clicked()), this, SLOT(selectThesaurusdir()));
1177 connect(thesaurusDirED, SIGNAL(textChanged(QString)),
1178 this, SIGNAL(changed()));
1180 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(selectTempdir()));
1181 connect(tempDirED, SIGNAL(textChanged(QString)),
1182 this, SIGNAL(changed()));
1184 connect(hunspellDirPB, SIGNAL(clicked()), this, SLOT(selectHunspelldir()));
1185 connect(hunspellDirED, SIGNAL(textChanged(QString)),
1186 this, SIGNAL(changed()));
1188 connect(pathPrefixED, SIGNAL(textChanged(QString)),
1189 this, SIGNAL(changed()));
1193 void PrefPaths::apply(LyXRC & rc) const
1195 rc.document_path = internal_path(fromqstr(workingDirED->text()));
1196 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
1197 rc.template_path = internal_path(fromqstr(templateDirED->text()));
1198 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
1199 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
1200 rc.thesaurusdir_path = internal_path(fromqstr(thesaurusDirED->text()));
1201 rc.hunspelldir_path = internal_path(fromqstr(hunspellDirED->text()));
1202 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
1203 // FIXME: should be a checkbox only
1204 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
1208 void PrefPaths::update(LyXRC const & rc)
1210 workingDirED->setText(toqstr(external_path(rc.document_path)));
1211 exampleDirED->setText(toqstr(external_path(rc.example_path)));
1212 templateDirED->setText(toqstr(external_path(rc.template_path)));
1213 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
1214 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
1215 thesaurusDirED->setText(toqstr(external_path(rc.thesaurusdir_path)));
1216 hunspellDirED->setText(toqstr(external_path(rc.hunspelldir_path)));
1217 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
1218 // FIXME: should be a checkbox only
1219 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
1223 void PrefPaths::selectExampledir()
1225 QString file = browseDir(internalPath(exampleDirED->text()),
1226 qt_("Select directory for example files"));
1227 if (!file.isEmpty())
1228 exampleDirED->setText(file);
1232 void PrefPaths::selectTemplatedir()
1234 QString file = browseDir(internalPath(templateDirED->text()),
1235 qt_("Select a document templates directory"));
1236 if (!file.isEmpty())
1237 templateDirED->setText(file);
1241 void PrefPaths::selectTempdir()
1243 QString file = browseDir(internalPath(tempDirED->text()),
1244 qt_("Select a temporary directory"));
1245 if (!file.isEmpty())
1246 tempDirED->setText(file);
1250 void PrefPaths::selectBackupdir()
1252 QString file = browseDir(internalPath(backupDirED->text()),
1253 qt_("Select a backups directory"));
1254 if (!file.isEmpty())
1255 backupDirED->setText(file);
1259 void PrefPaths::selectWorkingdir()
1261 QString file = browseDir(internalPath(workingDirED->text()),
1262 qt_("Select a document directory"));
1263 if (!file.isEmpty())
1264 workingDirED->setText(file);
1268 void PrefPaths::selectThesaurusdir()
1270 QString file = browseDir(internalPath(thesaurusDirED->text()),
1271 qt_("Set the path to the thesaurus dictionaries"));
1272 if (!file.isEmpty())
1273 thesaurusDirED->setText(file);
1277 void PrefPaths::selectHunspelldir()
1279 QString file = browseDir(internalPath(hunspellDirED->text()),
1280 qt_("Set the path to the Hunspell dictionaries"));
1281 if (!file.isEmpty())
1282 hunspellDirED->setText(file);
1286 void PrefPaths::selectLyxPipe()
1288 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1289 qt_("Give a filename for the LyX server pipe"));
1290 if (!file.isEmpty())
1291 lyxserverDirED->setText(file);
1295 /////////////////////////////////////////////////////////////////////
1299 /////////////////////////////////////////////////////////////////////
1301 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form)
1302 : PrefModule(qt_(catLanguage), qt_("Spellchecker"), form)
1306 #if defined(USE_ASPELL)
1307 spellcheckerCB->addItem(qt_("aspell"), QString("aspell"));
1309 #if defined(USE_ENCHANT)
1310 spellcheckerCB->addItem(qt_("enchant"), QString("enchant"));
1312 #if defined(USE_HUNSPELL)
1313 spellcheckerCB->addItem(qt_("hunspell"), QString("hunspell"));
1316 #if defined(USE_ASPELL) || defined(USE_ENCHANT) || defined(USE_HUNSPELL)
1317 connect(spellcheckerCB, SIGNAL(currentIndexChanged(int)),
1318 this, SIGNAL(changed()));
1319 connect(altLanguageED, SIGNAL(textChanged(QString)),
1320 this, SIGNAL(changed()));
1321 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1322 this, SIGNAL(changed()));
1323 connect(compoundWordCB, SIGNAL(clicked()),
1324 this, SIGNAL(changed()));
1325 connect(spellcheckContinuouslyCB, SIGNAL(clicked()),
1326 this, SIGNAL(changed()));
1327 connect(spellcheckNotesCB, SIGNAL(clicked()),
1328 this, SIGNAL(changed()));
1330 spellcheckerCB->setEnabled(false);
1331 altLanguageED->setEnabled(false);
1332 escapeCharactersED->setEnabled(false);
1333 compoundWordCB->setEnabled(false);
1334 spellcheckContinuouslyCB->setEnabled(false);
1335 spellcheckNotesCB->setEnabled(false);
1340 void PrefSpellchecker::apply(LyXRC & rc) const
1342 rc.spellchecker = fromqstr(spellcheckerCB->itemData(
1343 spellcheckerCB->currentIndex()).toString());
1344 rc.spellchecker_alt_lang = fromqstr(altLanguageED->text());
1345 rc.spellchecker_esc_chars = fromqstr(escapeCharactersED->text());
1346 rc.spellchecker_accept_compound = compoundWordCB->isChecked();
1347 rc.spellcheck_continuously = spellcheckContinuouslyCB->isChecked();
1348 rc.spellcheck_notes = spellcheckNotesCB->isChecked();
1352 void PrefSpellchecker::update(LyXRC const & rc)
1354 spellcheckerCB->setCurrentIndex(
1355 spellcheckerCB->findData(toqstr(rc.spellchecker)));
1356 altLanguageED->setText(toqstr(rc.spellchecker_alt_lang));
1357 escapeCharactersED->setText(toqstr(rc.spellchecker_esc_chars));
1358 compoundWordCB->setChecked(rc.spellchecker_accept_compound);
1359 spellcheckContinuouslyCB->setChecked(rc.spellcheck_continuously);
1360 spellcheckNotesCB->setChecked(rc.spellcheck_notes);
1365 /////////////////////////////////////////////////////////////////////
1369 /////////////////////////////////////////////////////////////////////
1372 PrefConverters::PrefConverters(GuiPreferences * form)
1373 : PrefModule(qt_(catFiles), qt_("Converters"), form)
1377 connect(converterNewPB, SIGNAL(clicked()),
1378 this, SLOT(updateConverter()));
1379 connect(converterRemovePB, SIGNAL(clicked()),
1380 this, SLOT(removeConverter()));
1381 connect(converterModifyPB, SIGNAL(clicked()),
1382 this, SLOT(updateConverter()));
1383 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1384 this, SLOT(switchConverter()));
1385 connect(converterFromCO, SIGNAL(activated(QString)),
1386 this, SLOT(changeConverter()));
1387 connect(converterToCO, SIGNAL(activated(QString)),
1388 this, SLOT(changeConverter()));
1389 connect(converterED, SIGNAL(textEdited(QString)),
1390 this, SLOT(changeConverter()));
1391 connect(converterFlagED, SIGNAL(textEdited(QString)),
1392 this, SLOT(changeConverter()));
1393 connect(converterNewPB, SIGNAL(clicked()),
1394 this, SIGNAL(changed()));
1395 connect(converterRemovePB, SIGNAL(clicked()),
1396 this, SIGNAL(changed()));
1397 connect(converterModifyPB, SIGNAL(clicked()),
1398 this, SIGNAL(changed()));
1399 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1400 this, SIGNAL(changed()));
1402 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1403 //converterDefGB->setFocusProxy(convertersLW);
1407 void PrefConverters::apply(LyXRC & rc) const
1409 rc.use_converter_cache = cacheCB->isChecked();
1410 rc.converter_cache_maxage = int(widgetToDouble(maxAgeLE) * 86400.0);
1414 void PrefConverters::update(LyXRC const & rc)
1416 cacheCB->setChecked(rc.use_converter_cache);
1418 doubleToWidget(maxAgeLE, (double(rc.converter_cache_maxage) / 86400.0), 'g', 6);
1423 void PrefConverters::updateGui()
1425 form_->formats().sort();
1426 form_->converters().update(form_->formats());
1427 // save current selection
1428 QString current = converterFromCO->currentText()
1429 + " -> " + converterToCO->currentText();
1431 converterFromCO->clear();
1432 converterToCO->clear();
1434 Formats::const_iterator cit = form_->formats().begin();
1435 Formats::const_iterator end = form_->formats().end();
1436 for (; cit != end; ++cit) {
1437 converterFromCO->addItem(qt_(cit->prettyname()));
1438 converterToCO->addItem(qt_(cit->prettyname()));
1441 // currentRowChanged(int) is also triggered when updating the listwidget
1442 // block signals to avoid unnecessary calls to switchConverter()
1443 convertersLW->blockSignals(true);
1444 convertersLW->clear();
1446 Converters::const_iterator ccit = form_->converters().begin();
1447 Converters::const_iterator cend = form_->converters().end();
1448 for (; ccit != cend; ++ccit) {
1449 QString const name =
1450 qt_(ccit->From->prettyname()) + " -> " + qt_(ccit->To->prettyname());
1451 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1452 new QListWidgetItem(name, convertersLW, type);
1454 convertersLW->sortItems(Qt::AscendingOrder);
1455 convertersLW->blockSignals(false);
1457 // restore selection
1458 if (!current.isEmpty()) {
1459 QList<QListWidgetItem *> const item =
1460 convertersLW->findItems(current, Qt::MatchExactly);
1461 if (!item.isEmpty())
1462 convertersLW->setCurrentItem(item.at(0));
1465 // select first element if restoring failed
1466 if (convertersLW->currentRow() == -1)
1467 convertersLW->setCurrentRow(0);
1473 void PrefConverters::switchConverter()
1475 int const cnr = convertersLW->currentItem()->type();
1476 Converter const & c(form_->converters().get(cnr));
1477 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1478 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1479 converterED->setText(toqstr(c.command));
1480 converterFlagED->setText(toqstr(c.flags));
1486 void PrefConverters::changeConverter()
1492 void PrefConverters::updateButtons()
1494 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1495 Format const & to = form_->formats().get(converterToCO->currentIndex());
1496 int const sel = form_->converters().getNumber(from.name(), to.name());
1497 bool const known = sel >= 0;
1498 bool const valid = !(converterED->text().isEmpty()
1499 || from.name() == to.name());
1501 int const cnr = convertersLW->currentItem()->type();
1502 Converter const & c = form_->converters().get(cnr);
1503 string const old_command = c.command;
1504 string const old_flag = c.flags;
1505 string const new_command = fromqstr(converterED->text());
1506 string const new_flag = fromqstr(converterFlagED->text());
1508 bool modified = (old_command != new_command || old_flag != new_flag);
1510 converterModifyPB->setEnabled(valid && known && modified);
1511 converterNewPB->setEnabled(valid && !known);
1512 converterRemovePB->setEnabled(known);
1514 maxAgeLE->setEnabled(cacheCB->isChecked());
1515 maxAgeLA->setEnabled(cacheCB->isChecked());
1520 // specify unique from/to or it doesn't appear. This is really bad UI
1521 // this is why we can use the same function for both new and modify
1522 void PrefConverters::updateConverter()
1524 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1525 Format const & to = form_->formats().get(converterToCO->currentIndex());
1526 string const flags = fromqstr(converterFlagED->text());
1527 string const command = fromqstr(converterED->text());
1529 Converter const * old =
1530 form_->converters().getConverter(from.name(), to.name());
1531 form_->converters().add(from.name(), to.name(), command, flags);
1534 form_->converters().updateLast(form_->formats());
1538 // Remove all files created by this converter from the cache, since
1539 // the modified converter might create different files.
1540 ConverterCache::get().remove_all(from.name(), to.name());
1544 void PrefConverters::removeConverter()
1546 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1547 Format const & to = form_->formats().get(converterToCO->currentIndex());
1548 form_->converters().erase(from.name(), to.name());
1552 // Remove all files created by this converter from the cache, since
1553 // a possible new converter might create different files.
1554 ConverterCache::get().remove_all(from.name(), to.name());
1558 void PrefConverters::on_cacheCB_stateChanged(int state)
1560 maxAgeLE->setEnabled(state == Qt::Checked);
1561 maxAgeLA->setEnabled(state == Qt::Checked);
1566 /////////////////////////////////////////////////////////////////////
1570 /////////////////////////////////////////////////////////////////////
1572 class FormatValidator : public QValidator
1575 FormatValidator(QWidget *, Formats const & f);
1576 void fixup(QString & input) const;
1577 QValidator::State validate(QString & input, int & pos) const;
1579 virtual QString toString(Format const & format) const = 0;
1581 Formats const & formats_;
1585 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1586 : QValidator(parent), formats_(f)
1591 void FormatValidator::fixup(QString & input) const
1593 Formats::const_iterator cit = formats_.begin();
1594 Formats::const_iterator end = formats_.end();
1595 for (; cit != end; ++cit) {
1596 QString const name = toString(*cit);
1597 if (distance(formats_.begin(), cit) == nr()) {
1605 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1607 Formats::const_iterator cit = formats_.begin();
1608 Formats::const_iterator end = formats_.end();
1609 bool unknown = true;
1610 for (; unknown && cit != end; ++cit) {
1611 QString const name = toString(*cit);
1612 if (distance(formats_.begin(), cit) != nr())
1613 unknown = name != input;
1616 if (unknown && !input.isEmpty())
1617 return QValidator::Acceptable;
1619 return QValidator::Intermediate;
1623 int FormatValidator::nr() const
1625 QComboBox * p = qobject_cast<QComboBox *>(parent());
1626 return p->itemData(p->currentIndex()).toInt();
1630 /////////////////////////////////////////////////////////////////////
1632 // FormatNameValidator
1634 /////////////////////////////////////////////////////////////////////
1636 class FormatNameValidator : public FormatValidator
1639 FormatNameValidator(QWidget * parent, Formats const & f)
1640 : FormatValidator(parent, f)
1643 QString toString(Format const & format) const
1645 return toqstr(format.name());
1650 /////////////////////////////////////////////////////////////////////
1652 // FormatPrettynameValidator
1654 /////////////////////////////////////////////////////////////////////
1656 class FormatPrettynameValidator : public FormatValidator
1659 FormatPrettynameValidator(QWidget * parent, Formats const & f)
1660 : FormatValidator(parent, f)
1663 QString toString(Format const & format) const
1665 return qt_(format.prettyname());
1670 /////////////////////////////////////////////////////////////////////
1674 /////////////////////////////////////////////////////////////////////
1676 PrefFileformats::PrefFileformats(GuiPreferences * form)
1677 : PrefModule(qt_(catFiles), qt_("File formats"), form)
1680 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1681 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1683 connect(documentCB, SIGNAL(clicked()),
1684 this, SLOT(setFlags()));
1685 connect(vectorCB, SIGNAL(clicked()),
1686 this, SLOT(setFlags()));
1687 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1688 this, SLOT(updatePrettyname()));
1689 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1690 this, SIGNAL(changed()));
1691 connect(defaultFormatCB, SIGNAL(activated(QString)),
1692 this, SIGNAL(changed()));
1693 connect(viewerCO, SIGNAL(activated(int)),
1694 this, SIGNAL(changed()));
1695 connect(editorCO, SIGNAL(activated(int)),
1696 this, SIGNAL(changed()));
1702 string const l10n_shortcut(string const prettyname, string const shortcut)
1704 if (shortcut.empty())
1707 string l10n_format =
1708 to_utf8(_(prettyname + '|' + shortcut));
1709 return split(l10n_format, '|');
1712 }; // namespace anon
1715 void PrefFileformats::apply(LyXRC & rc) const
1717 QString const default_format = defaultFormatCB->itemData(
1718 defaultFormatCB->currentIndex()).toString();
1719 rc.default_view_format = fromqstr(default_format);
1723 void PrefFileformats::update(LyXRC const & rc)
1725 viewer_alternatives = rc.viewer_alternatives;
1726 editor_alternatives = rc.editor_alternatives;
1727 bool const init = defaultFormatCB->currentText().isEmpty();
1731 defaultFormatCB->findData(toqstr(rc.default_view_format));
1732 defaultFormatCB->setCurrentIndex(pos);
1737 void PrefFileformats::updateView()
1739 QString const current = formatsCB->currentText();
1740 QString const current_def = defaultFormatCB->currentText();
1742 // update comboboxes with formats
1743 formatsCB->blockSignals(true);
1744 defaultFormatCB->blockSignals(true);
1746 defaultFormatCB->clear();
1747 form_->formats().sort();
1748 Formats::const_iterator cit = form_->formats().begin();
1749 Formats::const_iterator end = form_->formats().end();
1750 for (; cit != end; ++cit) {
1751 formatsCB->addItem(qt_(cit->prettyname()),
1752 QVariant(form_->formats().getNumber(cit->name())));
1753 if (form_->converters().isReachable("latex", cit->name())
1754 || form_->converters().isReachable("pdflatex", cit->name()))
1755 defaultFormatCB->addItem(qt_(cit->prettyname()),
1756 QVariant(toqstr(cit->name())));
1759 // restore selection
1760 int item = formatsCB->findText(current, Qt::MatchExactly);
1761 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1762 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1763 item = defaultFormatCB->findText(current_def, Qt::MatchExactly);
1764 defaultFormatCB->setCurrentIndex(item < 0 ? 0 : item);
1765 formatsCB->blockSignals(false);
1766 defaultFormatCB->blockSignals(false);
1770 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1772 int const nr = formatsCB->itemData(i).toInt();
1773 Format const f = form_->formats().get(nr);
1775 formatED->setText(toqstr(f.name()));
1776 copierED->setText(toqstr(form_->movers().command(f.name())));
1777 extensionED->setText(toqstr(f.extension()));
1778 shortcutED->setText(
1779 toqstr(l10n_shortcut(f.prettyname(), f.shortcut())));
1780 documentCB->setChecked((f.documentFormat()));
1781 vectorCB->setChecked((f.vectorFormat()));
1787 void PrefFileformats::setFlags()
1789 int flags = Format::none;
1790 if (documentCB->isChecked())
1791 flags |= Format::document;
1792 if (vectorCB->isChecked())
1793 flags |= Format::vector;
1794 currentFormat().setFlags(flags);
1799 void PrefFileformats::on_copierED_textEdited(const QString & s)
1801 string const fmt = fromqstr(formatED->text());
1802 form_->movers().set(fmt, fromqstr(s));
1807 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1809 currentFormat().setExtension(fromqstr(s));
1813 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1815 currentFormat().setViewer(fromqstr(s));
1820 void PrefFileformats::on_editorED_textEdited(const QString & s)
1822 currentFormat().setEditor(fromqstr(s));
1827 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1829 string const new_shortcut = fromqstr(s);
1830 if (new_shortcut == l10n_shortcut(currentFormat().prettyname(),
1831 currentFormat().shortcut()))
1833 currentFormat().setShortcut(new_shortcut);
1838 void PrefFileformats::on_formatED_editingFinished()
1840 string const newname = fromqstr(formatED->displayText());
1841 if (newname == currentFormat().name())
1844 currentFormat().setName(newname);
1849 void PrefFileformats::on_formatED_textChanged(const QString &)
1851 QString t = formatED->text();
1853 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1854 setValid(formatLA, valid);
1858 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1860 QString t = formatsCB->currentText();
1862 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1863 setValid(formatsLA, valid);
1867 void PrefFileformats::updatePrettyname()
1869 QString const newname = formatsCB->currentText();
1870 if (newname == qt_(currentFormat().prettyname()))
1873 currentFormat().setPrettyname(fromqstr(newname));
1881 void updateComboBox(LyXRC::Alternatives const & alts,
1882 string const & fmt, QComboBox * combo)
1884 LyXRC::Alternatives::const_iterator it =
1886 if (it != alts.end()) {
1887 LyXRC::CommandSet const & cmds = it->second;
1888 LyXRC::CommandSet::const_iterator sit =
1890 LyXRC::CommandSet::const_iterator const sen =
1892 for (; sit != sen; ++sit) {
1893 QString const qcmd = toqstr(*sit);
1894 combo->addItem(qcmd, qcmd);
1901 void PrefFileformats::updateViewers()
1903 Format const f = currentFormat();
1904 viewerCO->blockSignals(true);
1906 viewerCO->addItem(qt_("None"), QString());
1907 updateComboBox(viewer_alternatives, f.name(), viewerCO);
1908 viewerCO->addItem(qt_("Custom"), QString("custom viewer"));
1909 viewerCO->blockSignals(false);
1911 int pos = viewerCO->findData(toqstr(f.viewer()));
1914 viewerED->setEnabled(false);
1915 viewerCO->setCurrentIndex(pos);
1917 viewerED->setEnabled(true);
1918 viewerED->setText(toqstr(f.viewer()));
1919 viewerCO->setCurrentIndex(viewerCO->findData(toqstr("custom viewer")));
1924 void PrefFileformats::updateEditors()
1926 Format const f = currentFormat();
1927 editorCO->blockSignals(true);
1929 editorCO->addItem(qt_("None"), QString());
1930 updateComboBox(editor_alternatives, f.name(), editorCO);
1931 editorCO->addItem(qt_("Custom"), QString("custom editor"));
1932 editorCO->blockSignals(false);
1934 int pos = editorCO->findData(toqstr(f.editor()));
1937 editorED->setEnabled(false);
1938 editorCO->setCurrentIndex(pos);
1940 editorED->setEnabled(true);
1941 editorED->setText(toqstr(f.editor()));
1942 editorCO->setCurrentIndex(editorCO->findData(toqstr("custom editor")));
1947 void PrefFileformats::on_viewerCO_currentIndexChanged(int i)
1949 bool const custom = viewerCO->itemData(i).toString() == "custom viewer";
1950 viewerED->setEnabled(custom);
1952 currentFormat().setViewer(fromqstr(viewerCO->itemData(i).toString()));
1956 void PrefFileformats::on_editorCO_currentIndexChanged(int i)
1958 bool const custom = editorCO->itemData(i).toString() == "custom editor";
1959 editorED->setEnabled(custom);
1961 currentFormat().setEditor(fromqstr(editorCO->itemData(i).toString()));
1965 Format & PrefFileformats::currentFormat()
1967 int const i = formatsCB->currentIndex();
1968 int const nr = formatsCB->itemData(i).toInt();
1969 return form_->formats().get(nr);
1973 void PrefFileformats::on_formatNewPB_clicked()
1975 form_->formats().add("", "", "", "", "", "", Format::none);
1977 formatsCB->setCurrentIndex(0);
1978 formatsCB->setFocus(Qt::OtherFocusReason);
1982 void PrefFileformats::on_formatRemovePB_clicked()
1984 int const i = formatsCB->currentIndex();
1985 int const nr = formatsCB->itemData(i).toInt();
1986 string const current_text = form_->formats().get(nr).name();
1987 if (form_->converters().formatIsUsed(current_text)) {
1988 Alert::error(_("Format in use"),
1989 _("Cannot remove a Format used by a Converter. "
1990 "Remove the converter first."));
1994 form_->formats().erase(current_text);
1997 on_formatsCB_editTextChanged(formatsCB->currentText());
2002 /////////////////////////////////////////////////////////////////////
2006 /////////////////////////////////////////////////////////////////////
2008 PrefLanguage::PrefLanguage(GuiPreferences * form)
2009 : PrefModule(qt_(catLanguage), qt_("Language"), form)
2013 connect(rtlGB, SIGNAL(clicked()),
2014 this, SIGNAL(changed()));
2015 connect(visualCursorRB, SIGNAL(clicked()),
2016 this, SIGNAL(changed()));
2017 connect(logicalCursorRB, SIGNAL(clicked()),
2018 this, SIGNAL(changed()));
2019 connect(markForeignCB, SIGNAL(clicked()),
2020 this, SIGNAL(changed()));
2021 connect(autoBeginCB, SIGNAL(clicked()),
2022 this, SIGNAL(changed()));
2023 connect(autoEndCB, SIGNAL(clicked()),
2024 this, SIGNAL(changed()));
2025 connect(useBabelCB, SIGNAL(clicked()),
2026 this, SIGNAL(changed()));
2027 connect(globalCB, SIGNAL(clicked()),
2028 this, SIGNAL(changed()));
2029 connect(languagePackageED, SIGNAL(textChanged(QString)),
2030 this, SIGNAL(changed()));
2031 connect(startCommandED, SIGNAL(textChanged(QString)),
2032 this, SIGNAL(changed()));
2033 connect(endCommandED, SIGNAL(textChanged(QString)),
2034 this, SIGNAL(changed()));
2035 connect(uiLanguageCO, SIGNAL(activated(int)),
2036 this, SIGNAL(changed()));
2038 uiLanguageCO->clear();
2040 QAbstractItemModel * language_model = guiApp->languageModel();
2041 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
2042 language_model->sort(0);
2044 // FIXME: This is wrong, we need filter this list based on the available
2046 uiLanguageCO->blockSignals(true);
2047 uiLanguageCO->addItem(qt_("Default"), toqstr("auto"));
2048 for (int i = 0; i != language_model->rowCount(); ++i) {
2049 QModelIndex index = language_model->index(i, 0);
2050 uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
2051 index.data(Qt::UserRole).toString());
2053 uiLanguageCO->blockSignals(false);
2057 void PrefLanguage::on_uiLanguageCO_currentIndexChanged(int)
2059 QMessageBox::information(this, qt_("LyX needs to be restarted!"),
2060 qt_("The change of user interface language will be fully "
2061 "effective only after a restart."));
2065 void PrefLanguage::apply(LyXRC & rc) const
2067 // FIXME: remove rtl_support bool
2068 rc.rtl_support = rtlGB->isChecked();
2069 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
2070 rc.mark_foreign_language = markForeignCB->isChecked();
2071 rc.language_auto_begin = autoBeginCB->isChecked();
2072 rc.language_auto_end = autoEndCB->isChecked();
2073 rc.language_use_babel = useBabelCB->isChecked();
2074 rc.language_global_options = globalCB->isChecked();
2075 rc.language_package = fromqstr(languagePackageED->text());
2076 rc.language_command_begin = fromqstr(startCommandED->text());
2077 rc.language_command_end = fromqstr(endCommandED->text());
2078 rc.gui_language = fromqstr(
2079 uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString());
2083 void PrefLanguage::update(LyXRC const & rc)
2085 // FIXME: remove rtl_support bool
2086 rtlGB->setChecked(rc.rtl_support);
2087 if (rc.visual_cursor)
2088 visualCursorRB->setChecked(true);
2090 logicalCursorRB->setChecked(true);
2091 markForeignCB->setChecked(rc.mark_foreign_language);
2092 autoBeginCB->setChecked(rc.language_auto_begin);
2093 autoEndCB->setChecked(rc.language_auto_end);
2094 useBabelCB->setChecked(rc.language_use_babel);
2095 globalCB->setChecked(rc.language_global_options);
2096 languagePackageED->setText(toqstr(rc.language_package));
2097 startCommandED->setText(toqstr(rc.language_command_begin));
2098 endCommandED->setText(toqstr(rc.language_command_end));
2100 int pos = uiLanguageCO->findData(toqstr(rc.gui_language));
2101 uiLanguageCO->blockSignals(true);
2102 uiLanguageCO->setCurrentIndex(pos);
2103 uiLanguageCO->blockSignals(false);
2107 /////////////////////////////////////////////////////////////////////
2111 /////////////////////////////////////////////////////////////////////
2113 PrefPrinter::PrefPrinter(GuiPreferences * form)
2114 : PrefModule(qt_(catOutput), qt_("Printer"), form)
2118 connect(printerAdaptCB, SIGNAL(clicked()),
2119 this, SIGNAL(changed()));
2120 connect(printerCommandED, SIGNAL(textChanged(QString)),
2121 this, SIGNAL(changed()));
2122 connect(printerNameED, SIGNAL(textChanged(QString)),
2123 this, SIGNAL(changed()));
2124 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
2125 this, SIGNAL(changed()));
2126 connect(printerCopiesED, SIGNAL(textChanged(QString)),
2127 this, SIGNAL(changed()));
2128 connect(printerReverseED, SIGNAL(textChanged(QString)),
2129 this, SIGNAL(changed()));
2130 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
2131 this, SIGNAL(changed()));
2132 connect(printerExtensionED, SIGNAL(textChanged(QString)),
2133 this, SIGNAL(changed()));
2134 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
2135 this, SIGNAL(changed()));
2136 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
2137 this, SIGNAL(changed()));
2138 connect(printerEvenED, SIGNAL(textChanged(QString)),
2139 this, SIGNAL(changed()));
2140 connect(printerOddED, SIGNAL(textChanged(QString)),
2141 this, SIGNAL(changed()));
2142 connect(printerCollatedED, SIGNAL(textChanged(QString)),
2143 this, SIGNAL(changed()));
2144 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
2145 this, SIGNAL(changed()));
2146 connect(printerToFileED, SIGNAL(textChanged(QString)),
2147 this, SIGNAL(changed()));
2148 connect(printerExtraED, SIGNAL(textChanged(QString)),
2149 this, SIGNAL(changed()));
2150 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
2151 this, SIGNAL(changed()));
2152 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
2153 this, SIGNAL(changed()));
2157 void PrefPrinter::apply(LyXRC & rc) const
2159 rc.print_adapt_output = printerAdaptCB->isChecked();
2160 rc.print_command = fromqstr(printerCommandED->text());
2161 rc.printer = fromqstr(printerNameED->text());
2163 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
2164 rc.print_copies_flag = fromqstr(printerCopiesED->text());
2165 rc.print_reverse_flag = fromqstr(printerReverseED->text());
2166 rc.print_to_printer = fromqstr(printerToPrinterED->text());
2167 rc.print_file_extension = fromqstr(printerExtensionED->text());
2168 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
2169 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
2170 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
2171 rc.print_oddpage_flag = fromqstr(printerOddED->text());
2172 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
2173 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
2174 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
2175 rc.print_extra_options = fromqstr(printerExtraED->text());
2176 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
2177 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
2181 void PrefPrinter::update(LyXRC const & rc)
2183 printerAdaptCB->setChecked(rc.print_adapt_output);
2184 printerCommandED->setText(toqstr(rc.print_command));
2185 printerNameED->setText(toqstr(rc.printer));
2187 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
2188 printerCopiesED->setText(toqstr(rc.print_copies_flag));
2189 printerReverseED->setText(toqstr(rc.print_reverse_flag));
2190 printerToPrinterED->setText(toqstr(rc.print_to_printer));
2191 printerExtensionED->setText(toqstr(rc.print_file_extension));
2192 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
2193 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
2194 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
2195 printerOddED->setText(toqstr(rc.print_oddpage_flag));
2196 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
2197 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
2198 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
2199 printerExtraED->setText(toqstr(rc.print_extra_options));
2200 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
2201 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
2205 /////////////////////////////////////////////////////////////////////
2207 // PrefUserInterface
2209 /////////////////////////////////////////////////////////////////////
2211 PrefUserInterface::PrefUserInterface(GuiPreferences * form)
2212 : PrefModule(qt_(catLookAndFeel), qt_("User interface"), form)
2216 connect(autoSaveCB, SIGNAL(toggled(bool)),
2217 autoSaveSB, SLOT(setEnabled(bool)));
2218 connect(autoSaveCB, SIGNAL(toggled(bool)),
2219 TextLabel1, SLOT(setEnabled(bool)));
2220 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
2221 this, SIGNAL(changed()));
2222 #if QT_VERSION < 0x040500
2223 singleCloseTabButtonCB->setEnabled(false);
2225 connect(singleCloseTabButtonCB, SIGNAL(clicked()),
2226 this, SIGNAL(changed()));
2227 connect(uiFilePB, SIGNAL(clicked()),
2228 this, SLOT(selectUi()));
2229 connect(uiFileED, SIGNAL(textChanged(QString)),
2230 this, SIGNAL(changed()));
2231 connect(restoreCursorCB, SIGNAL(clicked()),
2232 this, SIGNAL(changed()));
2233 connect(loadSessionCB, SIGNAL(clicked()),
2234 this, SIGNAL(changed()));
2235 connect(allowGeometrySessionCB, SIGNAL(clicked()),
2236 this, SIGNAL(changed()));
2237 connect(autoSaveSB, SIGNAL(valueChanged(int)),
2238 this, SIGNAL(changed()));
2239 connect(autoSaveCB, SIGNAL(clicked()),
2240 this, SIGNAL(changed()));
2241 connect(backupCB, SIGNAL(clicked()),
2242 this, SIGNAL(changed()));
2243 connect(saveCompressedCB, SIGNAL(clicked()),
2244 this, SIGNAL(changed()));
2245 connect(lastfilesSB, SIGNAL(valueChanged(int)),
2246 this, SIGNAL(changed()));
2247 connect(tooltipCB, SIGNAL(toggled(bool)),
2248 this, SIGNAL(changed()));
2249 lastfilesSB->setMaximum(maxlastfiles);
2253 void PrefUserInterface::apply(LyXRC & rc) const
2255 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
2256 rc.use_lastfilepos = restoreCursorCB->isChecked();
2257 rc.load_session = loadSessionCB->isChecked();
2258 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
2259 rc.autosave = autoSaveCB->isChecked() ? autoSaveSB->value() * 60 : 0;
2260 rc.make_backup = backupCB->isChecked();
2261 rc.save_compressed = saveCompressedCB->isChecked();
2262 rc.num_lastfiles = lastfilesSB->value();
2263 rc.use_tooltip = tooltipCB->isChecked();
2264 rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
2265 rc.single_close_tab_button = singleCloseTabButtonCB->isChecked();
2266 #if QT_VERSION < 0x040500
2267 rc.single_close_tab_button = true;
2272 void PrefUserInterface::update(LyXRC const & rc)
2274 uiFileED->setText(toqstr(external_path(rc.ui_file)));
2275 restoreCursorCB->setChecked(rc.use_lastfilepos);
2276 loadSessionCB->setChecked(rc.load_session);
2277 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
2278 // convert to minutes
2279 bool autosave = rc.autosave > 0;
2280 int mins = rc.autosave / 60;
2283 autoSaveSB->setValue(mins);
2284 autoSaveCB->setChecked(autosave);
2285 autoSaveSB->setEnabled(autosave);
2286 backupCB->setChecked(rc.make_backup);
2287 saveCompressedCB->setChecked(rc.save_compressed);
2288 lastfilesSB->setValue(rc.num_lastfiles);
2289 tooltipCB->setChecked(rc.use_tooltip);
2290 openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
2291 singleCloseTabButtonCB->setChecked(rc.single_close_tab_button);
2295 void PrefUserInterface::selectUi()
2297 QString file = form_->browseUI(internalPath(uiFileED->text()));
2298 if (!file.isEmpty())
2299 uiFileED->setText(file);
2303 void PrefUserInterface::on_clearSessionPB_clicked()
2305 guiApp->clearSession();
2310 /////////////////////////////////////////////////////////////////////
2314 /////////////////////////////////////////////////////////////////////
2316 PrefEdit::PrefEdit(GuiPreferences * form)
2317 : PrefModule(qt_(catEditing), qt_("Control"), form)
2321 connect(cursorFollowsCB, SIGNAL(clicked()),
2322 this, SIGNAL(changed()));
2323 connect(scrollBelowCB, SIGNAL(clicked()),
2324 this, SIGNAL(changed()));
2325 connect(sortEnvironmentsCB, SIGNAL(clicked()),
2326 this, SIGNAL(changed()));
2327 connect(groupEnvironmentsCB, SIGNAL(clicked()),
2328 this, SIGNAL(changed()));
2329 connect(macroEditStyleCO, SIGNAL(activated(int)),
2330 this, SIGNAL(changed()));
2331 connect(fullscreenLimitGB, SIGNAL(clicked()),
2332 this, SIGNAL(changed()));
2333 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
2334 this, SIGNAL(changed()));
2335 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
2336 this, SIGNAL(changed()));
2337 connect(toggleMenubarCB, SIGNAL(toggled(bool)),
2338 this, SIGNAL(changed()));
2339 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
2340 this, SIGNAL(changed()));
2341 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
2342 this, SIGNAL(changed()));
2346 void PrefEdit::apply(LyXRC & rc) const
2348 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
2349 rc.scroll_below_document = scrollBelowCB->isChecked();
2350 rc.sort_layouts = sortEnvironmentsCB->isChecked();
2351 rc.group_layouts = groupEnvironmentsCB->isChecked();
2352 switch (macroEditStyleCO->currentIndex()) {
2353 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
2354 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
2355 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
2357 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
2358 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
2359 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
2360 rc.full_screen_menubar = toggleMenubarCB->isChecked();
2361 rc.full_screen_width = fullscreenWidthSB->value();
2362 rc.full_screen_limit = fullscreenLimitGB->isChecked();
2366 void PrefEdit::update(LyXRC const & rc)
2368 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
2369 scrollBelowCB->setChecked(rc.scroll_below_document);
2370 sortEnvironmentsCB->setChecked(rc.sort_layouts);
2371 groupEnvironmentsCB->setChecked(rc.group_layouts);
2372 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
2373 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
2374 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
2375 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
2376 toggleMenubarCB->setChecked(rc.full_screen_menubar);
2377 fullscreenWidthSB->setValue(rc.full_screen_width);
2378 fullscreenLimitGB->setChecked(rc.full_screen_limit);
2382 /////////////////////////////////////////////////////////////////////
2386 /////////////////////////////////////////////////////////////////////
2389 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
2391 Ui::shortcutUi::setupUi(this);
2392 QDialog::setModal(true);
2396 PrefShortcuts::PrefShortcuts(GuiPreferences * form)
2397 : PrefModule(qt_(catEditing), qt_("Shortcuts"), form)
2401 shortcutsTW->setColumnCount(2);
2402 shortcutsTW->headerItem()->setText(0, qt_("Function"));
2403 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
2404 shortcutsTW->setSortingEnabled(true);
2405 // Multi-selection can be annoying.
2406 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
2408 connect(bindFilePB, SIGNAL(clicked()),
2409 this, SLOT(selectBind()));
2410 connect(bindFileED, SIGNAL(textChanged(QString)),
2411 this, SIGNAL(changed()));
2413 shortcut_ = new GuiShortcutDialog(this);
2414 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
2415 shortcut_bc_.setOK(shortcut_->okPB);
2416 shortcut_bc_.setCancel(shortcut_->cancelPB);
2418 connect(shortcut_->okPB, SIGNAL(clicked()),
2419 shortcut_, SLOT(accept()));
2420 connect(shortcut_->okPB, SIGNAL(clicked()),
2421 this, SIGNAL(changed()));
2422 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2423 shortcut_, SLOT(reject()));
2424 connect(shortcut_->clearPB, SIGNAL(clicked()),
2425 this, SLOT(shortcutClearPressed()));
2426 connect(shortcut_->removePB, SIGNAL(clicked()),
2427 this, SLOT(shortcutRemovePressed()));
2428 connect(shortcut_->okPB, SIGNAL(clicked()),
2429 this, SLOT(shortcutOkPressed()));
2430 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2431 this, SLOT(shortcutCancelPressed()));
2435 void PrefShortcuts::apply(LyXRC & rc) const
2437 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
2438 // write user_bind and user_unbind to .lyx/bind/user.bind
2439 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
2440 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
2441 lyxerr << "LyX could not create the user bind directory '"
2442 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2445 if (!bind_dir.isDirWritable()) {
2446 lyxerr << "LyX could not write to the user bind directory '"
2447 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2450 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
2451 user_unbind_.write(user_bind_file.toFilesystemEncoding(), false, true);
2452 user_bind_.write(user_bind_file.toFilesystemEncoding(), true, false);
2453 // immediately apply the keybindings. Why this is not done before?
2454 // The good thing is that the menus are updated automatically.
2455 theTopLevelKeymap().clear();
2456 theTopLevelKeymap().read("site");
2457 theTopLevelKeymap().read(rc.bind_file, 0, KeyMap::Fallback);
2458 theTopLevelKeymap().read("user", 0, KeyMap::MissingOK);
2462 void PrefShortcuts::update(LyXRC const & rc)
2464 bindFileED->setText(toqstr(external_path(rc.bind_file)));
2466 system_bind_.clear();
2468 user_unbind_.clear();
2469 system_bind_.read("site");
2470 system_bind_.read(rc.bind_file);
2471 // \unbind in user.bind is added to user_unbind_
2472 user_bind_.read("user", &user_unbind_, KeyMap::MissingOK);
2473 updateShortcutsTW();
2477 void PrefShortcuts::updateShortcutsTW()
2479 shortcutsTW->clear();
2481 editItem_ = new QTreeWidgetItem(shortcutsTW);
2482 editItem_->setText(0, qt_("Cursor, Mouse and Editing functions"));
2483 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2485 mathItem_ = new QTreeWidgetItem(shortcutsTW);
2486 mathItem_->setText(0, qt_("Mathematical Symbols"));
2487 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2489 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2490 bufferItem_->setText(0, qt_("Document and Window"));
2491 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2493 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2494 layoutItem_->setText(0, qt_("Font, Layouts and Textclasses"));
2495 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2497 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2498 systemItem_->setText(0, qt_("System and Miscellaneous"));
2499 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2501 // listBindings(unbound=true) lists all bound and unbound lfuns
2502 // Items in this list is tagged by its source.
2503 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2505 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2507 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2508 KeyMap::UserUnbind);
2509 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2510 user_bindinglist.end());
2511 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2512 user_unbindinglist.end());
2514 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2515 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2516 for (; it != it_end; ++it)
2517 insertShortcutItem(it->request, it->sequence, KeyMap::ItemType(it->tag));
2519 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2520 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2521 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2522 modifyPB->setEnabled(!items.isEmpty());
2524 shortcutsTW->resizeColumnToContents(0);
2528 void PrefShortcuts::setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag)
2530 item->setData(0, Qt::UserRole, QVariant(tag));
2534 case KeyMap::System:
2536 case KeyMap::UserBind:
2539 case KeyMap::UserUnbind:
2540 font.setStrikeOut(true);
2542 // this item is not displayed now.
2543 case KeyMap::UserExtraUnbind:
2544 font.setStrikeOut(true);
2548 item->setFont(1, font);
2552 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2553 KeySequence const & seq, KeyMap::ItemType tag)
2555 FuncCode const action = lfun.action();
2556 string const action_name = lyxaction.getActionName(action);
2557 QString const lfun_name = toqstr(from_utf8(action_name)
2558 + ' ' + lfun.argument());
2559 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2560 KeyMap::ItemType item_tag = tag;
2562 QTreeWidgetItem * newItem = 0;
2563 // for unbind items, try to find an existing item in the system bind list
2564 if (tag == KeyMap::UserUnbind) {
2565 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2566 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2567 for (int i = 0; i < items.size(); ++i) {
2568 if (items[i]->text(1) == shortcut)
2572 // if not found, this unbind item is KeyMap::UserExtraUnbind
2573 // Such an item is not displayed to avoid confusion (what is
2574 // unmatched removed?).
2576 item_tag = KeyMap::UserExtraUnbind;
2581 switch(lyxaction.getActionType(action)) {
2582 case LyXAction::Hidden:
2584 case LyXAction::Edit:
2585 newItem = new QTreeWidgetItem(editItem_);
2587 case LyXAction::Math:
2588 newItem = new QTreeWidgetItem(mathItem_);
2590 case LyXAction::Buffer:
2591 newItem = new QTreeWidgetItem(bufferItem_);
2593 case LyXAction::Layout:
2594 newItem = new QTreeWidgetItem(layoutItem_);
2596 case LyXAction::System:
2597 newItem = new QTreeWidgetItem(systemItem_);
2600 // this should not happen
2601 newItem = new QTreeWidgetItem(shortcutsTW);
2605 newItem->setText(0, lfun_name);
2606 newItem->setText(1, shortcut);
2607 // record BindFile representation to recover KeySequence when needed.
2608 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2609 setItemType(newItem, item_tag);
2614 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2616 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2617 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2618 modifyPB->setEnabled(!items.isEmpty());
2619 if (items.isEmpty())
2622 KeyMap::ItemType tag =
2623 static_cast<KeyMap::ItemType>(items[0]->data(0, Qt::UserRole).toInt());
2624 if (tag == KeyMap::UserUnbind)
2625 removePB->setText(qt_("Res&tore"));
2627 removePB->setText(qt_("Remo&ve"));
2631 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2637 void PrefShortcuts::modifyShortcut()
2639 QTreeWidgetItem * item = shortcutsTW->currentItem();
2640 if (item->flags() & Qt::ItemIsSelectable) {
2641 shortcut_->lfunLE->setText(item->text(0));
2642 save_lfun_ = item->text(0).trimmed();
2643 shortcut_->shortcutWG->setText(item->text(1));
2645 seq.parse(fromqstr(item->data(1, Qt::UserRole).toString()));
2646 shortcut_->shortcutWG->setKeySequence(seq);
2647 shortcut_->shortcutWG->setFocus();
2653 void PrefShortcuts::removeShortcut()
2655 // it seems that only one item can be selected, but I am
2656 // removing all selected items anyway.
2657 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2658 for (int i = 0; i < items.size(); ++i) {
2659 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2660 string lfun = fromqstr(items[i]->text(0));
2661 FuncRequest func = lyxaction.lookupFunc(lfun);
2662 KeyMap::ItemType tag =
2663 static_cast<KeyMap::ItemType>(items[i]->data(0, Qt::UserRole).toInt());
2666 case KeyMap::System: {
2667 // for system bind, we do not touch the item
2668 // but add an user unbind item
2669 user_unbind_.bind(shortcut, func);
2670 setItemType(items[i], KeyMap::UserUnbind);
2671 removePB->setText(qt_("Res&tore"));
2674 case KeyMap::UserBind: {
2675 // for user_bind, we remove this bind
2676 QTreeWidgetItem * parent = items[i]->parent();
2677 int itemIdx = parent->indexOfChild(items[i]);
2678 parent->takeChild(itemIdx);
2680 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2682 shortcutsTW->scrollToItem(parent);
2683 user_bind_.unbind(shortcut, func);
2686 case KeyMap::UserUnbind: {
2687 // for user_unbind, we remove the unbind, and the item
2688 // become KeyMap::System again.
2689 user_unbind_.unbind(shortcut, func);
2690 setItemType(items[i], KeyMap::System);
2691 removePB->setText(qt_("Remo&ve"));
2694 case KeyMap::UserExtraUnbind: {
2695 // for user unbind that is not in system bind file,
2696 // remove this unbind file
2697 QTreeWidgetItem * parent = items[i]->parent();
2698 parent->takeChild(parent->indexOfChild(items[i]));
2699 user_unbind_.unbind(shortcut, func);
2706 void PrefShortcuts::selectBind()
2708 QString file = form_->browsebind(internalPath(bindFileED->text()));
2709 if (!file.isEmpty()) {
2710 bindFileED->setText(file);
2711 system_bind_ = KeyMap();
2712 system_bind_.read(fromqstr(file));
2713 updateShortcutsTW();
2718 void PrefShortcuts::on_modifyPB_pressed()
2724 void PrefShortcuts::on_newPB_pressed()
2726 shortcut_->lfunLE->clear();
2727 shortcut_->shortcutWG->reset();
2728 save_lfun_ = QString();
2733 void PrefShortcuts::on_removePB_pressed()
2740 void PrefShortcuts::on_searchLE_textEdited()
2742 if (searchLE->text().isEmpty()) {
2743 // show all hidden items
2744 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2746 shortcutsTW->setItemHidden(*it++, false);
2749 // search both columns
2750 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2751 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2752 matched += shortcutsTW->findItems(searchLE->text(),
2753 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2755 // hide everyone (to avoid searching in matched QList repeatedly
2756 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2758 shortcutsTW->setItemHidden(*it++, true);
2759 // show matched items
2760 for (int i = 0; i < matched.size(); ++i) {
2761 shortcutsTW->setItemHidden(matched[i], false);
2762 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2767 docstring makeCmdString(FuncRequest const & f)
2769 docstring actionStr = from_ascii(lyxaction.getActionName(f.action()));
2770 if (!f.argument().empty())
2771 actionStr += " " + f.argument();
2776 void PrefShortcuts::shortcutOkPressed()
2778 QString const new_lfun = shortcut_->lfunLE->text();
2779 FuncRequest func = lyxaction.lookupFunc(fromqstr(new_lfun));
2781 if (func.action() == LFUN_UNKNOWN_ACTION) {
2782 Alert::error(_("Failed to create shortcut"),
2783 _("Unknown or invalid LyX function"));
2787 KeySequence k = shortcut_->shortcutWG->getKeySequence();
2788 if (k.length() == 0) {
2789 Alert::error(_("Failed to create shortcut"),
2790 _("Invalid or empty key sequence"));
2794 // check to see if there's been any change
2795 FuncRequest oldBinding = system_bind_.getBinding(k);
2796 if (oldBinding.action() == LFUN_UNKNOWN_ACTION)
2797 oldBinding = user_bind_.getBinding(k);
2798 if (oldBinding == func)
2799 // nothing has changed
2802 // make sure this key isn't already bound---and, if so, not unbound
2803 FuncCode const unbind = user_unbind_.getBinding(k).action();
2804 docstring const action_string = makeCmdString(oldBinding);
2805 if (oldBinding.action() > LFUN_NOACTION && unbind == LFUN_UNKNOWN_ACTION
2806 && save_lfun_ != toqstr(action_string)) {
2807 // FIXME Perhaps we should offer to over-write the old shortcut?
2808 // If so, we'll need to remove it from our list, etc.
2809 Alert::error(_("Failed to create shortcut"),
2810 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s\n"
2811 "You need to remove that binding before creating a new one."),
2812 k.print(KeySequence::ForGui), action_string));
2816 if (!save_lfun_.isEmpty())
2817 // real modification of the lfun's shortcut,
2818 // so remove the previous one
2821 QTreeWidgetItem * item = insertShortcutItem(func, k, KeyMap::UserBind);
2823 user_bind_.bind(&k, func);
2824 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2825 shortcutsTW->setItemExpanded(item->parent(), true);
2826 shortcutsTW->scrollToItem(item);
2828 Alert::error(_("Failed to create shortcut"),
2829 _("Can not insert shortcut to the list"));
2835 void PrefShortcuts::shortcutCancelPressed()
2837 shortcut_->shortcutWG->reset();
2841 void PrefShortcuts::shortcutClearPressed()
2843 shortcut_->shortcutWG->reset();
2847 void PrefShortcuts::shortcutRemovePressed()
2849 shortcut_->shortcutWG->removeFromSequence();
2853 /////////////////////////////////////////////////////////////////////
2857 /////////////////////////////////////////////////////////////////////
2859 PrefIdentity::PrefIdentity(GuiPreferences * form)
2860 : PrefModule(QString(), qt_("Identity"), form)
2864 connect(nameED, SIGNAL(textChanged(QString)),
2865 this, SIGNAL(changed()));
2866 connect(emailED, SIGNAL(textChanged(QString)),
2867 this, SIGNAL(changed()));
2871 void PrefIdentity::apply(LyXRC & rc) const
2873 rc.user_name = fromqstr(nameED->text());
2874 rc.user_email = fromqstr(emailED->text());
2878 void PrefIdentity::update(LyXRC const & rc)
2880 nameED->setText(toqstr(rc.user_name));
2881 emailED->setText(toqstr(rc.user_email));
2886 /////////////////////////////////////////////////////////////////////
2890 /////////////////////////////////////////////////////////////////////
2892 GuiPreferences::GuiPreferences(GuiView & lv)
2893 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2897 QDialog::setModal(false);
2899 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2900 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2901 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2902 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2904 addModule(new PrefUserInterface(this));
2905 addModule(new PrefEdit(this));
2906 addModule(new PrefShortcuts(this));
2907 addModule(new PrefScreenFonts(this));
2908 addModule(new PrefColors(this));
2909 addModule(new PrefDisplay(this));
2910 addModule(new PrefInput(this));
2911 addModule(new PrefCompletion(this));
2913 addModule(new PrefPaths(this));
2915 addModule(new PrefIdentity(this));
2917 addModule(new PrefLanguage(this));
2918 addModule(new PrefSpellchecker(this));
2920 //for strftime validator
2921 PrefOutput * output = new PrefOutput(this);
2923 addModule(new PrefPrinter(this));
2924 addModule(new PrefLatex(this));
2926 PrefConverters * converters = new PrefConverters(this);
2927 PrefFileformats * formats = new PrefFileformats(this);
2928 connect(formats, SIGNAL(formatsChanged()),
2929 converters, SLOT(updateGui()));
2930 addModule(converters);
2933 prefsPS->setCurrentPanel(qt_("User interface"));
2934 // FIXME: hack to work around resizing bug in Qt >= 4.2
2935 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2936 #if QT_VERSION >= 0x040200
2937 prefsPS->updateGeometry();
2940 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2942 bc().setApply(applyPB);
2943 bc().setCancel(closePB);
2944 bc().setRestore(restorePB);
2946 // initialize the strftime validator
2947 bc().addCheckedLineEdit(output->DateED);
2951 void GuiPreferences::addModule(PrefModule * module)
2953 LASSERT(module, return);
2954 if (module->category().isEmpty())
2955 prefsPS->addPanel(module, module->title());
2957 prefsPS->addPanel(module, module->title(), module->category());
2958 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2959 modules_.push_back(module);
2963 void GuiPreferences::change_adaptor()
2969 void GuiPreferences::apply(LyXRC & rc) const
2971 size_t end = modules_.size();
2972 for (size_t i = 0; i != end; ++i)
2973 modules_[i]->apply(rc);
2977 void GuiPreferences::updateRc(LyXRC const & rc)
2979 size_t const end = modules_.size();
2980 for (size_t i = 0; i != end; ++i)
2981 modules_[i]->update(rc);
2985 void GuiPreferences::applyView()
2990 bool GuiPreferences::initialiseParams(string const &)
2993 formats_ = lyx::formats;
2994 converters_ = theConverters();
2995 converters_.update(formats_);
2996 movers_ = theMovers();
2998 update_screen_font_ = false;
3001 // Make sure that the bc is in the INITIAL state
3002 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3009 void GuiPreferences::dispatchParams()
3012 rc_.write(ss, true);
3013 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
3014 // FIXME: these need lfuns
3016 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
3018 lyx::formats = formats_;
3020 theConverters() = converters_;
3021 theConverters().update(lyx::formats);
3022 theConverters().buildGraph();
3024 theMovers() = movers_;
3026 vector<string>::const_iterator it = colors_.begin();
3027 vector<string>::const_iterator const end = colors_.end();
3028 for (; it != end; ++it)
3029 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
3032 if (update_screen_font_) {
3033 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
3034 update_screen_font_ = false;
3037 // The Save button has been pressed
3039 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
3043 void GuiPreferences::setColor(ColorCode col, QString const & hex)
3045 colors_.push_back(lcolor.getLyXName(col) + ' ' + fromqstr(hex));
3049 void GuiPreferences::updateScreenFonts()
3051 update_screen_font_ = true;
3055 QString GuiPreferences::browsebind(QString const & file) const
3057 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
3058 QStringList(qt_("LyX bind files (*.bind)")));
3062 QString GuiPreferences::browseUI(QString const & file) const
3064 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
3065 QStringList(qt_("LyX UI files (*.ui)")));
3069 QString GuiPreferences::browsekbmap(QString const & file) const
3071 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
3072 QStringList(qt_("LyX keyboard maps (*.kmap)")));
3076 QString GuiPreferences::browse(QString const & file,
3077 QString const & title) const
3079 return browseFile(file, title, QStringList(), true);
3083 // We support less paper sizes than the document dialog
3084 // Therefore this adjustment is needed.
3085 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
3089 return PAPER_DEFAULT;
3091 return PAPER_USLETTER;
3093 return PAPER_USLEGAL;
3095 return PAPER_USEXECUTIVE;
3105 // should not happen
3106 return PAPER_DEFAULT;
3111 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
3113 switch (papersize) {
3116 case PAPER_USLETTER:
3120 case PAPER_USEXECUTIVE:
3131 // should not happen
3137 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
3140 } // namespace frontend
3143 #include "moc_GuiPrefs.cpp"