2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2008-01-11 12:40:26 +00:00
|
|
|
* \file FloatPlacement.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Edwin Leuven
|
|
|
|
* \author John Levon
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2006-08-25 13:40:01 +00:00
|
|
|
#include "FloatPlacement.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "insets/InsetFloat.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2007-12-12 10:16:00 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-09-20 13:44:51 +00:00
|
|
|
namespace lyx {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2006-08-25 13:40:01 +00:00
|
|
|
FloatPlacement::FloatPlacement(QWidget *)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-08-25 13:40:01 +00:00
|
|
|
setupUi(this);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
connect(topCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
|
|
|
|
connect(bottomCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
|
|
|
|
connect(pageCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
|
|
|
|
connect(herepossiblyCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
|
|
|
|
connect(defaultsCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
|
2007-01-17 13:06:16 +00:00
|
|
|
connect(defaultsCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
|
|
|
|
connect(ignoreCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
|
|
|
|
connect(pageCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
|
|
|
|
connect(heredefinitelyCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
|
|
|
|
connect(herepossiblyCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
|
|
|
|
connect(bottomCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
|
|
|
|
connect(topCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
|
2006-08-25 13:40:01 +00:00
|
|
|
|
|
|
|
spanCB->hide();
|
|
|
|
sidewaysCB->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-08 22:09:40 +00:00
|
|
|
docstring FloatPlacement::dialogToParams() const
|
|
|
|
{
|
|
|
|
InsetFloatParams params;
|
|
|
|
params.type = fromqstr(floatType->text());
|
|
|
|
params.placement = get(params.wide, params.sideways);
|
|
|
|
return from_ascii(InsetFloat::params2string(params));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
void FloatPlacement::useWide()
|
|
|
|
{
|
2006-08-25 13:40:01 +00:00
|
|
|
spanCB->show();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FloatPlacement::useSideways()
|
|
|
|
{
|
2006-08-25 13:40:01 +00:00
|
|
|
sidewaysCB->show();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FloatPlacement::changedSlot()
|
|
|
|
{
|
2006-07-06 08:18:51 +00:00
|
|
|
// emit signal
|
2006-06-30 14:11:50 +00:00
|
|
|
changed();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FloatPlacement::set(string const & placement)
|
|
|
|
{
|
|
|
|
bool def_placement = false;
|
|
|
|
bool top = false;
|
|
|
|
bool bottom = false;
|
|
|
|
bool page = false;
|
|
|
|
bool here = false;
|
|
|
|
bool force = false;
|
|
|
|
bool here_definitely = false;
|
|
|
|
|
|
|
|
if (placement.empty()) {
|
|
|
|
def_placement = true;
|
|
|
|
} else if (contains(placement, 'H')) {
|
|
|
|
here_definitely = true;
|
|
|
|
} else {
|
|
|
|
if (contains(placement, '!')) {
|
|
|
|
force = true;
|
|
|
|
}
|
|
|
|
if (contains(placement, 't')) {
|
|
|
|
top = true;
|
|
|
|
}
|
|
|
|
if (contains(placement, 'b')) {
|
|
|
|
bottom = true;
|
|
|
|
}
|
|
|
|
if (contains(placement, 'p')) {
|
|
|
|
page = true;
|
|
|
|
}
|
|
|
|
if (contains(placement, 'h')) {
|
|
|
|
here = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultsCB->setChecked(def_placement);
|
|
|
|
topCB->setChecked(top);
|
|
|
|
bottomCB->setChecked(bottom);
|
|
|
|
pageCB->setChecked(page);
|
|
|
|
herepossiblyCB->setChecked(here);
|
|
|
|
ignoreCB->setChecked(force);
|
|
|
|
ignoreCB->setEnabled(top || bottom || page || here);
|
|
|
|
heredefinitelyCB->setChecked(here_definitely);
|
|
|
|
checkAllowed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-08 22:09:40 +00:00
|
|
|
void FloatPlacement::paramsToDialog(Inset const * inset)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2010-02-08 22:09:40 +00:00
|
|
|
InsetFloat const * fl = static_cast<InsetFloat const *>(inset);
|
|
|
|
InsetFloatParams const & params = fl->params();
|
|
|
|
|
|
|
|
floatType->setText(toqstr(params.type));
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
set(params.placement);
|
|
|
|
|
2008-01-11 18:56:53 +00:00
|
|
|
standardfloat_ = (params.type == "figure"
|
|
|
|
|| params.type == "table");
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
if (params.wide) {
|
|
|
|
herepossiblyCB->setChecked(false);
|
|
|
|
heredefinitelyCB->setChecked(false);
|
|
|
|
bottomCB->setChecked(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
spanCB->setChecked(params.wide);
|
|
|
|
sidewaysCB->setChecked(params.sideways);
|
2008-01-11 18:56:53 +00:00
|
|
|
// the package rotfloat only has *-versions for figure and table
|
|
|
|
spanCB->setEnabled(!params.sideways || standardfloat_);
|
2006-03-05 17:24:44 +00:00
|
|
|
checkAllowed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const FloatPlacement::get(bool & wide, bool & sideways) const
|
|
|
|
{
|
|
|
|
wide = spanCB->isChecked();
|
|
|
|
sideways = sidewaysCB->isChecked();
|
|
|
|
|
|
|
|
return get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const FloatPlacement::get() const
|
|
|
|
{
|
|
|
|
string placement;
|
|
|
|
|
|
|
|
if (defaultsCB->isChecked())
|
|
|
|
return placement;
|
|
|
|
|
|
|
|
if (heredefinitelyCB->isChecked()) {
|
|
|
|
placement += 'H';
|
|
|
|
} else {
|
|
|
|
if (ignoreCB->isChecked()) {
|
|
|
|
placement += '!';
|
|
|
|
}
|
|
|
|
if (topCB->isChecked()) {
|
|
|
|
placement += 't';
|
|
|
|
}
|
|
|
|
if (bottomCB->isChecked()) {
|
|
|
|
placement += 'b';
|
|
|
|
}
|
|
|
|
if (pageCB->isChecked()) {
|
|
|
|
placement += 'p';
|
|
|
|
}
|
|
|
|
if (herepossiblyCB->isChecked()) {
|
|
|
|
placement += 'h';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return placement;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FloatPlacement::tbhpClicked()
|
|
|
|
{
|
|
|
|
heredefinitelyCB->setChecked(false);
|
|
|
|
checkAllowed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-25 13:40:01 +00:00
|
|
|
void FloatPlacement::on_heredefinitelyCB_clicked()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
if (heredefinitelyCB->isChecked())
|
|
|
|
ignoreCB->setEnabled(false);
|
|
|
|
|
|
|
|
topCB->setChecked(false);
|
|
|
|
bottomCB->setChecked(false);
|
|
|
|
pageCB->setChecked(false);
|
|
|
|
herepossiblyCB->setChecked(false);
|
|
|
|
ignoreCB->setChecked(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-25 13:40:01 +00:00
|
|
|
void FloatPlacement::on_spanCB_clicked()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
checkAllowed();
|
2007-02-07 01:13:17 +00:00
|
|
|
changed();
|
2007-02-07 01:14:36 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
if (!spanCB->isChecked())
|
|
|
|
return;
|
|
|
|
|
|
|
|
herepossiblyCB->setChecked(false);
|
|
|
|
heredefinitelyCB->setChecked(false);
|
|
|
|
bottomCB->setChecked(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-25 13:40:01 +00:00
|
|
|
void FloatPlacement::on_sidewaysCB_clicked()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
checkAllowed();
|
2007-02-07 01:13:17 +00:00
|
|
|
changed();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FloatPlacement::checkAllowed()
|
|
|
|
{
|
2006-10-21 00:16:43 +00:00
|
|
|
bool const defaults = defaultsCB->isChecked();
|
|
|
|
bool ignore = topCB->isChecked();
|
2006-03-05 17:24:44 +00:00
|
|
|
ignore |= bottomCB->isChecked();
|
|
|
|
ignore |= pageCB->isChecked();
|
|
|
|
ignore |= herepossiblyCB->isChecked();
|
|
|
|
|
|
|
|
// float or document dialog?
|
2006-08-25 13:40:01 +00:00
|
|
|
if (spanCB->isVisible()) {
|
2006-10-21 00:16:43 +00:00
|
|
|
bool const span = spanCB->isChecked();
|
|
|
|
bool const sideways = sidewaysCB->isChecked();
|
2006-03-05 17:24:44 +00:00
|
|
|
defaultsCB->setEnabled(!sideways);
|
|
|
|
topCB->setEnabled(!sideways && !defaults);
|
|
|
|
bottomCB->setEnabled(!sideways && !defaults && !span);
|
|
|
|
pageCB->setEnabled(!sideways && !defaults);
|
|
|
|
ignoreCB->setEnabled(!sideways && !defaults && ignore);
|
|
|
|
herepossiblyCB->setEnabled(!sideways && !defaults && !span);
|
|
|
|
heredefinitelyCB->setEnabled(!sideways && !defaults && !span);
|
2008-01-11 18:56:53 +00:00
|
|
|
spanCB->setEnabled(!sideways || standardfloat_);
|
2006-03-05 17:24:44 +00:00
|
|
|
} else {
|
|
|
|
topCB->setEnabled(!defaults);
|
|
|
|
bottomCB->setEnabled(!defaults);
|
|
|
|
pageCB->setEnabled(!defaults);
|
|
|
|
ignoreCB->setEnabled(!defaults && ignore);
|
|
|
|
herepossiblyCB->setEnabled(!defaults);
|
|
|
|
heredefinitelyCB->setEnabled(!defaults);
|
|
|
|
}
|
|
|
|
}
|
2006-05-18 08:51:12 +00:00
|
|
|
|
2008-09-20 13:44:51 +00:00
|
|
|
} // namespace lyx
|
2006-08-25 13:40:01 +00:00
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_FloatPlacement.cpp"
|