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