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