2 * \file GuiCharacter.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "GuiCharacter.h"
16 #include "ControlCharacter.h"
17 #include "qt_helpers.h"
21 #include <QCloseEvent>
28 static vector<ShapePair> const getShapeData()
30 vector<ShapePair> shape(6);
34 pr.first = qt_("No change");
35 pr.second = Font::IGNORE_SHAPE;
38 pr.first = qt_("Upright");
39 pr.second = Font::UP_SHAPE;
42 pr.first = qt_("Italic");
43 pr.second = Font::ITALIC_SHAPE;
46 pr.first = qt_("Slanted");
47 pr.second = Font::SLANTED_SHAPE;
50 pr.first = qt_("Small Caps");
51 pr.second = Font::SMALLCAPS_SHAPE;
54 pr.first = qt_("Reset");
55 pr.second = Font::INHERIT_SHAPE;
62 static vector<SizePair> const getSizeData()
64 vector<SizePair> size(14);
68 pr.first = qt_("No change");
69 pr.second = Font::IGNORE_SIZE;
72 pr.first = qt_("Tiny");
73 pr.second = Font::SIZE_TINY;
76 pr.first = qt_("Smallest");
77 pr.second = Font::SIZE_SCRIPT;
80 pr.first = qt_("Smaller");
81 pr.second = Font::SIZE_FOOTNOTE;
84 pr.first = qt_("Small");
85 pr.second = Font::SIZE_SMALL;
88 pr.first = qt_("Normal");
89 pr.second = Font::SIZE_NORMAL;
92 pr.first = qt_("Large");
93 pr.second = Font::SIZE_LARGE;
96 pr.first = qt_("Larger");
97 pr.second = Font::SIZE_LARGER;
100 pr.first = qt_("Largest");
101 pr.second = Font::SIZE_LARGEST;
104 pr.first = qt_("Huge");
105 pr.second = Font::SIZE_HUGE;
108 pr.first = qt_("Huger");
109 pr.second = Font::SIZE_HUGER;
112 pr.first = qt_("Increase");
113 pr.second = Font::INCREASE_SIZE;
116 pr.first = qt_("Decrease");
117 pr.second = Font::DECREASE_SIZE;
120 pr.first = qt_("Reset");
121 pr.second = Font::INHERIT_SIZE;
128 static vector<BarPair> const getBarData()
130 vector<BarPair> bar(5);
134 pr.first = qt_("No change");
138 pr.first = qt_("Emph");
139 pr.second = EMPH_TOGGLE;
142 pr.first = qt_("Underbar");
143 pr.second = UNDERBAR_TOGGLE;
146 pr.first = qt_("Noun");
147 pr.second = NOUN_TOGGLE;
150 pr.first = qt_("Reset");
158 static vector<ColorPair> const getColorData()
160 vector<ColorPair> color(11);
164 pr.first = qt_("No change");
165 pr.second = Color::ignore;
168 pr.first = qt_("No color");
169 pr.second = Color::none;
172 pr.first = qt_("Black");
173 pr.second = Color::black;
176 pr.first = qt_("White");
177 pr.second = Color::white;
180 pr.first = qt_("Red");
181 pr.second = Color::red;
184 pr.first = qt_("Green");
185 pr.second = Color::green;
188 pr.first = qt_("Blue");
189 pr.second = Color::blue;
192 pr.first = qt_("Cyan");
193 pr.second = Color::cyan;
196 pr.first = qt_("Magenta");
197 pr.second = Color::magenta;
200 pr.first = qt_("Yellow");
201 pr.second = Color::yellow;
204 pr.first = qt_("Reset");
205 pr.second = Color::inherit;
212 static vector<SeriesPair> const getSeriesData()
214 vector<SeriesPair> series(4);
218 pr.first = qt_("No change");
219 pr.second = Font::IGNORE_SERIES;
222 pr.first = qt_("Medium");
223 pr.second = Font::MEDIUM_SERIES;
226 pr.first = qt_("Bold");
227 pr.second = Font::BOLD_SERIES;
230 pr.first = qt_("Reset");
231 pr.second = Font::INHERIT_SERIES;
238 static vector<FamilyPair> const getFamilyData()
240 vector<FamilyPair> family(5);
244 pr.first = qt_("No change");
245 pr.second = Font::IGNORE_FAMILY;
248 pr.first = qt_("Roman");
249 pr.second = Font::ROMAN_FAMILY;
252 pr.first = qt_("Sans Serif");
253 pr.second = Font::SANS_FAMILY;
256 pr.first = qt_("Typewriter");
257 pr.second = Font::TYPEWRITER_FAMILY;
260 pr.first = qt_("Reset");
261 pr.second = Font::INHERIT_FAMILY;
268 GuiCharacterDialog::GuiCharacterDialog(LyXView & lv)
269 : GuiDialog(lv, "character")
272 setController(new ControlCharacter(*this));
273 setViewTitle(_("Text Style"));
275 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
276 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
277 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
279 connect(miscCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
280 connect(sizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
281 connect(familyCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
282 connect(seriesCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
283 connect(shapeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
284 connect(colorCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
285 connect(langCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
286 connect(toggleallCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
288 family = getFamilyData();
289 series = getSeriesData();
290 shape = getShapeData();
291 size = getSizeData();
293 color = getColorData();
294 language = getLanguageData(true);
296 for (vector<FamilyPair>::const_iterator cit = family.begin();
297 cit != family.end(); ++cit) {
298 familyCO->addItem(cit->first);
301 for (vector<SeriesPair>::const_iterator cit = series.begin();
302 cit != series.end(); ++cit) {
303 seriesCO->addItem(cit->first);
305 for (vector<ShapePair>::const_iterator cit = shape.begin();
306 cit != shape.end(); ++cit) {
307 shapeCO->addItem(cit->first);
309 for (vector<SizePair>::const_iterator cit = size.begin();
310 cit != size.end(); ++cit) {
311 sizeCO->addItem(cit->first);
313 for (vector<BarPair>::const_iterator cit = bar.begin();
314 cit != bar.end(); ++cit) {
315 miscCO->addItem(cit->first);
317 for (vector<ColorPair>::const_iterator cit = color.begin();
318 cit != color.end(); ++cit) {
319 colorCO->addItem(cit->first);
321 for (vector<LanguagePair>::const_iterator cit = language.begin();
322 cit != language.end(); ++cit) {
323 langCO->addItem(toqstr(cit->first));
326 bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
328 bc().setApply(applyPB);
329 bc().setCancel(closePB);
330 bc().addReadOnly(familyCO);
331 bc().addReadOnly(seriesCO);
332 bc().addReadOnly(sizeCO);
333 bc().addReadOnly(shapeCO);
334 bc().addReadOnly(miscCO);
335 bc().addReadOnly(langCO);
336 bc().addReadOnly(colorCO);
337 bc().addReadOnly(toggleallCB);
338 bc().addReadOnly(autoapplyCB);
340 // FIXME: hack to work around resizing bug in Qt >= 4.2
341 // bug verified with Qt 4.2.{0-3} (JSpitzm)
342 #if QT_VERSION >= 0x040200
343 // qt resizes the comboboxes only after show(), so ...
349 ControlCharacter & GuiCharacterDialog::controller()
351 return static_cast<ControlCharacter &>(GuiDialog::controller());
355 void GuiCharacterDialog::change_adaptor()
359 if (!autoapplyCB->isChecked())
362 // to be really good here, we should set the combos to the values of
363 // the current text, and make it appear as "no change" if the values
364 // stay the same between applys. Might be difficult though wrt to a
365 // moved cursor - jbl
367 familyCO->setCurrentIndex(0);
368 seriesCO->setCurrentIndex(0);
369 sizeCO->setCurrentIndex(0);
370 shapeCO->setCurrentIndex(0);
371 miscCO->setCurrentIndex(0);
372 langCO->setCurrentIndex(0);
373 colorCO->setCurrentIndex(0);
377 void GuiCharacterDialog::closeEvent(QCloseEvent * e)
384 template<class A, class B>
385 static int findPos2nd(vector<std::pair<A, B> > const & vec, B const & val)
387 typedef typename vector<std::pair<A, B> >::const_iterator
390 for (const_iterator cit = vec.begin(); cit != vec.end(); ++cit)
391 if (cit->second == val)
392 return int(cit - vec.begin());
398 void GuiCharacterDialog::updateContents()
400 ControlCharacter const & ctrl = controller();
402 familyCO->setCurrentIndex(findPos2nd(family, ctrl.getFamily()));
403 seriesCO->setCurrentIndex(findPos2nd(series, ctrl.getSeries()));
404 shapeCO->setCurrentIndex(findPos2nd(shape, ctrl.getShape()));
405 sizeCO->setCurrentIndex(findPos2nd(size, ctrl.getSize()));
406 miscCO->setCurrentIndex(findPos2nd(bar, ctrl.getBar()));
407 colorCO->setCurrentIndex(findPos2nd(color, ctrl.getColor()));
408 langCO->setCurrentIndex(findPos2nd(language, ctrl.getLanguage()));
410 toggleallCB->setChecked(ctrl.getToggleAll());
414 void GuiCharacterDialog::applyView()
416 ControlCharacter & ctrl = controller();
418 ctrl.setFamily(family[familyCO->currentIndex()].second);
419 ctrl.setSeries(series[seriesCO->currentIndex()].second);
420 ctrl.setShape(shape[shapeCO->currentIndex()].second);
421 ctrl.setSize(size[sizeCO->currentIndex()].second);
422 ctrl.setBar(bar[miscCO->currentIndex()].second);
423 ctrl.setColor(color[colorCO->currentIndex()].second);
424 ctrl.setLanguage(language[langCO->currentIndex()].second);
426 ctrl.setToggleAll(toggleallCB->isChecked());
429 } // namespace frontend
432 #include "GuiCharacter_moc.cpp"