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 "FileDialog.h"
17 #include "GuiApplication.h"
18 #include "GuiFontExample.h"
19 #include "GuiFontLoader.h"
20 #include "GuiKeySymbol.h"
21 #include "qt_helpers.h"
23 #include "BufferList.h"
25 #include "ConverterCache.h"
26 #include "FuncRequest.h"
28 #include "KeySequence.h"
30 #include "LyXAction.h"
31 #include "PanelStack.h"
35 #include "support/debug.h"
36 #include "support/FileName.h"
37 #include "support/filetools.h"
38 #include "support/foreach.h"
39 #include "support/gettext.h"
40 #include "support/lstrings.h"
41 #include "support/os.h"
42 #include "support/Package.h"
44 #include "graphics/GraphicsTypes.h"
46 #include "frontends/alert.h"
47 #include "frontends/Application.h"
50 #include <QColorDialog>
51 #include <QFontDatabase>
52 #include <QHeaderView>
54 #include <QPixmapCache>
55 #include <QPushButton>
58 #include <QTreeWidget>
59 #include <QTreeWidgetItem>
69 using namespace lyx::support;
70 using namespace lyx::support::os;
75 /////////////////////////////////////////////////////////////////////
79 /////////////////////////////////////////////////////////////////////
81 /** Launch a file dialog and return the chosen file.
82 filename: a suggested filename.
83 title: the title of the dialog.
85 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
87 QString browseFile(QString const & filename,
88 QString const & title,
89 QStringList const & filters,
91 QString const & label1 = QString(),
92 QString const & dir1 = QString(),
93 QString const & label2 = QString(),
94 QString const & dir2 = QString())
96 QString lastPath = ".";
97 if (!filename.isEmpty())
98 lastPath = onlyPath(filename);
100 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
101 dlg.setButton2(label1, dir1);
102 dlg.setButton2(label2, dir2);
104 FileDialog::Result result;
107 result = dlg.save(lastPath, filters, onlyFilename(filename));
109 result = dlg.open(lastPath, filters, onlyFilename(filename));
111 return result.second;
115 /** Wrapper around browseFile which tries to provide a filename
116 * relative to the user or system directory. The dir, name and ext
117 * parameters have the same meaning as in the
118 * support::LibFileSearch function.
120 QString browseLibFile(QString const & dir,
121 QString const & name,
123 QString const & title,
124 QStringList const & filters)
127 QString const label1 = qt_("System files|#S#s");
129 toqstr(addName(package().system_support().absFilename(), fromqstr(dir)));
131 QString const label2 = qt_("User files|#U#u");
133 toqstr(addName(package().user_support().absFilename(), fromqstr(dir)));
135 QString const result = browseFile(toqstr(
136 libFileSearch(dir, name, ext).absFilename()),
137 title, filters, false, dir1, dir2);
139 // remove the extension if it is the default one
141 if (getExtension(result) == ext)
142 noextresult = removeExtension(result);
144 noextresult = result;
146 // remove the directory, if it is the default one
147 QString const file = onlyFilename(noextresult);
148 if (toqstr(libFileSearch(dir, file, ext).absFilename()) == result)
155 /** Launch a file dialog and return the chosen directory.
156 pathname: a suggested pathname.
157 title: the title of the dialog.
158 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
160 QString browseDir(QString const & pathname,
161 QString const & title,
162 QString const & label1 = QString(),
163 QString const & dir1 = QString(),
164 QString const & label2 = QString(),
165 QString const & dir2 = QString())
167 QString lastPath = ".";
168 if (!pathname.isEmpty())
169 lastPath = onlyPath(pathname);
171 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
172 dlg.setButton1(label1, dir1);
173 dlg.setButton2(label2, dir2);
175 FileDialog::Result const result =
176 dlg.opendir(lastPath, onlyFilename(pathname));
178 return result.second;
182 } // namespace frontend
185 QString browseRelFile(QString const & filename, QString const & refpath,
186 QString const & title, QStringList const & filters, bool save,
187 QString const & label1, QString const & dir1,
188 QString const & label2, QString const & dir2)
190 QString const fname = makeAbsPath(filename, refpath);
193 QString const outname =
194 frontend::browseFile(fname, title, filters, save, label1, dir1, label2, dir2);
196 QString const reloutname =
197 toqstr(makeRelPath(qstring_to_ucs4(outname), qstring_to_ucs4(refpath)));
199 if (reloutname.startsWith("../"))
207 /////////////////////////////////////////////////////////////////////
211 /////////////////////////////////////////////////////////////////////
215 string const catLookAndFeel = N_("Look & Feel");
216 string const catEditing = N_("Editing");
217 string const catLanguage = N_("Language Settings");
218 string const catOutput = N_("Output");
219 string const catFiles = N_("File Handling");
221 static void parseFontName(QString const & mangled0,
222 string & name, string & foundry)
224 string mangled = fromqstr(mangled0);
225 size_t const idx = mangled.find('[');
226 if (idx == string::npos || idx == 0) {
230 name = mangled.substr(0, idx - 1),
231 foundry = mangled.substr(idx + 1, mangled.size() - idx - 2);
236 static void setComboxFont(QComboBox * cb, string const & family,
237 string const & foundry)
239 QString fontname = toqstr(family);
240 if (!foundry.empty())
241 fontname += " [" + toqstr(foundry) + ']';
243 for (int i = 0; i != cb->count(); ++i) {
244 if (cb->itemText(i) == fontname) {
245 cb->setCurrentIndex(i);
250 // Try matching without foundry name
252 // We count in reverse in order to prefer the Xft foundry
253 for (int i = cb->count(); --i >= 0;) {
254 string name, foundry;
255 parseFontName(cb->itemText(i), name, foundry);
256 if (compare_ascii_no_case(name, family) == 0) {
257 cb->setCurrentIndex(i);
262 // family alone can contain e.g. "Helvetica [Adobe]"
263 string tmpname, tmpfoundry;
264 parseFontName(toqstr(family), tmpname, tmpfoundry);
266 // We count in reverse in order to prefer the Xft foundry
267 for (int i = cb->count(); --i >= 0; ) {
268 string name, foundry;
269 parseFontName(cb->itemText(i), name, foundry);
270 if (compare_ascii_no_case(name, foundry) == 0) {
271 cb->setCurrentIndex(i);
276 // Bleh, default fonts, and the names couldn't be found. Hack
280 font.setKerning(false);
282 QString const font_family = toqstr(family);
283 if (font_family == guiApp->romanFontName()) {
284 font.setStyleHint(QFont::Serif);
285 font.setFamily(font_family);
286 } else if (font_family == guiApp->sansFontName()) {
287 font.setStyleHint(QFont::SansSerif);
288 font.setFamily(font_family);
289 } else if (font_family == guiApp->typewriterFontName()) {
290 font.setStyleHint(QFont::TypeWriter);
291 font.setFamily(font_family);
293 LYXERR0("FAILED to find the default font: '"
294 << foundry << "', '" << family << '\'');
298 QFontInfo info(font);
299 string default_font_name, dummyfoundry;
300 parseFontName(info.family(), default_font_name, dummyfoundry);
301 LYXERR0("Apparent font is " << default_font_name);
303 for (int i = 0; i < cb->count(); ++i) {
304 LYXERR0("Looking at " << cb->itemText(i));
305 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
306 default_font_name) == 0) {
307 cb->setCurrentIndex(i);
312 LYXERR0("FAILED to find the font: '"
313 << foundry << "', '" << family << '\'');
318 /////////////////////////////////////////////////////////////////////
322 /////////////////////////////////////////////////////////////////////
324 PrefPlaintext::PrefPlaintext(QWidget * parent)
325 : PrefModule(qt_(catOutput), qt_("Plain text"), 0, parent)
328 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
329 this, SIGNAL(changed()));
330 connect(plaintextRoffED, SIGNAL(textChanged(QString)),
331 this, SIGNAL(changed()));
335 void PrefPlaintext::apply(LyXRC & rc) const
337 rc.plaintext_linelen = plaintextLinelengthSB->value();
338 rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
342 void PrefPlaintext::update(LyXRC const & rc)
344 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
345 plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
349 /////////////////////////////////////////////////////////////////////
353 /////////////////////////////////////////////////////////////////////
355 PrefDate::PrefDate(QWidget * parent)
356 : PrefModule(qt_(catOutput), qt_("Date format"), 0, parent)
359 connect(DateED, SIGNAL(textChanged(QString)),
360 this, SIGNAL(changed()));
364 void PrefDate::apply(LyXRC & rc) const
366 rc.date_insert_format = fromqstr(DateED->text());
370 void PrefDate::update(LyXRC const & rc)
372 DateED->setText(toqstr(rc.date_insert_format));
376 /////////////////////////////////////////////////////////////////////
380 /////////////////////////////////////////////////////////////////////
382 PrefInput::PrefInput(GuiPreferences * form, QWidget * parent)
383 : PrefModule(qt_(catEditing), qt_("Keyboard/Mouse"), form, parent)
387 connect(keymapCB, SIGNAL(clicked()),
388 this, SIGNAL(changed()));
389 connect(firstKeymapED, SIGNAL(textChanged(QString)),
390 this, SIGNAL(changed()));
391 connect(secondKeymapED, SIGNAL(textChanged(QString)),
392 this, SIGNAL(changed()));
393 connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
394 this, SIGNAL(changed()));
398 void PrefInput::apply(LyXRC & rc) const
400 // FIXME: can derive CB from the two EDs
401 rc.use_kbmap = keymapCB->isChecked();
402 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
403 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
404 rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
408 void PrefInput::update(LyXRC const & rc)
410 // FIXME: can derive CB from the two EDs
411 keymapCB->setChecked(rc.use_kbmap);
412 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
413 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
414 mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
418 QString PrefInput::testKeymap(QString keymap)
420 return form_->browsekbmap(toqstr(internal_path(fromqstr(keymap))));
424 void PrefInput::on_firstKeymapPB_clicked(bool)
426 QString const file = testKeymap(firstKeymapED->text());
428 firstKeymapED->setText(file);
432 void PrefInput::on_secondKeymapPB_clicked(bool)
434 QString const file = testKeymap(secondKeymapED->text());
436 secondKeymapED->setText(file);
440 void PrefInput::on_keymapCB_toggled(bool keymap)
442 firstKeymapLA->setEnabled(keymap);
443 secondKeymapLA->setEnabled(keymap);
444 firstKeymapED->setEnabled(keymap);
445 secondKeymapED->setEnabled(keymap);
446 firstKeymapPB->setEnabled(keymap);
447 secondKeymapPB->setEnabled(keymap);
451 /////////////////////////////////////////////////////////////////////
455 /////////////////////////////////////////////////////////////////////
457 PrefCompletion::PrefCompletion(GuiPreferences * form, QWidget * parent)
458 : PrefModule(qt_(catEditing), qt_("Input Completion"), form, parent)
462 connect(inlineDelaySB, SIGNAL(valueChanged(double)),
463 this, SIGNAL(changed()));
464 connect(inlineMathCB, SIGNAL(clicked()),
465 this, SIGNAL(changed()));
466 connect(inlineTextCB, SIGNAL(clicked()),
467 this, SIGNAL(changed()));
468 connect(inlineDotsCB, SIGNAL(clicked()),
469 this, SIGNAL(changed()));
470 connect(popupDelaySB, SIGNAL(valueChanged(double)),
471 this, SIGNAL(changed()));
472 connect(popupMathCB, SIGNAL(clicked()),
473 this, SIGNAL(changed()));
474 connect(popupTextCB, SIGNAL(clicked()),
475 this, SIGNAL(changed()));
476 connect(popupAfterCompleteCB, SIGNAL(clicked()),
477 this, SIGNAL(changed()));
478 connect(cursorTextCB, SIGNAL(clicked()),
479 this, SIGNAL(changed()));
483 void PrefCompletion::apply(LyXRC & rc) const
485 rc.completion_inline_delay = inlineDelaySB->value();
486 rc.completion_inline_math = inlineMathCB->isChecked();
487 rc.completion_inline_text = inlineTextCB->isChecked();
488 rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
489 rc.completion_popup_delay = popupDelaySB->value();
490 rc.completion_popup_math = popupMathCB->isChecked();
491 rc.completion_popup_text = popupTextCB->isChecked();
492 rc.completion_cursor_text = cursorTextCB->isChecked();
493 rc.completion_popup_after_complete =
494 popupAfterCompleteCB->isChecked();
498 void PrefCompletion::update(LyXRC const & rc)
500 inlineDelaySB->setValue(rc.completion_inline_delay);
501 inlineMathCB->setChecked(rc.completion_inline_math);
502 inlineTextCB->setChecked(rc.completion_inline_text);
503 inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
504 popupDelaySB->setValue(rc.completion_popup_delay);
505 popupMathCB->setChecked(rc.completion_popup_math);
506 popupTextCB->setChecked(rc.completion_popup_text);
507 cursorTextCB->setChecked(rc.completion_cursor_text);
508 popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
513 /////////////////////////////////////////////////////////////////////
517 /////////////////////////////////////////////////////////////////////
519 PrefLatex::PrefLatex(GuiPreferences * form, QWidget * parent)
520 : PrefModule(qt_(catOutput), qt_("LaTeX"), form, parent)
523 connect(latexEncodingED, SIGNAL(textChanged(QString)),
524 this, SIGNAL(changed()));
525 connect(latexChecktexED, SIGNAL(textChanged(QString)),
526 this, SIGNAL(changed()));
527 connect(latexBibtexED, SIGNAL(textChanged(QString)),
528 this, SIGNAL(changed()));
529 connect(latexIndexED, SIGNAL(textChanged(QString)),
530 this, SIGNAL(changed()));
531 connect(latexAutoresetCB, SIGNAL(clicked()),
532 this, SIGNAL(changed()));
533 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
534 this, SIGNAL(changed()));
535 connect(latexPaperSizeCO, SIGNAL(activated(int)),
536 this, SIGNAL(changed()));
538 #if defined(__CYGWIN__) || defined(_WIN32)
539 pathCB->setVisible(true);
540 connect(pathCB, SIGNAL(clicked()),
541 this, SIGNAL(changed()));
543 pathCB->setVisible(false);
548 void PrefLatex::apply(LyXRC & rc) const
550 rc.fontenc = fromqstr(latexEncodingED->text());
551 rc.chktex_command = fromqstr(latexChecktexED->text());
552 rc.bibtex_command = fromqstr(latexBibtexED->text());
553 rc.index_command = fromqstr(latexIndexED->text());
554 rc.auto_reset_options = latexAutoresetCB->isChecked();
555 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
556 rc.default_papersize =
557 form_->toPaperSize(latexPaperSizeCO->currentIndex());
558 #if defined(__CYGWIN__) || defined(_WIN32)
559 rc.windows_style_tex_paths = pathCB->isChecked();
564 void PrefLatex::update(LyXRC const & rc)
566 latexEncodingED->setText(toqstr(rc.fontenc));
567 latexChecktexED->setText(toqstr(rc.chktex_command));
568 latexBibtexED->setText(toqstr(rc.bibtex_command));
569 latexIndexED->setText(toqstr(rc.index_command));
570 latexAutoresetCB->setChecked(rc.auto_reset_options);
571 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
572 latexPaperSizeCO->setCurrentIndex(
573 form_->fromPaperSize(rc.default_papersize));
574 #if defined(__CYGWIN__) || defined(_WIN32)
575 pathCB->setChecked(rc.windows_style_tex_paths);
580 /////////////////////////////////////////////////////////////////////
584 /////////////////////////////////////////////////////////////////////
586 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form, QWidget * parent)
587 : PrefModule(qt_(catLookAndFeel), qt_("Screen fonts"), form, parent)
591 connect(screenRomanCO, SIGNAL(activated(QString)),
592 this, SLOT(select_roman(QString)));
593 connect(screenSansCO, SIGNAL(activated(QString)),
594 this, SLOT(select_sans(QString)));
595 connect(screenTypewriterCO, SIGNAL(activated(QString)),
596 this, SLOT(select_typewriter(QString)));
598 QFontDatabase fontdb;
599 QStringList families(fontdb.families());
600 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
601 screenRomanCO->addItem(*it);
602 screenSansCO->addItem(*it);
603 screenTypewriterCO->addItem(*it);
605 connect(screenRomanCO, SIGNAL(activated(QString)),
606 this, SIGNAL(changed()));
607 connect(screenSansCO, SIGNAL(activated(QString)),
608 this, SIGNAL(changed()));
609 connect(screenTypewriterCO, SIGNAL(activated(QString)),
610 this, SIGNAL(changed()));
611 connect(screenZoomSB, SIGNAL(valueChanged(int)),
612 this, SIGNAL(changed()));
613 connect(screenDpiSB, SIGNAL(valueChanged(int)),
614 this, SIGNAL(changed()));
615 connect(screenTinyED, SIGNAL(textChanged(QString)),
616 this, SIGNAL(changed()));
617 connect(screenSmallestED, SIGNAL(textChanged(QString)),
618 this, SIGNAL(changed()));
619 connect(screenSmallerED, SIGNAL(textChanged(QString)),
620 this, SIGNAL(changed()));
621 connect(screenSmallED, SIGNAL(textChanged(QString)),
622 this, SIGNAL(changed()));
623 connect(screenNormalED, SIGNAL(textChanged(QString)),
624 this, SIGNAL(changed()));
625 connect(screenLargeED, SIGNAL(textChanged(QString)),
626 this, SIGNAL(changed()));
627 connect(screenLargerED, SIGNAL(textChanged(QString)),
628 this, SIGNAL(changed()));
629 connect(screenLargestED, SIGNAL(textChanged(QString)),
630 this, SIGNAL(changed()));
631 connect(screenHugeED, SIGNAL(textChanged(QString)),
632 this, SIGNAL(changed()));
633 connect(screenHugerED, SIGNAL(textChanged(QString)),
634 this, SIGNAL(changed()));
635 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
636 this, SIGNAL(changed()));
638 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
639 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
640 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
641 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
642 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
643 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
644 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
645 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
646 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
647 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
651 void PrefScreenFonts::apply(LyXRC & rc) const
653 LyXRC const oldrc = rc;
655 parseFontName(screenRomanCO->currentText(),
656 rc.roman_font_name, rc.roman_font_foundry);
657 parseFontName(screenSansCO->currentText(),
658 rc.sans_font_name, rc.sans_font_foundry);
659 parseFontName(screenTypewriterCO->currentText(),
660 rc.typewriter_font_name, rc.typewriter_font_foundry);
662 rc.zoom = screenZoomSB->value();
663 rc.dpi = screenDpiSB->value();
664 rc.font_sizes[FONT_SIZE_TINY] = fromqstr(screenTinyED->text());
665 rc.font_sizes[FONT_SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
666 rc.font_sizes[FONT_SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
667 rc.font_sizes[FONT_SIZE_SMALL] = fromqstr(screenSmallED->text());
668 rc.font_sizes[FONT_SIZE_NORMAL] = fromqstr(screenNormalED->text());
669 rc.font_sizes[FONT_SIZE_LARGE] = fromqstr(screenLargeED->text());
670 rc.font_sizes[FONT_SIZE_LARGER] = fromqstr(screenLargerED->text());
671 rc.font_sizes[FONT_SIZE_LARGEST] = fromqstr(screenLargestED->text());
672 rc.font_sizes[FONT_SIZE_HUGE] = fromqstr(screenHugeED->text());
673 rc.font_sizes[FONT_SIZE_HUGER] = fromqstr(screenHugerED->text());
674 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
676 if (rc.font_sizes != oldrc.font_sizes
677 || rc.roman_font_name != oldrc.roman_font_name
678 || rc.sans_font_name != oldrc.sans_font_name
679 || rc.typewriter_font_name != oldrc.typewriter_font_name
680 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
681 // The global QPixmapCache is used in GuiPainter to cache text
682 // painting so we must reset it in case any of the above
683 // parameter is changed.
684 QPixmapCache::clear();
685 guiApp->fontLoader().update();
686 form_->updateScreenFonts();
691 void PrefScreenFonts::update(LyXRC const & rc)
693 setComboxFont(screenRomanCO, rc.roman_font_name,
694 rc.roman_font_foundry);
695 setComboxFont(screenSansCO, rc.sans_font_name,
696 rc.sans_font_foundry);
697 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
698 rc.typewriter_font_foundry);
700 select_roman(screenRomanCO->currentText());
701 select_sans(screenSansCO->currentText());
702 select_typewriter(screenTypewriterCO->currentText());
704 screenZoomSB->setValue(rc.zoom);
705 screenDpiSB->setValue(rc.dpi);
706 screenTinyED->setText(toqstr(rc.font_sizes[FONT_SIZE_TINY]));
707 screenSmallestED->setText(toqstr(rc.font_sizes[FONT_SIZE_SCRIPT]));
708 screenSmallerED->setText(toqstr(rc.font_sizes[FONT_SIZE_FOOTNOTE]));
709 screenSmallED->setText(toqstr(rc.font_sizes[FONT_SIZE_SMALL]));
710 screenNormalED->setText(toqstr(rc.font_sizes[FONT_SIZE_NORMAL]));
711 screenLargeED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGE]));
712 screenLargerED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGER]));
713 screenLargestED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGEST]));
714 screenHugeED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGE]));
715 screenHugerED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGER]));
717 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
718 #if defined(Q_WS_X11)
719 pixmapCacheCB->setEnabled(false);
725 void PrefScreenFonts::select_roman(const QString & name)
727 screenRomanFE->set(QFont(name), name);
731 void PrefScreenFonts::select_sans(const QString & name)
733 screenSansFE->set(QFont(name), name);
737 void PrefScreenFonts::select_typewriter(const QString & name)
739 screenTypewriterFE->set(QFont(name), name);
743 /////////////////////////////////////////////////////////////////////
747 /////////////////////////////////////////////////////////////////////
753 bool operator()(ColorCode lhs, ColorCode rhs) const {
754 return lcolor.getGUIName(lhs) < lcolor.getGUIName(rhs);
760 PrefColors::PrefColors(GuiPreferences * form, QWidget * parent)
761 : PrefModule(qt_(catLookAndFeel), qt_("Colors"), form, parent)
765 // FIXME: all of this initialization should be put into the controller.
766 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
767 // for some discussion of why that is not trivial.
768 QPixmap icon(32, 32);
769 for (int i = 0; i < Color_ignore; ++i) {
770 ColorCode lc = static_cast<ColorCode>(i);
778 || lc == Color_magenta
779 || lc == Color_yellow
780 || lc == Color_inherit
781 || lc == Color_ignore) continue;
783 lcolors_.push_back(lc);
785 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
786 vector<ColorCode>::const_iterator cit = lcolors_.begin();
787 vector<ColorCode>::const_iterator const end = lcolors_.end();
788 for (; cit != end; ++cit) {
789 (void) new QListWidgetItem(QIcon(icon),
790 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
792 curcolors_.resize(lcolors_.size());
793 newcolors_.resize(lcolors_.size());
794 // End initialization
796 connect(colorChangePB, SIGNAL(clicked()),
797 this, SLOT(change_color()));
798 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
799 this, SLOT(change_lyxObjects_selection()));
800 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
801 this, SLOT(change_color()));
805 void PrefColors::apply(LyXRC & /*rc*/) const
807 for (unsigned int i = 0; i < lcolors_.size(); ++i)
808 if (curcolors_[i] != newcolors_[i])
809 form_->setColor(lcolors_[i], fromqstr(newcolors_[i]));
813 void PrefColors::update(LyXRC const & /*rc*/)
815 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
816 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
817 QPixmap coloritem(32, 32);
818 coloritem.fill(color);
819 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
820 newcolors_[i] = curcolors_[i] = color.name();
822 change_lyxObjects_selection();
826 void PrefColors::change_color()
828 int const row = lyxObjectsLW->currentRow();
834 QString const color = newcolors_[row];
835 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
837 if (c.isValid() && c.name() != color) {
838 newcolors_[row] = c.name();
839 QPixmap coloritem(32, 32);
841 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
847 void PrefColors::change_lyxObjects_selection()
849 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
853 /////////////////////////////////////////////////////////////////////
857 /////////////////////////////////////////////////////////////////////
859 PrefDisplay::PrefDisplay(QWidget * parent)
860 : PrefModule(qt_(catLookAndFeel), qt_("Graphics"), 0, parent)
863 connect(instantPreviewCO, SIGNAL(activated(int)),
864 this, SIGNAL(changed()));
865 connect(displayGraphicsCO, SIGNAL(activated(int)),
866 this, SIGNAL(changed()));
870 void PrefDisplay::apply(LyXRC & rc) const
872 switch (instantPreviewCO->currentIndex()) {
873 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
874 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
875 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
878 graphics::DisplayType dtype;
879 switch (displayGraphicsCO->currentIndex()) {
880 case 3: dtype = graphics::NoDisplay; break;
881 case 2: dtype = graphics::ColorDisplay; break;
882 case 1: dtype = graphics::GrayscaleDisplay; break;
883 case 0: dtype = graphics::MonochromeDisplay; break;
884 default: dtype = graphics::GrayscaleDisplay;
886 rc.display_graphics = dtype;
888 // FIXME!! The graphics cache no longer has a changeDisplay method.
890 if (old_value != rc.display_graphics) {
891 graphics::GCache & gc = graphics::GCache::get();
898 void PrefDisplay::update(LyXRC const & rc)
900 switch (rc.preview) {
901 case LyXRC::PREVIEW_OFF:
902 instantPreviewCO->setCurrentIndex(0);
904 case LyXRC::PREVIEW_NO_MATH :
905 instantPreviewCO->setCurrentIndex(1);
907 case LyXRC::PREVIEW_ON :
908 instantPreviewCO->setCurrentIndex(2);
913 switch (rc.display_graphics) {
914 case graphics::NoDisplay: item = 3; break;
915 case graphics::ColorDisplay: item = 2; break;
916 case graphics::GrayscaleDisplay: item = 1; break;
917 case graphics::MonochromeDisplay: item = 0; break;
920 displayGraphicsCO->setCurrentIndex(item);
924 /////////////////////////////////////////////////////////////////////
928 /////////////////////////////////////////////////////////////////////
930 PrefPaths::PrefPaths(GuiPreferences * form, QWidget * parent)
931 : PrefModule(QString(), qt_("Paths"), form, parent)
934 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(select_exampledir()));
935 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
936 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
937 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
938 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
939 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
940 connect(workingDirED, SIGNAL(textChanged(QString)),
941 this, SIGNAL(changed()));
942 connect(exampleDirED, SIGNAL(textChanged(QString)),
943 this, SIGNAL(changed()));
944 connect(templateDirED, SIGNAL(textChanged(QString)),
945 this, SIGNAL(changed()));
946 connect(backupDirED, SIGNAL(textChanged(QString)),
947 this, SIGNAL(changed()));
948 connect(tempDirED, SIGNAL(textChanged(QString)),
949 this, SIGNAL(changed()));
950 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
951 this, SIGNAL(changed()));
952 connect(pathPrefixED, SIGNAL(textChanged(QString)),
953 this, SIGNAL(changed()));
957 void PrefPaths::apply(LyXRC & rc) const
959 rc.document_path = internal_path(fromqstr(workingDirED->text()));
960 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
961 rc.template_path = internal_path(fromqstr(templateDirED->text()));
962 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
963 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
964 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
965 // FIXME: should be a checkbox only
966 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
970 void PrefPaths::update(LyXRC const & rc)
972 workingDirED->setText(toqstr(external_path(rc.document_path)));
973 exampleDirED->setText(toqstr(external_path(rc.example_path)));
974 templateDirED->setText(toqstr(external_path(rc.template_path)));
975 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
976 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
977 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
978 // FIXME: should be a checkbox only
979 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
983 void PrefPaths::select_exampledir()
985 QString file = browseDir(internalPath(exampleDirED->text()),
986 qt_("Select directory for example files"));
988 exampleDirED->setText(file);
992 void PrefPaths::select_templatedir()
994 QString file = browseDir(internalPath(templateDirED->text()),
995 qt_("Select a document templates directory"));
997 templateDirED->setText(file);
1001 void PrefPaths::select_tempdir()
1003 QString file = browseDir(internalPath(tempDirED->text()),
1004 qt_("Select a temporary directory"));
1005 if (!file.isEmpty())
1006 tempDirED->setText(file);
1010 void PrefPaths::select_backupdir()
1012 QString file = browseDir(internalPath(backupDirED->text()),
1013 qt_("Select a backups directory"));
1014 if (!file.isEmpty())
1015 backupDirED->setText(file);
1019 void PrefPaths::select_workingdir()
1021 QString file = browseDir(internalPath(workingDirED->text()),
1022 qt_("Select a document directory"));
1023 if (!file.isEmpty())
1024 workingDirED->setText(file);
1028 void PrefPaths::select_lyxpipe()
1030 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1031 qt_("Give a filename for the LyX server pipe"));
1032 if (!file.isEmpty())
1033 lyxserverDirED->setText(file);
1037 /////////////////////////////////////////////////////////////////////
1041 /////////////////////////////////////////////////////////////////////
1043 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form, QWidget * parent)
1044 : PrefModule(qt_(catLanguage), qt_("Spellchecker"), form, parent)
1048 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
1049 #if defined (USE_ISPELL)
1050 connect(spellCommandCO, SIGNAL(activated(int)),
1051 this, SIGNAL(changed()));
1053 spellCommandCO->setEnabled(false);
1055 connect(altLanguageED, SIGNAL(textChanged(QString)),
1056 this, SIGNAL(changed()));
1057 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1058 this, SIGNAL(changed()));
1059 connect(persDictionaryED, SIGNAL(textChanged(QString)),
1060 this, SIGNAL(changed()));
1061 connect(compoundWordCB, SIGNAL(clicked()),
1062 this, SIGNAL(changed()));
1063 connect(inputEncodingCB, SIGNAL(clicked()),
1064 this, SIGNAL(changed()));
1066 spellCommandCO->addItem(qt_("ispell"));
1067 spellCommandCO->addItem(qt_("aspell"));
1068 spellCommandCO->addItem(qt_("hspell"));
1070 spellCommandCO->addItem(qt_("pspell (library)"));
1073 spellCommandCO->addItem(qt_("aspell (library)"));
1079 void PrefSpellchecker::apply(LyXRC & rc) const
1081 switch (spellCommandCO->currentIndex()) {
1085 rc.use_spell_lib = false;
1086 rc.isp_command = fromqstr(spellCommandCO->currentText());
1089 rc.use_spell_lib = true;
1093 // FIXME: remove isp_use_alt_lang
1094 rc.isp_alt_lang = fromqstr(altLanguageED->text());
1095 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
1096 // FIXME: remove isp_use_esc_chars
1097 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
1098 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
1099 // FIXME: remove isp_use_pers_dict
1100 rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
1101 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
1102 rc.isp_accept_compound = compoundWordCB->isChecked();
1103 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
1107 void PrefSpellchecker::update(LyXRC const & rc)
1109 spellCommandCO->setCurrentIndex(0);
1111 if (rc.isp_command == "ispell") {
1112 spellCommandCO->setCurrentIndex(0);
1113 } else if (rc.isp_command == "aspell") {
1114 spellCommandCO->setCurrentIndex(1);
1115 } else if (rc.isp_command == "hspell") {
1116 spellCommandCO->setCurrentIndex(2);
1119 if (rc.use_spell_lib) {
1120 #if defined(USE_ASPELL) || defined(USE_PSPELL)
1121 spellCommandCO->setCurrentIndex(3);
1125 // FIXME: remove isp_use_alt_lang
1126 altLanguageED->setText(toqstr(rc.isp_alt_lang));
1127 // FIXME: remove isp_use_esc_chars
1128 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
1129 // FIXME: remove isp_use_pers_dict
1130 persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
1131 compoundWordCB->setChecked(rc.isp_accept_compound);
1132 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
1136 void PrefSpellchecker::select_dict()
1138 QString file = form_->browsedict(internalPath(persDictionaryED->text()));
1139 if (!file.isEmpty())
1140 persDictionaryED->setText(file);
1145 /////////////////////////////////////////////////////////////////////
1149 /////////////////////////////////////////////////////////////////////
1152 PrefConverters::PrefConverters(GuiPreferences * form, QWidget * parent)
1153 : PrefModule(qt_(catFiles), qt_("Converters"), form, parent)
1157 connect(converterNewPB, SIGNAL(clicked()),
1158 this, SLOT(update_converter()));
1159 connect(converterRemovePB, SIGNAL(clicked()),
1160 this, SLOT(remove_converter()));
1161 connect(converterModifyPB, SIGNAL(clicked()),
1162 this, SLOT(update_converter()));
1163 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1164 this, SLOT(switch_converter()));
1165 connect(converterFromCO, SIGNAL(activated(QString)),
1166 this, SLOT(converter_changed()));
1167 connect(converterToCO, SIGNAL(activated(QString)),
1168 this, SLOT(converter_changed()));
1169 connect(converterED, SIGNAL(textEdited(QString)),
1170 this, SLOT(converter_changed()));
1171 connect(converterFlagED, SIGNAL(textEdited(QString)),
1172 this, SLOT(converter_changed()));
1173 connect(converterNewPB, SIGNAL(clicked()),
1174 this, SIGNAL(changed()));
1175 connect(converterRemovePB, SIGNAL(clicked()),
1176 this, SIGNAL(changed()));
1177 connect(converterModifyPB, SIGNAL(clicked()),
1178 this, SIGNAL(changed()));
1179 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1180 this, SIGNAL(changed()));
1182 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1183 //converterDefGB->setFocusProxy(convertersLW);
1187 void PrefConverters::apply(LyXRC & rc) const
1189 rc.use_converter_cache = cacheCB->isChecked();
1190 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
1194 void PrefConverters::update(LyXRC const & rc)
1196 cacheCB->setChecked(rc.use_converter_cache);
1198 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
1199 maxAgeLE->setText(max_age);
1204 void PrefConverters::updateGui()
1206 form_->formats().sort();
1207 form_->converters().update(form_->formats());
1208 // save current selection
1209 QString current = converterFromCO->currentText()
1210 + " -> " + converterToCO->currentText();
1212 converterFromCO->clear();
1213 converterToCO->clear();
1215 Formats::const_iterator cit = form_->formats().begin();
1216 Formats::const_iterator end = form_->formats().end();
1217 for (; cit != end; ++cit) {
1218 converterFromCO->addItem(toqstr(cit->prettyname()));
1219 converterToCO->addItem(toqstr(cit->prettyname()));
1222 // currentRowChanged(int) is also triggered when updating the listwidget
1223 // block signals to avoid unnecessary calls to switch_converter()
1224 convertersLW->blockSignals(true);
1225 convertersLW->clear();
1227 Converters::const_iterator ccit = form_->converters().begin();
1228 Converters::const_iterator cend = form_->converters().end();
1229 for (; ccit != cend; ++ccit) {
1231 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
1232 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1233 new QListWidgetItem(toqstr(name), convertersLW, type);
1235 convertersLW->sortItems(Qt::AscendingOrder);
1236 convertersLW->blockSignals(false);
1238 // restore selection
1239 if (!current.isEmpty()) {
1240 QList<QListWidgetItem *> const item =
1241 convertersLW->findItems(current, Qt::MatchExactly);
1242 if (!item.isEmpty())
1243 convertersLW->setCurrentItem(item.at(0));
1246 // select first element if restoring failed
1247 if (convertersLW->currentRow() == -1)
1248 convertersLW->setCurrentRow(0);
1254 void PrefConverters::switch_converter()
1256 int const cnr = convertersLW->currentItem()->type();
1257 Converter const & c(form_->converters().get(cnr));
1258 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1259 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1260 converterED->setText(toqstr(c.command));
1261 converterFlagED->setText(toqstr(c.flags));
1267 void PrefConverters::converter_changed()
1273 void PrefConverters::updateButtons()
1275 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1276 Format const & to = form_->formats().get(converterToCO->currentIndex());
1277 int const sel = form_->converters().getNumber(from.name(), to.name());
1278 bool const known = sel >= 0;
1279 bool const valid = !(converterED->text().isEmpty()
1280 || from.name() == to.name());
1282 int const cnr = convertersLW->currentItem()->type();
1283 Converter const & c(form_->converters().get(cnr));
1284 string const old_command = c.command;
1285 string const old_flag = c.flags;
1286 string const new_command(fromqstr(converterED->text()));
1287 string const new_flag(fromqstr(converterFlagED->text()));
1289 bool modified = (old_command != new_command) || (old_flag != new_flag);
1291 converterModifyPB->setEnabled(valid && known && modified);
1292 converterNewPB->setEnabled(valid && !known);
1293 converterRemovePB->setEnabled(known);
1295 maxAgeLE->setEnabled(cacheCB->isChecked());
1296 maxAgeLA->setEnabled(cacheCB->isChecked());
1301 // specify unique from/to or it doesn't appear. This is really bad UI
1302 // this is why we can use the same function for both new and modify
1303 void PrefConverters::update_converter()
1305 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1306 Format const & to = form_->formats().get(converterToCO->currentIndex());
1307 string const flags = fromqstr(converterFlagED->text());
1308 string const command = fromqstr(converterED->text());
1310 Converter const * old =
1311 form_->converters().getConverter(from.name(), to.name());
1312 form_->converters().add(from.name(), to.name(), command, flags);
1315 form_->converters().updateLast(form_->formats());
1319 // Remove all files created by this converter from the cache, since
1320 // the modified converter might create different files.
1321 ConverterCache::get().remove_all(from.name(), to.name());
1325 void PrefConverters::remove_converter()
1327 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1328 Format const & to = form_->formats().get(converterToCO->currentIndex());
1329 form_->converters().erase(from.name(), to.name());
1333 // Remove all files created by this converter from the cache, since
1334 // a possible new converter might create different files.
1335 ConverterCache::get().remove_all(from.name(), to.name());
1339 void PrefConverters::on_cacheCB_stateChanged(int state)
1341 maxAgeLE->setEnabled(state == Qt::Checked);
1342 maxAgeLA->setEnabled(state == Qt::Checked);
1347 /////////////////////////////////////////////////////////////////////
1351 /////////////////////////////////////////////////////////////////////
1353 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1354 : QValidator(parent), formats_(f)
1359 void FormatValidator::fixup(QString & input) const
1361 Formats::const_iterator cit = formats_.begin();
1362 Formats::const_iterator end = formats_.end();
1363 for (; cit != end; ++cit) {
1364 string const name = str(cit);
1365 if (distance(formats_.begin(), cit) == nr()) {
1366 input = toqstr(name);
1374 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1376 Formats::const_iterator cit = formats_.begin();
1377 Formats::const_iterator end = formats_.end();
1378 bool unknown = true;
1379 for (; unknown && cit != end; ++cit) {
1380 string const name = str(cit);
1381 if (distance(formats_.begin(), cit) != nr())
1382 unknown = toqstr(name) != input;
1385 if (unknown && !input.isEmpty())
1386 return QValidator::Acceptable;
1388 return QValidator::Intermediate;
1392 int FormatValidator::nr() const
1394 QComboBox * p = qobject_cast<QComboBox *>(parent());
1395 return p->itemData(p->currentIndex()).toInt();
1399 FormatNameValidator::FormatNameValidator(QWidget * parent, Formats const & f)
1400 : FormatValidator(parent, f)
1404 string FormatNameValidator::str(Formats::const_iterator it) const
1410 FormatPrettynameValidator::FormatPrettynameValidator(QWidget * parent, Formats const & f)
1411 : FormatValidator(parent, f)
1416 string FormatPrettynameValidator::str(Formats::const_iterator it) const
1418 return it->prettyname();
1422 PrefFileformats::PrefFileformats(GuiPreferences * form, QWidget * parent)
1423 : PrefModule(qt_(catFiles), qt_("File formats"), form, parent)
1426 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1427 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1429 connect(documentCB, SIGNAL(clicked()),
1430 this, SLOT(setFlags()));
1431 connect(vectorCB, SIGNAL(clicked()),
1432 this, SLOT(setFlags()));
1433 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1434 this, SLOT(updatePrettyname()));
1435 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1436 this, SIGNAL(changed()));
1440 void PrefFileformats::apply(LyXRC & /*rc*/) const
1445 void PrefFileformats::update(LyXRC const & /*rc*/)
1451 void PrefFileformats::updateView()
1453 QString const current = formatsCB->currentText();
1455 // update combobox with formats
1456 formatsCB->blockSignals(true);
1458 form_->formats().sort();
1459 Formats::const_iterator cit = form_->formats().begin();
1460 Formats::const_iterator end = form_->formats().end();
1461 for (; cit != end; ++cit)
1462 formatsCB->addItem(toqstr(cit->prettyname()),
1463 QVariant(form_->formats().getNumber(cit->name())) );
1465 // restore selection
1466 int const item = formatsCB->findText(current, Qt::MatchExactly);
1467 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1468 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1469 formatsCB->blockSignals(false);
1473 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1475 int const nr = formatsCB->itemData(i).toInt();
1476 Format const f = form_->formats().get(nr);
1478 formatED->setText(toqstr(f.name()));
1479 copierED->setText(toqstr(form_->movers().command(f.name())));
1480 extensionED->setText(toqstr(f.extension()));
1481 shortcutED->setText(toqstr(f.shortcut()));
1482 viewerED->setText(toqstr(f.viewer()));
1483 editorED->setText(toqstr(f.editor()));
1484 documentCB->setChecked((f.documentFormat()));
1485 vectorCB->setChecked((f.vectorFormat()));
1489 void PrefFileformats::setFlags()
1491 int flags = Format::none;
1492 if (documentCB->isChecked())
1493 flags |= Format::document;
1494 if (vectorCB->isChecked())
1495 flags |= Format::vector;
1496 currentFormat().setFlags(flags);
1501 void PrefFileformats::on_copierED_textEdited(const QString & s)
1503 string const fmt = fromqstr(formatED->text());
1504 form_->movers().set(fmt, fromqstr(s));
1509 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1511 currentFormat().setExtension(fromqstr(s));
1515 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1517 currentFormat().setViewer(fromqstr(s));
1522 void PrefFileformats::on_editorED_textEdited(const QString & s)
1524 currentFormat().setEditor(fromqstr(s));
1529 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1531 currentFormat().setShortcut(fromqstr(s));
1536 void PrefFileformats::on_formatED_editingFinished()
1538 string const newname = fromqstr(formatED->displayText());
1539 if (newname == currentFormat().name())
1542 currentFormat().setName(newname);
1547 void PrefFileformats::on_formatED_textChanged(const QString &)
1549 QString t = formatED->text();
1551 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1552 setValid(formatLA, valid);
1556 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1558 QString t = formatsCB->currentText();
1560 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1561 setValid(formatsLA, valid);
1565 void PrefFileformats::updatePrettyname()
1567 string const newname = fromqstr(formatsCB->currentText());
1568 if (newname == currentFormat().prettyname())
1571 currentFormat().setPrettyname(newname);
1578 Format & PrefFileformats::currentFormat()
1580 int const i = formatsCB->currentIndex();
1581 int const nr = formatsCB->itemData(i).toInt();
1582 return form_->formats().get(nr);
1586 void PrefFileformats::on_formatNewPB_clicked()
1588 form_->formats().add("", "", "", "", "", "", Format::none);
1590 formatsCB->setCurrentIndex(0);
1591 formatsCB->setFocus(Qt::OtherFocusReason);
1595 void PrefFileformats::on_formatRemovePB_clicked()
1597 int const i = formatsCB->currentIndex();
1598 int const nr = formatsCB->itemData(i).toInt();
1599 string const current_text = form_->formats().get(nr).name();
1600 if (form_->converters().formatIsUsed(current_text)) {
1601 Alert::error(_("Format in use"),
1602 _("Cannot remove a Format used by a Converter. "
1603 "Remove the converter first."));
1607 form_->formats().erase(current_text);
1610 on_formatsCB_editTextChanged(formatsCB->currentText());
1615 /////////////////////////////////////////////////////////////////////
1619 /////////////////////////////////////////////////////////////////////
1621 PrefLanguage::PrefLanguage(QWidget * parent)
1622 : PrefModule(qt_(catLanguage), qt_("Language"), 0, parent)
1626 connect(rtlGB, SIGNAL(clicked()),
1627 this, SIGNAL(changed()));
1628 connect(visualCursorRB, SIGNAL(clicked()),
1629 this, SIGNAL(changed()));
1630 connect(logicalCursorRB, SIGNAL(clicked()),
1631 this, SIGNAL(changed()));
1632 connect(markForeignCB, SIGNAL(clicked()),
1633 this, SIGNAL(changed()));
1634 connect(autoBeginCB, SIGNAL(clicked()),
1635 this, SIGNAL(changed()));
1636 connect(autoEndCB, SIGNAL(clicked()),
1637 this, SIGNAL(changed()));
1638 connect(useBabelCB, SIGNAL(clicked()),
1639 this, SIGNAL(changed()));
1640 connect(globalCB, SIGNAL(clicked()),
1641 this, SIGNAL(changed()));
1642 connect(languagePackageED, SIGNAL(textChanged(QString)),
1643 this, SIGNAL(changed()));
1644 connect(startCommandED, SIGNAL(textChanged(QString)),
1645 this, SIGNAL(changed()));
1646 connect(endCommandED, SIGNAL(textChanged(QString)),
1647 this, SIGNAL(changed()));
1648 connect(defaultLanguageCO, SIGNAL(activated(int)),
1649 this, SIGNAL(changed()));
1651 defaultLanguageCO->clear();
1653 defaultLanguageCO->setModel(guiApp->languageModel());
1657 void PrefLanguage::apply(LyXRC & rc) const
1659 // FIXME: remove rtl_support bool
1660 rc.rtl_support = rtlGB->isChecked();
1661 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
1662 rc.mark_foreign_language = markForeignCB->isChecked();
1663 rc.language_auto_begin = autoBeginCB->isChecked();
1664 rc.language_auto_end = autoEndCB->isChecked();
1665 rc.language_use_babel = useBabelCB->isChecked();
1666 rc.language_global_options = globalCB->isChecked();
1667 rc.language_package = fromqstr(languagePackageED->text());
1668 rc.language_command_begin = fromqstr(startCommandED->text());
1669 rc.language_command_end = fromqstr(endCommandED->text());
1670 rc.default_language = fromqstr(
1671 defaultLanguageCO->itemData(defaultLanguageCO->currentIndex()).toString());
1675 void PrefLanguage::update(LyXRC const & rc)
1677 // FIXME: remove rtl_support bool
1678 rtlGB->setChecked(rc.rtl_support);
1679 if (rc.visual_cursor)
1680 visualCursorRB->setChecked(true);
1682 logicalCursorRB->setChecked(true);
1683 markForeignCB->setChecked(rc.mark_foreign_language);
1684 autoBeginCB->setChecked(rc.language_auto_begin);
1685 autoEndCB->setChecked(rc.language_auto_end);
1686 useBabelCB->setChecked(rc.language_use_babel);
1687 globalCB->setChecked(rc.language_global_options);
1688 languagePackageED->setText(toqstr(rc.language_package));
1689 startCommandED->setText(toqstr(rc.language_command_begin));
1690 endCommandED->setText(toqstr(rc.language_command_end));
1692 int const pos = defaultLanguageCO->findData(toqstr(rc.default_language));
1693 defaultLanguageCO->setCurrentIndex(pos);
1697 /////////////////////////////////////////////////////////////////////
1701 /////////////////////////////////////////////////////////////////////
1703 PrefPrinter::PrefPrinter(QWidget * parent)
1704 : PrefModule(qt_(catOutput), qt_("Printer"), 0, parent)
1708 connect(printerAdaptCB, SIGNAL(clicked()),
1709 this, SIGNAL(changed()));
1710 connect(printerCommandED, SIGNAL(textChanged(QString)),
1711 this, SIGNAL(changed()));
1712 connect(printerNameED, SIGNAL(textChanged(QString)),
1713 this, SIGNAL(changed()));
1714 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
1715 this, SIGNAL(changed()));
1716 connect(printerCopiesED, SIGNAL(textChanged(QString)),
1717 this, SIGNAL(changed()));
1718 connect(printerReverseED, SIGNAL(textChanged(QString)),
1719 this, SIGNAL(changed()));
1720 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
1721 this, SIGNAL(changed()));
1722 connect(printerExtensionED, SIGNAL(textChanged(QString)),
1723 this, SIGNAL(changed()));
1724 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
1725 this, SIGNAL(changed()));
1726 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
1727 this, SIGNAL(changed()));
1728 connect(printerEvenED, SIGNAL(textChanged(QString)),
1729 this, SIGNAL(changed()));
1730 connect(printerOddED, SIGNAL(textChanged(QString)),
1731 this, SIGNAL(changed()));
1732 connect(printerCollatedED, SIGNAL(textChanged(QString)),
1733 this, SIGNAL(changed()));
1734 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
1735 this, SIGNAL(changed()));
1736 connect(printerToFileED, SIGNAL(textChanged(QString)),
1737 this, SIGNAL(changed()));
1738 connect(printerExtraED, SIGNAL(textChanged(QString)),
1739 this, SIGNAL(changed()));
1740 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
1741 this, SIGNAL(changed()));
1742 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
1743 this, SIGNAL(changed()));
1747 void PrefPrinter::apply(LyXRC & rc) const
1749 rc.print_adapt_output = printerAdaptCB->isChecked();
1750 rc.print_command = fromqstr(printerCommandED->text());
1751 rc.printer = fromqstr(printerNameED->text());
1753 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1754 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1755 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1756 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1757 rc.print_file_extension = fromqstr(printerExtensionED->text());
1758 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1759 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1760 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1761 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1762 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1763 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1764 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1765 rc.print_extra_options = fromqstr(printerExtraED->text());
1766 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1767 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1771 void PrefPrinter::update(LyXRC const & rc)
1773 printerAdaptCB->setChecked(rc.print_adapt_output);
1774 printerCommandED->setText(toqstr(rc.print_command));
1775 printerNameED->setText(toqstr(rc.printer));
1777 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1778 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1779 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1780 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1781 printerExtensionED->setText(toqstr(rc.print_file_extension));
1782 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1783 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1784 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1785 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1786 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1787 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1788 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1789 printerExtraED->setText(toqstr(rc.print_extra_options));
1790 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1791 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1795 /////////////////////////////////////////////////////////////////////
1797 // PrefUserInterface
1799 /////////////////////////////////////////////////////////////////////
1801 PrefUserInterface::PrefUserInterface(GuiPreferences * form, QWidget * parent)
1802 : PrefModule(qt_(catLookAndFeel), qt_("User interface"), form, parent)
1806 connect(autoSaveCB, SIGNAL(toggled(bool)),
1807 autoSaveSB, SLOT(setEnabled(bool)));
1808 connect(autoSaveCB, SIGNAL(toggled(bool)),
1809 TextLabel1, SLOT(setEnabled(bool)));
1810 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
1811 this, SIGNAL(changed()));
1812 connect(uiFilePB, SIGNAL(clicked()),
1813 this, SLOT(select_ui()));
1814 connect(uiFileED, SIGNAL(textChanged(QString)),
1815 this, SIGNAL(changed()));
1816 connect(restoreCursorCB, SIGNAL(clicked()),
1817 this, SIGNAL(changed()));
1818 connect(loadSessionCB, SIGNAL(clicked()),
1819 this, SIGNAL(changed()));
1820 connect(allowGeometrySessionCB, SIGNAL(clicked()),
1821 this, SIGNAL(changed()));
1822 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1823 this, SIGNAL(changed()));
1824 connect(autoSaveCB, SIGNAL(clicked()),
1825 this, SIGNAL(changed()));
1826 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1827 this, SIGNAL(changed()));
1828 connect(tooltipCB, 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.autosave = autoSaveSB->value() * 60;
1841 rc.make_backup = autoSaveCB->isChecked();
1842 rc.num_lastfiles = lastfilesSB->value();
1843 rc.use_tooltip = tooltipCB->isChecked();
1844 rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
1848 void PrefUserInterface::update(LyXRC const & rc)
1850 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1851 restoreCursorCB->setChecked(rc.use_lastfilepos);
1852 loadSessionCB->setChecked(rc.load_session);
1853 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
1854 // convert to minutes
1855 int mins(rc.autosave / 60);
1856 if (rc.autosave && !mins)
1858 autoSaveSB->setValue(mins);
1859 autoSaveCB->setChecked(rc.make_backup);
1860 lastfilesSB->setValue(rc.num_lastfiles);
1861 tooltipCB->setChecked(rc.use_tooltip);
1862 openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
1866 void PrefUserInterface::select_ui()
1868 QString file = form_->browseUI(internalPath(uiFileED->text()));
1869 if (!file.isEmpty())
1870 uiFileED->setText(file);
1873 /////////////////////////////////////////////////////////////////////
1877 /////////////////////////////////////////////////////////////////////
1879 PrefEdit::PrefEdit(GuiPreferences * form, QWidget * parent)
1880 : PrefModule(qt_(catEditing), qt_("Control"), form, parent)
1884 connect(cursorFollowsCB, SIGNAL(clicked()),
1885 this, SIGNAL(changed()));
1886 connect(sortEnvironmentsCB, SIGNAL(clicked()),
1887 this, SIGNAL(changed()));
1888 connect(groupEnvironmentsCB, SIGNAL(clicked()),
1889 this, SIGNAL(changed()));
1890 connect(macroEditStyleCO, SIGNAL(activated(int)),
1891 this, SIGNAL(changed()));
1892 connect(fullscreenLimitGB, SIGNAL(clicked()),
1893 this, SIGNAL(changed()));
1894 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
1895 this, SIGNAL(changed()));
1896 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
1897 this, SIGNAL(changed()));
1898 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
1899 this, SIGNAL(changed()));
1900 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
1901 this, SIGNAL(changed()));
1905 void PrefEdit::apply(LyXRC & rc) const
1907 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1908 rc.sort_layouts = sortEnvironmentsCB->isChecked();
1909 rc.group_layouts = groupEnvironmentsCB->isChecked();
1910 switch (macroEditStyleCO->currentIndex()) {
1911 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
1912 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
1913 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
1915 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
1916 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
1917 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
1918 rc.full_screen_width = fullscreenWidthSB->value();
1919 rc.full_screen_limit = fullscreenLimitGB->isChecked();
1923 void PrefEdit::update(LyXRC const & rc)
1925 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1926 sortEnvironmentsCB->setChecked(rc.sort_layouts);
1927 groupEnvironmentsCB->setChecked(rc.group_layouts);
1928 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
1929 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
1930 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
1931 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
1932 fullscreenWidthSB->setValue(rc.full_screen_width);
1933 fullscreenLimitGB->setChecked(rc.full_screen_limit);
1937 /////////////////////////////////////////////////////////////////////
1941 /////////////////////////////////////////////////////////////////////
1944 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
1946 Ui::shortcutUi::setupUi(this);
1947 QDialog::setModal(true);
1951 PrefShortcuts::PrefShortcuts(GuiPreferences * form, QWidget * parent)
1952 : PrefModule(qt_(catEditing), qt_("Shortcuts"), form, parent)
1956 shortcutsTW->setColumnCount(2);
1957 shortcutsTW->headerItem()->setText(0, qt_("Function"));
1958 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
1959 shortcutsTW->setSortingEnabled(true);
1960 // Multi-selection can be annoying.
1961 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
1963 connect(bindFilePB, SIGNAL(clicked()),
1964 this, SLOT(select_bind()));
1965 connect(bindFileED, SIGNAL(textChanged(QString)),
1966 this, SIGNAL(changed()));
1967 connect(removePB, SIGNAL(clicked()),
1968 this, SIGNAL(changed()));
1970 shortcut_ = new GuiShortcutDialog(this);
1971 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
1972 shortcut_bc_.setOK(shortcut_->okPB);
1973 shortcut_bc_.setCancel(shortcut_->cancelPB);
1975 connect(shortcut_->okPB, SIGNAL(clicked()),
1976 shortcut_, SLOT(accept()));
1977 connect(shortcut_->okPB, SIGNAL(clicked()),
1978 this, SIGNAL(changed()));
1979 connect(shortcut_->cancelPB, SIGNAL(clicked()),
1980 shortcut_, SLOT(reject()));
1981 connect(shortcut_->clearPB, SIGNAL(clicked()),
1982 this, SLOT(shortcut_clearPB_pressed()));
1983 connect(shortcut_->okPB, SIGNAL(clicked()),
1984 this, SLOT(shortcut_okPB_pressed()));
1988 void PrefShortcuts::apply(LyXRC & rc) const
1990 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1991 // write user_bind and user_unbind to .lyx/bind/user.bind
1992 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
1993 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
1994 lyxerr << "LyX could not create the user bind directory '"
1995 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
1998 if (!bind_dir.isDirWritable()) {
1999 lyxerr << "LyX could not write to the user bind directory '"
2000 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2003 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
2004 user_bind_.write(user_bind_file.toFilesystemEncoding(), false, false);
2005 user_unbind_.write(user_bind_file.toFilesystemEncoding(), true, true);
2006 // immediately apply the keybindings. Why this is not done before?
2007 // The good thing is that the menus are updated automatically.
2008 theTopLevelKeymap().clear();
2009 theTopLevelKeymap().read("site");
2010 theTopLevelKeymap().read(rc.bind_file);
2011 theTopLevelKeymap().read("user");
2015 void PrefShortcuts::update(LyXRC const & rc)
2017 bindFileED->setText(toqstr(external_path(rc.bind_file)));
2019 system_bind_.clear();
2021 user_unbind_.clear();
2022 system_bind_.read(rc.bind_file);
2023 // \unbind in user.bind is added to user_unbind_
2024 user_bind_.read("user", &user_unbind_);
2025 updateShortcutsTW();
2029 void PrefShortcuts::updateShortcutsTW()
2031 shortcutsTW->clear();
2033 editItem_ = new QTreeWidgetItem(shortcutsTW);
2034 editItem_->setText(0, qt_("Cursor, Mouse and Editing functions"));
2035 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2037 mathItem_ = new QTreeWidgetItem(shortcutsTW);
2038 mathItem_->setText(0, qt_("Mathematical Symbols"));
2039 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2041 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2042 bufferItem_->setText(0, qt_("Document and Window"));
2043 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2045 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2046 layoutItem_->setText(0, qt_("Font, Layouts and Textclasses"));
2047 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2049 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2050 systemItem_->setText(0, qt_("System and Miscellaneous"));
2051 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2053 // listBindings(unbound=true) lists all bound and unbound lfuns
2054 // Items in this list is tagged by its source.
2055 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2056 static_cast<int>(System));
2057 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2058 static_cast<int>(UserBind));
2059 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2060 static_cast<int>(UserUnbind));
2061 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2062 user_bindinglist.end());
2063 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2064 user_unbindinglist.end());
2066 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2067 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2068 for (; it != it_end; ++it)
2069 insertShortcutItem(it->request, it->sequence, item_type(it->tag));
2071 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2072 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2073 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2074 modifyPB->setEnabled(!items.isEmpty());
2076 shortcutsTW->resizeColumnToContents(0);
2080 void PrefShortcuts::setItemType(QTreeWidgetItem * item, item_type tag)
2082 item->setData(0, Qt::UserRole, QVariant(tag));
2092 font.setStrikeOut(true);
2094 // this item is not displayed now.
2095 case UserExtraUnbind:
2096 font.setStrikeOut(true);
2100 item->setFont(1, font);
2104 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2105 KeySequence const & seq, item_type tag)
2107 FuncCode action = lfun.action;
2108 string const action_name = lyxaction.getActionName(action);
2109 QString const lfun_name = toqstr(from_utf8(action_name)
2110 + ' ' + lfun.argument());
2111 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2112 item_type item_tag = tag;
2114 QTreeWidgetItem * newItem = 0;
2115 // for unbind items, try to find an existing item in the system bind list
2116 if (tag == UserUnbind) {
2117 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2118 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2119 for (int i = 0; i < items.size(); ++i) {
2120 if (items[i]->text(1) == shortcut)
2124 // if not found, this unbind item is UserExtraUnbind
2125 // Such an item is not displayed to avoid confusion (what is
2126 // unmatched removed?).
2128 item_tag = UserExtraUnbind;
2133 switch(lyxaction.getActionType(action)) {
2134 case LyXAction::Hidden:
2136 case LyXAction::Edit:
2137 newItem = new QTreeWidgetItem(editItem_);
2139 case LyXAction::Math:
2140 newItem = new QTreeWidgetItem(mathItem_);
2142 case LyXAction::Buffer:
2143 newItem = new QTreeWidgetItem(bufferItem_);
2145 case LyXAction::Layout:
2146 newItem = new QTreeWidgetItem(layoutItem_);
2148 case LyXAction::System:
2149 newItem = new QTreeWidgetItem(systemItem_);
2152 // this should not happen
2153 newItem = new QTreeWidgetItem(shortcutsTW);
2157 newItem->setText(0, lfun_name);
2158 newItem->setText(1, shortcut);
2159 // record BindFile representation to recover KeySequence when needed.
2160 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2161 setItemType(newItem, item_tag);
2166 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2168 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2169 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2170 modifyPB->setEnabled(!items.isEmpty());
2171 if (items.isEmpty())
2174 item_type tag = static_cast<item_type>(items[0]->data(0, Qt::UserRole).toInt());
2175 if (tag == UserUnbind)
2176 removePB->setText(qt_("Res&tore"));
2178 removePB->setText(qt_("Remo&ve"));
2182 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2188 void PrefShortcuts::modifyShortcut()
2190 QTreeWidgetItem * item = shortcutsTW->currentItem();
2191 if (item->flags() & Qt::ItemIsSelectable) {
2192 shortcut_->lfunLE->setText(item->text(0));
2193 shortcut_->shortcutLE->setText(item->text(1));
2194 shortcut_->shortcutLE->setFocus();
2200 void PrefShortcuts::select_bind()
2202 QString file = form_->browsebind(internalPath(bindFileED->text()));
2203 if (!file.isEmpty()) {
2204 bindFileED->setText(file);
2205 system_bind_ = KeyMap();
2206 system_bind_.read(fromqstr(file));
2207 updateShortcutsTW();
2212 void PrefShortcuts::on_modifyPB_pressed()
2218 void PrefShortcuts::on_newPB_pressed()
2220 shortcut_->lfunLE->clear();
2221 shortcut_->shortcutLE->reset();
2226 void PrefShortcuts::on_removePB_pressed()
2228 // it seems that only one item can be selected, but I am
2229 // removing all selected items anyway.
2230 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2231 for (int i = 0; i < items.size(); ++i) {
2232 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2233 string lfun = fromqstr(items[i]->text(0));
2234 FuncRequest func = lyxaction.lookupFunc(lfun);
2235 item_type tag = static_cast<item_type>(items[i]->data(0, Qt::UserRole).toInt());
2239 // for system bind, we do not touch the item
2240 // but add an user unbind item
2241 user_unbind_.bind(shortcut, func);
2242 setItemType(items[i], UserUnbind);
2243 removePB->setText(qt_("Res&tore"));
2247 // for user_bind, we remove this bind
2248 QTreeWidgetItem * parent = items[i]->parent();
2249 int itemIdx = parent->indexOfChild(items[i]);
2250 parent->takeChild(itemIdx);
2252 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2254 shortcutsTW->scrollToItem(parent);
2255 user_bind_.unbind(shortcut, func);
2259 // for user_unbind, we remove the unbind, and the item
2260 // become System again.
2261 user_unbind_.unbind(shortcut, func);
2262 setItemType(items[i], System);
2263 removePB->setText(qt_("Remo&ve"));
2266 case UserExtraUnbind: {
2267 // for user unbind that is not in system bind file,
2268 // remove this unbind file
2269 QTreeWidgetItem * parent = items[i]->parent();
2270 parent->takeChild(parent->indexOfChild(items[i]));
2271 user_unbind_.unbind(shortcut, func);
2278 void PrefShortcuts::on_searchLE_textEdited()
2280 if (searchLE->text().isEmpty()) {
2281 // show all hidden items
2282 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2284 shortcutsTW->setItemHidden(*it++, false);
2287 // search both columns
2288 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2289 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2290 matched += shortcutsTW->findItems(searchLE->text(),
2291 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2293 // hide everyone (to avoid searching in matched QList repeatedly
2294 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2296 shortcutsTW->setItemHidden(*it++, true);
2297 // show matched items
2298 for (int i = 0; i < matched.size(); ++i) {
2299 shortcutsTW->setItemHidden(matched[i], false);
2300 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2305 void PrefShortcuts::shortcut_okPB_pressed()
2307 string lfun = fromqstr(shortcut_->lfunLE->text());
2308 FuncRequest func = lyxaction.lookupFunc(lfun);
2310 if (func.action == LFUN_UNKNOWN_ACTION) {
2311 Alert::error(_("Failed to create shortcut"),
2312 _("Unknown or invalid LyX function"));
2316 KeySequence k = shortcut_->shortcutLE->getKeySequence();
2317 if (k.length() == 0) {
2318 Alert::error(_("Failed to create shortcut"),
2319 _("Invalid or empty key sequence"));
2323 // if both lfun and shortcut is valid
2324 if (user_bind_.hasBinding(k, func) || system_bind_.hasBinding(k, func)) {
2325 Alert::error(_("Failed to create shortcut"),
2326 _("Shortcut is already defined"));
2330 QTreeWidgetItem * item = insertShortcutItem(func, k, UserBind);
2332 user_bind_.bind(&k, func);
2333 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2334 shortcutsTW->setItemExpanded(item->parent(), true);
2335 shortcutsTW->scrollToItem(item);
2337 Alert::error(_("Failed to create shortcut"),
2338 _("Can not insert shortcut to the list"));
2344 void PrefShortcuts::shortcut_clearPB_pressed()
2346 shortcut_->shortcutLE->reset();
2347 shortcut_->shortcutLE->setFocus();
2351 /////////////////////////////////////////////////////////////////////
2355 /////////////////////////////////////////////////////////////////////
2357 PrefIdentity::PrefIdentity(QWidget * parent)
2358 : PrefModule(QString(), qt_("Identity"), 0, parent)
2362 connect(nameED, SIGNAL(textChanged(QString)),
2363 this, SIGNAL(changed()));
2364 connect(emailED, SIGNAL(textChanged(QString)),
2365 this, SIGNAL(changed()));
2369 void PrefIdentity::apply(LyXRC & rc) const
2371 rc.user_name = fromqstr(nameED->text());
2372 rc.user_email = fromqstr(emailED->text());
2376 void PrefIdentity::update(LyXRC const & rc)
2378 nameED->setText(toqstr(rc.user_name));
2379 emailED->setText(toqstr(rc.user_email));
2384 /////////////////////////////////////////////////////////////////////
2388 /////////////////////////////////////////////////////////////////////
2390 GuiPreferences::GuiPreferences(GuiView & lv)
2391 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2395 QDialog::setModal(false);
2397 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2398 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2399 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2400 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2402 add(new PrefUserInterface(this));
2403 add(new PrefEdit(this));
2404 add(new PrefShortcuts(this));
2405 add(new PrefScreenFonts(this));
2406 add(new PrefColors(this));
2407 add(new PrefDisplay);
2408 add(new PrefInput(this));
2409 add(new PrefCompletion(this));
2411 add(new PrefPaths(this));
2413 add(new PrefIdentity);
2415 add(new PrefLanguage);
2416 add(new PrefSpellchecker(this));
2418 add(new PrefPrinter);
2420 add(new PrefPlaintext);
2421 add(new PrefLatex(this));
2423 PrefConverters * converters = new PrefConverters(this);
2424 PrefFileformats * formats = new PrefFileformats(this);
2425 connect(formats, SIGNAL(formatsChanged()),
2426 converters, SLOT(updateGui()));
2430 prefsPS->setCurrentPanel(qt_("User interface"));
2431 // FIXME: hack to work around resizing bug in Qt >= 4.2
2432 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2433 #if QT_VERSION >= 0x040200
2434 prefsPS->updateGeometry();
2437 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2439 bc().setApply(applyPB);
2440 bc().setCancel(closePB);
2441 bc().setRestore(restorePB);
2445 void GuiPreferences::add(PrefModule * module)
2447 LASSERT(module, /**/);
2448 if (module->category().isEmpty())
2449 prefsPS->addPanel(module, module->title());
2451 prefsPS->addPanel(module, module->title(), module->category());
2452 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2453 modules_.push_back(module);
2457 void GuiPreferences::change_adaptor()
2463 void GuiPreferences::apply(LyXRC & rc) const
2465 size_t end = modules_.size();
2466 for (size_t i = 0; i != end; ++i)
2467 modules_[i]->apply(rc);
2471 void GuiPreferences::updateRc(LyXRC const & rc)
2473 size_t const end = modules_.size();
2474 for (size_t i = 0; i != end; ++i)
2475 modules_[i]->update(rc);
2479 void GuiPreferences::applyView()
2485 void GuiPreferences::updateContents()
2491 bool GuiPreferences::initialiseParams(string const &)
2494 formats_ = lyx::formats;
2495 converters_ = theConverters();
2496 converters_.update(formats_);
2497 movers_ = theMovers();
2499 update_screen_font_ = false;
2505 void GuiPreferences::dispatchParams()
2508 rc_.write(ss, true);
2509 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
2510 // FIXME: these need lfuns
2512 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
2514 lyx::formats = formats_;
2516 theConverters() = converters_;
2517 theConverters().update(lyx::formats);
2518 theConverters().buildGraph();
2520 theMovers() = movers_;
2522 vector<string>::const_iterator it = colors_.begin();
2523 vector<string>::const_iterator const end = colors_.end();
2524 for (; it != end; ++it)
2525 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
2528 if (update_screen_font_) {
2529 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2530 update_screen_font_ = false;
2533 // The Save button has been pressed
2535 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
2539 void GuiPreferences::setColor(ColorCode col, string const & hex)
2541 colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
2545 void GuiPreferences::updateScreenFonts()
2547 update_screen_font_ = true;
2551 QString GuiPreferences::browsebind(QString const & file) const
2553 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
2554 QStringList(qt_("LyX bind files (*.bind)")));
2558 QString GuiPreferences::browseUI(QString const & file) const
2560 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
2561 QStringList(qt_("LyX UI files (*.ui)")));
2565 QString GuiPreferences::browsekbmap(QString const & file) const
2567 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
2568 QStringList(qt_("LyX keyboard maps (*.kmap)")));
2572 QString GuiPreferences::browsedict(QString const & file) const
2574 return browseFile(file, qt_("Choose personal dictionary"),
2575 QStringList(lyxrc.use_spell_lib ? qt_("*.pws") : qt_("*.ispell")));
2579 QString GuiPreferences::browse(QString const & file,
2580 QString const & title) const
2582 return browseFile(file, title, QStringList(), true);
2586 // We support less paper sizes than the document dialog
2587 // Therefore this adjustment is needed.
2588 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
2592 return PAPER_DEFAULT;
2594 return PAPER_USLETTER;
2596 return PAPER_USLEGAL;
2598 return PAPER_USEXECUTIVE;
2608 // should not happen
2609 return PAPER_DEFAULT;
2614 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
2616 switch (papersize) {
2619 case PAPER_USLETTER:
2623 case PAPER_USEXECUTIVE:
2634 // should not happen
2640 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
2643 } // namespace frontend
2646 #include "GuiPrefs_moc.cpp"