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