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 FloatPlacement::FloatPlacement(QWidget * parent, char * name)
31 : QWidget(parent, name)
33 QHBoxLayout * toplayout = new QHBoxLayout(this, 11, 6);
34 layout = new QVBoxLayout(0, 0, 6);
35 QGroupBox * options = new QGroupBox(qt_("Advanced Placement Options"), this);
37 defaultsCB = new QCheckBox(qt_("Use &default placement"), this);
38 topCB = new QCheckBox(qt_("&Top of page"), options);
39 bottomCB = new QCheckBox(qt_("&Bottom of page"), options);
40 pageCB = new QCheckBox(qt_("&Page of floats"), options);
41 herepossiblyCB = new QCheckBox(qt_("&Here if possible"), options);
42 heredefinitelyCB = new QCheckBox(qt_("Here definitely"), options);
43 ignoreCB = new QCheckBox(qt_("&Ignore LaTeX rules"), options);
46 layout->addWidget(defaultsCB);
48 QVBoxLayout * optlay = new QVBoxLayout(options, 10, 6);
49 optlay->addSpacing(6);
50 optlay->addWidget(topCB);
51 optlay->addWidget(bottomCB);
52 optlay->addWidget(pageCB);
53 optlay->addWidget(herepossiblyCB);
54 optlay->addWidget(heredefinitelyCB);
55 optlay->addWidget(ignoreCB);
57 layout->addWidget(options);
59 toplayout->addLayout(layout);
61 connect(defaultsCB, SIGNAL(toggled(bool)), options, SLOT(setDisabled(bool)));
62 connect(defaultsCB, SIGNAL(toggled(bool)), ignoreCB, SLOT(setDisabled(bool)));
63 connect(defaultsCB, SIGNAL(toggled(bool)), pageCB, SLOT(setDisabled(bool)));
64 connect(defaultsCB, SIGNAL(toggled(bool)), heredefinitelyCB, SLOT(setDisabled(bool)));
65 connect(defaultsCB, SIGNAL(toggled(bool)), herepossiblyCB, SLOT(setDisabled(bool)));
66 connect(defaultsCB, SIGNAL(toggled(bool)), bottomCB, SLOT(setDisabled(bool)));
67 connect(defaultsCB, SIGNAL(toggled(bool)), topCB, SLOT(setDisabled(bool)));
69 connect(heredefinitelyCB, SIGNAL(clicked()), this, SLOT(heredefinitelyClicked()));
70 connect(topCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
71 connect(bottomCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
72 connect(pageCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
73 connect(herepossiblyCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
74 connect(defaultsCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
76 connect(defaultsCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
77 connect(ignoreCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
78 connect(pageCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
79 connect(heredefinitelyCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
80 connect(herepossiblyCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
81 connect(bottomCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
82 connect(topCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
86 void FloatPlacement::useWide()
88 spanCB = new QCheckBox(qt_("&Span columns"), this);
89 layout->addWidget(spanCB);
90 setTabOrder(ignoreCB, spanCB);
91 connect(spanCB, SIGNAL(clicked()), this, SLOT(spanClicked()));
92 connect(spanCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
96 void FloatPlacement::changedSlot()
102 void FloatPlacement::set(string const & placement)
104 bool def_placement = false;
110 bool here_definitely = false;
112 if (placement.empty()) {
113 def_placement = true;
114 } else if (contains(placement, "H")) {
115 here_definitely = true;
117 if (contains(placement, "!")) {
120 if (contains(placement, "t")) {
123 if (contains(placement, "b")) {
126 if (contains(placement, "p")) {
129 if (contains(placement, "h")) {
134 defaultsCB->setChecked(def_placement);
135 topCB->setChecked(top);
136 bottomCB->setChecked(bottom);
137 pageCB->setChecked(page);
138 herepossiblyCB->setChecked(here);
139 ignoreCB->setChecked(force);
140 ignoreCB->setEnabled(top || bottom || page || here);
141 heredefinitelyCB->setChecked(here_definitely);
145 void FloatPlacement::set(InsetFloatParams const & params)
147 set(params.placement);
150 herepossiblyCB->setChecked(false);
151 bottomCB->setChecked(false);
154 spanCB->setChecked(params.wide);
158 string const FloatPlacement::get(bool & wide) const
160 wide = spanCB->isChecked();
166 string const FloatPlacement::get() const
170 if (defaultsCB->isChecked())
173 if (heredefinitelyCB->isChecked()) {
176 if (ignoreCB->isChecked()) {
179 if (topCB->isChecked()) {
182 if (bottomCB->isChecked()) {
185 if (pageCB->isChecked()) {
188 if (herepossiblyCB->isChecked()) {
196 void FloatPlacement::tbhpClicked()
198 heredefinitelyCB->setChecked(false);
199 bool allow(topCB->isChecked());
200 allow |= bottomCB->isChecked();
201 allow |= pageCB->isChecked();
202 allow |= herepossiblyCB->isChecked();
203 ignoreCB->setEnabled(allow);
207 void FloatPlacement::heredefinitelyClicked()
209 if (heredefinitelyCB->isChecked());
210 ignoreCB->setEnabled(false);
212 topCB->setChecked(false);
213 bottomCB->setChecked(false);
214 pageCB->setChecked(false);
215 herepossiblyCB->setChecked(false);
216 ignoreCB->setChecked(false);
220 void FloatPlacement::spanClicked()
222 bool const span(spanCB->isChecked());
224 if (!defaultsCB->isChecked()) {
225 herepossiblyCB->setEnabled(!span);
226 heredefinitelyCB->setEnabled(!span);
232 herepossiblyCB->setChecked(false);
233 heredefinitelyCB->setChecked(false);