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 "ControlCharacter.h"
16 #include "QCharacterDialog.h"
17 #include "QCharacter.h"
20 #include "qt_helpers.h"
21 #include "support/lstrings.h"
23 #include <qcombobox.h>
24 #include <qcheckbox.h>
25 #include <qpushbutton.h>
32 typedef QController<ControlCharacter, QView<QCharacterDialog> > base_class;
35 QCharacter::QCharacter(Dialog & parent)
36 : base_class(parent, _("LyX: Change Text Style"))
41 void QCharacter::build_dialog()
43 dialog_.reset(new QCharacterDialog(this));
45 family = getFamilyData();
46 series = getSeriesData();
47 shape = getShapeData();
50 color = getColorData();
51 language = getLanguageData(true);
53 for (vector<FamilyPair>::const_iterator cit = family.begin();
54 cit != family.end(); ++cit) {
55 dialog_->familyCO->insertItem(toqstr(cit->first), -1);
58 for (vector<SeriesPair>::const_iterator cit = series.begin();
59 cit != series.end(); ++cit) {
60 dialog_->seriesCO->insertItem(toqstr(cit->first), -1);
62 for (vector<ShapePair>::const_iterator cit = shape.begin();
63 cit != shape.end(); ++cit) {
64 dialog_->shapeCO->insertItem(toqstr(cit->first), -1);
66 for (vector<SizePair>::const_iterator cit = size.begin();
67 cit != size.end(); ++cit) {
68 dialog_->sizeCO->insertItem(toqstr(cit->first), -1);
70 for (vector<BarPair>::const_iterator cit = bar.begin();
71 cit != bar.end(); ++cit) {
72 dialog_->miscCO->insertItem(toqstr(cit->first), -1);
74 for (vector<ColorPair>::const_iterator cit = color.begin();
75 cit != color.end(); ++cit) {
76 dialog_->colorCO->insertItem(toqstr(cit->first), -1);
78 for (vector<LanguagePair>::const_iterator cit = language.begin();
79 cit != language.end(); ++cit) {
80 dialog_->langCO->insertItem(toqstr(cit->first), -1);
83 bcview().setOK(dialog_->okPB);
84 bcview().setApply(dialog_->applyPB);
85 bcview().setCancel(dialog_->closePB);
86 bcview().addReadOnly(dialog_->familyCO);
87 bcview().addReadOnly(dialog_->seriesCO);
88 bcview().addReadOnly(dialog_->sizeCO);
89 bcview().addReadOnly(dialog_->shapeCO);
90 bcview().addReadOnly(dialog_->miscCO);
91 bcview().addReadOnly(dialog_->langCO);
92 bcview().addReadOnly(dialog_->colorCO);
93 bcview().addReadOnly(dialog_->toggleallCB);
94 bcview().addReadOnly(dialog_->autoapplyCB);
100 template<class A, class B>
101 int findPos2nd(vector<std::pair<A,B> > const & vec, B const & val)
103 typedef typename vector<std::pair<A, B> >::const_iterator
106 const_iterator cit = vec.begin();
107 for (; cit != vec.end(); ++cit) {
108 if (cit->second == val)
109 return int(cit - vec.begin());
117 void QCharacter::update_contents()
119 ControlCharacter const & ctrl = controller();
121 dialog_->familyCO->setCurrentItem(findPos2nd(family,
123 dialog_->seriesCO->setCurrentItem(findPos2nd(series,
125 dialog_->shapeCO->setCurrentItem(findPos2nd(shape, ctrl.getShape()));
126 dialog_->sizeCO->setCurrentItem(findPos2nd(size, ctrl.getSize()));
127 dialog_->miscCO->setCurrentItem(findPos2nd(bar, ctrl.getBar()));
128 dialog_->colorCO->setCurrentItem(findPos2nd(color, ctrl.getColor()));
129 dialog_->langCO->setCurrentItem(findPos2nd(language,
130 ctrl.getLanguage()));
132 dialog_->toggleallCB->setChecked(ctrl.getToggleAll());
136 void QCharacter::apply()
138 ControlCharacter & ctrl = controller();
140 ctrl.setFamily(family[dialog_->familyCO->currentItem()].second);
141 ctrl.setSeries(series[dialog_->seriesCO->currentItem()].second);
142 ctrl.setShape(shape[dialog_->shapeCO->currentItem()].second);
143 ctrl.setSize(size[dialog_->sizeCO->currentItem()].second);
144 ctrl.setBar(bar[dialog_->miscCO->currentItem()].second);
145 ctrl.setColor(color[dialog_->colorCO->currentItem()].second);
146 ctrl.setLanguage(language[dialog_->langCO->currentItem()].second);
148 ctrl.setToggleAll(dialog_->toggleallCB->isChecked());