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 "insets/insetfloat.h"
18 #include "support/lstrings.h"
20 #include <qcheckbox.h>
22 #include <qgroupbox.h>
24 using lyx::support::contains;
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)
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);
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);
48 layout->addWidget(defaultsCB);
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);
59 layout->addWidget(options);
61 toplayout->addLayout(layout);
63 connect(defaultsCB, SIGNAL(toggled(bool)), options, SLOT(setDisabled(bool)));
65 connect(heredefinitelyCB, SIGNAL(clicked()), this, SLOT(heredefinitelyClicked()));
66 connect(topCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
67 connect(bottomCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
68 connect(pageCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
69 connect(herepossiblyCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
70 connect(defaultsCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
72 connect(defaultsCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
73 connect(ignoreCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
74 connect(pageCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
75 connect(heredefinitelyCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
76 connect(herepossiblyCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
77 connect(bottomCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
78 connect(topCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
82 void FloatPlacement::useWide()
84 spanCB = new QCheckBox(qt_("&Span columns"), this);
85 layout->addWidget(spanCB);
86 setTabOrder(ignoreCB, spanCB);
87 connect(spanCB, SIGNAL(clicked()), this, SLOT(spanClicked()));
88 connect(spanCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
92 void FloatPlacement::useSideways()
94 sidewaysCB = new QCheckBox(qt_("&Rotate sideways"), this);
95 layout->addWidget(sidewaysCB);
96 setTabOrder(spanCB, sidewaysCB);
97 connect(sidewaysCB, SIGNAL(clicked()), this, SLOT(sidewaysClicked()));
98 connect(sidewaysCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
102 void FloatPlacement::changedSlot()
108 void FloatPlacement::set(string const & placement)
110 bool def_placement = false;
116 bool here_definitely = false;
118 if (placement.empty()) {
119 def_placement = true;
120 } else if (contains(placement, 'H')) {
121 here_definitely = true;
123 if (contains(placement, '!')) {
126 if (contains(placement, 't')) {
129 if (contains(placement, 'b')) {
132 if (contains(placement, 'p')) {
135 if (contains(placement, 'h')) {
140 defaultsCB->setChecked(def_placement);
141 topCB->setChecked(top);
142 bottomCB->setChecked(bottom);
143 pageCB->setChecked(page);
144 herepossiblyCB->setChecked(here);
145 ignoreCB->setChecked(force);
146 ignoreCB->setEnabled(top || bottom || page || here);
147 heredefinitelyCB->setChecked(here_definitely);
152 void FloatPlacement::set(InsetFloatParams const & params)
154 set(params.placement);
157 herepossiblyCB->setChecked(false);
158 heredefinitelyCB->setChecked(false);
159 bottomCB->setChecked(false);
162 spanCB->setChecked(params.wide);
163 sidewaysCB->setChecked(params.sideways);
164 sidewaysCB->setEnabled(params.type == "figure"
165 || params.type == "table");
170 string const FloatPlacement::get(bool & wide, bool & sideways) const
172 wide = spanCB->isChecked();
173 sideways = sidewaysCB->isChecked();
179 string const FloatPlacement::get() const
183 if (defaultsCB->isChecked())
186 if (heredefinitelyCB->isChecked()) {
189 if (ignoreCB->isChecked()) {
192 if (topCB->isChecked()) {
195 if (bottomCB->isChecked()) {
198 if (pageCB->isChecked()) {
201 if (herepossiblyCB->isChecked()) {
209 void FloatPlacement::tbhpClicked()
211 heredefinitelyCB->setChecked(false);
216 void FloatPlacement::heredefinitelyClicked()
218 if (heredefinitelyCB->isChecked());
219 ignoreCB->setEnabled(false);
221 topCB->setChecked(false);
222 bottomCB->setChecked(false);
223 pageCB->setChecked(false);
224 herepossiblyCB->setChecked(false);
225 ignoreCB->setChecked(false);
229 void FloatPlacement::spanClicked()
233 if (!spanCB->isChecked())
236 herepossiblyCB->setChecked(false);
237 heredefinitelyCB->setChecked(false);
238 bottomCB->setChecked(false);
242 void FloatPlacement::sidewaysClicked()
248 void FloatPlacement::checkAllowed()
250 bool const defaults(defaultsCB->isChecked());
251 bool ignore(topCB->isChecked());
252 ignore |= bottomCB->isChecked();
253 ignore |= pageCB->isChecked();
254 ignore |= herepossiblyCB->isChecked();
256 // float or document dialog?
258 bool const span(spanCB->isChecked());
259 bool const sideways(sidewaysCB->isChecked());
260 defaultsCB->setEnabled(!sideways);
261 topCB->setEnabled(!sideways && !defaults);
262 bottomCB->setEnabled(!sideways && !defaults && !span);
263 pageCB->setEnabled(!sideways && !defaults);
264 ignoreCB->setEnabled(!sideways && !defaults && ignore);
265 herepossiblyCB->setEnabled(!sideways && !defaults && !span);
266 heredefinitelyCB->setEnabled(!sideways && !defaults && !span);
267 spanCB->setEnabled(!sideways);
269 topCB->setEnabled(!defaults);
270 bottomCB->setEnabled(!defaults);
271 pageCB->setEnabled(!defaults);
272 ignoreCB->setEnabled(!defaults && ignore);
273 herepossiblyCB->setEnabled(!defaults);
274 heredefinitelyCB->setEnabled(!defaults);