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 QList<ShapePair> shapeData()
32 QList<ShapePair> shapes;
33 shapes << ShapePair(qt_("No change"), IGNORE_SHAPE);
34 shapes << ShapePair(qt_("Upright"), UP_SHAPE);
35 shapes << ShapePair(qt_("Italic"), ITALIC_SHAPE);
36 shapes << ShapePair(qt_("Slanted"), SLANTED_SHAPE);
37 shapes << ShapePair(qt_("Small Caps"), SMALLCAPS_SHAPE);
38 shapes << ShapePair(qt_("Reset"), INHERIT_SHAPE);
43 static QList<SizePair> sizeData()
45 QList<SizePair> sizes;
46 sizes << SizePair(qt_("No change"), FONT_SIZE_IGNORE);
47 sizes << SizePair(qt_("Tiny"), FONT_SIZE_TINY);
48 sizes << SizePair(qt_("Smallest"), FONT_SIZE_SCRIPT);
49 sizes << SizePair(qt_("Smaller"), FONT_SIZE_FOOTNOTE);
50 sizes << SizePair(qt_("Small"), FONT_SIZE_SMALL);
51 sizes << SizePair(qt_("Normal"), FONT_SIZE_NORMAL);
52 sizes << SizePair(qt_("Large"), FONT_SIZE_LARGE);
53 sizes << SizePair(qt_("Larger"), FONT_SIZE_LARGER);
54 sizes << SizePair(qt_("Largest"), FONT_SIZE_LARGEST);
55 sizes << SizePair(qt_("Huge"), FONT_SIZE_HUGE);
56 sizes << SizePair(qt_("Huger"), FONT_SIZE_HUGER);
57 sizes << SizePair(qt_("Increase"), FONT_SIZE_INCREASE);
58 sizes << SizePair(qt_("Decrease"), FONT_SIZE_DECREASE);
59 sizes << SizePair(qt_("Reset"), FONT_SIZE_INHERIT);
64 static QList<BarPair> barData()
67 bars << BarPair(qt_("No change"), IGNORE);
68 bars << BarPair(qt_("Emph"), EMPH_TOGGLE);
69 bars << BarPair(qt_("Underbar"), UNDERBAR_TOGGLE);
70 bars << BarPair(qt_("Noun"), NOUN_TOGGLE);
71 bars << BarPair(qt_("Reset"), INHERIT);
76 static QList<ColorPair> colorData()
78 QList<ColorPair> colors;
79 colors << ColorPair(qt_("No change"), Color_ignore);
80 colors << ColorPair(qt_("No color"), Color_none);
81 colors << ColorPair(qt_("Black"), Color_black);
82 colors << ColorPair(qt_("White"), Color_white);
83 colors << ColorPair(qt_("Red"), Color_red);
84 colors << ColorPair(qt_("Green"), Color_green);
85 colors << ColorPair(qt_("Blue"), Color_blue);
86 colors << ColorPair(qt_("Cyan"), Color_cyan);
87 colors << ColorPair(qt_("Magenta"), Color_magenta);
88 colors << ColorPair(qt_("Yellow"), Color_yellow);
89 colors << ColorPair(qt_("Reset"), Color_inherit);
94 static QList<SeriesPair> seriesData()
96 QList<SeriesPair> series;
97 series << SeriesPair(qt_("No change"), IGNORE_SERIES);
98 series << SeriesPair(qt_("Medium"), MEDIUM_SERIES);
99 series << SeriesPair(qt_("Bold"), BOLD_SERIES);
100 series << SeriesPair(qt_("Reset"), INHERIT_SERIES);
105 static QList<FamilyPair> familyData()
107 QList<FamilyPair> families;
108 families << FamilyPair(qt_("No change"), IGNORE_FAMILY);
109 families << FamilyPair(qt_("Roman"), ROMAN_FAMILY);
110 families << FamilyPair(qt_("Sans Serif"), SANS_FAMILY);
111 families << FamilyPair(qt_("Typewriter"), TYPEWRITER_FAMILY);
112 families << FamilyPair(qt_("Reset"), INHERIT_FAMILY);
117 GuiCharacter::GuiCharacter(GuiView & lv)
118 : GuiDialog(lv, "character", qt_("Text Style")), font_(ignore_font),
119 toggleall_(false), reset_lang_(false)
123 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
124 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
125 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
127 connect(miscCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
128 connect(sizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
129 connect(familyCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
130 connect(seriesCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
131 connect(shapeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
132 connect(colorCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
133 connect(langCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
134 connect(toggleallCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
137 // On Mac it's common to have tool windows which are always in the
138 // foreground and are hidden when the main window is not focused.
139 setWindowFlags(Qt::Tool);
140 autoapplyCB->setChecked(true);
143 family = familyData();
144 series = seriesData();
149 language = languageData(true);
151 for (QList<FamilyPair>::const_iterator cit = family.begin();
152 cit != family.end(); ++cit) {
153 familyCO->addItem(cit->first);
156 for (QList<SeriesPair>::const_iterator cit = series.begin();
157 cit != series.end(); ++cit) {
158 seriesCO->addItem(cit->first);
160 for (QList<ShapePair>::const_iterator cit = shape.begin();
161 cit != shape.end(); ++cit) {
162 shapeCO->addItem(cit->first);
164 for (QList<SizePair>::const_iterator cit = size.begin();
165 cit != size.end(); ++cit) {
166 sizeCO->addItem(cit->first);
168 for (QList<BarPair>::const_iterator cit = bar.begin();
169 cit != bar.end(); ++cit) {
170 miscCO->addItem(cit->first);
172 for (QList<ColorPair>::const_iterator cit = color.begin();
173 cit != color.end(); ++cit) {
174 colorCO->addItem(cit->first);
176 for (QList<LanguagePair>::const_iterator cit = language.begin();
177 cit != language.end(); ++cit) {
178 langCO->addItem(cit->first);
181 bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
183 bc().setApply(applyPB);
184 bc().setCancel(closePB);
185 bc().addReadOnly(familyCO);
186 bc().addReadOnly(seriesCO);
187 bc().addReadOnly(sizeCO);
188 bc().addReadOnly(shapeCO);
189 bc().addReadOnly(miscCO);
190 bc().addReadOnly(langCO);
191 bc().addReadOnly(colorCO);
192 bc().addReadOnly(toggleallCB);
193 bc().addReadOnly(autoapplyCB);
195 // FIXME: hack to work around resizing bug in Qt >= 4.2
196 // bug verified with Qt 4.2.{0-3} (JSpitzm)
197 #if QT_VERSION >= 0x040200
198 // qt resizes the comboboxes only after show(), so ...
204 void GuiCharacter::change_adaptor()
208 if (!autoapplyCB->isChecked())
211 // to be really good here, we should set the combos to the values of
212 // the current text, and make it appear as "no change" if the values
213 // stay the same between applys. Might be difficult though wrt to a
214 // moved cursor - jbl
216 familyCO->setCurrentIndex(0);
217 seriesCO->setCurrentIndex(0);
218 sizeCO->setCurrentIndex(0);
219 shapeCO->setCurrentIndex(0);
220 miscCO->setCurrentIndex(0);
221 langCO->setCurrentIndex(0);
222 colorCO->setCurrentIndex(0);
227 static int findPos2nd(QList<pair<QString, B> > const & vec, B const & val)
229 for (int i = 0; i != vec.size(); ++i)
230 if (vec[i].second == val)
236 void GuiCharacter::updateContents()
238 familyCO->setCurrentIndex(findPos2nd(family, getFamily()));
239 seriesCO->setCurrentIndex(findPos2nd(series, getSeries()));
240 shapeCO->setCurrentIndex(findPos2nd(shape, getShape()));
241 sizeCO->setCurrentIndex(findPos2nd(size, getSize()));
242 miscCO->setCurrentIndex(findPos2nd(bar, getBar()));
243 colorCO->setCurrentIndex(findPos2nd(color, getColor()));
244 langCO->setCurrentIndex(findPos2nd(language, getLanguage()));
246 toggleallCB->setChecked(toggleall_);
250 void GuiCharacter::applyView()
252 setFamily(family[familyCO->currentIndex()].second);
253 setSeries(series[seriesCO->currentIndex()].second);
254 setShape(shape[shapeCO->currentIndex()].second);
255 setSize(size[sizeCO->currentIndex()].second);
256 setBar(bar[miscCO->currentIndex()].second);
257 setColor(color[colorCO->currentIndex()].second);
258 setLanguage(language[langCO->currentIndex()].second);
260 toggleall_ = toggleallCB->isChecked();
264 bool GuiCharacter::initialiseParams(string const &)
266 // so that the user can press Ok
267 if (getFamily() != IGNORE_FAMILY
268 || getSeries() != IGNORE_SERIES
269 || getShape() != IGNORE_SHAPE
270 || getSize() != FONT_SIZE_IGNORE
271 || getBar() != IGNORE
272 || getColor() != Color_ignore
273 || font_.language() != ignore_language)
274 setButtonsValid(true);
280 void GuiCharacter::dispatchParams()
282 dispatch(FuncRequest(getLfun(), font_.toString(toggleall_)));
286 FontFamily GuiCharacter::getFamily() const
288 return font_.fontInfo().family();
292 void GuiCharacter::setFamily(FontFamily val)
294 font_.fontInfo().setFamily(val);
298 FontSeries GuiCharacter::getSeries() const
300 return font_.fontInfo().series();
304 void GuiCharacter::setSeries(FontSeries val)
306 font_.fontInfo().setSeries(val);
310 FontShape GuiCharacter::getShape() const
312 return font_.fontInfo().shape();
316 void GuiCharacter::setShape(FontShape val)
318 font_.fontInfo().setShape(val);
322 FontSize GuiCharacter::getSize() const
324 return font_.fontInfo().size();
328 void GuiCharacter::setSize(FontSize val)
330 font_.fontInfo().setSize(val);
334 FontState GuiCharacter::getBar() const
336 if (font_.fontInfo().emph() == FONT_TOGGLE)
339 if (font_.fontInfo().underbar() == FONT_TOGGLE)
340 return UNDERBAR_TOGGLE;
342 if (font_.fontInfo().noun() == FONT_TOGGLE)
345 if (font_.fontInfo().emph() == FONT_IGNORE
346 && font_.fontInfo().underbar() == FONT_IGNORE
347 && font_.fontInfo().noun() == FONT_IGNORE)
354 void GuiCharacter::setBar(FontState val)
358 font_.fontInfo().setEmph(FONT_IGNORE);
359 font_.fontInfo().setUnderbar(FONT_IGNORE);
360 font_.fontInfo().setNoun(FONT_IGNORE);
364 font_.fontInfo().setEmph(FONT_TOGGLE);
367 case UNDERBAR_TOGGLE:
368 font_.fontInfo().setUnderbar(FONT_TOGGLE);
372 font_.fontInfo().setNoun(FONT_TOGGLE);
376 font_.fontInfo().setEmph(FONT_INHERIT);
377 font_.fontInfo().setUnderbar(FONT_INHERIT);
378 font_.fontInfo().setNoun(FONT_INHERIT);
384 ColorCode GuiCharacter::getColor() const
386 return font_.fontInfo().color();
390 void GuiCharacter::setColor(ColorCode val)
404 font_.fontInfo().setColor(val);
412 QString GuiCharacter::getLanguage() const
416 if (font_.language())
417 return toqstr(font_.language()->lang());
422 void GuiCharacter::setLanguage(QString const & val)
425 font_.setLanguage(ignore_language);
426 else if (val == "reset") {
428 // Ignored in getLanguage, but needed for dispatchParams
429 font_.setLanguage(buffer().params().language);
431 font_.setLanguage(languages.getLanguage(fromqstr(val)));
436 Dialog * createGuiCharacter(GuiView & lv) { return new GuiCharacter(lv); }
439 } // namespace frontend
442 #include "GuiCharacter_moc.cpp"