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
15 #pragma implementation
18 #include "ControlCharacter.h"
19 #include "QCharacterDialog.h"
20 #include "QCharacter.h"
24 #include "support/lstrings.h"
26 #include <qcombobox.h>
27 #include <qcheckbox.h>
28 #include <qpushbutton.h>
35 typedef Qt2CB<ControlCharacter, Qt2DB<QCharacterDialog> > base_class;
38 QCharacter::QCharacter()
39 : base_class(_("Character"))
44 void QCharacter::build_dialog()
46 dialog_.reset(new QCharacterDialog(this));
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 dialog_->familyCO->insertItem(cit->first.c_str(), -1);
61 for (vector<SeriesPair>::const_iterator cit = series.begin();
62 cit != series.end(); ++cit) {
63 dialog_->seriesCO->insertItem(cit->first.c_str(), -1);
65 for (vector<ShapePair>::const_iterator cit = shape.begin();
66 cit != shape.end(); ++cit) {
67 dialog_->shapeCO->insertItem(cit->first.c_str(), -1);
69 for (vector<SizePair>::const_iterator cit = size.begin();
70 cit != size.end(); ++cit) {
71 dialog_->sizeCO->insertItem(cit->first.c_str(), -1);
73 for (vector<BarPair>::const_iterator cit = bar.begin();
74 cit != bar.end(); ++cit) {
75 dialog_->miscCO->insertItem(cit->first.c_str(), -1);
77 for (vector<ColorPair>::const_iterator cit = color.begin();
78 cit != color.end(); ++cit) {
79 dialog_->colorCO->insertItem(cit->first.c_str(), -1);
81 for (vector<LanguagePair>::const_iterator cit = language.begin();
82 cit != language.end(); ++cit) {
83 dialog_->langCO->insertItem(cit->first.c_str(), -1);
86 bc().setOK(dialog_->okPB);
87 bc().setApply(dialog_->applyPB);
88 bc().setCancel(dialog_->closePB);
89 bc().addReadOnly(dialog_->familyCO);
90 bc().addReadOnly(dialog_->seriesCO);
91 bc().addReadOnly(dialog_->sizeCO);
92 bc().addReadOnly(dialog_->shapeCO);
93 bc().addReadOnly(dialog_->miscCO);
94 bc().addReadOnly(dialog_->langCO);
95 bc().addReadOnly(dialog_->colorCO);
96 bc().addReadOnly(dialog_->toggleallCB);
97 bc().addReadOnly(dialog_->autoapplyCB);
103 template<class A, class B>
104 int findPos2nd(vector<std::pair<A,B> > const & vec, B const & val)
106 typedef typename vector<std::pair<A, B> >::const_iterator
109 const_iterator cit = vec.begin();
110 for (; cit != vec.end(); ++cit) {
111 if (cit->second == val)
112 return int(cit - vec.begin());
120 void QCharacter::update_contents()
122 ControlCharacter const & ctrl = controller();
124 dialog_->familyCO->setCurrentItem(findPos2nd(family,
126 dialog_->seriesCO->setCurrentItem(findPos2nd(series,
128 dialog_->shapeCO->setCurrentItem(findPos2nd(shape, ctrl.getShape()));
129 dialog_->sizeCO->setCurrentItem(findPos2nd(size, ctrl.getSize()));
130 dialog_->miscCO->setCurrentItem(findPos2nd(bar, ctrl.getBar()));
131 dialog_->colorCO->setCurrentItem(findPos2nd(color, ctrl.getColor()));
132 dialog_->langCO->setCurrentItem(findPos2nd(language,
133 ctrl.getLanguage()));
135 dialog_->toggleallCB->setChecked(ctrl.getToggleAll());
139 void QCharacter::apply()
141 ControlCharacter & ctrl = controller();
143 ctrl.setFamily(family[dialog_->familyCO->currentItem()].second);
144 ctrl.setSeries(series[dialog_->seriesCO->currentItem()].second);
145 ctrl.setShape(shape[dialog_->shapeCO->currentItem()].second);
146 ctrl.setSize(size[dialog_->sizeCO->currentItem()].second);
147 ctrl.setBar(bar[dialog_->miscCO->currentItem()].second);
148 ctrl.setColor(color[dialog_->colorCO->currentItem()].second);
149 ctrl.setLanguage(language[dialog_->langCO->currentItem()].second);
151 ctrl.setToggleAll(dialog_->toggleallCB->isChecked());