]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QCharacter.C
update for frnt::etc
[lyx.git] / src / frontends / qt2 / QCharacter.C
1 /**
2  * \file QCharacter.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author Edwin Leuven, leuven@fee.uva.nl
7  * \author John Levon <moz@compsoc.man.ac.uk>
8  */
9
10 #include <config.h>
11
12 #include <vector>
13
14 #include "gettext.h"
15 #include "support/lstrings.h"
16
17 #include "ControlCharacter.h"
18 #include "QCharacterDialog.h"
19 #include "QCharacter.h"
20 #include "Qt2BC.h"
21 #include <qcombobox.h>
22 #include <qcheckbox.h>
23 #include <qpushbutton.h>
24
25 using namespace frnt;
26 using std::vector;
27
28 typedef Qt2CB<ControlCharacter, Qt2DB<QCharacterDialog> > base_class;
29
30 QCharacter::QCharacter(ControlCharacter & c)
31         : base_class(c, _("Character"))
32 {
33 }
34
35
36 void QCharacter::build_dialog()
37 {
38         dialog_.reset(new QCharacterDialog(this));
39
40         family = getFamilyData();
41         series = getSeriesData();
42         shape  = getShapeData();
43         size   = getSizeData();
44         bar    = getBarData();
45         color  = getColorData();
46         language = getLanguageData();
47
48         for (vector<FamilyPair>::const_iterator cit = family.begin();
49                 cit != family.end(); ++cit) {
50                 dialog_->familyCO->insertItem(cit->first.c_str(), -1);
51         }
52         for (vector<SeriesPair>::const_iterator cit = series.begin();
53                 cit != series.end(); ++cit) {
54                 dialog_->seriesCO->insertItem(cit->first.c_str(), -1);
55         }
56         for (vector<ShapePair>::const_iterator cit = shape.begin();
57                 cit != shape.end(); ++cit) {
58                 dialog_->shapeCO->insertItem(cit->first.c_str(), -1);
59         }
60         for (vector<SizePair>::const_iterator cit = size.begin();
61                 cit != size.end(); ++cit) {
62                 dialog_->sizeCO->insertItem(cit->first.c_str(), -1);
63         }
64         for (vector<BarPair>::const_iterator cit = bar.begin();
65                 cit != bar.end(); ++cit) {
66                 dialog_->miscCO->insertItem(cit->first.c_str(), -1);
67         }
68         for (vector<ColorPair>::const_iterator cit = color.begin();
69                 cit != color.end(); ++cit) {
70                 dialog_->colorCO->insertItem(cit->first.c_str(), -1);
71         }
72         for (vector<LanguagePair>::const_iterator cit = language.begin();
73                 cit != language.end(); ++cit) {
74                 dialog_->langCO->insertItem(cit->first.c_str(), -1);
75         }
76
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);
89 }
90
91
92 namespace {
93
94 template<class A, class B>
95 int findPos2nd(vector<std::pair<A,B> > const & vec, B const & val)
96 {
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());
101         }
102         return 0;
103 }
104
105 } // namespace anon
106
107
108 void QCharacter::update_contents()
109 {
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()));
117
118         dialog_->toggleallCB->setChecked(controller().getToggleAll());
119 }
120
121
122 void QCharacter::apply()
123 {
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);
131
132         controller().setToggleAll(dialog_->toggleallCB->isChecked());
133 }