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"
24 #include "FuncRequest.h"
26 #include "GuiFontExample.h"
27 #include "GuiKeySymbol.h"
29 #include "KeySequence.h"
30 #include "LyXAction.h"
31 #include "PanelStack.h"
35 #include "support/FileName.h"
36 #include "support/filetools.h"
37 #include "support/lstrings.h"
38 #include "support/lyxlib.h"
39 #include "support/os.h"
40 #include "support/Package.h"
41 #include "support/FileFilterList.h"
43 #include "graphics/GraphicsTypes.h"
45 #include "frontend_helpers.h"
47 #include "frontends/alert.h"
48 #include "frontends/Application.h"
51 #include <QColorDialog>
52 #include <QFontDatabase>
53 #include <QHeaderView>
55 #include <QPixmapCache>
56 #include <QPushButton>
59 #include <QTreeWidget>
60 #include <QTreeWidgetItem>
62 #include <QCloseEvent>
72 using std::ostringstream;
80 using support::compare_ascii_no_case;
81 using support::os::external_path;
82 using support::os::external_path_list;
83 using support::os::internal_path;
84 using support::os::internal_path_list;
85 using support::FileName;
86 using support::FileFilterList;
87 using support::addPath;
88 using support::addName;
90 using support::package;
93 /////////////////////////////////////////////////////////////////////
97 /////////////////////////////////////////////////////////////////////
100 static size_t findPos_helper(std::vector<A> const & vec, A const & val)
102 typedef typename std::vector<A>::const_iterator Cit;
104 Cit it = std::find(vec.begin(), vec.end(), val);
107 return std::distance(vec.begin(), it);
111 static std::pair<string, string> parseFontName(string const & name)
113 string::size_type const idx = name.find('[');
114 if (idx == string::npos || idx == 0)
115 return make_pair(name, string());
116 return make_pair(name.substr(0, idx - 1),
117 name.substr(idx + 1, name.size() - idx - 2));
121 static void setComboxFont(QComboBox * cb, string const & family,
122 string const & foundry)
124 QString fontname = toqstr(family);
125 if (!foundry.empty())
126 fontname += " [" + toqstr(foundry) + ']';
128 for (int i = 0; i < cb->count(); ++i) {
129 if (cb->itemText(i) == fontname) {
130 cb->setCurrentIndex(i);
135 // Try matching without foundry name
137 // We count in reverse in order to prefer the Xft foundry
138 for (int i = cb->count(); --i >= 0;) {
139 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
140 if (compare_ascii_no_case(tmp.first, family) == 0) {
141 cb->setCurrentIndex(i);
146 // family alone can contain e.g. "Helvetica [Adobe]"
147 pair<string, string> tmpfam = parseFontName(family);
149 // We count in reverse in order to prefer the Xft foundry
150 for (int i = cb->count() - 1; i >= 0; --i) {
151 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
152 if (compare_ascii_no_case(tmp.first, tmpfam.first) == 0) {
153 cb->setCurrentIndex(i);
158 // Bleh, default fonts, and the names couldn't be found. Hack
162 font.setKerning(false);
164 if (family == theApp()->romanFontName()) {
165 font.setStyleHint(QFont::Serif);
166 font.setFamily(family.c_str());
167 } else if (family == theApp()->sansFontName()) {
168 font.setStyleHint(QFont::SansSerif);
169 font.setFamily(family.c_str());
170 } else if (family == theApp()->typewriterFontName()) {
171 font.setStyleHint(QFont::TypeWriter);
172 font.setFamily(family.c_str());
174 lyxerr << "FAILED to find the default font: '"
175 << foundry << "', '" << family << '\''<< endl;
179 QFontInfo info(font);
180 pair<string, string> tmp = parseFontName(fromqstr(info.family()));
181 string const & default_font_name = tmp.first;
182 lyxerr << "Apparent font is " << default_font_name << endl;
184 for (int i = 0; i < cb->count(); ++i) {
185 lyxerr << "Looking at " << fromqstr(cb->itemText(i)) << endl;
186 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
187 default_font_name) == 0) {
188 cb->setCurrentIndex(i);
193 lyxerr << "FAILED to find the font: '"
194 << foundry << "', '" << family << '\'' <<endl;
198 /////////////////////////////////////////////////////////////////////
202 /////////////////////////////////////////////////////////////////////
204 PrefPlaintext::PrefPlaintext(QWidget * parent)
205 : PrefModule(_("Plain text"), 0, parent)
208 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
209 this, SIGNAL(changed()));
210 connect(plaintextRoffED, SIGNAL(textChanged(QString)),
211 this, SIGNAL(changed()));
215 void PrefPlaintext::apply(LyXRC & rc) const
217 rc.plaintext_linelen = plaintextLinelengthSB->value();
218 rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
222 void PrefPlaintext::update(LyXRC const & rc)
224 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
225 plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
229 /////////////////////////////////////////////////////////////////////
233 /////////////////////////////////////////////////////////////////////
235 PrefDate::PrefDate(QWidget * parent)
236 : PrefModule(_("Date format"), 0, parent)
239 connect(DateED, SIGNAL(textChanged(QString)),
240 this, SIGNAL(changed()));
244 void PrefDate::apply(LyXRC & rc) const
246 rc.date_insert_format = fromqstr(DateED->text());
250 void PrefDate::update(LyXRC const & rc)
252 DateED->setText(toqstr(rc.date_insert_format));
256 /////////////////////////////////////////////////////////////////////
260 /////////////////////////////////////////////////////////////////////
262 PrefKeyboard::PrefKeyboard(GuiPreferences * form, QWidget * parent)
263 : PrefModule(_("Keyboard"), form, parent)
267 connect(keymapCB, SIGNAL(clicked()),
268 this, SIGNAL(changed()));
269 connect(firstKeymapED, SIGNAL(textChanged(QString)),
270 this, SIGNAL(changed()));
271 connect(secondKeymapED, SIGNAL(textChanged(QString)),
272 this, SIGNAL(changed()));
276 void PrefKeyboard::apply(LyXRC & rc) const
278 // FIXME: can derive CB from the two EDs
279 rc.use_kbmap = keymapCB->isChecked();
280 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
281 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
285 void PrefKeyboard::update(LyXRC const & rc)
287 // FIXME: can derive CB from the two EDs
288 keymapCB->setChecked(rc.use_kbmap);
289 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
290 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
294 QString PrefKeyboard::testKeymap(QString keymap)
296 return toqstr(form_->browsekbmap(from_utf8(internal_path(fromqstr(keymap)))));
300 void PrefKeyboard::on_firstKeymapPB_clicked(bool)
302 QString const file = testKeymap(firstKeymapED->text());
304 firstKeymapED->setText(file);
308 void PrefKeyboard::on_secondKeymapPB_clicked(bool)
310 QString const file = testKeymap(secondKeymapED->text());
312 secondKeymapED->setText(file);
316 void PrefKeyboard::on_keymapCB_toggled(bool keymap)
318 firstKeymapLA->setEnabled(keymap);
319 secondKeymapLA->setEnabled(keymap);
320 firstKeymapED->setEnabled(keymap);
321 secondKeymapED->setEnabled(keymap);
322 firstKeymapPB->setEnabled(keymap);
323 secondKeymapPB->setEnabled(keymap);
327 /////////////////////////////////////////////////////////////////////
331 /////////////////////////////////////////////////////////////////////
333 PrefLatex::PrefLatex(GuiPreferences * form, QWidget * parent)
334 : PrefModule(_("LaTeX"), form, parent)
337 connect(latexEncodingED, SIGNAL(textChanged(QString)),
338 this, SIGNAL(changed()));
339 connect(latexChecktexED, SIGNAL(textChanged(QString)),
340 this, SIGNAL(changed()));
341 connect(latexBibtexED, SIGNAL(textChanged(QString)),
342 this, SIGNAL(changed()));
343 connect(latexIndexED, SIGNAL(textChanged(QString)),
344 this, SIGNAL(changed()));
345 connect(latexAutoresetCB, SIGNAL(clicked()),
346 this, SIGNAL(changed()));
347 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
348 this, SIGNAL(changed()));
349 connect(latexPaperSizeCO, SIGNAL(activated(int)),
350 this, SIGNAL(changed()));
352 #if defined(__CYGWIN__) || defined(_WIN32)
353 pathCB->setVisible(true);
354 connect(pathCB, SIGNAL(clicked()),
355 this, SIGNAL(changed()));
357 pathCB->setVisible(false);
362 void PrefLatex::apply(LyXRC & rc) const
364 rc.fontenc = fromqstr(latexEncodingED->text());
365 rc.chktex_command = fromqstr(latexChecktexED->text());
366 rc.bibtex_command = fromqstr(latexBibtexED->text());
367 rc.index_command = fromqstr(latexIndexED->text());
368 rc.auto_reset_options = latexAutoresetCB->isChecked();
369 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
370 rc.default_papersize =
371 form_->toPaperSize(latexPaperSizeCO->currentIndex());
372 #if defined(__CYGWIN__) || defined(_WIN32)
373 rc.windows_style_tex_paths = pathCB->isChecked();
378 void PrefLatex::update(LyXRC const & rc)
380 latexEncodingED->setText(toqstr(rc.fontenc));
381 latexChecktexED->setText(toqstr(rc.chktex_command));
382 latexBibtexED->setText(toqstr(rc.bibtex_command));
383 latexIndexED->setText(toqstr(rc.index_command));
384 latexAutoresetCB->setChecked(rc.auto_reset_options);
385 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
386 latexPaperSizeCO->setCurrentIndex(
387 form_->fromPaperSize(rc.default_papersize));
388 #if defined(__CYGWIN__) || defined(_WIN32)
389 pathCB->setChecked(rc.windows_style_tex_paths);
394 /////////////////////////////////////////////////////////////////////
398 /////////////////////////////////////////////////////////////////////
400 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form, QWidget * parent)
401 : PrefModule(_("Screen fonts"), form, parent)
405 connect(screenRomanCO, SIGNAL(activated(QString)),
406 this, SLOT(select_roman(QString)));
407 connect(screenSansCO, SIGNAL(activated(QString)),
408 this, SLOT(select_sans(QString)));
409 connect(screenTypewriterCO, SIGNAL(activated(QString)),
410 this, SLOT(select_typewriter(QString)));
412 QFontDatabase fontdb;
413 QStringList families(fontdb.families());
414 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
415 screenRomanCO->addItem(*it);
416 screenSansCO->addItem(*it);
417 screenTypewriterCO->addItem(*it);
419 connect(screenRomanCO, SIGNAL(activated(QString)),
420 this, SIGNAL(changed()));
421 connect(screenSansCO, SIGNAL(activated(QString)),
422 this, SIGNAL(changed()));
423 connect(screenTypewriterCO, SIGNAL(activated(QString)),
424 this, SIGNAL(changed()));
425 connect(screenZoomSB, SIGNAL(valueChanged(int)),
426 this, SIGNAL(changed()));
427 connect(screenDpiSB, SIGNAL(valueChanged(int)),
428 this, SIGNAL(changed()));
429 connect(screenTinyED, SIGNAL(textChanged(QString)),
430 this, SIGNAL(changed()));
431 connect(screenSmallestED, SIGNAL(textChanged(QString)),
432 this, SIGNAL(changed()));
433 connect(screenSmallerED, SIGNAL(textChanged(QString)),
434 this, SIGNAL(changed()));
435 connect(screenSmallED, SIGNAL(textChanged(QString)),
436 this, SIGNAL(changed()));
437 connect(screenNormalED, SIGNAL(textChanged(QString)),
438 this, SIGNAL(changed()));
439 connect(screenLargeED, SIGNAL(textChanged(QString)),
440 this, SIGNAL(changed()));
441 connect(screenLargerED, SIGNAL(textChanged(QString)),
442 this, SIGNAL(changed()));
443 connect(screenLargestED, SIGNAL(textChanged(QString)),
444 this, SIGNAL(changed()));
445 connect(screenHugeED, SIGNAL(textChanged(QString)),
446 this, SIGNAL(changed()));
447 connect(screenHugerED, SIGNAL(textChanged(QString)),
448 this, SIGNAL(changed()));
450 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
451 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
452 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
453 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
454 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
455 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
456 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
457 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
458 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
459 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
463 void PrefScreenFonts::apply(LyXRC & rc) const
465 LyXRC const oldrc = rc;
467 boost::tie(rc.roman_font_name, rc.roman_font_foundry)
468 = parseFontName(fromqstr(screenRomanCO->currentText()));
469 boost::tie(rc.sans_font_name, rc.sans_font_foundry) =
470 parseFontName(fromqstr(screenSansCO->currentText()));
471 boost::tie(rc.typewriter_font_name, rc.typewriter_font_foundry) =
472 parseFontName(fromqstr(screenTypewriterCO->currentText()));
474 rc.zoom = screenZoomSB->value();
475 rc.dpi = screenDpiSB->value();
476 rc.font_sizes[FONT_SIZE_TINY] = fromqstr(screenTinyED->text());
477 rc.font_sizes[FONT_SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
478 rc.font_sizes[FONT_SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
479 rc.font_sizes[FONT_SIZE_SMALL] = fromqstr(screenSmallED->text());
480 rc.font_sizes[FONT_SIZE_NORMAL] = fromqstr(screenNormalED->text());
481 rc.font_sizes[FONT_SIZE_LARGE] = fromqstr(screenLargeED->text());
482 rc.font_sizes[FONT_SIZE_LARGER] = fromqstr(screenLargerED->text());
483 rc.font_sizes[FONT_SIZE_LARGEST] = fromqstr(screenLargestED->text());
484 rc.font_sizes[FONT_SIZE_HUGE] = fromqstr(screenHugeED->text());
485 rc.font_sizes[FONT_SIZE_HUGER] = fromqstr(screenHugerED->text());
487 if (rc.font_sizes != oldrc.font_sizes
488 || rc.roman_font_name != oldrc.roman_font_name
489 || rc.sans_font_name != oldrc.sans_font_name
490 || rc.typewriter_font_name != oldrc.typewriter_font_name
491 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
492 // The global QPixmapCache is used in GuiPainter to cache text
493 // painting so we must reset it in case any of the above
494 // parameter is changed.
495 QPixmapCache::clear();
496 guiApp->fontLoader().update();
497 form_->updateScreenFonts();
502 void PrefScreenFonts::update(LyXRC const & rc)
504 setComboxFont(screenRomanCO, rc.roman_font_name,
505 rc.roman_font_foundry);
506 setComboxFont(screenSansCO, rc.sans_font_name,
507 rc.sans_font_foundry);
508 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
509 rc.typewriter_font_foundry);
511 select_roman(screenRomanCO->currentText());
512 select_sans(screenSansCO->currentText());
513 select_typewriter(screenTypewriterCO->currentText());
515 screenZoomSB->setValue(rc.zoom);
516 screenDpiSB->setValue(rc.dpi);
517 screenTinyED->setText(toqstr(rc.font_sizes[FONT_SIZE_TINY]));
518 screenSmallestED->setText(toqstr(rc.font_sizes[FONT_SIZE_SCRIPT]));
519 screenSmallerED->setText(toqstr(rc.font_sizes[FONT_SIZE_FOOTNOTE]));
520 screenSmallED->setText(toqstr(rc.font_sizes[FONT_SIZE_SMALL]));
521 screenNormalED->setText(toqstr(rc.font_sizes[FONT_SIZE_NORMAL]));
522 screenLargeED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGE]));
523 screenLargerED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGER]));
524 screenLargestED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGEST]));
525 screenHugeED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGE]));
526 screenHugerED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGER]));
530 void PrefScreenFonts::select_roman(const QString & name)
532 screenRomanFE->set(QFont(name), name);
536 void PrefScreenFonts::select_sans(const QString & name)
538 screenSansFE->set(QFont(name), name);
542 void PrefScreenFonts::select_typewriter(const QString & name)
544 screenTypewriterFE->set(QFont(name), name);
548 /////////////////////////////////////////////////////////////////////
552 /////////////////////////////////////////////////////////////////////
558 bool operator()(ColorCode lhs, ColorCode rhs) const {
559 return lcolor.getGUIName(lhs) < lcolor.getGUIName(rhs);
565 PrefColors::PrefColors(GuiPreferences * form, QWidget * parent)
566 : PrefModule( _("Colors"), form, parent)
570 // FIXME: all of this initialization should be put into the controller.
571 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
572 // for some discussion of why that is not trivial.
573 QPixmap icon(32, 32);
574 for (int i = 0; i < Color_ignore; ++i) {
575 ColorCode lc = static_cast<ColorCode>(i);
583 || lc == Color_magenta
584 || lc == Color_yellow
585 || lc == Color_inherit
586 || lc == Color_ignore) continue;
588 lcolors_.push_back(lc);
590 std::sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
591 vector<ColorCode>::const_iterator cit = lcolors_.begin();
592 vector<ColorCode>::const_iterator const end = lcolors_.end();
593 for (; cit != end; ++cit) {
594 (void) new QListWidgetItem(QIcon(icon),
595 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
597 curcolors_.resize(lcolors_.size());
598 newcolors_.resize(lcolors_.size());
599 // End initialization
601 connect(colorChangePB, SIGNAL(clicked()),
602 this, SLOT(change_color()));
603 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
604 this, SLOT(change_lyxObjects_selection()));
605 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
606 this, SLOT(change_color()));
610 void PrefColors::apply(LyXRC & /*rc*/) const
612 for (unsigned int i = 0; i < lcolors_.size(); ++i)
613 if (curcolors_[i] != newcolors_[i])
614 form_->setColor(lcolors_[i], fromqstr(newcolors_[i]));
618 void PrefColors::update(LyXRC const & /*rc*/)
620 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
621 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
622 QPixmap coloritem(32, 32);
623 coloritem.fill(color);
624 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
625 newcolors_[i] = curcolors_[i] = color.name();
627 change_lyxObjects_selection();
630 void PrefColors::change_color()
632 int const row = lyxObjectsLW->currentRow();
638 QString const color = newcolors_[row];
639 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
641 if (c.isValid() && c.name() != color) {
642 newcolors_[row] = c.name();
643 QPixmap coloritem(32, 32);
645 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
651 void PrefColors::change_lyxObjects_selection()
653 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
657 /////////////////////////////////////////////////////////////////////
661 /////////////////////////////////////////////////////////////////////
663 PrefDisplay::PrefDisplay(QWidget * parent)
664 : PrefModule(_("Graphics"), 0, parent)
667 connect(instantPreviewCO, SIGNAL(activated(int)),
668 this, SIGNAL(changed()));
669 connect(displayGraphicsCO, SIGNAL(activated(int)),
670 this, SIGNAL(changed()));
674 void PrefDisplay::apply(LyXRC & rc) const
676 switch (instantPreviewCO->currentIndex()) {
677 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
678 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
679 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
682 lyx::graphics::DisplayType dtype;
683 switch (displayGraphicsCO->currentIndex()) {
684 case 3: dtype = graphics::NoDisplay; break;
685 case 2: dtype = graphics::ColorDisplay; break;
686 case 1: dtype = graphics::GrayscaleDisplay; break;
687 case 0: dtype = graphics::MonochromeDisplay; break;
688 default: dtype = graphics::GrayscaleDisplay;
690 rc.display_graphics = dtype;
692 // FIXME!! The graphics cache no longer has a changeDisplay method.
694 if (old_value != rc.display_graphics) {
695 graphics::GCache & gc = graphics::GCache::get();
702 void PrefDisplay::update(LyXRC const & rc)
704 switch (rc.preview) {
705 case LyXRC::PREVIEW_OFF:
706 instantPreviewCO->setCurrentIndex(0);
708 case LyXRC::PREVIEW_NO_MATH :
709 instantPreviewCO->setCurrentIndex(1);
711 case LyXRC::PREVIEW_ON :
712 instantPreviewCO->setCurrentIndex(2);
717 switch (rc.display_graphics) {
718 case graphics::NoDisplay: item = 3; break;
719 case graphics::ColorDisplay: item = 2; break;
720 case graphics::GrayscaleDisplay: item = 1; break;
721 case graphics::MonochromeDisplay: item = 0; break;
724 displayGraphicsCO->setCurrentIndex(item);
728 /////////////////////////////////////////////////////////////////////
732 /////////////////////////////////////////////////////////////////////
734 PrefPaths::PrefPaths(GuiPreferences * form, QWidget * parent)
735 : PrefModule(_("Paths"), form, parent)
738 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
739 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
740 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
741 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
742 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
743 connect(workingDirED, SIGNAL(textChanged(QString)),
744 this, SIGNAL(changed()));
745 connect(templateDirED, SIGNAL(textChanged(QString)),
746 this, SIGNAL(changed()));
747 connect(backupDirED, SIGNAL(textChanged(QString)),
748 this, SIGNAL(changed()));
749 connect(tempDirED, SIGNAL(textChanged(QString)),
750 this, SIGNAL(changed()));
751 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
752 this, SIGNAL(changed()));
753 connect(pathPrefixED, SIGNAL(textChanged(QString)),
754 this, SIGNAL(changed()));
758 void PrefPaths::apply(LyXRC & rc) const
760 rc.document_path = internal_path(fromqstr(workingDirED->text()));
761 rc.template_path = internal_path(fromqstr(templateDirED->text()));
762 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
763 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
764 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
765 // FIXME: should be a checkbox only
766 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
770 void PrefPaths::update(LyXRC const & rc)
772 workingDirED->setText(toqstr(external_path(rc.document_path)));
773 templateDirED->setText(toqstr(external_path(rc.template_path)));
774 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
775 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
776 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
777 // FIXME: should be a checkbox only
778 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
782 void PrefPaths::select_templatedir()
784 docstring file(form_->browsedir(
785 from_utf8(internal_path(fromqstr(templateDirED->text()))),
786 _("Select a document templates directory")));
788 templateDirED->setText(toqstr(file));
792 void PrefPaths::select_tempdir()
794 docstring file(form_->browsedir(
795 from_utf8(internal_path(fromqstr(tempDirED->text()))),
796 _("Select a temporary directory")));
798 tempDirED->setText(toqstr(file));
802 void PrefPaths::select_backupdir()
804 docstring file(form_->browsedir(
805 from_utf8(internal_path(fromqstr(backupDirED->text()))),
806 _("Select a backups directory")));
808 backupDirED->setText(toqstr(file));
812 void PrefPaths::select_workingdir()
814 docstring file(form_->browsedir(
815 from_utf8(internal_path(fromqstr(workingDirED->text()))),
816 _("Select a document directory")));
818 workingDirED->setText(toqstr(file));
822 void PrefPaths::select_lyxpipe()
824 docstring file(form_->browse(
825 from_utf8(internal_path(fromqstr(lyxserverDirED->text()))),
826 _("Give a filename for the LyX server pipe")));
828 lyxserverDirED->setText(toqstr(file));
832 /////////////////////////////////////////////////////////////////////
836 /////////////////////////////////////////////////////////////////////
838 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form, QWidget * parent)
839 : PrefModule(_("Spellchecker"), form, parent)
843 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
844 #if defined (USE_ISPELL)
845 connect(spellCommandCO, SIGNAL(activated(int)),
846 this, SIGNAL(changed()));
848 spellCommandCO->setEnabled(false);
850 connect(altLanguageED, SIGNAL(textChanged(QString)),
851 this, SIGNAL(changed()));
852 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
853 this, SIGNAL(changed()));
854 connect(persDictionaryED, SIGNAL(textChanged(QString)),
855 this, SIGNAL(changed()));
856 connect(compoundWordCB, SIGNAL(clicked()),
857 this, SIGNAL(changed()));
858 connect(inputEncodingCB, SIGNAL(clicked()),
859 this, SIGNAL(changed()));
861 spellCommandCO->addItem(qt_("ispell"));
862 spellCommandCO->addItem(qt_("aspell"));
863 spellCommandCO->addItem(qt_("hspell"));
865 spellCommandCO->addItem(qt_("pspell (library)"));
868 spellCommandCO->addItem(qt_("aspell (library)"));
874 void PrefSpellchecker::apply(LyXRC & rc) const
876 switch (spellCommandCO->currentIndex()) {
880 rc.use_spell_lib = false;
881 rc.isp_command = fromqstr(spellCommandCO->currentText());
884 rc.use_spell_lib = true;
888 // FIXME: remove isp_use_alt_lang
889 rc.isp_alt_lang = fromqstr(altLanguageED->text());
890 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
891 // FIXME: remove isp_use_esc_chars
892 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
893 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
894 // FIXME: remove isp_use_pers_dict
895 rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
896 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
897 rc.isp_accept_compound = compoundWordCB->isChecked();
898 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
902 void PrefSpellchecker::update(LyXRC const & rc)
904 spellCommandCO->setCurrentIndex(0);
906 if (rc.isp_command == "ispell") {
907 spellCommandCO->setCurrentIndex(0);
908 } else if (rc.isp_command == "aspell") {
909 spellCommandCO->setCurrentIndex(1);
910 } else if (rc.isp_command == "hspell") {
911 spellCommandCO->setCurrentIndex(2);
914 if (rc.use_spell_lib) {
915 #if defined(USE_ASPELL) || defined(USE_PSPELL)
916 spellCommandCO->setCurrentIndex(3);
920 // FIXME: remove isp_use_alt_lang
921 altLanguageED->setText(toqstr(rc.isp_alt_lang));
922 // FIXME: remove isp_use_esc_chars
923 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
924 // FIXME: remove isp_use_pers_dict
925 persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
926 compoundWordCB->setChecked(rc.isp_accept_compound);
927 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
931 void PrefSpellchecker::select_dict()
933 docstring file(form_->browsedict(
934 from_utf8(internal_path(fromqstr(persDictionaryED->text())))));
936 persDictionaryED->setText(toqstr(file));
941 /////////////////////////////////////////////////////////////////////
945 /////////////////////////////////////////////////////////////////////
948 PrefConverters::PrefConverters(GuiPreferences * form, QWidget * parent)
949 : PrefModule(_("Converters"), form, parent)
953 connect(converterNewPB, SIGNAL(clicked()),
954 this, SLOT(update_converter()));
955 connect(converterRemovePB, SIGNAL(clicked()),
956 this, SLOT(remove_converter()));
957 connect(converterModifyPB, SIGNAL(clicked()),
958 this, SLOT(update_converter()));
959 connect(convertersLW, SIGNAL(currentRowChanged(int)),
960 this, SLOT(switch_converter()));
961 connect(converterFromCO, SIGNAL(activated(QString)),
962 this, SLOT(converter_changed()));
963 connect(converterToCO, SIGNAL(activated(QString)),
964 this, SLOT(converter_changed()));
965 connect(converterED, SIGNAL(textEdited(QString)),
966 this, SLOT(converter_changed()));
967 connect(converterFlagED, SIGNAL(textEdited(QString)),
968 this, SLOT(converter_changed()));
969 connect(converterNewPB, SIGNAL(clicked()),
970 this, SIGNAL(changed()));
971 connect(converterRemovePB, SIGNAL(clicked()),
972 this, SIGNAL(changed()));
973 connect(converterModifyPB, SIGNAL(clicked()),
974 this, SIGNAL(changed()));
975 connect(maxAgeLE, SIGNAL(textEdited(QString)),
976 this, SIGNAL(changed()));
978 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
979 //converterDefGB->setFocusProxy(convertersLW);
983 void PrefConverters::apply(LyXRC & rc) const
985 rc.use_converter_cache = cacheCB->isChecked();
986 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
990 void PrefConverters::update(LyXRC const & rc)
992 cacheCB->setChecked(rc.use_converter_cache);
994 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
995 maxAgeLE->setText(max_age);
1000 void PrefConverters::updateGui()
1002 form_->formats().sort();
1003 form_->converters().update(form_->formats());
1004 // save current selection
1005 QString current = converterFromCO->currentText()
1006 + " -> " + converterToCO->currentText();
1008 converterFromCO->clear();
1009 converterToCO->clear();
1011 Formats::const_iterator cit = form_->formats().begin();
1012 Formats::const_iterator end = form_->formats().end();
1013 for (; cit != end; ++cit) {
1014 converterFromCO->addItem(toqstr(cit->prettyname()));
1015 converterToCO->addItem(toqstr(cit->prettyname()));
1018 // currentRowChanged(int) is also triggered when updating the listwidget
1019 // block signals to avoid unnecessary calls to switch_converter()
1020 convertersLW->blockSignals(true);
1021 convertersLW->clear();
1023 Converters::const_iterator ccit = form_->converters().begin();
1024 Converters::const_iterator cend = form_->converters().end();
1025 for (; ccit != cend; ++ccit) {
1026 std::string const name =
1027 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
1028 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1029 new QListWidgetItem(toqstr(name), convertersLW, type);
1031 convertersLW->sortItems(Qt::AscendingOrder);
1032 convertersLW->blockSignals(false);
1034 // restore selection
1035 if (!current.isEmpty()) {
1036 QList<QListWidgetItem *> const item =
1037 convertersLW->findItems(current, Qt::MatchExactly);
1038 if (!item.isEmpty())
1039 convertersLW->setCurrentItem(item.at(0));
1042 // select first element if restoring failed
1043 if (convertersLW->currentRow() == -1)
1044 convertersLW->setCurrentRow(0);
1050 void PrefConverters::switch_converter()
1052 int const cnr = convertersLW->currentItem()->type();
1053 Converter const & c(form_->converters().get(cnr));
1054 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1055 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1056 converterED->setText(toqstr(c.command));
1057 converterFlagED->setText(toqstr(c.flags));
1063 void PrefConverters::converter_changed()
1069 void PrefConverters::updateButtons()
1071 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1072 Format const & to = form_->formats().get(converterToCO->currentIndex());
1073 int const sel = form_->converters().getNumber(from.name(), to.name());
1074 bool const known = sel >= 0;
1075 bool const valid = !(converterED->text().isEmpty()
1076 || from.name() == to.name());
1078 int const cnr = convertersLW->currentItem()->type();
1079 Converter const & c(form_->converters().get(cnr));
1080 string const old_command = c.command;
1081 string const old_flag = c.flags;
1082 string const new_command(fromqstr(converterED->text()));
1083 string const new_flag(fromqstr(converterFlagED->text()));
1085 bool modified = (old_command != new_command) || (old_flag != new_flag);
1087 converterModifyPB->setEnabled(valid && known && modified);
1088 converterNewPB->setEnabled(valid && !known);
1089 converterRemovePB->setEnabled(known);
1091 maxAgeLE->setEnabled(cacheCB->isChecked());
1092 maxAgeLA->setEnabled(cacheCB->isChecked());
1097 // specify unique from/to or it doesn't appear. This is really bad UI
1098 // this is why we can use the same function for both new and modify
1099 void PrefConverters::update_converter()
1101 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1102 Format const & to = form_->formats().get(converterToCO->currentIndex());
1103 string const flags = fromqstr(converterFlagED->text());
1104 string const command = fromqstr(converterED->text());
1106 Converter const * old =
1107 form_->converters().getConverter(from.name(), to.name());
1108 form_->converters().add(from.name(), to.name(), command, flags);
1111 form_->converters().updateLast(form_->formats());
1115 // Remove all files created by this converter from the cache, since
1116 // the modified converter might create different files.
1117 ConverterCache::get().remove_all(from.name(), to.name());
1121 void PrefConverters::remove_converter()
1123 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1124 Format const & to = form_->formats().get(converterToCO->currentIndex());
1125 form_->converters().erase(from.name(), to.name());
1129 // Remove all files created by this converter from the cache, since
1130 // a possible new converter might create different files.
1131 ConverterCache::get().remove_all(from.name(), to.name());
1135 void PrefConverters::on_cacheCB_stateChanged(int state)
1137 maxAgeLE->setEnabled(state == Qt::Checked);
1138 maxAgeLA->setEnabled(state == Qt::Checked);
1143 /////////////////////////////////////////////////////////////////////
1147 /////////////////////////////////////////////////////////////////////
1149 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1150 : QValidator(parent), formats_(f)
1155 void FormatValidator::fixup(QString & input) const
1157 Formats::const_iterator cit = formats_.begin();
1158 Formats::const_iterator end = formats_.end();
1159 for (; cit != end; ++cit) {
1160 string const name = str(cit);
1161 if (distance(formats_.begin(), cit) == nr()) {
1162 input = toqstr(name);
1170 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1172 Formats::const_iterator cit = formats_.begin();
1173 Formats::const_iterator end = formats_.end();
1174 bool unknown = true;
1175 for (; unknown && cit != end; ++cit) {
1176 string const name = str(cit);
1177 if (distance(formats_.begin(), cit) != nr())
1178 unknown = toqstr(name) != input;
1181 if (unknown && !input.isEmpty())
1182 return QValidator::Acceptable;
1184 return QValidator::Intermediate;
1188 int FormatValidator::nr() const
1190 QComboBox * p = qobject_cast<QComboBox *>(parent());
1191 return p->itemData(p->currentIndex()).toInt();
1195 FormatNameValidator::FormatNameValidator(QWidget * parent, Formats const & f)
1196 : FormatValidator(parent, f)
1200 std::string FormatNameValidator::str(Formats::const_iterator it) const
1206 FormatPrettynameValidator::FormatPrettynameValidator(QWidget * parent, Formats const & f)
1207 : FormatValidator(parent, f)
1212 std::string FormatPrettynameValidator::str(Formats::const_iterator it) const
1214 return it->prettyname();
1218 PrefFileformats::PrefFileformats(GuiPreferences * form, QWidget * parent)
1219 : PrefModule(_("File formats"), form, parent)
1222 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1223 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1225 connect(documentCB, SIGNAL(clicked()),
1226 this, SLOT(setFlags()));
1227 connect(vectorCB, SIGNAL(clicked()),
1228 this, SLOT(setFlags()));
1229 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1230 this, SLOT(updatePrettyname()));
1231 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1232 this, SIGNAL(changed()));
1236 void PrefFileformats::apply(LyXRC & /*rc*/) const
1241 void PrefFileformats::update(LyXRC const & /*rc*/)
1247 void PrefFileformats::updateView()
1249 QString const current = formatsCB->currentText();
1251 // update combobox with formats
1252 formatsCB->blockSignals(true);
1254 form_->formats().sort();
1255 Formats::const_iterator cit = form_->formats().begin();
1256 Formats::const_iterator end = form_->formats().end();
1257 for (; cit != end; ++cit)
1258 formatsCB->addItem(toqstr(cit->prettyname()),
1259 QVariant(form_->formats().getNumber(cit->name())) );
1261 // restore selection
1262 int const item = formatsCB->findText(current, Qt::MatchExactly);
1263 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1264 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1265 formatsCB->blockSignals(false);
1269 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1271 int const nr = formatsCB->itemData(i).toInt();
1272 Format const f = form_->formats().get(nr);
1274 formatED->setText(toqstr(f.name()));
1275 copierED->setText(toqstr(form_->movers().command(f.name())));
1276 extensionED->setText(toqstr(f.extension()));
1277 shortcutED->setText(toqstr(f.shortcut()));
1278 viewerED->setText(toqstr(f.viewer()));
1279 editorED->setText(toqstr(f.editor()));
1280 documentCB->setChecked((f.documentFormat()));
1281 vectorCB->setChecked((f.vectorFormat()));
1285 void PrefFileformats::setFlags()
1287 int flags = Format::none;
1288 if (documentCB->isChecked())
1289 flags |= Format::document;
1290 if (vectorCB->isChecked())
1291 flags |= Format::vector;
1292 currentFormat().setFlags(flags);
1297 void PrefFileformats::on_copierED_textEdited(const QString & s)
1299 string const fmt = fromqstr(formatED->text());
1300 form_->movers().set(fmt, fromqstr(s));
1305 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1307 currentFormat().setExtension(fromqstr(s));
1311 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1313 currentFormat().setViewer(fromqstr(s));
1318 void PrefFileformats::on_editorED_textEdited(const QString & s)
1320 currentFormat().setEditor(fromqstr(s));
1325 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1327 currentFormat().setShortcut(fromqstr(s));
1332 void PrefFileformats::on_formatED_editingFinished()
1334 string const newname = fromqstr(formatED->displayText());
1335 if (newname == currentFormat().name())
1338 currentFormat().setName(newname);
1343 void PrefFileformats::on_formatED_textChanged(const QString &)
1345 QString t = formatED->text();
1347 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1348 setValid(formatLA, valid);
1352 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1354 QString t = formatsCB->currentText();
1356 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1357 setValid(formatsLA, valid);
1361 void PrefFileformats::updatePrettyname()
1363 string const newname = fromqstr(formatsCB->currentText());
1364 if (newname == currentFormat().prettyname())
1367 currentFormat().setPrettyname(newname);
1374 Format & PrefFileformats::currentFormat()
1376 int const i = formatsCB->currentIndex();
1377 int const nr = formatsCB->itemData(i).toInt();
1378 return form_->formats().get(nr);
1382 void PrefFileformats::on_formatNewPB_clicked()
1384 form_->formats().add("", "", "", "", "", "", Format::none);
1386 formatsCB->setCurrentIndex(0);
1387 formatsCB->setFocus(Qt::OtherFocusReason);
1391 void PrefFileformats::on_formatRemovePB_clicked()
1393 int const i = formatsCB->currentIndex();
1394 int const nr = formatsCB->itemData(i).toInt();
1395 string const current_text = form_->formats().get(nr).name();
1396 if (form_->converters().formatIsUsed(current_text)) {
1397 Alert::error(_("Format in use"),
1398 _("Cannot remove a Format used by a Converter. "
1399 "Remove the converter first."));
1403 form_->formats().erase(current_text);
1406 on_formatsCB_editTextChanged(formatsCB->currentText());
1411 /////////////////////////////////////////////////////////////////////
1415 /////////////////////////////////////////////////////////////////////
1417 PrefLanguage::PrefLanguage(QWidget * parent)
1418 : PrefModule(_("Language"), 0, parent)
1422 connect(rtlCB, SIGNAL(clicked()),
1423 this, SIGNAL(changed()));
1424 connect(markForeignCB, SIGNAL(clicked()),
1425 this, SIGNAL(changed()));
1426 connect(autoBeginCB, SIGNAL(clicked()),
1427 this, SIGNAL(changed()));
1428 connect(autoEndCB, SIGNAL(clicked()),
1429 this, SIGNAL(changed()));
1430 connect(useBabelCB, SIGNAL(clicked()),
1431 this, SIGNAL(changed()));
1432 connect(globalCB, SIGNAL(clicked()),
1433 this, SIGNAL(changed()));
1434 connect(languagePackageED, SIGNAL(textChanged(QString)),
1435 this, SIGNAL(changed()));
1436 connect(startCommandED, SIGNAL(textChanged(QString)),
1437 this, SIGNAL(changed()));
1438 connect(endCommandED, SIGNAL(textChanged(QString)),
1439 this, SIGNAL(changed()));
1440 connect(defaultLanguageCO, SIGNAL(activated(int)),
1441 this, SIGNAL(changed()));
1443 defaultLanguageCO->clear();
1445 // store the lang identifiers for later
1446 std::vector<LanguagePair> const langs = frontend::getLanguageData(false);
1447 std::vector<LanguagePair>::const_iterator lit = langs.begin();
1448 std::vector<LanguagePair>::const_iterator lend = langs.end();
1450 for (; lit != lend; ++lit) {
1451 defaultLanguageCO->addItem(toqstr(lit->first));
1452 lang_.push_back(lit->second);
1457 void PrefLanguage::apply(LyXRC & rc) const
1459 // FIXME: remove rtl_support bool
1460 rc.rtl_support = rtlCB->isChecked();
1461 rc.mark_foreign_language = markForeignCB->isChecked();
1462 rc.language_auto_begin = autoBeginCB->isChecked();
1463 rc.language_auto_end = autoEndCB->isChecked();
1464 rc.language_use_babel = useBabelCB->isChecked();
1465 rc.language_global_options = globalCB->isChecked();
1466 rc.language_package = fromqstr(languagePackageED->text());
1467 rc.language_command_begin = fromqstr(startCommandED->text());
1468 rc.language_command_end = fromqstr(endCommandED->text());
1469 rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1473 void PrefLanguage::update(LyXRC const & rc)
1475 // FIXME: remove rtl_support bool
1476 rtlCB->setChecked(rc.rtl_support);
1477 markForeignCB->setChecked(rc.mark_foreign_language);
1478 autoBeginCB->setChecked(rc.language_auto_begin);
1479 autoEndCB->setChecked(rc.language_auto_end);
1480 useBabelCB->setChecked(rc.language_use_babel);
1481 globalCB->setChecked(rc.language_global_options);
1482 languagePackageED->setText(toqstr(rc.language_package));
1483 startCommandED->setText(toqstr(rc.language_command_begin));
1484 endCommandED->setText(toqstr(rc.language_command_end));
1486 int const pos = int(findPos_helper(lang_, rc.default_language));
1487 defaultLanguageCO->setCurrentIndex(pos);
1491 /////////////////////////////////////////////////////////////////////
1495 /////////////////////////////////////////////////////////////////////
1497 PrefPrinter::PrefPrinter(QWidget * parent)
1498 : PrefModule(_("Printer"), 0, parent)
1502 connect(printerAdaptCB, SIGNAL(clicked()),
1503 this, SIGNAL(changed()));
1504 connect(printerCommandED, SIGNAL(textChanged(QString)),
1505 this, SIGNAL(changed()));
1506 connect(printerNameED, SIGNAL(textChanged(QString)),
1507 this, SIGNAL(changed()));
1508 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
1509 this, SIGNAL(changed()));
1510 connect(printerCopiesED, SIGNAL(textChanged(QString)),
1511 this, SIGNAL(changed()));
1512 connect(printerReverseED, SIGNAL(textChanged(QString)),
1513 this, SIGNAL(changed()));
1514 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
1515 this, SIGNAL(changed()));
1516 connect(printerExtensionED, SIGNAL(textChanged(QString)),
1517 this, SIGNAL(changed()));
1518 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
1519 this, SIGNAL(changed()));
1520 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
1521 this, SIGNAL(changed()));
1522 connect(printerEvenED, SIGNAL(textChanged(QString)),
1523 this, SIGNAL(changed()));
1524 connect(printerOddED, SIGNAL(textChanged(QString)),
1525 this, SIGNAL(changed()));
1526 connect(printerCollatedED, SIGNAL(textChanged(QString)),
1527 this, SIGNAL(changed()));
1528 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
1529 this, SIGNAL(changed()));
1530 connect(printerToFileED, SIGNAL(textChanged(QString)),
1531 this, SIGNAL(changed()));
1532 connect(printerExtraED, SIGNAL(textChanged(QString)),
1533 this, SIGNAL(changed()));
1534 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
1535 this, SIGNAL(changed()));
1536 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
1537 this, SIGNAL(changed()));
1541 void PrefPrinter::apply(LyXRC & rc) const
1543 rc.print_adapt_output = printerAdaptCB->isChecked();
1544 rc.print_command = fromqstr(printerCommandED->text());
1545 rc.printer = fromqstr(printerNameED->text());
1547 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1548 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1549 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1550 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1551 rc.print_file_extension = fromqstr(printerExtensionED->text());
1552 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1553 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1554 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1555 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1556 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1557 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1558 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1559 rc.print_extra_options = fromqstr(printerExtraED->text());
1560 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1561 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1565 void PrefPrinter::update(LyXRC const & rc)
1567 printerAdaptCB->setChecked(rc.print_adapt_output);
1568 printerCommandED->setText(toqstr(rc.print_command));
1569 printerNameED->setText(toqstr(rc.printer));
1571 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1572 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1573 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1574 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1575 printerExtensionED->setText(toqstr(rc.print_file_extension));
1576 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1577 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1578 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1579 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1580 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1581 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1582 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1583 printerExtraED->setText(toqstr(rc.print_extra_options));
1584 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1585 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1589 /////////////////////////////////////////////////////////////////////
1591 // PrefUserInterface
1593 /////////////////////////////////////////////////////////////////////
1595 PrefUserInterface::PrefUserInterface(GuiPreferences * form, QWidget * parent)
1596 : PrefModule(_("User interface"), form, parent)
1600 connect(autoSaveCB, SIGNAL(toggled(bool)),
1601 autoSaveSB, SLOT(setEnabled(bool)));
1602 connect(autoSaveCB, SIGNAL(toggled(bool)),
1603 TextLabel1, SLOT(setEnabled(bool)));
1604 connect(uiFilePB, SIGNAL(clicked()),
1605 this, SLOT(select_ui()));
1606 connect(uiFileED, SIGNAL(textChanged(QString)),
1607 this, SIGNAL(changed()));
1608 connect(restoreCursorCB, SIGNAL(clicked()),
1609 this, SIGNAL(changed()));
1610 connect(loadSessionCB, SIGNAL(clicked()),
1611 this, SIGNAL(changed()));
1612 connect(loadWindowSizeCB, SIGNAL(clicked()),
1613 this, SIGNAL(changed()));
1614 connect(loadWindowLocationCB, SIGNAL(clicked()),
1615 this, SIGNAL(changed()));
1616 connect(windowWidthSB, SIGNAL(valueChanged(int)),
1617 this, SIGNAL(changed()));
1618 connect(windowHeightSB, SIGNAL(valueChanged(int)),
1619 this, SIGNAL(changed()));
1620 connect(cursorFollowsCB, SIGNAL(clicked()),
1621 this, SIGNAL(changed()));
1622 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1623 this, SIGNAL(changed()));
1624 connect(autoSaveCB, SIGNAL(clicked()),
1625 this, SIGNAL(changed()));
1626 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1627 this, SIGNAL(changed()));
1628 lastfilesSB->setMaximum(maxlastfiles);
1632 void PrefUserInterface::apply(LyXRC & rc) const
1634 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1635 rc.use_lastfilepos = restoreCursorCB->isChecked();
1636 rc.load_session = loadSessionCB->isChecked();
1637 if (loadWindowSizeCB->isChecked()) {
1638 rc.geometry_width = 0;
1639 rc.geometry_height = 0;
1641 rc.geometry_width = windowWidthSB->value();
1642 rc.geometry_height = windowHeightSB->value();
1644 rc.geometry_xysaved = loadWindowLocationCB->isChecked();
1645 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1646 rc.autosave = autoSaveSB->value() * 60;
1647 rc.make_backup = autoSaveCB->isChecked();
1648 rc.num_lastfiles = lastfilesSB->value();
1652 void PrefUserInterface::update(LyXRC const & rc)
1654 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1655 restoreCursorCB->setChecked(rc.use_lastfilepos);
1656 loadSessionCB->setChecked(rc.load_session);
1657 bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
1658 loadWindowSizeCB->setChecked(loadWindowSize);
1659 if (!loadWindowSize) {
1660 windowWidthSB->setValue(rc.geometry_width);
1661 windowHeightSB->setValue(rc.geometry_height);
1663 loadWindowLocationCB->setChecked(rc.geometry_xysaved);
1664 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1665 // convert to minutes
1666 int mins(rc.autosave / 60);
1667 if (rc.autosave && !mins)
1669 autoSaveSB->setValue(mins);
1670 autoSaveCB->setChecked(rc.make_backup);
1671 lastfilesSB->setValue(rc.num_lastfiles);
1675 void PrefUserInterface::select_ui()
1677 docstring const name =
1678 from_utf8(internal_path(fromqstr(uiFileED->text())));
1679 docstring file = form_->browseUI(name);
1681 uiFileED->setText(toqstr(file));
1685 void PrefUserInterface::on_loadWindowSizeCB_toggled(bool loadwindowsize)
1687 windowWidthLA->setDisabled(loadwindowsize);
1688 windowHeightLA->setDisabled(loadwindowsize);
1689 windowWidthSB->setDisabled(loadwindowsize);
1690 windowHeightSB->setDisabled(loadwindowsize);
1694 /////////////////////////////////////////////////////////////////////
1698 /////////////////////////////////////////////////////////////////////
1701 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
1703 Ui::shortcutUi::setupUi(this);
1704 QDialog::setModal(true);
1708 PrefShortcuts::PrefShortcuts(GuiPreferences * form, QWidget * parent)
1709 : PrefModule(_("Shortcuts"), form, parent)
1713 shortcutsTW->setColumnCount(3);
1714 shortcutsTW->headerItem()->setText(0, qt_("Function"));
1715 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
1716 shortcutsTW->headerItem()->setText(2, qt_("Type"));
1717 shortcutsTW->setSortingEnabled(true);
1718 // Multi-selection can be annoying.
1719 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
1720 shortcutsTW->header()->resizeSection(0, 200);
1722 connect(bindFilePB, SIGNAL(clicked()),
1723 this, SLOT(select_bind()));
1724 connect(bindFileED, SIGNAL(textChanged(QString)),
1725 this, SIGNAL(changed()));
1726 connect(removePB, SIGNAL(clicked()),
1727 this, SIGNAL(changed()));
1729 shortcut_ = new GuiShortcutDialog(this);
1730 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
1731 shortcut_bc_.setOK(shortcut_->okPB);
1732 shortcut_bc_.setCancel(shortcut_->cancelPB);
1734 connect(shortcut_->okPB, SIGNAL(clicked()),
1735 shortcut_, SLOT(accept()));
1736 connect(shortcut_->okPB, SIGNAL(clicked()),
1737 this, SIGNAL(changed()));
1738 connect(shortcut_->cancelPB, SIGNAL(clicked()),
1739 shortcut_, SLOT(reject()));
1740 connect(shortcut_->clearPB, SIGNAL(clicked()),
1741 this, SLOT(shortcut_clearPB_pressed()));
1742 connect(shortcut_->okPB, SIGNAL(clicked()),
1743 this, SLOT(shortcut_okPB_pressed()));
1747 void PrefShortcuts::apply(LyXRC & rc) const
1749 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1750 // write user_bind and user_unbind to .lyx/bind/user.bind
1751 string bind_dir = addPath(package().user_support().absFilename(), "bind");
1752 if (!FileName(bind_dir).exists() && mkdir(FileName(bind_dir), 0777)) {
1753 lyxerr << "LyX could not create the user bind directory '"
1754 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
1757 if (!FileName(bind_dir).isDirWritable()) {
1758 lyxerr << "LyX could not write to the user bind directory '"
1759 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
1762 FileName user_bind_file = FileName(addName(bind_dir, "user.bind"));
1763 user_bind_.write(user_bind_file.toFilesystemEncoding(), false, false);
1764 user_unbind_.write(user_bind_file.toFilesystemEncoding(), true, true);
1765 // immediately apply the keybindings. Why this is not done before?
1766 // The good thing is that the menus are updated automatically.
1767 theTopLevelKeymap().clear();
1768 theTopLevelKeymap().read("site");
1769 theTopLevelKeymap().read(rc.bind_file);
1770 theTopLevelKeymap().read("user");
1774 void PrefShortcuts::update(LyXRC const & rc)
1776 bindFileED->setText(toqstr(external_path(rc.bind_file)));
1778 system_bind_.clear();
1780 user_unbind_.clear();
1781 system_bind_.read(rc.bind_file);
1782 // \unbind in user.bind is added to user_unbind_
1783 user_bind_.read("user", &user_unbind_);
1784 updateShortcutsTW();
1788 void PrefShortcuts::updateShortcutsTW()
1790 shortcutsTW->clear();
1792 editItem_ = new QTreeWidgetItem(shortcutsTW);
1793 editItem_->setText(0, toqstr("Cursor, Mouse and Editing functions"));
1794 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
1796 mathItem_ = new QTreeWidgetItem(shortcutsTW);
1797 mathItem_->setText(0, toqstr("Mathematical Symbols"));
1798 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
1800 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
1801 bufferItem_->setText(0, toqstr("Buffer and Window"));
1802 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
1804 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
1805 layoutItem_->setText(0, toqstr("Font, Layouts and Textclasses"));
1806 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
1808 systemItem_ = new QTreeWidgetItem(shortcutsTW);
1809 systemItem_->setText(0, toqstr("System and Miscellaneous"));
1810 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
1812 // listBindings(unbound=true) lists all bound and unbound lfuns
1813 // Items in this list is tagged by its source.
1814 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
1815 static_cast<int>(System));
1816 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
1817 static_cast<int>(UserBind));
1818 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
1819 static_cast<int>(UserUnbind));
1820 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
1821 user_bindinglist.end());
1822 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
1823 user_unbindinglist.end());
1825 KeyMap::BindingList::const_iterator it = bindinglist.begin();
1826 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
1827 for (; it != it_end; ++it)
1828 insertShortcutItem(it->get<0>(), it->get<1>(),
1829 static_cast<item_type>(it->get<2>()));
1831 shortcutsTW->sortItems(0, Qt::AscendingOrder);
1832 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
1833 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
1837 void PrefShortcuts::setItemType(QTreeWidgetItem * item, item_type tag)
1839 item->setData(0, Qt::UserRole, QVariant(tag));
1845 item->setText(2, "System shortcut");
1849 item->setText(2, "User defined shortcut");
1853 item->setText(2, "Removed system shortcut");
1855 case UserExtraUnbind:
1857 item->setText(2, "Unmatched removed system shortcut");
1861 for (int col = 0; col < shortcutsTW->columnCount(); ++col)
1862 #if QT_VERSION >= 0x040200
1863 item->setForeground(col, QBrush(QColor(color)));
1865 item->setTextColor(col, QColor(color));
1870 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
1871 KeySequence const & seq, item_type tag)
1873 kb_action action = lfun.action;
1874 string const action_name = lyxaction.getActionName(action);
1875 QString const lfun_name = toqstr(from_utf8(action_name)
1876 + " " + lfun.argument());
1877 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
1878 item_type item_tag = tag;
1880 QTreeWidgetItem * newItem = NULL;
1881 // for unbind items, try to find an existing item in the system bind list
1882 if (tag == UserUnbind) {
1883 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
1884 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
1885 for (int i = 0; i < items.size(); ++i) {
1886 if (items[i]->text(1) == shortcut)
1890 // if not found, this unbind item is UserExtraUnbind
1891 // Such an item is not displayed to avoid confusion (what is
1892 // unmatched removed?).
1894 item_tag = UserExtraUnbind;
1899 switch(lyxaction.getActionType(action)) {
1900 case LyXAction::Hidden:
1902 case LyXAction::Edit:
1903 newItem = new QTreeWidgetItem(editItem_);
1905 case LyXAction::Math:
1906 newItem = new QTreeWidgetItem(mathItem_);
1908 case LyXAction::Buffer:
1909 newItem = new QTreeWidgetItem(bufferItem_);
1911 case LyXAction::Layout:
1912 newItem = new QTreeWidgetItem(layoutItem_);
1914 case LyXAction::System:
1915 newItem = new QTreeWidgetItem(systemItem_);
1918 // this should not happen
1919 newItem = new QTreeWidgetItem(shortcutsTW);
1923 newItem->setText(0, lfun_name);
1924 newItem->setText(1, shortcut);
1925 // record BindFile representation to recover KeySequence when needed.
1926 newItem->setData(1, Qt::UserRole, QVariant(toqstr(seq.print(KeySequence::BindFile))));
1927 setItemType(newItem, item_tag);
1932 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
1934 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
1935 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
1936 if (items.isEmpty())
1939 item_type tag = static_cast<item_type>(items[0]->data(0, Qt::UserRole).toInt());
1940 if (tag == UserUnbind)
1941 removePB->setText(toqstr("Restore"));
1943 removePB->setText(toqstr("Remove"));
1947 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
1949 QTreeWidgetItem * item = shortcutsTW->currentItem();
1950 if (item->flags() & Qt::ItemIsSelectable) {
1951 shortcut_->lfunLE->setText(item->text(0));
1952 // clear the shortcut because I assume that a user will enter
1954 shortcut_->shortcutLE->reset();
1955 shortcut_->shortcutLE->setFocus();
1961 void PrefShortcuts::select_bind()
1963 docstring const name =
1964 from_utf8(internal_path(fromqstr(bindFileED->text())));
1965 docstring file = form_->browsebind(name);
1966 if (!file.empty()) {
1967 bindFileED->setText(toqstr(file));
1968 system_bind_ = KeyMap();
1969 system_bind_.read(to_utf8(file));
1970 updateShortcutsTW();
1975 void PrefShortcuts::on_newPB_pressed()
1977 shortcut_->lfunLE->clear();
1978 shortcut_->shortcutLE->reset();
1983 void PrefShortcuts::on_removePB_pressed()
1985 // it seems that only one item can be selected, but I am
1986 // removing all selected items anyway.
1987 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
1988 for (int i = 0; i < items.size(); ++i) {
1989 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
1990 string lfun = fromqstr(items[i]->text(0));
1991 FuncRequest func = lyxaction.lookupFunc(lfun);
1992 item_type tag = static_cast<item_type>(items[i]->data(0, Qt::UserRole).toInt());
1996 // for system bind, we do not touch the item
1997 // but add an user unbind item
1998 user_unbind_.bind(shortcut, func);
1999 setItemType(items[i], UserUnbind);
2003 // for user_bind, we remove this bind
2004 QTreeWidgetItem * parent = items[i]->parent();
2005 parent->takeChild(parent->indexOfChild(items[i]));
2006 user_bind_.unbind(shortcut, func);
2010 // for user_unbind, we remove the unbind, and the item
2011 // become System again.
2012 user_unbind_.unbind(shortcut, func);
2013 setItemType(items[i], System);
2016 case UserExtraUnbind: {
2017 // for user unbind that is not in system bind file,
2018 // remove this unbind file
2019 QTreeWidgetItem * parent = items[i]->parent();
2020 parent->takeChild(parent->indexOfChild(items[i]));
2021 user_unbind_.unbind(shortcut, func);
2028 void PrefShortcuts::on_searchLE_textEdited()
2030 if (searchLE->text().isEmpty()) {
2031 // show all hidden items
2032 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2034 shortcutsTW->setItemHidden(*it++, false);
2037 // search both columns
2038 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2039 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2040 matched += shortcutsTW->findItems(searchLE->text(),
2041 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2043 // hide everyone (to avoid searching in matched QList repeatedly
2044 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2046 shortcutsTW->setItemHidden(*it++, true);
2047 // show matched items
2048 for (int i = 0; i < matched.size(); ++i) {
2049 shortcutsTW->setItemHidden(matched[i], false);
2050 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2055 void PrefShortcuts::shortcut_okPB_pressed()
2057 string lfun = fromqstr(shortcut_->lfunLE->text());
2058 FuncRequest func = lyxaction.lookupFunc(lfun);
2060 if (func.action == LFUN_UNKNOWN_ACTION) {
2061 Alert::error(_("Failed to create shortcut"),
2062 _("Unknown or invalid LyX function"));
2066 KeySequence k = shortcut_->shortcutLE->getKeySequence();
2067 if (k.length() == 0) {
2068 Alert::error(_("Failed to create shortcut"),
2069 _("Invalid or empty key sequence"));
2073 // if both lfun and shortcut is valid
2074 if (user_bind_.hasBinding(k, func) || system_bind_.hasBinding(k, func)) {
2075 Alert::error(_("Failed to create shortcut"),
2076 _("Shortcut is alreay defined"));
2080 QTreeWidgetItem * item = insertShortcutItem(func, k, UserBind);
2082 user_bind_.bind(&k, func);
2083 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2084 shortcutsTW->setItemExpanded(item->parent(), true);
2085 shortcutsTW->scrollToItem(item);
2087 Alert::error(_("Failed to create shortcut"),
2088 _("Can not insert shortcut to the list"));
2094 void PrefShortcuts::shortcut_clearPB_pressed()
2096 shortcut_->shortcutLE->reset();
2097 shortcut_->shortcutLE->setFocus();
2101 /////////////////////////////////////////////////////////////////////
2105 /////////////////////////////////////////////////////////////////////
2107 PrefIdentity::PrefIdentity(QWidget * parent)
2108 : PrefModule(_("Identity"), 0, parent)
2112 connect(nameED, SIGNAL(textChanged(QString)),
2113 this, SIGNAL(changed()));
2114 connect(emailED, SIGNAL(textChanged(QString)),
2115 this, SIGNAL(changed()));
2119 void PrefIdentity::apply(LyXRC & rc) const
2121 rc.user_name = fromqstr(nameED->text());
2122 rc.user_email = fromqstr(emailED->text());
2126 void PrefIdentity::update(LyXRC const & rc)
2128 nameED->setText(toqstr(rc.user_name));
2129 emailED->setText(toqstr(rc.user_email));
2134 /////////////////////////////////////////////////////////////////////
2138 /////////////////////////////////////////////////////////////////////
2140 GuiPreferences::GuiPreferences(LyXView & lv)
2141 : GuiDialog(lv, "prefs"), update_screen_font_(false)
2144 setViewTitle(_("Preferences"));
2146 QDialog::setModal(false);
2148 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2149 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2150 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2151 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2153 add(new PrefUserInterface(this));
2154 add(new PrefShortcuts(this));
2155 add(new PrefScreenFonts(this));
2156 add(new PrefColors(this));
2157 add(new PrefDisplay);
2158 add(new PrefKeyboard(this));
2160 add(new PrefPaths(this));
2162 add(new PrefIdentity);
2164 add(new PrefLanguage);
2165 add(new PrefSpellchecker(this));
2167 add(new PrefPrinter);
2169 add(new PrefPlaintext);
2170 add(new PrefLatex(this));
2172 PrefConverters * converters = new PrefConverters(this);
2173 PrefFileformats * formats = new PrefFileformats(this);
2174 connect(formats, SIGNAL(formatsChanged()),
2175 converters, SLOT(updateGui()));
2179 prefsPS->setCurrentPanel(_("User interface"));
2180 // FIXME: hack to work around resizing bug in Qt >= 4.2
2181 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2182 #if QT_VERSION >= 0x040200
2183 prefsPS->updateGeometry();
2186 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2188 bc().setApply(applyPB);
2189 bc().setCancel(closePB);
2190 bc().setRestore(restorePB);
2194 void GuiPreferences::add(PrefModule * module)
2196 BOOST_ASSERT(module);
2197 prefsPS->addPanel(module, module->title());
2198 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2199 modules_.push_back(module);
2203 void GuiPreferences::closeEvent(QCloseEvent * e)
2210 void GuiPreferences::change_adaptor()
2216 void GuiPreferences::apply(LyXRC & rc) const
2218 size_t end = modules_.size();
2219 for (size_t i = 0; i != end; ++i)
2220 modules_[i]->apply(rc);
2224 void GuiPreferences::updateRc(LyXRC const & rc)
2226 size_t const end = modules_.size();
2227 for (size_t i = 0; i != end; ++i)
2228 modules_[i]->update(rc);
2232 void GuiPreferences::applyView()
2238 void GuiPreferences::updateContents()
2244 bool GuiPreferences::initialiseParams(std::string const &)
2247 formats_ = lyx::formats;
2248 converters_ = theConverters();
2249 converters_.update(formats_);
2250 movers_ = theMovers();
2252 update_screen_font_ = false;
2258 void GuiPreferences::dispatchParams()
2261 rc_.write(ss, true);
2262 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
2263 // FIXME: these need lfuns
2265 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
2267 lyx::formats = formats_;
2269 theConverters() = converters_;
2270 theConverters().update(lyx::formats);
2271 theConverters().buildGraph();
2273 theMovers() = movers_;
2275 vector<string>::const_iterator it = colors_.begin();
2276 vector<string>::const_iterator const end = colors_.end();
2277 for (; it != end; ++it)
2278 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
2281 if (update_screen_font_) {
2282 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2283 update_screen_font_ = false;
2286 // The Save button has been pressed
2288 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
2292 void GuiPreferences::setColor(ColorCode col, string const & hex)
2294 colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
2298 void GuiPreferences::updateScreenFonts()
2300 update_screen_font_ = true;
2304 docstring const GuiPreferences::browsebind(docstring const & file) const
2306 return browseLibFile(from_ascii("bind"), file, from_ascii("bind"),
2307 _("Choose bind file"),
2308 FileFilterList(_("LyX bind files (*.bind)")));
2312 docstring const GuiPreferences::browseUI(docstring const & file) const
2314 return browseLibFile(from_ascii("ui"), file, from_ascii("ui"),
2315 _("Choose UI file"),
2316 FileFilterList(_("LyX UI files (*.ui)")));
2320 docstring const GuiPreferences::browsekbmap(docstring const & file) const
2322 return browseLibFile(from_ascii("kbd"), file, from_ascii("kmap"),
2323 _("Choose keyboard map"),
2324 FileFilterList(_("LyX keyboard maps (*.kmap)")));
2328 docstring const GuiPreferences::browsedict(docstring const & file) const
2330 if (lyxrc.use_spell_lib)
2331 return browseFile(file,
2332 _("Choose personal dictionary"),
2333 FileFilterList(_("*.pws")));
2335 return browseFile(file,
2336 _("Choose personal dictionary"),
2337 FileFilterList(_("*.ispell")));
2341 docstring const GuiPreferences::browse(docstring const & file,
2342 docstring const & title) const
2344 return browseFile(file, title, FileFilterList(), true);
2348 docstring const GuiPreferences::browsedir(docstring const & path,
2349 docstring const & title) const
2351 return browseDir(path, title);
2355 // We support less paper sizes than the document dialog
2356 // Therefore this adjustment is needed.
2357 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
2361 return PAPER_DEFAULT;
2363 return PAPER_USLETTER;
2365 return PAPER_USLEGAL;
2367 return PAPER_USEXECUTIVE;
2377 // should not happen
2378 return PAPER_DEFAULT;
2383 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
2385 switch (papersize) {
2388 case PAPER_USLETTER:
2392 case PAPER_USEXECUTIVE:
2403 // should not happen
2409 Dialog * createGuiPreferences(LyXView & lv) { return new GuiPreferences(lv); }
2412 } // namespace frontend
2415 #include "GuiPrefs_moc.cpp"