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;
37 QCharacter::QCharacter()
38 : base_class(_("Character"))
43 void QCharacter::build_dialog()
45 dialog_.reset(new QCharacterDialog(this));
47 family = getFamilyData();
48 series = getSeriesData();
49 shape = getShapeData();
52 color = getColorData();
53 language = getLanguageData(true);
55 for (vector<FamilyPair>::const_iterator cit = family.begin();
56 cit != family.end(); ++cit) {
57 dialog_->familyCO->insertItem(cit->first.c_str(), -1);
59 for (vector<SeriesPair>::const_iterator cit = series.begin();
60 cit != series.end(); ++cit) {
61 dialog_->seriesCO->insertItem(cit->first.c_str(), -1);
63 for (vector<ShapePair>::const_iterator cit = shape.begin();
64 cit != shape.end(); ++cit) {
65 dialog_->shapeCO->insertItem(cit->first.c_str(), -1);
67 for (vector<SizePair>::const_iterator cit = size.begin();
68 cit != size.end(); ++cit) {
69 dialog_->sizeCO->insertItem(cit->first.c_str(), -1);
71 for (vector<BarPair>::const_iterator cit = bar.begin();
72 cit != bar.end(); ++cit) {
73 dialog_->miscCO->insertItem(cit->first.c_str(), -1);
75 for (vector<ColorPair>::const_iterator cit = color.begin();
76 cit != color.end(); ++cit) {
77 dialog_->colorCO->insertItem(cit->first.c_str(), -1);
79 for (vector<LanguagePair>::const_iterator cit = language.begin();
80 cit != language.end(); ++cit) {
81 dialog_->langCO->insertItem(cit->first.c_str(), -1);
84 bc().setOK(dialog_->okPB);
85 bc().setApply(dialog_->applyPB);
86 bc().setCancel(dialog_->closePB);
87 bc().addReadOnly(dialog_->familyCO);
88 bc().addReadOnly(dialog_->seriesCO);
89 bc().addReadOnly(dialog_->sizeCO);
90 bc().addReadOnly(dialog_->shapeCO);
91 bc().addReadOnly(dialog_->miscCO);
92 bc().addReadOnly(dialog_->langCO);
93 bc().addReadOnly(dialog_->colorCO);
94 bc().addReadOnly(dialog_->toggleallCB);
95 bc().addReadOnly(dialog_->autoapplyCB);
101 template<class A, class B>
102 int findPos2nd(vector<std::pair<A,B> > const & vec, B const & val)
104 typedef typename vector<std::pair<A, B> >::const_iterator
107 const_iterator cit = vec.begin();
108 for (; cit != vec.end(); ++cit) {
109 if (cit->second == val)
110 return int(cit - vec.begin());
118 void QCharacter::update_contents()
120 dialog_->familyCO->setCurrentItem(findPos2nd(family, controller().getFamily()));
121 dialog_->seriesCO->setCurrentItem(findPos2nd(series, controller().getSeries()));
122 dialog_->shapeCO->setCurrentItem(findPos2nd(shape, controller().getShape()));
123 dialog_->sizeCO->setCurrentItem(findPos2nd(size, controller().getSize()));
124 dialog_->miscCO->setCurrentItem(findPos2nd(bar, controller().getBar()));
125 dialog_->colorCO->setCurrentItem(findPos2nd(color, controller().getColor()));
126 dialog_->langCO->setCurrentItem(findPos2nd(language, controller().getLanguage()));
128 dialog_->toggleallCB->setChecked(controller().getToggleAll());
132 void QCharacter::apply()
134 controller().setFamily(family[dialog_->familyCO->currentItem()].second);
135 controller().setSeries(series[dialog_->seriesCO->currentItem()].second);
136 controller().setShape(shape[dialog_->shapeCO->currentItem()].second);
137 controller().setSize(size[dialog_->sizeCO->currentItem()].second);
138 controller().setBar(bar[dialog_->miscCO->currentItem()].second);
139 controller().setColor(color[dialog_->colorCO->currentItem()].second);
140 controller().setLanguage(language[dialog_->langCO->currentItem()].second);
142 controller().setToggleAll(dialog_->toggleallCB->isChecked());