3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
10 * Full author contact details are available in file CREDITS.
17 #include "qt_helpers.h"
18 #include "GuiApplication.h"
19 #include "GuiFontLoader.h"
21 #include "BufferList.h"
23 #include "ConverterCache.h"
26 #include "FuncRequest.h"
28 #include "GuiFontExample.h"
29 #include "GuiKeySymbol.h"
31 #include "KeySequence.h"
32 #include "LyXAction.h"
33 #include "PanelStack.h"
37 #include "support/FileName.h"
38 #include "support/filetools.h"
39 #include "support/lstrings.h"
40 #include "support/lyxlib.h"
41 #include "support/os.h"
42 #include "support/Package.h"
43 #include "support/FileFilterList.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(const 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(const 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(const QString&)),
270 this, SIGNAL(changed()));
271 connect(secondKeymapED, SIGNAL(textChanged(const 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(const QString&)),
338 this, SIGNAL(changed()));
339 connect(latexChecktexED, SIGNAL(textChanged(const QString&)),
340 this, SIGNAL(changed()));
341 connect(latexBibtexED, SIGNAL(textChanged(const QString&)),
342 this, SIGNAL(changed()));
343 connect(latexIndexED, SIGNAL(textChanged(const QString&)),
344 this, SIGNAL(changed()));
345 connect(latexAutoresetCB, SIGNAL(clicked()),
346 this, SIGNAL(changed()));
347 connect(latexDviPaperED, SIGNAL(textChanged(const 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(const QString&)),
406 this, SLOT(select_roman(const QString&)));
407 connect(screenSansCO, SIGNAL(activated(const QString&)),
408 this, SLOT(select_sans(const QString&)));
409 connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
410 this, SLOT(select_typewriter(const 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(const QString&)),
420 this, SIGNAL(changed()));
421 connect(screenSansCO, SIGNAL(activated(const QString&)),
422 this, SIGNAL(changed()));
423 connect(screenTypewriterCO, SIGNAL(activated(const 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(const QString&)),
430 this, SIGNAL(changed()));
431 connect(screenSmallestED, SIGNAL(textChanged(const QString&)),
432 this, SIGNAL(changed()));
433 connect(screenSmallerED, SIGNAL(textChanged(const QString&)),
434 this, SIGNAL(changed()));
435 connect(screenSmallED, SIGNAL(textChanged(const QString&)),
436 this, SIGNAL(changed()));
437 connect(screenNormalED, SIGNAL(textChanged(const QString&)),
438 this, SIGNAL(changed()));
439 connect(screenLargeED, SIGNAL(textChanged(const QString&)),
440 this, SIGNAL(changed()));
441 connect(screenLargerED, SIGNAL(textChanged(const QString&)),
442 this, SIGNAL(changed()));
443 connect(screenLargestED, SIGNAL(textChanged(const QString&)),
444 this, SIGNAL(changed()));
445 connect(screenHugeED, SIGNAL(textChanged(const QString&)),
446 this, SIGNAL(changed()));
447 connect(screenHugerED, SIGNAL(textChanged(const 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]));
529 void PrefScreenFonts::select_roman(const QString& name)
531 screenRomanFE->set(QFont(name), name);
535 void PrefScreenFonts::select_sans(const QString& name)
537 screenSansFE->set(QFont(name), name);
541 void PrefScreenFonts::select_typewriter(const QString& name)
543 screenTypewriterFE->set(QFont(name), name);
547 /////////////////////////////////////////////////////////////////////
551 /////////////////////////////////////////////////////////////////////
557 bool operator()(Color::color const & lhs, Color::color const & rhs) const {
558 return lcolor.getGUIName(lhs) < lcolor.getGUIName(rhs);
564 PrefColors::PrefColors(GuiPreferences * form, QWidget * parent)
565 : PrefModule( _("Colors"), form, parent)
569 // FIXME: all of this initialization should be put into the controller.
570 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
571 // for some discussion of why that is not trivial.
572 QPixmap icon(32, 32);
573 for (int i = 0; i < Color::ignore; ++i) {
574 Color::color lc = static_cast<Color::color>(i);
575 if (lc == Color::none
576 || lc == Color::black
577 || lc == Color::white
579 || lc == Color::green
582 || lc == Color::magenta
583 || lc == Color::yellow
584 || lc == Color::inherit
585 || lc == Color::ignore) continue;
587 lcolors_.push_back(lc);
589 std::sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
590 vector<Color_color>::const_iterator cit = lcolors_.begin();
591 vector<Color_color>::const_iterator const end = lcolors_.end();
592 for (; cit != end; ++cit) {
593 (void) new QListWidgetItem(QIcon(icon),
594 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
596 curcolors_.resize(lcolors_.size());
597 newcolors_.resize(lcolors_.size());
598 // End initialization
600 connect(colorChangePB, SIGNAL(clicked()),
601 this, SLOT(change_color()));
602 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
603 this, SLOT(change_lyxObjects_selection()));
604 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
605 this, SLOT(change_color()));
609 void PrefColors::apply(LyXRC & /*rc*/) const
611 for (unsigned int i = 0; i < lcolors_.size(); ++i)
612 if (curcolors_[i] != newcolors_[i])
613 form_->setColor(lcolors_[i], fromqstr(newcolors_[i]));
617 void PrefColors::update(LyXRC const & /*rc*/)
619 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
620 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
621 QPixmap coloritem(32, 32);
622 coloritem.fill(color);
623 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
624 newcolors_[i] = curcolors_[i] = color.name();
626 change_lyxObjects_selection();
629 void PrefColors::change_color()
631 int const row = lyxObjectsLW->currentRow();
637 QString const color = newcolors_[row];
638 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
640 if (c.isValid() && c.name() != color) {
641 newcolors_[row] = c.name();
642 QPixmap coloritem(32, 32);
644 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
650 void PrefColors::change_lyxObjects_selection()
652 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
656 /////////////////////////////////////////////////////////////////////
660 /////////////////////////////////////////////////////////////////////
662 PrefDisplay::PrefDisplay(QWidget * parent)
663 : PrefModule(_("Graphics"), 0, parent)
666 connect(instantPreviewCO, SIGNAL(activated(int)),
667 this, SIGNAL(changed()));
668 connect(displayGraphicsCO, SIGNAL(activated(int)),
669 this, SIGNAL(changed()));
673 void PrefDisplay::apply(LyXRC & rc) const
675 switch (instantPreviewCO->currentIndex()) {
676 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
677 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
678 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
681 lyx::graphics::DisplayType dtype;
682 switch (displayGraphicsCO->currentIndex()) {
683 case 3: dtype = lyx::graphics::NoDisplay; break;
684 case 2: dtype = lyx::graphics::ColorDisplay; break;
685 case 1: dtype = lyx::graphics::GrayscaleDisplay; break;
686 case 0: dtype = lyx::graphics::MonochromeDisplay; break;
687 default: dtype = lyx::graphics::GrayscaleDisplay;
689 rc.display_graphics = dtype;
691 // FIXME!! The graphics cache no longer has a changeDisplay method.
693 if (old_value != rc.display_graphics) {
694 lyx::graphics::GCache & gc = lyx::graphics::GCache::get();
701 void PrefDisplay::update(LyXRC const & rc)
703 switch (rc.preview) {
704 case LyXRC::PREVIEW_OFF:
705 instantPreviewCO->setCurrentIndex(0);
707 case LyXRC::PREVIEW_NO_MATH :
708 instantPreviewCO->setCurrentIndex(1);
710 case LyXRC::PREVIEW_ON :
711 instantPreviewCO->setCurrentIndex(2);
716 switch (rc.display_graphics) {
717 case lyx::graphics::NoDisplay: item = 3; break;
718 case lyx::graphics::ColorDisplay: item = 2; break;
719 case lyx::graphics::GrayscaleDisplay: item = 1; break;
720 case lyx::graphics::MonochromeDisplay: item = 0; break;
723 displayGraphicsCO->setCurrentIndex(item);
727 /////////////////////////////////////////////////////////////////////
731 /////////////////////////////////////////////////////////////////////
733 PrefPaths::PrefPaths(GuiPreferences * form, QWidget * parent)
734 : PrefModule(_("Paths"), form, parent)
737 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
738 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
739 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
740 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
741 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
742 connect(workingDirED, SIGNAL(textChanged(const QString&)),
743 this, SIGNAL(changed()));
744 connect(templateDirED, SIGNAL(textChanged(const QString&)),
745 this, SIGNAL(changed()));
746 connect(backupDirED, SIGNAL(textChanged(const QString&)),
747 this, SIGNAL(changed()));
748 connect(tempDirED, SIGNAL(textChanged(const QString&)),
749 this, SIGNAL(changed()));
750 connect(lyxserverDirED, SIGNAL(textChanged(const QString&)),
751 this, SIGNAL(changed()));
752 connect(pathPrefixED, SIGNAL(textChanged(const QString&)),
753 this, SIGNAL(changed()));
757 void PrefPaths::apply(LyXRC & rc) const
759 rc.document_path = internal_path(fromqstr(workingDirED->text()));
760 rc.template_path = internal_path(fromqstr(templateDirED->text()));
761 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
762 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
763 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
764 // FIXME: should be a checkbox only
765 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
769 void PrefPaths::update(LyXRC const & rc)
771 workingDirED->setText(toqstr(external_path(rc.document_path)));
772 templateDirED->setText(toqstr(external_path(rc.template_path)));
773 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
774 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
775 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
776 // FIXME: should be a checkbox only
777 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
781 void PrefPaths::select_templatedir()
783 docstring file(form_->browsedir(
784 from_utf8(internal_path(fromqstr(templateDirED->text()))),
785 _("Select a document templates directory")));
787 templateDirED->setText(toqstr(file));
791 void PrefPaths::select_tempdir()
793 docstring file(form_->browsedir(
794 from_utf8(internal_path(fromqstr(tempDirED->text()))),
795 _("Select a temporary directory")));
797 tempDirED->setText(toqstr(file));
801 void PrefPaths::select_backupdir()
803 docstring file(form_->browsedir(
804 from_utf8(internal_path(fromqstr(backupDirED->text()))),
805 _("Select a backups directory")));
807 backupDirED->setText(toqstr(file));
811 void PrefPaths::select_workingdir()
813 docstring file(form_->browsedir(
814 from_utf8(internal_path(fromqstr(workingDirED->text()))),
815 _("Select a document directory")));
817 workingDirED->setText(toqstr(file));
821 void PrefPaths::select_lyxpipe()
823 docstring file(form_->browse(
824 from_utf8(internal_path(fromqstr(lyxserverDirED->text()))),
825 _("Give a filename for the LyX server pipe")));
827 lyxserverDirED->setText(toqstr(file));
831 /////////////////////////////////////////////////////////////////////
835 /////////////////////////////////////////////////////////////////////
837 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form, QWidget * parent)
838 : PrefModule(_("Spellchecker"), form, parent)
842 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
843 #if defined (USE_ISPELL)
844 connect(spellCommandCO, SIGNAL(activated(int)),
845 this, SIGNAL(changed()));
847 spellCommandCO->setEnabled(false);
849 connect(altLanguageED, SIGNAL(textChanged(const QString&)),
850 this, SIGNAL(changed()));
851 connect(escapeCharactersED, SIGNAL(textChanged(const QString&)),
852 this, SIGNAL(changed()));
853 connect(persDictionaryED, SIGNAL(textChanged(const QString&)),
854 this, SIGNAL(changed()));
855 connect(compoundWordCB, SIGNAL(clicked()),
856 this, SIGNAL(changed()));
857 connect(inputEncodingCB, SIGNAL(clicked()),
858 this, SIGNAL(changed()));
860 spellCommandCO->addItem(qt_("ispell"));
861 spellCommandCO->addItem(qt_("aspell"));
862 spellCommandCO->addItem(qt_("hspell"));
864 spellCommandCO->addItem(qt_("pspell (library)"));
867 spellCommandCO->addItem(qt_("aspell (library)"));
873 void PrefSpellchecker::apply(LyXRC & rc) const
875 switch (spellCommandCO->currentIndex()) {
879 rc.use_spell_lib = false;
880 rc.isp_command = fromqstr(spellCommandCO->currentText());
883 rc.use_spell_lib = true;
887 // FIXME: remove isp_use_alt_lang
888 rc.isp_alt_lang = fromqstr(altLanguageED->text());
889 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
890 // FIXME: remove isp_use_esc_chars
891 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
892 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
893 // FIXME: remove isp_use_pers_dict
894 rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
895 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
896 rc.isp_accept_compound = compoundWordCB->isChecked();
897 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
901 void PrefSpellchecker::update(LyXRC const & rc)
903 spellCommandCO->setCurrentIndex(0);
905 if (rc.isp_command == "ispell") {
906 spellCommandCO->setCurrentIndex(0);
907 } else if (rc.isp_command == "aspell") {
908 spellCommandCO->setCurrentIndex(1);
909 } else if (rc.isp_command == "hspell") {
910 spellCommandCO->setCurrentIndex(2);
913 if (rc.use_spell_lib) {
914 #if defined(USE_ASPELL) || defined(USE_PSPELL)
915 spellCommandCO->setCurrentIndex(3);
919 // FIXME: remove isp_use_alt_lang
920 altLanguageED->setText(toqstr(rc.isp_alt_lang));
921 // FIXME: remove isp_use_esc_chars
922 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
923 // FIXME: remove isp_use_pers_dict
924 persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
925 compoundWordCB->setChecked(rc.isp_accept_compound);
926 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
930 void PrefSpellchecker::select_dict()
932 docstring file(form_->browsedict(
933 from_utf8(internal_path(fromqstr(persDictionaryED->text())))));
935 persDictionaryED->setText(toqstr(file));
940 /////////////////////////////////////////////////////////////////////
944 /////////////////////////////////////////////////////////////////////
947 PrefConverters::PrefConverters(GuiPreferences * form, QWidget * parent)
948 : PrefModule(_("Converters"), form, parent)
952 connect(converterNewPB, SIGNAL(clicked()),
953 this, SLOT(update_converter()));
954 connect(converterRemovePB, SIGNAL(clicked()),
955 this, SLOT(remove_converter()));
956 connect(converterModifyPB, SIGNAL(clicked()),
957 this, SLOT(update_converter()));
958 connect(convertersLW, SIGNAL(currentRowChanged(int)),
959 this, SLOT(switch_converter()));
960 connect(converterFromCO, SIGNAL(activated(const QString&)),
961 this, SLOT(converter_changed()));
962 connect(converterToCO, SIGNAL(activated(const QString&)),
963 this, SLOT(converter_changed()));
964 connect(converterED, SIGNAL(textEdited(const QString&)),
965 this, SLOT(converter_changed()));
966 connect(converterFlagED, SIGNAL(textEdited(const QString&)),
967 this, SLOT(converter_changed()));
968 connect(converterNewPB, SIGNAL(clicked()),
969 this, SIGNAL(changed()));
970 connect(converterRemovePB, SIGNAL(clicked()),
971 this, SIGNAL(changed()));
972 connect(converterModifyPB, SIGNAL(clicked()),
973 this, SIGNAL(changed()));
974 connect(maxAgeLE, SIGNAL(textEdited(const QString&)),
975 this, SIGNAL(changed()));
977 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
978 //converterDefGB->setFocusProxy(convertersLW);
982 void PrefConverters::apply(LyXRC & rc) const
984 rc.use_converter_cache = cacheCB->isChecked();
985 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
989 void PrefConverters::update(LyXRC const & rc)
991 cacheCB->setChecked(rc.use_converter_cache);
993 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
994 maxAgeLE->setText(max_age);
999 void PrefConverters::updateGui()
1001 form_->formats().sort();
1002 form_->converters().update(form_->formats());
1003 // save current selection
1004 QString current = converterFromCO->currentText()
1005 + " -> " + converterToCO->currentText();
1007 converterFromCO->clear();
1008 converterToCO->clear();
1010 Formats::const_iterator cit = form_->formats().begin();
1011 Formats::const_iterator end = form_->formats().end();
1012 for (; cit != end; ++cit) {
1013 converterFromCO->addItem(toqstr(cit->prettyname()));
1014 converterToCO->addItem(toqstr(cit->prettyname()));
1017 // currentRowChanged(int) is also triggered when updating the listwidget
1018 // block signals to avoid unnecessary calls to switch_converter()
1019 convertersLW->blockSignals(true);
1020 convertersLW->clear();
1022 Converters::const_iterator ccit = form_->converters().begin();
1023 Converters::const_iterator cend = form_->converters().end();
1024 for (; ccit != cend; ++ccit) {
1025 std::string const name =
1026 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
1027 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1028 new QListWidgetItem(toqstr(name), convertersLW, type);
1030 convertersLW->sortItems(Qt::AscendingOrder);
1031 convertersLW->blockSignals(false);
1033 // restore selection
1034 if (!current.isEmpty()) {
1035 QList<QListWidgetItem *> const item =
1036 convertersLW->findItems(current, Qt::MatchExactly);
1037 if (!item.isEmpty())
1038 convertersLW->setCurrentItem(item.at(0));
1041 // select first element if restoring failed
1042 if (convertersLW->currentRow() == -1)
1043 convertersLW->setCurrentRow(0);
1049 void PrefConverters::switch_converter()
1051 int const cnr = convertersLW->currentItem()->type();
1052 Converter const & c(form_->converters().get(cnr));
1053 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1054 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1055 converterED->setText(toqstr(c.command));
1056 converterFlagED->setText(toqstr(c.flags));
1062 void PrefConverters::converter_changed()
1068 void PrefConverters::updateButtons()
1070 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1071 Format const & to = form_->formats().get(converterToCO->currentIndex());
1072 int const sel = form_->converters().getNumber(from.name(), to.name());
1073 bool const known = !(sel < 0);
1074 bool const valid = !(converterED->text().isEmpty()
1075 || from.name() == to.name());
1077 int const cnr = convertersLW->currentItem()->type();
1078 Converter const & c(form_->converters().get(cnr));
1079 string const old_command = c.command;
1080 string const old_flag = c.flags;
1081 string const new_command(fromqstr(converterED->text()));
1082 string const new_flag(fromqstr(converterFlagED->text()));
1084 bool modified = ((old_command != new_command) || (old_flag != new_flag));
1086 converterModifyPB->setEnabled(valid && known && modified);
1087 converterNewPB->setEnabled(valid && !known);
1088 converterRemovePB->setEnabled(known);
1090 maxAgeLE->setEnabled(cacheCB->isChecked());
1091 maxAgeLA->setEnabled(cacheCB->isChecked());
1096 // specify unique from/to or it doesn't appear. This is really bad UI
1097 // this is why we can use the same function for both new and modify
1098 void PrefConverters::update_converter()
1100 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1101 Format const & to = form_->formats().get(converterToCO->currentIndex());
1102 string const flags = fromqstr(converterFlagED->text());
1103 string const command = fromqstr(converterED->text());
1105 Converter const * old =
1106 form_->converters().getConverter(from.name(), to.name());
1107 form_->converters().add(from.name(), to.name(), command, flags);
1110 form_->converters().updateLast(form_->formats());
1114 // Remove all files created by this converter from the cache, since
1115 // the modified converter might create different files.
1116 ConverterCache::get().remove_all(from.name(), to.name());
1120 void PrefConverters::remove_converter()
1122 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1123 Format const & to = form_->formats().get(converterToCO->currentIndex());
1124 form_->converters().erase(from.name(), to.name());
1128 // Remove all files created by this converter from the cache, since
1129 // a possible new converter might create different files.
1130 ConverterCache::get().remove_all(from.name(), to.name());
1134 void PrefConverters::on_cacheCB_stateChanged(int state)
1136 maxAgeLE->setEnabled(state == Qt::Checked);
1137 maxAgeLA->setEnabled(state == Qt::Checked);
1142 /////////////////////////////////////////////////////////////////////
1146 /////////////////////////////////////////////////////////////////////
1147 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1148 : QValidator(parent), formats_(f)
1153 void FormatValidator::fixup(QString & input) const
1155 Formats::const_iterator cit = formats_.begin();
1156 Formats::const_iterator end = formats_.end();
1157 for (; cit != end; ++cit) {
1158 string const name = str(cit);
1159 if (distance(formats_.begin(), cit) == nr()) {
1160 input = toqstr(name);
1168 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1170 Formats::const_iterator cit = formats_.begin();
1171 Formats::const_iterator end = formats_.end();
1172 bool unknown = true;
1173 for (; unknown && cit != end; ++cit) {
1174 string const name = str(cit);
1175 if (distance(formats_.begin(), cit) != nr())
1176 unknown = toqstr(name) != input;
1179 if (unknown && !input.isEmpty())
1180 return QValidator::Acceptable;
1182 return QValidator::Intermediate;
1186 int FormatValidator::nr() const
1188 QComboBox * p = qobject_cast<QComboBox *>(parent());
1189 return p->itemData(p->currentIndex()).toInt();
1193 FormatNameValidator::FormatNameValidator(QWidget * parent, Formats const & f)
1194 : FormatValidator(parent, f)
1198 std::string FormatNameValidator::str(Formats::const_iterator it) const
1204 FormatPrettynameValidator::FormatPrettynameValidator(QWidget * parent, Formats const & f)
1205 : FormatValidator(parent, f)
1210 std::string FormatPrettynameValidator::str(Formats::const_iterator it) const
1212 return it->prettyname();
1216 PrefFileformats::PrefFileformats(GuiPreferences * form, QWidget * parent)
1217 : PrefModule(_("File formats"), form, parent)
1220 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1221 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1223 connect(documentCB, SIGNAL(clicked()),
1224 this, SLOT(setFlags()));
1225 connect(vectorCB, SIGNAL(clicked()),
1226 this, SLOT(setFlags()));
1227 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1228 this, SLOT(updatePrettyname()));
1229 connect(formatsCB->lineEdit(), SIGNAL(textEdited(const QString &)),
1230 this, SIGNAL(changed()));
1234 void PrefFileformats::apply(LyXRC & /*rc*/) const
1239 void PrefFileformats::update(LyXRC const & /*rc*/)
1245 void PrefFileformats::updateView()
1247 QString const current = formatsCB->currentText();
1249 // update combobox with formats
1250 formatsCB->blockSignals(true);
1252 form_->formats().sort();
1253 Formats::const_iterator cit = form_->formats().begin();
1254 Formats::const_iterator end = form_->formats().end();
1255 for (; cit != end; ++cit)
1256 formatsCB->addItem(toqstr(cit->prettyname()),
1257 QVariant(form_->formats().getNumber(cit->name())) );
1259 // restore selection
1260 int const item = formatsCB->findText(current, Qt::MatchExactly);
1261 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1262 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1263 formatsCB->blockSignals(false);
1267 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1269 int const nr = formatsCB->itemData(i).toInt();
1270 Format const f = form_->formats().get(nr);
1272 formatED->setText(toqstr(f.name()));
1273 copierED->setText(toqstr(form_->movers().command(f.name())));
1274 extensionED->setText(toqstr(f.extension()));
1275 shortcutED->setText(toqstr(f.shortcut()));
1276 viewerED->setText(toqstr(f.viewer()));
1277 editorED->setText(toqstr(f.editor()));
1278 documentCB->setChecked((f.documentFormat()));
1279 vectorCB->setChecked((f.vectorFormat()));
1283 void PrefFileformats::setFlags()
1285 int flags = Format::none;
1286 if (documentCB->isChecked())
1287 flags |= Format::document;
1288 if (vectorCB->isChecked())
1289 flags |= Format::vector;
1290 currentFormat().setFlags(flags);
1295 void PrefFileformats::on_copierED_textEdited(const QString & s)
1297 string const fmt = fromqstr(formatED->text());
1298 form_->movers().set(fmt, fromqstr(s));
1303 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1305 currentFormat().setExtension(fromqstr(s));
1309 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1311 currentFormat().setViewer(fromqstr(s));
1316 void PrefFileformats::on_editorED_textEdited(const QString & s)
1318 currentFormat().setEditor(fromqstr(s));
1323 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1325 currentFormat().setShortcut(fromqstr(s));
1330 void PrefFileformats::on_formatED_editingFinished()
1332 string const newname = fromqstr(formatED->displayText());
1333 if (newname == currentFormat().name())
1336 currentFormat().setName(newname);
1341 void PrefFileformats::on_formatED_textChanged(const QString &)
1343 QString t = formatED->text();
1345 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1346 setValid(formatLA, valid);
1350 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1352 QString t = formatsCB->currentText();
1354 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1355 setValid(formatsLA, valid);
1359 void PrefFileformats::updatePrettyname()
1361 string const newname = fromqstr(formatsCB->currentText());
1362 if (newname == currentFormat().prettyname())
1365 currentFormat().setPrettyname(newname);
1372 Format & PrefFileformats::currentFormat()
1374 int const i = formatsCB->currentIndex();
1375 int const nr = formatsCB->itemData(i).toInt();
1376 return form_->formats().get(nr);
1380 void PrefFileformats::on_formatNewPB_clicked()
1382 form_->formats().add("", "", "", "", "", "", Format::none);
1384 formatsCB->setCurrentIndex(0);
1385 formatsCB->setFocus(Qt::OtherFocusReason);
1389 void PrefFileformats::on_formatRemovePB_clicked()
1391 int const i = formatsCB->currentIndex();
1392 int const nr = formatsCB->itemData(i).toInt();
1393 string const current_text = form_->formats().get(nr).name();
1394 if (form_->converters().formatIsUsed(current_text)) {
1395 Alert::error(_("Format in use"),
1396 _("Cannot remove a Format used by a Converter. "
1397 "Remove the converter first."));
1401 form_->formats().erase(current_text);
1404 on_formatsCB_editTextChanged(formatsCB->currentText());
1409 /////////////////////////////////////////////////////////////////////
1413 /////////////////////////////////////////////////////////////////////
1415 PrefLanguage::PrefLanguage(QWidget * parent)
1416 : PrefModule(_("Language"), 0, parent)
1420 connect(rtlCB, SIGNAL(clicked()),
1421 this, SIGNAL(changed()));
1422 connect(markForeignCB, SIGNAL(clicked()),
1423 this, SIGNAL(changed()));
1424 connect(autoBeginCB, SIGNAL(clicked()),
1425 this, SIGNAL(changed()));
1426 connect(autoEndCB, SIGNAL(clicked()),
1427 this, SIGNAL(changed()));
1428 connect(useBabelCB, SIGNAL(clicked()),
1429 this, SIGNAL(changed()));
1430 connect(globalCB, SIGNAL(clicked()),
1431 this, SIGNAL(changed()));
1432 connect(languagePackageED, SIGNAL(textChanged(const QString&)),
1433 this, SIGNAL(changed()));
1434 connect(startCommandED, SIGNAL(textChanged(const QString&)),
1435 this, SIGNAL(changed()));
1436 connect(endCommandED, SIGNAL(textChanged(const QString&)),
1437 this, SIGNAL(changed()));
1438 connect(defaultLanguageCO, SIGNAL(activated(int)),
1439 this, SIGNAL(changed()));
1441 defaultLanguageCO->clear();
1443 // store the lang identifiers for later
1444 std::vector<LanguagePair> const langs = frontend::getLanguageData(false);
1445 std::vector<LanguagePair>::const_iterator lit = langs.begin();
1446 std::vector<LanguagePair>::const_iterator lend = langs.end();
1448 for (; lit != lend; ++lit) {
1449 defaultLanguageCO->addItem(toqstr(lit->first));
1450 lang_.push_back(lit->second);
1455 void PrefLanguage::apply(LyXRC & rc) const
1457 // FIXME: remove rtl_support bool
1458 rc.rtl_support = rtlCB->isChecked();
1459 rc.mark_foreign_language = markForeignCB->isChecked();
1460 rc.language_auto_begin = autoBeginCB->isChecked();
1461 rc.language_auto_end = autoEndCB->isChecked();
1462 rc.language_use_babel = useBabelCB->isChecked();
1463 rc.language_global_options = globalCB->isChecked();
1464 rc.language_package = fromqstr(languagePackageED->text());
1465 rc.language_command_begin = fromqstr(startCommandED->text());
1466 rc.language_command_end = fromqstr(endCommandED->text());
1467 rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1471 void PrefLanguage::update(LyXRC const & rc)
1473 // FIXME: remove rtl_support bool
1474 rtlCB->setChecked(rc.rtl_support);
1475 markForeignCB->setChecked(rc.mark_foreign_language);
1476 autoBeginCB->setChecked(rc.language_auto_begin);
1477 autoEndCB->setChecked(rc.language_auto_end);
1478 useBabelCB->setChecked(rc.language_use_babel);
1479 globalCB->setChecked(rc.language_global_options);
1480 languagePackageED->setText(toqstr(rc.language_package));
1481 startCommandED->setText(toqstr(rc.language_command_begin));
1482 endCommandED->setText(toqstr(rc.language_command_end));
1484 int const pos = int(findPos_helper(lang_, rc.default_language));
1485 defaultLanguageCO->setCurrentIndex(pos);
1489 /////////////////////////////////////////////////////////////////////
1493 /////////////////////////////////////////////////////////////////////
1495 PrefPrinter::PrefPrinter(QWidget * parent)
1496 : PrefModule(_("Printer"), 0, parent)
1500 connect(printerAdaptCB, SIGNAL(clicked()),
1501 this, SIGNAL(changed()));
1502 connect(printerCommandED, SIGNAL(textChanged(const QString&)),
1503 this, SIGNAL(changed()));
1504 connect(printerNameED, SIGNAL(textChanged(const QString&)),
1505 this, SIGNAL(changed()));
1506 connect(printerPageRangeED, SIGNAL(textChanged(const QString&)),
1507 this, SIGNAL(changed()));
1508 connect(printerCopiesED, SIGNAL(textChanged(const QString&)),
1509 this, SIGNAL(changed()));
1510 connect(printerReverseED, SIGNAL(textChanged(const QString&)),
1511 this, SIGNAL(changed()));
1512 connect(printerToPrinterED, SIGNAL(textChanged(const QString&)),
1513 this, SIGNAL(changed()));
1514 connect(printerExtensionED, SIGNAL(textChanged(const QString&)),
1515 this, SIGNAL(changed()));
1516 connect(printerSpoolCommandED, SIGNAL(textChanged(const QString&)),
1517 this, SIGNAL(changed()));
1518 connect(printerPaperTypeED, SIGNAL(textChanged(const QString&)),
1519 this, SIGNAL(changed()));
1520 connect(printerEvenED, SIGNAL(textChanged(const QString&)),
1521 this, SIGNAL(changed()));
1522 connect(printerOddED, SIGNAL(textChanged(const QString&)),
1523 this, SIGNAL(changed()));
1524 connect(printerCollatedED, SIGNAL(textChanged(const QString&)),
1525 this, SIGNAL(changed()));
1526 connect(printerLandscapeED, SIGNAL(textChanged(const QString&)),
1527 this, SIGNAL(changed()));
1528 connect(printerToFileED, SIGNAL(textChanged(const QString&)),
1529 this, SIGNAL(changed()));
1530 connect(printerExtraED, SIGNAL(textChanged(const QString&)),
1531 this, SIGNAL(changed()));
1532 connect(printerSpoolPrefixED, SIGNAL(textChanged(const QString&)),
1533 this, SIGNAL(changed()));
1534 connect(printerPaperSizeED, SIGNAL(textChanged(const QString&)),
1535 this, SIGNAL(changed()));
1539 void PrefPrinter::apply(LyXRC & rc) const
1541 rc.print_adapt_output = printerAdaptCB->isChecked();
1542 rc.print_command = fromqstr(printerCommandED->text());
1543 rc.printer = fromqstr(printerNameED->text());
1545 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1546 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1547 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1548 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1549 rc.print_file_extension = fromqstr(printerExtensionED->text());
1550 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1551 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1552 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1553 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1554 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1555 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1556 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1557 rc.print_extra_options = fromqstr(printerExtraED->text());
1558 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1559 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1563 void PrefPrinter::update(LyXRC const & rc)
1565 printerAdaptCB->setChecked(rc.print_adapt_output);
1566 printerCommandED->setText(toqstr(rc.print_command));
1567 printerNameED->setText(toqstr(rc.printer));
1569 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1570 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1571 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1572 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1573 printerExtensionED->setText(toqstr(rc.print_file_extension));
1574 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1575 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1576 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1577 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1578 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1579 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1580 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1581 printerExtraED->setText(toqstr(rc.print_extra_options));
1582 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1583 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1587 /////////////////////////////////////////////////////////////////////
1589 // PrefUserInterface
1591 /////////////////////////////////////////////////////////////////////
1593 PrefUserInterface::PrefUserInterface(GuiPreferences * form, QWidget * parent)
1594 : PrefModule(_("User interface"), form, parent)
1598 connect(autoSaveCB, SIGNAL(toggled(bool)),
1599 autoSaveSB, SLOT(setEnabled(bool)));
1600 connect(autoSaveCB, SIGNAL(toggled(bool)),
1601 TextLabel1, SLOT(setEnabled(bool)));
1602 connect(uiFilePB, SIGNAL(clicked()),
1603 this, SLOT(select_ui()));
1604 connect(uiFileED, SIGNAL(textChanged(const QString &)),
1605 this, SIGNAL(changed()));
1606 connect(restoreCursorCB, SIGNAL(clicked()),
1607 this, SIGNAL(changed()));
1608 connect(loadSessionCB, SIGNAL(clicked()),
1609 this, SIGNAL(changed()));
1610 connect(loadWindowSizeCB, SIGNAL(clicked()),
1611 this, SIGNAL(changed()));
1612 connect(loadWindowLocationCB, SIGNAL(clicked()),
1613 this, SIGNAL(changed()));
1614 connect(windowWidthSB, SIGNAL(valueChanged(int)),
1615 this, SIGNAL(changed()));
1616 connect(windowHeightSB, SIGNAL(valueChanged(int)),
1617 this, SIGNAL(changed()));
1618 connect(cursorFollowsCB, SIGNAL(clicked()),
1619 this, SIGNAL(changed()));
1620 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1621 this, SIGNAL(changed()));
1622 connect(autoSaveCB, SIGNAL(clicked()),
1623 this, SIGNAL(changed()));
1624 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1625 this, SIGNAL(changed()));
1626 lastfilesSB->setMaximum(maxlastfiles);
1630 void PrefUserInterface::apply(LyXRC & rc) const
1632 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1633 rc.use_lastfilepos = restoreCursorCB->isChecked();
1634 rc.load_session = loadSessionCB->isChecked();
1635 if (loadWindowSizeCB->isChecked()) {
1636 rc.geometry_width = 0;
1637 rc.geometry_height = 0;
1639 rc.geometry_width = windowWidthSB->value();
1640 rc.geometry_height = windowHeightSB->value();
1642 rc.geometry_xysaved = loadWindowLocationCB->isChecked();
1643 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1644 rc.autosave = autoSaveSB->value() * 60;
1645 rc.make_backup = autoSaveCB->isChecked();
1646 rc.num_lastfiles = lastfilesSB->value();
1650 void PrefUserInterface::update(LyXRC const & rc)
1652 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1653 restoreCursorCB->setChecked(rc.use_lastfilepos);
1654 loadSessionCB->setChecked(rc.load_session);
1655 bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
1656 loadWindowSizeCB->setChecked(loadWindowSize);
1657 if (!loadWindowSize) {
1658 windowWidthSB->setValue(rc.geometry_width);
1659 windowHeightSB->setValue(rc.geometry_height);
1661 loadWindowLocationCB->setChecked(rc.geometry_xysaved);
1662 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1663 // convert to minutes
1664 int mins(rc.autosave / 60);
1665 if (rc.autosave && !mins)
1667 autoSaveSB->setValue(mins);
1668 autoSaveCB->setChecked(rc.make_backup);
1669 lastfilesSB->setValue(rc.num_lastfiles);
1673 void PrefUserInterface::select_ui()
1675 docstring const name =
1676 from_utf8(internal_path(fromqstr(uiFileED->text())));
1677 docstring file = form_->browseUI(name);
1679 uiFileED->setText(toqstr(file));
1683 void PrefUserInterface::on_loadWindowSizeCB_toggled(bool loadwindowsize)
1685 windowWidthLA->setDisabled(loadwindowsize);
1686 windowHeightLA->setDisabled(loadwindowsize);
1687 windowWidthSB->setDisabled(loadwindowsize);
1688 windowHeightSB->setDisabled(loadwindowsize);
1692 /////////////////////////////////////////////////////////////////////
1696 /////////////////////////////////////////////////////////////////////
1699 void ShortcutEdit::keyPressEvent(QKeyEvent * e)
1701 int keyQt = e->key();
1703 case Qt::Key_AltGr: //or else we get unicode salad
1705 case Qt::Key_Control:
1711 uint modifierKeys = e->modifiers();
1714 if (modifierKeys & Qt::SHIFT)
1716 if (modifierKeys & Qt::CTRL)
1718 if (modifierKeys & Qt::ALT)
1722 setKeySymbol(&sym, e);
1723 txt += toqstr(sym.getSymbolName());
1725 if (text().isEmpty())
1728 setText(text() + " " + txt);
1734 //prevent Qt from special casing Tab and Backtab
1735 bool ShortcutEdit::event(QEvent* e)
1737 if (e->type() == QEvent::ShortcutOverride)
1740 if (e->type() == QEvent::KeyPress) {
1741 keyPressEvent(static_cast<QKeyEvent *>(e));
1745 return QLineEdit::event(e);
1749 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
1751 Ui::shortcutUi::setupUi(this);
1752 QDialog::setModal(true);
1753 // adapted from ui_ShortcutUi.h
1754 shortcutLE = new ShortcutEdit(parent);
1755 shortcutLE->setObjectName(QString::fromUtf8("shortcutLE"));
1756 QSizePolicy sp(static_cast<QSizePolicy::Policy>(7), static_cast<QSizePolicy::Policy>(0));
1757 sp.setHorizontalStretch(0);
1758 sp.setVerticalStretch(0);
1759 sp.setHeightForWidth(shortcutLE->sizePolicy().hasHeightForWidth());
1760 shortcutLE->setSizePolicy(sp);
1761 gridLayout->addWidget(shortcutLE, 1, 1, 1, 1);
1762 QWidget::setTabOrder(shortcutLE, okPB);
1766 PrefShortcuts::PrefShortcuts(GuiPreferences * form, QWidget * parent)
1767 : PrefModule(_("Shortcuts"), form, parent)
1771 shortcutsTW->setColumnCount(2);
1772 shortcutsTW->headerItem()->setText(0, qt_("Function"));
1773 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
1774 shortcutsTW->setSortingEnabled(true);
1775 // Multi-selection can be annoying.
1776 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
1777 shortcutsTW->header()->resizeSection(0, 200);
1779 connect(bindFilePB, SIGNAL(clicked()),
1780 this, SLOT(select_bind()));
1781 connect(bindFileED, SIGNAL(textChanged(const QString &)),
1782 this, SIGNAL(changed()));
1783 connect(removePB, SIGNAL(clicked()),
1784 this, SIGNAL(changed()));
1786 shortcut_ = new GuiShortcutDialog(this);
1787 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
1788 shortcut_bc_.setOK(shortcut_->okPB);
1789 shortcut_bc_.setCancel(shortcut_->cancelPB);
1791 connect(shortcut_->okPB, SIGNAL(clicked()),
1792 shortcut_, SLOT(accept()));
1793 connect(shortcut_->okPB, SIGNAL(clicked()),
1794 this, SIGNAL(changed()));
1795 connect(shortcut_->cancelPB, SIGNAL(clicked()),
1796 shortcut_, SLOT(reject()));
1797 connect(shortcut_->clearPB, SIGNAL(clicked()),
1798 this, SLOT(shortcut_clearPB_pressed()));
1799 connect(shortcut_->okPB, SIGNAL(clicked()),
1800 this, SLOT(shortcut_okPB_pressed()));
1804 void PrefShortcuts::apply(LyXRC & rc) const
1806 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1807 // write user_bind and user_unbind to .lyx/bind/user.bind
1808 string bind_dir = addPath(package().user_support().absFilename(), "bind");
1809 if (!FileName(bind_dir).exists() && mkdir(FileName(bind_dir), 0777)) {
1810 lyxerr << "LyX could not create the user bind directory '"
1811 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
1814 if (!FileName(bind_dir).isDirWritable()) {
1815 lyxerr << "LyX could not write to the user bind directory '"
1816 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
1819 FileName user_bind_file = FileName(addName(bind_dir, "user.bind"));
1820 user_bind_.write(user_bind_file.toFilesystemEncoding(), false, false);
1821 user_unbind_.write(user_bind_file.toFilesystemEncoding(), true, true);
1822 // immediately apply the keybindings. Why this is not done before?
1823 // The good thing is that the menus are updated automatically.
1824 theTopLevelKeymap().clear();
1825 theTopLevelKeymap().read(rc.bind_file);
1826 theTopLevelKeymap().read("user");
1830 void PrefShortcuts::update(LyXRC const & rc)
1832 bindFileED->setText(toqstr(external_path(rc.bind_file)));
1834 system_bind_.clear();
1836 user_unbind_.clear();
1837 system_bind_.read(rc.bind_file);
1838 // \unbind in user.bind is added to user_unbind_
1839 user_bind_.read("user", &user_unbind_);
1840 updateShortcutsTW();
1844 void PrefShortcuts::updateShortcutsTW()
1846 shortcutsTW->clear();
1848 editItem_ = new QTreeWidgetItem(shortcutsTW);
1849 editItem_->setText(0, toqstr("Cursor, Mouse and Editing functions"));
1850 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
1852 mathItem_ = new QTreeWidgetItem(shortcutsTW);
1853 mathItem_->setText(0, toqstr("Mathematical Symbols"));
1854 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
1856 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
1857 bufferItem_->setText(0, toqstr("Buffer and Window"));
1858 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
1860 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
1861 layoutItem_->setText(0, toqstr("Font, Layouts and Textclasses"));
1862 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
1864 systemItem_ = new QTreeWidgetItem(shortcutsTW);
1865 systemItem_->setText(0, toqstr("System and Miscellaneous"));
1866 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
1868 // listBindings(unbound=true) lists all bound and unbound lfuns
1869 // Items in this list is tagged by its source.
1870 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
1871 static_cast<int>(System));
1872 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
1873 static_cast<int>(UserBind));
1874 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
1875 static_cast<int>(UserUnbind));
1876 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
1877 user_bindinglist.end());
1878 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
1879 user_unbindinglist.end());
1881 KeyMap::BindingList::const_iterator it = bindinglist.begin();
1882 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
1883 for (; it != it_end; ++it)
1884 insertShortcutItem(it->get<0>(), it->get<1>(),
1885 static_cast<item_type>(it->get<2>()));
1887 shortcutsTW->sortItems(0, Qt::AscendingOrder);
1888 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
1889 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
1890 searchPB->setEnabled(!searchLE->text().isEmpty());
1894 void PrefShortcuts::setItemType(QTreeWidgetItem * item, item_type tag)
1896 item->setData(0, Qt::UserRole, QVariant(tag));
1909 case UserExtraUnbind:
1914 #if QT_VERSION >= 0x040200
1915 item->setForeground(0, QBrush(QColor(color)));
1916 item->setForeground(1, QBrush(QColor(color)));
1918 item->setTextColor(0, QColor(color));
1919 item->setTextColor(1, QColor(color));
1924 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
1925 KeySequence const & seq, item_type tag)
1927 kb_action action = lfun.action;
1928 string const action_name = lyxaction.getActionName(action);
1929 QString const lfun_name = toqstr(from_utf8(action_name)
1930 + " " + lfun.argument());
1931 // use BindFile format instead of a more verbose form Portable
1932 // if the Shortcut dialog can hide all the bind file stuff,
1933 // Portable format can be used.
1934 QString const shortcut = toqstr(seq.print(KeySequence::BindFile));
1935 item_type item_tag = tag;
1937 QTreeWidgetItem * newItem = NULL;
1938 // for unbind items, try to find an existing item in the system bind list
1939 if (tag == UserUnbind) {
1940 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
1941 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
1942 for (int i = 0; i < items.size(); ++i) {
1943 if (items[i]->text(1) == shortcut)
1947 // if not found, this unbind item is UserExtraUnbind
1949 item_tag = UserExtraUnbind;
1952 switch(lyxaction.getActionType(action)) {
1953 case LyXAction::Hidden:
1955 case LyXAction::Edit:
1956 newItem = new QTreeWidgetItem(editItem_);
1958 case LyXAction::Math:
1959 newItem = new QTreeWidgetItem(mathItem_);
1961 case LyXAction::Buffer:
1962 newItem = new QTreeWidgetItem(bufferItem_);
1964 case LyXAction::Layout:
1965 newItem = new QTreeWidgetItem(layoutItem_);
1967 case LyXAction::System:
1968 newItem = new QTreeWidgetItem(systemItem_);
1971 // this should not happen
1972 newItem = new QTreeWidgetItem(shortcutsTW);
1976 newItem->setText(0, lfun_name);
1977 newItem->setText(1, shortcut);
1978 setItemType(newItem, item_tag);
1983 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
1985 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
1986 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
1987 if (items.isEmpty())
1990 item_type tag = static_cast<item_type>(items[0]->data(0, Qt::UserRole).toInt());
1991 if (tag == UserUnbind)
1992 removePB->setText(toqstr("Restore"));
1994 removePB->setText(toqstr("Remove"));
1998 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
2000 QTreeWidgetItem * item = shortcutsTW->currentItem();
2001 if (item->flags() & Qt::ItemIsSelectable) {
2002 shortcut_->lfunLE->setText(item->text(0));
2003 shortcut_->shortcutLE->setText(item->text(1));
2009 void PrefShortcuts::select_bind()
2011 docstring const name =
2012 from_utf8(internal_path(fromqstr(bindFileED->text())));
2013 docstring file = form_->browsebind(name);
2014 if (!file.empty()) {
2015 bindFileED->setText(toqstr(file));
2016 system_bind_ = KeyMap();
2017 system_bind_.read(to_utf8(file));
2018 updateShortcutsTW();
2023 void PrefShortcuts::on_newPB_pressed()
2025 shortcut_->lfunLE->clear();
2026 shortcut_->shortcutLE->clear();
2031 void PrefShortcuts::on_removePB_pressed()
2033 // it seems that only one item can be selected, but I am
2034 // removing all selected items anyway.
2035 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
2036 for (int i = 0; i < items.size(); ++i) {
2037 string shortcut = fromqstr(items[i]->text(1));
2038 string lfun = fromqstr(items[i]->text(0));
2039 FuncRequest func = lyxaction.lookupFunc(lfun);
2040 item_type tag = static_cast<item_type>(items[i]->data(0, Qt::UserRole).toInt());
2044 // for system bind, we do not touch the item
2045 // but add an user unbind item
2046 user_unbind_.bind(shortcut, func);
2047 setItemType(items[i], UserUnbind);
2051 // for user_bind, we remove this bind
2052 QTreeWidgetItem * parent = items[i]->parent();
2053 parent->takeChild(parent->indexOfChild(items[i]));
2054 user_bind_.unbind(shortcut, func);
2058 // for user_unbind, we remove the unbind, and the item
2059 // become System again.
2060 user_unbind_.unbind(shortcut, func);
2061 setItemType(items[i], System);
2064 case UserExtraUnbind: {
2065 // for user unbind that is not in system bind file,
2066 // remove this unbind file
2067 QTreeWidgetItem * parent = items[i]->parent();
2068 parent->takeChild(parent->indexOfChild(items[i]));
2069 user_unbind_.unbind(shortcut, func);
2076 void PrefShortcuts::on_searchPB_pressed()
2078 // search both columns
2079 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2080 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2081 matched += shortcutsTW->findItems(searchLE->text(),
2082 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2084 // hide everyone (to avoid searching in matched QList repeatedly
2085 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2087 shortcutsTW->setItemHidden(*it++, true);
2088 // show matched items
2089 for (int i = 0; i < matched.size(); ++i) {
2090 shortcutsTW->setItemHidden(matched[i], false);
2091 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2096 void PrefShortcuts::on_searchLE_textChanged()
2098 searchPB->setEnabled(!searchLE->text().isEmpty());
2099 if (searchLE->text().isEmpty()) {
2100 // show all hidden items
2101 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2103 shortcutsTW->setItemHidden(*it++, false);
2108 void PrefShortcuts::shortcut_okPB_pressed()
2110 string shortcut = fromqstr(shortcut_->shortcutLE->text());
2111 string lfun = fromqstr(shortcut_->lfunLE->text());
2112 FuncRequest func = lyxaction.lookupFunc(lfun);
2114 if (func.action == LFUN_UNKNOWN_ACTION) {
2115 Alert::error(_("Failed to create shortcut"),
2116 _("Unknown or invalid lyx function"));
2120 KeySequence k(0, 0);
2121 string::size_type const res = k.parse(shortcut);
2122 if (res != string::npos) {
2123 Alert::error(_("Failed to create shortcut"),
2124 _("Invalid key sequence"));
2128 // if both lfun and shortcut is valid
2129 if (user_bind_.hasBinding(k, func) || system_bind_.hasBinding(k, func)) {
2130 Alert::error(_("Failed to create shortcut"),
2131 _("Shortcut is alreay defined"));
2135 QTreeWidgetItem * item = insertShortcutItem(func, k, UserBind);
2137 user_bind_.bind(shortcut, func);
2138 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2139 shortcutsTW->setItemExpanded(item->parent(), true);
2140 shortcutsTW->scrollToItem(item);
2142 Alert::error(_("Failed to create shortcut"),
2143 _("Can not insert shortcut to the list"));
2149 void PrefShortcuts::shortcut_clearPB_pressed()
2151 shortcut_->shortcutLE->clear();
2152 shortcut_->shortcutLE->setFocus();
2156 /////////////////////////////////////////////////////////////////////
2160 /////////////////////////////////////////////////////////////////////
2162 PrefIdentity::PrefIdentity(QWidget * parent)
2163 : PrefModule(_("Identity"), 0, parent)
2167 connect(nameED, SIGNAL(textChanged(const QString&)),
2168 this, SIGNAL(changed()));
2169 connect(emailED, SIGNAL(textChanged(const QString&)),
2170 this, SIGNAL(changed()));
2174 void PrefIdentity::apply(LyXRC & rc) const
2176 rc.user_name = fromqstr(nameED->text());
2177 rc.user_email = fromqstr(emailED->text());
2181 void PrefIdentity::update(LyXRC const & rc)
2183 nameED->setText(toqstr(rc.user_name));
2184 emailED->setText(toqstr(rc.user_email));
2189 /////////////////////////////////////////////////////////////////////
2193 /////////////////////////////////////////////////////////////////////
2195 GuiPreferences::GuiPreferences(LyXView & lv)
2196 : GuiDialog(lv, "prefs"), update_screen_font_(false)
2199 setViewTitle(_("Preferences"));
2201 QDialog::setModal(false);
2203 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2204 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2205 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2206 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2208 add(new PrefUserInterface(this));
2209 add(new PrefShortcuts(this));
2210 add(new PrefScreenFonts(this));
2211 add(new PrefColors(this));
2212 add(new PrefDisplay);
2213 add(new PrefKeyboard(this));
2215 add(new PrefPaths(this));
2217 add(new PrefIdentity);
2219 add(new PrefLanguage);
2220 add(new PrefSpellchecker(this));
2222 add(new PrefPrinter);
2224 add(new PrefPlaintext);
2225 add(new PrefLatex(this));
2227 PrefConverters * converters = new PrefConverters(this);
2228 PrefFileformats * formats = new PrefFileformats(this);
2229 connect(formats, SIGNAL(formatsChanged()),
2230 converters, SLOT(updateGui()));
2234 prefsPS->setCurrentPanel(_("User interface"));
2235 // FIXME: hack to work around resizing bug in Qt >= 4.2
2236 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2237 #if QT_VERSION >= 0x040200
2238 prefsPS->updateGeometry();
2241 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2243 bc().setApply(applyPB);
2244 bc().setCancel(closePB);
2245 bc().setRestore(restorePB);
2249 void GuiPreferences::add(PrefModule * module)
2251 BOOST_ASSERT(module);
2252 prefsPS->addPanel(module, module->title());
2253 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2254 modules_.push_back(module);
2258 void GuiPreferences::closeEvent(QCloseEvent * e)
2265 void GuiPreferences::change_adaptor()
2271 void GuiPreferences::apply(LyXRC & rc) const
2273 size_t end = modules_.size();
2274 for (size_t i = 0; i != end; ++i)
2275 modules_[i]->apply(rc);
2279 void GuiPreferences::updateRc(LyXRC const & rc)
2281 size_t const end = modules_.size();
2282 for (size_t i = 0; i != end; ++i)
2283 modules_[i]->update(rc);
2287 void GuiPreferences::applyView()
2293 void GuiPreferences::updateContents()
2299 bool GuiPreferences::initialiseParams(std::string const &)
2302 formats_ = lyx::formats;
2303 converters_ = theConverters();
2304 converters_.update(formats_);
2305 movers_ = theMovers();
2307 update_screen_font_ = false;
2313 void GuiPreferences::dispatchParams()
2316 rc_.write(ss, true);
2317 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
2318 // FIXME: these need lfuns
2320 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
2322 lyx::formats = formats_;
2324 theConverters() = converters_;
2325 theConverters().update(lyx::formats);
2326 theConverters().buildGraph();
2328 theMovers() = movers_;
2330 vector<string>::const_iterator it = colors_.begin();
2331 vector<string>::const_iterator const end = colors_.end();
2332 for (; it != end; ++it)
2333 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
2336 if (update_screen_font_) {
2337 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2338 update_screen_font_ = false;
2341 // The Save button has been pressed
2343 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
2347 void GuiPreferences::setColor(Color_color col, string const & hex)
2349 colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
2353 void GuiPreferences::updateScreenFonts()
2355 update_screen_font_ = true;
2359 docstring const GuiPreferences::browsebind(docstring const & file) const
2361 return browseLibFile(from_ascii("bind"), file, from_ascii("bind"),
2362 _("Choose bind file"),
2363 FileFilterList(_("LyX bind files (*.bind)")));
2367 docstring const GuiPreferences::browseUI(docstring const & file) const
2369 return browseLibFile(from_ascii("ui"), file, from_ascii("ui"),
2370 _("Choose UI file"),
2371 FileFilterList(_("LyX UI files (*.ui)")));
2375 docstring const GuiPreferences::browsekbmap(docstring const & file) const
2377 return browseLibFile(from_ascii("kbd"), file, from_ascii("kmap"),
2378 _("Choose keyboard map"),
2379 FileFilterList(_("LyX keyboard maps (*.kmap)")));
2383 docstring const GuiPreferences::browsedict(docstring const & file) const
2385 if (lyxrc.use_spell_lib)
2386 return browseFile(file,
2387 _("Choose personal dictionary"),
2388 FileFilterList(_("*.pws")));
2390 return browseFile(file,
2391 _("Choose personal dictionary"),
2392 FileFilterList(_("*.ispell")));
2396 docstring const GuiPreferences::browse(docstring const & file,
2397 docstring const & title) const
2399 return browseFile(file, title, FileFilterList(), true);
2403 docstring const GuiPreferences::browsedir(docstring const & path,
2404 docstring const & title) const
2406 return browseDir(path, title);
2410 // We support less paper sizes than the document dialog
2411 // Therefore this adjustment is needed.
2412 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
2416 return PAPER_DEFAULT;
2418 return PAPER_USLETTER;
2420 return PAPER_USLEGAL;
2422 return PAPER_USEXECUTIVE;
2432 // should not happen
2433 return PAPER_DEFAULT;
2438 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
2440 switch (papersize) {
2443 case PAPER_USLETTER:
2447 case PAPER_USEXECUTIVE:
2458 // should not happen
2464 Dialog * createGuiPreferences(LyXView & lv) { return new GuiPreferences(lv); }
2467 } // namespace frontend
2470 #include "GuiPrefs_moc.cpp"