3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Abdelrazak Younes
9 * Full author contact details are available in file CREDITS.
16 #include "GuiApplication.h"
17 #include "qt_helpers.h"
24 #include "support/lstrings.h"
25 #include "support/os.h"
27 #include "controllers/ControlPrefs.h"
28 #include "controllers/frnt_lang.h"
29 #include "controllers/helper_funcs.h"
31 #include "frontends/Alert.h"
32 #include "frontends/lyx_gui.h"
34 #include "QPrefsDialog.h"
37 #include "panelstack.h"
38 #include "qfontexample.h"
43 #include "controllers/ControlPrefs.h"
46 #include <QColorDialog>
47 #include <QFontDatabase>
49 #include <QPushButton>
53 #include <QCloseEvent>
55 #include <boost/tuple/tuple.hpp>
59 using lyx::support::compare_no_case;
66 using std::ostringstream;
74 string const LookAndFeel = "Look and feel";
75 string const LanguageSettings = "Language settings";
76 string const Outputs = "Outputs";
79 // FIXME: move to helper_funcs.h
83 typename std::vector<A>::size_type
84 findPos(std::vector<A> const & vec, A const & val)
86 typedef typename std::vector<A>::const_iterator Cit;
88 Cit it = std::find(vec.begin(), vec.end(), val);
91 return distance(vec.begin(), it);
94 void setComboxFont(QComboBox * cb, string const & family, string const & foundry)
96 string const name = makeFontName(family, foundry);
97 for (int i = 0; i < cb->count(); ++i) {
98 if (fromqstr(cb->itemText(i)) == name) {
99 cb->setCurrentIndex(i);
104 // Try matching without foundry name
106 // We count in reverse in order to prefer the Xft foundry
107 for (int i = cb->count() - 1; i >= 0; --i) {
108 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
109 if (compare_no_case(tmp.first, family) == 0) {
110 cb->setCurrentIndex(i);
115 // family alone can contain e.g. "Helvetica [Adobe]"
116 pair<string, string> tmpfam = parseFontName(family);
118 // We count in reverse in order to prefer the Xft foundry
119 for (int i = cb->count() - 1; i >= 0; --i) {
120 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
121 if (compare_no_case(tmp.first, tmpfam.first) == 0) {
122 cb->setCurrentIndex(i);
127 // Bleh, default fonts, and the names couldn't be found. Hack
128 // for bug 1063. Qt makes baby Jesus cry.
132 if (family == theApp->romanFontName()) {
133 font.setStyleHint(QFont::Serif);
134 font.setFamily(family.c_str());
135 } else if (family == theApp->sansFontName()) {
136 font.setStyleHint(QFont::SansSerif);
137 font.setFamily(family.c_str());
138 } else if (family == theApp->typewriterFontName()) {
139 font.setStyleHint(QFont::TypeWriter);
140 font.setFamily(family.c_str());
142 lyxerr << "FAILED to find the default font: '"
143 << foundry << "', '" << family << '\''<< endl;
147 QFontInfo info(font);
148 pair<string, string> tmp = parseFontName(fromqstr(info.family()));
149 string const & default_font_name = tmp.first;
150 lyxerr << "Apparent font is " << default_font_name << endl;
152 for (int i = 0; i < cb->count(); ++i) {
153 lyxerr << "Looking at " << fromqstr(cb->itemText(i)) << endl;
154 if (compare_no_case(fromqstr(cb->itemText(i)),
155 default_font_name) == 0) {
156 cb->setCurrentIndex(i);
161 lyxerr << "FAILED to find the font: '"
162 << foundry << "', '" << family << '\'' <<endl;
166 QString const external_path(string const & input)
168 return toqstr(lyx::support::os::external_path(input));
172 string const internal_path(QString const & input)
174 return lyx::support::os::internal_path(fromqstr(input));
177 } // end namespace anon
180 PrefAscii::PrefAscii(QWidget * parent)
181 : PrefModule(lyx::to_utf8(_(Outputs)), lyx::to_utf8(_("Plain text")), 0, parent)
184 connect(asciiLinelengthSB, SIGNAL(valueChanged(int)),
185 this, SIGNAL(changed()));
186 connect(asciiRoffED, SIGNAL(textChanged(const QString&)),
187 this, SIGNAL(changed()));
191 void PrefAscii::apply(LyXRC & rc) const
193 rc.ascii_linelen = asciiLinelengthSB->value();
194 rc.ascii_roff_command = fromqstr(asciiRoffED->text());
198 void PrefAscii::update(LyXRC const & rc)
200 asciiLinelengthSB->setValue(rc.ascii_linelen);
201 asciiRoffED->setText(toqstr(rc.ascii_roff_command));
205 PrefDate::PrefDate(QWidget * parent)
206 : PrefModule(lyx::to_utf8(_(Outputs)), lyx::to_utf8(_("Date format")), 0, parent)
209 connect(DateED, SIGNAL(textChanged(const QString&)),
210 this, SIGNAL(changed()));
214 void PrefDate::apply(LyXRC & rc) const
216 rc.date_insert_format = fromqstr(DateED->text());
220 void PrefDate::update(LyXRC const & rc)
222 DateED->setText(toqstr(rc.date_insert_format));
226 PrefKeyboard::PrefKeyboard(QPrefs * form, QWidget * parent)
227 : PrefModule(lyx::to_utf8(_(LookAndFeel)), lyx::to_utf8(_("Keyboard")), form, parent)
231 connect(keymapCB, SIGNAL( toggled(bool) ),
232 firstKeymapLA, SLOT( setEnabled(bool) ) );
233 connect(keymapCB, SIGNAL( toggled(bool) ),
234 secondKeymapLA, SLOT( setEnabled(bool) ) );
235 connect(keymapCB, SIGNAL( toggled(bool) ),
236 firstKeymapED, SLOT( setEnabled(bool) ) );
237 connect(keymapCB, SIGNAL( toggled(bool) ),
238 secondKeymapED, SLOT( setEnabled(bool) ) );
239 connect(keymapCB, SIGNAL( toggled(bool) ),
240 firstKeymapPB, SLOT( setEnabled(bool) ) );
241 connect(keymapCB, SIGNAL( toggled(bool) ),
242 secondKeymapPB, SLOT( setEnabled(bool) ) );
244 connect(keymapCB, SIGNAL(toggled(bool)),
245 this, SIGNAL(changed()));
246 connect(firstKeymapED, SIGNAL(textChanged(const QString&)),
247 this, SIGNAL(changed()));
248 connect(secondKeymapED, SIGNAL(textChanged(const QString&)),
249 this, SIGNAL(changed()));
253 void PrefKeyboard::apply(LyXRC & rc) const
255 // FIXME: can derive CB from the two EDs
256 rc.use_kbmap = keymapCB->isChecked();
257 rc.primary_kbmap = internal_path(firstKeymapED->text());
258 rc.secondary_kbmap = internal_path(secondKeymapED->text());
262 void PrefKeyboard::update(LyXRC const & rc)
264 // FIXME: can derive CB from the two EDs
265 keymapCB->setChecked(rc.use_kbmap);
266 // no idea why we need these. Fscking Qt.
267 firstKeymapED->setEnabled(rc.use_kbmap);
268 firstKeymapPB->setEnabled(rc.use_kbmap);
269 firstKeymapLA->setEnabled(rc.use_kbmap);
270 secondKeymapED->setEnabled(rc.use_kbmap);
271 secondKeymapPB->setEnabled(rc.use_kbmap);
272 secondKeymapLA->setEnabled(rc.use_kbmap);
273 firstKeymapED->setText(external_path(rc.primary_kbmap));
274 secondKeymapED->setText(external_path(rc.secondary_kbmap));
278 QString PrefKeyboard::testKeymap(QString keymap)
280 return toqstr(form_->controller().browsekbmap(fromqstr(keymap)));
284 void PrefKeyboard::on_firstKeymapPB_clicked(bool)
286 QString file = testKeymap(firstKeymapED->text());
288 firstKeymapED->setText(file);
292 void PrefKeyboard::on_secondKeymapPB_clicked(bool)
294 QString file = testKeymap(secondKeymapED->text());
296 secondKeymapED->setText(file);
300 PrefLatex::PrefLatex(QPrefs * form, QWidget * parent)
301 : PrefModule(lyx::to_utf8(_(Outputs)), lyx::to_utf8(_("LaTeX")), form, parent)
304 connect(latexEncodingED, SIGNAL(textChanged(const QString&)),
305 this, SIGNAL(changed()));
306 connect(latexChecktexED, SIGNAL(textChanged(const QString&)),
307 this, SIGNAL(changed()));
308 connect(latexBibtexED, SIGNAL(textChanged(const QString&)),
309 this, SIGNAL(changed()));
310 connect(latexIndexED, SIGNAL(textChanged(const QString&)),
311 this, SIGNAL(changed()));
312 connect(latexAutoresetCB, SIGNAL(toggled(bool)),
313 this, SIGNAL(changed()));
314 connect(latexDviPaperED, SIGNAL(textChanged(const QString&)),
315 this, SIGNAL(changed()));
316 connect(latexPaperSizeCO, SIGNAL(activated(int)),
317 this, SIGNAL(changed()));
321 void PrefLatex::apply(LyXRC & rc) const
323 rc.fontenc = fromqstr(latexEncodingED->text());
324 rc.chktex_command = fromqstr(latexChecktexED->text());
325 rc.bibtex_command = fromqstr(latexBibtexED->text());
326 rc.index_command = fromqstr(latexIndexED->text());
327 rc.auto_reset_options = latexAutoresetCB->isChecked();
328 rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
329 rc.default_papersize =
330 form_->controller().toPaperSize(latexPaperSizeCO->currentIndex());
334 void PrefLatex::update(LyXRC const & rc)
336 latexEncodingED->setText(toqstr(rc.fontenc));
337 latexChecktexED->setText(toqstr(rc.chktex_command));
338 latexBibtexED->setText(toqstr(rc.bibtex_command));
339 latexIndexED->setText(toqstr(rc.index_command));
340 latexAutoresetCB->setChecked(rc.auto_reset_options);
341 latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
342 latexPaperSizeCO->setCurrentIndex(
343 form_->controller().fromPaperSize(rc.default_papersize));
347 PrefScreenFonts::PrefScreenFonts(QPrefs * form, QWidget * parent)
348 : PrefModule(lyx::to_utf8(_(LookAndFeel)), lyx::to_utf8(_("Screen fonts")), form, parent)
352 connect(screenRomanCO, SIGNAL(activated(const QString&)),
353 this, SLOT(select_roman(const QString&)));
354 connect(screenSansCO, SIGNAL(activated(const QString&)),
355 this, SLOT(select_sans(const QString&)));
356 connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
357 this, SLOT(select_typewriter(const QString&)));
359 QFontDatabase fontdb;
360 QStringList families(fontdb.families());
361 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
362 screenRomanCO->addItem(*it);
363 screenSansCO->addItem(*it);
364 screenTypewriterCO->addItem(*it);
366 connect(screenRomanCO, SIGNAL(activated(const QString&)),
367 this, SIGNAL(changed()));
368 connect(screenSansCO, SIGNAL(activated(const QString&)),
369 this, SIGNAL(changed()));
370 connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
371 this, SIGNAL(changed()));
372 connect(screenZoomSB, SIGNAL(valueChanged(int)),
373 this, SIGNAL(changed()));
374 connect(screenDpiSB, SIGNAL(valueChanged(int)),
375 this, SIGNAL(changed()));
376 connect(screenTinyED, SIGNAL(textChanged(const QString&)),
377 this, SIGNAL(changed()));
378 connect(screenSmallestED, SIGNAL(textChanged(const QString&)),
379 this, SIGNAL(changed()));
380 connect(screenSmallerED, SIGNAL(textChanged(const QString&)),
381 this, SIGNAL(changed()));
382 connect(screenSmallED, SIGNAL(textChanged(const QString&)),
383 this, SIGNAL(changed()));
384 connect(screenNormalED, SIGNAL(textChanged(const QString&)),
385 this, SIGNAL(changed()));
386 connect(screenLargeED, SIGNAL(textChanged(const QString&)),
387 this, SIGNAL(changed()));
388 connect(screenLargerED, SIGNAL(textChanged(const QString&)),
389 this, SIGNAL(changed()));
390 connect(screenLargestED, SIGNAL(textChanged(const QString&)),
391 this, SIGNAL(changed()));
392 connect(screenHugeED, SIGNAL(textChanged(const QString&)),
393 this, SIGNAL(changed()));
394 connect(screenHugerED, SIGNAL(textChanged(const QString&)),
395 this, SIGNAL(changed()));
397 screenTinyED->setValidator(new QDoubleValidator(
399 screenSmallestED->setValidator(new QDoubleValidator(
401 screenSmallerED->setValidator(new QDoubleValidator(
403 screenSmallED->setValidator(new QDoubleValidator(
405 screenNormalED->setValidator(new QDoubleValidator(
407 screenLargeED->setValidator(new QDoubleValidator(
409 screenLargerED->setValidator(new QDoubleValidator(
411 screenLargestED->setValidator(new QDoubleValidator(
413 screenHugeED->setValidator(new QDoubleValidator(
415 screenHugerED->setValidator(new QDoubleValidator(
420 void PrefScreenFonts::apply(LyXRC & rc) const
422 LyXRC const oldrc(rc);
424 boost::tie(rc.roman_font_name, rc.roman_font_foundry)
425 = parseFontName(fromqstr(screenRomanCO->currentText()));
426 boost::tie(rc.sans_font_name, rc.sans_font_foundry) =
427 parseFontName(fromqstr(screenSansCO->currentText()));
428 boost::tie(rc.typewriter_font_name, rc.typewriter_font_foundry) =
429 parseFontName(fromqstr(screenTypewriterCO->currentText()));
431 rc.zoom = screenZoomSB->value();
432 rc.dpi = screenDpiSB->value();
433 rc.font_sizes[LyXFont::SIZE_TINY] = fromqstr(screenTinyED->text());
434 rc.font_sizes[LyXFont::SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
435 rc.font_sizes[LyXFont::SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
436 rc.font_sizes[LyXFont::SIZE_SMALL] = fromqstr(screenSmallED->text());
437 rc.font_sizes[LyXFont::SIZE_NORMAL] = fromqstr(screenNormalED->text());
438 rc.font_sizes[LyXFont::SIZE_LARGE] = fromqstr(screenLargeED->text());
439 rc.font_sizes[LyXFont::SIZE_LARGER] = fromqstr(screenLargerED->text());
440 rc.font_sizes[LyXFont::SIZE_LARGEST] = fromqstr(screenLargestED->text());
441 rc.font_sizes[LyXFont::SIZE_HUGE] = fromqstr(screenHugeED->text());
442 rc.font_sizes[LyXFont::SIZE_HUGER] = fromqstr(screenHugerED->text());
444 if (rc.font_sizes != oldrc.font_sizes
445 || rc.roman_font_name != oldrc.roman_font_name
446 || rc.sans_font_name != oldrc.sans_font_name
447 || rc.typewriter_font_name != oldrc.typewriter_font_name
448 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
449 form_->controller().updateScreenFonts();
454 void PrefScreenFonts::update(LyXRC const & rc)
456 setComboxFont(screenRomanCO, rc.roman_font_name,
457 rc.roman_font_foundry);
458 setComboxFont(screenSansCO, rc.sans_font_name,
459 rc.sans_font_foundry);
460 setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
461 rc.typewriter_font_foundry);
463 select_roman(screenRomanCO->currentText());
464 select_sans(screenSansCO->currentText());
465 select_typewriter(screenTypewriterCO->currentText());
467 screenZoomSB->setValue(rc.zoom);
468 screenDpiSB->setValue(rc.dpi);
469 screenTinyED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_TINY]));
470 screenSmallestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SCRIPT]));
471 screenSmallerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_FOOTNOTE]));
472 screenSmallED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SMALL]));
473 screenNormalED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_NORMAL]));
474 screenLargeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGE]));
475 screenLargerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGER]));
476 screenLargestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGEST]));
477 screenHugeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_HUGE]));
478 screenHugerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_HUGER]));
481 void PrefScreenFonts::select_roman(const QString& name)
483 screenRomanFE->set(QFont(name), name);
487 void PrefScreenFonts::select_sans(const QString& name)
489 screenSansFE->set(QFont(name), name);
493 void PrefScreenFonts::select_typewriter(const QString& name)
495 screenTypewriterFE->set(QFont(name), name);
499 PrefColors::PrefColors(QPrefs * form, QWidget * parent)
500 : PrefModule(lyx::to_utf8(_(LookAndFeel)), lyx::to_utf8(_("Colors")), form, parent)
504 // FIXME: put in controller
505 for (int i = 0; i < LColor::ignore; ++i) {
506 LColor::color lc = static_cast<LColor::color>(i);
507 if (lc == LColor::none
508 || lc == LColor::black
509 || lc == LColor::white
511 || lc == LColor::green
512 || lc == LColor::blue
513 || lc == LColor::cyan
514 || lc == LColor::magenta
515 || lc == LColor::yellow
516 || lc == LColor::inherit
517 || lc == LColor::ignore) continue;
519 lcolors_.push_back(lc);
520 QColor color = QColor(guiApp->colorCache().get(lc));
521 prefcolors_.push_back(color.name());
522 QPixmap coloritem(32, 32);
523 coloritem.fill(color);
524 // This is not a memory leak:
525 /*QListWidgetItem * newItem =*/ new QListWidgetItem(QIcon(coloritem),
526 toqstr(lcolor.getGUIName(lc)), lyxObjectsLW);
528 newcolors_ = prefcolors_;
530 connect(colorChangePB, SIGNAL(clicked()),
531 this, SLOT(change_color()));
532 connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
533 this, SLOT(change_color()));
537 void PrefColors::apply(LyXRC & /*rc*/) const
539 for (unsigned int i = 0; i < lcolors_.size(); ++i) {
540 if (prefcolors_[i]!=newcolors_[i])
541 form_->controller().setColor(lcolors_[i], fromqstr(newcolors_[i]));
546 void PrefColors::update(LyXRC const & /*rc*/)
550 void PrefColors::change_color()
552 int const row = lyxObjectsLW->currentRow();
553 QString color = newcolors_[row];
554 QColor c(QColorDialog::getColor(QColor(color),
555 qApp->focusWidget()));
557 if (c.name()!=color) {
558 newcolors_[row] = c.name();
559 QPixmap coloritem(32, 32);
561 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
568 PrefCygwinPath::PrefCygwinPath(QWidget * parent)
569 : PrefModule(lyx::to_utf8(_(Outputs)), lyx::to_utf8(_("Paths")), 0, parent)
572 connect(pathCB, SIGNAL(toggled(bool)),
573 this, SIGNAL(changed()));
577 void PrefCygwinPath::apply(LyXRC & rc) const
579 rc.windows_style_tex_paths = pathCB->isChecked();
583 void PrefCygwinPath::update(LyXRC const & rc)
585 pathCB->setChecked(rc.windows_style_tex_paths);
589 PrefDisplay::PrefDisplay(QWidget * parent)
590 : PrefModule(lyx::to_utf8(_(LookAndFeel)), lyx::to_utf8(_("Graphics")), 0, parent)
593 connect(instantPreviewCO, SIGNAL(activated(int)),
594 this, SIGNAL(changed()));
595 connect(displayGraphicsCO, SIGNAL(activated(int)),
596 this, SIGNAL(changed()));
600 void PrefDisplay::apply(LyXRC & rc) const
602 switch (instantPreviewCO->currentIndex()) {
603 case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
604 case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
605 case 2: rc.preview = LyXRC::PREVIEW_ON; break;
608 lyx::graphics::DisplayType dtype;
609 switch (displayGraphicsCO->currentIndex()) {
610 case 3: dtype = lyx::graphics::NoDisplay; break;
611 case 2: dtype = lyx::graphics::ColorDisplay; break;
612 case 1: dtype = lyx::graphics::GrayscaleDisplay; break;
613 case 0: dtype = lyx::graphics::MonochromeDisplay; break;
614 default: dtype = lyx::graphics::GrayscaleDisplay;
616 rc.display_graphics = dtype;
619 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
622 if (old_value != rc.display_graphics) {
623 lyx::graphics::GCache & gc = lyx::graphics::GCache::get();
630 void PrefDisplay::update(LyXRC const & rc)
632 switch (rc.preview) {
633 case LyXRC::PREVIEW_OFF:
634 instantPreviewCO->setCurrentIndex(0);
636 case LyXRC::PREVIEW_NO_MATH :
637 instantPreviewCO->setCurrentIndex(1);
639 case LyXRC::PREVIEW_ON :
640 instantPreviewCO->setCurrentIndex(2);
645 switch (rc.display_graphics) {
646 case lyx::graphics::NoDisplay: item = 3; break;
647 case lyx::graphics::ColorDisplay: item = 2; break;
648 case lyx::graphics::GrayscaleDisplay: item = 1; break;
649 case lyx::graphics::MonochromeDisplay: item = 0; break;
652 displayGraphicsCO->setCurrentIndex(item);
656 PrefPaths::PrefPaths(QPrefs * form, QWidget * parent)
657 : PrefModule(string(), lyx::to_utf8(_("Paths")), form, parent)
660 connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
661 connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
662 connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
663 connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
664 connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
665 connect(workingDirED, SIGNAL(textChanged(const QString&)),
666 this, SIGNAL(changed()));
667 connect(templateDirED, SIGNAL(textChanged(const QString&)),
668 this, SIGNAL(changed()));
669 connect(backupDirED, SIGNAL(textChanged(const QString&)),
670 this, SIGNAL(changed()));
671 connect(tempDirED, SIGNAL(textChanged(const QString&)),
672 this, SIGNAL(changed()));
673 connect(lyxserverDirED, SIGNAL(textChanged(const QString&)),
674 this, SIGNAL(changed()));
675 connect(pathPrefixED, SIGNAL(textChanged(const QString&)),
676 this, SIGNAL(changed()));
680 void PrefPaths::apply(LyXRC & rc) const
682 rc.document_path = internal_path(workingDirED->text());
683 rc.template_path = internal_path(templateDirED->text());
684 rc.backupdir_path = internal_path(backupDirED->text());
685 rc.tempdir_path = internal_path(tempDirED->text());
686 rc.path_prefix = fromqstr(pathPrefixED->text());
687 // FIXME: should be a checkbox only
688 rc.lyxpipes = internal_path(lyxserverDirED->text());
692 void PrefPaths::update(LyXRC const & rc)
694 workingDirED->setText(external_path(rc.document_path));
695 templateDirED->setText(external_path(rc.template_path));
696 backupDirED->setText(external_path(rc.backupdir_path));
697 tempDirED->setText(external_path(rc.tempdir_path));
698 pathPrefixED->setText(toqstr(rc.path_prefix));
699 // FIXME: should be a checkbox only
700 lyxserverDirED->setText(external_path(rc.lyxpipes));
703 // NB: the lyx::to_utf8(_() is OK here because it gets passed back and we toqstr()) them
705 void PrefPaths::select_templatedir()
707 string file(form_->controller().browsedir(fromqstr(templateDirED->text()), lyx::to_utf8(_("Select a document templates directory"))));
709 templateDirED->setText(toqstr(file));
713 void PrefPaths::select_tempdir()
715 string file(form_->controller().browsedir(fromqstr(tempDirED->text()), lyx::to_utf8(_("Select a temporary directory"))));
717 tempDirED->setText(toqstr(file));
721 void PrefPaths::select_backupdir()
723 string file(form_->controller().browsedir(fromqstr(backupDirED->text()), lyx::to_utf8(_("Select a backups directory"))));
725 backupDirED->setText(toqstr(file));
729 void PrefPaths::select_workingdir()
731 string file(form_->controller().browsedir(fromqstr(workingDirED->text()), lyx::to_utf8(_("Select a document directory"))));
733 workingDirED->setText(toqstr(file));
737 void PrefPaths::select_lyxpipe()
739 string file(form_->controller().browse(fromqstr(lyxserverDirED->text()), lyx::to_utf8(_("Give a filename for the LyX server pipe"))));
741 lyxserverDirED->setText(toqstr(file));
745 PrefSpellchecker::PrefSpellchecker(QPrefs * form, QWidget * parent)
746 : PrefModule(lyx::to_utf8(_(LanguageSettings)), lyx::to_utf8(_("Spellchecker")), form, parent)
750 connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
751 #if defined (USE_ISPELL)
752 connect(spellCommandCO, SIGNAL(activated(int)),
753 this, SIGNAL(changed()));
755 spellCommandCO->setEnabled(false);
757 connect(altLanguageED, SIGNAL(textChanged(const QString&)),
758 this, SIGNAL(changed()));
759 connect(escapeCharactersED, SIGNAL(textChanged(const QString&)),
760 this, SIGNAL(changed()));
761 connect(persDictionaryED, SIGNAL(textChanged(const QString&)),
762 this, SIGNAL(changed()));
763 connect(compoundWordCB, SIGNAL(toggled(bool)),
764 this, SIGNAL(changed()));
765 connect(inputEncodingCB, SIGNAL(toggled(bool)),
766 this, SIGNAL(changed()));
768 spellCommandCO->addItem(qt_("ispell"));
769 spellCommandCO->addItem(qt_("aspell"));
770 spellCommandCO->addItem(qt_("hspell"));
772 spellCommandCO->addItem(qt_("pspell (library)"));
775 spellCommandCO->addItem(qt_("aspell (library)"));
781 void PrefSpellchecker::apply(LyXRC & rc) const
783 switch (spellCommandCO->currentIndex()) {
787 rc.use_spell_lib = false;
788 rc.isp_command = fromqstr(spellCommandCO->currentText());
791 rc.use_spell_lib = true;
795 // FIXME: remove isp_use_alt_lang
796 rc.isp_alt_lang = fromqstr(altLanguageED->text());
797 rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
798 // FIXME: remove isp_use_esc_chars
799 rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
800 rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
801 // FIXME: remove isp_use_pers_dict
802 rc.isp_pers_dict = internal_path(persDictionaryED->text());
803 rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
804 rc.isp_accept_compound = compoundWordCB->isChecked();
805 rc.isp_use_input_encoding = inputEncodingCB->isChecked();
809 void PrefSpellchecker::update(LyXRC const & rc)
811 spellCommandCO->setCurrentIndex(0);
813 if (rc.isp_command == "ispell") {
814 spellCommandCO->setCurrentIndex(0);
815 } else if (rc.isp_command == "aspell") {
816 spellCommandCO->setCurrentIndex(1);
817 } else if (rc.isp_command == "hspell") {
818 spellCommandCO->setCurrentIndex(2);
821 if (rc.use_spell_lib) {
822 #if defined(USE_ASPELL) || defined(USE_PSPELL)
823 spellCommandCO->setCurrentIndex(3);
827 // FIXME: remove isp_use_alt_lang
828 altLanguageED->setText(toqstr(rc.isp_alt_lang));
829 // FIXME: remove isp_use_esc_chars
830 escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
831 // FIXME: remove isp_use_pers_dict
832 persDictionaryED->setText(external_path(rc.isp_pers_dict));
833 compoundWordCB->setChecked(rc.isp_accept_compound);
834 inputEncodingCB->setChecked(rc.isp_use_input_encoding);
838 void PrefSpellchecker::select_dict()
840 string file(form_->controller().browsedict(fromqstr(persDictionaryED->text())));
842 persDictionaryED->setText(toqstr(file));
846 PrefConverters::PrefConverters(QPrefs * form, QWidget * parent)
847 : PrefModule(string(), lyx::to_utf8(_("Converters")), form, parent)
851 connect(converterNewPB, SIGNAL(clicked()),
852 this, SLOT(new_converter()));
853 connect(converterRemovePB, SIGNAL(clicked()),
854 this, SLOT(remove_converter()));
855 connect(converterModifyPB, SIGNAL(clicked()),
856 this, SLOT(modify_converter()));
857 connect(convertersLW, SIGNAL(currentRowChanged(int)),
858 this, SLOT(switch_converter(int)));
859 connect(converterFromCO, SIGNAL(activated(const QString&)),
860 this, SLOT(converter_changed()));
861 connect(converterToCO, SIGNAL(activated(const QString&)),
862 this, SLOT(converter_changed()));
863 connect(converterED, SIGNAL(textChanged(const QString&)),
864 this, SLOT(converter_changed()));
865 connect(converterFlagED, SIGNAL(textChanged(const QString&)),
866 this, SLOT(converter_changed()));
867 connect(converterNewPB, SIGNAL(clicked()),
868 this, SIGNAL(changed()));
869 connect(converterRemovePB, SIGNAL(clicked()),
870 this, SIGNAL(changed()));
871 connect(converterModifyPB, SIGNAL(clicked()),
872 this, SIGNAL(changed()));
876 void PrefConverters::apply(LyXRC & /*rc*/) const
881 void PrefConverters::update(LyXRC const & /*rc*/)
887 void PrefConverters::updateGui()
889 // save current selection
890 QString current = converterFromCO->currentText()
891 + " -> " + converterToCO->currentText();
893 converterFromCO->clear();
894 converterToCO->clear();
896 Formats::const_iterator cit = form_->formats().begin();
897 Formats::const_iterator end = form_->formats().end();
898 for (; cit != end; ++cit) {
899 converterFromCO->addItem(toqstr(cit->prettyname()));
900 converterToCO->addItem(toqstr(cit->prettyname()));
903 convertersLW->clear();
905 Converters::const_iterator ccit = form_->converters().begin();
906 Converters::const_iterator cend = form_->converters().end();
907 for (; ccit != cend; ++ccit) {
908 std::string const name = ccit->From->prettyname() + " -> "
909 + ccit->To->prettyname();
910 new QListWidgetItem(toqstr(name), convertersLW,
911 form_->converters().getNumber(ccit->From->name(), ccit->To->name()));
913 convertersLW->sortItems(Qt::AscendingOrder);
916 if (!current.isEmpty()) {
917 QList<QListWidgetItem *> const item =
918 convertersLW->findItems(current, Qt::MatchExactly);
920 convertersLW->setCurrentItem(item.at(0));
922 // select first element if restoring failed
923 if (convertersLW->currentRow() == -1)
924 convertersLW->setCurrentRow(0);
930 void PrefConverters::switch_converter(int nr)
935 int const cnr = convertersLW->currentItem()->type();
936 Converter const & c(form_->converters().get(cnr));
937 converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
938 converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
939 converterED->setText(toqstr(c.command));
940 converterFlagED->setText(toqstr(c.flags));
946 void PrefConverters::converter_changed()
952 void PrefConverters::updateButtons()
954 Format const & from(form_->formats().get(
955 converterFromCO->currentIndex()));
956 Format const & to(form_->formats().get(
957 converterToCO->currentIndex()));
958 int const sel = form_->converters().getNumber(from.name(), to.name());
959 bool const known = !(sel < 0);
960 bool const valid = !(converterED->text().isEmpty()
961 || from.name() == to.name());
963 int const cnr = convertersLW->currentItem()->type();
964 Converter const & c(form_->converters().get(cnr));
965 string const old_command = c.command;
966 string const old_flag = c.flags;
967 string const new_command(fromqstr(converterED->text()));
968 string const new_flag(fromqstr(converterFlagED->text()));
970 bool modified = ((old_command != new_command) || (old_flag != new_flag));
972 converterModifyPB->setEnabled(valid && known && modified);
973 converterNewPB->setEnabled(valid && !known);
974 converterRemovePB->setEnabled(known);
979 // specify unique from/to or it doesn't appear. This is really bad UI
980 void PrefConverters::new_converter()
982 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
983 Format const & to(form_->formats().get(converterToCO->currentIndex()));
984 string const command(fromqstr(converterED->text()));
985 string const flags(fromqstr(converterFlagED->text()));
987 Converter const * old = form_->converters().getConverter(from.name(), to.name());
988 form_->converters().add(from.name(), to.name(), command, flags);
990 form_->converters().updateLast(form_->formats());
994 QString const name = toqstr(from.name() + " -> " + to.name());
995 QList<QListWidgetItem *> const item =
996 convertersLW->findItems(name, Qt::MatchExactly);
998 convertersLW->setCurrentItem(item.at(0));
1002 void PrefConverters::modify_converter()
1004 QString const current_text =
1005 convertersLW->currentItem()->text();
1007 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1008 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1009 string flags(fromqstr(converterFlagED->text()));
1010 string name(fromqstr(converterED->text()));
1012 Converter const * old = form_->converters().getConverter(from.name(), to.name());
1013 form_->converters().add(from.name(), to.name(), name, flags);
1015 form_->converters().updateLast(form_->formats());
1019 QList<QListWidgetItem *> const item =
1020 convertersLW->findItems(current_text, Qt::MatchExactly);
1022 convertersLW->setCurrentItem(item.at(0));
1026 void PrefConverters::remove_converter()
1028 Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1029 Format const & to(form_->formats().get(converterToCO->currentIndex()));
1030 form_->converters().erase(from.name(), to.name());
1035 PrefCopiers::PrefCopiers(QPrefs * form, QWidget * parent)
1036 : PrefModule(string(), lyx::to_utf8(_("Copiers")), form, parent)
1040 connect(copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
1041 connect(copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
1042 connect(copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
1043 connect(AllCopiersLW, SIGNAL(currentRowChanged(int)),
1044 this, SLOT(switch_copierLB(int)));
1045 connect(copierFormatCO, SIGNAL(activated(int)), this, SLOT(switch_copierCO(int)));
1046 connect(copierNewPB, SIGNAL(clicked()),
1047 this, SIGNAL(changed()));
1048 connect(copierRemovePB, SIGNAL(clicked()),
1049 this, SIGNAL(changed()));
1050 connect(copierModifyPB, SIGNAL(clicked()),
1051 this, SIGNAL(changed()));
1052 connect(copierFormatCO, SIGNAL(activated(const QString&)), this, SLOT(copiers_changed()));
1053 connect(copierED, SIGNAL(textChanged(const QString&)), this, SLOT(copiers_changed()));
1057 void PrefCopiers::apply(LyXRC & /*rc*/) const
1062 void PrefCopiers::update(LyXRC const & /*rc*/)
1068 void PrefCopiers::update()
1070 // The choice widget
1071 // save current selection
1072 QString current = copierFormatCO->currentText();
1073 copierFormatCO->clear();
1075 for (Formats::const_iterator it = form_->formats().begin(),
1076 end = form_->formats().end();
1078 copierFormatCO->addItem(toqstr(it->prettyname()));
1081 // The browser widget
1082 AllCopiersLW->clear();
1084 for (Movers::iterator it = form_->movers().begin(),
1085 end = form_->movers().end();
1087 std::string const & command = it->second.command();
1088 if (command.empty())
1090 QString const pretty = toqstr(form_->formats().prettyName(it->first));
1091 AllCopiersLW->addItem(pretty);
1093 AllCopiersLW->sortItems(Qt::AscendingOrder);
1095 // restore selection
1096 if (!current.isEmpty()) {
1097 QList<QListWidgetItem *> item =
1098 AllCopiersLW->findItems(current, Qt::MatchExactly);
1100 AllCopiersLW->setCurrentItem(item.at(0));
1102 // select first element if restoring failed
1103 if (AllCopiersLW->currentRow() == -1)
1104 AllCopiersLW->setCurrentRow(0);
1110 class SamePrettyName {
1112 SamePrettyName(string const & n) : pretty_name_(n) {}
1114 bool operator()(::Format const & fmt) const {
1115 return fmt.prettyname() == pretty_name_;
1119 string const pretty_name_;
1123 Format const * getFormat(std::string const & prettyname)
1125 Formats::const_iterator it = ::formats.begin();
1126 Formats::const_iterator const end = ::formats.end();
1127 it = std::find_if(it, end, SamePrettyName(prettyname));
1128 return it == end ? 0 : &*it;
1134 void PrefCopiers::switch_copierLB(int row)
1139 std::string const browser_text =
1140 fromqstr(AllCopiersLW->currentItem()->text());
1141 Format const * fmt = getFormat(browser_text);
1145 QString const gui_name = toqstr(fmt->prettyname());
1146 QString const command = toqstr(form_->movers().command(fmt->name()));
1149 int const combo_size = copierFormatCO->count();
1150 for (int i = 0; i < combo_size; ++i) {
1151 QString const text = copierFormatCO->itemText(i);
1152 if (text == gui_name) {
1153 copierFormatCO->setCurrentIndex(i);
1154 copierED->setText(command);
1162 void PrefCopiers::switch_copierCO(int row)
1167 std::string const combo_text =
1168 fromqstr(copierFormatCO->currentText());
1169 Format const * fmt = getFormat(combo_text);
1173 QString const command = toqstr(form_->movers().command(fmt->name()));
1174 copierED->setText(command);
1176 QListWidgetItem * const index = AllCopiersLW->currentItem();
1178 AllCopiersLW->setItemSelected(index, false);
1180 QString const gui_name = toqstr(fmt->prettyname());
1181 int const browser_size = AllCopiersLW->count();
1182 for (int i = 0; i < browser_size; ++i) {
1183 QString const text = AllCopiersLW->item(i)->text();
1184 if (text == gui_name) {
1185 QListWidgetItem * item = AllCopiersLW->item(i);
1186 AllCopiersLW->setItemSelected(item, true);
1193 void PrefCopiers::copiers_changed()
1199 void PrefCopiers::updateButtons()
1201 QString selected = copierFormatCO->currentText();
1204 for (int i = 0; i < AllCopiersLW->count(); ++i) {
1205 if (AllCopiersLW->item(i)->text() == selected)
1209 bool const valid = !copierED->text().isEmpty();
1211 Format const * fmt = getFormat(fromqstr(selected));
1212 string const old_command = form_->movers().command(fmt->name());
1213 string const new_command(fromqstr(copierED->text()));
1215 bool modified = (old_command != new_command);
1217 copierModifyPB->setEnabled(valid && known && modified);
1218 copierNewPB->setEnabled(valid && !known);
1219 copierRemovePB->setEnabled(known);
1223 void PrefCopiers::new_copier()
1225 std::string const combo_text =
1226 fromqstr(copierFormatCO->currentText());
1227 Format const * fmt = getFormat(combo_text);
1231 string const command = fromqstr(copierED->text());
1232 if (command.empty())
1235 form_->movers().set(fmt->name(), command);
1238 int const last = AllCopiersLW->count() - 1;
1239 AllCopiersLW->setCurrentRow(last);
1245 void PrefCopiers::modify_copier()
1247 std::string const combo_text =
1248 fromqstr(copierFormatCO->currentText());
1249 Format const * fmt = getFormat(combo_text);
1253 string const command = fromqstr(copierED->text());
1254 form_->movers().set(fmt->name(), command);
1261 void PrefCopiers::remove_copier()
1263 std::string const combo_text =
1264 fromqstr(copierFormatCO->currentText());
1265 Format const * fmt = getFormat(combo_text);
1269 string const & fmt_name = fmt->name();
1270 form_->movers().set(fmt_name, string());
1278 PrefFileformats::PrefFileformats(QPrefs * form, QWidget * parent)
1279 : PrefModule(string(), lyx::to_utf8(_("File formats")), form, parent)
1283 connect(formatNewPB, SIGNAL(clicked()), this, SLOT(new_format()));
1284 connect(formatRemovePB, SIGNAL(clicked()), this, SLOT(remove_format()));
1285 connect(formatModifyPB, SIGNAL(clicked()), this, SLOT(modify_format()));
1286 connect(formatsLW, SIGNAL(currentRowChanged(int)),
1287 this, SLOT(switch_format(int)));
1288 connect(formatED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
1289 connect(guiNameED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
1290 connect(shortcutED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
1291 connect(extensionED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
1292 connect(viewerED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
1293 connect(editorED, SIGNAL(textChanged(const QString&)), this, SLOT(fileformat_changed()));
1294 connect(documentCB, SIGNAL(toggled(bool)), this, SLOT(fileformat_changed()));
1295 connect(vectorCB, SIGNAL(toggled(bool)), this, SLOT(fileformat_changed()));
1296 connect(formatNewPB, SIGNAL(clicked()),
1297 this, SIGNAL(changed()));
1298 connect(formatRemovePB, SIGNAL(clicked()),
1299 this, SIGNAL(changed()));
1300 connect(formatModifyPB, SIGNAL(clicked()),
1301 this, SIGNAL(changed()));
1305 void PrefFileformats::apply(LyXRC & /*rc*/) const
1310 void PrefFileformats::update(LyXRC const & /*rc*/)
1316 void PrefFileformats::update()
1318 // save current selection
1319 QString current = guiNameED->text();
1323 Formats::const_iterator cit = form_->formats().begin();
1324 Formats::const_iterator end = form_->formats().end();
1325 for (; cit != end; ++cit) {
1326 new QListWidgetItem(toqstr(cit->prettyname()),
1328 form_->formats().getNumber(cit->name()) );
1330 formatsLW->sortItems(Qt::AscendingOrder);
1332 // restore selection
1333 if (!current.isEmpty()) {
1334 QList<QListWidgetItem *> item = formatsLW->findItems(current, Qt::MatchExactly);
1336 formatsLW->setCurrentItem(item.at(0));
1338 // select first element if restoring failed
1339 if (formatsLW->currentRow() == -1)
1340 formatsLW->setCurrentRow(0);
1344 void PrefFileformats::switch_format(int nr)
1349 int const ftype = formatsLW->item(nr)->type();
1350 Format const f(form_->formats().get(ftype));
1352 formatED->setText(toqstr(f.name()));
1353 guiNameED->setText(toqstr(f.prettyname()));
1354 extensionED->setText(toqstr(f.extension()));
1355 shortcutED->setText(toqstr(f.shortcut()));
1356 viewerED->setText(toqstr(f.viewer()));
1357 editorED->setText(toqstr(f.editor()));
1358 documentCB->setChecked((f.documentFormat()));
1359 vectorCB->setChecked((f.vectorFormat()));
1360 formatRemovePB->setEnabled(
1361 !form_->converters().formatIsUsed(f.name()));
1367 void PrefFileformats::fileformat_changed()
1373 void PrefFileformats::updateButtons()
1375 QString const format = formatED->text();
1376 QString const gui_name = guiNameED->text();
1377 int const sel = form_->formats().getNumber(fromqstr(format));
1378 bool gui_name_known = false;
1380 for (int i = 0; i < formatsLW->count(); ++i) {
1381 if (formatsLW->item(i)->text() == gui_name) {
1382 gui_name_known = true;
1383 where = formatsLW->item(i)->type();
1387 // assure that a gui name cannot be chosen twice
1388 bool const known_otherwise = gui_name_known && (where != sel);
1390 bool const known = !(sel < 0);
1391 bool const valid = (!formatED->text().isEmpty()
1392 && !guiNameED->text().isEmpty());
1394 int const ftype = formatsLW->currentItem()->type();
1395 Format const & f(form_->formats().get(ftype));
1396 string const old_pretty(f.prettyname());
1397 string const old_shortcut(f.shortcut());
1398 string const old_extension(f.extension());
1399 string const old_viewer(f.viewer());
1400 string const old_editor(f.editor());
1401 bool const old_document(f.documentFormat());
1402 bool const old_vector(f.vectorFormat());
1404 string const new_pretty(fromqstr(gui_name));
1405 string const new_shortcut(fromqstr(shortcutED->text()));
1406 string const new_extension(fromqstr(extensionED->text()));
1407 string const new_viewer(fromqstr(viewerED->text()));
1408 string const new_editor(fromqstr(editorED->text()));
1409 bool const new_document(documentCB->isChecked());
1410 bool const new_vector(vectorCB->isChecked());
1412 bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
1413 || (old_extension != new_extension) || (old_viewer != new_viewer)
1414 || old_editor != new_editor || old_document != new_document
1415 || old_vector != new_vector);
1417 formatModifyPB->setEnabled(
1418 valid && known && modified && !known_otherwise);
1419 formatNewPB->setEnabled(valid && !known && !gui_name_known);
1420 formatRemovePB->setEnabled(known);
1423 void PrefFileformats::setConverters(PrefConverters * converters)
1425 converters_ = converters;
1428 void PrefFileformats::new_format()
1430 string const name = fromqstr(formatED->text());
1431 string const prettyname = fromqstr(guiNameED->text());
1432 string const extension = fromqstr(extensionED->text());
1433 string const shortcut = fromqstr(shortcutED->text());
1434 string const viewer = fromqstr(viewerED->text());
1435 string const editor = fromqstr(editorED->text());
1436 int flags = Format::none;
1437 if (documentCB->isChecked())
1438 flags |= Format::document;
1439 if (vectorCB->isChecked())
1440 flags |= Format::vector;
1442 form_->formats().add(name, extension, prettyname, shortcut, viewer,
1444 form_->formats().sort();
1447 QList<QListWidgetItem *> const item =
1448 formatsLW->findItems(toqstr(prettyname), Qt::MatchExactly);
1450 formatsLW->setCurrentItem(item.at(0));
1452 form_->converters().update(form_->formats());
1454 converters_->updateGui();
1459 void PrefFileformats::modify_format()
1461 int const current_item = formatsLW->currentItem()->type();
1462 QString const current_text =
1463 formatsLW->currentItem()->text();
1465 Format const & oldformat(form_->formats().get(current_item));
1466 string const oldpretty(oldformat.prettyname());
1467 string const name(fromqstr(formatED->text()));
1468 form_->formats().erase(oldformat.name());
1470 string const prettyname = fromqstr(guiNameED->text());
1471 string const extension = fromqstr(extensionED->text());
1472 string const shortcut = fromqstr(shortcutED->text());
1473 string const viewer = fromqstr(viewerED->text());
1474 string const editor = fromqstr(editorED->text());
1475 int flags = Format::none;
1476 if (documentCB->isChecked())
1477 flags |= Format::document;
1478 if (vectorCB->isChecked())
1479 flags |= Format::vector;
1481 form_->formats().add(name, extension, prettyname, shortcut, viewer,
1483 form_->formats().sort();
1485 formatsLW->setUpdatesEnabled(false);
1487 formatsLW->setUpdatesEnabled(true);
1488 formatsLW->update();
1490 converters_->updateGui();
1493 QList<QListWidgetItem *> const item =
1494 formatsLW->findItems(current_text, Qt::MatchExactly);
1496 formatsLW->setCurrentItem(item.at(0));
1500 void PrefFileformats::remove_format()
1502 int const nr = formatsLW->currentItem()->type();
1505 string const current_text = form_->formats().get(nr).name();
1506 if (form_->converters().formatIsUsed(current_text)) {
1507 Alert::error(_("Format in use"),
1508 _("Cannot remove a Format used by a Converter. "
1509 "Remove the converter first."));
1513 form_->formats().erase(current_text);
1515 form_->converters().update(form_->formats());
1517 converters_->updateGui();
1523 PrefLanguage::PrefLanguage(QWidget * parent)
1524 : PrefModule(string(), lyx::to_utf8(_("Language")), 0, parent)
1528 connect(rtlCB, SIGNAL(toggled(bool)),
1529 this, SIGNAL(changed()));
1530 connect(markForeignCB, SIGNAL(toggled(bool)),
1531 this, SIGNAL(changed()));
1532 connect(autoBeginCB, SIGNAL(toggled(bool)),
1533 this, SIGNAL(changed()));
1534 connect(autoEndCB, SIGNAL(toggled(bool)),
1535 this, SIGNAL(changed()));
1536 connect(useBabelCB, SIGNAL(toggled(bool)),
1537 this, SIGNAL(changed()));
1538 connect(globalCB, SIGNAL(toggled(bool)),
1539 this, SIGNAL(changed()));
1540 connect(languagePackageED, SIGNAL(textChanged(const QString&)),
1541 this, SIGNAL(changed()));
1542 connect(startCommandED, SIGNAL(textChanged(const QString&)),
1543 this, SIGNAL(changed()));
1544 connect(endCommandED, SIGNAL(textChanged(const QString&)),
1545 this, SIGNAL(changed()));
1546 connect(defaultLanguageCO, SIGNAL(activated(int)),
1547 this, SIGNAL(changed()));
1549 defaultLanguageCO->clear();
1551 // store the lang identifiers for later
1552 using lyx::frontend::LanguagePair;
1553 std::vector<LanguagePair> const langs =
1554 lyx::frontend::getLanguageData(false);
1555 lang_ = getSecond(langs);
1557 std::vector<LanguagePair>::const_iterator lit = langs.begin();
1558 std::vector<LanguagePair>::const_iterator lend = langs.end();
1559 for (; lit != lend; ++lit) {
1560 defaultLanguageCO->addItem(toqstr(lit->first));
1565 void PrefLanguage::apply(LyXRC & rc) const
1567 // FIXME: remove rtl_support bool
1568 rc.rtl_support = rtlCB->isChecked();
1569 rc.mark_foreign_language = markForeignCB->isChecked();
1570 rc.language_auto_begin = autoBeginCB->isChecked();
1571 rc.language_auto_end = autoEndCB->isChecked();
1572 rc.language_use_babel = useBabelCB->isChecked();
1573 rc.language_global_options = globalCB->isChecked();
1574 rc.language_package = fromqstr(languagePackageED->text());
1575 rc.language_command_begin = fromqstr(startCommandED->text());
1576 rc.language_command_end = fromqstr(endCommandED->text());
1577 rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1581 void PrefLanguage::update(LyXRC const & rc)
1583 // FIXME: remove rtl_support bool
1584 rtlCB->setChecked(rc.rtl_support);
1585 markForeignCB->setChecked(rc.mark_foreign_language);
1586 autoBeginCB->setChecked(rc.language_auto_begin);
1587 autoEndCB->setChecked(rc.language_auto_end);
1588 useBabelCB->setChecked(rc.language_use_babel);
1589 globalCB->setChecked(rc.language_global_options);
1590 languagePackageED->setText(toqstr(rc.language_package));
1591 startCommandED->setText(toqstr(rc.language_command_begin));
1592 endCommandED->setText(toqstr(rc.language_command_end));
1594 int const pos = int(findPos(lang_, rc.default_language));
1595 defaultLanguageCO->setCurrentIndex(pos);
1599 PrefPrinter::PrefPrinter(QWidget * parent)
1600 : PrefModule(lyx::to_utf8(_(Outputs)), lyx::to_utf8(_("Printer")), 0, parent)
1604 connect(printerAdaptCB, SIGNAL(toggled(bool)),
1605 this, SIGNAL(changed()));
1606 connect(printerCommandED, SIGNAL(textChanged(const QString&)),
1607 this, SIGNAL(changed()));
1608 connect(printerNameED, SIGNAL(textChanged(const QString&)),
1609 this, SIGNAL(changed()));
1610 connect(printerPageRangeED, SIGNAL(textChanged(const QString&)),
1611 this, SIGNAL(changed()));
1612 connect(printerCopiesED, SIGNAL(textChanged(const QString&)),
1613 this, SIGNAL(changed()));
1614 connect(printerReverseED, SIGNAL(textChanged(const QString&)),
1615 this, SIGNAL(changed()));
1616 connect(printerToPrinterED, SIGNAL(textChanged(const QString&)),
1617 this, SIGNAL(changed()));
1618 connect(printerExtensionED, SIGNAL(textChanged(const QString&)),
1619 this, SIGNAL(changed()));
1620 connect(printerSpoolCommandED, SIGNAL(textChanged(const QString&)),
1621 this, SIGNAL(changed()));
1622 connect(printerPaperTypeED, SIGNAL(textChanged(const QString&)),
1623 this, SIGNAL(changed()));
1624 connect(printerEvenED, SIGNAL(textChanged(const QString&)),
1625 this, SIGNAL(changed()));
1626 connect(printerOddED, SIGNAL(textChanged(const QString&)),
1627 this, SIGNAL(changed()));
1628 connect(printerCollatedED, SIGNAL(textChanged(const QString&)),
1629 this, SIGNAL(changed()));
1630 connect(printerLandscapeED, SIGNAL(textChanged(const QString&)),
1631 this, SIGNAL(changed()));
1632 connect(printerToFileED, SIGNAL(textChanged(const QString&)),
1633 this, SIGNAL(changed()));
1634 connect(printerExtraED, SIGNAL(textChanged(const QString&)),
1635 this, SIGNAL(changed()));
1636 connect(printerSpoolPrefixED, SIGNAL(textChanged(const QString&)),
1637 this, SIGNAL(changed()));
1638 connect(printerPaperSizeED, SIGNAL(textChanged(const QString&)),
1639 this, SIGNAL(changed()));
1643 void PrefPrinter::apply(LyXRC & rc) const
1645 rc.print_adapt_output = printerAdaptCB->isChecked();
1646 rc.print_command = fromqstr(printerCommandED->text());
1647 rc.printer = fromqstr(printerNameED->text());
1649 rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1650 rc.print_copies_flag = fromqstr(printerCopiesED->text());
1651 rc.print_reverse_flag = fromqstr(printerReverseED->text());
1652 rc.print_to_printer = fromqstr(printerToPrinterED->text());
1653 rc.print_file_extension = fromqstr(printerExtensionED->text());
1654 rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1655 rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1656 rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1657 rc.print_oddpage_flag = fromqstr(printerOddED->text());
1658 rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1659 rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1660 rc.print_to_file = internal_path(printerToFileED->text());
1661 rc.print_extra_options = fromqstr(printerExtraED->text());
1662 rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1663 rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1667 void PrefPrinter::update(LyXRC const & rc)
1669 printerAdaptCB->setChecked(rc.print_adapt_output);
1670 printerCommandED->setText(toqstr(rc.print_command));
1671 printerNameED->setText(toqstr(rc.printer));
1673 printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1674 printerCopiesED->setText(toqstr(rc.print_copies_flag));
1675 printerReverseED->setText(toqstr(rc.print_reverse_flag));
1676 printerToPrinterED->setText(toqstr(rc.print_to_printer));
1677 printerExtensionED->setText(toqstr(rc.print_file_extension));
1678 printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1679 printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1680 printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1681 printerOddED->setText(toqstr(rc.print_oddpage_flag));
1682 printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1683 printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1684 printerToFileED->setText(external_path(rc.print_to_file));
1685 printerExtraED->setText(toqstr(rc.print_extra_options));
1686 printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1687 printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1691 PrefUserInterface::PrefUserInterface(QPrefs * form, QWidget * parent)
1692 : PrefModule(lyx::to_utf8(_(LookAndFeel)), lyx::to_utf8(_("User interface")), form, parent)
1696 connect(autoSaveCB, SIGNAL( toggled(bool) ), autoSaveLA, SLOT( setEnabled(bool) ) );
1697 connect(autoSaveCB, SIGNAL( toggled(bool) ), autoSaveSB, SLOT( setEnabled(bool) ) );
1698 connect(autoSaveCB, SIGNAL( toggled(bool) ), TextLabel1, SLOT( setEnabled(bool) ) );
1699 connect(uiFilePB, SIGNAL(clicked()), this, SLOT(select_ui()));
1700 connect(bindFilePB, SIGNAL(clicked()), this, SLOT(select_bind()));
1701 connect(uiFileED, SIGNAL(textChanged(const QString&)),
1702 this, SIGNAL(changed()));
1703 connect(bindFileED, SIGNAL(textChanged(const QString&)),
1704 this, SIGNAL(changed()));
1705 connect(restoreCursorCB, SIGNAL(toggled(bool)),
1706 this, SIGNAL(changed()));
1707 connect(loadSessionCB, SIGNAL(toggled(bool)),
1708 this, SIGNAL(changed()));
1709 connect(loadWindowSizeCB, SIGNAL(toggled(bool)),
1710 this, SIGNAL(changed()));
1711 connect(loadWindowSizeCB, SIGNAL(toggled(bool)),
1712 windowWidthLA, SLOT(setDisabled(bool)));
1713 connect(loadWindowSizeCB, SIGNAL(toggled(bool)),
1714 windowHeightLA, SLOT(setDisabled(bool)));
1715 connect(loadWindowSizeCB, SIGNAL(toggled(bool)),
1716 windowWidthSB, SLOT(setDisabled(bool)));
1717 connect(loadWindowSizeCB, SIGNAL(toggled(bool)),
1718 windowHeightSB, SLOT(setDisabled(bool)));
1719 connect(loadWindowLocationCB, SIGNAL(toggled(bool)),
1720 this, SIGNAL(changed()));
1721 connect(windowWidthSB, SIGNAL(valueChanged(int)),
1722 this, SIGNAL(changed()));
1723 connect(windowHeightSB, SIGNAL(valueChanged(int)),
1724 this, SIGNAL(changed()));
1725 connect(cursorFollowsCB, SIGNAL(toggled(bool)),
1726 this, SIGNAL(changed()));
1727 connect(autoSaveSB, SIGNAL(valueChanged(int)),
1728 this, SIGNAL(changed()));
1729 connect(autoSaveCB, SIGNAL(toggled(bool)),
1730 this, SIGNAL(changed()));
1731 connect(lastfilesSB, SIGNAL(valueChanged(int)),
1732 this, SIGNAL(changed()));
1733 lastfilesSB->setMaximum(maxlastfiles);
1737 void PrefUserInterface::apply(LyXRC & rc) const
1739 rc.ui_file = internal_path(uiFileED->text());
1740 rc.bind_file = internal_path(bindFileED->text());
1741 rc.use_lastfilepos = restoreCursorCB->isChecked();
1742 rc.load_session = loadSessionCB->isChecked();
1743 if (loadWindowSizeCB->isChecked()) {
1744 rc.geometry_width = 0;
1745 rc.geometry_height = 0;
1747 rc.geometry_width = windowWidthSB->value();
1748 rc.geometry_height = windowHeightSB->value();
1750 rc.geometry_xysaved = loadWindowLocationCB->isChecked();
1751 rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1752 rc.autosave = autoSaveSB->value() * 60;
1753 rc.make_backup = autoSaveCB->isChecked();
1754 rc.num_lastfiles = lastfilesSB->value();
1758 void PrefUserInterface::update(LyXRC const & rc)
1760 uiFileED->setText(external_path(rc.ui_file));
1761 bindFileED->setText(external_path(rc.bind_file));
1762 restoreCursorCB->setChecked(rc.use_lastfilepos);
1763 loadSessionCB->setChecked(rc.load_session);
1764 bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
1765 loadWindowSizeCB->setChecked(loadWindowSize);
1766 windowWidthSB->setEnabled(!loadWindowSize);
1767 windowHeightSB->setEnabled(!loadWindowSize);
1768 windowWidthLA->setEnabled(!loadWindowSize);
1769 windowHeightLA->setEnabled(!loadWindowSize);
1770 if (!loadWindowSize) {
1771 windowWidthSB->setValue(rc.geometry_width);
1772 windowHeightSB->setValue(rc.geometry_height);
1774 loadWindowLocationCB->setChecked(rc.geometry_xysaved);
1775 cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1776 // convert to minutes
1777 int mins(rc.autosave / 60);
1778 if (rc.autosave && !mins)
1780 autoSaveSB->setValue(mins);
1781 autoSaveCB->setChecked(rc.make_backup);
1782 lastfilesSB->setValue(rc.num_lastfiles);
1787 void PrefUserInterface::select_ui()
1789 string file(form_->controller().browseUI(fromqstr(uiFileED->text())));
1791 uiFileED->setText(toqstr(file));
1795 void PrefUserInterface::select_bind()
1797 string file(form_->controller().browsebind(fromqstr(bindFileED->text())));
1799 bindFileED->setText(toqstr(file));
1803 PrefIdentity::PrefIdentity(QWidget * parent)
1804 : PrefModule(string(), lyx::to_utf8(_("Identity")), 0, parent)
1808 connect(nameED, SIGNAL(textChanged(const QString&)),
1809 this, SIGNAL(changed()));
1810 connect(emailED, SIGNAL(textChanged(const QString&)),
1811 this, SIGNAL(changed()));
1815 void PrefIdentity::apply(LyXRC & rc) const
1817 rc.user_name = fromqstr(nameED->text());
1818 rc.user_email = fromqstr(emailED->text());
1822 void PrefIdentity::update(LyXRC const & rc)
1824 nameED->setText(toqstr(rc.user_name));
1825 emailED->setText(toqstr(rc.user_email));
1830 QPrefsDialog::QPrefsDialog(QPrefs * form)
1834 QDialog::setModal(true);
1836 connect(savePB, SIGNAL(clicked()),
1837 form, SLOT(slotOK()));
1838 connect(applyPB, SIGNAL(clicked()),
1839 form, SLOT(slotApply()));
1840 connect(closePB, SIGNAL(clicked()),
1841 form, SLOT(slotClose()));
1842 connect(restorePB, SIGNAL(clicked()),
1843 form, SLOT(slotRestore()));
1847 add(new PrefKeyboard(form_));
1848 add(new PrefLatex(form_));
1849 add(new PrefScreenFonts(form_));
1850 add(new PrefColors(form_));
1852 #if defined(__CYGWIN__) || defined(_WIN32)
1853 add(new PrefCygwinPath);
1856 add(new PrefDisplay);
1857 add(new PrefPaths(form_));
1858 add(new PrefSpellchecker(form_));
1860 PrefConverters * converters = new PrefConverters(form_);
1861 PrefFileformats * formats = new PrefFileformats(form_);
1862 formats->setConverters(converters);
1866 add(new PrefCopiers(form_));
1868 add(new PrefLanguage);
1869 add(new PrefPrinter);
1870 add(new PrefUserInterface(form_));
1871 add(new PrefIdentity);
1873 prefsPS->setCurrentPanel(lyx::to_utf8(_("User interface")));
1875 form_->bcview().setOK(savePB);
1876 form_->bcview().setApply(applyPB);
1877 form_->bcview().setCancel(closePB);
1878 form_->bcview().setRestore(restorePB);
1882 QPrefsDialog::~QPrefsDialog()
1887 void QPrefsDialog::add(PrefModule * module)
1889 BOOST_ASSERT(module);
1891 // if (module->category().empty())
1892 // prefsPS->addPanel(module, module->title());
1894 prefsPS->addPanel(module, module->title(), module->category());
1896 connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
1898 modules_.push_back(module);
1901 void QPrefsDialog::closeEvent(QCloseEvent * e)
1903 form_->slotWMHide();
1908 void QPrefsDialog::change_adaptor()
1914 void QPrefsDialog::apply(LyXRC & rc) const
1916 size_t end = modules_.size();
1917 for (size_t i = 0; i != end; ++i)
1918 modules_[i]->apply(rc);
1922 void QPrefsDialog::update(LyXRC const & rc)
1924 size_t end = modules_.size();
1925 for (size_t i = 0; i != end; ++i)
1926 modules_[i]->update(rc);
1930 } // namespace frontend
1933 #include "QPrefsDialog_moc.cpp"