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 static int findPos_helper(QStringList const & vec, QString const & val)
215 for (int i = 0; i != vec.size(); ++i)
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 lyxerr << "FAILED to find the default font: '"
295 << foundry << "', '" << family << '\''<< endl;
299 QFontInfo info(font);
300 string default_font_name, dummyfoundry;
301 parseFontName(info.family(), default_font_name, dummyfoundry);
302 lyxerr << "Apparent font is " << default_font_name << endl;
304 for (int i = 0; i < cb->count(); ++i) {
305 lyxerr << "Looking at " << fromqstr(cb->itemText(i)) << endl;
306 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
307 default_font_name) == 0) {
308 cb->setCurrentIndex(i);
313 lyxerr << "FAILED to find the font: '"
314 << foundry << "', '" << family << '\'' <<endl;
318 /////////////////////////////////////////////////////////////////////
322 /////////////////////////////////////////////////////////////////////
324 PrefPlaintext::PrefPlaintext(QWidget * parent)
325 : PrefModule(qt_("Plain text"), 0, parent)
328 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
329 this, SIGNAL(changed()));
330 connect(plaintextRoffED, SIGNAL(textChanged(QString)),
331 this, SIGNAL(changed()));
335 void PrefPlaintext::apply(LyXRC & rc) const
337 rc.plaintext_linelen = plaintextLinelengthSB->value();
338 rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
342 void PrefPlaintext::update(LyXRC const & rc)
344 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
345 plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
349 /////////////////////////////////////////////////////////////////////
353 /////////////////////////////////////////////////////////////////////
355 PrefDate::PrefDate(QWidget * parent)
356 : PrefModule(qt_("Date format"), 0, parent)
359 connect(DateED, SIGNAL(textChanged(QString)),
360 this, SIGNAL(changed()));
364 void PrefDate::apply(LyXRC & rc) const
366 rc.date_insert_format = fromqstr(DateED->text());
370 void PrefDate::update(LyXRC const & rc)
372 DateED->setText(toqstr(rc.date_insert_format));
376 /////////////////////////////////////////////////////////////////////
380 /////////////////////////////////////////////////////////////////////
382 PrefInput::PrefInput(GuiPreferences * form, QWidget * parent)
383 : PrefModule(qt_("Keyboard/Mouse"), form, parent)
387 connect(keymapCB, SIGNAL(clicked()),
388 this, SIGNAL(changed()));
389 connect(firstKeymapED, SIGNAL(textChanged(QString)),
390 this, SIGNAL(changed()));
391 connect(secondKeymapED, SIGNAL(textChanged(QString)),
392 this, SIGNAL(changed()));
393 connect(inlineDelaySB, SIGNAL(valueChanged(double)),
394 this, SIGNAL(changed()));
395 connect(inlineMathCB, SIGNAL(clicked()),
396 this, SIGNAL(changed()));
397 connect(inlineTextCB, SIGNAL(clicked()),
398 this, SIGNAL(changed()));
399 connect(inlineDotsCB, SIGNAL(clicked()),
400 this, SIGNAL(changed()));
401 connect(popupDelaySB, SIGNAL(valueChanged(double)),
402 this, SIGNAL(changed()));
403 connect(popupMathCB, SIGNAL(clicked()),
404 this, SIGNAL(changed()));
405 connect(popupTextCB, SIGNAL(clicked()),
406 this, SIGNAL(changed()));
407 connect(popupAfterCompleteCB, SIGNAL(clicked()),
408 this, SIGNAL(changed()));
409 connect(cursorTextCB, SIGNAL(clicked()),
410 this, SIGNAL(changed()));
411 connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
412 this, SIGNAL(changed()));
416 void PrefInput::apply(LyXRC & rc) const
418 // FIXME: can derive CB from the two EDs
419 rc.use_kbmap = keymapCB->isChecked();
420 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
421 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
422 rc.completion_inline_delay = inlineDelaySB->value();
423 rc.completion_inline_math = inlineMathCB->isChecked();
424 rc.completion_inline_text = inlineTextCB->isChecked();
425 rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
426 rc.completion_popup_delay = popupDelaySB->value();
427 rc.completion_popup_math = popupMathCB->isChecked();
428 rc.completion_popup_text = popupTextCB->isChecked();
429 rc.completion_cursor_text = cursorTextCB->isChecked();
430 rc.completion_popup_after_complete
431 = popupAfterCompleteCB->isChecked();
432 rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
436 void PrefInput::update(LyXRC const & rc)
438 // FIXME: can derive CB from the two EDs
439 keymapCB->setChecked(rc.use_kbmap);
440 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
441 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
442 inlineDelaySB->setValue(rc.completion_inline_delay);
443 inlineMathCB->setChecked(rc.completion_inline_math);
444 inlineTextCB->setChecked(rc.completion_inline_text);
445 inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
446 popupDelaySB->setValue(rc.completion_popup_delay);
447 popupMathCB->setChecked(rc.completion_popup_math);
448 popupTextCB->setChecked(rc.completion_popup_text);
449 cursorTextCB->setChecked(rc.completion_cursor_text);
450 popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
451 mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
455 QString PrefInput::testKeymap(QString keymap)
457 return form_->browsekbmap(toqstr(internal_path(fromqstr(keymap))));
461 void PrefInput::on_firstKeymapPB_clicked(bool)
463 QString const file = testKeymap(firstKeymapED->text());
465 firstKeymapED->setText(file);
469 void PrefInput::on_secondKeymapPB_clicked(bool)
471 QString const file = testKeymap(secondKeymapED->text());
473 secondKeymapED->setText(file);
477 void PrefInput::on_keymapCB_toggled(bool keymap)
479 firstKeymapLA->setEnabled(keymap);
480 secondKeymapLA->setEnabled(keymap);
481 firstKeymapED->setEnabled(keymap);
482 secondKeymapED->setEnabled(keymap);
483 firstKeymapPB->setEnabled(keymap);
484 secondKeymapPB->setEnabled(keymap);
488 /////////////////////////////////////////////////////////////////////
492 /////////////////////////////////////////////////////////////////////
494 PrefLatex::PrefLatex(GuiPreferences * form, QWidget * parent)
495 : PrefModule(qt_("LaTeX"), form, parent)
498 connect(latexEncodingED, SIGNAL(textChanged(QString)),
499 this, SIGNAL(changed()));
500 connect(latexChecktexED, SIGNAL(textChanged(QString)),
501 this, SIGNAL(changed()));
502 connect(latexBibtexED, SIGNAL(textChanged(QString)),
503 this, SIGNAL(changed()));
504 connect(latexIndexED, SIGNAL(textChanged(QString)),
505 this, SIGNAL(changed()));
506 connect(latexAutoresetCB, SIGNAL(clicked()),
507 this, SIGNAL(changed()));
508 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
509 this, SIGNAL(changed()));
510 connect(latexPaperSizeCO, SIGNAL(activated(int)),
511 this, SIGNAL(changed()));
513 #if defined(__CYGWIN__) || defined(_WIN32)
514 pathCB->setVisible(true);
515 connect(pathCB, SIGNAL(clicked()),
516 this, SIGNAL(changed()));
518 pathCB->setVisible(false);
523 void PrefLatex::apply(LyXRC & rc) const
525 rc.fontenc = fromqstr(latexEncodingED->text());
526 rc.chktex_command = fromqstr(latexChecktexED->text());
527 rc.bibtex_command = fromqstr(latexBibtexED->text());
528 rc.index_command = fromqstr(latexIndexED->text());
529 rc.auto_reset_options = latexAutoresetCB->isChecked();
530 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
531 rc.default_papersize =
532 form_->toPaperSize(latexPaperSizeCO->currentIndex());
533 #if defined(__CYGWIN__) || defined(_WIN32)
534 rc.windows_style_tex_paths = pathCB->isChecked();
539 void PrefLatex::update(LyXRC const & rc)
541 latexEncodingED->setText(toqstr(rc.fontenc));
542 latexChecktexED->setText(toqstr(rc.chktex_command));
543 latexBibtexED->setText(toqstr(rc.bibtex_command));
544 latexIndexED->setText(toqstr(rc.index_command));
545 latexAutoresetCB->setChecked(rc.auto_reset_options);
546 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
547 latexPaperSizeCO->setCurrentIndex(
548 form_->fromPaperSize(rc.default_papersize));
549 #if defined(__CYGWIN__) || defined(_WIN32)
550 pathCB->setChecked(rc.windows_style_tex_paths);
555 /////////////////////////////////////////////////////////////////////
559 /////////////////////////////////////////////////////////////////////
561 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form, QWidget * parent)
562 : PrefModule(qt_("Screen fonts"), form, parent)
566 connect(screenRomanCO, SIGNAL(activated(QString)),
567 this, SLOT(select_roman(QString)));
568 connect(screenSansCO, SIGNAL(activated(QString)),
569 this, SLOT(select_sans(QString)));
570 connect(screenTypewriterCO, SIGNAL(activated(QString)),
571 this, SLOT(select_typewriter(QString)));
573 QFontDatabase fontdb;
574 QStringList families(fontdb.families());
575 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
576 screenRomanCO->addItem(*it);
577 screenSansCO->addItem(*it);
578 screenTypewriterCO->addItem(*it);
580 connect(screenRomanCO, SIGNAL(activated(QString)),
581 this, SIGNAL(changed()));
582 connect(screenSansCO, SIGNAL(activated(QString)),
583 this, SIGNAL(changed()));
584 connect(screenTypewriterCO, SIGNAL(activated(QString)),
585 this, SIGNAL(changed()));
586 connect(screenZoomSB, SIGNAL(valueChanged(int)),
587 this, SIGNAL(changed()));
588 connect(screenDpiSB, SIGNAL(valueChanged(int)),
589 this, SIGNAL(changed()));
590 connect(screenTinyED, SIGNAL(textChanged(QString)),
591 this, SIGNAL(changed()));
592 connect(screenSmallestED, SIGNAL(textChanged(QString)),
593 this, SIGNAL(changed()));
594 connect(screenSmallerED, SIGNAL(textChanged(QString)),
595 this, SIGNAL(changed()));
596 connect(screenSmallED, SIGNAL(textChanged(QString)),
597 this, SIGNAL(changed()));
598 connect(screenNormalED, SIGNAL(textChanged(QString)),
599 this, SIGNAL(changed()));
600 connect(screenLargeED, SIGNAL(textChanged(QString)),
601 this, SIGNAL(changed()));
602 connect(screenLargerED, SIGNAL(textChanged(QString)),
603 this, SIGNAL(changed()));
604 connect(screenLargestED, SIGNAL(textChanged(QString)),
605 this, SIGNAL(changed()));
606 connect(screenHugeED, SIGNAL(textChanged(QString)),
607 this, SIGNAL(changed()));
608 connect(screenHugerED, SIGNAL(textChanged(QString)),
609 this, SIGNAL(changed()));
610 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
611 this, SIGNAL(changed()));
613 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
614 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
615 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
616 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
617 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
618 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
619 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
620 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
621 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
622 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
626 void PrefScreenFonts::apply(LyXRC & rc) const
628 LyXRC const oldrc = rc;
630 parseFontName(screenRomanCO->currentText(),
631 rc.roman_font_name, rc.roman_font_foundry);
632 parseFontName(screenSansCO->currentText(),
633 rc.sans_font_name, rc.sans_font_foundry);
634 parseFontName(screenTypewriterCO->currentText(),
635 rc.typewriter_font_name, rc.typewriter_font_foundry);
637 rc.zoom = screenZoomSB->value();
638 rc.dpi = screenDpiSB->value();
639 rc.font_sizes[FONT_SIZE_TINY] = fromqstr(screenTinyED->text());
640 rc.font_sizes[FONT_SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
641 rc.font_sizes[FONT_SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
642 rc.font_sizes[FONT_SIZE_SMALL] = fromqstr(screenSmallED->text());
643 rc.font_sizes[FONT_SIZE_NORMAL] = fromqstr(screenNormalED->text());
644 rc.font_sizes[FONT_SIZE_LARGE] = fromqstr(screenLargeED->text());
645 rc.font_sizes[FONT_SIZE_LARGER] = fromqstr(screenLargerED->text());
646 rc.font_sizes[FONT_SIZE_LARGEST] = fromqstr(screenLargestED->text());
647 rc.font_sizes[FONT_SIZE_HUGE] = fromqstr(screenHugeED->text());
648 rc.font_sizes[FONT_SIZE_HUGER] = fromqstr(screenHugerED->text());
649 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
651 if (rc.font_sizes != oldrc.font_sizes
652 || rc.roman_font_name != oldrc.roman_font_name
653 || rc.sans_font_name != oldrc.sans_font_name
654 || rc.typewriter_font_name != oldrc.typewriter_font_name
655 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
656 // The global QPixmapCache is used in GuiPainter to cache text
657 // painting so we must reset it in case any of the above
658 // parameter is changed.
659 QPixmapCache::clear();
660 guiApp->fontLoader().update();
661 form_->updateScreenFonts();
666 void PrefScreenFonts::update(LyXRC const & rc)
668 setComboxFont(screenRomanCO, rc.roman_font_name,
669 rc.roman_font_foundry);
670 setComboxFont(screenSansCO, rc.sans_font_name,
671 rc.sans_font_foundry);
672 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
673 rc.typewriter_font_foundry);
675 select_roman(screenRomanCO->currentText());
676 select_sans(screenSansCO->currentText());
677 select_typewriter(screenTypewriterCO->currentText());
679 screenZoomSB->setValue(rc.zoom);
680 screenDpiSB->setValue(rc.dpi);
681 screenTinyED->setText(toqstr(rc.font_sizes[FONT_SIZE_TINY]));
682 screenSmallestED->setText(toqstr(rc.font_sizes[FONT_SIZE_SCRIPT]));
683 screenSmallerED->setText(toqstr(rc.font_sizes[FONT_SIZE_FOOTNOTE]));
684 screenSmallED->setText(toqstr(rc.font_sizes[FONT_SIZE_SMALL]));
685 screenNormalED->setText(toqstr(rc.font_sizes[FONT_SIZE_NORMAL]));
686 screenLargeED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGE]));
687 screenLargerED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGER]));
688 screenLargestED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGEST]));
689 screenHugeED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGE]));
690 screenHugerED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGER]));
692 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
693 #if defined(Q_WS_X11)
694 pixmapCacheCB->setEnabled(false);
700 void PrefScreenFonts::select_roman(const QString & name)
702 screenRomanFE->set(QFont(name), name);
706 void PrefScreenFonts::select_sans(const QString & name)
708 screenSansFE->set(QFont(name), name);
712 void PrefScreenFonts::select_typewriter(const QString & name)
714 screenTypewriterFE->set(QFont(name), name);
718 /////////////////////////////////////////////////////////////////////
722 /////////////////////////////////////////////////////////////////////
728 bool operator()(ColorCode lhs, ColorCode rhs) const {
729 return lcolor.getGUIName(lhs) < lcolor.getGUIName(rhs);
735 PrefColors::PrefColors(GuiPreferences * form, QWidget * parent)
736 : PrefModule(qt_("Colors"), form, parent)
740 // FIXME: all of this initialization should be put into the controller.
741 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
742 // for some discussion of why that is not trivial.
743 QPixmap icon(32, 32);
744 for (int i = 0; i < Color_ignore; ++i) {
745 ColorCode lc = static_cast<ColorCode>(i);
753 || lc == Color_magenta
754 || lc == Color_yellow
755 || lc == Color_inherit
756 || lc == Color_ignore) continue;
758 lcolors_.push_back(lc);
760 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
761 vector<ColorCode>::const_iterator cit = lcolors_.begin();
762 vector<ColorCode>::const_iterator const end = lcolors_.end();
763 for (; cit != end; ++cit) {
764 (void) new QListWidgetItem(QIcon(icon),
765 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
767 curcolors_.resize(lcolors_.size());
768 newcolors_.resize(lcolors_.size());
769 // End initialization
771 connect(colorChangePB, SIGNAL(clicked()),
772 this, SLOT(change_color()));
773 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
774 this, SLOT(change_lyxObjects_selection()));
775 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
776 this, SLOT(change_color()));
780 void PrefColors::apply(LyXRC & /*rc*/) const
782 for (unsigned int i = 0; i < lcolors_.size(); ++i)
783 if (curcolors_[i] != newcolors_[i])
784 form_->setColor(lcolors_[i], fromqstr(newcolors_[i]));
788 void PrefColors::update(LyXRC const & /*rc*/)
790 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
791 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
792 QPixmap coloritem(32, 32);
793 coloritem.fill(color);
794 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
795 newcolors_[i] = curcolors_[i] = color.name();
797 change_lyxObjects_selection();
801 void PrefColors::change_color()
803 int const row = lyxObjectsLW->currentRow();
809 QString const color = newcolors_[row];
810 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
812 if (c.isValid() && c.name() != color) {
813 newcolors_[row] = c.name();
814 QPixmap coloritem(32, 32);
816 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
822 void PrefColors::change_lyxObjects_selection()
824 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
828 /////////////////////////////////////////////////////////////////////
832 /////////////////////////////////////////////////////////////////////
834 PrefDisplay::PrefDisplay(QWidget * parent)
835 : PrefModule(qt_("Graphics"), 0, parent)
838 connect(instantPreviewCO, SIGNAL(activated(int)),
839 this, SIGNAL(changed()));
840 connect(displayGraphicsCO, SIGNAL(activated(int)),
841 this, SIGNAL(changed()));
845 void PrefDisplay::apply(LyXRC & rc) const
847 switch (instantPreviewCO->currentIndex()) {
848 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
849 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
850 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
853 graphics::DisplayType dtype;
854 switch (displayGraphicsCO->currentIndex()) {
855 case 3: dtype = graphics::NoDisplay; break;
856 case 2: dtype = graphics::ColorDisplay; break;
857 case 1: dtype = graphics::GrayscaleDisplay; break;
858 case 0: dtype = graphics::MonochromeDisplay; break;
859 default: dtype = graphics::GrayscaleDisplay;
861 rc.display_graphics = dtype;
863 // FIXME!! The graphics cache no longer has a changeDisplay method.
865 if (old_value != rc.display_graphics) {
866 graphics::GCache & gc = graphics::GCache::get();
873 void PrefDisplay::update(LyXRC const & rc)
875 switch (rc.preview) {
876 case LyXRC::PREVIEW_OFF:
877 instantPreviewCO->setCurrentIndex(0);
879 case LyXRC::PREVIEW_NO_MATH :
880 instantPreviewCO->setCurrentIndex(1);
882 case LyXRC::PREVIEW_ON :
883 instantPreviewCO->setCurrentIndex(2);
888 switch (rc.display_graphics) {
889 case graphics::NoDisplay: item = 3; break;
890 case graphics::ColorDisplay: item = 2; break;
891 case graphics::GrayscaleDisplay: item = 1; break;
892 case graphics::MonochromeDisplay: item = 0; break;
895 displayGraphicsCO->setCurrentIndex(item);
899 /////////////////////////////////////////////////////////////////////
903 /////////////////////////////////////////////////////////////////////
905 PrefPaths::PrefPaths(GuiPreferences * form, QWidget * parent)
906 : PrefModule(qt_("Paths"), form, parent)
909 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(select_exampledir()));
910 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
911 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
912 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
913 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
914 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
915 connect(workingDirED, SIGNAL(textChanged(QString)),
916 this, SIGNAL(changed()));
917 connect(exampleDirED, SIGNAL(textChanged(QString)),
918 this, SIGNAL(changed()));
919 connect(templateDirED, SIGNAL(textChanged(QString)),
920 this, SIGNAL(changed()));
921 connect(backupDirED, SIGNAL(textChanged(QString)),
922 this, SIGNAL(changed()));
923 connect(tempDirED, SIGNAL(textChanged(QString)),
924 this, SIGNAL(changed()));
925 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
926 this, SIGNAL(changed()));
927 connect(pathPrefixED, SIGNAL(textChanged(QString)),
928 this, SIGNAL(changed()));
932 void PrefPaths::apply(LyXRC & rc) const
934 rc.document_path = internal_path(fromqstr(workingDirED->text()));
935 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
936 rc.template_path = internal_path(fromqstr(templateDirED->text()));
937 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
938 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
939 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
940 // FIXME: should be a checkbox only
941 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
945 void PrefPaths::update(LyXRC const & rc)
947 workingDirED->setText(toqstr(external_path(rc.document_path)));
948 exampleDirED->setText(toqstr(external_path(rc.example_path)));
949 templateDirED->setText(toqstr(external_path(rc.template_path)));
950 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
951 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
952 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
953 // FIXME: should be a checkbox only
954 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
958 void PrefPaths::select_exampledir()
960 QString file = form_->browsedir(internalPath(exampleDirED->text()),
961 qt_("Select directory for example files"));
963 exampleDirED->setText(file);
967 void PrefPaths::select_templatedir()
969 QString file = form_->browsedir(internalPath(templateDirED->text()),
970 qt_("Select a document templates directory"));
972 templateDirED->setText(file);
976 void PrefPaths::select_tempdir()
978 QString file = form_->browsedir(internalPath(tempDirED->text()),
979 qt_("Select a temporary directory"));
981 tempDirED->setText(file);
985 void PrefPaths::select_backupdir()
987 QString file = form_->browsedir(internalPath(backupDirED->text()),
988 qt_("Select a backups directory"));
990 backupDirED->setText(file);
994 void PrefPaths::select_workingdir()
996 QString file = form_->browsedir(internalPath(workingDirED->text()),
997 qt_("Select a document directory"));
999 workingDirED->setText(file);
1003 void PrefPaths::select_lyxpipe()
1005 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1006 qt_("Give a filename for the LyX server pipe"));
1007 if (!file.isEmpty())
1008 lyxserverDirED->setText(file);
1012 /////////////////////////////////////////////////////////////////////
1016 /////////////////////////////////////////////////////////////////////
1018 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form, QWidget * parent)
1019 : PrefModule(qt_("Spellchecker"), form, parent)
1023 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
1024 #if defined (USE_ISPELL)
1025 connect(spellCommandCO, SIGNAL(activated(int)),
1026 this, SIGNAL(changed()));
1028 spellCommandCO->setEnabled(false);
1030 connect(altLanguageED, SIGNAL(textChanged(QString)),
1031 this, SIGNAL(changed()));
1032 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1033 this, SIGNAL(changed()));
1034 connect(persDictionaryED, SIGNAL(textChanged(QString)),
1035 this, SIGNAL(changed()));
1036 connect(compoundWordCB, SIGNAL(clicked()),
1037 this, SIGNAL(changed()));
1038 connect(inputEncodingCB, SIGNAL(clicked()),
1039 this, SIGNAL(changed()));
1041 spellCommandCO->addItem(qt_("ispell"));
1042 spellCommandCO->addItem(qt_("aspell"));
1043 spellCommandCO->addItem(qt_("hspell"));
1045 spellCommandCO->addItem(qt_("pspell (library)"));
1048 spellCommandCO->addItem(qt_("aspell (library)"));
1054 void PrefSpellchecker::apply(LyXRC & rc) const
1056 switch (spellCommandCO->currentIndex()) {
1060 rc.use_spell_lib = false;
1061 rc.isp_command = fromqstr(spellCommandCO->currentText());
1064 rc.use_spell_lib = true;
1068 // FIXME: remove isp_use_alt_lang
1069 rc.isp_alt_lang = fromqstr(altLanguageED->text());
1070 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
1071 // FIXME: remove isp_use_esc_chars
1072 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
1073 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
1074 // FIXME: remove isp_use_pers_dict
1075 rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
1076 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
1077 rc.isp_accept_compound = compoundWordCB->isChecked();
1078 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
1082 void PrefSpellchecker::update(LyXRC const & rc)
1084 spellCommandCO->setCurrentIndex(0);
1086 if (rc.isp_command == "ispell") {
1087 spellCommandCO->setCurrentIndex(0);
1088 } else if (rc.isp_command == "aspell") {
1089 spellCommandCO->setCurrentIndex(1);
1090 } else if (rc.isp_command == "hspell") {
1091 spellCommandCO->setCurrentIndex(2);
1094 if (rc.use_spell_lib) {
1095 #if defined(USE_ASPELL) || defined(USE_PSPELL)
1096 spellCommandCO->setCurrentIndex(3);
1100 // FIXME: remove isp_use_alt_lang
1101 altLanguageED->setText(toqstr(rc.isp_alt_lang));
1102 // FIXME: remove isp_use_esc_chars
1103 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
1104 // FIXME: remove isp_use_pers_dict
1105 persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
1106 compoundWordCB->setChecked(rc.isp_accept_compound);
1107 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
1111 void PrefSpellchecker::select_dict()
1113 QString file = form_->browsedict(internalPath(persDictionaryED->text()));
1114 if (!file.isEmpty())
1115 persDictionaryED->setText(file);
1120 /////////////////////////////////////////////////////////////////////
1124 /////////////////////////////////////////////////////////////////////
1127 PrefConverters::PrefConverters(GuiPreferences * form, QWidget * parent)
1128 : PrefModule(qt_("Converters"), form, parent)
1132 connect(converterNewPB, SIGNAL(clicked()),
1133 this, SLOT(update_converter()));
1134 connect(converterRemovePB, SIGNAL(clicked()),
1135 this, SLOT(remove_converter()));
1136 connect(converterModifyPB, SIGNAL(clicked()),
1137 this, SLOT(update_converter()));
1138 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1139 this, SLOT(switch_converter()));
1140 connect(converterFromCO, SIGNAL(activated(QString)),
1141 this, SLOT(converter_changed()));
1142 connect(converterToCO, SIGNAL(activated(QString)),
1143 this, SLOT(converter_changed()));
1144 connect(converterED, SIGNAL(textEdited(QString)),
1145 this, SLOT(converter_changed()));
1146 connect(converterFlagED, SIGNAL(textEdited(QString)),
1147 this, SLOT(converter_changed()));
1148 connect(converterNewPB, SIGNAL(clicked()),
1149 this, SIGNAL(changed()));
1150 connect(converterRemovePB, SIGNAL(clicked()),
1151 this, SIGNAL(changed()));
1152 connect(converterModifyPB, SIGNAL(clicked()),
1153 this, SIGNAL(changed()));
1154 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1155 this, SIGNAL(changed()));
1157 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1158 //converterDefGB->setFocusProxy(convertersLW);
1162 void PrefConverters::apply(LyXRC & rc) const
1164 rc.use_converter_cache = cacheCB->isChecked();
1165 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
1169 void PrefConverters::update(LyXRC const & rc)
1171 cacheCB->setChecked(rc.use_converter_cache);
1173 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
1174 maxAgeLE->setText(max_age);
1179 void PrefConverters::updateGui()
1181 form_->formats().sort();
1182 form_->converters().update(form_->formats());
1183 // save current selection
1184 QString current = converterFromCO->currentText()
1185 + " -> " + converterToCO->currentText();
1187 converterFromCO->clear();
1188 converterToCO->clear();
1190 Formats::const_iterator cit = form_->formats().begin();
1191 Formats::const_iterator end = form_->formats().end();
1192 for (; cit != end; ++cit) {
1193 converterFromCO->addItem(toqstr(cit->prettyname()));
1194 converterToCO->addItem(toqstr(cit->prettyname()));
1197 // currentRowChanged(int) is also triggered when updating the listwidget
1198 // block signals to avoid unnecessary calls to switch_converter()
1199 convertersLW->blockSignals(true);
1200 convertersLW->clear();
1202 Converters::const_iterator ccit = form_->converters().begin();
1203 Converters::const_iterator cend = form_->converters().end();
1204 for (; ccit != cend; ++ccit) {
1206 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
1207 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1208 new QListWidgetItem(toqstr(name), convertersLW, type);
1210 convertersLW->sortItems(Qt::AscendingOrder);
1211 convertersLW->blockSignals(false);
1213 // restore selection
1214 if (!current.isEmpty()) {
1215 QList<QListWidgetItem *> const item =
1216 convertersLW->findItems(current, Qt::MatchExactly);
1217 if (!item.isEmpty())
1218 convertersLW->setCurrentItem(item.at(0));
1221 // select first element if restoring failed
1222 if (convertersLW->currentRow() == -1)
1223 convertersLW->setCurrentRow(0);
1229 void PrefConverters::switch_converter()
1231 int const cnr = convertersLW->currentItem()->type();
1232 Converter const & c(form_->converters().get(cnr));
1233 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1234 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1235 converterED->setText(toqstr(c.command));
1236 converterFlagED->setText(toqstr(c.flags));
1242 void PrefConverters::converter_changed()
1248 void PrefConverters::updateButtons()
1250 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1251 Format const & to = form_->formats().get(converterToCO->currentIndex());
1252 int const sel = form_->converters().getNumber(from.name(), to.name());
1253 bool const known = sel >= 0;
1254 bool const valid = !(converterED->text().isEmpty()
1255 || from.name() == to.name());
1257 int const cnr = convertersLW->currentItem()->type();
1258 Converter const & c(form_->converters().get(cnr));
1259 string const old_command = c.command;
1260 string const old_flag = c.flags;
1261 string const new_command(fromqstr(converterED->text()));
1262 string const new_flag(fromqstr(converterFlagED->text()));
1264 bool modified = (old_command != new_command) || (old_flag != new_flag);
1266 converterModifyPB->setEnabled(valid && known && modified);
1267 converterNewPB->setEnabled(valid && !known);
1268 converterRemovePB->setEnabled(known);
1270 maxAgeLE->setEnabled(cacheCB->isChecked());
1271 maxAgeLA->setEnabled(cacheCB->isChecked());
1276 // specify unique from/to or it doesn't appear. This is really bad UI
1277 // this is why we can use the same function for both new and modify
1278 void PrefConverters::update_converter()
1280 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1281 Format const & to = form_->formats().get(converterToCO->currentIndex());
1282 string const flags = fromqstr(converterFlagED->text());
1283 string const command = fromqstr(converterED->text());
1285 Converter const * old =
1286 form_->converters().getConverter(from.name(), to.name());
1287 form_->converters().add(from.name(), to.name(), command, flags);
1290 form_->converters().updateLast(form_->formats());
1294 // Remove all files created by this converter from the cache, since
1295 // the modified converter might create different files.
1296 ConverterCache::get().remove_all(from.name(), to.name());
1300 void PrefConverters::remove_converter()
1302 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1303 Format const & to = form_->formats().get(converterToCO->currentIndex());
1304 form_->converters().erase(from.name(), to.name());
1308 // Remove all files created by this converter from the cache, since
1309 // a possible new converter might create different files.
1310 ConverterCache::get().remove_all(from.name(), to.name());
1314 void PrefConverters::on_cacheCB_stateChanged(int state)
1316 maxAgeLE->setEnabled(state == Qt::Checked);
1317 maxAgeLA->setEnabled(state == Qt::Checked);
1322 /////////////////////////////////////////////////////////////////////
1326 /////////////////////////////////////////////////////////////////////
1328 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1329 : QValidator(parent), formats_(f)
1334 void FormatValidator::fixup(QString & input) const
1336 Formats::const_iterator cit = formats_.begin();
1337 Formats::const_iterator end = formats_.end();
1338 for (; cit != end; ++cit) {
1339 string const name = str(cit);
1340 if (distance(formats_.begin(), cit) == nr()) {
1341 input = toqstr(name);
1349 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1351 Formats::const_iterator cit = formats_.begin();
1352 Formats::const_iterator end = formats_.end();
1353 bool unknown = true;
1354 for (; unknown && cit != end; ++cit) {
1355 string const name = str(cit);
1356 if (distance(formats_.begin(), cit) != nr())
1357 unknown = toqstr(name) != input;
1360 if (unknown && !input.isEmpty())
1361 return QValidator::Acceptable;
1363 return QValidator::Intermediate;
1367 int FormatValidator::nr() const
1369 QComboBox * p = qobject_cast<QComboBox *>(parent());
1370 return p->itemData(p->currentIndex()).toInt();
1374 FormatNameValidator::FormatNameValidator(QWidget * parent, Formats const & f)
1375 : FormatValidator(parent, f)
1379 string FormatNameValidator::str(Formats::const_iterator it) const
1385 FormatPrettynameValidator::FormatPrettynameValidator(QWidget * parent, Formats const & f)
1386 : FormatValidator(parent, f)
1391 string FormatPrettynameValidator::str(Formats::const_iterator it) const
1393 return it->prettyname();
1397 PrefFileformats::PrefFileformats(GuiPreferences * form, QWidget * parent)
1398 : PrefModule(qt_("File formats"), form, parent)
1401 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1402 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1404 connect(documentCB, SIGNAL(clicked()),
1405 this, SLOT(setFlags()));
1406 connect(vectorCB, SIGNAL(clicked()),
1407 this, SLOT(setFlags()));
1408 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1409 this, SLOT(updatePrettyname()));
1410 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1411 this, SIGNAL(changed()));
1415 void PrefFileformats::apply(LyXRC & /*rc*/) const
1420 void PrefFileformats::update(LyXRC const & /*rc*/)
1426 void PrefFileformats::updateView()
1428 QString const current = formatsCB->currentText();
1430 // update combobox with formats
1431 formatsCB->blockSignals(true);
1433 form_->formats().sort();
1434 Formats::const_iterator cit = form_->formats().begin();
1435 Formats::const_iterator end = form_->formats().end();
1436 for (; cit != end; ++cit)
1437 formatsCB->addItem(toqstr(cit->prettyname()),
1438 QVariant(form_->formats().getNumber(cit->name())) );
1440 // restore selection
1441 int const item = formatsCB->findText(current, Qt::MatchExactly);
1442 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1443 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1444 formatsCB->blockSignals(false);
1448 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1450 int const nr = formatsCB->itemData(i).toInt();
1451 Format const f = form_->formats().get(nr);
1453 formatED->setText(toqstr(f.name()));
1454 copierED->setText(toqstr(form_->movers().command(f.name())));
1455 extensionED->setText(toqstr(f.extension()));
1456 shortcutED->setText(toqstr(f.shortcut()));
1457 viewerED->setText(toqstr(f.viewer()));
1458 editorED->setText(toqstr(f.editor()));
1459 documentCB->setChecked((f.documentFormat()));
1460 vectorCB->setChecked((f.vectorFormat()));
1464 void PrefFileformats::setFlags()
1466 int flags = Format::none;
1467 if (documentCB->isChecked())
1468 flags |= Format::document;
1469 if (vectorCB->isChecked())
1470 flags |= Format::vector;
1471 currentFormat().setFlags(flags);
1476 void PrefFileformats::on_copierED_textEdited(const QString & s)
1478 string const fmt = fromqstr(formatED->text());
1479 form_->movers().set(fmt, fromqstr(s));
1484 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1486 currentFormat().setExtension(fromqstr(s));
1490 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1492 currentFormat().setViewer(fromqstr(s));
1497 void PrefFileformats::on_editorED_textEdited(const QString & s)
1499 currentFormat().setEditor(fromqstr(s));
1504 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1506 currentFormat().setShortcut(fromqstr(s));
1511 void PrefFileformats::on_formatED_editingFinished()
1513 string const newname = fromqstr(formatED->displayText());
1514 if (newname == currentFormat().name())
1517 currentFormat().setName(newname);
1522 void PrefFileformats::on_formatED_textChanged(const QString &)
1524 QString t = formatED->text();
1526 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1527 setValid(formatLA, valid);
1531 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1533 QString t = formatsCB->currentText();
1535 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1536 setValid(formatsLA, valid);
1540 void PrefFileformats::updatePrettyname()
1542 string const newname = fromqstr(formatsCB->currentText());
1543 if (newname == currentFormat().prettyname())
1546 currentFormat().setPrettyname(newname);
1553 Format & PrefFileformats::currentFormat()
1555 int const i = formatsCB->currentIndex();
1556 int const nr = formatsCB->itemData(i).toInt();
1557 return form_->formats().get(nr);
1561 void PrefFileformats::on_formatNewPB_clicked()
1563 form_->formats().add("", "", "", "", "", "", Format::none);
1565 formatsCB->setCurrentIndex(0);
1566 formatsCB->setFocus(Qt::OtherFocusReason);
1570 void PrefFileformats::on_formatRemovePB_clicked()
1572 int const i = formatsCB->currentIndex();
1573 int const nr = formatsCB->itemData(i).toInt();
1574 string const current_text = form_->formats().get(nr).name();
1575 if (form_->converters().formatIsUsed(current_text)) {
1576 Alert::error(_("Format in use"),
1577 _("Cannot remove a Format used by a Converter. "
1578 "Remove the converter first."));
1582 form_->formats().erase(current_text);
1585 on_formatsCB_editTextChanged(formatsCB->currentText());
1590 /////////////////////////////////////////////////////////////////////
1594 /////////////////////////////////////////////////////////////////////
1596 PrefLanguage::PrefLanguage(QWidget * parent)
1597 : PrefModule(qt_("Language"), 0, parent)
1601 connect(rtlGB, SIGNAL(clicked()),
1602 this, SIGNAL(changed()));
1603 connect(visualCursorRB, SIGNAL(clicked()),
1604 this, SIGNAL(changed()));
1605 connect(logicalCursorRB, SIGNAL(clicked()),
1606 this, SIGNAL(changed()));
1607 connect(markForeignCB, SIGNAL(clicked()),
1608 this, SIGNAL(changed()));
1609 connect(autoBeginCB, SIGNAL(clicked()),
1610 this, SIGNAL(changed()));
1611 connect(autoEndCB, SIGNAL(clicked()),
1612 this, SIGNAL(changed()));
1613 connect(useBabelCB, SIGNAL(clicked()),
1614 this, SIGNAL(changed()));
1615 connect(globalCB, SIGNAL(clicked()),
1616 this, SIGNAL(changed()));
1617 connect(languagePackageED, SIGNAL(textChanged(QString)),
1618 this, SIGNAL(changed()));
1619 connect(startCommandED, SIGNAL(textChanged(QString)),
1620 this, SIGNAL(changed()));
1621 connect(endCommandED, SIGNAL(textChanged(QString)),
1622 this, SIGNAL(changed()));
1623 connect(defaultLanguageCO, SIGNAL(activated(int)),
1624 this, SIGNAL(changed()));
1626 defaultLanguageCO->clear();
1628 // store the lang identifiers for later
1629 //foreach (LanguagePair const & lpair, languageData(false)) {
1630 QList<LanguagePair> l = languageData(false);
1631 foreach (LanguagePair const & lpair, l) {
1632 defaultLanguageCO->addItem(lpair.first);
1633 lang_.append(lpair.second);
1638 void PrefLanguage::apply(LyXRC & rc) const
1640 // FIXME: remove rtl_support bool
1641 rc.rtl_support = rtlGB->isChecked();
1642 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
1643 rc.mark_foreign_language = markForeignCB->isChecked();
1644 rc.language_auto_begin = autoBeginCB->isChecked();
1645 rc.language_auto_end = autoEndCB->isChecked();
1646 rc.language_use_babel = useBabelCB->isChecked();
1647 rc.language_global_options = globalCB->isChecked();
1648 rc.language_package = fromqstr(languagePackageED->text());
1649 rc.language_command_begin = fromqstr(startCommandED->text());
1650 rc.language_command_end = fromqstr(endCommandED->text());
1651 rc.default_language = fromqstr(lang_[defaultLanguageCO->currentIndex()]);
1655 void PrefLanguage::update(LyXRC const & rc)
1657 // FIXME: remove rtl_support bool
1658 rtlGB->setChecked(rc.rtl_support);
1659 if (rc.visual_cursor)
1660 visualCursorRB->setChecked(true);
1662 logicalCursorRB->setChecked(true);
1663 markForeignCB->setChecked(rc.mark_foreign_language);
1664 autoBeginCB->setChecked(rc.language_auto_begin);
1665 autoEndCB->setChecked(rc.language_auto_end);
1666 useBabelCB->setChecked(rc.language_use_babel);
1667 globalCB->setChecked(rc.language_global_options);
1668 languagePackageED->setText(toqstr(rc.language_package));
1669 startCommandED->setText(toqstr(rc.language_command_begin));
1670 endCommandED->setText(toqstr(rc.language_command_end));
1672 int const pos = findPos_helper(lang_, toqstr(rc.default_language));
1673 defaultLanguageCO->setCurrentIndex(pos);
1677 /////////////////////////////////////////////////////////////////////
1681 /////////////////////////////////////////////////////////////////////
1683 PrefPrinter::PrefPrinter(QWidget * parent)
1684 : PrefModule(qt_("Printer"), 0, parent)
1688 connect(printerAdaptCB, SIGNAL(clicked()),
1689 this, SIGNAL(changed()));
1690 connect(printerCommandED, SIGNAL(textChanged(QString)),
1691 this, SIGNAL(changed()));
1692 connect(printerNameED, SIGNAL(textChanged(QString)),
1693 this, SIGNAL(changed()));
1694 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
1695 this, SIGNAL(changed()));
1696 connect(printerCopiesED, SIGNAL(textChanged(QString)),
1697 this, SIGNAL(changed()));
1698 connect(printerReverseED, SIGNAL(textChanged(QString)),
1699 this, SIGNAL(changed()));
1700 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
1701 this, SIGNAL(changed()));
1702 connect(printerExtensionED, SIGNAL(textChanged(QString)),
1703 this, SIGNAL(changed()));
1704 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
1705 this, SIGNAL(changed()));
1706 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
1707 this, SIGNAL(changed()));
1708 connect(printerEvenED, SIGNAL(textChanged(QString)),
1709 this, SIGNAL(changed()));
1710 connect(printerOddED, SIGNAL(textChanged(QString)),
1711 this, SIGNAL(changed()));
1712 connect(printerCollatedED, SIGNAL(textChanged(QString)),
1713 this, SIGNAL(changed()));
1714 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
1715 this, SIGNAL(changed()));
1716 connect(printerToFileED, SIGNAL(textChanged(QString)),
1717 this, SIGNAL(changed()));
1718 connect(printerExtraED, SIGNAL(textChanged(QString)),
1719 this, SIGNAL(changed()));
1720 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
1721 this, SIGNAL(changed()));
1722 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
1723 this, SIGNAL(changed()));
1727 void PrefPrinter::apply(LyXRC & rc) const
1729 rc.print_adapt_output = printerAdaptCB->isChecked();
1730 rc.print_command = fromqstr(printerCommandED->text());
1731 rc.printer = fromqstr(printerNameED->text());
1733 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1734 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1735 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1736 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1737 rc.print_file_extension = fromqstr(printerExtensionED->text());
1738 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1739 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1740 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1741 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1742 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1743 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1744 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1745 rc.print_extra_options = fromqstr(printerExtraED->text());
1746 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1747 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1751 void PrefPrinter::update(LyXRC const & rc)
1753 printerAdaptCB->setChecked(rc.print_adapt_output);
1754 printerCommandED->setText(toqstr(rc.print_command));
1755 printerNameED->setText(toqstr(rc.printer));
1757 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1758 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1759 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1760 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1761 printerExtensionED->setText(toqstr(rc.print_file_extension));
1762 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1763 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1764 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1765 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1766 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1767 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1768 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1769 printerExtraED->setText(toqstr(rc.print_extra_options));
1770 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1771 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1775 /////////////////////////////////////////////////////////////////////
1777 // PrefUserInterface
1779 /////////////////////////////////////////////////////////////////////
1781 PrefUserInterface::PrefUserInterface(GuiPreferences * form, QWidget * parent)
1782 : PrefModule(qt_("User interface"), form, parent)
1786 connect(autoSaveCB, SIGNAL(toggled(bool)),
1787 autoSaveSB, SLOT(setEnabled(bool)));
1788 connect(autoSaveCB, SIGNAL(toggled(bool)),
1789 TextLabel1, SLOT(setEnabled(bool)));
1790 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
1791 this, SIGNAL(changed()));
1792 connect(uiFilePB, SIGNAL(clicked()),
1793 this, SLOT(select_ui()));
1794 connect(uiFileED, SIGNAL(textChanged(QString)),
1795 this, SIGNAL(changed()));
1796 connect(restoreCursorCB, SIGNAL(clicked()),
1797 this, SIGNAL(changed()));
1798 connect(loadSessionCB, SIGNAL(clicked()),
1799 this, SIGNAL(changed()));
1800 connect(allowGeometrySessionCB, SIGNAL(clicked()),
1801 this, SIGNAL(changed()));
1802 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1803 this, SIGNAL(changed()));
1804 connect(autoSaveCB, SIGNAL(clicked()),
1805 this, SIGNAL(changed()));
1806 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1807 this, SIGNAL(changed()));
1808 connect(tooltipCB, SIGNAL(toggled(bool)),
1809 this, SIGNAL(changed()));
1810 connect(useBundledCB, SIGNAL(toggled(bool)),
1811 this, SIGNAL(changed()));
1812 lastfilesSB->setMaximum(maxlastfiles);
1816 void PrefUserInterface::apply(LyXRC & rc) const
1818 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1819 rc.use_lastfilepos = restoreCursorCB->isChecked();
1820 rc.load_session = loadSessionCB->isChecked();
1821 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
1822 rc.autosave = autoSaveSB->value() * 60;
1823 rc.make_backup = autoSaveCB->isChecked();
1824 rc.num_lastfiles = lastfilesSB->value();
1825 rc.use_tooltip = tooltipCB->isChecked();
1826 rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
1827 rc.use_bundled_format = useBundledCB->isChecked();
1831 void PrefUserInterface::update(LyXRC const & rc)
1833 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1834 restoreCursorCB->setChecked(rc.use_lastfilepos);
1835 loadSessionCB->setChecked(rc.load_session);
1836 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
1837 // convert to minutes
1838 int mins(rc.autosave / 60);
1839 if (rc.autosave && !mins)
1841 autoSaveSB->setValue(mins);
1842 autoSaveCB->setChecked(rc.make_backup);
1843 lastfilesSB->setValue(rc.num_lastfiles);
1844 tooltipCB->setChecked(rc.use_tooltip);
1845 openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
1846 useBundledCB->setChecked(rc.use_bundled_format);
1850 void PrefUserInterface::select_ui()
1852 QString file = form_->browseUI(internalPath(uiFileED->text()));
1853 if (!file.isEmpty())
1854 uiFileED->setText(file);
1857 /////////////////////////////////////////////////////////////////////
1861 /////////////////////////////////////////////////////////////////////
1863 PrefEdit::PrefEdit(GuiPreferences * form, QWidget * parent)
1864 : PrefModule(qt_("Editing"), form, parent)
1868 connect(cursorFollowsCB, SIGNAL(clicked()),
1869 this, SIGNAL(changed()));
1870 connect(sortEnvironmentsCB, SIGNAL(clicked()),
1871 this, SIGNAL(changed()));
1872 connect(groupEnvironmentsCB, SIGNAL(clicked()),
1873 this, SIGNAL(changed()));
1874 connect(macroEditStyleCO, SIGNAL(activated(int)),
1875 this, SIGNAL(changed()));
1876 connect(fullscreenLimitGB, SIGNAL(clicked()),
1877 this, SIGNAL(changed()));
1878 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
1879 this, SIGNAL(changed()));
1880 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
1881 this, SIGNAL(changed()));
1882 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
1883 this, SIGNAL(changed()));
1884 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
1885 this, SIGNAL(changed()));
1889 void PrefEdit::apply(LyXRC & rc) const
1891 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1892 rc.sort_layouts = sortEnvironmentsCB->isChecked();
1893 rc.group_layouts = groupEnvironmentsCB->isChecked();
1894 switch (macroEditStyleCO->currentIndex()) {
1895 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
1896 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
1897 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
1899 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
1900 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
1901 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
1902 rc.full_screen_width = fullscreenWidthSB->value();
1903 rc.full_screen_limit = fullscreenLimitGB->isChecked();
1907 void PrefEdit::update(LyXRC const & rc)
1909 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1910 sortEnvironmentsCB->setChecked(rc.sort_layouts);
1911 groupEnvironmentsCB->setChecked(rc.group_layouts);
1912 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
1913 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
1914 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
1915 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
1916 fullscreenWidthSB->setValue(rc.full_screen_width);
1917 fullscreenLimitGB->setChecked(rc.full_screen_limit);
1921 /////////////////////////////////////////////////////////////////////
1925 /////////////////////////////////////////////////////////////////////
1928 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
1930 Ui::shortcutUi::setupUi(this);
1931 QDialog::setModal(true);
1935 PrefShortcuts::PrefShortcuts(GuiPreferences * form, QWidget * parent)
1936 : PrefModule(qt_("Shortcuts"), form, parent)
1940 shortcutsTW->setColumnCount(2);
1941 shortcutsTW->headerItem()->setText(0, qt_("Function"));
1942 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
1943 shortcutsTW->setSortingEnabled(true);
1944 // Multi-selection can be annoying.
1945 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
1946 shortcutsTW->header()->resizeSection(0, 200);
1948 connect(bindFilePB, SIGNAL(clicked()),
1949 this, SLOT(select_bind()));
1950 connect(bindFileED, SIGNAL(textChanged(QString)),
1951 this, SIGNAL(changed()));
1952 connect(removePB, SIGNAL(clicked()),
1953 this, SIGNAL(changed()));
1955 shortcut_ = new GuiShortcutDialog(this);
1956 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
1957 shortcut_bc_.setOK(shortcut_->okPB);
1958 shortcut_bc_.setCancel(shortcut_->cancelPB);
1960 connect(shortcut_->okPB, SIGNAL(clicked()),
1961 shortcut_, SLOT(accept()));
1962 connect(shortcut_->okPB, SIGNAL(clicked()),
1963 this, SIGNAL(changed()));
1964 connect(shortcut_->cancelPB, SIGNAL(clicked()),
1965 shortcut_, SLOT(reject()));
1966 connect(shortcut_->clearPB, SIGNAL(clicked()),
1967 this, SLOT(shortcut_clearPB_pressed()));
1968 connect(shortcut_->okPB, SIGNAL(clicked()),
1969 this, SLOT(shortcut_okPB_pressed()));
1973 void PrefShortcuts::apply(LyXRC & rc) const
1975 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1976 // write user_bind and user_unbind to .lyx/bind/user.bind
1977 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
1978 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
1979 lyxerr << "LyX could not create the user bind directory '"
1980 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
1983 if (!bind_dir.isDirWritable()) {
1984 lyxerr << "LyX could not write to the user bind directory '"
1985 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
1988 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
1989 user_bind_.write(user_bind_file.toFilesystemEncoding(), false, false);
1990 user_unbind_.write(user_bind_file.toFilesystemEncoding(), true, true);
1991 // immediately apply the keybindings. Why this is not done before?
1992 // The good thing is that the menus are updated automatically.
1993 theTopLevelKeymap().clear();
1994 theTopLevelKeymap().read("site");
1995 theTopLevelKeymap().read(rc.bind_file);
1996 theTopLevelKeymap().read("user");
2000 void PrefShortcuts::update(LyXRC const & rc)
2002 bindFileED->setText(toqstr(external_path(rc.bind_file)));
2004 system_bind_.clear();
2006 user_unbind_.clear();
2007 system_bind_.read(rc.bind_file);
2008 // \unbind in user.bind is added to user_unbind_
2009 user_bind_.read("user", &user_unbind_);
2010 updateShortcutsTW();
2014 void PrefShortcuts::updateShortcutsTW()
2016 shortcutsTW->clear();
2018 editItem_ = new QTreeWidgetItem(shortcutsTW);
2019 editItem_->setText(0, toqstr("Cursor, Mouse and Editing functions"));
2020 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
2022 mathItem_ = new QTreeWidgetItem(shortcutsTW);
2023 mathItem_->setText(0, toqstr("Mathematical Symbols"));
2024 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
2026 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
2027 bufferItem_->setText(0, toqstr("Buffer and Window"));
2028 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
2030 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2031 layoutItem_->setText(0, toqstr("Font, Layouts and Textclasses"));
2032 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2034 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2035 systemItem_->setText(0, toqstr("System and Miscellaneous"));
2036 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2038 // listBindings(unbound=true) lists all bound and unbound lfuns
2039 // Items in this list is tagged by its source.
2040 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2041 static_cast<int>(System));
2042 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2043 static_cast<int>(UserBind));
2044 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2045 static_cast<int>(UserUnbind));
2046 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2047 user_bindinglist.end());
2048 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2049 user_unbindinglist.end());
2051 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2052 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2053 for (; it != it_end; ++it)
2054 insertShortcutItem(it->request, it->sequence, item_type(it->tag));
2056 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2057 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2058 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2062 void PrefShortcuts::setItemType(QTreeWidgetItem * item, item_type tag)
2064 item->setData(0, Qt::UserRole, QVariant(tag));
2074 font.setStrikeOut(true);
2076 // this item is not displayed now.
2077 case UserExtraUnbind:
2078 font.setStrikeOut(true);
2082 item->setFont(1, font);
2086 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2087 KeySequence const & seq, item_type tag)
2089 FuncCode action = lfun.action;
2090 string const action_name = lyxaction.getActionName(action);
2091 QString const lfun_name = toqstr(from_utf8(action_name)
2092 + " " + lfun.argument());
2093 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2094 item_type item_tag = tag;
2096 QTreeWidgetItem * newItem = NULL;
2097 // for unbind items, try to find an existing item in the system bind list
2098 if (tag == UserUnbind) {
2099 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2100 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2101 for (int i = 0; i < items.size(); ++i) {
2102 if (items[i]->text(1) == shortcut)
2106 // if not found, this unbind item is UserExtraUnbind
2107 // Such an item is not displayed to avoid confusion (what is
2108 // unmatched removed?).
2110 item_tag = UserExtraUnbind;
2115 switch(lyxaction.getActionType(action)) {
2116 case LyXAction::Hidden:
2118 case LyXAction::Edit:
2119 newItem = new QTreeWidgetItem(editItem_);
2121 case LyXAction::Math:
2122 newItem = new QTreeWidgetItem(mathItem_);
2124 case LyXAction::Buffer:
2125 newItem = new QTreeWidgetItem(bufferItem_);
2127 case LyXAction::Layout:
2128 newItem = new QTreeWidgetItem(layoutItem_);
2130 case LyXAction::System:
2131 newItem = new QTreeWidgetItem(systemItem_);
2134 // this should not happen
2135 newItem = new QTreeWidgetItem(shortcutsTW);
2139 newItem->setText(0, lfun_name);
2140 newItem->setText(1, shortcut);
2141 // record BindFile representation to recover KeySequence when needed.
2142 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2143 setItemType(newItem, item_tag);
2148 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2150 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2151 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2152 if (items.isEmpty())
2155 item_type tag = static_cast<item_type>(items[0]->data(0, Qt::UserRole).toInt());
2156 if (tag == UserUnbind)
2157 removePB->setText(toqstr("Restore"));
2159 removePB->setText(toqstr("Remove"));
2163 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2165 QTreeWidgetItem * item = shortcutsTW->currentItem();
2166 if (item->flags() & Qt::ItemIsSelectable) {
2167 shortcut_->lfunLE->setText(item->text(0));
2168 // clear the shortcut because I assume that a user will enter
2170 shortcut_->shortcutLE->reset();
2171 shortcut_->shortcutLE->setFocus();
2177 void PrefShortcuts::select_bind()
2179 QString file = form_->browsebind(internalPath(bindFileED->text()));
2180 if (!file.isEmpty()) {
2181 bindFileED->setText(file);
2182 system_bind_ = KeyMap();
2183 system_bind_.read(fromqstr(file));
2184 updateShortcutsTW();
2189 void PrefShortcuts::on_newPB_pressed()
2191 shortcut_->lfunLE->clear();
2192 shortcut_->shortcutLE->reset();
2197 void PrefShortcuts::on_removePB_pressed()
2199 // it seems that only one item can be selected, but I am
2200 // removing all selected items anyway.
2201 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2202 for (int i = 0; i < items.size(); ++i) {
2203 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2204 string lfun = fromqstr(items[i]->text(0));
2205 FuncRequest func = lyxaction.lookupFunc(lfun);
2206 item_type tag = static_cast<item_type>(items[i]->data(0, Qt::UserRole).toInt());
2210 // for system bind, we do not touch the item
2211 // but add an user unbind item
2212 user_unbind_.bind(shortcut, func);
2213 setItemType(items[i], UserUnbind);
2214 removePB->setText(toqstr("Restore"));
2218 // for user_bind, we remove this bind
2219 QTreeWidgetItem * parent = items[i]->parent();
2220 int itemIdx = parent->indexOfChild(items[i]);
2221 parent->takeChild(itemIdx);
2223 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2225 shortcutsTW->scrollToItem(parent);
2226 user_bind_.unbind(shortcut, func);
2230 // for user_unbind, we remove the unbind, and the item
2231 // become System again.
2232 user_unbind_.unbind(shortcut, func);
2233 setItemType(items[i], System);
2234 removePB->setText(toqstr("Remove"));
2237 case UserExtraUnbind: {
2238 // for user unbind that is not in system bind file,
2239 // remove this unbind file
2240 QTreeWidgetItem * parent = items[i]->parent();
2241 parent->takeChild(parent->indexOfChild(items[i]));
2242 user_unbind_.unbind(shortcut, func);
2249 void PrefShortcuts::on_searchLE_textEdited()
2251 if (searchLE->text().isEmpty()) {
2252 // show all hidden items
2253 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2255 shortcutsTW->setItemHidden(*it++, false);
2258 // search both columns
2259 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2260 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2261 matched += shortcutsTW->findItems(searchLE->text(),
2262 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2264 // hide everyone (to avoid searching in matched QList repeatedly
2265 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2267 shortcutsTW->setItemHidden(*it++, true);
2268 // show matched items
2269 for (int i = 0; i < matched.size(); ++i) {
2270 shortcutsTW->setItemHidden(matched[i], false);
2271 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2276 void PrefShortcuts::shortcut_okPB_pressed()
2278 string lfun = fromqstr(shortcut_->lfunLE->text());
2279 FuncRequest func = lyxaction.lookupFunc(lfun);
2281 if (func.action == LFUN_UNKNOWN_ACTION) {
2282 Alert::error(_("Failed to create shortcut"),
2283 _("Unknown or invalid LyX function"));
2287 KeySequence k = shortcut_->shortcutLE->getKeySequence();
2288 if (k.length() == 0) {
2289 Alert::error(_("Failed to create shortcut"),
2290 _("Invalid or empty key sequence"));
2294 // if both lfun and shortcut is valid
2295 if (user_bind_.hasBinding(k, func) || system_bind_.hasBinding(k, func)) {
2296 Alert::error(_("Failed to create shortcut"),
2297 _("Shortcut is already defined"));
2301 QTreeWidgetItem * item = insertShortcutItem(func, k, UserBind);
2303 user_bind_.bind(&k, func);
2304 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2305 shortcutsTW->setItemExpanded(item->parent(), true);
2306 shortcutsTW->scrollToItem(item);
2308 Alert::error(_("Failed to create shortcut"),
2309 _("Can not insert shortcut to the list"));
2315 void PrefShortcuts::shortcut_clearPB_pressed()
2317 shortcut_->shortcutLE->reset();
2318 shortcut_->shortcutLE->setFocus();
2322 /////////////////////////////////////////////////////////////////////
2326 /////////////////////////////////////////////////////////////////////
2328 PrefIdentity::PrefIdentity(QWidget * parent)
2329 : PrefModule(qt_("Identity"), 0, parent)
2333 connect(nameED, SIGNAL(textChanged(QString)),
2334 this, SIGNAL(changed()));
2335 connect(emailED, SIGNAL(textChanged(QString)),
2336 this, SIGNAL(changed()));
2340 void PrefIdentity::apply(LyXRC & rc) const
2342 rc.user_name = fromqstr(nameED->text());
2343 rc.user_email = fromqstr(emailED->text());
2347 void PrefIdentity::update(LyXRC const & rc)
2349 nameED->setText(toqstr(rc.user_name));
2350 emailED->setText(toqstr(rc.user_email));
2355 /////////////////////////////////////////////////////////////////////
2359 /////////////////////////////////////////////////////////////////////
2361 GuiPreferences::GuiPreferences(GuiView & lv)
2362 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2366 QDialog::setModal(false);
2368 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2369 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2370 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2371 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2373 add(new PrefUserInterface(this));
2374 add(new PrefEdit(this));
2375 add(new PrefShortcuts(this));
2376 add(new PrefScreenFonts(this));
2377 add(new PrefColors(this));
2378 add(new PrefDisplay);
2379 add(new PrefInput(this));
2381 add(new PrefPaths(this));
2383 add(new PrefIdentity);
2385 add(new PrefLanguage);
2386 add(new PrefSpellchecker(this));
2388 add(new PrefPrinter);
2390 add(new PrefPlaintext);
2391 add(new PrefLatex(this));
2393 PrefConverters * converters = new PrefConverters(this);
2394 PrefFileformats * formats = new PrefFileformats(this);
2395 connect(formats, SIGNAL(formatsChanged()),
2396 converters, SLOT(updateGui()));
2400 prefsPS->setCurrentPanel(qt_("User interface"));
2401 // FIXME: hack to work around resizing bug in Qt >= 4.2
2402 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2403 #if QT_VERSION >= 0x040200
2404 prefsPS->updateGeometry();
2407 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2409 bc().setApply(applyPB);
2410 bc().setCancel(closePB);
2411 bc().setRestore(restorePB);
2415 void GuiPreferences::add(PrefModule * module)
2417 BOOST_ASSERT(module);
2418 prefsPS->addPanel(module, module->title());
2419 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2420 modules_.push_back(module);
2424 void GuiPreferences::change_adaptor()
2430 void GuiPreferences::apply(LyXRC & rc) const
2432 size_t end = modules_.size();
2433 for (size_t i = 0; i != end; ++i)
2434 modules_[i]->apply(rc);
2438 void GuiPreferences::updateRc(LyXRC const & rc)
2440 size_t const end = modules_.size();
2441 for (size_t i = 0; i != end; ++i)
2442 modules_[i]->update(rc);
2446 void GuiPreferences::applyView()
2452 void GuiPreferences::updateContents()
2458 bool GuiPreferences::initialiseParams(string const &)
2461 formats_ = lyx::formats;
2462 converters_ = theConverters();
2463 converters_.update(formats_);
2464 movers_ = theMovers();
2466 update_screen_font_ = false;
2472 void GuiPreferences::dispatchParams()
2475 rc_.write(ss, true);
2476 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
2477 // FIXME: these need lfuns
2479 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
2481 lyx::formats = formats_;
2483 theConverters() = converters_;
2484 theConverters().update(lyx::formats);
2485 theConverters().buildGraph();
2487 theMovers() = movers_;
2489 vector<string>::const_iterator it = colors_.begin();
2490 vector<string>::const_iterator const end = colors_.end();
2491 for (; it != end; ++it)
2492 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
2495 if (update_screen_font_) {
2496 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2497 update_screen_font_ = false;
2500 // The Save button has been pressed
2502 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
2506 void GuiPreferences::setColor(ColorCode col, string const & hex)
2508 colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
2512 void GuiPreferences::updateScreenFonts()
2514 update_screen_font_ = true;
2518 QString GuiPreferences::browsebind(QString const & file) const
2520 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
2521 FileFilterList(_("LyX bind files (*.bind)")));
2525 QString GuiPreferences::browseUI(QString const & file) const
2527 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
2528 FileFilterList(_("LyX UI files (*.ui)")));
2532 QString GuiPreferences::browsekbmap(QString const & file) const
2534 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
2535 FileFilterList(_("LyX keyboard maps (*.kmap)")));
2539 QString GuiPreferences::browsedict(QString const & file) const
2541 return browseFile(file, qt_("Choose personal dictionary"),
2542 FileFilterList(lyxrc.use_spell_lib ? _("*.pws") : _("*.ispell")));
2546 QString GuiPreferences::browse(QString const & file,
2547 QString const & title) const
2549 return browseFile(file, title, FileFilterList(), true);
2553 QString GuiPreferences::browsedir(QString const & path,
2554 QString const & title) const
2556 return browseDir(path, title);
2560 // We support less paper sizes than the document dialog
2561 // Therefore this adjustment is needed.
2562 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
2566 return PAPER_DEFAULT;
2568 return PAPER_USLETTER;
2570 return PAPER_USLEGAL;
2572 return PAPER_USEXECUTIVE;
2582 // should not happen
2583 return PAPER_DEFAULT;
2588 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
2590 switch (papersize) {
2593 case PAPER_USLETTER:
2597 case PAPER_USEXECUTIVE:
2608 // should not happen
2614 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
2617 } // namespace frontend
2620 #include "GuiPrefs_moc.cpp"