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"
16 #include "QCharacterDialog.h"
18 #include "qt_helpers.h"
22 #include <qpushbutton.h>
23 #include <qcheckbox.h>
24 #include <qcombobox.h>
31 typedef QController<ControlCharacter, QView<QCharacterDialog> > base_class;
34 QCharacter::QCharacter(Dialog & parent)
35 : base_class(parent, _("LyX: Change Text Style"))
40 void QCharacter::build_dialog()
42 dialog_.reset(new QCharacterDialog(this));
44 family = getFamilyData();
45 series = getSeriesData();
46 shape = getShapeData();
49 color = getColorData();
50 language = getLanguageData(true);
52 for (vector<FamilyPair>::const_iterator cit = family.begin();
53 cit != family.end(); ++cit) {
54 dialog_->familyCO->insertItem(toqstr(cit->first), -1);
57 for (vector<SeriesPair>::const_iterator cit = series.begin();
58 cit != series.end(); ++cit) {
59 dialog_->seriesCO->insertItem(toqstr(cit->first), -1);
61 for (vector<ShapePair>::const_iterator cit = shape.begin();
62 cit != shape.end(); ++cit) {
63 dialog_->shapeCO->insertItem(toqstr(cit->first), -1);
65 for (vector<SizePair>::const_iterator cit = size.begin();
66 cit != size.end(); ++cit) {
67 dialog_->sizeCO->insertItem(toqstr(cit->first), -1);
69 for (vector<BarPair>::const_iterator cit = bar.begin();
70 cit != bar.end(); ++cit) {
71 dialog_->miscCO->insertItem(toqstr(cit->first), -1);
73 for (vector<ColorPair>::const_iterator cit = color.begin();
74 cit != color.end(); ++cit) {
75 dialog_->colorCO->insertItem(toqstr(cit->first), -1);
77 for (vector<LanguagePair>::const_iterator cit = language.begin();
78 cit != language.end(); ++cit) {
79 dialog_->langCO->insertItem(toqstr(cit->first), -1);
82 bcview().setOK(dialog_->okPB);
83 bcview().setApply(dialog_->applyPB);
84 bcview().setCancel(dialog_->closePB);
85 bcview().addReadOnly(dialog_->familyCO);
86 bcview().addReadOnly(dialog_->seriesCO);
87 bcview().addReadOnly(dialog_->sizeCO);
88 bcview().addReadOnly(dialog_->shapeCO);
89 bcview().addReadOnly(dialog_->miscCO);
90 bcview().addReadOnly(dialog_->langCO);
91 bcview().addReadOnly(dialog_->colorCO);
92 bcview().addReadOnly(dialog_->toggleallCB);
93 bcview().addReadOnly(dialog_->autoapplyCB);
99 template<class A, class B>
100 int findPos2nd(vector<std::pair<A,B> > const & vec, B const & val)
102 typedef typename vector<std::pair<A, B> >::const_iterator
105 const_iterator cit = vec.begin();
106 for (; cit != vec.end(); ++cit) {
107 if (cit->second == val)
108 return int(cit - vec.begin());
116 void QCharacter::update_contents()
118 ControlCharacter const & ctrl = controller();
120 dialog_->familyCO->setCurrentItem(findPos2nd(family,
122 dialog_->seriesCO->setCurrentItem(findPos2nd(series,
124 dialog_->shapeCO->setCurrentItem(findPos2nd(shape, ctrl.getShape()));
125 dialog_->sizeCO->setCurrentItem(findPos2nd(size, ctrl.getSize()));
126 dialog_->miscCO->setCurrentItem(findPos2nd(bar, ctrl.getBar()));
127 dialog_->colorCO->setCurrentItem(findPos2nd(color, ctrl.getColor()));
128 dialog_->langCO->setCurrentItem(findPos2nd(language,
129 ctrl.getLanguage()));
131 dialog_->toggleallCB->setChecked(ctrl.getToggleAll());
135 void QCharacter::apply()
137 ControlCharacter & ctrl = controller();
139 ctrl.setFamily(family[dialog_->familyCO->currentItem()].second);
140 ctrl.setSeries(series[dialog_->seriesCO->currentItem()].second);
141 ctrl.setShape(shape[dialog_->shapeCO->currentItem()].second);
142 ctrl.setSize(size[dialog_->sizeCO->currentItem()].second);
143 ctrl.setBar(bar[dialog_->miscCO->currentItem()].second);
144 ctrl.setColor(color[dialog_->colorCO->currentItem()].second);
145 ctrl.setLanguage(language[dialog_->langCO->currentItem()].second);
147 ctrl.setToggleAll(dialog_->toggleallCB->isChecked());
150 } // namespace frontend