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(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
410 this, SIGNAL(changed()));
414 void PrefInput::apply(LyXRC & rc) const
416 // FIXME: can derive CB from the two EDs
417 rc.use_kbmap = keymapCB->isChecked();
418 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
419 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
420 rc.completion_inline_delay = inlineDelaySB->value();
421 rc.completion_inline_math = inlineMathCB->isChecked();
422 rc.completion_inline_text = inlineTextCB->isChecked();
423 rc.completion_inline_dots = inlineDotsCB->isChecked() ? 13 : -1;
424 rc.completion_popup_delay = popupDelaySB->value();
425 rc.completion_popup_math = popupMathCB->isChecked();
426 rc.completion_popup_text = popupTextCB->isChecked();
427 rc.completion_popup_after_complete
428 = popupAfterCompleteCB->isChecked();
429 rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
433 void PrefInput::update(LyXRC const & rc)
435 // FIXME: can derive CB from the two EDs
436 keymapCB->setChecked(rc.use_kbmap);
437 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
438 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
439 inlineDelaySB->setValue(rc.completion_inline_delay);
440 inlineMathCB->setChecked(rc.completion_inline_math);
441 inlineTextCB->setChecked(rc.completion_inline_text);
442 inlineDotsCB->setChecked(rc.completion_inline_dots != -1);
443 popupDelaySB->setValue(rc.completion_popup_delay);
444 popupMathCB->setChecked(rc.completion_popup_math);
445 popupTextCB->setChecked(rc.completion_popup_text);
446 popupAfterCompleteCB->setChecked(rc.completion_popup_after_complete);
447 mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
451 QString PrefInput::testKeymap(QString keymap)
453 return form_->browsekbmap(toqstr(internal_path(fromqstr(keymap))));
457 void PrefInput::on_firstKeymapPB_clicked(bool)
459 QString const file = testKeymap(firstKeymapED->text());
461 firstKeymapED->setText(file);
465 void PrefInput::on_secondKeymapPB_clicked(bool)
467 QString const file = testKeymap(secondKeymapED->text());
469 secondKeymapED->setText(file);
473 void PrefInput::on_keymapCB_toggled(bool keymap)
475 firstKeymapLA->setEnabled(keymap);
476 secondKeymapLA->setEnabled(keymap);
477 firstKeymapED->setEnabled(keymap);
478 secondKeymapED->setEnabled(keymap);
479 firstKeymapPB->setEnabled(keymap);
480 secondKeymapPB->setEnabled(keymap);
484 /////////////////////////////////////////////////////////////////////
488 /////////////////////////////////////////////////////////////////////
490 PrefLatex::PrefLatex(GuiPreferences * form, QWidget * parent)
491 : PrefModule(qt_("LaTeX"), form, parent)
494 connect(latexEncodingED, SIGNAL(textChanged(QString)),
495 this, SIGNAL(changed()));
496 connect(latexChecktexED, SIGNAL(textChanged(QString)),
497 this, SIGNAL(changed()));
498 connect(latexBibtexED, SIGNAL(textChanged(QString)),
499 this, SIGNAL(changed()));
500 connect(latexIndexED, SIGNAL(textChanged(QString)),
501 this, SIGNAL(changed()));
502 connect(latexAutoresetCB, SIGNAL(clicked()),
503 this, SIGNAL(changed()));
504 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
505 this, SIGNAL(changed()));
506 connect(latexPaperSizeCO, SIGNAL(activated(int)),
507 this, SIGNAL(changed()));
509 #if defined(__CYGWIN__) || defined(_WIN32)
510 pathCB->setVisible(true);
511 connect(pathCB, SIGNAL(clicked()),
512 this, SIGNAL(changed()));
514 pathCB->setVisible(false);
519 void PrefLatex::apply(LyXRC & rc) const
521 rc.fontenc = fromqstr(latexEncodingED->text());
522 rc.chktex_command = fromqstr(latexChecktexED->text());
523 rc.bibtex_command = fromqstr(latexBibtexED->text());
524 rc.index_command = fromqstr(latexIndexED->text());
525 rc.auto_reset_options = latexAutoresetCB->isChecked();
526 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
527 rc.default_papersize =
528 form_->toPaperSize(latexPaperSizeCO->currentIndex());
529 #if defined(__CYGWIN__) || defined(_WIN32)
530 rc.windows_style_tex_paths = pathCB->isChecked();
535 void PrefLatex::update(LyXRC const & rc)
537 latexEncodingED->setText(toqstr(rc.fontenc));
538 latexChecktexED->setText(toqstr(rc.chktex_command));
539 latexBibtexED->setText(toqstr(rc.bibtex_command));
540 latexIndexED->setText(toqstr(rc.index_command));
541 latexAutoresetCB->setChecked(rc.auto_reset_options);
542 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
543 latexPaperSizeCO->setCurrentIndex(
544 form_->fromPaperSize(rc.default_papersize));
545 #if defined(__CYGWIN__) || defined(_WIN32)
546 pathCB->setChecked(rc.windows_style_tex_paths);
551 /////////////////////////////////////////////////////////////////////
555 /////////////////////////////////////////////////////////////////////
557 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form, QWidget * parent)
558 : PrefModule(qt_("Screen fonts"), form, parent)
562 connect(screenRomanCO, SIGNAL(activated(QString)),
563 this, SLOT(select_roman(QString)));
564 connect(screenSansCO, SIGNAL(activated(QString)),
565 this, SLOT(select_sans(QString)));
566 connect(screenTypewriterCO, SIGNAL(activated(QString)),
567 this, SLOT(select_typewriter(QString)));
569 QFontDatabase fontdb;
570 QStringList families(fontdb.families());
571 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
572 screenRomanCO->addItem(*it);
573 screenSansCO->addItem(*it);
574 screenTypewriterCO->addItem(*it);
576 connect(screenRomanCO, SIGNAL(activated(QString)),
577 this, SIGNAL(changed()));
578 connect(screenSansCO, SIGNAL(activated(QString)),
579 this, SIGNAL(changed()));
580 connect(screenTypewriterCO, SIGNAL(activated(QString)),
581 this, SIGNAL(changed()));
582 connect(screenZoomSB, SIGNAL(valueChanged(int)),
583 this, SIGNAL(changed()));
584 connect(screenDpiSB, SIGNAL(valueChanged(int)),
585 this, SIGNAL(changed()));
586 connect(screenTinyED, SIGNAL(textChanged(QString)),
587 this, SIGNAL(changed()));
588 connect(screenSmallestED, SIGNAL(textChanged(QString)),
589 this, SIGNAL(changed()));
590 connect(screenSmallerED, SIGNAL(textChanged(QString)),
591 this, SIGNAL(changed()));
592 connect(screenSmallED, SIGNAL(textChanged(QString)),
593 this, SIGNAL(changed()));
594 connect(screenNormalED, SIGNAL(textChanged(QString)),
595 this, SIGNAL(changed()));
596 connect(screenLargeED, SIGNAL(textChanged(QString)),
597 this, SIGNAL(changed()));
598 connect(screenLargerED, SIGNAL(textChanged(QString)),
599 this, SIGNAL(changed()));
600 connect(screenLargestED, SIGNAL(textChanged(QString)),
601 this, SIGNAL(changed()));
602 connect(screenHugeED, SIGNAL(textChanged(QString)),
603 this, SIGNAL(changed()));
604 connect(screenHugerED, SIGNAL(textChanged(QString)),
605 this, SIGNAL(changed()));
606 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
607 this, SIGNAL(changed()));
609 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
610 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
611 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
612 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
613 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
614 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
615 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
616 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
617 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
618 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
622 void PrefScreenFonts::apply(LyXRC & rc) const
624 LyXRC const oldrc = rc;
626 parseFontName(screenRomanCO->currentText(),
627 rc.roman_font_name, rc.roman_font_foundry);
628 parseFontName(screenSansCO->currentText(),
629 rc.sans_font_name, rc.sans_font_foundry);
630 parseFontName(screenTypewriterCO->currentText(),
631 rc.typewriter_font_name, rc.typewriter_font_foundry);
633 rc.zoom = screenZoomSB->value();
634 rc.dpi = screenDpiSB->value();
635 rc.font_sizes[FONT_SIZE_TINY] = fromqstr(screenTinyED->text());
636 rc.font_sizes[FONT_SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
637 rc.font_sizes[FONT_SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
638 rc.font_sizes[FONT_SIZE_SMALL] = fromqstr(screenSmallED->text());
639 rc.font_sizes[FONT_SIZE_NORMAL] = fromqstr(screenNormalED->text());
640 rc.font_sizes[FONT_SIZE_LARGE] = fromqstr(screenLargeED->text());
641 rc.font_sizes[FONT_SIZE_LARGER] = fromqstr(screenLargerED->text());
642 rc.font_sizes[FONT_SIZE_LARGEST] = fromqstr(screenLargestED->text());
643 rc.font_sizes[FONT_SIZE_HUGE] = fromqstr(screenHugeED->text());
644 rc.font_sizes[FONT_SIZE_HUGER] = fromqstr(screenHugerED->text());
645 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
647 if (rc.font_sizes != oldrc.font_sizes
648 || rc.roman_font_name != oldrc.roman_font_name
649 || rc.sans_font_name != oldrc.sans_font_name
650 || rc.typewriter_font_name != oldrc.typewriter_font_name
651 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
652 // The global QPixmapCache is used in GuiPainter to cache text
653 // painting so we must reset it in case any of the above
654 // parameter is changed.
655 QPixmapCache::clear();
656 guiApp->fontLoader().update();
657 form_->updateScreenFonts();
662 void PrefScreenFonts::update(LyXRC const & rc)
664 setComboxFont(screenRomanCO, rc.roman_font_name,
665 rc.roman_font_foundry);
666 setComboxFont(screenSansCO, rc.sans_font_name,
667 rc.sans_font_foundry);
668 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
669 rc.typewriter_font_foundry);
671 select_roman(screenRomanCO->currentText());
672 select_sans(screenSansCO->currentText());
673 select_typewriter(screenTypewriterCO->currentText());
675 screenZoomSB->setValue(rc.zoom);
676 screenDpiSB->setValue(rc.dpi);
677 screenTinyED->setText(toqstr(rc.font_sizes[FONT_SIZE_TINY]));
678 screenSmallestED->setText(toqstr(rc.font_sizes[FONT_SIZE_SCRIPT]));
679 screenSmallerED->setText(toqstr(rc.font_sizes[FONT_SIZE_FOOTNOTE]));
680 screenSmallED->setText(toqstr(rc.font_sizes[FONT_SIZE_SMALL]));
681 screenNormalED->setText(toqstr(rc.font_sizes[FONT_SIZE_NORMAL]));
682 screenLargeED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGE]));
683 screenLargerED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGER]));
684 screenLargestED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGEST]));
685 screenHugeED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGE]));
686 screenHugerED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGER]));
688 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
689 #if defined(Q_WS_X11)
690 pixmapCacheCB->setEnabled(false);
696 void PrefScreenFonts::select_roman(const QString & name)
698 screenRomanFE->set(QFont(name), name);
702 void PrefScreenFonts::select_sans(const QString & name)
704 screenSansFE->set(QFont(name), name);
708 void PrefScreenFonts::select_typewriter(const QString & name)
710 screenTypewriterFE->set(QFont(name), name);
714 /////////////////////////////////////////////////////////////////////
718 /////////////////////////////////////////////////////////////////////
724 bool operator()(ColorCode lhs, ColorCode rhs) const {
725 return lcolor.getGUIName(lhs) < lcolor.getGUIName(rhs);
731 PrefColors::PrefColors(GuiPreferences * form, QWidget * parent)
732 : PrefModule(qt_("Colors"), form, parent)
736 // FIXME: all of this initialization should be put into the controller.
737 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
738 // for some discussion of why that is not trivial.
739 QPixmap icon(32, 32);
740 for (int i = 0; i < Color_ignore; ++i) {
741 ColorCode lc = static_cast<ColorCode>(i);
749 || lc == Color_magenta
750 || lc == Color_yellow
751 || lc == Color_inherit
752 || lc == Color_ignore) continue;
754 lcolors_.push_back(lc);
756 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
757 vector<ColorCode>::const_iterator cit = lcolors_.begin();
758 vector<ColorCode>::const_iterator const end = lcolors_.end();
759 for (; cit != end; ++cit) {
760 (void) new QListWidgetItem(QIcon(icon),
761 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
763 curcolors_.resize(lcolors_.size());
764 newcolors_.resize(lcolors_.size());
765 // End initialization
767 connect(colorChangePB, SIGNAL(clicked()),
768 this, SLOT(change_color()));
769 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
770 this, SLOT(change_lyxObjects_selection()));
771 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
772 this, SLOT(change_color()));
776 void PrefColors::apply(LyXRC & /*rc*/) const
778 for (unsigned int i = 0; i < lcolors_.size(); ++i)
779 if (curcolors_[i] != newcolors_[i])
780 form_->setColor(lcolors_[i], fromqstr(newcolors_[i]));
784 void PrefColors::update(LyXRC const & /*rc*/)
786 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
787 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
788 QPixmap coloritem(32, 32);
789 coloritem.fill(color);
790 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
791 newcolors_[i] = curcolors_[i] = color.name();
793 change_lyxObjects_selection();
797 void PrefColors::change_color()
799 int const row = lyxObjectsLW->currentRow();
805 QString const color = newcolors_[row];
806 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
808 if (c.isValid() && c.name() != color) {
809 newcolors_[row] = c.name();
810 QPixmap coloritem(32, 32);
812 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
818 void PrefColors::change_lyxObjects_selection()
820 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
824 /////////////////////////////////////////////////////////////////////
828 /////////////////////////////////////////////////////////////////////
830 PrefDisplay::PrefDisplay(QWidget * parent)
831 : PrefModule(qt_("Graphics"), 0, parent)
834 connect(instantPreviewCO, SIGNAL(activated(int)),
835 this, SIGNAL(changed()));
836 connect(displayGraphicsCO, SIGNAL(activated(int)),
837 this, SIGNAL(changed()));
841 void PrefDisplay::apply(LyXRC & rc) const
843 switch (instantPreviewCO->currentIndex()) {
844 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
845 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
846 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
849 graphics::DisplayType dtype;
850 switch (displayGraphicsCO->currentIndex()) {
851 case 3: dtype = graphics::NoDisplay; break;
852 case 2: dtype = graphics::ColorDisplay; break;
853 case 1: dtype = graphics::GrayscaleDisplay; break;
854 case 0: dtype = graphics::MonochromeDisplay; break;
855 default: dtype = graphics::GrayscaleDisplay;
857 rc.display_graphics = dtype;
859 // FIXME!! The graphics cache no longer has a changeDisplay method.
861 if (old_value != rc.display_graphics) {
862 graphics::GCache & gc = graphics::GCache::get();
869 void PrefDisplay::update(LyXRC const & rc)
871 switch (rc.preview) {
872 case LyXRC::PREVIEW_OFF:
873 instantPreviewCO->setCurrentIndex(0);
875 case LyXRC::PREVIEW_NO_MATH :
876 instantPreviewCO->setCurrentIndex(1);
878 case LyXRC::PREVIEW_ON :
879 instantPreviewCO->setCurrentIndex(2);
884 switch (rc.display_graphics) {
885 case graphics::NoDisplay: item = 3; break;
886 case graphics::ColorDisplay: item = 2; break;
887 case graphics::GrayscaleDisplay: item = 1; break;
888 case graphics::MonochromeDisplay: item = 0; break;
891 displayGraphicsCO->setCurrentIndex(item);
895 /////////////////////////////////////////////////////////////////////
899 /////////////////////////////////////////////////////////////////////
901 PrefPaths::PrefPaths(GuiPreferences * form, QWidget * parent)
902 : PrefModule(qt_("Paths"), form, parent)
905 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(select_exampledir()));
906 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
907 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
908 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
909 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
910 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
911 connect(workingDirED, SIGNAL(textChanged(QString)),
912 this, SIGNAL(changed()));
913 connect(exampleDirED, SIGNAL(textChanged(QString)),
914 this, SIGNAL(changed()));
915 connect(templateDirED, SIGNAL(textChanged(QString)),
916 this, SIGNAL(changed()));
917 connect(backupDirED, SIGNAL(textChanged(QString)),
918 this, SIGNAL(changed()));
919 connect(tempDirED, SIGNAL(textChanged(QString)),
920 this, SIGNAL(changed()));
921 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
922 this, SIGNAL(changed()));
923 connect(pathPrefixED, SIGNAL(textChanged(QString)),
924 this, SIGNAL(changed()));
928 void PrefPaths::apply(LyXRC & rc) const
930 rc.document_path = internal_path(fromqstr(workingDirED->text()));
931 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
932 rc.template_path = internal_path(fromqstr(templateDirED->text()));
933 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
934 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
935 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
936 // FIXME: should be a checkbox only
937 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
941 void PrefPaths::update(LyXRC const & rc)
943 workingDirED->setText(toqstr(external_path(rc.document_path)));
944 exampleDirED->setText(toqstr(external_path(rc.example_path)));
945 templateDirED->setText(toqstr(external_path(rc.template_path)));
946 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
947 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
948 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
949 // FIXME: should be a checkbox only
950 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
954 void PrefPaths::select_exampledir()
956 QString file = form_->browsedir(internalPath(exampleDirED->text()),
957 qt_("Select directory for example files"));
959 exampleDirED->setText(file);
963 void PrefPaths::select_templatedir()
965 QString file = form_->browsedir(internalPath(templateDirED->text()),
966 qt_("Select a document templates directory"));
968 templateDirED->setText(file);
972 void PrefPaths::select_tempdir()
974 QString file = form_->browsedir(internalPath(tempDirED->text()),
975 qt_("Select a temporary directory"));
977 tempDirED->setText(file);
981 void PrefPaths::select_backupdir()
983 QString file = form_->browsedir(internalPath(backupDirED->text()),
984 qt_("Select a backups directory"));
986 backupDirED->setText(file);
990 void PrefPaths::select_workingdir()
992 QString file = form_->browsedir(internalPath(workingDirED->text()),
993 qt_("Select a document directory"));
995 workingDirED->setText(file);
999 void PrefPaths::select_lyxpipe()
1001 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1002 qt_("Give a filename for the LyX server pipe"));
1003 if (!file.isEmpty())
1004 lyxserverDirED->setText(file);
1008 /////////////////////////////////////////////////////////////////////
1012 /////////////////////////////////////////////////////////////////////
1014 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form, QWidget * parent)
1015 : PrefModule(qt_("Spellchecker"), form, parent)
1019 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
1020 #if defined (USE_ISPELL)
1021 connect(spellCommandCO, SIGNAL(activated(int)),
1022 this, SIGNAL(changed()));
1024 spellCommandCO->setEnabled(false);
1026 connect(altLanguageED, SIGNAL(textChanged(QString)),
1027 this, SIGNAL(changed()));
1028 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1029 this, SIGNAL(changed()));
1030 connect(persDictionaryED, SIGNAL(textChanged(QString)),
1031 this, SIGNAL(changed()));
1032 connect(compoundWordCB, SIGNAL(clicked()),
1033 this, SIGNAL(changed()));
1034 connect(inputEncodingCB, SIGNAL(clicked()),
1035 this, SIGNAL(changed()));
1037 spellCommandCO->addItem(qt_("ispell"));
1038 spellCommandCO->addItem(qt_("aspell"));
1039 spellCommandCO->addItem(qt_("hspell"));
1041 spellCommandCO->addItem(qt_("pspell (library)"));
1044 spellCommandCO->addItem(qt_("aspell (library)"));
1050 void PrefSpellchecker::apply(LyXRC & rc) const
1052 switch (spellCommandCO->currentIndex()) {
1056 rc.use_spell_lib = false;
1057 rc.isp_command = fromqstr(spellCommandCO->currentText());
1060 rc.use_spell_lib = true;
1064 // FIXME: remove isp_use_alt_lang
1065 rc.isp_alt_lang = fromqstr(altLanguageED->text());
1066 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
1067 // FIXME: remove isp_use_esc_chars
1068 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
1069 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
1070 // FIXME: remove isp_use_pers_dict
1071 rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
1072 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
1073 rc.isp_accept_compound = compoundWordCB->isChecked();
1074 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
1078 void PrefSpellchecker::update(LyXRC const & rc)
1080 spellCommandCO->setCurrentIndex(0);
1082 if (rc.isp_command == "ispell") {
1083 spellCommandCO->setCurrentIndex(0);
1084 } else if (rc.isp_command == "aspell") {
1085 spellCommandCO->setCurrentIndex(1);
1086 } else if (rc.isp_command == "hspell") {
1087 spellCommandCO->setCurrentIndex(2);
1090 if (rc.use_spell_lib) {
1091 #if defined(USE_ASPELL) || defined(USE_PSPELL)
1092 spellCommandCO->setCurrentIndex(3);
1096 // FIXME: remove isp_use_alt_lang
1097 altLanguageED->setText(toqstr(rc.isp_alt_lang));
1098 // FIXME: remove isp_use_esc_chars
1099 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
1100 // FIXME: remove isp_use_pers_dict
1101 persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
1102 compoundWordCB->setChecked(rc.isp_accept_compound);
1103 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
1107 void PrefSpellchecker::select_dict()
1109 QString file = form_->browsedict(internalPath(persDictionaryED->text()));
1110 if (!file.isEmpty())
1111 persDictionaryED->setText(file);
1116 /////////////////////////////////////////////////////////////////////
1120 /////////////////////////////////////////////////////////////////////
1123 PrefConverters::PrefConverters(GuiPreferences * form, QWidget * parent)
1124 : PrefModule(qt_("Converters"), form, parent)
1128 connect(converterNewPB, SIGNAL(clicked()),
1129 this, SLOT(update_converter()));
1130 connect(converterRemovePB, SIGNAL(clicked()),
1131 this, SLOT(remove_converter()));
1132 connect(converterModifyPB, SIGNAL(clicked()),
1133 this, SLOT(update_converter()));
1134 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1135 this, SLOT(switch_converter()));
1136 connect(converterFromCO, SIGNAL(activated(QString)),
1137 this, SLOT(converter_changed()));
1138 connect(converterToCO, SIGNAL(activated(QString)),
1139 this, SLOT(converter_changed()));
1140 connect(converterED, SIGNAL(textEdited(QString)),
1141 this, SLOT(converter_changed()));
1142 connect(converterFlagED, SIGNAL(textEdited(QString)),
1143 this, SLOT(converter_changed()));
1144 connect(converterNewPB, SIGNAL(clicked()),
1145 this, SIGNAL(changed()));
1146 connect(converterRemovePB, SIGNAL(clicked()),
1147 this, SIGNAL(changed()));
1148 connect(converterModifyPB, SIGNAL(clicked()),
1149 this, SIGNAL(changed()));
1150 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1151 this, SIGNAL(changed()));
1153 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1154 //converterDefGB->setFocusProxy(convertersLW);
1158 void PrefConverters::apply(LyXRC & rc) const
1160 rc.use_converter_cache = cacheCB->isChecked();
1161 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
1165 void PrefConverters::update(LyXRC const & rc)
1167 cacheCB->setChecked(rc.use_converter_cache);
1169 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
1170 maxAgeLE->setText(max_age);
1175 void PrefConverters::updateGui()
1177 form_->formats().sort();
1178 form_->converters().update(form_->formats());
1179 // save current selection
1180 QString current = converterFromCO->currentText()
1181 + " -> " + converterToCO->currentText();
1183 converterFromCO->clear();
1184 converterToCO->clear();
1186 Formats::const_iterator cit = form_->formats().begin();
1187 Formats::const_iterator end = form_->formats().end();
1188 for (; cit != end; ++cit) {
1189 converterFromCO->addItem(toqstr(cit->prettyname()));
1190 converterToCO->addItem(toqstr(cit->prettyname()));
1193 // currentRowChanged(int) is also triggered when updating the listwidget
1194 // block signals to avoid unnecessary calls to switch_converter()
1195 convertersLW->blockSignals(true);
1196 convertersLW->clear();
1198 Converters::const_iterator ccit = form_->converters().begin();
1199 Converters::const_iterator cend = form_->converters().end();
1200 for (; ccit != cend; ++ccit) {
1202 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
1203 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1204 new QListWidgetItem(toqstr(name), convertersLW, type);
1206 convertersLW->sortItems(Qt::AscendingOrder);
1207 convertersLW->blockSignals(false);
1209 // restore selection
1210 if (!current.isEmpty()) {
1211 QList<QListWidgetItem *> const item =
1212 convertersLW->findItems(current, Qt::MatchExactly);
1213 if (!item.isEmpty())
1214 convertersLW->setCurrentItem(item.at(0));
1217 // select first element if restoring failed
1218 if (convertersLW->currentRow() == -1)
1219 convertersLW->setCurrentRow(0);
1225 void PrefConverters::switch_converter()
1227 int const cnr = convertersLW->currentItem()->type();
1228 Converter const & c(form_->converters().get(cnr));
1229 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1230 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1231 converterED->setText(toqstr(c.command));
1232 converterFlagED->setText(toqstr(c.flags));
1238 void PrefConverters::converter_changed()
1244 void PrefConverters::updateButtons()
1246 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1247 Format const & to = form_->formats().get(converterToCO->currentIndex());
1248 int const sel = form_->converters().getNumber(from.name(), to.name());
1249 bool const known = sel >= 0;
1250 bool const valid = !(converterED->text().isEmpty()
1251 || from.name() == to.name());
1253 int const cnr = convertersLW->currentItem()->type();
1254 Converter const & c(form_->converters().get(cnr));
1255 string const old_command = c.command;
1256 string const old_flag = c.flags;
1257 string const new_command(fromqstr(converterED->text()));
1258 string const new_flag(fromqstr(converterFlagED->text()));
1260 bool modified = (old_command != new_command) || (old_flag != new_flag);
1262 converterModifyPB->setEnabled(valid && known && modified);
1263 converterNewPB->setEnabled(valid && !known);
1264 converterRemovePB->setEnabled(known);
1266 maxAgeLE->setEnabled(cacheCB->isChecked());
1267 maxAgeLA->setEnabled(cacheCB->isChecked());
1272 // specify unique from/to or it doesn't appear. This is really bad UI
1273 // this is why we can use the same function for both new and modify
1274 void PrefConverters::update_converter()
1276 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1277 Format const & to = form_->formats().get(converterToCO->currentIndex());
1278 string const flags = fromqstr(converterFlagED->text());
1279 string const command = fromqstr(converterED->text());
1281 Converter const * old =
1282 form_->converters().getConverter(from.name(), to.name());
1283 form_->converters().add(from.name(), to.name(), command, flags);
1286 form_->converters().updateLast(form_->formats());
1290 // Remove all files created by this converter from the cache, since
1291 // the modified converter might create different files.
1292 ConverterCache::get().remove_all(from.name(), to.name());
1296 void PrefConverters::remove_converter()
1298 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1299 Format const & to = form_->formats().get(converterToCO->currentIndex());
1300 form_->converters().erase(from.name(), to.name());
1304 // Remove all files created by this converter from the cache, since
1305 // a possible new converter might create different files.
1306 ConverterCache::get().remove_all(from.name(), to.name());
1310 void PrefConverters::on_cacheCB_stateChanged(int state)
1312 maxAgeLE->setEnabled(state == Qt::Checked);
1313 maxAgeLA->setEnabled(state == Qt::Checked);
1318 /////////////////////////////////////////////////////////////////////
1322 /////////////////////////////////////////////////////////////////////
1324 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1325 : QValidator(parent), formats_(f)
1330 void FormatValidator::fixup(QString & input) const
1332 Formats::const_iterator cit = formats_.begin();
1333 Formats::const_iterator end = formats_.end();
1334 for (; cit != end; ++cit) {
1335 string const name = str(cit);
1336 if (distance(formats_.begin(), cit) == nr()) {
1337 input = toqstr(name);
1345 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1347 Formats::const_iterator cit = formats_.begin();
1348 Formats::const_iterator end = formats_.end();
1349 bool unknown = true;
1350 for (; unknown && cit != end; ++cit) {
1351 string const name = str(cit);
1352 if (distance(formats_.begin(), cit) != nr())
1353 unknown = toqstr(name) != input;
1356 if (unknown && !input.isEmpty())
1357 return QValidator::Acceptable;
1359 return QValidator::Intermediate;
1363 int FormatValidator::nr() const
1365 QComboBox * p = qobject_cast<QComboBox *>(parent());
1366 return p->itemData(p->currentIndex()).toInt();
1370 FormatNameValidator::FormatNameValidator(QWidget * parent, Formats const & f)
1371 : FormatValidator(parent, f)
1375 string FormatNameValidator::str(Formats::const_iterator it) const
1381 FormatPrettynameValidator::FormatPrettynameValidator(QWidget * parent, Formats const & f)
1382 : FormatValidator(parent, f)
1387 string FormatPrettynameValidator::str(Formats::const_iterator it) const
1389 return it->prettyname();
1393 PrefFileformats::PrefFileformats(GuiPreferences * form, QWidget * parent)
1394 : PrefModule(qt_("File formats"), form, parent)
1397 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1398 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1400 connect(documentCB, SIGNAL(clicked()),
1401 this, SLOT(setFlags()));
1402 connect(vectorCB, SIGNAL(clicked()),
1403 this, SLOT(setFlags()));
1404 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1405 this, SLOT(updatePrettyname()));
1406 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1407 this, SIGNAL(changed()));
1411 void PrefFileformats::apply(LyXRC & /*rc*/) const
1416 void PrefFileformats::update(LyXRC const & /*rc*/)
1422 void PrefFileformats::updateView()
1424 QString const current = formatsCB->currentText();
1426 // update combobox with formats
1427 formatsCB->blockSignals(true);
1429 form_->formats().sort();
1430 Formats::const_iterator cit = form_->formats().begin();
1431 Formats::const_iterator end = form_->formats().end();
1432 for (; cit != end; ++cit)
1433 formatsCB->addItem(toqstr(cit->prettyname()),
1434 QVariant(form_->formats().getNumber(cit->name())) );
1436 // restore selection
1437 int const item = formatsCB->findText(current, Qt::MatchExactly);
1438 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1439 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1440 formatsCB->blockSignals(false);
1444 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1446 int const nr = formatsCB->itemData(i).toInt();
1447 Format const f = form_->formats().get(nr);
1449 formatED->setText(toqstr(f.name()));
1450 copierED->setText(toqstr(form_->movers().command(f.name())));
1451 extensionED->setText(toqstr(f.extension()));
1452 shortcutED->setText(toqstr(f.shortcut()));
1453 viewerED->setText(toqstr(f.viewer()));
1454 editorED->setText(toqstr(f.editor()));
1455 documentCB->setChecked((f.documentFormat()));
1456 vectorCB->setChecked((f.vectorFormat()));
1460 void PrefFileformats::setFlags()
1462 int flags = Format::none;
1463 if (documentCB->isChecked())
1464 flags |= Format::document;
1465 if (vectorCB->isChecked())
1466 flags |= Format::vector;
1467 currentFormat().setFlags(flags);
1472 void PrefFileformats::on_copierED_textEdited(const QString & s)
1474 string const fmt = fromqstr(formatED->text());
1475 form_->movers().set(fmt, fromqstr(s));
1480 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1482 currentFormat().setExtension(fromqstr(s));
1486 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1488 currentFormat().setViewer(fromqstr(s));
1493 void PrefFileformats::on_editorED_textEdited(const QString & s)
1495 currentFormat().setEditor(fromqstr(s));
1500 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1502 currentFormat().setShortcut(fromqstr(s));
1507 void PrefFileformats::on_formatED_editingFinished()
1509 string const newname = fromqstr(formatED->displayText());
1510 if (newname == currentFormat().name())
1513 currentFormat().setName(newname);
1518 void PrefFileformats::on_formatED_textChanged(const QString &)
1520 QString t = formatED->text();
1522 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1523 setValid(formatLA, valid);
1527 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1529 QString t = formatsCB->currentText();
1531 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1532 setValid(formatsLA, valid);
1536 void PrefFileformats::updatePrettyname()
1538 string const newname = fromqstr(formatsCB->currentText());
1539 if (newname == currentFormat().prettyname())
1542 currentFormat().setPrettyname(newname);
1549 Format & PrefFileformats::currentFormat()
1551 int const i = formatsCB->currentIndex();
1552 int const nr = formatsCB->itemData(i).toInt();
1553 return form_->formats().get(nr);
1557 void PrefFileformats::on_formatNewPB_clicked()
1559 form_->formats().add("", "", "", "", "", "", Format::none);
1561 formatsCB->setCurrentIndex(0);
1562 formatsCB->setFocus(Qt::OtherFocusReason);
1566 void PrefFileformats::on_formatRemovePB_clicked()
1568 int const i = formatsCB->currentIndex();
1569 int const nr = formatsCB->itemData(i).toInt();
1570 string const current_text = form_->formats().get(nr).name();
1571 if (form_->converters().formatIsUsed(current_text)) {
1572 Alert::error(_("Format in use"),
1573 _("Cannot remove a Format used by a Converter. "
1574 "Remove the converter first."));
1578 form_->formats().erase(current_text);
1581 on_formatsCB_editTextChanged(formatsCB->currentText());
1586 /////////////////////////////////////////////////////////////////////
1590 /////////////////////////////////////////////////////////////////////
1592 PrefLanguage::PrefLanguage(QWidget * parent)
1593 : PrefModule(qt_("Language"), 0, parent)
1597 connect(rtlGB, SIGNAL(clicked()),
1598 this, SIGNAL(changed()));
1599 connect(visualCursorRB, SIGNAL(clicked()),
1600 this, SIGNAL(changed()));
1601 connect(logicalCursorRB, SIGNAL(clicked()),
1602 this, SIGNAL(changed()));
1603 connect(markForeignCB, SIGNAL(clicked()),
1604 this, SIGNAL(changed()));
1605 connect(autoBeginCB, SIGNAL(clicked()),
1606 this, SIGNAL(changed()));
1607 connect(autoEndCB, SIGNAL(clicked()),
1608 this, SIGNAL(changed()));
1609 connect(useBabelCB, SIGNAL(clicked()),
1610 this, SIGNAL(changed()));
1611 connect(globalCB, SIGNAL(clicked()),
1612 this, SIGNAL(changed()));
1613 connect(languagePackageED, SIGNAL(textChanged(QString)),
1614 this, SIGNAL(changed()));
1615 connect(startCommandED, SIGNAL(textChanged(QString)),
1616 this, SIGNAL(changed()));
1617 connect(endCommandED, SIGNAL(textChanged(QString)),
1618 this, SIGNAL(changed()));
1619 connect(defaultLanguageCO, SIGNAL(activated(int)),
1620 this, SIGNAL(changed()));
1622 defaultLanguageCO->clear();
1624 // store the lang identifiers for later
1625 //foreach (LanguagePair const & lpair, languageData(false)) {
1626 QList<LanguagePair> l = languageData(false);
1627 foreach (LanguagePair const & lpair, l) {
1628 defaultLanguageCO->addItem(lpair.first);
1629 lang_.append(lpair.second);
1634 void PrefLanguage::apply(LyXRC & rc) const
1636 // FIXME: remove rtl_support bool
1637 rc.rtl_support = rtlGB->isChecked();
1638 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
1639 rc.mark_foreign_language = markForeignCB->isChecked();
1640 rc.language_auto_begin = autoBeginCB->isChecked();
1641 rc.language_auto_end = autoEndCB->isChecked();
1642 rc.language_use_babel = useBabelCB->isChecked();
1643 rc.language_global_options = globalCB->isChecked();
1644 rc.language_package = fromqstr(languagePackageED->text());
1645 rc.language_command_begin = fromqstr(startCommandED->text());
1646 rc.language_command_end = fromqstr(endCommandED->text());
1647 rc.default_language = fromqstr(lang_[defaultLanguageCO->currentIndex()]);
1651 void PrefLanguage::update(LyXRC const & rc)
1653 // FIXME: remove rtl_support bool
1654 rtlGB->setChecked(rc.rtl_support);
1655 if (rc.visual_cursor)
1656 visualCursorRB->setChecked(true);
1658 logicalCursorRB->setChecked(true);
1659 markForeignCB->setChecked(rc.mark_foreign_language);
1660 autoBeginCB->setChecked(rc.language_auto_begin);
1661 autoEndCB->setChecked(rc.language_auto_end);
1662 useBabelCB->setChecked(rc.language_use_babel);
1663 globalCB->setChecked(rc.language_global_options);
1664 languagePackageED->setText(toqstr(rc.language_package));
1665 startCommandED->setText(toqstr(rc.language_command_begin));
1666 endCommandED->setText(toqstr(rc.language_command_end));
1668 int const pos = findPos_helper(lang_, toqstr(rc.default_language));
1669 defaultLanguageCO->setCurrentIndex(pos);
1673 /////////////////////////////////////////////////////////////////////
1677 /////////////////////////////////////////////////////////////////////
1679 PrefPrinter::PrefPrinter(QWidget * parent)
1680 : PrefModule(qt_("Printer"), 0, parent)
1684 connect(printerAdaptCB, SIGNAL(clicked()),
1685 this, SIGNAL(changed()));
1686 connect(printerCommandED, SIGNAL(textChanged(QString)),
1687 this, SIGNAL(changed()));
1688 connect(printerNameED, SIGNAL(textChanged(QString)),
1689 this, SIGNAL(changed()));
1690 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
1691 this, SIGNAL(changed()));
1692 connect(printerCopiesED, SIGNAL(textChanged(QString)),
1693 this, SIGNAL(changed()));
1694 connect(printerReverseED, SIGNAL(textChanged(QString)),
1695 this, SIGNAL(changed()));
1696 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
1697 this, SIGNAL(changed()));
1698 connect(printerExtensionED, SIGNAL(textChanged(QString)),
1699 this, SIGNAL(changed()));
1700 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
1701 this, SIGNAL(changed()));
1702 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
1703 this, SIGNAL(changed()));
1704 connect(printerEvenED, SIGNAL(textChanged(QString)),
1705 this, SIGNAL(changed()));
1706 connect(printerOddED, SIGNAL(textChanged(QString)),
1707 this, SIGNAL(changed()));
1708 connect(printerCollatedED, SIGNAL(textChanged(QString)),
1709 this, SIGNAL(changed()));
1710 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
1711 this, SIGNAL(changed()));
1712 connect(printerToFileED, SIGNAL(textChanged(QString)),
1713 this, SIGNAL(changed()));
1714 connect(printerExtraED, SIGNAL(textChanged(QString)),
1715 this, SIGNAL(changed()));
1716 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
1717 this, SIGNAL(changed()));
1718 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
1719 this, SIGNAL(changed()));
1723 void PrefPrinter::apply(LyXRC & rc) const
1725 rc.print_adapt_output = printerAdaptCB->isChecked();
1726 rc.print_command = fromqstr(printerCommandED->text());
1727 rc.printer = fromqstr(printerNameED->text());
1729 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1730 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1731 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1732 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1733 rc.print_file_extension = fromqstr(printerExtensionED->text());
1734 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1735 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1736 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1737 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1738 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1739 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1740 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1741 rc.print_extra_options = fromqstr(printerExtraED->text());
1742 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1743 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1747 void PrefPrinter::update(LyXRC const & rc)
1749 printerAdaptCB->setChecked(rc.print_adapt_output);
1750 printerCommandED->setText(toqstr(rc.print_command));
1751 printerNameED->setText(toqstr(rc.printer));
1753 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1754 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1755 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1756 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1757 printerExtensionED->setText(toqstr(rc.print_file_extension));
1758 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1759 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1760 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1761 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1762 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1763 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1764 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1765 printerExtraED->setText(toqstr(rc.print_extra_options));
1766 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1767 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1771 /////////////////////////////////////////////////////////////////////
1773 // PrefUserInterface
1775 /////////////////////////////////////////////////////////////////////
1777 PrefUserInterface::PrefUserInterface(GuiPreferences * form, QWidget * parent)
1778 : PrefModule(qt_("User interface"), form, parent)
1782 connect(autoSaveCB, SIGNAL(toggled(bool)),
1783 autoSaveSB, SLOT(setEnabled(bool)));
1784 connect(autoSaveCB, SIGNAL(toggled(bool)),
1785 TextLabel1, SLOT(setEnabled(bool)));
1786 connect(openDocumentsInTabsCB, SIGNAL(clicked()),
1787 this, SIGNAL(changed()));
1788 connect(uiFilePB, SIGNAL(clicked()),
1789 this, SLOT(select_ui()));
1790 connect(uiFileED, SIGNAL(textChanged(QString)),
1791 this, SIGNAL(changed()));
1792 connect(restoreCursorCB, SIGNAL(clicked()),
1793 this, SIGNAL(changed()));
1794 connect(loadSessionCB, SIGNAL(clicked()),
1795 this, SIGNAL(changed()));
1796 connect(allowGeometrySessionCB, SIGNAL(clicked()),
1797 this, SIGNAL(changed()));
1798 connect(cursorFollowsCB, SIGNAL(clicked()),
1799 this, SIGNAL(changed()));
1800 connect(sortEnvironmentsCB, SIGNAL(clicked()),
1801 this, SIGNAL(changed()));
1802 connect(groupEnvironmentsCB, SIGNAL(clicked()),
1803 this, SIGNAL(changed()));
1804 connect(macroEditStyleCO, SIGNAL(activated(int)),
1805 this, SIGNAL(changed()));
1806 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1807 this, SIGNAL(changed()));
1808 connect(autoSaveCB, SIGNAL(clicked()),
1809 this, SIGNAL(changed()));
1810 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1811 this, SIGNAL(changed()));
1812 connect(tooltipCB, SIGNAL(toggled(bool)),
1813 this, SIGNAL(changed()));
1814 connect(fullscreenLimitGB, SIGNAL(clicked()),
1815 this, SIGNAL(changed()));
1816 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
1817 this, SIGNAL(changed()));
1818 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
1819 this, SIGNAL(changed()));
1820 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
1821 this, SIGNAL(changed()));
1822 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
1823 this, SIGNAL(changed()));
1824 lastfilesSB->setMaximum(maxlastfiles);
1828 void PrefUserInterface::apply(LyXRC & rc) const
1830 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1831 rc.use_lastfilepos = restoreCursorCB->isChecked();
1832 rc.load_session = loadSessionCB->isChecked();
1833 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
1834 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1835 rc.sort_layouts = sortEnvironmentsCB->isChecked();
1836 rc.group_layouts = groupEnvironmentsCB->isChecked();
1837 switch (macroEditStyleCO->currentIndex()) {
1838 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
1839 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
1840 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
1842 rc.autosave = autoSaveSB->value() * 60;
1843 rc.make_backup = autoSaveCB->isChecked();
1844 rc.num_lastfiles = lastfilesSB->value();
1845 rc.use_tooltip = tooltipCB->isChecked();
1846 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
1847 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
1848 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
1849 rc.full_screen_width = fullscreenWidthSB->value();
1850 rc.full_screen_limit = fullscreenLimitGB->isChecked();
1851 rc.single_window = openDocumentsInTabsCB->isChecked();
1855 void PrefUserInterface::update(LyXRC const & rc)
1857 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1858 restoreCursorCB->setChecked(rc.use_lastfilepos);
1859 loadSessionCB->setChecked(rc.load_session);
1860 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
1861 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1862 sortEnvironmentsCB->setChecked(rc.sort_layouts);
1863 groupEnvironmentsCB->setChecked(rc.group_layouts);
1864 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
1865 // convert to minutes
1866 int mins(rc.autosave / 60);
1867 if (rc.autosave && !mins)
1869 autoSaveSB->setValue(mins);
1870 autoSaveCB->setChecked(rc.make_backup);
1871 lastfilesSB->setValue(rc.num_lastfiles);
1872 tooltipCB->setChecked(rc.use_tooltip);
1873 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
1874 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
1875 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
1876 fullscreenWidthSB->setValue(rc.full_screen_width);
1877 fullscreenLimitGB->setChecked(rc.full_screen_limit);
1878 openDocumentsInTabsCB->setChecked(rc.single_window);
1882 void PrefUserInterface::select_ui()
1884 QString file = form_->browseUI(internalPath(uiFileED->text()));
1885 if (!file.isEmpty())
1886 uiFileED->setText(file);
1890 /////////////////////////////////////////////////////////////////////
1894 /////////////////////////////////////////////////////////////////////
1897 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
1899 Ui::shortcutUi::setupUi(this);
1900 QDialog::setModal(true);
1904 PrefShortcuts::PrefShortcuts(GuiPreferences * form, QWidget * parent)
1905 : PrefModule(qt_("Shortcuts"), form, parent)
1909 shortcutsTW->setColumnCount(2);
1910 shortcutsTW->headerItem()->setText(0, qt_("Function"));
1911 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
1912 shortcutsTW->setSortingEnabled(true);
1913 // Multi-selection can be annoying.
1914 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
1915 shortcutsTW->header()->resizeSection(0, 200);
1917 connect(bindFilePB, SIGNAL(clicked()),
1918 this, SLOT(select_bind()));
1919 connect(bindFileED, SIGNAL(textChanged(QString)),
1920 this, SIGNAL(changed()));
1921 connect(removePB, SIGNAL(clicked()),
1922 this, SIGNAL(changed()));
1924 shortcut_ = new GuiShortcutDialog(this);
1925 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
1926 shortcut_bc_.setOK(shortcut_->okPB);
1927 shortcut_bc_.setCancel(shortcut_->cancelPB);
1929 connect(shortcut_->okPB, SIGNAL(clicked()),
1930 shortcut_, SLOT(accept()));
1931 connect(shortcut_->okPB, SIGNAL(clicked()),
1932 this, SIGNAL(changed()));
1933 connect(shortcut_->cancelPB, SIGNAL(clicked()),
1934 shortcut_, SLOT(reject()));
1935 connect(shortcut_->clearPB, SIGNAL(clicked()),
1936 this, SLOT(shortcut_clearPB_pressed()));
1937 connect(shortcut_->okPB, SIGNAL(clicked()),
1938 this, SLOT(shortcut_okPB_pressed()));
1942 void PrefShortcuts::apply(LyXRC & rc) const
1944 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1945 // write user_bind and user_unbind to .lyx/bind/user.bind
1946 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
1947 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
1948 lyxerr << "LyX could not create the user bind directory '"
1949 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
1952 if (!bind_dir.isDirWritable()) {
1953 lyxerr << "LyX could not write to the user bind directory '"
1954 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
1957 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
1958 user_bind_.write(user_bind_file.toFilesystemEncoding(), false, false);
1959 user_unbind_.write(user_bind_file.toFilesystemEncoding(), true, true);
1960 // immediately apply the keybindings. Why this is not done before?
1961 // The good thing is that the menus are updated automatically.
1962 theTopLevelKeymap().clear();
1963 theTopLevelKeymap().read("site");
1964 theTopLevelKeymap().read(rc.bind_file);
1965 theTopLevelKeymap().read("user");
1969 void PrefShortcuts::update(LyXRC const & rc)
1971 bindFileED->setText(toqstr(external_path(rc.bind_file)));
1973 system_bind_.clear();
1975 user_unbind_.clear();
1976 system_bind_.read(rc.bind_file);
1977 // \unbind in user.bind is added to user_unbind_
1978 user_bind_.read("user", &user_unbind_);
1979 updateShortcutsTW();
1983 void PrefShortcuts::updateShortcutsTW()
1985 shortcutsTW->clear();
1987 editItem_ = new QTreeWidgetItem(shortcutsTW);
1988 editItem_->setText(0, toqstr("Cursor, Mouse and Editing functions"));
1989 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
1991 mathItem_ = new QTreeWidgetItem(shortcutsTW);
1992 mathItem_->setText(0, toqstr("Mathematical Symbols"));
1993 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
1995 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
1996 bufferItem_->setText(0, toqstr("Buffer and Window"));
1997 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
1999 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
2000 layoutItem_->setText(0, toqstr("Font, Layouts and Textclasses"));
2001 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
2003 systemItem_ = new QTreeWidgetItem(shortcutsTW);
2004 systemItem_->setText(0, toqstr("System and Miscellaneous"));
2005 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
2007 // listBindings(unbound=true) lists all bound and unbound lfuns
2008 // Items in this list is tagged by its source.
2009 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2010 static_cast<int>(System));
2011 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2012 static_cast<int>(UserBind));
2013 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2014 static_cast<int>(UserUnbind));
2015 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2016 user_bindinglist.end());
2017 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2018 user_unbindinglist.end());
2020 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2021 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2022 for (; it != it_end; ++it)
2023 insertShortcutItem(it->request, it->sequence, item_type(it->tag));
2025 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2026 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2027 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2031 void PrefShortcuts::setItemType(QTreeWidgetItem * item, item_type tag)
2033 item->setData(0, Qt::UserRole, QVariant(tag));
2043 font.setStrikeOut(true);
2045 // this item is not displayed now.
2046 case UserExtraUnbind:
2047 font.setStrikeOut(true);
2051 item->setFont(1, font);
2055 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2056 KeySequence const & seq, item_type tag)
2058 kb_action action = lfun.action;
2059 string const action_name = lyxaction.getActionName(action);
2060 QString const lfun_name = toqstr(from_utf8(action_name)
2061 + " " + lfun.argument());
2062 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2063 item_type item_tag = tag;
2065 QTreeWidgetItem * newItem = NULL;
2066 // for unbind items, try to find an existing item in the system bind list
2067 if (tag == UserUnbind) {
2068 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2069 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2070 for (int i = 0; i < items.size(); ++i) {
2071 if (items[i]->text(1) == shortcut)
2075 // if not found, this unbind item is UserExtraUnbind
2076 // Such an item is not displayed to avoid confusion (what is
2077 // unmatched removed?).
2079 item_tag = UserExtraUnbind;
2084 switch(lyxaction.getActionType(action)) {
2085 case LyXAction::Hidden:
2087 case LyXAction::Edit:
2088 newItem = new QTreeWidgetItem(editItem_);
2090 case LyXAction::Math:
2091 newItem = new QTreeWidgetItem(mathItem_);
2093 case LyXAction::Buffer:
2094 newItem = new QTreeWidgetItem(bufferItem_);
2096 case LyXAction::Layout:
2097 newItem = new QTreeWidgetItem(layoutItem_);
2099 case LyXAction::System:
2100 newItem = new QTreeWidgetItem(systemItem_);
2103 // this should not happen
2104 newItem = new QTreeWidgetItem(shortcutsTW);
2108 newItem->setText(0, lfun_name);
2109 newItem->setText(1, shortcut);
2110 // record BindFile representation to recover KeySequence when needed.
2111 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2112 setItemType(newItem, item_tag);
2117 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2119 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2120 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2121 if (items.isEmpty())
2124 item_type tag = static_cast<item_type>(items[0]->data(0, Qt::UserRole).toInt());
2125 if (tag == UserUnbind)
2126 removePB->setText(toqstr("Restore"));
2128 removePB->setText(toqstr("Remove"));
2132 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2134 QTreeWidgetItem * item = shortcutsTW->currentItem();
2135 if (item->flags() & Qt::ItemIsSelectable) {
2136 shortcut_->lfunLE->setText(item->text(0));
2137 // clear the shortcut because I assume that a user will enter
2139 shortcut_->shortcutLE->reset();
2140 shortcut_->shortcutLE->setFocus();
2146 void PrefShortcuts::select_bind()
2148 QString file = form_->browsebind(internalPath(bindFileED->text()));
2149 if (!file.isEmpty()) {
2150 bindFileED->setText(file);
2151 system_bind_ = KeyMap();
2152 system_bind_.read(fromqstr(file));
2153 updateShortcutsTW();
2158 void PrefShortcuts::on_newPB_pressed()
2160 shortcut_->lfunLE->clear();
2161 shortcut_->shortcutLE->reset();
2166 void PrefShortcuts::on_removePB_pressed()
2168 // it seems that only one item can be selected, but I am
2169 // removing all selected items anyway.
2170 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2171 for (int i = 0; i < items.size(); ++i) {
2172 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2173 string lfun = fromqstr(items[i]->text(0));
2174 FuncRequest func = lyxaction.lookupFunc(lfun);
2175 item_type tag = static_cast<item_type>(items[i]->data(0, Qt::UserRole).toInt());
2179 // for system bind, we do not touch the item
2180 // but add an user unbind item
2181 user_unbind_.bind(shortcut, func);
2182 setItemType(items[i], UserUnbind);
2183 removePB->setText(toqstr("Restore"));
2187 // for user_bind, we remove this bind
2188 QTreeWidgetItem * parent = items[i]->parent();
2189 int itemIdx = parent->indexOfChild(items[i]);
2190 parent->takeChild(itemIdx);
2192 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2194 shortcutsTW->scrollToItem(parent);
2195 user_bind_.unbind(shortcut, func);
2199 // for user_unbind, we remove the unbind, and the item
2200 // become System again.
2201 user_unbind_.unbind(shortcut, func);
2202 setItemType(items[i], System);
2203 removePB->setText(toqstr("Remove"));
2206 case UserExtraUnbind: {
2207 // for user unbind that is not in system bind file,
2208 // remove this unbind file
2209 QTreeWidgetItem * parent = items[i]->parent();
2210 parent->takeChild(parent->indexOfChild(items[i]));
2211 user_unbind_.unbind(shortcut, func);
2218 void PrefShortcuts::on_searchLE_textEdited()
2220 if (searchLE->text().isEmpty()) {
2221 // show all hidden items
2222 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2224 shortcutsTW->setItemHidden(*it++, false);
2227 // search both columns
2228 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2229 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2230 matched += shortcutsTW->findItems(searchLE->text(),
2231 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2233 // hide everyone (to avoid searching in matched QList repeatedly
2234 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2236 shortcutsTW->setItemHidden(*it++, true);
2237 // show matched items
2238 for (int i = 0; i < matched.size(); ++i) {
2239 shortcutsTW->setItemHidden(matched[i], false);
2240 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2245 void PrefShortcuts::shortcut_okPB_pressed()
2247 string lfun = fromqstr(shortcut_->lfunLE->text());
2248 FuncRequest func = lyxaction.lookupFunc(lfun);
2250 if (func.action == LFUN_UNKNOWN_ACTION) {
2251 Alert::error(_("Failed to create shortcut"),
2252 _("Unknown or invalid LyX function"));
2256 KeySequence k = shortcut_->shortcutLE->getKeySequence();
2257 if (k.length() == 0) {
2258 Alert::error(_("Failed to create shortcut"),
2259 _("Invalid or empty key sequence"));
2263 // if both lfun and shortcut is valid
2264 if (user_bind_.hasBinding(k, func) || system_bind_.hasBinding(k, func)) {
2265 Alert::error(_("Failed to create shortcut"),
2266 _("Shortcut is already defined"));
2270 QTreeWidgetItem * item = insertShortcutItem(func, k, UserBind);
2272 user_bind_.bind(&k, func);
2273 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2274 shortcutsTW->setItemExpanded(item->parent(), true);
2275 shortcutsTW->scrollToItem(item);
2277 Alert::error(_("Failed to create shortcut"),
2278 _("Can not insert shortcut to the list"));
2284 void PrefShortcuts::shortcut_clearPB_pressed()
2286 shortcut_->shortcutLE->reset();
2287 shortcut_->shortcutLE->setFocus();
2291 /////////////////////////////////////////////////////////////////////
2295 /////////////////////////////////////////////////////////////////////
2297 PrefIdentity::PrefIdentity(QWidget * parent)
2298 : PrefModule(qt_("Identity"), 0, parent)
2302 connect(nameED, SIGNAL(textChanged(QString)),
2303 this, SIGNAL(changed()));
2304 connect(emailED, SIGNAL(textChanged(QString)),
2305 this, SIGNAL(changed()));
2309 void PrefIdentity::apply(LyXRC & rc) const
2311 rc.user_name = fromqstr(nameED->text());
2312 rc.user_email = fromqstr(emailED->text());
2316 void PrefIdentity::update(LyXRC const & rc)
2318 nameED->setText(toqstr(rc.user_name));
2319 emailED->setText(toqstr(rc.user_email));
2324 /////////////////////////////////////////////////////////////////////
2328 /////////////////////////////////////////////////////////////////////
2330 GuiPreferences::GuiPreferences(GuiView & lv)
2331 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2335 QDialog::setModal(false);
2337 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2338 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2339 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2340 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2342 add(new PrefUserInterface(this));
2343 add(new PrefShortcuts(this));
2344 add(new PrefScreenFonts(this));
2345 add(new PrefColors(this));
2346 add(new PrefDisplay);
2347 add(new PrefInput(this));
2349 add(new PrefPaths(this));
2351 add(new PrefIdentity);
2353 add(new PrefLanguage);
2354 add(new PrefSpellchecker(this));
2356 add(new PrefPrinter);
2358 add(new PrefPlaintext);
2359 add(new PrefLatex(this));
2361 PrefConverters * converters = new PrefConverters(this);
2362 PrefFileformats * formats = new PrefFileformats(this);
2363 connect(formats, SIGNAL(formatsChanged()),
2364 converters, SLOT(updateGui()));
2368 prefsPS->setCurrentPanel(qt_("User interface"));
2369 // FIXME: hack to work around resizing bug in Qt >= 4.2
2370 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2371 #if QT_VERSION >= 0x040200
2372 prefsPS->updateGeometry();
2375 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2377 bc().setApply(applyPB);
2378 bc().setCancel(closePB);
2379 bc().setRestore(restorePB);
2383 void GuiPreferences::add(PrefModule * module)
2385 BOOST_ASSERT(module);
2386 prefsPS->addPanel(module, module->title());
2387 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2388 modules_.push_back(module);
2392 void GuiPreferences::change_adaptor()
2398 void GuiPreferences::apply(LyXRC & rc) const
2400 size_t end = modules_.size();
2401 for (size_t i = 0; i != end; ++i)
2402 modules_[i]->apply(rc);
2406 void GuiPreferences::updateRc(LyXRC const & rc)
2408 size_t const end = modules_.size();
2409 for (size_t i = 0; i != end; ++i)
2410 modules_[i]->update(rc);
2414 void GuiPreferences::applyView()
2420 void GuiPreferences::updateContents()
2426 bool GuiPreferences::initialiseParams(string const &)
2429 formats_ = lyx::formats;
2430 converters_ = theConverters();
2431 converters_.update(formats_);
2432 movers_ = theMovers();
2434 update_screen_font_ = false;
2440 void GuiPreferences::dispatchParams()
2443 rc_.write(ss, true);
2444 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
2445 // FIXME: these need lfuns
2447 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
2449 lyx::formats = formats_;
2451 theConverters() = converters_;
2452 theConverters().update(lyx::formats);
2453 theConverters().buildGraph();
2455 theMovers() = movers_;
2457 vector<string>::const_iterator it = colors_.begin();
2458 vector<string>::const_iterator const end = colors_.end();
2459 for (; it != end; ++it)
2460 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
2463 if (update_screen_font_) {
2464 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2465 update_screen_font_ = false;
2468 // The Save button has been pressed
2470 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
2474 void GuiPreferences::setColor(ColorCode col, string const & hex)
2476 colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
2480 void GuiPreferences::updateScreenFonts()
2482 update_screen_font_ = true;
2486 QString GuiPreferences::browsebind(QString const & file) const
2488 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
2489 FileFilterList(_("LyX bind files (*.bind)")));
2493 QString GuiPreferences::browseUI(QString const & file) const
2495 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
2496 FileFilterList(_("LyX UI files (*.ui)")));
2500 QString GuiPreferences::browsekbmap(QString const & file) const
2502 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
2503 FileFilterList(_("LyX keyboard maps (*.kmap)")));
2507 QString GuiPreferences::browsedict(QString const & file) const
2509 return browseFile(file, qt_("Choose personal dictionary"),
2510 FileFilterList(lyxrc.use_spell_lib ? _("*.pws") : _("*.ispell")));
2514 QString GuiPreferences::browse(QString const & file,
2515 QString const & title) const
2517 return browseFile(file, title, FileFilterList(), true);
2521 QString GuiPreferences::browsedir(QString const & path,
2522 QString const & title) const
2524 return browseDir(path, title);
2528 // We support less paper sizes than the document dialog
2529 // Therefore this adjustment is needed.
2530 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
2534 return PAPER_DEFAULT;
2536 return PAPER_USLETTER;
2538 return PAPER_USLEGAL;
2540 return PAPER_USEXECUTIVE;
2550 // should not happen
2551 return PAPER_DEFAULT;
2556 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
2558 switch (papersize) {
2561 case PAPER_USLETTER:
2565 case PAPER_USEXECUTIVE:
2576 // should not happen
2582 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
2585 } // namespace frontend
2588 #include "GuiPrefs_moc.cpp"