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