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", qt_("Text Style")), font_(ignore_font),
273 toggleall_(false), reset_lang_(false)
277 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
278 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
279 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
281 connect(miscCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
282 connect(sizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
283 connect(familyCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
284 connect(seriesCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
285 connect(shapeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
286 connect(colorCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
287 connect(langCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
288 connect(toggleallCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
291 // On Mac it's common to have tool windows which are always in the
292 // foreground and are hidden when the main window is not focused.
293 setWindowFlags(Qt::Tool);
294 autoapplyCB->setChecked(true);
297 family = getFamilyData();
298 series = getSeriesData();
299 shape = getShapeData();
300 size = getSizeData();
302 color = getColorData();
303 language = getLanguageData(true);
305 for (vector<FamilyPair>::const_iterator cit = family.begin();
306 cit != family.end(); ++cit) {
307 familyCO->addItem(cit->first);
310 for (vector<SeriesPair>::const_iterator cit = series.begin();
311 cit != series.end(); ++cit) {
312 seriesCO->addItem(cit->first);
314 for (vector<ShapePair>::const_iterator cit = shape.begin();
315 cit != shape.end(); ++cit) {
316 shapeCO->addItem(cit->first);
318 for (vector<SizePair>::const_iterator cit = size.begin();
319 cit != size.end(); ++cit) {
320 sizeCO->addItem(cit->first);
322 for (vector<BarPair>::const_iterator cit = bar.begin();
323 cit != bar.end(); ++cit) {
324 miscCO->addItem(cit->first);
326 for (vector<ColorPair>::const_iterator cit = color.begin();
327 cit != color.end(); ++cit) {
328 colorCO->addItem(cit->first);
330 for (vector<LanguagePair>::const_iterator cit = language.begin();
331 cit != language.end(); ++cit) {
332 langCO->addItem(toqstr(cit->first));
335 bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
337 bc().setApply(applyPB);
338 bc().setCancel(closePB);
339 bc().addReadOnly(familyCO);
340 bc().addReadOnly(seriesCO);
341 bc().addReadOnly(sizeCO);
342 bc().addReadOnly(shapeCO);
343 bc().addReadOnly(miscCO);
344 bc().addReadOnly(langCO);
345 bc().addReadOnly(colorCO);
346 bc().addReadOnly(toggleallCB);
347 bc().addReadOnly(autoapplyCB);
349 // FIXME: hack to work around resizing bug in Qt >= 4.2
350 // bug verified with Qt 4.2.{0-3} (JSpitzm)
351 #if QT_VERSION >= 0x040200
352 // qt resizes the comboboxes only after show(), so ...
358 void GuiCharacter::change_adaptor()
362 if (!autoapplyCB->isChecked())
365 // to be really good here, we should set the combos to the values of
366 // the current text, and make it appear as "no change" if the values
367 // stay the same between applys. Might be difficult though wrt to a
368 // moved cursor - jbl
370 familyCO->setCurrentIndex(0);
371 seriesCO->setCurrentIndex(0);
372 sizeCO->setCurrentIndex(0);
373 shapeCO->setCurrentIndex(0);
374 miscCO->setCurrentIndex(0);
375 langCO->setCurrentIndex(0);
376 colorCO->setCurrentIndex(0);
380 void GuiCharacter::closeEvent(QCloseEvent * e)
383 GuiDialog::closeEvent(e);
387 template<class A, class B>
388 static int findPos2nd(vector<pair<A, B> > const & vec, B const & val)
390 typedef typename vector<pair<A, B> >::const_iterator
393 for (const_iterator cit = vec.begin(); cit != vec.end(); ++cit)
394 if (cit->second == val)
395 return int(cit - vec.begin());
401 void GuiCharacter::updateContents()
403 familyCO->setCurrentIndex(findPos2nd(family, getFamily()));
404 seriesCO->setCurrentIndex(findPos2nd(series, getSeries()));
405 shapeCO->setCurrentIndex(findPos2nd(shape, getShape()));
406 sizeCO->setCurrentIndex(findPos2nd(size, getSize()));
407 miscCO->setCurrentIndex(findPos2nd(bar, getBar()));
408 colorCO->setCurrentIndex(findPos2nd(color, getColor()));
409 langCO->setCurrentIndex(findPos2nd(language, getLanguage()));
411 toggleallCB->setChecked(toggleall_);
415 void GuiCharacter::applyView()
417 setFamily(family[familyCO->currentIndex()].second);
418 setSeries(series[seriesCO->currentIndex()].second);
419 setShape(shape[shapeCO->currentIndex()].second);
420 setSize(size[sizeCO->currentIndex()].second);
421 setBar(bar[miscCO->currentIndex()].second);
422 setColor(color[colorCO->currentIndex()].second);
423 setLanguage(language[langCO->currentIndex()].second);
425 toggleall_ = toggleallCB->isChecked();
429 bool GuiCharacter::initialiseParams(string const &)
431 // so that the user can press Ok
432 if (getFamily() != IGNORE_FAMILY
433 || getSeries() != IGNORE_SERIES
434 || getShape() != IGNORE_SHAPE
435 || getSize() != FONT_SIZE_IGNORE
436 || getBar() != IGNORE
437 || getColor() != Color_ignore
438 || font_.language() != ignore_language)
439 setButtonsValid(true);
445 void GuiCharacter::dispatchParams()
447 dispatch(FuncRequest(getLfun(), font_.toString(toggleall_)));
451 FontFamily GuiCharacter::getFamily() const
453 return font_.fontInfo().family();
457 void GuiCharacter::setFamily(FontFamily val)
459 font_.fontInfo().setFamily(val);
463 FontSeries GuiCharacter::getSeries() const
465 return font_.fontInfo().series();
469 void GuiCharacter::setSeries(FontSeries val)
471 font_.fontInfo().setSeries(val);
475 FontShape GuiCharacter::getShape() const
477 return font_.fontInfo().shape();
481 void GuiCharacter::setShape(FontShape val)
483 font_.fontInfo().setShape(val);
487 FontSize GuiCharacter::getSize() const
489 return font_.fontInfo().size();
493 void GuiCharacter::setSize(FontSize val)
495 font_.fontInfo().setSize(val);
499 FontState GuiCharacter::getBar() const
501 if (font_.fontInfo().emph() == FONT_TOGGLE)
504 if (font_.fontInfo().underbar() == FONT_TOGGLE)
505 return UNDERBAR_TOGGLE;
507 if (font_.fontInfo().noun() == FONT_TOGGLE)
510 if (font_.fontInfo().emph() == FONT_IGNORE
511 && font_.fontInfo().underbar() == FONT_IGNORE
512 && font_.fontInfo().noun() == FONT_IGNORE)
519 void GuiCharacter::setBar(FontState val)
523 font_.fontInfo().setEmph(FONT_IGNORE);
524 font_.fontInfo().setUnderbar(FONT_IGNORE);
525 font_.fontInfo().setNoun(FONT_IGNORE);
529 font_.fontInfo().setEmph(FONT_TOGGLE);
532 case UNDERBAR_TOGGLE:
533 font_.fontInfo().setUnderbar(FONT_TOGGLE);
537 font_.fontInfo().setNoun(FONT_TOGGLE);
541 font_.fontInfo().setEmph(FONT_INHERIT);
542 font_.fontInfo().setUnderbar(FONT_INHERIT);
543 font_.fontInfo().setNoun(FONT_INHERIT);
549 ColorCode GuiCharacter::getColor() const
551 return font_.fontInfo().color();
555 void GuiCharacter::setColor(ColorCode val)
569 font_.fontInfo().setColor(val);
577 string GuiCharacter::getLanguage() const
581 if (font_.language())
582 return font_.language()->lang();
587 void GuiCharacter::setLanguage(string const & val)
590 font_.setLanguage(ignore_language);
591 else if (val == "reset") {
593 // Ignored in getLanguage, but needed for dispatchParams
594 font_.setLanguage(buffer().params().language);
596 font_.setLanguage(languages.getLanguage(val));
601 Dialog * createGuiCharacter(GuiView & lv) { return new GuiCharacter(lv); }
604 } // namespace frontend
607 #include "GuiCharacter_moc.cpp"