2 * \file FloatPlacement.cpp
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"
18 #include "BufferParams.h"
19 #include "FloatList.h"
21 #include "insets/InsetFloat.h"
22 #include "support/lstrings.h"
25 using namespace lyx::support;
30 FloatPlacement::FloatPlacement(bool show_options, QWidget * parent)
31 : QWidget(parent), float_list_(0)
35 connect(floatTypeCO, SIGNAL(activated(int)), this, SLOT(changedSlot()));
36 connect(topCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
37 connect(bottomCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
38 connect(pageCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
39 connect(herepossiblyCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
40 connect(heredefinitelyCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
41 connect(ignoreCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
42 connect(spanCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
43 connect(sidewaysCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
45 spanCB->setVisible(show_options);
46 sidewaysCB->setVisible(show_options);
50 docstring FloatPlacement::dialogToParams() const
52 InsetFloatParams params;
53 params.type = fromqstr(floatTypeCO->itemData(floatTypeCO->currentIndex()).toString());
54 params.placement = get(params.wide, params.sideways);
55 return from_ascii(InsetFloat::params2string(params));
59 void FloatPlacement::useWide()
65 void FloatPlacement::useSideways()
71 void FloatPlacement::set(string const & placement)
73 bool def_placement = false;
79 bool here_definitely = false;
81 if (placement.empty()) {
83 } else if (contains(placement, 'H')) {
84 here_definitely = true;
86 if (contains(placement, '!')) {
89 if (contains(placement, 't')) {
92 if (contains(placement, 'b')) {
95 if (contains(placement, 'p')) {
98 if (contains(placement, 'h')) {
103 defaultsCB->setChecked(def_placement);
104 topCB->setChecked(top);
105 bottomCB->setChecked(bottom);
106 pageCB->setChecked(page);
107 herepossiblyCB->setChecked(here);
108 ignoreCB->setChecked(force);
109 heredefinitelyCB->setChecked(here_definitely);
114 void FloatPlacement::initFloatTypeCO(FloatList const & floats)
116 if (float_list_ == &floats)
119 float_list_ = &floats;
120 floatTypeCO->clear();
121 FloatList::const_iterator it = floats.begin();
122 FloatList::const_iterator const end = floats.end();
123 for (; it != end; ++it) {
124 floatTypeCO->addItem(qt_(it->second.name()),
125 toqstr(it->second.type()));
130 void FloatPlacement::paramsToDialog(Inset const * inset)
132 InsetFloat const * fl = static_cast<InsetFloat const *>(inset);
133 InsetFloatParams const & params = fl->params();
135 BufferParams const & bp = fl->buffer().params();
136 initFloatTypeCO(bp.documentClass().floats());
138 int const item = floatTypeCO->findData(toqstr(params.type));
139 floatTypeCO->setCurrentIndex(item);
141 set(params.placement);
143 standardfloat_ = (params.type == "figure"
144 || params.type == "table");
147 herepossiblyCB->setChecked(false);
148 heredefinitelyCB->setChecked(false);
149 bottomCB->setChecked(false);
152 spanCB->setChecked(params.wide);
153 sidewaysCB->setChecked(params.sideways);
154 // the package rotfloat only has *-versions for figure and table
155 spanCB->setEnabled(!params.sideways || standardfloat_);
160 string const FloatPlacement::get(bool & wide, bool & sideways) const
162 wide = spanCB->isChecked();
163 sideways = sidewaysCB->isChecked();
169 string const FloatPlacement::get() const
173 if (defaultsCB->isChecked())
176 if (heredefinitelyCB->isChecked()) {
179 if (ignoreCB->isChecked()) {
182 if (topCB->isChecked()) {
185 if (bottomCB->isChecked()) {
188 if (pageCB->isChecked()) {
191 if (herepossiblyCB->isChecked()) {
199 void FloatPlacement::on_defaultsCB_stateChanged(int state)
202 if (state == Qt::Checked)
204 if (topCB->isChecked() || bottomCB->isChecked()
205 || pageCB->isChecked() || herepossiblyCB->isChecked()
206 || heredefinitelyCB->isChecked() || ignoreCB->isChecked())
211 void FloatPlacement::changedSlot()
218 void FloatPlacement::checkAllowed()
220 bool const defaults = defaultsCB->isChecked();
221 bool const ignore = topCB->isChecked() || bottomCB->isChecked()
222 || pageCB->isChecked() || herepossiblyCB->isChecked();
223 bool const heredefinitely = heredefinitelyCB->isChecked();
225 // float or document dialog?
226 if (spanCB->isVisible()) {
227 bool const span = spanCB->isChecked();
228 bool const sideways = sidewaysCB->isChecked();
229 defaultsCB->setEnabled(!sideways);
230 topCB->setEnabled(!sideways && !defaults && !heredefinitely);
231 bottomCB->setEnabled(!sideways && !defaults && !span && !heredefinitely);
232 pageCB->setEnabled(!sideways && !defaults && !heredefinitely);
233 herepossiblyCB->setEnabled(!sideways && !defaults && !span && !heredefinitely);
234 heredefinitelyCB->setEnabled(!sideways && !defaults && !span);
235 ignoreCB->setEnabled(!sideways && !defaults && ignore && !heredefinitely);
236 spanCB->setEnabled(!sideways || standardfloat_);
238 topCB->setEnabled(!defaults && !heredefinitely);
239 bottomCB->setEnabled(!defaults && !heredefinitely);
240 pageCB->setEnabled(!defaults && !heredefinitely);
241 herepossiblyCB->setEnabled(!defaults && !heredefinitely);
242 heredefinitelyCB->setEnabled(!defaults);
243 ignoreCB->setEnabled(!defaults && ignore && !heredefinitely);
249 #include "moc_FloatPlacement.cpp"