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>
33 static vector<ShapePair> const getShapeData()
35 vector<ShapePair> shape(6);
39 pr.first = qt_("No change");
40 pr.second = IGNORE_SHAPE;
43 pr.first = qt_("Upright");
47 pr.first = qt_("Italic");
48 pr.second = ITALIC_SHAPE;
51 pr.first = qt_("Slanted");
52 pr.second = SLANTED_SHAPE;
55 pr.first = qt_("Small Caps");
56 pr.second = SMALLCAPS_SHAPE;
59 pr.first = qt_("Reset");
60 pr.second = INHERIT_SHAPE;
67 static vector<SizePair> const getSizeData()
69 vector<SizePair> size(14);
73 pr.first = qt_("No change");
74 pr.second = FONT_SIZE_IGNORE;
77 pr.first = qt_("Tiny");
78 pr.second = FONT_SIZE_TINY;
81 pr.first = qt_("Smallest");
82 pr.second = FONT_SIZE_SCRIPT;
85 pr.first = qt_("Smaller");
86 pr.second = FONT_SIZE_FOOTNOTE;
89 pr.first = qt_("Small");
90 pr.second = FONT_SIZE_SMALL;
93 pr.first = qt_("Normal");
94 pr.second = FONT_SIZE_NORMAL;
97 pr.first = qt_("Large");
98 pr.second = FONT_SIZE_LARGE;
101 pr.first = qt_("Larger");
102 pr.second = FONT_SIZE_LARGER;
105 pr.first = qt_("Largest");
106 pr.second = FONT_SIZE_LARGEST;
109 pr.first = qt_("Huge");
110 pr.second = FONT_SIZE_HUGE;
113 pr.first = qt_("Huger");
114 pr.second = FONT_SIZE_HUGER;
117 pr.first = qt_("Increase");
118 pr.second = FONT_SIZE_INCREASE;
121 pr.first = qt_("Decrease");
122 pr.second = FONT_SIZE_DECREASE;
125 pr.first = qt_("Reset");
126 pr.second = FONT_SIZE_INHERIT;
133 static vector<BarPair> const getBarData()
135 vector<BarPair> bar(5);
139 pr.first = qt_("No change");
143 pr.first = qt_("Emph");
144 pr.second = EMPH_TOGGLE;
147 pr.first = qt_("Underbar");
148 pr.second = UNDERBAR_TOGGLE;
151 pr.first = qt_("Noun");
152 pr.second = NOUN_TOGGLE;
155 pr.first = qt_("Reset");
163 static vector<ColorPair> const getColorData()
165 vector<ColorPair> color(11);
169 pr.first = qt_("No change");
170 pr.second = Color_ignore;
173 pr.first = qt_("No color");
174 pr.second = Color_none;
177 pr.first = qt_("Black");
178 pr.second = Color_black;
181 pr.first = qt_("White");
182 pr.second = Color_white;
185 pr.first = qt_("Red");
186 pr.second = Color_red;
189 pr.first = qt_("Green");
190 pr.second = Color_green;
193 pr.first = qt_("Blue");
194 pr.second = Color_blue;
197 pr.first = qt_("Cyan");
198 pr.second = Color_cyan;
201 pr.first = qt_("Magenta");
202 pr.second = Color_magenta;
205 pr.first = qt_("Yellow");
206 pr.second = Color_yellow;
209 pr.first = qt_("Reset");
210 pr.second = Color_inherit;
217 static vector<SeriesPair> const getSeriesData()
219 vector<SeriesPair> series(4);
223 pr.first = qt_("No change");
224 pr.second = IGNORE_SERIES;
227 pr.first = qt_("Medium");
228 pr.second = MEDIUM_SERIES;
231 pr.first = qt_("Bold");
232 pr.second = BOLD_SERIES;
235 pr.first = qt_("Reset");
236 pr.second = INHERIT_SERIES;
243 static vector<FamilyPair> const getFamilyData()
245 vector<FamilyPair> family(5);
249 pr.first = qt_("No change");
250 pr.second = IGNORE_FAMILY;
253 pr.first = qt_("Roman");
254 pr.second = ROMAN_FAMILY;
257 pr.first = qt_("Sans Serif");
258 pr.second = SANS_FAMILY;
261 pr.first = qt_("Typewriter");
262 pr.second = TYPEWRITER_FAMILY;
265 pr.first = qt_("Reset");
266 pr.second = INHERIT_FAMILY;
273 GuiCharacter::GuiCharacter(LyXView & lv)
274 : GuiDialog(lv, "character"), font_(ignore_font),
275 toggleall_(false), reset_lang_(false)
278 setViewTitle(_("Text Style"));
280 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
281 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
282 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
284 connect(miscCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
285 connect(sizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
286 connect(familyCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
287 connect(seriesCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
288 connect(shapeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
289 connect(colorCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
290 connect(langCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
291 connect(toggleallCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
293 family = getFamilyData();
294 series = getSeriesData();
295 shape = getShapeData();
296 size = getSizeData();
298 color = getColorData();
299 language = getLanguageData(true);
301 for (vector<FamilyPair>::const_iterator cit = family.begin();
302 cit != family.end(); ++cit) {
303 familyCO->addItem(cit->first);
306 for (vector<SeriesPair>::const_iterator cit = series.begin();
307 cit != series.end(); ++cit) {
308 seriesCO->addItem(cit->first);
310 for (vector<ShapePair>::const_iterator cit = shape.begin();
311 cit != shape.end(); ++cit) {
312 shapeCO->addItem(cit->first);
314 for (vector<SizePair>::const_iterator cit = size.begin();
315 cit != size.end(); ++cit) {
316 sizeCO->addItem(cit->first);
318 for (vector<BarPair>::const_iterator cit = bar.begin();
319 cit != bar.end(); ++cit) {
320 miscCO->addItem(cit->first);
322 for (vector<ColorPair>::const_iterator cit = color.begin();
323 cit != color.end(); ++cit) {
324 colorCO->addItem(cit->first);
326 for (vector<LanguagePair>::const_iterator cit = language.begin();
327 cit != language.end(); ++cit) {
328 langCO->addItem(toqstr(cit->first));
331 bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
333 bc().setApply(applyPB);
334 bc().setCancel(closePB);
335 bc().addReadOnly(familyCO);
336 bc().addReadOnly(seriesCO);
337 bc().addReadOnly(sizeCO);
338 bc().addReadOnly(shapeCO);
339 bc().addReadOnly(miscCO);
340 bc().addReadOnly(langCO);
341 bc().addReadOnly(colorCO);
342 bc().addReadOnly(toggleallCB);
343 bc().addReadOnly(autoapplyCB);
345 // FIXME: hack to work around resizing bug in Qt >= 4.2
346 // bug verified with Qt 4.2.{0-3} (JSpitzm)
347 #if QT_VERSION >= 0x040200
348 // qt resizes the comboboxes only after show(), so ...
354 void GuiCharacter::change_adaptor()
358 if (!autoapplyCB->isChecked())
361 // to be really good here, we should set the combos to the values of
362 // the current text, and make it appear as "no change" if the values
363 // stay the same between applys. Might be difficult though wrt to a
364 // moved cursor - jbl
366 familyCO->setCurrentIndex(0);
367 seriesCO->setCurrentIndex(0);
368 sizeCO->setCurrentIndex(0);
369 shapeCO->setCurrentIndex(0);
370 miscCO->setCurrentIndex(0);
371 langCO->setCurrentIndex(0);
372 colorCO->setCurrentIndex(0);
376 void GuiCharacter::closeEvent(QCloseEvent * e)
379 GuiDialog::closeEvent(e);
383 template<class A, class B>
384 static int findPos2nd(vector<std::pair<A, B> > const & vec, B const & val)
386 typedef typename vector<std::pair<A, B> >::const_iterator
389 for (const_iterator cit = vec.begin(); cit != vec.end(); ++cit)
390 if (cit->second == val)
391 return int(cit - vec.begin());
397 void GuiCharacter::updateContents()
399 familyCO->setCurrentIndex(findPos2nd(family, getFamily()));
400 seriesCO->setCurrentIndex(findPos2nd(series, getSeries()));
401 shapeCO->setCurrentIndex(findPos2nd(shape, getShape()));
402 sizeCO->setCurrentIndex(findPos2nd(size, getSize()));
403 miscCO->setCurrentIndex(findPos2nd(bar, getBar()));
404 colorCO->setCurrentIndex(findPos2nd(color, getColor()));
405 langCO->setCurrentIndex(findPos2nd(language, getLanguage()));
407 toggleallCB->setChecked(toggleall_);
411 void GuiCharacter::applyView()
413 setFamily(family[familyCO->currentIndex()].second);
414 setSeries(series[seriesCO->currentIndex()].second);
415 setShape(shape[shapeCO->currentIndex()].second);
416 setSize(size[sizeCO->currentIndex()].second);
417 setBar(bar[miscCO->currentIndex()].second);
418 setColor(color[colorCO->currentIndex()].second);
419 setLanguage(language[langCO->currentIndex()].second);
421 toggleall_ = toggleallCB->isChecked();
425 bool GuiCharacter::initialiseParams(string const &)
427 // so that the user can press Ok
428 if (getFamily() != IGNORE_FAMILY
429 || getSeries() != IGNORE_SERIES
430 || getShape() != IGNORE_SHAPE
431 || getSize() != FONT_SIZE_IGNORE
432 || getBar() != IGNORE
433 || getColor() != Color_ignore
434 || font_.language() != ignore_language)
435 setButtonsValid(true);
441 void GuiCharacter::dispatchParams()
443 dispatch(FuncRequest(getLfun(), font_.toString(toggleall_)));
447 FontFamily GuiCharacter::getFamily() const
449 return font_.fontInfo().family();
453 void GuiCharacter::setFamily(FontFamily val)
455 font_.fontInfo().setFamily(val);
459 FontSeries GuiCharacter::getSeries() const
461 return font_.fontInfo().series();
465 void GuiCharacter::setSeries(FontSeries val)
467 font_.fontInfo().setSeries(val);
471 FontShape GuiCharacter::getShape() const
473 return font_.fontInfo().shape();
477 void GuiCharacter::setShape(FontShape val)
479 font_.fontInfo().setShape(val);
483 FontSize GuiCharacter::getSize() const
485 return font_.fontInfo().size();
489 void GuiCharacter::setSize(FontSize val)
491 font_.fontInfo().setSize(val);
495 FontState GuiCharacter::getBar() const
497 if (font_.fontInfo().emph() == FONT_TOGGLE)
500 if (font_.fontInfo().underbar() == FONT_TOGGLE)
501 return UNDERBAR_TOGGLE;
503 if (font_.fontInfo().noun() == FONT_TOGGLE)
506 if (font_.fontInfo().emph() == FONT_IGNORE
507 && font_.fontInfo().underbar() == FONT_IGNORE
508 && font_.fontInfo().noun() == FONT_IGNORE)
515 void GuiCharacter::setBar(FontState val)
519 font_.fontInfo().setEmph(FONT_IGNORE);
520 font_.fontInfo().setUnderbar(FONT_IGNORE);
521 font_.fontInfo().setNoun(FONT_IGNORE);
525 font_.fontInfo().setEmph(FONT_TOGGLE);
528 case UNDERBAR_TOGGLE:
529 font_.fontInfo().setUnderbar(FONT_TOGGLE);
533 font_.fontInfo().setNoun(FONT_TOGGLE);
537 font_.fontInfo().setEmph(FONT_INHERIT);
538 font_.fontInfo().setUnderbar(FONT_INHERIT);
539 font_.fontInfo().setNoun(FONT_INHERIT);
545 ColorCode GuiCharacter::getColor() const
547 return font_.fontInfo().color();
551 void GuiCharacter::setColor(ColorCode val)
565 font_.fontInfo().setColor(val);
573 string GuiCharacter::getLanguage() const
577 if (font_.language())
578 return font_.language()->lang();
583 void GuiCharacter::setLanguage(string const & val)
586 font_.setLanguage(ignore_language);
587 else if (val == "reset") {
589 // Ignored in getLanguage, but needed for dispatchParams
590 font_.setLanguage(buffer().params().language);
592 font_.setLanguage(languages.getLanguage(val));
597 Dialog * createGuiCharacter(LyXView & lv) { return new GuiCharacter(lv); }
600 } // namespace frontend
603 #include "GuiCharacter_moc.cpp"