]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QPrefsDialog.C
renaming in frontends/qt4/ui: s/Q//g
[lyx.git] / src / frontends / qt4 / QPrefsDialog.C
1 /**
2  * \file QPrefsDialog.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13 #include "debug.h"
14
15 #include "Qt2BC.h"
16 #include "GuiApplication.h"
17 #include "qt_helpers.h"
18
19 #include "debug.h"
20 #include "session.h"
21 #include "LColor.h"
22 #include "lyxfont.h"
23
24 #include "support/lstrings.h"
25 #include "support/os.h"
26
27 #include "controllers/ControlPrefs.h"
28 #include "controllers/frnt_lang.h"
29 #include "controllers/helper_funcs.h"
30
31 #include "frontends/Alert.h"
32 #include "frontends/Application.h"
33
34 #include "QPrefsDialog.h"
35 #include "QPrefs.h"
36
37 #include "panelstack.h"
38 #include "qfontexample.h"
39
40 #include "gettext.h"
41 #include "LColor.h"
42
43 #include "controllers/ControlPrefs.h"
44
45 #include <QCheckBox>
46 #include <QColorDialog>
47 #include <QFontDatabase>
48 #include <QLineEdit>
49 #include <QPushButton>
50 #include <QSpinBox>
51 #include <QString>
52 #include <QValidator>
53 #include <QCloseEvent>
54
55 #include <boost/tuple/tuple.hpp>
56 #include <iomanip>
57 #include <sstream>
58
59 using lyx::support::compare_ascii_no_case;
60 using lyx::support::os::external_path;
61 using lyx::support::os::external_path_list;
62 using lyx::support::os::internal_path;
63 using lyx::support::os::internal_path_list;
64
65 using std::distance;
66 using std::endl;
67 using std::setfill;
68 using std::setw;
69 using std::string;
70 using std::ostringstream;
71 using std::pair;
72 using std::vector;
73
74
75 namespace lyx {
76 namespace frontend {
77
78 string const LookAndFeel = N_("Look and feel");
79 string const LanguageSettings = N_("Language settings");
80 string const Outputs = N_("Outputs");
81
82
83 // FIXME: move to helper_funcs.h
84 namespace {
85
86 template<class A>
87 typename std::vector<A>::size_type
88 findPos_helper(std::vector<A> const & vec, A const & val)
89 {
90         typedef typename std::vector<A>::const_iterator Cit;
91
92         Cit it = std::find(vec.begin(), vec.end(), val);
93         if (it == vec.end())
94                 return 0;
95         return distance(vec.begin(), it);
96 }
97
98 void setComboxFont(QComboBox * cb, string const & family, string const & foundry)
99 {
100         string const name = makeFontName(family, foundry);
101         for (int i = 0; i < cb->count(); ++i) {
102                 if (fromqstr(cb->itemText(i)) == name) {
103                         cb->setCurrentIndex(i);
104                         return;
105                 }
106         }
107
108         // Try matching without foundry name
109
110         // We count in reverse in order to prefer the Xft foundry
111         for (int i = cb->count() - 1; i >= 0; --i) {
112                 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
113                 if (compare_ascii_no_case(tmp.first, family) == 0) {
114                         cb->setCurrentIndex(i);
115                         return;
116                 }
117         }
118
119         // family alone can contain e.g. "Helvetica [Adobe]"
120         pair<string, string> tmpfam = parseFontName(family);
121
122         // We count in reverse in order to prefer the Xft foundry
123         for (int i = cb->count() - 1; i >= 0; --i) {
124                 pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
125                 if (compare_ascii_no_case(tmp.first, tmpfam.first) == 0) {
126                         cb->setCurrentIndex(i);
127                         return;
128                 }
129         }
130
131         // Bleh, default fonts, and the names couldn't be found. Hack
132         // for bug 1063. Qt makes baby Jesus cry.
133
134         QFont font;
135         font.setKerning(false);
136
137         if (family == theApp()->romanFontName()) {
138                 font.setStyleHint(QFont::Serif);
139                 font.setFamily(family.c_str());
140         } else if (family == theApp()->sansFontName()) {
141                 font.setStyleHint(QFont::SansSerif);
142                 font.setFamily(family.c_str());
143         } else if (family == theApp()->typewriterFontName()) {
144                 font.setStyleHint(QFont::TypeWriter);
145                 font.setFamily(family.c_str());
146         } else {
147                 lyxerr << "FAILED to find the default font: '"
148                        << foundry << "', '" << family << '\''<< endl;
149                 return;
150         }
151
152         QFontInfo info(font);
153         pair<string, string> tmp = parseFontName(fromqstr(info.family()));
154         string const & default_font_name = tmp.first;
155         lyxerr << "Apparent font is " << default_font_name << endl;
156
157         for (int i = 0; i < cb->count(); ++i) {
158                 lyxerr << "Looking at " << fromqstr(cb->itemText(i)) << endl;
159                 if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
160                                     default_font_name) == 0) {
161                         cb->setCurrentIndex(i);
162                         return;
163                 }
164         }
165
166         lyxerr << "FAILED to find the font: '"
167                << foundry << "', '" << family << '\'' <<endl;
168 }
169
170 } // end namespace anon
171
172
173 PrefPlaintext::PrefPlaintext(QWidget * parent)
174 : PrefModule(_(Outputs), _("Plain text"), 0, parent)
175 {
176         setupUi(this);
177         connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
178                 this, SIGNAL(changed()));
179         connect(plaintextRoffED, SIGNAL(textChanged(const QString&)),
180                 this, SIGNAL(changed()));
181 }
182
183
184 void PrefPlaintext::apply(LyXRC & rc) const
185 {
186         rc.plaintext_linelen = plaintextLinelengthSB->value();
187         rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
188 }
189
190
191 void PrefPlaintext::update(LyXRC const & rc)
192 {
193         plaintextLinelengthSB->setValue(rc.plaintext_linelen);
194         plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
195 }
196
197
198 PrefDate::PrefDate(QWidget * parent)
199 : PrefModule(_(Outputs), _("Date format"), 0, parent)
200 {
201         setupUi(this);
202         connect(DateED, SIGNAL(textChanged(const QString&)),
203                 this, SIGNAL(changed()));
204 }
205
206
207 void PrefDate::apply(LyXRC & rc) const
208 {
209         rc.date_insert_format = fromqstr(DateED->text());
210 }
211
212
213 void PrefDate::update(LyXRC const & rc)
214 {
215         DateED->setText(toqstr(rc.date_insert_format));
216 }
217
218
219 PrefKeyboard::PrefKeyboard(QPrefs * form, QWidget * parent)
220 : PrefModule(_(LookAndFeel), _("Keyboard"), form, parent)
221 {
222         setupUi(this);
223
224         connect(keymapCB, SIGNAL(clicked()),
225                 this, SIGNAL(changed()));
226         connect(firstKeymapED, SIGNAL(textChanged(const QString&)),
227                 this, SIGNAL(changed()));
228         connect(secondKeymapED, SIGNAL(textChanged(const QString&)),
229                 this, SIGNAL(changed()));
230 }
231
232
233 void PrefKeyboard::apply(LyXRC & rc) const
234 {
235         // FIXME: can derive CB from the two EDs
236         rc.use_kbmap = keymapCB->isChecked();
237         rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
238         rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
239 }
240
241
242 void PrefKeyboard::update(LyXRC const & rc)
243 {
244         // FIXME: can derive CB from the two EDs
245         keymapCB->setChecked(rc.use_kbmap);
246         firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
247         secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
248 }
249
250
251 QString PrefKeyboard::testKeymap(QString keymap)
252 {
253         return toqstr(form_->controller().browsekbmap(from_utf8(internal_path(fromqstr(keymap)))));
254 }
255
256
257 void PrefKeyboard::on_firstKeymapPB_clicked(bool)
258 {
259         QString const file = testKeymap(firstKeymapED->text());
260         if (!file.isEmpty())
261                 firstKeymapED->setText(file);
262 }
263
264
265 void PrefKeyboard::on_secondKeymapPB_clicked(bool)
266 {
267         QString const file = testKeymap(secondKeymapED->text());
268         if (!file.isEmpty())
269                 secondKeymapED->setText(file);
270 }
271
272
273 void PrefKeyboard::on_keymapCB_toggled(bool keymap)
274 {
275         firstKeymapLA->setEnabled(keymap);
276         secondKeymapLA->setEnabled(keymap);
277         firstKeymapED->setEnabled(keymap);
278         secondKeymapED->setEnabled(keymap);
279         firstKeymapPB->setEnabled(keymap);
280         secondKeymapPB->setEnabled(keymap);
281 }
282
283
284 PrefLatex::PrefLatex(QPrefs * form, QWidget * parent)
285 : PrefModule(_(Outputs), _("LaTeX"), form, parent)
286 {
287         setupUi(this);
288         connect(latexEncodingED, SIGNAL(textChanged(const QString&)),
289                 this, SIGNAL(changed()));
290         connect(latexChecktexED, SIGNAL(textChanged(const QString&)),
291                 this, SIGNAL(changed()));
292         connect(latexBibtexED, SIGNAL(textChanged(const QString&)),
293                 this, SIGNAL(changed()));
294         connect(latexIndexED, SIGNAL(textChanged(const QString&)),
295                 this, SIGNAL(changed()));
296         connect(latexAutoresetCB, SIGNAL(clicked()),
297                 this, SIGNAL(changed()));
298         connect(latexDviPaperED, SIGNAL(textChanged(const QString&)),
299                 this, SIGNAL(changed()));
300         connect(latexPaperSizeCO, SIGNAL(activated(int)),
301                 this, SIGNAL(changed()));
302 }
303
304
305 void PrefLatex::apply(LyXRC & rc) const
306 {
307         rc.fontenc = fromqstr(latexEncodingED->text());
308         rc.chktex_command = fromqstr(latexChecktexED->text());
309         rc.bibtex_command = fromqstr(latexBibtexED->text());
310         rc.index_command = fromqstr(latexIndexED->text());
311         rc.auto_reset_options = latexAutoresetCB->isChecked();
312         rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
313         rc.default_papersize =
314                 form_->controller().toPaperSize(latexPaperSizeCO->currentIndex());
315 }
316
317
318 void PrefLatex::update(LyXRC const & rc)
319 {
320         latexEncodingED->setText(toqstr(rc.fontenc));
321         latexChecktexED->setText(toqstr(rc.chktex_command));
322         latexBibtexED->setText(toqstr(rc.bibtex_command));
323         latexIndexED->setText(toqstr(rc.index_command));
324         latexAutoresetCB->setChecked(rc.auto_reset_options);
325         latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
326         latexPaperSizeCO->setCurrentIndex(
327                 form_->controller().fromPaperSize(rc.default_papersize));
328 }
329
330
331 PrefScreenFonts::PrefScreenFonts(QPrefs * form, QWidget * parent)
332 : PrefModule(_(LookAndFeel), _("Screen fonts"), form, parent)
333 {
334         setupUi(this);
335
336         connect(screenRomanCO, SIGNAL(activated(const QString&)),
337                 this, SLOT(select_roman(const QString&)));
338         connect(screenSansCO, SIGNAL(activated(const QString&)),
339                 this, SLOT(select_sans(const QString&)));
340         connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
341                 this, SLOT(select_typewriter(const QString&)));
342
343         QFontDatabase fontdb;
344         QStringList families(fontdb.families());
345         for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
346                 screenRomanCO->addItem(*it);
347                 screenSansCO->addItem(*it);
348                 screenTypewriterCO->addItem(*it);
349         }
350         connect(screenRomanCO, SIGNAL(activated(const QString&)),
351                 this, SIGNAL(changed()));
352         connect(screenSansCO, SIGNAL(activated(const QString&)),
353                 this, SIGNAL(changed()));
354         connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
355                 this, SIGNAL(changed()));
356         connect(screenZoomSB, SIGNAL(valueChanged(int)),
357                 this, SIGNAL(changed()));
358         connect(screenDpiSB, SIGNAL(valueChanged(int)),
359                 this, SIGNAL(changed()));
360         connect(screenTinyED, SIGNAL(textChanged(const QString&)),
361                 this, SIGNAL(changed()));
362         connect(screenSmallestED, SIGNAL(textChanged(const QString&)),
363                 this, SIGNAL(changed()));
364         connect(screenSmallerED, SIGNAL(textChanged(const QString&)),
365                 this, SIGNAL(changed()));
366         connect(screenSmallED, SIGNAL(textChanged(const QString&)),
367                 this, SIGNAL(changed()));
368         connect(screenNormalED, SIGNAL(textChanged(const QString&)),
369                 this, SIGNAL(changed()));
370         connect(screenLargeED, SIGNAL(textChanged(const QString&)),
371                 this, SIGNAL(changed()));
372         connect(screenLargerED, SIGNAL(textChanged(const QString&)),
373                 this, SIGNAL(changed()));
374         connect(screenLargestED, SIGNAL(textChanged(const QString&)),
375                 this, SIGNAL(changed()));
376         connect(screenHugeED, SIGNAL(textChanged(const QString&)),
377                 this, SIGNAL(changed()));
378         connect(screenHugerED, SIGNAL(textChanged(const QString&)),
379                 this, SIGNAL(changed()));
380
381         screenTinyED->setValidator(new QDoubleValidator(
382                 screenTinyED));
383         screenSmallestED->setValidator(new QDoubleValidator(
384                 screenSmallestED));
385         screenSmallerED->setValidator(new QDoubleValidator(
386                 screenSmallerED));
387         screenSmallED->setValidator(new QDoubleValidator(
388                 screenSmallED));
389         screenNormalED->setValidator(new QDoubleValidator(
390                 screenNormalED));
391         screenLargeED->setValidator(new QDoubleValidator(
392                 screenLargeED));
393         screenLargerED->setValidator(new QDoubleValidator(
394                 screenLargerED));
395         screenLargestED->setValidator(new QDoubleValidator(
396                 screenLargestED));
397         screenHugeED->setValidator(new QDoubleValidator(
398                 screenHugeED));
399         screenHugerED->setValidator(new QDoubleValidator(
400                 screenHugerED));
401 }
402
403
404 void PrefScreenFonts::apply(LyXRC & rc) const
405 {
406         LyXRC const oldrc(rc);
407
408         boost::tie(rc.roman_font_name, rc.roman_font_foundry)
409                 = parseFontName(fromqstr(screenRomanCO->currentText()));
410         boost::tie(rc.sans_font_name, rc.sans_font_foundry) =
411                 parseFontName(fromqstr(screenSansCO->currentText()));
412         boost::tie(rc.typewriter_font_name, rc.typewriter_font_foundry) =
413                 parseFontName(fromqstr(screenTypewriterCO->currentText()));
414
415         rc.zoom = screenZoomSB->value();
416         rc.dpi = screenDpiSB->value();
417         rc.font_sizes[LyXFont::SIZE_TINY] = fromqstr(screenTinyED->text());
418         rc.font_sizes[LyXFont::SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
419         rc.font_sizes[LyXFont::SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
420         rc.font_sizes[LyXFont::SIZE_SMALL] = fromqstr(screenSmallED->text());
421         rc.font_sizes[LyXFont::SIZE_NORMAL] = fromqstr(screenNormalED->text());
422         rc.font_sizes[LyXFont::SIZE_LARGE] = fromqstr(screenLargeED->text());
423         rc.font_sizes[LyXFont::SIZE_LARGER] = fromqstr(screenLargerED->text());
424         rc.font_sizes[LyXFont::SIZE_LARGEST] = fromqstr(screenLargestED->text());
425         rc.font_sizes[LyXFont::SIZE_HUGE] = fromqstr(screenHugeED->text());
426         rc.font_sizes[LyXFont::SIZE_HUGER] = fromqstr(screenHugerED->text());
427
428         if (rc.font_sizes != oldrc.font_sizes
429                 || rc.roman_font_name != oldrc.roman_font_name
430                 || rc.sans_font_name != oldrc.sans_font_name
431                 || rc.typewriter_font_name != oldrc.typewriter_font_name
432                 || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
433                 form_->controller().updateScreenFonts();
434         }
435 }
436
437
438 void PrefScreenFonts::update(LyXRC const & rc)
439 {
440         setComboxFont(screenRomanCO, rc.roman_font_name,
441                         rc.roman_font_foundry);
442         setComboxFont(screenSansCO, rc.sans_font_name,
443                         rc.sans_font_foundry);
444         setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
445                         rc.typewriter_font_foundry);
446
447         select_roman(screenRomanCO->currentText());
448         select_sans(screenSansCO->currentText());
449         select_typewriter(screenTypewriterCO->currentText());
450
451         screenZoomSB->setValue(rc.zoom);
452         screenDpiSB->setValue(rc.dpi);
453         screenTinyED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_TINY]));
454         screenSmallestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SCRIPT]));
455         screenSmallerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_FOOTNOTE]));
456         screenSmallED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SMALL]));
457         screenNormalED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_NORMAL]));
458         screenLargeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGE]));
459         screenLargerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGER]));
460         screenLargestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGEST]));
461         screenHugeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_HUGE]));
462         screenHugerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_HUGER]));
463 }
464
465 void PrefScreenFonts::select_roman(const QString& name)
466 {
467         screenRomanFE->set(QFont(name), name);
468 }
469
470
471 void PrefScreenFonts::select_sans(const QString& name)
472 {
473         screenSansFE->set(QFont(name), name);
474 }
475
476
477 void PrefScreenFonts::select_typewriter(const QString& name)
478 {
479         screenTypewriterFE->set(QFont(name), name);
480 }
481
482
483 PrefColors::PrefColors(QPrefs * form, QWidget * parent)
484 : PrefModule(_(LookAndFeel), _("Colors"), form, parent)
485 {
486         setupUi(this);
487
488         // FIXME: all of this initialization should be put into the controller.
489         // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
490         // for some discussion of why that is not trivial.
491         for (int i = 0; i < LColor::ignore; ++i) {
492                 LColor::color lc = static_cast<LColor::color>(i);
493                 if (lc == LColor::none
494                         || lc == LColor::black
495                         || lc == LColor::white
496                         || lc == LColor::red
497                         || lc == LColor::green
498                         || lc == LColor::blue
499                         || lc == LColor::cyan
500                         || lc == LColor::magenta
501                         || lc == LColor::yellow
502                         || lc == LColor::inherit
503                         || lc == LColor::ignore) continue;
504
505                 lcolors_.push_back(lc);
506                 QColor color = QColor(guiApp->colorCache().get(lc));
507                 curcolors_.push_back(color.name());
508                 QPixmap coloritem(32, 32);
509                 coloritem.fill(color);
510                 // This is not a memory leak:
511                 /*QListWidgetItem * newItem =*/ new QListWidgetItem(QIcon(coloritem),
512                         toqstr(lcolor.getGUIName(lc)), lyxObjectsLW);
513         }
514         newcolors_ = curcolors_;
515         // End initialization
516
517         connect(colorChangePB, SIGNAL(clicked()),
518                 this, SLOT(change_color()));
519         connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
520                 this, SLOT(change_color()));
521 }
522
523
524 void PrefColors::apply(LyXRC & /*rc*/) const
525 {
526         for (unsigned int i = 0; i < lcolors_.size(); ++i) {
527                 if (curcolors_[i]!=newcolors_[i])
528                         form_->controller().setColor(lcolors_[i], fromqstr(newcolors_[i]));
529         }
530         // HACK The following line is needed because the values are not 
531         // re-initialized in ControlPrefs::initialiseParams but are only 
532         // initialized in the constructor. But the constructor is only called 
533         // once, when the dialog if first created, and is not called again when 
534         // Tools > Preferences is selected a second time: It's just called up 
535         // from memory. [See QDialogView::show(): if (!form) { build(); }.]
536         curcolors_ = newcolors_;
537 }
538
539
540 // FIXME The fact that this method is empty is also a symptom of the
541 // problem here.
542 void PrefColors::update(LyXRC const & /*rc*/)
543 {
544 }
545
546 void PrefColors::change_color()
547 {
548         int const row = lyxObjectsLW->currentRow();
549         QString color = newcolors_[row];
550         QColor c(QColorDialog::getColor(QColor(color),
551                 qApp->focusWidget()));
552
553         if (c.name()!=color) {
554                 newcolors_[row] = c.name();
555                 QPixmap coloritem(32, 32);
556                 coloritem.fill(c);
557                 lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
558                 // emit signal
559                 changed();
560         }
561 }
562
563
564 PrefCygwinPath::PrefCygwinPath(QWidget * parent)
565 : PrefModule(_(Outputs), _("Paths"), 0, parent)
566 {
567         setupUi(this);
568         connect(pathCB, SIGNAL(clicked()),
569                 this, SIGNAL(changed()));
570 }
571
572
573 void PrefCygwinPath::apply(LyXRC & rc) const
574 {
575         rc.windows_style_tex_paths = pathCB->isChecked();
576 }
577
578
579 void PrefCygwinPath::update(LyXRC const & rc)
580 {
581         pathCB->setChecked(rc.windows_style_tex_paths);
582 }
583
584
585 PrefDisplay::PrefDisplay(QWidget * parent)
586 : PrefModule(_(LookAndFeel), _("Graphics"), 0, parent)
587 {
588         setupUi(this);
589         connect(instantPreviewCO, SIGNAL(activated(int)),
590                 this, SIGNAL(changed()));
591         connect(displayGraphicsCO, SIGNAL(activated(int)),
592                 this, SIGNAL(changed()));
593 }
594
595
596 void PrefDisplay::apply(LyXRC & rc) const
597 {
598         switch (instantPreviewCO->currentIndex()) {
599         case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
600         case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
601         case 2: rc.preview = LyXRC::PREVIEW_ON; break;
602         }
603
604         lyx::graphics::DisplayType dtype;
605         switch (displayGraphicsCO->currentIndex()) {
606         case 3: dtype = lyx::graphics::NoDisplay; break;
607         case 2: dtype = lyx::graphics::ColorDisplay; break;
608         case 1: dtype = lyx::graphics::GrayscaleDisplay;        break;
609         case 0: dtype = lyx::graphics::MonochromeDisplay; break;
610         default: dtype = lyx::graphics::GrayscaleDisplay;
611         }
612         rc.display_graphics = dtype;
613
614 #ifdef WITH_WARNINGS
615 #warning FIXME!! The graphics cache no longer has a changeDisplay method.
616 #endif
617 #if 0
618         if (old_value != rc.display_graphics) {
619                 lyx::graphics::GCache & gc = lyx::graphics::GCache::get();
620                 gc.changeDisplay();
621         }
622 #endif
623 }
624
625
626 void PrefDisplay::update(LyXRC const & rc)
627 {
628         switch (rc.preview) {
629         case LyXRC::PREVIEW_OFF:
630                 instantPreviewCO->setCurrentIndex(0);
631                 break;
632         case LyXRC::PREVIEW_NO_MATH :
633                 instantPreviewCO->setCurrentIndex(1);
634                 break;
635         case LyXRC::PREVIEW_ON :
636                 instantPreviewCO->setCurrentIndex(2);
637                 break;
638         }
639
640         int item = 2;
641         switch (rc.display_graphics) {
642                 case lyx::graphics::NoDisplay:          item = 3; break;
643                 case lyx::graphics::ColorDisplay:       item = 2; break;
644                 case lyx::graphics::GrayscaleDisplay:   item = 1; break;
645                 case lyx::graphics::MonochromeDisplay:  item = 0; break;
646                 default: break;
647         }
648         displayGraphicsCO->setCurrentIndex(item);
649 }
650
651
652 PrefPaths::PrefPaths(QPrefs * form, QWidget * parent)
653 : PrefModule(docstring(), _("Paths"), form, parent)
654 {
655         setupUi(this);
656         connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
657         connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
658         connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
659         connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
660         connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
661         connect(workingDirED, SIGNAL(textChanged(const QString&)),
662                 this, SIGNAL(changed()));
663         connect(templateDirED, SIGNAL(textChanged(const QString&)),
664                 this, SIGNAL(changed()));
665         connect(backupDirED, SIGNAL(textChanged(const QString&)),
666                 this, SIGNAL(changed()));
667         connect(tempDirED, SIGNAL(textChanged(const QString&)),
668                 this, SIGNAL(changed()));
669         connect(lyxserverDirED, SIGNAL(textChanged(const QString&)),
670                 this, SIGNAL(changed()));
671         connect(pathPrefixED, SIGNAL(textChanged(const QString&)),
672                 this, SIGNAL(changed()));
673 }
674
675
676 void PrefPaths::apply(LyXRC & rc) const
677 {
678         rc.document_path = internal_path(fromqstr(workingDirED->text()));
679         rc.template_path = internal_path(fromqstr(templateDirED->text()));
680         rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
681         rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
682         rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
683         // FIXME: should be a checkbox only
684         rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
685 }
686
687
688 void PrefPaths::update(LyXRC const & rc)
689 {
690         workingDirED->setText(toqstr(external_path(rc.document_path)));
691         templateDirED->setText(toqstr(external_path(rc.template_path)));
692         backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
693         tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
694         pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
695         // FIXME: should be a checkbox only
696         lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
697 }
698
699
700 void PrefPaths::select_templatedir()
701 {
702         docstring file(form_->controller().browsedir(
703                 from_utf8(internal_path(fromqstr(templateDirED->text()))),
704                 _("Select a document templates directory")));
705         if (!file.empty())
706                 templateDirED->setText(toqstr(file));
707 }
708
709
710 void PrefPaths::select_tempdir()
711 {
712         docstring file(form_->controller().browsedir(
713                 from_utf8(internal_path(fromqstr(tempDirED->text()))),
714                 _("Select a temporary directory")));
715         if (!file.empty())
716                 tempDirED->setText(toqstr(file));
717 }
718
719
720 void PrefPaths::select_backupdir()
721 {
722         docstring file(form_->controller().browsedir(
723                 from_utf8(internal_path(fromqstr(backupDirED->text()))),
724                 _("Select a backups directory")));
725         if (!file.empty())
726                 backupDirED->setText(toqstr(file));
727 }
728
729
730 void PrefPaths::select_workingdir()
731 {
732         docstring file(form_->controller().browsedir(
733                 from_utf8(internal_path(fromqstr(workingDirED->text()))),
734                 _("Select a document directory")));
735         if (!file.empty())
736                 workingDirED->setText(toqstr(file));
737 }
738
739
740 void PrefPaths::select_lyxpipe()
741 {
742         docstring file(form_->controller().browse(
743                 from_utf8(internal_path(fromqstr(lyxserverDirED->text()))),
744                 _("Give a filename for the LyX server pipe")));
745         if (!file.empty())
746                 lyxserverDirED->setText(toqstr(file));
747 }
748
749
750 PrefSpellchecker::PrefSpellchecker(QPrefs * form, QWidget * parent)
751 : PrefModule(_(LanguageSettings), _("Spellchecker"), form, parent)
752 {
753         setupUi(this);
754
755         connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
756 #if defined (USE_ISPELL)
757         connect(spellCommandCO, SIGNAL(activated(int)),
758                 this, SIGNAL(changed()));
759 #else
760         spellCommandCO->setEnabled(false);
761 #endif
762         connect(altLanguageED, SIGNAL(textChanged(const QString&)),
763                 this, SIGNAL(changed()));
764         connect(escapeCharactersED, SIGNAL(textChanged(const QString&)),
765                 this, SIGNAL(changed()));
766         connect(persDictionaryED, SIGNAL(textChanged(const QString&)),
767                 this, SIGNAL(changed()));
768         connect(compoundWordCB, SIGNAL(clicked()),
769                 this, SIGNAL(changed()));
770         connect(inputEncodingCB, SIGNAL(clicked()),
771                 this, SIGNAL(changed()));
772
773         spellCommandCO->addItem(qt_("ispell"));
774         spellCommandCO->addItem(qt_("aspell"));
775         spellCommandCO->addItem(qt_("hspell"));
776 #ifdef USE_PSPELL
777         spellCommandCO->addItem(qt_("pspell (library)"));
778 #else
779 #ifdef USE_ASPELL
780         spellCommandCO->addItem(qt_("aspell (library)"));
781 #endif
782 #endif
783 }
784
785
786 void PrefSpellchecker::apply(LyXRC & rc) const
787 {
788         switch (spellCommandCO->currentIndex()) {
789                 case 0:
790                 case 1:
791                 case 2:
792                         rc.use_spell_lib = false;
793                         rc.isp_command = fromqstr(spellCommandCO->currentText());
794                         break;
795                 case 3:
796                         rc.use_spell_lib = true;
797                         break;
798         }
799
800         // FIXME: remove isp_use_alt_lang
801         rc.isp_alt_lang = fromqstr(altLanguageED->text());
802         rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
803         // FIXME: remove isp_use_esc_chars
804         rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
805         rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
806         // FIXME: remove isp_use_pers_dict
807         rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
808         rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
809         rc.isp_accept_compound = compoundWordCB->isChecked();
810         rc.isp_use_input_encoding = inputEncodingCB->isChecked();
811 }
812
813
814 void PrefSpellchecker::update(LyXRC const & rc)
815 {
816         spellCommandCO->setCurrentIndex(0);
817
818         if (rc.isp_command == "ispell") {
819                 spellCommandCO->setCurrentIndex(0);
820         } else if (rc.isp_command == "aspell") {
821                 spellCommandCO->setCurrentIndex(1);
822         } else if (rc.isp_command == "hspell") {
823                 spellCommandCO->setCurrentIndex(2);
824         }
825
826         if (rc.use_spell_lib) {
827 #if defined(USE_ASPELL) || defined(USE_PSPELL)
828                 spellCommandCO->setCurrentIndex(3);
829 #endif
830         }
831
832         // FIXME: remove isp_use_alt_lang
833         altLanguageED->setText(toqstr(rc.isp_alt_lang));
834         // FIXME: remove isp_use_esc_chars
835         escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
836         // FIXME: remove isp_use_pers_dict
837         persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
838         compoundWordCB->setChecked(rc.isp_accept_compound);
839         inputEncodingCB->setChecked(rc.isp_use_input_encoding);
840 }
841
842
843 void PrefSpellchecker::select_dict()
844 {
845         docstring file(form_->controller().browsedict(
846                 from_utf8(internal_path(fromqstr(persDictionaryED->text())))));
847         if (!file.empty())
848                 persDictionaryED->setText(toqstr(file));
849 }
850
851
852 PrefConverters::PrefConverters(QPrefs * form, QWidget * parent)
853 : PrefModule(docstring(), _("Converters"), form, parent)
854 {
855         setupUi(this);
856
857         connect(converterNewPB, SIGNAL(clicked()),
858                 this, SLOT(update_converter()));
859         connect(converterRemovePB, SIGNAL(clicked()),
860                 this, SLOT(remove_converter()));
861         connect(converterModifyPB, SIGNAL(clicked()),
862                 this, SLOT(update_converter()));
863         connect(convertersLW, SIGNAL(currentRowChanged(int)),
864                 this, SLOT(switch_converter()));
865         connect(converterFromCO, SIGNAL(activated(const QString&)),
866                 this, SLOT(converter_changed()));
867         connect(converterToCO, SIGNAL(activated(const QString&)),
868                 this, SLOT(converter_changed()));
869         connect(converterED, SIGNAL(textChanged(const QString&)),
870                 this, SLOT(converter_changed()));
871         connect(converterFlagED, SIGNAL(textChanged(const QString&)),
872                 this, SLOT(converter_changed()));
873         connect(converterNewPB, SIGNAL(clicked()),
874                 this, SIGNAL(changed()));
875         connect(converterRemovePB, SIGNAL(clicked()),
876                 this, SIGNAL(changed()));
877         connect(converterModifyPB, SIGNAL(clicked()),
878                 this, SIGNAL(changed()));
879         connect(maxAgeLE, SIGNAL(textChanged(const QString&)),
880                 this, SIGNAL(changed()));
881
882         maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
883         converterDefGB->setFocusProxy(convertersLW);
884 }
885
886
887 void PrefConverters::apply(LyXRC & rc) const
888 {
889         rc.use_converter_cache = cacheCB->isChecked();
890         rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
891 }
892
893
894 void PrefConverters::update(LyXRC const & rc)
895 {
896         cacheCB->setChecked(rc.use_converter_cache);
897         QString max_age;
898         max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
899         maxAgeLE->setText(max_age);
900         updateGui();
901 }
902
903
904 void PrefConverters::updateGui()
905 {
906         // save current selection
907         QString current = converterFromCO->currentText()
908                 + " -> " + converterToCO->currentText();
909
910         converterFromCO->clear();
911         converterToCO->clear();
912
913         Formats::const_iterator cit = form_->formats().begin();
914         Formats::const_iterator end = form_->formats().end();
915         for (; cit != end; ++cit) {
916                 converterFromCO->addItem(toqstr(cit->prettyname()));
917                 converterToCO->addItem(toqstr(cit->prettyname()));
918         }
919
920         // currentRowChanged(int) is also triggered when updating the listwidget
921         // block signals to avoid unnecessary calls to switch_converter()
922         convertersLW->blockSignals(true);
923         convertersLW->clear();
924
925         Converters::const_iterator ccit = form_->converters().begin();
926         Converters::const_iterator cend = form_->converters().end();
927         for (; ccit != cend; ++ccit) {
928                 std::string const name =
929                         ccit->From->prettyname() + " -> " + ccit->To->prettyname();
930                 int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
931                 new QListWidgetItem(toqstr(name), convertersLW, type);
932         }
933         convertersLW->sortItems(Qt::AscendingOrder);
934         convertersLW->blockSignals(false);
935
936         // restore selection
937         if (!current.isEmpty()) {
938                 QList<QListWidgetItem *> const item =
939                         convertersLW->findItems(current, Qt::MatchExactly);
940                 if (item.size()>0)
941                         convertersLW->setCurrentItem(item.at(0));
942         }
943
944         // select first element if restoring failed
945         if (convertersLW->currentRow() == -1)
946                 convertersLW->setCurrentRow(0);
947
948         updateButtons();
949 }
950
951
952 void PrefConverters::switch_converter()
953 {
954         int const cnr = convertersLW->currentItem()->type();
955         Converter const & c(form_->converters().get(cnr));
956         converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
957         converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
958         converterED->setText(toqstr(c.command));
959         converterFlagED->setText(toqstr(c.flags));
960
961         updateButtons();
962 }
963
964
965 void PrefConverters::converter_changed()
966 {
967         updateButtons();
968 }
969
970
971 void PrefConverters::updateButtons()
972 {
973         Format const & from(form_->formats().get(converterFromCO->currentIndex()));
974         Format const & to(form_->formats().get(converterToCO->currentIndex()));
975         int const sel = form_->converters().getNumber(from.name(), to.name());
976         bool const known = !(sel < 0);
977         bool const valid = !(converterED->text().isEmpty()
978                 || from.name() == to.name());
979
980         int const cnr = convertersLW->currentItem()->type();
981         Converter const & c(form_->converters().get(cnr));
982         string const old_command = c.command;
983         string const old_flag = c.flags;
984         string const new_command(fromqstr(converterED->text()));
985         string const new_flag(fromqstr(converterFlagED->text()));
986
987         bool modified = ((old_command != new_command) || (old_flag != new_flag));
988
989         converterModifyPB->setEnabled(valid && known && modified);
990         converterNewPB->setEnabled(valid && !known);
991         converterRemovePB->setEnabled(known);
992
993         maxAgeLE->setEnabled(cacheCB->isChecked());
994         maxAgeLA->setEnabled(cacheCB->isChecked());
995 }
996
997
998 // FIXME: user must
999 // specify unique from/to or it doesn't appear. This is really bad UI
1000 // this is why we can use the same function for both new and modify
1001 void PrefConverters::update_converter()
1002 {
1003         Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1004         Format const & to(form_->formats().get(converterToCO->currentIndex()));
1005         string const flags = fromqstr(converterFlagED->text());
1006         string const command = fromqstr(converterED->text());
1007
1008         Converter const * old = form_->converters().getConverter(from.name(), to.name());
1009         form_->converters().add(from.name(), to.name(), command, flags);
1010         if (!old) {
1011                 form_->converters().updateLast(form_->formats());
1012         }
1013
1014         updateGui();
1015 }
1016
1017
1018 void PrefConverters::remove_converter()
1019 {
1020         Format const & from(form_->formats().get(converterFromCO->currentIndex()));
1021         Format const & to(form_->formats().get(converterToCO->currentIndex()));
1022         form_->converters().erase(from.name(), to.name());
1023
1024         updateGui();
1025 }
1026
1027
1028 void PrefConverters::on_cacheCB_stateChanged(int state)
1029 {
1030         maxAgeLE->setEnabled(state == Qt::Checked);
1031         maxAgeLA->setEnabled(state == Qt::Checked);
1032         changed();
1033 }
1034
1035
1036 PrefCopiers::PrefCopiers(QPrefs * form, QWidget * parent)
1037 : PrefModule(docstring(), _("Copiers"), form, parent)
1038 {
1039         setupUi(this);
1040
1041         connect(copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
1042         connect(copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
1043         connect(copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
1044         connect(AllCopiersLW, SIGNAL(currentRowChanged(int)),
1045                 this, SLOT(switch_copierLB(int)));
1046         connect(copierFormatCO, SIGNAL(activated(int)), this, SLOT(switch_copierCO(int)));
1047         connect(copierNewPB, SIGNAL(clicked()),
1048                 this, SIGNAL(changed()));
1049         connect(copierRemovePB, SIGNAL(clicked()),
1050                 this, SIGNAL(changed()));
1051         connect(copierModifyPB, SIGNAL(clicked()),
1052                 this, SIGNAL(changed()));
1053         connect(copierFormatCO, SIGNAL(activated(const QString&)), this, SLOT(copiers_changed()));
1054         connect(copierED, SIGNAL(textChanged(const QString&)), this, SLOT(copiers_changed()));
1055 }
1056
1057
1058 void PrefCopiers::apply(LyXRC & /*rc*/) const
1059 {
1060 }
1061
1062
1063 void PrefCopiers::update(LyXRC const & /*rc*/)
1064 {
1065         update();
1066 }
1067
1068
1069 void PrefCopiers::update()
1070 {
1071         // The choice widget
1072         // save current selection
1073         QString current = copierFormatCO->currentText();
1074         copierFormatCO->clear();
1075
1076         for (Formats::const_iterator it = form_->formats().begin(),
1077                      end = form_->formats().end();
1078              it != end; ++it) {
1079                 copierFormatCO->addItem(toqstr(it->prettyname()));
1080         }
1081
1082         // The browser widget
1083         AllCopiersLW->clear();
1084
1085         for (Movers::const_iterator it = form_->movers().begin(),
1086                      end = form_->movers().end();
1087              it != end; ++it) {
1088                 std::string const & command = it->second.command();
1089                 if (command.empty())
1090                         continue;
1091                 QString const pretty = toqstr(form_->formats().prettyName(it->first));
1092                 AllCopiersLW->addItem(pretty);
1093         }
1094         AllCopiersLW->sortItems(Qt::AscendingOrder);
1095
1096         // restore selection
1097         if (!current.isEmpty()) {
1098                 QList<QListWidgetItem *> item =
1099                         AllCopiersLW->findItems(current, Qt::MatchExactly);
1100                 if (item.size()>0)
1101                         AllCopiersLW->setCurrentItem(item.at(0));
1102         }
1103         // select first element if restoring failed
1104         if (AllCopiersLW->currentRow() == -1)
1105                 AllCopiersLW->setCurrentRow(0);
1106 }
1107
1108
1109 namespace {
1110
1111 class SamePrettyName {
1112 public:
1113         SamePrettyName(string const & n) : pretty_name_(n) {}
1114
1115         bool operator()(lyx::Format const & fmt) const {
1116                 return fmt.prettyname() == pretty_name_;
1117         }
1118
1119 private:
1120         string const pretty_name_;
1121 };
1122
1123
1124 Format const * getFormat(std::string const & prettyname)
1125 {
1126         Formats::const_iterator it = lyx::formats.begin();
1127         Formats::const_iterator const end = lyx::formats.end();
1128         it = std::find_if(it, end, SamePrettyName(prettyname));
1129         return it == end ? 0 : &*it;
1130 }
1131
1132 } // namespace anon
1133
1134
1135 void PrefCopiers::switch_copierLB(int row)
1136 {
1137         if (row < 0)
1138                 return;
1139
1140         // FIXME UNICODE?
1141         std::string const browser_text =
1142                 fromqstr(AllCopiersLW->currentItem()->text());
1143         Format const * fmt = getFormat(browser_text);
1144         if (fmt == 0)
1145                 return;
1146
1147         QString const gui_name = toqstr(fmt->prettyname());
1148         QString const command = toqstr(form_->movers().command(fmt->name()));
1149
1150         copierED->clear();
1151         int const combo_size = copierFormatCO->count();
1152         for (int i = 0; i < combo_size; ++i) {
1153                 QString const text = copierFormatCO->itemText(i);
1154                 if (text == gui_name) {
1155                         copierFormatCO->setCurrentIndex(i);
1156                         copierED->setText(command);
1157                         break;
1158                 }
1159         }
1160         updateButtons();
1161 }
1162
1163
1164 void PrefCopiers::switch_copierCO(int row)
1165 {
1166         if (row<0)
1167                 return;
1168
1169         std::string const combo_text =
1170                 fromqstr(copierFormatCO->currentText());
1171         Format const * fmt = getFormat(combo_text);
1172         if (fmt == 0)
1173                 return;
1174
1175         QString const command = toqstr(form_->movers().command(fmt->name()));
1176         copierED->setText(command);
1177
1178         QListWidgetItem * const index = AllCopiersLW->currentItem();
1179         if (index >= 0)
1180                 AllCopiersLW->setItemSelected(index, false);
1181
1182         QString const gui_name = toqstr(fmt->prettyname());
1183         int const browser_size = AllCopiersLW->count();
1184         for (int i = 0; i < browser_size; ++i) {
1185                 QString const text = AllCopiersLW->item(i)->text();
1186                 if (text == gui_name) {
1187                         QListWidgetItem * item = AllCopiersLW->item(i);
1188                         AllCopiersLW->setItemSelected(item, true);
1189                         break;
1190                 }
1191         }
1192 }
1193
1194
1195 void PrefCopiers::copiers_changed()
1196 {
1197         updateButtons();
1198 }
1199
1200
1201 void PrefCopiers::updateButtons()
1202 {
1203         QString selected = copierFormatCO->currentText();
1204
1205         bool known = false;
1206         for (int i = 0; i < AllCopiersLW->count(); ++i) {
1207                 if (AllCopiersLW->item(i)->text() == selected)
1208                         known = true;
1209         }
1210
1211         bool const valid = !copierED->text().isEmpty();
1212
1213         Format const * fmt = getFormat(fromqstr(selected));
1214         string const old_command = form_->movers().command(fmt->name());
1215         string const new_command(fromqstr(copierED->text()));
1216
1217         bool modified = (old_command != new_command);
1218
1219         copierModifyPB->setEnabled(valid && known && modified);
1220         copierNewPB->setEnabled(valid && !known);
1221         copierRemovePB->setEnabled(known);
1222 }
1223
1224
1225 void PrefCopiers::new_copier()
1226 {
1227         std::string const combo_text =
1228                 fromqstr(copierFormatCO->currentText());
1229         Format const * fmt = getFormat(combo_text);
1230         if (fmt == 0)
1231                 return;
1232
1233         string const command = fromqstr(copierED->text());
1234         if (command.empty())
1235                 return;
1236
1237         form_->movers().set(fmt->name(), command);
1238
1239         update();
1240         int const last = AllCopiersLW->count() - 1;
1241         AllCopiersLW->setCurrentRow(last);
1242
1243         updateButtons();
1244 }
1245
1246
1247 void PrefCopiers::modify_copier()
1248 {
1249         std::string const combo_text =
1250                 fromqstr(copierFormatCO->currentText());
1251         Format const * fmt = getFormat(combo_text);
1252         if (fmt == 0)
1253                 return;
1254
1255         string const command = fromqstr(copierED->text());
1256         form_->movers().set(fmt->name(), command);
1257
1258         update();
1259         updateButtons();
1260 }
1261
1262
1263 void PrefCopiers::remove_copier()
1264 {
1265         std::string const combo_text =
1266                 fromqstr(copierFormatCO->currentText());
1267         Format const * fmt = getFormat(combo_text);
1268         if (fmt == 0)
1269                 return;
1270
1271         string const & fmt_name = fmt->name();
1272         form_->movers().set(fmt_name, string());
1273
1274         update();
1275         updateButtons();
1276 }
1277
1278
1279
1280 PrefFileformats::PrefFileformats(QPrefs * form, QWidget * parent)
1281 : PrefModule(docstring(), _("File formats"), form, parent)
1282 {
1283         setupUi(this);
1284
1285         connect(formatNewPB, SIGNAL(clicked()),
1286                 this, SLOT(new_format()));
1287         connect(formatRemovePB, SIGNAL(clicked()),
1288                 this, SLOT(remove_format()));
1289         connect(formatModifyPB, SIGNAL(clicked()),
1290                 this, SLOT(modify_format()));
1291         connect(formatsLW, SIGNAL(currentRowChanged(int)),
1292                 this, SLOT(switch_format(int)));
1293         connect(formatED, SIGNAL(textChanged(const QString&)),
1294                 this, SLOT(fileformat_changed()));
1295         connect(guiNameED, SIGNAL(textChanged(const QString&)),
1296                 this, SLOT(fileformat_changed()));
1297         connect(shortcutED, SIGNAL(textChanged(const QString&)),
1298                 this, SLOT(fileformat_changed()));
1299         connect(extensionED, SIGNAL(textChanged(const QString&)),
1300                 this, SLOT(fileformat_changed()));
1301         connect(viewerED, SIGNAL(textChanged(const QString&)),
1302                 this, SLOT(fileformat_changed()));
1303         connect(editorED, SIGNAL(textChanged(const QString&)),
1304                 this, SLOT(fileformat_changed()));
1305         connect(documentCB, SIGNAL(clicked()),
1306                 this, SLOT(fileformat_changed()));
1307         connect(vectorCB, SIGNAL(clicked()),
1308                 this, SLOT(fileformat_changed()));
1309         connect(formatNewPB, SIGNAL(clicked()),
1310                 this, SIGNAL(changed()));
1311         connect(formatRemovePB, SIGNAL(clicked()),
1312                 this, SIGNAL(changed()));
1313         connect(formatModifyPB, SIGNAL(clicked()),
1314                 this, SIGNAL(changed()));
1315 }
1316
1317
1318 void PrefFileformats::apply(LyXRC & /*rc*/) const
1319 {
1320 }
1321
1322
1323 void PrefFileformats::update(LyXRC const & /*rc*/)
1324 {
1325         update();
1326 }
1327
1328
1329 void PrefFileformats::update()
1330 {
1331         // save current selection
1332         QString current = guiNameED->text();
1333
1334         // update listwidget with formats
1335         formatsLW->blockSignals(true);
1336         formatsLW->clear();
1337         Formats::const_iterator cit = form_->formats().begin();
1338         Formats::const_iterator end = form_->formats().end();
1339         for (; cit != end; ++cit) {
1340                 new QListWidgetItem(toqstr(cit->prettyname()),
1341                                                         formatsLW,
1342                                                         form_->formats().getNumber(cit->name()) );
1343         }
1344         formatsLW->sortItems(Qt::AscendingOrder);
1345         formatsLW->blockSignals(false);
1346
1347         // restore selection
1348         if (!current.isEmpty()) {
1349                 QList<QListWidgetItem *>  item = formatsLW->findItems(current, Qt::MatchExactly);
1350                 if (item.size()>0)
1351                         formatsLW->setCurrentItem(item.at(0));
1352         }
1353         // select first element if restoring failed
1354         if (formatsLW->currentRow() == -1)
1355                 formatsLW->setCurrentRow(0);
1356 }
1357
1358
1359 void PrefFileformats::switch_format(int nr)
1360 {
1361         int const ftype = formatsLW->item(nr)->type();
1362         Format const f = form_->formats().get(ftype);
1363
1364         formatED->setText(toqstr(f.name()));
1365         guiNameED->setText(toqstr(f.prettyname()));
1366         extensionED->setText(toqstr(f.extension()));
1367         shortcutED->setText(toqstr(f.shortcut()));
1368         viewerED->setText(toqstr(f.viewer()));
1369         editorED->setText(toqstr(f.editor()));
1370         documentCB->setChecked((f.documentFormat()));
1371         vectorCB->setChecked((f.vectorFormat()));
1372
1373         updateButtons();
1374 }
1375
1376
1377 void PrefFileformats::fileformat_changed()
1378 {
1379         updateButtons();
1380 }
1381
1382
1383 void PrefFileformats::updateButtons()
1384 {
1385         QString const format = formatED->text();
1386         QString const gui_name = guiNameED->text();
1387         int const sel = form_->formats().getNumber(fromqstr(format));
1388         bool gui_name_known = false;
1389         int where = sel;
1390         for (int i = 0; i < formatsLW->count(); ++i) {
1391                 if (formatsLW->item(i)->text() == gui_name) {
1392                         gui_name_known = true;
1393                         where = formatsLW->item(i)->type();
1394                 }
1395         }
1396
1397         // assure that a gui name cannot be chosen twice
1398         bool const known_otherwise = gui_name_known && (where != sel);
1399
1400         bool const known = !(sel < 0);
1401         bool const valid = (!formatED->text().isEmpty()
1402                 && !guiNameED->text().isEmpty());
1403
1404         int const ftype = formatsLW->currentItem()->type();
1405         Format const & f(form_->formats().get(ftype));
1406         string const old_pretty(f.prettyname());
1407         string const old_shortcut(f.shortcut());
1408         string const old_extension(f.extension());
1409         string const old_viewer(f.viewer());
1410         string const old_editor(f.editor());
1411         bool const old_document(f.documentFormat());
1412         bool const old_vector(f.vectorFormat());
1413
1414         string const new_pretty(fromqstr(gui_name));
1415         string const new_shortcut(fromqstr(shortcutED->text()));
1416         string const new_extension(fromqstr(extensionED->text()));
1417         string const new_viewer(fromqstr(viewerED->text()));
1418         string const new_editor(fromqstr(editorED->text()));
1419         bool const new_document(documentCB->isChecked());
1420         bool const new_vector(vectorCB->isChecked());
1421
1422         bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
1423                 || (old_extension != new_extension) || (old_viewer != new_viewer)
1424                 || old_editor != new_editor || old_document != new_document
1425                 || old_vector != new_vector);
1426
1427         formatModifyPB->setEnabled(valid && known && modified && !known_otherwise);
1428         formatNewPB->setEnabled(valid && !known && !gui_name_known);
1429         formatRemovePB->setEnabled(known);
1430 }
1431
1432
1433 void PrefFileformats::new_format()
1434 {
1435         string const name = fromqstr(formatED->text());
1436         string const prettyname = fromqstr(guiNameED->text());
1437         string const extension = fromqstr(extensionED->text());
1438         string const shortcut = fromqstr(shortcutED->text());
1439         string const viewer = fromqstr(viewerED->text());
1440         string const editor = fromqstr(editorED->text());
1441         int flags = Format::none;
1442         if (documentCB->isChecked())
1443                 flags |= Format::document;
1444         if (vectorCB->isChecked())
1445                 flags |= Format::vector;
1446
1447         form_->formats().add(name, extension, prettyname, shortcut, viewer,
1448                              editor, flags);
1449         form_->formats().sort();
1450         form_->converters().update(form_->formats());
1451
1452         update();
1453         updateButtons();
1454         formatsChanged();
1455 }
1456
1457
1458 void PrefFileformats::modify_format()
1459 {
1460         int const current_item = formatsLW->currentItem()->type();
1461         Format const & oldformat = form_->formats().get(current_item);
1462         form_->formats().erase(oldformat.name());
1463
1464         new_format();
1465 }
1466
1467
1468 void PrefFileformats::remove_format()
1469 {
1470         int const nr = formatsLW->currentItem()->type();
1471         string const current_text = form_->formats().get(nr).name();
1472         if (form_->converters().formatIsUsed(current_text)) {
1473                 Alert::error(_("Format in use"),
1474                              _("Cannot remove a Format used by a Converter. "
1475                                             "Remove the converter first."));
1476                 return;
1477         }
1478
1479         form_->formats().erase(current_text);
1480         form_->converters().update(form_->formats());
1481
1482         update();
1483         updateButtons();
1484         formatsChanged();
1485 }
1486
1487
1488
1489 PrefLanguage::PrefLanguage(QWidget * parent)
1490 : PrefModule(_(LanguageSettings), _("Language"), 0, parent)
1491 {
1492         setupUi(this);
1493
1494         connect(rtlCB, SIGNAL(clicked()),
1495                 this, SIGNAL(changed()));
1496         connect(markForeignCB, SIGNAL(clicked()),
1497                 this, SIGNAL(changed()));
1498         connect(autoBeginCB, SIGNAL(clicked()),
1499                 this, SIGNAL(changed()));
1500         connect(autoEndCB, SIGNAL(clicked()),
1501                 this, SIGNAL(changed()));
1502         connect(useBabelCB, SIGNAL(clicked()),
1503                 this, SIGNAL(changed()));
1504         connect(globalCB, SIGNAL(clicked()),
1505                 this, SIGNAL(changed()));
1506         connect(languagePackageED, SIGNAL(textChanged(const QString&)),
1507                 this, SIGNAL(changed()));
1508         connect(startCommandED, SIGNAL(textChanged(const QString&)),
1509                 this, SIGNAL(changed()));
1510         connect(endCommandED, SIGNAL(textChanged(const QString&)),
1511                 this, SIGNAL(changed()));
1512         connect(defaultLanguageCO, SIGNAL(activated(int)),
1513                 this, SIGNAL(changed()));
1514
1515         defaultLanguageCO->clear();
1516
1517         // store the lang identifiers for later
1518         std::vector<LanguagePair> const langs =
1519                 lyx::frontend::getLanguageData(false);
1520         lang_ = getSecond(langs);
1521
1522         std::vector<LanguagePair>::const_iterator lit  = langs.begin();
1523         std::vector<LanguagePair>::const_iterator lend = langs.end();
1524         for (; lit != lend; ++lit) {
1525                 defaultLanguageCO->addItem(toqstr(lit->first));
1526         }
1527 }
1528
1529
1530 void PrefLanguage::apply(LyXRC & rc) const
1531 {
1532         // FIXME: remove rtl_support bool
1533         rc.rtl_support = rtlCB->isChecked();
1534         rc.mark_foreign_language = markForeignCB->isChecked();
1535         rc.language_auto_begin = autoBeginCB->isChecked();
1536         rc.language_auto_end = autoEndCB->isChecked();
1537         rc.language_use_babel = useBabelCB->isChecked();
1538         rc.language_global_options = globalCB->isChecked();
1539         rc.language_package = fromqstr(languagePackageED->text());
1540         rc.language_command_begin = fromqstr(startCommandED->text());
1541         rc.language_command_end = fromqstr(endCommandED->text());
1542         rc.default_language = lang_[defaultLanguageCO->currentIndex()];
1543 }
1544
1545
1546 void PrefLanguage::update(LyXRC const & rc)
1547 {
1548         // FIXME: remove rtl_support bool
1549         rtlCB->setChecked(rc.rtl_support);
1550         markForeignCB->setChecked(rc.mark_foreign_language);
1551         autoBeginCB->setChecked(rc.language_auto_begin);
1552         autoEndCB->setChecked(rc.language_auto_end);
1553         useBabelCB->setChecked(rc.language_use_babel);
1554         globalCB->setChecked(rc.language_global_options);
1555         languagePackageED->setText(toqstr(rc.language_package));
1556         startCommandED->setText(toqstr(rc.language_command_begin));
1557         endCommandED->setText(toqstr(rc.language_command_end));
1558
1559         int const pos = int(findPos_helper(lang_, rc.default_language));
1560         defaultLanguageCO->setCurrentIndex(pos);
1561 }
1562
1563
1564 PrefPrinter::PrefPrinter(QWidget * parent)
1565 : PrefModule(_(Outputs), _("Printer"), 0, parent)
1566 {
1567         setupUi(this);
1568
1569         connect(printerAdaptCB, SIGNAL(clicked()),
1570                 this, SIGNAL(changed()));
1571         connect(printerCommandED, SIGNAL(textChanged(const QString&)),
1572                 this, SIGNAL(changed()));
1573         connect(printerNameED, SIGNAL(textChanged(const QString&)),
1574                 this, SIGNAL(changed()));
1575         connect(printerPageRangeED, SIGNAL(textChanged(const QString&)),
1576                 this, SIGNAL(changed()));
1577         connect(printerCopiesED, SIGNAL(textChanged(const QString&)),
1578                 this, SIGNAL(changed()));
1579         connect(printerReverseED, SIGNAL(textChanged(const QString&)),
1580                 this, SIGNAL(changed()));
1581         connect(printerToPrinterED, SIGNAL(textChanged(const QString&)),
1582                 this, SIGNAL(changed()));
1583         connect(printerExtensionED, SIGNAL(textChanged(const QString&)),
1584                 this, SIGNAL(changed()));
1585         connect(printerSpoolCommandED, SIGNAL(textChanged(const QString&)),
1586                 this, SIGNAL(changed()));
1587         connect(printerPaperTypeED, SIGNAL(textChanged(const QString&)),
1588                 this, SIGNAL(changed()));
1589         connect(printerEvenED, SIGNAL(textChanged(const QString&)),
1590                 this, SIGNAL(changed()));
1591         connect(printerOddED, SIGNAL(textChanged(const QString&)),
1592                 this, SIGNAL(changed()));
1593         connect(printerCollatedED, SIGNAL(textChanged(const QString&)),
1594                 this, SIGNAL(changed()));
1595         connect(printerLandscapeED, SIGNAL(textChanged(const QString&)),
1596                 this, SIGNAL(changed()));
1597         connect(printerToFileED, SIGNAL(textChanged(const QString&)),
1598                 this, SIGNAL(changed()));
1599         connect(printerExtraED, SIGNAL(textChanged(const QString&)),
1600                 this, SIGNAL(changed()));
1601         connect(printerSpoolPrefixED, SIGNAL(textChanged(const QString&)),
1602                 this, SIGNAL(changed()));
1603         connect(printerPaperSizeED, SIGNAL(textChanged(const QString&)),
1604                 this, SIGNAL(changed()));
1605 }
1606
1607
1608 void PrefPrinter::apply(LyXRC & rc) const
1609 {
1610         rc.print_adapt_output = printerAdaptCB->isChecked();
1611         rc.print_command = fromqstr(printerCommandED->text());
1612         rc.printer = fromqstr(printerNameED->text());
1613
1614         rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
1615         rc.print_copies_flag = fromqstr(printerCopiesED->text());
1616         rc.print_reverse_flag = fromqstr(printerReverseED->text());
1617         rc.print_to_printer = fromqstr(printerToPrinterED->text());
1618         rc.print_file_extension = fromqstr(printerExtensionED->text());
1619         rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
1620         rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
1621         rc.print_evenpage_flag = fromqstr(printerEvenED->text());
1622         rc.print_oddpage_flag = fromqstr(printerOddED->text());
1623         rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
1624         rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
1625         rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
1626         rc.print_extra_options = fromqstr(printerExtraED->text());
1627         rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
1628         rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
1629 }
1630
1631
1632 void PrefPrinter::update(LyXRC const & rc)
1633 {
1634         printerAdaptCB->setChecked(rc.print_adapt_output);
1635         printerCommandED->setText(toqstr(rc.print_command));
1636         printerNameED->setText(toqstr(rc.printer));
1637
1638         printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
1639         printerCopiesED->setText(toqstr(rc.print_copies_flag));
1640         printerReverseED->setText(toqstr(rc.print_reverse_flag));
1641         printerToPrinterED->setText(toqstr(rc.print_to_printer));
1642         printerExtensionED->setText(toqstr(rc.print_file_extension));
1643         printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
1644         printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
1645         printerEvenED->setText(toqstr(rc.print_evenpage_flag));
1646         printerOddED->setText(toqstr(rc.print_oddpage_flag));
1647         printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
1648         printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
1649         printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
1650         printerExtraED->setText(toqstr(rc.print_extra_options));
1651         printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
1652         printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
1653 }
1654
1655
1656 PrefUserInterface::PrefUserInterface(QPrefs * form, QWidget * parent)
1657 : PrefModule(_(LookAndFeel), _("User interface"), form, parent)
1658 {
1659         setupUi(this);
1660
1661         connect(autoSaveCB, SIGNAL( toggled(bool) ), autoSaveLA, SLOT( setEnabled(bool) ) );
1662         connect(autoSaveCB, SIGNAL( toggled(bool) ), autoSaveSB, SLOT( setEnabled(bool) ) );
1663         connect(autoSaveCB, SIGNAL( toggled(bool) ), TextLabel1, SLOT( setEnabled(bool) ) );
1664         connect(uiFilePB, SIGNAL(clicked()), this, SLOT(select_ui()));
1665         connect(bindFilePB, SIGNAL(clicked()), this, SLOT(select_bind()));
1666         connect(uiFileED, SIGNAL(textChanged(const QString&)),
1667                 this, SIGNAL(changed()));
1668         connect(bindFileED, SIGNAL(textChanged(const QString&)),
1669                 this, SIGNAL(changed()));
1670         connect(restoreCursorCB, SIGNAL(clicked()),
1671                 this, SIGNAL(changed()));
1672         connect(loadSessionCB, SIGNAL(clicked()),
1673                 this, SIGNAL(changed()));
1674         connect(loadWindowSizeCB, SIGNAL(clicked()),
1675                 this, SIGNAL(changed()));
1676         connect(loadWindowLocationCB, SIGNAL(clicked()),
1677                 this, SIGNAL(changed()));
1678         connect(windowWidthSB, SIGNAL(valueChanged(int)),
1679                 this, SIGNAL(changed()));
1680         connect(windowHeightSB, SIGNAL(valueChanged(int)),
1681                 this, SIGNAL(changed()));
1682         connect(cursorFollowsCB, SIGNAL(clicked()),
1683                 this, SIGNAL(changed()));
1684         connect(autoSaveSB, SIGNAL(valueChanged(int)),
1685                 this, SIGNAL(changed()));
1686         connect(autoSaveCB, SIGNAL(clicked()),
1687                 this, SIGNAL(changed()));
1688         connect(lastfilesSB, SIGNAL(valueChanged(int)),
1689                 this, SIGNAL(changed()));
1690         lastfilesSB->setMaximum(maxlastfiles);
1691 }
1692
1693
1694 void PrefUserInterface::apply(LyXRC & rc) const
1695 {
1696         rc.ui_file = internal_path(fromqstr(uiFileED->text()));
1697         rc.bind_file = internal_path(fromqstr(bindFileED->text()));
1698         rc.use_lastfilepos = restoreCursorCB->isChecked();
1699         rc.load_session = loadSessionCB->isChecked();
1700         if (loadWindowSizeCB->isChecked()) {
1701                 rc.geometry_width = 0;
1702                 rc.geometry_height = 0;
1703         } else {
1704                 rc.geometry_width = windowWidthSB->value();
1705                 rc.geometry_height = windowHeightSB->value();
1706         }
1707         rc.geometry_xysaved = loadWindowLocationCB->isChecked();
1708         rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
1709         rc.autosave = autoSaveSB->value() * 60;
1710         rc.make_backup = autoSaveCB->isChecked();
1711         rc.num_lastfiles = lastfilesSB->value();
1712 }
1713
1714
1715 void PrefUserInterface::update(LyXRC const & rc)
1716 {
1717         uiFileED->setText(toqstr(external_path(rc.ui_file)));
1718         bindFileED->setText(toqstr(external_path(rc.bind_file)));
1719         restoreCursorCB->setChecked(rc.use_lastfilepos);
1720         loadSessionCB->setChecked(rc.load_session);
1721         bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
1722         loadWindowSizeCB->setChecked(loadWindowSize);
1723         if (!loadWindowSize) {
1724                 windowWidthSB->setValue(rc.geometry_width);
1725                 windowHeightSB->setValue(rc.geometry_height);
1726         }
1727         loadWindowLocationCB->setChecked(rc.geometry_xysaved);
1728         cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
1729         // convert to minutes
1730         int mins(rc.autosave / 60);
1731         if (rc.autosave && !mins)
1732                 mins = 1;
1733         autoSaveSB->setValue(mins);
1734         autoSaveCB->setChecked(rc.make_backup);
1735         lastfilesSB->setValue(rc.num_lastfiles);
1736 }
1737
1738
1739
1740 void PrefUserInterface::select_ui()
1741 {
1742         docstring const name =
1743                 from_utf8(internal_path(fromqstr(uiFileED->text())));
1744         docstring file(form_->controller().browseUI(name));
1745         if (!file.empty())
1746                 uiFileED->setText(toqstr(file));
1747 }
1748
1749
1750 void PrefUserInterface::select_bind()
1751 {
1752         docstring const name =
1753                 from_utf8(internal_path(fromqstr(bindFileED->text())));
1754         docstring file(form_->controller().browsebind(name));
1755         if (!file.empty())
1756                 bindFileED->setText(toqstr(file));
1757 }
1758
1759
1760 void PrefUserInterface::on_loadWindowSizeCB_toggled(bool loadwindowsize)
1761 {
1762         windowWidthLA->setDisabled(loadwindowsize);
1763         windowHeightLA->setDisabled(loadwindowsize);
1764         windowWidthSB->setDisabled(loadwindowsize);
1765         windowHeightSB->setDisabled(loadwindowsize);
1766 }
1767
1768
1769 PrefIdentity::PrefIdentity(QWidget * parent)
1770 : PrefModule(docstring(), _("Identity"), 0, parent)
1771 {
1772         setupUi(this);
1773
1774         connect(nameED, SIGNAL(textChanged(const QString&)),
1775                 this, SIGNAL(changed()));
1776         connect(emailED, SIGNAL(textChanged(const QString&)),
1777                 this, SIGNAL(changed()));
1778 }
1779
1780
1781 void PrefIdentity::apply(LyXRC & rc) const
1782 {
1783         rc.user_name = fromqstr(nameED->text());
1784         rc.user_email = fromqstr(emailED->text());
1785 }
1786
1787
1788 void PrefIdentity::update(LyXRC const & rc)
1789 {
1790         nameED->setText(toqstr(rc.user_name));
1791         emailED->setText(toqstr(rc.user_email));
1792 }
1793
1794
1795
1796 QPrefsDialog::QPrefsDialog(QPrefs * form)
1797         : form_(form)
1798 {
1799         setupUi(this);
1800         QDialog::setModal(false);
1801
1802         connect(savePB, SIGNAL(clicked()),
1803                 form, SLOT(slotOK()));
1804         connect(applyPB, SIGNAL(clicked()),
1805                 form, SLOT(slotApply()));
1806         connect(closePB, SIGNAL(clicked()),
1807                 form, SLOT(slotClose()));
1808         connect(restorePB, SIGNAL(clicked()),
1809                 form, SLOT(slotRestore()));
1810
1811         add(new PrefUserInterface(form_));
1812         add(new PrefScreenFonts(form_));
1813         add(new PrefColors(form_));
1814         add(new PrefDisplay);
1815         add(new PrefKeyboard(form_));
1816
1817         add(new PrefPaths(form_));
1818
1819         add(new PrefIdentity);
1820
1821         add(new PrefLanguage);
1822         add(new PrefSpellchecker(form_));
1823
1824         add(new PrefPrinter);
1825         add(new PrefDate);
1826         add(new PrefPlaintext);
1827         add(new PrefLatex(form_));
1828
1829 #if defined(__CYGWIN__) || defined(_WIN32)
1830         add(new PrefCygwinPath);
1831 #endif
1832
1833
1834         PrefConverters * converters = new PrefConverters(form_);
1835         PrefFileformats * formats = new PrefFileformats(form_);
1836         connect(formats, SIGNAL(formatsChanged()),
1837                         converters, SLOT(updateGui()));
1838         add(converters);
1839         add(formats);
1840
1841         add(new PrefCopiers(form_));
1842
1843
1844         prefsPS->setCurrentPanel(_("User interface"));
1845 // FIXME: hack to work around resizing bug in Qt >= 4.2
1846 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1847 #if QT_VERSION >= 0x040200
1848         prefsPS->updateGeometry();
1849 #endif
1850
1851         form_->bcview().setOK(savePB);
1852         form_->bcview().setApply(applyPB);
1853         form_->bcview().setCancel(closePB);
1854         form_->bcview().setRestore(restorePB);
1855 }
1856
1857
1858 QPrefsDialog::~QPrefsDialog()
1859 {
1860 }
1861
1862
1863 void QPrefsDialog::add(PrefModule * module)
1864 {
1865         BOOST_ASSERT(module);
1866
1867 //      if (module->category().empty())
1868 //              prefsPS->addPanel(module, module->title());
1869 //      else
1870                 prefsPS->addPanel(module, module->title(), module->category());
1871
1872         connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
1873
1874         modules_.push_back(module);
1875 }
1876
1877 void QPrefsDialog::closeEvent(QCloseEvent * e)
1878 {
1879         form_->slotWMHide();
1880         e->accept();
1881 }
1882
1883
1884 void QPrefsDialog::change_adaptor()
1885 {
1886         form_->changed();
1887 }
1888
1889
1890 void QPrefsDialog::apply(LyXRC & rc) const
1891 {
1892         size_t end = modules_.size();
1893         for (size_t i = 0; i != end; ++i)
1894                 modules_[i]->apply(rc);
1895 }
1896
1897
1898 void QPrefsDialog::updateRc(LyXRC const & rc)
1899 {
1900         size_t end = modules_.size();
1901         for (size_t i = 0; i != end; ++i)
1902                 modules_[i]->update(rc);
1903 }
1904
1905
1906 } // namespace frontend
1907 } // namespace lyx
1908
1909 #include "QPrefsDialog_moc.cpp"