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"
|
2010-10-31 01:04:03 +00:00
|
|
|
#include "TextClass.h"
|
2010-02-10 17:33:39 +00:00
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "insets/InsetFloat.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2010-03-31 19:38:05 +00:00
|
|
|
#include <map>
|
|
|
|
|
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)
|
2016-06-12 03:30:33 +00:00
|
|
|
: InsetParamsWidget(parent), standardfloat_ (true),
|
|
|
|
allows_wide_(true), allows_sideways_(true), 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-03-01 09:03:15 +00:00
|
|
|
floatTypeTitle->setVisible(show_options);
|
|
|
|
floatTypeCO->setVisible(show_options);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-22 08:37:14 +00:00
|
|
|
bool FloatPlacement::possiblePlacement(char const & p) const
|
|
|
|
{
|
|
|
|
return !spanCB->isVisible() || contains(allowed_placement_, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2015-05-22 08:37:14 +00:00
|
|
|
} else if (contains(placement, 'H') && possiblePlacement('H')) {
|
2006-03-05 17:24:44 +00:00
|
|
|
here_definitely = true;
|
|
|
|
} else {
|
2015-05-22 08:37:14 +00:00
|
|
|
if (contains(placement, '!') && possiblePlacement('!')) {
|
2006-03-05 17:24:44 +00:00
|
|
|
force = true;
|
|
|
|
}
|
2015-05-22 08:37:14 +00:00
|
|
|
if (contains(placement, 't') && possiblePlacement('t')) {
|
2006-03-05 17:24:44 +00:00
|
|
|
top = true;
|
|
|
|
}
|
2015-05-22 08:37:14 +00:00
|
|
|
if (contains(placement, 'b') && possiblePlacement('b')) {
|
2006-03-05 17:24:44 +00:00
|
|
|
bottom = true;
|
|
|
|
}
|
2015-05-22 08:37:14 +00:00
|
|
|
if (contains(placement, 'p') && possiblePlacement('p')) {
|
2006-03-05 17:24:44 +00:00
|
|
|
page = true;
|
|
|
|
}
|
2015-05-22 08:37:14 +00:00
|
|
|
if (contains(placement, 'h') && possiblePlacement('h')) {
|
2006-03-05 17:24:44 +00:00
|
|
|
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()),
|
2010-03-04 13:42:05 +00:00
|
|
|
toqstr(it->second.floattype()));
|
2010-02-10 17:33:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2015-05-22 16:59:17 +00:00
|
|
|
FloatList const & floats = bp.documentClass().floats();
|
|
|
|
initFloatTypeCO(floats);
|
2010-02-10 17:33:39 +00:00
|
|
|
|
|
|
|
int const item = floatTypeCO->findData(toqstr(params.type));
|
|
|
|
floatTypeCO->setCurrentIndex(item);
|
2010-02-08 22:09:40 +00:00
|
|
|
|
2015-05-22 16:59:17 +00:00
|
|
|
allowed_placement_ = floats.allowedPlacement(params.type);
|
|
|
|
allows_sideways_ = floats.allowsSideways(params.type);
|
|
|
|
allows_wide_ = floats.allowsWide(params.type);
|
2015-05-22 08:37:14 +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);
|
|
|
|
}
|
|
|
|
|
2015-05-22 16:59:17 +00:00
|
|
|
spanCB->setChecked(params.wide && allows_wide_);
|
|
|
|
sidewaysCB->setChecked(params.sideways && allows_sideways_);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-11 09:35:02 +00:00
|
|
|
void FloatPlacement::checkAllowed() const
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
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);
|
2015-05-22 08:37:14 +00:00
|
|
|
topCB->setEnabled(!sideways && !defaults && !heredefinitely
|
|
|
|
&& contains(allowed_placement_, 't'));
|
|
|
|
bottomCB->setEnabled(!sideways && !defaults && !span && !heredefinitely
|
|
|
|
&& contains(allowed_placement_, 'b'));
|
|
|
|
pageCB->setEnabled(!sideways && !defaults && !heredefinitely
|
|
|
|
&& contains(allowed_placement_, 'p'));
|
|
|
|
herepossiblyCB->setEnabled(!sideways && !defaults && !span && !heredefinitely
|
|
|
|
&& contains(allowed_placement_, 'h'));
|
|
|
|
heredefinitelyCB->setEnabled(!sideways && !defaults && !span
|
|
|
|
&& contains(allowed_placement_, 'H'));
|
|
|
|
ignoreCB->setEnabled(!sideways && !defaults && ignore && !heredefinitely
|
|
|
|
&& contains(allowed_placement_, '!'));
|
2015-05-22 16:59:17 +00:00
|
|
|
spanCB->setEnabled(allows_wide_ && (!sideways || standardfloat_));
|
|
|
|
sidewaysCB->setEnabled(allows_sideways_);
|
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
|
|
|
|
2015-04-02 15:03:08 +00:00
|
|
|
|
|
|
|
bool FloatPlacement::checkWidgets(bool readonly) const
|
|
|
|
{
|
2015-05-11 09:35:02 +00:00
|
|
|
if (readonly) {
|
|
|
|
floatTypeCO->setEnabled(false);
|
|
|
|
defaultsCB->setEnabled(false);
|
|
|
|
options->setEnabled(false);
|
|
|
|
spanCB->setEnabled(false);
|
|
|
|
sidewaysCB->setEnabled(false);
|
|
|
|
} else
|
|
|
|
checkAllowed();
|
2015-04-02 15:03:08 +00:00
|
|
|
|
|
|
|
return InsetParamsWidget::checkWidgets();
|
|
|
|
}
|
|
|
|
|
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"
|