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>
15 #include "support/lstrings.h"
17 #include "ControlCharacter.h"
18 #include "QCharacterDialog.h"
19 #include "QCharacter.h"
21 #include <qcombobox.h>
22 #include <qcheckbox.h>
23 #include <qpushbutton.h>
28 typedef Qt2CB<ControlCharacter, Qt2DB<QCharacterDialog> > base_class;
30 QCharacter::QCharacter()
31 : base_class(_("Character"))
36 void QCharacter::build_dialog()
38 dialog_.reset(new QCharacterDialog(this));
40 family = getFamilyData();
41 series = getSeriesData();
42 shape = getShapeData();
45 color = getColorData();
46 language = getLanguageData(true);
48 for (vector<FamilyPair>::const_iterator cit = family.begin();
49 cit != family.end(); ++cit) {
50 dialog_->familyCO->insertItem(cit->first.c_str(), -1);
52 for (vector<SeriesPair>::const_iterator cit = series.begin();
53 cit != series.end(); ++cit) {
54 dialog_->seriesCO->insertItem(cit->first.c_str(), -1);
56 for (vector<ShapePair>::const_iterator cit = shape.begin();
57 cit != shape.end(); ++cit) {
58 dialog_->shapeCO->insertItem(cit->first.c_str(), -1);
60 for (vector<SizePair>::const_iterator cit = size.begin();
61 cit != size.end(); ++cit) {
62 dialog_->sizeCO->insertItem(cit->first.c_str(), -1);
64 for (vector<BarPair>::const_iterator cit = bar.begin();
65 cit != bar.end(); ++cit) {
66 dialog_->miscCO->insertItem(cit->first.c_str(), -1);
68 for (vector<ColorPair>::const_iterator cit = color.begin();
69 cit != color.end(); ++cit) {
70 dialog_->colorCO->insertItem(cit->first.c_str(), -1);
72 for (vector<LanguagePair>::const_iterator cit = language.begin();
73 cit != language.end(); ++cit) {
74 dialog_->langCO->insertItem(cit->first.c_str(), -1);
77 bc().setOK(dialog_->okPB);
78 bc().setApply(dialog_->applyPB);
79 bc().setCancel(dialog_->closePB);
80 bc().addReadOnly(dialog_->familyCO);
81 bc().addReadOnly(dialog_->seriesCO);
82 bc().addReadOnly(dialog_->sizeCO);
83 bc().addReadOnly(dialog_->shapeCO);
84 bc().addReadOnly(dialog_->miscCO);
85 bc().addReadOnly(dialog_->langCO);
86 bc().addReadOnly(dialog_->colorCO);
87 bc().addReadOnly(dialog_->toggleallCB);
88 bc().addReadOnly(dialog_->autoapplyCB);
94 template<class A, class B>
95 int findPos2nd(vector<std::pair<A,B> > const & vec, B const & val)
97 vector<std::pair<A,B> >::const_iterator cit = vec.begin();
98 for (; cit != vec.end(); ++cit) {
99 if (cit->second == val)
100 return int(cit - vec.begin());
108 void QCharacter::update_contents()
110 dialog_->familyCO->setCurrentItem(findPos2nd(family, controller().getFamily()));
111 dialog_->seriesCO->setCurrentItem(findPos2nd(series, controller().getSeries()));
112 dialog_->shapeCO->setCurrentItem(findPos2nd(shape, controller().getShape()));
113 dialog_->sizeCO->setCurrentItem(findPos2nd(size, controller().getSize()));
114 dialog_->miscCO->setCurrentItem(findPos2nd(bar, controller().getBar()));
115 dialog_->colorCO->setCurrentItem(findPos2nd(color, controller().getColor()));
116 dialog_->langCO->setCurrentItem(findPos2nd(language, controller().getLanguage()));
118 dialog_->toggleallCB->setChecked(controller().getToggleAll());
122 void QCharacter::apply()
124 controller().setFamily(family[dialog_->familyCO->currentItem()].second);
125 controller().setSeries(series[dialog_->seriesCO->currentItem()].second);
126 controller().setShape(shape[dialog_->shapeCO->currentItem()].second);
127 controller().setSize(size[dialog_->sizeCO->currentItem()].second);
128 controller().setBar(bar[dialog_->miscCO->currentItem()].second);
129 controller().setColor(color[dialog_->colorCO->currentItem()].second);
130 controller().setLanguage(language[dialog_->langCO->currentItem()].second);
132 controller().setToggleAll(dialog_->toggleallCB->isChecked());