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 "qt_helpers.h"
17 #include "GuiApplication.h"
18 #include "GuiFontLoader.h"
20 #include "BufferList.h"
22 #include "ConverterCache.h"
23 #include "FileDialog.h"
24 #include "FuncRequest.h"
25 #include "GuiFontExample.h"
26 #include "GuiKeySymbol.h"
28 #include "KeySequence.h"
29 #include "LyXAction.h"
30 #include "PanelStack.h"
34 #include "support/debug.h"
35 #include "support/FileFilterList.h"
36 #include "support/FileName.h"
37 #include "support/filetools.h"
38 #include "support/gettext.h"
39 #include "support/lstrings.h"
40 #include "support/os.h"
41 #include "support/Package.h"
43 #include "graphics/GraphicsTypes.h"
45 #include "frontends/alert.h"
46 #include "frontends/Application.h"
49 #include <QColorDialog>
50 #include <QFontDatabase>
51 #include <QHeaderView>
53 #include <QPixmapCache>
54 #include <QPushButton>
57 #include <QTreeWidget>
58 #include <QTreeWidgetItem>
68 using namespace lyx::support;
69 using namespace lyx::support::os;
74 /////////////////////////////////////////////////////////////////////
78 /////////////////////////////////////////////////////////////////////
80 FileName libFileSearch(QString const & dir, QString const & name,
81 QString const & ext = QString())
83 return support::libFileSearch(fromqstr(dir), fromqstr(name), fromqstr(ext));
87 /** Launch a file dialog and return the chosen file.
88 filename: a suggested filename.
89 title: the title of the dialog.
91 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
93 QString browseFile(QString const & filename,
94 QString const & title,
95 support::FileFilterList const & filters,
97 QString const & label1 = QString(),
98 QString const & dir1 = QString(),
99 QString const & label2 = QString(),
100 QString const & dir2 = QString())
102 QString lastPath = ".";
103 if (!filename.isEmpty())
104 lastPath = onlyPath(filename);
106 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
107 dlg.setButton2(label1, dir1);
108 dlg.setButton2(label2, dir2);
110 FileDialog::Result result;
113 result = dlg.save(lastPath, filters, onlyFilename(filename));
115 result = dlg.open(lastPath, filters, onlyFilename(filename));
117 return result.second;
121 /** Wrapper around browseFile which tries to provide a filename
122 * relative to the user or system directory. The dir, name and ext
123 * parameters have the same meaning as in the
124 * support::LibFileSearch function.
126 QString browseLibFile(QString const & dir,
127 QString const & name,
129 QString const & title,
130 support::FileFilterList const & filters)
133 QString const label1 = qt_("System files|#S#s");
135 toqstr(addName(package().system_support().absFilename(), fromqstr(dir)));
137 QString const label2 = qt_("User files|#U#u");
139 toqstr(addName(package().user_support().absFilename(), fromqstr(dir)));
141 QString const result = browseFile(toqstr(
142 libFileSearch(dir, name, ext).absFilename()),
143 title, filters, false, dir1, dir2);
145 // remove the extension if it is the default one
147 if (toqstr(getExtension(fromqstr(result))) == ext)
148 noextresult = toqstr(removeExtension(fromqstr(result)));
150 noextresult = result;
152 // remove the directory, if it is the default one
153 QString const file = onlyFilename(noextresult);
154 if (toqstr(libFileSearch(dir, file, ext).absFilename()) == result)
161 /** Launch a file dialog and return the chosen directory.
162 pathname: a suggested pathname.
163 title: the title of the dialog.
164 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
166 QString browseDir(QString const & pathname,
167 QString const & title,
168 QString const & label1 = QString(),
169 QString const & dir1 = QString(),
170 QString const & label2 = QString(),
171 QString const & dir2 = QString())
173 QString lastPath = ".";
174 if (!pathname.isEmpty())
175 lastPath = onlyPath(pathname);
177 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
178 dlg.setButton1(label1, dir1);
179 dlg.setButton2(label2, dir2);
181 FileDialog::Result const result =
182 dlg.opendir(lastPath, onlyFilename(pathname));
184 return result.second;
188 QString browseRelFile(QString const & filename, QString const & refpath,
189 QString const & title, FileFilterList const & filters, bool save,
190 QString const & label1, QString const & dir1,
191 QString const & label2, QString const & dir2)
193 QString const fname = toqstr(makeAbsPath(
194 fromqstr(filename), fromqstr(refpath)).absFilename());
196 QString const outname =
197 browseFile(fname, title, filters, save, label1, dir1, label2, dir2);
199 QString const reloutname =
200 toqstr(makeRelPath(qstring_to_ucs4(outname), qstring_to_ucs4(refpath)));
202 if (reloutname.startsWith("../"))
208 } // namespace frontend
210 docstring browseRelFile(docstring const & filename, docstring const & refpath,
211 docstring const & title, FileFilterList const & filters, bool save,
212 docstring const & label1, docstring const & dir1,
213 docstring const & label2, docstring const & dir2)
215 return qstring_to_ucs4(frontend::browseRelFile(
216 toqstr(filename), toqstr(refpath),
217 toqstr(title), filters, save,
218 toqstr(label1), toqstr(dir1),
219 toqstr(label2), toqstr(dir2)));
223 /////////////////////////////////////////////////////////////////////
227 /////////////////////////////////////////////////////////////////////
232 static size_t findPos_helper(vector<A> const & vec, A const & val)
234 typedef typename vector<A>::const_iterator Cit;
236 Cit it = find(vec.begin(), vec.end(), val);
239 return distance(vec.begin(), it);
243 static void parseFontName(QString const & mangled0,
244 string & name, string & foundry)
246 string mangled = fromqstr(mangled0);
247 size_t const idx = mangled.find('[');
248 if (idx == string::npos || idx == 0) {
252 name = mangled.substr(0, idx - 1),
253 foundry = mangled.substr(idx + 1, mangled.size() - idx - 2);
258 static void setComboxFont(QComboBox * cb, string const & family,
259 string const & foundry)
261 QString fontname = toqstr(family);
262 if (!foundry.empty())
263 fontname += " [" + toqstr(foundry) + ']';
265 for (int i = 0; i != cb->count(); ++i) {
266 if (cb->itemText(i) == fontname) {
267 cb->setCurrentIndex(i);
272 // Try matching without foundry name
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, family) == 0) {
279 cb->setCurrentIndex(i);
284 // family alone can contain e.g. "Helvetica [Adobe]"
285 string tmpname, tmpfoundry;
286 parseFontName(toqstr(family), tmpname, tmpfoundry);
288 // We count in reverse in order to prefer the Xft foundry
289 for (int i = cb->count(); --i >= 0; ) {
290 string name, foundry;
291 parseFontName(cb->itemText(i), name, foundry);
292 if (compare_ascii_no_case(name, foundry) == 0) {
293 cb->setCurrentIndex(i);
298 // Bleh, default fonts, and the names couldn't be found. Hack
302 font.setKerning(false);
304 QString const font_family = toqstr(family);
305 if (font_family == guiApp->romanFontName()) {
306 font.setStyleHint(QFont::Serif);
307 font.setFamily(font_family);
308 } else if (font_family == guiApp->sansFontName()) {
309 font.setStyleHint(QFont::SansSerif);
310 font.setFamily(font_family);
311 } else if (font_family == guiApp->typewriterFontName()) {
312 font.setStyleHint(QFont::TypeWriter);
313 font.setFamily(font_family);
315 lyxerr << "FAILED to find the default font: '"
316 << foundry << "', '" << family << '\''<< endl;
320 QFontInfo info(font);
321 string default_font_name, dummyfoundry;
322 parseFontName(info.family(), default_font_name, dummyfoundry);
323 lyxerr << "Apparent font is " << default_font_name << endl;
325 for (int i = 0; i < cb->count(); ++i) {
326 lyxerr << "Looking at " << fromqstr(cb->itemText(i)) << endl;
327 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
328 default_font_name) == 0) {
329 cb->setCurrentIndex(i);
334 lyxerr << "FAILED to find the font: '"
335 << foundry << "', '" << family << '\'' <<endl;
339 /////////////////////////////////////////////////////////////////////
343 /////////////////////////////////////////////////////////////////////
345 PrefPlaintext::PrefPlaintext(QWidget * parent)
346 : PrefModule(qt_("Plain text"), 0, parent)
349 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
350 this, SIGNAL(changed()));
351 connect(plaintextRoffED, SIGNAL(textChanged(QString)),
352 this, SIGNAL(changed()));
356 void PrefPlaintext::apply(LyXRC & rc) const
358 rc.plaintext_linelen = plaintextLinelengthSB->value();
359 rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
363 void PrefPlaintext::update(LyXRC const & rc)
365 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
366 plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
370 /////////////////////////////////////////////////////////////////////
374 /////////////////////////////////////////////////////////////////////
376 PrefDate::PrefDate(QWidget * parent)
377 : PrefModule(qt_("Date format"), 0, parent)
380 connect(DateED, SIGNAL(textChanged(QString)),
381 this, SIGNAL(changed()));
385 void PrefDate::apply(LyXRC & rc) const
387 rc.date_insert_format = fromqstr(DateED->text());
391 void PrefDate::update(LyXRC const & rc)
393 DateED->setText(toqstr(rc.date_insert_format));
397 /////////////////////////////////////////////////////////////////////
401 /////////////////////////////////////////////////////////////////////
403 PrefInput::PrefInput(GuiPreferences * form, QWidget * parent)
404 : PrefModule(qt_("Keyboard/Mouse"), form, parent)
408 connect(keymapCB, SIGNAL(clicked()),
409 this, SIGNAL(changed()));
410 connect(firstKeymapED, SIGNAL(textChanged(QString)),
411 this, SIGNAL(changed()));
412 connect(secondKeymapED, SIGNAL(textChanged(QString)),
413 this, SIGNAL(changed()));
414 connect(inlineDelaySB, SIGNAL(valueChanged(double)),
415 this, SIGNAL(changed()));
416 connect(inlineMathCB, SIGNAL(clicked()),
417 this, SIGNAL(changed()));
418 connect(inlineTextCB, SIGNAL(clicked()),
419 this, SIGNAL(changed()));
420 connect(inlineDotsCB, SIGNAL(clicked()),
421 this, SIGNAL(changed()));
422 connect(popupDelaySB, SIGNAL(valueChanged(double)),
423 this, SIGNAL(changed()));
424 connect(popupMathCB, SIGNAL(clicked()),
425 this, SIGNAL(changed()));
426 connect(popupTextCB, SIGNAL(clicked()),
427 this, SIGNAL(changed()));
428 connect(popupAfterCompleteCB, SIGNAL(clicked()),
429 this, SIGNAL(changed()));
430 connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
431 this, SIGNAL(changed()));
435 void PrefInput::apply(LyXRC & rc) const
437 // FIXME: can derive CB from the two EDs
438 rc.use_kbmap = keymapCB->isChecked();
439 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
440 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
441 rc.completion_inline_delay = inlineDelaySB->value();
442 rc.completion_inline_math = inlineMathCB->isChecked();
443 rc.completion_inline_text = inlineTextCB->isChecked();
444 rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
445 rc.completion_popup_delay = popupDelaySB->value();
446 rc.completion_popup_math = popupMathCB->isChecked();
447 rc.completion_popup_text = popupTextCB->isChecked();
448 rc.completion_popup_after_complete
449 = popupAfterCompleteCB->isChecked();
450 rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
454 void PrefInput::update(LyXRC const & rc)
456 // FIXME: can derive CB from the two EDs
457 keymapCB->setChecked(rc.use_kbmap);
458 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
459 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
460 inlineDelaySB->setValue(rc.completion_inline_delay);
461 inlineMathCB->setChecked(rc.completion_inline_math);
462 inlineTextCB->setChecked(rc.completion_inline_text);
463 inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
464 popupDelaySB->setValue(rc.completion_popup_delay);
465 popupMathCB->setChecked(rc.completion_popup_math);
466 popupTextCB->setChecked(rc.completion_popup_text);
467 popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
468 mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
472 QString PrefInput::testKeymap(QString keymap)
474 return form_->browsekbmap(toqstr(internal_path(fromqstr(keymap))));
478 void PrefInput::on_firstKeymapPB_clicked(bool)
480 QString const file = testKeymap(firstKeymapED->text());
482 firstKeymapED->setText(file);
486 void PrefInput::on_secondKeymapPB_clicked(bool)
488 QString const file = testKeymap(secondKeymapED->text());
490 secondKeymapED->setText(file);
494 void PrefInput::on_keymapCB_toggled(bool keymap)
496 firstKeymapLA->setEnabled(keymap);
497 secondKeymapLA->setEnabled(keymap);
498 firstKeymapED->setEnabled(keymap);
499 secondKeymapED->setEnabled(keymap);
500 firstKeymapPB->setEnabled(keymap);
501 secondKeymapPB->setEnabled(keymap);
505 /////////////////////////////////////////////////////////////////////
509 /////////////////////////////////////////////////////////////////////
511 PrefLatex::PrefLatex(GuiPreferences * form, QWidget * parent)
512 : PrefModule(qt_("LaTeX"), form, parent)
515 connect(latexEncodingED, SIGNAL(textChanged(QString)),
516 this, SIGNAL(changed()));
517 connect(latexChecktexED, SIGNAL(textChanged(QString)),
518 this, SIGNAL(changed()));
519 connect(latexBibtexED, SIGNAL(textChanged(QString)),
520 this, SIGNAL(changed()));
521 connect(latexIndexED, SIGNAL(textChanged(QString)),
522 this, SIGNAL(changed()));
523 connect(latexAutoresetCB, SIGNAL(clicked()),
524 this, SIGNAL(changed()));
525 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
526 this, SIGNAL(changed()));
527 connect(latexPaperSizeCO, SIGNAL(activated(int)),
528 this, SIGNAL(changed()));
530 #if defined(__CYGWIN__) || defined(_WIN32)
531 pathCB->setVisible(true);
532 connect(pathCB, SIGNAL(clicked()),
533 this, SIGNAL(changed()));
535 pathCB->setVisible(false);
540 void PrefLatex::apply(LyXRC & rc) const
542 rc.fontenc = fromqstr(latexEncodingED->text());
543 rc.chktex_command = fromqstr(latexChecktexED->text());
544 rc.bibtex_command = fromqstr(latexBibtexED->text());
545 rc.index_command = fromqstr(latexIndexED->text());
546 rc.auto_reset_options = latexAutoresetCB->isChecked();
547 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
548 rc.default_papersize =
549 form_->toPaperSize(latexPaperSizeCO->currentIndex());
550 #if defined(__CYGWIN__) || defined(_WIN32)
551 rc.windows_style_tex_paths = pathCB->isChecked();
556 void PrefLatex::update(LyXRC const & rc)
558 latexEncodingED->setText(toqstr(rc.fontenc));
559 latexChecktexED->setText(toqstr(rc.chktex_command));
560 latexBibtexED->setText(toqstr(rc.bibtex_command));
561 latexIndexED->setText(toqstr(rc.index_command));
562 latexAutoresetCB->setChecked(rc.auto_reset_options);
563 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
564 latexPaperSizeCO->setCurrentIndex(
565 form_->fromPaperSize(rc.default_papersize));
566 #if defined(__CYGWIN__) || defined(_WIN32)
567 pathCB->setChecked(rc.windows_style_tex_paths);
572 /////////////////////////////////////////////////////////////////////
576 /////////////////////////////////////////////////////////////////////
578 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form, QWidget * parent)
579 : PrefModule(qt_("Screen fonts"), form, parent)
583 connect(screenRomanCO, SIGNAL(activated(QString)),
584 this, SLOT(select_roman(QString)));
585 connect(screenSansCO, SIGNAL(activated(QString)),
586 this, SLOT(select_sans(QString)));
587 connect(screenTypewriterCO, SIGNAL(activated(QString)),
588 this, SLOT(select_typewriter(QString)));
590 QFontDatabase fontdb;
591 QStringList families(fontdb.families());
592 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
593 screenRomanCO->addItem(*it);
594 screenSansCO->addItem(*it);
595 screenTypewriterCO->addItem(*it);
597 connect(screenRomanCO, SIGNAL(activated(QString)),
598 this, SIGNAL(changed()));
599 connect(screenSansCO, SIGNAL(activated(QString)),
600 this, SIGNAL(changed()));
601 connect(screenTypewriterCO, SIGNAL(activated(QString)),
602 this, SIGNAL(changed()));
603 connect(screenZoomSB, SIGNAL(valueChanged(int)),
604 this, SIGNAL(changed()));
605 connect(screenDpiSB, SIGNAL(valueChanged(int)),
606 this, SIGNAL(changed()));
607 connect(screenTinyED, SIGNAL(textChanged(QString)),
608 this, SIGNAL(changed()));
609 connect(screenSmallestED, SIGNAL(textChanged(QString)),
610 this, SIGNAL(changed()));
611 connect(screenSmallerED, SIGNAL(textChanged(QString)),
612 this, SIGNAL(changed()));
613 connect(screenSmallED, SIGNAL(textChanged(QString)),
614 this, SIGNAL(changed()));
615 connect(screenNormalED, SIGNAL(textChanged(QString)),
616 this, SIGNAL(changed()));
617 connect(screenLargeED, SIGNAL(textChanged(QString)),
618 this, SIGNAL(changed()));
619 connect(screenLargerED, SIGNAL(textChanged(QString)),
620 this, SIGNAL(changed()));
621 connect(screenLargestED, SIGNAL(textChanged(QString)),
622 this, SIGNAL(changed()));
623 connect(screenHugeED, SIGNAL(textChanged(QString)),
624 this, SIGNAL(changed()));
625 connect(screenHugerED, SIGNAL(textChanged(QString)),
626 this, SIGNAL(changed()));
627 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
628 this, SIGNAL(changed()));
630 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
631 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
632 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
633 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
634 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
635 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
636 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
637 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
638 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
639 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
643 void PrefScreenFonts::apply(LyXRC & rc) const
645 LyXRC const oldrc = rc;
647 parseFontName(screenRomanCO->currentText(),
648 rc.roman_font_name, rc.roman_font_foundry);
649 parseFontName(screenSansCO->currentText(),
650 rc.sans_font_name, rc.sans_font_foundry);
651 parseFontName(screenTypewriterCO->currentText(),
652 rc.typewriter_font_name, rc.typewriter_font_foundry);
654 rc.zoom = screenZoomSB->value();
655 rc.dpi = screenDpiSB->value();
656 rc.font_sizes[FONT_SIZE_TINY] = fromqstr(screenTinyED->text());
657 rc.font_sizes[FONT_SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
658 rc.font_sizes[FONT_SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
659 rc.font_sizes[FONT_SIZE_SMALL] = fromqstr(screenSmallED->text());
660 rc.font_sizes[FONT_SIZE_NORMAL] = fromqstr(screenNormalED->text());
661 rc.font_sizes[FONT_SIZE_LARGE] = fromqstr(screenLargeED->text());
662 rc.font_sizes[FONT_SIZE_LARGER] = fromqstr(screenLargerED->text());
663 rc.font_sizes[FONT_SIZE_LARGEST] = fromqstr(screenLargestED->text());
664 rc.font_sizes[FONT_SIZE_HUGE] = fromqstr(screenHugeED->text());
665 rc.font_sizes[FONT_SIZE_HUGER] = fromqstr(screenHugerED->text());
666 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
668 if (rc.font_sizes != oldrc.font_sizes
669 || rc.roman_font_name != oldrc.roman_font_name
670 || rc.sans_font_name != oldrc.sans_font_name
671 || rc.typewriter_font_name != oldrc.typewriter_font_name
672 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
673 // The global QPixmapCache is used in GuiPainter to cache text
674 // painting so we must reset it in case any of the above
675 // parameter is changed.
676 QPixmapCache::clear();
677 guiApp->fontLoader().update();
678 form_->updateScreenFonts();
683 void PrefScreenFonts::update(LyXRC const & rc)
685 setComboxFont(screenRomanCO, rc.roman_font_name,
686 rc.roman_font_foundry);
687 setComboxFont(screenSansCO, rc.sans_font_name,
688 rc.sans_font_foundry);
689 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
690 rc.typewriter_font_foundry);
692 select_roman(screenRomanCO->currentText());
693 select_sans(screenSansCO->currentText());
694 select_typewriter(screenTypewriterCO->currentText());
696 screenZoomSB->setValue(rc.zoom);
697 screenDpiSB->setValue(rc.dpi);
698 screenTinyED->setText(toqstr(rc.font_sizes[FONT_SIZE_TINY]));
699 screenSmallestED->setText(toqstr(rc.font_sizes[FONT_SIZE_SCRIPT]));
700 screenSmallerED->setText(toqstr(rc.font_sizes[FONT_SIZE_FOOTNOTE]));
701 screenSmallED->setText(toqstr(rc.font_sizes[FONT_SIZE_SMALL]));
702 screenNormalED->setText(toqstr(rc.font_sizes[FONT_SIZE_NORMAL]));
703 screenLargeED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGE]));
704 screenLargerED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGER]));
705 screenLargestED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGEST]));
706 screenHugeED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGE]));
707 screenHugerED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGER]));
709 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
710 #if defined(Q_WS_X11)
711 pixmapCacheCB->setEnabled(false);
717 void PrefScreenFonts::select_roman(const QString & name)
719 screenRomanFE->set(QFont(name), name);
723 void PrefScreenFonts::select_sans(const QString & name)
725 screenSansFE->set(QFont(name), name);
729 void PrefScreenFonts::select_typewriter(const QString & name)
731 screenTypewriterFE->set(QFont(name), name);
735 /////////////////////////////////////////////////////////////////////
739 /////////////////////////////////////////////////////////////////////
745 bool operator()(ColorCode lhs, ColorCode rhs) const {
746 return lcolor.getGUIName(lhs) < lcolor.getGUIName(rhs);
752 PrefColors::PrefColors(GuiPreferences * form, QWidget * parent)
753 : PrefModule(qt_("Colors"), form, parent)
757 // FIXME: all of this initialization should be put into the controller.
758 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
759 // for some discussion of why that is not trivial.
760 QPixmap icon(32, 32);
761 for (int i = 0; i < Color_ignore; ++i) {
762 ColorCode lc = static_cast<ColorCode>(i);
770 || lc == Color_magenta
771 || lc == Color_yellow
772 || lc == Color_inherit
773 || lc == Color_ignore) continue;
775 lcolors_.push_back(lc);
777 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
778 vector<ColorCode>::const_iterator cit = lcolors_.begin();
779 vector<ColorCode>::const_iterator const end = lcolors_.end();
780 for (; cit != end; ++cit) {
781 (void) new QListWidgetItem(QIcon(icon),
782 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
784 curcolors_.resize(lcolors_.size());
785 newcolors_.resize(lcolors_.size());
786 // End initialization
788 connect(colorChangePB, SIGNAL(clicked()),
789 this, SLOT(change_color()));
790 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
791 this, SLOT(change_lyxObjects_selection()));
792 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
793 this, SLOT(change_color()));
797 void PrefColors::apply(LyXRC & /*rc*/) const
799 for (unsigned int i = 0; i < lcolors_.size(); ++i)
800 if (curcolors_[i] != newcolors_[i])
801 form_->setColor(lcolors_[i], fromqstr(newcolors_[i]));
805 void PrefColors::update(LyXRC const & /*rc*/)
807 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
808 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
809 QPixmap coloritem(32, 32);
810 coloritem.fill(color);
811 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
812 newcolors_[i] = curcolors_[i] = color.name();
814 change_lyxObjects_selection();
817 void PrefColors::change_color()
819 int const row = lyxObjectsLW->currentRow();
825 QString const color = newcolors_[row];
826 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
828 if (c.isValid() && c.name() != color) {
829 newcolors_[row] = c.name();
830 QPixmap coloritem(32, 32);
832 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
838 void PrefColors::change_lyxObjects_selection()
840 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
844 /////////////////////////////////////////////////////////////////////
848 /////////////////////////////////////////////////////////////////////
850 PrefDisplay::PrefDisplay(QWidget * parent)
851 : PrefModule(qt_("Graphics"), 0, parent)
854 connect(instantPreviewCO, SIGNAL(activated(int)),
855 this, SIGNAL(changed()));
856 connect(displayGraphicsCO, SIGNAL(activated(int)),
857 this, SIGNAL(changed()));
861 void PrefDisplay::apply(LyXRC & rc) const
863 switch (instantPreviewCO->currentIndex()) {
864 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
865 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
866 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
869 graphics::DisplayType dtype;
870 switch (displayGraphicsCO->currentIndex()) {
871 case 3: dtype = graphics::NoDisplay; break;
872 case 2: dtype = graphics::ColorDisplay; break;
873 case 1: dtype = graphics::GrayscaleDisplay; break;
874 case 0: dtype = graphics::MonochromeDisplay; break;
875 default: dtype = graphics::GrayscaleDisplay;
877 rc.display_graphics = dtype;
879 // FIXME!! The graphics cache no longer has a changeDisplay method.
881 if (old_value != rc.display_graphics) {
882 graphics::GCache & gc = graphics::GCache::get();
889 void PrefDisplay::update(LyXRC const & rc)
891 switch (rc.preview) {
892 case LyXRC::PREVIEW_OFF:
893 instantPreviewCO->setCurrentIndex(0);
895 case LyXRC::PREVIEW_NO_MATH :
896 instantPreviewCO->setCurrentIndex(1);
898 case LyXRC::PREVIEW_ON :
899 instantPreviewCO->setCurrentIndex(2);
904 switch (rc.display_graphics) {
905 case graphics::NoDisplay: item = 3; break;
906 case graphics::ColorDisplay: item = 2; break;
907 case graphics::GrayscaleDisplay: item = 1; break;
908 case graphics::MonochromeDisplay: item = 0; break;
911 displayGraphicsCO->setCurrentIndex(item);
915 /////////////////////////////////////////////////////////////////////
919 /////////////////////////////////////////////////////////////////////
921 PrefPaths::PrefPaths(GuiPreferences * form, QWidget * parent)
922 : PrefModule(qt_("Paths"), form, parent)
925 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(select_exampledir()));
926 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
927 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
928 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
929 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
930 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
931 connect(workingDirED, SIGNAL(textChanged(QString)),
932 this, SIGNAL(changed()));
933 connect(exampleDirED, SIGNAL(textChanged(QString)),
934 this, SIGNAL(changed()));
935 connect(templateDirED, SIGNAL(textChanged(QString)),
936 this, SIGNAL(changed()));
937 connect(backupDirED, SIGNAL(textChanged(QString)),
938 this, SIGNAL(changed()));
939 connect(tempDirED, SIGNAL(textChanged(QString)),
940 this, SIGNAL(changed()));
941 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
942 this, SIGNAL(changed()));
943 connect(pathPrefixED, SIGNAL(textChanged(QString)),
944 this, SIGNAL(changed()));
948 void PrefPaths::apply(LyXRC & rc) const
950 rc.document_path = internal_path(fromqstr(workingDirED->text()));
951 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
952 rc.template_path = internal_path(fromqstr(templateDirED->text()));
953 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
954 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
955 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
956 // FIXME: should be a checkbox only
957 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
961 void PrefPaths::update(LyXRC const & rc)
963 workingDirED->setText(toqstr(external_path(rc.document_path)));
964 exampleDirED->setText(toqstr(external_path(rc.example_path)));
965 templateDirED->setText(toqstr(external_path(rc.template_path)));
966 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
967 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
968 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
969 // FIXME: should be a checkbox only
970 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
974 void PrefPaths::select_exampledir()
976 QString file = form_->browsedir(internalPath(exampleDirED->text()),
977 qt_("Select directory for example files"));
979 exampleDirED->setText(file);
983 void PrefPaths::select_templatedir()
985 QString file = form_->browsedir(internalPath(templateDirED->text()),
986 qt_("Select a document templates directory"));
988 templateDirED->setText(file);
992 void PrefPaths::select_tempdir()
994 QString file = form_->browsedir(internalPath(tempDirED->text()),
995 qt_("Select a temporary directory"));
997 tempDirED->setText(file);
1001 void PrefPaths::select_backupdir()
1003 QString file = form_->browsedir(internalPath(backupDirED->text()),
1004 qt_("Select a backups directory"));
1005 if (!file.isEmpty())
1006 backupDirED->setText(file);
1010 void PrefPaths::select_workingdir()
1012 QString file = form_->browsedir(internalPath(workingDirED->text()),
1013 qt_("Select a document directory"));
1014 if (!file.isEmpty())
1015 workingDirED->setText(file);
1019 void PrefPaths::select_lyxpipe()
1021 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1022 qt_("Give a filename for the LyX server pipe"));
1023 if (!file.isEmpty())
1024 lyxserverDirED->setText(file);
1028 /////////////////////////////////////////////////////////////////////
1032 /////////////////////////////////////////////////////////////////////
1034 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form, QWidget * parent)
1035 : PrefModule(qt_("Spellchecker"), form, parent)
1039 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
1040 #if defined (USE_ISPELL)
1041 connect(spellCommandCO, SIGNAL(activated(int)),
1042 this, SIGNAL(changed()));
1044 spellCommandCO->setEnabled(false);
1046 connect(altLanguageED, SIGNAL(textChanged(QString)),
1047 this, SIGNAL(changed()));
1048 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1049 this, SIGNAL(changed()));
1050 connect(persDictionaryED, SIGNAL(textChanged(QString)),
1051 this, SIGNAL(changed()));
1052 connect(compoundWordCB, SIGNAL(clicked()),
1053 this, SIGNAL(changed()));
1054 connect(inputEncodingCB, SIGNAL(clicked()),
1055 this, SIGNAL(changed()));
1057 spellCommandCO->addItem(qt_("ispell"));
1058 spellCommandCO->addItem(qt_("aspell"));
1059 spellCommandCO->addItem(qt_("hspell"));
1061 spellCommandCO->addItem(qt_("pspell (library)"));
1064 spellCommandCO->addItem(qt_("aspell (library)"));
1070 void PrefSpellchecker::apply(LyXRC & rc) const
1072 switch (spellCommandCO->currentIndex()) {
1076 rc.use_spell_lib = false;
1077 rc.isp_command = fromqstr(spellCommandCO->currentText());
1080 rc.use_spell_lib = true;
1084 // FIXME: remove isp_use_alt_lang
1085 rc.isp_alt_lang = fromqstr(altLanguageED->text());
1086 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
1087 // FIXME: remove isp_use_esc_chars
1088 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
1089 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
1090 // FIXME: remove isp_use_pers_dict
1091 rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
1092 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
1093 rc.isp_accept_compound = compoundWordCB->isChecked();
1094 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
1098 void PrefSpellchecker::update(LyXRC const & rc)
1100 spellCommandCO->setCurrentIndex(0);
1102 if (rc.isp_command == "ispell") {
1103 spellCommandCO->setCurrentIndex(0);
1104 } else if (rc.isp_command == "aspell") {
1105 spellCommandCO->setCurrentIndex(1);
1106 } else if (rc.isp_command == "hspell") {
1107 spellCommandCO->setCurrentIndex(2);
1110 if (rc.use_spell_lib) {
1111 #if defined(USE_ASPELL) || defined(USE_PSPELL)
1112 spellCommandCO->setCurrentIndex(3);
1116 // FIXME: remove isp_use_alt_lang
1117 altLanguageED->setText(toqstr(rc.isp_alt_lang));
1118 // FIXME: remove isp_use_esc_chars
1119 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
1120 // FIXME: remove isp_use_pers_dict
1121 persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
1122 compoundWordCB->setChecked(rc.isp_accept_compound);
1123 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
1127 void PrefSpellchecker::select_dict()
1129 QString file = form_->browsedict(internalPath(persDictionaryED->text()));
1130 if (!file.isEmpty())
1131 persDictionaryED->setText(file);
1136 /////////////////////////////////////////////////////////////////////
1140 /////////////////////////////////////////////////////////////////////
1143 PrefConverters::PrefConverters(GuiPreferences * form, QWidget * parent)
1144 : PrefModule(qt_("Converters"), form, parent)
1148 connect(converterNewPB, SIGNAL(clicked()),
1149 this, SLOT(update_converter()));
1150 connect(converterRemovePB, SIGNAL(clicked()),
1151 this, SLOT(remove_converter()));
1152 connect(converterModifyPB, SIGNAL(clicked()),
1153 this, SLOT(update_converter()));
1154 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1155 this, SLOT(switch_converter()));
1156 connect(converterFromCO, SIGNAL(activated(QString)),
1157 this, SLOT(converter_changed()));
1158 connect(converterToCO, SIGNAL(activated(QString)),
1159 this, SLOT(converter_changed()));
1160 connect(converterED, SIGNAL(textEdited(QString)),
1161 this, SLOT(converter_changed()));
1162 connect(converterFlagED, SIGNAL(textEdited(QString)),
1163 this, SLOT(converter_changed()));
1164 connect(converterNewPB, SIGNAL(clicked()),
1165 this, SIGNAL(changed()));
1166 connect(converterRemovePB, SIGNAL(clicked()),
1167 this, SIGNAL(changed()));
1168 connect(converterModifyPB, SIGNAL(clicked()),
1169 this, SIGNAL(changed()));
1170 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1171 this, SIGNAL(changed()));
1173 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1174 //converterDefGB->setFocusProxy(convertersLW);
1178 void PrefConverters::apply(LyXRC & rc) const
1180 rc.use_converter_cache = cacheCB->isChecked();
1181 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
1185 void PrefConverters::update(LyXRC const & rc)
1187 cacheCB->setChecked(rc.use_converter_cache);
1189 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
1190 maxAgeLE->setText(max_age);
1195 void PrefConverters::updateGui()
1197 form_->formats().sort();
1198 form_->converters().update(form_->formats());
1199 // save current selection
1200 QString current = converterFromCO->currentText()
1201 + " -> " + converterToCO->currentText();
1203 converterFromCO->clear();
1204 converterToCO->clear();
1206 Formats::const_iterator cit = form_->formats().begin();
1207 Formats::const_iterator end = form_->formats().end();
1208 for (; cit != end; ++cit) {
1209 converterFromCO->addItem(toqstr(cit->prettyname()));
1210 converterToCO->addItem(toqstr(cit->prettyname()));
1213 // currentRowChanged(int) is also triggered when updating the listwidget
1214 // block signals to avoid unnecessary calls to switch_converter()
1215 convertersLW->blockSignals(true);
1216 convertersLW->clear();
1218 Converters::const_iterator ccit = form_->converters().begin();
1219 Converters::const_iterator cend = form_->converters().end();
1220 for (; ccit != cend; ++ccit) {
1222 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
1223 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1224 new QListWidgetItem(toqstr(name), convertersLW, type);
1226 convertersLW->sortItems(Qt::AscendingOrder);
1227 convertersLW->blockSignals(false);
1229 // restore selection
1230 if (!current.isEmpty()) {
1231 QList<QListWidgetItem *> const item =
1232 convertersLW->findItems(current, Qt::MatchExactly);
1233 if (!item.isEmpty())
1234 convertersLW->setCurrentItem(item.at(0));
1237 // select first element if restoring failed
1238 if (convertersLW->currentRow() == -1)
1239 convertersLW->setCurrentRow(0);
1245 void PrefConverters::switch_converter()
1247 int const cnr = convertersLW->currentItem()->type();
1248 Converter const & c(form_->converters().get(cnr));
1249 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1250 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1251 converterED->setText(toqstr(c.command));
1252 converterFlagED->setText(toqstr(c.flags));
1258 void PrefConverters::converter_changed()
1264 void PrefConverters::updateButtons()
1266 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1267 Format const & to = form_->formats().get(converterToCO->currentIndex());
1268 int const sel = form_->converters().getNumber(from.name(), to.name());
1269 bool const known = sel >= 0;
1270 bool const valid = !(converterED->text().isEmpty()
1271 || from.name() == to.name());
1273 int const cnr = convertersLW->currentItem()->type();
1274 Converter const & c(form_->converters().get(cnr));
1275 string const old_command = c.command;
1276 string const old_flag = c.flags;
1277 string const new_command(fromqstr(converterED->text()));
1278 string const new_flag(fromqstr(converterFlagED->text()));
1280 bool modified = (old_command != new_command) || (old_flag != new_flag);
1282 converterModifyPB->setEnabled(valid && known && modified);
1283 converterNewPB->setEnabled(valid && !known);
1284 converterRemovePB->setEnabled(known);
1286 maxAgeLE->setEnabled(cacheCB->isChecked());
1287 maxAgeLA->setEnabled(cacheCB->isChecked());
1292 // specify unique from/to or it doesn't appear. This is really bad UI
1293 // this is why we can use the same function for both new and modify
1294 void PrefConverters::update_converter()
1296 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1297 Format const & to = form_->formats().get(converterToCO->currentIndex());
1298 string const flags = fromqstr(converterFlagED->text());
1299 string const command = fromqstr(converterED->text());
1301 Converter const * old =
1302 form_->converters().getConverter(from.name(), to.name());
1303 form_->converters().add(from.name(), to.name(), command, flags);
1306 form_->converters().updateLast(form_->formats());
1310 // Remove all files created by this converter from the cache, since
1311 // the modified converter might create different files.
1312 ConverterCache::get().remove_all(from.name(), to.name());
1316 void PrefConverters::remove_converter()
1318 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1319 Format const & to = form_->formats().get(converterToCO->currentIndex());
1320 form_->converters().erase(from.name(), to.name());
1324 // Remove all files created by this converter from the cache, since
1325 // a possible new converter might create different files.
1326 ConverterCache::get().remove_all(from.name(), to.name());
1330 void PrefConverters::on_cacheCB_stateChanged(int state)
1332 maxAgeLE->setEnabled(state == Qt::Checked);
1333 maxAgeLA->setEnabled(state == Qt::Checked);
1338 /////////////////////////////////////////////////////////////////////
1342 /////////////////////////////////////////////////////////////////////
1344 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1345 : QValidator(parent), formats_(f)
1350 void FormatValidator::fixup(QString & input) const
1352 Formats::const_iterator cit = formats_.begin();
1353 Formats::const_iterator end = formats_.end();
1354 for (; cit != end; ++cit) {
1355 string const name = str(cit);
1356 if (distance(formats_.begin(), cit) == nr()) {
1357 input = toqstr(name);
1365 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1367 Formats::const_iterator cit = formats_.begin();
1368 Formats::const_iterator end = formats_.end();
1369 bool unknown = true;
1370 for (; unknown && cit != end; ++cit) {
1371 string const name = str(cit);
1372 if (distance(formats_.begin(), cit) != nr())
1373 unknown = toqstr(name) != input;
1376 if (unknown && !input.isEmpty())
1377 return QValidator::Acceptable;
1379 return QValidator::Intermediate;
1383 int FormatValidator::nr() const
1385 QComboBox * p = qobject_cast<QComboBox *>(parent());
1386 return p->itemData(p->currentIndex()).toInt();
1390 FormatNameValidator::FormatNameValidator(QWidget * parent, Formats const & f)
1391 : FormatValidator(parent, f)
1395 string FormatNameValidator::str(Formats::const_iterator it) const
1401 FormatPrettynameValidator::FormatPrettynameValidator(QWidget * parent, Formats const & f)
1402 : FormatValidator(parent, f)
1407 string FormatPrettynameValidator::str(Formats::const_iterator it) const
1409 return it->prettyname();
1413 PrefFileformats::PrefFileformats(GuiPreferences * form, QWidget * parent)
1414 : PrefModule(qt_("File formats"), form, parent)
1417 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1418 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1420 connect(documentCB, SIGNAL(clicked()),
1421 this, SLOT(setFlags()));
1422 connect(vectorCB, SIGNAL(clicked()),
1423 this, SLOT(setFlags()));
1424 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1425 this, SLOT(updatePrettyname()));
1426 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1427 this, SIGNAL(changed()));
1431 void PrefFileformats::apply(LyXRC & /*rc*/) const
1436 void PrefFileformats::update(LyXRC const & /*rc*/)
1442 void PrefFileformats::updateView()
1444 QString const current = formatsCB->currentText();
1446 // update combobox with formats
1447 formatsCB->blockSignals(true);
1449 form_->formats().sort();
1450 Formats::const_iterator cit = form_->formats().begin();
1451 Formats::const_iterator end = form_->formats().end();
1452 for (; cit != end; ++cit)
1453 formatsCB->addItem(toqstr(cit->prettyname()),
1454 QVariant(form_->formats().getNumber(cit->name())) );
1456 // restore selection
1457 int const item = formatsCB->findText(current, Qt::MatchExactly);
1458 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1459 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1460 formatsCB->blockSignals(false);
1464 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1466 int const nr = formatsCB->itemData(i).toInt();
1467 Format const f = form_->formats().get(nr);
1469 formatED->setText(toqstr(f.name()));
1470 copierED->setText(toqstr(form_->movers().command(f.name())));
1471 extensionED->setText(toqstr(f.extension()));
1472 shortcutED->setText(toqstr(f.shortcut()));
1473 viewerED->setText(toqstr(f.viewer()));
1474 editorED->setText(toqstr(f.editor()));
1475 documentCB->setChecked((f.documentFormat()));
1476 vectorCB->setChecked((f.vectorFormat()));
1480 void PrefFileformats::setFlags()
1482 int flags = Format::none;
1483 if (documentCB->isChecked())
1484 flags |= Format::document;
1485 if (vectorCB->isChecked())
1486 flags |= Format::vector;
1487 currentFormat().setFlags(flags);
1492 void PrefFileformats::on_copierED_textEdited(const QString & s)
1494 string const fmt = fromqstr(formatED->text());
1495 form_->movers().set(fmt, fromqstr(s));
1500 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1502 currentFormat().setExtension(fromqstr(s));
1506 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1508 currentFormat().setViewer(fromqstr(s));
1513 void PrefFileformats::on_editorED_textEdited(const QString & s)
1515 currentFormat().setEditor(fromqstr(s));
1520 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1522 currentFormat().setShortcut(fromqstr(s));
1527 void PrefFileformats::on_formatED_editingFinished()
1529 string const newname = fromqstr(formatED->displayText());
1530 if (newname == currentFormat().name())
1533 currentFormat().setName(newname);
1538 void PrefFileformats::on_formatED_textChanged(const QString &)
1540 QString t = formatED->text();
1542 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1543 setValid(formatLA, valid);
1547 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1549 QString t = formatsCB->currentText();
1551 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1552 setValid(formatsLA, valid);
1556 void PrefFileformats::updatePrettyname()
1558 string const newname = fromqstr(formatsCB->currentText());
1559 if (newname == currentFormat().prettyname())
1562 currentFormat().setPrettyname(newname);
1569 Format & PrefFileformats::currentFormat()
1571 int const i = formatsCB->currentIndex();
1572 int const nr = formatsCB->itemData(i).toInt();
1573 return form_->formats().get(nr);
1577 void PrefFileformats::on_formatNewPB_clicked()
1579 form_->formats().add("", "", "", "", "", "", Format::none);
1581 formatsCB->setCurrentIndex(0);
1582 formatsCB->setFocus(Qt::OtherFocusReason);
1586 void PrefFileformats::on_formatRemovePB_clicked()
1588 int const i = formatsCB->currentIndex();
1589 int const nr = formatsCB->itemData(i).toInt();
1590 string const current_text = form_->formats().get(nr).name();
1591 if (form_->converters().formatIsUsed(current_text)) {
1592 Alert::error(_("Format in use"),
1593 _("Cannot remove a Format used by a Converter. "
1594 "Remove the converter first."));
1598 form_->formats().erase(current_text);
1601 on_formatsCB_editTextChanged(formatsCB->currentText());
1606 /////////////////////////////////////////////////////////////////////
1610 /////////////////////////////////////////////////////////////////////
1612 PrefLanguage::PrefLanguage(QWidget * parent)
1613 : PrefModule(qt_("Language"), 0, parent)
1617 connect(rtlGB, SIGNAL(clicked()),
1618 this, SIGNAL(changed()));
1619 connect(visualCursorRB, SIGNAL(clicked()),
1620 this, SIGNAL(changed()));
1621 connect(logicalCursorRB, SIGNAL(clicked()),
1622 this, SIGNAL(changed()));
1623 connect(markForeignCB, SIGNAL(clicked()),
1624 this, SIGNAL(changed()));
1625 connect(autoBeginCB, SIGNAL(clicked()),
1626 this, SIGNAL(changed()));
1627 connect(autoEndCB, SIGNAL(clicked()),
1628 this, SIGNAL(changed()));
1629 connect(useBabelCB, SIGNAL(clicked()),
1630 this, SIGNAL(changed()));
1631 connect(globalCB, SIGNAL(clicked()),
1632 this, SIGNAL(changed()));
1633 connect(languagePackageED, SIGNAL(textChanged(QString)),
1634 this, SIGNAL(changed()));
1635 connect(startCommandED, SIGNAL(textChanged(QString)),
1636 this, SIGNAL(changed()));
1637 connect(endCommandED, SIGNAL(textChanged(QString)),
1638 this, SIGNAL(changed()));
1639 connect(defaultLanguageCO, SIGNAL(activated(int)),
1640 this, SIGNAL(changed()));
1642 defaultLanguageCO->clear();
1644 // store the lang identifiers for later
1645 vector<LanguagePair> const langs = getLanguageData(false);
1646 vector<LanguagePair>::const_iterator lit = langs.begin();
1647 vector<LanguagePair>::const_iterator lend = langs.end();
1649 for (; lit != lend; ++lit) {
1650 defaultLanguageCO->addItem(toqstr(lit->first));
1651 lang_.push_back(lit->second);
1656 void PrefLanguage::apply(LyXRC & rc) const
1658 // FIXME: remove rtl_support bool
1659 rc.rtl_support = rtlGB->isChecked();
1660 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
1661 rc.mark_foreign_language = markForeignCB->isChecked();
1662 rc.language_auto_begin = autoBeginCB->isChecked();
1663 rc.language_auto_end = autoEndCB->isChecked();
1664 rc.language_use_babel = useBabelCB->isChecked();
1665 rc.language_global_options = globalCB->isChecked();
1666 rc.language_package = fromqstr(languagePackageED->text());
1667 rc.language_command_begin = fromqstr(startCommandED->text());
1668 rc.language_command_end = fromqstr(endCommandED->text());
1669 rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1673 void PrefLanguage::update(LyXRC const & rc)
1675 // FIXME: remove rtl_support bool
1676 rtlGB->setChecked(rc.rtl_support);
1677 if (rc.visual_cursor)
1678 visualCursorRB->setChecked(true);
1680 logicalCursorRB->setChecked(true);
1681 markForeignCB->setChecked(rc.mark_foreign_language);
1682 autoBeginCB->setChecked(rc.language_auto_begin);
1683 autoEndCB->setChecked(rc.language_auto_end);
1684 useBabelCB->setChecked(rc.language_use_babel);
1685 globalCB->setChecked(rc.language_global_options);
1686 languagePackageED->setText(toqstr(rc.language_package));
1687 startCommandED->setText(toqstr(rc.language_command_begin));
1688 endCommandED->setText(toqstr(rc.language_command_end));
1690 int const pos = int(findPos_helper(lang_, rc.default_language));
1691 defaultLanguageCO->setCurrentIndex(pos);
1695 /////////////////////////////////////////////////////////////////////
1699 /////////////////////////////////////////////////////////////////////
1701 PrefPrinter::PrefPrinter(QWidget * parent)
1702 : PrefModule(qt_("Printer"), 0, parent)
1706 connect(printerAdaptCB, SIGNAL(clicked()),
1707 this, SIGNAL(changed()));
1708 connect(printerCommandED, SIGNAL(textChanged(QString)),
1709 this, SIGNAL(changed()));
1710 connect(printerNameED, SIGNAL(textChanged(QString)),
1711 this, SIGNAL(changed()));
1712 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
1713 this, SIGNAL(changed()));
1714 connect(printerCopiesED, SIGNAL(textChanged(QString)),
1715 this, SIGNAL(changed()));
1716 connect(printerReverseED, SIGNAL(textChanged(QString)),
1717 this, SIGNAL(changed()));
1718 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
1719 this, SIGNAL(changed()));
1720 connect(printerExtensionED, SIGNAL(textChanged(QString)),
1721 this, SIGNAL(changed()));
1722 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
1723 this, SIGNAL(changed()));
1724 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
1725 this, SIGNAL(changed()));
1726 connect(printerEvenED, SIGNAL(textChanged(QString)),
1727 this, SIGNAL(changed()));
1728 connect(printerOddED, SIGNAL(textChanged(QString)),
1729 this, SIGNAL(changed()));
1730 connect(printerCollatedED, SIGNAL(textChanged(QString)),
1731 this, SIGNAL(changed()));
1732 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
1733 this, SIGNAL(changed()));
1734 connect(printerToFileED, SIGNAL(textChanged(QString)),
1735 this, SIGNAL(changed()));
1736 connect(printerExtraED, SIGNAL(textChanged(QString)),
1737 this, SIGNAL(changed()));
1738 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
1739 this, SIGNAL(changed()));
1740 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
1741 this, SIGNAL(changed()));
1745 void PrefPrinter::apply(LyXRC & rc) const
1747 rc.print_adapt_output = printerAdaptCB->isChecked();
1748 rc.print_command = fromqstr(printerCommandED->text());
1749 rc.printer = fromqstr(printerNameED->text());
1751 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1752 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1753 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1754 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1755 rc.print_file_extension = fromqstr(printerExtensionED->text());
1756 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1757 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1758 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1759 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1760 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1761 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1762 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1763 rc.print_extra_options = fromqstr(printerExtraED->text());
1764 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1765 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1769 void PrefPrinter::update(LyXRC const & rc)
1771 printerAdaptCB->setChecked(rc.print_adapt_output);
1772 printerCommandED->setText(toqstr(rc.print_command));
1773 printerNameED->setText(toqstr(rc.printer));
1775 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1776 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1777 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1778 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1779 printerExtensionED->setText(toqstr(rc.print_file_extension));
1780 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1781 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1782 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1783 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1784 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1785 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1786 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1787 printerExtraED->setText(toqstr(rc.print_extra_options));
1788 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1789 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1793 /////////////////////////////////////////////////////////////////////
1795 // PrefUserInterface
1797 /////////////////////////////////////////////////////////////////////
1799 PrefUserInterface::PrefUserInterface(GuiPreferences * form, QWidget * parent)
1800 : PrefModule(qt_("User interface"), form, parent)
1804 connect(autoSaveCB, SIGNAL(toggled(bool)),
1805 autoSaveSB, SLOT(setEnabled(bool)));
1806 connect(autoSaveCB, SIGNAL(toggled(bool)),
1807 TextLabel1, SLOT(setEnabled(bool)));
1808 connect(uiFilePB, SIGNAL(clicked()),
1809 this, SLOT(select_ui()));
1810 connect(uiFileED, SIGNAL(textChanged(QString)),
1811 this, SIGNAL(changed()));
1812 connect(restoreCursorCB, SIGNAL(clicked()),
1813 this, SIGNAL(changed()));
1814 connect(loadSessionCB, SIGNAL(clicked()),
1815 this, SIGNAL(changed()));
1816 connect(allowGeometrySessionCB, SIGNAL(clicked()),
1817 this, SIGNAL(changed()));
1818 connect(cursorFollowsCB, SIGNAL(clicked()),
1819 this, SIGNAL(changed()));
1820 connect(sortEnvironmentsCB, SIGNAL(clicked()),
1821 this, SIGNAL(changed()));
1822 connect(macroEditStyleCO, SIGNAL(activated(int)),
1823 this, SIGNAL(changed()));
1824 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1825 this, SIGNAL(changed()));
1826 connect(autoSaveCB, SIGNAL(clicked()),
1827 this, SIGNAL(changed()));
1828 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1829 this, SIGNAL(changed()));
1830 connect(tooltipCB, SIGNAL(toggled(bool)),
1831 this, SIGNAL(changed()));
1832 connect(fullscreenLimitGB, SIGNAL(clicked()),
1833 this, SIGNAL(changed()));
1834 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
1835 this, SIGNAL(changed()));
1836 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
1837 this, SIGNAL(changed()));
1838 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
1839 this, SIGNAL(changed()));
1840 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
1841 this, SIGNAL(changed()));
1842 lastfilesSB->setMaximum(maxlastfiles);
1846 void PrefUserInterface::apply(LyXRC & rc) const
1848 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1849 rc.use_lastfilepos = restoreCursorCB->isChecked();
1850 rc.load_session = loadSessionCB->isChecked();
1851 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
1852 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1853 rc.sort_layouts = sortEnvironmentsCB->isChecked();
1854 switch (macroEditStyleCO->currentIndex()) {
1855 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
1856 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
1857 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
1859 rc.autosave = autoSaveSB->value() * 60;
1860 rc.make_backup = autoSaveCB->isChecked();
1861 rc.num_lastfiles = lastfilesSB->value();
1862 rc.use_tooltip = tooltipCB->isChecked();
1863 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
1864 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
1865 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
1866 rc.full_screen_width = fullscreenWidthSB->value();
1867 rc.full_screen_limit = fullscreenLimitGB->isChecked();
1871 void PrefUserInterface::update(LyXRC const & rc)
1873 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1874 restoreCursorCB->setChecked(rc.use_lastfilepos);
1875 loadSessionCB->setChecked(rc.load_session);
1876 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
1877 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1878 sortEnvironmentsCB->setChecked(rc.sort_layouts);
1879 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
1880 // convert to minutes
1881 int mins(rc.autosave / 60);
1882 if (rc.autosave && !mins)
1884 autoSaveSB->setValue(mins);
1885 autoSaveCB->setChecked(rc.make_backup);
1886 lastfilesSB->setValue(rc.num_lastfiles);
1887 tooltipCB->setChecked(rc.use_tooltip);
1888 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
1889 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
1890 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
1891 fullscreenWidthSB->setValue(rc.full_screen_width);
1892 fullscreenLimitGB->setChecked(rc.full_screen_limit);
1897 void PrefUserInterface::select_ui()
1899 QString file = form_->browseUI(internalPath(uiFileED->text()));
1900 if (!file.isEmpty())
1901 uiFileED->setText(file);
1905 /////////////////////////////////////////////////////////////////////
1909 /////////////////////////////////////////////////////////////////////
1912 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
1914 Ui::shortcutUi::setupUi(this);
1915 QDialog::setModal(true);
1919 PrefShortcuts::PrefShortcuts(GuiPreferences * form, QWidget * parent)
1920 : PrefModule(qt_("Shortcuts"), form, parent)
1924 shortcutsTW->setColumnCount(2);
1925 shortcutsTW->headerItem()->setText(0, qt_("Function"));
1926 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
1927 shortcutsTW->setSortingEnabled(true);
1928 // Multi-selection can be annoying.
1929 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
1930 shortcutsTW->header()->resizeSection(0, 200);
1932 connect(bindFilePB, SIGNAL(clicked()),
1933 this, SLOT(select_bind()));
1934 connect(bindFileED, SIGNAL(textChanged(QString)),
1935 this, SIGNAL(changed()));
1936 connect(removePB, SIGNAL(clicked()),
1937 this, SIGNAL(changed()));
1939 shortcut_ = new GuiShortcutDialog(this);
1940 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
1941 shortcut_bc_.setOK(shortcut_->okPB);
1942 shortcut_bc_.setCancel(shortcut_->cancelPB);
1944 connect(shortcut_->okPB, SIGNAL(clicked()),
1945 shortcut_, SLOT(accept()));
1946 connect(shortcut_->okPB, SIGNAL(clicked()),
1947 this, SIGNAL(changed()));
1948 connect(shortcut_->cancelPB, SIGNAL(clicked()),
1949 shortcut_, SLOT(reject()));
1950 connect(shortcut_->clearPB, SIGNAL(clicked()),
1951 this, SLOT(shortcut_clearPB_pressed()));
1952 connect(shortcut_->okPB, SIGNAL(clicked()),
1953 this, SLOT(shortcut_okPB_pressed()));
1957 void PrefShortcuts::apply(LyXRC & rc) const
1959 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1960 // write user_bind and user_unbind to .lyx/bind/user.bind
1961 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
1962 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
1963 lyxerr << "LyX could not create the user bind directory '"
1964 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
1967 if (!bind_dir.isDirWritable()) {
1968 lyxerr << "LyX could not write to the user bind directory '"
1969 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
1972 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
1973 user_bind_.write(user_bind_file.toFilesystemEncoding(), false, false);
1974 user_unbind_.write(user_bind_file.toFilesystemEncoding(), true, true);
1975 // immediately apply the keybindings. Why this is not done before?
1976 // The good thing is that the menus are updated automatically.
1977 theTopLevelKeymap().clear();
1978 theTopLevelKeymap().read("site");
1979 theTopLevelKeymap().read(rc.bind_file);
1980 theTopLevelKeymap().read("user");
1984 void PrefShortcuts::update(LyXRC const & rc)
1986 bindFileED->setText(toqstr(external_path(rc.bind_file)));
1988 system_bind_.clear();
1990 user_unbind_.clear();
1991 system_bind_.read(rc.bind_file);
1992 // \unbind in user.bind is added to user_unbind_
1993 user_bind_.read("user", &user_unbind_);
1994 updateShortcutsTW();
1998 void PrefShortcuts::updateShortcutsTW()
2000 shortcutsTW->clear();
2002 editItem_ = new QTreeWidgetItem(shortcutsTW);
2003 editItem_->setText(0, toqstr("Cursor, Mouse and Editing functions"));
2004 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2006 mathItem_ = new QTreeWidgetItem(shortcutsTW);
2007 mathItem_->setText(0, toqstr("Mathematical Symbols"));
2008 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2010 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2011 bufferItem_->setText(0, toqstr("Buffer and Window"));
2012 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2014 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2015 layoutItem_->setText(0, toqstr("Font, Layouts and Textclasses"));
2016 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2018 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2019 systemItem_->setText(0, toqstr("System and Miscellaneous"));
2020 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2022 // listBindings(unbound=true) lists all bound and unbound lfuns
2023 // Items in this list is tagged by its source.
2024 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2025 static_cast<int>(System));
2026 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2027 static_cast<int>(UserBind));
2028 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2029 static_cast<int>(UserUnbind));
2030 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2031 user_bindinglist.end());
2032 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2033 user_unbindinglist.end());
2035 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2036 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2037 for (; it != it_end; ++it)
2038 insertShortcutItem(it->request, it->sequence, item_type(it->tag));
2040 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2041 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2042 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2046 void PrefShortcuts::setItemType(QTreeWidgetItem * item, item_type tag)
2048 item->setData(0, Qt::UserRole, QVariant(tag));
2058 font.setStrikeOut(true);
2060 // this item is not displayed now.
2061 case UserExtraUnbind:
2062 font.setStrikeOut(true);
2066 item->setFont(1, font);
2070 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2071 KeySequence const & seq, item_type tag)
2073 kb_action action = lfun.action;
2074 string const action_name = lyxaction.getActionName(action);
2075 QString const lfun_name = toqstr(from_utf8(action_name)
2076 + " " + lfun.argument());
2077 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2078 item_type item_tag = tag;
2080 QTreeWidgetItem * newItem = NULL;
2081 // for unbind items, try to find an existing item in the system bind list
2082 if (tag == UserUnbind) {
2083 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2084 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2085 for (int i = 0; i < items.size(); ++i) {
2086 if (items[i]->text(1) == shortcut)
2090 // if not found, this unbind item is UserExtraUnbind
2091 // Such an item is not displayed to avoid confusion (what is
2092 // unmatched removed?).
2094 item_tag = UserExtraUnbind;
2099 switch(lyxaction.getActionType(action)) {
2100 case LyXAction::Hidden:
2102 case LyXAction::Edit:
2103 newItem = new QTreeWidgetItem(editItem_);
2105 case LyXAction::Math:
2106 newItem = new QTreeWidgetItem(mathItem_);
2108 case LyXAction::Buffer:
2109 newItem = new QTreeWidgetItem(bufferItem_);
2111 case LyXAction::Layout:
2112 newItem = new QTreeWidgetItem(layoutItem_);
2114 case LyXAction::System:
2115 newItem = new QTreeWidgetItem(systemItem_);
2118 // this should not happen
2119 newItem = new QTreeWidgetItem(shortcutsTW);
2123 newItem->setText(0, lfun_name);
2124 newItem->setText(1, shortcut);
2125 // record BindFile representation to recover KeySequence when needed.
2126 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2127 setItemType(newItem, item_tag);
2132 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2134 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2135 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2136 if (items.isEmpty())
2139 item_type tag = static_cast<item_type>(items[0]->data(0, Qt::UserRole).toInt());
2140 if (tag == UserUnbind)
2141 removePB->setText(toqstr("Restore"));
2143 removePB->setText(toqstr("Remove"));
2147 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2149 QTreeWidgetItem * item = shortcutsTW->currentItem();
2150 if (item->flags() & Qt::ItemIsSelectable) {
2151 shortcut_->lfunLE->setText(item->text(0));
2152 // clear the shortcut because I assume that a user will enter
2154 shortcut_->shortcutLE->reset();
2155 shortcut_->shortcutLE->setFocus();
2161 void PrefShortcuts::select_bind()
2163 QString file = form_->browsebind(internalPath(bindFileED->text()));
2164 if (!file.isEmpty()) {
2165 bindFileED->setText(file);
2166 system_bind_ = KeyMap();
2167 system_bind_.read(fromqstr(file));
2168 updateShortcutsTW();
2173 void PrefShortcuts::on_newPB_pressed()
2175 shortcut_->lfunLE->clear();
2176 shortcut_->shortcutLE->reset();
2181 void PrefShortcuts::on_removePB_pressed()
2183 // it seems that only one item can be selected, but I am
2184 // removing all selected items anyway.
2185 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2186 for (int i = 0; i < items.size(); ++i) {
2187 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2188 string lfun = fromqstr(items[i]->text(0));
2189 FuncRequest func = lyxaction.lookupFunc(lfun);
2190 item_type tag = static_cast<item_type>(items[i]->data(0, Qt::UserRole).toInt());
2194 // for system bind, we do not touch the item
2195 // but add an user unbind item
2196 user_unbind_.bind(shortcut, func);
2197 setItemType(items[i], UserUnbind);
2198 removePB->setText(toqstr("Restore"));
2202 // for user_bind, we remove this bind
2203 QTreeWidgetItem * parent = items[i]->parent();
2204 int itemIdx = parent->indexOfChild(items[i]);
2205 parent->takeChild(itemIdx);
2207 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2209 shortcutsTW->scrollToItem(parent);
2210 user_bind_.unbind(shortcut, func);
2214 // for user_unbind, we remove the unbind, and the item
2215 // become System again.
2216 user_unbind_.unbind(shortcut, func);
2217 setItemType(items[i], System);
2218 removePB->setText(toqstr("Remove"));
2221 case UserExtraUnbind: {
2222 // for user unbind that is not in system bind file,
2223 // remove this unbind file
2224 QTreeWidgetItem * parent = items[i]->parent();
2225 parent->takeChild(parent->indexOfChild(items[i]));
2226 user_unbind_.unbind(shortcut, func);
2233 void PrefShortcuts::on_searchLE_textEdited()
2235 if (searchLE->text().isEmpty()) {
2236 // show all hidden items
2237 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2239 shortcutsTW->setItemHidden(*it++, false);
2242 // search both columns
2243 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2244 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2245 matched += shortcutsTW->findItems(searchLE->text(),
2246 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2248 // hide everyone (to avoid searching in matched QList repeatedly
2249 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2251 shortcutsTW->setItemHidden(*it++, true);
2252 // show matched items
2253 for (int i = 0; i < matched.size(); ++i) {
2254 shortcutsTW->setItemHidden(matched[i], false);
2255 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2260 void PrefShortcuts::shortcut_okPB_pressed()
2262 string lfun = fromqstr(shortcut_->lfunLE->text());
2263 FuncRequest func = lyxaction.lookupFunc(lfun);
2265 if (func.action == LFUN_UNKNOWN_ACTION) {
2266 Alert::error(_("Failed to create shortcut"),
2267 _("Unknown or invalid LyX function"));
2271 KeySequence k = shortcut_->shortcutLE->getKeySequence();
2272 if (k.length() == 0) {
2273 Alert::error(_("Failed to create shortcut"),
2274 _("Invalid or empty key sequence"));
2278 // if both lfun and shortcut is valid
2279 if (user_bind_.hasBinding(k, func) || system_bind_.hasBinding(k, func)) {
2280 Alert::error(_("Failed to create shortcut"),
2281 _("Shortcut is already defined"));
2285 QTreeWidgetItem * item = insertShortcutItem(func, k, UserBind);
2287 user_bind_.bind(&k, func);
2288 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2289 shortcutsTW->setItemExpanded(item->parent(), true);
2290 shortcutsTW->scrollToItem(item);
2292 Alert::error(_("Failed to create shortcut"),
2293 _("Can not insert shortcut to the list"));
2299 void PrefShortcuts::shortcut_clearPB_pressed()
2301 shortcut_->shortcutLE->reset();
2302 shortcut_->shortcutLE->setFocus();
2306 /////////////////////////////////////////////////////////////////////
2310 /////////////////////////////////////////////////////////////////////
2312 PrefIdentity::PrefIdentity(QWidget * parent)
2313 : PrefModule(qt_("Identity"), 0, parent)
2317 connect(nameED, SIGNAL(textChanged(QString)),
2318 this, SIGNAL(changed()));
2319 connect(emailED, SIGNAL(textChanged(QString)),
2320 this, SIGNAL(changed()));
2324 void PrefIdentity::apply(LyXRC & rc) const
2326 rc.user_name = fromqstr(nameED->text());
2327 rc.user_email = fromqstr(emailED->text());
2331 void PrefIdentity::update(LyXRC const & rc)
2333 nameED->setText(toqstr(rc.user_name));
2334 emailED->setText(toqstr(rc.user_email));
2339 /////////////////////////////////////////////////////////////////////
2343 /////////////////////////////////////////////////////////////////////
2345 GuiPreferences::GuiPreferences(GuiView & lv)
2346 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2350 QDialog::setModal(false);
2352 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2353 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2354 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2355 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2357 add(new PrefUserInterface(this));
2358 add(new PrefShortcuts(this));
2359 add(new PrefScreenFonts(this));
2360 add(new PrefColors(this));
2361 add(new PrefDisplay);
2362 add(new PrefInput(this));
2364 add(new PrefPaths(this));
2366 add(new PrefIdentity);
2368 add(new PrefLanguage);
2369 add(new PrefSpellchecker(this));
2371 add(new PrefPrinter);
2373 add(new PrefPlaintext);
2374 add(new PrefLatex(this));
2376 PrefConverters * converters = new PrefConverters(this);
2377 PrefFileformats * formats = new PrefFileformats(this);
2378 connect(formats, SIGNAL(formatsChanged()),
2379 converters, SLOT(updateGui()));
2383 prefsPS->setCurrentPanel(qt_("User interface"));
2384 // FIXME: hack to work around resizing bug in Qt >= 4.2
2385 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2386 #if QT_VERSION >= 0x040200
2387 prefsPS->updateGeometry();
2390 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2392 bc().setApply(applyPB);
2393 bc().setCancel(closePB);
2394 bc().setRestore(restorePB);
2398 void GuiPreferences::add(PrefModule * module)
2400 BOOST_ASSERT(module);
2401 prefsPS->addPanel(module, module->title());
2402 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2403 modules_.push_back(module);
2407 void GuiPreferences::change_adaptor()
2413 void GuiPreferences::apply(LyXRC & rc) const
2415 size_t end = modules_.size();
2416 for (size_t i = 0; i != end; ++i)
2417 modules_[i]->apply(rc);
2421 void GuiPreferences::updateRc(LyXRC const & rc)
2423 size_t const end = modules_.size();
2424 for (size_t i = 0; i != end; ++i)
2425 modules_[i]->update(rc);
2429 void GuiPreferences::applyView()
2435 void GuiPreferences::updateContents()
2441 bool GuiPreferences::initialiseParams(string const &)
2444 formats_ = lyx::formats;
2445 converters_ = theConverters();
2446 converters_.update(formats_);
2447 movers_ = theMovers();
2449 update_screen_font_ = false;
2455 void GuiPreferences::dispatchParams()
2458 rc_.write(ss, true);
2459 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
2460 // FIXME: these need lfuns
2462 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
2464 lyx::formats = formats_;
2466 theConverters() = converters_;
2467 theConverters().update(lyx::formats);
2468 theConverters().buildGraph();
2470 theMovers() = movers_;
2472 vector<string>::const_iterator it = colors_.begin();
2473 vector<string>::const_iterator const end = colors_.end();
2474 for (; it != end; ++it)
2475 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
2478 if (update_screen_font_) {
2479 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2480 update_screen_font_ = false;
2483 // The Save button has been pressed
2485 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
2489 void GuiPreferences::setColor(ColorCode col, string const & hex)
2491 colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
2495 void GuiPreferences::updateScreenFonts()
2497 update_screen_font_ = true;
2501 QString GuiPreferences::browsebind(QString const & file) const
2503 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
2504 FileFilterList(_("LyX bind files (*.bind)")));
2508 QString GuiPreferences::browseUI(QString const & file) const
2510 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
2511 FileFilterList(_("LyX UI files (*.ui)")));
2515 QString GuiPreferences::browsekbmap(QString const & file) const
2517 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
2518 FileFilterList(_("LyX keyboard maps (*.kmap)")));
2522 QString GuiPreferences::browsedict(QString const & file) const
2524 return browseFile(file, qt_("Choose personal dictionary"),
2525 FileFilterList(lyxrc.use_spell_lib ? _("*.pws") : _("*.ispell")));
2529 QString GuiPreferences::browse(QString const & file,
2530 QString const & title) const
2532 return browseFile(file, title, FileFilterList(), true);
2536 QString GuiPreferences::browsedir(QString const & path,
2537 QString const & title) const
2539 return browseDir(path, title);
2543 // We support less paper sizes than the document dialog
2544 // Therefore this adjustment is needed.
2545 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
2549 return PAPER_DEFAULT;
2551 return PAPER_USLETTER;
2553 return PAPER_USLEGAL;
2555 return PAPER_USEXECUTIVE;
2565 // should not happen
2566 return PAPER_DEFAULT;
2571 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
2573 switch (papersize) {
2576 case PAPER_USLETTER:
2580 case PAPER_USEXECUTIVE:
2591 // should not happen
2597 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
2600 } // namespace frontend
2603 #include "GuiPrefs_moc.cpp"