]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QCharacter.C
some tabular fixes for the problems reported by Helge
[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 #include "QCharacter.h"
15 #include "ControlCharacter.h"
16 #include "QCharacterDialog.h"
17 #include "Qt2BC.h"
18 #include "qt_helpers.h"
19
20 #include "LColor.h"
21
22 #include <qpushbutton.h>
23 #include <qcheckbox.h>
24 #include <qcombobox.h>
25
26 using std::vector;
27
28 namespace lyx {
29 namespace frontend {
30
31 typedef QController<ControlCharacter, QView<QCharacterDialog> > base_class;
32
33
34 QCharacter::QCharacter(Dialog & parent)
35         : base_class(parent, _("LyX: Change Text Style"))
36 {
37 }
38
39
40 void QCharacter::build_dialog()
41 {
42         dialog_.reset(new QCharacterDialog(this));
43
44         family = getFamilyData();
45         series = getSeriesData();
46         shape  = getShapeData();
47         size   = getSizeData();
48         bar    = getBarData();
49         color  = getColorData();
50         language = getLanguageData(true);
51
52         for (vector<FamilyPair>::const_iterator cit = family.begin();
53                 cit != family.end(); ++cit) {
54                 dialog_->familyCO->insertItem(toqstr(cit->first), -1);
55         }
56
57         for (vector<SeriesPair>::const_iterator cit = series.begin();
58                 cit != series.end(); ++cit) {
59                 dialog_->seriesCO->insertItem(toqstr(cit->first), -1);
60         }
61         for (vector<ShapePair>::const_iterator cit = shape.begin();
62                 cit != shape.end(); ++cit) {
63                 dialog_->shapeCO->insertItem(toqstr(cit->first), -1);
64         }
65         for (vector<SizePair>::const_iterator cit = size.begin();
66                 cit != size.end(); ++cit) {
67                 dialog_->sizeCO->insertItem(toqstr(cit->first), -1);
68         }
69         for (vector<BarPair>::const_iterator cit = bar.begin();
70                 cit != bar.end(); ++cit) {
71                 dialog_->miscCO->insertItem(toqstr(cit->first), -1);
72         }
73         for (vector<ColorPair>::const_iterator cit = color.begin();
74                 cit != color.end(); ++cit) {
75                 dialog_->colorCO->insertItem(toqstr(cit->first), -1);
76         }
77         for (vector<LanguagePair>::const_iterator cit = language.begin();
78                 cit != language.end(); ++cit) {
79                 dialog_->langCO->insertItem(toqstr(cit->first), -1);
80         }
81
82         bcview().setOK(dialog_->okPB);
83         bcview().setApply(dialog_->applyPB);
84         bcview().setCancel(dialog_->closePB);
85         bcview().addReadOnly(dialog_->familyCO);
86         bcview().addReadOnly(dialog_->seriesCO);
87         bcview().addReadOnly(dialog_->sizeCO);
88         bcview().addReadOnly(dialog_->shapeCO);
89         bcview().addReadOnly(dialog_->miscCO);
90         bcview().addReadOnly(dialog_->langCO);
91         bcview().addReadOnly(dialog_->colorCO);
92         bcview().addReadOnly(dialog_->toggleallCB);
93         bcview().addReadOnly(dialog_->autoapplyCB);
94 }
95
96
97 namespace {
98
99 template<class A, class B>
100 int findPos2nd(vector<std::pair<A,B> > const & vec, B const & val)
101 {
102         typedef typename vector<std::pair<A, B> >::const_iterator
103                 const_iterator;
104
105         const_iterator cit = vec.begin();
106         for (; cit != vec.end(); ++cit) {
107                 if (cit->second == val)
108                         return int(cit - vec.begin());
109         }
110         return 0;
111 }
112
113 } // namespace anon
114
115
116 void QCharacter::update_contents()
117 {
118         ControlCharacter const & ctrl = controller();
119
120         dialog_->familyCO->setCurrentItem(findPos2nd(family,
121                                                      ctrl.getFamily()));
122         dialog_->seriesCO->setCurrentItem(findPos2nd(series,
123                                                      ctrl.getSeries()));
124         dialog_->shapeCO->setCurrentItem(findPos2nd(shape, ctrl.getShape()));
125         dialog_->sizeCO->setCurrentItem(findPos2nd(size, ctrl.getSize()));
126         dialog_->miscCO->setCurrentItem(findPos2nd(bar, ctrl.getBar()));
127         dialog_->colorCO->setCurrentItem(findPos2nd(color, ctrl.getColor()));
128         dialog_->langCO->setCurrentItem(findPos2nd(language,
129                                                    ctrl.getLanguage()));
130
131         dialog_->toggleallCB->setChecked(ctrl.getToggleAll());
132 }
133
134
135 void QCharacter::apply()
136 {
137         ControlCharacter & ctrl = controller();
138
139         ctrl.setFamily(family[dialog_->familyCO->currentItem()].second);
140         ctrl.setSeries(series[dialog_->seriesCO->currentItem()].second);
141         ctrl.setShape(shape[dialog_->shapeCO->currentItem()].second);
142         ctrl.setSize(size[dialog_->sizeCO->currentItem()].second);
143         ctrl.setBar(bar[dialog_->miscCO->currentItem()].second);
144         ctrl.setColor(color[dialog_->colorCO->currentItem()].second);
145         ctrl.setLanguage(language[dialog_->langCO->currentItem()].second);
146
147         ctrl.setToggleAll(dialog_->toggleallCB->isChecked());
148 }
149
150 } // namespace frontend
151 } // namespace lyx