]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiCharacter.cpp
Fix completion in math when inline completion was not yet shown
[lyx.git] / src / frontends / qt / GuiCharacter.cpp
1 /**
2  * \file GuiCharacter.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  * \author Edwin Leuven
8  * \author John Levon
9  * \author Jürgen Spitzmüller
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "GuiCharacter.h"
17
18 #include "GuiApplication.h"
19 #include "qt_helpers.h"
20
21 #include "Buffer.h"
22 #include "BufferParams.h"
23 #include "BufferView.h"
24 #include "Color.h"
25 #include "ColorCache.h"
26 #include "ColorSet.h"
27 #include "Cursor.h"
28 #include "FuncRequest.h"
29 #include "Language.h"
30 #include "Paragraph.h"
31
32 #include "support/gettext.h"
33
34 #include <QAbstractItemModel>
35 #include <QPushButton>
36 #include <QComboBox>
37 #include <QMenu>
38 #include <QModelIndex>
39 #include <QSettings>
40 #include <QVariant>
41
42 using namespace std;
43
44 namespace lyx {
45 namespace frontend {
46
47 static QList<ShapePair> shapeData()
48 {
49         QList<ShapePair> shapes;
50         shapes << ShapePair(qt_("No change"), IGNORE_SHAPE);
51         shapes << ShapePair(qt_("Default"), INHERIT_SHAPE);
52         shapes << ShapePair(qt_("Upright"), UP_SHAPE);
53         shapes << ShapePair(qt_("Italic"), ITALIC_SHAPE);
54         shapes << ShapePair(qt_("Slanted"), SLANTED_SHAPE);
55         shapes << ShapePair(qt_("Small Caps"), SMALLCAPS_SHAPE);
56         return shapes;
57 }
58
59
60 static QList<SizePair> sizeData()
61 {
62         QList<SizePair> sizes;
63         sizes << SizePair(qt_("No change"), IGNORE_SIZE);
64         sizes << SizePair(qt_("Default"), INHERIT_SIZE);
65         sizes << SizePair(qt_("Tiny"), TINY_SIZE);
66         sizes << SizePair(qt_("Smallest"), SCRIPT_SIZE);
67         sizes << SizePair(qt_("Smaller"), FOOTNOTE_SIZE);
68         sizes << SizePair(qt_("Small"), SMALL_SIZE);
69         sizes << SizePair(qt_("Normal"), NORMAL_SIZE);
70         sizes << SizePair(qt_("Large"), LARGE_SIZE);
71         sizes << SizePair(qt_("Larger"), LARGER_SIZE);
72         sizes << SizePair(qt_("Largest"), LARGEST_SIZE);
73         sizes << SizePair(qt_("Huge"), HUGE_SIZE);
74         sizes << SizePair(qt_("Huger"), HUGER_SIZE);
75         sizes << SizePair(qt_("Increase"), INCREASE_SIZE);
76         sizes << SizePair(qt_("Decrease"), DECREASE_SIZE);
77         return sizes;
78 }
79
80
81 static QList<BarPair> barData()
82 {
83         QList<BarPair> bars;
84         bars << BarPair(qt_("No change"), IGNORE);
85         bars << BarPair(qt_("Default"), INHERIT);
86         bars << BarPair(qt_("(Without)[[underlining]]"), NONE);
87         bars << BarPair(qt_("Single[[underlining]]"), UNDERBAR);
88         bars << BarPair(qt_("Double[[underlining]]"), UULINE);
89         bars << BarPair(qt_("Wavy"), UWAVE);
90         return bars;
91 }
92
93
94 static QList<BarPair> strikeData()
95 {
96         QList<BarPair> strike;
97         strike << BarPair(qt_("No change"), IGNORE);
98         strike << BarPair(qt_("Default"), INHERIT);
99         strike << BarPair(qt_("(Without)[[strikethrough]]"), NONE);
100         strike << BarPair(qt_("Single[[strikethrough]]"), STRIKEOUT);
101         strike << BarPair(qt_("With /"), XOUT);
102         return strike;
103 }
104
105
106 static QList<ColorCode> colorData()
107 {
108         QList<ColorCode> colors;
109         colors << Color_black;
110         colors << Color_blue;
111         colors << Color_brown;
112         colors << Color_cyan;
113         colors << Color_darkgray;
114         colors << Color_gray;
115         colors << Color_green;
116         colors << Color_lightgray;
117         colors << Color_lime;
118         colors << Color_magenta;
119         colors << Color_olive;
120         colors << Color_orange;
121         colors << Color_pink;
122         colors << Color_purple;
123         colors << Color_red;
124         colors << Color_teal;
125         colors << Color_violet;
126         colors << Color_white;
127         colors << Color_yellow;
128         return colors;
129 }
130
131
132 static QList<SeriesPair> seriesData()
133 {
134         QList<SeriesPair> series;
135         series << SeriesPair(qt_("No change"), IGNORE_SERIES);
136         series << SeriesPair(qt_("Default"),     INHERIT_SERIES);
137         series << SeriesPair(qt_("Medium"),    MEDIUM_SERIES);
138         series << SeriesPair(qt_("Bold"),      BOLD_SERIES);
139         return series;
140 }
141
142
143 static QList<FamilyPair> familyData()
144 {
145         QList<FamilyPair> families;
146         families << FamilyPair(qt_("No change"),  IGNORE_FAMILY);
147         families << FamilyPair(qt_("Default"),      INHERIT_FAMILY);
148         families << FamilyPair(qt_("Roman"),      ROMAN_FAMILY);
149         families << FamilyPair(qt_("Sans Serif"), SANS_FAMILY);
150         families << FamilyPair(qt_("Typewriter"), TYPEWRITER_FAMILY);
151         return families;
152 }
153
154
155 static QList<LanguagePair> languageData()
156 {
157         QList<LanguagePair> list;
158         // FIXME (Abdel 14/05/2008): it would be nice if we could use this model
159         // directly in the language combo; but, as we need also the 'No Change' and
160         // 'Default' items, this is not possible right now. Separating those two
161         // entries in radio buttons would be a better GUI IMHO.
162         QAbstractItemModel * language_model = guiApp->languageModel();
163         // Make sure the items are sorted.
164         language_model->sort(0);
165
166         for (int i = 0; i != language_model->rowCount(); ++i) {
167                 QModelIndex index = language_model->index(i, 0);
168                 list << LanguagePair(index.data(Qt::DisplayRole).toString(),
169                         index.data(Qt::UserRole).toString());
170         }
171         return list;
172 }
173
174
175 namespace {
176
177 template<typename T>
178 void fillCombo(QComboBox * combo, QList<T> const & list)
179 {
180         typename QList<T>::const_iterator cit = list.begin();
181         for (; cit != list.end(); ++cit)
182                 combo->addItem(cit->first);
183 }
184
185 template<typename T>
186 void fillComboColor(QComboBox * combo, QList<T> const & list)
187 {
188         // at first add the 2 colors "No change" and "No color"
189         combo->addItem(qt_("No change"), "ignore");
190         combo->addItem(qt_("Default"), "inherit");
191         combo->addItem(qt_("(Without)[[color]]"), "none");
192         // now add the real colors
193         QPixmap coloritem(32, 32);
194         QColor color;
195         QList<ColorCode>::const_iterator cit = list.begin();
196         for (; cit != list.end(); ++cit) {
197                 QString const lyxname = toqstr(lcolor.getLyXName(*cit));
198                 QString const guiname = toqstr(translateIfPossible(lcolor.getGUIName(*cit)));
199                 color = QColor(guiApp->colorCache().get(*cit, false));
200                 coloritem.fill(color);
201                 combo->addItem(QIcon(coloritem), guiname, lyxname);
202         }
203 }
204
205 } // namespace
206
207 GuiCharacter::GuiCharacter(GuiView & lv)
208         : GuiDialog(lv, "character", qt_("Text Properties")),
209           font_(ignore_font, ignore_language),
210           emph_(false), noun_(false), nospellcheck_(false)
211 {
212         setupUi(this);
213
214         // fix height to minimum
215         setFixedHeight(sizeHint().height());
216
217         connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
218                 this, SLOT(slotButtonBox(QAbstractButton *)));
219         connect(autoapplyCB, SIGNAL(stateChanged(int)), this,
220                 SLOT(slotAutoApply()));
221
222         connect(ulineCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
223         connect(strikeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
224         connect(sizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
225         connect(familyCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
226         connect(seriesCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
227         connect(shapeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
228         connect(colorCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
229         connect(langCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
230
231         family = familyData();
232         series = seriesData();
233         shape  = shapeData();
234         size   = sizeData();
235         bar    = barData();
236         strike = strikeData();
237         color  = colorData();
238         sort(color.begin(), color.end(), ColorSorter);
239
240         language = languageData();
241         language.prepend(LanguagePair(qt_("Default"), "reset"));
242         language.prepend(LanguagePair(qt_("No change"), "ignore"));
243
244         fillCombo(familyCO, family);
245         fillCombo(seriesCO, series);
246         fillCombo(sizeCO, size);
247         fillCombo(shapeCO, shape);
248         fillCombo(ulineCO, bar);
249         fillCombo(strikeCO, strike);
250         fillComboColor(colorCO, color);
251         fillCombo(langCO, language);
252
253         bc().setPolicy(ButtonPolicy::OkApplyCancelAutoReadOnlyPolicy);
254         bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
255         bc().setApply(buttonBox->button(QDialogButtonBox::Apply));
256         bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
257         bc().setRestore(buttonBox->button(QDialogButtonBox::Reset));
258         bc().setAutoApply(autoapplyCB);
259         bc().addReadOnly(familyCO);
260         bc().addReadOnly(seriesCO);
261         bc().addReadOnly(sizeCO);
262         bc().addReadOnly(shapeCO);
263         bc().addReadOnly(ulineCO);
264         bc().addReadOnly(strikeCO);
265         bc().addReadOnly(nounCB);
266         bc().addReadOnly(emphCB);
267         bc().addReadOnly(nospellcheckCB);
268         bc().addReadOnly(langCO);
269         bc().addReadOnly(colorCO);
270         bc().addReadOnly(autoapplyCB);
271
272         // Add button menu to restore button to reset
273         // all widgets to "Defaults" or "No Change"
274         resetdefault_ = new QAction(qt_("Reset All To &Default"), this);
275         resetnochange_ = new QAction(qt_("Reset All To No Chan&ge"), this);
276         QMenu * resetmenu = new QMenu();
277         resetmenu->addAction(resetdefault_);
278         resetmenu->addAction(resetnochange_);
279         buttonBox->button(QDialogButtonBox::RestoreDefaults)->setMenu(resetmenu);
280         buttonBox->button(QDialogButtonBox::RestoreDefaults)->setText(qt_("&Reset All Fields"));
281         connect(resetdefault_, SIGNAL(triggered()), this, SLOT(resetToDefault()));
282         connect(resetnochange_, SIGNAL(triggered()), this, SLOT(resetToNoChange()));
283
284 #ifdef Q_OS_MAC
285         // On Mac it's common to have tool windows which are always in the
286         // foreground and are hidden when the main window is not focused.
287         setWindowFlags(Qt::Tool);
288         autoapplyCB->setChecked(true);
289 #endif
290 }
291
292
293 void GuiCharacter::on_emphCB_clicked()
294 {
295         // skip intermediate state at user click
296         if (!emph_) {
297                 emphCB->setCheckState(Qt::Checked);
298                 emph_ = true;
299         }
300         change_adaptor();
301 }
302
303
304 void GuiCharacter::on_nounCB_clicked()
305 {
306         // skip intermediate state at user click
307         if (!noun_) {
308                 nounCB->setCheckState(Qt::Checked);
309                 noun_ = true;
310         }
311         change_adaptor();
312 }
313
314
315 void GuiCharacter::on_nospellcheckCB_clicked()
316 {
317         // skip intermediate state at user click
318         if (!nospellcheck_) {
319                 nospellcheckCB->setCheckState(Qt::Checked);
320                 nospellcheck_ = true;
321         }
322         change_adaptor();
323 }
324
325
326 void GuiCharacter::resetToDefault()
327 {
328         Font font(inherit_font);
329         font.setLanguage(reset_language);
330         paramsToDialog(font);
331         change_adaptor();
332 }
333
334
335 void GuiCharacter::resetToNoChange()
336 {
337         Font font(ignore_font);
338         font.setLanguage(ignore_language);
339         paramsToDialog(font);
340         change_adaptor();
341 }
342
343
344 template<class P, class B>
345 static int findPos2nd(QList<P> const & vec, B const & val)
346 {
347         for (int i = 0; i != vec.size(); ++i)
348                 if (vec[i].second == val)
349                         return i;
350         return 0;
351 }
352
353
354 namespace{
355 FontDeco getBar(FontInfo const & fi)
356 {
357         if (fi.underbar() == FONT_ON)
358                 return UNDERBAR;
359
360         if (fi.uuline() == FONT_ON)
361                 return UULINE;
362
363         if (fi.uwave() == FONT_ON)
364                 return UWAVE;
365
366         if (fi.underbar() == FONT_IGNORE)
367                 return IGNORE;
368
369         if (fi.underbar() == FONT_INHERIT)
370                 return INHERIT;
371
372         return NONE;
373 }
374
375
376 FontDeco getStrike(FontInfo const & fi)
377 {
378         if (fi.strikeout() == FONT_ON)
379                 return STRIKEOUT;
380
381         if (fi.xout() == FONT_ON)
382                 return XOUT;
383
384         if (fi.strikeout() == FONT_IGNORE)
385                 return IGNORE;
386
387         if (fi.strikeout() == FONT_INHERIT)
388                 return INHERIT;
389
390         return NONE;
391 }
392
393
394 Qt::CheckState getMarkupState(lyx::FontState fs)
395 {
396         switch (fs) {
397         case FONT_INHERIT:
398         case FONT_OFF:
399                 return Qt::Unchecked;
400         case FONT_ON:
401                 return Qt::Checked;
402         case FONT_TOGGLE:
403         case FONT_IGNORE:
404         default:
405                 return Qt::PartiallyChecked;
406         }
407 }
408
409 lyx::FontState setMarkupState(Qt::CheckState cs)
410 {
411         switch (cs) {
412         case Qt::Unchecked:
413                 return FONT_OFF;
414         case Qt::Checked:
415                 return FONT_ON;
416         case Qt::PartiallyChecked:
417         default:
418                 return FONT_IGNORE;
419         }
420 }
421
422 } // end namespace anon
423
424
425 void GuiCharacter::change_adaptor()
426 {
427         changed();
428
429         checkRestoreDefaults();
430
431         if (!autoapplyCB->isChecked())
432                 return;
433
434         // to be really good here, we should set the combos to the values of
435         // the current text, and make it appear as "no change" if the values
436         // stay the same between applies. Might be difficult though wrt to a
437         // moved cursor - jbl
438         slotApply();
439 }
440
441
442 void GuiCharacter::checkRestoreDefaults()
443 {
444         if (familyCO->currentIndex() == -1 || seriesCO->currentIndex() == -1
445             || shapeCO->currentIndex() == -1 || sizeCO->currentIndex() == -1
446             || ulineCO->currentIndex() == -1 || strikeCO->currentIndex() == -1
447             || colorCO->currentIndex() == -1 || langCO->currentIndex() == -1)
448                 // dialog not yet built
449                 return;
450
451         // (De)Activate Restore Defaults menu items
452         resetdefault_->setEnabled(
453                 family[familyCO->currentIndex()].second != INHERIT_FAMILY
454                 || series[seriesCO->currentIndex()].second != INHERIT_SERIES
455                 || shape[shapeCO->currentIndex()].second != INHERIT_SHAPE
456                 || size[sizeCO->currentIndex()].second != INHERIT_SIZE
457                 || setMarkupState(emphCB->checkState()) != FONT_OFF
458                 || setMarkupState(nounCB->checkState()) != FONT_OFF
459                 || setMarkupState(nospellcheckCB->checkState()) != FONT_OFF
460                 || bar[ulineCO->currentIndex()].second != INHERIT
461                 || strike[strikeCO->currentIndex()].second != INHERIT
462                 || lcolor.getFromLyXName(fromqstr(colorCO->itemData(colorCO->currentIndex()).toString())) != Color_inherit
463                 || languages.getLanguage(fromqstr(language[langCO->currentIndex()].second)) != reset_language);
464
465         resetnochange_->setEnabled(
466                 family[familyCO->currentIndex()].second != IGNORE_FAMILY
467                 || series[seriesCO->currentIndex()].second != IGNORE_SERIES
468                 || shape[shapeCO->currentIndex()].second != IGNORE_SHAPE
469                 || size[sizeCO->currentIndex()].second != IGNORE_SIZE
470                 || setMarkupState(emphCB->checkState()) != FONT_IGNORE
471                 || setMarkupState(nounCB->checkState()) != FONT_IGNORE
472                 || setMarkupState(nospellcheckCB->checkState()) != FONT_IGNORE
473                 || bar[ulineCO->currentIndex()].second != IGNORE
474                 || strike[strikeCO->currentIndex()].second != IGNORE
475                 || lcolor.getFromLyXName(fromqstr(colorCO->itemData(colorCO->currentIndex()).toString())) != Color_ignore
476                 || languages.getLanguage(fromqstr(language[langCO->currentIndex()].second)) != ignore_language);
477 }
478
479
480 void GuiCharacter::updateContents()
481 {
482         if (bufferview()->cursor().selection()) {
483                 Font font = bufferview()->cursor().current_font;
484                 FontInfo fi = font.fontInfo();
485                 BufferParams const & bp = buffer().masterParams();
486
487                 // Check if each font attribute is constant for the selection range.
488                 DocIterator const from = bufferview()->cursor().selectionBegin();
489                 DocIterator const to = bufferview()->cursor().selectionEnd();
490                 for (DocIterator dit = from ; dit != to && !dit.atEnd(); ) {
491                         if (!dit.inTexted()) {
492                                 dit.forwardPos();
493                                 continue;
494                         }
495                         Paragraph const & par = dit.paragraph();
496                         pos_type const pos = dit.pos();
497                         Font tmp = par.getFontSettings(bp, pos);
498                         if (font.language() != tmp.language())
499                                 font.setLanguage(ignore_language);
500                         if (fi.family() != tmp.fontInfo().family())
501                                 font.fontInfo().setFamily(IGNORE_FAMILY);
502                         if (fi.series() != tmp.fontInfo().series())
503                                 font.fontInfo().setSeries(IGNORE_SERIES);
504                         if (fi.shape() != tmp.fontInfo().shape())
505                                 font.fontInfo().setShape(IGNORE_SHAPE);
506                         if (fi.size() != tmp.fontInfo().size())
507                                 font.fontInfo().setSize(IGNORE_SIZE);
508                         if (fi.emph() != tmp.fontInfo().emph())
509                                 font.fontInfo().setEmph(FONT_IGNORE);
510                         if (fi.noun() != tmp.fontInfo().noun())
511                                 font.fontInfo().setNoun(FONT_IGNORE);
512                         if (fi.nospellcheck() != tmp.fontInfo().nospellcheck())
513                                 font.fontInfo().setNoSpellcheck(FONT_IGNORE);
514                         if (fi.color() != tmp.fontInfo().color())
515                                 font.fontInfo().setColor(Color_ignore);
516                         if (fi.underbar() != tmp.fontInfo().underbar()
517                             || fi.uuline() != tmp.fontInfo().uuline()
518                             || fi.uwave() != tmp.fontInfo().uwave())
519                                 setBar(font.fontInfo(), IGNORE);
520                         if (fi.strikeout() != tmp.fontInfo().strikeout()
521                             || fi.xout() != tmp.fontInfo().xout())
522                                 setStrike(font.fontInfo(), IGNORE);
523                         dit.forwardPos();
524                 }
525                 font_ = font;
526         } else
527                 font_ = bufferview()->cursor().current_font;
528
529         // If we use the buffer language, display "Default"
530         if (font_.language() == buffer().params().language)
531                 font_.setLanguage(reset_language);
532
533         paramsToDialog(font_);
534
535         checkRestoreDefaults();
536 }
537
538
539 void GuiCharacter::setBar(FontInfo & fi, FontDeco val)
540 {
541         switch (val) {
542         case IGNORE:
543                 fi.setUnderbar(FONT_IGNORE);
544                 fi.setUuline(FONT_IGNORE);
545                 fi.setUwave(FONT_IGNORE);
546                 break;
547         case UNDERBAR:
548                 setBar(fi, NONE);
549                 fi.setUnderbar(FONT_ON);
550                 break;
551         case UULINE:
552                 setBar(fi, NONE);
553                 fi.setUuline(FONT_ON);
554                 break;
555         case UWAVE:
556                 setBar(fi, NONE);
557                 fi.setUwave(FONT_ON);
558                 break;
559         case INHERIT:
560                 fi.setUnderbar(FONT_INHERIT);
561                 fi.setUuline(FONT_INHERIT);
562                 fi.setUwave(FONT_INHERIT);
563                 break;
564         case NONE:
565                 fi.setUnderbar(FONT_OFF);
566                 fi.setUuline(FONT_OFF);
567                 fi.setUwave(FONT_OFF);
568                 break;
569         case XOUT:
570         case STRIKEOUT:
571         default:
572                 break;
573         }
574 }
575
576
577 void GuiCharacter::setStrike(FontInfo & fi, FontDeco val)
578 {
579         switch (val) {
580         case IGNORE:
581                 fi.setStrikeout(FONT_IGNORE);
582                 fi.setXout(FONT_IGNORE);
583                 break;
584         case STRIKEOUT:
585                 setStrike(fi, NONE);
586                 fi.setStrikeout(FONT_ON);
587                 break;
588         case XOUT:
589                 setStrike(fi, NONE);
590                 fi.setXout(FONT_ON);
591                 break;
592         case INHERIT:
593                 fi.setStrikeout(FONT_INHERIT);
594                 fi.setXout(FONT_INHERIT);
595                 break;
596         case NONE:
597                 fi.setStrikeout(FONT_OFF);
598                 fi.setXout(FONT_OFF);
599                 break;
600         case UNDERBAR:
601         case UWAVE:
602         case UULINE:
603         default:
604                 break;
605         }
606 }
607
608
609 void GuiCharacter::paramsToDialog(Font const & font)
610 {
611         FontInfo const & fi = font.fontInfo();
612         familyCO->setCurrentIndex(findPos2nd(family, fi.family()));
613         seriesCO->setCurrentIndex(findPos2nd(series, fi.series()));
614         shapeCO->setCurrentIndex(findPos2nd(shape, fi.shape()));
615         sizeCO->setCurrentIndex(findPos2nd(size, fi.size()));
616         ulineCO->setCurrentIndex(findPos2nd(bar, getBar(fi)));
617         strikeCO->setCurrentIndex(findPos2nd(strike, getStrike(fi)));
618         colorCO->setCurrentIndex(colorCO->findData(toqstr(lcolor.getLyXName(fi.color()))));
619         emphCB->setCheckState(getMarkupState(fi.emph()));
620         nounCB->setCheckState(getMarkupState(fi.noun()));
621         nospellcheckCB->setCheckState(getMarkupState(fi.nospellcheck()));
622         emph_ = emphCB->checkState() == Qt::Checked;
623         noun_ = nounCB->checkState() == Qt::Checked;
624         nospellcheck_ = nospellcheckCB->checkState() == Qt::Checked;
625
626         // reset_language is a null pointer.
627         QString const lang = (font.language() == reset_language)
628                 ? "reset" : toqstr(font.language()->lang());
629         langCO->setCurrentIndex(findPos2nd(language, lang));
630 }
631
632
633 void GuiCharacter::applyView()
634 {
635         FontInfo & fi = font_.fontInfo();
636         fi.setFamily(family[familyCO->currentIndex()].second);
637         fi.setSeries(series[seriesCO->currentIndex()].second);
638         fi.setShape(shape[shapeCO->currentIndex()].second);
639         fi.setSize(size[sizeCO->currentIndex()].second);
640         fi.setEmph(setMarkupState(emphCB->checkState()));
641         fi.setNoun(setMarkupState(nounCB->checkState()));
642         fi.setNoSpellcheck(setMarkupState(nospellcheckCB->checkState()));
643         setBar(fi, bar[ulineCO->currentIndex()].second);
644         setStrike(fi, strike[strikeCO->currentIndex()].second);
645         fi.setColor(lcolor.getFromLyXName(fromqstr(colorCO->itemData(colorCO->currentIndex()).toString())));
646
647         font_.setLanguage(languages.getLanguage(
648                 fromqstr(language[langCO->currentIndex()].second)));
649 }
650
651
652 bool GuiCharacter::initialiseParams(string const &)
653 {
654         if (autoapplyCB->isChecked())
655                 return true;
656
657         FontInfo & fi = font_.fontInfo();
658
659         // so that the user can press Ok
660         if (fi.family()    != IGNORE_FAMILY
661             || fi.series() != IGNORE_SERIES
662             || fi.shape()  != IGNORE_SHAPE
663             || fi.size()   != IGNORE_SIZE
664             || getBar(fi)  != IGNORE
665             || fi.color()  != Color_ignore
666             || font_.language() != ignore_language)
667                 setButtonsValid(true);
668
669         paramsToDialog(font_);
670         // Make sure that the bc is in the INITIAL state
671         if (bc().policy().buttonStatus(ButtonPolicy::OKAY))
672                 bc().restore();
673         return true;
674 }
675
676
677 void GuiCharacter::dispatchParams()
678 {
679         dispatch(FuncRequest(getLfun(), font_.toString(false)));
680 }
681
682
683 void GuiCharacter::saveSession(QSettings & settings) const
684 {
685         Dialog::saveSession(settings);
686         settings.setValue(sessionKey() + "/autoapply", autoapplyCB->isChecked());
687 }
688
689
690 void GuiCharacter::restoreSession()
691 {
692         Dialog::restoreSession();
693         QSettings settings;
694         autoapplyCB->setChecked(
695                 settings.value(sessionKey() + "/autoapply").toBool());
696 }
697
698
699 } // namespace frontend
700 } // namespace lyx
701
702 #include "moc_GuiCharacter.cpp"