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 "QCharacter.h"
15 #include "ControlCharacter.h"
17 #include "qt_helpers.h"
22 #include <QCloseEvent>
29 /////////////////////////////////////////////////////////////////////
33 /////////////////////////////////////////////////////////////////////
35 QCharacterDialog::QCharacterDialog(QCharacter * form)
39 connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
40 connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply()));
41 connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
43 connect(miscCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
44 connect(sizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
45 connect(familyCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
46 connect(seriesCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
47 connect(shapeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
48 connect(colorCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
49 connect(langCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
50 connect(toggleallCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
54 void QCharacterDialog::change_adaptor()
58 if (!autoapplyCB->isChecked())
61 // to be really good here, we should set the combos to the values of
62 // the current text, and make it appear as "no change" if the values
63 // stay the same between applys. Might be difficult though wrt to a
66 familyCO->setCurrentIndex(0);
67 seriesCO->setCurrentIndex(0);
68 sizeCO->setCurrentIndex(0);
69 shapeCO->setCurrentIndex(0);
70 miscCO->setCurrentIndex(0);
71 langCO->setCurrentIndex(0);
72 colorCO->setCurrentIndex(0);
76 void QCharacterDialog::closeEvent(QCloseEvent * e)
83 /////////////////////////////////////////////////////////////////////
87 /////////////////////////////////////////////////////////////////////
89 typedef QController<ControlCharacter, QView<QCharacterDialog> > CharacterBase;
91 QCharacter::QCharacter(Dialog & parent)
92 : CharacterBase(parent, _("Text Style"))
97 void QCharacter::build_dialog()
99 dialog_.reset(new QCharacterDialog(this));
101 family = getFamilyData();
102 series = getSeriesData();
103 shape = getShapeData();
104 size = getSizeData();
106 color = getColorData();
107 language = getLanguageData(true);
109 for (vector<FamilyPair>::const_iterator cit = family.begin();
110 cit != family.end(); ++cit) {
111 dialog_->familyCO->addItem(toqstr(cit->first));
114 for (vector<SeriesPair>::const_iterator cit = series.begin();
115 cit != series.end(); ++cit) {
116 dialog_->seriesCO->addItem(toqstr(cit->first));
118 for (vector<ShapePair>::const_iterator cit = shape.begin();
119 cit != shape.end(); ++cit) {
120 dialog_->shapeCO->addItem(toqstr(cit->first));
122 for (vector<SizePair>::const_iterator cit = size.begin();
123 cit != size.end(); ++cit) {
124 dialog_->sizeCO->addItem(toqstr(cit->first));
126 for (vector<BarPair>::const_iterator cit = bar.begin();
127 cit != bar.end(); ++cit) {
128 dialog_->miscCO->addItem(toqstr(cit->first));
130 for (vector<ColorPair>::const_iterator cit = color.begin();
131 cit != color.end(); ++cit) {
132 dialog_->colorCO->addItem(toqstr(cit->first));
134 for (vector<LanguagePair>::const_iterator cit = language.begin();
135 cit != language.end(); ++cit) {
136 dialog_->langCO->addItem(toqstr(cit->first));
139 bcview().setOK(dialog_->okPB);
140 bcview().setApply(dialog_->applyPB);
141 bcview().setCancel(dialog_->closePB);
142 bcview().addReadOnly(dialog_->familyCO);
143 bcview().addReadOnly(dialog_->seriesCO);
144 bcview().addReadOnly(dialog_->sizeCO);
145 bcview().addReadOnly(dialog_->shapeCO);
146 bcview().addReadOnly(dialog_->miscCO);
147 bcview().addReadOnly(dialog_->langCO);
148 bcview().addReadOnly(dialog_->colorCO);
149 bcview().addReadOnly(dialog_->toggleallCB);
150 bcview().addReadOnly(dialog_->autoapplyCB);
152 // FIXME: hack to work around resizing bug in Qt >= 4.2
153 // bug verified with Qt 4.2.{0-3} (JSpitzm)
154 #if QT_VERSION >= 0x040200
155 // qt resizes the comboboxes only after show(), so ...
163 template<class A, class B>
164 int findPos2nd(vector<std::pair<A,B> > const & vec, B const & val)
166 typedef typename vector<std::pair<A, B> >::const_iterator
169 const_iterator cit = vec.begin();
170 for (; cit != vec.end(); ++cit) {
171 if (cit->second == val)
172 return int(cit - vec.begin());
180 void QCharacter::update_contents()
182 ControlCharacter const & ctrl = controller();
184 dialog_->familyCO->setCurrentIndex(findPos2nd(family,
186 dialog_->seriesCO->setCurrentIndex(findPos2nd(series,
188 dialog_->shapeCO->setCurrentIndex(findPos2nd(shape, ctrl.getShape()));
189 dialog_->sizeCO->setCurrentIndex(findPos2nd(size, ctrl.getSize()));
190 dialog_->miscCO->setCurrentIndex(findPos2nd(bar, ctrl.getBar()));
191 dialog_->colorCO->setCurrentIndex(findPos2nd(color, ctrl.getColor()));
192 dialog_->langCO->setCurrentIndex(findPos2nd(language,
193 ctrl.getLanguage()));
195 dialog_->toggleallCB->setChecked(ctrl.getToggleAll());
199 void QCharacter::apply()
201 ControlCharacter & ctrl = controller();
203 ctrl.setFamily(family[dialog_->familyCO->currentIndex()].second);
204 ctrl.setSeries(series[dialog_->seriesCO->currentIndex()].second);
205 ctrl.setShape(shape[dialog_->shapeCO->currentIndex()].second);
206 ctrl.setSize(size[dialog_->sizeCO->currentIndex()].second);
207 ctrl.setBar(bar[dialog_->miscCO->currentIndex()].second);
208 ctrl.setColor(color[dialog_->colorCO->currentIndex()].second);
209 ctrl.setLanguage(language[dialog_->langCO->currentIndex()].second);
211 ctrl.setToggleAll(dialog_->toggleallCB->isChecked());
214 } // namespace frontend
217 #include "QCharacter_moc.cpp"