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 } // namespace frontend
190 QString browseRelFile(QString const & filename, QString const & refpath,
191 QString const & title, FileFilterList const & filters, bool save,
192 QString const & label1, QString const & dir1,
193 QString const & label2, QString const & dir2)
195 QString const fname = toqstr(makeAbsPath(
196 fromqstr(filename), fromqstr(refpath)).absFilename());
198 QString const outname =
199 frontend::browseFile(fname, title, filters, save, label1, dir1, label2, dir2);
201 QString const reloutname =
202 toqstr(makeRelPath(qstring_to_ucs4(outname), qstring_to_ucs4(refpath)));
204 if (reloutname.startsWith("../"))
211 /////////////////////////////////////////////////////////////////////
215 /////////////////////////////////////////////////////////////////////
220 static size_t findPos_helper(vector<A> const & vec, A const & val)
222 typedef typename vector<A>::const_iterator Cit;
224 Cit it = find(vec.begin(), vec.end(), val);
227 return distance(vec.begin(), it);
231 static void parseFontName(QString const & mangled0,
232 string & name, string & foundry)
234 string mangled = fromqstr(mangled0);
235 size_t const idx = mangled.find('[');
236 if (idx == string::npos || idx == 0) {
240 name = mangled.substr(0, idx - 1),
241 foundry = mangled.substr(idx + 1, mangled.size() - idx - 2);
246 static void setComboxFont(QComboBox * cb, string const & family,
247 string const & foundry)
249 QString fontname = toqstr(family);
250 if (!foundry.empty())
251 fontname += " [" + toqstr(foundry) + ']';
253 for (int i = 0; i != cb->count(); ++i) {
254 if (cb->itemText(i) == fontname) {
255 cb->setCurrentIndex(i);
260 // Try matching without foundry name
262 // We count in reverse in order to prefer the Xft foundry
263 for (int i = cb->count(); --i >= 0;) {
264 string name, foundry;
265 parseFontName(cb->itemText(i), name, foundry);
266 if (compare_ascii_no_case(name, family) == 0) {
267 cb->setCurrentIndex(i);
272 // family alone can contain e.g. "Helvetica [Adobe]"
273 string tmpname, tmpfoundry;
274 parseFontName(toqstr(family), tmpname, tmpfoundry);
276 // We count in reverse in order to prefer the Xft foundry
277 for (int i = cb->count(); --i >= 0; ) {
278 string name, foundry;
279 parseFontName(cb->itemText(i), name, foundry);
280 if (compare_ascii_no_case(name, foundry) == 0) {
281 cb->setCurrentIndex(i);
286 // Bleh, default fonts, and the names couldn't be found. Hack
290 font.setKerning(false);
292 QString const font_family = toqstr(family);
293 if (font_family == guiApp->romanFontName()) {
294 font.setStyleHint(QFont::Serif);
295 font.setFamily(font_family);
296 } else if (font_family == guiApp->sansFontName()) {
297 font.setStyleHint(QFont::SansSerif);
298 font.setFamily(font_family);
299 } else if (font_family == guiApp->typewriterFontName()) {
300 font.setStyleHint(QFont::TypeWriter);
301 font.setFamily(font_family);
303 lyxerr << "FAILED to find the default font: '"
304 << foundry << "', '" << family << '\''<< endl;
308 QFontInfo info(font);
309 string default_font_name, dummyfoundry;
310 parseFontName(info.family(), default_font_name, dummyfoundry);
311 lyxerr << "Apparent font is " << default_font_name << endl;
313 for (int i = 0; i < cb->count(); ++i) {
314 lyxerr << "Looking at " << fromqstr(cb->itemText(i)) << endl;
315 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
316 default_font_name) == 0) {
317 cb->setCurrentIndex(i);
322 lyxerr << "FAILED to find the font: '"
323 << foundry << "', '" << family << '\'' <<endl;
327 /////////////////////////////////////////////////////////////////////
331 /////////////////////////////////////////////////////////////////////
333 PrefPlaintext::PrefPlaintext(QWidget * parent)
334 : PrefModule(qt_("Plain text"), 0, parent)
337 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
338 this, SIGNAL(changed()));
339 connect(plaintextRoffED, SIGNAL(textChanged(QString)),
340 this, SIGNAL(changed()));
344 void PrefPlaintext::apply(LyXRC & rc) const
346 rc.plaintext_linelen = plaintextLinelengthSB->value();
347 rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
351 void PrefPlaintext::update(LyXRC const & rc)
353 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
354 plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
358 /////////////////////////////////////////////////////////////////////
362 /////////////////////////////////////////////////////////////////////
364 PrefDate::PrefDate(QWidget * parent)
365 : PrefModule(qt_("Date format"), 0, parent)
368 connect(DateED, SIGNAL(textChanged(QString)),
369 this, SIGNAL(changed()));
373 void PrefDate::apply(LyXRC & rc) const
375 rc.date_insert_format = fromqstr(DateED->text());
379 void PrefDate::update(LyXRC const & rc)
381 DateED->setText(toqstr(rc.date_insert_format));
385 /////////////////////////////////////////////////////////////////////
389 /////////////////////////////////////////////////////////////////////
391 PrefInput::PrefInput(GuiPreferences * form, QWidget * parent)
392 : PrefModule(qt_("Keyboard/Mouse"), form, parent)
396 connect(keymapCB, SIGNAL(clicked()),
397 this, SIGNAL(changed()));
398 connect(firstKeymapED, SIGNAL(textChanged(QString)),
399 this, SIGNAL(changed()));
400 connect(secondKeymapED, SIGNAL(textChanged(QString)),
401 this, SIGNAL(changed()));
402 connect(inlineDelaySB, SIGNAL(valueChanged(double)),
403 this, SIGNAL(changed()));
404 connect(inlineMathCB, SIGNAL(clicked()),
405 this, SIGNAL(changed()));
406 connect(inlineTextCB, SIGNAL(clicked()),
407 this, SIGNAL(changed()));
408 connect(inlineDotsCB, SIGNAL(clicked()),
409 this, SIGNAL(changed()));
410 connect(popupDelaySB, SIGNAL(valueChanged(double)),
411 this, SIGNAL(changed()));
412 connect(popupMathCB, SIGNAL(clicked()),
413 this, SIGNAL(changed()));
414 connect(popupTextCB, SIGNAL(clicked()),
415 this, SIGNAL(changed()));
416 connect(popupAfterCompleteCB, SIGNAL(clicked()),
417 this, SIGNAL(changed()));
418 connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
419 this, SIGNAL(changed()));
423 void PrefInput::apply(LyXRC & rc) const
425 // FIXME: can derive CB from the two EDs
426 rc.use_kbmap = keymapCB->isChecked();
427 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
428 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
429 rc.completion_inline_delay = inlineDelaySB->value();
430 rc.completion_inline_math = inlineMathCB->isChecked();
431 rc.completion_inline_text = inlineTextCB->isChecked();
432 rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
433 rc.completion_popup_delay = popupDelaySB->value();
434 rc.completion_popup_math = popupMathCB->isChecked();
435 rc.completion_popup_text = popupTextCB->isChecked();
436 rc.completion_popup_after_complete
437 = popupAfterCompleteCB->isChecked();
438 rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
442 void PrefInput::update(LyXRC const & rc)
444 // FIXME: can derive CB from the two EDs
445 keymapCB->setChecked(rc.use_kbmap);
446 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
447 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
448 inlineDelaySB->setValue(rc.completion_inline_delay);
449 inlineMathCB->setChecked(rc.completion_inline_math);
450 inlineTextCB->setChecked(rc.completion_inline_text);
451 inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
452 popupDelaySB->setValue(rc.completion_popup_delay);
453 popupMathCB->setChecked(rc.completion_popup_math);
454 popupTextCB->setChecked(rc.completion_popup_text);
455 popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
456 mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
460 QString PrefInput::testKeymap(QString keymap)
462 return form_->browsekbmap(toqstr(internal_path(fromqstr(keymap))));
466 void PrefInput::on_firstKeymapPB_clicked(bool)
468 QString const file = testKeymap(firstKeymapED->text());
470 firstKeymapED->setText(file);
474 void PrefInput::on_secondKeymapPB_clicked(bool)
476 QString const file = testKeymap(secondKeymapED->text());
478 secondKeymapED->setText(file);
482 void PrefInput::on_keymapCB_toggled(bool keymap)
484 firstKeymapLA->setEnabled(keymap);
485 secondKeymapLA->setEnabled(keymap);
486 firstKeymapED->setEnabled(keymap);
487 secondKeymapED->setEnabled(keymap);
488 firstKeymapPB->setEnabled(keymap);
489 secondKeymapPB->setEnabled(keymap);
493 /////////////////////////////////////////////////////////////////////
497 /////////////////////////////////////////////////////////////////////
499 PrefLatex::PrefLatex(GuiPreferences * form, QWidget * parent)
500 : PrefModule(qt_("LaTeX"), form, parent)
503 connect(latexEncodingED, SIGNAL(textChanged(QString)),
504 this, SIGNAL(changed()));
505 connect(latexChecktexED, SIGNAL(textChanged(QString)),
506 this, SIGNAL(changed()));
507 connect(latexBibtexED, SIGNAL(textChanged(QString)),
508 this, SIGNAL(changed()));
509 connect(latexIndexED, SIGNAL(textChanged(QString)),
510 this, SIGNAL(changed()));
511 connect(latexAutoresetCB, SIGNAL(clicked()),
512 this, SIGNAL(changed()));
513 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
514 this, SIGNAL(changed()));
515 connect(latexPaperSizeCO, SIGNAL(activated(int)),
516 this, SIGNAL(changed()));
518 #if defined(__CYGWIN__) || defined(_WIN32)
519 pathCB->setVisible(true);
520 connect(pathCB, SIGNAL(clicked()),
521 this, SIGNAL(changed()));
523 pathCB->setVisible(false);
528 void PrefLatex::apply(LyXRC & rc) const
530 rc.fontenc = fromqstr(latexEncodingED->text());
531 rc.chktex_command = fromqstr(latexChecktexED->text());
532 rc.bibtex_command = fromqstr(latexBibtexED->text());
533 rc.index_command = fromqstr(latexIndexED->text());
534 rc.auto_reset_options = latexAutoresetCB->isChecked();
535 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
536 rc.default_papersize =
537 form_->toPaperSize(latexPaperSizeCO->currentIndex());
538 #if defined(__CYGWIN__) || defined(_WIN32)
539 rc.windows_style_tex_paths = pathCB->isChecked();
544 void PrefLatex::update(LyXRC const & rc)
546 latexEncodingED->setText(toqstr(rc.fontenc));
547 latexChecktexED->setText(toqstr(rc.chktex_command));
548 latexBibtexED->setText(toqstr(rc.bibtex_command));
549 latexIndexED->setText(toqstr(rc.index_command));
550 latexAutoresetCB->setChecked(rc.auto_reset_options);
551 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
552 latexPaperSizeCO->setCurrentIndex(
553 form_->fromPaperSize(rc.default_papersize));
554 #if defined(__CYGWIN__) || defined(_WIN32)
555 pathCB->setChecked(rc.windows_style_tex_paths);
560 /////////////////////////////////////////////////////////////////////
564 /////////////////////////////////////////////////////////////////////
566 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form, QWidget * parent)
567 : PrefModule(qt_("Screen fonts"), form, parent)
571 connect(screenRomanCO, SIGNAL(activated(QString)),
572 this, SLOT(select_roman(QString)));
573 connect(screenSansCO, SIGNAL(activated(QString)),
574 this, SLOT(select_sans(QString)));
575 connect(screenTypewriterCO, SIGNAL(activated(QString)),
576 this, SLOT(select_typewriter(QString)));
578 QFontDatabase fontdb;
579 QStringList families(fontdb.families());
580 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
581 screenRomanCO->addItem(*it);
582 screenSansCO->addItem(*it);
583 screenTypewriterCO->addItem(*it);
585 connect(screenRomanCO, SIGNAL(activated(QString)),
586 this, SIGNAL(changed()));
587 connect(screenSansCO, SIGNAL(activated(QString)),
588 this, SIGNAL(changed()));
589 connect(screenTypewriterCO, SIGNAL(activated(QString)),
590 this, SIGNAL(changed()));
591 connect(screenZoomSB, SIGNAL(valueChanged(int)),
592 this, SIGNAL(changed()));
593 connect(screenDpiSB, SIGNAL(valueChanged(int)),
594 this, SIGNAL(changed()));
595 connect(screenTinyED, SIGNAL(textChanged(QString)),
596 this, SIGNAL(changed()));
597 connect(screenSmallestED, SIGNAL(textChanged(QString)),
598 this, SIGNAL(changed()));
599 connect(screenSmallerED, SIGNAL(textChanged(QString)),
600 this, SIGNAL(changed()));
601 connect(screenSmallED, SIGNAL(textChanged(QString)),
602 this, SIGNAL(changed()));
603 connect(screenNormalED, SIGNAL(textChanged(QString)),
604 this, SIGNAL(changed()));
605 connect(screenLargeED, SIGNAL(textChanged(QString)),
606 this, SIGNAL(changed()));
607 connect(screenLargerED, SIGNAL(textChanged(QString)),
608 this, SIGNAL(changed()));
609 connect(screenLargestED, SIGNAL(textChanged(QString)),
610 this, SIGNAL(changed()));
611 connect(screenHugeED, SIGNAL(textChanged(QString)),
612 this, SIGNAL(changed()));
613 connect(screenHugerED, SIGNAL(textChanged(QString)),
614 this, SIGNAL(changed()));
615 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
616 this, SIGNAL(changed()));
618 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
619 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
620 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
621 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
622 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
623 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
624 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
625 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
626 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
627 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
631 void PrefScreenFonts::apply(LyXRC & rc) const
633 LyXRC const oldrc = rc;
635 parseFontName(screenRomanCO->currentText(),
636 rc.roman_font_name, rc.roman_font_foundry);
637 parseFontName(screenSansCO->currentText(),
638 rc.sans_font_name, rc.sans_font_foundry);
639 parseFontName(screenTypewriterCO->currentText(),
640 rc.typewriter_font_name, rc.typewriter_font_foundry);
642 rc.zoom = screenZoomSB->value();
643 rc.dpi = screenDpiSB->value();
644 rc.font_sizes[FONT_SIZE_TINY] = fromqstr(screenTinyED->text());
645 rc.font_sizes[FONT_SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
646 rc.font_sizes[FONT_SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
647 rc.font_sizes[FONT_SIZE_SMALL] = fromqstr(screenSmallED->text());
648 rc.font_sizes[FONT_SIZE_NORMAL] = fromqstr(screenNormalED->text());
649 rc.font_sizes[FONT_SIZE_LARGE] = fromqstr(screenLargeED->text());
650 rc.font_sizes[FONT_SIZE_LARGER] = fromqstr(screenLargerED->text());
651 rc.font_sizes[FONT_SIZE_LARGEST] = fromqstr(screenLargestED->text());
652 rc.font_sizes[FONT_SIZE_HUGE] = fromqstr(screenHugeED->text());
653 rc.font_sizes[FONT_SIZE_HUGER] = fromqstr(screenHugerED->text());
654 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
656 if (rc.font_sizes != oldrc.font_sizes
657 || rc.roman_font_name != oldrc.roman_font_name
658 || rc.sans_font_name != oldrc.sans_font_name
659 || rc.typewriter_font_name != oldrc.typewriter_font_name
660 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
661 // The global QPixmapCache is used in GuiPainter to cache text
662 // painting so we must reset it in case any of the above
663 // parameter is changed.
664 QPixmapCache::clear();
665 guiApp->fontLoader().update();
666 form_->updateScreenFonts();
671 void PrefScreenFonts::update(LyXRC const & rc)
673 setComboxFont(screenRomanCO, rc.roman_font_name,
674 rc.roman_font_foundry);
675 setComboxFont(screenSansCO, rc.sans_font_name,
676 rc.sans_font_foundry);
677 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
678 rc.typewriter_font_foundry);
680 select_roman(screenRomanCO->currentText());
681 select_sans(screenSansCO->currentText());
682 select_typewriter(screenTypewriterCO->currentText());
684 screenZoomSB->setValue(rc.zoom);
685 screenDpiSB->setValue(rc.dpi);
686 screenTinyED->setText(toqstr(rc.font_sizes[FONT_SIZE_TINY]));
687 screenSmallestED->setText(toqstr(rc.font_sizes[FONT_SIZE_SCRIPT]));
688 screenSmallerED->setText(toqstr(rc.font_sizes[FONT_SIZE_FOOTNOTE]));
689 screenSmallED->setText(toqstr(rc.font_sizes[FONT_SIZE_SMALL]));
690 screenNormalED->setText(toqstr(rc.font_sizes[FONT_SIZE_NORMAL]));
691 screenLargeED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGE]));
692 screenLargerED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGER]));
693 screenLargestED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGEST]));
694 screenHugeED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGE]));
695 screenHugerED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGER]));
697 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
698 #if defined(Q_WS_X11)
699 pixmapCacheCB->setEnabled(false);
705 void PrefScreenFonts::select_roman(const QString & name)
707 screenRomanFE->set(QFont(name), name);
711 void PrefScreenFonts::select_sans(const QString & name)
713 screenSansFE->set(QFont(name), name);
717 void PrefScreenFonts::select_typewriter(const QString & name)
719 screenTypewriterFE->set(QFont(name), name);
723 /////////////////////////////////////////////////////////////////////
727 /////////////////////////////////////////////////////////////////////
733 bool operator()(ColorCode lhs, ColorCode rhs) const {
734 return lcolor.getGUIName(lhs) < lcolor.getGUIName(rhs);
740 PrefColors::PrefColors(GuiPreferences * form, QWidget * parent)
741 : PrefModule(qt_("Colors"), form, parent)
745 // FIXME: all of this initialization should be put into the controller.
746 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
747 // for some discussion of why that is not trivial.
748 QPixmap icon(32, 32);
749 for (int i = 0; i < Color_ignore; ++i) {
750 ColorCode lc = static_cast<ColorCode>(i);
758 || lc == Color_magenta
759 || lc == Color_yellow
760 || lc == Color_inherit
761 || lc == Color_ignore) continue;
763 lcolors_.push_back(lc);
765 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
766 vector<ColorCode>::const_iterator cit = lcolors_.begin();
767 vector<ColorCode>::const_iterator const end = lcolors_.end();
768 for (; cit != end; ++cit) {
769 (void) new QListWidgetItem(QIcon(icon),
770 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
772 curcolors_.resize(lcolors_.size());
773 newcolors_.resize(lcolors_.size());
774 // End initialization
776 connect(colorChangePB, SIGNAL(clicked()),
777 this, SLOT(change_color()));
778 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
779 this, SLOT(change_lyxObjects_selection()));
780 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
781 this, SLOT(change_color()));
785 void PrefColors::apply(LyXRC & /*rc*/) const
787 for (unsigned int i = 0; i < lcolors_.size(); ++i)
788 if (curcolors_[i] != newcolors_[i])
789 form_->setColor(lcolors_[i], fromqstr(newcolors_[i]));
793 void PrefColors::update(LyXRC const & /*rc*/)
795 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
796 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
797 QPixmap coloritem(32, 32);
798 coloritem.fill(color);
799 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
800 newcolors_[i] = curcolors_[i] = color.name();
802 change_lyxObjects_selection();
805 void PrefColors::change_color()
807 int const row = lyxObjectsLW->currentRow();
813 QString const color = newcolors_[row];
814 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
816 if (c.isValid() && c.name() != color) {
817 newcolors_[row] = c.name();
818 QPixmap coloritem(32, 32);
820 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
826 void PrefColors::change_lyxObjects_selection()
828 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
832 /////////////////////////////////////////////////////////////////////
836 /////////////////////////////////////////////////////////////////////
838 PrefDisplay::PrefDisplay(QWidget * parent)
839 : PrefModule(qt_("Graphics"), 0, parent)
842 connect(instantPreviewCO, SIGNAL(activated(int)),
843 this, SIGNAL(changed()));
844 connect(displayGraphicsCO, SIGNAL(activated(int)),
845 this, SIGNAL(changed()));
849 void PrefDisplay::apply(LyXRC & rc) const
851 switch (instantPreviewCO->currentIndex()) {
852 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
853 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
854 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
857 graphics::DisplayType dtype;
858 switch (displayGraphicsCO->currentIndex()) {
859 case 3: dtype = graphics::NoDisplay; break;
860 case 2: dtype = graphics::ColorDisplay; break;
861 case 1: dtype = graphics::GrayscaleDisplay; break;
862 case 0: dtype = graphics::MonochromeDisplay; break;
863 default: dtype = graphics::GrayscaleDisplay;
865 rc.display_graphics = dtype;
867 // FIXME!! The graphics cache no longer has a changeDisplay method.
869 if (old_value != rc.display_graphics) {
870 graphics::GCache & gc = graphics::GCache::get();
877 void PrefDisplay::update(LyXRC const & rc)
879 switch (rc.preview) {
880 case LyXRC::PREVIEW_OFF:
881 instantPreviewCO->setCurrentIndex(0);
883 case LyXRC::PREVIEW_NO_MATH :
884 instantPreviewCO->setCurrentIndex(1);
886 case LyXRC::PREVIEW_ON :
887 instantPreviewCO->setCurrentIndex(2);
892 switch (rc.display_graphics) {
893 case graphics::NoDisplay: item = 3; break;
894 case graphics::ColorDisplay: item = 2; break;
895 case graphics::GrayscaleDisplay: item = 1; break;
896 case graphics::MonochromeDisplay: item = 0; break;
899 displayGraphicsCO->setCurrentIndex(item);
903 /////////////////////////////////////////////////////////////////////
907 /////////////////////////////////////////////////////////////////////
909 PrefPaths::PrefPaths(GuiPreferences * form, QWidget * parent)
910 : PrefModule(qt_("Paths"), form, parent)
913 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(select_exampledir()));
914 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
915 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
916 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
917 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
918 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
919 connect(workingDirED, SIGNAL(textChanged(QString)),
920 this, SIGNAL(changed()));
921 connect(exampleDirED, SIGNAL(textChanged(QString)),
922 this, SIGNAL(changed()));
923 connect(templateDirED, SIGNAL(textChanged(QString)),
924 this, SIGNAL(changed()));
925 connect(backupDirED, SIGNAL(textChanged(QString)),
926 this, SIGNAL(changed()));
927 connect(tempDirED, SIGNAL(textChanged(QString)),
928 this, SIGNAL(changed()));
929 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
930 this, SIGNAL(changed()));
931 connect(pathPrefixED, SIGNAL(textChanged(QString)),
932 this, SIGNAL(changed()));
936 void PrefPaths::apply(LyXRC & rc) const
938 rc.document_path = internal_path(fromqstr(workingDirED->text()));
939 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
940 rc.template_path = internal_path(fromqstr(templateDirED->text()));
941 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
942 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
943 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
944 // FIXME: should be a checkbox only
945 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
949 void PrefPaths::update(LyXRC const & rc)
951 workingDirED->setText(toqstr(external_path(rc.document_path)));
952 exampleDirED->setText(toqstr(external_path(rc.example_path)));
953 templateDirED->setText(toqstr(external_path(rc.template_path)));
954 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
955 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
956 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
957 // FIXME: should be a checkbox only
958 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
962 void PrefPaths::select_exampledir()
964 QString file = form_->browsedir(internalPath(exampleDirED->text()),
965 qt_("Select directory for example files"));
967 exampleDirED->setText(file);
971 void PrefPaths::select_templatedir()
973 QString file = form_->browsedir(internalPath(templateDirED->text()),
974 qt_("Select a document templates directory"));
976 templateDirED->setText(file);
980 void PrefPaths::select_tempdir()
982 QString file = form_->browsedir(internalPath(tempDirED->text()),
983 qt_("Select a temporary directory"));
985 tempDirED->setText(file);
989 void PrefPaths::select_backupdir()
991 QString file = form_->browsedir(internalPath(backupDirED->text()),
992 qt_("Select a backups directory"));
994 backupDirED->setText(file);
998 void PrefPaths::select_workingdir()
1000 QString file = form_->browsedir(internalPath(workingDirED->text()),
1001 qt_("Select a document directory"));
1002 if (!file.isEmpty())
1003 workingDirED->setText(file);
1007 void PrefPaths::select_lyxpipe()
1009 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1010 qt_("Give a filename for the LyX server pipe"));
1011 if (!file.isEmpty())
1012 lyxserverDirED->setText(file);
1016 /////////////////////////////////////////////////////////////////////
1020 /////////////////////////////////////////////////////////////////////
1022 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form, QWidget * parent)
1023 : PrefModule(qt_("Spellchecker"), form, parent)
1027 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
1028 #if defined (USE_ISPELL)
1029 connect(spellCommandCO, SIGNAL(activated(int)),
1030 this, SIGNAL(changed()));
1032 spellCommandCO->setEnabled(false);
1034 connect(altLanguageED, SIGNAL(textChanged(QString)),
1035 this, SIGNAL(changed()));
1036 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1037 this, SIGNAL(changed()));
1038 connect(persDictionaryED, SIGNAL(textChanged(QString)),
1039 this, SIGNAL(changed()));
1040 connect(compoundWordCB, SIGNAL(clicked()),
1041 this, SIGNAL(changed()));
1042 connect(inputEncodingCB, SIGNAL(clicked()),
1043 this, SIGNAL(changed()));
1045 spellCommandCO->addItem(qt_("ispell"));
1046 spellCommandCO->addItem(qt_("aspell"));
1047 spellCommandCO->addItem(qt_("hspell"));
1049 spellCommandCO->addItem(qt_("pspell (library)"));
1052 spellCommandCO->addItem(qt_("aspell (library)"));
1058 void PrefSpellchecker::apply(LyXRC & rc) const
1060 switch (spellCommandCO->currentIndex()) {
1064 rc.use_spell_lib = false;
1065 rc.isp_command = fromqstr(spellCommandCO->currentText());
1068 rc.use_spell_lib = true;
1072 // FIXME: remove isp_use_alt_lang
1073 rc.isp_alt_lang = fromqstr(altLanguageED->text());
1074 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
1075 // FIXME: remove isp_use_esc_chars
1076 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
1077 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
1078 // FIXME: remove isp_use_pers_dict
1079 rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
1080 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
1081 rc.isp_accept_compound = compoundWordCB->isChecked();
1082 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
1086 void PrefSpellchecker::update(LyXRC const & rc)
1088 spellCommandCO->setCurrentIndex(0);
1090 if (rc.isp_command == "ispell") {
1091 spellCommandCO->setCurrentIndex(0);
1092 } else if (rc.isp_command == "aspell") {
1093 spellCommandCO->setCurrentIndex(1);
1094 } else if (rc.isp_command == "hspell") {
1095 spellCommandCO->setCurrentIndex(2);
1098 if (rc.use_spell_lib) {
1099 #if defined(USE_ASPELL) || defined(USE_PSPELL)
1100 spellCommandCO->setCurrentIndex(3);
1104 // FIXME: remove isp_use_alt_lang
1105 altLanguageED->setText(toqstr(rc.isp_alt_lang));
1106 // FIXME: remove isp_use_esc_chars
1107 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
1108 // FIXME: remove isp_use_pers_dict
1109 persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
1110 compoundWordCB->setChecked(rc.isp_accept_compound);
1111 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
1115 void PrefSpellchecker::select_dict()
1117 QString file = form_->browsedict(internalPath(persDictionaryED->text()));
1118 if (!file.isEmpty())
1119 persDictionaryED->setText(file);
1124 /////////////////////////////////////////////////////////////////////
1128 /////////////////////////////////////////////////////////////////////
1131 PrefConverters::PrefConverters(GuiPreferences * form, QWidget * parent)
1132 : PrefModule(qt_("Converters"), form, parent)
1136 connect(converterNewPB, SIGNAL(clicked()),
1137 this, SLOT(update_converter()));
1138 connect(converterRemovePB, SIGNAL(clicked()),
1139 this, SLOT(remove_converter()));
1140 connect(converterModifyPB, SIGNAL(clicked()),
1141 this, SLOT(update_converter()));
1142 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1143 this, SLOT(switch_converter()));
1144 connect(converterFromCO, SIGNAL(activated(QString)),
1145 this, SLOT(converter_changed()));
1146 connect(converterToCO, SIGNAL(activated(QString)),
1147 this, SLOT(converter_changed()));
1148 connect(converterED, SIGNAL(textEdited(QString)),
1149 this, SLOT(converter_changed()));
1150 connect(converterFlagED, SIGNAL(textEdited(QString)),
1151 this, SLOT(converter_changed()));
1152 connect(converterNewPB, SIGNAL(clicked()),
1153 this, SIGNAL(changed()));
1154 connect(converterRemovePB, SIGNAL(clicked()),
1155 this, SIGNAL(changed()));
1156 connect(converterModifyPB, SIGNAL(clicked()),
1157 this, SIGNAL(changed()));
1158 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1159 this, SIGNAL(changed()));
1161 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1162 //converterDefGB->setFocusProxy(convertersLW);
1166 void PrefConverters::apply(LyXRC & rc) const
1168 rc.use_converter_cache = cacheCB->isChecked();
1169 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
1173 void PrefConverters::update(LyXRC const & rc)
1175 cacheCB->setChecked(rc.use_converter_cache);
1177 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
1178 maxAgeLE->setText(max_age);
1183 void PrefConverters::updateGui()
1185 form_->formats().sort();
1186 form_->converters().update(form_->formats());
1187 // save current selection
1188 QString current = converterFromCO->currentText()
1189 + " -> " + converterToCO->currentText();
1191 converterFromCO->clear();
1192 converterToCO->clear();
1194 Formats::const_iterator cit = form_->formats().begin();
1195 Formats::const_iterator end = form_->formats().end();
1196 for (; cit != end; ++cit) {
1197 converterFromCO->addItem(toqstr(cit->prettyname()));
1198 converterToCO->addItem(toqstr(cit->prettyname()));
1201 // currentRowChanged(int) is also triggered when updating the listwidget
1202 // block signals to avoid unnecessary calls to switch_converter()
1203 convertersLW->blockSignals(true);
1204 convertersLW->clear();
1206 Converters::const_iterator ccit = form_->converters().begin();
1207 Converters::const_iterator cend = form_->converters().end();
1208 for (; ccit != cend; ++ccit) {
1210 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
1211 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1212 new QListWidgetItem(toqstr(name), convertersLW, type);
1214 convertersLW->sortItems(Qt::AscendingOrder);
1215 convertersLW->blockSignals(false);
1217 // restore selection
1218 if (!current.isEmpty()) {
1219 QList<QListWidgetItem *> const item =
1220 convertersLW->findItems(current, Qt::MatchExactly);
1221 if (!item.isEmpty())
1222 convertersLW->setCurrentItem(item.at(0));
1225 // select first element if restoring failed
1226 if (convertersLW->currentRow() == -1)
1227 convertersLW->setCurrentRow(0);
1233 void PrefConverters::switch_converter()
1235 int const cnr = convertersLW->currentItem()->type();
1236 Converter const & c(form_->converters().get(cnr));
1237 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1238 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1239 converterED->setText(toqstr(c.command));
1240 converterFlagED->setText(toqstr(c.flags));
1246 void PrefConverters::converter_changed()
1252 void PrefConverters::updateButtons()
1254 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1255 Format const & to = form_->formats().get(converterToCO->currentIndex());
1256 int const sel = form_->converters().getNumber(from.name(), to.name());
1257 bool const known = sel >= 0;
1258 bool const valid = !(converterED->text().isEmpty()
1259 || from.name() == to.name());
1261 int const cnr = convertersLW->currentItem()->type();
1262 Converter const & c(form_->converters().get(cnr));
1263 string const old_command = c.command;
1264 string const old_flag = c.flags;
1265 string const new_command(fromqstr(converterED->text()));
1266 string const new_flag(fromqstr(converterFlagED->text()));
1268 bool modified = (old_command != new_command) || (old_flag != new_flag);
1270 converterModifyPB->setEnabled(valid && known && modified);
1271 converterNewPB->setEnabled(valid && !known);
1272 converterRemovePB->setEnabled(known);
1274 maxAgeLE->setEnabled(cacheCB->isChecked());
1275 maxAgeLA->setEnabled(cacheCB->isChecked());
1280 // specify unique from/to or it doesn't appear. This is really bad UI
1281 // this is why we can use the same function for both new and modify
1282 void PrefConverters::update_converter()
1284 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1285 Format const & to = form_->formats().get(converterToCO->currentIndex());
1286 string const flags = fromqstr(converterFlagED->text());
1287 string const command = fromqstr(converterED->text());
1289 Converter const * old =
1290 form_->converters().getConverter(from.name(), to.name());
1291 form_->converters().add(from.name(), to.name(), command, flags);
1294 form_->converters().updateLast(form_->formats());
1298 // Remove all files created by this converter from the cache, since
1299 // the modified converter might create different files.
1300 ConverterCache::get().remove_all(from.name(), to.name());
1304 void PrefConverters::remove_converter()
1306 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1307 Format const & to = form_->formats().get(converterToCO->currentIndex());
1308 form_->converters().erase(from.name(), to.name());
1312 // Remove all files created by this converter from the cache, since
1313 // a possible new converter might create different files.
1314 ConverterCache::get().remove_all(from.name(), to.name());
1318 void PrefConverters::on_cacheCB_stateChanged(int state)
1320 maxAgeLE->setEnabled(state == Qt::Checked);
1321 maxAgeLA->setEnabled(state == Qt::Checked);
1326 /////////////////////////////////////////////////////////////////////
1330 /////////////////////////////////////////////////////////////////////
1332 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1333 : QValidator(parent), formats_(f)
1338 void FormatValidator::fixup(QString & input) const
1340 Formats::const_iterator cit = formats_.begin();
1341 Formats::const_iterator end = formats_.end();
1342 for (; cit != end; ++cit) {
1343 string const name = str(cit);
1344 if (distance(formats_.begin(), cit) == nr()) {
1345 input = toqstr(name);
1353 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1355 Formats::const_iterator cit = formats_.begin();
1356 Formats::const_iterator end = formats_.end();
1357 bool unknown = true;
1358 for (; unknown && cit != end; ++cit) {
1359 string const name = str(cit);
1360 if (distance(formats_.begin(), cit) != nr())
1361 unknown = toqstr(name) != input;
1364 if (unknown && !input.isEmpty())
1365 return QValidator::Acceptable;
1367 return QValidator::Intermediate;
1371 int FormatValidator::nr() const
1373 QComboBox * p = qobject_cast<QComboBox *>(parent());
1374 return p->itemData(p->currentIndex()).toInt();
1378 FormatNameValidator::FormatNameValidator(QWidget * parent, Formats const & f)
1379 : FormatValidator(parent, f)
1383 string FormatNameValidator::str(Formats::const_iterator it) const
1389 FormatPrettynameValidator::FormatPrettynameValidator(QWidget * parent, Formats const & f)
1390 : FormatValidator(parent, f)
1395 string FormatPrettynameValidator::str(Formats::const_iterator it) const
1397 return it->prettyname();
1401 PrefFileformats::PrefFileformats(GuiPreferences * form, QWidget * parent)
1402 : PrefModule(qt_("File formats"), form, parent)
1405 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1406 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1408 connect(documentCB, SIGNAL(clicked()),
1409 this, SLOT(setFlags()));
1410 connect(vectorCB, SIGNAL(clicked()),
1411 this, SLOT(setFlags()));
1412 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1413 this, SLOT(updatePrettyname()));
1414 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1415 this, SIGNAL(changed()));
1419 void PrefFileformats::apply(LyXRC & /*rc*/) const
1424 void PrefFileformats::update(LyXRC const & /*rc*/)
1430 void PrefFileformats::updateView()
1432 QString const current = formatsCB->currentText();
1434 // update combobox with formats
1435 formatsCB->blockSignals(true);
1437 form_->formats().sort();
1438 Formats::const_iterator cit = form_->formats().begin();
1439 Formats::const_iterator end = form_->formats().end();
1440 for (; cit != end; ++cit)
1441 formatsCB->addItem(toqstr(cit->prettyname()),
1442 QVariant(form_->formats().getNumber(cit->name())) );
1444 // restore selection
1445 int const item = formatsCB->findText(current, Qt::MatchExactly);
1446 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1447 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1448 formatsCB->blockSignals(false);
1452 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1454 int const nr = formatsCB->itemData(i).toInt();
1455 Format const f = form_->formats().get(nr);
1457 formatED->setText(toqstr(f.name()));
1458 copierED->setText(toqstr(form_->movers().command(f.name())));
1459 extensionED->setText(toqstr(f.extension()));
1460 shortcutED->setText(toqstr(f.shortcut()));
1461 viewerED->setText(toqstr(f.viewer()));
1462 editorED->setText(toqstr(f.editor()));
1463 documentCB->setChecked((f.documentFormat()));
1464 vectorCB->setChecked((f.vectorFormat()));
1468 void PrefFileformats::setFlags()
1470 int flags = Format::none;
1471 if (documentCB->isChecked())
1472 flags |= Format::document;
1473 if (vectorCB->isChecked())
1474 flags |= Format::vector;
1475 currentFormat().setFlags(flags);
1480 void PrefFileformats::on_copierED_textEdited(const QString & s)
1482 string const fmt = fromqstr(formatED->text());
1483 form_->movers().set(fmt, fromqstr(s));
1488 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1490 currentFormat().setExtension(fromqstr(s));
1494 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1496 currentFormat().setViewer(fromqstr(s));
1501 void PrefFileformats::on_editorED_textEdited(const QString & s)
1503 currentFormat().setEditor(fromqstr(s));
1508 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1510 currentFormat().setShortcut(fromqstr(s));
1515 void PrefFileformats::on_formatED_editingFinished()
1517 string const newname = fromqstr(formatED->displayText());
1518 if (newname == currentFormat().name())
1521 currentFormat().setName(newname);
1526 void PrefFileformats::on_formatED_textChanged(const QString &)
1528 QString t = formatED->text();
1530 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1531 setValid(formatLA, valid);
1535 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1537 QString t = formatsCB->currentText();
1539 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1540 setValid(formatsLA, valid);
1544 void PrefFileformats::updatePrettyname()
1546 string const newname = fromqstr(formatsCB->currentText());
1547 if (newname == currentFormat().prettyname())
1550 currentFormat().setPrettyname(newname);
1557 Format & PrefFileformats::currentFormat()
1559 int const i = formatsCB->currentIndex();
1560 int const nr = formatsCB->itemData(i).toInt();
1561 return form_->formats().get(nr);
1565 void PrefFileformats::on_formatNewPB_clicked()
1567 form_->formats().add("", "", "", "", "", "", Format::none);
1569 formatsCB->setCurrentIndex(0);
1570 formatsCB->setFocus(Qt::OtherFocusReason);
1574 void PrefFileformats::on_formatRemovePB_clicked()
1576 int const i = formatsCB->currentIndex();
1577 int const nr = formatsCB->itemData(i).toInt();
1578 string const current_text = form_->formats().get(nr).name();
1579 if (form_->converters().formatIsUsed(current_text)) {
1580 Alert::error(_("Format in use"),
1581 _("Cannot remove a Format used by a Converter. "
1582 "Remove the converter first."));
1586 form_->formats().erase(current_text);
1589 on_formatsCB_editTextChanged(formatsCB->currentText());
1594 /////////////////////////////////////////////////////////////////////
1598 /////////////////////////////////////////////////////////////////////
1600 PrefLanguage::PrefLanguage(QWidget * parent)
1601 : PrefModule(qt_("Language"), 0, parent)
1605 connect(rtlGB, SIGNAL(clicked()),
1606 this, SIGNAL(changed()));
1607 connect(visualCursorRB, SIGNAL(clicked()),
1608 this, SIGNAL(changed()));
1609 connect(logicalCursorRB, SIGNAL(clicked()),
1610 this, SIGNAL(changed()));
1611 connect(markForeignCB, SIGNAL(clicked()),
1612 this, SIGNAL(changed()));
1613 connect(autoBeginCB, SIGNAL(clicked()),
1614 this, SIGNAL(changed()));
1615 connect(autoEndCB, SIGNAL(clicked()),
1616 this, SIGNAL(changed()));
1617 connect(useBabelCB, SIGNAL(clicked()),
1618 this, SIGNAL(changed()));
1619 connect(globalCB, SIGNAL(clicked()),
1620 this, SIGNAL(changed()));
1621 connect(languagePackageED, SIGNAL(textChanged(QString)),
1622 this, SIGNAL(changed()));
1623 connect(startCommandED, SIGNAL(textChanged(QString)),
1624 this, SIGNAL(changed()));
1625 connect(endCommandED, SIGNAL(textChanged(QString)),
1626 this, SIGNAL(changed()));
1627 connect(defaultLanguageCO, SIGNAL(activated(int)),
1628 this, SIGNAL(changed()));
1630 defaultLanguageCO->clear();
1632 // store the lang identifiers for later
1633 vector<LanguagePair> const langs = getLanguageData(false);
1634 vector<LanguagePair>::const_iterator lit = langs.begin();
1635 vector<LanguagePair>::const_iterator lend = langs.end();
1637 for (; lit != lend; ++lit) {
1638 defaultLanguageCO->addItem(toqstr(lit->first));
1639 lang_.push_back(lit->second);
1644 void PrefLanguage::apply(LyXRC & rc) const
1646 // FIXME: remove rtl_support bool
1647 rc.rtl_support = rtlGB->isChecked();
1648 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
1649 rc.mark_foreign_language = markForeignCB->isChecked();
1650 rc.language_auto_begin = autoBeginCB->isChecked();
1651 rc.language_auto_end = autoEndCB->isChecked();
1652 rc.language_use_babel = useBabelCB->isChecked();
1653 rc.language_global_options = globalCB->isChecked();
1654 rc.language_package = fromqstr(languagePackageED->text());
1655 rc.language_command_begin = fromqstr(startCommandED->text());
1656 rc.language_command_end = fromqstr(endCommandED->text());
1657 rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1661 void PrefLanguage::update(LyXRC const & rc)
1663 // FIXME: remove rtl_support bool
1664 rtlGB->setChecked(rc.rtl_support);
1665 if (rc.visual_cursor)
1666 visualCursorRB->setChecked(true);
1668 logicalCursorRB->setChecked(true);
1669 markForeignCB->setChecked(rc.mark_foreign_language);
1670 autoBeginCB->setChecked(rc.language_auto_begin);
1671 autoEndCB->setChecked(rc.language_auto_end);
1672 useBabelCB->setChecked(rc.language_use_babel);
1673 globalCB->setChecked(rc.language_global_options);
1674 languagePackageED->setText(toqstr(rc.language_package));
1675 startCommandED->setText(toqstr(rc.language_command_begin));
1676 endCommandED->setText(toqstr(rc.language_command_end));
1678 int const pos = int(findPos_helper(lang_, rc.default_language));
1679 defaultLanguageCO->setCurrentIndex(pos);
1683 /////////////////////////////////////////////////////////////////////
1687 /////////////////////////////////////////////////////////////////////
1689 PrefPrinter::PrefPrinter(QWidget * parent)
1690 : PrefModule(qt_("Printer"), 0, parent)
1694 connect(printerAdaptCB, SIGNAL(clicked()),
1695 this, SIGNAL(changed()));
1696 connect(printerCommandED, SIGNAL(textChanged(QString)),
1697 this, SIGNAL(changed()));
1698 connect(printerNameED, SIGNAL(textChanged(QString)),
1699 this, SIGNAL(changed()));
1700 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
1701 this, SIGNAL(changed()));
1702 connect(printerCopiesED, SIGNAL(textChanged(QString)),
1703 this, SIGNAL(changed()));
1704 connect(printerReverseED, SIGNAL(textChanged(QString)),
1705 this, SIGNAL(changed()));
1706 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
1707 this, SIGNAL(changed()));
1708 connect(printerExtensionED, SIGNAL(textChanged(QString)),
1709 this, SIGNAL(changed()));
1710 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
1711 this, SIGNAL(changed()));
1712 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
1713 this, SIGNAL(changed()));
1714 connect(printerEvenED, SIGNAL(textChanged(QString)),
1715 this, SIGNAL(changed()));
1716 connect(printerOddED, SIGNAL(textChanged(QString)),
1717 this, SIGNAL(changed()));
1718 connect(printerCollatedED, SIGNAL(textChanged(QString)),
1719 this, SIGNAL(changed()));
1720 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
1721 this, SIGNAL(changed()));
1722 connect(printerToFileED, SIGNAL(textChanged(QString)),
1723 this, SIGNAL(changed()));
1724 connect(printerExtraED, SIGNAL(textChanged(QString)),
1725 this, SIGNAL(changed()));
1726 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
1727 this, SIGNAL(changed()));
1728 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
1729 this, SIGNAL(changed()));
1733 void PrefPrinter::apply(LyXRC & rc) const
1735 rc.print_adapt_output = printerAdaptCB->isChecked();
1736 rc.print_command = fromqstr(printerCommandED->text());
1737 rc.printer = fromqstr(printerNameED->text());
1739 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1740 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1741 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1742 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1743 rc.print_file_extension = fromqstr(printerExtensionED->text());
1744 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1745 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1746 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1747 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1748 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1749 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1750 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1751 rc.print_extra_options = fromqstr(printerExtraED->text());
1752 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1753 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1757 void PrefPrinter::update(LyXRC const & rc)
1759 printerAdaptCB->setChecked(rc.print_adapt_output);
1760 printerCommandED->setText(toqstr(rc.print_command));
1761 printerNameED->setText(toqstr(rc.printer));
1763 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1764 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1765 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1766 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1767 printerExtensionED->setText(toqstr(rc.print_file_extension));
1768 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1769 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1770 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1771 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1772 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1773 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1774 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1775 printerExtraED->setText(toqstr(rc.print_extra_options));
1776 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1777 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1781 /////////////////////////////////////////////////////////////////////
1783 // PrefUserInterface
1785 /////////////////////////////////////////////////////////////////////
1787 PrefUserInterface::PrefUserInterface(GuiPreferences * form, QWidget * parent)
1788 : PrefModule(qt_("User interface"), form, parent)
1792 connect(autoSaveCB, SIGNAL(toggled(bool)),
1793 autoSaveSB, SLOT(setEnabled(bool)));
1794 connect(autoSaveCB, SIGNAL(toggled(bool)),
1795 TextLabel1, SLOT(setEnabled(bool)));
1796 connect(uiFilePB, SIGNAL(clicked()),
1797 this, SLOT(select_ui()));
1798 connect(uiFileED, SIGNAL(textChanged(QString)),
1799 this, SIGNAL(changed()));
1800 connect(restoreCursorCB, SIGNAL(clicked()),
1801 this, SIGNAL(changed()));
1802 connect(loadSessionCB, SIGNAL(clicked()),
1803 this, SIGNAL(changed()));
1804 connect(allowGeometrySessionCB, SIGNAL(clicked()),
1805 this, SIGNAL(changed()));
1806 connect(cursorFollowsCB, SIGNAL(clicked()),
1807 this, SIGNAL(changed()));
1808 connect(sortEnvironmentsCB, SIGNAL(clicked()),
1809 this, SIGNAL(changed()));
1810 connect(macroEditStyleCO, SIGNAL(activated(int)),
1811 this, SIGNAL(changed()));
1812 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1813 this, SIGNAL(changed()));
1814 connect(autoSaveCB, SIGNAL(clicked()),
1815 this, SIGNAL(changed()));
1816 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1817 this, SIGNAL(changed()));
1818 connect(tooltipCB, SIGNAL(toggled(bool)),
1819 this, SIGNAL(changed()));
1820 connect(fullscreenLimitGB, SIGNAL(clicked()),
1821 this, SIGNAL(changed()));
1822 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
1823 this, SIGNAL(changed()));
1824 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
1825 this, SIGNAL(changed()));
1826 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
1827 this, SIGNAL(changed()));
1828 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
1829 this, SIGNAL(changed()));
1830 lastfilesSB->setMaximum(maxlastfiles);
1834 void PrefUserInterface::apply(LyXRC & rc) const
1836 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1837 rc.use_lastfilepos = restoreCursorCB->isChecked();
1838 rc.load_session = loadSessionCB->isChecked();
1839 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
1840 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1841 rc.sort_layouts = sortEnvironmentsCB->isChecked();
1842 switch (macroEditStyleCO->currentIndex()) {
1843 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
1844 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
1845 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
1847 rc.autosave = autoSaveSB->value() * 60;
1848 rc.make_backup = autoSaveCB->isChecked();
1849 rc.num_lastfiles = lastfilesSB->value();
1850 rc.use_tooltip = tooltipCB->isChecked();
1851 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
1852 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
1853 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
1854 rc.full_screen_width = fullscreenWidthSB->value();
1855 rc.full_screen_limit = fullscreenLimitGB->isChecked();
1859 void PrefUserInterface::update(LyXRC const & rc)
1861 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1862 restoreCursorCB->setChecked(rc.use_lastfilepos);
1863 loadSessionCB->setChecked(rc.load_session);
1864 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
1865 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1866 sortEnvironmentsCB->setChecked(rc.sort_layouts);
1867 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
1868 // convert to minutes
1869 int mins(rc.autosave / 60);
1870 if (rc.autosave && !mins)
1872 autoSaveSB->setValue(mins);
1873 autoSaveCB->setChecked(rc.make_backup);
1874 lastfilesSB->setValue(rc.num_lastfiles);
1875 tooltipCB->setChecked(rc.use_tooltip);
1876 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
1877 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
1878 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
1879 fullscreenWidthSB->setValue(rc.full_screen_width);
1880 fullscreenLimitGB->setChecked(rc.full_screen_limit);
1885 void PrefUserInterface::select_ui()
1887 QString file = form_->browseUI(internalPath(uiFileED->text()));
1888 if (!file.isEmpty())
1889 uiFileED->setText(file);
1893 /////////////////////////////////////////////////////////////////////
1897 /////////////////////////////////////////////////////////////////////
1900 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
1902 Ui::shortcutUi::setupUi(this);
1903 QDialog::setModal(true);
1907 PrefShortcuts::PrefShortcuts(GuiPreferences * form, QWidget * parent)
1908 : PrefModule(qt_("Shortcuts"), form, parent)
1912 shortcutsTW->setColumnCount(2);
1913 shortcutsTW->headerItem()->setText(0, qt_("Function"));
1914 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
1915 shortcutsTW->setSortingEnabled(true);
1916 // Multi-selection can be annoying.
1917 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
1918 shortcutsTW->header()->resizeSection(0, 200);
1920 connect(bindFilePB, SIGNAL(clicked()),
1921 this, SLOT(select_bind()));
1922 connect(bindFileED, SIGNAL(textChanged(QString)),
1923 this, SIGNAL(changed()));
1924 connect(removePB, SIGNAL(clicked()),
1925 this, SIGNAL(changed()));
1927 shortcut_ = new GuiShortcutDialog(this);
1928 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
1929 shortcut_bc_.setOK(shortcut_->okPB);
1930 shortcut_bc_.setCancel(shortcut_->cancelPB);
1932 connect(shortcut_->okPB, SIGNAL(clicked()),
1933 shortcut_, SLOT(accept()));
1934 connect(shortcut_->okPB, SIGNAL(clicked()),
1935 this, SIGNAL(changed()));
1936 connect(shortcut_->cancelPB, SIGNAL(clicked()),
1937 shortcut_, SLOT(reject()));
1938 connect(shortcut_->clearPB, SIGNAL(clicked()),
1939 this, SLOT(shortcut_clearPB_pressed()));
1940 connect(shortcut_->okPB, SIGNAL(clicked()),
1941 this, SLOT(shortcut_okPB_pressed()));
1945 void PrefShortcuts::apply(LyXRC & rc) const
1947 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1948 // write user_bind and user_unbind to .lyx/bind/user.bind
1949 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
1950 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
1951 lyxerr << "LyX could not create the user bind directory '"
1952 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
1955 if (!bind_dir.isDirWritable()) {
1956 lyxerr << "LyX could not write to the user bind directory '"
1957 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
1960 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
1961 user_bind_.write(user_bind_file.toFilesystemEncoding(), false, false);
1962 user_unbind_.write(user_bind_file.toFilesystemEncoding(), true, true);
1963 // immediately apply the keybindings. Why this is not done before?
1964 // The good thing is that the menus are updated automatically.
1965 theTopLevelKeymap().clear();
1966 theTopLevelKeymap().read("site");
1967 theTopLevelKeymap().read(rc.bind_file);
1968 theTopLevelKeymap().read("user");
1972 void PrefShortcuts::update(LyXRC const & rc)
1974 bindFileED->setText(toqstr(external_path(rc.bind_file)));
1976 system_bind_.clear();
1978 user_unbind_.clear();
1979 system_bind_.read(rc.bind_file);
1980 // \unbind in user.bind is added to user_unbind_
1981 user_bind_.read("user", &user_unbind_);
1982 updateShortcutsTW();
1986 void PrefShortcuts::updateShortcutsTW()
1988 shortcutsTW->clear();
1990 editItem_ = new QTreeWidgetItem(shortcutsTW);
1991 editItem_->setText(0, toqstr("Cursor, Mouse and Editing functions"));
1992 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
1994 mathItem_ = new QTreeWidgetItem(shortcutsTW);
1995 mathItem_->setText(0, toqstr("Mathematical Symbols"));
1996 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
1998 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
1999 bufferItem_->setText(0, toqstr("Buffer and Window"));
2000 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2002 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2003 layoutItem_->setText(0, toqstr("Font, Layouts and Textclasses"));
2004 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2006 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2007 systemItem_->setText(0, toqstr("System and Miscellaneous"));
2008 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2010 // listBindings(unbound=true) lists all bound and unbound lfuns
2011 // Items in this list is tagged by its source.
2012 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2013 static_cast<int>(System));
2014 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2015 static_cast<int>(UserBind));
2016 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2017 static_cast<int>(UserUnbind));
2018 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2019 user_bindinglist.end());
2020 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2021 user_unbindinglist.end());
2023 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2024 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2025 for (; it != it_end; ++it)
2026 insertShortcutItem(it->request, it->sequence, item_type(it->tag));
2028 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2029 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2030 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2034 void PrefShortcuts::setItemType(QTreeWidgetItem * item, item_type tag)
2036 item->setData(0, Qt::UserRole, QVariant(tag));
2046 font.setStrikeOut(true);
2048 // this item is not displayed now.
2049 case UserExtraUnbind:
2050 font.setStrikeOut(true);
2054 item->setFont(1, font);
2058 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2059 KeySequence const & seq, item_type tag)
2061 kb_action action = lfun.action;
2062 string const action_name = lyxaction.getActionName(action);
2063 QString const lfun_name = toqstr(from_utf8(action_name)
2064 + " " + lfun.argument());
2065 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2066 item_type item_tag = tag;
2068 QTreeWidgetItem * newItem = NULL;
2069 // for unbind items, try to find an existing item in the system bind list
2070 if (tag == UserUnbind) {
2071 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2072 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2073 for (int i = 0; i < items.size(); ++i) {
2074 if (items[i]->text(1) == shortcut)
2078 // if not found, this unbind item is UserExtraUnbind
2079 // Such an item is not displayed to avoid confusion (what is
2080 // unmatched removed?).
2082 item_tag = UserExtraUnbind;
2087 switch(lyxaction.getActionType(action)) {
2088 case LyXAction::Hidden:
2090 case LyXAction::Edit:
2091 newItem = new QTreeWidgetItem(editItem_);
2093 case LyXAction::Math:
2094 newItem = new QTreeWidgetItem(mathItem_);
2096 case LyXAction::Buffer:
2097 newItem = new QTreeWidgetItem(bufferItem_);
2099 case LyXAction::Layout:
2100 newItem = new QTreeWidgetItem(layoutItem_);
2102 case LyXAction::System:
2103 newItem = new QTreeWidgetItem(systemItem_);
2106 // this should not happen
2107 newItem = new QTreeWidgetItem(shortcutsTW);
2111 newItem->setText(0, lfun_name);
2112 newItem->setText(1, shortcut);
2113 // record BindFile representation to recover KeySequence when needed.
2114 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2115 setItemType(newItem, item_tag);
2120 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2122 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2123 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2124 if (items.isEmpty())
2127 item_type tag = static_cast<item_type>(items[0]->data(0, Qt::UserRole).toInt());
2128 if (tag == UserUnbind)
2129 removePB->setText(toqstr("Restore"));
2131 removePB->setText(toqstr("Remove"));
2135 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2137 QTreeWidgetItem * item = shortcutsTW->currentItem();
2138 if (item->flags() & Qt::ItemIsSelectable) {
2139 shortcut_->lfunLE->setText(item->text(0));
2140 // clear the shortcut because I assume that a user will enter
2142 shortcut_->shortcutLE->reset();
2143 shortcut_->shortcutLE->setFocus();
2149 void PrefShortcuts::select_bind()
2151 QString file = form_->browsebind(internalPath(bindFileED->text()));
2152 if (!file.isEmpty()) {
2153 bindFileED->setText(file);
2154 system_bind_ = KeyMap();
2155 system_bind_.read(fromqstr(file));
2156 updateShortcutsTW();
2161 void PrefShortcuts::on_newPB_pressed()
2163 shortcut_->lfunLE->clear();
2164 shortcut_->shortcutLE->reset();
2169 void PrefShortcuts::on_removePB_pressed()
2171 // it seems that only one item can be selected, but I am
2172 // removing all selected items anyway.
2173 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2174 for (int i = 0; i < items.size(); ++i) {
2175 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2176 string lfun = fromqstr(items[i]->text(0));
2177 FuncRequest func = lyxaction.lookupFunc(lfun);
2178 item_type tag = static_cast<item_type>(items[i]->data(0, Qt::UserRole).toInt());
2182 // for system bind, we do not touch the item
2183 // but add an user unbind item
2184 user_unbind_.bind(shortcut, func);
2185 setItemType(items[i], UserUnbind);
2186 removePB->setText(toqstr("Restore"));
2190 // for user_bind, we remove this bind
2191 QTreeWidgetItem * parent = items[i]->parent();
2192 int itemIdx = parent->indexOfChild(items[i]);
2193 parent->takeChild(itemIdx);
2195 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2197 shortcutsTW->scrollToItem(parent);
2198 user_bind_.unbind(shortcut, func);
2202 // for user_unbind, we remove the unbind, and the item
2203 // become System again.
2204 user_unbind_.unbind(shortcut, func);
2205 setItemType(items[i], System);
2206 removePB->setText(toqstr("Remove"));
2209 case UserExtraUnbind: {
2210 // for user unbind that is not in system bind file,
2211 // remove this unbind file
2212 QTreeWidgetItem * parent = items[i]->parent();
2213 parent->takeChild(parent->indexOfChild(items[i]));
2214 user_unbind_.unbind(shortcut, func);
2221 void PrefShortcuts::on_searchLE_textEdited()
2223 if (searchLE->text().isEmpty()) {
2224 // show all hidden items
2225 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2227 shortcutsTW->setItemHidden(*it++, false);
2230 // search both columns
2231 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2232 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2233 matched += shortcutsTW->findItems(searchLE->text(),
2234 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2236 // hide everyone (to avoid searching in matched QList repeatedly
2237 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2239 shortcutsTW->setItemHidden(*it++, true);
2240 // show matched items
2241 for (int i = 0; i < matched.size(); ++i) {
2242 shortcutsTW->setItemHidden(matched[i], false);
2243 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2248 void PrefShortcuts::shortcut_okPB_pressed()
2250 string lfun = fromqstr(shortcut_->lfunLE->text());
2251 FuncRequest func = lyxaction.lookupFunc(lfun);
2253 if (func.action == LFUN_UNKNOWN_ACTION) {
2254 Alert::error(_("Failed to create shortcut"),
2255 _("Unknown or invalid LyX function"));
2259 KeySequence k = shortcut_->shortcutLE->getKeySequence();
2260 if (k.length() == 0) {
2261 Alert::error(_("Failed to create shortcut"),
2262 _("Invalid or empty key sequence"));
2266 // if both lfun and shortcut is valid
2267 if (user_bind_.hasBinding(k, func) || system_bind_.hasBinding(k, func)) {
2268 Alert::error(_("Failed to create shortcut"),
2269 _("Shortcut is already defined"));
2273 QTreeWidgetItem * item = insertShortcutItem(func, k, UserBind);
2275 user_bind_.bind(&k, func);
2276 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2277 shortcutsTW->setItemExpanded(item->parent(), true);
2278 shortcutsTW->scrollToItem(item);
2280 Alert::error(_("Failed to create shortcut"),
2281 _("Can not insert shortcut to the list"));
2287 void PrefShortcuts::shortcut_clearPB_pressed()
2289 shortcut_->shortcutLE->reset();
2290 shortcut_->shortcutLE->setFocus();
2294 /////////////////////////////////////////////////////////////////////
2298 /////////////////////////////////////////////////////////////////////
2300 PrefIdentity::PrefIdentity(QWidget * parent)
2301 : PrefModule(qt_("Identity"), 0, parent)
2305 connect(nameED, SIGNAL(textChanged(QString)),
2306 this, SIGNAL(changed()));
2307 connect(emailED, SIGNAL(textChanged(QString)),
2308 this, SIGNAL(changed()));
2312 void PrefIdentity::apply(LyXRC & rc) const
2314 rc.user_name = fromqstr(nameED->text());
2315 rc.user_email = fromqstr(emailED->text());
2319 void PrefIdentity::update(LyXRC const & rc)
2321 nameED->setText(toqstr(rc.user_name));
2322 emailED->setText(toqstr(rc.user_email));
2327 /////////////////////////////////////////////////////////////////////
2331 /////////////////////////////////////////////////////////////////////
2333 GuiPreferences::GuiPreferences(GuiView & lv)
2334 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2338 QDialog::setModal(false);
2340 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2341 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2342 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2343 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2345 add(new PrefUserInterface(this));
2346 add(new PrefShortcuts(this));
2347 add(new PrefScreenFonts(this));
2348 add(new PrefColors(this));
2349 add(new PrefDisplay);
2350 add(new PrefInput(this));
2352 add(new PrefPaths(this));
2354 add(new PrefIdentity);
2356 add(new PrefLanguage);
2357 add(new PrefSpellchecker(this));
2359 add(new PrefPrinter);
2361 add(new PrefPlaintext);
2362 add(new PrefLatex(this));
2364 PrefConverters * converters = new PrefConverters(this);
2365 PrefFileformats * formats = new PrefFileformats(this);
2366 connect(formats, SIGNAL(formatsChanged()),
2367 converters, SLOT(updateGui()));
2371 prefsPS->setCurrentPanel(qt_("User interface"));
2372 // FIXME: hack to work around resizing bug in Qt >= 4.2
2373 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2374 #if QT_VERSION >= 0x040200
2375 prefsPS->updateGeometry();
2378 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2380 bc().setApply(applyPB);
2381 bc().setCancel(closePB);
2382 bc().setRestore(restorePB);
2386 void GuiPreferences::add(PrefModule * module)
2388 BOOST_ASSERT(module);
2389 prefsPS->addPanel(module, module->title());
2390 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2391 modules_.push_back(module);
2395 void GuiPreferences::change_adaptor()
2401 void GuiPreferences::apply(LyXRC & rc) const
2403 size_t end = modules_.size();
2404 for (size_t i = 0; i != end; ++i)
2405 modules_[i]->apply(rc);
2409 void GuiPreferences::updateRc(LyXRC const & rc)
2411 size_t const end = modules_.size();
2412 for (size_t i = 0; i != end; ++i)
2413 modules_[i]->update(rc);
2417 void GuiPreferences::applyView()
2423 void GuiPreferences::updateContents()
2429 bool GuiPreferences::initialiseParams(string const &)
2432 formats_ = lyx::formats;
2433 converters_ = theConverters();
2434 converters_.update(formats_);
2435 movers_ = theMovers();
2437 update_screen_font_ = false;
2443 void GuiPreferences::dispatchParams()
2446 rc_.write(ss, true);
2447 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
2448 // FIXME: these need lfuns
2450 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
2452 lyx::formats = formats_;
2454 theConverters() = converters_;
2455 theConverters().update(lyx::formats);
2456 theConverters().buildGraph();
2458 theMovers() = movers_;
2460 vector<string>::const_iterator it = colors_.begin();
2461 vector<string>::const_iterator const end = colors_.end();
2462 for (; it != end; ++it)
2463 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
2466 if (update_screen_font_) {
2467 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2468 update_screen_font_ = false;
2471 // The Save button has been pressed
2473 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
2477 void GuiPreferences::setColor(ColorCode col, string const & hex)
2479 colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
2483 void GuiPreferences::updateScreenFonts()
2485 update_screen_font_ = true;
2489 QString GuiPreferences::browsebind(QString const & file) const
2491 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
2492 FileFilterList(_("LyX bind files (*.bind)")));
2496 QString GuiPreferences::browseUI(QString const & file) const
2498 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
2499 FileFilterList(_("LyX UI files (*.ui)")));
2503 QString GuiPreferences::browsekbmap(QString const & file) const
2505 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
2506 FileFilterList(_("LyX keyboard maps (*.kmap)")));
2510 QString GuiPreferences::browsedict(QString const & file) const
2512 return browseFile(file, qt_("Choose personal dictionary"),
2513 FileFilterList(lyxrc.use_spell_lib ? _("*.pws") : _("*.ispell")));
2517 QString GuiPreferences::browse(QString const & file,
2518 QString const & title) const
2520 return browseFile(file, title, FileFilterList(), true);
2524 QString GuiPreferences::browsedir(QString const & path,
2525 QString const & title) const
2527 return browseDir(path, title);
2531 // We support less paper sizes than the document dialog
2532 // Therefore this adjustment is needed.
2533 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
2537 return PAPER_DEFAULT;
2539 return PAPER_USLETTER;
2541 return PAPER_USLEGAL;
2543 return PAPER_USEXECUTIVE;
2553 // should not happen
2554 return PAPER_DEFAULT;
2559 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
2561 switch (papersize) {
2564 case PAPER_USLETTER:
2568 case PAPER_USEXECUTIVE:
2579 // should not happen
2585 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
2588 } // namespace frontend
2591 #include "GuiPrefs_moc.cpp"