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, _("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);
94 // FIXME: hack to work around resizing bug in Qt >= 4.2
95 // bug verified with Qt 4.2.{0-2} (JSpitzm)
96 #if (QT_VERSION >= 0x040200)
97 // qt resizes the comboboxes only after show(), so ...
105 template<class A, class B>
106 int findPos2nd(vector<std::pair<A,B> > const & vec, B const & val)
108 typedef typename vector<std::pair<A, B> >::const_iterator
111 const_iterator cit = vec.begin();
112 for (; cit != vec.end(); ++cit) {
113 if (cit->second == val)
114 return int(cit - vec.begin());
122 void QCharacter::update_contents()
124 ControlCharacter const & ctrl = controller();
126 dialog_->familyCO->setCurrentIndex(findPos2nd(family,
128 dialog_->seriesCO->setCurrentIndex(findPos2nd(series,
130 dialog_->shapeCO->setCurrentIndex(findPos2nd(shape, ctrl.getShape()));
131 dialog_->sizeCO->setCurrentIndex(findPos2nd(size, ctrl.getSize()));
132 dialog_->miscCO->setCurrentIndex(findPos2nd(bar, ctrl.getBar()));
133 dialog_->colorCO->setCurrentIndex(findPos2nd(color, ctrl.getColor()));
134 dialog_->langCO->setCurrentIndex(findPos2nd(language,
135 ctrl.getLanguage()));
137 dialog_->toggleallCB->setChecked(ctrl.getToggleAll());
141 void QCharacter::apply()
143 ControlCharacter & ctrl = controller();
145 ctrl.setFamily(family[dialog_->familyCO->currentIndex()].second);
146 ctrl.setSeries(series[dialog_->seriesCO->currentIndex()].second);
147 ctrl.setShape(shape[dialog_->shapeCO->currentIndex()].second);
148 ctrl.setSize(size[dialog_->sizeCO->currentIndex()].second);
149 ctrl.setBar(bar[dialog_->miscCO->currentIndex()].second);
150 ctrl.setColor(color[dialog_->colorCO->currentIndex()].second);
151 ctrl.setLanguage(language[dialog_->langCO->currentIndex()].second);
153 ctrl.setToggleAll(dialog_->toggleallCB->isChecked());
156 } // namespace frontend