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"
49 #include <QAbstractItemModel>
51 #include <QColorDialog>
52 #include <QFontDatabase>
53 #include <QHeaderView>
55 #include <QPixmapCache>
56 #include <QPushButton>
59 #include <QTreeWidget>
60 #include <QTreeWidgetItem>
70 using namespace lyx::support;
71 using namespace lyx::support::os;
76 /////////////////////////////////////////////////////////////////////
80 /////////////////////////////////////////////////////////////////////
82 /** Launch a file dialog and return the chosen file.
83 filename: a suggested filename.
84 title: the title of the dialog.
86 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
88 QString browseFile(QString const & filename,
89 QString const & title,
90 QStringList const & filters,
92 QString const & label1 = QString(),
93 QString const & dir1 = QString(),
94 QString const & label2 = QString(),
95 QString const & dir2 = QString())
97 QString lastPath = ".";
98 if (!filename.isEmpty())
99 lastPath = onlyPath(filename);
101 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
102 dlg.setButton2(label1, dir1);
103 dlg.setButton2(label2, dir2);
105 FileDialog::Result result;
108 result = dlg.save(lastPath, filters, onlyFilename(filename));
110 result = dlg.open(lastPath, filters, onlyFilename(filename));
112 return result.second;
116 /** Wrapper around browseFile which tries to provide a filename
117 * relative to the user or system directory. The dir, name and ext
118 * parameters have the same meaning as in the
119 * support::LibFileSearch function.
121 QString browseLibFile(QString const & dir,
122 QString const & name,
124 QString const & title,
125 QStringList const & filters)
128 QString const label1 = qt_("System files|#S#s");
130 toqstr(addName(package().system_support().absFilename(), fromqstr(dir)));
132 QString const label2 = qt_("User files|#U#u");
134 toqstr(addName(package().user_support().absFilename(), fromqstr(dir)));
136 QString const result = browseFile(toqstr(
137 libFileSearch(dir, name, ext).absFilename()),
138 title, filters, false, dir1, dir2);
140 // remove the extension if it is the default one
142 if (getExtension(result) == ext)
143 noextresult = removeExtension(result);
145 noextresult = result;
147 // remove the directory, if it is the default one
148 QString const file = onlyFilename(noextresult);
149 if (toqstr(libFileSearch(dir, file, ext).absFilename()) == result)
156 /** Launch a file dialog and return the chosen directory.
157 pathname: a suggested pathname.
158 title: the title of the dialog.
159 dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
161 QString browseDir(QString const & pathname,
162 QString const & title,
163 QString const & label1 = QString(),
164 QString const & dir1 = QString(),
165 QString const & label2 = QString(),
166 QString const & dir2 = QString())
168 QString lastPath = ".";
169 if (!pathname.isEmpty())
170 lastPath = onlyPath(pathname);
172 FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
173 dlg.setButton1(label1, dir1);
174 dlg.setButton2(label2, dir2);
176 FileDialog::Result const result =
177 dlg.opendir(lastPath, onlyFilename(pathname));
179 return result.second;
183 } // namespace frontend
186 QString browseRelFile(QString const & filename, QString const & refpath,
187 QString const & title, QStringList const & filters, bool save,
188 QString const & label1, QString const & dir1,
189 QString const & label2, QString const & dir2)
191 QString const fname = makeAbsPath(filename, refpath);
194 QString const outname =
195 frontend::browseFile(fname, title, filters, save, label1, dir1, label2, dir2);
197 QString const reloutname =
198 toqstr(makeRelPath(qstring_to_ucs4(outname), qstring_to_ucs4(refpath)));
200 if (reloutname.startsWith("../"))
208 /////////////////////////////////////////////////////////////////////
212 /////////////////////////////////////////////////////////////////////
216 string const catLookAndFeel = N_("Look & Feel");
217 string const catEditing = N_("Editing");
218 string const catLanguage = N_("Language Settings");
219 string const catOutput = N_("Output");
220 string const catFiles = N_("File Handling");
222 static void parseFontName(QString const & mangled0,
223 string & name, string & foundry)
225 string mangled = fromqstr(mangled0);
226 size_t const idx = mangled.find('[');
227 if (idx == string::npos || idx == 0) {
231 name = mangled.substr(0, idx - 1),
232 foundry = mangled.substr(idx + 1, mangled.size() - idx - 2);
237 static void setComboxFont(QComboBox * cb, string const & family,
238 string const & foundry)
240 QString fontname = toqstr(family);
241 if (!foundry.empty())
242 fontname += " [" + toqstr(foundry) + ']';
244 for (int i = 0; i != cb->count(); ++i) {
245 if (cb->itemText(i) == fontname) {
246 cb->setCurrentIndex(i);
251 // Try matching without foundry name
253 // We count in reverse in order to prefer the Xft foundry
254 for (int i = cb->count(); --i >= 0;) {
255 string name, foundry;
256 parseFontName(cb->itemText(i), name, foundry);
257 if (compare_ascii_no_case(name, family) == 0) {
258 cb->setCurrentIndex(i);
263 // family alone can contain e.g. "Helvetica [Adobe]"
264 string tmpname, tmpfoundry;
265 parseFontName(toqstr(family), tmpname, tmpfoundry);
267 // We count in reverse in order to prefer the Xft foundry
268 for (int i = cb->count(); --i >= 0; ) {
269 string name, foundry;
270 parseFontName(cb->itemText(i), name, foundry);
271 if (compare_ascii_no_case(name, foundry) == 0) {
272 cb->setCurrentIndex(i);
277 // Bleh, default fonts, and the names couldn't be found. Hack
281 font.setKerning(false);
283 QString const font_family = toqstr(family);
284 if (font_family == guiApp->romanFontName()) {
285 font.setStyleHint(QFont::Serif);
286 font.setFamily(font_family);
287 } else if (font_family == guiApp->sansFontName()) {
288 font.setStyleHint(QFont::SansSerif);
289 font.setFamily(font_family);
290 } else if (font_family == guiApp->typewriterFontName()) {
291 font.setStyleHint(QFont::TypeWriter);
292 font.setFamily(font_family);
294 LYXERR0("FAILED to find the default font: '"
295 << foundry << "', '" << family << '\'');
299 QFontInfo info(font);
300 string default_font_name, dummyfoundry;
301 parseFontName(info.family(), default_font_name, dummyfoundry);
302 LYXERR0("Apparent font is " << default_font_name);
304 for (int i = 0; i < cb->count(); ++i) {
305 LYXERR0("Looking at " << cb->itemText(i));
306 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
307 default_font_name) == 0) {
308 cb->setCurrentIndex(i);
313 LYXERR0("FAILED to find the font: '"
314 << foundry << "', '" << family << '\'');
319 /////////////////////////////////////////////////////////////////////
323 /////////////////////////////////////////////////////////////////////
325 PrefPlaintext::PrefPlaintext(QWidget * parent)
326 : PrefModule(qt_(catOutput), qt_("Plain text"), 0, parent)
329 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
330 this, SIGNAL(changed()));
331 connect(plaintextRoffED, SIGNAL(textChanged(QString)),
332 this, SIGNAL(changed()));
336 void PrefPlaintext::apply(LyXRC & rc) const
338 rc.plaintext_linelen = plaintextLinelengthSB->value();
339 rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
343 void PrefPlaintext::update(LyXRC const & rc)
345 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
346 plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
350 /////////////////////////////////////////////////////////////////////
354 /////////////////////////////////////////////////////////////////////
356 PrefDate::PrefDate(QWidget * parent)
357 : PrefModule(qt_(catOutput), qt_("Date format"), 0, parent)
360 connect(DateED, SIGNAL(textChanged(QString)),
361 this, SIGNAL(changed()));
365 void PrefDate::apply(LyXRC & rc) const
367 rc.date_insert_format = fromqstr(DateED->text());
371 void PrefDate::update(LyXRC const & rc)
373 DateED->setText(toqstr(rc.date_insert_format));
377 /////////////////////////////////////////////////////////////////////
381 /////////////////////////////////////////////////////////////////////
383 PrefInput::PrefInput(GuiPreferences * form, QWidget * parent)
384 : PrefModule(qt_(catEditing), qt_("Keyboard/Mouse"), form, parent)
388 connect(keymapCB, SIGNAL(clicked()),
389 this, SIGNAL(changed()));
390 connect(firstKeymapED, SIGNAL(textChanged(QString)),
391 this, SIGNAL(changed()));
392 connect(secondKeymapED, SIGNAL(textChanged(QString)),
393 this, SIGNAL(changed()));
394 connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
395 this, SIGNAL(changed()));
399 void PrefInput::apply(LyXRC & rc) const
401 // FIXME: can derive CB from the two EDs
402 rc.use_kbmap = keymapCB->isChecked();
403 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
404 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
405 rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
409 void PrefInput::update(LyXRC const & rc)
411 // FIXME: can derive CB from the two EDs
412 keymapCB->setChecked(rc.use_kbmap);
413 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
414 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
415 mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
419 QString PrefInput::testKeymap(QString keymap)
421 return form_->browsekbmap(toqstr(internal_path(fromqstr(keymap))));
425 void PrefInput::on_firstKeymapPB_clicked(bool)
427 QString const file = testKeymap(firstKeymapED->text());
429 firstKeymapED->setText(file);
433 void PrefInput::on_secondKeymapPB_clicked(bool)
435 QString const file = testKeymap(secondKeymapED->text());
437 secondKeymapED->setText(file);
441 void PrefInput::on_keymapCB_toggled(bool keymap)
443 firstKeymapLA->setEnabled(keymap);
444 secondKeymapLA->setEnabled(keymap);
445 firstKeymapED->setEnabled(keymap);
446 secondKeymapED->setEnabled(keymap);
447 firstKeymapPB->setEnabled(keymap);
448 secondKeymapPB->setEnabled(keymap);
452 /////////////////////////////////////////////////////////////////////
456 /////////////////////////////////////////////////////////////////////
458 PrefCompletion::PrefCompletion(GuiPreferences * form, QWidget * parent)
459 : PrefModule(qt_(catEditing), qt_("Input Completion"), form, parent)
463 connect(inlineDelaySB, SIGNAL(valueChanged(double)),
464 this, SIGNAL(changed()));
465 connect(inlineMathCB, SIGNAL(clicked()),
466 this, SIGNAL(changed()));
467 connect(inlineTextCB, SIGNAL(clicked()),
468 this, SIGNAL(changed()));
469 connect(inlineDotsCB, SIGNAL(clicked()),
470 this, SIGNAL(changed()));
471 connect(popupDelaySB, SIGNAL(valueChanged(double)),
472 this, SIGNAL(changed()));
473 connect(popupMathCB, SIGNAL(clicked()),
474 this, SIGNAL(changed()));
475 connect(popupTextCB, SIGNAL(clicked()),
476 this, SIGNAL(changed()));
477 connect(popupAfterCompleteCB, SIGNAL(clicked()),
478 this, SIGNAL(changed()));
479 connect(cursorTextCB, SIGNAL(clicked()),
480 this, SIGNAL(changed()));
484 void PrefCompletion::apply(LyXRC & rc) const
486 rc.completion_inline_delay = inlineDelaySB->value();
487 rc.completion_inline_math = inlineMathCB->isChecked();
488 rc.completion_inline_text = inlineTextCB->isChecked();
489 rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
490 rc.completion_popup_delay = popupDelaySB->value();
491 rc.completion_popup_math = popupMathCB->isChecked();
492 rc.completion_popup_text = popupTextCB->isChecked();
493 rc.completion_cursor_text = cursorTextCB->isChecked();
494 rc.completion_popup_after_complete =
495 popupAfterCompleteCB->isChecked();
499 void PrefCompletion::update(LyXRC const & rc)
501 inlineDelaySB->setValue(rc.completion_inline_delay);
502 inlineMathCB->setChecked(rc.completion_inline_math);
503 inlineTextCB->setChecked(rc.completion_inline_text);
504 inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
505 popupDelaySB->setValue(rc.completion_popup_delay);
506 popupMathCB->setChecked(rc.completion_popup_math);
507 popupTextCB->setChecked(rc.completion_popup_text);
508 cursorTextCB->setChecked(rc.completion_cursor_text);
509 popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
514 /////////////////////////////////////////////////////////////////////
518 /////////////////////////////////////////////////////////////////////
520 PrefLatex::PrefLatex(GuiPreferences * form, QWidget * parent)
521 : PrefModule(qt_(catOutput), qt_("LaTeX"), form, parent)
524 connect(latexEncodingED, SIGNAL(textChanged(QString)),
525 this, SIGNAL(changed()));
526 connect(latexChecktexED, SIGNAL(textChanged(QString)),
527 this, SIGNAL(changed()));
528 connect(latexBibtexED, SIGNAL(textChanged(QString)),
529 this, SIGNAL(changed()));
530 connect(latexIndexED, SIGNAL(textChanged(QString)),
531 this, SIGNAL(changed()));
532 connect(latexAutoresetCB, SIGNAL(clicked()),
533 this, SIGNAL(changed()));
534 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
535 this, SIGNAL(changed()));
536 connect(latexPaperSizeCO, SIGNAL(activated(int)),
537 this, SIGNAL(changed()));
539 #if defined(__CYGWIN__) || defined(_WIN32)
540 pathCB->setVisible(true);
541 connect(pathCB, SIGNAL(clicked()),
542 this, SIGNAL(changed()));
544 pathCB->setVisible(false);
549 void PrefLatex::apply(LyXRC & rc) const
551 rc.fontenc = fromqstr(latexEncodingED->text());
552 rc.chktex_command = fromqstr(latexChecktexED->text());
553 rc.bibtex_command = fromqstr(latexBibtexED->text());
554 rc.index_command = fromqstr(latexIndexED->text());
555 rc.auto_reset_options = latexAutoresetCB->isChecked();
556 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
557 rc.default_papersize =
558 form_->toPaperSize(latexPaperSizeCO->currentIndex());
559 #if defined(__CYGWIN__) || defined(_WIN32)
560 rc.windows_style_tex_paths = pathCB->isChecked();
565 void PrefLatex::update(LyXRC const & rc)
567 latexEncodingED->setText(toqstr(rc.fontenc));
568 latexChecktexED->setText(toqstr(rc.chktex_command));
569 latexBibtexED->setText(toqstr(rc.bibtex_command));
570 latexIndexED->setText(toqstr(rc.index_command));
571 latexAutoresetCB->setChecked(rc.auto_reset_options);
572 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
573 latexPaperSizeCO->setCurrentIndex(
574 form_->fromPaperSize(rc.default_papersize));
575 #if defined(__CYGWIN__) || defined(_WIN32)
576 pathCB->setChecked(rc.windows_style_tex_paths);
581 /////////////////////////////////////////////////////////////////////
585 /////////////////////////////////////////////////////////////////////
587 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form, QWidget * parent)
588 : PrefModule(qt_(catLookAndFeel), qt_("Screen fonts"), form, parent)
592 connect(screenRomanCO, SIGNAL(activated(QString)),
593 this, SLOT(select_roman(QString)));
594 connect(screenSansCO, SIGNAL(activated(QString)),
595 this, SLOT(select_sans(QString)));
596 connect(screenTypewriterCO, SIGNAL(activated(QString)),
597 this, SLOT(select_typewriter(QString)));
599 QFontDatabase fontdb;
600 QStringList families(fontdb.families());
601 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
602 screenRomanCO->addItem(*it);
603 screenSansCO->addItem(*it);
604 screenTypewriterCO->addItem(*it);
606 connect(screenRomanCO, SIGNAL(activated(QString)),
607 this, SIGNAL(changed()));
608 connect(screenSansCO, SIGNAL(activated(QString)),
609 this, SIGNAL(changed()));
610 connect(screenTypewriterCO, SIGNAL(activated(QString)),
611 this, SIGNAL(changed()));
612 connect(screenZoomSB, SIGNAL(valueChanged(int)),
613 this, SIGNAL(changed()));
614 connect(screenDpiSB, SIGNAL(valueChanged(int)),
615 this, SIGNAL(changed()));
616 connect(screenTinyED, SIGNAL(textChanged(QString)),
617 this, SIGNAL(changed()));
618 connect(screenSmallestED, SIGNAL(textChanged(QString)),
619 this, SIGNAL(changed()));
620 connect(screenSmallerED, SIGNAL(textChanged(QString)),
621 this, SIGNAL(changed()));
622 connect(screenSmallED, SIGNAL(textChanged(QString)),
623 this, SIGNAL(changed()));
624 connect(screenNormalED, SIGNAL(textChanged(QString)),
625 this, SIGNAL(changed()));
626 connect(screenLargeED, SIGNAL(textChanged(QString)),
627 this, SIGNAL(changed()));
628 connect(screenLargerED, SIGNAL(textChanged(QString)),
629 this, SIGNAL(changed()));
630 connect(screenLargestED, SIGNAL(textChanged(QString)),
631 this, SIGNAL(changed()));
632 connect(screenHugeED, SIGNAL(textChanged(QString)),
633 this, SIGNAL(changed()));
634 connect(screenHugerED, SIGNAL(textChanged(QString)),
635 this, SIGNAL(changed()));
636 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
637 this, SIGNAL(changed()));
639 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
640 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
641 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
642 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
643 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
644 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
645 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
646 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
647 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
648 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
652 void PrefScreenFonts::apply(LyXRC & rc) const
654 LyXRC const oldrc = rc;
656 parseFontName(screenRomanCO->currentText(),
657 rc.roman_font_name, rc.roman_font_foundry);
658 parseFontName(screenSansCO->currentText(),
659 rc.sans_font_name, rc.sans_font_foundry);
660 parseFontName(screenTypewriterCO->currentText(),
661 rc.typewriter_font_name, rc.typewriter_font_foundry);
663 rc.zoom = screenZoomSB->value();
664 rc.dpi = screenDpiSB->value();
665 rc.font_sizes[FONT_SIZE_TINY] = fromqstr(screenTinyED->text());
666 rc.font_sizes[FONT_SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
667 rc.font_sizes[FONT_SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
668 rc.font_sizes[FONT_SIZE_SMALL] = fromqstr(screenSmallED->text());
669 rc.font_sizes[FONT_SIZE_NORMAL] = fromqstr(screenNormalED->text());
670 rc.font_sizes[FONT_SIZE_LARGE] = fromqstr(screenLargeED->text());
671 rc.font_sizes[FONT_SIZE_LARGER] = fromqstr(screenLargerED->text());
672 rc.font_sizes[FONT_SIZE_LARGEST] = fromqstr(screenLargestED->text());
673 rc.font_sizes[FONT_SIZE_HUGE] = fromqstr(screenHugeED->text());
674 rc.font_sizes[FONT_SIZE_HUGER] = fromqstr(screenHugerED->text());
675 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
677 if (rc.font_sizes != oldrc.font_sizes
678 || rc.roman_font_name != oldrc.roman_font_name
679 || rc.sans_font_name != oldrc.sans_font_name
680 || rc.typewriter_font_name != oldrc.typewriter_font_name
681 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
682 // The global QPixmapCache is used in GuiPainter to cache text
683 // painting so we must reset it in case any of the above
684 // parameter is changed.
685 QPixmapCache::clear();
686 guiApp->fontLoader().update();
687 form_->updateScreenFonts();
692 void PrefScreenFonts::update(LyXRC const & rc)
694 setComboxFont(screenRomanCO, rc.roman_font_name,
695 rc.roman_font_foundry);
696 setComboxFont(screenSansCO, rc.sans_font_name,
697 rc.sans_font_foundry);
698 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
699 rc.typewriter_font_foundry);
701 select_roman(screenRomanCO->currentText());
702 select_sans(screenSansCO->currentText());
703 select_typewriter(screenTypewriterCO->currentText());
705 screenZoomSB->setValue(rc.zoom);
706 screenDpiSB->setValue(rc.dpi);
707 screenTinyED->setText(toqstr(rc.font_sizes[FONT_SIZE_TINY]));
708 screenSmallestED->setText(toqstr(rc.font_sizes[FONT_SIZE_SCRIPT]));
709 screenSmallerED->setText(toqstr(rc.font_sizes[FONT_SIZE_FOOTNOTE]));
710 screenSmallED->setText(toqstr(rc.font_sizes[FONT_SIZE_SMALL]));
711 screenNormalED->setText(toqstr(rc.font_sizes[FONT_SIZE_NORMAL]));
712 screenLargeED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGE]));
713 screenLargerED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGER]));
714 screenLargestED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGEST]));
715 screenHugeED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGE]));
716 screenHugerED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGER]));
718 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
719 #if defined(Q_WS_X11)
720 pixmapCacheCB->setEnabled(false);
726 void PrefScreenFonts::select_roman(const QString & name)
728 screenRomanFE->set(QFont(name), name);
732 void PrefScreenFonts::select_sans(const QString & name)
734 screenSansFE->set(QFont(name), name);
738 void PrefScreenFonts::select_typewriter(const QString & name)
740 screenTypewriterFE->set(QFont(name), name);
744 /////////////////////////////////////////////////////////////////////
748 /////////////////////////////////////////////////////////////////////
754 bool operator()(ColorCode lhs, ColorCode rhs) const {
755 return lcolor.getGUIName(lhs) < lcolor.getGUIName(rhs);
761 PrefColors::PrefColors(GuiPreferences * form, QWidget * parent)
762 : PrefModule(qt_(catLookAndFeel), qt_("Colors"), form, parent)
766 // FIXME: all of this initialization should be put into the controller.
767 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
768 // for some discussion of why that is not trivial.
769 QPixmap icon(32, 32);
770 for (int i = 0; i < Color_ignore; ++i) {
771 ColorCode lc = static_cast<ColorCode>(i);
779 || lc == Color_magenta
780 || lc == Color_yellow
781 || lc == Color_inherit
782 || lc == Color_ignore) continue;
784 lcolors_.push_back(lc);
786 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
787 vector<ColorCode>::const_iterator cit = lcolors_.begin();
788 vector<ColorCode>::const_iterator const end = lcolors_.end();
789 for (; cit != end; ++cit) {
790 (void) new QListWidgetItem(QIcon(icon),
791 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
793 curcolors_.resize(lcolors_.size());
794 newcolors_.resize(lcolors_.size());
795 // End initialization
797 connect(colorChangePB, SIGNAL(clicked()),
798 this, SLOT(change_color()));
799 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
800 this, SLOT(change_lyxObjects_selection()));
801 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
802 this, SLOT(change_color()));
806 void PrefColors::apply(LyXRC & /*rc*/) const
808 for (unsigned int i = 0; i < lcolors_.size(); ++i)
809 if (curcolors_[i] != newcolors_[i])
810 form_->setColor(lcolors_[i], fromqstr(newcolors_[i]));
814 void PrefColors::update(LyXRC const & /*rc*/)
816 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
817 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
818 QPixmap coloritem(32, 32);
819 coloritem.fill(color);
820 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
821 newcolors_[i] = curcolors_[i] = color.name();
823 change_lyxObjects_selection();
827 void PrefColors::change_color()
829 int const row = lyxObjectsLW->currentRow();
835 QString const color = newcolors_[row];
836 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
838 if (c.isValid() && c.name() != color) {
839 newcolors_[row] = c.name();
840 QPixmap coloritem(32, 32);
842 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
848 void PrefColors::change_lyxObjects_selection()
850 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
854 /////////////////////////////////////////////////////////////////////
858 /////////////////////////////////////////////////////////////////////
860 PrefDisplay::PrefDisplay(QWidget * parent)
861 : PrefModule(qt_(catLookAndFeel), qt_("Graphics"), 0, parent)
864 connect(instantPreviewCO, SIGNAL(activated(int)),
865 this, SIGNAL(changed()));
866 connect(displayGraphicsCO, SIGNAL(activated(int)),
867 this, SIGNAL(changed()));
871 void PrefDisplay::apply(LyXRC & rc) const
873 switch (instantPreviewCO->currentIndex()) {
874 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
875 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
876 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
879 graphics::DisplayType dtype;
880 switch (displayGraphicsCO->currentIndex()) {
881 case 3: dtype = graphics::NoDisplay; break;
882 case 2: dtype = graphics::ColorDisplay; break;
883 case 1: dtype = graphics::GrayscaleDisplay; break;
884 case 0: dtype = graphics::MonochromeDisplay; break;
885 default: dtype = graphics::GrayscaleDisplay;
887 rc.display_graphics = dtype;
889 // FIXME!! The graphics cache no longer has a changeDisplay method.
891 if (old_value != rc.display_graphics) {
892 graphics::GCache & gc = graphics::GCache::get();
899 void PrefDisplay::update(LyXRC const & rc)
901 switch (rc.preview) {
902 case LyXRC::PREVIEW_OFF:
903 instantPreviewCO->setCurrentIndex(0);
905 case LyXRC::PREVIEW_NO_MATH :
906 instantPreviewCO->setCurrentIndex(1);
908 case LyXRC::PREVIEW_ON :
909 instantPreviewCO->setCurrentIndex(2);
914 switch (rc.display_graphics) {
915 case graphics::NoDisplay: item = 3; break;
916 case graphics::ColorDisplay: item = 2; break;
917 case graphics::GrayscaleDisplay: item = 1; break;
918 case graphics::MonochromeDisplay: item = 0; break;
921 displayGraphicsCO->setCurrentIndex(item);
925 /////////////////////////////////////////////////////////////////////
929 /////////////////////////////////////////////////////////////////////
931 PrefPaths::PrefPaths(GuiPreferences * form, QWidget * parent)
932 : PrefModule(QString(), qt_("Paths"), form, parent)
935 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(select_exampledir()));
936 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
937 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
938 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
939 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
940 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
941 connect(workingDirED, SIGNAL(textChanged(QString)),
942 this, SIGNAL(changed()));
943 connect(exampleDirED, SIGNAL(textChanged(QString)),
944 this, SIGNAL(changed()));
945 connect(templateDirED, SIGNAL(textChanged(QString)),
946 this, SIGNAL(changed()));
947 connect(backupDirED, SIGNAL(textChanged(QString)),
948 this, SIGNAL(changed()));
949 connect(tempDirED, SIGNAL(textChanged(QString)),
950 this, SIGNAL(changed()));
951 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
952 this, SIGNAL(changed()));
953 connect(pathPrefixED, SIGNAL(textChanged(QString)),
954 this, SIGNAL(changed()));
958 void PrefPaths::apply(LyXRC & rc) const
960 rc.document_path = internal_path(fromqstr(workingDirED->text()));
961 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
962 rc.template_path = internal_path(fromqstr(templateDirED->text()));
963 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
964 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
965 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
966 // FIXME: should be a checkbox only
967 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
971 void PrefPaths::update(LyXRC const & rc)
973 workingDirED->setText(toqstr(external_path(rc.document_path)));
974 exampleDirED->setText(toqstr(external_path(rc.example_path)));
975 templateDirED->setText(toqstr(external_path(rc.template_path)));
976 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
977 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
978 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
979 // FIXME: should be a checkbox only
980 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
984 void PrefPaths::select_exampledir()
986 QString file = browseDir(internalPath(exampleDirED->text()),
987 qt_("Select directory for example files"));
989 exampleDirED->setText(file);
993 void PrefPaths::select_templatedir()
995 QString file = browseDir(internalPath(templateDirED->text()),
996 qt_("Select a document templates directory"));
998 templateDirED->setText(file);
1002 void PrefPaths::select_tempdir()
1004 QString file = browseDir(internalPath(tempDirED->text()),
1005 qt_("Select a temporary directory"));
1006 if (!file.isEmpty())
1007 tempDirED->setText(file);
1011 void PrefPaths::select_backupdir()
1013 QString file = browseDir(internalPath(backupDirED->text()),
1014 qt_("Select a backups directory"));
1015 if (!file.isEmpty())
1016 backupDirED->setText(file);
1020 void PrefPaths::select_workingdir()
1022 QString file = browseDir(internalPath(workingDirED->text()),
1023 qt_("Select a document directory"));
1024 if (!file.isEmpty())
1025 workingDirED->setText(file);
1029 void PrefPaths::select_lyxpipe()
1031 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1032 qt_("Give a filename for the LyX server pipe"));
1033 if (!file.isEmpty())
1034 lyxserverDirED->setText(file);
1038 /////////////////////////////////////////////////////////////////////
1042 /////////////////////////////////////////////////////////////////////
1044 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form, QWidget * parent)
1045 : PrefModule(qt_(catLanguage), qt_("Spellchecker"), form, parent)
1049 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
1050 #if defined (USE_ISPELL)
1051 connect(spellCommandCO, SIGNAL(activated(int)),
1052 this, SIGNAL(changed()));
1054 spellCommandCO->setEnabled(false);
1056 connect(altLanguageED, SIGNAL(textChanged(QString)),
1057 this, SIGNAL(changed()));
1058 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1059 this, SIGNAL(changed()));
1060 connect(persDictionaryED, SIGNAL(textChanged(QString)),
1061 this, SIGNAL(changed()));
1062 connect(compoundWordCB, SIGNAL(clicked()),
1063 this, SIGNAL(changed()));
1064 connect(inputEncodingCB, SIGNAL(clicked()),
1065 this, SIGNAL(changed()));
1067 spellCommandCO->addItem(qt_("ispell"));
1068 spellCommandCO->addItem(qt_("aspell"));
1069 spellCommandCO->addItem(qt_("hspell"));
1071 spellCommandCO->addItem(qt_("pspell (library)"));
1074 spellCommandCO->addItem(qt_("aspell (library)"));
1080 void PrefSpellchecker::apply(LyXRC & rc) const
1082 switch (spellCommandCO->currentIndex()) {
1086 rc.use_spell_lib = false;
1087 rc.isp_command = fromqstr(spellCommandCO->currentText());
1090 rc.use_spell_lib = true;
1094 // FIXME: remove isp_use_alt_lang
1095 rc.isp_alt_lang = fromqstr(altLanguageED->text());
1096 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
1097 // FIXME: remove isp_use_esc_chars
1098 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
1099 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
1100 // FIXME: remove isp_use_pers_dict
1101 rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
1102 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
1103 rc.isp_accept_compound = compoundWordCB->isChecked();
1104 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
1108 void PrefSpellchecker::update(LyXRC const & rc)
1110 spellCommandCO->setCurrentIndex(0);
1112 if (rc.isp_command == "ispell") {
1113 spellCommandCO->setCurrentIndex(0);
1114 } else if (rc.isp_command == "aspell") {
1115 spellCommandCO->setCurrentIndex(1);
1116 } else if (rc.isp_command == "hspell") {
1117 spellCommandCO->setCurrentIndex(2);
1120 if (rc.use_spell_lib) {
1121 #if defined(USE_ASPELL) || defined(USE_PSPELL)
1122 spellCommandCO->setCurrentIndex(3);
1126 // FIXME: remove isp_use_alt_lang
1127 altLanguageED->setText(toqstr(rc.isp_alt_lang));
1128 // FIXME: remove isp_use_esc_chars
1129 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
1130 // FIXME: remove isp_use_pers_dict
1131 persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
1132 compoundWordCB->setChecked(rc.isp_accept_compound);
1133 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
1137 void PrefSpellchecker::select_dict()
1139 QString file = form_->browsedict(internalPath(persDictionaryED->text()));
1140 if (!file.isEmpty())
1141 persDictionaryED->setText(file);
1146 /////////////////////////////////////////////////////////////////////
1150 /////////////////////////////////////////////////////////////////////
1153 PrefConverters::PrefConverters(GuiPreferences * form, QWidget * parent)
1154 : PrefModule(qt_(catFiles), qt_("Converters"), form, parent)
1158 connect(converterNewPB, SIGNAL(clicked()),
1159 this, SLOT(update_converter()));
1160 connect(converterRemovePB, SIGNAL(clicked()),
1161 this, SLOT(remove_converter()));
1162 connect(converterModifyPB, SIGNAL(clicked()),
1163 this, SLOT(update_converter()));
1164 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1165 this, SLOT(switch_converter()));
1166 connect(converterFromCO, SIGNAL(activated(QString)),
1167 this, SLOT(converter_changed()));
1168 connect(converterToCO, SIGNAL(activated(QString)),
1169 this, SLOT(converter_changed()));
1170 connect(converterED, SIGNAL(textEdited(QString)),
1171 this, SLOT(converter_changed()));
1172 connect(converterFlagED, SIGNAL(textEdited(QString)),
1173 this, SLOT(converter_changed()));
1174 connect(converterNewPB, SIGNAL(clicked()),
1175 this, SIGNAL(changed()));
1176 connect(converterRemovePB, SIGNAL(clicked()),
1177 this, SIGNAL(changed()));
1178 connect(converterModifyPB, SIGNAL(clicked()),
1179 this, SIGNAL(changed()));
1180 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1181 this, SIGNAL(changed()));
1183 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1184 //converterDefGB->setFocusProxy(convertersLW);
1188 void PrefConverters::apply(LyXRC & rc) const
1190 rc.use_converter_cache = cacheCB->isChecked();
1191 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
1195 void PrefConverters::update(LyXRC const & rc)
1197 cacheCB->setChecked(rc.use_converter_cache);
1199 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
1200 maxAgeLE->setText(max_age);
1205 void PrefConverters::updateGui()
1207 form_->formats().sort();
1208 form_->converters().update(form_->formats());
1209 // save current selection
1210 QString current = converterFromCO->currentText()
1211 + " -> " + converterToCO->currentText();
1213 converterFromCO->clear();
1214 converterToCO->clear();
1216 Formats::const_iterator cit = form_->formats().begin();
1217 Formats::const_iterator end = form_->formats().end();
1218 for (; cit != end; ++cit) {
1219 converterFromCO->addItem(toqstr(cit->prettyname()));
1220 converterToCO->addItem(toqstr(cit->prettyname()));
1223 // currentRowChanged(int) is also triggered when updating the listwidget
1224 // block signals to avoid unnecessary calls to switch_converter()
1225 convertersLW->blockSignals(true);
1226 convertersLW->clear();
1228 Converters::const_iterator ccit = form_->converters().begin();
1229 Converters::const_iterator cend = form_->converters().end();
1230 for (; ccit != cend; ++ccit) {
1232 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
1233 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1234 new QListWidgetItem(toqstr(name), convertersLW, type);
1236 convertersLW->sortItems(Qt::AscendingOrder);
1237 convertersLW->blockSignals(false);
1239 // restore selection
1240 if (!current.isEmpty()) {
1241 QList<QListWidgetItem *> const item =
1242 convertersLW->findItems(current, Qt::MatchExactly);
1243 if (!item.isEmpty())
1244 convertersLW->setCurrentItem(item.at(0));
1247 // select first element if restoring failed
1248 if (convertersLW->currentRow() == -1)
1249 convertersLW->setCurrentRow(0);
1255 void PrefConverters::switch_converter()
1257 int const cnr = convertersLW->currentItem()->type();
1258 Converter const & c(form_->converters().get(cnr));
1259 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1260 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1261 converterED->setText(toqstr(c.command));
1262 converterFlagED->setText(toqstr(c.flags));
1268 void PrefConverters::converter_changed()
1274 void PrefConverters::updateButtons()
1276 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1277 Format const & to = form_->formats().get(converterToCO->currentIndex());
1278 int const sel = form_->converters().getNumber(from.name(), to.name());
1279 bool const known = sel >= 0;
1280 bool const valid = !(converterED->text().isEmpty()
1281 || from.name() == to.name());
1283 int const cnr = convertersLW->currentItem()->type();
1284 Converter const & c(form_->converters().get(cnr));
1285 string const old_command = c.command;
1286 string const old_flag = c.flags;
1287 string const new_command(fromqstr(converterED->text()));
1288 string const new_flag(fromqstr(converterFlagED->text()));
1290 bool modified = (old_command != new_command) || (old_flag != new_flag);
1292 converterModifyPB->setEnabled(valid && known && modified);
1293 converterNewPB->setEnabled(valid && !known);
1294 converterRemovePB->setEnabled(known);
1296 maxAgeLE->setEnabled(cacheCB->isChecked());
1297 maxAgeLA->setEnabled(cacheCB->isChecked());
1302 // specify unique from/to or it doesn't appear. This is really bad UI
1303 // this is why we can use the same function for both new and modify
1304 void PrefConverters::update_converter()
1306 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1307 Format const & to = form_->formats().get(converterToCO->currentIndex());
1308 string const flags = fromqstr(converterFlagED->text());
1309 string const command = fromqstr(converterED->text());
1311 Converter const * old =
1312 form_->converters().getConverter(from.name(), to.name());
1313 form_->converters().add(from.name(), to.name(), command, flags);
1316 form_->converters().updateLast(form_->formats());
1320 // Remove all files created by this converter from the cache, since
1321 // the modified converter might create different files.
1322 ConverterCache::get().remove_all(from.name(), to.name());
1326 void PrefConverters::remove_converter()
1328 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1329 Format const & to = form_->formats().get(converterToCO->currentIndex());
1330 form_->converters().erase(from.name(), to.name());
1334 // Remove all files created by this converter from the cache, since
1335 // a possible new converter might create different files.
1336 ConverterCache::get().remove_all(from.name(), to.name());
1340 void PrefConverters::on_cacheCB_stateChanged(int state)
1342 maxAgeLE->setEnabled(state == Qt::Checked);
1343 maxAgeLA->setEnabled(state == Qt::Checked);
1348 /////////////////////////////////////////////////////////////////////
1352 /////////////////////////////////////////////////////////////////////
1354 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1355 : QValidator(parent), formats_(f)
1360 void FormatValidator::fixup(QString & input) const
1362 Formats::const_iterator cit = formats_.begin();
1363 Formats::const_iterator end = formats_.end();
1364 for (; cit != end; ++cit) {
1365 string const name = str(cit);
1366 if (distance(formats_.begin(), cit) == nr()) {
1367 input = toqstr(name);
1375 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1377 Formats::const_iterator cit = formats_.begin();
1378 Formats::const_iterator end = formats_.end();
1379 bool unknown = true;
1380 for (; unknown && cit != end; ++cit) {
1381 string const name = str(cit);
1382 if (distance(formats_.begin(), cit) != nr())
1383 unknown = toqstr(name) != input;
1386 if (unknown && !input.isEmpty())
1387 return QValidator::Acceptable;
1389 return QValidator::Intermediate;
1393 int FormatValidator::nr() const
1395 QComboBox * p = qobject_cast<QComboBox *>(parent());
1396 return p->itemData(p->currentIndex()).toInt();
1400 FormatNameValidator::FormatNameValidator(QWidget * parent, Formats const & f)
1401 : FormatValidator(parent, f)
1405 string FormatNameValidator::str(Formats::const_iterator it) const
1411 FormatPrettynameValidator::FormatPrettynameValidator(QWidget * parent, Formats const & f)
1412 : FormatValidator(parent, f)
1417 string FormatPrettynameValidator::str(Formats::const_iterator it) const
1419 return it->prettyname();
1423 PrefFileformats::PrefFileformats(GuiPreferences * form, QWidget * parent)
1424 : PrefModule(qt_(catFiles), qt_("File formats"), form, parent)
1427 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1428 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1430 connect(documentCB, SIGNAL(clicked()),
1431 this, SLOT(setFlags()));
1432 connect(vectorCB, SIGNAL(clicked()),
1433 this, SLOT(setFlags()));
1434 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1435 this, SLOT(updatePrettyname()));
1436 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1437 this, SIGNAL(changed()));
1441 void PrefFileformats::apply(LyXRC & /*rc*/) const
1446 void PrefFileformats::update(LyXRC const & /*rc*/)
1452 void PrefFileformats::updateView()
1454 QString const current = formatsCB->currentText();
1456 // update combobox with formats
1457 formatsCB->blockSignals(true);
1459 form_->formats().sort();
1460 Formats::const_iterator cit = form_->formats().begin();
1461 Formats::const_iterator end = form_->formats().end();
1462 for (; cit != end; ++cit)
1463 formatsCB->addItem(toqstr(cit->prettyname()),
1464 QVariant(form_->formats().getNumber(cit->name())) );
1466 // restore selection
1467 int const item = formatsCB->findText(current, Qt::MatchExactly);
1468 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1469 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1470 formatsCB->blockSignals(false);
1474 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1476 int const nr = formatsCB->itemData(i).toInt();
1477 Format const f = form_->formats().get(nr);
1479 formatED->setText(toqstr(f.name()));
1480 copierED->setText(toqstr(form_->movers().command(f.name())));
1481 extensionED->setText(toqstr(f.extension()));
1482 shortcutED->setText(toqstr(f.shortcut()));
1483 viewerED->setText(toqstr(f.viewer()));
1484 editorED->setText(toqstr(f.editor()));
1485 documentCB->setChecked((f.documentFormat()));
1486 vectorCB->setChecked((f.vectorFormat()));
1490 void PrefFileformats::setFlags()
1492 int flags = Format::none;
1493 if (documentCB->isChecked())
1494 flags |= Format::document;
1495 if (vectorCB->isChecked())
1496 flags |= Format::vector;
1497 currentFormat().setFlags(flags);
1502 void PrefFileformats::on_copierED_textEdited(const QString & s)
1504 string const fmt = fromqstr(formatED->text());
1505 form_->movers().set(fmt, fromqstr(s));
1510 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1512 currentFormat().setExtension(fromqstr(s));
1516 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1518 currentFormat().setViewer(fromqstr(s));
1523 void PrefFileformats::on_editorED_textEdited(const QString & s)
1525 currentFormat().setEditor(fromqstr(s));
1530 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1532 currentFormat().setShortcut(fromqstr(s));
1537 void PrefFileformats::on_formatED_editingFinished()
1539 string const newname = fromqstr(formatED->displayText());
1540 if (newname == currentFormat().name())
1543 currentFormat().setName(newname);
1548 void PrefFileformats::on_formatED_textChanged(const QString &)
1550 QString t = formatED->text();
1552 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1553 setValid(formatLA, valid);
1557 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1559 QString t = formatsCB->currentText();
1561 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1562 setValid(formatsLA, valid);
1566 void PrefFileformats::updatePrettyname()
1568 string const newname = fromqstr(formatsCB->currentText());
1569 if (newname == currentFormat().prettyname())
1572 currentFormat().setPrettyname(newname);
1579 Format & PrefFileformats::currentFormat()
1581 int const i = formatsCB->currentIndex();
1582 int const nr = formatsCB->itemData(i).toInt();
1583 return form_->formats().get(nr);
1587 void PrefFileformats::on_formatNewPB_clicked()
1589 form_->formats().add("", "", "", "", "", "", Format::none);
1591 formatsCB->setCurrentIndex(0);
1592 formatsCB->setFocus(Qt::OtherFocusReason);
1596 void PrefFileformats::on_formatRemovePB_clicked()
1598 int const i = formatsCB->currentIndex();
1599 int const nr = formatsCB->itemData(i).toInt();
1600 string const current_text = form_->formats().get(nr).name();
1601 if (form_->converters().formatIsUsed(current_text)) {
1602 Alert::error(_("Format in use"),
1603 _("Cannot remove a Format used by a Converter. "
1604 "Remove the converter first."));
1608 form_->formats().erase(current_text);
1611 on_formatsCB_editTextChanged(formatsCB->currentText());
1616 /////////////////////////////////////////////////////////////////////
1620 /////////////////////////////////////////////////////////////////////
1622 PrefLanguage::PrefLanguage(QWidget * parent)
1623 : PrefModule(qt_(catLanguage), qt_("Language"), 0, parent)
1627 connect(rtlGB, SIGNAL(clicked()),
1628 this, SIGNAL(changed()));
1629 connect(visualCursorRB, SIGNAL(clicked()),
1630 this, SIGNAL(changed()));
1631 connect(logicalCursorRB, SIGNAL(clicked()),
1632 this, SIGNAL(changed()));
1633 connect(markForeignCB, SIGNAL(clicked()),
1634 this, SIGNAL(changed()));
1635 connect(autoBeginCB, SIGNAL(clicked()),
1636 this, SIGNAL(changed()));
1637 connect(autoEndCB, SIGNAL(clicked()),
1638 this, SIGNAL(changed()));
1639 connect(useBabelCB, SIGNAL(clicked()),
1640 this, SIGNAL(changed()));
1641 connect(globalCB, SIGNAL(clicked()),
1642 this, SIGNAL(changed()));
1643 connect(languagePackageED, SIGNAL(textChanged(QString)),
1644 this, SIGNAL(changed()));
1645 connect(startCommandED, SIGNAL(textChanged(QString)),
1646 this, SIGNAL(changed()));
1647 connect(endCommandED, SIGNAL(textChanged(QString)),
1648 this, SIGNAL(changed()));
1649 connect(defaultLanguageCO, SIGNAL(activated(int)),
1650 this, SIGNAL(changed()));
1652 defaultLanguageCO->clear();
1654 QAbstractItemModel * language_model = guiApp->languageModel();
1655 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1656 language_model->sort(0);
1657 defaultLanguageCO->setModel(language_model);
1661 void PrefLanguage::apply(LyXRC & rc) const
1663 // FIXME: remove rtl_support bool
1664 rc.rtl_support = rtlGB->isChecked();
1665 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
1666 rc.mark_foreign_language = markForeignCB->isChecked();
1667 rc.language_auto_begin = autoBeginCB->isChecked();
1668 rc.language_auto_end = autoEndCB->isChecked();
1669 rc.language_use_babel = useBabelCB->isChecked();
1670 rc.language_global_options = globalCB->isChecked();
1671 rc.language_package = fromqstr(languagePackageED->text());
1672 rc.language_command_begin = fromqstr(startCommandED->text());
1673 rc.language_command_end = fromqstr(endCommandED->text());
1674 rc.default_language = fromqstr(
1675 defaultLanguageCO->itemData(defaultLanguageCO->currentIndex()).toString());
1679 void PrefLanguage::update(LyXRC const & rc)
1681 // FIXME: remove rtl_support bool
1682 rtlGB->setChecked(rc.rtl_support);
1683 if (rc.visual_cursor)
1684 visualCursorRB->setChecked(true);
1686 logicalCursorRB->setChecked(true);
1687 markForeignCB->setChecked(rc.mark_foreign_language);
1688 autoBeginCB->setChecked(rc.language_auto_begin);
1689 autoEndCB->setChecked(rc.language_auto_end);
1690 useBabelCB->setChecked(rc.language_use_babel);
1691 globalCB->setChecked(rc.language_global_options);
1692 languagePackageED->setText(toqstr(rc.language_package));
1693 startCommandED->setText(toqstr(rc.language_command_begin));
1694 endCommandED->setText(toqstr(rc.language_command_end));
1696 int const pos = defaultLanguageCO->findData(toqstr(rc.default_language));
1697 defaultLanguageCO->setCurrentIndex(pos);
1701 /////////////////////////////////////////////////////////////////////
1705 /////////////////////////////////////////////////////////////////////
1707 PrefPrinter::PrefPrinter(QWidget * parent)
1708 : PrefModule(qt_(catOutput), qt_("Printer"), 0, parent)
1712 connect(printerAdaptCB, SIGNAL(clicked()),
1713 this, SIGNAL(changed()));
1714 connect(printerCommandED, SIGNAL(textChanged(QString)),
1715 this, SIGNAL(changed()));
1716 connect(printerNameED, SIGNAL(textChanged(QString)),
1717 this, SIGNAL(changed()));
1718 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
1719 this, SIGNAL(changed()));
1720 connect(printerCopiesED, SIGNAL(textChanged(QString)),
1721 this, SIGNAL(changed()));
1722 connect(printerReverseED, SIGNAL(textChanged(QString)),
1723 this, SIGNAL(changed()));
1724 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
1725 this, SIGNAL(changed()));
1726 connect(printerExtensionED, SIGNAL(textChanged(QString)),
1727 this, SIGNAL(changed()));
1728 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
1729 this, SIGNAL(changed()));
1730 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
1731 this, SIGNAL(changed()));
1732 connect(printerEvenED, SIGNAL(textChanged(QString)),
1733 this, SIGNAL(changed()));
1734 connect(printerOddED, SIGNAL(textChanged(QString)),
1735 this, SIGNAL(changed()));
1736 connect(printerCollatedED, SIGNAL(textChanged(QString)),
1737 this, SIGNAL(changed()));
1738 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
1739 this, SIGNAL(changed()));
1740 connect(printerToFileED, SIGNAL(textChanged(QString)),
1741 this, SIGNAL(changed()));
1742 connect(printerExtraED, SIGNAL(textChanged(QString)),
1743 this, SIGNAL(changed()));
1744 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
1745 this, SIGNAL(changed()));
1746 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
1747 this, SIGNAL(changed()));
1751 void PrefPrinter::apply(LyXRC & rc) const
1753 rc.print_adapt_output = printerAdaptCB->isChecked();
1754 rc.print_command = fromqstr(printerCommandED->text());
1755 rc.printer = fromqstr(printerNameED->text());
1757 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1758 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1759 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1760 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1761 rc.print_file_extension = fromqstr(printerExtensionED->text());
1762 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1763 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1764 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1765 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1766 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1767 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1768 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1769 rc.print_extra_options = fromqstr(printerExtraED->text());
1770 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1771 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1775 void PrefPrinter::update(LyXRC const & rc)
1777 printerAdaptCB->setChecked(rc.print_adapt_output);
1778 printerCommandED->setText(toqstr(rc.print_command));
1779 printerNameED->setText(toqstr(rc.printer));
1781 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1782 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1783 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1784 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1785 printerExtensionED->setText(toqstr(rc.print_file_extension));
1786 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1787 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1788 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1789 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1790 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1791 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1792 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1793 printerExtraED->setText(toqstr(rc.print_extra_options));
1794 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1795 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1799 /////////////////////////////////////////////////////////////////////
1801 // PrefUserInterface
1803 /////////////////////////////////////////////////////////////////////
1805 PrefUserInterface::PrefUserInterface(GuiPreferences * form, QWidget * parent)
1806 : PrefModule(qt_(catLookAndFeel), qt_("User interface"), form, parent)
1810 connect(autoSaveCB, SIGNAL(toggled(bool)),
1811 autoSaveSB, SLOT(setEnabled(bool)));
1812 connect(autoSaveCB, SIGNAL(toggled(bool)),
1813 TextLabel1, SLOT(setEnabled(bool)));
1814 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
1815 this, SIGNAL(changed()));
1816 connect(uiFilePB, SIGNAL(clicked()),
1817 this, SLOT(select_ui()));
1818 connect(uiFileED, SIGNAL(textChanged(QString)),
1819 this, SIGNAL(changed()));
1820 connect(restoreCursorCB, SIGNAL(clicked()),
1821 this, SIGNAL(changed()));
1822 connect(loadSessionCB, SIGNAL(clicked()),
1823 this, SIGNAL(changed()));
1824 connect(allowGeometrySessionCB, SIGNAL(clicked()),
1825 this, SIGNAL(changed()));
1826 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1827 this, SIGNAL(changed()));
1828 connect(autoSaveCB, SIGNAL(clicked()),
1829 this, SIGNAL(changed()));
1830 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1831 this, SIGNAL(changed()));
1832 connect(tooltipCB, SIGNAL(toggled(bool)),
1833 this, SIGNAL(changed()));
1834 lastfilesSB->setMaximum(maxlastfiles);
1838 void PrefUserInterface::apply(LyXRC & rc) const
1840 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1841 rc.use_lastfilepos = restoreCursorCB->isChecked();
1842 rc.load_session = loadSessionCB->isChecked();
1843 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
1844 rc.autosave = autoSaveSB->value() * 60;
1845 rc.make_backup = autoSaveCB->isChecked();
1846 rc.num_lastfiles = lastfilesSB->value();
1847 rc.use_tooltip = tooltipCB->isChecked();
1848 rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
1852 void PrefUserInterface::update(LyXRC const & rc)
1854 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1855 restoreCursorCB->setChecked(rc.use_lastfilepos);
1856 loadSessionCB->setChecked(rc.load_session);
1857 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
1858 // convert to minutes
1859 int mins(rc.autosave / 60);
1860 if (rc.autosave && !mins)
1862 autoSaveSB->setValue(mins);
1863 autoSaveCB->setChecked(rc.make_backup);
1864 lastfilesSB->setValue(rc.num_lastfiles);
1865 tooltipCB->setChecked(rc.use_tooltip);
1866 openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
1870 void PrefUserInterface::select_ui()
1872 QString file = form_->browseUI(internalPath(uiFileED->text()));
1873 if (!file.isEmpty())
1874 uiFileED->setText(file);
1877 /////////////////////////////////////////////////////////////////////
1881 /////////////////////////////////////////////////////////////////////
1883 PrefEdit::PrefEdit(GuiPreferences * form, QWidget * parent)
1884 : PrefModule(qt_(catEditing), qt_("Control"), form, parent)
1888 connect(cursorFollowsCB, SIGNAL(clicked()),
1889 this, SIGNAL(changed()));
1890 connect(sortEnvironmentsCB, SIGNAL(clicked()),
1891 this, SIGNAL(changed()));
1892 connect(groupEnvironmentsCB, SIGNAL(clicked()),
1893 this, SIGNAL(changed()));
1894 connect(macroEditStyleCO, SIGNAL(activated(int)),
1895 this, SIGNAL(changed()));
1896 connect(fullscreenLimitGB, SIGNAL(clicked()),
1897 this, SIGNAL(changed()));
1898 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
1899 this, SIGNAL(changed()));
1900 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
1901 this, SIGNAL(changed()));
1902 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
1903 this, SIGNAL(changed()));
1904 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
1905 this, SIGNAL(changed()));
1909 void PrefEdit::apply(LyXRC & rc) const
1911 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1912 rc.sort_layouts = sortEnvironmentsCB->isChecked();
1913 rc.group_layouts = groupEnvironmentsCB->isChecked();
1914 switch (macroEditStyleCO->currentIndex()) {
1915 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
1916 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
1917 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
1919 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
1920 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
1921 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
1922 rc.full_screen_width = fullscreenWidthSB->value();
1923 rc.full_screen_limit = fullscreenLimitGB->isChecked();
1927 void PrefEdit::update(LyXRC const & rc)
1929 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1930 sortEnvironmentsCB->setChecked(rc.sort_layouts);
1931 groupEnvironmentsCB->setChecked(rc.group_layouts);
1932 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
1933 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
1934 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
1935 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
1936 fullscreenWidthSB->setValue(rc.full_screen_width);
1937 fullscreenLimitGB->setChecked(rc.full_screen_limit);
1941 /////////////////////////////////////////////////////////////////////
1945 /////////////////////////////////////////////////////////////////////
1948 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
1950 Ui::shortcutUi::setupUi(this);
1951 QDialog::setModal(true);
1955 PrefShortcuts::PrefShortcuts(GuiPreferences * form, QWidget * parent)
1956 : PrefModule(qt_(catEditing), qt_("Shortcuts"), form, parent)
1960 shortcutsTW->setColumnCount(2);
1961 shortcutsTW->headerItem()->setText(0, qt_("Function"));
1962 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
1963 shortcutsTW->setSortingEnabled(true);
1964 // Multi-selection can be annoying.
1965 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
1967 connect(bindFilePB, SIGNAL(clicked()),
1968 this, SLOT(select_bind()));
1969 connect(bindFileED, SIGNAL(textChanged(QString)),
1970 this, SIGNAL(changed()));
1971 connect(removePB, SIGNAL(clicked()),
1972 this, SIGNAL(changed()));
1974 shortcut_ = new GuiShortcutDialog(this);
1975 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
1976 shortcut_bc_.setOK(shortcut_->okPB);
1977 shortcut_bc_.setCancel(shortcut_->cancelPB);
1979 connect(shortcut_->okPB, SIGNAL(clicked()),
1980 shortcut_, SLOT(accept()));
1981 connect(shortcut_->okPB, SIGNAL(clicked()),
1982 this, SIGNAL(changed()));
1983 connect(shortcut_->cancelPB, SIGNAL(clicked()),
1984 shortcut_, SLOT(reject()));
1985 connect(shortcut_->clearPB, SIGNAL(clicked()),
1986 this, SLOT(shortcut_clearPB_pressed()));
1987 connect(shortcut_->okPB, SIGNAL(clicked()),
1988 this, SLOT(shortcut_okPB_pressed()));
1992 void PrefShortcuts::apply(LyXRC & rc) const
1994 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1995 // write user_bind and user_unbind to .lyx/bind/user.bind
1996 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
1997 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
1998 lyxerr << "LyX could not create the user bind directory '"
1999 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2002 if (!bind_dir.isDirWritable()) {
2003 lyxerr << "LyX could not write to the user bind directory '"
2004 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
2007 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
2008 user_bind_.write(user_bind_file.toFilesystemEncoding(), false, false);
2009 user_unbind_.write(user_bind_file.toFilesystemEncoding(), true, true);
2010 // immediately apply the keybindings. Why this is not done before?
2011 // The good thing is that the menus are updated automatically.
2012 theTopLevelKeymap().clear();
2013 theTopLevelKeymap().read("site");
2014 theTopLevelKeymap().read(rc.bind_file);
2015 theTopLevelKeymap().read("user");
2019 void PrefShortcuts::update(LyXRC const & rc)
2021 bindFileED->setText(toqstr(external_path(rc.bind_file)));
2023 system_bind_.clear();
2025 user_unbind_.clear();
2026 system_bind_.read(rc.bind_file);
2027 // \unbind in user.bind is added to user_unbind_
2028 user_bind_.read("user", &user_unbind_);
2029 updateShortcutsTW();
2033 void PrefShortcuts::updateShortcutsTW()
2035 shortcutsTW->clear();
2037 editItem_ = new QTreeWidgetItem(shortcutsTW);
2038 editItem_->setText(0, qt_("Cursor, Mouse and Editing functions"));
2039 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2041 mathItem_ = new QTreeWidgetItem(shortcutsTW);
2042 mathItem_->setText(0, qt_("Mathematical Symbols"));
2043 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2045 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2046 bufferItem_->setText(0, qt_("Document and Window"));
2047 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2049 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2050 layoutItem_->setText(0, qt_("Font, Layouts and Textclasses"));
2051 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2053 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2054 systemItem_->setText(0, qt_("System and Miscellaneous"));
2055 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2057 // listBindings(unbound=true) lists all bound and unbound lfuns
2058 // Items in this list is tagged by its source.
2059 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2060 static_cast<int>(System));
2061 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2062 static_cast<int>(UserBind));
2063 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2064 static_cast<int>(UserUnbind));
2065 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2066 user_bindinglist.end());
2067 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2068 user_unbindinglist.end());
2070 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2071 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2072 for (; it != it_end; ++it)
2073 insertShortcutItem(it->request, it->sequence, item_type(it->tag));
2075 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2076 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2077 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2078 modifyPB->setEnabled(!items.isEmpty());
2080 shortcutsTW->resizeColumnToContents(0);
2084 void PrefShortcuts::setItemType(QTreeWidgetItem * item, item_type tag)
2086 item->setData(0, Qt::UserRole, QVariant(tag));
2096 font.setStrikeOut(true);
2098 // this item is not displayed now.
2099 case UserExtraUnbind:
2100 font.setStrikeOut(true);
2104 item->setFont(1, font);
2108 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2109 KeySequence const & seq, item_type tag)
2111 FuncCode action = lfun.action;
2112 string const action_name = lyxaction.getActionName(action);
2113 QString const lfun_name = toqstr(from_utf8(action_name)
2114 + ' ' + lfun.argument());
2115 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2116 item_type item_tag = tag;
2118 QTreeWidgetItem * newItem = 0;
2119 // for unbind items, try to find an existing item in the system bind list
2120 if (tag == UserUnbind) {
2121 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2122 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2123 for (int i = 0; i < items.size(); ++i) {
2124 if (items[i]->text(1) == shortcut)
2128 // if not found, this unbind item is UserExtraUnbind
2129 // Such an item is not displayed to avoid confusion (what is
2130 // unmatched removed?).
2132 item_tag = UserExtraUnbind;
2137 switch(lyxaction.getActionType(action)) {
2138 case LyXAction::Hidden:
2140 case LyXAction::Edit:
2141 newItem = new QTreeWidgetItem(editItem_);
2143 case LyXAction::Math:
2144 newItem = new QTreeWidgetItem(mathItem_);
2146 case LyXAction::Buffer:
2147 newItem = new QTreeWidgetItem(bufferItem_);
2149 case LyXAction::Layout:
2150 newItem = new QTreeWidgetItem(layoutItem_);
2152 case LyXAction::System:
2153 newItem = new QTreeWidgetItem(systemItem_);
2156 // this should not happen
2157 newItem = new QTreeWidgetItem(shortcutsTW);
2161 newItem->setText(0, lfun_name);
2162 newItem->setText(1, shortcut);
2163 // record BindFile representation to recover KeySequence when needed.
2164 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2165 setItemType(newItem, item_tag);
2170 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2172 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2173 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2174 modifyPB->setEnabled(!items.isEmpty());
2175 if (items.isEmpty())
2178 item_type tag = static_cast<item_type>(items[0]->data(0, Qt::UserRole).toInt());
2179 if (tag == UserUnbind)
2180 removePB->setText(qt_("Res&tore"));
2182 removePB->setText(qt_("Remo&ve"));
2186 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2192 void PrefShortcuts::modifyShortcut()
2194 QTreeWidgetItem * item = shortcutsTW->currentItem();
2195 if (item->flags() & Qt::ItemIsSelectable) {
2196 shortcut_->lfunLE->setText(item->text(0));
2197 shortcut_->shortcutLE->setText(item->text(1));
2198 shortcut_->shortcutLE->setFocus();
2204 void PrefShortcuts::select_bind()
2206 QString file = form_->browsebind(internalPath(bindFileED->text()));
2207 if (!file.isEmpty()) {
2208 bindFileED->setText(file);
2209 system_bind_ = KeyMap();
2210 system_bind_.read(fromqstr(file));
2211 updateShortcutsTW();
2216 void PrefShortcuts::on_modifyPB_pressed()
2222 void PrefShortcuts::on_newPB_pressed()
2224 shortcut_->lfunLE->clear();
2225 shortcut_->shortcutLE->reset();
2230 void PrefShortcuts::on_removePB_pressed()
2232 // it seems that only one item can be selected, but I am
2233 // removing all selected items anyway.
2234 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2235 for (int i = 0; i < items.size(); ++i) {
2236 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2237 string lfun = fromqstr(items[i]->text(0));
2238 FuncRequest func = lyxaction.lookupFunc(lfun);
2239 item_type tag = static_cast<item_type>(items[i]->data(0, Qt::UserRole).toInt());
2243 // for system bind, we do not touch the item
2244 // but add an user unbind item
2245 user_unbind_.bind(shortcut, func);
2246 setItemType(items[i], UserUnbind);
2247 removePB->setText(qt_("Res&tore"));
2251 // for user_bind, we remove this bind
2252 QTreeWidgetItem * parent = items[i]->parent();
2253 int itemIdx = parent->indexOfChild(items[i]);
2254 parent->takeChild(itemIdx);
2256 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2258 shortcutsTW->scrollToItem(parent);
2259 user_bind_.unbind(shortcut, func);
2263 // for user_unbind, we remove the unbind, and the item
2264 // become System again.
2265 user_unbind_.unbind(shortcut, func);
2266 setItemType(items[i], System);
2267 removePB->setText(qt_("Remo&ve"));
2270 case UserExtraUnbind: {
2271 // for user unbind that is not in system bind file,
2272 // remove this unbind file
2273 QTreeWidgetItem * parent = items[i]->parent();
2274 parent->takeChild(parent->indexOfChild(items[i]));
2275 user_unbind_.unbind(shortcut, func);
2282 void PrefShortcuts::on_searchLE_textEdited()
2284 if (searchLE->text().isEmpty()) {
2285 // show all hidden items
2286 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2288 shortcutsTW->setItemHidden(*it++, false);
2291 // search both columns
2292 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2293 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2294 matched += shortcutsTW->findItems(searchLE->text(),
2295 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2297 // hide everyone (to avoid searching in matched QList repeatedly
2298 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2300 shortcutsTW->setItemHidden(*it++, true);
2301 // show matched items
2302 for (int i = 0; i < matched.size(); ++i) {
2303 shortcutsTW->setItemHidden(matched[i], false);
2304 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2309 void PrefShortcuts::shortcut_okPB_pressed()
2311 string lfun = fromqstr(shortcut_->lfunLE->text());
2312 FuncRequest func = lyxaction.lookupFunc(lfun);
2314 if (func.action == LFUN_UNKNOWN_ACTION) {
2315 Alert::error(_("Failed to create shortcut"),
2316 _("Unknown or invalid LyX function"));
2320 KeySequence k = shortcut_->shortcutLE->getKeySequence();
2321 if (k.length() == 0) {
2322 Alert::error(_("Failed to create shortcut"),
2323 _("Invalid or empty key sequence"));
2327 // if both lfun and shortcut is valid
2328 if (user_bind_.hasBinding(k, func) || system_bind_.hasBinding(k, func)) {
2329 Alert::error(_("Failed to create shortcut"),
2330 _("Shortcut is already defined"));
2334 QTreeWidgetItem * item = insertShortcutItem(func, k, UserBind);
2336 user_bind_.bind(&k, func);
2337 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2338 shortcutsTW->setItemExpanded(item->parent(), true);
2339 shortcutsTW->scrollToItem(item);
2341 Alert::error(_("Failed to create shortcut"),
2342 _("Can not insert shortcut to the list"));
2348 void PrefShortcuts::shortcut_clearPB_pressed()
2350 shortcut_->shortcutLE->reset();
2351 shortcut_->shortcutLE->setFocus();
2355 /////////////////////////////////////////////////////////////////////
2359 /////////////////////////////////////////////////////////////////////
2361 PrefIdentity::PrefIdentity(QWidget * parent)
2362 : PrefModule(QString(), qt_("Identity"), 0, parent)
2366 connect(nameED, SIGNAL(textChanged(QString)),
2367 this, SIGNAL(changed()));
2368 connect(emailED, SIGNAL(textChanged(QString)),
2369 this, SIGNAL(changed()));
2373 void PrefIdentity::apply(LyXRC & rc) const
2375 rc.user_name = fromqstr(nameED->text());
2376 rc.user_email = fromqstr(emailED->text());
2380 void PrefIdentity::update(LyXRC const & rc)
2382 nameED->setText(toqstr(rc.user_name));
2383 emailED->setText(toqstr(rc.user_email));
2388 /////////////////////////////////////////////////////////////////////
2392 /////////////////////////////////////////////////////////////////////
2394 GuiPreferences::GuiPreferences(GuiView & lv)
2395 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2399 QDialog::setModal(false);
2401 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2402 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2403 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2404 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2406 add(new PrefUserInterface(this));
2407 add(new PrefEdit(this));
2408 add(new PrefShortcuts(this));
2409 add(new PrefScreenFonts(this));
2410 add(new PrefColors(this));
2411 add(new PrefDisplay);
2412 add(new PrefInput(this));
2413 add(new PrefCompletion(this));
2415 add(new PrefPaths(this));
2417 add(new PrefIdentity);
2419 add(new PrefLanguage);
2420 add(new PrefSpellchecker(this));
2422 add(new PrefPrinter);
2424 add(new PrefPlaintext);
2425 add(new PrefLatex(this));
2427 PrefConverters * converters = new PrefConverters(this);
2428 PrefFileformats * formats = new PrefFileformats(this);
2429 connect(formats, SIGNAL(formatsChanged()),
2430 converters, SLOT(updateGui()));
2434 prefsPS->setCurrentPanel(qt_("User interface"));
2435 // FIXME: hack to work around resizing bug in Qt >= 4.2
2436 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2437 #if QT_VERSION >= 0x040200
2438 prefsPS->updateGeometry();
2441 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2443 bc().setApply(applyPB);
2444 bc().setCancel(closePB);
2445 bc().setRestore(restorePB);
2449 void GuiPreferences::add(PrefModule * module)
2451 LASSERT(module, /**/);
2452 if (module->category().isEmpty())
2453 prefsPS->addPanel(module, module->title());
2455 prefsPS->addPanel(module, module->title(), module->category());
2456 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2457 modules_.push_back(module);
2461 void GuiPreferences::change_adaptor()
2467 void GuiPreferences::apply(LyXRC & rc) const
2469 size_t end = modules_.size();
2470 for (size_t i = 0; i != end; ++i)
2471 modules_[i]->apply(rc);
2475 void GuiPreferences::updateRc(LyXRC const & rc)
2477 size_t const end = modules_.size();
2478 for (size_t i = 0; i != end; ++i)
2479 modules_[i]->update(rc);
2483 void GuiPreferences::applyView()
2489 void GuiPreferences::updateContents()
2495 bool GuiPreferences::initialiseParams(string const &)
2498 formats_ = lyx::formats;
2499 converters_ = theConverters();
2500 converters_.update(formats_);
2501 movers_ = theMovers();
2503 update_screen_font_ = false;
2509 void GuiPreferences::dispatchParams()
2512 rc_.write(ss, true);
2513 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
2514 // FIXME: these need lfuns
2516 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
2518 lyx::formats = formats_;
2520 theConverters() = converters_;
2521 theConverters().update(lyx::formats);
2522 theConverters().buildGraph();
2524 theMovers() = movers_;
2526 vector<string>::const_iterator it = colors_.begin();
2527 vector<string>::const_iterator const end = colors_.end();
2528 for (; it != end; ++it)
2529 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
2532 if (update_screen_font_) {
2533 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2534 update_screen_font_ = false;
2537 // The Save button has been pressed
2539 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
2543 void GuiPreferences::setColor(ColorCode col, string const & hex)
2545 colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
2549 void GuiPreferences::updateScreenFonts()
2551 update_screen_font_ = true;
2555 QString GuiPreferences::browsebind(QString const & file) const
2557 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
2558 QStringList(qt_("LyX bind files (*.bind)")));
2562 QString GuiPreferences::browseUI(QString const & file) const
2564 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
2565 QStringList(qt_("LyX UI files (*.ui)")));
2569 QString GuiPreferences::browsekbmap(QString const & file) const
2571 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
2572 QStringList(qt_("LyX keyboard maps (*.kmap)")));
2576 QString GuiPreferences::browsedict(QString const & file) const
2578 return browseFile(file, qt_("Choose personal dictionary"),
2579 QStringList(lyxrc.use_spell_lib ? qt_("*.pws") : qt_("*.ispell")));
2583 QString GuiPreferences::browse(QString const & file,
2584 QString const & title) const
2586 return browseFile(file, title, QStringList(), true);
2590 // We support less paper sizes than the document dialog
2591 // Therefore this adjustment is needed.
2592 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
2596 return PAPER_DEFAULT;
2598 return PAPER_USLETTER;
2600 return PAPER_USLEGAL;
2602 return PAPER_USEXECUTIVE;
2612 // should not happen
2613 return PAPER_DEFAULT;
2618 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
2620 switch (papersize) {
2623 case PAPER_USLETTER:
2627 case PAPER_USEXECUTIVE:
2638 // should not happen
2644 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
2647 } // namespace frontend
2650 #include "GuiPrefs_moc.cpp"