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"
18 #include "frontend_helpers.h"
21 #include <QCloseEvent>
28 GuiCharacterDialog::GuiCharacterDialog(LyXView & lv)
29 : GuiDialog(lv, "character")
32 setController(new ControlCharacter(*this));
33 setViewTitle(_("Text Style"));
35 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
36 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
37 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
39 connect(miscCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
40 connect(sizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
41 connect(familyCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
42 connect(seriesCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
43 connect(shapeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
44 connect(colorCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
45 connect(langCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
46 connect(toggleallCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
48 family = getFamilyData();
49 series = getSeriesData();
50 shape = getShapeData();
53 color = getColorData();
54 language = getLanguageData(true);
56 for (vector<FamilyPair>::const_iterator cit = family.begin();
57 cit != family.end(); ++cit) {
58 familyCO->addItem(toqstr(cit->first));
61 for (vector<SeriesPair>::const_iterator cit = series.begin();
62 cit != series.end(); ++cit) {
63 seriesCO->addItem(toqstr(cit->first));
65 for (vector<ShapePair>::const_iterator cit = shape.begin();
66 cit != shape.end(); ++cit) {
67 shapeCO->addItem(toqstr(cit->first));
69 for (vector<SizePair>::const_iterator cit = size.begin();
70 cit != size.end(); ++cit) {
71 sizeCO->addItem(toqstr(cit->first));
73 for (vector<BarPair>::const_iterator cit = bar.begin();
74 cit != bar.end(); ++cit) {
75 miscCO->addItem(toqstr(cit->first));
77 for (vector<ColorPair>::const_iterator cit = color.begin();
78 cit != color.end(); ++cit) {
79 colorCO->addItem(toqstr(cit->first));
81 for (vector<LanguagePair>::const_iterator cit = language.begin();
82 cit != language.end(); ++cit) {
83 langCO->addItem(toqstr(cit->first));
86 bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
88 bc().setApply(applyPB);
89 bc().setCancel(closePB);
90 bc().addReadOnly(familyCO);
91 bc().addReadOnly(seriesCO);
92 bc().addReadOnly(sizeCO);
93 bc().addReadOnly(shapeCO);
94 bc().addReadOnly(miscCO);
95 bc().addReadOnly(langCO);
96 bc().addReadOnly(colorCO);
97 bc().addReadOnly(toggleallCB);
98 bc().addReadOnly(autoapplyCB);
100 // FIXME: hack to work around resizing bug in Qt >= 4.2
101 // bug verified with Qt 4.2.{0-3} (JSpitzm)
102 #if QT_VERSION >= 0x040200
103 // qt resizes the comboboxes only after show(), so ...
109 ControlCharacter & GuiCharacterDialog::controller()
111 return static_cast<ControlCharacter &>(GuiDialog::controller());
115 void GuiCharacterDialog::change_adaptor()
119 if (!autoapplyCB->isChecked())
122 // to be really good here, we should set the combos to the values of
123 // the current text, and make it appear as "no change" if the values
124 // stay the same between applys. Might be difficult though wrt to a
125 // moved cursor - jbl
127 familyCO->setCurrentIndex(0);
128 seriesCO->setCurrentIndex(0);
129 sizeCO->setCurrentIndex(0);
130 shapeCO->setCurrentIndex(0);
131 miscCO->setCurrentIndex(0);
132 langCO->setCurrentIndex(0);
133 colorCO->setCurrentIndex(0);
137 void GuiCharacterDialog::closeEvent(QCloseEvent * e)
144 template<class A, class B>
145 static int findPos2nd(vector<std::pair<A,B> > const & vec, B const & val)
147 typedef typename vector<std::pair<A, B> >::const_iterator
150 const_iterator cit = vec.begin();
151 for (; cit != vec.end(); ++cit) {
152 if (cit->second == val)
153 return int(cit - vec.begin());
159 void GuiCharacterDialog::updateContents()
161 ControlCharacter const & ctrl = controller();
163 familyCO->setCurrentIndex(findPos2nd(family,
165 seriesCO->setCurrentIndex(findPos2nd(series,
167 shapeCO->setCurrentIndex(findPos2nd(shape, ctrl.getShape()));
168 sizeCO->setCurrentIndex(findPos2nd(size, ctrl.getSize()));
169 miscCO->setCurrentIndex(findPos2nd(bar, ctrl.getBar()));
170 colorCO->setCurrentIndex(findPos2nd(color, ctrl.getColor()));
171 langCO->setCurrentIndex(findPos2nd(language,
172 ctrl.getLanguage()));
174 toggleallCB->setChecked(ctrl.getToggleAll());
178 void GuiCharacterDialog::applyView()
180 ControlCharacter & ctrl = controller();
182 ctrl.setFamily(family[familyCO->currentIndex()].second);
183 ctrl.setSeries(series[seriesCO->currentIndex()].second);
184 ctrl.setShape(shape[shapeCO->currentIndex()].second);
185 ctrl.setSize(size[sizeCO->currentIndex()].second);
186 ctrl.setBar(bar[miscCO->currentIndex()].second);
187 ctrl.setColor(color[colorCO->currentIndex()].second);
188 ctrl.setLanguage(language[langCO->currentIndex()].second);
190 ctrl.setToggleAll(toggleallCB->isChecked());
193 } // namespace frontend
196 #include "GuiCharacter_moc.cpp"