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"
17 #include "insets/InsetFloat.h"
18 #include "support/lstrings.h"
21 using namespace lyx::support;
26 FloatPlacement::FloatPlacement(bool show_options, QWidget * parent)
31 connect(topCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
32 connect(bottomCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
33 connect(pageCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
34 connect(herepossiblyCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
35 connect(heredefinitelyCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
36 connect(ignoreCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
37 connect(spanCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
38 connect(sidewaysCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
40 spanCB->setVisible(show_options);
41 sidewaysCB->setVisible(show_options);
45 docstring FloatPlacement::dialogToParams() const
47 InsetFloatParams params;
48 params.type = float_type_;
49 params.placement = get(params.wide, params.sideways);
50 return from_ascii(InsetFloat::params2string(params));
54 void FloatPlacement::useWide()
60 void FloatPlacement::useSideways()
66 void FloatPlacement::set(string const & placement)
68 bool def_placement = false;
74 bool here_definitely = false;
76 if (placement.empty()) {
78 } else if (contains(placement, 'H')) {
79 here_definitely = true;
81 if (contains(placement, '!')) {
84 if (contains(placement, 't')) {
87 if (contains(placement, 'b')) {
90 if (contains(placement, 'p')) {
93 if (contains(placement, 'h')) {
98 defaultsCB->setChecked(def_placement);
99 topCB->setChecked(top);
100 bottomCB->setChecked(bottom);
101 pageCB->setChecked(page);
102 herepossiblyCB->setChecked(here);
103 ignoreCB->setChecked(force);
104 heredefinitelyCB->setChecked(here_definitely);
109 void FloatPlacement::paramsToDialog(Inset const * inset)
111 InsetFloat const * fl = static_cast<InsetFloat const *>(inset);
112 InsetFloatParams const & params = fl->params();
114 float_type_ = params.type;
115 floatType->setText(toqstr(fl->floatName(float_type_)));
117 set(params.placement);
119 standardfloat_ = (params.type == "figure"
120 || params.type == "table");
123 herepossiblyCB->setChecked(false);
124 heredefinitelyCB->setChecked(false);
125 bottomCB->setChecked(false);
128 spanCB->setChecked(params.wide);
129 sidewaysCB->setChecked(params.sideways);
130 // the package rotfloat only has *-versions for figure and table
131 spanCB->setEnabled(!params.sideways || standardfloat_);
136 string const FloatPlacement::get(bool & wide, bool & sideways) const
138 wide = spanCB->isChecked();
139 sideways = sidewaysCB->isChecked();
145 string const FloatPlacement::get() const
149 if (defaultsCB->isChecked())
152 if (heredefinitelyCB->isChecked()) {
155 if (ignoreCB->isChecked()) {
158 if (topCB->isChecked()) {
161 if (bottomCB->isChecked()) {
164 if (pageCB->isChecked()) {
167 if (herepossiblyCB->isChecked()) {
175 void FloatPlacement::on_defaultsCB_stateChanged(int state)
178 if (state == Qt::Checked)
180 if (topCB->isChecked() || bottomCB->isChecked()
181 || pageCB->isChecked() || herepossiblyCB->isChecked()
182 || heredefinitelyCB->isChecked() || ignoreCB->isChecked())
187 void FloatPlacement::changedSlot()
194 void FloatPlacement::checkAllowed()
196 bool const defaults = defaultsCB->isChecked();
197 bool const ignore = topCB->isChecked() || bottomCB->isChecked()
198 || pageCB->isChecked() || herepossiblyCB->isChecked();
199 bool const heredefinitely = heredefinitelyCB->isChecked();
201 // float or document dialog?
202 if (spanCB->isVisible()) {
203 bool const span = spanCB->isChecked();
204 bool const sideways = sidewaysCB->isChecked();
205 defaultsCB->setEnabled(!sideways);
206 topCB->setEnabled(!sideways && !defaults && !heredefinitely);
207 bottomCB->setEnabled(!sideways && !defaults && !span && !heredefinitely);
208 pageCB->setEnabled(!sideways && !defaults && !heredefinitely);
209 herepossiblyCB->setEnabled(!sideways && !defaults && !span && !heredefinitely);
210 heredefinitelyCB->setEnabled(!sideways && !defaults && !span);
211 ignoreCB->setEnabled(!sideways && !defaults && ignore && !heredefinitely);
212 spanCB->setEnabled(!sideways || standardfloat_);
214 topCB->setEnabled(!defaults && !heredefinitely);
215 bottomCB->setEnabled(!defaults && !heredefinitely);
216 pageCB->setEnabled(!defaults && !heredefinitely);
217 herepossiblyCB->setEnabled(!defaults && !heredefinitely);
218 heredefinitelyCB->setEnabled(!defaults);
219 ignoreCB->setEnabled(!defaults && ignore && !heredefinitely);
225 #include "moc_FloatPlacement.cpp"