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