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 namespace lyx::support;
26 // FIXME: set disabled doesn't work properly
28 FloatPlacement::FloatPlacement(QWidget * parent, char * name)
29 : QWidget(parent, name)
31 QHBoxLayout * toplayout = new QHBoxLayout(this, 11, 6);
32 layout = new QVBoxLayout(0, 0, 6);
33 QGroupBox * options = new QGroupBox(qt_("Advanced Placement Options"), this);
35 defaultsCB = new QCheckBox(qt_("Use &default placement"), this);
36 topCB = new QCheckBox(qt_("&Top of page"), options);
37 bottomCB = new QCheckBox(qt_("&Bottom of page"), options);
38 pageCB = new QCheckBox(qt_("&Page of floats"), options);
39 herepossiblyCB = new QCheckBox(qt_("&Here if possible"), options);
40 heredefinitelyCB = new QCheckBox(qt_("Here definitely"), options);
41 ignoreCB = new QCheckBox(qt_("&Ignore LaTeX rules"), options);
44 layout->addWidget(defaultsCB);
46 QVBoxLayout * optlay = new QVBoxLayout(options, 10, 6);
47 optlay->addSpacing(6);
48 optlay->addWidget(topCB);
49 optlay->addWidget(bottomCB);
50 optlay->addWidget(pageCB);
51 optlay->addWidget(herepossiblyCB);
52 optlay->addWidget(heredefinitelyCB);
53 optlay->addWidget(ignoreCB);
55 layout->addWidget(options);
57 toplayout->addLayout(layout);
59 connect(defaultsCB, SIGNAL(toggled(bool)), options, SLOT(setDisabled(bool)));
60 connect(defaultsCB, SIGNAL(toggled(bool)), ignoreCB, SLOT(setDisabled(bool)));
61 connect(defaultsCB, SIGNAL(toggled(bool)), pageCB, SLOT(setDisabled(bool)));
62 connect(defaultsCB, SIGNAL(toggled(bool)), heredefinitelyCB, SLOT(setDisabled(bool)));
63 connect(defaultsCB, SIGNAL(toggled(bool)), herepossiblyCB, SLOT(setDisabled(bool)));
64 connect(defaultsCB, SIGNAL(toggled(bool)), bottomCB, SLOT(setDisabled(bool)));
65 connect(defaultsCB, SIGNAL(toggled(bool)), topCB, SLOT(setDisabled(bool)));
67 connect(heredefinitelyCB, SIGNAL(clicked()), this, SLOT(heredefinitelyClicked()));
68 connect(topCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
69 connect(bottomCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
70 connect(pageCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
71 connect(herepossiblyCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
72 connect(defaultsCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
74 connect(defaultsCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
75 connect(ignoreCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
76 connect(pageCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
77 connect(heredefinitelyCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
78 connect(herepossiblyCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
79 connect(bottomCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
80 connect(topCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
84 void FloatPlacement::useWide()
86 spanCB = new QCheckBox(qt_("&Span columns"), this);
87 layout->addWidget(spanCB);
88 setTabOrder(ignoreCB, spanCB);
89 connect(spanCB, SIGNAL(clicked()), this, SLOT(spanClicked()));
90 connect(spanCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
94 void FloatPlacement::changedSlot()
100 void FloatPlacement::set(string const & placement)
102 bool def_placement = false;
108 bool here_definitely = false;
110 if (placement.empty()) {
111 def_placement = true;
112 } else if (contains(placement, "H")) {
113 here_definitely = true;
115 if (contains(placement, "!")) {
118 if (contains(placement, "t")) {
121 if (contains(placement, "b")) {
124 if (contains(placement, "p")) {
127 if (contains(placement, "h")) {
132 defaultsCB->setChecked(def_placement);
133 topCB->setChecked(top);
134 bottomCB->setChecked(bottom);
135 pageCB->setChecked(page);
136 herepossiblyCB->setChecked(here);
137 ignoreCB->setChecked(force);
138 ignoreCB->setEnabled(top || bottom || page || here);
139 heredefinitelyCB->setChecked(here_definitely);
143 void FloatPlacement::set(InsetFloatParams const & params)
145 set(params.placement);
148 herepossiblyCB->setChecked(false);
149 bottomCB->setChecked(false);
152 spanCB->setChecked(params.wide);
156 string const FloatPlacement::get(bool & wide) const
158 wide = spanCB->isChecked();
164 string const FloatPlacement::get() const
168 if (defaultsCB->isChecked())
171 if (heredefinitelyCB->isChecked()) {
174 if (ignoreCB->isChecked()) {
177 if (topCB->isChecked()) {
180 if (bottomCB->isChecked()) {
183 if (pageCB->isChecked()) {
186 if (herepossiblyCB->isChecked()) {
194 void FloatPlacement::tbhpClicked()
196 heredefinitelyCB->setChecked(false);
197 bool allow(topCB->isChecked());
198 allow |= bottomCB->isChecked();
199 allow |= pageCB->isChecked();
200 allow |= herepossiblyCB->isChecked();
201 ignoreCB->setEnabled(allow);
205 void FloatPlacement::heredefinitelyClicked()
207 if (heredefinitelyCB->isChecked());
208 ignoreCB->setEnabled(false);
210 topCB->setChecked(false);
211 bottomCB->setChecked(false);
212 pageCB->setChecked(false);
213 herepossiblyCB->setChecked(false);
214 ignoreCB->setChecked(false);
218 void FloatPlacement::spanClicked()
220 bool const span(spanCB->isChecked());
222 if (!defaultsCB->isChecked()) {
223 herepossiblyCB->setEnabled(!span);
224 heredefinitelyCB->setEnabled(!span);
230 herepossiblyCB->setChecked(false);
231 heredefinitelyCB->setChecked(false);