]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/floatplacement.C
rename LFUN enum values according to their command (as used in th minibuffer/bind...
[lyx.git] / src / frontends / qt4 / floatplacement.C
1 /**
2  * \file floatplacement.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 "floatplacement.h"
15 #include "qt_helpers.h"
16 //Added by qt3to4:
17 #include <QVBoxLayout>
18 #include <QHBoxLayout>
19
20 #include "insets/insetfloat.h"
21 #include "support/lstrings.h"
22
23 #include <QCheckBox>
24 #include <QLayout>
25 #include <QGroupBox>
26
27 using lyx::support::contains;
28
29 using std::string;
30
31
32 // FIXME: set disabled doesn't work properly
33 // should be fixed now (jspitzm)
34 FloatPlacement::FloatPlacement(QWidget * parent, char * name)
35         : QWidget(parent)
36 {
37         QHBoxLayout * toplayout = new QHBoxLayout(this, 11, 6);
38         layout = new QVBoxLayout(0, 0, 6);
39         QGroupBox * options = new QGroupBox(qt_("Advanced Placement Options"), this);
40
41         defaultsCB = new QCheckBox(qt_("Use &default placement"), this);
42         topCB = new QCheckBox(qt_("&Top of page"), options);
43         bottomCB = new QCheckBox(qt_("&Bottom of page"), options);
44         pageCB = new QCheckBox(qt_("&Page of floats"), options);
45         herepossiblyCB = new QCheckBox(qt_("&Here if possible"), options);
46         heredefinitelyCB = new QCheckBox(qt_("Here definitely"), options);
47         ignoreCB = new QCheckBox(qt_("&Ignore LaTeX rules"), options);
48         spanCB = 0;
49         sidewaysCB = 0;
50
51         layout->addWidget(defaultsCB);
52
53         QVBoxLayout * optlay = new QVBoxLayout(options, 10, 6);
54         optlay->addSpacing(6);
55         optlay->addWidget(topCB);
56         optlay->addWidget(bottomCB);
57         optlay->addWidget(pageCB);
58         optlay->addWidget(herepossiblyCB);
59         optlay->addWidget(heredefinitelyCB);
60         optlay->addWidget(ignoreCB);
61
62         layout->addWidget(options);
63
64         toplayout->addLayout(layout);
65
66         connect(defaultsCB, SIGNAL(toggled(bool)), options, SLOT(setDisabled(bool)));
67
68         connect(heredefinitelyCB, SIGNAL(clicked()), this, SLOT(heredefinitelyClicked()));
69         connect(topCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
70         connect(bottomCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
71         connect(pageCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
72         connect(herepossiblyCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
73         connect(defaultsCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
74
75         connect(defaultsCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
76         connect(ignoreCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
77         connect(pageCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
78         connect(heredefinitelyCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
79         connect(herepossiblyCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
80         connect(bottomCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
81         connect(topCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
82 }
83
84
85 void FloatPlacement::useWide()
86 {
87         spanCB = new QCheckBox(qt_("&Span columns"), this);
88         layout->addWidget(spanCB);
89         setTabOrder(ignoreCB, spanCB);
90         connect(spanCB, SIGNAL(clicked()), this, SLOT(spanClicked()));
91         connect(spanCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
92 }
93
94
95 void FloatPlacement::useSideways()
96 {
97         sidewaysCB = new QCheckBox(qt_("&Rotate sideways"), this);
98         layout->addWidget(sidewaysCB);
99         setTabOrder(spanCB, sidewaysCB);
100         connect(sidewaysCB, SIGNAL(clicked()), this, SLOT(sidewaysClicked()));
101         connect(sidewaysCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
102 }
103
104
105 void FloatPlacement::changedSlot()
106 {
107         emit changed();
108 }
109
110
111 void FloatPlacement::set(string const & placement)
112 {
113         bool def_placement = false;
114         bool top = false;
115         bool bottom = false;
116         bool page = false;
117         bool here = false;
118         bool force = false;
119         bool here_definitely = false;
120
121         if (placement.empty()) {
122                 def_placement = true;
123         } else if (contains(placement, 'H')) {
124                 here_definitely = true;
125         } else {
126                 if (contains(placement, '!')) {
127                         force = true;
128                 }
129                 if (contains(placement, 't')) {
130                         top = true;
131                 }
132                 if (contains(placement, 'b')) {
133                         bottom = true;
134                 }
135                 if (contains(placement, 'p')) {
136                         page = true;
137                 }
138                 if (contains(placement, 'h')) {
139                         here = true;
140                 }
141         }
142
143         defaultsCB->setChecked(def_placement);
144         topCB->setChecked(top);
145         bottomCB->setChecked(bottom);
146         pageCB->setChecked(page);
147         herepossiblyCB->setChecked(here);
148         ignoreCB->setChecked(force);
149         ignoreCB->setEnabled(top || bottom || page || here);
150         heredefinitelyCB->setChecked(here_definitely);
151         checkAllowed();
152 }
153
154
155 void FloatPlacement::set(InsetFloatParams const & params)
156 {
157         set(params.placement);
158
159         if (params.wide) {
160                 herepossiblyCB->setChecked(false);
161                 heredefinitelyCB->setChecked(false);
162                 bottomCB->setChecked(false);
163         }
164
165         spanCB->setChecked(params.wide);
166         sidewaysCB->setChecked(params.sideways);
167         sidewaysCB->setEnabled(params.type == "figure"
168                 || params.type == "table");
169         checkAllowed();
170 }
171
172
173 string const FloatPlacement::get(bool & wide, bool & sideways) const
174 {
175         wide = spanCB->isChecked();
176         sideways = sidewaysCB->isChecked();
177
178         return get();
179 }
180
181
182 string const FloatPlacement::get() const
183 {
184         string placement;
185
186         if (defaultsCB->isChecked())
187                 return placement;
188
189         if (heredefinitelyCB->isChecked()) {
190                 placement += 'H';
191         } else {
192                 if (ignoreCB->isChecked()) {
193                         placement += '!';
194                 }
195                 if (topCB->isChecked()) {
196                         placement += 't';
197                 }
198                 if (bottomCB->isChecked()) {
199                         placement += 'b';
200                 }
201                 if (pageCB->isChecked()) {
202                         placement += 'p';
203                 }
204                 if (herepossiblyCB->isChecked()) {
205                         placement += 'h';
206                 }
207         }
208         return placement;
209 }
210
211
212 void FloatPlacement::tbhpClicked()
213 {
214         heredefinitelyCB->setChecked(false);
215         checkAllowed();
216 }
217
218
219 void FloatPlacement::heredefinitelyClicked()
220 {
221         if (heredefinitelyCB->isChecked())
222                 ignoreCB->setEnabled(false);
223
224         topCB->setChecked(false);
225         bottomCB->setChecked(false);
226         pageCB->setChecked(false);
227         herepossiblyCB->setChecked(false);
228         ignoreCB->setChecked(false);
229 }
230
231
232 void FloatPlacement::spanClicked()
233 {
234         checkAllowed();
235
236         if (!spanCB->isChecked())
237                 return;
238
239         herepossiblyCB->setChecked(false);
240         heredefinitelyCB->setChecked(false);
241         bottomCB->setChecked(false);
242 }
243
244
245 void FloatPlacement::sidewaysClicked()
246 {
247         checkAllowed();
248 }
249
250
251 void FloatPlacement::checkAllowed()
252 {
253         bool const defaults(defaultsCB->isChecked());
254         bool ignore(topCB->isChecked());
255         ignore |= bottomCB->isChecked();
256         ignore |= pageCB->isChecked();
257         ignore |= herepossiblyCB->isChecked();
258
259         // float or document dialog?
260         if (spanCB != 0) {
261                 bool const span(spanCB->isChecked());
262                 bool const sideways(sidewaysCB->isChecked());
263                 defaultsCB->setEnabled(!sideways);
264                 topCB->setEnabled(!sideways && !defaults);
265                 bottomCB->setEnabled(!sideways && !defaults && !span);
266                 pageCB->setEnabled(!sideways && !defaults);
267                 ignoreCB->setEnabled(!sideways && !defaults && ignore);
268                 herepossiblyCB->setEnabled(!sideways && !defaults && !span);
269                 heredefinitelyCB->setEnabled(!sideways && !defaults && !span);
270                 spanCB->setEnabled(!sideways);
271         } else {
272                 topCB->setEnabled(!defaults);
273                 bottomCB->setEnabled(!defaults);
274                 pageCB->setEnabled(!defaults);
275                 ignoreCB->setEnabled(!defaults && ignore);
276                 herepossiblyCB->setEnabled(!defaults);
277                 heredefinitelyCB->setEnabled(!defaults);
278         }
279 }