]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QCharacter.C
small cleanup and removal of warnings
[lyx.git] / src / frontends / qt2 / QCharacter.C
1 /**
2  * \file QCharacter.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "ControlCharacter.h"
19 #include "QCharacterDialog.h"
20 #include "QCharacter.h"
21 #include "Qt2BC.h"
22
23 #include "gettext.h"
24 #include "support/lstrings.h"
25
26 #include <qcombobox.h>
27 #include <qcheckbox.h>
28 #include <qpushbutton.h>
29
30 #include <vector>
31
32 using namespace frnt;
33 using std::vector;
34
35 typedef Qt2CB<ControlCharacter, Qt2DB<QCharacterDialog> > base_class;
36
37 QCharacter::QCharacter()
38         : base_class(_("Character"))
39 {
40 }
41
42
43 void QCharacter::build_dialog()
44 {
45         dialog_.reset(new QCharacterDialog(this));
46
47         family = getFamilyData();
48         series = getSeriesData();
49         shape  = getShapeData();
50         size   = getSizeData();
51         bar    = getBarData();
52         color  = getColorData();
53         language = getLanguageData(true);
54
55         for (vector<FamilyPair>::const_iterator cit = family.begin();
56                 cit != family.end(); ++cit) {
57                 dialog_->familyCO->insertItem(cit->first.c_str(), -1);
58         }
59         for (vector<SeriesPair>::const_iterator cit = series.begin();
60                 cit != series.end(); ++cit) {
61                 dialog_->seriesCO->insertItem(cit->first.c_str(), -1);
62         }
63         for (vector<ShapePair>::const_iterator cit = shape.begin();
64                 cit != shape.end(); ++cit) {
65                 dialog_->shapeCO->insertItem(cit->first.c_str(), -1);
66         }
67         for (vector<SizePair>::const_iterator cit = size.begin();
68                 cit != size.end(); ++cit) {
69                 dialog_->sizeCO->insertItem(cit->first.c_str(), -1);
70         }
71         for (vector<BarPair>::const_iterator cit = bar.begin();
72                 cit != bar.end(); ++cit) {
73                 dialog_->miscCO->insertItem(cit->first.c_str(), -1);
74         }
75         for (vector<ColorPair>::const_iterator cit = color.begin();
76                 cit != color.end(); ++cit) {
77                 dialog_->colorCO->insertItem(cit->first.c_str(), -1);
78         }
79         for (vector<LanguagePair>::const_iterator cit = language.begin();
80                 cit != language.end(); ++cit) {
81                 dialog_->langCO->insertItem(cit->first.c_str(), -1);
82         }
83
84         bc().setOK(dialog_->okPB);
85         bc().setApply(dialog_->applyPB);
86         bc().setCancel(dialog_->closePB);
87         bc().addReadOnly(dialog_->familyCO);
88         bc().addReadOnly(dialog_->seriesCO);
89         bc().addReadOnly(dialog_->sizeCO);
90         bc().addReadOnly(dialog_->shapeCO);
91         bc().addReadOnly(dialog_->miscCO);
92         bc().addReadOnly(dialog_->langCO);
93         bc().addReadOnly(dialog_->colorCO);
94         bc().addReadOnly(dialog_->toggleallCB);
95         bc().addReadOnly(dialog_->autoapplyCB);
96 }
97
98
99 namespace {
100
101 template<class A, class B>
102 int findPos2nd(vector<std::pair<A,B> > const & vec, B const & val)
103 {
104         typedef typename vector<std::pair<A, B> >::const_iterator
105                 const_iterator;
106
107         const_iterator cit = vec.begin();
108         for (; cit != vec.end(); ++cit) {
109                 if (cit->second == val)
110                         return int(cit - vec.begin());
111         }
112         return 0;
113 }
114
115 } // namespace anon
116
117
118 void QCharacter::update_contents()
119 {
120         dialog_->familyCO->setCurrentItem(findPos2nd(family, controller().getFamily()));
121         dialog_->seriesCO->setCurrentItem(findPos2nd(series, controller().getSeries()));
122         dialog_->shapeCO->setCurrentItem(findPos2nd(shape, controller().getShape()));
123         dialog_->sizeCO->setCurrentItem(findPos2nd(size, controller().getSize()));
124         dialog_->miscCO->setCurrentItem(findPos2nd(bar, controller().getBar()));
125         dialog_->colorCO->setCurrentItem(findPos2nd(color, controller().getColor()));
126         dialog_->langCO->setCurrentItem(findPos2nd(language, controller().getLanguage()));
127
128         dialog_->toggleallCB->setChecked(controller().getToggleAll());
129 }
130
131
132 void QCharacter::apply()
133 {
134         controller().setFamily(family[dialog_->familyCO->currentItem()].second);
135         controller().setSeries(series[dialog_->seriesCO->currentItem()].second);
136         controller().setShape(shape[dialog_->shapeCO->currentItem()].second);
137         controller().setSize(size[dialog_->sizeCO->currentItem()].second);
138         controller().setBar(bar[dialog_->miscCO->currentItem()].second);
139         controller().setColor(color[dialog_->colorCO->currentItem()].second);
140         controller().setLanguage(language[dialog_->langCO->currentItem()].second);
141
142         controller().setToggleAll(dialog_->toggleallCB->isChecked());
143 }