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