2 * \file floatplacement.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "floatplacement.h"
15 #include "qt_helpers.h"
17 #include <QVBoxLayout>
18 #include <QHBoxLayout>
20 #include "insets/insetfloat.h"
21 #include "support/lstrings.h"
27 using lyx::support::contains;
32 // FIXME: set disabled doesn't work properly
33 // should be fixed now (jspitzm)
34 FloatPlacement::FloatPlacement(QWidget * parent, char * name)
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);
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);
51 layout->addWidget(defaultsCB);
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);
62 layout->addWidget(options);
64 toplayout->addLayout(layout);
66 connect(defaultsCB, SIGNAL(toggled(bool)), options, SLOT(setDisabled(bool)));
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()));
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()));
85 void FloatPlacement::useWide()
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()));
95 void FloatPlacement::useSideways()
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()));
105 void FloatPlacement::changedSlot()
112 void FloatPlacement::set(string const & placement)
114 bool def_placement = false;
120 bool here_definitely = false;
122 if (placement.empty()) {
123 def_placement = true;
124 } else if (contains(placement, 'H')) {
125 here_definitely = true;
127 if (contains(placement, '!')) {
130 if (contains(placement, 't')) {
133 if (contains(placement, 'b')) {
136 if (contains(placement, 'p')) {
139 if (contains(placement, 'h')) {
144 defaultsCB->setChecked(def_placement);
145 topCB->setChecked(top);
146 bottomCB->setChecked(bottom);
147 pageCB->setChecked(page);
148 herepossiblyCB->setChecked(here);
149 ignoreCB->setChecked(force);
150 ignoreCB->setEnabled(top || bottom || page || here);
151 heredefinitelyCB->setChecked(here_definitely);
156 void FloatPlacement::set(InsetFloatParams const & params)
158 set(params.placement);
161 herepossiblyCB->setChecked(false);
162 heredefinitelyCB->setChecked(false);
163 bottomCB->setChecked(false);
166 spanCB->setChecked(params.wide);
167 sidewaysCB->setChecked(params.sideways);
168 sidewaysCB->setEnabled(params.type == "figure"
169 || params.type == "table");
174 string const FloatPlacement::get(bool & wide, bool & sideways) const
176 wide = spanCB->isChecked();
177 sideways = sidewaysCB->isChecked();
183 string const FloatPlacement::get() const
187 if (defaultsCB->isChecked())
190 if (heredefinitelyCB->isChecked()) {
193 if (ignoreCB->isChecked()) {
196 if (topCB->isChecked()) {
199 if (bottomCB->isChecked()) {
202 if (pageCB->isChecked()) {
205 if (herepossiblyCB->isChecked()) {
213 void FloatPlacement::tbhpClicked()
215 heredefinitelyCB->setChecked(false);
220 void FloatPlacement::heredefinitelyClicked()
222 if (heredefinitelyCB->isChecked())
223 ignoreCB->setEnabled(false);
225 topCB->setChecked(false);
226 bottomCB->setChecked(false);
227 pageCB->setChecked(false);
228 herepossiblyCB->setChecked(false);
229 ignoreCB->setChecked(false);
233 void FloatPlacement::spanClicked()
237 if (!spanCB->isChecked())
240 herepossiblyCB->setChecked(false);
241 heredefinitelyCB->setChecked(false);
242 bottomCB->setChecked(false);
246 void FloatPlacement::sidewaysClicked()
252 void FloatPlacement::checkAllowed()
254 bool const defaults(defaultsCB->isChecked());
255 bool ignore(topCB->isChecked());
256 ignore |= bottomCB->isChecked();
257 ignore |= pageCB->isChecked();
258 ignore |= herepossiblyCB->isChecked();
260 // float or document dialog?
262 bool const span(spanCB->isChecked());
263 bool const sideways(sidewaysCB->isChecked());
264 defaultsCB->setEnabled(!sideways);
265 topCB->setEnabled(!sideways && !defaults);
266 bottomCB->setEnabled(!sideways && !defaults && !span);
267 pageCB->setEnabled(!sideways && !defaults);
268 ignoreCB->setEnabled(!sideways && !defaults && ignore);
269 herepossiblyCB->setEnabled(!sideways && !defaults && !span);
270 heredefinitelyCB->setEnabled(!sideways && !defaults && !span);
271 spanCB->setEnabled(!sideways);
273 topCB->setEnabled(!defaults);
274 bottomCB->setEnabled(!defaults);
275 pageCB->setEnabled(!defaults);
276 ignoreCB->setEnabled(!defaults && ignore);
277 herepossiblyCB->setEnabled(!defaults);
278 heredefinitelyCB->setEnabled(!defaults);
282 #include "floatplacement_moc.cpp"