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"
38 #include "support/debug.h"
39 #include "support/FileName.h"
40 #include "support/filetools.h"
41 #include "support/foreach.h"
42 #include "support/gettext.h"
43 #include "support/lstrings.h"
44 #include "support/os.h"
45 #include "support/Package.h"
47 #include "graphics/GraphicsTypes.h"
49 #include "frontends/alert.h"
50 #include "frontends/Application.h"
51 #include "frontends/FontLoader.h"
53 #include <QAbstractItemModel>
55 #include <QColorDialog>
56 #include <QFontDatabase>
57 #include <QHeaderView>
59 #include <QMessageBox>
60 #include <QPixmapCache>
61 #include <QPushButton>
64 #include <QTreeWidget>
65 #include <QTreeWidgetItem>
75 using namespace lyx::support;
76 using namespace lyx::support::os;
81 /////////////////////////////////////////////////////////////////////
85 /////////////////////////////////////////////////////////////////////
87 /** Launch a file dialog and return the chosen file.
88 filename: a suggested filename.
89 title: the title of the dialog.
91 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
93 QString browseFile(QString const & filename,
94 QString const & title,
95 QStringList const & filters,
97 QString const & label1 = QString(),
98 QString const & dir1 = QString(),
99 QString const & label2 = QString(),
100 QString const & dir2 = QString(),
101 QString const & fallback_dir = QString())
103 QString lastPath = ".";
104 if (!filename.isEmpty())
105 lastPath = onlyPath(filename);
106 else if(!fallback_dir.isEmpty())
107 lastPath = fallback_dir;
109 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
110 dlg.setButton2(label1, dir1);
111 dlg.setButton2(label2, dir2);
113 FileDialog::Result result;
116 result = dlg.save(lastPath, filters, onlyFilename(filename));
118 result = dlg.open(lastPath, filters, onlyFilename(filename));
120 return result.second;
124 /** Wrapper around browseFile which tries to provide a filename
125 * relative to the user or system directory. The dir, name and ext
126 * parameters have the same meaning as in the
127 * support::LibFileSearch function.
129 QString browseLibFile(QString const & dir,
130 QString const & name,
132 QString const & title,
133 QStringList const & filters)
136 QString const label1 = qt_("System files|#S#s");
138 toqstr(addName(package().system_support().absFilename(), fromqstr(dir)));
140 QString const label2 = qt_("User files|#U#u");
142 toqstr(addName(package().user_support().absFilename(), fromqstr(dir)));
144 QString const result = browseFile(toqstr(
145 libFileSearch(dir, name, ext).absFilename()),
146 title, filters, false, dir1, dir2, QString(), QString(), dir1);
148 // remove the extension if it is the default one
150 if (getExtension(result) == ext)
151 noextresult = removeExtension(result);
153 noextresult = result;
155 // remove the directory, if it is the default one
156 QString const file = onlyFilename(noextresult);
157 if (toqstr(libFileSearch(dir, file, ext).absFilename()) == result)
164 /** Launch a file dialog and return the chosen directory.
165 pathname: a suggested pathname.
166 title: the title of the dialog.
167 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
169 QString browseDir(QString const & pathname,
170 QString const & title,
171 QString const & label1 = QString(),
172 QString const & dir1 = QString(),
173 QString const & label2 = QString(),
174 QString const & dir2 = QString())
176 QString lastPath = ".";
177 if (!pathname.isEmpty())
178 lastPath = onlyPath(pathname);
180 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
181 dlg.setButton1(label1, dir1);
182 dlg.setButton2(label2, dir2);
184 FileDialog::Result const result =
185 dlg.opendir(lastPath, onlyFilename(pathname));
187 return result.second;
191 } // namespace frontend
194 QString browseRelFile(QString const & filename, QString const & refpath,
195 QString const & title, QStringList const & filters, bool save,
196 QString const & label1, QString const & dir1,
197 QString const & label2, QString const & dir2)
199 QString const fname = makeAbsPath(filename, refpath);
202 QString const outname =
203 frontend::browseFile(fname, title, filters, save, label1, dir1, label2, dir2);
205 QString const reloutname =
206 toqstr(makeRelPath(qstring_to_ucs4(outname), qstring_to_ucs4(refpath)));
208 if (reloutname.startsWith("../"))
216 /////////////////////////////////////////////////////////////////////
220 /////////////////////////////////////////////////////////////////////
224 string const catLookAndFeel = N_("Look & Feel");
225 string const catEditing = N_("Editing");
226 string const catLanguage = N_("Language Settings");
227 string const catOutput = N_("Output");
228 string const catFiles = N_("File Handling");
230 static void parseFontName(QString const & mangled0,
231 string & name, string & foundry)
233 string mangled = fromqstr(mangled0);
234 size_t const idx = mangled.find('[');
235 if (idx == string::npos || idx == 0) {
239 name = mangled.substr(0, idx - 1),
240 foundry = mangled.substr(idx + 1, mangled.size() - idx - 2);
245 static void setComboxFont(QComboBox * cb, string const & family,
246 string const & foundry)
248 QString fontname = toqstr(family);
249 if (!foundry.empty())
250 fontname += " [" + toqstr(foundry) + ']';
252 for (int i = 0; i != cb->count(); ++i) {
253 if (cb->itemText(i) == fontname) {
254 cb->setCurrentIndex(i);
259 // Try matching without foundry name
261 // We count in reverse in order to prefer the Xft foundry
262 for (int i = cb->count(); --i >= 0;) {
263 string name, foundry;
264 parseFontName(cb->itemText(i), name, foundry);
265 if (compare_ascii_no_case(name, family) == 0) {
266 cb->setCurrentIndex(i);
271 // family alone can contain e.g. "Helvetica [Adobe]"
272 string tmpname, tmpfoundry;
273 parseFontName(toqstr(family), tmpname, tmpfoundry);
275 // We count in reverse in order to prefer the Xft foundry
276 for (int i = cb->count(); --i >= 0; ) {
277 string name, foundry;
278 parseFontName(cb->itemText(i), name, foundry);
279 if (compare_ascii_no_case(name, foundry) == 0) {
280 cb->setCurrentIndex(i);
285 // Bleh, default fonts, and the names couldn't be found. Hack
289 font.setKerning(false);
291 QString const font_family = toqstr(family);
292 if (font_family == guiApp->romanFontName()) {
293 font.setStyleHint(QFont::Serif);
294 font.setFamily(font_family);
295 } else if (font_family == guiApp->sansFontName()) {
296 font.setStyleHint(QFont::SansSerif);
297 font.setFamily(font_family);
298 } else if (font_family == guiApp->typewriterFontName()) {
299 font.setStyleHint(QFont::TypeWriter);
300 font.setFamily(font_family);
302 LYXERR0("FAILED to find the default font: '"
303 << foundry << "', '" << family << '\'');
307 QFontInfo info(font);
308 string default_font_name, dummyfoundry;
309 parseFontName(info.family(), default_font_name, dummyfoundry);
310 LYXERR0("Apparent font is " << default_font_name);
312 for (int i = 0; i < cb->count(); ++i) {
313 LYXERR0("Looking at " << cb->itemText(i));
314 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
315 default_font_name) == 0) {
316 cb->setCurrentIndex(i);
321 LYXERR0("FAILED to find the font: '"
322 << foundry << "', '" << family << '\'');
327 /////////////////////////////////////////////////////////////////////
331 /////////////////////////////////////////////////////////////////////
333 PrefPlaintext::PrefPlaintext(GuiPreferences * form)
334 : PrefModule(qt_(catOutput), qt_("Plain text"), form)
337 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
338 this, SIGNAL(changed()));
342 void PrefPlaintext::apply(LyXRC & rc) const
344 rc.plaintext_linelen = plaintextLinelengthSB->value();
348 void PrefPlaintext::update(LyXRC const & rc)
350 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
354 /////////////////////////////////////////////////////////////////////
358 /////////////////////////////////////////////////////////////////////
360 class StrftimeValidator : public QValidator
363 StrftimeValidator(QWidget *);
364 QValidator::State validate(QString & input, int & pos) const;
368 StrftimeValidator::StrftimeValidator(QWidget * parent)
374 QValidator::State StrftimeValidator::validate(QString & input, int & /*pos*/) const
376 if (is_valid_strftime(fromqstr(input)))
377 return QValidator::Acceptable;
379 return QValidator::Intermediate;
383 /////////////////////////////////////////////////////////////////////
387 /////////////////////////////////////////////////////////////////////
389 PrefDate::PrefDate(GuiPreferences * form)
390 : PrefModule(qt_(catOutput), qt_("Date format"), form)
393 DateED->setValidator(new StrftimeValidator(DateED));
394 connect(DateED, SIGNAL(textChanged(QString)),
395 this, SIGNAL(changed()));
399 void PrefDate::on_DateED_textChanged(const QString &)
401 QString t = DateED->text();
403 bool valid = DateED->validator()->validate(t, p)
404 == QValidator::Acceptable;
405 setValid(DateLA, valid);
409 void PrefDate::apply(LyXRC & rc) const
411 rc.date_insert_format = fromqstr(DateED->text());
415 void PrefDate::update(LyXRC const & rc)
417 DateED->setText(toqstr(rc.date_insert_format));
421 /////////////////////////////////////////////////////////////////////
425 /////////////////////////////////////////////////////////////////////
427 PrefInput::PrefInput(GuiPreferences * form)
428 : PrefModule(qt_(catEditing), qt_("Keyboard/Mouse"), form)
432 connect(keymapCB, SIGNAL(clicked()),
433 this, SIGNAL(changed()));
434 connect(firstKeymapED, SIGNAL(textChanged(QString)),
435 this, SIGNAL(changed()));
436 connect(secondKeymapED, SIGNAL(textChanged(QString)),
437 this, SIGNAL(changed()));
438 connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
439 this, SIGNAL(changed()));
443 void PrefInput::apply(LyXRC & rc) const
445 // FIXME: can derive CB from the two EDs
446 rc.use_kbmap = keymapCB->isChecked();
447 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
448 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
449 rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
453 void PrefInput::update(LyXRC const & rc)
455 // FIXME: can derive CB from the two EDs
456 keymapCB->setChecked(rc.use_kbmap);
457 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
458 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
459 mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
463 QString PrefInput::testKeymap(QString const & keymap)
465 return form_->browsekbmap(internalPath(keymap));
469 void PrefInput::on_firstKeymapPB_clicked(bool)
471 QString const file = testKeymap(firstKeymapED->text());
473 firstKeymapED->setText(file);
477 void PrefInput::on_secondKeymapPB_clicked(bool)
479 QString const file = testKeymap(secondKeymapED->text());
481 secondKeymapED->setText(file);
485 void PrefInput::on_keymapCB_toggled(bool keymap)
487 firstKeymapLA->setEnabled(keymap);
488 secondKeymapLA->setEnabled(keymap);
489 firstKeymapED->setEnabled(keymap);
490 secondKeymapED->setEnabled(keymap);
491 firstKeymapPB->setEnabled(keymap);
492 secondKeymapPB->setEnabled(keymap);
496 /////////////////////////////////////////////////////////////////////
500 /////////////////////////////////////////////////////////////////////
502 PrefCompletion::PrefCompletion(GuiPreferences * form)
503 : PrefModule(qt_(catEditing), qt_("Input Completion"), form)
507 connect(inlineDelaySB, SIGNAL(valueChanged(double)),
508 this, SIGNAL(changed()));
509 connect(inlineMathCB, SIGNAL(clicked()),
510 this, SIGNAL(changed()));
511 connect(inlineTextCB, SIGNAL(clicked()),
512 this, SIGNAL(changed()));
513 connect(inlineDotsCB, SIGNAL(clicked()),
514 this, SIGNAL(changed()));
515 connect(popupDelaySB, SIGNAL(valueChanged(double)),
516 this, SIGNAL(changed()));
517 connect(popupMathCB, SIGNAL(clicked()),
518 this, SIGNAL(changed()));
519 connect(popupTextCB, SIGNAL(clicked()),
520 this, SIGNAL(changed()));
521 connect(popupAfterCompleteCB, SIGNAL(clicked()),
522 this, SIGNAL(changed()));
523 connect(cursorTextCB, SIGNAL(clicked()),
524 this, SIGNAL(changed()));
528 void PrefCompletion::apply(LyXRC & rc) const
530 rc.completion_inline_delay = inlineDelaySB->value();
531 rc.completion_inline_math = inlineMathCB->isChecked();
532 rc.completion_inline_text = inlineTextCB->isChecked();
533 rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
534 rc.completion_popup_delay = popupDelaySB->value();
535 rc.completion_popup_math = popupMathCB->isChecked();
536 rc.completion_popup_text = popupTextCB->isChecked();
537 rc.completion_cursor_text = cursorTextCB->isChecked();
538 rc.completion_popup_after_complete =
539 popupAfterCompleteCB->isChecked();
543 void PrefCompletion::update(LyXRC const & rc)
545 inlineDelaySB->setValue(rc.completion_inline_delay);
546 inlineMathCB->setChecked(rc.completion_inline_math);
547 inlineTextCB->setChecked(rc.completion_inline_text);
548 inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
549 popupDelaySB->setValue(rc.completion_popup_delay);
550 popupMathCB->setChecked(rc.completion_popup_math);
551 popupTextCB->setChecked(rc.completion_popup_text);
552 cursorTextCB->setChecked(rc.completion_cursor_text);
553 popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
558 /////////////////////////////////////////////////////////////////////
562 /////////////////////////////////////////////////////////////////////
564 PrefLatex::PrefLatex(GuiPreferences * form)
565 : PrefModule(qt_(catOutput), qt_("LaTeX"), form)
568 connect(latexEncodingED, SIGNAL(textChanged(QString)),
569 this, SIGNAL(changed()));
570 connect(latexChecktexED, SIGNAL(textChanged(QString)),
571 this, SIGNAL(changed()));
572 connect(latexBibtexED, SIGNAL(textChanged(QString)),
573 this, SIGNAL(changed()));
574 connect(latexIndexED, SIGNAL(textChanged(QString)),
575 this, SIGNAL(changed()));
576 connect(latexAutoresetCB, SIGNAL(clicked()),
577 this, SIGNAL(changed()));
578 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
579 this, SIGNAL(changed()));
580 connect(latexPaperSizeCO, SIGNAL(activated(int)),
581 this, SIGNAL(changed()));
583 #if defined(__CYGWIN__) || defined(_WIN32)
584 pathCB->setVisible(true);
585 connect(pathCB, SIGNAL(clicked()),
586 this, SIGNAL(changed()));
588 pathCB->setVisible(false);
593 void PrefLatex::apply(LyXRC & rc) const
595 rc.fontenc = fromqstr(latexEncodingED->text());
596 rc.chktex_command = fromqstr(latexChecktexED->text());
597 rc.bibtex_command = fromqstr(latexBibtexED->text());
598 rc.index_command = fromqstr(latexIndexED->text());
599 rc.nomencl_command = fromqstr(latexNomenclED->text());
600 rc.auto_reset_options = latexAutoresetCB->isChecked();
601 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
602 rc.default_papersize =
603 form_->toPaperSize(latexPaperSizeCO->currentIndex());
604 #if defined(__CYGWIN__) || defined(_WIN32)
605 rc.windows_style_tex_paths = pathCB->isChecked();
610 void PrefLatex::update(LyXRC const & rc)
612 latexEncodingED->setText(toqstr(rc.fontenc));
613 latexChecktexED->setText(toqstr(rc.chktex_command));
614 latexBibtexED->setText(toqstr(rc.bibtex_command));
615 latexIndexED->setText(toqstr(rc.index_command));
616 latexNomenclED->setText(toqstr(rc.nomencl_command));
617 latexAutoresetCB->setChecked(rc.auto_reset_options);
618 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
619 latexPaperSizeCO->setCurrentIndex(
620 form_->fromPaperSize(rc.default_papersize));
621 #if defined(__CYGWIN__) || defined(_WIN32)
622 pathCB->setChecked(rc.windows_style_tex_paths);
627 /////////////////////////////////////////////////////////////////////
631 /////////////////////////////////////////////////////////////////////
633 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form)
634 : PrefModule(qt_(catLookAndFeel), qt_("Screen fonts"), form)
638 connect(screenRomanCO, SIGNAL(activated(QString)),
639 this, SLOT(select_roman(QString)));
640 connect(screenSansCO, SIGNAL(activated(QString)),
641 this, SLOT(select_sans(QString)));
642 connect(screenTypewriterCO, SIGNAL(activated(QString)),
643 this, SLOT(select_typewriter(QString)));
645 QFontDatabase fontdb;
646 QStringList families(fontdb.families());
647 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
648 screenRomanCO->addItem(*it);
649 screenSansCO->addItem(*it);
650 screenTypewriterCO->addItem(*it);
652 connect(screenRomanCO, SIGNAL(activated(QString)),
653 this, SIGNAL(changed()));
654 connect(screenSansCO, SIGNAL(activated(QString)),
655 this, SIGNAL(changed()));
656 connect(screenTypewriterCO, SIGNAL(activated(QString)),
657 this, SIGNAL(changed()));
658 connect(screenZoomSB, SIGNAL(valueChanged(int)),
659 this, SIGNAL(changed()));
660 connect(screenDpiSB, SIGNAL(valueChanged(int)),
661 this, SIGNAL(changed()));
662 connect(screenTinyED, SIGNAL(textChanged(QString)),
663 this, SIGNAL(changed()));
664 connect(screenSmallestED, SIGNAL(textChanged(QString)),
665 this, SIGNAL(changed()));
666 connect(screenSmallerED, SIGNAL(textChanged(QString)),
667 this, SIGNAL(changed()));
668 connect(screenSmallED, SIGNAL(textChanged(QString)),
669 this, SIGNAL(changed()));
670 connect(screenNormalED, SIGNAL(textChanged(QString)),
671 this, SIGNAL(changed()));
672 connect(screenLargeED, SIGNAL(textChanged(QString)),
673 this, SIGNAL(changed()));
674 connect(screenLargerED, SIGNAL(textChanged(QString)),
675 this, SIGNAL(changed()));
676 connect(screenLargestED, SIGNAL(textChanged(QString)),
677 this, SIGNAL(changed()));
678 connect(screenHugeED, SIGNAL(textChanged(QString)),
679 this, SIGNAL(changed()));
680 connect(screenHugerED, SIGNAL(textChanged(QString)),
681 this, SIGNAL(changed()));
682 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
683 this, SIGNAL(changed()));
685 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
686 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
687 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
688 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
689 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
690 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
691 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
692 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
693 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
694 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
698 void PrefScreenFonts::apply(LyXRC & rc) const
700 LyXRC const oldrc = rc;
702 parseFontName(screenRomanCO->currentText(),
703 rc.roman_font_name, rc.roman_font_foundry);
704 parseFontName(screenSansCO->currentText(),
705 rc.sans_font_name, rc.sans_font_foundry);
706 parseFontName(screenTypewriterCO->currentText(),
707 rc.typewriter_font_name, rc.typewriter_font_foundry);
709 rc.zoom = screenZoomSB->value();
710 rc.dpi = screenDpiSB->value();
711 rc.font_sizes[FONT_SIZE_TINY] = fromqstr(screenTinyED->text());
712 rc.font_sizes[FONT_SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
713 rc.font_sizes[FONT_SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
714 rc.font_sizes[FONT_SIZE_SMALL] = fromqstr(screenSmallED->text());
715 rc.font_sizes[FONT_SIZE_NORMAL] = fromqstr(screenNormalED->text());
716 rc.font_sizes[FONT_SIZE_LARGE] = fromqstr(screenLargeED->text());
717 rc.font_sizes[FONT_SIZE_LARGER] = fromqstr(screenLargerED->text());
718 rc.font_sizes[FONT_SIZE_LARGEST] = fromqstr(screenLargestED->text());
719 rc.font_sizes[FONT_SIZE_HUGE] = fromqstr(screenHugeED->text());
720 rc.font_sizes[FONT_SIZE_HUGER] = fromqstr(screenHugerED->text());
721 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
723 if (rc.font_sizes != oldrc.font_sizes
724 || rc.roman_font_name != oldrc.roman_font_name
725 || rc.sans_font_name != oldrc.sans_font_name
726 || rc.typewriter_font_name != oldrc.typewriter_font_name
727 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
728 // The global QPixmapCache is used in GuiPainter to cache text
729 // painting so we must reset it in case any of the above
730 // parameter is changed.
731 QPixmapCache::clear();
732 guiApp->fontLoader().update();
733 form_->updateScreenFonts();
738 void PrefScreenFonts::update(LyXRC const & rc)
740 setComboxFont(screenRomanCO, rc.roman_font_name,
741 rc.roman_font_foundry);
742 setComboxFont(screenSansCO, rc.sans_font_name,
743 rc.sans_font_foundry);
744 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
745 rc.typewriter_font_foundry);
747 select_roman(screenRomanCO->currentText());
748 select_sans(screenSansCO->currentText());
749 select_typewriter(screenTypewriterCO->currentText());
751 screenZoomSB->setValue(rc.zoom);
752 screenDpiSB->setValue(rc.dpi);
753 screenTinyED->setText(toqstr(rc.font_sizes[FONT_SIZE_TINY]));
754 screenSmallestED->setText(toqstr(rc.font_sizes[FONT_SIZE_SCRIPT]));
755 screenSmallerED->setText(toqstr(rc.font_sizes[FONT_SIZE_FOOTNOTE]));
756 screenSmallED->setText(toqstr(rc.font_sizes[FONT_SIZE_SMALL]));
757 screenNormalED->setText(toqstr(rc.font_sizes[FONT_SIZE_NORMAL]));
758 screenLargeED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGE]));
759 screenLargerED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGER]));
760 screenLargestED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGEST]));
761 screenHugeED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGE]));
762 screenHugerED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGER]));
764 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
765 #if defined(Q_WS_X11)
766 pixmapCacheCB->setEnabled(false);
772 void PrefScreenFonts::select_roman(const QString & name)
774 screenRomanFE->set(QFont(name), name);
778 void PrefScreenFonts::select_sans(const QString & name)
780 screenSansFE->set(QFont(name), name);
784 void PrefScreenFonts::select_typewriter(const QString & name)
786 screenTypewriterFE->set(QFont(name), name);
790 /////////////////////////////////////////////////////////////////////
794 /////////////////////////////////////////////////////////////////////
800 bool operator()(ColorCode lhs, ColorCode rhs) const {
802 compare_no_case(lcolor.getGUIName(lhs), lcolor.getGUIName(rhs)) < 0;
808 PrefColors::PrefColors(GuiPreferences * form)
809 : PrefModule(qt_(catLookAndFeel), qt_("Colors"), form)
813 // FIXME: all of this initialization should be put into the controller.
814 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
815 // for some discussion of why that is not trivial.
816 QPixmap icon(32, 32);
817 for (int i = 0; i < Color_ignore; ++i) {
818 ColorCode lc = static_cast<ColorCode>(i);
826 || lc == Color_magenta
827 || lc == Color_yellow
828 || lc == Color_inherit
829 || lc == Color_ignore) continue;
831 lcolors_.push_back(lc);
833 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
834 vector<ColorCode>::const_iterator cit = lcolors_.begin();
835 vector<ColorCode>::const_iterator const end = lcolors_.end();
836 for (; cit != end; ++cit) {
837 (void) new QListWidgetItem(QIcon(icon),
838 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
840 curcolors_.resize(lcolors_.size());
841 newcolors_.resize(lcolors_.size());
842 // End initialization
844 connect(colorChangePB, SIGNAL(clicked()),
845 this, SLOT(change_color()));
846 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
847 this, SLOT(change_lyxObjects_selection()));
848 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
849 this, SLOT(change_color()));
853 void PrefColors::apply(LyXRC & /*rc*/) const
855 for (unsigned int i = 0; i < lcolors_.size(); ++i)
856 if (curcolors_[i] != newcolors_[i])
857 form_->setColor(lcolors_[i], newcolors_[i]);
861 void PrefColors::update(LyXRC const & /*rc*/)
863 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
864 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
865 QPixmap coloritem(32, 32);
866 coloritem.fill(color);
867 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
868 newcolors_[i] = curcolors_[i] = color.name();
870 change_lyxObjects_selection();
874 void PrefColors::change_color()
876 int const row = lyxObjectsLW->currentRow();
882 QString const color = newcolors_[row];
883 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
885 if (c.isValid() && c.name() != color) {
886 newcolors_[row] = c.name();
887 QPixmap coloritem(32, 32);
889 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
895 void PrefColors::change_lyxObjects_selection()
897 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
901 /////////////////////////////////////////////////////////////////////
905 /////////////////////////////////////////////////////////////////////
907 PrefDisplay::PrefDisplay(GuiPreferences * form)
908 : PrefModule(qt_(catLookAndFeel), qt_("Graphics"), form)
911 connect(displayGraphicsCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
912 connect(instantPreviewCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
916 void PrefDisplay::apply(LyXRC & rc) const
918 switch (instantPreviewCO->currentIndex()) {
919 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
920 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
921 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
924 rc.display_graphics = displayGraphicsCB->isChecked();
926 // FIXME!! The graphics cache no longer has a changeDisplay method.
928 if (old_value != rc.display_graphics) {
929 graphics::GCache & gc = graphics::GCache::get();
936 void PrefDisplay::update(LyXRC const & rc)
938 switch (rc.preview) {
939 case LyXRC::PREVIEW_OFF:
940 instantPreviewCO->setCurrentIndex(0);
942 case LyXRC::PREVIEW_NO_MATH :
943 instantPreviewCO->setCurrentIndex(1);
945 case LyXRC::PREVIEW_ON :
946 instantPreviewCO->setCurrentIndex(2);
950 displayGraphicsCB->setChecked(rc.display_graphics);
951 instantPreviewCO->setEnabled(rc.display_graphics);
955 /////////////////////////////////////////////////////////////////////
959 /////////////////////////////////////////////////////////////////////
961 PrefPaths::PrefPaths(GuiPreferences * form)
962 : PrefModule(QString(), qt_("Paths"), form)
965 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(select_exampledir()));
966 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
967 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
968 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
969 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
970 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
971 connect(thesaurusDirPB, SIGNAL(clicked()), this, SLOT(select_thesaurusdir()));
972 connect(workingDirED, SIGNAL(textChanged(QString)),
973 this, SIGNAL(changed()));
974 connect(exampleDirED, SIGNAL(textChanged(QString)),
975 this, SIGNAL(changed()));
976 connect(templateDirED, SIGNAL(textChanged(QString)),
977 this, SIGNAL(changed()));
978 connect(backupDirED, SIGNAL(textChanged(QString)),
979 this, SIGNAL(changed()));
980 connect(tempDirED, SIGNAL(textChanged(QString)),
981 this, SIGNAL(changed()));
982 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
983 this, SIGNAL(changed()));
984 connect(thesaurusDirED, SIGNAL(textChanged(QString)),
985 this, SIGNAL(changed()));
986 connect(pathPrefixED, SIGNAL(textChanged(QString)),
987 this, SIGNAL(changed()));
991 void PrefPaths::apply(LyXRC & rc) const
993 rc.document_path = internal_path(fromqstr(workingDirED->text()));
994 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
995 rc.template_path = internal_path(fromqstr(templateDirED->text()));
996 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
997 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
998 rc.thesaurusdir_path = internal_path(fromqstr(thesaurusDirED->text()));
999 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
1000 // FIXME: should be a checkbox only
1001 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
1005 void PrefPaths::update(LyXRC const & rc)
1007 workingDirED->setText(toqstr(external_path(rc.document_path)));
1008 exampleDirED->setText(toqstr(external_path(rc.example_path)));
1009 templateDirED->setText(toqstr(external_path(rc.template_path)));
1010 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
1011 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
1012 thesaurusDirED->setText(toqstr(external_path(rc.thesaurusdir_path)));
1013 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
1014 // FIXME: should be a checkbox only
1015 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
1019 void PrefPaths::select_exampledir()
1021 QString file = browseDir(internalPath(exampleDirED->text()),
1022 qt_("Select directory for example files"));
1023 if (!file.isEmpty())
1024 exampleDirED->setText(file);
1028 void PrefPaths::select_templatedir()
1030 QString file = browseDir(internalPath(templateDirED->text()),
1031 qt_("Select a document templates directory"));
1032 if (!file.isEmpty())
1033 templateDirED->setText(file);
1037 void PrefPaths::select_tempdir()
1039 QString file = browseDir(internalPath(tempDirED->text()),
1040 qt_("Select a temporary directory"));
1041 if (!file.isEmpty())
1042 tempDirED->setText(file);
1046 void PrefPaths::select_backupdir()
1048 QString file = browseDir(internalPath(backupDirED->text()),
1049 qt_("Select a backups directory"));
1050 if (!file.isEmpty())
1051 backupDirED->setText(file);
1055 void PrefPaths::select_workingdir()
1057 QString file = browseDir(internalPath(workingDirED->text()),
1058 qt_("Select a document directory"));
1059 if (!file.isEmpty())
1060 workingDirED->setText(file);
1064 void PrefPaths::select_thesaurusdir()
1066 QString file = browseDir(internalPath(thesaurusDirED->text()),
1067 qt_("Set the path to the thesaurus dictionaries"));
1068 if (!file.isEmpty())
1069 thesaurusDirED->setText(file);
1073 void PrefPaths::select_lyxpipe()
1075 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1076 qt_("Give a filename for the LyX server pipe"));
1077 if (!file.isEmpty())
1078 lyxserverDirED->setText(file);
1082 /////////////////////////////////////////////////////////////////////
1086 /////////////////////////////////////////////////////////////////////
1088 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form)
1089 : PrefModule(qt_(catLanguage), qt_("Spellchecker"), form)
1093 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
1095 connect(altLanguageED, SIGNAL(textChanged(QString)),
1096 this, SIGNAL(changed()));
1097 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1098 this, SIGNAL(changed()));
1099 connect(persDictionaryED, SIGNAL(textChanged(QString)),
1100 this, SIGNAL(changed()));
1101 connect(compoundWordCB, SIGNAL(clicked()),
1102 this, SIGNAL(changed()));
1103 connect(inputEncodingCB, SIGNAL(clicked()),
1104 this, SIGNAL(changed()));
1105 connect(spellcheckContinuouslyCB, SIGNAL(clicked()),
1106 this, SIGNAL(changed()));
1110 void PrefSpellchecker::apply(LyXRC & rc) const
1112 // FIXME: remove spellchecker_use_alt_lang
1113 rc.spellchecker_alt_lang = fromqstr(altLanguageED->text());
1114 rc.spellchecker_use_alt_lang = !rc.spellchecker_alt_lang.empty();
1115 // FIXME: remove spellchecker_use_esc_chars
1116 rc.spellchecker_esc_chars = fromqstr(escapeCharactersED->text());
1117 rc.spellchecker_use_esc_chars = !rc.spellchecker_esc_chars.empty();
1118 // FIXME: remove spellchecker_use_pers_dict
1119 rc.spellchecker_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
1120 rc.spellchecker_use_pers_dict = !rc.spellchecker_pers_dict.empty();
1121 rc.spellchecker_accept_compound = compoundWordCB->isChecked();
1122 rc.spellchecker_use_input_encoding = inputEncodingCB->isChecked();
1123 rc.spellcheck_continuously = spellcheckContinuouslyCB->isChecked();
1127 void PrefSpellchecker::update(LyXRC const & rc)
1129 // FIXME: remove spellchecker_use_alt_lang
1130 altLanguageED->setText(toqstr(rc.spellchecker_alt_lang));
1131 // FIXME: remove spellchecker_use_esc_chars
1132 escapeCharactersED->setText(toqstr(rc.spellchecker_esc_chars));
1133 // FIXME: remove spellchecker_use_pers_dict
1134 persDictionaryED->setText(toqstr(external_path(rc.spellchecker_pers_dict)));
1135 compoundWordCB->setChecked(rc.spellchecker_accept_compound);
1136 inputEncodingCB->setChecked(rc.spellchecker_use_input_encoding);
1137 spellcheckContinuouslyCB->setChecked(rc.spellcheck_continuously);
1141 void PrefSpellchecker::select_dict()
1143 QString file = form_->browsedict(internalPath(persDictionaryED->text()));
1144 if (!file.isEmpty())
1145 persDictionaryED->setText(file);
1150 /////////////////////////////////////////////////////////////////////
1154 /////////////////////////////////////////////////////////////////////
1157 PrefConverters::PrefConverters(GuiPreferences * form)
1158 : PrefModule(qt_(catFiles), qt_("Converters"), form)
1162 connect(converterNewPB, SIGNAL(clicked()),
1163 this, SLOT(update_converter()));
1164 connect(converterRemovePB, SIGNAL(clicked()),
1165 this, SLOT(remove_converter()));
1166 connect(converterModifyPB, SIGNAL(clicked()),
1167 this, SLOT(update_converter()));
1168 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1169 this, SLOT(switch_converter()));
1170 connect(converterFromCO, SIGNAL(activated(QString)),
1171 this, SLOT(converter_changed()));
1172 connect(converterToCO, SIGNAL(activated(QString)),
1173 this, SLOT(converter_changed()));
1174 connect(converterED, SIGNAL(textEdited(QString)),
1175 this, SLOT(converter_changed()));
1176 connect(converterFlagED, SIGNAL(textEdited(QString)),
1177 this, SLOT(converter_changed()));
1178 connect(converterNewPB, SIGNAL(clicked()),
1179 this, SIGNAL(changed()));
1180 connect(converterRemovePB, SIGNAL(clicked()),
1181 this, SIGNAL(changed()));
1182 connect(converterModifyPB, SIGNAL(clicked()),
1183 this, SIGNAL(changed()));
1184 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1185 this, SIGNAL(changed()));
1187 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1188 //converterDefGB->setFocusProxy(convertersLW);
1192 void PrefConverters::apply(LyXRC & rc) const
1194 rc.use_converter_cache = cacheCB->isChecked();
1195 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
1199 void PrefConverters::update(LyXRC const & rc)
1201 cacheCB->setChecked(rc.use_converter_cache);
1203 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
1204 maxAgeLE->setText(max_age);
1209 void PrefConverters::updateGui()
1211 form_->formats().sort();
1212 form_->converters().update(form_->formats());
1213 // save current selection
1214 QString current = converterFromCO->currentText()
1215 + " -> " + converterToCO->currentText();
1217 converterFromCO->clear();
1218 converterToCO->clear();
1220 Formats::const_iterator cit = form_->formats().begin();
1221 Formats::const_iterator end = form_->formats().end();
1222 for (; cit != end; ++cit) {
1223 converterFromCO->addItem(qt_(cit->prettyname()));
1224 converterToCO->addItem(qt_(cit->prettyname()));
1227 // currentRowChanged(int) is also triggered when updating the listwidget
1228 // block signals to avoid unnecessary calls to switch_converter()
1229 convertersLW->blockSignals(true);
1230 convertersLW->clear();
1232 Converters::const_iterator ccit = form_->converters().begin();
1233 Converters::const_iterator cend = form_->converters().end();
1234 for (; ccit != cend; ++ccit) {
1235 QString const name =
1236 qt_(ccit->From->prettyname()) + " -> " + qt_(ccit->To->prettyname());
1237 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1238 new QListWidgetItem(name, convertersLW, type);
1240 convertersLW->sortItems(Qt::AscendingOrder);
1241 convertersLW->blockSignals(false);
1243 // restore selection
1244 if (!current.isEmpty()) {
1245 QList<QListWidgetItem *> const item =
1246 convertersLW->findItems(current, Qt::MatchExactly);
1247 if (!item.isEmpty())
1248 convertersLW->setCurrentItem(item.at(0));
1251 // select first element if restoring failed
1252 if (convertersLW->currentRow() == -1)
1253 convertersLW->setCurrentRow(0);
1259 void PrefConverters::switch_converter()
1261 int const cnr = convertersLW->currentItem()->type();
1262 Converter const & c(form_->converters().get(cnr));
1263 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1264 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1265 converterED->setText(toqstr(c.command));
1266 converterFlagED->setText(toqstr(c.flags));
1272 void PrefConverters::converter_changed()
1278 void PrefConverters::updateButtons()
1280 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1281 Format const & to = form_->formats().get(converterToCO->currentIndex());
1282 int const sel = form_->converters().getNumber(from.name(), to.name());
1283 bool const known = sel >= 0;
1284 bool const valid = !(converterED->text().isEmpty()
1285 || from.name() == to.name());
1287 int const cnr = convertersLW->currentItem()->type();
1288 Converter const & c = form_->converters().get(cnr);
1289 string const old_command = c.command;
1290 string const old_flag = c.flags;
1291 string const new_command = fromqstr(converterED->text());
1292 string const new_flag = fromqstr(converterFlagED->text());
1294 bool modified = (old_command != new_command || old_flag != new_flag);
1296 converterModifyPB->setEnabled(valid && known && modified);
1297 converterNewPB->setEnabled(valid && !known);
1298 converterRemovePB->setEnabled(known);
1300 maxAgeLE->setEnabled(cacheCB->isChecked());
1301 maxAgeLA->setEnabled(cacheCB->isChecked());
1306 // specify unique from/to or it doesn't appear. This is really bad UI
1307 // this is why we can use the same function for both new and modify
1308 void PrefConverters::update_converter()
1310 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1311 Format const & to = form_->formats().get(converterToCO->currentIndex());
1312 string const flags = fromqstr(converterFlagED->text());
1313 string const command = fromqstr(converterED->text());
1315 Converter const * old =
1316 form_->converters().getConverter(from.name(), to.name());
1317 form_->converters().add(from.name(), to.name(), command, flags);
1320 form_->converters().updateLast(form_->formats());
1324 // Remove all files created by this converter from the cache, since
1325 // the modified converter might create different files.
1326 ConverterCache::get().remove_all(from.name(), to.name());
1330 void PrefConverters::remove_converter()
1332 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1333 Format const & to = form_->formats().get(converterToCO->currentIndex());
1334 form_->converters().erase(from.name(), to.name());
1338 // Remove all files created by this converter from the cache, since
1339 // a possible new converter might create different files.
1340 ConverterCache::get().remove_all(from.name(), to.name());
1344 void PrefConverters::on_cacheCB_stateChanged(int state)
1346 maxAgeLE->setEnabled(state == Qt::Checked);
1347 maxAgeLA->setEnabled(state == Qt::Checked);
1352 /////////////////////////////////////////////////////////////////////
1356 /////////////////////////////////////////////////////////////////////
1358 class FormatValidator : public QValidator
1361 FormatValidator(QWidget *, Formats const & f);
1362 void fixup(QString & input) const;
1363 QValidator::State validate(QString & input, int & pos) const;
1365 virtual QString toString(Format const & format) const = 0;
1367 Formats const & formats_;
1371 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1372 : QValidator(parent), formats_(f)
1377 void FormatValidator::fixup(QString & input) const
1379 Formats::const_iterator cit = formats_.begin();
1380 Formats::const_iterator end = formats_.end();
1381 for (; cit != end; ++cit) {
1382 QString const name = toString(*cit);
1383 if (distance(formats_.begin(), cit) == nr()) {
1391 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1393 Formats::const_iterator cit = formats_.begin();
1394 Formats::const_iterator end = formats_.end();
1395 bool unknown = true;
1396 for (; unknown && cit != end; ++cit) {
1397 QString const name = toString(*cit);
1398 if (distance(formats_.begin(), cit) != nr())
1399 unknown = name != input;
1402 if (unknown && !input.isEmpty())
1403 return QValidator::Acceptable;
1405 return QValidator::Intermediate;
1409 int FormatValidator::nr() const
1411 QComboBox * p = qobject_cast<QComboBox *>(parent());
1412 return p->itemData(p->currentIndex()).toInt();
1416 /////////////////////////////////////////////////////////////////////
1418 // FormatNameValidator
1420 /////////////////////////////////////////////////////////////////////
1422 class FormatNameValidator : public FormatValidator
1425 FormatNameValidator(QWidget * parent, Formats const & f)
1426 : FormatValidator(parent, f)
1429 QString toString(Format const & format) const
1431 return toqstr(format.name());
1436 /////////////////////////////////////////////////////////////////////
1438 // FormatPrettynameValidator
1440 /////////////////////////////////////////////////////////////////////
1442 class FormatPrettynameValidator : public FormatValidator
1445 FormatPrettynameValidator(QWidget * parent, Formats const & f)
1446 : FormatValidator(parent, f)
1449 QString toString(Format const & format) const
1451 return qt_(format.prettyname());
1456 /////////////////////////////////////////////////////////////////////
1460 /////////////////////////////////////////////////////////////////////
1462 PrefFileformats::PrefFileformats(GuiPreferences * form)
1463 : PrefModule(qt_(catFiles), qt_("File formats"), form)
1466 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1467 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1469 connect(documentCB, SIGNAL(clicked()),
1470 this, SLOT(setFlags()));
1471 connect(vectorCB, SIGNAL(clicked()),
1472 this, SLOT(setFlags()));
1473 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1474 this, SLOT(updatePrettyname()));
1475 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1476 this, SIGNAL(changed()));
1477 connect(defaultFormatCB, SIGNAL(activated(QString)),
1478 this, SIGNAL(changed()));
1484 string const l10n_shortcut(string const prettyname, string const shortcut)
1486 if (shortcut.empty())
1489 string l10n_format =
1490 to_utf8(_(prettyname + '|' + shortcut));
1491 return split(l10n_format, '|');
1494 }; // namespace anon
1497 void PrefFileformats::apply(LyXRC & rc) const
1499 QString const default_format = defaultFormatCB->itemData(
1500 defaultFormatCB->currentIndex()).toString();
1501 rc.default_view_format = fromqstr(default_format);
1505 void PrefFileformats::update(LyXRC const & rc)
1507 bool const init = defaultFormatCB->currentText().isEmpty();
1510 int const pos = defaultFormatCB->findData(toqstr(
1511 rc.default_view_format));
1512 defaultFormatCB->setCurrentIndex(pos);
1517 void PrefFileformats::updateView()
1519 QString const current = formatsCB->currentText();
1520 QString const current_def = defaultFormatCB->currentText();
1522 // update combobox with formats
1523 formatsCB->blockSignals(true);
1524 defaultFormatCB->blockSignals(true);
1526 form_->formats().sort();
1527 Formats::const_iterator cit = form_->formats().begin();
1528 Formats::const_iterator end = form_->formats().end();
1529 for (; cit != end; ++cit) {
1530 formatsCB->addItem(qt_(cit->prettyname()),
1531 QVariant(form_->formats().getNumber(cit->name())));
1532 if (form_->converters().isReachable("latex", cit->name())
1533 || form_->converters().isReachable("pdflatex", cit->name()))
1534 defaultFormatCB->addItem(qt_(cit->prettyname()),
1535 QVariant(toqstr(cit->name())));
1538 // restore selection
1539 int item = formatsCB->findText(current, Qt::MatchExactly);
1540 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1541 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1542 item = defaultFormatCB->findText(current_def, Qt::MatchExactly);
1543 defaultFormatCB->setCurrentIndex(item < 0 ? 0 : item);
1544 formatsCB->blockSignals(false);
1545 defaultFormatCB->blockSignals(false);
1549 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1551 int const nr = formatsCB->itemData(i).toInt();
1552 Format const f = form_->formats().get(nr);
1554 formatED->setText(toqstr(f.name()));
1555 copierED->setText(toqstr(form_->movers().command(f.name())));
1556 extensionED->setText(toqstr(f.extension()));
1557 shortcutED->setText(
1558 toqstr(l10n_shortcut(f.prettyname(), f.shortcut())));
1559 viewerED->setText(toqstr(f.viewer()));
1560 editorED->setText(toqstr(f.editor()));
1561 documentCB->setChecked((f.documentFormat()));
1562 vectorCB->setChecked((f.vectorFormat()));
1566 void PrefFileformats::setFlags()
1568 int flags = Format::none;
1569 if (documentCB->isChecked())
1570 flags |= Format::document;
1571 if (vectorCB->isChecked())
1572 flags |= Format::vector;
1573 currentFormat().setFlags(flags);
1578 void PrefFileformats::on_copierED_textEdited(const QString & s)
1580 string const fmt = fromqstr(formatED->text());
1581 form_->movers().set(fmt, fromqstr(s));
1586 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1588 currentFormat().setExtension(fromqstr(s));
1592 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1594 currentFormat().setViewer(fromqstr(s));
1599 void PrefFileformats::on_editorED_textEdited(const QString & s)
1601 currentFormat().setEditor(fromqstr(s));
1606 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1608 string const new_shortcut = fromqstr(s);
1609 if (new_shortcut == l10n_shortcut(currentFormat().prettyname(),
1610 currentFormat().shortcut()))
1612 currentFormat().setShortcut(new_shortcut);
1617 void PrefFileformats::on_formatED_editingFinished()
1619 string const newname = fromqstr(formatED->displayText());
1620 if (newname == currentFormat().name())
1623 currentFormat().setName(newname);
1628 void PrefFileformats::on_formatED_textChanged(const QString &)
1630 QString t = formatED->text();
1632 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1633 setValid(formatLA, valid);
1637 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1639 QString t = formatsCB->currentText();
1641 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1642 setValid(formatsLA, valid);
1646 void PrefFileformats::updatePrettyname()
1648 QString const newname = formatsCB->currentText();
1649 if (newname == qt_(currentFormat().prettyname()))
1652 currentFormat().setPrettyname(fromqstr(newname));
1659 Format & PrefFileformats::currentFormat()
1661 int const i = formatsCB->currentIndex();
1662 int const nr = formatsCB->itemData(i).toInt();
1663 return form_->formats().get(nr);
1667 void PrefFileformats::on_formatNewPB_clicked()
1669 form_->formats().add("", "", "", "", "", "", Format::none);
1671 formatsCB->setCurrentIndex(0);
1672 formatsCB->setFocus(Qt::OtherFocusReason);
1676 void PrefFileformats::on_formatRemovePB_clicked()
1678 int const i = formatsCB->currentIndex();
1679 int const nr = formatsCB->itemData(i).toInt();
1680 string const current_text = form_->formats().get(nr).name();
1681 if (form_->converters().formatIsUsed(current_text)) {
1682 Alert::error(_("Format in use"),
1683 _("Cannot remove a Format used by a Converter. "
1684 "Remove the converter first."));
1688 form_->formats().erase(current_text);
1691 on_formatsCB_editTextChanged(formatsCB->currentText());
1696 /////////////////////////////////////////////////////////////////////
1700 /////////////////////////////////////////////////////////////////////
1702 PrefLanguage::PrefLanguage(GuiPreferences * form)
1703 : PrefModule(qt_(catLanguage), qt_("Language"), form)
1707 connect(rtlGB, SIGNAL(clicked()),
1708 this, SIGNAL(changed()));
1709 connect(visualCursorRB, SIGNAL(clicked()),
1710 this, SIGNAL(changed()));
1711 connect(logicalCursorRB, SIGNAL(clicked()),
1712 this, SIGNAL(changed()));
1713 connect(markForeignCB, SIGNAL(clicked()),
1714 this, SIGNAL(changed()));
1715 connect(autoBeginCB, SIGNAL(clicked()),
1716 this, SIGNAL(changed()));
1717 connect(autoEndCB, SIGNAL(clicked()),
1718 this, SIGNAL(changed()));
1719 connect(useBabelCB, SIGNAL(clicked()),
1720 this, SIGNAL(changed()));
1721 connect(globalCB, SIGNAL(clicked()),
1722 this, SIGNAL(changed()));
1723 connect(languagePackageED, SIGNAL(textChanged(QString)),
1724 this, SIGNAL(changed()));
1725 connect(startCommandED, SIGNAL(textChanged(QString)),
1726 this, SIGNAL(changed()));
1727 connect(endCommandED, SIGNAL(textChanged(QString)),
1728 this, SIGNAL(changed()));
1729 connect(uiLanguageCO, SIGNAL(activated(int)),
1730 this, SIGNAL(changed()));
1732 uiLanguageCO->clear();
1734 QAbstractItemModel * language_model = guiApp->languageModel();
1735 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1736 language_model->sort(0);
1738 // FIXME: This is wrong, we need filter this list based on the available
1740 uiLanguageCO->blockSignals(true);
1741 uiLanguageCO->addItem(qt_("Default"), toqstr("auto"));
1742 for (int i = 0; i != language_model->rowCount(); ++i) {
1743 QModelIndex index = language_model->index(i, 0);
1744 uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
1745 index.data(Qt::UserRole).toString());
1747 uiLanguageCO->blockSignals(false);
1751 void PrefLanguage::on_uiLanguageCO_currentIndexChanged(int)
1753 QMessageBox::information(this, qt_("LyX needs to be restarted!"),
1754 qt_("The change of user interface language will be fully "
1755 "effective only after a restart."));
1759 void PrefLanguage::apply(LyXRC & rc) const
1761 // FIXME: remove rtl_support bool
1762 rc.rtl_support = rtlGB->isChecked();
1763 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
1764 rc.mark_foreign_language = markForeignCB->isChecked();
1765 rc.language_auto_begin = autoBeginCB->isChecked();
1766 rc.language_auto_end = autoEndCB->isChecked();
1767 rc.language_use_babel = useBabelCB->isChecked();
1768 rc.language_global_options = globalCB->isChecked();
1769 rc.language_package = fromqstr(languagePackageED->text());
1770 rc.language_command_begin = fromqstr(startCommandED->text());
1771 rc.language_command_end = fromqstr(endCommandED->text());
1772 rc.gui_language = fromqstr(
1773 uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString());
1777 void PrefLanguage::update(LyXRC const & rc)
1779 // FIXME: remove rtl_support bool
1780 rtlGB->setChecked(rc.rtl_support);
1781 if (rc.visual_cursor)
1782 visualCursorRB->setChecked(true);
1784 logicalCursorRB->setChecked(true);
1785 markForeignCB->setChecked(rc.mark_foreign_language);
1786 autoBeginCB->setChecked(rc.language_auto_begin);
1787 autoEndCB->setChecked(rc.language_auto_end);
1788 useBabelCB->setChecked(rc.language_use_babel);
1789 globalCB->setChecked(rc.language_global_options);
1790 languagePackageED->setText(toqstr(rc.language_package));
1791 startCommandED->setText(toqstr(rc.language_command_begin));
1792 endCommandED->setText(toqstr(rc.language_command_end));
1794 int pos = uiLanguageCO->findData(toqstr(rc.gui_language));
1795 uiLanguageCO->blockSignals(true);
1796 uiLanguageCO->setCurrentIndex(pos);
1797 uiLanguageCO->blockSignals(false);
1801 /////////////////////////////////////////////////////////////////////
1805 /////////////////////////////////////////////////////////////////////
1807 PrefPrinter::PrefPrinter(GuiPreferences * form)
1808 : PrefModule(qt_(catOutput), qt_("Printer"), form)
1812 connect(printerAdaptCB, SIGNAL(clicked()),
1813 this, SIGNAL(changed()));
1814 connect(printerCommandED, SIGNAL(textChanged(QString)),
1815 this, SIGNAL(changed()));
1816 connect(printerNameED, SIGNAL(textChanged(QString)),
1817 this, SIGNAL(changed()));
1818 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
1819 this, SIGNAL(changed()));
1820 connect(printerCopiesED, SIGNAL(textChanged(QString)),
1821 this, SIGNAL(changed()));
1822 connect(printerReverseED, SIGNAL(textChanged(QString)),
1823 this, SIGNAL(changed()));
1824 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
1825 this, SIGNAL(changed()));
1826 connect(printerExtensionED, SIGNAL(textChanged(QString)),
1827 this, SIGNAL(changed()));
1828 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
1829 this, SIGNAL(changed()));
1830 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
1831 this, SIGNAL(changed()));
1832 connect(printerEvenED, SIGNAL(textChanged(QString)),
1833 this, SIGNAL(changed()));
1834 connect(printerOddED, SIGNAL(textChanged(QString)),
1835 this, SIGNAL(changed()));
1836 connect(printerCollatedED, SIGNAL(textChanged(QString)),
1837 this, SIGNAL(changed()));
1838 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
1839 this, SIGNAL(changed()));
1840 connect(printerToFileED, SIGNAL(textChanged(QString)),
1841 this, SIGNAL(changed()));
1842 connect(printerExtraED, SIGNAL(textChanged(QString)),
1843 this, SIGNAL(changed()));
1844 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
1845 this, SIGNAL(changed()));
1846 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
1847 this, SIGNAL(changed()));
1851 void PrefPrinter::apply(LyXRC & rc) const
1853 rc.print_adapt_output = printerAdaptCB->isChecked();
1854 rc.print_command = fromqstr(printerCommandED->text());
1855 rc.printer = fromqstr(printerNameED->text());
1857 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1858 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1859 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1860 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1861 rc.print_file_extension = fromqstr(printerExtensionED->text());
1862 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1863 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1864 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1865 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1866 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1867 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1868 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1869 rc.print_extra_options = fromqstr(printerExtraED->text());
1870 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1871 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1875 void PrefPrinter::update(LyXRC const & rc)
1877 printerAdaptCB->setChecked(rc.print_adapt_output);
1878 printerCommandED->setText(toqstr(rc.print_command));
1879 printerNameED->setText(toqstr(rc.printer));
1881 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1882 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1883 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1884 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1885 printerExtensionED->setText(toqstr(rc.print_file_extension));
1886 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1887 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1888 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1889 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1890 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1891 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1892 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1893 printerExtraED->setText(toqstr(rc.print_extra_options));
1894 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1895 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1899 /////////////////////////////////////////////////////////////////////
1901 // PrefUserInterface
1903 /////////////////////////////////////////////////////////////////////
1905 PrefUserInterface::PrefUserInterface(GuiPreferences * form)
1906 : PrefModule(qt_(catLookAndFeel), qt_("User interface"), form)
1910 connect(autoSaveCB, SIGNAL(toggled(bool)),
1911 autoSaveSB, SLOT(setEnabled(bool)));
1912 connect(autoSaveCB, SIGNAL(toggled(bool)),
1913 TextLabel1, SLOT(setEnabled(bool)));
1914 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
1915 this, SIGNAL(changed()));
1916 connect(uiFilePB, SIGNAL(clicked()),
1917 this, SLOT(select_ui()));
1918 connect(uiFileED, SIGNAL(textChanged(QString)),
1919 this, SIGNAL(changed()));
1920 connect(restoreCursorCB, SIGNAL(clicked()),
1921 this, SIGNAL(changed()));
1922 connect(loadSessionCB, SIGNAL(clicked()),
1923 this, SIGNAL(changed()));
1924 connect(allowGeometrySessionCB, SIGNAL(clicked()),
1925 this, SIGNAL(changed()));
1926 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1927 this, SIGNAL(changed()));
1928 connect(autoSaveCB, SIGNAL(clicked()),
1929 this, SIGNAL(changed()));
1930 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1931 this, SIGNAL(changed()));
1932 connect(tooltipCB, SIGNAL(toggled(bool)),
1933 this, SIGNAL(changed()));
1934 lastfilesSB->setMaximum(maxlastfiles);
1938 void PrefUserInterface::apply(LyXRC & rc) const
1940 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1941 rc.use_lastfilepos = restoreCursorCB->isChecked();
1942 rc.load_session = loadSessionCB->isChecked();
1943 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
1944 rc.autosave = autoSaveSB->value() * 60;
1945 rc.make_backup = autoSaveCB->isChecked();
1946 rc.num_lastfiles = lastfilesSB->value();
1947 rc.use_tooltip = tooltipCB->isChecked();
1948 rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
1952 void PrefUserInterface::update(LyXRC const & rc)
1954 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1955 restoreCursorCB->setChecked(rc.use_lastfilepos);
1956 loadSessionCB->setChecked(rc.load_session);
1957 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
1958 // convert to minutes
1959 int mins(rc.autosave / 60);
1960 if (rc.autosave && !mins)
1962 autoSaveSB->setValue(mins);
1963 autoSaveCB->setChecked(rc.make_backup);
1964 lastfilesSB->setValue(rc.num_lastfiles);
1965 tooltipCB->setChecked(rc.use_tooltip);
1966 openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
1970 void PrefUserInterface::select_ui()
1972 QString file = form_->browseUI(internalPath(uiFileED->text()));
1973 if (!file.isEmpty())
1974 uiFileED->setText(file);
1978 void PrefUserInterface::on_clearSessionPB_clicked()
1980 guiApp->clearSession();
1985 /////////////////////////////////////////////////////////////////////
1989 /////////////////////////////////////////////////////////////////////
1991 PrefEdit::PrefEdit(GuiPreferences * form)
1992 : PrefModule(qt_(catEditing), qt_("Control"), form)
1996 connect(cursorFollowsCB, SIGNAL(clicked()),
1997 this, SIGNAL(changed()));
1998 connect(scrollBelowCB, SIGNAL(clicked()),
1999 this, SIGNAL(changed()));
2000 connect(sortEnvironmentsCB, SIGNAL(clicked()),
2001 this, SIGNAL(changed()));
2002 connect(groupEnvironmentsCB, SIGNAL(clicked()),
2003 this, SIGNAL(changed()));
2004 connect(macroEditStyleCO, SIGNAL(activated(int)),
2005 this, SIGNAL(changed()));
2006 connect(fullscreenLimitGB, SIGNAL(clicked()),
2007 this, SIGNAL(changed()));
2008 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
2009 this, SIGNAL(changed()));
2010 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
2011 this, SIGNAL(changed()));
2012 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
2013 this, SIGNAL(changed()));
2014 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
2015 this, SIGNAL(changed()));
2019 void PrefEdit::apply(LyXRC & rc) const
2021 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
2022 rc.scroll_below_document = scrollBelowCB->isChecked();
2023 rc.sort_layouts = sortEnvironmentsCB->isChecked();
2024 rc.group_layouts = groupEnvironmentsCB->isChecked();
2025 switch (macroEditStyleCO->currentIndex()) {
2026 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
2027 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
2028 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
2030 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
2031 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
2032 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
2033 rc.full_screen_width = fullscreenWidthSB->value();
2034 rc.full_screen_limit = fullscreenLimitGB->isChecked();
2038 void PrefEdit::update(LyXRC const & rc)
2040 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
2041 scrollBelowCB->setChecked(rc.scroll_below_document);
2042 sortEnvironmentsCB->setChecked(rc.sort_layouts);
2043 groupEnvironmentsCB->setChecked(rc.group_layouts);
2044 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
2045 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
2046 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
2047 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
2048 fullscreenWidthSB->setValue(rc.full_screen_width);
2049 fullscreenLimitGB->setChecked(rc.full_screen_limit);
2053 /////////////////////////////////////////////////////////////////////
2057 /////////////////////////////////////////////////////////////////////
2060 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
2062 Ui::shortcutUi::setupUi(this);
2063 QDialog::setModal(true);
2067 PrefShortcuts::PrefShortcuts(GuiPreferences * form)
2068 : PrefModule(qt_(catEditing), qt_("Shortcuts"), form)
2072 shortcutsTW->setColumnCount(2);
2073 shortcutsTW->headerItem()->setText(0, qt_("Function"));
2074 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
2075 shortcutsTW->setSortingEnabled(true);
2076 // Multi-selection can be annoying.
2077 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
2079 connect(bindFilePB, SIGNAL(clicked()),
2080 this, SLOT(select_bind()));
2081 connect(bindFileED, SIGNAL(textChanged(QString)),
2082 this, SIGNAL(changed()));
2083 connect(removePB, SIGNAL(clicked()),
2084 this, SIGNAL(changed()));
2086 shortcut_ = new GuiShortcutDialog(this);
2087 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
2088 shortcut_bc_.setOK(shortcut_->okPB);
2089 shortcut_bc_.setCancel(shortcut_->cancelPB);
2091 connect(shortcut_->okPB, SIGNAL(clicked()),
2092 shortcut_, SLOT(accept()));
2093 connect(shortcut_->okPB, SIGNAL(clicked()),
2094 this, SIGNAL(changed()));
2095 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2096 shortcut_, SLOT(reject()));
2097 connect(shortcut_->clearPB, SIGNAL(clicked()),
2098 this, SLOT(shortcut_clearPB_pressed()));
2099 connect(shortcut_->removePB, SIGNAL(clicked()),
2100 this, SLOT(shortcut_removePB_pressed()));
2101 connect(shortcut_->okPB, SIGNAL(clicked()),
2102 this, SLOT(shortcut_okPB_pressed()));
2103 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2104 this, SLOT(shortcut_cancelPB_pressed()));
2108 void PrefShortcuts::apply(LyXRC & rc) const
2110 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
2111 // write user_bind and user_unbind to .lyx/bind/user.bind
2112 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
2113 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
2114 lyxerr << "LyX could not create the user bind directory '"
2115 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2118 if (!bind_dir.isDirWritable()) {
2119 lyxerr << "LyX could not write to the user bind directory '"
2120 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2123 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
2124 user_unbind_.write(user_bind_file.toFilesystemEncoding(), false, true);
2125 user_bind_.write(user_bind_file.toFilesystemEncoding(), true, false);
2126 // immediately apply the keybindings. Why this is not done before?
2127 // The good thing is that the menus are updated automatically.
2128 theTopLevelKeymap().clear();
2129 theTopLevelKeymap().read("site");
2130 theTopLevelKeymap().read(rc.bind_file);
2131 theTopLevelKeymap().read("user");
2135 void PrefShortcuts::update(LyXRC const & rc)
2137 bindFileED->setText(toqstr(external_path(rc.bind_file)));
2139 system_bind_.clear();
2141 user_unbind_.clear();
2142 system_bind_.read("site");
2143 system_bind_.read(rc.bind_file);
2144 // \unbind in user.bind is added to user_unbind_
2145 user_bind_.read("user", &user_unbind_);
2146 updateShortcutsTW();
2150 void PrefShortcuts::updateShortcutsTW()
2152 shortcutsTW->clear();
2154 editItem_ = new QTreeWidgetItem(shortcutsTW);
2155 editItem_->setText(0, qt_("Cursor, Mouse and Editing functions"));
2156 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2158 mathItem_ = new QTreeWidgetItem(shortcutsTW);
2159 mathItem_->setText(0, qt_("Mathematical Symbols"));
2160 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2162 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2163 bufferItem_->setText(0, qt_("Document and Window"));
2164 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2166 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2167 layoutItem_->setText(0, qt_("Font, Layouts and Textclasses"));
2168 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2170 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2171 systemItem_->setText(0, qt_("System and Miscellaneous"));
2172 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2174 // listBindings(unbound=true) lists all bound and unbound lfuns
2175 // Items in this list is tagged by its source.
2176 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2178 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2180 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2181 KeyMap::UserUnbind);
2182 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2183 user_bindinglist.end());
2184 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2185 user_unbindinglist.end());
2187 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2188 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2189 for (; it != it_end; ++it)
2190 insertShortcutItem(it->request, it->sequence, KeyMap::ItemType(it->tag));
2192 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2193 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2194 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2195 modifyPB->setEnabled(!items.isEmpty());
2197 shortcutsTW->resizeColumnToContents(0);
2201 void PrefShortcuts::setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag)
2203 item->setData(0, Qt::UserRole, QVariant(tag));
2207 case KeyMap::System:
2209 case KeyMap::UserBind:
2212 case KeyMap::UserUnbind:
2213 font.setStrikeOut(true);
2215 // this item is not displayed now.
2216 case KeyMap::UserExtraUnbind:
2217 font.setStrikeOut(true);
2221 item->setFont(1, font);
2225 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2226 KeySequence const & seq, KeyMap::ItemType tag)
2228 FuncCode action = lfun.action;
2229 string const action_name = lyxaction.getActionName(action);
2230 QString const lfun_name = toqstr(from_utf8(action_name)
2231 + ' ' + lfun.argument());
2232 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2233 KeyMap::ItemType item_tag = tag;
2235 QTreeWidgetItem * newItem = 0;
2236 // for unbind items, try to find an existing item in the system bind list
2237 if (tag == KeyMap::UserUnbind) {
2238 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2239 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2240 for (int i = 0; i < items.size(); ++i) {
2241 if (items[i]->text(1) == shortcut)
2245 // if not found, this unbind item is KeyMap::UserExtraUnbind
2246 // Such an item is not displayed to avoid confusion (what is
2247 // unmatched removed?).
2249 item_tag = KeyMap::UserExtraUnbind;
2254 switch(lyxaction.getActionType(action)) {
2255 case LyXAction::Hidden:
2257 case LyXAction::Edit:
2258 newItem = new QTreeWidgetItem(editItem_);
2260 case LyXAction::Math:
2261 newItem = new QTreeWidgetItem(mathItem_);
2263 case LyXAction::Buffer:
2264 newItem = new QTreeWidgetItem(bufferItem_);
2266 case LyXAction::Layout:
2267 newItem = new QTreeWidgetItem(layoutItem_);
2269 case LyXAction::System:
2270 newItem = new QTreeWidgetItem(systemItem_);
2273 // this should not happen
2274 newItem = new QTreeWidgetItem(shortcutsTW);
2278 newItem->setText(0, lfun_name);
2279 newItem->setText(1, shortcut);
2280 // record BindFile representation to recover KeySequence when needed.
2281 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2282 setItemType(newItem, item_tag);
2287 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2289 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2290 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2291 modifyPB->setEnabled(!items.isEmpty());
2292 if (items.isEmpty())
2295 KeyMap::ItemType tag =
2296 static_cast<KeyMap::ItemType>(items[0]->data(0, Qt::UserRole).toInt());
2297 if (tag == KeyMap::UserUnbind)
2298 removePB->setText(qt_("Res&tore"));
2300 removePB->setText(qt_("Remo&ve"));
2304 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2310 void PrefShortcuts::modifyShortcut()
2312 QTreeWidgetItem * item = shortcutsTW->currentItem();
2313 if (item->flags() & Qt::ItemIsSelectable) {
2314 shortcut_->lfunLE->setText(item->text(0));
2315 save_lfun_ = item->text(0);
2316 shortcut_->shortcutWG->setText(item->text(1));
2318 seq.parse(fromqstr(item->data(1, Qt::UserRole).toString()));
2319 shortcut_->shortcutWG->setKeySequence(seq);
2320 shortcut_->shortcutWG->setFocus();
2326 void PrefShortcuts::removeShortcut()
2328 // it seems that only one item can be selected, but I am
2329 // removing all selected items anyway.
2330 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2331 for (int i = 0; i < items.size(); ++i) {
2332 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2333 string lfun = fromqstr(items[i]->text(0));
2334 FuncRequest func = lyxaction.lookupFunc(lfun);
2335 KeyMap::ItemType tag =
2336 static_cast<KeyMap::ItemType>(items[i]->data(0, Qt::UserRole).toInt());
2339 case KeyMap::System: {
2340 // for system bind, we do not touch the item
2341 // but add an user unbind item
2342 user_unbind_.bind(shortcut, func);
2343 setItemType(items[i], KeyMap::UserUnbind);
2344 removePB->setText(qt_("Res&tore"));
2347 case KeyMap::UserBind: {
2348 // for user_bind, we remove this bind
2349 QTreeWidgetItem * parent = items[i]->parent();
2350 int itemIdx = parent->indexOfChild(items[i]);
2351 parent->takeChild(itemIdx);
2353 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2355 shortcutsTW->scrollToItem(parent);
2356 user_bind_.unbind(shortcut, func);
2359 case KeyMap::UserUnbind: {
2360 // for user_unbind, we remove the unbind, and the item
2361 // become KeyMap::System again.
2362 user_unbind_.unbind(shortcut, func);
2363 setItemType(items[i], KeyMap::System);
2364 removePB->setText(qt_("Remo&ve"));
2367 case KeyMap::UserExtraUnbind: {
2368 // for user unbind that is not in system bind file,
2369 // remove this unbind file
2370 QTreeWidgetItem * parent = items[i]->parent();
2371 parent->takeChild(parent->indexOfChild(items[i]));
2372 user_unbind_.unbind(shortcut, func);
2379 void PrefShortcuts::select_bind()
2381 QString file = form_->browsebind(internalPath(bindFileED->text()));
2382 if (!file.isEmpty()) {
2383 bindFileED->setText(file);
2384 system_bind_ = KeyMap();
2385 system_bind_.read(fromqstr(file));
2386 updateShortcutsTW();
2391 void PrefShortcuts::on_modifyPB_pressed()
2397 void PrefShortcuts::on_newPB_pressed()
2399 shortcut_->lfunLE->clear();
2400 shortcut_->shortcutWG->reset();
2401 save_lfun_ = QString();
2406 void PrefShortcuts::on_removePB_pressed()
2412 void PrefShortcuts::on_searchLE_textEdited()
2414 if (searchLE->text().isEmpty()) {
2415 // show all hidden items
2416 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2418 shortcutsTW->setItemHidden(*it++, false);
2421 // search both columns
2422 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2423 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2424 matched += shortcutsTW->findItems(searchLE->text(),
2425 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2427 // hide everyone (to avoid searching in matched QList repeatedly
2428 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2430 shortcutsTW->setItemHidden(*it++, true);
2431 // show matched items
2432 for (int i = 0; i < matched.size(); ++i) {
2433 shortcutsTW->setItemHidden(matched[i], false);
2434 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2439 docstring makeCmdString(FuncRequest const & f)
2441 docstring actionStr = from_ascii(lyxaction.getActionName(f.action));
2442 if (!f.argument().empty())
2443 actionStr += " " + f.argument();
2448 void PrefShortcuts::shortcut_okPB_pressed()
2450 QString const new_lfun = shortcut_->lfunLE->text();
2451 FuncRequest func = lyxaction.lookupFunc(fromqstr(new_lfun));
2453 if (func.action == LFUN_UNKNOWN_ACTION) {
2454 Alert::error(_("Failed to create shortcut"),
2455 _("Unknown or invalid LyX function"));
2459 KeySequence k = shortcut_->shortcutWG->getKeySequence();
2460 if (k.length() == 0) {
2461 Alert::error(_("Failed to create shortcut"),
2462 _("Invalid or empty key sequence"));
2466 // check to see if there's been any change
2467 FuncRequest oldBinding = system_bind_.getBinding(k);
2468 if (oldBinding.action == LFUN_UNKNOWN_ACTION)
2469 oldBinding = user_bind_.getBinding(k);
2470 if (oldBinding == func) {
2471 docstring const actionStr = makeCmdString(func);
2472 Alert::error(_("Failed to create shortcut"),
2473 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s"),
2474 k.print(KeySequence::ForGui), actionStr));
2478 // make sure this key isn't already bound---and, if so, not unbound
2479 FuncCode const unbind = user_unbind_.getBinding(k).action;
2480 if (oldBinding.action != LFUN_UNKNOWN_ACTION && unbind == LFUN_UNKNOWN_ACTION)
2482 // FIXME Perhaps we should offer to over-write the old shortcut?
2483 // If so, we'll need to remove it from our list, etc.
2484 docstring const actionStr = makeCmdString(oldBinding);
2485 Alert::error(_("Failed to create shortcut"),
2486 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s\n"
2487 "You need to remove that binding before creating a new one."),
2488 k.print(KeySequence::ForGui), actionStr));
2492 if (!save_lfun_.isEmpty() && new_lfun == save_lfun_)
2493 // real modification of the lfun's shortcut,
2494 // so remove the previous one
2497 QTreeWidgetItem * item = insertShortcutItem(func, k, KeyMap::UserBind);
2499 user_bind_.bind(&k, func);
2500 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2501 shortcutsTW->setItemExpanded(item->parent(), true);
2502 shortcutsTW->scrollToItem(item);
2504 Alert::error(_("Failed to create shortcut"),
2505 _("Can not insert shortcut to the list"));
2511 void PrefShortcuts::shortcut_cancelPB_pressed()
2513 shortcut_->shortcutWG->reset();
2517 void PrefShortcuts::shortcut_clearPB_pressed()
2519 shortcut_->shortcutWG->reset();
2523 void PrefShortcuts::shortcut_removePB_pressed()
2525 shortcut_->shortcutWG->removeFromSequence();
2529 /////////////////////////////////////////////////////////////////////
2533 /////////////////////////////////////////////////////////////////////
2535 PrefIdentity::PrefIdentity(GuiPreferences * form)
2536 : PrefModule(QString(), qt_("Identity"), form)
2540 connect(nameED, SIGNAL(textChanged(QString)),
2541 this, SIGNAL(changed()));
2542 connect(emailED, SIGNAL(textChanged(QString)),
2543 this, SIGNAL(changed()));
2547 void PrefIdentity::apply(LyXRC & rc) const
2549 rc.user_name = fromqstr(nameED->text());
2550 rc.user_email = fromqstr(emailED->text());
2554 void PrefIdentity::update(LyXRC const & rc)
2556 nameED->setText(toqstr(rc.user_name));
2557 emailED->setText(toqstr(rc.user_email));
2562 /////////////////////////////////////////////////////////////////////
2566 /////////////////////////////////////////////////////////////////////
2568 GuiPreferences::GuiPreferences(GuiView & lv)
2569 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2573 QDialog::setModal(false);
2575 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2576 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2577 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2578 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2580 addModule(new PrefUserInterface(this));
2581 addModule(new PrefEdit(this));
2582 addModule(new PrefShortcuts(this));
2583 addModule(new PrefScreenFonts(this));
2584 addModule(new PrefColors(this));
2585 addModule(new PrefDisplay(this));
2586 addModule(new PrefInput(this));
2587 addModule(new PrefCompletion(this));
2589 addModule(new PrefPaths(this));
2591 addModule(new PrefIdentity(this));
2593 addModule(new PrefLanguage(this));
2594 addModule(new PrefSpellchecker(this));
2596 addModule(new PrefPrinter(this));
2597 PrefDate * dateFormat = new PrefDate(this);
2598 addModule(dateFormat);
2599 addModule(new PrefPlaintext(this));
2600 addModule(new PrefLatex(this));
2602 PrefConverters * converters = new PrefConverters(this);
2603 PrefFileformats * formats = new PrefFileformats(this);
2604 connect(formats, SIGNAL(formatsChanged()),
2605 converters, SLOT(updateGui()));
2606 addModule(converters);
2609 prefsPS->setCurrentPanel(qt_("User interface"));
2610 // FIXME: hack to work around resizing bug in Qt >= 4.2
2611 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2612 #if QT_VERSION >= 0x040200
2613 prefsPS->updateGeometry();
2616 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2618 bc().setApply(applyPB);
2619 bc().setCancel(closePB);
2620 bc().setRestore(restorePB);
2622 // initialize the strftime validator
2623 bc().addCheckedLineEdit(dateFormat->DateED);
2627 void GuiPreferences::addModule(PrefModule * module)
2629 LASSERT(module, return);
2630 if (module->category().isEmpty())
2631 prefsPS->addPanel(module, module->title());
2633 prefsPS->addPanel(module, module->title(), module->category());
2634 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2635 modules_.push_back(module);
2639 void GuiPreferences::change_adaptor()
2645 void GuiPreferences::apply(LyXRC & rc) const
2647 size_t end = modules_.size();
2648 for (size_t i = 0; i != end; ++i)
2649 modules_[i]->apply(rc);
2653 void GuiPreferences::updateRc(LyXRC const & rc)
2655 size_t const end = modules_.size();
2656 for (size_t i = 0; i != end; ++i)
2657 modules_[i]->update(rc);
2661 void GuiPreferences::applyView()
2666 bool GuiPreferences::initialiseParams(string const &)
2669 formats_ = lyx::formats;
2670 converters_ = theConverters();
2671 converters_.update(formats_);
2672 movers_ = theMovers();
2674 update_screen_font_ = false;
2677 // Make sure that the bc is in the INITIAL state
2678 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
2685 void GuiPreferences::dispatchParams()
2688 rc_.write(ss, true);
2689 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
2690 // FIXME: these need lfuns
2692 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
2694 lyx::formats = formats_;
2696 theConverters() = converters_;
2697 theConverters().update(lyx::formats);
2698 theConverters().buildGraph();
2700 theMovers() = movers_;
2702 vector<string>::const_iterator it = colors_.begin();
2703 vector<string>::const_iterator const end = colors_.end();
2704 for (; it != end; ++it)
2705 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
2708 if (update_screen_font_) {
2709 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2710 update_screen_font_ = false;
2713 // The Save button has been pressed
2715 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
2719 void GuiPreferences::setColor(ColorCode col, QString const & hex)
2721 colors_.push_back(lcolor.getLyXName(col) + ' ' + fromqstr(hex));
2725 void GuiPreferences::updateScreenFonts()
2727 update_screen_font_ = true;
2731 QString GuiPreferences::browsebind(QString const & file) const
2733 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
2734 QStringList(qt_("LyX bind files (*.bind)")));
2738 QString GuiPreferences::browseUI(QString const & file) const
2740 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
2741 QStringList(qt_("LyX UI files (*.ui)")));
2745 QString GuiPreferences::browsekbmap(QString const & file) const
2747 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
2748 QStringList(qt_("LyX keyboard maps (*.kmap)")));
2752 QString GuiPreferences::browsedict(QString const & file) const
2754 return browseFile(file, qt_("Choose personal dictionary"),
2755 QStringList(qt_("*.pws")));
2759 QString GuiPreferences::browse(QString const & file,
2760 QString const & title) const
2762 return browseFile(file, title, QStringList(), true);
2766 // We support less paper sizes than the document dialog
2767 // Therefore this adjustment is needed.
2768 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
2772 return PAPER_DEFAULT;
2774 return PAPER_USLETTER;
2776 return PAPER_USLEGAL;
2778 return PAPER_USEXECUTIVE;
2788 // should not happen
2789 return PAPER_DEFAULT;
2794 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
2796 switch (papersize) {
2799 case PAPER_USLETTER:
2803 case PAPER_USEXECUTIVE:
2814 // should not happen
2820 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
2823 } // namespace frontend
2826 #include "moc_GuiPrefs.cpp"