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"
|
|
|
|
|
2010-02-10 17:33:39 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferParams.h"
|
|
|
|
#include "FloatList.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
|
|
|
|
2010-02-15 23:17:45 +00:00
|
|
|
namespace frontend {
|
|
|
|
|
2010-02-10 12:26:59 +00:00
|
|
|
FloatPlacement::FloatPlacement(bool show_options, QWidget * parent)
|
2010-02-15 23:17:45 +00:00
|
|
|
: InsetParamsWidget(parent), float_list_(0)
|
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
|
|
|
|
2010-02-10 17:33:39 +00:00
|
|
|
connect(floatTypeCO, SIGNAL(activated(int)), this, SLOT(changedSlot()));
|
2010-02-10 12:26:59 +00:00
|
|
|
connect(topCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
|
|
|
|
connect(bottomCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
|
2007-01-17 13:06:16 +00:00
|
|
|
connect(pageCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
|
|
|
|
connect(herepossiblyCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
|
2010-02-10 12:26:59 +00:00
|
|
|
connect(heredefinitelyCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
|
|
|
|
connect(ignoreCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
|
|
|
|
connect(spanCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
|
|
|
|
connect(sidewaysCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
|
2006-08-25 13:40:01 +00:00
|
|
|
|
2010-02-10 12:26:59 +00:00
|
|
|
spanCB->setVisible(show_options);
|
|
|
|
sidewaysCB->setVisible(show_options);
|
2006-08-25 13:40:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-08 22:09:40 +00:00
|
|
|
docstring FloatPlacement::dialogToParams() const
|
|
|
|
{
|
|
|
|
InsetFloatParams params;
|
2010-02-10 17:33:39 +00:00
|
|
|
params.type = fromqstr(floatTypeCO->itemData(floatTypeCO->currentIndex()).toString());
|
2010-02-08 22:09:40 +00:00
|
|
|
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::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);
|
|
|
|
heredefinitelyCB->setChecked(here_definitely);
|
|
|
|
checkAllowed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-10 17:33:39 +00:00
|
|
|
void FloatPlacement::initFloatTypeCO(FloatList const & floats)
|
|
|
|
{
|
|
|
|
if (float_list_ == &floats)
|
|
|
|
return;
|
|
|
|
|
|
|
|
float_list_ = &floats;
|
|
|
|
floatTypeCO->clear();
|
|
|
|
FloatList::const_iterator it = floats.begin();
|
|
|
|
FloatList::const_iterator const end = floats.end();
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
floatTypeCO->addItem(qt_(it->second.name()),
|
|
|
|
toqstr(it->second.type()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2010-02-10 17:33:39 +00:00
|
|
|
BufferParams const & bp = fl->buffer().params();
|
|
|
|
initFloatTypeCO(bp.documentClass().floats());
|
|
|
|
|
|
|
|
int const item = floatTypeCO->findData(toqstr(params.type));
|
|
|
|
floatTypeCO->setCurrentIndex(item);
|
2010-02-08 22:09:40 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-10 12:26:59 +00:00
|
|
|
void FloatPlacement::on_defaultsCB_stateChanged(int state)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
checkAllowed();
|
2010-02-10 12:26:59 +00:00
|
|
|
if (state == Qt::Checked)
|
2006-03-05 17:24:44 +00:00
|
|
|
return;
|
2010-02-10 12:26:59 +00:00
|
|
|
if (topCB->isChecked() || bottomCB->isChecked()
|
|
|
|
|| pageCB->isChecked() || herepossiblyCB->isChecked()
|
|
|
|
|| heredefinitelyCB->isChecked() || ignoreCB->isChecked())
|
|
|
|
changed();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-10 12:26:59 +00:00
|
|
|
void FloatPlacement::changedSlot()
|
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();
|
2010-02-10 12:26:59 +00:00
|
|
|
bool const ignore = topCB->isChecked() || bottomCB->isChecked()
|
|
|
|
|| pageCB->isChecked() || herepossiblyCB->isChecked();
|
|
|
|
bool const heredefinitely = heredefinitelyCB->isChecked();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// 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);
|
2010-02-10 12:26:59 +00:00
|
|
|
topCB->setEnabled(!sideways && !defaults && !heredefinitely);
|
|
|
|
bottomCB->setEnabled(!sideways && !defaults && !span && !heredefinitely);
|
|
|
|
pageCB->setEnabled(!sideways && !defaults && !heredefinitely);
|
|
|
|
herepossiblyCB->setEnabled(!sideways && !defaults && !span && !heredefinitely);
|
2006-03-05 17:24:44 +00:00
|
|
|
heredefinitelyCB->setEnabled(!sideways && !defaults && !span);
|
2010-02-10 12:26:59 +00:00
|
|
|
ignoreCB->setEnabled(!sideways && !defaults && ignore && !heredefinitely);
|
2008-01-11 18:56:53 +00:00
|
|
|
spanCB->setEnabled(!sideways || standardfloat_);
|
2006-03-05 17:24:44 +00:00
|
|
|
} else {
|
2010-02-10 12:26:59 +00:00
|
|
|
topCB->setEnabled(!defaults && !heredefinitely);
|
|
|
|
bottomCB->setEnabled(!defaults && !heredefinitely);
|
|
|
|
pageCB->setEnabled(!defaults && !heredefinitely);
|
|
|
|
herepossiblyCB->setEnabled(!defaults && !heredefinitely);
|
2006-03-05 17:24:44 +00:00
|
|
|
heredefinitelyCB->setEnabled(!defaults);
|
2010-02-10 12:26:59 +00:00
|
|
|
ignoreCB->setEnabled(!defaults && ignore && !heredefinitely);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-18 08:51:12 +00:00
|
|
|
|
2010-02-15 23:17:45 +00:00
|
|
|
} // namespace frontend
|
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"
|