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