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;
32 FloatPlacement::FloatPlacement(bool show_options, QWidget * parent)
33 : InsetParamsWidget(parent), float_list_(0)
37 connect(floatTypeCO, SIGNAL(activated(int)), this, SLOT(changedSlot()));
38 connect(topCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
39 connect(bottomCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
40 connect(pageCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
41 connect(herepossiblyCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
42 connect(heredefinitelyCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
43 connect(ignoreCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
44 connect(spanCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
45 connect(sidewaysCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
47 spanCB->setVisible(show_options);
48 sidewaysCB->setVisible(show_options);
52 docstring FloatPlacement::dialogToParams() const
54 InsetFloatParams params;
55 params.type = fromqstr(floatTypeCO->itemData(floatTypeCO->currentIndex()).toString());
56 params.placement = get(params.wide, params.sideways);
57 return from_ascii(InsetFloat::params2string(params));
61 void FloatPlacement::useWide()
67 void FloatPlacement::useSideways()
73 void FloatPlacement::set(string const & placement)
75 bool def_placement = false;
81 bool here_definitely = false;
83 if (placement.empty()) {
85 } else if (contains(placement, 'H')) {
86 here_definitely = true;
88 if (contains(placement, '!')) {
91 if (contains(placement, 't')) {
94 if (contains(placement, 'b')) {
97 if (contains(placement, 'p')) {
100 if (contains(placement, 'h')) {
105 defaultsCB->setChecked(def_placement);
106 topCB->setChecked(top);
107 bottomCB->setChecked(bottom);
108 pageCB->setChecked(page);
109 herepossiblyCB->setChecked(here);
110 ignoreCB->setChecked(force);
111 heredefinitelyCB->setChecked(here_definitely);
116 void FloatPlacement::initFloatTypeCO(FloatList const & floats)
118 if (float_list_ == &floats)
121 float_list_ = &floats;
122 floatTypeCO->clear();
123 FloatList::const_iterator it = floats.begin();
124 FloatList::const_iterator const end = floats.end();
125 for (; it != end; ++it) {
126 floatTypeCO->addItem(qt_(it->second.name()),
127 toqstr(it->second.type()));
132 void FloatPlacement::paramsToDialog(Inset const * inset)
134 InsetFloat const * fl = static_cast<InsetFloat const *>(inset);
135 InsetFloatParams const & params = fl->params();
137 BufferParams const & bp = fl->buffer().params();
138 initFloatTypeCO(bp.documentClass().floats());
140 int const item = floatTypeCO->findData(toqstr(params.type));
141 floatTypeCO->setCurrentIndex(item);
143 set(params.placement);
145 standardfloat_ = (params.type == "figure"
146 || params.type == "table");
149 herepossiblyCB->setChecked(false);
150 heredefinitelyCB->setChecked(false);
151 bottomCB->setChecked(false);
154 spanCB->setChecked(params.wide);
155 sidewaysCB->setChecked(params.sideways);
156 // the package rotfloat only has *-versions for figure and table
157 spanCB->setEnabled(!params.sideways || standardfloat_);
162 string const FloatPlacement::get(bool & wide, bool & sideways) const
164 wide = spanCB->isChecked();
165 sideways = sidewaysCB->isChecked();
171 string const FloatPlacement::get() const
175 if (defaultsCB->isChecked())
178 if (heredefinitelyCB->isChecked()) {
181 if (ignoreCB->isChecked()) {
184 if (topCB->isChecked()) {
187 if (bottomCB->isChecked()) {
190 if (pageCB->isChecked()) {
193 if (herepossiblyCB->isChecked()) {
201 void FloatPlacement::on_defaultsCB_stateChanged(int state)
204 if (state == Qt::Checked)
206 if (topCB->isChecked() || bottomCB->isChecked()
207 || pageCB->isChecked() || herepossiblyCB->isChecked()
208 || heredefinitelyCB->isChecked() || ignoreCB->isChecked())
213 void FloatPlacement::changedSlot()
220 void FloatPlacement::checkAllowed()
222 bool const defaults = defaultsCB->isChecked();
223 bool const ignore = topCB->isChecked() || bottomCB->isChecked()
224 || pageCB->isChecked() || herepossiblyCB->isChecked();
225 bool const heredefinitely = heredefinitelyCB->isChecked();
227 // float or document dialog?
228 if (spanCB->isVisible()) {
229 bool const span = spanCB->isChecked();
230 bool const sideways = sidewaysCB->isChecked();
231 defaultsCB->setEnabled(!sideways);
232 topCB->setEnabled(!sideways && !defaults && !heredefinitely);
233 bottomCB->setEnabled(!sideways && !defaults && !span && !heredefinitely);
234 pageCB->setEnabled(!sideways && !defaults && !heredefinitely);
235 herepossiblyCB->setEnabled(!sideways && !defaults && !span && !heredefinitely);
236 heredefinitelyCB->setEnabled(!sideways && !defaults && !span);
237 ignoreCB->setEnabled(!sideways && !defaults && ignore && !heredefinitely);
238 spanCB->setEnabled(!sideways || standardfloat_);
240 topCB->setEnabled(!defaults && !heredefinitely);
241 bottomCB->setEnabled(!defaults && !heredefinitely);
242 pageCB->setEnabled(!defaults && !heredefinitely);
243 herepossiblyCB->setEnabled(!defaults && !heredefinitely);
244 heredefinitelyCB->setEnabled(!defaults);
245 ignoreCB->setEnabled(!defaults && ignore && !heredefinitely);
249 } // namespace frontend
252 #include "moc_FloatPlacement.cpp"