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()));
338 connect(plaintextRoffED, SIGNAL(textChanged(QString)),
339 this, SIGNAL(changed()));
343 void PrefPlaintext::apply(LyXRC & rc) const
345 rc.plaintext_linelen = plaintextLinelengthSB->value();
346 rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
350 void PrefPlaintext::update(LyXRC const & rc)
352 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
353 plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
357 /////////////////////////////////////////////////////////////////////
361 /////////////////////////////////////////////////////////////////////
363 PrefDate::PrefDate(GuiPreferences * form)
364 : PrefModule(qt_(catOutput), qt_("Date format"), form)
367 connect(DateED, SIGNAL(textChanged(QString)),
368 this, SIGNAL(changed()));
372 void PrefDate::apply(LyXRC & rc) const
374 rc.date_insert_format = fromqstr(DateED->text());
378 void PrefDate::update(LyXRC const & rc)
380 DateED->setText(toqstr(rc.date_insert_format));
384 /////////////////////////////////////////////////////////////////////
388 /////////////////////////////////////////////////////////////////////
390 PrefInput::PrefInput(GuiPreferences * form)
391 : PrefModule(qt_(catEditing), qt_("Keyboard/Mouse"), form)
395 connect(keymapCB, SIGNAL(clicked()),
396 this, SIGNAL(changed()));
397 connect(firstKeymapED, SIGNAL(textChanged(QString)),
398 this, SIGNAL(changed()));
399 connect(secondKeymapED, SIGNAL(textChanged(QString)),
400 this, SIGNAL(changed()));
401 connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
402 this, SIGNAL(changed()));
406 void PrefInput::apply(LyXRC & rc) const
408 // FIXME: can derive CB from the two EDs
409 rc.use_kbmap = keymapCB->isChecked();
410 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
411 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
412 rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
416 void PrefInput::update(LyXRC const & rc)
418 // FIXME: can derive CB from the two EDs
419 keymapCB->setChecked(rc.use_kbmap);
420 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
421 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
422 mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
426 QString PrefInput::testKeymap(QString const & keymap)
428 return form_->browsekbmap(internalPath(keymap));
432 void PrefInput::on_firstKeymapPB_clicked(bool)
434 QString const file = testKeymap(firstKeymapED->text());
436 firstKeymapED->setText(file);
440 void PrefInput::on_secondKeymapPB_clicked(bool)
442 QString const file = testKeymap(secondKeymapED->text());
444 secondKeymapED->setText(file);
448 void PrefInput::on_keymapCB_toggled(bool keymap)
450 firstKeymapLA->setEnabled(keymap);
451 secondKeymapLA->setEnabled(keymap);
452 firstKeymapED->setEnabled(keymap);
453 secondKeymapED->setEnabled(keymap);
454 firstKeymapPB->setEnabled(keymap);
455 secondKeymapPB->setEnabled(keymap);
459 /////////////////////////////////////////////////////////////////////
463 /////////////////////////////////////////////////////////////////////
465 PrefCompletion::PrefCompletion(GuiPreferences * form)
466 : PrefModule(qt_(catEditing), qt_("Input Completion"), form)
470 connect(inlineDelaySB, SIGNAL(valueChanged(double)),
471 this, SIGNAL(changed()));
472 connect(inlineMathCB, SIGNAL(clicked()),
473 this, SIGNAL(changed()));
474 connect(inlineTextCB, SIGNAL(clicked()),
475 this, SIGNAL(changed()));
476 connect(inlineDotsCB, SIGNAL(clicked()),
477 this, SIGNAL(changed()));
478 connect(popupDelaySB, SIGNAL(valueChanged(double)),
479 this, SIGNAL(changed()));
480 connect(popupMathCB, SIGNAL(clicked()),
481 this, SIGNAL(changed()));
482 connect(popupTextCB, SIGNAL(clicked()),
483 this, SIGNAL(changed()));
484 connect(popupAfterCompleteCB, SIGNAL(clicked()),
485 this, SIGNAL(changed()));
486 connect(cursorTextCB, SIGNAL(clicked()),
487 this, SIGNAL(changed()));
491 void PrefCompletion::apply(LyXRC & rc) const
493 rc.completion_inline_delay = inlineDelaySB->value();
494 rc.completion_inline_math = inlineMathCB->isChecked();
495 rc.completion_inline_text = inlineTextCB->isChecked();
496 rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
497 rc.completion_popup_delay = popupDelaySB->value();
498 rc.completion_popup_math = popupMathCB->isChecked();
499 rc.completion_popup_text = popupTextCB->isChecked();
500 rc.completion_cursor_text = cursorTextCB->isChecked();
501 rc.completion_popup_after_complete =
502 popupAfterCompleteCB->isChecked();
506 void PrefCompletion::update(LyXRC const & rc)
508 inlineDelaySB->setValue(rc.completion_inline_delay);
509 inlineMathCB->setChecked(rc.completion_inline_math);
510 inlineTextCB->setChecked(rc.completion_inline_text);
511 inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
512 popupDelaySB->setValue(rc.completion_popup_delay);
513 popupMathCB->setChecked(rc.completion_popup_math);
514 popupTextCB->setChecked(rc.completion_popup_text);
515 cursorTextCB->setChecked(rc.completion_cursor_text);
516 popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
521 /////////////////////////////////////////////////////////////////////
525 /////////////////////////////////////////////////////////////////////
527 PrefLatex::PrefLatex(GuiPreferences * form)
528 : PrefModule(qt_(catOutput), qt_("LaTeX"), form)
531 connect(latexEncodingED, SIGNAL(textChanged(QString)),
532 this, SIGNAL(changed()));
533 connect(latexChecktexED, SIGNAL(textChanged(QString)),
534 this, SIGNAL(changed()));
535 connect(latexBibtexED, SIGNAL(textChanged(QString)),
536 this, SIGNAL(changed()));
537 connect(latexIndexED, SIGNAL(textChanged(QString)),
538 this, SIGNAL(changed()));
539 connect(latexAutoresetCB, SIGNAL(clicked()),
540 this, SIGNAL(changed()));
541 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
542 this, SIGNAL(changed()));
543 connect(latexPaperSizeCO, SIGNAL(activated(int)),
544 this, SIGNAL(changed()));
546 #if defined(__CYGWIN__) || defined(_WIN32)
547 pathCB->setVisible(true);
548 connect(pathCB, SIGNAL(clicked()),
549 this, SIGNAL(changed()));
551 pathCB->setVisible(false);
556 void PrefLatex::apply(LyXRC & rc) const
558 rc.fontenc = fromqstr(latexEncodingED->text());
559 rc.chktex_command = fromqstr(latexChecktexED->text());
560 rc.bibtex_command = fromqstr(latexBibtexED->text());
561 rc.index_command = fromqstr(latexIndexED->text());
562 rc.nomencl_command = fromqstr(latexNomenclED->text());
563 rc.auto_reset_options = latexAutoresetCB->isChecked();
564 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
565 rc.default_papersize =
566 form_->toPaperSize(latexPaperSizeCO->currentIndex());
567 #if defined(__CYGWIN__) || defined(_WIN32)
568 rc.windows_style_tex_paths = pathCB->isChecked();
573 void PrefLatex::update(LyXRC const & rc)
575 latexEncodingED->setText(toqstr(rc.fontenc));
576 latexChecktexED->setText(toqstr(rc.chktex_command));
577 latexBibtexED->setText(toqstr(rc.bibtex_command));
578 latexIndexED->setText(toqstr(rc.index_command));
579 latexNomenclED->setText(toqstr(rc.nomencl_command));
580 latexAutoresetCB->setChecked(rc.auto_reset_options);
581 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
582 latexPaperSizeCO->setCurrentIndex(
583 form_->fromPaperSize(rc.default_papersize));
584 #if defined(__CYGWIN__) || defined(_WIN32)
585 pathCB->setChecked(rc.windows_style_tex_paths);
590 /////////////////////////////////////////////////////////////////////
594 /////////////////////////////////////////////////////////////////////
596 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form)
597 : PrefModule(qt_(catLookAndFeel), qt_("Screen fonts"), form)
601 connect(screenRomanCO, SIGNAL(activated(QString)),
602 this, SLOT(select_roman(QString)));
603 connect(screenSansCO, SIGNAL(activated(QString)),
604 this, SLOT(select_sans(QString)));
605 connect(screenTypewriterCO, SIGNAL(activated(QString)),
606 this, SLOT(select_typewriter(QString)));
608 QFontDatabase fontdb;
609 QStringList families(fontdb.families());
610 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
611 screenRomanCO->addItem(*it);
612 screenSansCO->addItem(*it);
613 screenTypewriterCO->addItem(*it);
615 connect(screenRomanCO, SIGNAL(activated(QString)),
616 this, SIGNAL(changed()));
617 connect(screenSansCO, SIGNAL(activated(QString)),
618 this, SIGNAL(changed()));
619 connect(screenTypewriterCO, SIGNAL(activated(QString)),
620 this, SIGNAL(changed()));
621 connect(screenZoomSB, SIGNAL(valueChanged(int)),
622 this, SIGNAL(changed()));
623 connect(screenDpiSB, SIGNAL(valueChanged(int)),
624 this, SIGNAL(changed()));
625 connect(screenTinyED, SIGNAL(textChanged(QString)),
626 this, SIGNAL(changed()));
627 connect(screenSmallestED, SIGNAL(textChanged(QString)),
628 this, SIGNAL(changed()));
629 connect(screenSmallerED, SIGNAL(textChanged(QString)),
630 this, SIGNAL(changed()));
631 connect(screenSmallED, SIGNAL(textChanged(QString)),
632 this, SIGNAL(changed()));
633 connect(screenNormalED, SIGNAL(textChanged(QString)),
634 this, SIGNAL(changed()));
635 connect(screenLargeED, SIGNAL(textChanged(QString)),
636 this, SIGNAL(changed()));
637 connect(screenLargerED, SIGNAL(textChanged(QString)),
638 this, SIGNAL(changed()));
639 connect(screenLargestED, SIGNAL(textChanged(QString)),
640 this, SIGNAL(changed()));
641 connect(screenHugeED, SIGNAL(textChanged(QString)),
642 this, SIGNAL(changed()));
643 connect(screenHugerED, SIGNAL(textChanged(QString)),
644 this, SIGNAL(changed()));
645 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
646 this, SIGNAL(changed()));
648 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
649 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
650 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
651 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
652 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
653 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
654 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
655 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
656 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
657 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
661 void PrefScreenFonts::apply(LyXRC & rc) const
663 LyXRC const oldrc = rc;
665 parseFontName(screenRomanCO->currentText(),
666 rc.roman_font_name, rc.roman_font_foundry);
667 parseFontName(screenSansCO->currentText(),
668 rc.sans_font_name, rc.sans_font_foundry);
669 parseFontName(screenTypewriterCO->currentText(),
670 rc.typewriter_font_name, rc.typewriter_font_foundry);
672 rc.zoom = screenZoomSB->value();
673 rc.dpi = screenDpiSB->value();
674 rc.font_sizes[FONT_SIZE_TINY] = fromqstr(screenTinyED->text());
675 rc.font_sizes[FONT_SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
676 rc.font_sizes[FONT_SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
677 rc.font_sizes[FONT_SIZE_SMALL] = fromqstr(screenSmallED->text());
678 rc.font_sizes[FONT_SIZE_NORMAL] = fromqstr(screenNormalED->text());
679 rc.font_sizes[FONT_SIZE_LARGE] = fromqstr(screenLargeED->text());
680 rc.font_sizes[FONT_SIZE_LARGER] = fromqstr(screenLargerED->text());
681 rc.font_sizes[FONT_SIZE_LARGEST] = fromqstr(screenLargestED->text());
682 rc.font_sizes[FONT_SIZE_HUGE] = fromqstr(screenHugeED->text());
683 rc.font_sizes[FONT_SIZE_HUGER] = fromqstr(screenHugerED->text());
684 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
686 if (rc.font_sizes != oldrc.font_sizes
687 || rc.roman_font_name != oldrc.roman_font_name
688 || rc.sans_font_name != oldrc.sans_font_name
689 || rc.typewriter_font_name != oldrc.typewriter_font_name
690 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
691 // The global QPixmapCache is used in GuiPainter to cache text
692 // painting so we must reset it in case any of the above
693 // parameter is changed.
694 QPixmapCache::clear();
695 guiApp->fontLoader().update();
696 form_->updateScreenFonts();
701 void PrefScreenFonts::update(LyXRC const & rc)
703 setComboxFont(screenRomanCO, rc.roman_font_name,
704 rc.roman_font_foundry);
705 setComboxFont(screenSansCO, rc.sans_font_name,
706 rc.sans_font_foundry);
707 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
708 rc.typewriter_font_foundry);
710 select_roman(screenRomanCO->currentText());
711 select_sans(screenSansCO->currentText());
712 select_typewriter(screenTypewriterCO->currentText());
714 screenZoomSB->setValue(rc.zoom);
715 screenDpiSB->setValue(rc.dpi);
716 screenTinyED->setText(toqstr(rc.font_sizes[FONT_SIZE_TINY]));
717 screenSmallestED->setText(toqstr(rc.font_sizes[FONT_SIZE_SCRIPT]));
718 screenSmallerED->setText(toqstr(rc.font_sizes[FONT_SIZE_FOOTNOTE]));
719 screenSmallED->setText(toqstr(rc.font_sizes[FONT_SIZE_SMALL]));
720 screenNormalED->setText(toqstr(rc.font_sizes[FONT_SIZE_NORMAL]));
721 screenLargeED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGE]));
722 screenLargerED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGER]));
723 screenLargestED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGEST]));
724 screenHugeED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGE]));
725 screenHugerED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGER]));
727 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
728 #if defined(Q_WS_X11)
729 pixmapCacheCB->setEnabled(false);
735 void PrefScreenFonts::select_roman(const QString & name)
737 screenRomanFE->set(QFont(name), name);
741 void PrefScreenFonts::select_sans(const QString & name)
743 screenSansFE->set(QFont(name), name);
747 void PrefScreenFonts::select_typewriter(const QString & name)
749 screenTypewriterFE->set(QFont(name), name);
753 /////////////////////////////////////////////////////////////////////
757 /////////////////////////////////////////////////////////////////////
763 bool operator()(ColorCode lhs, ColorCode rhs) const {
764 return lcolor.getGUIName(lhs) < lcolor.getGUIName(rhs);
770 PrefColors::PrefColors(GuiPreferences * form)
771 : PrefModule(qt_(catLookAndFeel), qt_("Colors"), form)
775 // FIXME: all of this initialization should be put into the controller.
776 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
777 // for some discussion of why that is not trivial.
778 QPixmap icon(32, 32);
779 for (int i = 0; i < Color_ignore; ++i) {
780 ColorCode lc = static_cast<ColorCode>(i);
788 || lc == Color_magenta
789 || lc == Color_yellow
790 || lc == Color_inherit
791 || lc == Color_ignore) continue;
793 lcolors_.push_back(lc);
795 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
796 vector<ColorCode>::const_iterator cit = lcolors_.begin();
797 vector<ColorCode>::const_iterator const end = lcolors_.end();
798 for (; cit != end; ++cit) {
799 (void) new QListWidgetItem(QIcon(icon),
800 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
802 curcolors_.resize(lcolors_.size());
803 newcolors_.resize(lcolors_.size());
804 // End initialization
806 connect(colorChangePB, SIGNAL(clicked()),
807 this, SLOT(change_color()));
808 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
809 this, SLOT(change_lyxObjects_selection()));
810 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
811 this, SLOT(change_color()));
815 void PrefColors::apply(LyXRC & /*rc*/) const
817 for (unsigned int i = 0; i < lcolors_.size(); ++i)
818 if (curcolors_[i] != newcolors_[i])
819 form_->setColor(lcolors_[i], newcolors_[i]);
823 void PrefColors::update(LyXRC const & /*rc*/)
825 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
826 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
827 QPixmap coloritem(32, 32);
828 coloritem.fill(color);
829 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
830 newcolors_[i] = curcolors_[i] = color.name();
832 change_lyxObjects_selection();
836 void PrefColors::change_color()
838 int const row = lyxObjectsLW->currentRow();
844 QString const color = newcolors_[row];
845 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
847 if (c.isValid() && c.name() != color) {
848 newcolors_[row] = c.name();
849 QPixmap coloritem(32, 32);
851 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
857 void PrefColors::change_lyxObjects_selection()
859 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
863 /////////////////////////////////////////////////////////////////////
867 /////////////////////////////////////////////////////////////////////
869 PrefDisplay::PrefDisplay(GuiPreferences * form)
870 : PrefModule(qt_(catLookAndFeel), qt_("Graphics"), form)
873 connect(displayGraphicsCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
874 connect(instantPreviewCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
878 void PrefDisplay::apply(LyXRC & rc) const
880 switch (instantPreviewCO->currentIndex()) {
881 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
882 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
883 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
886 rc.display_graphics = displayGraphicsCB->isChecked();
888 // FIXME!! The graphics cache no longer has a changeDisplay method.
890 if (old_value != rc.display_graphics) {
891 graphics::GCache & gc = graphics::GCache::get();
898 void PrefDisplay::update(LyXRC const & rc)
900 switch (rc.preview) {
901 case LyXRC::PREVIEW_OFF:
902 instantPreviewCO->setCurrentIndex(0);
904 case LyXRC::PREVIEW_NO_MATH :
905 instantPreviewCO->setCurrentIndex(1);
907 case LyXRC::PREVIEW_ON :
908 instantPreviewCO->setCurrentIndex(2);
912 displayGraphicsCB->setChecked(rc.display_graphics);
913 instantPreviewCO->setEnabled(rc.display_graphics);
917 /////////////////////////////////////////////////////////////////////
921 /////////////////////////////////////////////////////////////////////
923 PrefPaths::PrefPaths(GuiPreferences * form)
924 : PrefModule(QString(), qt_("Paths"), form)
927 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(select_exampledir()));
928 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
929 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
930 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
931 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
932 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
933 connect(workingDirED, SIGNAL(textChanged(QString)),
934 this, SIGNAL(changed()));
935 connect(exampleDirED, SIGNAL(textChanged(QString)),
936 this, SIGNAL(changed()));
937 connect(templateDirED, SIGNAL(textChanged(QString)),
938 this, SIGNAL(changed()));
939 connect(backupDirED, SIGNAL(textChanged(QString)),
940 this, SIGNAL(changed()));
941 connect(tempDirED, SIGNAL(textChanged(QString)),
942 this, SIGNAL(changed()));
943 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
944 this, SIGNAL(changed()));
945 connect(pathPrefixED, SIGNAL(textChanged(QString)),
946 this, SIGNAL(changed()));
950 void PrefPaths::apply(LyXRC & rc) const
952 rc.document_path = internal_path(fromqstr(workingDirED->text()));
953 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
954 rc.template_path = internal_path(fromqstr(templateDirED->text()));
955 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
956 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
957 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
958 // FIXME: should be a checkbox only
959 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
963 void PrefPaths::update(LyXRC const & rc)
965 workingDirED->setText(toqstr(external_path(rc.document_path)));
966 exampleDirED->setText(toqstr(external_path(rc.example_path)));
967 templateDirED->setText(toqstr(external_path(rc.template_path)));
968 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
969 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
970 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
971 // FIXME: should be a checkbox only
972 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
976 void PrefPaths::select_exampledir()
978 QString file = browseDir(internalPath(exampleDirED->text()),
979 qt_("Select directory for example files"));
981 exampleDirED->setText(file);
985 void PrefPaths::select_templatedir()
987 QString file = browseDir(internalPath(templateDirED->text()),
988 qt_("Select a document templates directory"));
990 templateDirED->setText(file);
994 void PrefPaths::select_tempdir()
996 QString file = browseDir(internalPath(tempDirED->text()),
997 qt_("Select a temporary directory"));
999 tempDirED->setText(file);
1003 void PrefPaths::select_backupdir()
1005 QString file = browseDir(internalPath(backupDirED->text()),
1006 qt_("Select a backups directory"));
1007 if (!file.isEmpty())
1008 backupDirED->setText(file);
1012 void PrefPaths::select_workingdir()
1014 QString file = browseDir(internalPath(workingDirED->text()),
1015 qt_("Select a document directory"));
1016 if (!file.isEmpty())
1017 workingDirED->setText(file);
1021 void PrefPaths::select_lyxpipe()
1023 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1024 qt_("Give a filename for the LyX server pipe"));
1025 if (!file.isEmpty())
1026 lyxserverDirED->setText(file);
1030 /////////////////////////////////////////////////////////////////////
1034 /////////////////////////////////////////////////////////////////////
1036 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form)
1037 : PrefModule(qt_(catLanguage), qt_("Spellchecker"), form)
1041 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
1042 spellCommandCO->setEnabled(false);
1044 connect(altLanguageED, SIGNAL(textChanged(QString)),
1045 this, SIGNAL(changed()));
1046 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1047 this, SIGNAL(changed()));
1048 connect(persDictionaryED, SIGNAL(textChanged(QString)),
1049 this, SIGNAL(changed()));
1050 connect(compoundWordCB, SIGNAL(clicked()),
1051 this, SIGNAL(changed()));
1052 connect(inputEncodingCB, SIGNAL(clicked()),
1053 this, SIGNAL(changed()));
1055 spellCommandCO->addItem(qt_("aspell"));
1057 spellCommandCO->addItem(qt_("aspell (library)"));
1062 void PrefSpellchecker::apply(LyXRC & rc) const
1064 switch (spellCommandCO->currentIndex()) {
1066 rc.use_spell_lib = false;
1067 rc.spellchecker_command = fromqstr(spellCommandCO->currentText());
1070 rc.use_spell_lib = true;
1074 // FIXME: remove spellchecker_use_alt_lang
1075 rc.spellchecker_alt_lang = fromqstr(altLanguageED->text());
1076 rc.spellchecker_use_alt_lang = !rc.spellchecker_alt_lang.empty();
1077 // FIXME: remove spellchecker_use_esc_chars
1078 rc.spellchecker_esc_chars = fromqstr(escapeCharactersED->text());
1079 rc.spellchecker_use_esc_chars = !rc.spellchecker_esc_chars.empty();
1080 // FIXME: remove spellchecker_use_pers_dict
1081 rc.spellchecker_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
1082 rc.spellchecker_use_pers_dict = !rc.spellchecker_pers_dict.empty();
1083 rc.spellchecker_accept_compound = compoundWordCB->isChecked();
1084 rc.spellchecker_use_input_encoding = inputEncodingCB->isChecked();
1088 void PrefSpellchecker::update(LyXRC const & rc)
1090 spellCommandCO->setCurrentIndex(0);
1092 if (rc.spellchecker_command == "aspell")
1093 spellCommandCO->setCurrentIndex(0);
1095 if (rc.use_spell_lib) {
1096 #if defined(USE_ASPELL)
1097 spellCommandCO->setCurrentIndex(1);
1101 // FIXME: remove spellchecker_use_alt_lang
1102 altLanguageED->setText(toqstr(rc.spellchecker_alt_lang));
1103 // FIXME: remove spellchecker_use_esc_chars
1104 escapeCharactersED->setText(toqstr(rc.spellchecker_esc_chars));
1105 // FIXME: remove spellchecker_use_pers_dict
1106 persDictionaryED->setText(toqstr(external_path(rc.spellchecker_pers_dict)));
1107 compoundWordCB->setChecked(rc.spellchecker_accept_compound);
1108 inputEncodingCB->setChecked(rc.spellchecker_use_input_encoding);
1112 void PrefSpellchecker::select_dict()
1114 QString file = form_->browsedict(internalPath(persDictionaryED->text()));
1115 if (!file.isEmpty())
1116 persDictionaryED->setText(file);
1121 /////////////////////////////////////////////////////////////////////
1125 /////////////////////////////////////////////////////////////////////
1128 PrefConverters::PrefConverters(GuiPreferences * form)
1129 : PrefModule(qt_(catFiles), qt_("Converters"), form)
1133 connect(converterNewPB, SIGNAL(clicked()),
1134 this, SLOT(update_converter()));
1135 connect(converterRemovePB, SIGNAL(clicked()),
1136 this, SLOT(remove_converter()));
1137 connect(converterModifyPB, SIGNAL(clicked()),
1138 this, SLOT(update_converter()));
1139 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1140 this, SLOT(switch_converter()));
1141 connect(converterFromCO, SIGNAL(activated(QString)),
1142 this, SLOT(converter_changed()));
1143 connect(converterToCO, SIGNAL(activated(QString)),
1144 this, SLOT(converter_changed()));
1145 connect(converterED, SIGNAL(textEdited(QString)),
1146 this, SLOT(converter_changed()));
1147 connect(converterFlagED, SIGNAL(textEdited(QString)),
1148 this, SLOT(converter_changed()));
1149 connect(converterNewPB, SIGNAL(clicked()),
1150 this, SIGNAL(changed()));
1151 connect(converterRemovePB, SIGNAL(clicked()),
1152 this, SIGNAL(changed()));
1153 connect(converterModifyPB, SIGNAL(clicked()),
1154 this, SIGNAL(changed()));
1155 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1156 this, SIGNAL(changed()));
1158 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1159 //converterDefGB->setFocusProxy(convertersLW);
1163 void PrefConverters::apply(LyXRC & rc) const
1165 rc.use_converter_cache = cacheCB->isChecked();
1166 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
1170 void PrefConverters::update(LyXRC const & rc)
1172 cacheCB->setChecked(rc.use_converter_cache);
1174 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
1175 maxAgeLE->setText(max_age);
1180 void PrefConverters::updateGui()
1182 form_->formats().sort();
1183 form_->converters().update(form_->formats());
1184 // save current selection
1185 QString current = converterFromCO->currentText()
1186 + " -> " + converterToCO->currentText();
1188 converterFromCO->clear();
1189 converterToCO->clear();
1191 Formats::const_iterator cit = form_->formats().begin();
1192 Formats::const_iterator end = form_->formats().end();
1193 for (; cit != end; ++cit) {
1194 converterFromCO->addItem(qt_(cit->prettyname()));
1195 converterToCO->addItem(qt_(cit->prettyname()));
1198 // currentRowChanged(int) is also triggered when updating the listwidget
1199 // block signals to avoid unnecessary calls to switch_converter()
1200 convertersLW->blockSignals(true);
1201 convertersLW->clear();
1203 Converters::const_iterator ccit = form_->converters().begin();
1204 Converters::const_iterator cend = form_->converters().end();
1205 for (; ccit != cend; ++ccit) {
1206 QString const name =
1207 qt_(ccit->From->prettyname()) + " -> " + qt_(ccit->To->prettyname());
1208 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1209 new QListWidgetItem(name, convertersLW, type);
1211 convertersLW->sortItems(Qt::AscendingOrder);
1212 convertersLW->blockSignals(false);
1214 // restore selection
1215 if (!current.isEmpty()) {
1216 QList<QListWidgetItem *> const item =
1217 convertersLW->findItems(current, Qt::MatchExactly);
1218 if (!item.isEmpty())
1219 convertersLW->setCurrentItem(item.at(0));
1222 // select first element if restoring failed
1223 if (convertersLW->currentRow() == -1)
1224 convertersLW->setCurrentRow(0);
1230 void PrefConverters::switch_converter()
1232 int const cnr = convertersLW->currentItem()->type();
1233 Converter const & c(form_->converters().get(cnr));
1234 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1235 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1236 converterED->setText(toqstr(c.command));
1237 converterFlagED->setText(toqstr(c.flags));
1243 void PrefConverters::converter_changed()
1249 void PrefConverters::updateButtons()
1251 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1252 Format const & to = form_->formats().get(converterToCO->currentIndex());
1253 int const sel = form_->converters().getNumber(from.name(), to.name());
1254 bool const known = sel >= 0;
1255 bool const valid = !(converterED->text().isEmpty()
1256 || from.name() == to.name());
1258 int const cnr = convertersLW->currentItem()->type();
1259 Converter const & c = form_->converters().get(cnr);
1260 string const old_command = c.command;
1261 string const old_flag = c.flags;
1262 string const new_command = fromqstr(converterED->text());
1263 string const new_flag = fromqstr(converterFlagED->text());
1265 bool modified = (old_command != new_command || old_flag != new_flag);
1267 converterModifyPB->setEnabled(valid && known && modified);
1268 converterNewPB->setEnabled(valid && !known);
1269 converterRemovePB->setEnabled(known);
1271 maxAgeLE->setEnabled(cacheCB->isChecked());
1272 maxAgeLA->setEnabled(cacheCB->isChecked());
1277 // specify unique from/to or it doesn't appear. This is really bad UI
1278 // this is why we can use the same function for both new and modify
1279 void PrefConverters::update_converter()
1281 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1282 Format const & to = form_->formats().get(converterToCO->currentIndex());
1283 string const flags = fromqstr(converterFlagED->text());
1284 string const command = fromqstr(converterED->text());
1286 Converter const * old =
1287 form_->converters().getConverter(from.name(), to.name());
1288 form_->converters().add(from.name(), to.name(), command, flags);
1291 form_->converters().updateLast(form_->formats());
1295 // Remove all files created by this converter from the cache, since
1296 // the modified converter might create different files.
1297 ConverterCache::get().remove_all(from.name(), to.name());
1301 void PrefConverters::remove_converter()
1303 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1304 Format const & to = form_->formats().get(converterToCO->currentIndex());
1305 form_->converters().erase(from.name(), to.name());
1309 // Remove all files created by this converter from the cache, since
1310 // a possible new converter might create different files.
1311 ConverterCache::get().remove_all(from.name(), to.name());
1315 void PrefConverters::on_cacheCB_stateChanged(int state)
1317 maxAgeLE->setEnabled(state == Qt::Checked);
1318 maxAgeLA->setEnabled(state == Qt::Checked);
1323 /////////////////////////////////////////////////////////////////////
1327 /////////////////////////////////////////////////////////////////////
1329 class FormatValidator : public QValidator
1332 FormatValidator(QWidget *, Formats const & f);
1333 void fixup(QString & input) const;
1334 QValidator::State validate(QString & input, int & pos) const;
1336 virtual QString toString(Format const & format) const = 0;
1338 Formats const & formats_;
1342 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1343 : QValidator(parent), formats_(f)
1348 void FormatValidator::fixup(QString & input) const
1350 Formats::const_iterator cit = formats_.begin();
1351 Formats::const_iterator end = formats_.end();
1352 for (; cit != end; ++cit) {
1353 QString const name = toString(*cit);
1354 if (distance(formats_.begin(), cit) == nr()) {
1362 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1364 Formats::const_iterator cit = formats_.begin();
1365 Formats::const_iterator end = formats_.end();
1366 bool unknown = true;
1367 for (; unknown && cit != end; ++cit) {
1368 QString const name = toString(*cit);
1369 if (distance(formats_.begin(), cit) != nr())
1370 unknown = name != input;
1373 if (unknown && !input.isEmpty())
1374 return QValidator::Acceptable;
1376 return QValidator::Intermediate;
1380 int FormatValidator::nr() const
1382 QComboBox * p = qobject_cast<QComboBox *>(parent());
1383 return p->itemData(p->currentIndex()).toInt();
1387 /////////////////////////////////////////////////////////////////////
1389 // FormatNameValidator
1391 /////////////////////////////////////////////////////////////////////
1393 class FormatNameValidator : public FormatValidator
1396 FormatNameValidator(QWidget * parent, Formats const & f)
1397 : FormatValidator(parent, f)
1400 QString toString(Format const & format) const
1402 return toqstr(format.name());
1407 /////////////////////////////////////////////////////////////////////
1409 // FormatPrettynameValidator
1411 /////////////////////////////////////////////////////////////////////
1413 class FormatPrettynameValidator : public FormatValidator
1416 FormatPrettynameValidator(QWidget * parent, Formats const & f)
1417 : FormatValidator(parent, f)
1420 QString toString(Format const & format) const
1422 return qt_(format.prettyname());
1427 /////////////////////////////////////////////////////////////////////
1431 /////////////////////////////////////////////////////////////////////
1433 PrefFileformats::PrefFileformats(GuiPreferences * form)
1434 : PrefModule(qt_(catFiles), qt_("File formats"), form)
1437 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1438 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1440 connect(documentCB, SIGNAL(clicked()),
1441 this, SLOT(setFlags()));
1442 connect(vectorCB, SIGNAL(clicked()),
1443 this, SLOT(setFlags()));
1444 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1445 this, SLOT(updatePrettyname()));
1446 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1447 this, SIGNAL(changed()));
1453 string const l10n_shortcut(string const prettyname, string const shortcut)
1455 if (shortcut.empty())
1458 string l10n_format =
1459 to_utf8(_(prettyname + '|' + shortcut));
1460 return split(l10n_format, '|');
1463 }; // namespace anon
1466 void PrefFileformats::apply(LyXRC & /*rc*/) const
1471 void PrefFileformats::update(LyXRC const & /*rc*/)
1477 void PrefFileformats::updateView()
1479 QString const current = formatsCB->currentText();
1481 // update combobox with formats
1482 formatsCB->blockSignals(true);
1484 form_->formats().sort();
1485 Formats::const_iterator cit = form_->formats().begin();
1486 Formats::const_iterator end = form_->formats().end();
1487 for (; cit != end; ++cit)
1488 formatsCB->addItem(qt_(cit->prettyname()),
1489 QVariant(form_->formats().getNumber(cit->name())));
1491 // restore selection
1492 int const item = formatsCB->findText(current, Qt::MatchExactly);
1493 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1494 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1495 formatsCB->blockSignals(false);
1499 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1501 int const nr = formatsCB->itemData(i).toInt();
1502 Format const f = form_->formats().get(nr);
1504 formatED->setText(toqstr(f.name()));
1505 copierED->setText(toqstr(form_->movers().command(f.name())));
1506 extensionED->setText(toqstr(f.extension()));
1507 shortcutED->setText(
1508 toqstr(l10n_shortcut(f.prettyname(), f.shortcut())));
1509 viewerED->setText(toqstr(f.viewer()));
1510 editorED->setText(toqstr(f.editor()));
1511 documentCB->setChecked((f.documentFormat()));
1512 vectorCB->setChecked((f.vectorFormat()));
1516 void PrefFileformats::setFlags()
1518 int flags = Format::none;
1519 if (documentCB->isChecked())
1520 flags |= Format::document;
1521 if (vectorCB->isChecked())
1522 flags |= Format::vector;
1523 currentFormat().setFlags(flags);
1528 void PrefFileformats::on_copierED_textEdited(const QString & s)
1530 string const fmt = fromqstr(formatED->text());
1531 form_->movers().set(fmt, fromqstr(s));
1536 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1538 currentFormat().setExtension(fromqstr(s));
1542 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1544 currentFormat().setViewer(fromqstr(s));
1549 void PrefFileformats::on_editorED_textEdited(const QString & s)
1551 currentFormat().setEditor(fromqstr(s));
1556 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1558 string const new_shortcut = fromqstr(s);
1559 if (new_shortcut == l10n_shortcut(currentFormat().prettyname(),
1560 currentFormat().shortcut()))
1562 currentFormat().setShortcut(new_shortcut);
1567 void PrefFileformats::on_formatED_editingFinished()
1569 string const newname = fromqstr(formatED->displayText());
1570 if (newname == currentFormat().name())
1573 currentFormat().setName(newname);
1578 void PrefFileformats::on_formatED_textChanged(const QString &)
1580 QString t = formatED->text();
1582 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1583 setValid(formatLA, valid);
1587 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1589 QString t = formatsCB->currentText();
1591 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1592 setValid(formatsLA, valid);
1596 void PrefFileformats::updatePrettyname()
1598 QString const newname = formatsCB->currentText();
1599 if (newname == qt_(currentFormat().prettyname()))
1602 currentFormat().setPrettyname(fromqstr(newname));
1609 Format & PrefFileformats::currentFormat()
1611 int const i = formatsCB->currentIndex();
1612 int const nr = formatsCB->itemData(i).toInt();
1613 return form_->formats().get(nr);
1617 void PrefFileformats::on_formatNewPB_clicked()
1619 form_->formats().add("", "", "", "", "", "", Format::none);
1621 formatsCB->setCurrentIndex(0);
1622 formatsCB->setFocus(Qt::OtherFocusReason);
1626 void PrefFileformats::on_formatRemovePB_clicked()
1628 int const i = formatsCB->currentIndex();
1629 int const nr = formatsCB->itemData(i).toInt();
1630 string const current_text = form_->formats().get(nr).name();
1631 if (form_->converters().formatIsUsed(current_text)) {
1632 Alert::error(_("Format in use"),
1633 _("Cannot remove a Format used by a Converter. "
1634 "Remove the converter first."));
1638 form_->formats().erase(current_text);
1641 on_formatsCB_editTextChanged(formatsCB->currentText());
1646 /////////////////////////////////////////////////////////////////////
1650 /////////////////////////////////////////////////////////////////////
1652 PrefLanguage::PrefLanguage(GuiPreferences * form)
1653 : PrefModule(qt_(catLanguage), qt_("Language"), form)
1657 connect(rtlGB, SIGNAL(clicked()),
1658 this, SIGNAL(changed()));
1659 connect(visualCursorRB, SIGNAL(clicked()),
1660 this, SIGNAL(changed()));
1661 connect(logicalCursorRB, SIGNAL(clicked()),
1662 this, SIGNAL(changed()));
1663 connect(markForeignCB, SIGNAL(clicked()),
1664 this, SIGNAL(changed()));
1665 connect(autoBeginCB, SIGNAL(clicked()),
1666 this, SIGNAL(changed()));
1667 connect(autoEndCB, SIGNAL(clicked()),
1668 this, SIGNAL(changed()));
1669 connect(useBabelCB, SIGNAL(clicked()),
1670 this, SIGNAL(changed()));
1671 connect(globalCB, SIGNAL(clicked()),
1672 this, SIGNAL(changed()));
1673 connect(languagePackageED, SIGNAL(textChanged(QString)),
1674 this, SIGNAL(changed()));
1675 connect(startCommandED, SIGNAL(textChanged(QString)),
1676 this, SIGNAL(changed()));
1677 connect(endCommandED, SIGNAL(textChanged(QString)),
1678 this, SIGNAL(changed()));
1679 connect(defaultLanguageCO, SIGNAL(activated(int)),
1680 this, SIGNAL(changed()));
1681 connect(uiLanguageCO, SIGNAL(activated(int)),
1682 this, SIGNAL(changed()));
1684 defaultLanguageCO->clear();
1685 uiLanguageCO->clear();
1687 QAbstractItemModel * language_model = guiApp->languageModel();
1688 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1689 language_model->sort(0);
1690 defaultLanguageCO->setModel(language_model);
1692 // FIXME: This is wrong, we need filter this list based on the available
1694 uiLanguageCO->blockSignals(true);
1695 uiLanguageCO->addItem(qt_("Default"), toqstr("auto"));
1696 for (int i = 0; i != language_model->rowCount(); ++i) {
1697 QModelIndex index = language_model->index(i, 0);
1698 uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
1699 index.data(Qt::UserRole).toString());
1701 uiLanguageCO->blockSignals(false);
1705 void PrefLanguage::on_uiLanguageCO_currentIndexChanged(int)
1707 QMessageBox::information(this, qt_("LyX needs to be restarted!"),
1708 qt_("The change of user interface language will be fully "
1709 "effective only after a restart."));
1713 void PrefLanguage::apply(LyXRC & rc) const
1715 // FIXME: remove rtl_support bool
1716 rc.rtl_support = rtlGB->isChecked();
1717 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
1718 rc.mark_foreign_language = markForeignCB->isChecked();
1719 rc.language_auto_begin = autoBeginCB->isChecked();
1720 rc.language_auto_end = autoEndCB->isChecked();
1721 rc.language_use_babel = useBabelCB->isChecked();
1722 rc.language_global_options = globalCB->isChecked();
1723 rc.language_package = fromqstr(languagePackageED->text());
1724 rc.language_command_begin = fromqstr(startCommandED->text());
1725 rc.language_command_end = fromqstr(endCommandED->text());
1726 rc.default_language = fromqstr(
1727 defaultLanguageCO->itemData(defaultLanguageCO->currentIndex()).toString());
1728 rc.gui_language = fromqstr(
1729 uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString());
1733 void PrefLanguage::update(LyXRC const & rc)
1735 // FIXME: remove rtl_support bool
1736 rtlGB->setChecked(rc.rtl_support);
1737 if (rc.visual_cursor)
1738 visualCursorRB->setChecked(true);
1740 logicalCursorRB->setChecked(true);
1741 markForeignCB->setChecked(rc.mark_foreign_language);
1742 autoBeginCB->setChecked(rc.language_auto_begin);
1743 autoEndCB->setChecked(rc.language_auto_end);
1744 useBabelCB->setChecked(rc.language_use_babel);
1745 globalCB->setChecked(rc.language_global_options);
1746 languagePackageED->setText(toqstr(rc.language_package));
1747 startCommandED->setText(toqstr(rc.language_command_begin));
1748 endCommandED->setText(toqstr(rc.language_command_end));
1750 int pos = defaultLanguageCO->findData(toqstr(rc.default_language));
1751 defaultLanguageCO->setCurrentIndex(pos);
1752 pos = uiLanguageCO->findData(toqstr(rc.gui_language));
1753 uiLanguageCO->blockSignals(true);
1754 uiLanguageCO->setCurrentIndex(pos);
1755 uiLanguageCO->blockSignals(false);
1759 /////////////////////////////////////////////////////////////////////
1763 /////////////////////////////////////////////////////////////////////
1765 PrefPrinter::PrefPrinter(GuiPreferences * form)
1766 : PrefModule(qt_(catOutput), qt_("Printer"), form)
1770 connect(printerAdaptCB, SIGNAL(clicked()),
1771 this, SIGNAL(changed()));
1772 connect(printerCommandED, SIGNAL(textChanged(QString)),
1773 this, SIGNAL(changed()));
1774 connect(printerNameED, SIGNAL(textChanged(QString)),
1775 this, SIGNAL(changed()));
1776 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
1777 this, SIGNAL(changed()));
1778 connect(printerCopiesED, SIGNAL(textChanged(QString)),
1779 this, SIGNAL(changed()));
1780 connect(printerReverseED, SIGNAL(textChanged(QString)),
1781 this, SIGNAL(changed()));
1782 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
1783 this, SIGNAL(changed()));
1784 connect(printerExtensionED, SIGNAL(textChanged(QString)),
1785 this, SIGNAL(changed()));
1786 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
1787 this, SIGNAL(changed()));
1788 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
1789 this, SIGNAL(changed()));
1790 connect(printerEvenED, SIGNAL(textChanged(QString)),
1791 this, SIGNAL(changed()));
1792 connect(printerOddED, SIGNAL(textChanged(QString)),
1793 this, SIGNAL(changed()));
1794 connect(printerCollatedED, SIGNAL(textChanged(QString)),
1795 this, SIGNAL(changed()));
1796 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
1797 this, SIGNAL(changed()));
1798 connect(printerToFileED, SIGNAL(textChanged(QString)),
1799 this, SIGNAL(changed()));
1800 connect(printerExtraED, SIGNAL(textChanged(QString)),
1801 this, SIGNAL(changed()));
1802 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
1803 this, SIGNAL(changed()));
1804 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
1805 this, SIGNAL(changed()));
1809 void PrefPrinter::apply(LyXRC & rc) const
1811 rc.print_adapt_output = printerAdaptCB->isChecked();
1812 rc.print_command = fromqstr(printerCommandED->text());
1813 rc.printer = fromqstr(printerNameED->text());
1815 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1816 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1817 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1818 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1819 rc.print_file_extension = fromqstr(printerExtensionED->text());
1820 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1821 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1822 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1823 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1824 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1825 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1826 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1827 rc.print_extra_options = fromqstr(printerExtraED->text());
1828 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1829 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1833 void PrefPrinter::update(LyXRC const & rc)
1835 printerAdaptCB->setChecked(rc.print_adapt_output);
1836 printerCommandED->setText(toqstr(rc.print_command));
1837 printerNameED->setText(toqstr(rc.printer));
1839 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1840 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1841 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1842 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1843 printerExtensionED->setText(toqstr(rc.print_file_extension));
1844 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1845 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1846 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1847 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1848 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1849 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1850 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1851 printerExtraED->setText(toqstr(rc.print_extra_options));
1852 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1853 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1857 /////////////////////////////////////////////////////////////////////
1859 // PrefUserInterface
1861 /////////////////////////////////////////////////////////////////////
1863 PrefUserInterface::PrefUserInterface(GuiPreferences * form)
1864 : PrefModule(qt_(catLookAndFeel), qt_("User interface"), form)
1868 connect(autoSaveCB, SIGNAL(toggled(bool)),
1869 autoSaveSB, SLOT(setEnabled(bool)));
1870 connect(autoSaveCB, SIGNAL(toggled(bool)),
1871 TextLabel1, SLOT(setEnabled(bool)));
1872 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
1873 this, SIGNAL(changed()));
1874 connect(uiFilePB, SIGNAL(clicked()),
1875 this, SLOT(select_ui()));
1876 connect(uiFileED, SIGNAL(textChanged(QString)),
1877 this, SIGNAL(changed()));
1878 connect(restoreCursorCB, SIGNAL(clicked()),
1879 this, SIGNAL(changed()));
1880 connect(loadSessionCB, SIGNAL(clicked()),
1881 this, SIGNAL(changed()));
1882 connect(allowGeometrySessionCB, SIGNAL(clicked()),
1883 this, SIGNAL(changed()));
1884 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1885 this, SIGNAL(changed()));
1886 connect(autoSaveCB, SIGNAL(clicked()),
1887 this, SIGNAL(changed()));
1888 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1889 this, SIGNAL(changed()));
1890 connect(tooltipCB, SIGNAL(toggled(bool)),
1891 this, SIGNAL(changed()));
1892 lastfilesSB->setMaximum(maxlastfiles);
1896 void PrefUserInterface::apply(LyXRC & rc) const
1898 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1899 rc.use_lastfilepos = restoreCursorCB->isChecked();
1900 rc.load_session = loadSessionCB->isChecked();
1901 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
1902 rc.autosave = autoSaveSB->value() * 60;
1903 rc.make_backup = autoSaveCB->isChecked();
1904 rc.num_lastfiles = lastfilesSB->value();
1905 rc.use_tooltip = tooltipCB->isChecked();
1906 rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
1910 void PrefUserInterface::update(LyXRC const & rc)
1912 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1913 restoreCursorCB->setChecked(rc.use_lastfilepos);
1914 loadSessionCB->setChecked(rc.load_session);
1915 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
1916 // convert to minutes
1917 int mins(rc.autosave / 60);
1918 if (rc.autosave && !mins)
1920 autoSaveSB->setValue(mins);
1921 autoSaveCB->setChecked(rc.make_backup);
1922 lastfilesSB->setValue(rc.num_lastfiles);
1923 tooltipCB->setChecked(rc.use_tooltip);
1924 openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
1928 void PrefUserInterface::select_ui()
1930 QString file = form_->browseUI(internalPath(uiFileED->text()));
1931 if (!file.isEmpty())
1932 uiFileED->setText(file);
1936 void PrefUserInterface::on_clearSessionPB_clicked()
1938 guiApp->clearSession();
1943 /////////////////////////////////////////////////////////////////////
1947 /////////////////////////////////////////////////////////////////////
1949 PrefEdit::PrefEdit(GuiPreferences * form)
1950 : PrefModule(qt_(catEditing), qt_("Control"), form)
1954 connect(cursorFollowsCB, SIGNAL(clicked()),
1955 this, SIGNAL(changed()));
1956 connect(sortEnvironmentsCB, SIGNAL(clicked()),
1957 this, SIGNAL(changed()));
1958 connect(groupEnvironmentsCB, SIGNAL(clicked()),
1959 this, SIGNAL(changed()));
1960 connect(macroEditStyleCO, SIGNAL(activated(int)),
1961 this, SIGNAL(changed()));
1962 connect(fullscreenLimitGB, SIGNAL(clicked()),
1963 this, SIGNAL(changed()));
1964 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
1965 this, SIGNAL(changed()));
1966 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
1967 this, SIGNAL(changed()));
1968 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
1969 this, SIGNAL(changed()));
1970 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
1971 this, SIGNAL(changed()));
1975 void PrefEdit::apply(LyXRC & rc) const
1977 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1978 rc.sort_layouts = sortEnvironmentsCB->isChecked();
1979 rc.group_layouts = groupEnvironmentsCB->isChecked();
1980 switch (macroEditStyleCO->currentIndex()) {
1981 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
1982 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
1983 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
1985 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
1986 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
1987 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
1988 rc.full_screen_width = fullscreenWidthSB->value();
1989 rc.full_screen_limit = fullscreenLimitGB->isChecked();
1993 void PrefEdit::update(LyXRC const & rc)
1995 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1996 sortEnvironmentsCB->setChecked(rc.sort_layouts);
1997 groupEnvironmentsCB->setChecked(rc.group_layouts);
1998 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
1999 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
2000 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
2001 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
2002 fullscreenWidthSB->setValue(rc.full_screen_width);
2003 fullscreenLimitGB->setChecked(rc.full_screen_limit);
2007 /////////////////////////////////////////////////////////////////////
2011 /////////////////////////////////////////////////////////////////////
2014 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
2016 Ui::shortcutUi::setupUi(this);
2017 QDialog::setModal(true);
2021 PrefShortcuts::PrefShortcuts(GuiPreferences * form)
2022 : PrefModule(qt_(catEditing), qt_("Shortcuts"), form)
2026 shortcutsTW->setColumnCount(2);
2027 shortcutsTW->headerItem()->setText(0, qt_("Function"));
2028 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
2029 shortcutsTW->setSortingEnabled(true);
2030 // Multi-selection can be annoying.
2031 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
2033 connect(bindFilePB, SIGNAL(clicked()),
2034 this, SLOT(select_bind()));
2035 connect(bindFileED, SIGNAL(textChanged(QString)),
2036 this, SIGNAL(changed()));
2037 connect(removePB, SIGNAL(clicked()),
2038 this, SIGNAL(changed()));
2040 shortcut_ = new GuiShortcutDialog(this);
2041 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
2042 shortcut_bc_.setOK(shortcut_->okPB);
2043 shortcut_bc_.setCancel(shortcut_->cancelPB);
2045 connect(shortcut_->okPB, SIGNAL(clicked()),
2046 shortcut_, SLOT(accept()));
2047 connect(shortcut_->okPB, SIGNAL(clicked()),
2048 this, SIGNAL(changed()));
2049 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2050 shortcut_, SLOT(reject()));
2051 connect(shortcut_->clearPB, SIGNAL(clicked()),
2052 this, SLOT(shortcut_clearPB_pressed()));
2053 connect(shortcut_->removePB, SIGNAL(clicked()),
2054 this, SLOT(shortcut_removePB_pressed()));
2055 connect(shortcut_->okPB, SIGNAL(clicked()),
2056 this, SLOT(shortcut_okPB_pressed()));
2057 connect(shortcut_->cancelPB, SIGNAL(clicked()),
2058 this, SLOT(shortcut_cancelPB_pressed()));
2062 void PrefShortcuts::apply(LyXRC & rc) const
2064 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
2065 // write user_bind and user_unbind to .lyx/bind/user.bind
2066 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
2067 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
2068 lyxerr << "LyX could not create the user bind directory '"
2069 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2072 if (!bind_dir.isDirWritable()) {
2073 lyxerr << "LyX could not write to the user bind directory '"
2074 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2077 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
2078 user_bind_.write(user_bind_file.toFilesystemEncoding(), false, false);
2079 user_unbind_.write(user_bind_file.toFilesystemEncoding(), true, true);
2080 // immediately apply the keybindings. Why this is not done before?
2081 // The good thing is that the menus are updated automatically.
2082 theTopLevelKeymap().clear();
2083 theTopLevelKeymap().read("site");
2084 theTopLevelKeymap().read(rc.bind_file);
2085 theTopLevelKeymap().read("user");
2089 void PrefShortcuts::update(LyXRC const & rc)
2091 bindFileED->setText(toqstr(external_path(rc.bind_file)));
2093 system_bind_.clear();
2095 user_unbind_.clear();
2096 system_bind_.read("site");
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,
2132 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2134 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2135 KeyMap::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, KeyMap::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, KeyMap::ItemType tag)
2157 item->setData(0, Qt::UserRole, QVariant(tag));
2161 case KeyMap::System:
2163 case KeyMap::UserBind:
2166 case KeyMap::UserUnbind:
2167 font.setStrikeOut(true);
2169 // this item is not displayed now.
2170 case KeyMap::UserExtraUnbind:
2171 font.setStrikeOut(true);
2175 item->setFont(1, font);
2179 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2180 KeySequence const & seq, KeyMap::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 KeyMap::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 == KeyMap::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 KeyMap::UserExtraUnbind
2200 // Such an item is not displayed to avoid confusion (what is
2201 // unmatched removed?).
2203 item_tag = KeyMap::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 KeyMap::ItemType tag =
2250 static_cast<KeyMap::ItemType>(items[0]->data(0, Qt::UserRole).toInt());
2251 if (tag == KeyMap::UserUnbind)
2252 removePB->setText(qt_("Res&tore"));
2254 removePB->setText(qt_("Remo&ve"));
2258 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2264 void PrefShortcuts::modifyShortcut()
2266 QTreeWidgetItem * item = shortcutsTW->currentItem();
2267 if (item->flags() & Qt::ItemIsSelectable) {
2268 shortcut_->lfunLE->setText(item->text(0));
2269 save_lfun_ = item->text(0);
2270 shortcut_->shortcutWG->setText(item->text(1));
2272 seq.parse(fromqstr(item->data(1, Qt::UserRole).toString()));
2273 shortcut_->shortcutWG->setKeySequence(seq);
2274 shortcut_->shortcutWG->setFocus();
2280 void PrefShortcuts::removeShortcut()
2282 // it seems that only one item can be selected, but I am
2283 // removing all selected items anyway.
2284 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2285 for (int i = 0; i < items.size(); ++i) {
2286 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2287 string lfun = fromqstr(items[i]->text(0));
2288 FuncRequest func = lyxaction.lookupFunc(lfun);
2289 KeyMap::ItemType tag =
2290 static_cast<KeyMap::ItemType>(items[i]->data(0, Qt::UserRole).toInt());
2293 case KeyMap::System: {
2294 // for system bind, we do not touch the item
2295 // but add an user unbind item
2296 user_unbind_.bind(shortcut, func);
2297 setItemType(items[i], KeyMap::UserUnbind);
2298 removePB->setText(qt_("Res&tore"));
2301 case KeyMap::UserBind: {
2302 // for user_bind, we remove this bind
2303 QTreeWidgetItem * parent = items[i]->parent();
2304 int itemIdx = parent->indexOfChild(items[i]);
2305 parent->takeChild(itemIdx);
2307 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2309 shortcutsTW->scrollToItem(parent);
2310 user_bind_.unbind(shortcut, func);
2313 case KeyMap::UserUnbind: {
2314 // for user_unbind, we remove the unbind, and the item
2315 // become KeyMap::System again.
2316 user_unbind_.unbind(shortcut, func);
2317 setItemType(items[i], KeyMap::System);
2318 removePB->setText(qt_("Remo&ve"));
2321 case KeyMap::UserExtraUnbind: {
2322 // for user unbind that is not in system bind file,
2323 // remove this unbind file
2324 QTreeWidgetItem * parent = items[i]->parent();
2325 parent->takeChild(parent->indexOfChild(items[i]));
2326 user_unbind_.unbind(shortcut, func);
2333 void PrefShortcuts::select_bind()
2335 QString file = form_->browsebind(internalPath(bindFileED->text()));
2336 if (!file.isEmpty()) {
2337 bindFileED->setText(file);
2338 system_bind_ = KeyMap();
2339 system_bind_.read(fromqstr(file));
2340 updateShortcutsTW();
2345 void PrefShortcuts::on_modifyPB_pressed()
2351 void PrefShortcuts::on_newPB_pressed()
2353 shortcut_->lfunLE->clear();
2354 shortcut_->shortcutWG->reset();
2355 save_lfun_ = QString();
2360 void PrefShortcuts::on_removePB_pressed()
2366 void PrefShortcuts::on_searchLE_textEdited()
2368 if (searchLE->text().isEmpty()) {
2369 // show all hidden items
2370 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2372 shortcutsTW->setItemHidden(*it++, false);
2375 // search both columns
2376 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2377 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2378 matched += shortcutsTW->findItems(searchLE->text(),
2379 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2381 // hide everyone (to avoid searching in matched QList repeatedly
2382 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2384 shortcutsTW->setItemHidden(*it++, true);
2385 // show matched items
2386 for (int i = 0; i < matched.size(); ++i) {
2387 shortcutsTW->setItemHidden(matched[i], false);
2388 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2393 docstring makeCmdString(FuncRequest const & f)
2395 docstring actionStr = from_ascii(lyxaction.getActionName(f.action));
2396 if (!f.argument().empty())
2397 actionStr += " " + f.argument();
2402 void PrefShortcuts::shortcut_okPB_pressed()
2404 QString const new_lfun = shortcut_->lfunLE->text();
2405 FuncRequest func = lyxaction.lookupFunc(fromqstr(new_lfun));
2407 if (func.action == LFUN_UNKNOWN_ACTION) {
2408 Alert::error(_("Failed to create shortcut"),
2409 _("Unknown or invalid LyX function"));
2413 KeySequence k = shortcut_->shortcutWG->getKeySequence();
2414 if (k.length() == 0) {
2415 Alert::error(_("Failed to create shortcut"),
2416 _("Invalid or empty key sequence"));
2420 // check to see if there's been any change
2421 FuncRequest oldBinding = system_bind_.getBinding(k);
2422 if (oldBinding.action == LFUN_UNKNOWN_ACTION)
2423 oldBinding = user_bind_.getBinding(k);
2424 if (oldBinding == func) {
2425 docstring const actionStr = makeCmdString(func);
2426 Alert::error(_("Failed to create shortcut"),
2427 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s"),
2428 k.print(KeySequence::ForGui), actionStr));
2432 // make sure this key isn't already bound---and, if so, not unbound
2433 FuncCode const unbind = user_unbind_.getBinding(k).action;
2434 if (oldBinding.action != LFUN_UNKNOWN_ACTION && unbind == LFUN_UNKNOWN_ACTION)
2436 // FIXME Perhaps we should offer to over-write the old shortcut?
2437 // If so, we'll need to remove it from our list, etc.
2438 docstring const actionStr = makeCmdString(oldBinding);
2439 Alert::error(_("Failed to create shortcut"),
2440 bformat(_("Shortcut `%1$s' is already bound to:\n%2$s\n"
2441 "You need to remove that binding before creating a new one."),
2442 k.print(KeySequence::ForGui), actionStr));
2446 if (!save_lfun_.isEmpty() && new_lfun == save_lfun_)
2447 // real modification of the lfun's shortcut,
2448 // so remove the previous one
2451 QTreeWidgetItem * item = insertShortcutItem(func, k, KeyMap::UserBind);
2453 user_bind_.bind(&k, func);
2454 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2455 shortcutsTW->setItemExpanded(item->parent(), true);
2456 shortcutsTW->scrollToItem(item);
2458 Alert::error(_("Failed to create shortcut"),
2459 _("Can not insert shortcut to the list"));
2465 void PrefShortcuts::shortcut_cancelPB_pressed()
2467 shortcut_->shortcutWG->reset();
2471 void PrefShortcuts::shortcut_clearPB_pressed()
2473 shortcut_->shortcutWG->reset();
2477 void PrefShortcuts::shortcut_removePB_pressed()
2479 shortcut_->shortcutWG->removeFromSequence();
2483 /////////////////////////////////////////////////////////////////////
2487 /////////////////////////////////////////////////////////////////////
2489 PrefIdentity::PrefIdentity(GuiPreferences * form)
2490 : PrefModule(QString(), qt_("Identity"), form)
2494 connect(nameED, SIGNAL(textChanged(QString)),
2495 this, SIGNAL(changed()));
2496 connect(emailED, SIGNAL(textChanged(QString)),
2497 this, SIGNAL(changed()));
2501 void PrefIdentity::apply(LyXRC & rc) const
2503 rc.user_name = fromqstr(nameED->text());
2504 rc.user_email = fromqstr(emailED->text());
2508 void PrefIdentity::update(LyXRC const & rc)
2510 nameED->setText(toqstr(rc.user_name));
2511 emailED->setText(toqstr(rc.user_email));
2516 /////////////////////////////////////////////////////////////////////
2520 /////////////////////////////////////////////////////////////////////
2522 GuiPreferences::GuiPreferences(GuiView & lv)
2523 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2527 QDialog::setModal(false);
2529 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2530 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2531 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2532 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2534 addModule(new PrefUserInterface(this));
2535 addModule(new PrefEdit(this));
2536 addModule(new PrefShortcuts(this));
2537 addModule(new PrefScreenFonts(this));
2538 addModule(new PrefColors(this));
2539 addModule(new PrefDisplay(this));
2540 addModule(new PrefInput(this));
2541 addModule(new PrefCompletion(this));
2543 addModule(new PrefPaths(this));
2545 addModule(new PrefIdentity(this));
2547 addModule(new PrefLanguage(this));
2548 addModule(new PrefSpellchecker(this));
2550 addModule(new PrefPrinter(this));
2551 addModule(new PrefDate(this));
2552 addModule(new PrefPlaintext(this));
2553 addModule(new PrefLatex(this));
2555 PrefConverters * converters = new PrefConverters(this);
2556 PrefFileformats * formats = new PrefFileformats(this);
2557 connect(formats, SIGNAL(formatsChanged()),
2558 converters, SLOT(updateGui()));
2559 addModule(converters);
2562 prefsPS->setCurrentPanel(qt_("User interface"));
2563 // FIXME: hack to work around resizing bug in Qt >= 4.2
2564 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2565 #if QT_VERSION >= 0x040200
2566 prefsPS->updateGeometry();
2569 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2571 bc().setApply(applyPB);
2572 bc().setCancel(closePB);
2573 bc().setRestore(restorePB);
2577 void GuiPreferences::addModule(PrefModule * module)
2579 LASSERT(module, /**/);
2580 if (module->category().isEmpty())
2581 prefsPS->addPanel(module, module->title());
2583 prefsPS->addPanel(module, module->title(), module->category());
2584 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2585 modules_.push_back(module);
2589 void GuiPreferences::change_adaptor()
2595 void GuiPreferences::apply(LyXRC & rc) const
2597 size_t end = modules_.size();
2598 for (size_t i = 0; i != end; ++i)
2599 modules_[i]->apply(rc);
2603 void GuiPreferences::updateRc(LyXRC const & rc)
2605 size_t const end = modules_.size();
2606 for (size_t i = 0; i != end; ++i)
2607 modules_[i]->update(rc);
2611 void GuiPreferences::applyView()
2616 bool GuiPreferences::initialiseParams(string const &)
2619 formats_ = lyx::formats;
2620 converters_ = theConverters();
2621 converters_.update(formats_);
2622 movers_ = theMovers();
2624 update_screen_font_ = false;
2631 void GuiPreferences::dispatchParams()
2634 rc_.write(ss, true);
2635 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
2636 // FIXME: these need lfuns
2638 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
2640 lyx::formats = formats_;
2642 theConverters() = converters_;
2643 theConverters().update(lyx::formats);
2644 theConverters().buildGraph();
2646 theMovers() = movers_;
2648 vector<string>::const_iterator it = colors_.begin();
2649 vector<string>::const_iterator const end = colors_.end();
2650 for (; it != end; ++it)
2651 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
2654 if (update_screen_font_) {
2655 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2656 update_screen_font_ = false;
2659 // The Save button has been pressed
2661 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
2665 void GuiPreferences::setColor(ColorCode col, QString const & hex)
2667 colors_.push_back(lcolor.getLyXName(col) + ' ' + fromqstr(hex));
2671 void GuiPreferences::updateScreenFonts()
2673 update_screen_font_ = true;
2677 QString GuiPreferences::browsebind(QString const & file) const
2679 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
2680 QStringList(qt_("LyX bind files (*.bind)")));
2684 QString GuiPreferences::browseUI(QString const & file) const
2686 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
2687 QStringList(qt_("LyX UI files (*.ui)")));
2691 QString GuiPreferences::browsekbmap(QString const & file) const
2693 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
2694 QStringList(qt_("LyX keyboard maps (*.kmap)")));
2698 QString GuiPreferences::browsedict(QString const & file) const
2700 return browseFile(file, qt_("Choose personal dictionary"),
2701 QStringList(lyxrc.use_spell_lib ? qt_("*.pws") : qt_("*.ispell")));
2705 QString GuiPreferences::browse(QString const & file,
2706 QString const & title) const
2708 return browseFile(file, title, QStringList(), true);
2712 // We support less paper sizes than the document dialog
2713 // Therefore this adjustment is needed.
2714 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
2718 return PAPER_DEFAULT;
2720 return PAPER_USLETTER;
2722 return PAPER_USLEGAL;
2724 return PAPER_USEXECUTIVE;
2734 // should not happen
2735 return PAPER_DEFAULT;
2740 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
2742 switch (papersize) {
2745 case PAPER_USLETTER:
2749 case PAPER_USEXECUTIVE:
2760 // should not happen
2766 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
2769 } // namespace frontend
2772 #include "moc_GuiPrefs.cpp"