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/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 support::FileFilterList 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 support::FileFilterList 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
184 QString browseRelFile(QString const & filename, QString const & refpath,
185 QString const & title, FileFilterList const & filters, bool save,
186 QString const & label1, QString const & dir1,
187 QString const & label2, QString const & dir2)
189 QString const fname = toqstr(makeAbsPath(
190 fromqstr(filename), fromqstr(refpath)).absFilename());
192 QString const outname =
193 frontend::browseFile(fname, title, filters, save, label1, dir1, label2, dir2);
195 QString const reloutname =
196 toqstr(makeRelPath(qstring_to_ucs4(outname), qstring_to_ucs4(refpath)));
198 if (reloutname.startsWith("../"))
205 /////////////////////////////////////////////////////////////////////
209 /////////////////////////////////////////////////////////////////////
213 string const catLookAndFeel = N_("Look & Feel");
214 string const catEditing = N_("Editing");
215 string const catLanguage = N_("Language Settings");
216 string const catOutput = N_("Output");
217 string const catFiles = N_("File Handling");
219 static int findPos_helper(QStringList const & vec, QString const & val)
221 for (int i = 0; i != vec.size(); ++i)
228 static void parseFontName(QString const & mangled0,
229 string & name, string & foundry)
231 string mangled = fromqstr(mangled0);
232 size_t const idx = mangled.find('[');
233 if (idx == string::npos || idx == 0) {
237 name = mangled.substr(0, idx - 1),
238 foundry = mangled.substr(idx + 1, mangled.size() - idx - 2);
243 static void setComboxFont(QComboBox * cb, string const & family,
244 string const & foundry)
246 QString fontname = toqstr(family);
247 if (!foundry.empty())
248 fontname += " [" + toqstr(foundry) + ']';
250 for (int i = 0; i != cb->count(); ++i) {
251 if (cb->itemText(i) == fontname) {
252 cb->setCurrentIndex(i);
257 // Try matching without foundry name
259 // We count in reverse in order to prefer the Xft foundry
260 for (int i = cb->count(); --i >= 0;) {
261 string name, foundry;
262 parseFontName(cb->itemText(i), name, foundry);
263 if (compare_ascii_no_case(name, family) == 0) {
264 cb->setCurrentIndex(i);
269 // family alone can contain e.g. "Helvetica [Adobe]"
270 string tmpname, tmpfoundry;
271 parseFontName(toqstr(family), tmpname, tmpfoundry);
273 // We count in reverse in order to prefer the Xft foundry
274 for (int i = cb->count(); --i >= 0; ) {
275 string name, foundry;
276 parseFontName(cb->itemText(i), name, foundry);
277 if (compare_ascii_no_case(name, foundry) == 0) {
278 cb->setCurrentIndex(i);
283 // Bleh, default fonts, and the names couldn't be found. Hack
287 font.setKerning(false);
289 QString const font_family = toqstr(family);
290 if (font_family == guiApp->romanFontName()) {
291 font.setStyleHint(QFont::Serif);
292 font.setFamily(font_family);
293 } else if (font_family == guiApp->sansFontName()) {
294 font.setStyleHint(QFont::SansSerif);
295 font.setFamily(font_family);
296 } else if (font_family == guiApp->typewriterFontName()) {
297 font.setStyleHint(QFont::TypeWriter);
298 font.setFamily(font_family);
300 lyxerr << "FAILED to find the default font: '"
301 << foundry << "', '" << family << '\''<< endl;
305 QFontInfo info(font);
306 string default_font_name, dummyfoundry;
307 parseFontName(info.family(), default_font_name, dummyfoundry);
308 lyxerr << "Apparent font is " << default_font_name << endl;
310 for (int i = 0; i < cb->count(); ++i) {
311 lyxerr << "Looking at " << fromqstr(cb->itemText(i)) << endl;
312 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
313 default_font_name) == 0) {
314 cb->setCurrentIndex(i);
319 lyxerr << "FAILED to find the font: '"
320 << foundry << "', '" << family << '\'' <<endl;
324 /////////////////////////////////////////////////////////////////////
328 /////////////////////////////////////////////////////////////////////
330 PrefPlaintext::PrefPlaintext(QWidget * parent)
331 : PrefModule(qt_(catOutput), qt_("Plain text"), 0, parent)
334 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
335 this, SIGNAL(changed()));
336 connect(plaintextRoffED, SIGNAL(textChanged(QString)),
337 this, SIGNAL(changed()));
341 void PrefPlaintext::apply(LyXRC & rc) const
343 rc.plaintext_linelen = plaintextLinelengthSB->value();
344 rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
348 void PrefPlaintext::update(LyXRC const & rc)
350 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
351 plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
355 /////////////////////////////////////////////////////////////////////
359 /////////////////////////////////////////////////////////////////////
361 PrefDate::PrefDate(QWidget * parent)
362 : PrefModule(qt_(catOutput), qt_("Date format"), 0, parent)
365 connect(DateED, SIGNAL(textChanged(QString)),
366 this, SIGNAL(changed()));
370 void PrefDate::apply(LyXRC & rc) const
372 rc.date_insert_format = fromqstr(DateED->text());
376 void PrefDate::update(LyXRC const & rc)
378 DateED->setText(toqstr(rc.date_insert_format));
382 /////////////////////////////////////////////////////////////////////
386 /////////////////////////////////////////////////////////////////////
388 PrefInput::PrefInput(GuiPreferences * form, QWidget * parent)
389 : PrefModule(qt_(catEditing), qt_("Keyboard/Mouse"), form, parent)
393 connect(keymapCB, SIGNAL(clicked()),
394 this, SIGNAL(changed()));
395 connect(firstKeymapED, SIGNAL(textChanged(QString)),
396 this, SIGNAL(changed()));
397 connect(secondKeymapED, SIGNAL(textChanged(QString)),
398 this, SIGNAL(changed()));
399 connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
400 this, SIGNAL(changed()));
404 void PrefInput::apply(LyXRC & rc) const
406 // FIXME: can derive CB from the two EDs
407 rc.use_kbmap = keymapCB->isChecked();
408 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
409 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
410 rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
414 void PrefInput::update(LyXRC const & rc)
416 // FIXME: can derive CB from the two EDs
417 keymapCB->setChecked(rc.use_kbmap);
418 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
419 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
420 mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
424 QString PrefInput::testKeymap(QString keymap)
426 return form_->browsekbmap(toqstr(internal_path(fromqstr(keymap))));
430 void PrefInput::on_firstKeymapPB_clicked(bool)
432 QString const file = testKeymap(firstKeymapED->text());
434 firstKeymapED->setText(file);
438 void PrefInput::on_secondKeymapPB_clicked(bool)
440 QString const file = testKeymap(secondKeymapED->text());
442 secondKeymapED->setText(file);
446 void PrefInput::on_keymapCB_toggled(bool keymap)
448 firstKeymapLA->setEnabled(keymap);
449 secondKeymapLA->setEnabled(keymap);
450 firstKeymapED->setEnabled(keymap);
451 secondKeymapED->setEnabled(keymap);
452 firstKeymapPB->setEnabled(keymap);
453 secondKeymapPB->setEnabled(keymap);
457 /////////////////////////////////////////////////////////////////////
461 /////////////////////////////////////////////////////////////////////
463 PrefCompletion::PrefCompletion(GuiPreferences * form, QWidget * parent)
464 : PrefModule(qt_(catEditing), qt_("Input Completion"), form, parent)
468 connect(inlineDelaySB, SIGNAL(valueChanged(double)),
469 this, SIGNAL(changed()));
470 connect(inlineMathCB, SIGNAL(clicked()),
471 this, SIGNAL(changed()));
472 connect(inlineTextCB, SIGNAL(clicked()),
473 this, SIGNAL(changed()));
474 connect(inlineDotsCB, SIGNAL(clicked()),
475 this, SIGNAL(changed()));
476 connect(popupDelaySB, SIGNAL(valueChanged(double)),
477 this, SIGNAL(changed()));
478 connect(popupMathCB, SIGNAL(clicked()),
479 this, SIGNAL(changed()));
480 connect(popupTextCB, SIGNAL(clicked()),
481 this, SIGNAL(changed()));
482 connect(popupAfterCompleteCB, SIGNAL(clicked()),
483 this, SIGNAL(changed()));
484 connect(cursorTextCB, SIGNAL(clicked()),
485 this, SIGNAL(changed()));
489 void PrefCompletion::apply(LyXRC & rc) const
491 rc.completion_inline_delay = inlineDelaySB->value();
492 rc.completion_inline_math = inlineMathCB->isChecked();
493 rc.completion_inline_text = inlineTextCB->isChecked();
494 rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
495 rc.completion_popup_delay = popupDelaySB->value();
496 rc.completion_popup_math = popupMathCB->isChecked();
497 rc.completion_popup_text = popupTextCB->isChecked();
498 rc.completion_cursor_text = cursorTextCB->isChecked();
499 rc.completion_popup_after_complete =
500 popupAfterCompleteCB->isChecked();
504 void PrefCompletion::update(LyXRC const & rc)
506 inlineDelaySB->setValue(rc.completion_inline_delay);
507 inlineMathCB->setChecked(rc.completion_inline_math);
508 inlineTextCB->setChecked(rc.completion_inline_text);
509 inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
510 popupDelaySB->setValue(rc.completion_popup_delay);
511 popupMathCB->setChecked(rc.completion_popup_math);
512 popupTextCB->setChecked(rc.completion_popup_text);
513 cursorTextCB->setChecked(rc.completion_cursor_text);
514 popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
519 /////////////////////////////////////////////////////////////////////
523 /////////////////////////////////////////////////////////////////////
525 PrefLatex::PrefLatex(GuiPreferences * form, QWidget * parent)
526 : PrefModule(qt_(catOutput), qt_("LaTeX"), form, parent)
529 connect(latexEncodingED, SIGNAL(textChanged(QString)),
530 this, SIGNAL(changed()));
531 connect(latexChecktexED, SIGNAL(textChanged(QString)),
532 this, SIGNAL(changed()));
533 connect(latexBibtexED, SIGNAL(textChanged(QString)),
534 this, SIGNAL(changed()));
535 connect(latexIndexED, SIGNAL(textChanged(QString)),
536 this, SIGNAL(changed()));
537 connect(latexAutoresetCB, SIGNAL(clicked()),
538 this, SIGNAL(changed()));
539 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
540 this, SIGNAL(changed()));
541 connect(latexPaperSizeCO, SIGNAL(activated(int)),
542 this, SIGNAL(changed()));
544 #if defined(__CYGWIN__) || defined(_WIN32)
545 pathCB->setVisible(true);
546 connect(pathCB, SIGNAL(clicked()),
547 this, SIGNAL(changed()));
549 pathCB->setVisible(false);
554 void PrefLatex::apply(LyXRC & rc) const
556 rc.fontenc = fromqstr(latexEncodingED->text());
557 rc.chktex_command = fromqstr(latexChecktexED->text());
558 rc.bibtex_command = fromqstr(latexBibtexED->text());
559 rc.index_command = fromqstr(latexIndexED->text());
560 rc.auto_reset_options = latexAutoresetCB->isChecked();
561 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
562 rc.default_papersize =
563 form_->toPaperSize(latexPaperSizeCO->currentIndex());
564 #if defined(__CYGWIN__) || defined(_WIN32)
565 rc.windows_style_tex_paths = pathCB->isChecked();
570 void PrefLatex::update(LyXRC const & rc)
572 latexEncodingED->setText(toqstr(rc.fontenc));
573 latexChecktexED->setText(toqstr(rc.chktex_command));
574 latexBibtexED->setText(toqstr(rc.bibtex_command));
575 latexIndexED->setText(toqstr(rc.index_command));
576 latexAutoresetCB->setChecked(rc.auto_reset_options);
577 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
578 latexPaperSizeCO->setCurrentIndex(
579 form_->fromPaperSize(rc.default_papersize));
580 #if defined(__CYGWIN__) || defined(_WIN32)
581 pathCB->setChecked(rc.windows_style_tex_paths);
586 /////////////////////////////////////////////////////////////////////
590 /////////////////////////////////////////////////////////////////////
592 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form, QWidget * parent)
593 : PrefModule(qt_(catLookAndFeel), qt_("Screen fonts"), form, parent)
597 connect(screenRomanCO, SIGNAL(activated(QString)),
598 this, SLOT(select_roman(QString)));
599 connect(screenSansCO, SIGNAL(activated(QString)),
600 this, SLOT(select_sans(QString)));
601 connect(screenTypewriterCO, SIGNAL(activated(QString)),
602 this, SLOT(select_typewriter(QString)));
604 QFontDatabase fontdb;
605 QStringList families(fontdb.families());
606 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
607 screenRomanCO->addItem(*it);
608 screenSansCO->addItem(*it);
609 screenTypewriterCO->addItem(*it);
611 connect(screenRomanCO, SIGNAL(activated(QString)),
612 this, SIGNAL(changed()));
613 connect(screenSansCO, SIGNAL(activated(QString)),
614 this, SIGNAL(changed()));
615 connect(screenTypewriterCO, SIGNAL(activated(QString)),
616 this, SIGNAL(changed()));
617 connect(screenZoomSB, SIGNAL(valueChanged(int)),
618 this, SIGNAL(changed()));
619 connect(screenDpiSB, SIGNAL(valueChanged(int)),
620 this, SIGNAL(changed()));
621 connect(screenTinyED, SIGNAL(textChanged(QString)),
622 this, SIGNAL(changed()));
623 connect(screenSmallestED, SIGNAL(textChanged(QString)),
624 this, SIGNAL(changed()));
625 connect(screenSmallerED, SIGNAL(textChanged(QString)),
626 this, SIGNAL(changed()));
627 connect(screenSmallED, SIGNAL(textChanged(QString)),
628 this, SIGNAL(changed()));
629 connect(screenNormalED, SIGNAL(textChanged(QString)),
630 this, SIGNAL(changed()));
631 connect(screenLargeED, SIGNAL(textChanged(QString)),
632 this, SIGNAL(changed()));
633 connect(screenLargerED, SIGNAL(textChanged(QString)),
634 this, SIGNAL(changed()));
635 connect(screenLargestED, SIGNAL(textChanged(QString)),
636 this, SIGNAL(changed()));
637 connect(screenHugeED, SIGNAL(textChanged(QString)),
638 this, SIGNAL(changed()));
639 connect(screenHugerED, SIGNAL(textChanged(QString)),
640 this, SIGNAL(changed()));
641 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
642 this, SIGNAL(changed()));
644 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
645 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
646 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
647 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
648 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
649 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
650 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
651 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
652 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
653 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
657 void PrefScreenFonts::apply(LyXRC & rc) const
659 LyXRC const oldrc = rc;
661 parseFontName(screenRomanCO->currentText(),
662 rc.roman_font_name, rc.roman_font_foundry);
663 parseFontName(screenSansCO->currentText(),
664 rc.sans_font_name, rc.sans_font_foundry);
665 parseFontName(screenTypewriterCO->currentText(),
666 rc.typewriter_font_name, rc.typewriter_font_foundry);
668 rc.zoom = screenZoomSB->value();
669 rc.dpi = screenDpiSB->value();
670 rc.font_sizes[FONT_SIZE_TINY] = fromqstr(screenTinyED->text());
671 rc.font_sizes[FONT_SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
672 rc.font_sizes[FONT_SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
673 rc.font_sizes[FONT_SIZE_SMALL] = fromqstr(screenSmallED->text());
674 rc.font_sizes[FONT_SIZE_NORMAL] = fromqstr(screenNormalED->text());
675 rc.font_sizes[FONT_SIZE_LARGE] = fromqstr(screenLargeED->text());
676 rc.font_sizes[FONT_SIZE_LARGER] = fromqstr(screenLargerED->text());
677 rc.font_sizes[FONT_SIZE_LARGEST] = fromqstr(screenLargestED->text());
678 rc.font_sizes[FONT_SIZE_HUGE] = fromqstr(screenHugeED->text());
679 rc.font_sizes[FONT_SIZE_HUGER] = fromqstr(screenHugerED->text());
680 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
682 if (rc.font_sizes != oldrc.font_sizes
683 || rc.roman_font_name != oldrc.roman_font_name
684 || rc.sans_font_name != oldrc.sans_font_name
685 || rc.typewriter_font_name != oldrc.typewriter_font_name
686 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
687 // The global QPixmapCache is used in GuiPainter to cache text
688 // painting so we must reset it in case any of the above
689 // parameter is changed.
690 QPixmapCache::clear();
691 guiApp->fontLoader().update();
692 form_->updateScreenFonts();
697 void PrefScreenFonts::update(LyXRC const & rc)
699 setComboxFont(screenRomanCO, rc.roman_font_name,
700 rc.roman_font_foundry);
701 setComboxFont(screenSansCO, rc.sans_font_name,
702 rc.sans_font_foundry);
703 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
704 rc.typewriter_font_foundry);
706 select_roman(screenRomanCO->currentText());
707 select_sans(screenSansCO->currentText());
708 select_typewriter(screenTypewriterCO->currentText());
710 screenZoomSB->setValue(rc.zoom);
711 screenDpiSB->setValue(rc.dpi);
712 screenTinyED->setText(toqstr(rc.font_sizes[FONT_SIZE_TINY]));
713 screenSmallestED->setText(toqstr(rc.font_sizes[FONT_SIZE_SCRIPT]));
714 screenSmallerED->setText(toqstr(rc.font_sizes[FONT_SIZE_FOOTNOTE]));
715 screenSmallED->setText(toqstr(rc.font_sizes[FONT_SIZE_SMALL]));
716 screenNormalED->setText(toqstr(rc.font_sizes[FONT_SIZE_NORMAL]));
717 screenLargeED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGE]));
718 screenLargerED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGER]));
719 screenLargestED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGEST]));
720 screenHugeED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGE]));
721 screenHugerED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGER]));
723 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
724 #if defined(Q_WS_X11)
725 pixmapCacheCB->setEnabled(false);
731 void PrefScreenFonts::select_roman(const QString & name)
733 screenRomanFE->set(QFont(name), name);
737 void PrefScreenFonts::select_sans(const QString & name)
739 screenSansFE->set(QFont(name), name);
743 void PrefScreenFonts::select_typewriter(const QString & name)
745 screenTypewriterFE->set(QFont(name), name);
749 /////////////////////////////////////////////////////////////////////
753 /////////////////////////////////////////////////////////////////////
759 bool operator()(ColorCode lhs, ColorCode rhs) const {
760 return lcolor.getGUIName(lhs) < lcolor.getGUIName(rhs);
766 PrefColors::PrefColors(GuiPreferences * form, QWidget * parent)
767 : PrefModule(qt_(catLookAndFeel), qt_("Colors"), form, parent)
771 // FIXME: all of this initialization should be put into the controller.
772 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
773 // for some discussion of why that is not trivial.
774 QPixmap icon(32, 32);
775 for (int i = 0; i < Color_ignore; ++i) {
776 ColorCode lc = static_cast<ColorCode>(i);
784 || lc == Color_magenta
785 || lc == Color_yellow
786 || lc == Color_inherit
787 || lc == Color_ignore) continue;
789 lcolors_.push_back(lc);
791 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
792 vector<ColorCode>::const_iterator cit = lcolors_.begin();
793 vector<ColorCode>::const_iterator const end = lcolors_.end();
794 for (; cit != end; ++cit) {
795 (void) new QListWidgetItem(QIcon(icon),
796 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
798 curcolors_.resize(lcolors_.size());
799 newcolors_.resize(lcolors_.size());
800 // End initialization
802 connect(colorChangePB, SIGNAL(clicked()),
803 this, SLOT(change_color()));
804 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
805 this, SLOT(change_lyxObjects_selection()));
806 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
807 this, SLOT(change_color()));
811 void PrefColors::apply(LyXRC & /*rc*/) const
813 for (unsigned int i = 0; i < lcolors_.size(); ++i)
814 if (curcolors_[i] != newcolors_[i])
815 form_->setColor(lcolors_[i], fromqstr(newcolors_[i]));
819 void PrefColors::update(LyXRC const & /*rc*/)
821 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
822 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
823 QPixmap coloritem(32, 32);
824 coloritem.fill(color);
825 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
826 newcolors_[i] = curcolors_[i] = color.name();
828 change_lyxObjects_selection();
832 void PrefColors::change_color()
834 int const row = lyxObjectsLW->currentRow();
840 QString const color = newcolors_[row];
841 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
843 if (c.isValid() && c.name() != color) {
844 newcolors_[row] = c.name();
845 QPixmap coloritem(32, 32);
847 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
853 void PrefColors::change_lyxObjects_selection()
855 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
859 /////////////////////////////////////////////////////////////////////
863 /////////////////////////////////////////////////////////////////////
865 PrefDisplay::PrefDisplay(QWidget * parent)
866 : PrefModule(qt_(catLookAndFeel), qt_("Graphics"), 0, parent)
869 connect(instantPreviewCO, SIGNAL(activated(int)),
870 this, SIGNAL(changed()));
871 connect(displayGraphicsCO, SIGNAL(activated(int)),
872 this, SIGNAL(changed()));
876 void PrefDisplay::apply(LyXRC & rc) const
878 switch (instantPreviewCO->currentIndex()) {
879 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
880 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
881 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
884 graphics::DisplayType dtype;
885 switch (displayGraphicsCO->currentIndex()) {
886 case 3: dtype = graphics::NoDisplay; break;
887 case 2: dtype = graphics::ColorDisplay; break;
888 case 1: dtype = graphics::GrayscaleDisplay; break;
889 case 0: dtype = graphics::MonochromeDisplay; break;
890 default: dtype = graphics::GrayscaleDisplay;
892 rc.display_graphics = dtype;
894 // FIXME!! The graphics cache no longer has a changeDisplay method.
896 if (old_value != rc.display_graphics) {
897 graphics::GCache & gc = graphics::GCache::get();
904 void PrefDisplay::update(LyXRC const & rc)
906 switch (rc.preview) {
907 case LyXRC::PREVIEW_OFF:
908 instantPreviewCO->setCurrentIndex(0);
910 case LyXRC::PREVIEW_NO_MATH :
911 instantPreviewCO->setCurrentIndex(1);
913 case LyXRC::PREVIEW_ON :
914 instantPreviewCO->setCurrentIndex(2);
919 switch (rc.display_graphics) {
920 case graphics::NoDisplay: item = 3; break;
921 case graphics::ColorDisplay: item = 2; break;
922 case graphics::GrayscaleDisplay: item = 1; break;
923 case graphics::MonochromeDisplay: item = 0; break;
926 displayGraphicsCO->setCurrentIndex(item);
930 /////////////////////////////////////////////////////////////////////
934 /////////////////////////////////////////////////////////////////////
936 PrefPaths::PrefPaths(GuiPreferences * form, QWidget * parent)
937 : PrefModule(QString(), qt_("Paths"), form, parent)
940 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(select_exampledir()));
941 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
942 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
943 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
944 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
945 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
946 connect(workingDirED, SIGNAL(textChanged(QString)),
947 this, SIGNAL(changed()));
948 connect(exampleDirED, SIGNAL(textChanged(QString)),
949 this, SIGNAL(changed()));
950 connect(templateDirED, SIGNAL(textChanged(QString)),
951 this, SIGNAL(changed()));
952 connect(backupDirED, SIGNAL(textChanged(QString)),
953 this, SIGNAL(changed()));
954 connect(tempDirED, SIGNAL(textChanged(QString)),
955 this, SIGNAL(changed()));
956 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
957 this, SIGNAL(changed()));
958 connect(pathPrefixED, SIGNAL(textChanged(QString)),
959 this, SIGNAL(changed()));
963 void PrefPaths::apply(LyXRC & rc) const
965 rc.document_path = internal_path(fromqstr(workingDirED->text()));
966 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
967 rc.template_path = internal_path(fromqstr(templateDirED->text()));
968 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
969 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
970 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
971 // FIXME: should be a checkbox only
972 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
976 void PrefPaths::update(LyXRC const & rc)
978 workingDirED->setText(toqstr(external_path(rc.document_path)));
979 exampleDirED->setText(toqstr(external_path(rc.example_path)));
980 templateDirED->setText(toqstr(external_path(rc.template_path)));
981 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
982 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
983 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
984 // FIXME: should be a checkbox only
985 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
989 void PrefPaths::select_exampledir()
991 QString file = form_->browsedir(internalPath(exampleDirED->text()),
992 qt_("Select directory for example files"));
994 exampleDirED->setText(file);
998 void PrefPaths::select_templatedir()
1000 QString file = form_->browsedir(internalPath(templateDirED->text()),
1001 qt_("Select a document templates directory"));
1002 if (!file.isEmpty())
1003 templateDirED->setText(file);
1007 void PrefPaths::select_tempdir()
1009 QString file = form_->browsedir(internalPath(tempDirED->text()),
1010 qt_("Select a temporary directory"));
1011 if (!file.isEmpty())
1012 tempDirED->setText(file);
1016 void PrefPaths::select_backupdir()
1018 QString file = form_->browsedir(internalPath(backupDirED->text()),
1019 qt_("Select a backups directory"));
1020 if (!file.isEmpty())
1021 backupDirED->setText(file);
1025 void PrefPaths::select_workingdir()
1027 QString file = form_->browsedir(internalPath(workingDirED->text()),
1028 qt_("Select a document directory"));
1029 if (!file.isEmpty())
1030 workingDirED->setText(file);
1034 void PrefPaths::select_lyxpipe()
1036 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1037 qt_("Give a filename for the LyX server pipe"));
1038 if (!file.isEmpty())
1039 lyxserverDirED->setText(file);
1043 /////////////////////////////////////////////////////////////////////
1047 /////////////////////////////////////////////////////////////////////
1049 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form, QWidget * parent)
1050 : PrefModule(qt_(catLanguage), qt_("Spellchecker"), form, parent)
1054 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
1055 #if defined (USE_ISPELL)
1056 connect(spellCommandCO, SIGNAL(activated(int)),
1057 this, SIGNAL(changed()));
1059 spellCommandCO->setEnabled(false);
1061 connect(altLanguageED, SIGNAL(textChanged(QString)),
1062 this, SIGNAL(changed()));
1063 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1064 this, SIGNAL(changed()));
1065 connect(persDictionaryED, SIGNAL(textChanged(QString)),
1066 this, SIGNAL(changed()));
1067 connect(compoundWordCB, SIGNAL(clicked()),
1068 this, SIGNAL(changed()));
1069 connect(inputEncodingCB, SIGNAL(clicked()),
1070 this, SIGNAL(changed()));
1072 spellCommandCO->addItem(qt_("ispell"));
1073 spellCommandCO->addItem(qt_("aspell"));
1074 spellCommandCO->addItem(qt_("hspell"));
1076 spellCommandCO->addItem(qt_("pspell (library)"));
1079 spellCommandCO->addItem(qt_("aspell (library)"));
1085 void PrefSpellchecker::apply(LyXRC & rc) const
1087 switch (spellCommandCO->currentIndex()) {
1091 rc.use_spell_lib = false;
1092 rc.isp_command = fromqstr(spellCommandCO->currentText());
1095 rc.use_spell_lib = true;
1099 // FIXME: remove isp_use_alt_lang
1100 rc.isp_alt_lang = fromqstr(altLanguageED->text());
1101 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
1102 // FIXME: remove isp_use_esc_chars
1103 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
1104 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
1105 // FIXME: remove isp_use_pers_dict
1106 rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
1107 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
1108 rc.isp_accept_compound = compoundWordCB->isChecked();
1109 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
1113 void PrefSpellchecker::update(LyXRC const & rc)
1115 spellCommandCO->setCurrentIndex(0);
1117 if (rc.isp_command == "ispell") {
1118 spellCommandCO->setCurrentIndex(0);
1119 } else if (rc.isp_command == "aspell") {
1120 spellCommandCO->setCurrentIndex(1);
1121 } else if (rc.isp_command == "hspell") {
1122 spellCommandCO->setCurrentIndex(2);
1125 if (rc.use_spell_lib) {
1126 #if defined(USE_ASPELL) || defined(USE_PSPELL)
1127 spellCommandCO->setCurrentIndex(3);
1131 // FIXME: remove isp_use_alt_lang
1132 altLanguageED->setText(toqstr(rc.isp_alt_lang));
1133 // FIXME: remove isp_use_esc_chars
1134 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
1135 // FIXME: remove isp_use_pers_dict
1136 persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
1137 compoundWordCB->setChecked(rc.isp_accept_compound);
1138 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
1142 void PrefSpellchecker::select_dict()
1144 QString file = form_->browsedict(internalPath(persDictionaryED->text()));
1145 if (!file.isEmpty())
1146 persDictionaryED->setText(file);
1151 /////////////////////////////////////////////////////////////////////
1155 /////////////////////////////////////////////////////////////////////
1158 PrefConverters::PrefConverters(GuiPreferences * form, QWidget * parent)
1159 : PrefModule(qt_(catFiles), qt_("Converters"), form, parent)
1163 connect(converterNewPB, SIGNAL(clicked()),
1164 this, SLOT(update_converter()));
1165 connect(converterRemovePB, SIGNAL(clicked()),
1166 this, SLOT(remove_converter()));
1167 connect(converterModifyPB, SIGNAL(clicked()),
1168 this, SLOT(update_converter()));
1169 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1170 this, SLOT(switch_converter()));
1171 connect(converterFromCO, SIGNAL(activated(QString)),
1172 this, SLOT(converter_changed()));
1173 connect(converterToCO, SIGNAL(activated(QString)),
1174 this, SLOT(converter_changed()));
1175 connect(converterED, SIGNAL(textEdited(QString)),
1176 this, SLOT(converter_changed()));
1177 connect(converterFlagED, SIGNAL(textEdited(QString)),
1178 this, SLOT(converter_changed()));
1179 connect(converterNewPB, SIGNAL(clicked()),
1180 this, SIGNAL(changed()));
1181 connect(converterRemovePB, SIGNAL(clicked()),
1182 this, SIGNAL(changed()));
1183 connect(converterModifyPB, SIGNAL(clicked()),
1184 this, SIGNAL(changed()));
1185 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1186 this, SIGNAL(changed()));
1188 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1189 //converterDefGB->setFocusProxy(convertersLW);
1193 void PrefConverters::apply(LyXRC & rc) const
1195 rc.use_converter_cache = cacheCB->isChecked();
1196 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
1200 void PrefConverters::update(LyXRC const & rc)
1202 cacheCB->setChecked(rc.use_converter_cache);
1204 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
1205 maxAgeLE->setText(max_age);
1210 void PrefConverters::updateGui()
1212 form_->formats().sort();
1213 form_->converters().update(form_->formats());
1214 // save current selection
1215 QString current = converterFromCO->currentText()
1216 + " -> " + converterToCO->currentText();
1218 converterFromCO->clear();
1219 converterToCO->clear();
1221 Formats::const_iterator cit = form_->formats().begin();
1222 Formats::const_iterator end = form_->formats().end();
1223 for (; cit != end; ++cit) {
1224 converterFromCO->addItem(toqstr(cit->prettyname()));
1225 converterToCO->addItem(toqstr(cit->prettyname()));
1228 // currentRowChanged(int) is also triggered when updating the listwidget
1229 // block signals to avoid unnecessary calls to switch_converter()
1230 convertersLW->blockSignals(true);
1231 convertersLW->clear();
1233 Converters::const_iterator ccit = form_->converters().begin();
1234 Converters::const_iterator cend = form_->converters().end();
1235 for (; ccit != cend; ++ccit) {
1237 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
1238 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1239 new QListWidgetItem(toqstr(name), convertersLW, type);
1241 convertersLW->sortItems(Qt::AscendingOrder);
1242 convertersLW->blockSignals(false);
1244 // restore selection
1245 if (!current.isEmpty()) {
1246 QList<QListWidgetItem *> const item =
1247 convertersLW->findItems(current, Qt::MatchExactly);
1248 if (!item.isEmpty())
1249 convertersLW->setCurrentItem(item.at(0));
1252 // select first element if restoring failed
1253 if (convertersLW->currentRow() == -1)
1254 convertersLW->setCurrentRow(0);
1260 void PrefConverters::switch_converter()
1262 int const cnr = convertersLW->currentItem()->type();
1263 Converter const & c(form_->converters().get(cnr));
1264 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1265 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1266 converterED->setText(toqstr(c.command));
1267 converterFlagED->setText(toqstr(c.flags));
1273 void PrefConverters::converter_changed()
1279 void PrefConverters::updateButtons()
1281 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1282 Format const & to = form_->formats().get(converterToCO->currentIndex());
1283 int const sel = form_->converters().getNumber(from.name(), to.name());
1284 bool const known = sel >= 0;
1285 bool const valid = !(converterED->text().isEmpty()
1286 || from.name() == to.name());
1288 int const cnr = convertersLW->currentItem()->type();
1289 Converter const & c(form_->converters().get(cnr));
1290 string const old_command = c.command;
1291 string const old_flag = c.flags;
1292 string const new_command(fromqstr(converterED->text()));
1293 string const new_flag(fromqstr(converterFlagED->text()));
1295 bool modified = (old_command != new_command) || (old_flag != new_flag);
1297 converterModifyPB->setEnabled(valid && known && modified);
1298 converterNewPB->setEnabled(valid && !known);
1299 converterRemovePB->setEnabled(known);
1301 maxAgeLE->setEnabled(cacheCB->isChecked());
1302 maxAgeLA->setEnabled(cacheCB->isChecked());
1307 // specify unique from/to or it doesn't appear. This is really bad UI
1308 // this is why we can use the same function for both new and modify
1309 void PrefConverters::update_converter()
1311 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1312 Format const & to = form_->formats().get(converterToCO->currentIndex());
1313 string const flags = fromqstr(converterFlagED->text());
1314 string const command = fromqstr(converterED->text());
1316 Converter const * old =
1317 form_->converters().getConverter(from.name(), to.name());
1318 form_->converters().add(from.name(), to.name(), command, flags);
1321 form_->converters().updateLast(form_->formats());
1325 // Remove all files created by this converter from the cache, since
1326 // the modified converter might create different files.
1327 ConverterCache::get().remove_all(from.name(), to.name());
1331 void PrefConverters::remove_converter()
1333 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1334 Format const & to = form_->formats().get(converterToCO->currentIndex());
1335 form_->converters().erase(from.name(), to.name());
1339 // Remove all files created by this converter from the cache, since
1340 // a possible new converter might create different files.
1341 ConverterCache::get().remove_all(from.name(), to.name());
1345 void PrefConverters::on_cacheCB_stateChanged(int state)
1347 maxAgeLE->setEnabled(state == Qt::Checked);
1348 maxAgeLA->setEnabled(state == Qt::Checked);
1353 /////////////////////////////////////////////////////////////////////
1357 /////////////////////////////////////////////////////////////////////
1359 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1360 : QValidator(parent), formats_(f)
1365 void FormatValidator::fixup(QString & input) const
1367 Formats::const_iterator cit = formats_.begin();
1368 Formats::const_iterator end = formats_.end();
1369 for (; cit != end; ++cit) {
1370 string const name = str(cit);
1371 if (distance(formats_.begin(), cit) == nr()) {
1372 input = toqstr(name);
1380 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1382 Formats::const_iterator cit = formats_.begin();
1383 Formats::const_iterator end = formats_.end();
1384 bool unknown = true;
1385 for (; unknown && cit != end; ++cit) {
1386 string const name = str(cit);
1387 if (distance(formats_.begin(), cit) != nr())
1388 unknown = toqstr(name) != input;
1391 if (unknown && !input.isEmpty())
1392 return QValidator::Acceptable;
1394 return QValidator::Intermediate;
1398 int FormatValidator::nr() const
1400 QComboBox * p = qobject_cast<QComboBox *>(parent());
1401 return p->itemData(p->currentIndex()).toInt();
1405 FormatNameValidator::FormatNameValidator(QWidget * parent, Formats const & f)
1406 : FormatValidator(parent, f)
1410 string FormatNameValidator::str(Formats::const_iterator it) const
1416 FormatPrettynameValidator::FormatPrettynameValidator(QWidget * parent, Formats const & f)
1417 : FormatValidator(parent, f)
1422 string FormatPrettynameValidator::str(Formats::const_iterator it) const
1424 return it->prettyname();
1428 PrefFileformats::PrefFileformats(GuiPreferences * form, QWidget * parent)
1429 : PrefModule(qt_(catFiles), qt_("File formats"), form, parent)
1432 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1433 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1435 connect(documentCB, SIGNAL(clicked()),
1436 this, SLOT(setFlags()));
1437 connect(vectorCB, SIGNAL(clicked()),
1438 this, SLOT(setFlags()));
1439 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1440 this, SLOT(updatePrettyname()));
1441 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1442 this, SIGNAL(changed()));
1446 void PrefFileformats::apply(LyXRC & /*rc*/) const
1451 void PrefFileformats::update(LyXRC const & /*rc*/)
1457 void PrefFileformats::updateView()
1459 QString const current = formatsCB->currentText();
1461 // update combobox with formats
1462 formatsCB->blockSignals(true);
1464 form_->formats().sort();
1465 Formats::const_iterator cit = form_->formats().begin();
1466 Formats::const_iterator end = form_->formats().end();
1467 for (; cit != end; ++cit)
1468 formatsCB->addItem(toqstr(cit->prettyname()),
1469 QVariant(form_->formats().getNumber(cit->name())) );
1471 // restore selection
1472 int const item = formatsCB->findText(current, Qt::MatchExactly);
1473 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1474 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1475 formatsCB->blockSignals(false);
1479 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1481 int const nr = formatsCB->itemData(i).toInt();
1482 Format const f = form_->formats().get(nr);
1484 formatED->setText(toqstr(f.name()));
1485 copierED->setText(toqstr(form_->movers().command(f.name())));
1486 extensionED->setText(toqstr(f.extension()));
1487 shortcutED->setText(toqstr(f.shortcut()));
1488 viewerED->setText(toqstr(f.viewer()));
1489 editorED->setText(toqstr(f.editor()));
1490 documentCB->setChecked((f.documentFormat()));
1491 vectorCB->setChecked((f.vectorFormat()));
1495 void PrefFileformats::setFlags()
1497 int flags = Format::none;
1498 if (documentCB->isChecked())
1499 flags |= Format::document;
1500 if (vectorCB->isChecked())
1501 flags |= Format::vector;
1502 currentFormat().setFlags(flags);
1507 void PrefFileformats::on_copierED_textEdited(const QString & s)
1509 string const fmt = fromqstr(formatED->text());
1510 form_->movers().set(fmt, fromqstr(s));
1515 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1517 currentFormat().setExtension(fromqstr(s));
1521 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1523 currentFormat().setViewer(fromqstr(s));
1528 void PrefFileformats::on_editorED_textEdited(const QString & s)
1530 currentFormat().setEditor(fromqstr(s));
1535 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1537 currentFormat().setShortcut(fromqstr(s));
1542 void PrefFileformats::on_formatED_editingFinished()
1544 string const newname = fromqstr(formatED->displayText());
1545 if (newname == currentFormat().name())
1548 currentFormat().setName(newname);
1553 void PrefFileformats::on_formatED_textChanged(const QString &)
1555 QString t = formatED->text();
1557 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1558 setValid(formatLA, valid);
1562 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1564 QString t = formatsCB->currentText();
1566 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1567 setValid(formatsLA, valid);
1571 void PrefFileformats::updatePrettyname()
1573 string const newname = fromqstr(formatsCB->currentText());
1574 if (newname == currentFormat().prettyname())
1577 currentFormat().setPrettyname(newname);
1584 Format & PrefFileformats::currentFormat()
1586 int const i = formatsCB->currentIndex();
1587 int const nr = formatsCB->itemData(i).toInt();
1588 return form_->formats().get(nr);
1592 void PrefFileformats::on_formatNewPB_clicked()
1594 form_->formats().add("", "", "", "", "", "", Format::none);
1596 formatsCB->setCurrentIndex(0);
1597 formatsCB->setFocus(Qt::OtherFocusReason);
1601 void PrefFileformats::on_formatRemovePB_clicked()
1603 int const i = formatsCB->currentIndex();
1604 int const nr = formatsCB->itemData(i).toInt();
1605 string const current_text = form_->formats().get(nr).name();
1606 if (form_->converters().formatIsUsed(current_text)) {
1607 Alert::error(_("Format in use"),
1608 _("Cannot remove a Format used by a Converter. "
1609 "Remove the converter first."));
1613 form_->formats().erase(current_text);
1616 on_formatsCB_editTextChanged(formatsCB->currentText());
1621 /////////////////////////////////////////////////////////////////////
1625 /////////////////////////////////////////////////////////////////////
1627 PrefLanguage::PrefLanguage(QWidget * parent)
1628 : PrefModule(qt_(catLanguage), qt_("Language"), 0, parent)
1632 connect(rtlGB, SIGNAL(clicked()),
1633 this, SIGNAL(changed()));
1634 connect(visualCursorRB, SIGNAL(clicked()),
1635 this, SIGNAL(changed()));
1636 connect(logicalCursorRB, SIGNAL(clicked()),
1637 this, SIGNAL(changed()));
1638 connect(markForeignCB, SIGNAL(clicked()),
1639 this, SIGNAL(changed()));
1640 connect(autoBeginCB, SIGNAL(clicked()),
1641 this, SIGNAL(changed()));
1642 connect(autoEndCB, SIGNAL(clicked()),
1643 this, SIGNAL(changed()));
1644 connect(useBabelCB, SIGNAL(clicked()),
1645 this, SIGNAL(changed()));
1646 connect(globalCB, SIGNAL(clicked()),
1647 this, SIGNAL(changed()));
1648 connect(languagePackageED, SIGNAL(textChanged(QString)),
1649 this, SIGNAL(changed()));
1650 connect(startCommandED, SIGNAL(textChanged(QString)),
1651 this, SIGNAL(changed()));
1652 connect(endCommandED, SIGNAL(textChanged(QString)),
1653 this, SIGNAL(changed()));
1654 connect(defaultLanguageCO, SIGNAL(activated(int)),
1655 this, SIGNAL(changed()));
1657 defaultLanguageCO->clear();
1659 // store the lang identifiers for later
1660 //foreach (LanguagePair const & lpair, languageData(false)) {
1661 QList<LanguagePair> l = languageData(false);
1662 foreach (LanguagePair const & lpair, l) {
1663 defaultLanguageCO->addItem(lpair.first);
1664 lang_.append(lpair.second);
1669 void PrefLanguage::apply(LyXRC & rc) const
1671 // FIXME: remove rtl_support bool
1672 rc.rtl_support = rtlGB->isChecked();
1673 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
1674 rc.mark_foreign_language = markForeignCB->isChecked();
1675 rc.language_auto_begin = autoBeginCB->isChecked();
1676 rc.language_auto_end = autoEndCB->isChecked();
1677 rc.language_use_babel = useBabelCB->isChecked();
1678 rc.language_global_options = globalCB->isChecked();
1679 rc.language_package = fromqstr(languagePackageED->text());
1680 rc.language_command_begin = fromqstr(startCommandED->text());
1681 rc.language_command_end = fromqstr(endCommandED->text());
1682 rc.default_language = fromqstr(lang_[defaultLanguageCO->currentIndex()]);
1686 void PrefLanguage::update(LyXRC const & rc)
1688 // FIXME: remove rtl_support bool
1689 rtlGB->setChecked(rc.rtl_support);
1690 if (rc.visual_cursor)
1691 visualCursorRB->setChecked(true);
1693 logicalCursorRB->setChecked(true);
1694 markForeignCB->setChecked(rc.mark_foreign_language);
1695 autoBeginCB->setChecked(rc.language_auto_begin);
1696 autoEndCB->setChecked(rc.language_auto_end);
1697 useBabelCB->setChecked(rc.language_use_babel);
1698 globalCB->setChecked(rc.language_global_options);
1699 languagePackageED->setText(toqstr(rc.language_package));
1700 startCommandED->setText(toqstr(rc.language_command_begin));
1701 endCommandED->setText(toqstr(rc.language_command_end));
1703 int const pos = findPos_helper(lang_, toqstr(rc.default_language));
1704 defaultLanguageCO->setCurrentIndex(pos);
1708 /////////////////////////////////////////////////////////////////////
1712 /////////////////////////////////////////////////////////////////////
1714 PrefPrinter::PrefPrinter(QWidget * parent)
1715 : PrefModule(qt_(catOutput), qt_("Printer"), 0, parent)
1719 connect(printerAdaptCB, SIGNAL(clicked()),
1720 this, SIGNAL(changed()));
1721 connect(printerCommandED, SIGNAL(textChanged(QString)),
1722 this, SIGNAL(changed()));
1723 connect(printerNameED, SIGNAL(textChanged(QString)),
1724 this, SIGNAL(changed()));
1725 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
1726 this, SIGNAL(changed()));
1727 connect(printerCopiesED, SIGNAL(textChanged(QString)),
1728 this, SIGNAL(changed()));
1729 connect(printerReverseED, SIGNAL(textChanged(QString)),
1730 this, SIGNAL(changed()));
1731 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
1732 this, SIGNAL(changed()));
1733 connect(printerExtensionED, SIGNAL(textChanged(QString)),
1734 this, SIGNAL(changed()));
1735 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
1736 this, SIGNAL(changed()));
1737 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
1738 this, SIGNAL(changed()));
1739 connect(printerEvenED, SIGNAL(textChanged(QString)),
1740 this, SIGNAL(changed()));
1741 connect(printerOddED, SIGNAL(textChanged(QString)),
1742 this, SIGNAL(changed()));
1743 connect(printerCollatedED, SIGNAL(textChanged(QString)),
1744 this, SIGNAL(changed()));
1745 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
1746 this, SIGNAL(changed()));
1747 connect(printerToFileED, SIGNAL(textChanged(QString)),
1748 this, SIGNAL(changed()));
1749 connect(printerExtraED, SIGNAL(textChanged(QString)),
1750 this, SIGNAL(changed()));
1751 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
1752 this, SIGNAL(changed()));
1753 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
1754 this, SIGNAL(changed()));
1758 void PrefPrinter::apply(LyXRC & rc) const
1760 rc.print_adapt_output = printerAdaptCB->isChecked();
1761 rc.print_command = fromqstr(printerCommandED->text());
1762 rc.printer = fromqstr(printerNameED->text());
1764 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1765 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1766 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1767 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1768 rc.print_file_extension = fromqstr(printerExtensionED->text());
1769 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1770 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1771 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1772 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1773 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1774 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1775 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1776 rc.print_extra_options = fromqstr(printerExtraED->text());
1777 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1778 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1782 void PrefPrinter::update(LyXRC const & rc)
1784 printerAdaptCB->setChecked(rc.print_adapt_output);
1785 printerCommandED->setText(toqstr(rc.print_command));
1786 printerNameED->setText(toqstr(rc.printer));
1788 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1789 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1790 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1791 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1792 printerExtensionED->setText(toqstr(rc.print_file_extension));
1793 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1794 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1795 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1796 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1797 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1798 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1799 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1800 printerExtraED->setText(toqstr(rc.print_extra_options));
1801 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1802 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1806 /////////////////////////////////////////////////////////////////////
1808 // PrefUserInterface
1810 /////////////////////////////////////////////////////////////////////
1812 PrefUserInterface::PrefUserInterface(GuiPreferences * form, QWidget * parent)
1813 : PrefModule(qt_(catLookAndFeel), qt_("User interface"), form, parent)
1817 connect(autoSaveCB, SIGNAL(toggled(bool)),
1818 autoSaveSB, SLOT(setEnabled(bool)));
1819 connect(autoSaveCB, SIGNAL(toggled(bool)),
1820 TextLabel1, SLOT(setEnabled(bool)));
1821 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
1822 this, SIGNAL(changed()));
1823 connect(uiFilePB, SIGNAL(clicked()),
1824 this, SLOT(select_ui()));
1825 connect(uiFileED, SIGNAL(textChanged(QString)),
1826 this, SIGNAL(changed()));
1827 connect(restoreCursorCB, SIGNAL(clicked()),
1828 this, SIGNAL(changed()));
1829 connect(loadSessionCB, SIGNAL(clicked()),
1830 this, SIGNAL(changed()));
1831 connect(allowGeometrySessionCB, SIGNAL(clicked()),
1832 this, SIGNAL(changed()));
1833 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1834 this, SIGNAL(changed()));
1835 connect(autoSaveCB, SIGNAL(clicked()),
1836 this, SIGNAL(changed()));
1837 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1838 this, SIGNAL(changed()));
1839 connect(tooltipCB, SIGNAL(toggled(bool)),
1840 this, SIGNAL(changed()));
1841 connect(useBundledCB, SIGNAL(toggled(bool)),
1842 this, SIGNAL(changed()));
1843 lastfilesSB->setMaximum(maxlastfiles);
1847 void PrefUserInterface::apply(LyXRC & rc) const
1849 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1850 rc.use_lastfilepos = restoreCursorCB->isChecked();
1851 rc.load_session = loadSessionCB->isChecked();
1852 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
1853 rc.autosave = autoSaveSB->value() * 60;
1854 rc.make_backup = autoSaveCB->isChecked();
1855 rc.num_lastfiles = lastfilesSB->value();
1856 rc.use_tooltip = tooltipCB->isChecked();
1857 rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
1858 rc.use_bundled_format = useBundledCB->isChecked();
1862 void PrefUserInterface::update(LyXRC const & rc)
1864 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1865 restoreCursorCB->setChecked(rc.use_lastfilepos);
1866 loadSessionCB->setChecked(rc.load_session);
1867 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
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 openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
1877 useBundledCB->setChecked(rc.use_bundled_format);
1881 void PrefUserInterface::select_ui()
1883 QString file = form_->browseUI(internalPath(uiFileED->text()));
1884 if (!file.isEmpty())
1885 uiFileED->setText(file);
1888 /////////////////////////////////////////////////////////////////////
1892 /////////////////////////////////////////////////////////////////////
1894 PrefEdit::PrefEdit(GuiPreferences * form, QWidget * parent)
1895 : PrefModule(qt_(catEditing), qt_("Control"), form, parent)
1899 connect(cursorFollowsCB, SIGNAL(clicked()),
1900 this, SIGNAL(changed()));
1901 connect(sortEnvironmentsCB, SIGNAL(clicked()),
1902 this, SIGNAL(changed()));
1903 connect(groupEnvironmentsCB, SIGNAL(clicked()),
1904 this, SIGNAL(changed()));
1905 connect(macroEditStyleCO, SIGNAL(activated(int)),
1906 this, SIGNAL(changed()));
1907 connect(fullscreenLimitGB, SIGNAL(clicked()),
1908 this, SIGNAL(changed()));
1909 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
1910 this, SIGNAL(changed()));
1911 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
1912 this, SIGNAL(changed()));
1913 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
1914 this, SIGNAL(changed()));
1915 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
1916 this, SIGNAL(changed()));
1920 void PrefEdit::apply(LyXRC & rc) const
1922 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1923 rc.sort_layouts = sortEnvironmentsCB->isChecked();
1924 rc.group_layouts = groupEnvironmentsCB->isChecked();
1925 switch (macroEditStyleCO->currentIndex()) {
1926 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
1927 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
1928 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
1930 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
1931 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
1932 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
1933 rc.full_screen_width = fullscreenWidthSB->value();
1934 rc.full_screen_limit = fullscreenLimitGB->isChecked();
1938 void PrefEdit::update(LyXRC const & rc)
1940 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1941 sortEnvironmentsCB->setChecked(rc.sort_layouts);
1942 groupEnvironmentsCB->setChecked(rc.group_layouts);
1943 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
1944 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
1945 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
1946 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
1947 fullscreenWidthSB->setValue(rc.full_screen_width);
1948 fullscreenLimitGB->setChecked(rc.full_screen_limit);
1952 /////////////////////////////////////////////////////////////////////
1956 /////////////////////////////////////////////////////////////////////
1959 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
1961 Ui::shortcutUi::setupUi(this);
1962 QDialog::setModal(true);
1966 PrefShortcuts::PrefShortcuts(GuiPreferences * form, QWidget * parent)
1967 : PrefModule(qt_(catEditing), qt_("Shortcuts"), form, parent)
1971 shortcutsTW->setColumnCount(2);
1972 shortcutsTW->headerItem()->setText(0, qt_("Function"));
1973 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
1974 shortcutsTW->setSortingEnabled(true);
1975 // Multi-selection can be annoying.
1976 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
1977 shortcutsTW->header()->resizeSection(0, 200);
1979 connect(bindFilePB, SIGNAL(clicked()),
1980 this, SLOT(select_bind()));
1981 connect(bindFileED, SIGNAL(textChanged(QString)),
1982 this, SIGNAL(changed()));
1983 connect(removePB, SIGNAL(clicked()),
1984 this, SIGNAL(changed()));
1986 shortcut_ = new GuiShortcutDialog(this);
1987 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
1988 shortcut_bc_.setOK(shortcut_->okPB);
1989 shortcut_bc_.setCancel(shortcut_->cancelPB);
1991 connect(shortcut_->okPB, SIGNAL(clicked()),
1992 shortcut_, SLOT(accept()));
1993 connect(shortcut_->okPB, SIGNAL(clicked()),
1994 this, SIGNAL(changed()));
1995 connect(shortcut_->cancelPB, SIGNAL(clicked()),
1996 shortcut_, SLOT(reject()));
1997 connect(shortcut_->clearPB, SIGNAL(clicked()),
1998 this, SLOT(shortcut_clearPB_pressed()));
1999 connect(shortcut_->okPB, SIGNAL(clicked()),
2000 this, SLOT(shortcut_okPB_pressed()));
2004 void PrefShortcuts::apply(LyXRC & rc) const
2006 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
2007 // write user_bind and user_unbind to .lyx/bind/user.bind
2008 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
2009 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
2010 lyxerr << "LyX could not create the user bind directory '"
2011 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2014 if (!bind_dir.isDirWritable()) {
2015 lyxerr << "LyX could not write to the user bind directory '"
2016 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2019 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
2020 user_bind_.write(user_bind_file.toFilesystemEncoding(), false, false);
2021 user_unbind_.write(user_bind_file.toFilesystemEncoding(), true, true);
2022 // immediately apply the keybindings. Why this is not done before?
2023 // The good thing is that the menus are updated automatically.
2024 theTopLevelKeymap().clear();
2025 theTopLevelKeymap().read("site");
2026 theTopLevelKeymap().read(rc.bind_file);
2027 theTopLevelKeymap().read("user");
2031 void PrefShortcuts::update(LyXRC const & rc)
2033 bindFileED->setText(toqstr(external_path(rc.bind_file)));
2035 system_bind_.clear();
2037 user_unbind_.clear();
2038 system_bind_.read(rc.bind_file);
2039 // \unbind in user.bind is added to user_unbind_
2040 user_bind_.read("user", &user_unbind_);
2041 updateShortcutsTW();
2045 void PrefShortcuts::updateShortcutsTW()
2047 shortcutsTW->clear();
2049 editItem_ = new QTreeWidgetItem(shortcutsTW);
2050 editItem_->setText(0, qt_("Cursor, Mouse and Editing functions"));
2051 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2053 mathItem_ = new QTreeWidgetItem(shortcutsTW);
2054 mathItem_->setText(0, qt_("Mathematical Symbols"));
2055 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2057 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2058 bufferItem_->setText(0, qt_("Buffer and Window"));
2059 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2061 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2062 layoutItem_->setText(0, qt_("Font, Layouts and Textclasses"));
2063 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2065 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2066 systemItem_->setText(0, qt_("System and Miscellaneous"));
2067 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2069 // listBindings(unbound=true) lists all bound and unbound lfuns
2070 // Items in this list is tagged by its source.
2071 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2072 static_cast<int>(System));
2073 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2074 static_cast<int>(UserBind));
2075 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2076 static_cast<int>(UserUnbind));
2077 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2078 user_bindinglist.end());
2079 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2080 user_unbindinglist.end());
2082 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2083 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2084 for (; it != it_end; ++it)
2085 insertShortcutItem(it->request, it->sequence, item_type(it->tag));
2087 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2088 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2089 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2093 void PrefShortcuts::setItemType(QTreeWidgetItem * item, item_type tag)
2095 item->setData(0, Qt::UserRole, QVariant(tag));
2105 font.setStrikeOut(true);
2107 // this item is not displayed now.
2108 case UserExtraUnbind:
2109 font.setStrikeOut(true);
2113 item->setFont(1, font);
2117 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2118 KeySequence const & seq, item_type tag)
2120 FuncCode action = lfun.action;
2121 string const action_name = lyxaction.getActionName(action);
2122 QString const lfun_name = toqstr(from_utf8(action_name)
2123 + ' ' + lfun.argument());
2124 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2125 item_type item_tag = tag;
2127 QTreeWidgetItem * newItem = 0;
2128 // for unbind items, try to find an existing item in the system bind list
2129 if (tag == UserUnbind) {
2130 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2131 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2132 for (int i = 0; i < items.size(); ++i) {
2133 if (items[i]->text(1) == shortcut)
2137 // if not found, this unbind item is UserExtraUnbind
2138 // Such an item is not displayed to avoid confusion (what is
2139 // unmatched removed?).
2141 item_tag = UserExtraUnbind;
2146 switch(lyxaction.getActionType(action)) {
2147 case LyXAction::Hidden:
2149 case LyXAction::Edit:
2150 newItem = new QTreeWidgetItem(editItem_);
2152 case LyXAction::Math:
2153 newItem = new QTreeWidgetItem(mathItem_);
2155 case LyXAction::Buffer:
2156 newItem = new QTreeWidgetItem(bufferItem_);
2158 case LyXAction::Layout:
2159 newItem = new QTreeWidgetItem(layoutItem_);
2161 case LyXAction::System:
2162 newItem = new QTreeWidgetItem(systemItem_);
2165 // this should not happen
2166 newItem = new QTreeWidgetItem(shortcutsTW);
2170 newItem->setText(0, lfun_name);
2171 newItem->setText(1, shortcut);
2172 // record BindFile representation to recover KeySequence when needed.
2173 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2174 setItemType(newItem, item_tag);
2179 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2181 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2182 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2183 if (items.isEmpty())
2186 item_type tag = static_cast<item_type>(items[0]->data(0, Qt::UserRole).toInt());
2187 if (tag == UserUnbind)
2188 removePB->setText(qt_("Res&tore"));
2190 removePB->setText(qt_("Remo&ve"));
2194 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2196 QTreeWidgetItem * item = shortcutsTW->currentItem();
2197 if (item->flags() & Qt::ItemIsSelectable) {
2198 shortcut_->lfunLE->setText(item->text(0));
2199 // clear the shortcut because I assume that a user will enter
2201 shortcut_->shortcutLE->reset();
2202 shortcut_->shortcutLE->setFocus();
2208 void PrefShortcuts::select_bind()
2210 QString file = form_->browsebind(internalPath(bindFileED->text()));
2211 if (!file.isEmpty()) {
2212 bindFileED->setText(file);
2213 system_bind_ = KeyMap();
2214 system_bind_.read(fromqstr(file));
2215 updateShortcutsTW();
2220 void PrefShortcuts::on_newPB_pressed()
2222 shortcut_->lfunLE->clear();
2223 shortcut_->shortcutLE->reset();
2228 void PrefShortcuts::on_removePB_pressed()
2230 // it seems that only one item can be selected, but I am
2231 // removing all selected items anyway.
2232 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2233 for (int i = 0; i < items.size(); ++i) {
2234 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2235 string lfun = fromqstr(items[i]->text(0));
2236 FuncRequest func = lyxaction.lookupFunc(lfun);
2237 item_type tag = static_cast<item_type>(items[i]->data(0, Qt::UserRole).toInt());
2241 // for system bind, we do not touch the item
2242 // but add an user unbind item
2243 user_unbind_.bind(shortcut, func);
2244 setItemType(items[i], UserUnbind);
2245 removePB->setText(qt_("Res&tore"));
2249 // for user_bind, we remove this bind
2250 QTreeWidgetItem * parent = items[i]->parent();
2251 int itemIdx = parent->indexOfChild(items[i]);
2252 parent->takeChild(itemIdx);
2254 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2256 shortcutsTW->scrollToItem(parent);
2257 user_bind_.unbind(shortcut, func);
2261 // for user_unbind, we remove the unbind, and the item
2262 // become System again.
2263 user_unbind_.unbind(shortcut, func);
2264 setItemType(items[i], System);
2265 removePB->setText(qt_("Remo&ve"));
2268 case UserExtraUnbind: {
2269 // for user unbind that is not in system bind file,
2270 // remove this unbind file
2271 QTreeWidgetItem * parent = items[i]->parent();
2272 parent->takeChild(parent->indexOfChild(items[i]));
2273 user_unbind_.unbind(shortcut, func);
2280 void PrefShortcuts::on_searchLE_textEdited()
2282 if (searchLE->text().isEmpty()) {
2283 // show all hidden items
2284 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2286 shortcutsTW->setItemHidden(*it++, false);
2289 // search both columns
2290 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2291 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2292 matched += shortcutsTW->findItems(searchLE->text(),
2293 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2295 // hide everyone (to avoid searching in matched QList repeatedly
2296 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2298 shortcutsTW->setItemHidden(*it++, true);
2299 // show matched items
2300 for (int i = 0; i < matched.size(); ++i) {
2301 shortcutsTW->setItemHidden(matched[i], false);
2302 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2307 void PrefShortcuts::shortcut_okPB_pressed()
2309 string lfun = fromqstr(shortcut_->lfunLE->text());
2310 FuncRequest func = lyxaction.lookupFunc(lfun);
2312 if (func.action == LFUN_UNKNOWN_ACTION) {
2313 Alert::error(_("Failed to create shortcut"),
2314 _("Unknown or invalid LyX function"));
2318 KeySequence k = shortcut_->shortcutLE->getKeySequence();
2319 if (k.length() == 0) {
2320 Alert::error(_("Failed to create shortcut"),
2321 _("Invalid or empty key sequence"));
2325 // if both lfun and shortcut is valid
2326 if (user_bind_.hasBinding(k, func) || system_bind_.hasBinding(k, func)) {
2327 Alert::error(_("Failed to create shortcut"),
2328 _("Shortcut is already defined"));
2332 QTreeWidgetItem * item = insertShortcutItem(func, k, UserBind);
2334 user_bind_.bind(&k, func);
2335 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2336 shortcutsTW->setItemExpanded(item->parent(), true);
2337 shortcutsTW->scrollToItem(item);
2339 Alert::error(_("Failed to create shortcut"),
2340 _("Can not insert shortcut to the list"));
2346 void PrefShortcuts::shortcut_clearPB_pressed()
2348 shortcut_->shortcutLE->reset();
2349 shortcut_->shortcutLE->setFocus();
2353 /////////////////////////////////////////////////////////////////////
2357 /////////////////////////////////////////////////////////////////////
2359 PrefIdentity::PrefIdentity(QWidget * parent)
2360 : PrefModule(QString(), qt_("Identity"), 0, parent)
2364 connect(nameED, SIGNAL(textChanged(QString)),
2365 this, SIGNAL(changed()));
2366 connect(emailED, SIGNAL(textChanged(QString)),
2367 this, SIGNAL(changed()));
2371 void PrefIdentity::apply(LyXRC & rc) const
2373 rc.user_name = fromqstr(nameED->text());
2374 rc.user_email = fromqstr(emailED->text());
2378 void PrefIdentity::update(LyXRC const & rc)
2380 nameED->setText(toqstr(rc.user_name));
2381 emailED->setText(toqstr(rc.user_email));
2386 /////////////////////////////////////////////////////////////////////
2390 /////////////////////////////////////////////////////////////////////
2392 GuiPreferences::GuiPreferences(GuiView & lv)
2393 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2397 QDialog::setModal(false);
2399 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2400 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2401 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2402 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2404 add(new PrefUserInterface(this));
2405 add(new PrefEdit(this));
2406 add(new PrefShortcuts(this));
2407 add(new PrefScreenFonts(this));
2408 add(new PrefColors(this));
2409 add(new PrefDisplay);
2410 add(new PrefInput(this));
2411 add(new PrefCompletion(this));
2413 add(new PrefPaths(this));
2415 add(new PrefIdentity);
2417 add(new PrefLanguage);
2418 add(new PrefSpellchecker(this));
2420 add(new PrefPrinter);
2422 add(new PrefPlaintext);
2423 add(new PrefLatex(this));
2425 PrefConverters * converters = new PrefConverters(this);
2426 PrefFileformats * formats = new PrefFileformats(this);
2427 connect(formats, SIGNAL(formatsChanged()),
2428 converters, SLOT(updateGui()));
2432 prefsPS->setCurrentPanel(qt_("User interface"));
2433 // FIXME: hack to work around resizing bug in Qt >= 4.2
2434 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2435 #if QT_VERSION >= 0x040200
2436 prefsPS->updateGeometry();
2439 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2441 bc().setApply(applyPB);
2442 bc().setCancel(closePB);
2443 bc().setRestore(restorePB);
2447 void GuiPreferences::add(PrefModule * module)
2449 LASSERT(module, /**/);
2450 if (module->category().isEmpty())
2451 prefsPS->addPanel(module, module->title());
2453 prefsPS->addPanel(module, module->title(), module->category());
2454 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2455 modules_.push_back(module);
2459 void GuiPreferences::change_adaptor()
2465 void GuiPreferences::apply(LyXRC & rc) const
2467 size_t end = modules_.size();
2468 for (size_t i = 0; i != end; ++i)
2469 modules_[i]->apply(rc);
2473 void GuiPreferences::updateRc(LyXRC const & rc)
2475 size_t const end = modules_.size();
2476 for (size_t i = 0; i != end; ++i)
2477 modules_[i]->update(rc);
2481 void GuiPreferences::applyView()
2487 void GuiPreferences::updateContents()
2493 bool GuiPreferences::initialiseParams(string const &)
2496 formats_ = lyx::formats;
2497 converters_ = theConverters();
2498 converters_.update(formats_);
2499 movers_ = theMovers();
2501 update_screen_font_ = false;
2507 void GuiPreferences::dispatchParams()
2510 rc_.write(ss, true);
2511 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
2512 // FIXME: these need lfuns
2514 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
2516 lyx::formats = formats_;
2518 theConverters() = converters_;
2519 theConverters().update(lyx::formats);
2520 theConverters().buildGraph();
2522 theMovers() = movers_;
2524 vector<string>::const_iterator it = colors_.begin();
2525 vector<string>::const_iterator const end = colors_.end();
2526 for (; it != end; ++it)
2527 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
2530 if (update_screen_font_) {
2531 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2532 update_screen_font_ = false;
2535 // The Save button has been pressed
2537 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
2541 void GuiPreferences::setColor(ColorCode col, string const & hex)
2543 colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
2547 void GuiPreferences::updateScreenFonts()
2549 update_screen_font_ = true;
2553 QString GuiPreferences::browsebind(QString const & file) const
2555 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
2556 FileFilterList(_("LyX bind files (*.bind)")));
2560 QString GuiPreferences::browseUI(QString const & file) const
2562 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
2563 FileFilterList(_("LyX UI files (*.ui)")));
2567 QString GuiPreferences::browsekbmap(QString const & file) const
2569 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
2570 FileFilterList(_("LyX keyboard maps (*.kmap)")));
2574 QString GuiPreferences::browsedict(QString const & file) const
2576 return browseFile(file, qt_("Choose personal dictionary"),
2577 FileFilterList(lyxrc.use_spell_lib ? _("*.pws") : _("*.ispell")));
2581 QString GuiPreferences::browse(QString const & file,
2582 QString const & title) const
2584 return browseFile(file, title, FileFilterList(), true);
2588 QString GuiPreferences::browsedir(QString const & path,
2589 QString const & title) const
2591 return browseDir(path, title);
2595 // We support less paper sizes than the document dialog
2596 // Therefore this adjustment is needed.
2597 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
2601 return PAPER_DEFAULT;
2603 return PAPER_USLETTER;
2605 return PAPER_USLEGAL;
2607 return PAPER_USEXECUTIVE;
2617 // should not happen
2618 return PAPER_DEFAULT;
2623 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
2625 switch (papersize) {
2628 case PAPER_USLETTER:
2632 case PAPER_USEXECUTIVE:
2643 // should not happen
2649 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
2652 } // namespace frontend
2655 #include "GuiPrefs_moc.cpp"