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"
30 static vector<ShapePair> const getShapeData()
32 vector<ShapePair> shape(6);
36 pr.first = qt_("No change");
37 pr.second = IGNORE_SHAPE;
40 pr.first = qt_("Upright");
44 pr.first = qt_("Italic");
45 pr.second = ITALIC_SHAPE;
48 pr.first = qt_("Slanted");
49 pr.second = SLANTED_SHAPE;
52 pr.first = qt_("Small Caps");
53 pr.second = SMALLCAPS_SHAPE;
56 pr.first = qt_("Reset");
57 pr.second = INHERIT_SHAPE;
64 static vector<SizePair> const getSizeData()
66 vector<SizePair> size(14);
70 pr.first = qt_("No change");
71 pr.second = FONT_SIZE_IGNORE;
74 pr.first = qt_("Tiny");
75 pr.second = FONT_SIZE_TINY;
78 pr.first = qt_("Smallest");
79 pr.second = FONT_SIZE_SCRIPT;
82 pr.first = qt_("Smaller");
83 pr.second = FONT_SIZE_FOOTNOTE;
86 pr.first = qt_("Small");
87 pr.second = FONT_SIZE_SMALL;
90 pr.first = qt_("Normal");
91 pr.second = FONT_SIZE_NORMAL;
94 pr.first = qt_("Large");
95 pr.second = FONT_SIZE_LARGE;
98 pr.first = qt_("Larger");
99 pr.second = FONT_SIZE_LARGER;
102 pr.first = qt_("Largest");
103 pr.second = FONT_SIZE_LARGEST;
106 pr.first = qt_("Huge");
107 pr.second = FONT_SIZE_HUGE;
110 pr.first = qt_("Huger");
111 pr.second = FONT_SIZE_HUGER;
114 pr.first = qt_("Increase");
115 pr.second = FONT_SIZE_INCREASE;
118 pr.first = qt_("Decrease");
119 pr.second = FONT_SIZE_DECREASE;
122 pr.first = qt_("Reset");
123 pr.second = FONT_SIZE_INHERIT;
130 static vector<BarPair> const getBarData()
132 vector<BarPair> bar(5);
136 pr.first = qt_("No change");
140 pr.first = qt_("Emph");
141 pr.second = EMPH_TOGGLE;
144 pr.first = qt_("Underbar");
145 pr.second = UNDERBAR_TOGGLE;
148 pr.first = qt_("Noun");
149 pr.second = NOUN_TOGGLE;
152 pr.first = qt_("Reset");
160 static vector<ColorPair> const getColorData()
162 vector<ColorPair> color(11);
166 pr.first = qt_("No change");
167 pr.second = Color_ignore;
170 pr.first = qt_("No color");
171 pr.second = Color_none;
174 pr.first = qt_("Black");
175 pr.second = Color_black;
178 pr.first = qt_("White");
179 pr.second = Color_white;
182 pr.first = qt_("Red");
183 pr.second = Color_red;
186 pr.first = qt_("Green");
187 pr.second = Color_green;
190 pr.first = qt_("Blue");
191 pr.second = Color_blue;
194 pr.first = qt_("Cyan");
195 pr.second = Color_cyan;
198 pr.first = qt_("Magenta");
199 pr.second = Color_magenta;
202 pr.first = qt_("Yellow");
203 pr.second = Color_yellow;
206 pr.first = qt_("Reset");
207 pr.second = Color_inherit;
214 static vector<SeriesPair> const getSeriesData()
216 vector<SeriesPair> series(4);
220 pr.first = qt_("No change");
221 pr.second = IGNORE_SERIES;
224 pr.first = qt_("Medium");
225 pr.second = MEDIUM_SERIES;
228 pr.first = qt_("Bold");
229 pr.second = BOLD_SERIES;
232 pr.first = qt_("Reset");
233 pr.second = INHERIT_SERIES;
240 static vector<FamilyPair> const getFamilyData()
242 vector<FamilyPair> family(5);
246 pr.first = qt_("No change");
247 pr.second = IGNORE_FAMILY;
250 pr.first = qt_("Roman");
251 pr.second = ROMAN_FAMILY;
254 pr.first = qt_("Sans Serif");
255 pr.second = SANS_FAMILY;
258 pr.first = qt_("Typewriter");
259 pr.second = TYPEWRITER_FAMILY;
262 pr.first = qt_("Reset");
263 pr.second = INHERIT_FAMILY;
270 GuiCharacter::GuiCharacter(GuiView & lv)
271 : GuiDialog(lv, "character", qt_("Text Style")), font_(ignore_font),
272 toggleall_(false), reset_lang_(false)
276 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
277 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
278 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
280 connect(miscCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
281 connect(sizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
282 connect(familyCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
283 connect(seriesCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
284 connect(shapeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
285 connect(colorCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
286 connect(langCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
287 connect(toggleallCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
290 // On Mac it's common to have tool windows which are always in the
291 // foreground and are hidden when the main window is not focused.
292 setWindowFlags(Qt::Tool);
293 autoapplyCB->setChecked(true);
296 family = getFamilyData();
297 series = getSeriesData();
298 shape = getShapeData();
299 size = getSizeData();
301 color = getColorData();
302 language = getLanguageData(true);
304 for (vector<FamilyPair>::const_iterator cit = family.begin();
305 cit != family.end(); ++cit) {
306 familyCO->addItem(cit->first);
309 for (vector<SeriesPair>::const_iterator cit = series.begin();
310 cit != series.end(); ++cit) {
311 seriesCO->addItem(cit->first);
313 for (vector<ShapePair>::const_iterator cit = shape.begin();
314 cit != shape.end(); ++cit) {
315 shapeCO->addItem(cit->first);
317 for (vector<SizePair>::const_iterator cit = size.begin();
318 cit != size.end(); ++cit) {
319 sizeCO->addItem(cit->first);
321 for (vector<BarPair>::const_iterator cit = bar.begin();
322 cit != bar.end(); ++cit) {
323 miscCO->addItem(cit->first);
325 for (vector<ColorPair>::const_iterator cit = color.begin();
326 cit != color.end(); ++cit) {
327 colorCO->addItem(cit->first);
329 for (vector<LanguagePair>::const_iterator cit = language.begin();
330 cit != language.end(); ++cit) {
331 langCO->addItem(toqstr(cit->first));
334 bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
336 bc().setApply(applyPB);
337 bc().setCancel(closePB);
338 bc().addReadOnly(familyCO);
339 bc().addReadOnly(seriesCO);
340 bc().addReadOnly(sizeCO);
341 bc().addReadOnly(shapeCO);
342 bc().addReadOnly(miscCO);
343 bc().addReadOnly(langCO);
344 bc().addReadOnly(colorCO);
345 bc().addReadOnly(toggleallCB);
346 bc().addReadOnly(autoapplyCB);
348 // FIXME: hack to work around resizing bug in Qt >= 4.2
349 // bug verified with Qt 4.2.{0-3} (JSpitzm)
350 #if QT_VERSION >= 0x040200
351 // qt resizes the comboboxes only after show(), so ...
357 void GuiCharacter::change_adaptor()
361 if (!autoapplyCB->isChecked())
364 // to be really good here, we should set the combos to the values of
365 // the current text, and make it appear as "no change" if the values
366 // stay the same between applys. Might be difficult though wrt to a
367 // moved cursor - jbl
369 familyCO->setCurrentIndex(0);
370 seriesCO->setCurrentIndex(0);
371 sizeCO->setCurrentIndex(0);
372 shapeCO->setCurrentIndex(0);
373 miscCO->setCurrentIndex(0);
374 langCO->setCurrentIndex(0);
375 colorCO->setCurrentIndex(0);
379 template<class A, class B>
380 static int findPos2nd(vector<pair<A, B> > const & vec, B const & val)
382 typedef typename vector<pair<A, B> >::const_iterator
385 for (const_iterator cit = vec.begin(); cit != vec.end(); ++cit)
386 if (cit->second == val)
387 return int(cit - vec.begin());
393 void GuiCharacter::updateContents()
395 familyCO->setCurrentIndex(findPos2nd(family, getFamily()));
396 seriesCO->setCurrentIndex(findPos2nd(series, getSeries()));
397 shapeCO->setCurrentIndex(findPos2nd(shape, getShape()));
398 sizeCO->setCurrentIndex(findPos2nd(size, getSize()));
399 miscCO->setCurrentIndex(findPos2nd(bar, getBar()));
400 colorCO->setCurrentIndex(findPos2nd(color, getColor()));
401 langCO->setCurrentIndex(findPos2nd(language, getLanguage()));
403 toggleallCB->setChecked(toggleall_);
407 void GuiCharacter::applyView()
409 setFamily(family[familyCO->currentIndex()].second);
410 setSeries(series[seriesCO->currentIndex()].second);
411 setShape(shape[shapeCO->currentIndex()].second);
412 setSize(size[sizeCO->currentIndex()].second);
413 setBar(bar[miscCO->currentIndex()].second);
414 setColor(color[colorCO->currentIndex()].second);
415 setLanguage(language[langCO->currentIndex()].second);
417 toggleall_ = toggleallCB->isChecked();
421 bool GuiCharacter::initialiseParams(string const &)
423 // so that the user can press Ok
424 if (getFamily() != IGNORE_FAMILY
425 || getSeries() != IGNORE_SERIES
426 || getShape() != IGNORE_SHAPE
427 || getSize() != FONT_SIZE_IGNORE
428 || getBar() != IGNORE
429 || getColor() != Color_ignore
430 || font_.language() != ignore_language)
431 setButtonsValid(true);
437 void GuiCharacter::dispatchParams()
439 dispatch(FuncRequest(getLfun(), font_.toString(toggleall_)));
443 FontFamily GuiCharacter::getFamily() const
445 return font_.fontInfo().family();
449 void GuiCharacter::setFamily(FontFamily val)
451 font_.fontInfo().setFamily(val);
455 FontSeries GuiCharacter::getSeries() const
457 return font_.fontInfo().series();
461 void GuiCharacter::setSeries(FontSeries val)
463 font_.fontInfo().setSeries(val);
467 FontShape GuiCharacter::getShape() const
469 return font_.fontInfo().shape();
473 void GuiCharacter::setShape(FontShape val)
475 font_.fontInfo().setShape(val);
479 FontSize GuiCharacter::getSize() const
481 return font_.fontInfo().size();
485 void GuiCharacter::setSize(FontSize val)
487 font_.fontInfo().setSize(val);
491 FontState GuiCharacter::getBar() const
493 if (font_.fontInfo().emph() == FONT_TOGGLE)
496 if (font_.fontInfo().underbar() == FONT_TOGGLE)
497 return UNDERBAR_TOGGLE;
499 if (font_.fontInfo().noun() == FONT_TOGGLE)
502 if (font_.fontInfo().emph() == FONT_IGNORE
503 && font_.fontInfo().underbar() == FONT_IGNORE
504 && font_.fontInfo().noun() == FONT_IGNORE)
511 void GuiCharacter::setBar(FontState val)
515 font_.fontInfo().setEmph(FONT_IGNORE);
516 font_.fontInfo().setUnderbar(FONT_IGNORE);
517 font_.fontInfo().setNoun(FONT_IGNORE);
521 font_.fontInfo().setEmph(FONT_TOGGLE);
524 case UNDERBAR_TOGGLE:
525 font_.fontInfo().setUnderbar(FONT_TOGGLE);
529 font_.fontInfo().setNoun(FONT_TOGGLE);
533 font_.fontInfo().setEmph(FONT_INHERIT);
534 font_.fontInfo().setUnderbar(FONT_INHERIT);
535 font_.fontInfo().setNoun(FONT_INHERIT);
541 ColorCode GuiCharacter::getColor() const
543 return font_.fontInfo().color();
547 void GuiCharacter::setColor(ColorCode val)
561 font_.fontInfo().setColor(val);
569 string GuiCharacter::getLanguage() const
573 if (font_.language())
574 return font_.language()->lang();
579 void GuiCharacter::setLanguage(string const & val)
582 font_.setLanguage(ignore_language);
583 else if (val == "reset") {
585 // Ignored in getLanguage, but needed for dispatchParams
586 font_.setLanguage(buffer().params().language);
588 font_.setLanguage(languages.getLanguage(val));
593 Dialog * createGuiCharacter(GuiView & lv) { return new GuiCharacter(lv); }
596 } // namespace frontend
599 #include "GuiCharacter_moc.cpp"