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"
21 #include "BufferParams.h"
22 #include "FuncRequest.h"
26 #include <QCloseEvent>
35 static vector<ShapePair> const getShapeData()
37 vector<ShapePair> shape(6);
41 pr.first = qt_("No change");
42 pr.second = Font::IGNORE_SHAPE;
45 pr.first = qt_("Upright");
46 pr.second = Font::UP_SHAPE;
49 pr.first = qt_("Italic");
50 pr.second = Font::ITALIC_SHAPE;
53 pr.first = qt_("Slanted");
54 pr.second = Font::SLANTED_SHAPE;
57 pr.first = qt_("Small Caps");
58 pr.second = Font::SMALLCAPS_SHAPE;
61 pr.first = qt_("Reset");
62 pr.second = Font::INHERIT_SHAPE;
69 static vector<SizePair> const getSizeData()
71 vector<SizePair> size(14);
75 pr.first = qt_("No change");
76 pr.second = Font::IGNORE_SIZE;
79 pr.first = qt_("Tiny");
80 pr.second = Font::SIZE_TINY;
83 pr.first = qt_("Smallest");
84 pr.second = Font::SIZE_SCRIPT;
87 pr.first = qt_("Smaller");
88 pr.second = Font::SIZE_FOOTNOTE;
91 pr.first = qt_("Small");
92 pr.second = Font::SIZE_SMALL;
95 pr.first = qt_("Normal");
96 pr.second = Font::SIZE_NORMAL;
99 pr.first = qt_("Large");
100 pr.second = Font::SIZE_LARGE;
103 pr.first = qt_("Larger");
104 pr.second = Font::SIZE_LARGER;
107 pr.first = qt_("Largest");
108 pr.second = Font::SIZE_LARGEST;
111 pr.first = qt_("Huge");
112 pr.second = Font::SIZE_HUGE;
115 pr.first = qt_("Huger");
116 pr.second = Font::SIZE_HUGER;
119 pr.first = qt_("Increase");
120 pr.second = Font::INCREASE_SIZE;
123 pr.first = qt_("Decrease");
124 pr.second = Font::DECREASE_SIZE;
127 pr.first = qt_("Reset");
128 pr.second = Font::INHERIT_SIZE;
135 static vector<BarPair> const getBarData()
137 vector<BarPair> bar(5);
141 pr.first = qt_("No change");
145 pr.first = qt_("Emph");
146 pr.second = EMPH_TOGGLE;
149 pr.first = qt_("Underbar");
150 pr.second = UNDERBAR_TOGGLE;
153 pr.first = qt_("Noun");
154 pr.second = NOUN_TOGGLE;
157 pr.first = qt_("Reset");
165 static vector<ColorPair> const getColorData()
167 vector<ColorPair> color(11);
171 pr.first = qt_("No change");
172 pr.second = Color::ignore;
175 pr.first = qt_("No color");
176 pr.second = Color::none;
179 pr.first = qt_("Black");
180 pr.second = Color::black;
183 pr.first = qt_("White");
184 pr.second = Color::white;
187 pr.first = qt_("Red");
188 pr.second = Color::red;
191 pr.first = qt_("Green");
192 pr.second = Color::green;
195 pr.first = qt_("Blue");
196 pr.second = Color::blue;
199 pr.first = qt_("Cyan");
200 pr.second = Color::cyan;
203 pr.first = qt_("Magenta");
204 pr.second = Color::magenta;
207 pr.first = qt_("Yellow");
208 pr.second = Color::yellow;
211 pr.first = qt_("Reset");
212 pr.second = Color::inherit;
219 static vector<SeriesPair> const getSeriesData()
221 vector<SeriesPair> series(4);
225 pr.first = qt_("No change");
226 pr.second = Font::IGNORE_SERIES;
229 pr.first = qt_("Medium");
230 pr.second = Font::MEDIUM_SERIES;
233 pr.first = qt_("Bold");
234 pr.second = Font::BOLD_SERIES;
237 pr.first = qt_("Reset");
238 pr.second = Font::INHERIT_SERIES;
245 static vector<FamilyPair> const getFamilyData()
247 vector<FamilyPair> family(5);
251 pr.first = qt_("No change");
252 pr.second = Font::IGNORE_FAMILY;
255 pr.first = qt_("Roman");
256 pr.second = Font::ROMAN_FAMILY;
259 pr.first = qt_("Sans Serif");
260 pr.second = Font::SANS_FAMILY;
263 pr.first = qt_("Typewriter");
264 pr.second = Font::TYPEWRITER_FAMILY;
267 pr.first = qt_("Reset");
268 pr.second = Font::INHERIT_FAMILY;
275 GuiCharacter::GuiCharacter(LyXView & lv)
276 : GuiDialog(lv, "character"), Controller(this), font_(Font::ALL_IGNORE),
277 toggleall_(false), reset_lang_(false)
280 setController(this, false);
281 setViewTitle(_("Text Style"));
283 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
284 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
285 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
287 connect(miscCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
288 connect(sizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
289 connect(familyCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
290 connect(seriesCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
291 connect(shapeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
292 connect(colorCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
293 connect(langCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
294 connect(toggleallCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
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 void GuiCharacter::closeEvent(QCloseEvent * e)
382 GuiDialog::closeEvent(e);
386 template<class A, class B>
387 static int findPos2nd(vector<std::pair<A, B> > const & vec, B const & val)
389 typedef typename vector<std::pair<A, B> >::const_iterator
392 for (const_iterator cit = vec.begin(); cit != vec.end(); ++cit)
393 if (cit->second == val)
394 return int(cit - vec.begin());
400 void GuiCharacter::updateContents()
402 familyCO->setCurrentIndex(findPos2nd(family, getFamily()));
403 seriesCO->setCurrentIndex(findPos2nd(series, getSeries()));
404 shapeCO->setCurrentIndex(findPos2nd(shape, getShape()));
405 sizeCO->setCurrentIndex(findPos2nd(size, getSize()));
406 miscCO->setCurrentIndex(findPos2nd(bar, getBar()));
407 colorCO->setCurrentIndex(findPos2nd(color, getColor()));
408 langCO->setCurrentIndex(findPos2nd(language, getLanguage()));
410 toggleallCB->setChecked(getToggleAll());
414 void GuiCharacter::applyView()
416 setFamily(family[familyCO->currentIndex()].second);
417 setSeries(series[seriesCO->currentIndex()].second);
418 setShape(shape[shapeCO->currentIndex()].second);
419 setSize(size[sizeCO->currentIndex()].second);
420 setBar(bar[miscCO->currentIndex()].second);
421 setColor(color[colorCO->currentIndex()].second);
422 setLanguage(language[langCO->currentIndex()].second);
424 setToggleAll(toggleallCB->isChecked());
428 bool GuiCharacter::initialiseParams(string const &)
430 // so that the user can press Ok
431 if (getFamily() != Font::IGNORE_FAMILY
432 || getSeries() != Font::IGNORE_SERIES
433 || getShape() != Font::IGNORE_SHAPE
434 || getSize() != Font::IGNORE_SIZE
435 || getBar() != IGNORE
436 || getColor() != Color::ignore
437 || font_.language() != ignore_language)
438 dialog().setButtonsValid(true);
444 void GuiCharacter::dispatchParams()
446 dispatch(FuncRequest(getLfun(), font_.toString(toggleall_)));
450 Font::FONT_FAMILY GuiCharacter::getFamily() const
452 return font_.family();
456 void GuiCharacter::setFamily(Font::FONT_FAMILY val)
458 font_.setFamily(val);
462 Font::FONT_SERIES GuiCharacter::getSeries() const
464 return font_.series();
468 void GuiCharacter::setSeries(Font::FONT_SERIES val)
470 font_.setSeries(val);
474 Font::FONT_SHAPE GuiCharacter::getShape() const
476 return font_.shape();
480 void GuiCharacter::setShape(Font::FONT_SHAPE val)
486 Font::FONT_SIZE GuiCharacter::getSize() const
492 void GuiCharacter::setSize(Font::FONT_SIZE val)
498 FontState GuiCharacter::getBar() const
500 if (font_.emph() == Font::TOGGLE)
503 if (font_.underbar() == Font::TOGGLE)
504 return UNDERBAR_TOGGLE;
506 if (font_.noun() == Font::TOGGLE)
509 if (font_.emph() == Font::IGNORE
510 && font_.underbar() == Font::IGNORE
511 && font_.noun() == Font::IGNORE)
518 void GuiCharacter::setBar(FontState val)
522 font_.setEmph(Font::IGNORE);
523 font_.setUnderbar(Font::IGNORE);
524 font_.setNoun(Font::IGNORE);
528 font_.setEmph(Font::TOGGLE);
531 case UNDERBAR_TOGGLE:
532 font_.setUnderbar(Font::TOGGLE);
536 font_.setNoun(Font::TOGGLE);
540 font_.setEmph(Font::INHERIT);
541 font_.setUnderbar(Font::INHERIT);
542 font_.setNoun(Font::INHERIT);
548 Color_color GuiCharacter::getColor() const
550 return font_.color();
554 void GuiCharacter::setColor(Color_color val)
576 string GuiCharacter::getLanguage() const
580 if (font_.language())
581 return font_.language()->lang();
586 void GuiCharacter::setLanguage(string const & val)
589 font_.setLanguage(ignore_language);
590 else if (val == "reset") {
592 // Ignored in getLanguage, but needed for dispatchParams
593 font_.setLanguage(buffer().params().language);
595 font_.setLanguage(languages.getLanguage(val));
600 bool GuiCharacter::getToggleAll() const
606 void GuiCharacter::setToggleAll(bool t)
612 Dialog * createGuiCharacter(LyXView & lv) { return new GuiCharacter(lv); }
615 } // namespace frontend
618 #include "GuiCharacter_moc.cpp"