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