3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
16 #include "qt_helpers.h"
17 #include "GuiApplication.h"
18 #include "GuiFontLoader.h"
20 #include "BufferList.h"
22 #include "ConverterCache.h"
23 #include "support/debug.h"
24 #include "FuncRequest.h"
25 #include "support/gettext.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/os.h"
39 #include "support/Package.h"
40 #include "support/FileFilterList.h"
42 #include "graphics/GraphicsTypes.h"
44 #include "frontends/alert.h"
45 #include "frontends/Application.h"
48 #include <QColorDialog>
49 #include <QFontDatabase>
50 #include <QHeaderView>
52 #include <QPixmapCache>
53 #include <QPushButton>
56 #include <QTreeWidget>
57 #include <QTreeWidgetItem>
59 #include <QCloseEvent>
68 using namespace lyx::support;
69 using namespace lyx::support::os;
75 /////////////////////////////////////////////////////////////////////
79 /////////////////////////////////////////////////////////////////////
82 static size_t findPos_helper(vector<A> const & vec, A const & val)
84 typedef typename vector<A>::const_iterator Cit;
86 Cit it = find(vec.begin(), vec.end(), val);
89 return distance(vec.begin(), it);
93 static void parseFontName(QString const & mangled0,
94 string & name, string & foundry)
96 string mangled = fromqstr(mangled0);
97 size_t const idx = mangled.find('[');
98 if (idx == string::npos || idx == 0) {
102 name = mangled.substr(0, idx - 1),
103 foundry = mangled.substr(idx + 1, mangled.size() - idx - 2);
108 static void setComboxFont(QComboBox * cb, string const & family,
109 string const & foundry)
111 QString fontname = toqstr(family);
112 if (!foundry.empty())
113 fontname += " [" + toqstr(foundry) + ']';
115 for (int i = 0; i < cb->count(); ++i) {
116 if (cb->itemText(i) == fontname) {
117 cb->setCurrentIndex(i);
122 // Try matching without foundry name
124 // We count in reverse in order to prefer the Xft foundry
125 for (int i = cb->count(); --i >= 0;) {
126 string name, foundry;
127 parseFontName(cb->itemText(i), name, foundry);
128 if (compare_ascii_no_case(name, family) == 0) {
129 cb->setCurrentIndex(i);
134 // family alone can contain e.g. "Helvetica [Adobe]"
135 string tmpname, tmpfoundry;
136 parseFontName(toqstr(family), tmpname, tmpfoundry);
138 // We count in reverse in order to prefer the Xft foundry
139 for (int i = cb->count(); --i >= 0; ) {
140 string name, foundry;
141 parseFontName(cb->itemText(i), name, foundry);
142 if (compare_ascii_no_case(name, foundry) == 0) {
143 cb->setCurrentIndex(i);
148 // Bleh, default fonts, and the names couldn't be found. Hack
152 font.setKerning(false);
154 QString const font_family = toqstr(family);
155 if (font_family == guiApp->romanFontName()) {
156 font.setStyleHint(QFont::Serif);
157 font.setFamily(font_family);
158 } else if (font_family == guiApp->sansFontName()) {
159 font.setStyleHint(QFont::SansSerif);
160 font.setFamily(font_family);
161 } else if (font_family == guiApp->typewriterFontName()) {
162 font.setStyleHint(QFont::TypeWriter);
163 font.setFamily(font_family);
165 lyxerr << "FAILED to find the default font: '"
166 << foundry << "', '" << family << '\''<< endl;
170 QFontInfo info(font);
171 string default_font_name, dummyfoundry;
172 parseFontName(info.family(), default_font_name, dummyfoundry);
173 lyxerr << "Apparent font is " << default_font_name << endl;
175 for (int i = 0; i < cb->count(); ++i) {
176 lyxerr << "Looking at " << fromqstr(cb->itemText(i)) << endl;
177 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
178 default_font_name) == 0) {
179 cb->setCurrentIndex(i);
184 lyxerr << "FAILED to find the font: '"
185 << foundry << "', '" << family << '\'' <<endl;
189 /////////////////////////////////////////////////////////////////////
193 /////////////////////////////////////////////////////////////////////
195 PrefPlaintext::PrefPlaintext(QWidget * parent)
196 : PrefModule(_("Plain text"), 0, parent)
199 connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
200 this, SIGNAL(changed()));
201 connect(plaintextRoffED, SIGNAL(textChanged(QString)),
202 this, SIGNAL(changed()));
206 void PrefPlaintext::apply(LyXRC & rc) const
208 rc.plaintext_linelen = plaintextLinelengthSB->value();
209 rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
213 void PrefPlaintext::update(LyXRC const & rc)
215 plaintextLinelengthSB->setValue(rc.plaintext_linelen);
216 plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
220 /////////////////////////////////////////////////////////////////////
224 /////////////////////////////////////////////////////////////////////
226 PrefDate::PrefDate(QWidget * parent)
227 : PrefModule(_("Date format"), 0, parent)
230 connect(DateED, SIGNAL(textChanged(QString)),
231 this, SIGNAL(changed()));
235 void PrefDate::apply(LyXRC & rc) const
237 rc.date_insert_format = fromqstr(DateED->text());
241 void PrefDate::update(LyXRC const & rc)
243 DateED->setText(toqstr(rc.date_insert_format));
247 /////////////////////////////////////////////////////////////////////
251 /////////////////////////////////////////////////////////////////////
253 PrefInput::PrefInput(GuiPreferences * form, QWidget * parent)
254 : PrefModule(_("Keyboard/Mouse"), form, parent)
258 connect(keymapCB, SIGNAL(clicked()),
259 this, SIGNAL(changed()));
260 connect(firstKeymapED, SIGNAL(textChanged(QString)),
261 this, SIGNAL(changed()));
262 connect(secondKeymapED, SIGNAL(textChanged(QString)),
263 this, SIGNAL(changed()));
264 connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)),
265 this, SIGNAL(changed()));
269 void PrefInput::apply(LyXRC & rc) const
271 // FIXME: can derive CB from the two EDs
272 rc.use_kbmap = keymapCB->isChecked();
273 rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
274 rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
275 rc.mouse_wheel_speed = mouseWheelSpeedSB->value();
279 void PrefInput::update(LyXRC const & rc)
281 // FIXME: can derive CB from the two EDs
282 keymapCB->setChecked(rc.use_kbmap);
283 firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
284 secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
285 mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed);
289 QString PrefInput::testKeymap(QString keymap)
291 return toqstr(form_->browsekbmap(from_utf8(internal_path(fromqstr(keymap)))));
295 void PrefInput::on_firstKeymapPB_clicked(bool)
297 QString const file = testKeymap(firstKeymapED->text());
299 firstKeymapED->setText(file);
303 void PrefInput::on_secondKeymapPB_clicked(bool)
305 QString const file = testKeymap(secondKeymapED->text());
307 secondKeymapED->setText(file);
311 void PrefInput::on_keymapCB_toggled(bool keymap)
313 firstKeymapLA->setEnabled(keymap);
314 secondKeymapLA->setEnabled(keymap);
315 firstKeymapED->setEnabled(keymap);
316 secondKeymapED->setEnabled(keymap);
317 firstKeymapPB->setEnabled(keymap);
318 secondKeymapPB->setEnabled(keymap);
322 /////////////////////////////////////////////////////////////////////
326 /////////////////////////////////////////////////////////////////////
328 PrefLatex::PrefLatex(GuiPreferences * form, QWidget * parent)
329 : PrefModule(_("LaTeX"), form, parent)
332 connect(latexEncodingED, SIGNAL(textChanged(QString)),
333 this, SIGNAL(changed()));
334 connect(latexChecktexED, SIGNAL(textChanged(QString)),
335 this, SIGNAL(changed()));
336 connect(latexBibtexED, SIGNAL(textChanged(QString)),
337 this, SIGNAL(changed()));
338 connect(latexIndexED, SIGNAL(textChanged(QString)),
339 this, SIGNAL(changed()));
340 connect(latexAutoresetCB, SIGNAL(clicked()),
341 this, SIGNAL(changed()));
342 connect(latexDviPaperED, SIGNAL(textChanged(QString)),
343 this, SIGNAL(changed()));
344 connect(latexPaperSizeCO, SIGNAL(activated(int)),
345 this, SIGNAL(changed()));
347 #if defined(__CYGWIN__) || defined(_WIN32)
348 pathCB->setVisible(true);
349 connect(pathCB, SIGNAL(clicked()),
350 this, SIGNAL(changed()));
352 pathCB->setVisible(false);
357 void PrefLatex::apply(LyXRC & rc) const
359 rc.fontenc = fromqstr(latexEncodingED->text());
360 rc.chktex_command = fromqstr(latexChecktexED->text());
361 rc.bibtex_command = fromqstr(latexBibtexED->text());
362 rc.index_command = fromqstr(latexIndexED->text());
363 rc.auto_reset_options = latexAutoresetCB->isChecked();
364 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
365 rc.default_papersize =
366 form_->toPaperSize(latexPaperSizeCO->currentIndex());
367 #if defined(__CYGWIN__) || defined(_WIN32)
368 rc.windows_style_tex_paths = pathCB->isChecked();
373 void PrefLatex::update(LyXRC const & rc)
375 latexEncodingED->setText(toqstr(rc.fontenc));
376 latexChecktexED->setText(toqstr(rc.chktex_command));
377 latexBibtexED->setText(toqstr(rc.bibtex_command));
378 latexIndexED->setText(toqstr(rc.index_command));
379 latexAutoresetCB->setChecked(rc.auto_reset_options);
380 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
381 latexPaperSizeCO->setCurrentIndex(
382 form_->fromPaperSize(rc.default_papersize));
383 #if defined(__CYGWIN__) || defined(_WIN32)
384 pathCB->setChecked(rc.windows_style_tex_paths);
389 /////////////////////////////////////////////////////////////////////
393 /////////////////////////////////////////////////////////////////////
395 PrefScreenFonts::PrefScreenFonts(GuiPreferences * form, QWidget * parent)
396 : PrefModule(_("Screen fonts"), form, parent)
400 connect(screenRomanCO, SIGNAL(activated(QString)),
401 this, SLOT(select_roman(QString)));
402 connect(screenSansCO, SIGNAL(activated(QString)),
403 this, SLOT(select_sans(QString)));
404 connect(screenTypewriterCO, SIGNAL(activated(QString)),
405 this, SLOT(select_typewriter(QString)));
407 QFontDatabase fontdb;
408 QStringList families(fontdb.families());
409 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
410 screenRomanCO->addItem(*it);
411 screenSansCO->addItem(*it);
412 screenTypewriterCO->addItem(*it);
414 connect(screenRomanCO, SIGNAL(activated(QString)),
415 this, SIGNAL(changed()));
416 connect(screenSansCO, SIGNAL(activated(QString)),
417 this, SIGNAL(changed()));
418 connect(screenTypewriterCO, SIGNAL(activated(QString)),
419 this, SIGNAL(changed()));
420 connect(screenZoomSB, SIGNAL(valueChanged(int)),
421 this, SIGNAL(changed()));
422 connect(screenDpiSB, SIGNAL(valueChanged(int)),
423 this, SIGNAL(changed()));
424 connect(screenTinyED, SIGNAL(textChanged(QString)),
425 this, SIGNAL(changed()));
426 connect(screenSmallestED, SIGNAL(textChanged(QString)),
427 this, SIGNAL(changed()));
428 connect(screenSmallerED, SIGNAL(textChanged(QString)),
429 this, SIGNAL(changed()));
430 connect(screenSmallED, SIGNAL(textChanged(QString)),
431 this, SIGNAL(changed()));
432 connect(screenNormalED, SIGNAL(textChanged(QString)),
433 this, SIGNAL(changed()));
434 connect(screenLargeED, SIGNAL(textChanged(QString)),
435 this, SIGNAL(changed()));
436 connect(screenLargerED, SIGNAL(textChanged(QString)),
437 this, SIGNAL(changed()));
438 connect(screenLargestED, SIGNAL(textChanged(QString)),
439 this, SIGNAL(changed()));
440 connect(screenHugeED, SIGNAL(textChanged(QString)),
441 this, SIGNAL(changed()));
442 connect(screenHugerED, SIGNAL(textChanged(QString)),
443 this, SIGNAL(changed()));
444 connect(pixmapCacheCB, SIGNAL(toggled(bool)),
445 this, SIGNAL(changed()));
447 screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
448 screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
449 screenSmallerED->setValidator(new QDoubleValidator(screenSmallerED));
450 screenSmallED->setValidator(new QDoubleValidator(screenSmallED));
451 screenNormalED->setValidator(new QDoubleValidator(screenNormalED));
452 screenLargeED->setValidator(new QDoubleValidator(screenLargeED));
453 screenLargerED->setValidator(new QDoubleValidator(screenLargerED));
454 screenLargestED->setValidator(new QDoubleValidator(screenLargestED));
455 screenHugeED->setValidator(new QDoubleValidator(screenHugeED));
456 screenHugerED->setValidator(new QDoubleValidator(screenHugerED));
460 void PrefScreenFonts::apply(LyXRC & rc) const
462 LyXRC const oldrc = rc;
464 parseFontName(screenRomanCO->currentText(),
465 rc.roman_font_name, rc.roman_font_foundry);
466 parseFontName(screenSansCO->currentText(),
467 rc.sans_font_name, rc.sans_font_foundry);
468 parseFontName(screenTypewriterCO->currentText(),
469 rc.typewriter_font_name, rc.typewriter_font_foundry);
471 rc.zoom = screenZoomSB->value();
472 rc.dpi = screenDpiSB->value();
473 rc.font_sizes[FONT_SIZE_TINY] = fromqstr(screenTinyED->text());
474 rc.font_sizes[FONT_SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
475 rc.font_sizes[FONT_SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
476 rc.font_sizes[FONT_SIZE_SMALL] = fromqstr(screenSmallED->text());
477 rc.font_sizes[FONT_SIZE_NORMAL] = fromqstr(screenNormalED->text());
478 rc.font_sizes[FONT_SIZE_LARGE] = fromqstr(screenLargeED->text());
479 rc.font_sizes[FONT_SIZE_LARGER] = fromqstr(screenLargerED->text());
480 rc.font_sizes[FONT_SIZE_LARGEST] = fromqstr(screenLargestED->text());
481 rc.font_sizes[FONT_SIZE_HUGE] = fromqstr(screenHugeED->text());
482 rc.font_sizes[FONT_SIZE_HUGER] = fromqstr(screenHugerED->text());
483 rc.use_pixmap_cache = pixmapCacheCB->isChecked();
485 if (rc.font_sizes != oldrc.font_sizes
486 || rc.roman_font_name != oldrc.roman_font_name
487 || rc.sans_font_name != oldrc.sans_font_name
488 || rc.typewriter_font_name != oldrc.typewriter_font_name
489 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
490 // The global QPixmapCache is used in GuiPainter to cache text
491 // painting so we must reset it in case any of the above
492 // parameter is changed.
493 QPixmapCache::clear();
494 guiApp->fontLoader().update();
495 form_->updateScreenFonts();
500 void PrefScreenFonts::update(LyXRC const & rc)
502 setComboxFont(screenRomanCO, rc.roman_font_name,
503 rc.roman_font_foundry);
504 setComboxFont(screenSansCO, rc.sans_font_name,
505 rc.sans_font_foundry);
506 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
507 rc.typewriter_font_foundry);
509 select_roman(screenRomanCO->currentText());
510 select_sans(screenSansCO->currentText());
511 select_typewriter(screenTypewriterCO->currentText());
513 screenZoomSB->setValue(rc.zoom);
514 screenDpiSB->setValue(rc.dpi);
515 screenTinyED->setText(toqstr(rc.font_sizes[FONT_SIZE_TINY]));
516 screenSmallestED->setText(toqstr(rc.font_sizes[FONT_SIZE_SCRIPT]));
517 screenSmallerED->setText(toqstr(rc.font_sizes[FONT_SIZE_FOOTNOTE]));
518 screenSmallED->setText(toqstr(rc.font_sizes[FONT_SIZE_SMALL]));
519 screenNormalED->setText(toqstr(rc.font_sizes[FONT_SIZE_NORMAL]));
520 screenLargeED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGE]));
521 screenLargerED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGER]));
522 screenLargestED->setText(toqstr(rc.font_sizes[FONT_SIZE_LARGEST]));
523 screenHugeED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGE]));
524 screenHugerED->setText(toqstr(rc.font_sizes[FONT_SIZE_HUGER]));
526 pixmapCacheCB->setChecked(rc.use_pixmap_cache);
527 #if defined(Q_WS_X11)
528 pixmapCacheCB->setEnabled(false);
534 void PrefScreenFonts::select_roman(const QString & name)
536 screenRomanFE->set(QFont(name), name);
540 void PrefScreenFonts::select_sans(const QString & name)
542 screenSansFE->set(QFont(name), name);
546 void PrefScreenFonts::select_typewriter(const QString & name)
548 screenTypewriterFE->set(QFont(name), name);
552 /////////////////////////////////////////////////////////////////////
556 /////////////////////////////////////////////////////////////////////
562 bool operator()(ColorCode lhs, ColorCode rhs) const {
563 return lcolor.getGUIName(lhs) < lcolor.getGUIName(rhs);
569 PrefColors::PrefColors(GuiPreferences * form, QWidget * parent)
570 : PrefModule( _("Colors"), form, parent)
574 // FIXME: all of this initialization should be put into the controller.
575 // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
576 // for some discussion of why that is not trivial.
577 QPixmap icon(32, 32);
578 for (int i = 0; i < Color_ignore; ++i) {
579 ColorCode lc = static_cast<ColorCode>(i);
587 || lc == Color_magenta
588 || lc == Color_yellow
589 || lc == Color_inherit
590 || lc == Color_ignore) continue;
592 lcolors_.push_back(lc);
594 sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
595 vector<ColorCode>::const_iterator cit = lcolors_.begin();
596 vector<ColorCode>::const_iterator const end = lcolors_.end();
597 for (; cit != end; ++cit) {
598 (void) new QListWidgetItem(QIcon(icon),
599 toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW);
601 curcolors_.resize(lcolors_.size());
602 newcolors_.resize(lcolors_.size());
603 // End initialization
605 connect(colorChangePB, SIGNAL(clicked()),
606 this, SLOT(change_color()));
607 connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
608 this, SLOT(change_lyxObjects_selection()));
609 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
610 this, SLOT(change_color()));
614 void PrefColors::apply(LyXRC & /*rc*/) const
616 for (unsigned int i = 0; i < lcolors_.size(); ++i)
617 if (curcolors_[i] != newcolors_[i])
618 form_->setColor(lcolors_[i], fromqstr(newcolors_[i]));
622 void PrefColors::update(LyXRC const & /*rc*/)
624 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
625 QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
626 QPixmap coloritem(32, 32);
627 coloritem.fill(color);
628 lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
629 newcolors_[i] = curcolors_[i] = color.name();
631 change_lyxObjects_selection();
634 void PrefColors::change_color()
636 int const row = lyxObjectsLW->currentRow();
642 QString const color = newcolors_[row];
643 QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
645 if (c.isValid() && c.name() != color) {
646 newcolors_[row] = c.name();
647 QPixmap coloritem(32, 32);
649 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
655 void PrefColors::change_lyxObjects_selection()
657 colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
661 /////////////////////////////////////////////////////////////////////
665 /////////////////////////////////////////////////////////////////////
667 PrefDisplay::PrefDisplay(QWidget * parent)
668 : PrefModule(_("Graphics"), 0, parent)
671 connect(instantPreviewCO, SIGNAL(activated(int)),
672 this, SIGNAL(changed()));
673 connect(displayGraphicsCO, SIGNAL(activated(int)),
674 this, SIGNAL(changed()));
678 void PrefDisplay::apply(LyXRC & rc) const
680 switch (instantPreviewCO->currentIndex()) {
681 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
682 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
683 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
686 graphics::DisplayType dtype;
687 switch (displayGraphicsCO->currentIndex()) {
688 case 3: dtype = graphics::NoDisplay; break;
689 case 2: dtype = graphics::ColorDisplay; break;
690 case 1: dtype = graphics::GrayscaleDisplay; break;
691 case 0: dtype = graphics::MonochromeDisplay; break;
692 default: dtype = graphics::GrayscaleDisplay;
694 rc.display_graphics = dtype;
696 // FIXME!! The graphics cache no longer has a changeDisplay method.
698 if (old_value != rc.display_graphics) {
699 graphics::GCache & gc = graphics::GCache::get();
706 void PrefDisplay::update(LyXRC const & rc)
708 switch (rc.preview) {
709 case LyXRC::PREVIEW_OFF:
710 instantPreviewCO->setCurrentIndex(0);
712 case LyXRC::PREVIEW_NO_MATH :
713 instantPreviewCO->setCurrentIndex(1);
715 case LyXRC::PREVIEW_ON :
716 instantPreviewCO->setCurrentIndex(2);
721 switch (rc.display_graphics) {
722 case graphics::NoDisplay: item = 3; break;
723 case graphics::ColorDisplay: item = 2; break;
724 case graphics::GrayscaleDisplay: item = 1; break;
725 case graphics::MonochromeDisplay: item = 0; break;
728 displayGraphicsCO->setCurrentIndex(item);
732 /////////////////////////////////////////////////////////////////////
736 /////////////////////////////////////////////////////////////////////
738 PrefPaths::PrefPaths(GuiPreferences * form, QWidget * parent)
739 : PrefModule(_("Paths"), form, parent)
742 connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(select_exampledir()));
743 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
744 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
745 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
746 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
747 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
748 connect(workingDirED, SIGNAL(textChanged(QString)),
749 this, SIGNAL(changed()));
750 connect(exampleDirED, SIGNAL(textChanged(QString)),
751 this, SIGNAL(changed()));
752 connect(templateDirED, SIGNAL(textChanged(QString)),
753 this, SIGNAL(changed()));
754 connect(backupDirED, SIGNAL(textChanged(QString)),
755 this, SIGNAL(changed()));
756 connect(tempDirED, SIGNAL(textChanged(QString)),
757 this, SIGNAL(changed()));
758 connect(lyxserverDirED, SIGNAL(textChanged(QString)),
759 this, SIGNAL(changed()));
760 connect(pathPrefixED, SIGNAL(textChanged(QString)),
761 this, SIGNAL(changed()));
765 void PrefPaths::apply(LyXRC & rc) const
767 rc.document_path = internal_path(fromqstr(workingDirED->text()));
768 rc.example_path = internal_path(fromqstr(exampleDirED->text()));
769 rc.template_path = internal_path(fromqstr(templateDirED->text()));
770 rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
771 rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
772 rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
773 // FIXME: should be a checkbox only
774 rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
778 void PrefPaths::update(LyXRC const & rc)
780 workingDirED->setText(toqstr(external_path(rc.document_path)));
781 exampleDirED->setText(toqstr(external_path(rc.example_path)));
782 templateDirED->setText(toqstr(external_path(rc.template_path)));
783 backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
784 tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
785 pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
786 // FIXME: should be a checkbox only
787 lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
791 void PrefPaths::select_exampledir()
793 docstring file(form_->browsedir(
794 from_utf8(internal_path(fromqstr(exampleDirED->text()))),
795 _("Select directory for example files")));
797 exampleDirED->setText(toqstr(file));
801 void PrefPaths::select_templatedir()
803 docstring file(form_->browsedir(
804 from_utf8(internal_path(fromqstr(templateDirED->text()))),
805 _("Select a document templates directory")));
807 templateDirED->setText(toqstr(file));
811 void PrefPaths::select_tempdir()
813 docstring file(form_->browsedir(
814 from_utf8(internal_path(fromqstr(tempDirED->text()))),
815 _("Select a temporary directory")));
817 tempDirED->setText(toqstr(file));
821 void PrefPaths::select_backupdir()
823 docstring file(form_->browsedir(
824 from_utf8(internal_path(fromqstr(backupDirED->text()))),
825 _("Select a backups directory")));
827 backupDirED->setText(toqstr(file));
831 void PrefPaths::select_workingdir()
833 docstring file(form_->browsedir(
834 from_utf8(internal_path(fromqstr(workingDirED->text()))),
835 _("Select a document directory")));
837 workingDirED->setText(toqstr(file));
841 void PrefPaths::select_lyxpipe()
843 docstring file(form_->browse(
844 from_utf8(internal_path(fromqstr(lyxserverDirED->text()))),
845 _("Give a filename for the LyX server pipe")));
847 lyxserverDirED->setText(toqstr(file));
851 /////////////////////////////////////////////////////////////////////
855 /////////////////////////////////////////////////////////////////////
857 PrefSpellchecker::PrefSpellchecker(GuiPreferences * form, QWidget * parent)
858 : PrefModule(_("Spellchecker"), form, parent)
862 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
863 #if defined (USE_ISPELL)
864 connect(spellCommandCO, SIGNAL(activated(int)),
865 this, SIGNAL(changed()));
867 spellCommandCO->setEnabled(false);
869 connect(altLanguageED, SIGNAL(textChanged(QString)),
870 this, SIGNAL(changed()));
871 connect(escapeCharactersED, SIGNAL(textChanged(QString)),
872 this, SIGNAL(changed()));
873 connect(persDictionaryED, SIGNAL(textChanged(QString)),
874 this, SIGNAL(changed()));
875 connect(compoundWordCB, SIGNAL(clicked()),
876 this, SIGNAL(changed()));
877 connect(inputEncodingCB, SIGNAL(clicked()),
878 this, SIGNAL(changed()));
880 spellCommandCO->addItem(qt_("ispell"));
881 spellCommandCO->addItem(qt_("aspell"));
882 spellCommandCO->addItem(qt_("hspell"));
884 spellCommandCO->addItem(qt_("pspell (library)"));
887 spellCommandCO->addItem(qt_("aspell (library)"));
893 void PrefSpellchecker::apply(LyXRC & rc) const
895 switch (spellCommandCO->currentIndex()) {
899 rc.use_spell_lib = false;
900 rc.isp_command = fromqstr(spellCommandCO->currentText());
903 rc.use_spell_lib = true;
907 // FIXME: remove isp_use_alt_lang
908 rc.isp_alt_lang = fromqstr(altLanguageED->text());
909 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
910 // FIXME: remove isp_use_esc_chars
911 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
912 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
913 // FIXME: remove isp_use_pers_dict
914 rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
915 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
916 rc.isp_accept_compound = compoundWordCB->isChecked();
917 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
921 void PrefSpellchecker::update(LyXRC const & rc)
923 spellCommandCO->setCurrentIndex(0);
925 if (rc.isp_command == "ispell") {
926 spellCommandCO->setCurrentIndex(0);
927 } else if (rc.isp_command == "aspell") {
928 spellCommandCO->setCurrentIndex(1);
929 } else if (rc.isp_command == "hspell") {
930 spellCommandCO->setCurrentIndex(2);
933 if (rc.use_spell_lib) {
934 #if defined(USE_ASPELL) || defined(USE_PSPELL)
935 spellCommandCO->setCurrentIndex(3);
939 // FIXME: remove isp_use_alt_lang
940 altLanguageED->setText(toqstr(rc.isp_alt_lang));
941 // FIXME: remove isp_use_esc_chars
942 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
943 // FIXME: remove isp_use_pers_dict
944 persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
945 compoundWordCB->setChecked(rc.isp_accept_compound);
946 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
950 void PrefSpellchecker::select_dict()
952 docstring file(form_->browsedict(
953 from_utf8(internal_path(fromqstr(persDictionaryED->text())))));
955 persDictionaryED->setText(toqstr(file));
960 /////////////////////////////////////////////////////////////////////
964 /////////////////////////////////////////////////////////////////////
967 PrefConverters::PrefConverters(GuiPreferences * form, QWidget * parent)
968 : PrefModule(_("Converters"), form, parent)
972 connect(converterNewPB, SIGNAL(clicked()),
973 this, SLOT(update_converter()));
974 connect(converterRemovePB, SIGNAL(clicked()),
975 this, SLOT(remove_converter()));
976 connect(converterModifyPB, SIGNAL(clicked()),
977 this, SLOT(update_converter()));
978 connect(convertersLW, SIGNAL(currentRowChanged(int)),
979 this, SLOT(switch_converter()));
980 connect(converterFromCO, SIGNAL(activated(QString)),
981 this, SLOT(converter_changed()));
982 connect(converterToCO, SIGNAL(activated(QString)),
983 this, SLOT(converter_changed()));
984 connect(converterED, SIGNAL(textEdited(QString)),
985 this, SLOT(converter_changed()));
986 connect(converterFlagED, SIGNAL(textEdited(QString)),
987 this, SLOT(converter_changed()));
988 connect(converterNewPB, SIGNAL(clicked()),
989 this, SIGNAL(changed()));
990 connect(converterRemovePB, SIGNAL(clicked()),
991 this, SIGNAL(changed()));
992 connect(converterModifyPB, SIGNAL(clicked()),
993 this, SIGNAL(changed()));
994 connect(maxAgeLE, SIGNAL(textEdited(QString)),
995 this, SIGNAL(changed()));
997 maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
998 //converterDefGB->setFocusProxy(convertersLW);
1002 void PrefConverters::apply(LyXRC & rc) const
1004 rc.use_converter_cache = cacheCB->isChecked();
1005 rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
1009 void PrefConverters::update(LyXRC const & rc)
1011 cacheCB->setChecked(rc.use_converter_cache);
1013 max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
1014 maxAgeLE->setText(max_age);
1019 void PrefConverters::updateGui()
1021 form_->formats().sort();
1022 form_->converters().update(form_->formats());
1023 // save current selection
1024 QString current = converterFromCO->currentText()
1025 + " -> " + converterToCO->currentText();
1027 converterFromCO->clear();
1028 converterToCO->clear();
1030 Formats::const_iterator cit = form_->formats().begin();
1031 Formats::const_iterator end = form_->formats().end();
1032 for (; cit != end; ++cit) {
1033 converterFromCO->addItem(toqstr(cit->prettyname()));
1034 converterToCO->addItem(toqstr(cit->prettyname()));
1037 // currentRowChanged(int) is also triggered when updating the listwidget
1038 // block signals to avoid unnecessary calls to switch_converter()
1039 convertersLW->blockSignals(true);
1040 convertersLW->clear();
1042 Converters::const_iterator ccit = form_->converters().begin();
1043 Converters::const_iterator cend = form_->converters().end();
1044 for (; ccit != cend; ++ccit) {
1046 ccit->From->prettyname() + " -> " + ccit->To->prettyname();
1047 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
1048 new QListWidgetItem(toqstr(name), convertersLW, type);
1050 convertersLW->sortItems(Qt::AscendingOrder);
1051 convertersLW->blockSignals(false);
1053 // restore selection
1054 if (!current.isEmpty()) {
1055 QList<QListWidgetItem *> const item =
1056 convertersLW->findItems(current, Qt::MatchExactly);
1057 if (!item.isEmpty())
1058 convertersLW->setCurrentItem(item.at(0));
1061 // select first element if restoring failed
1062 if (convertersLW->currentRow() == -1)
1063 convertersLW->setCurrentRow(0);
1069 void PrefConverters::switch_converter()
1071 int const cnr = convertersLW->currentItem()->type();
1072 Converter const & c(form_->converters().get(cnr));
1073 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
1074 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
1075 converterED->setText(toqstr(c.command));
1076 converterFlagED->setText(toqstr(c.flags));
1082 void PrefConverters::converter_changed()
1088 void PrefConverters::updateButtons()
1090 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1091 Format const & to = form_->formats().get(converterToCO->currentIndex());
1092 int const sel = form_->converters().getNumber(from.name(), to.name());
1093 bool const known = sel >= 0;
1094 bool const valid = !(converterED->text().isEmpty()
1095 || from.name() == to.name());
1097 int const cnr = convertersLW->currentItem()->type();
1098 Converter const & c(form_->converters().get(cnr));
1099 string const old_command = c.command;
1100 string const old_flag = c.flags;
1101 string const new_command(fromqstr(converterED->text()));
1102 string const new_flag(fromqstr(converterFlagED->text()));
1104 bool modified = (old_command != new_command) || (old_flag != new_flag);
1106 converterModifyPB->setEnabled(valid && known && modified);
1107 converterNewPB->setEnabled(valid && !known);
1108 converterRemovePB->setEnabled(known);
1110 maxAgeLE->setEnabled(cacheCB->isChecked());
1111 maxAgeLA->setEnabled(cacheCB->isChecked());
1116 // specify unique from/to or it doesn't appear. This is really bad UI
1117 // this is why we can use the same function for both new and modify
1118 void PrefConverters::update_converter()
1120 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1121 Format const & to = form_->formats().get(converterToCO->currentIndex());
1122 string const flags = fromqstr(converterFlagED->text());
1123 string const command = fromqstr(converterED->text());
1125 Converter const * old =
1126 form_->converters().getConverter(from.name(), to.name());
1127 form_->converters().add(from.name(), to.name(), command, flags);
1130 form_->converters().updateLast(form_->formats());
1134 // Remove all files created by this converter from the cache, since
1135 // the modified converter might create different files.
1136 ConverterCache::get().remove_all(from.name(), to.name());
1140 void PrefConverters::remove_converter()
1142 Format const & from = form_->formats().get(converterFromCO->currentIndex());
1143 Format const & to = form_->formats().get(converterToCO->currentIndex());
1144 form_->converters().erase(from.name(), to.name());
1148 // Remove all files created by this converter from the cache, since
1149 // a possible new converter might create different files.
1150 ConverterCache::get().remove_all(from.name(), to.name());
1154 void PrefConverters::on_cacheCB_stateChanged(int state)
1156 maxAgeLE->setEnabled(state == Qt::Checked);
1157 maxAgeLA->setEnabled(state == Qt::Checked);
1162 /////////////////////////////////////////////////////////////////////
1166 /////////////////////////////////////////////////////////////////////
1168 FormatValidator::FormatValidator(QWidget * parent, Formats const & f)
1169 : QValidator(parent), formats_(f)
1174 void FormatValidator::fixup(QString & input) const
1176 Formats::const_iterator cit = formats_.begin();
1177 Formats::const_iterator end = formats_.end();
1178 for (; cit != end; ++cit) {
1179 string const name = str(cit);
1180 if (distance(formats_.begin(), cit) == nr()) {
1181 input = toqstr(name);
1189 QValidator::State FormatValidator::validate(QString & input, int & /*pos*/) const
1191 Formats::const_iterator cit = formats_.begin();
1192 Formats::const_iterator end = formats_.end();
1193 bool unknown = true;
1194 for (; unknown && cit != end; ++cit) {
1195 string const name = str(cit);
1196 if (distance(formats_.begin(), cit) != nr())
1197 unknown = toqstr(name) != input;
1200 if (unknown && !input.isEmpty())
1201 return QValidator::Acceptable;
1203 return QValidator::Intermediate;
1207 int FormatValidator::nr() const
1209 QComboBox * p = qobject_cast<QComboBox *>(parent());
1210 return p->itemData(p->currentIndex()).toInt();
1214 FormatNameValidator::FormatNameValidator(QWidget * parent, Formats const & f)
1215 : FormatValidator(parent, f)
1219 string FormatNameValidator::str(Formats::const_iterator it) const
1225 FormatPrettynameValidator::FormatPrettynameValidator(QWidget * parent, Formats const & f)
1226 : FormatValidator(parent, f)
1231 string FormatPrettynameValidator::str(Formats::const_iterator it) const
1233 return it->prettyname();
1237 PrefFileformats::PrefFileformats(GuiPreferences * form, QWidget * parent)
1238 : PrefModule(_("File formats"), form, parent)
1241 formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
1242 formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
1244 connect(documentCB, SIGNAL(clicked()),
1245 this, SLOT(setFlags()));
1246 connect(vectorCB, SIGNAL(clicked()),
1247 this, SLOT(setFlags()));
1248 connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
1249 this, SLOT(updatePrettyname()));
1250 connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
1251 this, SIGNAL(changed()));
1255 void PrefFileformats::apply(LyXRC & /*rc*/) const
1260 void PrefFileformats::update(LyXRC const & /*rc*/)
1266 void PrefFileformats::updateView()
1268 QString const current = formatsCB->currentText();
1270 // update combobox with formats
1271 formatsCB->blockSignals(true);
1273 form_->formats().sort();
1274 Formats::const_iterator cit = form_->formats().begin();
1275 Formats::const_iterator end = form_->formats().end();
1276 for (; cit != end; ++cit)
1277 formatsCB->addItem(toqstr(cit->prettyname()),
1278 QVariant(form_->formats().getNumber(cit->name())) );
1280 // restore selection
1281 int const item = formatsCB->findText(current, Qt::MatchExactly);
1282 formatsCB->setCurrentIndex(item < 0 ? 0 : item);
1283 on_formatsCB_currentIndexChanged(item < 0 ? 0 : item);
1284 formatsCB->blockSignals(false);
1288 void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
1290 int const nr = formatsCB->itemData(i).toInt();
1291 Format const f = form_->formats().get(nr);
1293 formatED->setText(toqstr(f.name()));
1294 copierED->setText(toqstr(form_->movers().command(f.name())));
1295 extensionED->setText(toqstr(f.extension()));
1296 shortcutED->setText(toqstr(f.shortcut()));
1297 viewerED->setText(toqstr(f.viewer()));
1298 editorED->setText(toqstr(f.editor()));
1299 documentCB->setChecked((f.documentFormat()));
1300 vectorCB->setChecked((f.vectorFormat()));
1304 void PrefFileformats::setFlags()
1306 int flags = Format::none;
1307 if (documentCB->isChecked())
1308 flags |= Format::document;
1309 if (vectorCB->isChecked())
1310 flags |= Format::vector;
1311 currentFormat().setFlags(flags);
1316 void PrefFileformats::on_copierED_textEdited(const QString & s)
1318 string const fmt = fromqstr(formatED->text());
1319 form_->movers().set(fmt, fromqstr(s));
1324 void PrefFileformats::on_extensionED_textEdited(const QString & s)
1326 currentFormat().setExtension(fromqstr(s));
1330 void PrefFileformats::on_viewerED_textEdited(const QString & s)
1332 currentFormat().setViewer(fromqstr(s));
1337 void PrefFileformats::on_editorED_textEdited(const QString & s)
1339 currentFormat().setEditor(fromqstr(s));
1344 void PrefFileformats::on_shortcutED_textEdited(const QString & s)
1346 currentFormat().setShortcut(fromqstr(s));
1351 void PrefFileformats::on_formatED_editingFinished()
1353 string const newname = fromqstr(formatED->displayText());
1354 if (newname == currentFormat().name())
1357 currentFormat().setName(newname);
1362 void PrefFileformats::on_formatED_textChanged(const QString &)
1364 QString t = formatED->text();
1366 bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable;
1367 setValid(formatLA, valid);
1371 void PrefFileformats::on_formatsCB_editTextChanged(const QString &)
1373 QString t = formatsCB->currentText();
1375 bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable;
1376 setValid(formatsLA, valid);
1380 void PrefFileformats::updatePrettyname()
1382 string const newname = fromqstr(formatsCB->currentText());
1383 if (newname == currentFormat().prettyname())
1386 currentFormat().setPrettyname(newname);
1393 Format & PrefFileformats::currentFormat()
1395 int const i = formatsCB->currentIndex();
1396 int const nr = formatsCB->itemData(i).toInt();
1397 return form_->formats().get(nr);
1401 void PrefFileformats::on_formatNewPB_clicked()
1403 form_->formats().add("", "", "", "", "", "", Format::none);
1405 formatsCB->setCurrentIndex(0);
1406 formatsCB->setFocus(Qt::OtherFocusReason);
1410 void PrefFileformats::on_formatRemovePB_clicked()
1412 int const i = formatsCB->currentIndex();
1413 int const nr = formatsCB->itemData(i).toInt();
1414 string const current_text = form_->formats().get(nr).name();
1415 if (form_->converters().formatIsUsed(current_text)) {
1416 Alert::error(_("Format in use"),
1417 _("Cannot remove a Format used by a Converter. "
1418 "Remove the converter first."));
1422 form_->formats().erase(current_text);
1425 on_formatsCB_editTextChanged(formatsCB->currentText());
1430 /////////////////////////////////////////////////////////////////////
1434 /////////////////////////////////////////////////////////////////////
1436 PrefLanguage::PrefLanguage(QWidget * parent)
1437 : PrefModule(_("Language"), 0, parent)
1441 connect(rtlGB, SIGNAL(clicked()),
1442 this, SIGNAL(changed()));
1443 connect(visualCursorRB, SIGNAL(clicked()),
1444 this, SIGNAL(changed()));
1445 connect(logicalCursorRB, SIGNAL(clicked()),
1446 this, SIGNAL(changed()));
1447 connect(markForeignCB, SIGNAL(clicked()),
1448 this, SIGNAL(changed()));
1449 connect(autoBeginCB, SIGNAL(clicked()),
1450 this, SIGNAL(changed()));
1451 connect(autoEndCB, SIGNAL(clicked()),
1452 this, SIGNAL(changed()));
1453 connect(useBabelCB, SIGNAL(clicked()),
1454 this, SIGNAL(changed()));
1455 connect(globalCB, SIGNAL(clicked()),
1456 this, SIGNAL(changed()));
1457 connect(languagePackageED, SIGNAL(textChanged(QString)),
1458 this, SIGNAL(changed()));
1459 connect(startCommandED, SIGNAL(textChanged(QString)),
1460 this, SIGNAL(changed()));
1461 connect(endCommandED, SIGNAL(textChanged(QString)),
1462 this, SIGNAL(changed()));
1463 connect(defaultLanguageCO, SIGNAL(activated(int)),
1464 this, SIGNAL(changed()));
1466 defaultLanguageCO->clear();
1468 // store the lang identifiers for later
1469 vector<LanguagePair> const langs = getLanguageData(false);
1470 vector<LanguagePair>::const_iterator lit = langs.begin();
1471 vector<LanguagePair>::const_iterator lend = langs.end();
1473 for (; lit != lend; ++lit) {
1474 defaultLanguageCO->addItem(toqstr(lit->first));
1475 lang_.push_back(lit->second);
1480 void PrefLanguage::apply(LyXRC & rc) const
1482 // FIXME: remove rtl_support bool
1483 rc.rtl_support = rtlGB->isChecked();
1484 rc.visual_cursor = rtlGB->isChecked() && visualCursorRB->isChecked();
1485 rc.mark_foreign_language = markForeignCB->isChecked();
1486 rc.language_auto_begin = autoBeginCB->isChecked();
1487 rc.language_auto_end = autoEndCB->isChecked();
1488 rc.language_use_babel = useBabelCB->isChecked();
1489 rc.language_global_options = globalCB->isChecked();
1490 rc.language_package = fromqstr(languagePackageED->text());
1491 rc.language_command_begin = fromqstr(startCommandED->text());
1492 rc.language_command_end = fromqstr(endCommandED->text());
1493 rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1497 void PrefLanguage::update(LyXRC const & rc)
1499 // FIXME: remove rtl_support bool
1500 rtlGB->setChecked(rc.rtl_support);
1501 if (rc.visual_cursor)
1502 visualCursorRB->setChecked(true);
1504 logicalCursorRB->setChecked(true);
1505 markForeignCB->setChecked(rc.mark_foreign_language);
1506 autoBeginCB->setChecked(rc.language_auto_begin);
1507 autoEndCB->setChecked(rc.language_auto_end);
1508 useBabelCB->setChecked(rc.language_use_babel);
1509 globalCB->setChecked(rc.language_global_options);
1510 languagePackageED->setText(toqstr(rc.language_package));
1511 startCommandED->setText(toqstr(rc.language_command_begin));
1512 endCommandED->setText(toqstr(rc.language_command_end));
1514 int const pos = int(findPos_helper(lang_, rc.default_language));
1515 defaultLanguageCO->setCurrentIndex(pos);
1519 /////////////////////////////////////////////////////////////////////
1523 /////////////////////////////////////////////////////////////////////
1525 PrefPrinter::PrefPrinter(QWidget * parent)
1526 : PrefModule(_("Printer"), 0, parent)
1530 connect(printerAdaptCB, SIGNAL(clicked()),
1531 this, SIGNAL(changed()));
1532 connect(printerCommandED, SIGNAL(textChanged(QString)),
1533 this, SIGNAL(changed()));
1534 connect(printerNameED, SIGNAL(textChanged(QString)),
1535 this, SIGNAL(changed()));
1536 connect(printerPageRangeED, SIGNAL(textChanged(QString)),
1537 this, SIGNAL(changed()));
1538 connect(printerCopiesED, SIGNAL(textChanged(QString)),
1539 this, SIGNAL(changed()));
1540 connect(printerReverseED, SIGNAL(textChanged(QString)),
1541 this, SIGNAL(changed()));
1542 connect(printerToPrinterED, SIGNAL(textChanged(QString)),
1543 this, SIGNAL(changed()));
1544 connect(printerExtensionED, SIGNAL(textChanged(QString)),
1545 this, SIGNAL(changed()));
1546 connect(printerSpoolCommandED, SIGNAL(textChanged(QString)),
1547 this, SIGNAL(changed()));
1548 connect(printerPaperTypeED, SIGNAL(textChanged(QString)),
1549 this, SIGNAL(changed()));
1550 connect(printerEvenED, SIGNAL(textChanged(QString)),
1551 this, SIGNAL(changed()));
1552 connect(printerOddED, SIGNAL(textChanged(QString)),
1553 this, SIGNAL(changed()));
1554 connect(printerCollatedED, SIGNAL(textChanged(QString)),
1555 this, SIGNAL(changed()));
1556 connect(printerLandscapeED, SIGNAL(textChanged(QString)),
1557 this, SIGNAL(changed()));
1558 connect(printerToFileED, SIGNAL(textChanged(QString)),
1559 this, SIGNAL(changed()));
1560 connect(printerExtraED, SIGNAL(textChanged(QString)),
1561 this, SIGNAL(changed()));
1562 connect(printerSpoolPrefixED, SIGNAL(textChanged(QString)),
1563 this, SIGNAL(changed()));
1564 connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
1565 this, SIGNAL(changed()));
1569 void PrefPrinter::apply(LyXRC & rc) const
1571 rc.print_adapt_output = printerAdaptCB->isChecked();
1572 rc.print_command = fromqstr(printerCommandED->text());
1573 rc.printer = fromqstr(printerNameED->text());
1575 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1576 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1577 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1578 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1579 rc.print_file_extension = fromqstr(printerExtensionED->text());
1580 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1581 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1582 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1583 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1584 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1585 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1586 rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1587 rc.print_extra_options = fromqstr(printerExtraED->text());
1588 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1589 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1593 void PrefPrinter::update(LyXRC const & rc)
1595 printerAdaptCB->setChecked(rc.print_adapt_output);
1596 printerCommandED->setText(toqstr(rc.print_command));
1597 printerNameED->setText(toqstr(rc.printer));
1599 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1600 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1601 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1602 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1603 printerExtensionED->setText(toqstr(rc.print_file_extension));
1604 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1605 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1606 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1607 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1608 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1609 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1610 printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1611 printerExtraED->setText(toqstr(rc.print_extra_options));
1612 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1613 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1617 /////////////////////////////////////////////////////////////////////
1619 // PrefUserInterface
1621 /////////////////////////////////////////////////////////////////////
1623 PrefUserInterface::PrefUserInterface(GuiPreferences * form, QWidget * parent)
1624 : PrefModule(_("User interface"), form, parent)
1628 connect(autoSaveCB, SIGNAL(toggled(bool)),
1629 autoSaveSB, SLOT(setEnabled(bool)));
1630 connect(autoSaveCB, SIGNAL(toggled(bool)),
1631 TextLabel1, SLOT(setEnabled(bool)));
1632 connect(uiFilePB, SIGNAL(clicked()),
1633 this, SLOT(select_ui()));
1634 connect(uiFileED, SIGNAL(textChanged(QString)),
1635 this, SIGNAL(changed()));
1636 connect(restoreCursorCB, SIGNAL(clicked()),
1637 this, SIGNAL(changed()));
1638 connect(loadSessionCB, SIGNAL(clicked()),
1639 this, SIGNAL(changed()));
1640 connect(allowGeometrySessionCB, SIGNAL(clicked()),
1641 this, SIGNAL(changed()));
1642 connect(cursorFollowsCB, SIGNAL(clicked()),
1643 this, SIGNAL(changed()));
1644 connect(sortEnvironmentsCB, SIGNAL(clicked()),
1645 this, SIGNAL(changed()));
1646 connect(macroEditStyleCO, SIGNAL(activated(int)),
1647 this, SIGNAL(changed()));
1648 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1649 this, SIGNAL(changed()));
1650 connect(autoSaveCB, SIGNAL(clicked()),
1651 this, SIGNAL(changed()));
1652 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1653 this, SIGNAL(changed()));
1654 connect(tooltipCB, SIGNAL(toggled(bool)),
1655 this, SIGNAL(changed()));
1656 lastfilesSB->setMaximum(maxlastfiles);
1660 void PrefUserInterface::apply(LyXRC & rc) const
1662 rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1663 rc.use_lastfilepos = restoreCursorCB->isChecked();
1664 rc.load_session = loadSessionCB->isChecked();
1665 rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
1666 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1667 rc.sort_layouts = sortEnvironmentsCB->isChecked();
1668 switch (macroEditStyleCO->currentIndex()) {
1669 case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
1670 case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
1671 case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST; break;
1673 rc.autosave = autoSaveSB->value() * 60;
1674 rc.make_backup = autoSaveCB->isChecked();
1675 rc.num_lastfiles = lastfilesSB->value();
1676 rc.use_tooltip = tooltipCB->isChecked();
1680 void PrefUserInterface::update(LyXRC const & rc)
1682 uiFileED->setText(toqstr(external_path(rc.ui_file)));
1683 restoreCursorCB->setChecked(rc.use_lastfilepos);
1684 loadSessionCB->setChecked(rc.load_session);
1685 allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
1686 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1687 sortEnvironmentsCB->setChecked(rc.sort_layouts);
1688 macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
1689 // convert to minutes
1690 int mins(rc.autosave / 60);
1691 if (rc.autosave && !mins)
1693 autoSaveSB->setValue(mins);
1694 autoSaveCB->setChecked(rc.make_backup);
1695 lastfilesSB->setValue(rc.num_lastfiles);
1696 tooltipCB->setChecked(rc.use_tooltip);
1700 void PrefUserInterface::select_ui()
1702 docstring const name =
1703 from_utf8(internal_path(fromqstr(uiFileED->text())));
1704 docstring file = form_->browseUI(name);
1706 uiFileED->setText(toqstr(file));
1710 /////////////////////////////////////////////////////////////////////
1714 /////////////////////////////////////////////////////////////////////
1717 GuiShortcutDialog::GuiShortcutDialog(QWidget * parent) : QDialog(parent)
1719 Ui::shortcutUi::setupUi(this);
1720 QDialog::setModal(true);
1724 PrefShortcuts::PrefShortcuts(GuiPreferences * form, QWidget * parent)
1725 : PrefModule(_("Shortcuts"), form, parent)
1729 shortcutsTW->setColumnCount(2);
1730 shortcutsTW->headerItem()->setText(0, qt_("Function"));
1731 shortcutsTW->headerItem()->setText(1, qt_("Shortcut"));
1732 shortcutsTW->setSortingEnabled(true);
1733 // Multi-selection can be annoying.
1734 // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
1735 shortcutsTW->header()->resizeSection(0, 200);
1737 connect(bindFilePB, SIGNAL(clicked()),
1738 this, SLOT(select_bind()));
1739 connect(bindFileED, SIGNAL(textChanged(QString)),
1740 this, SIGNAL(changed()));
1741 connect(removePB, SIGNAL(clicked()),
1742 this, SIGNAL(changed()));
1744 shortcut_ = new GuiShortcutDialog(this);
1745 shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
1746 shortcut_bc_.setOK(shortcut_->okPB);
1747 shortcut_bc_.setCancel(shortcut_->cancelPB);
1749 connect(shortcut_->okPB, SIGNAL(clicked()),
1750 shortcut_, SLOT(accept()));
1751 connect(shortcut_->okPB, SIGNAL(clicked()),
1752 this, SIGNAL(changed()));
1753 connect(shortcut_->cancelPB, SIGNAL(clicked()),
1754 shortcut_, SLOT(reject()));
1755 connect(shortcut_->clearPB, SIGNAL(clicked()),
1756 this, SLOT(shortcut_clearPB_pressed()));
1757 connect(shortcut_->okPB, SIGNAL(clicked()),
1758 this, SLOT(shortcut_okPB_pressed()));
1762 void PrefShortcuts::apply(LyXRC & rc) const
1764 rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1765 // write user_bind and user_unbind to .lyx/bind/user.bind
1766 FileName bind_dir(addPath(package().user_support().absFilename(), "bind"));
1767 if (!bind_dir.exists() && !bind_dir.createDirectory(0777)) {
1768 lyxerr << "LyX could not create the user bind directory '"
1769 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
1772 if (!bind_dir.isDirWritable()) {
1773 lyxerr << "LyX could not write to the user bind directory '"
1774 << bind_dir << "'. All user-defined key bindings will be lost." << endl;
1777 FileName user_bind_file(bind_dir.absFilename() + "/user.bind");
1778 user_bind_.write(user_bind_file.toFilesystemEncoding(), false, false);
1779 user_unbind_.write(user_bind_file.toFilesystemEncoding(), true, true);
1780 // immediately apply the keybindings. Why this is not done before?
1781 // The good thing is that the menus are updated automatically.
1782 theTopLevelKeymap().clear();
1783 theTopLevelKeymap().read("site");
1784 theTopLevelKeymap().read(rc.bind_file);
1785 theTopLevelKeymap().read("user");
1789 void PrefShortcuts::update(LyXRC const & rc)
1791 bindFileED->setText(toqstr(external_path(rc.bind_file)));
1793 system_bind_.clear();
1795 user_unbind_.clear();
1796 system_bind_.read(rc.bind_file);
1797 // \unbind in user.bind is added to user_unbind_
1798 user_bind_.read("user", &user_unbind_);
1799 updateShortcutsTW();
1803 void PrefShortcuts::updateShortcutsTW()
1805 shortcutsTW->clear();
1807 editItem_ = new QTreeWidgetItem(shortcutsTW);
1808 editItem_->setText(0, toqstr("Cursor, Mouse and Editing functions"));
1809 editItem_->setFlags(editItem_->flags() & ~Qt::ItemIsSelectable);
1811 mathItem_ = new QTreeWidgetItem(shortcutsTW);
1812 mathItem_->setText(0, toqstr("Mathematical Symbols"));
1813 mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
1815 bufferItem_ = new QTreeWidgetItem(shortcutsTW);
1816 bufferItem_->setText(0, toqstr("Buffer and Window"));
1817 bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
1819 layoutItem_ = new QTreeWidgetItem(shortcutsTW);
1820 layoutItem_->setText(0, toqstr("Font, Layouts and Textclasses"));
1821 layoutItem_->setFlags(layoutItem_->flags() & ~Qt::ItemIsSelectable);
1823 systemItem_ = new QTreeWidgetItem(shortcutsTW);
1824 systemItem_->setText(0, toqstr("System and Miscellaneous"));
1825 systemItem_->setFlags(systemItem_->flags() & ~Qt::ItemIsSelectable);
1827 // listBindings(unbound=true) lists all bound and unbound lfuns
1828 // Items in this list is tagged by its source.
1829 KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
1830 static_cast<int>(System));
1831 KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
1832 static_cast<int>(UserBind));
1833 KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
1834 static_cast<int>(UserUnbind));
1835 bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
1836 user_bindinglist.end());
1837 bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
1838 user_unbindinglist.end());
1840 KeyMap::BindingList::const_iterator it = bindinglist.begin();
1841 KeyMap::BindingList::const_iterator it_end = bindinglist.end();
1842 for (; it != it_end; ++it)
1843 insertShortcutItem(it->request, it->sequence, item_type(it->tag));
1845 shortcutsTW->sortItems(0, Qt::AscendingOrder);
1846 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
1847 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
1851 void PrefShortcuts::setItemType(QTreeWidgetItem * item, item_type tag)
1853 item->setData(0, Qt::UserRole, QVariant(tag));
1863 font.setStrikeOut(true);
1865 // this item is not displayed now.
1866 case UserExtraUnbind:
1867 font.setStrikeOut(true);
1871 item->setFont(1, font);
1875 QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
1876 KeySequence const & seq, item_type tag)
1878 kb_action action = lfun.action;
1879 string const action_name = lyxaction.getActionName(action);
1880 QString const lfun_name = toqstr(from_utf8(action_name)
1881 + " " + lfun.argument());
1882 QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
1883 item_type item_tag = tag;
1885 QTreeWidgetItem * newItem = NULL;
1886 // for unbind items, try to find an existing item in the system bind list
1887 if (tag == UserUnbind) {
1888 QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
1889 Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
1890 for (int i = 0; i < items.size(); ++i) {
1891 if (items[i]->text(1) == shortcut)
1895 // if not found, this unbind item is UserExtraUnbind
1896 // Such an item is not displayed to avoid confusion (what is
1897 // unmatched removed?).
1899 item_tag = UserExtraUnbind;
1904 switch(lyxaction.getActionType(action)) {
1905 case LyXAction::Hidden:
1907 case LyXAction::Edit:
1908 newItem = new QTreeWidgetItem(editItem_);
1910 case LyXAction::Math:
1911 newItem = new QTreeWidgetItem(mathItem_);
1913 case LyXAction::Buffer:
1914 newItem = new QTreeWidgetItem(bufferItem_);
1916 case LyXAction::Layout:
1917 newItem = new QTreeWidgetItem(layoutItem_);
1919 case LyXAction::System:
1920 newItem = new QTreeWidgetItem(systemItem_);
1923 // this should not happen
1924 newItem = new QTreeWidgetItem(shortcutsTW);
1928 newItem->setText(0, lfun_name);
1929 newItem->setText(1, shortcut);
1930 // record BindFile representation to recover KeySequence when needed.
1931 newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
1932 setItemType(newItem, item_tag);
1937 void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
1939 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
1940 removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
1941 if (items.isEmpty())
1944 item_type tag = static_cast<item_type>(items[0]->data(0, Qt::UserRole).toInt());
1945 if (tag == UserUnbind)
1946 removePB->setText(toqstr("Restore"));
1948 removePB->setText(toqstr("Remove"));
1952 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
1954 QTreeWidgetItem * item = shortcutsTW->currentItem();
1955 if (item->flags() & Qt::ItemIsSelectable) {
1956 shortcut_->lfunLE->setText(item->text(0));
1957 // clear the shortcut because I assume that a user will enter
1959 shortcut_->shortcutLE->reset();
1960 shortcut_->shortcutLE->setFocus();
1966 void PrefShortcuts::select_bind()
1968 docstring const name =
1969 from_utf8(internal_path(fromqstr(bindFileED->text())));
1970 docstring file = form_->browsebind(name);
1971 if (!file.empty()) {
1972 bindFileED->setText(toqstr(file));
1973 system_bind_ = KeyMap();
1974 system_bind_.read(to_utf8(file));
1975 updateShortcutsTW();
1980 void PrefShortcuts::on_newPB_pressed()
1982 shortcut_->lfunLE->clear();
1983 shortcut_->shortcutLE->reset();
1988 void PrefShortcuts::on_removePB_pressed()
1990 // it seems that only one item can be selected, but I am
1991 // removing all selected items anyway.
1992 QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
1993 for (int i = 0; i < items.size(); ++i) {
1994 string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
1995 string lfun = fromqstr(items[i]->text(0));
1996 FuncRequest func = lyxaction.lookupFunc(lfun);
1997 item_type tag = static_cast<item_type>(items[i]->data(0, Qt::UserRole).toInt());
2001 // for system bind, we do not touch the item
2002 // but add an user unbind item
2003 user_unbind_.bind(shortcut, func);
2004 setItemType(items[i], UserUnbind);
2005 removePB->setText(toqstr("Restore"));
2009 // for user_bind, we remove this bind
2010 QTreeWidgetItem * parent = items[i]->parent();
2011 int itemIdx = parent->indexOfChild(items[i]);
2012 parent->takeChild(itemIdx);
2014 shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
2016 shortcutsTW->scrollToItem(parent);
2017 user_bind_.unbind(shortcut, func);
2021 // for user_unbind, we remove the unbind, and the item
2022 // become System again.
2023 user_unbind_.unbind(shortcut, func);
2024 setItemType(items[i], System);
2025 removePB->setText(toqstr("Remove"));
2028 case UserExtraUnbind: {
2029 // for user unbind that is not in system bind file,
2030 // remove this unbind file
2031 QTreeWidgetItem * parent = items[i]->parent();
2032 parent->takeChild(parent->indexOfChild(items[i]));
2033 user_unbind_.unbind(shortcut, func);
2040 void PrefShortcuts::on_searchLE_textEdited()
2042 if (searchLE->text().isEmpty()) {
2043 // show all hidden items
2044 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
2046 shortcutsTW->setItemHidden(*it++, false);
2049 // search both columns
2050 QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
2051 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
2052 matched += shortcutsTW->findItems(searchLE->text(),
2053 Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
2055 // hide everyone (to avoid searching in matched QList repeatedly
2056 QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
2058 shortcutsTW->setItemHidden(*it++, true);
2059 // show matched items
2060 for (int i = 0; i < matched.size(); ++i) {
2061 shortcutsTW->setItemHidden(matched[i], false);
2062 shortcutsTW->setItemExpanded(matched[i]->parent(), true);
2067 void PrefShortcuts::shortcut_okPB_pressed()
2069 string lfun = fromqstr(shortcut_->lfunLE->text());
2070 FuncRequest func = lyxaction.lookupFunc(lfun);
2072 if (func.action == LFUN_UNKNOWN_ACTION) {
2073 Alert::error(_("Failed to create shortcut"),
2074 _("Unknown or invalid LyX function"));
2078 KeySequence k = shortcut_->shortcutLE->getKeySequence();
2079 if (k.length() == 0) {
2080 Alert::error(_("Failed to create shortcut"),
2081 _("Invalid or empty key sequence"));
2085 // if both lfun and shortcut is valid
2086 if (user_bind_.hasBinding(k, func) || system_bind_.hasBinding(k, func)) {
2087 Alert::error(_("Failed to create shortcut"),
2088 _("Shortcut is already defined"));
2092 QTreeWidgetItem * item = insertShortcutItem(func, k, UserBind);
2094 user_bind_.bind(&k, func);
2095 shortcutsTW->sortItems(0, Qt::AscendingOrder);
2096 shortcutsTW->setItemExpanded(item->parent(), true);
2097 shortcutsTW->scrollToItem(item);
2099 Alert::error(_("Failed to create shortcut"),
2100 _("Can not insert shortcut to the list"));
2106 void PrefShortcuts::shortcut_clearPB_pressed()
2108 shortcut_->shortcutLE->reset();
2109 shortcut_->shortcutLE->setFocus();
2113 /////////////////////////////////////////////////////////////////////
2117 /////////////////////////////////////////////////////////////////////
2119 PrefIdentity::PrefIdentity(QWidget * parent)
2120 : PrefModule(_("Identity"), 0, parent)
2124 connect(nameED, SIGNAL(textChanged(QString)),
2125 this, SIGNAL(changed()));
2126 connect(emailED, SIGNAL(textChanged(QString)),
2127 this, SIGNAL(changed()));
2131 void PrefIdentity::apply(LyXRC & rc) const
2133 rc.user_name = fromqstr(nameED->text());
2134 rc.user_email = fromqstr(emailED->text());
2138 void PrefIdentity::update(LyXRC const & rc)
2140 nameED->setText(toqstr(rc.user_name));
2141 emailED->setText(toqstr(rc.user_email));
2146 /////////////////////////////////////////////////////////////////////
2150 /////////////////////////////////////////////////////////////////////
2152 GuiPreferences::GuiPreferences(GuiView & lv)
2153 : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
2157 QDialog::setModal(false);
2159 connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
2160 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
2161 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
2162 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
2164 add(new PrefUserInterface(this));
2165 add(new PrefShortcuts(this));
2166 add(new PrefScreenFonts(this));
2167 add(new PrefColors(this));
2168 add(new PrefDisplay);
2169 add(new PrefInput(this));
2171 add(new PrefPaths(this));
2173 add(new PrefIdentity);
2175 add(new PrefLanguage);
2176 add(new PrefSpellchecker(this));
2178 add(new PrefPrinter);
2180 add(new PrefPlaintext);
2181 add(new PrefLatex(this));
2183 PrefConverters * converters = new PrefConverters(this);
2184 PrefFileformats * formats = new PrefFileformats(this);
2185 connect(formats, SIGNAL(formatsChanged()),
2186 converters, SLOT(updateGui()));
2190 prefsPS->setCurrentPanel(_("User interface"));
2191 // FIXME: hack to work around resizing bug in Qt >= 4.2
2192 // bug verified with Qt 4.2.{0-3} (JSpitzm)
2193 #if QT_VERSION >= 0x040200
2194 prefsPS->updateGeometry();
2197 bc().setPolicy(ButtonPolicy::PreferencesPolicy);
2199 bc().setApply(applyPB);
2200 bc().setCancel(closePB);
2201 bc().setRestore(restorePB);
2205 void GuiPreferences::add(PrefModule * module)
2207 BOOST_ASSERT(module);
2208 prefsPS->addPanel(module, module->title());
2209 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
2210 modules_.push_back(module);
2214 void GuiPreferences::closeEvent(QCloseEvent * e)
2221 void GuiPreferences::change_adaptor()
2227 void GuiPreferences::apply(LyXRC & rc) const
2229 size_t end = modules_.size();
2230 for (size_t i = 0; i != end; ++i)
2231 modules_[i]->apply(rc);
2235 void GuiPreferences::updateRc(LyXRC const & rc)
2237 size_t const end = modules_.size();
2238 for (size_t i = 0; i != end; ++i)
2239 modules_[i]->update(rc);
2243 void GuiPreferences::applyView()
2249 void GuiPreferences::updateContents()
2255 bool GuiPreferences::initialiseParams(string const &)
2258 formats_ = lyx::formats;
2259 converters_ = theConverters();
2260 converters_.update(formats_);
2261 movers_ = theMovers();
2263 update_screen_font_ = false;
2269 void GuiPreferences::dispatchParams()
2272 rc_.write(ss, true);
2273 dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
2274 // FIXME: these need lfuns
2276 theBufferList().setCurrentAuthor(from_utf8(rc_.user_name), from_utf8(rc_.user_email));
2278 lyx::formats = formats_;
2280 theConverters() = converters_;
2281 theConverters().update(lyx::formats);
2282 theConverters().buildGraph();
2284 theMovers() = movers_;
2286 vector<string>::const_iterator it = colors_.begin();
2287 vector<string>::const_iterator const end = colors_.end();
2288 for (; it != end; ++it)
2289 dispatch(FuncRequest(LFUN_SET_COLOR, *it));
2292 if (update_screen_font_) {
2293 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2294 update_screen_font_ = false;
2297 // The Save button has been pressed
2299 dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
2303 void GuiPreferences::setColor(ColorCode col, string const & hex)
2305 colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
2309 void GuiPreferences::updateScreenFonts()
2311 update_screen_font_ = true;
2315 docstring const GuiPreferences::browsebind(docstring const & file) const
2317 return browseLibFile(from_ascii("bind"), file, from_ascii("bind"),
2318 _("Choose bind file"),
2319 FileFilterList(_("LyX bind files (*.bind)")));
2323 docstring const GuiPreferences::browseUI(docstring const & file) const
2325 return browseLibFile(from_ascii("ui"), file, from_ascii("ui"),
2326 _("Choose UI file"),
2327 FileFilterList(_("LyX UI files (*.ui)")));
2331 docstring const GuiPreferences::browsekbmap(docstring const & file) const
2333 return browseLibFile(from_ascii("kbd"), file, from_ascii("kmap"),
2334 _("Choose keyboard map"),
2335 FileFilterList(_("LyX keyboard maps (*.kmap)")));
2339 docstring const GuiPreferences::browsedict(docstring const & file) const
2341 if (lyxrc.use_spell_lib)
2342 return browseFile(file,
2343 _("Choose personal dictionary"),
2344 FileFilterList(_("*.pws")));
2346 return browseFile(file,
2347 _("Choose personal dictionary"),
2348 FileFilterList(_("*.ispell")));
2352 docstring const GuiPreferences::browse(docstring const & file,
2353 docstring const & title) const
2355 return browseFile(file, title, FileFilterList(), true);
2359 docstring const GuiPreferences::browsedir(docstring const & path,
2360 docstring const & title) const
2362 return browseDir(path, title);
2366 // We support less paper sizes than the document dialog
2367 // Therefore this adjustment is needed.
2368 PAPER_SIZE GuiPreferences::toPaperSize(int i) const
2372 return PAPER_DEFAULT;
2374 return PAPER_USLETTER;
2376 return PAPER_USLEGAL;
2378 return PAPER_USEXECUTIVE;
2388 // should not happen
2389 return PAPER_DEFAULT;
2394 int GuiPreferences::fromPaperSize(PAPER_SIZE papersize) const
2396 switch (papersize) {
2399 case PAPER_USLETTER:
2403 case PAPER_USEXECUTIVE:
2414 // should not happen
2420 Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
2423 } // namespace frontend
2426 #include "GuiPrefs_moc.cpp"