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)));
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)));
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()));
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()));
88 void FloatPlacement::useWide()
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()));
98 void FloatPlacement::useSideways()
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()));
108 void FloatPlacement::changedSlot()
114 void FloatPlacement::set(string const & placement)
116 bool def_placement = false;
122 bool here_definitely = false;
124 if (placement.empty()) {
125 def_placement = true;
126 } else if (contains(placement, 'H')) {
127 here_definitely = true;
129 if (contains(placement, '!')) {
132 if (contains(placement, 't')) {
135 if (contains(placement, 'b')) {
138 if (contains(placement, 'p')) {
141 if (contains(placement, 'h')) {
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);
157 void FloatPlacement::set(InsetFloatParams const & params)
159 set(params.placement);
162 herepossiblyCB->setChecked(false);
163 heredefinitelyCB->setChecked(false);
164 bottomCB->setChecked(false);
167 spanCB->setChecked(params.wide);
168 sidewaysCB->setChecked(params.sideways);
169 sidewaysCB->setEnabled(params.type == "figure"
170 || 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);
216 bool allow(topCB->isChecked());
217 allow |= bottomCB->isChecked();
218 allow |= pageCB->isChecked();
219 allow |= herepossiblyCB->isChecked();
220 ignoreCB->setEnabled(allow);
224 void FloatPlacement::heredefinitelyClicked()
226 if (heredefinitelyCB->isChecked());
227 ignoreCB->setEnabled(false);
229 topCB->setChecked(false);
230 bottomCB->setChecked(false);
231 pageCB->setChecked(false);
232 herepossiblyCB->setChecked(false);
233 ignoreCB->setChecked(false);
237 void FloatPlacement::spanClicked()
239 bool const span(spanCB->isChecked());
241 if (!defaultsCB->isChecked()) {
242 herepossiblyCB->setEnabled(!span);
243 heredefinitelyCB->setEnabled(!span);
244 bottomCB->setEnabled(!span);
250 herepossiblyCB->setChecked(false);
251 heredefinitelyCB->setChecked(false);
252 bottomCB->setChecked(false);
256 void FloatPlacement::sidewaysClicked()
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();
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);