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()));
374 void PrefOutput::on_DateED_textChanged(const QString &)
376 QString t = DateED->text();
378 bool valid = DateED->validator()->validate(t, p)
379 == QValidator::Acceptable;
380 setValid(DateLA, valid);
384 void PrefOutput::apply(LyXRC & rc) const
386 rc.date_insert_format = fromqstr(DateED->text());
387 rc.plaintext_linelen = plaintextLinelengthSB->value();
391 void PrefOutput::update(LyXRC const & rc)
393 DateED->setText(toqstr(rc.date_insert_format));
394 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
398 /////////////////////////////////////////////////////////////////////
402 /////////////////////////////////////////////////////////////////////
404 PrefInput::PrefInput(GuiPreferences * form)
405 : PrefModule(qt_(catEditing), qt_("Keyboard/Mouse"), form)
409 connect(keymapCB, SIGNAL(clicked()),
410 this, SIGNAL(changed()));
411 connect(firstKeymapED, SIGNAL(textChanged(QString)),
412 this, SIGNAL(changed()));
413 connect(secondKeymapED, SIGNAL(textChanged(QString)),
414 this, SIGNAL(changed()));
415 connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
416 this, SIGNAL(changed()));
420 void PrefInput::apply(LyXRC & rc) const
422 // FIXME: can derive CB from the two EDs
423 rc.use_kbmap = keymapCB->isChecked();
424 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
425 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
426 rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
430 void PrefInput::update(LyXRC const & rc)
432 // FIXME: can derive CB from the two EDs
433 keymapCB->setChecked(rc.use_kbmap);
434 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
435 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
436 mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
440 QString PrefInput::testKeymap(QString const & keymap)
442 return form_->browsekbmap(internalPath(keymap));
446 void PrefInput::on_firstKeymapPB_clicked(bool)
448 QString const file = testKeymap(firstKeymapED->text());
450 firstKeymapED->setText(file);
454 void PrefInput::on_secondKeymapPB_clicked(bool)
456 QString const file = testKeymap(secondKeymapED->text());
458 secondKeymapED->setText(file);
462 void PrefInput::on_keymapCB_toggled(bool keymap)
464 firstKeymapLA->setEnabled(keymap);
465 secondKeymapLA->setEnabled(keymap);
466 firstKeymapED->setEnabled(keymap);
467 secondKeymapED->setEnabled(keymap);
468 firstKeymapPB->setEnabled(keymap);
469 secondKeymapPB->setEnabled(keymap);
473 /////////////////////////////////////////////////////////////////////
477 /////////////////////////////////////////////////////////////////////
479 PrefCompletion::PrefCompletion(GuiPreferences * form)
480 : PrefModule(qt_(catEditing), qt_("Input Completion"), form)
484 connect(inlineDelaySB, SIGNAL(valueChanged(double)),
485 this, SIGNAL(changed()));
486 connect(inlineMathCB, SIGNAL(clicked()),
487 this, SIGNAL(changed()));
488 connect(inlineTextCB, SIGNAL(clicked()),
489 this, SIGNAL(changed()));
490 connect(inlineDotsCB, SIGNAL(clicked()),
491 this, SIGNAL(changed()));
492 connect(popupDelaySB, SIGNAL(valueChanged(double)),
493 this, SIGNAL(changed()));
494 connect(popupMathCB, SIGNAL(clicked()),
495 this, SIGNAL(changed()));
496 connect(autocorrectionCB, SIGNAL(clicked()),
497 this, SIGNAL(changed()));
498 connect(popupTextCB, SIGNAL(clicked()),
499 this, SIGNAL(changed()));
500 connect(popupAfterCompleteCB, SIGNAL(clicked()),
501 this, SIGNAL(changed()));
502 connect(cursorTextCB, SIGNAL(clicked()),
503 this, SIGNAL(changed()));
507 void PrefCompletion::on_inlineTextCB_clicked()
513 void PrefCompletion::on_popupTextCB_clicked()
519 void PrefCompletion::enableCB()
521 cursorTextCB->setEnabled(
522 popupTextCB->isChecked() || inlineTextCB->isChecked());
526 void PrefCompletion::apply(LyXRC & rc) const
528 rc.completion_inline_delay = inlineDelaySB->value();
529 rc.completion_inline_math = inlineMathCB->isChecked();
530 rc.completion_inline_text = inlineTextCB->isChecked();
531 rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
532 rc.completion_popup_delay = popupDelaySB->value();
533 rc.completion_popup_math = popupMathCB->isChecked();
534 rc.autocorrection_math = autocorrectionCB->isChecked();
535 rc.completion_popup_text = popupTextCB->isChecked();
536 rc.completion_cursor_text = cursorTextCB->isChecked();
537 rc.completion_popup_after_complete =
538 popupAfterCompleteCB->isChecked();
542 void PrefCompletion::update(LyXRC const & rc)
544 inlineDelaySB->setValue(rc.completion_inline_delay);
545 inlineMathCB->setChecked(rc.completion_inline_math);
546 inlineTextCB->setChecked(rc.completion_inline_text);
547 inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
548 popupDelaySB->setValue(rc.completion_popup_delay);
549 popupMathCB->setChecked(rc.completion_popup_math);
550 autocorrectionCB->setChecked(rc.autocorrection_math);
551 popupTextCB->setChecked(rc.completion_popup_text);
552 cursorTextCB->setChecked(rc.completion_cursor_text);
553 popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
559 /////////////////////////////////////////////////////////////////////
563 /////////////////////////////////////////////////////////////////////
565 PrefLatex::PrefLatex(GuiPreferences * form)
566 : PrefModule(qt_(catOutput), qt_("LaTeX"), form)
569 connect(latexEncodingCB, SIGNAL(clicked()),
570 this, SIGNAL(changed()));
571 connect(latexEncodingED, SIGNAL(textChanged(QString)),
572 this, SIGNAL(changed()));
573 connect(latexChecktexED, SIGNAL(textChanged(QString)),
574 this, SIGNAL(changed()));
575 connect(latexBibtexCO, SIGNAL(activated(int)),
576 this, SIGNAL(changed()));
577 connect(latexBibtexED, SIGNAL(textChanged(QString)),
578 this, SIGNAL(changed()));
579 connect(latexJBibtexED, SIGNAL(textChanged(QString)),
580 this, SIGNAL(changed()));
581 connect(latexIndexCO, SIGNAL(activated(int)),
582 this, SIGNAL(changed()));
583 connect(latexIndexED, SIGNAL(textChanged(QString)),
584 this, SIGNAL(changed()));
585 connect(latexJIndexED, SIGNAL(textChanged(QString)),
586 this, SIGNAL(changed()));
587 connect(latexAutoresetCB, SIGNAL(clicked()),
588 this, SIGNAL(changed()));
589 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
590 this, SIGNAL(changed()));
591 connect(latexPaperSizeCO, SIGNAL(activated(int)),
592 this, SIGNAL(changed()));
594 #if defined(__CYGWIN__) || defined(_WIN32)
595 pathCB->setVisible(true);
596 connect(pathCB, SIGNAL(clicked()),
597 this, SIGNAL(changed()));
599 pathCB->setVisible(false);
604 void PrefLatex::on_latexEncodingCB_stateChanged(int state)
606 latexEncodingED->setEnabled(state == Qt::Checked);
610 void PrefLatex::on_latexBibtexCO_activated(int n)
612 QString const bibtex = latexBibtexCO->itemData(n).toString();
613 if (bibtex.isEmpty()) {
614 latexBibtexED->clear();
615 latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
618 for (LyXRC::CommandSet::const_iterator it = bibtex_alternatives.begin();
619 it != bibtex_alternatives.end(); ++it) {
620 QString const bib = toqstr(*it);
621 int ind = bib.indexOf(" ");
622 QString sel_command = bib.left(ind);
623 QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
624 if (bibtex == sel_command) {
626 latexBibtexED->clear();
628 latexBibtexED->setText(sel_options.trimmed());
631 latexBibtexOptionsLA->setText(qt_("&Options:"));
635 void PrefLatex::on_latexIndexCO_activated(int n)
637 QString const index = latexIndexCO->itemData(n).toString();
638 if (index.isEmpty()) {
639 latexIndexED->clear();
640 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
643 for (LyXRC::CommandSet::const_iterator it = index_alternatives.begin();
644 it != index_alternatives.end(); ++it) {
645 QString const idx = toqstr(*it);
646 int ind = idx.indexOf(" ");
647 QString sel_command = idx.left(ind);
648 QString sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
649 if (index == sel_command) {
651 latexIndexED->clear();
653 latexIndexED->setText(sel_options.trimmed());
656 latexIndexOptionsLA->setText(qt_("Op&tions:"));
660 void PrefLatex::apply(LyXRC & rc) const
662 // If bibtex is not empty, bibopt contains the options, otherwise
663 // it is a customized bibtex command with options.
664 QString const bibtex = latexBibtexCO->itemData(
665 latexBibtexCO->currentIndex()).toString();
666 QString const bibopt = latexBibtexED->text();
667 if (bibtex.isEmpty())
668 rc.bibtex_command = fromqstr(bibopt);
669 else if (bibopt.isEmpty())
670 rc.bibtex_command = fromqstr(bibtex);
672 rc.bibtex_command = fromqstr(bibtex) + " " + fromqstr(bibopt);
674 // If index is not empty, idxopt contains the options, otherwise
675 // it is a customized index command with options.
676 QString const index = latexIndexCO->itemData(
677 latexIndexCO->currentIndex()).toString();
678 QString const idxopt = latexIndexED->text();
680 rc.index_command = fromqstr(idxopt);
681 else if (idxopt.isEmpty())
682 rc.index_command = fromqstr(index);
684 rc.index_command = fromqstr(index) + " " + fromqstr(idxopt);
686 if (latexEncodingCB->isChecked())
687 rc.fontenc = fromqstr(latexEncodingED->text());
689 rc.fontenc = "default";
690 rc.chktex_command = fromqstr(latexChecktexED->text());
691 rc.jbibtex_command = fromqstr(latexJBibtexED->text());
692 rc.jindex_command = fromqstr(latexJIndexED->text());
693 rc.nomencl_command = fromqstr(latexNomenclED->text());
694 rc.auto_reset_options = latexAutoresetCB->isChecked();
695 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
696 rc.default_papersize =
697 form_->toPaperSize(latexPaperSizeCO->currentIndex());
698 #if defined(__CYGWIN__) || defined(_WIN32)
699 rc.windows_style_tex_paths = pathCB->isChecked();
704 void PrefLatex::update(LyXRC const & rc)
706 latexBibtexCO->clear();
708 latexBibtexCO->addItem(qt_("Custom"), QString());
709 for (LyXRC::CommandSet::const_iterator it = rc.bibtex_alternatives.begin();
710 it != rc.bibtex_alternatives.end(); ++it) {
711 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
712 latexBibtexCO->addItem(command, command);
715 bibtex_alternatives = rc.bibtex_alternatives;
717 QString const bib = toqstr(rc.bibtex_command);
718 int ind = bib.indexOf(" ");
719 QString sel_command = bib.left(ind);
720 QString sel_options = ind < 0 ? QString() : bib.mid(ind + 1);
722 int pos = latexBibtexCO->findData(sel_command);
724 latexBibtexCO->setCurrentIndex(pos);
725 latexBibtexED->setText(sel_options.trimmed());
726 latexBibtexOptionsLA->setText(qt_("&Options:"));
728 latexBibtexED->setText(toqstr(rc.bibtex_command));
729 latexBibtexCO->setCurrentIndex(0);
730 latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
733 latexIndexCO->clear();
735 latexIndexCO->addItem(qt_("Custom"), QString());
736 for (LyXRC::CommandSet::const_iterator it = rc.index_alternatives.begin();
737 it != rc.index_alternatives.end(); ++it) {
738 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
739 latexIndexCO->addItem(command, command);
742 index_alternatives = rc.index_alternatives;
744 QString const idx = toqstr(rc.index_command);
745 ind = idx.indexOf(" ");
746 sel_command = idx.left(ind);
747 sel_options = ind < 0 ? QString() : idx.mid(ind + 1);
749 pos = latexIndexCO->findData(sel_command);
751 latexIndexCO->setCurrentIndex(pos);
752 latexIndexED->setText(sel_options.trimmed());
753 latexIndexOptionsLA->setText(qt_("Op&tions:"));
755 latexIndexED->setText(toqstr(rc.index_command));
756 latexIndexCO->setCurrentIndex(0);
757 latexIndexOptionsLA->setText(qt_("Co&mmand:"));
760 if (rc.fontenc == "default") {
761 latexEncodingCB->setChecked(false);
762 latexEncodingED->setEnabled(false);
764 latexEncodingCB->setChecked(true);
765 latexEncodingED->setEnabled(true);
766 latexEncodingED->setText(toqstr(rc.fontenc));
768 latexChecktexED->setText(toqstr(rc.chktex_command));
769 latexJBibtexED->setText(toqstr(rc.jbibtex_command));
770 latexJIndexED->setText(toqstr(rc.jindex_command));
771 latexNomenclED->setText(toqstr(rc.nomencl_command));
772 latexAutoresetCB->setChecked(rc.auto_reset_options);
773 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
774 latexPaperSizeCO->setCurrentIndex(
775 form_->fromPaperSize(rc.default_papersize));
776 #if defined(__CYGWIN__) || defined(_WIN32)
777 pathCB->setChecked(rc.windows_style_tex_paths);
782 /////////////////////////////////////////////////////////////////////
786 /////////////////////////////////////////////////////////////////////
788 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form)
789 : PrefModule(qt_(catLookAndFeel), qt_("Screen fonts"), form)
793 connect(screenRomanCO, SIGNAL(activated(QString)),
794 this, SLOT(selectRoman(QString)));
795 connect(screenSansCO, SIGNAL(activated(QString)),
796 this, SLOT(selectSans(QString)));
797 connect(screenTypewriterCO, SIGNAL(activated(QString)),
798 this, SLOT(selectTypewriter(QString)));
800 QFontDatabase fontdb;
801 QStringList families(fontdb.families());
802 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
803 screenRomanCO->addItem(*it);
804 screenSansCO->addItem(*it);
805 screenTypewriterCO->addItem(*it);
807 connect(screenRomanCO, SIGNAL(activated(QString)),
808 this, SIGNAL(changed()));
809 connect(screenSansCO, SIGNAL(activated(QString)),
810 this, SIGNAL(changed()));
811 connect(screenTypewriterCO, SIGNAL(activated(QString)),
812 this, SIGNAL(changed()));
813 connect(screenZoomSB, SIGNAL(valueChanged(int)),
814 this, SIGNAL(changed()));
815 connect(screenDpiSB, SIGNAL(valueChanged(int)),
816 this, SIGNAL(changed()));
817 connect(screenTinyED, SIGNAL(textChanged(QString)),
818 this, SIGNAL(changed()));
819 connect(screenSmallestED, SIGNAL(textChanged(QString)),
820 this, SIGNAL(changed()));
821 connect(screenSmallerED, SIGNAL(textChanged(QString)),
822 this, SIGNAL(changed()));
823 connect(screenSmallED, SIGNAL(textChanged(QString)),
824 this, SIGNAL(changed()));
825 connect(screenNormalED, SIGNAL(textChanged(QString)),
826 this, SIGNAL(changed()));
827 connect(screenLargeED, SIGNAL(textChanged(QString)),
828 this, SIGNAL(changed()));
829 connect(screenLargerED, SIGNAL(textChanged(QString)),
830 this, SIGNAL(changed()));
831 connect(screenLargestED, SIGNAL(textChanged(QString)),
832 this, SIGNAL(changed()));
833 connect(screenHugeED, SIGNAL(textChanged(QString)),
834 this, SIGNAL(changed()));
835 connect(screenHugerED, SIGNAL(textChanged(QString)),
836 this, SIGNAL(changed()));
837 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
838 this, SIGNAL(changed()));
840 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
841 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
842 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
843 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
844 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
845 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
846 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
847 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
848 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
849 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
853 void PrefScreenFonts::apply(LyXRC & rc) const
855 LyXRC const oldrc = rc;
857 parseFontName(screenRomanCO->currentText(),
858 rc.roman_font_name, rc.roman_font_foundry);
859 parseFontName(screenSansCO->currentText(),
860 rc.sans_font_name, rc.sans_font_foundry);
861 parseFontName(screenTypewriterCO->currentText(),
862 rc.typewriter_font_name, rc.typewriter_font_foundry);
864 rc.zoom = screenZoomSB->value();
865 rc.dpi = screenDpiSB->value();
866 rc.font_sizes[FONT_SIZE_TINY] = widgetToDoubleStr(screenTinyED);
867 rc.font_sizes[FONT_SIZE_SCRIPT] = widgetToDoubleStr(screenSmallestED);
868 rc.font_sizes[FONT_SIZE_FOOTNOTE] = widgetToDoubleStr(screenSmallerED);
869 rc.font_sizes[FONT_SIZE_SMALL] = widgetToDoubleStr(screenSmallED);
870 rc.font_sizes[FONT_SIZE_NORMAL] = widgetToDoubleStr(screenNormalED);
871 rc.font_sizes[FONT_SIZE_LARGE] = widgetToDoubleStr(screenLargeED);
872 rc.font_sizes[FONT_SIZE_LARGER] = widgetToDoubleStr(screenLargerED);
873 rc.font_sizes[FONT_SIZE_LARGEST] = widgetToDoubleStr(screenLargestED);
874 rc.font_sizes[FONT_SIZE_HUGE] = widgetToDoubleStr(screenHugeED);
875 rc.font_sizes[FONT_SIZE_HUGER] = widgetToDoubleStr(screenHugerED);
876 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
878 if (rc.font_sizes != oldrc.font_sizes
879 || rc.roman_font_name != oldrc.roman_font_name
880 || rc.sans_font_name != oldrc.sans_font_name
881 || rc.typewriter_font_name != oldrc.typewriter_font_name
882 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
883 // The global QPixmapCache is used in GuiPainter to cache text
884 // painting so we must reset it in case any of the above
885 // parameter is changed.
886 QPixmapCache::clear();
887 guiApp->fontLoader().update();
888 form_->updateScreenFonts();
893 void PrefScreenFonts::update(LyXRC const & rc)
895 setComboxFont(screenRomanCO, rc.roman_font_name,
896 rc.roman_font_foundry);
897 setComboxFont(screenSansCO, rc.sans_font_name,
898 rc.sans_font_foundry);
899 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
900 rc.typewriter_font_foundry);
902 selectRoman(screenRomanCO->currentText());
903 selectSans(screenSansCO->currentText());
904 selectTypewriter(screenTypewriterCO->currentText());
906 screenZoomSB->setValue(rc.zoom);
907 screenDpiSB->setValue(rc.dpi);
908 doubleToWidget(screenTinyED, rc.font_sizes[FONT_SIZE_TINY]);
909 doubleToWidget(screenSmallestED, rc.font_sizes[FONT_SIZE_SCRIPT]);
910 doubleToWidget(screenSmallerED, rc.font_sizes[FONT_SIZE_FOOTNOTE]);
911 doubleToWidget(screenSmallED, rc.font_sizes[FONT_SIZE_SMALL]);
912 doubleToWidget(screenNormalED, rc.font_sizes[FONT_SIZE_NORMAL]);
913 doubleToWidget(screenLargeED, rc.font_sizes[FONT_SIZE_LARGE]);
914 doubleToWidget(screenLargerED, rc.font_sizes[FONT_SIZE_LARGER]);
915 doubleToWidget(screenLargestED, rc.font_sizes[FONT_SIZE_LARGEST]);
916 doubleToWidget(screenHugeED, rc.font_sizes[FONT_SIZE_HUGE]);
917 doubleToWidget(screenHugerED, rc.font_sizes[FONT_SIZE_HUGER]);
919 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
920 #if defined(Q_WS_X11)
921 pixmapCacheCB->setEnabled(false);
927 void PrefScreenFonts::selectRoman(const QString & name)
929 screenRomanFE->set(QFont(name), name);
933 void PrefScreenFonts::selectSans(const QString & name)
935 screenSansFE->set(QFont(name), name);
939 void PrefScreenFonts::selectTypewriter(const QString & name)
941 screenTypewriterFE->set(QFont(name), name);
945 /////////////////////////////////////////////////////////////////////
949 /////////////////////////////////////////////////////////////////////
955 bool operator()(ColorCode lhs, ColorCode rhs) const {
957 compare_no_case(lcolor.getGUIName(lhs), lcolor.getGUIName(rhs)) < 0;
963 PrefColors::PrefColors(GuiPreferences * form)
964 : PrefModule(qt_(catLookAndFeel), qt_("Colors"), form)
968 // FIXME: all of this initialization should be put into the controller.
969 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
970 // for some discussion of why that is not trivial.
971 QPixmap icon(32, 32);
972 for (int i = 0; i < Color_ignore; ++i) {
973 ColorCode lc = static_cast<ColorCode>(i);
981 || lc == Color_magenta
982 || lc == Color_yellow
983 || lc == Color_inherit
984 || lc == Color_ignore
985 || lc == Color_greyedouttext
986 || lc == Color_shadedbg) continue;
988 lcolors_.push_back(lc);
990 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
991 vector<ColorCode>::const_iterator cit = lcolors_.begin();
992 vector<ColorCode>::const_iterator const end = lcolors_.end();
993 for (; cit != end; ++cit) {
994 (void) new QListWidgetItem(QIcon(icon),
995 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
997 curcolors_.resize(lcolors_.size());
998 newcolors_.resize(lcolors_.size());
999 // End initialization
1001 connect(colorChangePB, SIGNAL(clicked()),
1002 this, SLOT(changeColor()));
1003 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
1004 this, SLOT(changeLyxObjectsSelection()));
1005 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
1006 this, SLOT(changeColor()));
1010 void PrefColors::apply(LyXRC & /*rc*/) const
1012 for (unsigned int i = 0; i < lcolors_.size(); ++i)
1013 if (curcolors_[i] != newcolors_[i])
1014 form_->setColor(lcolors_[i], newcolors_[i]);
1018 void PrefColors::update(LyXRC const & /*rc*/)
1020 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
1021 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
1022 QPixmap coloritem(32, 32);
1023 coloritem.fill(color);
1024 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
1025 newcolors_[i] = curcolors_[i] = color.name();
1027 changeLyxObjectsSelection();
1031 void PrefColors::changeColor()
1033 int const row = lyxObjectsLW->currentRow();
1039 QString const color = newcolors_[row];
1040 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
1042 if (c.isValid() && c.name() != color) {
1043 newcolors_[row] = c.name();
1044 QPixmap coloritem(32, 32);
1046 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
1052 void PrefColors::changeLyxObjectsSelection()
1054 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
1058 /////////////////////////////////////////////////////////////////////
1062 /////////////////////////////////////////////////////////////////////
1064 PrefDisplay::PrefDisplay(GuiPreferences * form)
1065 : PrefModule(qt_(catLookAndFeel), qt_("Display"), form)
1068 connect(displayGraphicsCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
1069 connect(instantPreviewCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
1070 connect(previewSizeSB, SIGNAL(valueChanged(double)), this, SIGNAL(changed()));
1071 connect(paragraphMarkerCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
1072 if (instantPreviewCO->currentIndex() == 0)
1073 previewSizeSB->setEnabled(false);
1075 previewSizeSB->setEnabled(true);
1079 void PrefDisplay::on_instantPreviewCO_currentIndexChanged(int index)
1082 previewSizeSB->setEnabled(false);
1084 previewSizeSB->setEnabled(true);
1088 void PrefDisplay::apply(LyXRC & rc) const
1090 switch (instantPreviewCO->currentIndex()) {
1091 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
1092 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
1093 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
1096 rc.display_graphics = displayGraphicsCB->isChecked();
1097 rc.preview_scale_factor = previewSizeSB->value();
1098 rc.paragraph_markers = paragraphMarkerCB->isChecked();
1100 // FIXME!! The graphics cache no longer has a changeDisplay method.
1102 if (old_value != rc.display_graphics) {
1103 graphics::GCache & gc = graphics::GCache::get();
1110 void PrefDisplay::update(LyXRC const & rc)
1112 switch (rc.preview) {
1113 case LyXRC::PREVIEW_OFF:
1114 instantPreviewCO->setCurrentIndex(0);
1116 case LyXRC::PREVIEW_NO_MATH :
1117 instantPreviewCO->setCurrentIndex(1);
1119 case LyXRC::PREVIEW_ON :
1120 instantPreviewCO->setCurrentIndex(2);
1124 displayGraphicsCB->setChecked(rc.display_graphics);
1125 instantPreviewCO->setEnabled(rc.display_graphics);
1126 previewSizeSB->setValue(rc.preview_scale_factor);
1127 paragraphMarkerCB->setChecked(rc.paragraph_markers);
1131 /////////////////////////////////////////////////////////////////////
1135 /////////////////////////////////////////////////////////////////////
1137 PrefPaths::PrefPaths(GuiPreferences * form)
1138 : PrefModule(QString(), qt_("Paths"), form)
1142 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(selectWorkingdir()));
1143 connect(workingDirED, SIGNAL(textChanged(QString)),
1144 this, SIGNAL(changed()));
1146 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(selectTemplatedir()));
1147 connect(templateDirED, SIGNAL(textChanged(QString)),
1148 this, SIGNAL(changed()));
1150 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(selectExampledir()));
1151 connect(exampleDirED, SIGNAL(textChanged(QString)),
1152 this, SIGNAL(changed()));
1154 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(selectBackupdir()));
1155 connect(backupDirED, SIGNAL(textChanged(QString)),
1156 this, SIGNAL(changed()));
1158 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(selectLyxPipe()));
1159 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
1160 this, SIGNAL(changed()));
1162 connect(thesaurusDirPB, SIGNAL(clicked()), this, SLOT(selectThesaurusdir()));
1163 connect(thesaurusDirED, SIGNAL(textChanged(QString)),
1164 this, SIGNAL(changed()));
1166 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(selectTempdir()));
1167 connect(tempDirED, SIGNAL(textChanged(QString)),
1168 this, SIGNAL(changed()));
1170 connect(hunspellDirPB, SIGNAL(clicked()), this, SLOT(selectHunspelldir()));
1171 connect(hunspellDirED, SIGNAL(textChanged(QString)),
1172 this, SIGNAL(changed()));
1174 connect(pathPrefixED, SIGNAL(textChanged(QString)),
1175 this, SIGNAL(changed()));
1179 void PrefPaths::apply(LyXRC & rc) const
1181 rc.document_path = internal_path(fromqstr(workingDirED->text()));
1182 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
1183 rc.template_path = internal_path(fromqstr(templateDirED->text()));
1184 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
1185 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
1186 rc.thesaurusdir_path = internal_path(fromqstr(thesaurusDirED->text()));
1187 rc.hunspelldir_path = internal_path(fromqstr(hunspellDirED->text()));
1188 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
1189 // FIXME: should be a checkbox only
1190 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
1194 void PrefPaths::update(LyXRC const & rc)
1196 workingDirED->setText(toqstr(external_path(rc.document_path)));
1197 exampleDirED->setText(toqstr(external_path(rc.example_path)));
1198 templateDirED->setText(toqstr(external_path(rc.template_path)));
1199 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
1200 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
1201 thesaurusDirED->setText(toqstr(external_path(rc.thesaurusdir_path)));
1202 hunspellDirED->setText(toqstr(external_path(rc.hunspelldir_path)));
1203 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
1204 // FIXME: should be a checkbox only
1205 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
1209 void PrefPaths::selectExampledir()
1211 QString file = browseDir(internalPath(exampleDirED->text()),
1212 qt_("Select directory for example files"));
1213 if (!file.isEmpty())
1214 exampleDirED->setText(file);
1218 void PrefPaths::selectTemplatedir()
1220 QString file = browseDir(internalPath(templateDirED->text()),
1221 qt_("Select a document templates directory"));
1222 if (!file.isEmpty())
1223 templateDirED->setText(file);
1227 void PrefPaths::selectTempdir()
1229 QString file = browseDir(internalPath(tempDirED->text()),
1230 qt_("Select a temporary directory"));
1231 if (!file.isEmpty())
1232 tempDirED->setText(file);
1236 void PrefPaths::selectBackupdir()
1238 QString file = browseDir(internalPath(backupDirED->text()),
1239 qt_("Select a backups directory"));
1240 if (!file.isEmpty())
1241 backupDirED->setText(file);
1245 void PrefPaths::selectWorkingdir()
1247 QString file = browseDir(internalPath(workingDirED->text()),
1248 qt_("Select a document directory"));
1249 if (!file.isEmpty())
1250 workingDirED->setText(file);
1254 void PrefPaths::selectThesaurusdir()
1256 QString file = browseDir(internalPath(thesaurusDirED->text()),
1257 qt_("Set the path to the thesaurus dictionaries"));
1258 if (!file.isEmpty())
1259 thesaurusDirED->setText(file);
1263 void PrefPaths::selectHunspelldir()
1265 QString file = browseDir(internalPath(hunspellDirED->text()),
1266 qt_("Set the path to the Hunspell dictionaries"));
1267 if (!file.isEmpty())
1268 hunspellDirED->setText(file);
1272 void PrefPaths::selectLyxPipe()
1274 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1275 qt_("Give a filename for the LyX server pipe"));
1276 if (!file.isEmpty())
1277 lyxserverDirED->setText(file);
1281 /////////////////////////////////////////////////////////////////////
1285 /////////////////////////////////////////////////////////////////////
1287 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form)
1288 : PrefModule(qt_(catLanguage), qt_("Spellchecker"), form)
1292 #if defined(USE_ASPELL)
1293 spellcheckerCB->addItem(qt_("aspell"), QString("aspell"));
1295 #if defined(USE_ENCHANT)
1296 spellcheckerCB->addItem(qt_("enchant"), QString("enchant"));
1298 #if defined(USE_HUNSPELL)
1299 spellcheckerCB->addItem(qt_("hunspell"), QString("hunspell"));
1302 #if defined(USE_ASPELL) || defined(USE_ENCHANT) || defined(USE_HUNSPELL)
1303 connect(spellcheckerCB, SIGNAL(currentIndexChanged(int)),
1304 this, SIGNAL(changed()));
1305 connect(altLanguageED, SIGNAL(textChanged(QString)),
1306 this, SIGNAL(changed()));
1307 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1308 this, SIGNAL(changed()));
1309 connect(compoundWordCB, SIGNAL(clicked()),
1310 this, SIGNAL(changed()));
1311 connect(spellcheckContinuouslyCB, SIGNAL(clicked()),
1312 this, SIGNAL(changed()));
1313 connect(spellcheckNotesCB, SIGNAL(clicked()),
1314 this, SIGNAL(changed()));
1316 spellcheckerCB->setEnabled(false);
1317 altLanguageED->setEnabled(false);
1318 escapeCharactersED->setEnabled(false);
1319 compoundWordCB->setEnabled(false);
1320 spellcheckContinuouslyCB->setEnabled(false);
1321 spellcheckNotesCB->setEnabled(false);
1326 void PrefSpellchecker::apply(LyXRC & rc) const
1328 rc.spellchecker = fromqstr(spellcheckerCB->itemData(
1329 spellcheckerCB->currentIndex()).toString());
1330 rc.spellchecker_alt_lang = fromqstr(altLanguageED->text());
1331 rc.spellchecker_esc_chars = fromqstr(escapeCharactersED->text());
1332 rc.spellchecker_accept_compound = compoundWordCB->isChecked();
1333 rc.spellcheck_continuously = spellcheckContinuouslyCB->isChecked();
1334 rc.spellcheck_notes = spellcheckNotesCB->isChecked();
1338 void PrefSpellchecker::update(LyXRC const & rc)
1340 spellcheckerCB->setCurrentIndex(
1341 spellcheckerCB->findData(toqstr(rc.spellchecker)));
1342 altLanguageED->setText(toqstr(rc.spellchecker_alt_lang));
1343 escapeCharactersED->setText(toqstr(rc.spellchecker_esc_chars));
1344 compoundWordCB->setChecked(rc.spellchecker_accept_compound);
1345 spellcheckContinuouslyCB->setChecked(rc.spellcheck_continuously);
1346 spellcheckNotesCB->setChecked(rc.spellcheck_notes);
1351 /////////////////////////////////////////////////////////////////////
1355 /////////////////////////////////////////////////////////////////////
1358 PrefConverters::PrefConverters(GuiPreferences * form)
1359 : PrefModule(qt_(catFiles), qt_("Converters"), form)
1363 connect(converterNewPB, SIGNAL(clicked()),
1364 this, SLOT(updateConverter()));
1365 connect(converterRemovePB, SIGNAL(clicked()),
1366 this, SLOT(removeConverter()));
1367 connect(converterModifyPB, SIGNAL(clicked()),
1368 this, SLOT(updateConverter()));
1369 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1370 this, SLOT(switchConverter()));
1371 connect(converterFromCO, SIGNAL(activated(QString)),
1372 this, SLOT(changeConverter()));
1373 connect(converterToCO, SIGNAL(activated(QString)),
1374 this, SLOT(changeConverter()));
1375 connect(converterED, SIGNAL(textEdited(QString)),
1376 this, SLOT(changeConverter()));
1377 connect(converterFlagED, SIGNAL(textEdited(QString)),
1378 this, SLOT(changeConverter()));
1379 connect(converterNewPB, SIGNAL(clicked()),
1380 this, SIGNAL(changed()));
1381 connect(converterRemovePB, SIGNAL(clicked()),
1382 this, SIGNAL(changed()));
1383 connect(converterModifyPB, SIGNAL(clicked()),
1384 this, SIGNAL(changed()));
1385 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1386 this, SIGNAL(changed()));
1388 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1389 //converterDefGB->setFocusProxy(convertersLW);
1393 void PrefConverters::apply(LyXRC & rc) const
1395 rc.use_converter_cache = cacheCB->isChecked();
1396 rc.converter_cache_maxage = int(widgetToDouble(maxAgeLE) * 86400.0);
1400 void PrefConverters::update(LyXRC const & rc)
1402 cacheCB->setChecked(rc.use_converter_cache);
1404 doubleToWidget(maxAgeLE, (double(rc.converter_cache_maxage) / 86400.0), 'g', 6);
1409 void PrefConverters::updateGui()
1411 form_->formats().sort();
1412 form_->converters().update(form_->formats());
1413 // save current selection
1414 QString current = converterFromCO->currentText()
1415 + " -> " + converterToCO->currentText();
1417 converterFromCO->clear();
1418 converterToCO->clear();
1420 Formats::const_iterator cit = form_->formats().begin();
1421 Formats::const_iterator end = form_->formats().end();
1422 for (; cit != end; ++cit) {
1423 converterFromCO->addItem(qt_(cit->prettyname()));
1424 converterToCO->addItem(qt_(cit->prettyname()));
1427 // currentRowChanged(int) is also triggered when updating the listwidget
1428 // block signals to avoid unnecessary calls to switchConverter()
1429 convertersLW->blockSignals(true);
1430 convertersLW->clear();
1432 Converters::const_iterator ccit = form_->converters().begin();
1433 Converters::const_iterator cend = form_->converters().end();
1434 for (; ccit != cend; ++ccit) {
1435 QString const name =
1436 qt_(ccit->From->prettyname()) + " -> " + qt_(ccit->To->prettyname());
1437 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1438 new QListWidgetItem(name, convertersLW, type);
1440 convertersLW->sortItems(Qt::AscendingOrder);
1441 convertersLW->blockSignals(false);
1443 // restore selection
1444 if (!current.isEmpty()) {
1445 QList<QListWidgetItem *> const item =
1446 convertersLW->findItems(current, Qt::MatchExactly);
1447 if (!item.isEmpty())
1448 convertersLW->setCurrentItem(item.at(0));
1451 // select first element if restoring failed
1452 if (convertersLW->currentRow() == -1)
1453 convertersLW->setCurrentRow(0);
1459 void PrefConverters::switchConverter()
1461 int const cnr = convertersLW->currentItem()->type();
1462 Converter const & c(form_->converters().get(cnr));
1463 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1464 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1465 converterED->setText(toqstr(c.command));
1466 converterFlagED->setText(toqstr(c.flags));
1472 void PrefConverters::changeConverter()
1478 void PrefConverters::updateButtons()
1480 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1481 Format const & to = form_->formats().get(converterToCO->currentIndex());
1482 int const sel = form_->converters().getNumber(from.name(), to.name());
1483 bool const known = sel >= 0;
1484 bool const valid = !(converterED->text().isEmpty()
1485 || from.name() == to.name());
1487 int const cnr = convertersLW->currentItem()->type();
1488 Converter const & c = form_->converters().get(cnr);
1489 string const old_command = c.command;
1490 string const old_flag = c.flags;
1491 string const new_command = fromqstr(converterED->text());
1492 string const new_flag = fromqstr(converterFlagED->text());
1494 bool modified = (old_command != new_command || old_flag != new_flag);
1496 converterModifyPB->setEnabled(valid && known && modified);
1497 converterNewPB->setEnabled(valid && !known);
1498 converterRemovePB->setEnabled(known);
1500 maxAgeLE->setEnabled(cacheCB->isChecked());
1501 maxAgeLA->setEnabled(cacheCB->isChecked());
1506 // specify unique from/to or it doesn't appear. This is really bad UI
1507 // this is why we can use the same function for both new and modify
1508 void PrefConverters::updateConverter()
1510 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1511 Format const & to = form_->formats().get(converterToCO->currentIndex());
1512 string const flags = fromqstr(converterFlagED->text());
1513 string const command = fromqstr(converterED->text());
1515 Converter const * old =
1516 form_->converters().getConverter(from.name(), to.name());
1517 form_->converters().add(from.name(), to.name(), command, flags);
1520 form_->converters().updateLast(form_->formats());
1524 // Remove all files created by this converter from the cache, since
1525 // the modified converter might create different files.
1526 ConverterCache::get().remove_all(from.name(), to.name());
1530 void PrefConverters::removeConverter()
1532 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1533 Format const & to = form_->formats().get(converterToCO->currentIndex());
1534 form_->converters().erase(from.name(), to.name());
1538 // Remove all files created by this converter from the cache, since
1539 // a possible new converter might create different files.
1540 ConverterCache::get().remove_all(from.name(), to.name());
1544 void PrefConverters::on_cacheCB_stateChanged(int state)
1546 maxAgeLE->setEnabled(state == Qt::Checked);
1547 maxAgeLA->setEnabled(state == Qt::Checked);
1552 /////////////////////////////////////////////////////////////////////
1556 /////////////////////////////////////////////////////////////////////
1558 class FormatValidator : public QValidator
1561 FormatValidator(QWidget *, Formats const & f);
1562 void fixup(QString & input) const;
1563 QValidator::State validate(QString & input, int & pos) const;
1565 virtual QString toString(Format const & format) const = 0;
1567 Formats const & formats_;
1571 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1572 : QValidator(parent), formats_(f)
1577 void FormatValidator::fixup(QString & input) const
1579 Formats::const_iterator cit = formats_.begin();
1580 Formats::const_iterator end = formats_.end();
1581 for (; cit != end; ++cit) {
1582 QString const name = toString(*cit);
1583 if (distance(formats_.begin(), cit) == nr()) {
1591 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1593 Formats::const_iterator cit = formats_.begin();
1594 Formats::const_iterator end = formats_.end();
1595 bool unknown = true;
1596 for (; unknown && cit != end; ++cit) {
1597 QString const name = toString(*cit);
1598 if (distance(formats_.begin(), cit) != nr())
1599 unknown = name != input;
1602 if (unknown && !input.isEmpty())
1603 return QValidator::Acceptable;
1605 return QValidator::Intermediate;
1609 int FormatValidator::nr() const
1611 QComboBox * p = qobject_cast<QComboBox *>(parent());
1612 return p->itemData(p->currentIndex()).toInt();
1616 /////////////////////////////////////////////////////////////////////
1618 // FormatNameValidator
1620 /////////////////////////////////////////////////////////////////////
1622 class FormatNameValidator : public FormatValidator
1625 FormatNameValidator(QWidget * parent, Formats const & f)
1626 : FormatValidator(parent, f)
1629 QString toString(Format const & format) const
1631 return toqstr(format.name());
1636 /////////////////////////////////////////////////////////////////////
1638 // FormatPrettynameValidator
1640 /////////////////////////////////////////////////////////////////////
1642 class FormatPrettynameValidator : public FormatValidator
1645 FormatPrettynameValidator(QWidget * parent, Formats const & f)
1646 : FormatValidator(parent, f)
1649 QString toString(Format const & format) const
1651 return qt_(format.prettyname());
1656 /////////////////////////////////////////////////////////////////////
1660 /////////////////////////////////////////////////////////////////////
1662 PrefFileformats::PrefFileformats(GuiPreferences * form)
1663 : PrefModule(qt_(catFiles), qt_("File formats"), form)
1666 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1667 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1669 connect(documentCB, SIGNAL(clicked()),
1670 this, SLOT(setFlags()));
1671 connect(vectorCB, SIGNAL(clicked()),
1672 this, SLOT(setFlags()));
1673 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1674 this, SLOT(updatePrettyname()));
1675 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1676 this, SIGNAL(changed()));
1677 connect(defaultFormatCB, SIGNAL(activated(QString)),
1678 this, SIGNAL(changed()));
1679 connect(viewerCO, SIGNAL(activated(int)),
1680 this, SIGNAL(changed()));
1681 connect(editorCO, SIGNAL(activated(int)),
1682 this, SIGNAL(changed()));
1688 string const l10n_shortcut(string const prettyname, string const shortcut)
1690 if (shortcut.empty())
1693 string l10n_format =
1694 to_utf8(_(prettyname + '|' + shortcut));
1695 return split(l10n_format, '|');
1698 }; // namespace anon
1701 void PrefFileformats::apply(LyXRC & rc) const
1703 QString const default_format = defaultFormatCB->itemData(
1704 defaultFormatCB->currentIndex()).toString();
1705 rc.default_view_format = fromqstr(default_format);
1709 void PrefFileformats::update(LyXRC const & rc)
1711 viewer_alternatives = rc.viewer_alternatives;
1712 editor_alternatives = rc.editor_alternatives;
1713 bool const init = defaultFormatCB->currentText().isEmpty();
1717 defaultFormatCB->findData(toqstr(rc.default_view_format));
1718 defaultFormatCB->setCurrentIndex(pos);
1723 void PrefFileformats::updateView()
1725 QString const current = formatsCB->currentText();
1726 QString const current_def = defaultFormatCB->currentText();
1728 // update comboboxes with formats
1729 formatsCB->blockSignals(true);
1730 defaultFormatCB->blockSignals(true);
1732 defaultFormatCB->clear();
1733 form_->formats().sort();
1734 Formats::const_iterator cit = form_->formats().begin();
1735 Formats::const_iterator end = form_->formats().end();
1736 for (; cit != end; ++cit) {
1737 formatsCB->addItem(qt_(cit->prettyname()),
1738 QVariant(form_->formats().getNumber(cit->name())));
1739 if (form_->converters().isReachable("latex", cit->name())
1740 || form_->converters().isReachable("pdflatex", cit->name()))
1741 defaultFormatCB->addItem(qt_(cit->prettyname()),
1742 QVariant(toqstr(cit->name())));
1745 // restore selection
1746 int item = formatsCB->findText(current, Qt::MatchExactly);
1747 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1748 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1749 item = defaultFormatCB->findText(current_def, Qt::MatchExactly);
1750 defaultFormatCB->setCurrentIndex(item < 0 ? 0 : item);
1751 formatsCB->blockSignals(false);
1752 defaultFormatCB->blockSignals(false);
1756 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1758 int const nr = formatsCB->itemData(i).toInt();
1759 Format const f = form_->formats().get(nr);
1761 formatED->setText(toqstr(f.name()));
1762 copierED->setText(toqstr(form_->movers().command(f.name())));
1763 extensionED->setText(toqstr(f.extension()));
1764 shortcutED->setText(
1765 toqstr(l10n_shortcut(f.prettyname(), f.shortcut())));
1766 documentCB->setChecked((f.documentFormat()));
1767 vectorCB->setChecked((f.vectorFormat()));
1773 void PrefFileformats::setFlags()
1775 int flags = Format::none;
1776 if (documentCB->isChecked())
1777 flags |= Format::document;
1778 if (vectorCB->isChecked())
1779 flags |= Format::vector;
1780 currentFormat().setFlags(flags);
1785 void PrefFileformats::on_copierED_textEdited(const QString & s)
1787 string const fmt = fromqstr(formatED->text());
1788 form_->movers().set(fmt, fromqstr(s));
1793 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1795 currentFormat().setExtension(fromqstr(s));
1799 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1801 currentFormat().setViewer(fromqstr(s));
1806 void PrefFileformats::on_editorED_textEdited(const QString & s)
1808 currentFormat().setEditor(fromqstr(s));
1813 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1815 string const new_shortcut = fromqstr(s);
1816 if (new_shortcut == l10n_shortcut(currentFormat().prettyname(),
1817 currentFormat().shortcut()))
1819 currentFormat().setShortcut(new_shortcut);
1824 void PrefFileformats::on_formatED_editingFinished()
1826 string const newname = fromqstr(formatED->displayText());
1827 if (newname == currentFormat().name())
1830 currentFormat().setName(newname);
1835 void PrefFileformats::on_formatED_textChanged(const QString &)
1837 QString t = formatED->text();
1839 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1840 setValid(formatLA, valid);
1844 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1846 QString t = formatsCB->currentText();
1848 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1849 setValid(formatsLA, valid);
1853 void PrefFileformats::updatePrettyname()
1855 QString const newname = formatsCB->currentText();
1856 if (newname == qt_(currentFormat().prettyname()))
1859 currentFormat().setPrettyname(fromqstr(newname));
1867 void updateComboBox(LyXRC::Alternatives const & alts,
1868 string const & fmt, QComboBox * combo)
1870 LyXRC::Alternatives::const_iterator it =
1872 if (it != alts.end()) {
1873 LyXRC::CommandSet const & cmds = it->second;
1874 LyXRC::CommandSet::const_iterator sit =
1876 LyXRC::CommandSet::const_iterator const sen =
1878 for (; sit != sen; ++sit) {
1879 QString const qcmd = toqstr(*sit);
1880 combo->addItem(qcmd, qcmd);
1887 void PrefFileformats::updateViewers()
1889 Format const f = currentFormat();
1890 viewerCO->blockSignals(true);
1892 viewerCO->addItem(qt_("None"), QString());
1893 updateComboBox(viewer_alternatives, f.name(), viewerCO);
1894 viewerCO->addItem(qt_("Custom"), QString("custom viewer"));
1895 viewerCO->blockSignals(false);
1897 int pos = viewerCO->findData(toqstr(f.viewer()));
1900 viewerED->setEnabled(false);
1901 viewerCO->setCurrentIndex(pos);
1903 viewerED->setEnabled(true);
1904 viewerED->setText(toqstr(f.viewer()));
1905 viewerCO->setCurrentIndex(viewerCO->findData(toqstr("custom viewer")));
1910 void PrefFileformats::updateEditors()
1912 Format const f = currentFormat();
1913 editorCO->blockSignals(true);
1915 editorCO->addItem(qt_("None"), QString());
1916 updateComboBox(editor_alternatives, f.name(), editorCO);
1917 editorCO->addItem(qt_("Custom"), QString("custom editor"));
1918 editorCO->blockSignals(false);
1920 int pos = editorCO->findData(toqstr(f.editor()));
1923 editorED->setEnabled(false);
1924 editorCO->setCurrentIndex(pos);
1926 editorED->setEnabled(true);
1927 editorED->setText(toqstr(f.editor()));
1928 editorCO->setCurrentIndex(editorCO->findData(toqstr("custom editor")));
1933 void PrefFileformats::on_viewerCO_currentIndexChanged(int i)
1935 bool const custom = viewerCO->itemData(i).toString() == "custom viewer";
1936 viewerED->setEnabled(custom);
1938 currentFormat().setViewer(fromqstr(viewerCO->itemData(i).toString()));
1942 void PrefFileformats::on_editorCO_currentIndexChanged(int i)
1944 bool const custom = editorCO->itemData(i).toString() == "custom editor";
1945 editorED->setEnabled(custom);
1947 currentFormat().setEditor(fromqstr(editorCO->itemData(i).toString()));
1951 Format & PrefFileformats::currentFormat()
1953 int const i = formatsCB->currentIndex();
1954 int const nr = formatsCB->itemData(i).toInt();
1955 return form_->formats().get(nr);
1959 void PrefFileformats::on_formatNewPB_clicked()
1961 form_->formats().add("", "", "", "", "", "", Format::none);
1963 formatsCB->setCurrentIndex(0);
1964 formatsCB->setFocus(Qt::OtherFocusReason);
1968 void PrefFileformats::on_formatRemovePB_clicked()
1970 int const i = formatsCB->currentIndex();
1971 int const nr = formatsCB->itemData(i).toInt();
1972 string const current_text = form_->formats().get(nr).name();
1973 if (form_->converters().formatIsUsed(current_text)) {
1974 Alert::error(_("Format in use"),
1975 _("Cannot remove a Format used by a Converter. "
1976 "Remove the converter first."));
1980 form_->formats().erase(current_text);
1983 on_formatsCB_editTextChanged(formatsCB->currentText());
1988 /////////////////////////////////////////////////////////////////////
1992 /////////////////////////////////////////////////////////////////////
1994 PrefLanguage::PrefLanguage(GuiPreferences * form)
1995 : PrefModule(qt_(catLanguage), qt_("Language"), form)
1999 connect(rtlGB, SIGNAL(clicked()),
2000 this, SIGNAL(changed()));
2001 connect(visualCursorRB, SIGNAL(clicked()),
2002 this, SIGNAL(changed()));
2003 connect(logicalCursorRB, SIGNAL(clicked()),
2004 this, SIGNAL(changed()));
2005 connect(markForeignCB, SIGNAL(clicked()),
2006 this, SIGNAL(changed()));
2007 connect(autoBeginCB, SIGNAL(clicked()),
2008 this, SIGNAL(changed()));
2009 connect(autoEndCB, SIGNAL(clicked()),
2010 this, SIGNAL(changed()));
2011 connect(useBabelCB, SIGNAL(clicked()),
2012 this, SIGNAL(changed()));
2013 connect(globalCB, SIGNAL(clicked()),
2014 this, SIGNAL(changed()));
2015 connect(languagePackageED, SIGNAL(textChanged(QString)),
2016 this, SIGNAL(changed()));
2017 connect(startCommandED, SIGNAL(textChanged(QString)),
2018 this, SIGNAL(changed()));
2019 connect(endCommandED, SIGNAL(textChanged(QString)),
2020 this, SIGNAL(changed()));
2021 connect(uiLanguageCO, SIGNAL(activated(int)),
2022 this, SIGNAL(changed()));
2024 uiLanguageCO->clear();
2026 QAbstractItemModel * language_model = guiApp->languageModel();
2027 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
2028 language_model->sort(0);
2030 // FIXME: This is wrong, we need filter this list based on the available
2032 uiLanguageCO->blockSignals(true);
2033 uiLanguageCO->addItem(qt_("Default"), toqstr("auto"));
2034 for (int i = 0; i != language_model->rowCount(); ++i) {
2035 QModelIndex index = language_model->index(i, 0);
2036 uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
2037 index.data(Qt::UserRole).toString());
2039 uiLanguageCO->blockSignals(false);
2043 void PrefLanguage::on_uiLanguageCO_currentIndexChanged(int)
2045 QMessageBox::information(this, qt_("LyX needs to be restarted!"),
2046 qt_("The change of user interface language will be fully "
2047 "effective only after a restart."));
2051 void PrefLanguage::apply(LyXRC & rc) const
2053 // FIXME: remove rtl_support bool
2054 rc.rtl_support = rtlGB->isChecked();
2055 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
2056 rc.mark_foreign_language = markForeignCB->isChecked();
2057 rc.language_auto_begin = autoBeginCB->isChecked();
2058 rc.language_auto_end = autoEndCB->isChecked();
2059 rc.language_use_babel = useBabelCB->isChecked();
2060 rc.language_global_options = globalCB->isChecked();
2061 rc.language_package = fromqstr(languagePackageED->text());
2062 rc.language_command_begin = fromqstr(startCommandED->text());
2063 rc.language_command_end = fromqstr(endCommandED->text());
2064 rc.gui_language = fromqstr(
2065 uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString());
2069 void PrefLanguage::update(LyXRC const & rc)
2071 // FIXME: remove rtl_support bool
2072 rtlGB->setChecked(rc.rtl_support);
2073 if (rc.visual_cursor)
2074 visualCursorRB->setChecked(true);
2076 logicalCursorRB->setChecked(true);
2077 markForeignCB->setChecked(rc.mark_foreign_language);
2078 autoBeginCB->setChecked(rc.language_auto_begin);
2079 autoEndCB->setChecked(rc.language_auto_end);
2080 useBabelCB->setChecked(rc.language_use_babel);
2081 globalCB->setChecked(rc.language_global_options);
2082 languagePackageED->setText(toqstr(rc.language_package));
2083 startCommandED->setText(toqstr(rc.language_command_begin));
2084 endCommandED->setText(toqstr(rc.language_command_end));
2086 int pos = uiLanguageCO->findData(toqstr(rc.gui_language));
2087 uiLanguageCO->blockSignals(true);
2088 uiLanguageCO->setCurrentIndex(pos);
2089 uiLanguageCO->blockSignals(false);
2093 /////////////////////////////////////////////////////////////////////
2097 /////////////////////////////////////////////////////////////////////
2099 PrefPrinter::PrefPrinter(GuiPreferences * form)
2100 : PrefModule(qt_(catOutput), qt_("Printer"), form)
2104 connect(printerAdaptCB, SIGNAL(clicked()),
2105 this, SIGNAL(changed()));
2106 connect(printerCommandED, SIGNAL(textChanged(QString)),
2107 this, SIGNAL(changed()));
2108 connect(printerNameED, SIGNAL(textChanged(QString)),
2109 this, SIGNAL(changed()));
2110 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
2111 this, SIGNAL(changed()));
2112 connect(printerCopiesED, SIGNAL(textChanged(QString)),
2113 this, SIGNAL(changed()));
2114 connect(printerReverseED, SIGNAL(textChanged(QString)),
2115 this, SIGNAL(changed()));
2116 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
2117 this, SIGNAL(changed()));
2118 connect(printerExtensionED, SIGNAL(textChanged(QString)),
2119 this, SIGNAL(changed()));
2120 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
2121 this, SIGNAL(changed()));
2122 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
2123 this, SIGNAL(changed()));
2124 connect(printerEvenED, SIGNAL(textChanged(QString)),
2125 this, SIGNAL(changed()));
2126 connect(printerOddED, SIGNAL(textChanged(QString)),
2127 this, SIGNAL(changed()));
2128 connect(printerCollatedED, SIGNAL(textChanged(QString)),
2129 this, SIGNAL(changed()));
2130 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
2131 this, SIGNAL(changed()));
2132 connect(printerToFileED, SIGNAL(textChanged(QString)),
2133 this, SIGNAL(changed()));
2134 connect(printerExtraED, SIGNAL(textChanged(QString)),
2135 this, SIGNAL(changed()));
2136 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
2137 this, SIGNAL(changed()));
2138 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
2139 this, SIGNAL(changed()));
2143 void PrefPrinter::apply(LyXRC & rc) const
2145 rc.print_adapt_output = printerAdaptCB->isChecked();
2146 rc.print_command = fromqstr(printerCommandED->text());
2147 rc.printer = fromqstr(printerNameED->text());
2149 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
2150 rc.print_copies_flag = fromqstr(printerCopiesED->text());
2151 rc.print_reverse_flag = fromqstr(printerReverseED->text());
2152 rc.print_to_printer = fromqstr(printerToPrinterED->text());
2153 rc.print_file_extension = fromqstr(printerExtensionED->text());
2154 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
2155 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
2156 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
2157 rc.print_oddpage_flag = fromqstr(printerOddED->text());
2158 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
2159 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
2160 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
2161 rc.print_extra_options = fromqstr(printerExtraED->text());
2162 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
2163 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
2167 void PrefPrinter::update(LyXRC const & rc)
2169 printerAdaptCB->setChecked(rc.print_adapt_output);
2170 printerCommandED->setText(toqstr(rc.print_command));
2171 printerNameED->setText(toqstr(rc.printer));
2173 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
2174 printerCopiesED->setText(toqstr(rc.print_copies_flag));
2175 printerReverseED->setText(toqstr(rc.print_reverse_flag));
2176 printerToPrinterED->setText(toqstr(rc.print_to_printer));
2177 printerExtensionED->setText(toqstr(rc.print_file_extension));
2178 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
2179 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
2180 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
2181 printerOddED->setText(toqstr(rc.print_oddpage_flag));
2182 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
2183 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
2184 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
2185 printerExtraED->setText(toqstr(rc.print_extra_options));
2186 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
2187 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
2191 /////////////////////////////////////////////////////////////////////
2193 // PrefUserInterface
2195 /////////////////////////////////////////////////////////////////////
2197 PrefUserInterface::PrefUserInterface(GuiPreferences * form)
2198 : PrefModule(qt_(catLookAndFeel), qt_("User interface"), form)
2202 connect(autoSaveCB, SIGNAL(toggled(bool)),
2203 autoSaveSB, SLOT(setEnabled(bool)));
2204 connect(autoSaveCB, SIGNAL(toggled(bool)),
2205 TextLabel1, SLOT(setEnabled(bool)));
2206 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
2207 this, SIGNAL(changed()));
2208 #if QT_VERSION < 0x040500
2209 singleCloseTabButtonCB->setEnabled(false);
2211 connect(singleCloseTabButtonCB, SIGNAL(clicked()),
2212 this, SIGNAL(changed()));
2213 connect(uiFilePB, SIGNAL(clicked()),
2214 this, SLOT(selectUi()));
2215 connect(uiFileED, SIGNAL(textChanged(QString)),
2216 this, SIGNAL(changed()));
2217 connect(restoreCursorCB, SIGNAL(clicked()),
2218 this, SIGNAL(changed()));
2219 connect(loadSessionCB, SIGNAL(clicked()),
2220 this, SIGNAL(changed()));
2221 connect(allowGeometrySessionCB, SIGNAL(clicked()),
2222 this, SIGNAL(changed()));
2223 connect(autoSaveSB, SIGNAL(valueChanged(int)),
2224 this, SIGNAL(changed()));
2225 connect(autoSaveCB, SIGNAL(clicked()),
2226 this, SIGNAL(changed()));
2227 connect(backupCB, SIGNAL(clicked()),
2228 this, SIGNAL(changed()));
2229 connect(saveCompressedCB, SIGNAL(clicked()),
2230 this, SIGNAL(changed()));
2231 connect(lastfilesSB, SIGNAL(valueChanged(int)),
2232 this, SIGNAL(changed()));
2233 connect(tooltipCB, SIGNAL(toggled(bool)),
2234 this, SIGNAL(changed()));
2235 lastfilesSB->setMaximum(maxlastfiles);
2239 void PrefUserInterface::apply(LyXRC & rc) const
2241 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
2242 rc.use_lastfilepos = restoreCursorCB->isChecked();
2243 rc.load_session = loadSessionCB->isChecked();
2244 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
2245 rc.autosave = autoSaveCB->isChecked() ? autoSaveSB->value() * 60 : 0;
2246 rc.make_backup = backupCB->isChecked();
2247 rc.save_compressed = saveCompressedCB->isChecked();
2248 rc.num_lastfiles = lastfilesSB->value();
2249 rc.use_tooltip = tooltipCB->isChecked();
2250 rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
2251 rc.single_close_tab_button = singleCloseTabButtonCB->isChecked();
2252 #if QT_VERSION < 0x040500
2253 rc.single_close_tab_button = true;
2258 void PrefUserInterface::update(LyXRC const & rc)
2260 uiFileED->setText(toqstr(external_path(rc.ui_file)));
2261 restoreCursorCB->setChecked(rc.use_lastfilepos);
2262 loadSessionCB->setChecked(rc.load_session);
2263 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
2264 // convert to minutes
2265 bool autosave = rc.autosave > 0;
2266 int mins = rc.autosave / 60;
2269 autoSaveSB->setValue(mins);
2270 autoSaveCB->setChecked(autosave);
2271 autoSaveSB->setEnabled(autosave);
2272 backupCB->setChecked(rc.make_backup);
2273 saveCompressedCB->setChecked(rc.save_compressed);
2274 lastfilesSB->setValue(rc.num_lastfiles);
2275 tooltipCB->setChecked(rc.use_tooltip);
2276 openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
2277 singleCloseTabButtonCB->setChecked(rc.single_close_tab_button);
2281 void PrefUserInterface::selectUi()
2283 QString file = form_->browseUI(internalPath(uiFileED->text()));
2284 if (!file.isEmpty())
2285 uiFileED->setText(file);
2289 void PrefUserInterface::on_clearSessionPB_clicked()
2291 guiApp->clearSession();
2296 /////////////////////////////////////////////////////////////////////
2300 /////////////////////////////////////////////////////////////////////
2302 PrefEdit::PrefEdit(GuiPreferences * form)
2303 : PrefModule(qt_(catEditing), qt_("Control"), form)
2307 connect(cursorFollowsCB, SIGNAL(clicked()),
2308 this, SIGNAL(changed()));
2309 connect(scrollBelowCB, SIGNAL(clicked()),
2310 this, SIGNAL(changed()));
2311 connect(sortEnvironmentsCB, SIGNAL(clicked()),
2312 this, SIGNAL(changed()));
2313 connect(groupEnvironmentsCB, SIGNAL(clicked()),
2314 this, SIGNAL(changed()));
2315 connect(macroEditStyleCO, SIGNAL(activated(int)),
2316 this, SIGNAL(changed()));
2317 connect(fullscreenLimitGB, SIGNAL(clicked()),
2318 this, SIGNAL(changed()));
2319 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
2320 this, SIGNAL(changed()));
2321 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
2322 this, SIGNAL(changed()));
2323 connect(toggleMenubarCB, SIGNAL(toggled(bool)),
2324 this, SIGNAL(changed()));
2325 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
2326 this, SIGNAL(changed()));
2327 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
2328 this, SIGNAL(changed()));
2332 void PrefEdit::apply(LyXRC & rc) const
2334 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
2335 rc.scroll_below_document = scrollBelowCB->isChecked();
2336 rc.sort_layouts = sortEnvironmentsCB->isChecked();
2337 rc.group_layouts = groupEnvironmentsCB->isChecked();
2338 switch (macroEditStyleCO->currentIndex()) {
2339 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
2340 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
2341 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
2343 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
2344 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
2345 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
2346 rc.full_screen_menubar = toggleMenubarCB->isChecked();
2347 rc.full_screen_width = fullscreenWidthSB->value();
2348 rc.full_screen_limit = fullscreenLimitGB->isChecked();
2352 void PrefEdit::update(LyXRC const & rc)
2354 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
2355 scrollBelowCB->setChecked(rc.scroll_below_document);
2356 sortEnvironmentsCB->setChecked(rc.sort_layouts);
2357 groupEnvironmentsCB->setChecked(rc.group_layouts);
2358 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
2359 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
2360 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
2361 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
2362 toggleMenubarCB->setChecked(rc.full_screen_menubar);
2363 fullscreenWidthSB->setValue(rc.full_screen_width);
2364 fullscreenLimitGB->setChecked(rc.full_screen_limit);
2368 /////////////////////////////////////////////////////////////////////
2372 /////////////////////////////////////////////////////////////////////
2375 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
2377 Ui::shortcutUi::setupUi(this);
2378 QDialog::setModal(true);
2382 PrefShortcuts::PrefShortcuts(GuiPreferences * form)
2383 : PrefModule(qt_(catEditing), qt_("Shortcuts"), form)
2387 shortcutsTW->setColumnCount(2);
2388 shortcutsTW->headerItem()->setText(0, qt_("Function"));
2389 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
2390 shortcutsTW->setSortingEnabled(true);
2391 // Multi-selection can be annoying.
2392 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
2394 connect(bindFilePB, SIGNAL(clicked()),
2395 this, SLOT(selectBind()));
2396 connect(bindFileED, SIGNAL(textChanged(QString)),
2397 this, SIGNAL(changed()));
2399 shortcut_ = new GuiShortcutDialog(this);
2400 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
2401 shortcut_bc_.setOK(shortcut_->okPB);
2402 shortcut_bc_.setCancel(shortcut_->cancelPB);
2404 connect(shortcut_->okPB, SIGNAL(clicked()),
2405 shortcut_, SLOT(accept()));
2406 connect(shortcut_->okPB, SIGNAL(clicked()),
2407 this, SIGNAL(changed()));
2408 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2409 shortcut_, SLOT(reject()));
2410 connect(shortcut_->clearPB, SIGNAL(clicked()),
2411 this, SLOT(shortcutClearPressed()));
2412 connect(shortcut_->removePB, SIGNAL(clicked()),
2413 this, SLOT(shortcutRemovePressed()));
2414 connect(shortcut_->okPB, SIGNAL(clicked()),
2415 this, SLOT(shortcutOkPressed()));
2416 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2417 this, SLOT(shortcutCancelPressed()));
2421 void PrefShortcuts::apply(LyXRC & rc) const
2423 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
2424 // write user_bind and user_unbind to .lyx/bind/user.bind
2425 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
2426 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
2427 lyxerr << "LyX could not create the user bind directory '"
2428 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2431 if (!bind_dir.isDirWritable()) {
2432 lyxerr << "LyX could not write to the user bind directory '"
2433 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2436 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
2437 user_unbind_.write(user_bind_file.toFilesystemEncoding(), false, true);
2438 user_bind_.write(user_bind_file.toFilesystemEncoding(), true, false);
2439 // immediately apply the keybindings. Why this is not done before?
2440 // The good thing is that the menus are updated automatically.
2441 theTopLevelKeymap().clear();
2442 theTopLevelKeymap().read("site");
2443 theTopLevelKeymap().read(rc.bind_file, 0, KeyMap::Fallback);
2444 theTopLevelKeymap().read("user", 0, KeyMap::MissingOK);
2448 void PrefShortcuts::update(LyXRC const & rc)
2450 bindFileED->setText(toqstr(external_path(rc.bind_file)));
2452 system_bind_.clear();
2454 user_unbind_.clear();
2455 system_bind_.read("site");
2456 system_bind_.read(rc.bind_file);
2457 // \unbind in user.bind is added to user_unbind_
2458 user_bind_.read("user", &user_unbind_, KeyMap::MissingOK);
2459 updateShortcutsTW();
2463 void PrefShortcuts::updateShortcutsTW()
2465 shortcutsTW->clear();
2467 editItem_ = new QTreeWidgetItem(shortcutsTW);
2468 editItem_->setText(0, qt_("Cursor, Mouse and Editing functions"));
2469 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2471 mathItem_ = new QTreeWidgetItem(shortcutsTW);
2472 mathItem_->setText(0, qt_("Mathematical Symbols"));
2473 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2475 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2476 bufferItem_->setText(0, qt_("Document and Window"));
2477 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2479 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2480 layoutItem_->setText(0, qt_("Font, Layouts and Textclasses"));
2481 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2483 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2484 systemItem_->setText(0, qt_("System and Miscellaneous"));
2485 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2487 // listBindings(unbound=true) lists all bound and unbound lfuns
2488 // Items in this list is tagged by its source.
2489 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2491 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2493 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2494 KeyMap::UserUnbind);
2495 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2496 user_bindinglist.end());
2497 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2498 user_unbindinglist.end());
2500 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2501 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2502 for (; it != it_end; ++it)
2503 insertShortcutItem(it->request, it->sequence, KeyMap::ItemType(it->tag));
2505 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2506 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2507 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2508 modifyPB->setEnabled(!items.isEmpty());
2510 shortcutsTW->resizeColumnToContents(0);
2514 void PrefShortcuts::setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag)
2516 item->setData(0, Qt::UserRole, QVariant(tag));
2520 case KeyMap::System:
2522 case KeyMap::UserBind:
2525 case KeyMap::UserUnbind:
2526 font.setStrikeOut(true);
2528 // this item is not displayed now.
2529 case KeyMap::UserExtraUnbind:
2530 font.setStrikeOut(true);
2534 item->setFont(1, font);
2538 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2539 KeySequence const & seq, KeyMap::ItemType tag)
2541 FuncCode const action = lfun.action();
2542 string const action_name = lyxaction.getActionName(action);
2543 QString const lfun_name = toqstr(from_utf8(action_name)
2544 + ' ' + lfun.argument());
2545 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2546 KeyMap::ItemType item_tag = tag;
2548 QTreeWidgetItem * newItem = 0;
2549 // for unbind items, try to find an existing item in the system bind list
2550 if (tag == KeyMap::UserUnbind) {
2551 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2552 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2553 for (int i = 0; i < items.size(); ++i) {
2554 if (items[i]->text(1) == shortcut)
2558 // if not found, this unbind item is KeyMap::UserExtraUnbind
2559 // Such an item is not displayed to avoid confusion (what is
2560 // unmatched removed?).
2562 item_tag = KeyMap::UserExtraUnbind;
2567 switch(lyxaction.getActionType(action)) {
2568 case LyXAction::Hidden:
2570 case LyXAction::Edit:
2571 newItem = new QTreeWidgetItem(editItem_);
2573 case LyXAction::Math:
2574 newItem = new QTreeWidgetItem(mathItem_);
2576 case LyXAction::Buffer:
2577 newItem = new QTreeWidgetItem(bufferItem_);
2579 case LyXAction::Layout:
2580 newItem = new QTreeWidgetItem(layoutItem_);
2582 case LyXAction::System:
2583 newItem = new QTreeWidgetItem(systemItem_);
2586 // this should not happen
2587 newItem = new QTreeWidgetItem(shortcutsTW);
2591 newItem->setText(0, lfun_name);
2592 newItem->setText(1, shortcut);
2593 // record BindFile representation to recover KeySequence when needed.
2594 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2595 setItemType(newItem, item_tag);
2600 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2602 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2603 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2604 modifyPB->setEnabled(!items.isEmpty());
2605 if (items.isEmpty())
2608 KeyMap::ItemType tag =
2609 static_cast<KeyMap::ItemType>(items[0]->data(0, Qt::UserRole).toInt());
2610 if (tag == KeyMap::UserUnbind)
2611 removePB->setText(qt_("Res&tore"));
2613 removePB->setText(qt_("Remo&ve"));
2617 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2623 void PrefShortcuts::modifyShortcut()
2625 QTreeWidgetItem * item = shortcutsTW->currentItem();
2626 if (item->flags() & Qt::ItemIsSelectable) {
2627 shortcut_->lfunLE->setText(item->text(0));
2628 save_lfun_ = item->text(0).trimmed();
2629 shortcut_->shortcutWG->setText(item->text(1));
2631 seq.parse(fromqstr(item->data(1, Qt::UserRole).toString()));
2632 shortcut_->shortcutWG->setKeySequence(seq);
2633 shortcut_->shortcutWG->setFocus();
2639 void PrefShortcuts::removeShortcut()
2641 // it seems that only one item can be selected, but I am
2642 // removing all selected items anyway.
2643 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2644 for (int i = 0; i < items.size(); ++i) {
2645 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2646 string lfun = fromqstr(items[i]->text(0));
2647 FuncRequest func = lyxaction.lookupFunc(lfun);
2648 KeyMap::ItemType tag =
2649 static_cast<KeyMap::ItemType>(items[i]->data(0, Qt::UserRole).toInt());
2652 case KeyMap::System: {
2653 // for system bind, we do not touch the item
2654 // but add an user unbind item
2655 user_unbind_.bind(shortcut, func);
2656 setItemType(items[i], KeyMap::UserUnbind);
2657 removePB->setText(qt_("Res&tore"));
2660 case KeyMap::UserBind: {
2661 // for user_bind, we remove this bind
2662 QTreeWidgetItem * parent = items[i]->parent();
2663 int itemIdx = parent->indexOfChild(items[i]);
2664 parent->takeChild(itemIdx);
2666 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2668 shortcutsTW->scrollToItem(parent);
2669 user_bind_.unbind(shortcut, func);
2672 case KeyMap::UserUnbind: {
2673 // for user_unbind, we remove the unbind, and the item
2674 // become KeyMap::System again.
2675 user_unbind_.unbind(shortcut, func);
2676 setItemType(items[i], KeyMap::System);
2677 removePB->setText(qt_("Remo&ve"));
2680 case KeyMap::UserExtraUnbind: {
2681 // for user unbind that is not in system bind file,
2682 // remove this unbind file
2683 QTreeWidgetItem * parent = items[i]->parent();
2684 parent->takeChild(parent->indexOfChild(items[i]));
2685 user_unbind_.unbind(shortcut, func);
2692 void PrefShortcuts::selectBind()
2694 QString file = form_->browsebind(internalPath(bindFileED->text()));
2695 if (!file.isEmpty()) {
2696 bindFileED->setText(file);
2697 system_bind_ = KeyMap();
2698 system_bind_.read(fromqstr(file));
2699 updateShortcutsTW();
2704 void PrefShortcuts::on_modifyPB_pressed()
2710 void PrefShortcuts::on_newPB_pressed()
2712 shortcut_->lfunLE->clear();
2713 shortcut_->shortcutWG->reset();
2714 save_lfun_ = QString();
2719 void PrefShortcuts::on_removePB_pressed()
2726 void PrefShortcuts::on_searchLE_textEdited()
2728 if (searchLE->text().isEmpty()) {
2729 // show all hidden items
2730 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2732 shortcutsTW->setItemHidden(*it++, false);
2735 // search both columns
2736 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2737 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2738 matched += shortcutsTW->findItems(searchLE->text(),
2739 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2741 // hide everyone (to avoid searching in matched QList repeatedly
2742 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2744 shortcutsTW->setItemHidden(*it++, true);
2745 // show matched items
2746 for (int i = 0; i < matched.size(); ++i) {
2747 shortcutsTW->setItemHidden(matched[i], false);
2748 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2753 docstring makeCmdString(FuncRequest const & f)
2755 docstring actionStr = from_ascii(lyxaction.getActionName(f.action()));
2756 if (!f.argument().empty())
2757 actionStr += " " + f.argument();
2762 void PrefShortcuts::shortcutOkPressed()
2764 QString const new_lfun = shortcut_->lfunLE->text();
2765 FuncRequest func = lyxaction.lookupFunc(fromqstr(new_lfun));
2767 if (func.action() == LFUN_UNKNOWN_ACTION) {
2768 Alert::error(_("Failed to create shortcut"),
2769 _("Unknown or invalid LyX function"));
2773 KeySequence k = shortcut_->shortcutWG->getKeySequence();
2774 if (k.length() == 0) {
2775 Alert::error(_("Failed to create shortcut"),
2776 _("Invalid or empty key sequence"));
2780 // check to see if there's been any change
2781 FuncRequest oldBinding = system_bind_.getBinding(k);
2782 if (oldBinding.action() == LFUN_UNKNOWN_ACTION)
2783 oldBinding = user_bind_.getBinding(k);
2784 if (oldBinding == func)
2785 // nothing has changed
2788 // make sure this key isn't already bound---and, if so, not unbound
2789 FuncCode const unbind = user_unbind_.getBinding(k).action();
2790 docstring const action_string = makeCmdString(oldBinding);
2791 if (oldBinding.action() > LFUN_NOACTION && unbind == LFUN_UNKNOWN_ACTION
2792 && save_lfun_ != toqstr(action_string)) {
2793 // FIXME Perhaps we should offer to over-write the old shortcut?
2794 // If so, we'll need to remove it from our list, etc.
2795 Alert::error(_("Failed to create shortcut"),
2796 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s\n"
2797 "You need to remove that binding before creating a new one."),
2798 k.print(KeySequence::ForGui), action_string));
2802 if (!save_lfun_.isEmpty())
2803 // real modification of the lfun's shortcut,
2804 // so remove the previous one
2807 QTreeWidgetItem * item = insertShortcutItem(func, k, KeyMap::UserBind);
2809 user_bind_.bind(&k, func);
2810 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2811 shortcutsTW->setItemExpanded(item->parent(), true);
2812 shortcutsTW->scrollToItem(item);
2814 Alert::error(_("Failed to create shortcut"),
2815 _("Can not insert shortcut to the list"));
2821 void PrefShortcuts::shortcutCancelPressed()
2823 shortcut_->shortcutWG->reset();
2827 void PrefShortcuts::shortcutClearPressed()
2829 shortcut_->shortcutWG->reset();
2833 void PrefShortcuts::shortcutRemovePressed()
2835 shortcut_->shortcutWG->removeFromSequence();
2839 /////////////////////////////////////////////////////////////////////
2843 /////////////////////////////////////////////////////////////////////
2845 PrefIdentity::PrefIdentity(GuiPreferences * form)
2846 : PrefModule(QString(), qt_("Identity"), form)
2850 connect(nameED, SIGNAL(textChanged(QString)),
2851 this, SIGNAL(changed()));
2852 connect(emailED, SIGNAL(textChanged(QString)),
2853 this, SIGNAL(changed()));
2857 void PrefIdentity::apply(LyXRC & rc) const
2859 rc.user_name = fromqstr(nameED->text());
2860 rc.user_email = fromqstr(emailED->text());
2864 void PrefIdentity::update(LyXRC const & rc)
2866 nameED->setText(toqstr(rc.user_name));
2867 emailED->setText(toqstr(rc.user_email));
2872 /////////////////////////////////////////////////////////////////////
2876 /////////////////////////////////////////////////////////////////////
2878 GuiPreferences::GuiPreferences(GuiView & lv)
2879 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2883 QDialog::setModal(false);
2885 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2886 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2887 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2888 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2890 addModule(new PrefUserInterface(this));
2891 addModule(new PrefEdit(this));
2892 addModule(new PrefShortcuts(this));
2893 addModule(new PrefScreenFonts(this));
2894 addModule(new PrefColors(this));
2895 addModule(new PrefDisplay(this));
2896 addModule(new PrefInput(this));
2897 addModule(new PrefCompletion(this));
2899 addModule(new PrefPaths(this));
2901 addModule(new PrefIdentity(this));
2903 addModule(new PrefLanguage(this));
2904 addModule(new PrefSpellchecker(this));
2906 //for strftime validator
2907 PrefOutput * output = new PrefOutput(this);
2909 addModule(new PrefPrinter(this));
2910 addModule(new PrefLatex(this));
2912 PrefConverters * converters = new PrefConverters(this);
2913 PrefFileformats * formats = new PrefFileformats(this);
2914 connect(formats, SIGNAL(formatsChanged()),
2915 converters, SLOT(updateGui()));
2916 addModule(converters);
2919 prefsPS->setCurrentPanel(qt_("User interface"));
2920 // FIXME: hack to work around resizing bug in Qt >= 4.2
2921 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2922 #if QT_VERSION >= 0x040200
2923 prefsPS->updateGeometry();
2926 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2928 bc().setApply(applyPB);
2929 bc().setCancel(closePB);
2930 bc().setRestore(restorePB);
2932 // initialize the strftime validator
2933 bc().addCheckedLineEdit(output->DateED);
2937 void GuiPreferences::addModule(PrefModule * module)
2939 LASSERT(module, return);
2940 if (module->category().isEmpty())
2941 prefsPS->addPanel(module, module->title());
2943 prefsPS->addPanel(module, module->title(), module->category());
2944 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2945 modules_.push_back(module);
2949 void GuiPreferences::change_adaptor()
2955 void GuiPreferences::apply(LyXRC & rc) const
2957 size_t end = modules_.size();
2958 for (size_t i = 0; i != end; ++i)
2959 modules_[i]->apply(rc);
2963 void GuiPreferences::updateRc(LyXRC const & rc)
2965 size_t const end = modules_.size();
2966 for (size_t i = 0; i != end; ++i)
2967 modules_[i]->update(rc);
2971 void GuiPreferences::applyView()
2976 bool GuiPreferences::initialiseParams(string const &)
2979 formats_ = lyx::formats;
2980 converters_ = theConverters();
2981 converters_.update(formats_);
2982 movers_ = theMovers();
2984 update_screen_font_ = false;
2987 // Make sure that the bc is in the INITIAL state
2988 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
2995 void GuiPreferences::dispatchParams()
2998 rc_.write(ss, true);
2999 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
3000 // FIXME: these need lfuns
3002 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
3004 lyx::formats = formats_;
3006 theConverters() = converters_;
3007 theConverters().update(lyx::formats);
3008 theConverters().buildGraph();
3010 theMovers() = movers_;
3012 vector<string>::const_iterator it = colors_.begin();
3013 vector<string>::const_iterator const end = colors_.end();
3014 for (; it != end; ++it)
3015 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
3018 if (update_screen_font_) {
3019 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
3020 update_screen_font_ = false;
3023 // The Save button has been pressed
3025 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
3029 void GuiPreferences::setColor(ColorCode col, QString const & hex)
3031 colors_.push_back(lcolor.getLyXName(col) + ' ' + fromqstr(hex));
3035 void GuiPreferences::updateScreenFonts()
3037 update_screen_font_ = true;
3041 QString GuiPreferences::browsebind(QString const & file) const
3043 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
3044 QStringList(qt_("LyX bind files (*.bind)")));
3048 QString GuiPreferences::browseUI(QString const & file) const
3050 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
3051 QStringList(qt_("LyX UI files (*.ui)")));
3055 QString GuiPreferences::browsekbmap(QString const & file) const
3057 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
3058 QStringList(qt_("LyX keyboard maps (*.kmap)")));
3062 QString GuiPreferences::browse(QString const & file,
3063 QString const & title) const
3065 return browseFile(file, title, QStringList(), true);
3069 // We support less paper sizes than the document dialog
3070 // Therefore this adjustment is needed.
3071 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
3075 return PAPER_DEFAULT;
3077 return PAPER_USLETTER;
3079 return PAPER_USLEGAL;
3081 return PAPER_USEXECUTIVE;
3091 // should not happen
3092 return PAPER_DEFAULT;
3097 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
3099 switch (papersize) {
3102 case PAPER_USLETTER:
3106 case PAPER_USEXECUTIVE:
3117 // should not happen
3123 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
3126 } // namespace frontend
3129 #include "moc_GuiPrefs.cpp"