3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
6 * \author Edwin Leuven, leuven@fee.uva.nl
7 * \author John Levon <moz@compsoc.man.ac.uk>
13 #include "support/lstrings.h"
15 #include "ControlCharacter.h"
16 #include "QCharacterDialog.h"
17 #include "QCharacter.h"
19 #include <qcombobox.h>
20 #include <qcheckbox.h>
21 #include <qpushbutton.h>
23 using namespace character;
26 typedef Qt2CB<ControlCharacter, Qt2DB<QCharacterDialog> > base_class;
28 QCharacter::QCharacter(ControlCharacter & c)
29 : base_class(c, _("Character"))
34 void QCharacter::build_dialog()
36 dialog_.reset(new QCharacterDialog(this));
38 family = getFamilyData();
39 series = getSeriesData();
40 shape = getShapeData();
43 color = getColorData();
44 language = getLanguageData();
46 for (vector<FamilyPair>::const_iterator cit = family.begin();
47 cit != family.end(); ++cit) {
48 dialog_->familyCO->insertItem(cit->first.c_str(), -1);
50 for (vector<SeriesPair>::const_iterator cit = series.begin();
51 cit != series.end(); ++cit) {
52 dialog_->seriesCO->insertItem(cit->first.c_str(), -1);
54 for (vector<ShapePair>::const_iterator cit = shape.begin();
55 cit != shape.end(); ++cit) {
56 dialog_->shapeCO->insertItem(cit->first.c_str(), -1);
58 for (vector<SizePair>::const_iterator cit = size.begin();
59 cit != size.end(); ++cit) {
60 dialog_->sizeCO->insertItem(cit->first.c_str(), -1);
62 for (vector<BarPair>::const_iterator cit = bar.begin();
63 cit != bar.end(); ++cit) {
64 dialog_->miscCO->insertItem(cit->first.c_str(), -1);
66 for (vector<ColorPair>::const_iterator cit = color.begin();
67 cit != color.end(); ++cit) {
68 dialog_->colorCO->insertItem(cit->first.c_str(), -1);
70 for (vector<string>::const_iterator cit = language.begin();
71 cit != language.end(); ++cit) {
72 dialog_->langCO->insertItem(cit->c_str(), -1);
75 bc().setOK(dialog_->okPB);
76 bc().setApply(dialog_->applyPB);
77 bc().setCancel(dialog_->closePB);
78 bc().addReadOnly(dialog_->familyCO);
79 bc().addReadOnly(dialog_->seriesCO);
80 bc().addReadOnly(dialog_->sizeCO);
81 bc().addReadOnly(dialog_->shapeCO);
82 bc().addReadOnly(dialog_->miscCO);
83 bc().addReadOnly(dialog_->langCO);
84 bc().addReadOnly(dialog_->colorCO);
85 bc().addReadOnly(dialog_->toggleallCB);
86 bc().addReadOnly(dialog_->autoapplyCB);
92 template<class A, class B>
93 int findPos2nd(vector<std::pair<A,B> > const & vec, B const & val)
95 vector<std::pair<A,B> >::const_iterator cit = vec.begin();
96 for (; cit != vec.end(); ++cit) {
97 if (cit->second == val)
98 return int(cit - vec.begin());
106 void QCharacter::update_contents()
108 dialog_->familyCO->setCurrentItem(findPos2nd(family, controller().getFamily()));
109 dialog_->seriesCO->setCurrentItem(findPos2nd(series, controller().getSeries()));
110 dialog_->shapeCO->setCurrentItem(findPos2nd(shape, controller().getShape()));
111 dialog_->sizeCO->setCurrentItem(findPos2nd(size, controller().getSize()));
112 dialog_->miscCO->setCurrentItem(findPos2nd(bar, controller().getBar()));
113 dialog_->colorCO->setCurrentItem(findPos2nd(color, controller().getColor()));
115 dialog_->toggleallCB->setChecked(controller().getToggleAll());
117 string const thelanguage(controller().getLanguage());
119 for (vector<string>::const_iterator cit = language.begin();
120 cit != language.end(); ++i, ++cit) {
121 if (*cit == thelanguage) {
122 dialog_->langCO->setCurrentItem(i);
129 void QCharacter::apply()
131 controller().setFamily(family[dialog_->familyCO->currentItem()].second);
132 controller().setSeries(series[dialog_->seriesCO->currentItem()].second);
133 controller().setShape(shape[dialog_->shapeCO->currentItem()].second);
134 controller().setSize(size[dialog_->sizeCO->currentItem()].second);
135 controller().setBar(bar[dialog_->miscCO->currentItem()].second);
136 controller().setColor(color[dialog_->colorCO->currentItem()].second);
138 controller().setLanguage(dialog_->langCO->currentText().latin1());
140 controller().setToggleAll(dialog_->toggleallCB->isChecked());