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 // FIXME: set disabled doesn't work properly
26 FloatPlacement::FloatPlacement(QWidget * parent, char * name)
27 : QWidget(parent, name)
29 QHBoxLayout * toplayout = new QHBoxLayout(this, 11, 6);
30 layout = new QVBoxLayout(0, 0, 6);
31 QGroupBox * options = new QGroupBox(qt_("Advanced Placement Options"), this);
33 defaultsCB = new QCheckBox(qt_("Use &default placement"), this);
34 topCB = new QCheckBox(qt_("&Top of page"), options);
35 bottomCB = new QCheckBox(qt_("&Bottom of page"), options);
36 pageCB = new QCheckBox(qt_("&Page of floats"), options);
37 herepossiblyCB = new QCheckBox(qt_("&Here if possible"), options);
38 heredefinitelyCB = new QCheckBox(qt_("Here definitely"), options);
39 ignoreCB = new QCheckBox(qt_("&Ignore LaTeX rules"), options);
42 layout->addWidget(defaultsCB);
44 QVBoxLayout * optlay = new QVBoxLayout(options, 10, 6);
45 optlay->addSpacing(6);
46 optlay->addWidget(topCB);
47 optlay->addWidget(bottomCB);
48 optlay->addWidget(pageCB);
49 optlay->addWidget(herepossiblyCB);
50 optlay->addWidget(heredefinitelyCB);
51 optlay->addWidget(ignoreCB);
53 layout->addWidget(options);
55 toplayout->addLayout(layout);
57 connect(defaultsCB, SIGNAL(toggled(bool)), options, SLOT(setDisabled(bool)));
58 connect(defaultsCB, SIGNAL(toggled(bool)), ignoreCB, SLOT(setDisabled(bool)));
59 connect(defaultsCB, SIGNAL(toggled(bool)), pageCB, SLOT(setDisabled(bool)));
60 connect(defaultsCB, SIGNAL(toggled(bool)), heredefinitelyCB, SLOT(setDisabled(bool)));
61 connect(defaultsCB, SIGNAL(toggled(bool)), herepossiblyCB, SLOT(setDisabled(bool)));
62 connect(defaultsCB, SIGNAL(toggled(bool)), bottomCB, SLOT(setDisabled(bool)));
63 connect(defaultsCB, SIGNAL(toggled(bool)), topCB, 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::changedSlot()
98 void FloatPlacement::set(string const & placement)
100 bool def_placement = false;
106 bool here_definitely = false;
108 if (placement.empty()) {
109 def_placement = true;
110 } else if (contains(placement, "H")) {
111 here_definitely = true;
113 if (contains(placement, "!")) {
116 if (contains(placement, "t")) {
119 if (contains(placement, "b")) {
122 if (contains(placement, "p")) {
125 if (contains(placement, "h")) {
130 defaultsCB->setChecked(def_placement);
131 topCB->setChecked(top);
132 bottomCB->setChecked(bottom);
133 pageCB->setChecked(page);
134 herepossiblyCB->setChecked(here);
135 ignoreCB->setChecked(force);
136 ignoreCB->setEnabled(top || bottom || page || here);
137 heredefinitelyCB->setChecked(here_definitely);
141 void FloatPlacement::set(InsetFloatParams const & params)
143 set(params.placement);
146 herepossiblyCB->setChecked(false);
147 bottomCB->setChecked(false);
150 spanCB->setChecked(params.wide);
154 string const FloatPlacement::get(bool & wide) const
156 wide = spanCB->isChecked();
162 string const FloatPlacement::get() const
166 if (defaultsCB->isChecked())
169 if (heredefinitelyCB->isChecked()) {
172 if (ignoreCB->isChecked()) {
175 if (topCB->isChecked()) {
178 if (bottomCB->isChecked()) {
181 if (pageCB->isChecked()) {
184 if (herepossiblyCB->isChecked()) {
192 void FloatPlacement::tbhpClicked()
194 heredefinitelyCB->setChecked(false);
195 bool allow(topCB->isChecked());
196 allow |= bottomCB->isChecked();
197 allow |= pageCB->isChecked();
198 allow |= herepossiblyCB->isChecked();
199 ignoreCB->setEnabled(allow);
203 void FloatPlacement::heredefinitelyClicked()
205 if (heredefinitelyCB->isChecked());
206 ignoreCB->setEnabled(false);
208 topCB->setChecked(false);
209 bottomCB->setChecked(false);
210 pageCB->setChecked(false);
211 herepossiblyCB->setChecked(false);
212 ignoreCB->setChecked(false);
216 void FloatPlacement::spanClicked()
218 bool const span(spanCB->isChecked());
220 if (!defaultsCB->isChecked()) {
221 herepossiblyCB->setEnabled(!span);
222 heredefinitelyCB->setEnabled(!span);
228 herepossiblyCB->setChecked(false);
229 heredefinitelyCB->setChecked(false);