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"
15 #include "qt_helpers.h"
16 #include "frontend_helpers.h"
19 #include <QCloseEvent>
26 /////////////////////////////////////////////////////////////////////
30 /////////////////////////////////////////////////////////////////////
32 GuiCharacterDialog::GuiCharacterDialog(GuiCharacter * form)
36 connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
37 connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply()));
38 connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
40 connect(miscCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
41 connect(sizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
42 connect(familyCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
43 connect(seriesCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
44 connect(shapeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
45 connect(colorCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
46 connect(langCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
47 connect(toggleallCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
51 void GuiCharacterDialog::change_adaptor()
55 if (!autoapplyCB->isChecked())
58 // to be really good here, we should set the combos to the values of
59 // the current text, and make it appear as "no change" if the values
60 // stay the same between applys. Might be difficult though wrt to a
63 familyCO->setCurrentIndex(0);
64 seriesCO->setCurrentIndex(0);
65 sizeCO->setCurrentIndex(0);
66 shapeCO->setCurrentIndex(0);
67 miscCO->setCurrentIndex(0);
68 langCO->setCurrentIndex(0);
69 colorCO->setCurrentIndex(0);
73 void GuiCharacterDialog::closeEvent(QCloseEvent * e)
80 /////////////////////////////////////////////////////////////////////
84 /////////////////////////////////////////////////////////////////////
87 GuiCharacter::GuiCharacter(GuiDialog & parent)
88 : GuiView<GuiCharacterDialog>(parent, _("Text Style"))
93 void GuiCharacter::build_dialog()
95 dialog_.reset(new GuiCharacterDialog(this));
97 family = getFamilyData();
98 series = getSeriesData();
99 shape = getShapeData();
100 size = getSizeData();
102 color = getColorData();
103 language = getLanguageData(true);
105 for (vector<FamilyPair>::const_iterator cit = family.begin();
106 cit != family.end(); ++cit) {
107 dialog_->familyCO->addItem(toqstr(cit->first));
110 for (vector<SeriesPair>::const_iterator cit = series.begin();
111 cit != series.end(); ++cit) {
112 dialog_->seriesCO->addItem(toqstr(cit->first));
114 for (vector<ShapePair>::const_iterator cit = shape.begin();
115 cit != shape.end(); ++cit) {
116 dialog_->shapeCO->addItem(toqstr(cit->first));
118 for (vector<SizePair>::const_iterator cit = size.begin();
119 cit != size.end(); ++cit) {
120 dialog_->sizeCO->addItem(toqstr(cit->first));
122 for (vector<BarPair>::const_iterator cit = bar.begin();
123 cit != bar.end(); ++cit) {
124 dialog_->miscCO->addItem(toqstr(cit->first));
126 for (vector<ColorPair>::const_iterator cit = color.begin();
127 cit != color.end(); ++cit) {
128 dialog_->colorCO->addItem(toqstr(cit->first));
130 for (vector<LanguagePair>::const_iterator cit = language.begin();
131 cit != language.end(); ++cit) {
132 dialog_->langCO->addItem(toqstr(cit->first));
135 bc().setOK(dialog_->okPB);
136 bc().setApply(dialog_->applyPB);
137 bc().setCancel(dialog_->closePB);
138 bc().addReadOnly(dialog_->familyCO);
139 bc().addReadOnly(dialog_->seriesCO);
140 bc().addReadOnly(dialog_->sizeCO);
141 bc().addReadOnly(dialog_->shapeCO);
142 bc().addReadOnly(dialog_->miscCO);
143 bc().addReadOnly(dialog_->langCO);
144 bc().addReadOnly(dialog_->colorCO);
145 bc().addReadOnly(dialog_->toggleallCB);
146 bc().addReadOnly(dialog_->autoapplyCB);
148 // FIXME: hack to work around resizing bug in Qt >= 4.2
149 // bug verified with Qt 4.2.{0-3} (JSpitzm)
150 #if QT_VERSION >= 0x040200
151 // qt resizes the comboboxes only after show(), so ...
159 template<class A, class B>
160 int findPos2nd(vector<std::pair<A,B> > const & vec, B const & val)
162 typedef typename vector<std::pair<A, B> >::const_iterator
165 const_iterator cit = vec.begin();
166 for (; cit != vec.end(); ++cit) {
167 if (cit->second == val)
168 return int(cit - vec.begin());
176 void GuiCharacter::update_contents()
178 ControlCharacter const & ctrl = controller();
180 dialog_->familyCO->setCurrentIndex(findPos2nd(family,
182 dialog_->seriesCO->setCurrentIndex(findPos2nd(series,
184 dialog_->shapeCO->setCurrentIndex(findPos2nd(shape, ctrl.getShape()));
185 dialog_->sizeCO->setCurrentIndex(findPos2nd(size, ctrl.getSize()));
186 dialog_->miscCO->setCurrentIndex(findPos2nd(bar, ctrl.getBar()));
187 dialog_->colorCO->setCurrentIndex(findPos2nd(color, ctrl.getColor()));
188 dialog_->langCO->setCurrentIndex(findPos2nd(language,
189 ctrl.getLanguage()));
191 dialog_->toggleallCB->setChecked(ctrl.getToggleAll());
195 void GuiCharacter::applyView()
197 ControlCharacter & ctrl = controller();
199 ctrl.setFamily(family[dialog_->familyCO->currentIndex()].second);
200 ctrl.setSeries(series[dialog_->seriesCO->currentIndex()].second);
201 ctrl.setShape(shape[dialog_->shapeCO->currentIndex()].second);
202 ctrl.setSize(size[dialog_->sizeCO->currentIndex()].second);
203 ctrl.setBar(bar[dialog_->miscCO->currentIndex()].second);
204 ctrl.setColor(color[dialog_->colorCO->currentIndex()].second);
205 ctrl.setLanguage(language[dialog_->langCO->currentIndex()].second);
207 ctrl.setToggleAll(dialog_->toggleallCB->isChecked());
210 } // namespace frontend
213 #include "GuiCharacter_moc.cpp"