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"
26 #include "ConverterCache.h"
27 #include "FontEnums.h"
28 #include "FuncRequest.h"
30 #include "KeySequence.h"
32 #include "LyXAction.h"
33 #include "PanelStack.h"
37 #include "support/debug.h"
38 #include "support/FileName.h"
39 #include "support/filetools.h"
40 #include "support/foreach.h"
41 #include "support/gettext.h"
42 #include "support/lstrings.h"
43 #include "support/os.h"
44 #include "support/Package.h"
46 #include "graphics/GraphicsTypes.h"
48 #include "frontends/alert.h"
49 #include "frontends/Application.h"
50 #include "frontends/FontLoader.h"
52 #include <QAbstractItemModel>
54 #include <QColorDialog>
55 #include <QFontDatabase>
56 #include <QHeaderView>
58 #include <QMessageBox>
59 #include <QPixmapCache>
60 #include <QPushButton>
63 #include <QTreeWidget>
64 #include <QTreeWidgetItem>
74 using namespace lyx::support;
75 using namespace lyx::support::os;
80 /////////////////////////////////////////////////////////////////////
84 /////////////////////////////////////////////////////////////////////
86 /** Launch a file dialog and return the chosen file.
87 filename: a suggested filename.
88 title: the title of the dialog.
90 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
92 QString browseFile(QString const & filename,
93 QString const & title,
94 QStringList const & filters,
96 QString const & label1 = QString(),
97 QString const & dir1 = QString(),
98 QString const & label2 = QString(),
99 QString const & dir2 = QString(),
100 QString const & fallback_dir = QString())
102 QString lastPath = ".";
103 if (!filename.isEmpty())
104 lastPath = onlyPath(filename);
105 else if(!fallback_dir.isEmpty())
106 lastPath = fallback_dir;
108 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
109 dlg.setButton2(label1, dir1);
110 dlg.setButton2(label2, dir2);
112 FileDialog::Result result;
115 result = dlg.save(lastPath, filters, onlyFilename(filename));
117 result = dlg.open(lastPath, filters, onlyFilename(filename));
119 return result.second;
123 /** Wrapper around browseFile which tries to provide a filename
124 * relative to the user or system directory. The dir, name and ext
125 * parameters have the same meaning as in the
126 * support::LibFileSearch function.
128 QString browseLibFile(QString const & dir,
129 QString const & name,
131 QString const & title,
132 QStringList const & filters)
135 QString const label1 = qt_("System files|#S#s");
137 toqstr(addName(package().system_support().absFilename(), fromqstr(dir)));
139 QString const label2 = qt_("User files|#U#u");
141 toqstr(addName(package().user_support().absFilename(), fromqstr(dir)));
143 QString const result = browseFile(toqstr(
144 libFileSearch(dir, name, ext).absFilename()),
145 title, filters, false, dir1, dir2, QString(), QString(), dir1);
147 // remove the extension if it is the default one
149 if (getExtension(result) == ext)
150 noextresult = removeExtension(result);
152 noextresult = result;
154 // remove the directory, if it is the default one
155 QString const file = onlyFilename(noextresult);
156 if (toqstr(libFileSearch(dir, file, ext).absFilename()) == result)
163 /** Launch a file dialog and return the chosen directory.
164 pathname: a suggested pathname.
165 title: the title of the dialog.
166 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
168 QString browseDir(QString const & pathname,
169 QString const & title,
170 QString const & label1 = QString(),
171 QString const & dir1 = QString(),
172 QString const & label2 = QString(),
173 QString const & dir2 = QString())
175 QString lastPath = ".";
176 if (!pathname.isEmpty())
177 lastPath = onlyPath(pathname);
179 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
180 dlg.setButton1(label1, dir1);
181 dlg.setButton2(label2, dir2);
183 FileDialog::Result const result =
184 dlg.opendir(lastPath, onlyFilename(pathname));
186 return result.second;
190 } // namespace frontend
193 QString browseRelFile(QString const & filename, QString const & refpath,
194 QString const & title, QStringList const & filters, bool save,
195 QString const & label1, QString const & dir1,
196 QString const & label2, QString const & dir2)
198 QString const fname = makeAbsPath(filename, refpath);
201 QString const outname =
202 frontend::browseFile(fname, title, filters, save, label1, dir1, label2, dir2);
204 QString const reloutname =
205 toqstr(makeRelPath(qstring_to_ucs4(outname), qstring_to_ucs4(refpath)));
207 if (reloutname.startsWith("../"))
215 /////////////////////////////////////////////////////////////////////
219 /////////////////////////////////////////////////////////////////////
223 string const catLookAndFeel = N_("Look & Feel");
224 string const catEditing = N_("Editing");
225 string const catLanguage = N_("Language Settings");
226 string const catOutput = N_("Output");
227 string const catFiles = N_("File Handling");
229 static void parseFontName(QString const & mangled0,
230 string & name, string & foundry)
232 string mangled = fromqstr(mangled0);
233 size_t const idx = mangled.find('[');
234 if (idx == string::npos || idx == 0) {
238 name = mangled.substr(0, idx - 1),
239 foundry = mangled.substr(idx + 1, mangled.size() - idx - 2);
244 static void setComboxFont(QComboBox * cb, string const & family,
245 string const & foundry)
247 QString fontname = toqstr(family);
248 if (!foundry.empty())
249 fontname += " [" + toqstr(foundry) + ']';
251 for (int i = 0; i != cb->count(); ++i) {
252 if (cb->itemText(i) == fontname) {
253 cb->setCurrentIndex(i);
258 // Try matching without foundry name
260 // We count in reverse in order to prefer the Xft foundry
261 for (int i = cb->count(); --i >= 0;) {
262 string name, foundry;
263 parseFontName(cb->itemText(i), name, foundry);
264 if (compare_ascii_no_case(name, family) == 0) {
265 cb->setCurrentIndex(i);
270 // family alone can contain e.g. "Helvetica [Adobe]"
271 string tmpname, tmpfoundry;
272 parseFontName(toqstr(family), tmpname, tmpfoundry);
274 // We count in reverse in order to prefer the Xft foundry
275 for (int i = cb->count(); --i >= 0; ) {
276 string name, foundry;
277 parseFontName(cb->itemText(i), name, foundry);
278 if (compare_ascii_no_case(name, foundry) == 0) {
279 cb->setCurrentIndex(i);
284 // Bleh, default fonts, and the names couldn't be found. Hack
288 font.setKerning(false);
290 QString const font_family = toqstr(family);
291 if (font_family == guiApp->romanFontName()) {
292 font.setStyleHint(QFont::Serif);
293 font.setFamily(font_family);
294 } else if (font_family == guiApp->sansFontName()) {
295 font.setStyleHint(QFont::SansSerif);
296 font.setFamily(font_family);
297 } else if (font_family == guiApp->typewriterFontName()) {
298 font.setStyleHint(QFont::TypeWriter);
299 font.setFamily(font_family);
301 LYXERR0("FAILED to find the default font: '"
302 << foundry << "', '" << family << '\'');
306 QFontInfo info(font);
307 string default_font_name, dummyfoundry;
308 parseFontName(info.family(), default_font_name, dummyfoundry);
309 LYXERR0("Apparent font is " << default_font_name);
311 for (int i = 0; i < cb->count(); ++i) {
312 LYXERR0("Looking at " << cb->itemText(i));
313 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
314 default_font_name) == 0) {
315 cb->setCurrentIndex(i);
320 LYXERR0("FAILED to find the font: '"
321 << foundry << "', '" << family << '\'');
326 /////////////////////////////////////////////////////////////////////
330 /////////////////////////////////////////////////////////////////////
332 PrefPlaintext::PrefPlaintext(GuiPreferences * form)
333 : PrefModule(qt_(catOutput), qt_("Plain text"), form)
336 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
337 this, SIGNAL(changed()));
341 void PrefPlaintext::apply(LyXRC & rc) const
343 rc.plaintext_linelen = plaintextLinelengthSB->value();
347 void PrefPlaintext::update(LyXRC const & rc)
349 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
353 /////////////////////////////////////////////////////////////////////
357 /////////////////////////////////////////////////////////////////////
359 PrefDate::PrefDate(GuiPreferences * form)
360 : PrefModule(qt_(catOutput), qt_("Date format"), form)
363 connect(DateED, SIGNAL(textChanged(QString)),
364 this, SIGNAL(changed()));
368 void PrefDate::apply(LyXRC & rc) const
370 rc.date_insert_format = fromqstr(DateED->text());
374 void PrefDate::update(LyXRC const & rc)
376 DateED->setText(toqstr(rc.date_insert_format));
380 /////////////////////////////////////////////////////////////////////
384 /////////////////////////////////////////////////////////////////////
386 PrefInput::PrefInput(GuiPreferences * form)
387 : PrefModule(qt_(catEditing), qt_("Keyboard/Mouse"), form)
391 connect(keymapCB, SIGNAL(clicked()),
392 this, SIGNAL(changed()));
393 connect(firstKeymapED, SIGNAL(textChanged(QString)),
394 this, SIGNAL(changed()));
395 connect(secondKeymapED, SIGNAL(textChanged(QString)),
396 this, SIGNAL(changed()));
397 connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
398 this, SIGNAL(changed()));
402 void PrefInput::apply(LyXRC & rc) const
404 // FIXME: can derive CB from the two EDs
405 rc.use_kbmap = keymapCB->isChecked();
406 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
407 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
408 rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
412 void PrefInput::update(LyXRC const & rc)
414 // FIXME: can derive CB from the two EDs
415 keymapCB->setChecked(rc.use_kbmap);
416 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
417 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
418 mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
422 QString PrefInput::testKeymap(QString const & keymap)
424 return form_->browsekbmap(internalPath(keymap));
428 void PrefInput::on_firstKeymapPB_clicked(bool)
430 QString const file = testKeymap(firstKeymapED->text());
432 firstKeymapED->setText(file);
436 void PrefInput::on_secondKeymapPB_clicked(bool)
438 QString const file = testKeymap(secondKeymapED->text());
440 secondKeymapED->setText(file);
444 void PrefInput::on_keymapCB_toggled(bool keymap)
446 firstKeymapLA->setEnabled(keymap);
447 secondKeymapLA->setEnabled(keymap);
448 firstKeymapED->setEnabled(keymap);
449 secondKeymapED->setEnabled(keymap);
450 firstKeymapPB->setEnabled(keymap);
451 secondKeymapPB->setEnabled(keymap);
455 /////////////////////////////////////////////////////////////////////
459 /////////////////////////////////////////////////////////////////////
461 PrefCompletion::PrefCompletion(GuiPreferences * form)
462 : PrefModule(qt_(catEditing), qt_("Input Completion"), form)
466 connect(inlineDelaySB, SIGNAL(valueChanged(double)),
467 this, SIGNAL(changed()));
468 connect(inlineMathCB, SIGNAL(clicked()),
469 this, SIGNAL(changed()));
470 connect(inlineTextCB, SIGNAL(clicked()),
471 this, SIGNAL(changed()));
472 connect(inlineDotsCB, SIGNAL(clicked()),
473 this, SIGNAL(changed()));
474 connect(popupDelaySB, SIGNAL(valueChanged(double)),
475 this, SIGNAL(changed()));
476 connect(popupMathCB, SIGNAL(clicked()),
477 this, SIGNAL(changed()));
478 connect(popupTextCB, SIGNAL(clicked()),
479 this, SIGNAL(changed()));
480 connect(popupAfterCompleteCB, SIGNAL(clicked()),
481 this, SIGNAL(changed()));
482 connect(cursorTextCB, SIGNAL(clicked()),
483 this, SIGNAL(changed()));
487 void PrefCompletion::apply(LyXRC & rc) const
489 rc.completion_inline_delay = inlineDelaySB->value();
490 rc.completion_inline_math = inlineMathCB->isChecked();
491 rc.completion_inline_text = inlineTextCB->isChecked();
492 rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
493 rc.completion_popup_delay = popupDelaySB->value();
494 rc.completion_popup_math = popupMathCB->isChecked();
495 rc.completion_popup_text = popupTextCB->isChecked();
496 rc.completion_cursor_text = cursorTextCB->isChecked();
497 rc.completion_popup_after_complete =
498 popupAfterCompleteCB->isChecked();
502 void PrefCompletion::update(LyXRC const & rc)
504 inlineDelaySB->setValue(rc.completion_inline_delay);
505 inlineMathCB->setChecked(rc.completion_inline_math);
506 inlineTextCB->setChecked(rc.completion_inline_text);
507 inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
508 popupDelaySB->setValue(rc.completion_popup_delay);
509 popupMathCB->setChecked(rc.completion_popup_math);
510 popupTextCB->setChecked(rc.completion_popup_text);
511 cursorTextCB->setChecked(rc.completion_cursor_text);
512 popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
517 /////////////////////////////////////////////////////////////////////
521 /////////////////////////////////////////////////////////////////////
523 PrefLatex::PrefLatex(GuiPreferences * form)
524 : PrefModule(qt_(catOutput), qt_("LaTeX"), form)
527 connect(latexEncodingED, SIGNAL(textChanged(QString)),
528 this, SIGNAL(changed()));
529 connect(latexChecktexED, SIGNAL(textChanged(QString)),
530 this, SIGNAL(changed()));
531 connect(latexBibtexED, SIGNAL(textChanged(QString)),
532 this, SIGNAL(changed()));
533 connect(latexIndexED, SIGNAL(textChanged(QString)),
534 this, SIGNAL(changed()));
535 connect(latexAutoresetCB, SIGNAL(clicked()),
536 this, SIGNAL(changed()));
537 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
538 this, SIGNAL(changed()));
539 connect(latexPaperSizeCO, SIGNAL(activated(int)),
540 this, SIGNAL(changed()));
542 #if defined(__CYGWIN__) || defined(_WIN32)
543 pathCB->setVisible(true);
544 connect(pathCB, SIGNAL(clicked()),
545 this, SIGNAL(changed()));
547 pathCB->setVisible(false);
552 void PrefLatex::apply(LyXRC & rc) const
554 rc.fontenc = fromqstr(latexEncodingED->text());
555 rc.chktex_command = fromqstr(latexChecktexED->text());
556 rc.bibtex_command = fromqstr(latexBibtexED->text());
557 rc.index_command = fromqstr(latexIndexED->text());
558 rc.nomencl_command = fromqstr(latexNomenclED->text());
559 rc.auto_reset_options = latexAutoresetCB->isChecked();
560 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
561 rc.default_papersize =
562 form_->toPaperSize(latexPaperSizeCO->currentIndex());
563 #if defined(__CYGWIN__) || defined(_WIN32)
564 rc.windows_style_tex_paths = pathCB->isChecked();
569 void PrefLatex::update(LyXRC const & rc)
571 latexEncodingED->setText(toqstr(rc.fontenc));
572 latexChecktexED->setText(toqstr(rc.chktex_command));
573 latexBibtexED->setText(toqstr(rc.bibtex_command));
574 latexIndexED->setText(toqstr(rc.index_command));
575 latexNomenclED->setText(toqstr(rc.nomencl_command));
576 latexAutoresetCB->setChecked(rc.auto_reset_options);
577 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
578 latexPaperSizeCO->setCurrentIndex(
579 form_->fromPaperSize(rc.default_papersize));
580 #if defined(__CYGWIN__) || defined(_WIN32)
581 pathCB->setChecked(rc.windows_style_tex_paths);
586 /////////////////////////////////////////////////////////////////////
590 /////////////////////////////////////////////////////////////////////
592 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form)
593 : PrefModule(qt_(catLookAndFeel), qt_("Screen fonts"), form)
597 connect(screenRomanCO, SIGNAL(activated(QString)),
598 this, SLOT(select_roman(QString)));
599 connect(screenSansCO, SIGNAL(activated(QString)),
600 this, SLOT(select_sans(QString)));
601 connect(screenTypewriterCO, SIGNAL(activated(QString)),
602 this, SLOT(select_typewriter(QString)));
604 QFontDatabase fontdb;
605 QStringList families(fontdb.families());
606 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
607 screenRomanCO->addItem(*it);
608 screenSansCO->addItem(*it);
609 screenTypewriterCO->addItem(*it);
611 connect(screenRomanCO, SIGNAL(activated(QString)),
612 this, SIGNAL(changed()));
613 connect(screenSansCO, SIGNAL(activated(QString)),
614 this, SIGNAL(changed()));
615 connect(screenTypewriterCO, SIGNAL(activated(QString)),
616 this, SIGNAL(changed()));
617 connect(screenZoomSB, SIGNAL(valueChanged(int)),
618 this, SIGNAL(changed()));
619 connect(screenDpiSB, SIGNAL(valueChanged(int)),
620 this, SIGNAL(changed()));
621 connect(screenTinyED, SIGNAL(textChanged(QString)),
622 this, SIGNAL(changed()));
623 connect(screenSmallestED, SIGNAL(textChanged(QString)),
624 this, SIGNAL(changed()));
625 connect(screenSmallerED, SIGNAL(textChanged(QString)),
626 this, SIGNAL(changed()));
627 connect(screenSmallED, SIGNAL(textChanged(QString)),
628 this, SIGNAL(changed()));
629 connect(screenNormalED, SIGNAL(textChanged(QString)),
630 this, SIGNAL(changed()));
631 connect(screenLargeED, SIGNAL(textChanged(QString)),
632 this, SIGNAL(changed()));
633 connect(screenLargerED, SIGNAL(textChanged(QString)),
634 this, SIGNAL(changed()));
635 connect(screenLargestED, SIGNAL(textChanged(QString)),
636 this, SIGNAL(changed()));
637 connect(screenHugeED, SIGNAL(textChanged(QString)),
638 this, SIGNAL(changed()));
639 connect(screenHugerED, SIGNAL(textChanged(QString)),
640 this, SIGNAL(changed()));
641 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
642 this, SIGNAL(changed()));
644 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
645 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
646 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
647 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
648 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
649 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
650 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
651 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
652 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
653 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
657 void PrefScreenFonts::apply(LyXRC & rc) const
659 LyXRC const oldrc = rc;
661 parseFontName(screenRomanCO->currentText(),
662 rc.roman_font_name, rc.roman_font_foundry);
663 parseFontName(screenSansCO->currentText(),
664 rc.sans_font_name, rc.sans_font_foundry);
665 parseFontName(screenTypewriterCO->currentText(),
666 rc.typewriter_font_name, rc.typewriter_font_foundry);
668 rc.zoom = screenZoomSB->value();
669 rc.dpi = screenDpiSB->value();
670 rc.font_sizes[FONT_SIZE_TINY] = fromqstr(screenTinyED->text());
671 rc.font_sizes[FONT_SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
672 rc.font_sizes[FONT_SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
673 rc.font_sizes[FONT_SIZE_SMALL] = fromqstr(screenSmallED->text());
674 rc.font_sizes[FONT_SIZE_NORMAL] = fromqstr(screenNormalED->text());
675 rc.font_sizes[FONT_SIZE_LARGE] = fromqstr(screenLargeED->text());
676 rc.font_sizes[FONT_SIZE_LARGER] = fromqstr(screenLargerED->text());
677 rc.font_sizes[FONT_SIZE_LARGEST] = fromqstr(screenLargestED->text());
678 rc.font_sizes[FONT_SIZE_HUGE] = fromqstr(screenHugeED->text());
679 rc.font_sizes[FONT_SIZE_HUGER] = fromqstr(screenHugerED->text());
680 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
682 if (rc.font_sizes != oldrc.font_sizes
683 || rc.roman_font_name != oldrc.roman_font_name
684 || rc.sans_font_name != oldrc.sans_font_name
685 || rc.typewriter_font_name != oldrc.typewriter_font_name
686 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
687 // The global QPixmapCache is used in GuiPainter to cache text
688 // painting so we must reset it in case any of the above
689 // parameter is changed.
690 QPixmapCache::clear();
691 guiApp->fontLoader().update();
692 form_->updateScreenFonts();
697 void PrefScreenFonts::update(LyXRC const & rc)
699 setComboxFont(screenRomanCO, rc.roman_font_name,
700 rc.roman_font_foundry);
701 setComboxFont(screenSansCO, rc.sans_font_name,
702 rc.sans_font_foundry);
703 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
704 rc.typewriter_font_foundry);
706 select_roman(screenRomanCO->currentText());
707 select_sans(screenSansCO->currentText());
708 select_typewriter(screenTypewriterCO->currentText());
710 screenZoomSB->setValue(rc.zoom);
711 screenDpiSB->setValue(rc.dpi);
712 screenTinyED->setText(toqstr(rc.font_sizes[FONT_SIZE_TINY]));
713 screenSmallestED->setText(toqstr(rc.font_sizes[FONT_SIZE_SCRIPT]));
714 screenSmallerED->setText(toqstr(rc.font_sizes[FONT_SIZE_FOOTNOTE]));
715 screenSmallED->setText(toqstr(rc.font_sizes[FONT_SIZE_SMALL]));
716 screenNormalED->setText(toqstr(rc.font_sizes[FONT_SIZE_NORMAL]));
717 screenLargeED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGE]));
718 screenLargerED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGER]));
719 screenLargestED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGEST]));
720 screenHugeED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGE]));
721 screenHugerED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGER]));
723 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
724 #if defined(Q_WS_X11)
725 pixmapCacheCB->setEnabled(false);
731 void PrefScreenFonts::select_roman(const QString & name)
733 screenRomanFE->set(QFont(name), name);
737 void PrefScreenFonts::select_sans(const QString & name)
739 screenSansFE->set(QFont(name), name);
743 void PrefScreenFonts::select_typewriter(const QString & name)
745 screenTypewriterFE->set(QFont(name), name);
749 /////////////////////////////////////////////////////////////////////
753 /////////////////////////////////////////////////////////////////////
759 bool operator()(ColorCode lhs, ColorCode rhs) const {
760 return lcolor.getGUIName(lhs) < lcolor.getGUIName(rhs);
766 PrefColors::PrefColors(GuiPreferences * form)
767 : PrefModule(qt_(catLookAndFeel), qt_("Colors"), form)
771 // FIXME: all of this initialization should be put into the controller.
772 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
773 // for some discussion of why that is not trivial.
774 QPixmap icon(32, 32);
775 for (int i = 0; i < Color_ignore; ++i) {
776 ColorCode lc = static_cast<ColorCode>(i);
784 || lc == Color_magenta
785 || lc == Color_yellow
786 || lc == Color_inherit
787 || lc == Color_ignore) continue;
789 lcolors_.push_back(lc);
791 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
792 vector<ColorCode>::const_iterator cit = lcolors_.begin();
793 vector<ColorCode>::const_iterator const end = lcolors_.end();
794 for (; cit != end; ++cit) {
795 (void) new QListWidgetItem(QIcon(icon),
796 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
798 curcolors_.resize(lcolors_.size());
799 newcolors_.resize(lcolors_.size());
800 // End initialization
802 connect(colorChangePB, SIGNAL(clicked()),
803 this, SLOT(change_color()));
804 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
805 this, SLOT(change_lyxObjects_selection()));
806 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
807 this, SLOT(change_color()));
811 void PrefColors::apply(LyXRC & /*rc*/) const
813 for (unsigned int i = 0; i < lcolors_.size(); ++i)
814 if (curcolors_[i] != newcolors_[i])
815 form_->setColor(lcolors_[i], newcolors_[i]);
819 void PrefColors::update(LyXRC const & /*rc*/)
821 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
822 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
823 QPixmap coloritem(32, 32);
824 coloritem.fill(color);
825 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
826 newcolors_[i] = curcolors_[i] = color.name();
828 change_lyxObjects_selection();
832 void PrefColors::change_color()
834 int const row = lyxObjectsLW->currentRow();
840 QString const color = newcolors_[row];
841 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
843 if (c.isValid() && c.name() != color) {
844 newcolors_[row] = c.name();
845 QPixmap coloritem(32, 32);
847 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
853 void PrefColors::change_lyxObjects_selection()
855 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
859 /////////////////////////////////////////////////////////////////////
863 /////////////////////////////////////////////////////////////////////
865 PrefDisplay::PrefDisplay(GuiPreferences * form)
866 : PrefModule(qt_(catLookAndFeel), qt_("Graphics"), form)
869 connect(displayGraphicsCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
870 connect(instantPreviewCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
874 void PrefDisplay::apply(LyXRC & rc) const
876 switch (instantPreviewCO->currentIndex()) {
877 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
878 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
879 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
882 rc.display_graphics = displayGraphicsCB->isChecked();
884 // FIXME!! The graphics cache no longer has a changeDisplay method.
886 if (old_value != rc.display_graphics) {
887 graphics::GCache & gc = graphics::GCache::get();
894 void PrefDisplay::update(LyXRC const & rc)
896 switch (rc.preview) {
897 case LyXRC::PREVIEW_OFF:
898 instantPreviewCO->setCurrentIndex(0);
900 case LyXRC::PREVIEW_NO_MATH :
901 instantPreviewCO->setCurrentIndex(1);
903 case LyXRC::PREVIEW_ON :
904 instantPreviewCO->setCurrentIndex(2);
908 displayGraphicsCB->setChecked(rc.display_graphics);
909 instantPreviewCO->setEnabled(rc.display_graphics);
913 /////////////////////////////////////////////////////////////////////
917 /////////////////////////////////////////////////////////////////////
919 PrefPaths::PrefPaths(GuiPreferences * form)
920 : PrefModule(QString(), qt_("Paths"), form)
923 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(select_exampledir()));
924 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
925 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
926 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
927 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
928 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
929 connect(workingDirED, SIGNAL(textChanged(QString)),
930 this, SIGNAL(changed()));
931 connect(exampleDirED, SIGNAL(textChanged(QString)),
932 this, SIGNAL(changed()));
933 connect(templateDirED, SIGNAL(textChanged(QString)),
934 this, SIGNAL(changed()));
935 connect(backupDirED, SIGNAL(textChanged(QString)),
936 this, SIGNAL(changed()));
937 connect(tempDirED, SIGNAL(textChanged(QString)),
938 this, SIGNAL(changed()));
939 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
940 this, SIGNAL(changed()));
941 connect(pathPrefixED, SIGNAL(textChanged(QString)),
942 this, SIGNAL(changed()));
946 void PrefPaths::apply(LyXRC & rc) const
948 rc.document_path = internal_path(fromqstr(workingDirED->text()));
949 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
950 rc.template_path = internal_path(fromqstr(templateDirED->text()));
951 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
952 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
953 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
954 // FIXME: should be a checkbox only
955 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
959 void PrefPaths::update(LyXRC const & rc)
961 workingDirED->setText(toqstr(external_path(rc.document_path)));
962 exampleDirED->setText(toqstr(external_path(rc.example_path)));
963 templateDirED->setText(toqstr(external_path(rc.template_path)));
964 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
965 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
966 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
967 // FIXME: should be a checkbox only
968 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
972 void PrefPaths::select_exampledir()
974 QString file = browseDir(internalPath(exampleDirED->text()),
975 qt_("Select directory for example files"));
977 exampleDirED->setText(file);
981 void PrefPaths::select_templatedir()
983 QString file = browseDir(internalPath(templateDirED->text()),
984 qt_("Select a document templates directory"));
986 templateDirED->setText(file);
990 void PrefPaths::select_tempdir()
992 QString file = browseDir(internalPath(tempDirED->text()),
993 qt_("Select a temporary directory"));
995 tempDirED->setText(file);
999 void PrefPaths::select_backupdir()
1001 QString file = browseDir(internalPath(backupDirED->text()),
1002 qt_("Select a backups directory"));
1003 if (!file.isEmpty())
1004 backupDirED->setText(file);
1008 void PrefPaths::select_workingdir()
1010 QString file = browseDir(internalPath(workingDirED->text()),
1011 qt_("Select a document directory"));
1012 if (!file.isEmpty())
1013 workingDirED->setText(file);
1017 void PrefPaths::select_lyxpipe()
1019 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1020 qt_("Give a filename for the LyX server pipe"));
1021 if (!file.isEmpty())
1022 lyxserverDirED->setText(file);
1026 /////////////////////////////////////////////////////////////////////
1030 /////////////////////////////////////////////////////////////////////
1032 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form)
1033 : PrefModule(qt_(catLanguage), qt_("Spellchecker"), form)
1037 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
1039 connect(altLanguageED, SIGNAL(textChanged(QString)),
1040 this, SIGNAL(changed()));
1041 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1042 this, SIGNAL(changed()));
1043 connect(persDictionaryED, SIGNAL(textChanged(QString)),
1044 this, SIGNAL(changed()));
1045 connect(compoundWordCB, SIGNAL(clicked()),
1046 this, SIGNAL(changed()));
1047 connect(inputEncodingCB, SIGNAL(clicked()),
1048 this, SIGNAL(changed()));
1052 void PrefSpellchecker::apply(LyXRC & rc) const
1054 // FIXME: remove spellchecker_use_alt_lang
1055 rc.spellchecker_alt_lang = fromqstr(altLanguageED->text());
1056 rc.spellchecker_use_alt_lang = !rc.spellchecker_alt_lang.empty();
1057 // FIXME: remove spellchecker_use_esc_chars
1058 rc.spellchecker_esc_chars = fromqstr(escapeCharactersED->text());
1059 rc.spellchecker_use_esc_chars = !rc.spellchecker_esc_chars.empty();
1060 // FIXME: remove spellchecker_use_pers_dict
1061 rc.spellchecker_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
1062 rc.spellchecker_use_pers_dict = !rc.spellchecker_pers_dict.empty();
1063 rc.spellchecker_accept_compound = compoundWordCB->isChecked();
1064 rc.spellchecker_use_input_encoding = inputEncodingCB->isChecked();
1068 void PrefSpellchecker::update(LyXRC const & rc)
1070 // FIXME: remove spellchecker_use_alt_lang
1071 altLanguageED->setText(toqstr(rc.spellchecker_alt_lang));
1072 // FIXME: remove spellchecker_use_esc_chars
1073 escapeCharactersED->setText(toqstr(rc.spellchecker_esc_chars));
1074 // FIXME: remove spellchecker_use_pers_dict
1075 persDictionaryED->setText(toqstr(external_path(rc.spellchecker_pers_dict)));
1076 compoundWordCB->setChecked(rc.spellchecker_accept_compound);
1077 inputEncodingCB->setChecked(rc.spellchecker_use_input_encoding);
1081 void PrefSpellchecker::select_dict()
1083 QString file = form_->browsedict(internalPath(persDictionaryED->text()));
1084 if (!file.isEmpty())
1085 persDictionaryED->setText(file);
1090 /////////////////////////////////////////////////////////////////////
1094 /////////////////////////////////////////////////////////////////////
1097 PrefConverters::PrefConverters(GuiPreferences * form)
1098 : PrefModule(qt_(catFiles), qt_("Converters"), form)
1102 connect(converterNewPB, SIGNAL(clicked()),
1103 this, SLOT(update_converter()));
1104 connect(converterRemovePB, SIGNAL(clicked()),
1105 this, SLOT(remove_converter()));
1106 connect(converterModifyPB, SIGNAL(clicked()),
1107 this, SLOT(update_converter()));
1108 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1109 this, SLOT(switch_converter()));
1110 connect(converterFromCO, SIGNAL(activated(QString)),
1111 this, SLOT(converter_changed()));
1112 connect(converterToCO, SIGNAL(activated(QString)),
1113 this, SLOT(converter_changed()));
1114 connect(converterED, SIGNAL(textEdited(QString)),
1115 this, SLOT(converter_changed()));
1116 connect(converterFlagED, SIGNAL(textEdited(QString)),
1117 this, SLOT(converter_changed()));
1118 connect(converterNewPB, SIGNAL(clicked()),
1119 this, SIGNAL(changed()));
1120 connect(converterRemovePB, SIGNAL(clicked()),
1121 this, SIGNAL(changed()));
1122 connect(converterModifyPB, SIGNAL(clicked()),
1123 this, SIGNAL(changed()));
1124 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1125 this, SIGNAL(changed()));
1127 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1128 //converterDefGB->setFocusProxy(convertersLW);
1132 void PrefConverters::apply(LyXRC & rc) const
1134 rc.use_converter_cache = cacheCB->isChecked();
1135 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
1139 void PrefConverters::update(LyXRC const & rc)
1141 cacheCB->setChecked(rc.use_converter_cache);
1143 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
1144 maxAgeLE->setText(max_age);
1149 void PrefConverters::updateGui()
1151 form_->formats().sort();
1152 form_->converters().update(form_->formats());
1153 // save current selection
1154 QString current = converterFromCO->currentText()
1155 + " -> " + converterToCO->currentText();
1157 converterFromCO->clear();
1158 converterToCO->clear();
1160 Formats::const_iterator cit = form_->formats().begin();
1161 Formats::const_iterator end = form_->formats().end();
1162 for (; cit != end; ++cit) {
1163 converterFromCO->addItem(qt_(cit->prettyname()));
1164 converterToCO->addItem(qt_(cit->prettyname()));
1167 // currentRowChanged(int) is also triggered when updating the listwidget
1168 // block signals to avoid unnecessary calls to switch_converter()
1169 convertersLW->blockSignals(true);
1170 convertersLW->clear();
1172 Converters::const_iterator ccit = form_->converters().begin();
1173 Converters::const_iterator cend = form_->converters().end();
1174 for (; ccit != cend; ++ccit) {
1175 QString const name =
1176 qt_(ccit->From->prettyname()) + " -> " + qt_(ccit->To->prettyname());
1177 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1178 new QListWidgetItem(name, convertersLW, type);
1180 convertersLW->sortItems(Qt::AscendingOrder);
1181 convertersLW->blockSignals(false);
1183 // restore selection
1184 if (!current.isEmpty()) {
1185 QList<QListWidgetItem *> const item =
1186 convertersLW->findItems(current, Qt::MatchExactly);
1187 if (!item.isEmpty())
1188 convertersLW->setCurrentItem(item.at(0));
1191 // select first element if restoring failed
1192 if (convertersLW->currentRow() == -1)
1193 convertersLW->setCurrentRow(0);
1199 void PrefConverters::switch_converter()
1201 int const cnr = convertersLW->currentItem()->type();
1202 Converter const & c(form_->converters().get(cnr));
1203 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1204 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1205 converterED->setText(toqstr(c.command));
1206 converterFlagED->setText(toqstr(c.flags));
1212 void PrefConverters::converter_changed()
1218 void PrefConverters::updateButtons()
1220 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1221 Format const & to = form_->formats().get(converterToCO->currentIndex());
1222 int const sel = form_->converters().getNumber(from.name(), to.name());
1223 bool const known = sel >= 0;
1224 bool const valid = !(converterED->text().isEmpty()
1225 || from.name() == to.name());
1227 int const cnr = convertersLW->currentItem()->type();
1228 Converter const & c = form_->converters().get(cnr);
1229 string const old_command = c.command;
1230 string const old_flag = c.flags;
1231 string const new_command = fromqstr(converterED->text());
1232 string const new_flag = fromqstr(converterFlagED->text());
1234 bool modified = (old_command != new_command || old_flag != new_flag);
1236 converterModifyPB->setEnabled(valid && known && modified);
1237 converterNewPB->setEnabled(valid && !known);
1238 converterRemovePB->setEnabled(known);
1240 maxAgeLE->setEnabled(cacheCB->isChecked());
1241 maxAgeLA->setEnabled(cacheCB->isChecked());
1246 // specify unique from/to or it doesn't appear. This is really bad UI
1247 // this is why we can use the same function for both new and modify
1248 void PrefConverters::update_converter()
1250 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1251 Format const & to = form_->formats().get(converterToCO->currentIndex());
1252 string const flags = fromqstr(converterFlagED->text());
1253 string const command = fromqstr(converterED->text());
1255 Converter const * old =
1256 form_->converters().getConverter(from.name(), to.name());
1257 form_->converters().add(from.name(), to.name(), command, flags);
1260 form_->converters().updateLast(form_->formats());
1264 // Remove all files created by this converter from the cache, since
1265 // the modified converter might create different files.
1266 ConverterCache::get().remove_all(from.name(), to.name());
1270 void PrefConverters::remove_converter()
1272 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1273 Format const & to = form_->formats().get(converterToCO->currentIndex());
1274 form_->converters().erase(from.name(), to.name());
1278 // Remove all files created by this converter from the cache, since
1279 // a possible new converter might create different files.
1280 ConverterCache::get().remove_all(from.name(), to.name());
1284 void PrefConverters::on_cacheCB_stateChanged(int state)
1286 maxAgeLE->setEnabled(state == Qt::Checked);
1287 maxAgeLA->setEnabled(state == Qt::Checked);
1292 /////////////////////////////////////////////////////////////////////
1296 /////////////////////////////////////////////////////////////////////
1298 class FormatValidator : public QValidator
1301 FormatValidator(QWidget *, Formats const & f);
1302 void fixup(QString & input) const;
1303 QValidator::State validate(QString & input, int & pos) const;
1305 virtual QString toString(Format const & format) const = 0;
1307 Formats const & formats_;
1311 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1312 : QValidator(parent), formats_(f)
1317 void FormatValidator::fixup(QString & input) const
1319 Formats::const_iterator cit = formats_.begin();
1320 Formats::const_iterator end = formats_.end();
1321 for (; cit != end; ++cit) {
1322 QString const name = toString(*cit);
1323 if (distance(formats_.begin(), cit) == nr()) {
1331 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1333 Formats::const_iterator cit = formats_.begin();
1334 Formats::const_iterator end = formats_.end();
1335 bool unknown = true;
1336 for (; unknown && cit != end; ++cit) {
1337 QString const name = toString(*cit);
1338 if (distance(formats_.begin(), cit) != nr())
1339 unknown = name != input;
1342 if (unknown && !input.isEmpty())
1343 return QValidator::Acceptable;
1345 return QValidator::Intermediate;
1349 int FormatValidator::nr() const
1351 QComboBox * p = qobject_cast<QComboBox *>(parent());
1352 return p->itemData(p->currentIndex()).toInt();
1356 /////////////////////////////////////////////////////////////////////
1358 // FormatNameValidator
1360 /////////////////////////////////////////////////////////////////////
1362 class FormatNameValidator : public FormatValidator
1365 FormatNameValidator(QWidget * parent, Formats const & f)
1366 : FormatValidator(parent, f)
1369 QString toString(Format const & format) const
1371 return toqstr(format.name());
1376 /////////////////////////////////////////////////////////////////////
1378 // FormatPrettynameValidator
1380 /////////////////////////////////////////////////////////////////////
1382 class FormatPrettynameValidator : public FormatValidator
1385 FormatPrettynameValidator(QWidget * parent, Formats const & f)
1386 : FormatValidator(parent, f)
1389 QString toString(Format const & format) const
1391 return qt_(format.prettyname());
1396 /////////////////////////////////////////////////////////////////////
1400 /////////////////////////////////////////////////////////////////////
1402 PrefFileformats::PrefFileformats(GuiPreferences * form)
1403 : PrefModule(qt_(catFiles), qt_("File formats"), form)
1406 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1407 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1409 connect(documentCB, SIGNAL(clicked()),
1410 this, SLOT(setFlags()));
1411 connect(vectorCB, SIGNAL(clicked()),
1412 this, SLOT(setFlags()));
1413 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1414 this, SLOT(updatePrettyname()));
1415 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1416 this, SIGNAL(changed()));
1422 string const l10n_shortcut(string const prettyname, string const shortcut)
1424 if (shortcut.empty())
1427 string l10n_format =
1428 to_utf8(_(prettyname + '|' + shortcut));
1429 return split(l10n_format, '|');
1432 }; // namespace anon
1435 void PrefFileformats::apply(LyXRC & /*rc*/) const
1440 void PrefFileformats::update(LyXRC const & /*rc*/)
1446 void PrefFileformats::updateView()
1448 QString const current = formatsCB->currentText();
1450 // update combobox with formats
1451 formatsCB->blockSignals(true);
1453 form_->formats().sort();
1454 Formats::const_iterator cit = form_->formats().begin();
1455 Formats::const_iterator end = form_->formats().end();
1456 for (; cit != end; ++cit)
1457 formatsCB->addItem(qt_(cit->prettyname()),
1458 QVariant(form_->formats().getNumber(cit->name())));
1460 // restore selection
1461 int const item = formatsCB->findText(current, Qt::MatchExactly);
1462 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1463 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1464 formatsCB->blockSignals(false);
1468 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1470 int const nr = formatsCB->itemData(i).toInt();
1471 Format const f = form_->formats().get(nr);
1473 formatED->setText(toqstr(f.name()));
1474 copierED->setText(toqstr(form_->movers().command(f.name())));
1475 extensionED->setText(toqstr(f.extension()));
1476 shortcutED->setText(
1477 toqstr(l10n_shortcut(f.prettyname(), f.shortcut())));
1478 viewerED->setText(toqstr(f.viewer()));
1479 editorED->setText(toqstr(f.editor()));
1480 documentCB->setChecked((f.documentFormat()));
1481 vectorCB->setChecked((f.vectorFormat()));
1485 void PrefFileformats::setFlags()
1487 int flags = Format::none;
1488 if (documentCB->isChecked())
1489 flags |= Format::document;
1490 if (vectorCB->isChecked())
1491 flags |= Format::vector;
1492 currentFormat().setFlags(flags);
1497 void PrefFileformats::on_copierED_textEdited(const QString & s)
1499 string const fmt = fromqstr(formatED->text());
1500 form_->movers().set(fmt, fromqstr(s));
1505 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1507 currentFormat().setExtension(fromqstr(s));
1511 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1513 currentFormat().setViewer(fromqstr(s));
1518 void PrefFileformats::on_editorED_textEdited(const QString & s)
1520 currentFormat().setEditor(fromqstr(s));
1525 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1527 string const new_shortcut = fromqstr(s);
1528 if (new_shortcut == l10n_shortcut(currentFormat().prettyname(),
1529 currentFormat().shortcut()))
1531 currentFormat().setShortcut(new_shortcut);
1536 void PrefFileformats::on_formatED_editingFinished()
1538 string const newname = fromqstr(formatED->displayText());
1539 if (newname == currentFormat().name())
1542 currentFormat().setName(newname);
1547 void PrefFileformats::on_formatED_textChanged(const QString &)
1549 QString t = formatED->text();
1551 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1552 setValid(formatLA, valid);
1556 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1558 QString t = formatsCB->currentText();
1560 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1561 setValid(formatsLA, valid);
1565 void PrefFileformats::updatePrettyname()
1567 QString const newname = formatsCB->currentText();
1568 if (newname == qt_(currentFormat().prettyname()))
1571 currentFormat().setPrettyname(fromqstr(newname));
1578 Format & PrefFileformats::currentFormat()
1580 int const i = formatsCB->currentIndex();
1581 int const nr = formatsCB->itemData(i).toInt();
1582 return form_->formats().get(nr);
1586 void PrefFileformats::on_formatNewPB_clicked()
1588 form_->formats().add("", "", "", "", "", "", Format::none);
1590 formatsCB->setCurrentIndex(0);
1591 formatsCB->setFocus(Qt::OtherFocusReason);
1595 void PrefFileformats::on_formatRemovePB_clicked()
1597 int const i = formatsCB->currentIndex();
1598 int const nr = formatsCB->itemData(i).toInt();
1599 string const current_text = form_->formats().get(nr).name();
1600 if (form_->converters().formatIsUsed(current_text)) {
1601 Alert::error(_("Format in use"),
1602 _("Cannot remove a Format used by a Converter. "
1603 "Remove the converter first."));
1607 form_->formats().erase(current_text);
1610 on_formatsCB_editTextChanged(formatsCB->currentText());
1615 /////////////////////////////////////////////////////////////////////
1619 /////////////////////////////////////////////////////////////////////
1621 PrefLanguage::PrefLanguage(GuiPreferences * form)
1622 : PrefModule(qt_(catLanguage), qt_("Language"), form)
1626 connect(rtlGB, SIGNAL(clicked()),
1627 this, SIGNAL(changed()));
1628 connect(visualCursorRB, SIGNAL(clicked()),
1629 this, SIGNAL(changed()));
1630 connect(logicalCursorRB, SIGNAL(clicked()),
1631 this, SIGNAL(changed()));
1632 connect(markForeignCB, SIGNAL(clicked()),
1633 this, SIGNAL(changed()));
1634 connect(autoBeginCB, SIGNAL(clicked()),
1635 this, SIGNAL(changed()));
1636 connect(autoEndCB, SIGNAL(clicked()),
1637 this, SIGNAL(changed()));
1638 connect(useBabelCB, SIGNAL(clicked()),
1639 this, SIGNAL(changed()));
1640 connect(globalCB, SIGNAL(clicked()),
1641 this, SIGNAL(changed()));
1642 connect(languagePackageED, SIGNAL(textChanged(QString)),
1643 this, SIGNAL(changed()));
1644 connect(startCommandED, SIGNAL(textChanged(QString)),
1645 this, SIGNAL(changed()));
1646 connect(endCommandED, SIGNAL(textChanged(QString)),
1647 this, SIGNAL(changed()));
1648 connect(defaultLanguageCO, SIGNAL(activated(int)),
1649 this, SIGNAL(changed()));
1650 connect(uiLanguageCO, SIGNAL(activated(int)),
1651 this, SIGNAL(changed()));
1653 defaultLanguageCO->clear();
1654 uiLanguageCO->clear();
1656 QAbstractItemModel * language_model = guiApp->languageModel();
1657 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1658 language_model->sort(0);
1659 defaultLanguageCO->setModel(language_model);
1661 // FIXME: This is wrong, we need filter this list based on the available
1663 uiLanguageCO->blockSignals(true);
1664 uiLanguageCO->addItem(qt_("Default"), toqstr("auto"));
1665 for (int i = 0; i != language_model->rowCount(); ++i) {
1666 QModelIndex index = language_model->index(i, 0);
1667 uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
1668 index.data(Qt::UserRole).toString());
1670 uiLanguageCO->blockSignals(false);
1674 void PrefLanguage::on_uiLanguageCO_currentIndexChanged(int)
1676 QMessageBox::information(this, qt_("LyX needs to be restarted!"),
1677 qt_("The change of user interface language will be fully "
1678 "effective only after a restart."));
1682 void PrefLanguage::apply(LyXRC & rc) const
1684 // FIXME: remove rtl_support bool
1685 rc.rtl_support = rtlGB->isChecked();
1686 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
1687 rc.mark_foreign_language = markForeignCB->isChecked();
1688 rc.language_auto_begin = autoBeginCB->isChecked();
1689 rc.language_auto_end = autoEndCB->isChecked();
1690 rc.language_use_babel = useBabelCB->isChecked();
1691 rc.language_global_options = globalCB->isChecked();
1692 rc.language_package = fromqstr(languagePackageED->text());
1693 rc.language_command_begin = fromqstr(startCommandED->text());
1694 rc.language_command_end = fromqstr(endCommandED->text());
1695 rc.default_language = fromqstr(
1696 defaultLanguageCO->itemData(defaultLanguageCO->currentIndex()).toString());
1697 rc.gui_language = fromqstr(
1698 uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString());
1702 void PrefLanguage::update(LyXRC const & rc)
1704 // FIXME: remove rtl_support bool
1705 rtlGB->setChecked(rc.rtl_support);
1706 if (rc.visual_cursor)
1707 visualCursorRB->setChecked(true);
1709 logicalCursorRB->setChecked(true);
1710 markForeignCB->setChecked(rc.mark_foreign_language);
1711 autoBeginCB->setChecked(rc.language_auto_begin);
1712 autoEndCB->setChecked(rc.language_auto_end);
1713 useBabelCB->setChecked(rc.language_use_babel);
1714 globalCB->setChecked(rc.language_global_options);
1715 languagePackageED->setText(toqstr(rc.language_package));
1716 startCommandED->setText(toqstr(rc.language_command_begin));
1717 endCommandED->setText(toqstr(rc.language_command_end));
1719 int pos = defaultLanguageCO->findData(toqstr(rc.default_language));
1720 defaultLanguageCO->setCurrentIndex(pos);
1721 pos = uiLanguageCO->findData(toqstr(rc.gui_language));
1722 uiLanguageCO->blockSignals(true);
1723 uiLanguageCO->setCurrentIndex(pos);
1724 uiLanguageCO->blockSignals(false);
1728 /////////////////////////////////////////////////////////////////////
1732 /////////////////////////////////////////////////////////////////////
1734 PrefPrinter::PrefPrinter(GuiPreferences * form)
1735 : PrefModule(qt_(catOutput), qt_("Printer"), form)
1739 connect(printerAdaptCB, SIGNAL(clicked()),
1740 this, SIGNAL(changed()));
1741 connect(printerCommandED, SIGNAL(textChanged(QString)),
1742 this, SIGNAL(changed()));
1743 connect(printerNameED, SIGNAL(textChanged(QString)),
1744 this, SIGNAL(changed()));
1745 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
1746 this, SIGNAL(changed()));
1747 connect(printerCopiesED, SIGNAL(textChanged(QString)),
1748 this, SIGNAL(changed()));
1749 connect(printerReverseED, SIGNAL(textChanged(QString)),
1750 this, SIGNAL(changed()));
1751 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
1752 this, SIGNAL(changed()));
1753 connect(printerExtensionED, SIGNAL(textChanged(QString)),
1754 this, SIGNAL(changed()));
1755 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
1756 this, SIGNAL(changed()));
1757 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
1758 this, SIGNAL(changed()));
1759 connect(printerEvenED, SIGNAL(textChanged(QString)),
1760 this, SIGNAL(changed()));
1761 connect(printerOddED, SIGNAL(textChanged(QString)),
1762 this, SIGNAL(changed()));
1763 connect(printerCollatedED, SIGNAL(textChanged(QString)),
1764 this, SIGNAL(changed()));
1765 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
1766 this, SIGNAL(changed()));
1767 connect(printerToFileED, SIGNAL(textChanged(QString)),
1768 this, SIGNAL(changed()));
1769 connect(printerExtraED, SIGNAL(textChanged(QString)),
1770 this, SIGNAL(changed()));
1771 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
1772 this, SIGNAL(changed()));
1773 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
1774 this, SIGNAL(changed()));
1778 void PrefPrinter::apply(LyXRC & rc) const
1780 rc.print_adapt_output = printerAdaptCB->isChecked();
1781 rc.print_command = fromqstr(printerCommandED->text());
1782 rc.printer = fromqstr(printerNameED->text());
1784 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1785 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1786 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1787 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1788 rc.print_file_extension = fromqstr(printerExtensionED->text());
1789 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1790 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1791 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1792 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1793 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1794 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1795 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1796 rc.print_extra_options = fromqstr(printerExtraED->text());
1797 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1798 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1802 void PrefPrinter::update(LyXRC const & rc)
1804 printerAdaptCB->setChecked(rc.print_adapt_output);
1805 printerCommandED->setText(toqstr(rc.print_command));
1806 printerNameED->setText(toqstr(rc.printer));
1808 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1809 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1810 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1811 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1812 printerExtensionED->setText(toqstr(rc.print_file_extension));
1813 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1814 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1815 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1816 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1817 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1818 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1819 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1820 printerExtraED->setText(toqstr(rc.print_extra_options));
1821 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1822 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1826 /////////////////////////////////////////////////////////////////////
1828 // PrefUserInterface
1830 /////////////////////////////////////////////////////////////////////
1832 PrefUserInterface::PrefUserInterface(GuiPreferences * form)
1833 : PrefModule(qt_(catLookAndFeel), qt_("User interface"), form)
1837 connect(autoSaveCB, SIGNAL(toggled(bool)),
1838 autoSaveSB, SLOT(setEnabled(bool)));
1839 connect(autoSaveCB, SIGNAL(toggled(bool)),
1840 TextLabel1, SLOT(setEnabled(bool)));
1841 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
1842 this, SIGNAL(changed()));
1843 connect(uiFilePB, SIGNAL(clicked()),
1844 this, SLOT(select_ui()));
1845 connect(uiFileED, SIGNAL(textChanged(QString)),
1846 this, SIGNAL(changed()));
1847 connect(restoreCursorCB, SIGNAL(clicked()),
1848 this, SIGNAL(changed()));
1849 connect(loadSessionCB, SIGNAL(clicked()),
1850 this, SIGNAL(changed()));
1851 connect(allowGeometrySessionCB, SIGNAL(clicked()),
1852 this, SIGNAL(changed()));
1853 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1854 this, SIGNAL(changed()));
1855 connect(autoSaveCB, SIGNAL(clicked()),
1856 this, SIGNAL(changed()));
1857 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1858 this, SIGNAL(changed()));
1859 connect(tooltipCB, SIGNAL(toggled(bool)),
1860 this, SIGNAL(changed()));
1861 lastfilesSB->setMaximum(maxlastfiles);
1865 void PrefUserInterface::apply(LyXRC & rc) const
1867 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1868 rc.use_lastfilepos = restoreCursorCB->isChecked();
1869 rc.load_session = loadSessionCB->isChecked();
1870 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
1871 rc.autosave = autoSaveSB->value() * 60;
1872 rc.make_backup = autoSaveCB->isChecked();
1873 rc.num_lastfiles = lastfilesSB->value();
1874 rc.use_tooltip = tooltipCB->isChecked();
1875 rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
1879 void PrefUserInterface::update(LyXRC const & rc)
1881 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1882 restoreCursorCB->setChecked(rc.use_lastfilepos);
1883 loadSessionCB->setChecked(rc.load_session);
1884 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
1885 // convert to minutes
1886 int mins(rc.autosave / 60);
1887 if (rc.autosave && !mins)
1889 autoSaveSB->setValue(mins);
1890 autoSaveCB->setChecked(rc.make_backup);
1891 lastfilesSB->setValue(rc.num_lastfiles);
1892 tooltipCB->setChecked(rc.use_tooltip);
1893 openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
1897 void PrefUserInterface::select_ui()
1899 QString file = form_->browseUI(internalPath(uiFileED->text()));
1900 if (!file.isEmpty())
1901 uiFileED->setText(file);
1905 void PrefUserInterface::on_clearSessionPB_clicked()
1907 guiApp->clearSession();
1912 /////////////////////////////////////////////////////////////////////
1916 /////////////////////////////////////////////////////////////////////
1918 PrefEdit::PrefEdit(GuiPreferences * form)
1919 : PrefModule(qt_(catEditing), qt_("Control"), form)
1923 connect(cursorFollowsCB, SIGNAL(clicked()),
1924 this, SIGNAL(changed()));
1925 connect(sortEnvironmentsCB, SIGNAL(clicked()),
1926 this, SIGNAL(changed()));
1927 connect(groupEnvironmentsCB, SIGNAL(clicked()),
1928 this, SIGNAL(changed()));
1929 connect(macroEditStyleCO, SIGNAL(activated(int)),
1930 this, SIGNAL(changed()));
1931 connect(fullscreenLimitGB, SIGNAL(clicked()),
1932 this, SIGNAL(changed()));
1933 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
1934 this, SIGNAL(changed()));
1935 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
1936 this, SIGNAL(changed()));
1937 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
1938 this, SIGNAL(changed()));
1939 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
1940 this, SIGNAL(changed()));
1944 void PrefEdit::apply(LyXRC & rc) const
1946 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1947 rc.sort_layouts = sortEnvironmentsCB->isChecked();
1948 rc.group_layouts = groupEnvironmentsCB->isChecked();
1949 switch (macroEditStyleCO->currentIndex()) {
1950 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
1951 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
1952 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
1954 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
1955 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
1956 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
1957 rc.full_screen_width = fullscreenWidthSB->value();
1958 rc.full_screen_limit = fullscreenLimitGB->isChecked();
1962 void PrefEdit::update(LyXRC const & rc)
1964 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1965 sortEnvironmentsCB->setChecked(rc.sort_layouts);
1966 groupEnvironmentsCB->setChecked(rc.group_layouts);
1967 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
1968 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
1969 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
1970 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
1971 fullscreenWidthSB->setValue(rc.full_screen_width);
1972 fullscreenLimitGB->setChecked(rc.full_screen_limit);
1976 /////////////////////////////////////////////////////////////////////
1980 /////////////////////////////////////////////////////////////////////
1983 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
1985 Ui::shortcutUi::setupUi(this);
1986 QDialog::setModal(true);
1990 PrefShortcuts::PrefShortcuts(GuiPreferences * form)
1991 : PrefModule(qt_(catEditing), qt_("Shortcuts"), form)
1995 shortcutsTW->setColumnCount(2);
1996 shortcutsTW->headerItem()->setText(0, qt_("Function"));
1997 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
1998 shortcutsTW->setSortingEnabled(true);
1999 // Multi-selection can be annoying.
2000 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
2002 connect(bindFilePB, SIGNAL(clicked()),
2003 this, SLOT(select_bind()));
2004 connect(bindFileED, SIGNAL(textChanged(QString)),
2005 this, SIGNAL(changed()));
2006 connect(removePB, SIGNAL(clicked()),
2007 this, SIGNAL(changed()));
2009 shortcut_ = new GuiShortcutDialog(this);
2010 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
2011 shortcut_bc_.setOK(shortcut_->okPB);
2012 shortcut_bc_.setCancel(shortcut_->cancelPB);
2014 connect(shortcut_->okPB, SIGNAL(clicked()),
2015 shortcut_, SLOT(accept()));
2016 connect(shortcut_->okPB, SIGNAL(clicked()),
2017 this, SIGNAL(changed()));
2018 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2019 shortcut_, SLOT(reject()));
2020 connect(shortcut_->clearPB, SIGNAL(clicked()),
2021 this, SLOT(shortcut_clearPB_pressed()));
2022 connect(shortcut_->removePB, SIGNAL(clicked()),
2023 this, SLOT(shortcut_removePB_pressed()));
2024 connect(shortcut_->okPB, SIGNAL(clicked()),
2025 this, SLOT(shortcut_okPB_pressed()));
2026 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2027 this, SLOT(shortcut_cancelPB_pressed()));
2031 void PrefShortcuts::apply(LyXRC & rc) const
2033 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
2034 // write user_bind and user_unbind to .lyx/bind/user.bind
2035 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
2036 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
2037 lyxerr << "LyX could not create the user bind directory '"
2038 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2041 if (!bind_dir.isDirWritable()) {
2042 lyxerr << "LyX could not write to the user bind directory '"
2043 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2046 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
2047 user_bind_.write(user_bind_file.toFilesystemEncoding(), false, false);
2048 user_unbind_.write(user_bind_file.toFilesystemEncoding(), true, true);
2049 // immediately apply the keybindings. Why this is not done before?
2050 // The good thing is that the menus are updated automatically.
2051 theTopLevelKeymap().clear();
2052 theTopLevelKeymap().read("site");
2053 theTopLevelKeymap().read(rc.bind_file);
2054 theTopLevelKeymap().read("user");
2058 void PrefShortcuts::update(LyXRC const & rc)
2060 bindFileED->setText(toqstr(external_path(rc.bind_file)));
2062 system_bind_.clear();
2064 user_unbind_.clear();
2065 system_bind_.read("site");
2066 system_bind_.read(rc.bind_file);
2067 // \unbind in user.bind is added to user_unbind_
2068 user_bind_.read("user", &user_unbind_);
2069 updateShortcutsTW();
2073 void PrefShortcuts::updateShortcutsTW()
2075 shortcutsTW->clear();
2077 editItem_ = new QTreeWidgetItem(shortcutsTW);
2078 editItem_->setText(0, qt_("Cursor, Mouse and Editing functions"));
2079 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2081 mathItem_ = new QTreeWidgetItem(shortcutsTW);
2082 mathItem_->setText(0, qt_("Mathematical Symbols"));
2083 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2085 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2086 bufferItem_->setText(0, qt_("Document and Window"));
2087 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2089 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2090 layoutItem_->setText(0, qt_("Font, Layouts and Textclasses"));
2091 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2093 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2094 systemItem_->setText(0, qt_("System and Miscellaneous"));
2095 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2097 // listBindings(unbound=true) lists all bound and unbound lfuns
2098 // Items in this list is tagged by its source.
2099 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2101 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2103 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2104 KeyMap::UserUnbind);
2105 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2106 user_bindinglist.end());
2107 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2108 user_unbindinglist.end());
2110 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2111 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2112 for (; it != it_end; ++it)
2113 insertShortcutItem(it->request, it->sequence, KeyMap::ItemType(it->tag));
2115 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2116 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2117 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2118 modifyPB->setEnabled(!items.isEmpty());
2120 shortcutsTW->resizeColumnToContents(0);
2124 void PrefShortcuts::setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag)
2126 item->setData(0, Qt::UserRole, QVariant(tag));
2130 case KeyMap::System:
2132 case KeyMap::UserBind:
2135 case KeyMap::UserUnbind:
2136 font.setStrikeOut(true);
2138 // this item is not displayed now.
2139 case KeyMap::UserExtraUnbind:
2140 font.setStrikeOut(true);
2144 item->setFont(1, font);
2148 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2149 KeySequence const & seq, KeyMap::ItemType tag)
2151 FuncCode action = lfun.action;
2152 string const action_name = lyxaction.getActionName(action);
2153 QString const lfun_name = toqstr(from_utf8(action_name)
2154 + ' ' + lfun.argument());
2155 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2156 KeyMap::ItemType item_tag = tag;
2158 QTreeWidgetItem * newItem = 0;
2159 // for unbind items, try to find an existing item in the system bind list
2160 if (tag == KeyMap::UserUnbind) {
2161 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2162 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2163 for (int i = 0; i < items.size(); ++i) {
2164 if (items[i]->text(1) == shortcut)
2168 // if not found, this unbind item is KeyMap::UserExtraUnbind
2169 // Such an item is not displayed to avoid confusion (what is
2170 // unmatched removed?).
2172 item_tag = KeyMap::UserExtraUnbind;
2177 switch(lyxaction.getActionType(action)) {
2178 case LyXAction::Hidden:
2180 case LyXAction::Edit:
2181 newItem = new QTreeWidgetItem(editItem_);
2183 case LyXAction::Math:
2184 newItem = new QTreeWidgetItem(mathItem_);
2186 case LyXAction::Buffer:
2187 newItem = new QTreeWidgetItem(bufferItem_);
2189 case LyXAction::Layout:
2190 newItem = new QTreeWidgetItem(layoutItem_);
2192 case LyXAction::System:
2193 newItem = new QTreeWidgetItem(systemItem_);
2196 // this should not happen
2197 newItem = new QTreeWidgetItem(shortcutsTW);
2201 newItem->setText(0, lfun_name);
2202 newItem->setText(1, shortcut);
2203 // record BindFile representation to recover KeySequence when needed.
2204 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2205 setItemType(newItem, item_tag);
2210 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2212 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2213 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2214 modifyPB->setEnabled(!items.isEmpty());
2215 if (items.isEmpty())
2218 KeyMap::ItemType tag =
2219 static_cast<KeyMap::ItemType>(items[0]->data(0, Qt::UserRole).toInt());
2220 if (tag == KeyMap::UserUnbind)
2221 removePB->setText(qt_("Res&tore"));
2223 removePB->setText(qt_("Remo&ve"));
2227 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2233 void PrefShortcuts::modifyShortcut()
2235 QTreeWidgetItem * item = shortcutsTW->currentItem();
2236 if (item->flags() & Qt::ItemIsSelectable) {
2237 shortcut_->lfunLE->setText(item->text(0));
2238 save_lfun_ = item->text(0);
2239 shortcut_->shortcutWG->setText(item->text(1));
2241 seq.parse(fromqstr(item->data(1, Qt::UserRole).toString()));
2242 shortcut_->shortcutWG->setKeySequence(seq);
2243 shortcut_->shortcutWG->setFocus();
2249 void PrefShortcuts::removeShortcut()
2251 // it seems that only one item can be selected, but I am
2252 // removing all selected items anyway.
2253 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2254 for (int i = 0; i < items.size(); ++i) {
2255 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2256 string lfun = fromqstr(items[i]->text(0));
2257 FuncRequest func = lyxaction.lookupFunc(lfun);
2258 KeyMap::ItemType tag =
2259 static_cast<KeyMap::ItemType>(items[i]->data(0, Qt::UserRole).toInt());
2262 case KeyMap::System: {
2263 // for system bind, we do not touch the item
2264 // but add an user unbind item
2265 user_unbind_.bind(shortcut, func);
2266 setItemType(items[i], KeyMap::UserUnbind);
2267 removePB->setText(qt_("Res&tore"));
2270 case KeyMap::UserBind: {
2271 // for user_bind, we remove this bind
2272 QTreeWidgetItem * parent = items[i]->parent();
2273 int itemIdx = parent->indexOfChild(items[i]);
2274 parent->takeChild(itemIdx);
2276 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2278 shortcutsTW->scrollToItem(parent);
2279 user_bind_.unbind(shortcut, func);
2282 case KeyMap::UserUnbind: {
2283 // for user_unbind, we remove the unbind, and the item
2284 // become KeyMap::System again.
2285 user_unbind_.unbind(shortcut, func);
2286 setItemType(items[i], KeyMap::System);
2287 removePB->setText(qt_("Remo&ve"));
2290 case KeyMap::UserExtraUnbind: {
2291 // for user unbind that is not in system bind file,
2292 // remove this unbind file
2293 QTreeWidgetItem * parent = items[i]->parent();
2294 parent->takeChild(parent->indexOfChild(items[i]));
2295 user_unbind_.unbind(shortcut, func);
2302 void PrefShortcuts::select_bind()
2304 QString file = form_->browsebind(internalPath(bindFileED->text()));
2305 if (!file.isEmpty()) {
2306 bindFileED->setText(file);
2307 system_bind_ = KeyMap();
2308 system_bind_.read(fromqstr(file));
2309 updateShortcutsTW();
2314 void PrefShortcuts::on_modifyPB_pressed()
2320 void PrefShortcuts::on_newPB_pressed()
2322 shortcut_->lfunLE->clear();
2323 shortcut_->shortcutWG->reset();
2324 save_lfun_ = QString();
2329 void PrefShortcuts::on_removePB_pressed()
2335 void PrefShortcuts::on_searchLE_textEdited()
2337 if (searchLE->text().isEmpty()) {
2338 // show all hidden items
2339 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2341 shortcutsTW->setItemHidden(*it++, false);
2344 // search both columns
2345 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2346 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2347 matched += shortcutsTW->findItems(searchLE->text(),
2348 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2350 // hide everyone (to avoid searching in matched QList repeatedly
2351 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2353 shortcutsTW->setItemHidden(*it++, true);
2354 // show matched items
2355 for (int i = 0; i < matched.size(); ++i) {
2356 shortcutsTW->setItemHidden(matched[i], false);
2357 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2362 docstring makeCmdString(FuncRequest const & f)
2364 docstring actionStr = from_ascii(lyxaction.getActionName(f.action));
2365 if (!f.argument().empty())
2366 actionStr += " " + f.argument();
2371 void PrefShortcuts::shortcut_okPB_pressed()
2373 QString const new_lfun = shortcut_->lfunLE->text();
2374 FuncRequest func = lyxaction.lookupFunc(fromqstr(new_lfun));
2376 if (func.action == LFUN_UNKNOWN_ACTION) {
2377 Alert::error(_("Failed to create shortcut"),
2378 _("Unknown or invalid LyX function"));
2382 KeySequence k = shortcut_->shortcutWG->getKeySequence();
2383 if (k.length() == 0) {
2384 Alert::error(_("Failed to create shortcut"),
2385 _("Invalid or empty key sequence"));
2389 // check to see if there's been any change
2390 FuncRequest oldBinding = system_bind_.getBinding(k);
2391 if (oldBinding.action == LFUN_UNKNOWN_ACTION)
2392 oldBinding = user_bind_.getBinding(k);
2393 if (oldBinding == func) {
2394 docstring const actionStr = makeCmdString(func);
2395 Alert::error(_("Failed to create shortcut"),
2396 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s"),
2397 k.print(KeySequence::ForGui), actionStr));
2401 // make sure this key isn't already bound---and, if so, not unbound
2402 FuncCode const unbind = user_unbind_.getBinding(k).action;
2403 if (oldBinding.action != LFUN_UNKNOWN_ACTION && unbind == LFUN_UNKNOWN_ACTION)
2405 // FIXME Perhaps we should offer to over-write the old shortcut?
2406 // If so, we'll need to remove it from our list, etc.
2407 docstring const actionStr = makeCmdString(oldBinding);
2408 Alert::error(_("Failed to create shortcut"),
2409 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s\n"
2410 "You need to remove that binding before creating a new one."),
2411 k.print(KeySequence::ForGui), actionStr));
2415 if (!save_lfun_.isEmpty() && new_lfun == save_lfun_)
2416 // real modification of the lfun's shortcut,
2417 // so remove the previous one
2420 QTreeWidgetItem * item = insertShortcutItem(func, k, KeyMap::UserBind);
2422 user_bind_.bind(&k, func);
2423 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2424 shortcutsTW->setItemExpanded(item->parent(), true);
2425 shortcutsTW->scrollToItem(item);
2427 Alert::error(_("Failed to create shortcut"),
2428 _("Can not insert shortcut to the list"));
2434 void PrefShortcuts::shortcut_cancelPB_pressed()
2436 shortcut_->shortcutWG->reset();
2440 void PrefShortcuts::shortcut_clearPB_pressed()
2442 shortcut_->shortcutWG->reset();
2446 void PrefShortcuts::shortcut_removePB_pressed()
2448 shortcut_->shortcutWG->removeFromSequence();
2452 /////////////////////////////////////////////////////////////////////
2456 /////////////////////////////////////////////////////////////////////
2458 PrefIdentity::PrefIdentity(GuiPreferences * form)
2459 : PrefModule(QString(), qt_("Identity"), form)
2463 connect(nameED, SIGNAL(textChanged(QString)),
2464 this, SIGNAL(changed()));
2465 connect(emailED, SIGNAL(textChanged(QString)),
2466 this, SIGNAL(changed()));
2470 void PrefIdentity::apply(LyXRC & rc) const
2472 rc.user_name = fromqstr(nameED->text());
2473 rc.user_email = fromqstr(emailED->text());
2477 void PrefIdentity::update(LyXRC const & rc)
2479 nameED->setText(toqstr(rc.user_name));
2480 emailED->setText(toqstr(rc.user_email));
2485 /////////////////////////////////////////////////////////////////////
2489 /////////////////////////////////////////////////////////////////////
2491 GuiPreferences::GuiPreferences(GuiView & lv)
2492 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2496 QDialog::setModal(false);
2498 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2499 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2500 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2501 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2503 addModule(new PrefUserInterface(this));
2504 addModule(new PrefEdit(this));
2505 addModule(new PrefShortcuts(this));
2506 addModule(new PrefScreenFonts(this));
2507 addModule(new PrefColors(this));
2508 addModule(new PrefDisplay(this));
2509 addModule(new PrefInput(this));
2510 addModule(new PrefCompletion(this));
2512 addModule(new PrefPaths(this));
2514 addModule(new PrefIdentity(this));
2516 addModule(new PrefLanguage(this));
2517 addModule(new PrefSpellchecker(this));
2519 addModule(new PrefPrinter(this));
2520 addModule(new PrefDate(this));
2521 addModule(new PrefPlaintext(this));
2522 addModule(new PrefLatex(this));
2524 PrefConverters * converters = new PrefConverters(this);
2525 PrefFileformats * formats = new PrefFileformats(this);
2526 connect(formats, SIGNAL(formatsChanged()),
2527 converters, SLOT(updateGui()));
2528 addModule(converters);
2531 prefsPS->setCurrentPanel(qt_("User interface"));
2532 // FIXME: hack to work around resizing bug in Qt >= 4.2
2533 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2534 #if QT_VERSION >= 0x040200
2535 prefsPS->updateGeometry();
2538 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2540 bc().setApply(applyPB);
2541 bc().setCancel(closePB);
2542 bc().setRestore(restorePB);
2546 void GuiPreferences::addModule(PrefModule * module)
2548 LASSERT(module, return);
2549 if (module->category().isEmpty())
2550 prefsPS->addPanel(module, module->title());
2552 prefsPS->addPanel(module, module->title(), module->category());
2553 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2554 modules_.push_back(module);
2558 void GuiPreferences::change_adaptor()
2564 void GuiPreferences::apply(LyXRC & rc) const
2566 size_t end = modules_.size();
2567 for (size_t i = 0; i != end; ++i)
2568 modules_[i]->apply(rc);
2572 void GuiPreferences::updateRc(LyXRC const & rc)
2574 size_t const end = modules_.size();
2575 for (size_t i = 0; i != end; ++i)
2576 modules_[i]->update(rc);
2580 void GuiPreferences::applyView()
2585 bool GuiPreferences::initialiseParams(string const &)
2588 formats_ = lyx::formats;
2589 converters_ = theConverters();
2590 converters_.update(formats_);
2591 movers_ = theMovers();
2593 update_screen_font_ = false;
2600 void GuiPreferences::dispatchParams()
2603 rc_.write(ss, true);
2604 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
2605 // FIXME: these need lfuns
2607 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
2609 lyx::formats = formats_;
2611 theConverters() = converters_;
2612 theConverters().update(lyx::formats);
2613 theConverters().buildGraph();
2615 theMovers() = movers_;
2617 vector<string>::const_iterator it = colors_.begin();
2618 vector<string>::const_iterator const end = colors_.end();
2619 for (; it != end; ++it)
2620 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
2623 if (update_screen_font_) {
2624 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2625 update_screen_font_ = false;
2628 // The Save button has been pressed
2630 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
2634 void GuiPreferences::setColor(ColorCode col, QString const & hex)
2636 colors_.push_back(lcolor.getLyXName(col) + ' ' + fromqstr(hex));
2640 void GuiPreferences::updateScreenFonts()
2642 update_screen_font_ = true;
2646 QString GuiPreferences::browsebind(QString const & file) const
2648 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
2649 QStringList(qt_("LyX bind files (*.bind)")));
2653 QString GuiPreferences::browseUI(QString const & file) const
2655 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
2656 QStringList(qt_("LyX UI files (*.ui)")));
2660 QString GuiPreferences::browsekbmap(QString const & file) const
2662 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
2663 QStringList(qt_("LyX keyboard maps (*.kmap)")));
2667 QString GuiPreferences::browsedict(QString const & file) const
2669 return browseFile(file, qt_("Choose personal dictionary"),
2670 QStringList(qt_("*.pws")));
2674 QString GuiPreferences::browse(QString const & file,
2675 QString const & title) const
2677 return browseFile(file, title, QStringList(), true);
2681 // We support less paper sizes than the document dialog
2682 // Therefore this adjustment is needed.
2683 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
2687 return PAPER_DEFAULT;
2689 return PAPER_USLETTER;
2691 return PAPER_USLEGAL;
2693 return PAPER_USEXECUTIVE;
2703 // should not happen
2704 return PAPER_DEFAULT;
2709 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
2711 switch (papersize) {
2714 case PAPER_USLETTER:
2718 case PAPER_USEXECUTIVE:
2729 // should not happen
2735 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
2738 } // namespace frontend
2741 #include "moc_GuiPrefs.cpp"