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 floatTypeTitle->setVisible(show_options);
48 floatTypeCO->setVisible(show_options);
49 spanCB->setVisible(show_options);
50 sidewaysCB->setVisible(show_options);
54 docstring FloatPlacement::dialogToParams() const
56 InsetFloatParams params;
57 params.type = fromqstr(floatTypeCO->itemData(floatTypeCO->currentIndex()).toString());
58 params.placement = get(params.wide, params.sideways);
59 return from_ascii(InsetFloat::params2string(params));
63 void FloatPlacement::useWide()
69 void FloatPlacement::useSideways()
75 void FloatPlacement::set(string const & placement)
77 bool def_placement = false;
83 bool here_definitely = false;
85 if (placement.empty()) {
87 } else if (contains(placement, 'H')) {
88 here_definitely = true;
90 if (contains(placement, '!')) {
93 if (contains(placement, 't')) {
96 if (contains(placement, 'b')) {
99 if (contains(placement, 'p')) {
102 if (contains(placement, 'h')) {
107 defaultsCB->setChecked(def_placement);
108 topCB->setChecked(top);
109 bottomCB->setChecked(bottom);
110 pageCB->setChecked(page);
111 herepossiblyCB->setChecked(here);
112 ignoreCB->setChecked(force);
113 heredefinitelyCB->setChecked(here_definitely);
118 void FloatPlacement::initFloatTypeCO(FloatList const & floats)
120 if (float_list_ == &floats)
123 float_list_ = &floats;
124 floatTypeCO->clear();
125 FloatList::const_iterator it = floats.begin();
126 FloatList::const_iterator const end = floats.end();
127 for (; it != end; ++it) {
128 floatTypeCO->addItem(qt_(it->second.name()),
129 toqstr(it->second.floattype()));
134 void FloatPlacement::paramsToDialog(Inset const * inset)
136 InsetFloat const * fl = static_cast<InsetFloat const *>(inset);
137 InsetFloatParams const & params = fl->params();
139 BufferParams const & bp = fl->buffer().params();
140 initFloatTypeCO(bp.documentClass().floats());
142 int const item = floatTypeCO->findData(toqstr(params.type));
143 floatTypeCO->setCurrentIndex(item);
145 set(params.placement);
147 standardfloat_ = (params.type == "figure"
148 || params.type == "table");
151 herepossiblyCB->setChecked(false);
152 heredefinitelyCB->setChecked(false);
153 bottomCB->setChecked(false);
156 spanCB->setChecked(params.wide);
157 sidewaysCB->setChecked(params.sideways);
158 // the package rotfloat only has *-versions for figure and table
159 spanCB->setEnabled(!params.sideways || standardfloat_);
164 string const FloatPlacement::get(bool & wide, bool & sideways) const
166 wide = spanCB->isChecked();
167 sideways = sidewaysCB->isChecked();
173 string const FloatPlacement::get() const
177 if (defaultsCB->isChecked())
180 if (heredefinitelyCB->isChecked()) {
183 if (ignoreCB->isChecked()) {
186 if (topCB->isChecked()) {
189 if (bottomCB->isChecked()) {
192 if (pageCB->isChecked()) {
195 if (herepossiblyCB->isChecked()) {
203 void FloatPlacement::on_defaultsCB_stateChanged(int state)
206 if (state == Qt::Checked)
208 if (topCB->isChecked() || bottomCB->isChecked()
209 || pageCB->isChecked() || herepossiblyCB->isChecked()
210 || heredefinitelyCB->isChecked() || ignoreCB->isChecked())
215 void FloatPlacement::changedSlot()
222 void FloatPlacement::checkAllowed()
224 bool const defaults = defaultsCB->isChecked();
225 bool const ignore = topCB->isChecked() || bottomCB->isChecked()
226 || pageCB->isChecked() || herepossiblyCB->isChecked();
227 bool const heredefinitely = heredefinitelyCB->isChecked();
229 // float or document dialog?
230 if (spanCB->isVisible()) {
231 bool const span = spanCB->isChecked();
232 bool const sideways = sidewaysCB->isChecked();
233 defaultsCB->setEnabled(!sideways);
234 topCB->setEnabled(!sideways && !defaults && !heredefinitely);
235 bottomCB->setEnabled(!sideways && !defaults && !span && !heredefinitely);
236 pageCB->setEnabled(!sideways && !defaults && !heredefinitely);
237 herepossiblyCB->setEnabled(!sideways && !defaults && !span && !heredefinitely);
238 heredefinitelyCB->setEnabled(!sideways && !defaults && !span);
239 ignoreCB->setEnabled(!sideways && !defaults && ignore && !heredefinitely);
240 spanCB->setEnabled(!sideways || standardfloat_);
242 topCB->setEnabled(!defaults && !heredefinitely);
243 bottomCB->setEnabled(!defaults && !heredefinitely);
244 pageCB->setEnabled(!defaults && !heredefinitely);
245 herepossiblyCB->setEnabled(!defaults && !heredefinitely);
246 heredefinitelyCB->setEnabled(!defaults);
247 ignoreCB->setEnabled(!defaults && ignore && !heredefinitely);
251 } // namespace frontend
254 #include "moc_FloatPlacement.cpp"