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();
796 void PrefColors::change_color()
798 int const row = lyxObjectsLW->currentRow();
804 QString const color = newcolors_[row];
805 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
807 if (c.isValid() && c.name() != color) {
808 newcolors_[row] = c.name();
809 QPixmap coloritem(32, 32);
811 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
817 void PrefColors::change_lyxObjects_selection()
819 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
823 /////////////////////////////////////////////////////////////////////
827 /////////////////////////////////////////////////////////////////////
829 PrefDisplay::PrefDisplay(QWidget * parent)
830 : PrefModule(qt_("Graphics"), 0, parent)
833 connect(instantPreviewCO, SIGNAL(activated(int)),
834 this, SIGNAL(changed()));
835 connect(displayGraphicsCO, SIGNAL(activated(int)),
836 this, SIGNAL(changed()));
840 void PrefDisplay::apply(LyXRC & rc) const
842 switch (instantPreviewCO->currentIndex()) {
843 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
844 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
845 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
848 graphics::DisplayType dtype;
849 switch (displayGraphicsCO->currentIndex()) {
850 case 3: dtype = graphics::NoDisplay; break;
851 case 2: dtype = graphics::ColorDisplay; break;
852 case 1: dtype = graphics::GrayscaleDisplay; break;
853 case 0: dtype = graphics::MonochromeDisplay; break;
854 default: dtype = graphics::GrayscaleDisplay;
856 rc.display_graphics = dtype;
858 // FIXME!! The graphics cache no longer has a changeDisplay method.
860 if (old_value != rc.display_graphics) {
861 graphics::GCache & gc = graphics::GCache::get();
868 void PrefDisplay::update(LyXRC const & rc)
870 switch (rc.preview) {
871 case LyXRC::PREVIEW_OFF:
872 instantPreviewCO->setCurrentIndex(0);
874 case LyXRC::PREVIEW_NO_MATH :
875 instantPreviewCO->setCurrentIndex(1);
877 case LyXRC::PREVIEW_ON :
878 instantPreviewCO->setCurrentIndex(2);
883 switch (rc.display_graphics) {
884 case graphics::NoDisplay: item = 3; break;
885 case graphics::ColorDisplay: item = 2; break;
886 case graphics::GrayscaleDisplay: item = 1; break;
887 case graphics::MonochromeDisplay: item = 0; break;
890 displayGraphicsCO->setCurrentIndex(item);
894 /////////////////////////////////////////////////////////////////////
898 /////////////////////////////////////////////////////////////////////
900 PrefPaths::PrefPaths(GuiPreferences * form, QWidget * parent)
901 : PrefModule(qt_("Paths"), form, parent)
904 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(select_exampledir()));
905 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
906 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
907 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
908 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
909 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
910 connect(workingDirED, SIGNAL(textChanged(QString)),
911 this, SIGNAL(changed()));
912 connect(exampleDirED, SIGNAL(textChanged(QString)),
913 this, SIGNAL(changed()));
914 connect(templateDirED, SIGNAL(textChanged(QString)),
915 this, SIGNAL(changed()));
916 connect(backupDirED, SIGNAL(textChanged(QString)),
917 this, SIGNAL(changed()));
918 connect(tempDirED, SIGNAL(textChanged(QString)),
919 this, SIGNAL(changed()));
920 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
921 this, SIGNAL(changed()));
922 connect(pathPrefixED, SIGNAL(textChanged(QString)),
923 this, SIGNAL(changed()));
927 void PrefPaths::apply(LyXRC & rc) const
929 rc.document_path = internal_path(fromqstr(workingDirED->text()));
930 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
931 rc.template_path = internal_path(fromqstr(templateDirED->text()));
932 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
933 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
934 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
935 // FIXME: should be a checkbox only
936 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
940 void PrefPaths::update(LyXRC const & rc)
942 workingDirED->setText(toqstr(external_path(rc.document_path)));
943 exampleDirED->setText(toqstr(external_path(rc.example_path)));
944 templateDirED->setText(toqstr(external_path(rc.template_path)));
945 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
946 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
947 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
948 // FIXME: should be a checkbox only
949 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
953 void PrefPaths::select_exampledir()
955 QString file = form_->browsedir(internalPath(exampleDirED->text()),
956 qt_("Select directory for example files"));
958 exampleDirED->setText(file);
962 void PrefPaths::select_templatedir()
964 QString file = form_->browsedir(internalPath(templateDirED->text()),
965 qt_("Select a document templates directory"));
967 templateDirED->setText(file);
971 void PrefPaths::select_tempdir()
973 QString file = form_->browsedir(internalPath(tempDirED->text()),
974 qt_("Select a temporary directory"));
976 tempDirED->setText(file);
980 void PrefPaths::select_backupdir()
982 QString file = form_->browsedir(internalPath(backupDirED->text()),
983 qt_("Select a backups directory"));
985 backupDirED->setText(file);
989 void PrefPaths::select_workingdir()
991 QString file = form_->browsedir(internalPath(workingDirED->text()),
992 qt_("Select a document directory"));
994 workingDirED->setText(file);
998 void PrefPaths::select_lyxpipe()
1000 QString file = form_->browse(internalPath(lyxserverDirED->text()),
1001 qt_("Give a filename for the LyX server pipe"));
1002 if (!file.isEmpty())
1003 lyxserverDirED->setText(file);
1007 /////////////////////////////////////////////////////////////////////
1011 /////////////////////////////////////////////////////////////////////
1013 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form, QWidget * parent)
1014 : PrefModule(qt_("Spellchecker"), form, parent)
1018 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
1019 #if defined (USE_ISPELL)
1020 connect(spellCommandCO, SIGNAL(activated(int)),
1021 this, SIGNAL(changed()));
1023 spellCommandCO->setEnabled(false);
1025 connect(altLanguageED, SIGNAL(textChanged(QString)),
1026 this, SIGNAL(changed()));
1027 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
1028 this, SIGNAL(changed()));
1029 connect(persDictionaryED, SIGNAL(textChanged(QString)),
1030 this, SIGNAL(changed()));
1031 connect(compoundWordCB, SIGNAL(clicked()),
1032 this, SIGNAL(changed()));
1033 connect(inputEncodingCB, SIGNAL(clicked()),
1034 this, SIGNAL(changed()));
1036 spellCommandCO->addItem(qt_("ispell"));
1037 spellCommandCO->addItem(qt_("aspell"));
1038 spellCommandCO->addItem(qt_("hspell"));
1040 spellCommandCO->addItem(qt_("pspell (library)"));
1043 spellCommandCO->addItem(qt_("aspell (library)"));
1049 void PrefSpellchecker::apply(LyXRC & rc) const
1051 switch (spellCommandCO->currentIndex()) {
1055 rc.use_spell_lib = false;
1056 rc.isp_command = fromqstr(spellCommandCO->currentText());
1059 rc.use_spell_lib = true;
1063 // FIXME: remove isp_use_alt_lang
1064 rc.isp_alt_lang = fromqstr(altLanguageED->text());
1065 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
1066 // FIXME: remove isp_use_esc_chars
1067 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
1068 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
1069 // FIXME: remove isp_use_pers_dict
1070 rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
1071 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
1072 rc.isp_accept_compound = compoundWordCB->isChecked();
1073 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
1077 void PrefSpellchecker::update(LyXRC const & rc)
1079 spellCommandCO->setCurrentIndex(0);
1081 if (rc.isp_command == "ispell") {
1082 spellCommandCO->setCurrentIndex(0);
1083 } else if (rc.isp_command == "aspell") {
1084 spellCommandCO->setCurrentIndex(1);
1085 } else if (rc.isp_command == "hspell") {
1086 spellCommandCO->setCurrentIndex(2);
1089 if (rc.use_spell_lib) {
1090 #if defined(USE_ASPELL) || defined(USE_PSPELL)
1091 spellCommandCO->setCurrentIndex(3);
1095 // FIXME: remove isp_use_alt_lang
1096 altLanguageED->setText(toqstr(rc.isp_alt_lang));
1097 // FIXME: remove isp_use_esc_chars
1098 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
1099 // FIXME: remove isp_use_pers_dict
1100 persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
1101 compoundWordCB->setChecked(rc.isp_accept_compound);
1102 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
1106 void PrefSpellchecker::select_dict()
1108 QString file = form_->browsedict(internalPath(persDictionaryED->text()));
1109 if (!file.isEmpty())
1110 persDictionaryED->setText(file);
1115 /////////////////////////////////////////////////////////////////////
1119 /////////////////////////////////////////////////////////////////////
1122 PrefConverters::PrefConverters(GuiPreferences * form, QWidget * parent)
1123 : PrefModule(qt_("Converters"), form, parent)
1127 connect(converterNewPB, SIGNAL(clicked()),
1128 this, SLOT(update_converter()));
1129 connect(converterRemovePB, SIGNAL(clicked()),
1130 this, SLOT(remove_converter()));
1131 connect(converterModifyPB, SIGNAL(clicked()),
1132 this, SLOT(update_converter()));
1133 connect(convertersLW, SIGNAL(currentRowChanged(int)),
1134 this, SLOT(switch_converter()));
1135 connect(converterFromCO, SIGNAL(activated(QString)),
1136 this, SLOT(converter_changed()));
1137 connect(converterToCO, SIGNAL(activated(QString)),
1138 this, SLOT(converter_changed()));
1139 connect(converterED, SIGNAL(textEdited(QString)),
1140 this, SLOT(converter_changed()));
1141 connect(converterFlagED, SIGNAL(textEdited(QString)),
1142 this, SLOT(converter_changed()));
1143 connect(converterNewPB, SIGNAL(clicked()),
1144 this, SIGNAL(changed()));
1145 connect(converterRemovePB, SIGNAL(clicked()),
1146 this, SIGNAL(changed()));
1147 connect(converterModifyPB, SIGNAL(clicked()),
1148 this, SIGNAL(changed()));
1149 connect(maxAgeLE, SIGNAL(textEdited(QString)),
1150 this, SIGNAL(changed()));
1152 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
1153 //converterDefGB->setFocusProxy(convertersLW);
1157 void PrefConverters::apply(LyXRC & rc) const
1159 rc.use_converter_cache = cacheCB->isChecked();
1160 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
1164 void PrefConverters::update(LyXRC const & rc)
1166 cacheCB->setChecked(rc.use_converter_cache);
1168 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
1169 maxAgeLE->setText(max_age);
1174 void PrefConverters::updateGui()
1176 form_->formats().sort();
1177 form_->converters().update(form_->formats());
1178 // save current selection
1179 QString current = converterFromCO->currentText()
1180 + " -> " + converterToCO->currentText();
1182 converterFromCO->clear();
1183 converterToCO->clear();
1185 Formats::const_iterator cit = form_->formats().begin();
1186 Formats::const_iterator end = form_->formats().end();
1187 for (; cit != end; ++cit) {
1188 converterFromCO->addItem(toqstr(cit->prettyname()));
1189 converterToCO->addItem(toqstr(cit->prettyname()));
1192 // currentRowChanged(int) is also triggered when updating the listwidget
1193 // block signals to avoid unnecessary calls to switch_converter()
1194 convertersLW->blockSignals(true);
1195 convertersLW->clear();
1197 Converters::const_iterator ccit = form_->converters().begin();
1198 Converters::const_iterator cend = form_->converters().end();
1199 for (; ccit != cend; ++ccit) {
1201 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
1202 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1203 new QListWidgetItem(toqstr(name), convertersLW, type);
1205 convertersLW->sortItems(Qt::AscendingOrder);
1206 convertersLW->blockSignals(false);
1208 // restore selection
1209 if (!current.isEmpty()) {
1210 QList<QListWidgetItem *> const item =
1211 convertersLW->findItems(current, Qt::MatchExactly);
1212 if (!item.isEmpty())
1213 convertersLW->setCurrentItem(item.at(0));
1216 // select first element if restoring failed
1217 if (convertersLW->currentRow() == -1)
1218 convertersLW->setCurrentRow(0);
1224 void PrefConverters::switch_converter()
1226 int const cnr = convertersLW->currentItem()->type();
1227 Converter const & c(form_->converters().get(cnr));
1228 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1229 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1230 converterED->setText(toqstr(c.command));
1231 converterFlagED->setText(toqstr(c.flags));
1237 void PrefConverters::converter_changed()
1243 void PrefConverters::updateButtons()
1245 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1246 Format const & to = form_->formats().get(converterToCO->currentIndex());
1247 int const sel = form_->converters().getNumber(from.name(), to.name());
1248 bool const known = sel >= 0;
1249 bool const valid = !(converterED->text().isEmpty()
1250 || from.name() == to.name());
1252 int const cnr = convertersLW->currentItem()->type();
1253 Converter const & c(form_->converters().get(cnr));
1254 string const old_command = c.command;
1255 string const old_flag = c.flags;
1256 string const new_command(fromqstr(converterED->text()));
1257 string const new_flag(fromqstr(converterFlagED->text()));
1259 bool modified = (old_command != new_command) || (old_flag != new_flag);
1261 converterModifyPB->setEnabled(valid && known && modified);
1262 converterNewPB->setEnabled(valid && !known);
1263 converterRemovePB->setEnabled(known);
1265 maxAgeLE->setEnabled(cacheCB->isChecked());
1266 maxAgeLA->setEnabled(cacheCB->isChecked());
1271 // specify unique from/to or it doesn't appear. This is really bad UI
1272 // this is why we can use the same function for both new and modify
1273 void PrefConverters::update_converter()
1275 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1276 Format const & to = form_->formats().get(converterToCO->currentIndex());
1277 string const flags = fromqstr(converterFlagED->text());
1278 string const command = fromqstr(converterED->text());
1280 Converter const * old =
1281 form_->converters().getConverter(from.name(), to.name());
1282 form_->converters().add(from.name(), to.name(), command, flags);
1285 form_->converters().updateLast(form_->formats());
1289 // Remove all files created by this converter from the cache, since
1290 // the modified converter might create different files.
1291 ConverterCache::get().remove_all(from.name(), to.name());
1295 void PrefConverters::remove_converter()
1297 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1298 Format const & to = form_->formats().get(converterToCO->currentIndex());
1299 form_->converters().erase(from.name(), to.name());
1303 // Remove all files created by this converter from the cache, since
1304 // a possible new converter might create different files.
1305 ConverterCache::get().remove_all(from.name(), to.name());
1309 void PrefConverters::on_cacheCB_stateChanged(int state)
1311 maxAgeLE->setEnabled(state == Qt::Checked);
1312 maxAgeLA->setEnabled(state == Qt::Checked);
1317 /////////////////////////////////////////////////////////////////////
1321 /////////////////////////////////////////////////////////////////////
1323 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1324 : QValidator(parent), formats_(f)
1329 void FormatValidator::fixup(QString & input) const
1331 Formats::const_iterator cit = formats_.begin();
1332 Formats::const_iterator end = formats_.end();
1333 for (; cit != end; ++cit) {
1334 string const name = str(cit);
1335 if (distance(formats_.begin(), cit) == nr()) {
1336 input = toqstr(name);
1344 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1346 Formats::const_iterator cit = formats_.begin();
1347 Formats::const_iterator end = formats_.end();
1348 bool unknown = true;
1349 for (; unknown && cit != end; ++cit) {
1350 string const name = str(cit);
1351 if (distance(formats_.begin(), cit) != nr())
1352 unknown = toqstr(name) != input;
1355 if (unknown && !input.isEmpty())
1356 return QValidator::Acceptable;
1358 return QValidator::Intermediate;
1362 int FormatValidator::nr() const
1364 QComboBox * p = qobject_cast<QComboBox *>(parent());
1365 return p->itemData(p->currentIndex()).toInt();
1369 FormatNameValidator::FormatNameValidator(QWidget * parent, Formats const & f)
1370 : FormatValidator(parent, f)
1374 string FormatNameValidator::str(Formats::const_iterator it) const
1380 FormatPrettynameValidator::FormatPrettynameValidator(QWidget * parent, Formats const & f)
1381 : FormatValidator(parent, f)
1386 string FormatPrettynameValidator::str(Formats::const_iterator it) const
1388 return it->prettyname();
1392 PrefFileformats::PrefFileformats(GuiPreferences * form, QWidget * parent)
1393 : PrefModule(qt_("File formats"), form, parent)
1396 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1397 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1399 connect(documentCB, SIGNAL(clicked()),
1400 this, SLOT(setFlags()));
1401 connect(vectorCB, SIGNAL(clicked()),
1402 this, SLOT(setFlags()));
1403 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1404 this, SLOT(updatePrettyname()));
1405 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1406 this, SIGNAL(changed()));
1410 void PrefFileformats::apply(LyXRC & /*rc*/) const
1415 void PrefFileformats::update(LyXRC const & /*rc*/)
1421 void PrefFileformats::updateView()
1423 QString const current = formatsCB->currentText();
1425 // update combobox with formats
1426 formatsCB->blockSignals(true);
1428 form_->formats().sort();
1429 Formats::const_iterator cit = form_->formats().begin();
1430 Formats::const_iterator end = form_->formats().end();
1431 for (; cit != end; ++cit)
1432 formatsCB->addItem(toqstr(cit->prettyname()),
1433 QVariant(form_->formats().getNumber(cit->name())) );
1435 // restore selection
1436 int const item = formatsCB->findText(current, Qt::MatchExactly);
1437 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1438 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1439 formatsCB->blockSignals(false);
1443 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1445 int const nr = formatsCB->itemData(i).toInt();
1446 Format const f = form_->formats().get(nr);
1448 formatED->setText(toqstr(f.name()));
1449 copierED->setText(toqstr(form_->movers().command(f.name())));
1450 extensionED->setText(toqstr(f.extension()));
1451 shortcutED->setText(toqstr(f.shortcut()));
1452 viewerED->setText(toqstr(f.viewer()));
1453 editorED->setText(toqstr(f.editor()));
1454 documentCB->setChecked((f.documentFormat()));
1455 vectorCB->setChecked((f.vectorFormat()));
1459 void PrefFileformats::setFlags()
1461 int flags = Format::none;
1462 if (documentCB->isChecked())
1463 flags |= Format::document;
1464 if (vectorCB->isChecked())
1465 flags |= Format::vector;
1466 currentFormat().setFlags(flags);
1471 void PrefFileformats::on_copierED_textEdited(const QString & s)
1473 string const fmt = fromqstr(formatED->text());
1474 form_->movers().set(fmt, fromqstr(s));
1479 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1481 currentFormat().setExtension(fromqstr(s));
1485 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1487 currentFormat().setViewer(fromqstr(s));
1492 void PrefFileformats::on_editorED_textEdited(const QString & s)
1494 currentFormat().setEditor(fromqstr(s));
1499 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1501 currentFormat().setShortcut(fromqstr(s));
1506 void PrefFileformats::on_formatED_editingFinished()
1508 string const newname = fromqstr(formatED->displayText());
1509 if (newname == currentFormat().name())
1512 currentFormat().setName(newname);
1517 void PrefFileformats::on_formatED_textChanged(const QString &)
1519 QString t = formatED->text();
1521 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1522 setValid(formatLA, valid);
1526 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1528 QString t = formatsCB->currentText();
1530 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1531 setValid(formatsLA, valid);
1535 void PrefFileformats::updatePrettyname()
1537 string const newname = fromqstr(formatsCB->currentText());
1538 if (newname == currentFormat().prettyname())
1541 currentFormat().setPrettyname(newname);
1548 Format & PrefFileformats::currentFormat()
1550 int const i = formatsCB->currentIndex();
1551 int const nr = formatsCB->itemData(i).toInt();
1552 return form_->formats().get(nr);
1556 void PrefFileformats::on_formatNewPB_clicked()
1558 form_->formats().add("", "", "", "", "", "", Format::none);
1560 formatsCB->setCurrentIndex(0);
1561 formatsCB->setFocus(Qt::OtherFocusReason);
1565 void PrefFileformats::on_formatRemovePB_clicked()
1567 int const i = formatsCB->currentIndex();
1568 int const nr = formatsCB->itemData(i).toInt();
1569 string const current_text = form_->formats().get(nr).name();
1570 if (form_->converters().formatIsUsed(current_text)) {
1571 Alert::error(_("Format in use"),
1572 _("Cannot remove a Format used by a Converter. "
1573 "Remove the converter first."));
1577 form_->formats().erase(current_text);
1580 on_formatsCB_editTextChanged(formatsCB->currentText());
1585 /////////////////////////////////////////////////////////////////////
1589 /////////////////////////////////////////////////////////////////////
1591 PrefLanguage::PrefLanguage(QWidget * parent)
1592 : PrefModule(qt_("Language"), 0, parent)
1596 connect(rtlGB, SIGNAL(clicked()),
1597 this, SIGNAL(changed()));
1598 connect(visualCursorRB, SIGNAL(clicked()),
1599 this, SIGNAL(changed()));
1600 connect(logicalCursorRB, SIGNAL(clicked()),
1601 this, SIGNAL(changed()));
1602 connect(markForeignCB, SIGNAL(clicked()),
1603 this, SIGNAL(changed()));
1604 connect(autoBeginCB, SIGNAL(clicked()),
1605 this, SIGNAL(changed()));
1606 connect(autoEndCB, SIGNAL(clicked()),
1607 this, SIGNAL(changed()));
1608 connect(useBabelCB, SIGNAL(clicked()),
1609 this, SIGNAL(changed()));
1610 connect(globalCB, SIGNAL(clicked()),
1611 this, SIGNAL(changed()));
1612 connect(languagePackageED, SIGNAL(textChanged(QString)),
1613 this, SIGNAL(changed()));
1614 connect(startCommandED, SIGNAL(textChanged(QString)),
1615 this, SIGNAL(changed()));
1616 connect(endCommandED, SIGNAL(textChanged(QString)),
1617 this, SIGNAL(changed()));
1618 connect(defaultLanguageCO, SIGNAL(activated(int)),
1619 this, SIGNAL(changed()));
1621 defaultLanguageCO->clear();
1623 // store the lang identifiers for later
1624 //foreach (LanguagePair const & lpair, languageData(false)) {
1625 QList<LanguagePair> l = languageData(false);
1626 foreach (LanguagePair const & lpair, l) {
1627 defaultLanguageCO->addItem(lpair.first);
1628 lang_.append(lpair.second);
1633 void PrefLanguage::apply(LyXRC & rc) const
1635 // FIXME: remove rtl_support bool
1636 rc.rtl_support = rtlGB->isChecked();
1637 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
1638 rc.mark_foreign_language = markForeignCB->isChecked();
1639 rc.language_auto_begin = autoBeginCB->isChecked();
1640 rc.language_auto_end = autoEndCB->isChecked();
1641 rc.language_use_babel = useBabelCB->isChecked();
1642 rc.language_global_options = globalCB->isChecked();
1643 rc.language_package = fromqstr(languagePackageED->text());
1644 rc.language_command_begin = fromqstr(startCommandED->text());
1645 rc.language_command_end = fromqstr(endCommandED->text());
1646 rc.default_language = fromqstr(lang_[defaultLanguageCO->currentIndex()]);
1650 void PrefLanguage::update(LyXRC const & rc)
1652 // FIXME: remove rtl_support bool
1653 rtlGB->setChecked(rc.rtl_support);
1654 if (rc.visual_cursor)
1655 visualCursorRB->setChecked(true);
1657 logicalCursorRB->setChecked(true);
1658 markForeignCB->setChecked(rc.mark_foreign_language);
1659 autoBeginCB->setChecked(rc.language_auto_begin);
1660 autoEndCB->setChecked(rc.language_auto_end);
1661 useBabelCB->setChecked(rc.language_use_babel);
1662 globalCB->setChecked(rc.language_global_options);
1663 languagePackageED->setText(toqstr(rc.language_package));
1664 startCommandED->setText(toqstr(rc.language_command_begin));
1665 endCommandED->setText(toqstr(rc.language_command_end));
1667 int const pos = findPos_helper(lang_, toqstr(rc.default_language));
1668 defaultLanguageCO->setCurrentIndex(pos);
1672 /////////////////////////////////////////////////////////////////////
1676 /////////////////////////////////////////////////////////////////////
1678 PrefPrinter::PrefPrinter(QWidget * parent)
1679 : PrefModule(qt_("Printer"), 0, parent)
1683 connect(printerAdaptCB, SIGNAL(clicked()),
1684 this, SIGNAL(changed()));
1685 connect(printerCommandED, SIGNAL(textChanged(QString)),
1686 this, SIGNAL(changed()));
1687 connect(printerNameED, SIGNAL(textChanged(QString)),
1688 this, SIGNAL(changed()));
1689 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
1690 this, SIGNAL(changed()));
1691 connect(printerCopiesED, SIGNAL(textChanged(QString)),
1692 this, SIGNAL(changed()));
1693 connect(printerReverseED, SIGNAL(textChanged(QString)),
1694 this, SIGNAL(changed()));
1695 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
1696 this, SIGNAL(changed()));
1697 connect(printerExtensionED, SIGNAL(textChanged(QString)),
1698 this, SIGNAL(changed()));
1699 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
1700 this, SIGNAL(changed()));
1701 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
1702 this, SIGNAL(changed()));
1703 connect(printerEvenED, SIGNAL(textChanged(QString)),
1704 this, SIGNAL(changed()));
1705 connect(printerOddED, SIGNAL(textChanged(QString)),
1706 this, SIGNAL(changed()));
1707 connect(printerCollatedED, SIGNAL(textChanged(QString)),
1708 this, SIGNAL(changed()));
1709 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
1710 this, SIGNAL(changed()));
1711 connect(printerToFileED, SIGNAL(textChanged(QString)),
1712 this, SIGNAL(changed()));
1713 connect(printerExtraED, SIGNAL(textChanged(QString)),
1714 this, SIGNAL(changed()));
1715 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
1716 this, SIGNAL(changed()));
1717 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
1718 this, SIGNAL(changed()));
1722 void PrefPrinter::apply(LyXRC & rc) const
1724 rc.print_adapt_output = printerAdaptCB->isChecked();
1725 rc.print_command = fromqstr(printerCommandED->text());
1726 rc.printer = fromqstr(printerNameED->text());
1728 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1729 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1730 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1731 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1732 rc.print_file_extension = fromqstr(printerExtensionED->text());
1733 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1734 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1735 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1736 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1737 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1738 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1739 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1740 rc.print_extra_options = fromqstr(printerExtraED->text());
1741 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1742 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1746 void PrefPrinter::update(LyXRC const & rc)
1748 printerAdaptCB->setChecked(rc.print_adapt_output);
1749 printerCommandED->setText(toqstr(rc.print_command));
1750 printerNameED->setText(toqstr(rc.printer));
1752 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1753 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1754 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1755 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1756 printerExtensionED->setText(toqstr(rc.print_file_extension));
1757 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1758 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1759 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1760 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1761 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1762 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1763 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1764 printerExtraED->setText(toqstr(rc.print_extra_options));
1765 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1766 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1770 /////////////////////////////////////////////////////////////////////
1772 // PrefUserInterface
1774 /////////////////////////////////////////////////////////////////////
1776 PrefUserInterface::PrefUserInterface(GuiPreferences * form, QWidget * parent)
1777 : PrefModule(qt_("User interface"), form, parent)
1781 connect(autoSaveCB, SIGNAL(toggled(bool)),
1782 autoSaveSB, SLOT(setEnabled(bool)));
1783 connect(autoSaveCB, SIGNAL(toggled(bool)),
1784 TextLabel1, SLOT(setEnabled(bool)));
1785 connect(uiFilePB, SIGNAL(clicked()),
1786 this, SLOT(select_ui()));
1787 connect(uiFileED, SIGNAL(textChanged(QString)),
1788 this, SIGNAL(changed()));
1789 connect(restoreCursorCB, SIGNAL(clicked()),
1790 this, SIGNAL(changed()));
1791 connect(loadSessionCB, SIGNAL(clicked()),
1792 this, SIGNAL(changed()));
1793 connect(allowGeometrySessionCB, SIGNAL(clicked()),
1794 this, SIGNAL(changed()));
1795 connect(cursorFollowsCB, SIGNAL(clicked()),
1796 this, SIGNAL(changed()));
1797 connect(sortEnvironmentsCB, SIGNAL(clicked()),
1798 this, SIGNAL(changed()));
1799 connect(macroEditStyleCO, SIGNAL(activated(int)),
1800 this, SIGNAL(changed()));
1801 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1802 this, SIGNAL(changed()));
1803 connect(autoSaveCB, SIGNAL(clicked()),
1804 this, SIGNAL(changed()));
1805 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1806 this, SIGNAL(changed()));
1807 connect(tooltipCB, SIGNAL(toggled(bool)),
1808 this, SIGNAL(changed()));
1809 connect(fullscreenLimitGB, SIGNAL(clicked()),
1810 this, SIGNAL(changed()));
1811 connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
1812 this, SIGNAL(changed()));
1813 connect(toggleTabbarCB, SIGNAL(toggled(bool)),
1814 this, SIGNAL(changed()));
1815 connect(toggleScrollbarCB, SIGNAL(toggled(bool)),
1816 this, SIGNAL(changed()));
1817 connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
1818 this, SIGNAL(changed()));
1819 lastfilesSB->setMaximum(maxlastfiles);
1823 void PrefUserInterface::apply(LyXRC & rc) const
1825 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1826 rc.use_lastfilepos = restoreCursorCB->isChecked();
1827 rc.load_session = loadSessionCB->isChecked();
1828 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
1829 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1830 rc.sort_layouts = sortEnvironmentsCB->isChecked();
1831 switch (macroEditStyleCO->currentIndex()) {
1832 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
1833 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
1834 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
1836 rc.autosave = autoSaveSB->value() * 60;
1837 rc.make_backup = autoSaveCB->isChecked();
1838 rc.num_lastfiles = lastfilesSB->value();
1839 rc.use_tooltip = tooltipCB->isChecked();
1840 rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
1841 rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
1842 rc.full_screen_tabbar = toggleTabbarCB->isChecked();
1843 rc.full_screen_width = fullscreenWidthSB->value();
1844 rc.full_screen_limit = fullscreenLimitGB->isChecked();
1848 void PrefUserInterface::update(LyXRC const & rc)
1850 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1851 restoreCursorCB->setChecked(rc.use_lastfilepos);
1852 loadSessionCB->setChecked(rc.load_session);
1853 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
1854 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1855 sortEnvironmentsCB->setChecked(rc.sort_layouts);
1856 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
1857 // convert to minutes
1858 int mins(rc.autosave / 60);
1859 if (rc.autosave && !mins)
1861 autoSaveSB->setValue(mins);
1862 autoSaveCB->setChecked(rc.make_backup);
1863 lastfilesSB->setValue(rc.num_lastfiles);
1864 tooltipCB->setChecked(rc.use_tooltip);
1865 toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
1866 toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
1867 toggleTabbarCB->setChecked(rc.full_screen_tabbar);
1868 fullscreenWidthSB->setValue(rc.full_screen_width);
1869 fullscreenLimitGB->setChecked(rc.full_screen_limit);
1874 void PrefUserInterface::select_ui()
1876 QString file = form_->browseUI(internalPath(uiFileED->text()));
1877 if (!file.isEmpty())
1878 uiFileED->setText(file);
1882 /////////////////////////////////////////////////////////////////////
1886 /////////////////////////////////////////////////////////////////////
1889 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
1891 Ui::shortcutUi::setupUi(this);
1892 QDialog::setModal(true);
1896 PrefShortcuts::PrefShortcuts(GuiPreferences * form, QWidget * parent)
1897 : PrefModule(qt_("Shortcuts"), form, parent)
1901 shortcutsTW->setColumnCount(2);
1902 shortcutsTW->headerItem()->setText(0, qt_("Function"));
1903 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
1904 shortcutsTW->setSortingEnabled(true);
1905 // Multi-selection can be annoying.
1906 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
1907 shortcutsTW->header()->resizeSection(0, 200);
1909 connect(bindFilePB, SIGNAL(clicked()),
1910 this, SLOT(select_bind()));
1911 connect(bindFileED, SIGNAL(textChanged(QString)),
1912 this, SIGNAL(changed()));
1913 connect(removePB, SIGNAL(clicked()),
1914 this, SIGNAL(changed()));
1916 shortcut_ = new GuiShortcutDialog(this);
1917 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
1918 shortcut_bc_.setOK(shortcut_->okPB);
1919 shortcut_bc_.setCancel(shortcut_->cancelPB);
1921 connect(shortcut_->okPB, SIGNAL(clicked()),
1922 shortcut_, SLOT(accept()));
1923 connect(shortcut_->okPB, SIGNAL(clicked()),
1924 this, SIGNAL(changed()));
1925 connect(shortcut_->cancelPB, SIGNAL(clicked()),
1926 shortcut_, SLOT(reject()));
1927 connect(shortcut_->clearPB, SIGNAL(clicked()),
1928 this, SLOT(shortcut_clearPB_pressed()));
1929 connect(shortcut_->okPB, SIGNAL(clicked()),
1930 this, SLOT(shortcut_okPB_pressed()));
1934 void PrefShortcuts::apply(LyXRC & rc) const
1936 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1937 // write user_bind and user_unbind to .lyx/bind/user.bind
1938 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
1939 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
1940 lyxerr << "LyX could not create the user bind directory '"
1941 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
1944 if (!bind_dir.isDirWritable()) {
1945 lyxerr << "LyX could not write to the user bind directory '"
1946 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
1949 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
1950 user_bind_.write(user_bind_file.toFilesystemEncoding(), false, false);
1951 user_unbind_.write(user_bind_file.toFilesystemEncoding(), true, true);
1952 // immediately apply the keybindings. Why this is not done before?
1953 // The good thing is that the menus are updated automatically.
1954 theTopLevelKeymap().clear();
1955 theTopLevelKeymap().read("site");
1956 theTopLevelKeymap().read(rc.bind_file);
1957 theTopLevelKeymap().read("user");
1961 void PrefShortcuts::update(LyXRC const & rc)
1963 bindFileED->setText(toqstr(external_path(rc.bind_file)));
1965 system_bind_.clear();
1967 user_unbind_.clear();
1968 system_bind_.read(rc.bind_file);
1969 // \unbind in user.bind is added to user_unbind_
1970 user_bind_.read("user", &user_unbind_);
1971 updateShortcutsTW();
1975 void PrefShortcuts::updateShortcutsTW()
1977 shortcutsTW->clear();
1979 editItem_ = new QTreeWidgetItem(shortcutsTW);
1980 editItem_->setText(0, toqstr("Cursor, Mouse and Editing functions"));
1981 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
1983 mathItem_ = new QTreeWidgetItem(shortcutsTW);
1984 mathItem_->setText(0, toqstr("Mathematical Symbols"));
1985 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
1987 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
1988 bufferItem_->setText(0, toqstr("Buffer and Window"));
1989 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
1991 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
1992 layoutItem_->setText(0, toqstr("Font, Layouts and Textclasses"));
1993 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
1995 systemItem_ = new QTreeWidgetItem(shortcutsTW);
1996 systemItem_->setText(0, toqstr("System and Miscellaneous"));
1997 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
1999 // listBindings(unbound=true) lists all bound and unbound lfuns
2000 // Items in this list is tagged by its source.
2001 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
2002 static_cast<int>(System));
2003 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
2004 static_cast<int>(UserBind));
2005 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
2006 static_cast<int>(UserUnbind));
2007 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
2008 user_bindinglist.end());
2009 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
2010 user_unbindinglist.end());
2012 KeyMap::BindingList::const_iterator it = bindinglist.begin();
2013 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
2014 for (; it != it_end; ++it)
2015 insertShortcutItem(it->request, it->sequence, item_type(it->tag));
2017 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2018 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2019 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2023 void PrefShortcuts::setItemType(QTreeWidgetItem * item, item_type tag)
2025 item->setData(0, Qt::UserRole, QVariant(tag));
2035 font.setStrikeOut(true);
2037 // this item is not displayed now.
2038 case UserExtraUnbind:
2039 font.setStrikeOut(true);
2043 item->setFont(1, font);
2047 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
2048 KeySequence const & seq, item_type tag)
2050 kb_action action = lfun.action;
2051 string const action_name = lyxaction.getActionName(action);
2052 QString const lfun_name = toqstr(from_utf8(action_name)
2053 + " " + lfun.argument());
2054 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
2055 item_type item_tag = tag;
2057 QTreeWidgetItem * newItem = NULL;
2058 // for unbind items, try to find an existing item in the system bind list
2059 if (tag == UserUnbind) {
2060 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
2061 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
2062 for (int i = 0; i < items.size(); ++i) {
2063 if (items[i]->text(1) == shortcut)
2067 // if not found, this unbind item is UserExtraUnbind
2068 // Such an item is not displayed to avoid confusion (what is
2069 // unmatched removed?).
2071 item_tag = UserExtraUnbind;
2076 switch(lyxaction.getActionType(action)) {
2077 case LyXAction::Hidden:
2079 case LyXAction::Edit:
2080 newItem = new QTreeWidgetItem(editItem_);
2082 case LyXAction::Math:
2083 newItem = new QTreeWidgetItem(mathItem_);
2085 case LyXAction::Buffer:
2086 newItem = new QTreeWidgetItem(bufferItem_);
2088 case LyXAction::Layout:
2089 newItem = new QTreeWidgetItem(layoutItem_);
2091 case LyXAction::System:
2092 newItem = new QTreeWidgetItem(systemItem_);
2095 // this should not happen
2096 newItem = new QTreeWidgetItem(shortcutsTW);
2100 newItem->setText(0, lfun_name);
2101 newItem->setText(1, shortcut);
2102 // record BindFile representation to recover KeySequence when needed.
2103 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
2104 setItemType(newItem, item_tag);
2109 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
2111 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2112 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
2113 if (items.isEmpty())
2116 item_type tag = static_cast<item_type>(items[0]->data(0, Qt::UserRole).toInt());
2117 if (tag == UserUnbind)
2118 removePB->setText(toqstr("Restore"));
2120 removePB->setText(toqstr("Remove"));
2124 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2126 QTreeWidgetItem * item = shortcutsTW->currentItem();
2127 if (item->flags() & Qt::ItemIsSelectable) {
2128 shortcut_->lfunLE->setText(item->text(0));
2129 // clear the shortcut because I assume that a user will enter
2131 shortcut_->shortcutLE->reset();
2132 shortcut_->shortcutLE->setFocus();
2138 void PrefShortcuts::select_bind()
2140 QString file = form_->browsebind(internalPath(bindFileED->text()));
2141 if (!file.isEmpty()) {
2142 bindFileED->setText(file);
2143 system_bind_ = KeyMap();
2144 system_bind_.read(fromqstr(file));
2145 updateShortcutsTW();
2150 void PrefShortcuts::on_newPB_pressed()
2152 shortcut_->lfunLE->clear();
2153 shortcut_->shortcutLE->reset();
2158 void PrefShortcuts::on_removePB_pressed()
2160 // it seems that only one item can be selected, but I am
2161 // removing all selected items anyway.
2162 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2163 for (int i = 0; i < items.size(); ++i) {
2164 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
2165 string lfun = fromqstr(items[i]->text(0));
2166 FuncRequest func = lyxaction.lookupFunc(lfun);
2167 item_type tag = static_cast<item_type>(items[i]->data(0, Qt::UserRole).toInt());
2171 // for system bind, we do not touch the item
2172 // but add an user unbind item
2173 user_unbind_.bind(shortcut, func);
2174 setItemType(items[i], UserUnbind);
2175 removePB->setText(toqstr("Restore"));
2179 // for user_bind, we remove this bind
2180 QTreeWidgetItem * parent = items[i]->parent();
2181 int itemIdx = parent->indexOfChild(items[i]);
2182 parent->takeChild(itemIdx);
2184 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2186 shortcutsTW->scrollToItem(parent);
2187 user_bind_.unbind(shortcut, func);
2191 // for user_unbind, we remove the unbind, and the item
2192 // become System again.
2193 user_unbind_.unbind(shortcut, func);
2194 setItemType(items[i], System);
2195 removePB->setText(toqstr("Remove"));
2198 case UserExtraUnbind: {
2199 // for user unbind that is not in system bind file,
2200 // remove this unbind file
2201 QTreeWidgetItem * parent = items[i]->parent();
2202 parent->takeChild(parent->indexOfChild(items[i]));
2203 user_unbind_.unbind(shortcut, func);
2210 void PrefShortcuts::on_searchLE_textEdited()
2212 if (searchLE->text().isEmpty()) {
2213 // show all hidden items
2214 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2216 shortcutsTW->setItemHidden(*it++, false);
2219 // search both columns
2220 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2221 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2222 matched += shortcutsTW->findItems(searchLE->text(),
2223 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2225 // hide everyone (to avoid searching in matched QList repeatedly
2226 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2228 shortcutsTW->setItemHidden(*it++, true);
2229 // show matched items
2230 for (int i = 0; i < matched.size(); ++i) {
2231 shortcutsTW->setItemHidden(matched[i], false);
2232 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2237 void PrefShortcuts::shortcut_okPB_pressed()
2239 string lfun = fromqstr(shortcut_->lfunLE->text());
2240 FuncRequest func = lyxaction.lookupFunc(lfun);
2242 if (func.action == LFUN_UNKNOWN_ACTION) {
2243 Alert::error(_("Failed to create shortcut"),
2244 _("Unknown or invalid LyX function"));
2248 KeySequence k = shortcut_->shortcutLE->getKeySequence();
2249 if (k.length() == 0) {
2250 Alert::error(_("Failed to create shortcut"),
2251 _("Invalid or empty key sequence"));
2255 // if both lfun and shortcut is valid
2256 if (user_bind_.hasBinding(k, func) || system_bind_.hasBinding(k, func)) {
2257 Alert::error(_("Failed to create shortcut"),
2258 _("Shortcut is already defined"));
2262 QTreeWidgetItem * item = insertShortcutItem(func, k, UserBind);
2264 user_bind_.bind(&k, func);
2265 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2266 shortcutsTW->setItemExpanded(item->parent(), true);
2267 shortcutsTW->scrollToItem(item);
2269 Alert::error(_("Failed to create shortcut"),
2270 _("Can not insert shortcut to the list"));
2276 void PrefShortcuts::shortcut_clearPB_pressed()
2278 shortcut_->shortcutLE->reset();
2279 shortcut_->shortcutLE->setFocus();
2283 /////////////////////////////////////////////////////////////////////
2287 /////////////////////////////////////////////////////////////////////
2289 PrefIdentity::PrefIdentity(QWidget * parent)
2290 : PrefModule(qt_("Identity"), 0, parent)
2294 connect(nameED, SIGNAL(textChanged(QString)),
2295 this, SIGNAL(changed()));
2296 connect(emailED, SIGNAL(textChanged(QString)),
2297 this, SIGNAL(changed()));
2301 void PrefIdentity::apply(LyXRC & rc) const
2303 rc.user_name = fromqstr(nameED->text());
2304 rc.user_email = fromqstr(emailED->text());
2308 void PrefIdentity::update(LyXRC const & rc)
2310 nameED->setText(toqstr(rc.user_name));
2311 emailED->setText(toqstr(rc.user_email));
2316 /////////////////////////////////////////////////////////////////////
2320 /////////////////////////////////////////////////////////////////////
2322 GuiPreferences::GuiPreferences(GuiView & lv)
2323 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2327 QDialog::setModal(false);
2329 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2330 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2331 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2332 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2334 add(new PrefUserInterface(this));
2335 add(new PrefShortcuts(this));
2336 add(new PrefScreenFonts(this));
2337 add(new PrefColors(this));
2338 add(new PrefDisplay);
2339 add(new PrefInput(this));
2341 add(new PrefPaths(this));
2343 add(new PrefIdentity);
2345 add(new PrefLanguage);
2346 add(new PrefSpellchecker(this));
2348 add(new PrefPrinter);
2350 add(new PrefPlaintext);
2351 add(new PrefLatex(this));
2353 PrefConverters * converters = new PrefConverters(this);
2354 PrefFileformats * formats = new PrefFileformats(this);
2355 connect(formats, SIGNAL(formatsChanged()),
2356 converters, SLOT(updateGui()));
2360 prefsPS->setCurrentPanel(qt_("User interface"));
2361 // FIXME: hack to work around resizing bug in Qt >= 4.2
2362 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2363 #if QT_VERSION >= 0x040200
2364 prefsPS->updateGeometry();
2367 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2369 bc().setApply(applyPB);
2370 bc().setCancel(closePB);
2371 bc().setRestore(restorePB);
2375 void GuiPreferences::add(PrefModule * module)
2377 BOOST_ASSERT(module);
2378 prefsPS->addPanel(module, module->title());
2379 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2380 modules_.push_back(module);
2384 void GuiPreferences::change_adaptor()
2390 void GuiPreferences::apply(LyXRC & rc) const
2392 size_t end = modules_.size();
2393 for (size_t i = 0; i != end; ++i)
2394 modules_[i]->apply(rc);
2398 void GuiPreferences::updateRc(LyXRC const & rc)
2400 size_t const end = modules_.size();
2401 for (size_t i = 0; i != end; ++i)
2402 modules_[i]->update(rc);
2406 void GuiPreferences::applyView()
2412 void GuiPreferences::updateContents()
2418 bool GuiPreferences::initialiseParams(string const &)
2421 formats_ = lyx::formats;
2422 converters_ = theConverters();
2423 converters_.update(formats_);
2424 movers_ = theMovers();
2426 update_screen_font_ = false;
2432 void GuiPreferences::dispatchParams()
2435 rc_.write(ss, true);
2436 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
2437 // FIXME: these need lfuns
2439 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
2441 lyx::formats = formats_;
2443 theConverters() = converters_;
2444 theConverters().update(lyx::formats);
2445 theConverters().buildGraph();
2447 theMovers() = movers_;
2449 vector<string>::const_iterator it = colors_.begin();
2450 vector<string>::const_iterator const end = colors_.end();
2451 for (; it != end; ++it)
2452 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
2455 if (update_screen_font_) {
2456 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2457 update_screen_font_ = false;
2460 // The Save button has been pressed
2462 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
2466 void GuiPreferences::setColor(ColorCode col, string const & hex)
2468 colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
2472 void GuiPreferences::updateScreenFonts()
2474 update_screen_font_ = true;
2478 QString GuiPreferences::browsebind(QString const & file) const
2480 return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
2481 FileFilterList(_("LyX bind files (*.bind)")));
2485 QString GuiPreferences::browseUI(QString const & file) const
2487 return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
2488 FileFilterList(_("LyX UI files (*.ui)")));
2492 QString GuiPreferences::browsekbmap(QString const & file) const
2494 return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
2495 FileFilterList(_("LyX keyboard maps (*.kmap)")));
2499 QString GuiPreferences::browsedict(QString const & file) const
2501 return browseFile(file, qt_("Choose personal dictionary"),
2502 FileFilterList(lyxrc.use_spell_lib ? _("*.pws") : _("*.ispell")));
2506 QString GuiPreferences::browse(QString const & file,
2507 QString const & title) const
2509 return browseFile(file, title, FileFilterList(), true);
2513 QString GuiPreferences::browsedir(QString const & path,
2514 QString const & title) const
2516 return browseDir(path, title);
2520 // We support less paper sizes than the document dialog
2521 // Therefore this adjustment is needed.
2522 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
2526 return PAPER_DEFAULT;
2528 return PAPER_USLETTER;
2530 return PAPER_USLEGAL;
2532 return PAPER_USEXECUTIVE;
2542 // should not happen
2543 return PAPER_DEFAULT;
2548 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
2550 switch (papersize) {
2553 case PAPER_USLETTER:
2557 case PAPER_USEXECUTIVE:
2568 // should not happen
2574 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
2577 } // namespace frontend
2580 #include "GuiPrefs_moc.cpp"