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())
101 QString lastPath = ".";
102 if (!filename.isEmpty())
103 lastPath = onlyPath(filename);
105 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
106 dlg.setButton2(label1, dir1);
107 dlg.setButton2(label2, dir2);
109 FileDialog::Result result;
112 result = dlg.save(lastPath, filters, onlyFilename(filename));
114 result = dlg.open(lastPath, filters, onlyFilename(filename));
116 return result.second;
120 /** Wrapper around browseFile which tries to provide a filename
121 * relative to the user or system directory. The dir, name and ext
122 * parameters have the same meaning as in the
123 * support::LibFileSearch function.
125 QString browseLibFile(QString const & dir,
126 QString const & name,
128 QString const & title,
129 QStringList const & filters)
132 QString const label1 = qt_("System files|#S#s");
134 toqstr(addName(package().system_support().absFilename(), fromqstr(dir)));
136 QString const label2 = qt_("User files|#U#u");
138 toqstr(addName(package().user_support().absFilename(), fromqstr(dir)));
140 QString const result = browseFile(toqstr(
141 libFileSearch(dir, name, ext).absFilename()),
142 title, filters, false, dir1, dir2);
144 // remove the extension if it is the default one
146 if (getExtension(result) == ext)
147 noextresult = removeExtension(result);
149 noextresult = result;
151 // remove the directory, if it is the default one
152 QString const file = onlyFilename(noextresult);
153 if (toqstr(libFileSearch(dir, file, ext).absFilename()) == result)
160 /** Launch a file dialog and return the chosen directory.
161 pathname: a suggested pathname.
162 title: the title of the dialog.
163 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
165 QString browseDir(QString const & pathname,
166 QString const & title,
167 QString const & label1 = QString(),
168 QString const & dir1 = QString(),
169 QString const & label2 = QString(),
170 QString const & dir2 = QString())
172 QString lastPath = ".";
173 if (!pathname.isEmpty())
174 lastPath = onlyPath(pathname);
176 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
177 dlg.setButton1(label1, dir1);
178 dlg.setButton2(label2, dir2);
180 FileDialog::Result const result =
181 dlg.opendir(lastPath, onlyFilename(pathname));
183 return result.second;
187 } // namespace frontend
190 QString browseRelFile(QString const & filename, QString const & refpath,
191 QString const & title, QStringList const & filters, bool save,
192 QString const & label1, QString const & dir1,
193 QString const & label2, QString const & dir2)
195 QString const fname = makeAbsPath(filename, refpath);
198 QString const outname =
199 frontend::browseFile(fname, title, filters, save, label1, dir1, label2, dir2);
201 QString const reloutname =
202 toqstr(makeRelPath(qstring_to_ucs4(outname), qstring_to_ucs4(refpath)));
204 if (reloutname.startsWith("../"))
212 /////////////////////////////////////////////////////////////////////
216 /////////////////////////////////////////////////////////////////////
220 string const catLookAndFeel = N_("Look & Feel");
221 string const catEditing = N_("Editing");
222 string const catLanguage = N_("Language Settings");
223 string const catOutput = N_("Output");
224 string const catFiles = N_("File Handling");
226 static void parseFontName(QString const & mangled0,
227 string & name, string & foundry)
229 string mangled = fromqstr(mangled0);
230 size_t const idx = mangled.find('[');
231 if (idx == string::npos || idx == 0) {
235 name = mangled.substr(0, idx - 1),
236 foundry = mangled.substr(idx + 1, mangled.size() - idx - 2);
241 static void setComboxFont(QComboBox * cb, string const & family,
242 string const & foundry)
244 QString fontname = toqstr(family);
245 if (!foundry.empty())
246 fontname += " [" + toqstr(foundry) + ']';
248 for (int i = 0; i != cb->count(); ++i) {
249 if (cb->itemText(i) == fontname) {
250 cb->setCurrentIndex(i);
255 // Try matching without foundry name
257 // We count in reverse in order to prefer the Xft foundry
258 for (int i = cb->count(); --i >= 0;) {
259 string name, foundry;
260 parseFontName(cb->itemText(i), name, foundry);
261 if (compare_ascii_no_case(name, family) == 0) {
262 cb->setCurrentIndex(i);
267 // family alone can contain e.g. "Helvetica [Adobe]"
268 string tmpname, tmpfoundry;
269 parseFontName(toqstr(family), tmpname, tmpfoundry);
271 // We count in reverse in order to prefer the Xft foundry
272 for (int i = cb->count(); --i >= 0; ) {
273 string name, foundry;
274 parseFontName(cb->itemText(i), name, foundry);
275 if (compare_ascii_no_case(name, foundry) == 0) {
276 cb->setCurrentIndex(i);
281 // Bleh, default fonts, and the names couldn't be found. Hack
285 font.setKerning(false);
287 QString const font_family = toqstr(family);
288 if (font_family == guiApp->romanFontName()) {
289 font.setStyleHint(QFont::Serif);
290 font.setFamily(font_family);
291 } else if (font_family == guiApp->sansFontName()) {
292 font.setStyleHint(QFont::SansSerif);
293 font.setFamily(font_family);
294 } else if (font_family == guiApp->typewriterFontName()) {
295 font.setStyleHint(QFont::TypeWriter);
296 font.setFamily(font_family);
298 LYXERR0("FAILED to find the default font: '"
299 << foundry << "', '" << family << '\'');
303 QFontInfo info(font);
304 string default_font_name, dummyfoundry;
305 parseFontName(info.family(), default_font_name, dummyfoundry);
306 LYXERR0("Apparent font is " << default_font_name);
308 for (int i = 0; i < cb->count(); ++i) {
309 LYXERR0("Looking at " << cb->itemText(i));
310 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
311 default_font_name) == 0) {
312 cb->setCurrentIndex(i);
317 LYXERR0("FAILED to find the font: '"
318 << foundry << "', '" << family << '\'');
323 /////////////////////////////////////////////////////////////////////
327 /////////////////////////////////////////////////////////////////////
329 PrefPlaintext::PrefPlaintext(GuiPreferences * form)
330 : PrefModule(qt_(catOutput), qt_("Plain text"), form)
333 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
334 this, SIGNAL(changed()));
335 connect(plaintextRoffED, SIGNAL(textChanged(QString)),
336 this, SIGNAL(changed()));
340 void PrefPlaintext::apply(LyXRC & rc) const
342 rc.plaintext_linelen = plaintextLinelengthSB->value();
343 rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
347 void PrefPlaintext::update(LyXRC const & rc)
349 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
350 plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
354 /////////////////////////////////////////////////////////////////////
358 /////////////////////////////////////////////////////////////////////
360 PrefDate::PrefDate(GuiPreferences * form)
361 : PrefModule(qt_(catOutput), qt_("Date format"), form)
364 connect(DateED, SIGNAL(textChanged(QString)),
365 this, SIGNAL(changed()));
369 void PrefDate::apply(LyXRC & rc) const
371 rc.date_insert_format = fromqstr(DateED->text());
375 void PrefDate::update(LyXRC const & rc)
377 DateED->setText(toqstr(rc.date_insert_format));
381 /////////////////////////////////////////////////////////////////////
385 /////////////////////////////////////////////////////////////////////
387 PrefInput::PrefInput(GuiPreferences * form)
388 : PrefModule(qt_(catEditing), qt_("Keyboard/Mouse"), form)
392 connect(keymapCB, SIGNAL(clicked()),
393 this, SIGNAL(changed()));
394 connect(firstKeymapED, SIGNAL(textChanged(QString)),
395 this, SIGNAL(changed()));
396 connect(secondKeymapED, SIGNAL(textChanged(QString)),
397 this, SIGNAL(changed()));
398 connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
399 this, SIGNAL(changed()));
403 void PrefInput::apply(LyXRC & rc) const
405 // FIXME: can derive CB from the two EDs
406 rc.use_kbmap = keymapCB->isChecked();
407 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
408 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
409 rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
413 void PrefInput::update(LyXRC const & rc)
415 // FIXME: can derive CB from the two EDs
416 keymapCB->setChecked(rc.use_kbmap);
417 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
418 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
419 mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
423 QString PrefInput::testKeymap(QString const & keymap)
425 return form_->browsekbmap(internalPath(keymap));
429 void PrefInput::on_firstKeymapPB_clicked(bool)
431 QString const file = testKeymap(firstKeymapED->text());
433 firstKeymapED->setText(file);
437 void PrefInput::on_secondKeymapPB_clicked(bool)
439 QString const file = testKeymap(secondKeymapED->text());
441 secondKeymapED->setText(file);
445 void PrefInput::on_keymapCB_toggled(bool keymap)
447 firstKeymapLA->setEnabled(keymap);
448 secondKeymapLA->setEnabled(keymap);
449 firstKeymapED->setEnabled(keymap);
450 secondKeymapED->setEnabled(keymap);
451 firstKeymapPB->setEnabled(keymap);
452 secondKeymapPB->setEnabled(keymap);
456 /////////////////////////////////////////////////////////////////////
460 /////////////////////////////////////////////////////////////////////
462 PrefCompletion::PrefCompletion(GuiPreferences * form)
463 : PrefModule(qt_(catEditing), qt_("Input Completion"), form)
467 connect(inlineDelaySB, SIGNAL(valueChanged(double)),
468 this, SIGNAL(changed()));
469 connect(inlineMathCB, SIGNAL(clicked()),
470 this, SIGNAL(changed()));
471 connect(inlineTextCB, SIGNAL(clicked()),
472 this, SIGNAL(changed()));
473 connect(inlineDotsCB, SIGNAL(clicked()),
474 this, SIGNAL(changed()));
475 connect(popupDelaySB, SIGNAL(valueChanged(double)),
476 this, SIGNAL(changed()));
477 connect(popupMathCB, SIGNAL(clicked()),
478 this, SIGNAL(changed()));
479 connect(popupTextCB, SIGNAL(clicked()),
480 this, SIGNAL(changed()));
481 connect(popupAfterCompleteCB, SIGNAL(clicked()),
482 this, SIGNAL(changed()));
483 connect(cursorTextCB, SIGNAL(clicked()),
484 this, SIGNAL(changed()));
488 void PrefCompletion::apply(LyXRC & rc) const
490 rc.completion_inline_delay = inlineDelaySB->value();
491 rc.completion_inline_math = inlineMathCB->isChecked();
492 rc.completion_inline_text = inlineTextCB->isChecked();
493 rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
494 rc.completion_popup_delay = popupDelaySB->value();
495 rc.completion_popup_math = popupMathCB->isChecked();
496 rc.completion_popup_text = popupTextCB->isChecked();
497 rc.completion_cursor_text = cursorTextCB->isChecked();
498 rc.completion_popup_after_complete =
499 popupAfterCompleteCB->isChecked();
503 void PrefCompletion::update(LyXRC const & rc)
505 inlineDelaySB->setValue(rc.completion_inline_delay);
506 inlineMathCB->setChecked(rc.completion_inline_math);
507 inlineTextCB->setChecked(rc.completion_inline_text);
508 inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
509 popupDelaySB->setValue(rc.completion_popup_delay);
510 popupMathCB->setChecked(rc.completion_popup_math);
511 popupTextCB->setChecked(rc.completion_popup_text);
512 cursorTextCB->setChecked(rc.completion_cursor_text);
513 popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
518 /////////////////////////////////////////////////////////////////////
522 /////////////////////////////////////////////////////////////////////
524 PrefLatex::PrefLatex(GuiPreferences * form)
525 : PrefModule(qt_(catOutput), qt_("LaTeX"), form)
528 connect(latexEncodingED, SIGNAL(textChanged(QString)),
529 this, SIGNAL(changed()));
530 connect(latexChecktexED, SIGNAL(textChanged(QString)),
531 this, SIGNAL(changed()));
532 connect(latexBibtexED, SIGNAL(textChanged(QString)),
533 this, SIGNAL(changed()));
534 connect(latexIndexED, SIGNAL(textChanged(QString)),
535 this, SIGNAL(changed()));
536 connect(latexAutoresetCB, SIGNAL(clicked()),
537 this, SIGNAL(changed()));
538 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
539 this, SIGNAL(changed()));
540 connect(latexPaperSizeCO, SIGNAL(activated(int)),
541 this, SIGNAL(changed()));
543 #if defined(__CYGWIN__) || defined(_WIN32)
544 pathCB->setVisible(true);
545 connect(pathCB, SIGNAL(clicked()),
546 this, SIGNAL(changed()));
548 pathCB->setVisible(false);
553 void PrefLatex::apply(LyXRC & rc) const
555 rc.fontenc = fromqstr(latexEncodingED->text());
556 rc.chktex_command = fromqstr(latexChecktexED->text());
557 rc.bibtex_command = fromqstr(latexBibtexED->text());
558 rc.index_command = fromqstr(latexIndexED->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 latexAutoresetCB->setChecked(rc.auto_reset_options);
576 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
577 latexPaperSizeCO->setCurrentIndex(
578 form_->fromPaperSize(rc.default_papersize));
579 #if defined(__CYGWIN__) || defined(_WIN32)
580 pathCB->setChecked(rc.windows_style_tex_paths);
585 /////////////////////////////////////////////////////////////////////
589 /////////////////////////////////////////////////////////////////////
591 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form)
592 : PrefModule(qt_(catLookAndFeel), qt_("Screen fonts"), form)
596 connect(screenRomanCO, SIGNAL(activated(QString)),
597 this, SLOT(select_roman(QString)));
598 connect(screenSansCO, SIGNAL(activated(QString)),
599 this, SLOT(select_sans(QString)));
600 connect(screenTypewriterCO, SIGNAL(activated(QString)),
601 this, SLOT(select_typewriter(QString)));
603 QFontDatabase fontdb;
604 QStringList families(fontdb.families());
605 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
606 screenRomanCO->addItem(*it);
607 screenSansCO->addItem(*it);
608 screenTypewriterCO->addItem(*it);
610 connect(screenRomanCO, SIGNAL(activated(QString)),
611 this, SIGNAL(changed()));
612 connect(screenSansCO, SIGNAL(activated(QString)),
613 this, SIGNAL(changed()));
614 connect(screenTypewriterCO, SIGNAL(activated(QString)),
615 this, SIGNAL(changed()));
616 connect(screenZoomSB, SIGNAL(valueChanged(int)),
617 this, SIGNAL(changed()));
618 connect(screenDpiSB, SIGNAL(valueChanged(int)),
619 this, SIGNAL(changed()));
620 connect(screenTinyED, SIGNAL(textChanged(QString)),
621 this, SIGNAL(changed()));
622 connect(screenSmallestED, SIGNAL(textChanged(QString)),
623 this, SIGNAL(changed()));
624 connect(screenSmallerED, SIGNAL(textChanged(QString)),
625 this, SIGNAL(changed()));
626 connect(screenSmallED, SIGNAL(textChanged(QString)),
627 this, SIGNAL(changed()));
628 connect(screenNormalED, SIGNAL(textChanged(QString)),
629 this, SIGNAL(changed()));
630 connect(screenLargeED, SIGNAL(textChanged(QString)),
631 this, SIGNAL(changed()));
632 connect(screenLargerED, SIGNAL(textChanged(QString)),
633 this, SIGNAL(changed()));
634 connect(screenLargestED, SIGNAL(textChanged(QString)),
635 this, SIGNAL(changed()));
636 connect(screenHugeED, SIGNAL(textChanged(QString)),
637 this, SIGNAL(changed()));
638 connect(screenHugerED, SIGNAL(textChanged(QString)),
639 this, SIGNAL(changed()));
640 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
641 this, SIGNAL(changed()));
643 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
644 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
645 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
646 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
647 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
648 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
649 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
650 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
651 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
652 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
656 void PrefScreenFonts::apply(LyXRC & rc) const
658 LyXRC const oldrc = rc;
660 parseFontName(screenRomanCO->currentText(),
661 rc.roman_font_name, rc.roman_font_foundry);
662 parseFontName(screenSansCO->currentText(),
663 rc.sans_font_name, rc.sans_font_foundry);
664 parseFontName(screenTypewriterCO->currentText(),
665 rc.typewriter_font_name, rc.typewriter_font_foundry);
667 rc.zoom = screenZoomSB->value();
668 rc.dpi = screenDpiSB->value();
669 rc.font_sizes[FONT_SIZE_TINY] = fromqstr(screenTinyED->text());
670 rc.font_sizes[FONT_SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
671 rc.font_sizes[FONT_SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
672 rc.font_sizes[FONT_SIZE_SMALL] = fromqstr(screenSmallED->text());
673 rc.font_sizes[FONT_SIZE_NORMAL] = fromqstr(screenNormalED->text());
674 rc.font_sizes[FONT_SIZE_LARGE] = fromqstr(screenLargeED->text());
675 rc.font_sizes[FONT_SIZE_LARGER] = fromqstr(screenLargerED->text());
676 rc.font_sizes[FONT_SIZE_LARGEST] = fromqstr(screenLargestED->text());
677 rc.font_sizes[FONT_SIZE_HUGE] = fromqstr(screenHugeED->text());
678 rc.font_sizes[FONT_SIZE_HUGER] = fromqstr(screenHugerED->text());
679 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
681 if (rc.font_sizes != oldrc.font_sizes
682 || rc.roman_font_name != oldrc.roman_font_name
683 || rc.sans_font_name != oldrc.sans_font_name
684 || rc.typewriter_font_name != oldrc.typewriter_font_name
685 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
686 // The global QPixmapCache is used in GuiPainter to cache text
687 // painting so we must reset it in case any of the above
688 // parameter is changed.
689 QPixmapCache::clear();
690 guiApp->fontLoader().update();
691 form_->updateScreenFonts();
696 void PrefScreenFonts::update(LyXRC const & rc)
698 setComboxFont(screenRomanCO, rc.roman_font_name,
699 rc.roman_font_foundry);
700 setComboxFont(screenSansCO, rc.sans_font_name,
701 rc.sans_font_foundry);
702 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
703 rc.typewriter_font_foundry);
705 select_roman(screenRomanCO->currentText());
706 select_sans(screenSansCO->currentText());
707 select_typewriter(screenTypewriterCO->currentText());
709 screenZoomSB->setValue(rc.zoom);
710 screenDpiSB->setValue(rc.dpi);
711 screenTinyED->setText(toqstr(rc.font_sizes[FONT_SIZE_TINY]));
712 screenSmallestED->setText(toqstr(rc.font_sizes[FONT_SIZE_SCRIPT]));
713 screenSmallerED->setText(toqstr(rc.font_sizes[FONT_SIZE_FOOTNOTE]));
714 screenSmallED->setText(toqstr(rc.font_sizes[FONT_SIZE_SMALL]));
715 screenNormalED->setText(toqstr(rc.font_sizes[FONT_SIZE_NORMAL]));
716 screenLargeED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGE]));
717 screenLargerED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGER]));
718 screenLargestED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGEST]));
719 screenHugeED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGE]));
720 screenHugerED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGER]));
722 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
723 #if defined(Q_WS_X11)
724 pixmapCacheCB->setEnabled(false);
730 void PrefScreenFonts::select_roman(const QString & name)
732 screenRomanFE->set(QFont(name), name);
736 void PrefScreenFonts::select_sans(const QString & name)
738 screenSansFE->set(QFont(name), name);
742 void PrefScreenFonts::select_typewriter(const QString & name)
744 screenTypewriterFE->set(QFont(name), name);
748 /////////////////////////////////////////////////////////////////////
752 /////////////////////////////////////////////////////////////////////
758 bool operator()(ColorCode lhs, ColorCode rhs) const {
759 return lcolor.getGUIName(lhs) < lcolor.getGUIName(rhs);
765 PrefColors::PrefColors(GuiPreferences * form)
766 : PrefModule(qt_(catLookAndFeel), qt_("Colors"), form)
770 // FIXME: all of this initialization should be put into the controller.
771 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
772 // for some discussion of why that is not trivial.
773 QPixmap icon(32, 32);
774 for (int i = 0; i < Color_ignore; ++i) {
775 ColorCode lc = static_cast<ColorCode>(i);
783 || lc == Color_magenta
784 || lc == Color_yellow
785 || lc == Color_inherit
786 || lc == Color_ignore) continue;
788 lcolors_.push_back(lc);
790 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
791 vector<ColorCode>::const_iterator cit = lcolors_.begin();
792 vector<ColorCode>::const_iterator const end = lcolors_.end();
793 for (; cit != end; ++cit) {
794 (void) new QListWidgetItem(QIcon(icon),
795 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
797 curcolors_.resize(lcolors_.size());
798 newcolors_.resize(lcolors_.size());
799 // End initialization
801 connect(colorChangePB, SIGNAL(clicked()),
802 this, SLOT(change_color()));
803 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
804 this, SLOT(change_lyxObjects_selection()));
805 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
806 this, SLOT(change_color()));
810 void PrefColors::apply(LyXRC & /*rc*/) const
812 for (unsigned int i = 0; i < lcolors_.size(); ++i)
813 if (curcolors_[i] != newcolors_[i])
814 form_->setColor(lcolors_[i], newcolors_[i]);
818 void PrefColors::update(LyXRC const & /*rc*/)
820 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
821 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
822 QPixmap coloritem(32, 32);
823 coloritem.fill(color);
824 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
825 newcolors_[i] = curcolors_[i] = color.name();
827 change_lyxObjects_selection();
831 void PrefColors::change_color()
833 int const row = lyxObjectsLW->currentRow();
839 QString const color = newcolors_[row];
840 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
842 if (c.isValid() && c.name() != color) {
843 newcolors_[row] = c.name();
844 QPixmap coloritem(32, 32);
846 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
852 void PrefColors::change_lyxObjects_selection()
854 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
858 /////////////////////////////////////////////////////////////////////
862 /////////////////////////////////////////////////////////////////////
864 PrefDisplay::PrefDisplay(GuiPreferences * form)
865 : PrefModule(qt_(catLookAndFeel), qt_("Graphics"), form)
868 connect(displayGraphicsCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
869 connect(instantPreviewCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
873 void PrefDisplay::apply(LyXRC & rc) const
875 switch (instantPreviewCO->currentIndex()) {
876 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
877 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
878 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
881 rc.display_graphics = displayGraphicsCB->isChecked();
883 // FIXME!! The graphics cache no longer has a changeDisplay method.
885 if (old_value != rc.display_graphics) {
886 graphics::GCache & gc = graphics::GCache::get();
893 void PrefDisplay::update(LyXRC const & rc)
895 switch (rc.preview) {
896 case LyXRC::PREVIEW_OFF:
897 instantPreviewCO->setCurrentIndex(0);
899 case LyXRC::PREVIEW_NO_MATH :
900 instantPreviewCO->setCurrentIndex(1);
902 case LyXRC::PREVIEW_ON :
903 instantPreviewCO->setCurrentIndex(2);
907 displayGraphicsCB->setChecked(rc.display_graphics);
908 instantPreviewCO->setEnabled(rc.display_graphics);
912 /////////////////////////////////////////////////////////////////////
916 /////////////////////////////////////////////////////////////////////
918 PrefPaths::PrefPaths(GuiPreferences * form)
919 : PrefModule(QString(), qt_("Paths"), form)
922 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(select_exampledir()));
923 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
924 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
925 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
926 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
927 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
928 connect(workingDirED, SIGNAL(textChanged(QString)),
929 this, SIGNAL(changed()));
930 connect(exampleDirED, SIGNAL(textChanged(QString)),
931 this, SIGNAL(changed()));
932 connect(templateDirED, SIGNAL(textChanged(QString)),
933 this, SIGNAL(changed()));
934 connect(backupDirED, SIGNAL(textChanged(QString)),
935 this, SIGNAL(changed()));
936 connect(tempDirED, SIGNAL(textChanged(QString)),
937 this, SIGNAL(changed()));
938 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
939 this, SIGNAL(changed()));
940 connect(pathPrefixED, SIGNAL(textChanged(QString)),
941 this, SIGNAL(changed()));
945 void PrefPaths::apply(LyXRC & rc) const
947 rc.document_path = internal_path(fromqstr(workingDirED->text()));
948 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
949 rc.template_path = internal_path(fromqstr(templateDirED->text()));
950 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
951 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
952 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
953 // FIXME: should be a checkbox only
954 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
958 void PrefPaths::update(LyXRC const & rc)
960 workingDirED->setText(toqstr(external_path(rc.document_path)));
961 exampleDirED->setText(toqstr(external_path(rc.example_path)));
962 templateDirED->setText(toqstr(external_path(rc.template_path)));
963 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
964 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
965 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
966 // FIXME: should be a checkbox only
967 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
971 void PrefPaths::select_exampledir()
973 QString file = browseDir(internalPath(exampleDirED->text()),
974 qt_("Select directory for example files"));
976 exampleDirED->setText(file);
980 void PrefPaths::select_templatedir()
982 QString file = browseDir(internalPath(templateDirED->text()),
983 qt_("Select a document templates directory"));
985 templateDirED->setText(file);
989 void PrefPaths::select_tempdir()
991 QString file = browseDir(internalPath(tempDirED->text()),
992 qt_("Select a temporary directory"));
994 tempDirED->setText(file);
998 void PrefPaths::select_backupdir()
1000 QString file = browseDir(internalPath(backupDirED->text()),
1001 qt_("Select a backups directory"));
1002 if (!file.isEmpty())
1003 backupDirED->setText(file);
1007 void PrefPaths::select_workingdir()
1009 QString file = browseDir(internalPath(workingDirED->text()),
1010 qt_("Select a document directory"));
1011 if (!file.isEmpty())
1012 workingDirED->setText(file);
1016 void PrefPaths::select_lyxpipe()
1018 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1019 qt_("Give a filename for the LyX server pipe"));
1020 if (!file.isEmpty())
1021 lyxserverDirED->setText(file);
1025 /////////////////////////////////////////////////////////////////////
1029 /////////////////////////////////////////////////////////////////////
1031 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form)
1032 : PrefModule(qt_(catLanguage), qt_("Spellchecker"), form)
1036 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
1037 #if defined (USE_ISPELL)
1038 connect(spellCommandCO, SIGNAL(activated(int)),
1039 this, SIGNAL(changed()));
1041 spellCommandCO->setEnabled(false);
1043 connect(altLanguageED, SIGNAL(textChanged(QString)),
1044 this, SIGNAL(changed()));
1045 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1046 this, SIGNAL(changed()));
1047 connect(persDictionaryED, SIGNAL(textChanged(QString)),
1048 this, SIGNAL(changed()));
1049 connect(compoundWordCB, SIGNAL(clicked()),
1050 this, SIGNAL(changed()));
1051 connect(inputEncodingCB, SIGNAL(clicked()),
1052 this, SIGNAL(changed()));
1054 spellCommandCO->addItem(qt_("ispell"));
1055 spellCommandCO->addItem(qt_("aspell"));
1056 spellCommandCO->addItem(qt_("hspell"));
1058 spellCommandCO->addItem(qt_("pspell (library)"));
1061 spellCommandCO->addItem(qt_("aspell (library)"));
1067 void PrefSpellchecker::apply(LyXRC & rc) const
1069 switch (spellCommandCO->currentIndex()) {
1073 rc.use_spell_lib = false;
1074 rc.isp_command = fromqstr(spellCommandCO->currentText());
1077 rc.use_spell_lib = true;
1081 // FIXME: remove isp_use_alt_lang
1082 rc.isp_alt_lang = fromqstr(altLanguageED->text());
1083 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
1084 // FIXME: remove isp_use_esc_chars
1085 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
1086 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
1087 // FIXME: remove isp_use_pers_dict
1088 rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
1089 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
1090 rc.isp_accept_compound = compoundWordCB->isChecked();
1091 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
1095 void PrefSpellchecker::update(LyXRC const & rc)
1097 spellCommandCO->setCurrentIndex(0);
1099 if (rc.isp_command == "ispell") {
1100 spellCommandCO->setCurrentIndex(0);
1101 } else if (rc.isp_command == "aspell") {
1102 spellCommandCO->setCurrentIndex(1);
1103 } else if (rc.isp_command == "hspell") {
1104 spellCommandCO->setCurrentIndex(2);
1107 if (rc.use_spell_lib) {
1108 #if defined(USE_ASPELL) || defined(USE_PSPELL)
1109 spellCommandCO->setCurrentIndex(3);
1113 // FIXME: remove isp_use_alt_lang
1114 altLanguageED->setText(toqstr(rc.isp_alt_lang));
1115 // FIXME: remove isp_use_esc_chars
1116 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
1117 // FIXME: remove isp_use_pers_dict
1118 persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
1119 compoundWordCB->setChecked(rc.isp_accept_compound);
1120 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
1124 void PrefSpellchecker::select_dict()
1126 QString file = form_->browsedict(internalPath(persDictionaryED->text()));
1127 if (!file.isEmpty())
1128 persDictionaryED->setText(file);
1133 /////////////////////////////////////////////////////////////////////
1137 /////////////////////////////////////////////////////////////////////
1140 PrefConverters::PrefConverters(GuiPreferences * form)
1141 : PrefModule(qt_(catFiles), qt_("Converters"), form)
1145 connect(converterNewPB, SIGNAL(clicked()),
1146 this, SLOT(update_converter()));
1147 connect(converterRemovePB, SIGNAL(clicked()),
1148 this, SLOT(remove_converter()));
1149 connect(converterModifyPB, SIGNAL(clicked()),
1150 this, SLOT(update_converter()));
1151 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1152 this, SLOT(switch_converter()));
1153 connect(converterFromCO, SIGNAL(activated(QString)),
1154 this, SLOT(converter_changed()));
1155 connect(converterToCO, SIGNAL(activated(QString)),
1156 this, SLOT(converter_changed()));
1157 connect(converterED, SIGNAL(textEdited(QString)),
1158 this, SLOT(converter_changed()));
1159 connect(converterFlagED, SIGNAL(textEdited(QString)),
1160 this, SLOT(converter_changed()));
1161 connect(converterNewPB, SIGNAL(clicked()),
1162 this, SIGNAL(changed()));
1163 connect(converterRemovePB, SIGNAL(clicked()),
1164 this, SIGNAL(changed()));
1165 connect(converterModifyPB, SIGNAL(clicked()),
1166 this, SIGNAL(changed()));
1167 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1168 this, SIGNAL(changed()));
1170 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1171 //converterDefGB->setFocusProxy(convertersLW);
1175 void PrefConverters::apply(LyXRC & rc) const
1177 rc.use_converter_cache = cacheCB->isChecked();
1178 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
1182 void PrefConverters::update(LyXRC const & rc)
1184 cacheCB->setChecked(rc.use_converter_cache);
1186 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
1187 maxAgeLE->setText(max_age);
1192 void PrefConverters::updateGui()
1194 form_->formats().sort();
1195 form_->converters().update(form_->formats());
1196 // save current selection
1197 QString current = converterFromCO->currentText()
1198 + " -> " + converterToCO->currentText();
1200 converterFromCO->clear();
1201 converterToCO->clear();
1203 Formats::const_iterator cit = form_->formats().begin();
1204 Formats::const_iterator end = form_->formats().end();
1205 for (; cit != end; ++cit) {
1206 converterFromCO->addItem(qt_(cit->prettyname()));
1207 converterToCO->addItem(qt_(cit->prettyname()));
1210 // currentRowChanged(int) is also triggered when updating the listwidget
1211 // block signals to avoid unnecessary calls to switch_converter()
1212 convertersLW->blockSignals(true);
1213 convertersLW->clear();
1215 Converters::const_iterator ccit = form_->converters().begin();
1216 Converters::const_iterator cend = form_->converters().end();
1217 for (; ccit != cend; ++ccit) {
1218 QString const name =
1219 qt_(ccit->From->prettyname()) + " -> " + qt_(ccit->To->prettyname());
1220 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1221 new QListWidgetItem(name, convertersLW, type);
1223 convertersLW->sortItems(Qt::AscendingOrder);
1224 convertersLW->blockSignals(false);
1226 // restore selection
1227 if (!current.isEmpty()) {
1228 QList<QListWidgetItem *> const item =
1229 convertersLW->findItems(current, Qt::MatchExactly);
1230 if (!item.isEmpty())
1231 convertersLW->setCurrentItem(item.at(0));
1234 // select first element if restoring failed
1235 if (convertersLW->currentRow() == -1)
1236 convertersLW->setCurrentRow(0);
1242 void PrefConverters::switch_converter()
1244 int const cnr = convertersLW->currentItem()->type();
1245 Converter const & c(form_->converters().get(cnr));
1246 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1247 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1248 converterED->setText(toqstr(c.command));
1249 converterFlagED->setText(toqstr(c.flags));
1255 void PrefConverters::converter_changed()
1261 void PrefConverters::updateButtons()
1263 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1264 Format const & to = form_->formats().get(converterToCO->currentIndex());
1265 int const sel = form_->converters().getNumber(from.name(), to.name());
1266 bool const known = sel >= 0;
1267 bool const valid = !(converterED->text().isEmpty()
1268 || from.name() == to.name());
1270 int const cnr = convertersLW->currentItem()->type();
1271 Converter const & c = form_->converters().get(cnr);
1272 string const old_command = c.command;
1273 string const old_flag = c.flags;
1274 string const new_command = fromqstr(converterED->text());
1275 string const new_flag = fromqstr(converterFlagED->text());
1277 bool modified = (old_command != new_command || old_flag != new_flag);
1279 converterModifyPB->setEnabled(valid && known && modified);
1280 converterNewPB->setEnabled(valid && !known);
1281 converterRemovePB->setEnabled(known);
1283 maxAgeLE->setEnabled(cacheCB->isChecked());
1284 maxAgeLA->setEnabled(cacheCB->isChecked());
1289 // specify unique from/to or it doesn't appear. This is really bad UI
1290 // this is why we can use the same function for both new and modify
1291 void PrefConverters::update_converter()
1293 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1294 Format const & to = form_->formats().get(converterToCO->currentIndex());
1295 string const flags = fromqstr(converterFlagED->text());
1296 string const command = fromqstr(converterED->text());
1298 Converter const * old =
1299 form_->converters().getConverter(from.name(), to.name());
1300 form_->converters().add(from.name(), to.name(), command, flags);
1303 form_->converters().updateLast(form_->formats());
1307 // Remove all files created by this converter from the cache, since
1308 // the modified converter might create different files.
1309 ConverterCache::get().remove_all(from.name(), to.name());
1313 void PrefConverters::remove_converter()
1315 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1316 Format const & to = form_->formats().get(converterToCO->currentIndex());
1317 form_->converters().erase(from.name(), to.name());
1321 // Remove all files created by this converter from the cache, since
1322 // a possible new converter might create different files.
1323 ConverterCache::get().remove_all(from.name(), to.name());
1327 void PrefConverters::on_cacheCB_stateChanged(int state)
1329 maxAgeLE->setEnabled(state == Qt::Checked);
1330 maxAgeLA->setEnabled(state == Qt::Checked);
1335 /////////////////////////////////////////////////////////////////////
1339 /////////////////////////////////////////////////////////////////////
1341 class FormatValidator : public QValidator
1344 FormatValidator(QWidget *, Formats const & f);
1345 void fixup(QString & input) const;
1346 QValidator::State validate(QString & input, int & pos) const;
1348 virtual QString toString(Format const & format) const = 0;
1350 Formats const & formats_;
1354 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1355 : QValidator(parent), formats_(f)
1360 void FormatValidator::fixup(QString & input) const
1362 Formats::const_iterator cit = formats_.begin();
1363 Formats::const_iterator end = formats_.end();
1364 for (; cit != end; ++cit) {
1365 QString const name = toString(*cit);
1366 if (distance(formats_.begin(), cit) == nr()) {
1374 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1376 Formats::const_iterator cit = formats_.begin();
1377 Formats::const_iterator end = formats_.end();
1378 bool unknown = true;
1379 for (; unknown && cit != end; ++cit) {
1380 QString const name = toString(*cit);
1381 if (distance(formats_.begin(), cit) != nr())
1382 unknown = name != input;
1385 if (unknown && !input.isEmpty())
1386 return QValidator::Acceptable;
1388 return QValidator::Intermediate;
1392 int FormatValidator::nr() const
1394 QComboBox * p = qobject_cast<QComboBox *>(parent());
1395 return p->itemData(p->currentIndex()).toInt();
1399 /////////////////////////////////////////////////////////////////////
1401 // FormatNameValidator
1403 /////////////////////////////////////////////////////////////////////
1405 class FormatNameValidator : public FormatValidator
1408 FormatNameValidator(QWidget * parent, Formats const & f)
1409 : FormatValidator(parent, f)
1412 QString toString(Format const & format) const
1414 return toqstr(format.name());
1419 /////////////////////////////////////////////////////////////////////
1421 // FormatPrettynameValidator
1423 /////////////////////////////////////////////////////////////////////
1425 class FormatPrettynameValidator : public FormatValidator
1428 FormatPrettynameValidator(QWidget * parent, Formats const & f)
1429 : FormatValidator(parent, f)
1432 QString toString(Format const & format) const
1434 return qt_(format.prettyname());
1439 /////////////////////////////////////////////////////////////////////
1443 /////////////////////////////////////////////////////////////////////
1445 PrefFileformats::PrefFileformats(GuiPreferences * form)
1446 : PrefModule(qt_(catFiles), qt_("File formats"), form)
1449 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1450 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1452 connect(documentCB, SIGNAL(clicked()),
1453 this, SLOT(setFlags()));
1454 connect(vectorCB, SIGNAL(clicked()),
1455 this, SLOT(setFlags()));
1456 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1457 this, SLOT(updatePrettyname()));
1458 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1459 this, SIGNAL(changed()));
1465 string const l10n_shortcut(string const prettyname, string const shortcut)
1467 if (shortcut.empty())
1470 string l10n_format =
1471 to_utf8(_(prettyname + '|' + shortcut));
1472 return split(l10n_format, '|');
1475 }; // namespace anon
1478 void PrefFileformats::apply(LyXRC & /*rc*/) const
1483 void PrefFileformats::update(LyXRC const & /*rc*/)
1489 void PrefFileformats::updateView()
1491 QString const current = formatsCB->currentText();
1493 // update combobox with formats
1494 formatsCB->blockSignals(true);
1496 form_->formats().sort();
1497 Formats::const_iterator cit = form_->formats().begin();
1498 Formats::const_iterator end = form_->formats().end();
1499 for (; cit != end; ++cit)
1500 formatsCB->addItem(qt_(cit->prettyname()),
1501 QVariant(form_->formats().getNumber(cit->name())));
1503 // restore selection
1504 int const item = formatsCB->findText(current, Qt::MatchExactly);
1505 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1506 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1507 formatsCB->blockSignals(false);
1511 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1513 int const nr = formatsCB->itemData(i).toInt();
1514 Format const f = form_->formats().get(nr);
1516 formatED->setText(toqstr(f.name()));
1517 copierED->setText(toqstr(form_->movers().command(f.name())));
1518 extensionED->setText(toqstr(f.extension()));
1519 shortcutED->setText(
1520 toqstr(l10n_shortcut(f.prettyname(), f.shortcut())));
1521 viewerED->setText(toqstr(f.viewer()));
1522 editorED->setText(toqstr(f.editor()));
1523 documentCB->setChecked((f.documentFormat()));
1524 vectorCB->setChecked((f.vectorFormat()));
1528 void PrefFileformats::setFlags()
1530 int flags = Format::none;
1531 if (documentCB->isChecked())
1532 flags |= Format::document;
1533 if (vectorCB->isChecked())
1534 flags |= Format::vector;
1535 currentFormat().setFlags(flags);
1540 void PrefFileformats::on_copierED_textEdited(const QString & s)
1542 string const fmt = fromqstr(formatED->text());
1543 form_->movers().set(fmt, fromqstr(s));
1548 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1550 currentFormat().setExtension(fromqstr(s));
1554 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1556 currentFormat().setViewer(fromqstr(s));
1561 void PrefFileformats::on_editorED_textEdited(const QString & s)
1563 currentFormat().setEditor(fromqstr(s));
1568 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1570 string const new_shortcut = fromqstr(s);
1571 if (new_shortcut == l10n_shortcut(currentFormat().prettyname(),
1572 currentFormat().shortcut()))
1574 currentFormat().setShortcut(new_shortcut);
1579 void PrefFileformats::on_formatED_editingFinished()
1581 string const newname = fromqstr(formatED->displayText());
1582 if (newname == currentFormat().name())
1585 currentFormat().setName(newname);
1590 void PrefFileformats::on_formatED_textChanged(const QString &)
1592 QString t = formatED->text();
1594 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1595 setValid(formatLA, valid);
1599 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1601 QString t = formatsCB->currentText();
1603 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1604 setValid(formatsLA, valid);
1608 void PrefFileformats::updatePrettyname()
1610 QString const newname = formatsCB->currentText();
1611 if (newname == qt_(currentFormat().prettyname()))
1614 currentFormat().setPrettyname(fromqstr(newname));
1621 Format & PrefFileformats::currentFormat()
1623 int const i = formatsCB->currentIndex();
1624 int const nr = formatsCB->itemData(i).toInt();
1625 return form_->formats().get(nr);
1629 void PrefFileformats::on_formatNewPB_clicked()
1631 form_->formats().add("", "", "", "", "", "", Format::none);
1633 formatsCB->setCurrentIndex(0);
1634 formatsCB->setFocus(Qt::OtherFocusReason);
1638 void PrefFileformats::on_formatRemovePB_clicked()
1640 int const i = formatsCB->currentIndex();
1641 int const nr = formatsCB->itemData(i).toInt();
1642 string const current_text = form_->formats().get(nr).name();
1643 if (form_->converters().formatIsUsed(current_text)) {
1644 Alert::error(_("Format in use"),
1645 _("Cannot remove a Format used by a Converter. "
1646 "Remove the converter first."));
1650 form_->formats().erase(current_text);
1653 on_formatsCB_editTextChanged(formatsCB->currentText());
1658 /////////////////////////////////////////////////////////////////////
1662 /////////////////////////////////////////////////////////////////////
1664 PrefLanguage::PrefLanguage(GuiPreferences * form)
1665 : PrefModule(qt_(catLanguage), qt_("Language"), form)
1669 connect(rtlGB, SIGNAL(clicked()),
1670 this, SIGNAL(changed()));
1671 connect(visualCursorRB, SIGNAL(clicked()),
1672 this, SIGNAL(changed()));
1673 connect(logicalCursorRB, SIGNAL(clicked()),
1674 this, SIGNAL(changed()));
1675 connect(markForeignCB, SIGNAL(clicked()),
1676 this, SIGNAL(changed()));
1677 connect(autoBeginCB, SIGNAL(clicked()),
1678 this, SIGNAL(changed()));
1679 connect(autoEndCB, SIGNAL(clicked()),
1680 this, SIGNAL(changed()));
1681 connect(useBabelCB, SIGNAL(clicked()),
1682 this, SIGNAL(changed()));
1683 connect(globalCB, SIGNAL(clicked()),
1684 this, SIGNAL(changed()));
1685 connect(languagePackageED, SIGNAL(textChanged(QString)),
1686 this, SIGNAL(changed()));
1687 connect(startCommandED, SIGNAL(textChanged(QString)),
1688 this, SIGNAL(changed()));
1689 connect(endCommandED, SIGNAL(textChanged(QString)),
1690 this, SIGNAL(changed()));
1691 connect(defaultLanguageCO, SIGNAL(activated(int)),
1692 this, SIGNAL(changed()));
1693 connect(uiLanguageCO, SIGNAL(activated(int)),
1694 this, SIGNAL(changed()));
1696 defaultLanguageCO->clear();
1697 uiLanguageCO->clear();
1699 QAbstractItemModel * language_model = guiApp->languageModel();
1700 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1701 language_model->sort(0);
1702 defaultLanguageCO->setModel(language_model);
1704 // FIXME: This is wrong, we need filter this list based on the available
1706 uiLanguageCO->blockSignals(true);
1707 uiLanguageCO->addItem(qt_("Default"), toqstr("auto"));
1708 for (int i = 0; i != language_model->rowCount(); ++i) {
1709 QModelIndex index = language_model->index(i, 0);
1710 uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
1711 index.data(Qt::UserRole).toString());
1713 uiLanguageCO->blockSignals(false);
1717 void PrefLanguage::on_uiLanguageCO_currentIndexChanged(int)
1719 QMessageBox::information(this, qt_("LyX needs to be restarted!"),
1720 qt_("The change of user interface language will be fully "
1721 "effective only after a restart."));
1725 void PrefLanguage::apply(LyXRC & rc) const
1727 // FIXME: remove rtl_support bool
1728 rc.rtl_support = rtlGB->isChecked();
1729 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
1730 rc.mark_foreign_language = markForeignCB->isChecked();
1731 rc.language_auto_begin = autoBeginCB->isChecked();
1732 rc.language_auto_end = autoEndCB->isChecked();
1733 rc.language_use_babel = useBabelCB->isChecked();
1734 rc.language_global_options = globalCB->isChecked();
1735 rc.language_package = fromqstr(languagePackageED->text());
1736 rc.language_command_begin = fromqstr(startCommandED->text());
1737 rc.language_command_end = fromqstr(endCommandED->text());
1738 rc.default_language = fromqstr(
1739 defaultLanguageCO->itemData(defaultLanguageCO->currentIndex()).toString());
1740 rc.gui_language = fromqstr(
1741 uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString());
1745 void PrefLanguage::update(LyXRC const & rc)
1747 // FIXME: remove rtl_support bool
1748 rtlGB->setChecked(rc.rtl_support);
1749 if (rc.visual_cursor)
1750 visualCursorRB->setChecked(true);
1752 logicalCursorRB->setChecked(true);
1753 markForeignCB->setChecked(rc.mark_foreign_language);
1754 autoBeginCB->setChecked(rc.language_auto_begin);
1755 autoEndCB->setChecked(rc.language_auto_end);
1756 useBabelCB->setChecked(rc.language_use_babel);
1757 globalCB->setChecked(rc.language_global_options);
1758 languagePackageED->setText(toqstr(rc.language_package));
1759 startCommandED->setText(toqstr(rc.language_command_begin));
1760 endCommandED->setText(toqstr(rc.language_command_end));
1762 int pos = defaultLanguageCO->findData(toqstr(rc.default_language));
1763 defaultLanguageCO->setCurrentIndex(pos);
1764 pos = uiLanguageCO->findData(toqstr(rc.gui_language));
1765 uiLanguageCO->blockSignals(true);
1766 uiLanguageCO->setCurrentIndex(pos);
1767 uiLanguageCO->blockSignals(false);
1771 /////////////////////////////////////////////////////////////////////
1775 /////////////////////////////////////////////////////////////////////
1777 PrefPrinter::PrefPrinter(GuiPreferences * form)
1778 : PrefModule(qt_(catOutput), qt_("Printer"), form)
1782 connect(printerAdaptCB, SIGNAL(clicked()),
1783 this, SIGNAL(changed()));
1784 connect(printerCommandED, SIGNAL(textChanged(QString)),
1785 this, SIGNAL(changed()));
1786 connect(printerNameED, SIGNAL(textChanged(QString)),
1787 this, SIGNAL(changed()));
1788 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
1789 this, SIGNAL(changed()));
1790 connect(printerCopiesED, SIGNAL(textChanged(QString)),
1791 this, SIGNAL(changed()));
1792 connect(printerReverseED, SIGNAL(textChanged(QString)),
1793 this, SIGNAL(changed()));
1794 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
1795 this, SIGNAL(changed()));
1796 connect(printerExtensionED, SIGNAL(textChanged(QString)),
1797 this, SIGNAL(changed()));
1798 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
1799 this, SIGNAL(changed()));
1800 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
1801 this, SIGNAL(changed()));
1802 connect(printerEvenED, SIGNAL(textChanged(QString)),
1803 this, SIGNAL(changed()));
1804 connect(printerOddED, SIGNAL(textChanged(QString)),
1805 this, SIGNAL(changed()));
1806 connect(printerCollatedED, SIGNAL(textChanged(QString)),
1807 this, SIGNAL(changed()));
1808 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
1809 this, SIGNAL(changed()));
1810 connect(printerToFileED, SIGNAL(textChanged(QString)),
1811 this, SIGNAL(changed()));
1812 connect(printerExtraED, SIGNAL(textChanged(QString)),
1813 this, SIGNAL(changed()));
1814 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
1815 this, SIGNAL(changed()));
1816 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
1817 this, SIGNAL(changed()));
1821 void PrefPrinter::apply(LyXRC & rc) const
1823 rc.print_adapt_output = printerAdaptCB->isChecked();
1824 rc.print_command = fromqstr(printerCommandED->text());
1825 rc.printer = fromqstr(printerNameED->text());
1827 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1828 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1829 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1830 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1831 rc.print_file_extension = fromqstr(printerExtensionED->text());
1832 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1833 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1834 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1835 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1836 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1837 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1838 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1839 rc.print_extra_options = fromqstr(printerExtraED->text());
1840 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1841 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1845 void PrefPrinter::update(LyXRC const & rc)
1847 printerAdaptCB->setChecked(rc.print_adapt_output);
1848 printerCommandED->setText(toqstr(rc.print_command));
1849 printerNameED->setText(toqstr(rc.printer));
1851 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1852 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1853 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1854 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1855 printerExtensionED->setText(toqstr(rc.print_file_extension));
1856 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1857 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1858 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1859 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1860 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1861 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1862 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1863 printerExtraED->setText(toqstr(rc.print_extra_options));
1864 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1865 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1869 /////////////////////////////////////////////////////////////////////
1871 // PrefUserInterface
1873 /////////////////////////////////////////////////////////////////////
1875 PrefUserInterface::PrefUserInterface(GuiPreferences * form)
1876 : PrefModule(qt_(catLookAndFeel), qt_("User interface"), form)
1880 connect(autoSaveCB, SIGNAL(toggled(bool)),
1881 autoSaveSB, SLOT(setEnabled(bool)));
1882 connect(autoSaveCB, SIGNAL(toggled(bool)),
1883 TextLabel1, SLOT(setEnabled(bool)));
1884 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
1885 this, SIGNAL(changed()));
1886 connect(uiFilePB, SIGNAL(clicked()),
1887 this, SLOT(select_ui()));
1888 connect(uiFileED, SIGNAL(textChanged(QString)),
1889 this, SIGNAL(changed()));
1890 connect(restoreCursorCB, SIGNAL(clicked()),
1891 this, SIGNAL(changed()));
1892 connect(loadSessionCB, SIGNAL(clicked()),
1893 this, SIGNAL(changed()));
1894 connect(allowGeometrySessionCB, SIGNAL(clicked()),
1895 this, SIGNAL(changed()));
1896 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1897 this, SIGNAL(changed()));
1898 connect(autoSaveCB, SIGNAL(clicked()),
1899 this, SIGNAL(changed()));
1900 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1901 this, SIGNAL(changed()));
1902 connect(tooltipCB, SIGNAL(toggled(bool)),
1903 this, SIGNAL(changed()));
1904 lastfilesSB->setMaximum(maxlastfiles);
1908 void PrefUserInterface::apply(LyXRC & rc) const
1910 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1911 rc.use_lastfilepos = restoreCursorCB->isChecked();
1912 rc.load_session = loadSessionCB->isChecked();
1913 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
1914 rc.autosave = autoSaveSB->value() * 60;
1915 rc.make_backup = autoSaveCB->isChecked();
1916 rc.num_lastfiles = lastfilesSB->value();
1917 rc.use_tooltip = tooltipCB->isChecked();
1918 rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
1922 void PrefUserInterface::update(LyXRC const & rc)
1924 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1925 restoreCursorCB->setChecked(rc.use_lastfilepos);
1926 loadSessionCB->setChecked(rc.load_session);
1927 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
1928 // convert to minutes
1929 int mins(rc.autosave / 60);
1930 if (rc.autosave && !mins)
1932 autoSaveSB->setValue(mins);
1933 autoSaveCB->setChecked(rc.make_backup);
1934 lastfilesSB->setValue(rc.num_lastfiles);
1935 tooltipCB->setChecked(rc.use_tooltip);
1936 openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
1940 void PrefUserInterface::select_ui()
1942 QString file = form_->browseUI(internalPath(uiFileED->text()));
1943 if (!file.isEmpty())
1944 uiFileED->setText(file);
1948 /////////////////////////////////////////////////////////////////////
1952 /////////////////////////////////////////////////////////////////////
1954 PrefEdit::PrefEdit(GuiPreferences * form)
1955 : PrefModule(qt_(catEditing), qt_("Control"), form)
1959 connect(cursorFollowsCB, SIGNAL(clicked()),
1960 this, SIGNAL(changed()));
1961 connect(sortEnvironmentsCB, SIGNAL(clicked()),
1962 this, SIGNAL(changed()));
1963 connect(groupEnvironmentsCB, SIGNAL(clicked()),
1964 this, SIGNAL(changed()));
1965 connect(macroEditStyleCO, SIGNAL(activated(int)),
1966 this, SIGNAL(changed()));
1967 connect(fullscreenLimitGB, SIGNAL(clicked()),
1968 this, SIGNAL(changed()));
1969 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
1970 this, SIGNAL(changed()));
1971 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
1972 this, SIGNAL(changed()));
1973 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
1974 this, SIGNAL(changed()));
1975 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
1976 this, SIGNAL(changed()));
1980 void PrefEdit::apply(LyXRC & rc) const
1982 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1983 rc.sort_layouts = sortEnvironmentsCB->isChecked();
1984 rc.group_layouts = groupEnvironmentsCB->isChecked();
1985 switch (macroEditStyleCO->currentIndex()) {
1986 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
1987 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
1988 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
1990 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
1991 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
1992 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
1993 rc.full_screen_width = fullscreenWidthSB->value();
1994 rc.full_screen_limit = fullscreenLimitGB->isChecked();
1998 void PrefEdit::update(LyXRC const & rc)
2000 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
2001 sortEnvironmentsCB->setChecked(rc.sort_layouts);
2002 groupEnvironmentsCB->setChecked(rc.group_layouts);
2003 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
2004 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
2005 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
2006 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
2007 fullscreenWidthSB->setValue(rc.full_screen_width);
2008 fullscreenLimitGB->setChecked(rc.full_screen_limit);
2012 /////////////////////////////////////////////////////////////////////
2016 /////////////////////////////////////////////////////////////////////
2019 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
2021 Ui::shortcutUi::setupUi(this);
2022 QDialog::setModal(true);
2026 PrefShortcuts::PrefShortcuts(GuiPreferences * form)
2027 : PrefModule(qt_(catEditing), qt_("Shortcuts"), form)
2031 shortcutsTW->setColumnCount(2);
2032 shortcutsTW->headerItem()->setText(0, qt_("Function"));
2033 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
2034 shortcutsTW->setSortingEnabled(true);
2035 // Multi-selection can be annoying.
2036 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
2038 connect(bindFilePB, SIGNAL(clicked()),
2039 this, SLOT(select_bind()));
2040 connect(bindFileED, SIGNAL(textChanged(QString)),
2041 this, SIGNAL(changed()));
2042 connect(removePB, SIGNAL(clicked()),
2043 this, SIGNAL(changed()));
2045 shortcut_ = new GuiShortcutDialog(this);
2046 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
2047 shortcut_bc_.setOK(shortcut_->okPB);
2048 shortcut_bc_.setCancel(shortcut_->cancelPB);
2050 connect(shortcut_->okPB, SIGNAL(clicked()),
2051 shortcut_, SLOT(accept()));
2052 connect(shortcut_->okPB, SIGNAL(clicked()),
2053 this, SIGNAL(changed()));
2054 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2055 shortcut_, SLOT(reject()));
2056 connect(shortcut_->clearPB, SIGNAL(clicked()),
2057 this, SLOT(shortcut_clearPB_pressed()));
2058 connect(shortcut_->okPB, SIGNAL(clicked()),
2059 this, SLOT(shortcut_okPB_pressed()));
2063 void PrefShortcuts::apply(LyXRC & rc) const
2065 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
2066 // write user_bind and user_unbind to .lyx/bind/user.bind
2067 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
2068 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
2069 lyxerr << "LyX could not create the user bind directory '"
2070 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2073 if (!bind_dir.isDirWritable()) {
2074 lyxerr << "LyX could not write to the user bind directory '"
2075 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2078 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
2079 user_bind_.write(user_bind_file.toFilesystemEncoding(), false, false);
2080 user_unbind_.write(user_bind_file.toFilesystemEncoding(), true, true);
2081 // immediately apply the keybindings. Why this is not done before?
2082 // The good thing is that the menus are updated automatically.
2083 theTopLevelKeymap().clear();
2084 theTopLevelKeymap().read("site");
2085 theTopLevelKeymap().read(rc.bind_file);
2086 theTopLevelKeymap().read("user");
2090 void PrefShortcuts::update(LyXRC const & rc)
2092 bindFileED->setText(toqstr(external_path(rc.bind_file)));
2094 system_bind_.clear();
2096 user_unbind_.clear();
2097 system_bind_.read(rc.bind_file);
2098 // \unbind in user.bind is added to user_unbind_
2099 user_bind_.read("user", &user_unbind_);
2100 updateShortcutsTW();
2104 void PrefShortcuts::updateShortcutsTW()
2106 shortcutsTW->clear();
2108 editItem_ = new QTreeWidgetItem(shortcutsTW);
2109 editItem_->setText(0, qt_("Cursor, Mouse and Editing functions"));
2110 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2112 mathItem_ = new QTreeWidgetItem(shortcutsTW);
2113 mathItem_->setText(0, qt_("Mathematical Symbols"));
2114 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2116 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2117 bufferItem_->setText(0, qt_("Document and Window"));
2118 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2120 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2121 layoutItem_->setText(0, qt_("Font, Layouts and Textclasses"));
2122 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2124 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2125 systemItem_->setText(0, qt_("System and Miscellaneous"));
2126 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2128 // listBindings(unbound=true) lists all bound and unbound lfuns
2129 // Items in this list is tagged by its source.
2130 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2131 static_cast<int>(System));
2132 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2133 static_cast<int>(UserBind));
2134 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2135 static_cast<int>(UserUnbind));
2136 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2137 user_bindinglist.end());
2138 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2139 user_unbindinglist.end());
2141 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2142 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2143 for (; it != it_end; ++it)
2144 insertShortcutItem(it->request, it->sequence, ItemType(it->tag));
2146 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2147 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2148 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2149 modifyPB->setEnabled(!items.isEmpty());
2151 shortcutsTW->resizeColumnToContents(0);
2155 void PrefShortcuts::setItemType(QTreeWidgetItem * item, ItemType tag)
2157 item->setData(0, Qt::UserRole, QVariant(tag));
2167 font.setStrikeOut(true);
2169 // this item is not displayed now.
2170 case UserExtraUnbind:
2171 font.setStrikeOut(true);
2175 item->setFont(1, font);
2179 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2180 KeySequence const & seq, ItemType tag)
2182 FuncCode action = lfun.action;
2183 string const action_name = lyxaction.getActionName(action);
2184 QString const lfun_name = toqstr(from_utf8(action_name)
2185 + ' ' + lfun.argument());
2186 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2187 ItemType item_tag = tag;
2189 QTreeWidgetItem * newItem = 0;
2190 // for unbind items, try to find an existing item in the system bind list
2191 if (tag == UserUnbind) {
2192 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2193 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2194 for (int i = 0; i < items.size(); ++i) {
2195 if (items[i]->text(1) == shortcut)
2199 // if not found, this unbind item is UserExtraUnbind
2200 // Such an item is not displayed to avoid confusion (what is
2201 // unmatched removed?).
2203 item_tag = UserExtraUnbind;
2208 switch(lyxaction.getActionType(action)) {
2209 case LyXAction::Hidden:
2211 case LyXAction::Edit:
2212 newItem = new QTreeWidgetItem(editItem_);
2214 case LyXAction::Math:
2215 newItem = new QTreeWidgetItem(mathItem_);
2217 case LyXAction::Buffer:
2218 newItem = new QTreeWidgetItem(bufferItem_);
2220 case LyXAction::Layout:
2221 newItem = new QTreeWidgetItem(layoutItem_);
2223 case LyXAction::System:
2224 newItem = new QTreeWidgetItem(systemItem_);
2227 // this should not happen
2228 newItem = new QTreeWidgetItem(shortcutsTW);
2232 newItem->setText(0, lfun_name);
2233 newItem->setText(1, shortcut);
2234 // record BindFile representation to recover KeySequence when needed.
2235 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2236 setItemType(newItem, item_tag);
2241 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2243 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2244 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2245 modifyPB->setEnabled(!items.isEmpty());
2246 if (items.isEmpty())
2249 ItemType tag = static_cast<ItemType>(items[0]->data(0, Qt::UserRole).toInt());
2250 if (tag == UserUnbind)
2251 removePB->setText(qt_("Res&tore"));
2253 removePB->setText(qt_("Remo&ve"));
2257 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2263 void PrefShortcuts::modifyShortcut()
2265 QTreeWidgetItem * item = shortcutsTW->currentItem();
2266 if (item->flags() & Qt::ItemIsSelectable) {
2267 shortcut_->lfunLE->setText(item->text(0));
2268 shortcut_->shortcutLE->setText(item->text(1));
2269 shortcut_->shortcutLE->setFocus();
2275 void PrefShortcuts::select_bind()
2277 QString file = form_->browsebind(internalPath(bindFileED->text()));
2278 if (!file.isEmpty()) {
2279 bindFileED->setText(file);
2280 system_bind_ = KeyMap();
2281 system_bind_.read(fromqstr(file));
2282 updateShortcutsTW();
2287 void PrefShortcuts::on_modifyPB_pressed()
2293 void PrefShortcuts::on_newPB_pressed()
2295 shortcut_->lfunLE->clear();
2296 shortcut_->shortcutLE->reset();
2301 void PrefShortcuts::on_removePB_pressed()
2303 // it seems that only one item can be selected, but I am
2304 // removing all selected items anyway.
2305 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2306 for (int i = 0; i < items.size(); ++i) {
2307 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2308 string lfun = fromqstr(items[i]->text(0));
2309 FuncRequest func = lyxaction.lookupFunc(lfun);
2310 ItemType tag = static_cast<ItemType>(items[i]->data(0, Qt::UserRole).toInt());
2314 // for system bind, we do not touch the item
2315 // but add an user unbind item
2316 user_unbind_.bind(shortcut, func);
2317 setItemType(items[i], UserUnbind);
2318 removePB->setText(qt_("Res&tore"));
2322 // for user_bind, we remove this bind
2323 QTreeWidgetItem * parent = items[i]->parent();
2324 int itemIdx = parent->indexOfChild(items[i]);
2325 parent->takeChild(itemIdx);
2327 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2329 shortcutsTW->scrollToItem(parent);
2330 user_bind_.unbind(shortcut, func);
2334 // for user_unbind, we remove the unbind, and the item
2335 // become System again.
2336 user_unbind_.unbind(shortcut, func);
2337 setItemType(items[i], System);
2338 removePB->setText(qt_("Remo&ve"));
2341 case UserExtraUnbind: {
2342 // for user unbind that is not in system bind file,
2343 // remove this unbind file
2344 QTreeWidgetItem * parent = items[i]->parent();
2345 parent->takeChild(parent->indexOfChild(items[i]));
2346 user_unbind_.unbind(shortcut, func);
2353 void PrefShortcuts::on_searchLE_textEdited()
2355 if (searchLE->text().isEmpty()) {
2356 // show all hidden items
2357 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2359 shortcutsTW->setItemHidden(*it++, false);
2362 // search both columns
2363 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2364 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2365 matched += shortcutsTW->findItems(searchLE->text(),
2366 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2368 // hide everyone (to avoid searching in matched QList repeatedly
2369 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2371 shortcutsTW->setItemHidden(*it++, true);
2372 // show matched items
2373 for (int i = 0; i < matched.size(); ++i) {
2374 shortcutsTW->setItemHidden(matched[i], false);
2375 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2380 void PrefShortcuts::shortcut_okPB_pressed()
2382 string lfun = fromqstr(shortcut_->lfunLE->text());
2383 FuncRequest func = lyxaction.lookupFunc(lfun);
2385 if (func.action == LFUN_UNKNOWN_ACTION) {
2386 Alert::error(_("Failed to create shortcut"),
2387 _("Unknown or invalid LyX function"));
2391 KeySequence k = shortcut_->shortcutLE->getKeySequence();
2392 if (k.length() == 0) {
2393 Alert::error(_("Failed to create shortcut"),
2394 _("Invalid or empty key sequence"));
2398 // if both lfun and shortcut is valid
2399 if (user_bind_.hasBinding(k, func) || system_bind_.hasBinding(k, func)) {
2400 Alert::error(_("Failed to create shortcut"),
2401 _("Shortcut is already defined"));
2405 QTreeWidgetItem * item = insertShortcutItem(func, k, UserBind);
2407 user_bind_.bind(&k, func);
2408 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2409 shortcutsTW->setItemExpanded(item->parent(), true);
2410 shortcutsTW->scrollToItem(item);
2412 Alert::error(_("Failed to create shortcut"),
2413 _("Can not insert shortcut to the list"));
2419 void PrefShortcuts::shortcut_clearPB_pressed()
2421 shortcut_->shortcutLE->reset();
2422 shortcut_->shortcutLE->setFocus();
2426 /////////////////////////////////////////////////////////////////////
2430 /////////////////////////////////////////////////////////////////////
2432 PrefIdentity::PrefIdentity(GuiPreferences * form)
2433 : PrefModule(QString(), qt_("Identity"), form)
2437 connect(nameED, SIGNAL(textChanged(QString)),
2438 this, SIGNAL(changed()));
2439 connect(emailED, SIGNAL(textChanged(QString)),
2440 this, SIGNAL(changed()));
2444 void PrefIdentity::apply(LyXRC & rc) const
2446 rc.user_name = fromqstr(nameED->text());
2447 rc.user_email = fromqstr(emailED->text());
2451 void PrefIdentity::update(LyXRC const & rc)
2453 nameED->setText(toqstr(rc.user_name));
2454 emailED->setText(toqstr(rc.user_email));
2459 /////////////////////////////////////////////////////////////////////
2463 /////////////////////////////////////////////////////////////////////
2465 GuiPreferences::GuiPreferences(GuiView & lv)
2466 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2470 QDialog::setModal(false);
2472 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2473 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2474 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2475 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2477 addModule(new PrefUserInterface(this));
2478 addModule(new PrefEdit(this));
2479 addModule(new PrefShortcuts(this));
2480 addModule(new PrefScreenFonts(this));
2481 addModule(new PrefColors(this));
2482 addModule(new PrefDisplay(this));
2483 addModule(new PrefInput(this));
2484 addModule(new PrefCompletion(this));
2486 addModule(new PrefPaths(this));
2488 addModule(new PrefIdentity(this));
2490 addModule(new PrefLanguage(this));
2491 addModule(new PrefSpellchecker(this));
2493 addModule(new PrefPrinter(this));
2494 addModule(new PrefDate(this));
2495 addModule(new PrefPlaintext(this));
2496 addModule(new PrefLatex(this));
2498 PrefConverters * converters = new PrefConverters(this);
2499 PrefFileformats * formats = new PrefFileformats(this);
2500 connect(formats, SIGNAL(formatsChanged()),
2501 converters, SLOT(updateGui()));
2502 addModule(converters);
2505 prefsPS->setCurrentPanel(qt_("User interface"));
2506 // FIXME: hack to work around resizing bug in Qt >= 4.2
2507 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2508 #if QT_VERSION >= 0x040200
2509 prefsPS->updateGeometry();
2512 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2514 bc().setApply(applyPB);
2515 bc().setCancel(closePB);
2516 bc().setRestore(restorePB);
2520 void GuiPreferences::addModule(PrefModule * module)
2522 LASSERT(module, /**/);
2523 if (module->category().isEmpty())
2524 prefsPS->addPanel(module, module->title());
2526 prefsPS->addPanel(module, module->title(), module->category());
2527 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2528 modules_.push_back(module);
2532 void GuiPreferences::change_adaptor()
2538 void GuiPreferences::apply(LyXRC & rc) const
2540 size_t end = modules_.size();
2541 for (size_t i = 0; i != end; ++i)
2542 modules_[i]->apply(rc);
2546 void GuiPreferences::updateRc(LyXRC const & rc)
2548 size_t const end = modules_.size();
2549 for (size_t i = 0; i != end; ++i)
2550 modules_[i]->update(rc);
2554 void GuiPreferences::applyView()
2559 bool GuiPreferences::initialiseParams(string const &)
2562 formats_ = lyx::formats;
2563 converters_ = theConverters();
2564 converters_.update(formats_);
2565 movers_ = theMovers();
2567 update_screen_font_ = false;
2574 void GuiPreferences::dispatchParams()
2577 rc_.write(ss, true);
2578 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
2579 // FIXME: these need lfuns
2581 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
2583 lyx::formats = formats_;
2585 theConverters() = converters_;
2586 theConverters().update(lyx::formats);
2587 theConverters().buildGraph();
2589 theMovers() = movers_;
2591 vector<string>::const_iterator it = colors_.begin();
2592 vector<string>::const_iterator const end = colors_.end();
2593 for (; it != end; ++it)
2594 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
2597 if (update_screen_font_) {
2598 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2599 update_screen_font_ = false;
2602 // The Save button has been pressed
2604 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
2608 void GuiPreferences::setColor(ColorCode col, QString const & hex)
2610 colors_.push_back(lcolor.getLyXName(col) + ' ' + fromqstr(hex));
2614 void GuiPreferences::updateScreenFonts()
2616 update_screen_font_ = true;
2620 QString GuiPreferences::browsebind(QString const & file) const
2622 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
2623 QStringList(qt_("LyX bind files (*.bind)")));
2627 QString GuiPreferences::browseUI(QString const & file) const
2629 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
2630 QStringList(qt_("LyX UI files (*.ui)")));
2634 QString GuiPreferences::browsekbmap(QString const & file) const
2636 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
2637 QStringList(qt_("LyX keyboard maps (*.kmap)")));
2641 QString GuiPreferences::browsedict(QString const & file) const
2643 return browseFile(file, qt_("Choose personal dictionary"),
2644 QStringList(lyxrc.use_spell_lib ? qt_("*.pws") : qt_("*.ispell")));
2648 QString GuiPreferences::browse(QString const & file,
2649 QString const & title) const
2651 return browseFile(file, title, QStringList(), true);
2655 // We support less paper sizes than the document dialog
2656 // Therefore this adjustment is needed.
2657 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
2661 return PAPER_DEFAULT;
2663 return PAPER_USLETTER;
2665 return PAPER_USLEGAL;
2667 return PAPER_USEXECUTIVE;
2677 // should not happen
2678 return PAPER_DEFAULT;
2683 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
2685 switch (papersize) {
2688 case PAPER_USLETTER:
2692 case PAPER_USEXECUTIVE:
2703 // should not happen
2709 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
2712 } // namespace frontend
2715 #include "GuiPrefs_moc.cpp"