2 * \file GuiCharacter.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS.
15 #include "GuiCharacter.h"
17 #include "qt_helpers.h"
20 #include "BufferParams.h"
21 #include "FuncRequest.h"
24 #include <QCloseEvent>
31 static vector<ShapePair> const getShapeData()
33 vector<ShapePair> shape(6);
37 pr.first = qt_("No change");
38 pr.second = IGNORE_SHAPE;
41 pr.first = qt_("Upright");
45 pr.first = qt_("Italic");
46 pr.second = ITALIC_SHAPE;
49 pr.first = qt_("Slanted");
50 pr.second = SLANTED_SHAPE;
53 pr.first = qt_("Small Caps");
54 pr.second = SMALLCAPS_SHAPE;
57 pr.first = qt_("Reset");
58 pr.second = INHERIT_SHAPE;
65 static vector<SizePair> const getSizeData()
67 vector<SizePair> size(14);
71 pr.first = qt_("No change");
72 pr.second = FONT_SIZE_IGNORE;
75 pr.first = qt_("Tiny");
76 pr.second = FONT_SIZE_TINY;
79 pr.first = qt_("Smallest");
80 pr.second = FONT_SIZE_SCRIPT;
83 pr.first = qt_("Smaller");
84 pr.second = FONT_SIZE_FOOTNOTE;
87 pr.first = qt_("Small");
88 pr.second = FONT_SIZE_SMALL;
91 pr.first = qt_("Normal");
92 pr.second = FONT_SIZE_NORMAL;
95 pr.first = qt_("Large");
96 pr.second = FONT_SIZE_LARGE;
99 pr.first = qt_("Larger");
100 pr.second = FONT_SIZE_LARGER;
103 pr.first = qt_("Largest");
104 pr.second = FONT_SIZE_LARGEST;
107 pr.first = qt_("Huge");
108 pr.second = FONT_SIZE_HUGE;
111 pr.first = qt_("Huger");
112 pr.second = FONT_SIZE_HUGER;
115 pr.first = qt_("Increase");
116 pr.second = FONT_SIZE_INCREASE;
119 pr.first = qt_("Decrease");
120 pr.second = FONT_SIZE_DECREASE;
123 pr.first = qt_("Reset");
124 pr.second = FONT_SIZE_INHERIT;
131 static vector<BarPair> const getBarData()
133 vector<BarPair> bar(5);
137 pr.first = qt_("No change");
141 pr.first = qt_("Emph");
142 pr.second = EMPH_TOGGLE;
145 pr.first = qt_("Underbar");
146 pr.second = UNDERBAR_TOGGLE;
149 pr.first = qt_("Noun");
150 pr.second = NOUN_TOGGLE;
153 pr.first = qt_("Reset");
161 static vector<ColorPair> const getColorData()
163 vector<ColorPair> color(11);
167 pr.first = qt_("No change");
168 pr.second = Color_ignore;
171 pr.first = qt_("No color");
172 pr.second = Color_none;
175 pr.first = qt_("Black");
176 pr.second = Color_black;
179 pr.first = qt_("White");
180 pr.second = Color_white;
183 pr.first = qt_("Red");
184 pr.second = Color_red;
187 pr.first = qt_("Green");
188 pr.second = Color_green;
191 pr.first = qt_("Blue");
192 pr.second = Color_blue;
195 pr.first = qt_("Cyan");
196 pr.second = Color_cyan;
199 pr.first = qt_("Magenta");
200 pr.second = Color_magenta;
203 pr.first = qt_("Yellow");
204 pr.second = Color_yellow;
207 pr.first = qt_("Reset");
208 pr.second = Color_inherit;
215 static vector<SeriesPair> const getSeriesData()
217 vector<SeriesPair> series(4);
221 pr.first = qt_("No change");
222 pr.second = IGNORE_SERIES;
225 pr.first = qt_("Medium");
226 pr.second = MEDIUM_SERIES;
229 pr.first = qt_("Bold");
230 pr.second = BOLD_SERIES;
233 pr.first = qt_("Reset");
234 pr.second = INHERIT_SERIES;
241 static vector<FamilyPair> const getFamilyData()
243 vector<FamilyPair> family(5);
247 pr.first = qt_("No change");
248 pr.second = IGNORE_FAMILY;
251 pr.first = qt_("Roman");
252 pr.second = ROMAN_FAMILY;
255 pr.first = qt_("Sans Serif");
256 pr.second = SANS_FAMILY;
259 pr.first = qt_("Typewriter");
260 pr.second = TYPEWRITER_FAMILY;
263 pr.first = qt_("Reset");
264 pr.second = INHERIT_FAMILY;
271 GuiCharacter::GuiCharacter(GuiView & lv)
272 : GuiDialog(lv, "character"), font_(ignore_font),
273 toggleall_(false), reset_lang_(false)
276 setViewTitle(_("Text Style"));
278 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
279 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
280 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
282 connect(miscCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
283 connect(sizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
284 connect(familyCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
285 connect(seriesCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
286 connect(shapeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
287 connect(colorCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
288 connect(langCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
289 connect(toggleallCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
291 family = getFamilyData();
292 series = getSeriesData();
293 shape = getShapeData();
294 size = getSizeData();
296 color = getColorData();
297 language = getLanguageData(true);
299 for (vector<FamilyPair>::const_iterator cit = family.begin();
300 cit != family.end(); ++cit) {
301 familyCO->addItem(cit->first);
304 for (vector<SeriesPair>::const_iterator cit = series.begin();
305 cit != series.end(); ++cit) {
306 seriesCO->addItem(cit->first);
308 for (vector<ShapePair>::const_iterator cit = shape.begin();
309 cit != shape.end(); ++cit) {
310 shapeCO->addItem(cit->first);
312 for (vector<SizePair>::const_iterator cit = size.begin();
313 cit != size.end(); ++cit) {
314 sizeCO->addItem(cit->first);
316 for (vector<BarPair>::const_iterator cit = bar.begin();
317 cit != bar.end(); ++cit) {
318 miscCO->addItem(cit->first);
320 for (vector<ColorPair>::const_iterator cit = color.begin();
321 cit != color.end(); ++cit) {
322 colorCO->addItem(cit->first);
324 for (vector<LanguagePair>::const_iterator cit = language.begin();
325 cit != language.end(); ++cit) {
326 langCO->addItem(toqstr(cit->first));
329 bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
331 bc().setApply(applyPB);
332 bc().setCancel(closePB);
333 bc().addReadOnly(familyCO);
334 bc().addReadOnly(seriesCO);
335 bc().addReadOnly(sizeCO);
336 bc().addReadOnly(shapeCO);
337 bc().addReadOnly(miscCO);
338 bc().addReadOnly(langCO);
339 bc().addReadOnly(colorCO);
340 bc().addReadOnly(toggleallCB);
341 bc().addReadOnly(autoapplyCB);
343 // FIXME: hack to work around resizing bug in Qt >= 4.2
344 // bug verified with Qt 4.2.{0-3} (JSpitzm)
345 #if QT_VERSION >= 0x040200
346 // qt resizes the comboboxes only after show(), so ...
352 void GuiCharacter::change_adaptor()
356 if (!autoapplyCB->isChecked())
359 // to be really good here, we should set the combos to the values of
360 // the current text, and make it appear as "no change" if the values
361 // stay the same between applys. Might be difficult though wrt to a
362 // moved cursor - jbl
364 familyCO->setCurrentIndex(0);
365 seriesCO->setCurrentIndex(0);
366 sizeCO->setCurrentIndex(0);
367 shapeCO->setCurrentIndex(0);
368 miscCO->setCurrentIndex(0);
369 langCO->setCurrentIndex(0);
370 colorCO->setCurrentIndex(0);
374 void GuiCharacter::closeEvent(QCloseEvent * e)
377 GuiDialog::closeEvent(e);
381 template<class A, class B>
382 static int findPos2nd(vector<pair<A, B> > const & vec, B const & val)
384 typedef typename vector<pair<A, B> >::const_iterator
387 for (const_iterator cit = vec.begin(); cit != vec.end(); ++cit)
388 if (cit->second == val)
389 return int(cit - vec.begin());
395 void GuiCharacter::updateContents()
397 familyCO->setCurrentIndex(findPos2nd(family, getFamily()));
398 seriesCO->setCurrentIndex(findPos2nd(series, getSeries()));
399 shapeCO->setCurrentIndex(findPos2nd(shape, getShape()));
400 sizeCO->setCurrentIndex(findPos2nd(size, getSize()));
401 miscCO->setCurrentIndex(findPos2nd(bar, getBar()));
402 colorCO->setCurrentIndex(findPos2nd(color, getColor()));
403 langCO->setCurrentIndex(findPos2nd(language, getLanguage()));
405 toggleallCB->setChecked(toggleall_);
409 void GuiCharacter::applyView()
411 setFamily(family[familyCO->currentIndex()].second);
412 setSeries(series[seriesCO->currentIndex()].second);
413 setShape(shape[shapeCO->currentIndex()].second);
414 setSize(size[sizeCO->currentIndex()].second);
415 setBar(bar[miscCO->currentIndex()].second);
416 setColor(color[colorCO->currentIndex()].second);
417 setLanguage(language[langCO->currentIndex()].second);
419 toggleall_ = toggleallCB->isChecked();
423 bool GuiCharacter::initialiseParams(string const &)
425 // so that the user can press Ok
426 if (getFamily() != IGNORE_FAMILY
427 || getSeries() != IGNORE_SERIES
428 || getShape() != IGNORE_SHAPE
429 || getSize() != FONT_SIZE_IGNORE
430 || getBar() != IGNORE
431 || getColor() != Color_ignore
432 || font_.language() != ignore_language)
433 setButtonsValid(true);
439 void GuiCharacter::dispatchParams()
441 dispatch(FuncRequest(getLfun(), font_.toString(toggleall_)));
445 FontFamily GuiCharacter::getFamily() const
447 return font_.fontInfo().family();
451 void GuiCharacter::setFamily(FontFamily val)
453 font_.fontInfo().setFamily(val);
457 FontSeries GuiCharacter::getSeries() const
459 return font_.fontInfo().series();
463 void GuiCharacter::setSeries(FontSeries val)
465 font_.fontInfo().setSeries(val);
469 FontShape GuiCharacter::getShape() const
471 return font_.fontInfo().shape();
475 void GuiCharacter::setShape(FontShape val)
477 font_.fontInfo().setShape(val);
481 FontSize GuiCharacter::getSize() const
483 return font_.fontInfo().size();
487 void GuiCharacter::setSize(FontSize val)
489 font_.fontInfo().setSize(val);
493 FontState GuiCharacter::getBar() const
495 if (font_.fontInfo().emph() == FONT_TOGGLE)
498 if (font_.fontInfo().underbar() == FONT_TOGGLE)
499 return UNDERBAR_TOGGLE;
501 if (font_.fontInfo().noun() == FONT_TOGGLE)
504 if (font_.fontInfo().emph() == FONT_IGNORE
505 && font_.fontInfo().underbar() == FONT_IGNORE
506 && font_.fontInfo().noun() == FONT_IGNORE)
513 void GuiCharacter::setBar(FontState val)
517 font_.fontInfo().setEmph(FONT_IGNORE);
518 font_.fontInfo().setUnderbar(FONT_IGNORE);
519 font_.fontInfo().setNoun(FONT_IGNORE);
523 font_.fontInfo().setEmph(FONT_TOGGLE);
526 case UNDERBAR_TOGGLE:
527 font_.fontInfo().setUnderbar(FONT_TOGGLE);
531 font_.fontInfo().setNoun(FONT_TOGGLE);
535 font_.fontInfo().setEmph(FONT_INHERIT);
536 font_.fontInfo().setUnderbar(FONT_INHERIT);
537 font_.fontInfo().setNoun(FONT_INHERIT);
543 ColorCode GuiCharacter::getColor() const
545 return font_.fontInfo().color();
549 void GuiCharacter::setColor(ColorCode val)
563 font_.fontInfo().setColor(val);
571 string GuiCharacter::getLanguage() const
575 if (font_.language())
576 return font_.language()->lang();
581 void GuiCharacter::setLanguage(string const & val)
584 font_.setLanguage(ignore_language);
585 else if (val == "reset") {
587 // Ignored in getLanguage, but needed for dispatchParams
588 font_.setLanguage(buffer().params().language);
590 font_.setLanguage(languages.getLanguage(val));
595 Dialog * createGuiCharacter(GuiView & lv) { return new GuiCharacter(lv); }
598 } // namespace frontend
601 #include "GuiCharacter_moc.cpp"