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>
30 typedef QController<ControlCharacter, QView<QCharacterDialog> > base_class;
33 QCharacter::QCharacter(Dialog & parent)
34 : base_class(parent, lyx::to_utf8(_("Text Style")))
39 void QCharacter::build_dialog()
41 dialog_.reset(new QCharacterDialog(this));
43 family = getFamilyData();
44 series = getSeriesData();
45 shape = getShapeData();
48 color = getColorData();
49 language = getLanguageData(true);
51 for (vector<FamilyPair>::const_iterator cit = family.begin();
52 cit != family.end(); ++cit) {
53 dialog_->familyCO->addItem(toqstr(cit->first));
56 for (vector<SeriesPair>::const_iterator cit = series.begin();
57 cit != series.end(); ++cit) {
58 dialog_->seriesCO->addItem(toqstr(cit->first));
60 for (vector<ShapePair>::const_iterator cit = shape.begin();
61 cit != shape.end(); ++cit) {
62 dialog_->shapeCO->addItem(toqstr(cit->first));
64 for (vector<SizePair>::const_iterator cit = size.begin();
65 cit != size.end(); ++cit) {
66 dialog_->sizeCO->addItem(toqstr(cit->first));
68 for (vector<BarPair>::const_iterator cit = bar.begin();
69 cit != bar.end(); ++cit) {
70 dialog_->miscCO->addItem(toqstr(cit->first));
72 for (vector<ColorPair>::const_iterator cit = color.begin();
73 cit != color.end(); ++cit) {
74 dialog_->colorCO->addItem(toqstr(cit->first));
76 for (vector<LanguagePair>::const_iterator cit = language.begin();
77 cit != language.end(); ++cit) {
78 dialog_->langCO->addItem(toqstr(cit->first));
81 bcview().setOK(dialog_->okPB);
82 bcview().setApply(dialog_->applyPB);
83 bcview().setCancel(dialog_->closePB);
84 bcview().addReadOnly(dialog_->familyCO);
85 bcview().addReadOnly(dialog_->seriesCO);
86 bcview().addReadOnly(dialog_->sizeCO);
87 bcview().addReadOnly(dialog_->shapeCO);
88 bcview().addReadOnly(dialog_->miscCO);
89 bcview().addReadOnly(dialog_->langCO);
90 bcview().addReadOnly(dialog_->colorCO);
91 bcview().addReadOnly(dialog_->toggleallCB);
92 bcview().addReadOnly(dialog_->autoapplyCB);
98 template<class A, class B>
99 int findPos2nd(vector<std::pair<A,B> > const & vec, B const & val)
101 typedef typename vector<std::pair<A, B> >::const_iterator
104 const_iterator cit = vec.begin();
105 for (; cit != vec.end(); ++cit) {
106 if (cit->second == val)
107 return int(cit - vec.begin());
115 void QCharacter::update_contents()
117 ControlCharacter const & ctrl = controller();
119 dialog_->familyCO->setCurrentIndex(findPos2nd(family,
121 dialog_->seriesCO->setCurrentIndex(findPos2nd(series,
123 dialog_->shapeCO->setCurrentIndex(findPos2nd(shape, ctrl.getShape()));
124 dialog_->sizeCO->setCurrentIndex(findPos2nd(size, ctrl.getSize()));
125 dialog_->miscCO->setCurrentIndex(findPos2nd(bar, ctrl.getBar()));
126 dialog_->colorCO->setCurrentIndex(findPos2nd(color, ctrl.getColor()));
127 dialog_->langCO->setCurrentIndex(findPos2nd(language,
128 ctrl.getLanguage()));
130 dialog_->toggleallCB->setChecked(ctrl.getToggleAll());
134 void QCharacter::apply()
136 ControlCharacter & ctrl = controller();
138 ctrl.setFamily(family[dialog_->familyCO->currentIndex()].second);
139 ctrl.setSeries(series[dialog_->seriesCO->currentIndex()].second);
140 ctrl.setShape(shape[dialog_->shapeCO->currentIndex()].second);
141 ctrl.setSize(size[dialog_->sizeCO->currentIndex()].second);
142 ctrl.setBar(bar[dialog_->miscCO->currentIndex()].second);
143 ctrl.setColor(color[dialog_->colorCO->currentIndex()].second);
144 ctrl.setLanguage(language[dialog_->langCO->currentIndex()].second);
146 ctrl.setToggleAll(dialog_->toggleallCB->isChecked());
149 } // namespace frontend