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 #include "QCharacter.h"
16 #include "ControlCharacter.h"
17 #include "QCharacterDialog.h"
20 #include "qt_helpers.h"
22 #include <qpushbutton.h>
23 #include <qcheckbox.h>
24 #include <qcombobox.h>
29 using frnt::ColorPair;
30 using frnt::FamilyPair;
31 using frnt::getBarData;
32 using frnt::getColorData;
33 using frnt::getFamilyData;
34 using frnt::getLanguageData;
35 using frnt::getSeriesData;
36 using frnt::getShapeData;
37 using frnt::getSizeData;
38 using frnt::LanguagePair;
39 using frnt::SeriesPair;
40 using frnt::ShapePair;
46 typedef QController<ControlCharacter, QView<QCharacterDialog> > base_class;
49 QCharacter::QCharacter(Dialog & parent)
50 : base_class(parent, _("LyX: Change Text Style"))
55 void QCharacter::build_dialog()
57 dialog_.reset(new QCharacterDialog(this));
59 family = getFamilyData();
60 series = getSeriesData();
61 shape = getShapeData();
64 color = getColorData();
65 language = getLanguageData(true);
67 for (vector<FamilyPair>::const_iterator cit = family.begin();
68 cit != family.end(); ++cit) {
69 dialog_->familyCO->insertItem(toqstr(cit->first), -1);
72 for (vector<SeriesPair>::const_iterator cit = series.begin();
73 cit != series.end(); ++cit) {
74 dialog_->seriesCO->insertItem(toqstr(cit->first), -1);
76 for (vector<ShapePair>::const_iterator cit = shape.begin();
77 cit != shape.end(); ++cit) {
78 dialog_->shapeCO->insertItem(toqstr(cit->first), -1);
80 for (vector<SizePair>::const_iterator cit = size.begin();
81 cit != size.end(); ++cit) {
82 dialog_->sizeCO->insertItem(toqstr(cit->first), -1);
84 for (vector<BarPair>::const_iterator cit = bar.begin();
85 cit != bar.end(); ++cit) {
86 dialog_->miscCO->insertItem(toqstr(cit->first), -1);
88 for (vector<ColorPair>::const_iterator cit = color.begin();
89 cit != color.end(); ++cit) {
90 dialog_->colorCO->insertItem(toqstr(cit->first), -1);
92 for (vector<LanguagePair>::const_iterator cit = language.begin();
93 cit != language.end(); ++cit) {
94 dialog_->langCO->insertItem(toqstr(cit->first), -1);
97 bcview().setOK(dialog_->okPB);
98 bcview().setApply(dialog_->applyPB);
99 bcview().setCancel(dialog_->closePB);
100 bcview().addReadOnly(dialog_->familyCO);
101 bcview().addReadOnly(dialog_->seriesCO);
102 bcview().addReadOnly(dialog_->sizeCO);
103 bcview().addReadOnly(dialog_->shapeCO);
104 bcview().addReadOnly(dialog_->miscCO);
105 bcview().addReadOnly(dialog_->langCO);
106 bcview().addReadOnly(dialog_->colorCO);
107 bcview().addReadOnly(dialog_->toggleallCB);
108 bcview().addReadOnly(dialog_->autoapplyCB);
114 template<class A, class B>
115 int findPos2nd(vector<std::pair<A,B> > const & vec, B const & val)
117 typedef typename vector<std::pair<A, B> >::const_iterator
120 const_iterator cit = vec.begin();
121 for (; cit != vec.end(); ++cit) {
122 if (cit->second == val)
123 return int(cit - vec.begin());
131 void QCharacter::update_contents()
133 ControlCharacter const & ctrl = controller();
135 dialog_->familyCO->setCurrentItem(findPos2nd(family,
137 dialog_->seriesCO->setCurrentItem(findPos2nd(series,
139 dialog_->shapeCO->setCurrentItem(findPos2nd(shape, ctrl.getShape()));
140 dialog_->sizeCO->setCurrentItem(findPos2nd(size, ctrl.getSize()));
141 dialog_->miscCO->setCurrentItem(findPos2nd(bar, ctrl.getBar()));
142 dialog_->colorCO->setCurrentItem(findPos2nd(color, ctrl.getColor()));
143 dialog_->langCO->setCurrentItem(findPos2nd(language,
144 ctrl.getLanguage()));
146 dialog_->toggleallCB->setChecked(ctrl.getToggleAll());
150 void QCharacter::apply()
152 ControlCharacter & ctrl = controller();
154 ctrl.setFamily(family[dialog_->familyCO->currentItem()].second);
155 ctrl.setSeries(series[dialog_->seriesCO->currentItem()].second);
156 ctrl.setShape(shape[dialog_->shapeCO->currentItem()].second);
157 ctrl.setSize(size[dialog_->sizeCO->currentItem()].second);
158 ctrl.setBar(bar[dialog_->miscCO->currentItem()].second);
159 ctrl.setColor(color[dialog_->colorCO->currentItem()].second);
160 ctrl.setLanguage(language[dialog_->langCO->currentItem()].second);
162 ctrl.setToggleAll(dialog_->toggleallCB->isChecked());