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"
27 using namespace lyx::support;
34 FloatPlacement::FloatPlacement(bool show_options, QWidget * parent)
35 : InsetParamsWidget(parent), float_list_(0)
39 connect(floatTypeCO, SIGNAL(activated(int)), this, SLOT(changedSlot()));
40 connect(topCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
41 connect(bottomCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
42 connect(pageCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
43 connect(herepossiblyCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
44 connect(heredefinitelyCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
45 connect(ignoreCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
46 connect(spanCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
47 connect(sidewaysCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
49 floatTypeTitle->setVisible(show_options);
50 floatTypeCO->setVisible(show_options);
51 spanCB->setVisible(show_options);
52 sidewaysCB->setVisible(show_options);
56 docstring FloatPlacement::dialogToParams() const
58 InsetFloatParams params;
59 params.type = fromqstr(floatTypeCO->itemData(floatTypeCO->currentIndex()).toString());
60 params.placement = get(params.wide, params.sideways);
61 return from_ascii(InsetFloat::params2string(params));
65 void FloatPlacement::useWide()
71 void FloatPlacement::useSideways()
77 void FloatPlacement::set(string const & placement)
79 bool def_placement = false;
85 bool here_definitely = false;
87 if (placement.empty()) {
89 } else if (contains(placement, 'H')) {
90 here_definitely = true;
92 if (contains(placement, '!')) {
95 if (contains(placement, 't')) {
98 if (contains(placement, 'b')) {
101 if (contains(placement, 'p')) {
104 if (contains(placement, 'h')) {
109 defaultsCB->setChecked(def_placement);
110 topCB->setChecked(top);
111 bottomCB->setChecked(bottom);
112 pageCB->setChecked(page);
113 herepossiblyCB->setChecked(here);
114 ignoreCB->setChecked(force);
115 heredefinitelyCB->setChecked(here_definitely);
120 void FloatPlacement::initFloatTypeCO(FloatList const & floats)
122 if (float_list_ == &floats)
125 float_list_ = &floats;
126 floatTypeCO->clear();
127 FloatList::const_iterator it = floats.begin();
128 FloatList::const_iterator const end = floats.end();
129 for (; it != end; ++it) {
130 floatTypeCO->addItem(qt_(it->second.name()),
131 toqstr(it->second.floattype()));
136 void FloatPlacement::paramsToDialog(Inset const * inset)
138 InsetFloat const * fl = static_cast<InsetFloat const *>(inset);
139 InsetFloatParams const & params = fl->params();
141 BufferParams const & bp = fl->buffer().params();
142 initFloatTypeCO(bp.documentClass().floats());
144 int const item = floatTypeCO->findData(toqstr(params.type));
145 floatTypeCO->setCurrentIndex(item);
147 set(params.placement);
149 standardfloat_ = (params.type == "figure"
150 || params.type == "table");
153 herepossiblyCB->setChecked(false);
154 heredefinitelyCB->setChecked(false);
155 bottomCB->setChecked(false);
158 spanCB->setChecked(params.wide);
159 sidewaysCB->setChecked(params.sideways);
160 // the package rotfloat only has *-versions for figure and table
161 spanCB->setEnabled(!params.sideways || standardfloat_);
166 string const FloatPlacement::get(bool & wide, bool & sideways) const
168 wide = spanCB->isChecked();
169 sideways = sidewaysCB->isChecked();
175 string const FloatPlacement::get() const
179 if (defaultsCB->isChecked())
182 if (heredefinitelyCB->isChecked()) {
185 if (ignoreCB->isChecked()) {
188 if (topCB->isChecked()) {
191 if (bottomCB->isChecked()) {
194 if (pageCB->isChecked()) {
197 if (herepossiblyCB->isChecked()) {
205 void FloatPlacement::on_defaultsCB_stateChanged(int state)
208 if (state == Qt::Checked)
210 if (topCB->isChecked() || bottomCB->isChecked()
211 || pageCB->isChecked() || herepossiblyCB->isChecked()
212 || heredefinitelyCB->isChecked() || ignoreCB->isChecked())
217 void FloatPlacement::changedSlot()
224 void FloatPlacement::checkAllowed()
226 bool const defaults = defaultsCB->isChecked();
227 bool const ignore = topCB->isChecked() || bottomCB->isChecked()
228 || pageCB->isChecked() || herepossiblyCB->isChecked();
229 bool const heredefinitely = heredefinitelyCB->isChecked();
231 // float or document dialog?
232 if (spanCB->isVisible()) {
233 bool const span = spanCB->isChecked();
234 bool const sideways = sidewaysCB->isChecked();
235 defaultsCB->setEnabled(!sideways);
236 topCB->setEnabled(!sideways && !defaults && !heredefinitely);
237 bottomCB->setEnabled(!sideways && !defaults && !span && !heredefinitely);
238 pageCB->setEnabled(!sideways && !defaults && !heredefinitely);
239 herepossiblyCB->setEnabled(!sideways && !defaults && !span && !heredefinitely);
240 heredefinitelyCB->setEnabled(!sideways && !defaults && !span);
241 ignoreCB->setEnabled(!sideways && !defaults && ignore && !heredefinitely);
242 spanCB->setEnabled(!sideways || standardfloat_);
244 topCB->setEnabled(!defaults && !heredefinitely);
245 bottomCB->setEnabled(!defaults && !heredefinitely);
246 pageCB->setEnabled(!defaults && !heredefinitely);
247 herepossiblyCB->setEnabled(!defaults && !heredefinitely);
248 heredefinitelyCB->setEnabled(!defaults);
249 ignoreCB->setEnabled(!defaults && ignore && !heredefinitely);
253 } // namespace frontend
256 #include "moc_FloatPlacement.cpp"