2003-03-28 17:19:49 +00:00
|
|
|
/**
|
|
|
|
* \file floatplacement.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Edwin Leuven
|
|
|
|
* \author John Levon
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-03-28 17:19:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "floatplacement.h"
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
|
|
#include "insets/insetfloat.h"
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
|
|
#include <qcheckbox.h>
|
|
|
|
#include <qlayout.h>
|
|
|
|
#include <qgroupbox.h>
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
using lyx::support::contains;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
|
|
|
|
2003-03-28 17:19:49 +00:00
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
// FIXME: set disabled doesn't work properly
|
2004-03-29 11:38:39 +00:00
|
|
|
// should be fixed now (jspitzm)
|
2003-03-28 17:19:49 +00:00
|
|
|
FloatPlacement::FloatPlacement(QWidget * parent, char * name)
|
|
|
|
: QWidget(parent, name)
|
|
|
|
{
|
|
|
|
QHBoxLayout * toplayout = new QHBoxLayout(this, 11, 6);
|
|
|
|
layout = new QVBoxLayout(0, 0, 6);
|
|
|
|
QGroupBox * options = new QGroupBox(qt_("Advanced Placement Options"), this);
|
|
|
|
|
|
|
|
defaultsCB = new QCheckBox(qt_("Use &default placement"), this);
|
2003-04-12 04:49:05 +00:00
|
|
|
topCB = new QCheckBox(qt_("&Top of page"), options);
|
|
|
|
bottomCB = new QCheckBox(qt_("&Bottom of page"), options);
|
2003-03-28 17:19:49 +00:00
|
|
|
pageCB = new QCheckBox(qt_("&Page of floats"), options);
|
|
|
|
herepossiblyCB = new QCheckBox(qt_("&Here if possible"), options);
|
2003-04-12 04:49:05 +00:00
|
|
|
heredefinitelyCB = new QCheckBox(qt_("Here definitely"), options);
|
|
|
|
ignoreCB = new QCheckBox(qt_("&Ignore LaTeX rules"), options);
|
2003-03-28 17:19:49 +00:00
|
|
|
spanCB = 0;
|
2004-03-29 11:38:39 +00:00
|
|
|
sidewaysCB = 0;
|
2003-03-28 17:19:49 +00:00
|
|
|
|
|
|
|
layout->addWidget(defaultsCB);
|
|
|
|
|
|
|
|
QVBoxLayout * optlay = new QVBoxLayout(options, 10, 6);
|
|
|
|
optlay->addSpacing(6);
|
|
|
|
optlay->addWidget(topCB);
|
|
|
|
optlay->addWidget(bottomCB);
|
|
|
|
optlay->addWidget(pageCB);
|
|
|
|
optlay->addWidget(herepossiblyCB);
|
|
|
|
optlay->addWidget(heredefinitelyCB);
|
|
|
|
optlay->addWidget(ignoreCB);
|
|
|
|
|
|
|
|
layout->addWidget(options);
|
|
|
|
|
|
|
|
toplayout->addLayout(layout);
|
|
|
|
|
|
|
|
connect(defaultsCB, SIGNAL(toggled(bool)), options, SLOT(setDisabled(bool)));
|
2004-04-01 16:06:34 +00:00
|
|
|
connect(defaultsCB, SIGNAL(toggled(bool)), this, SLOT(defClicked()));
|
2003-03-28 17:19:49 +00:00
|
|
|
|
|
|
|
connect(heredefinitelyCB, SIGNAL(clicked()), this, SLOT(heredefinitelyClicked()));
|
|
|
|
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()));
|
|
|
|
|
|
|
|
connect(defaultsCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
|
|
|
|
connect(ignoreCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
|
|
|
|
connect(pageCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
|
|
|
|
connect(heredefinitelyCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
|
|
|
|
connect(herepossiblyCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
|
|
|
|
connect(bottomCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
|
|
|
|
connect(topCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FloatPlacement::useWide()
|
|
|
|
{
|
|
|
|
spanCB = new QCheckBox(qt_("&Span columns"), this);
|
|
|
|
layout->addWidget(spanCB);
|
2003-04-12 04:49:05 +00:00
|
|
|
setTabOrder(ignoreCB, spanCB);
|
2003-03-28 17:19:49 +00:00
|
|
|
connect(spanCB, SIGNAL(clicked()), this, SLOT(spanClicked()));
|
|
|
|
connect(spanCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-29 11:38:39 +00:00
|
|
|
void FloatPlacement::useSideways()
|
|
|
|
{
|
|
|
|
sidewaysCB = new QCheckBox(qt_("&Rotate sideways"), this);
|
|
|
|
layout->addWidget(sidewaysCB);
|
|
|
|
setTabOrder(spanCB, sidewaysCB);
|
|
|
|
connect(sidewaysCB, SIGNAL(clicked()), this, SLOT(sidewaysClicked()));
|
|
|
|
connect(sidewaysCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-28 17:19:49 +00:00
|
|
|
void FloatPlacement::changedSlot()
|
|
|
|
{
|
|
|
|
emit changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2004-02-01 12:46:14 +00:00
|
|
|
} else if (contains(placement, 'H')) {
|
2003-03-28 17:19:49 +00:00
|
|
|
here_definitely = true;
|
|
|
|
} else {
|
2004-02-01 12:46:14 +00:00
|
|
|
if (contains(placement, '!')) {
|
2003-03-28 17:19:49 +00:00
|
|
|
force = true;
|
|
|
|
}
|
2004-02-01 12:46:14 +00:00
|
|
|
if (contains(placement, 't')) {
|
2003-03-28 17:19:49 +00:00
|
|
|
top = true;
|
|
|
|
}
|
2004-02-01 12:46:14 +00:00
|
|
|
if (contains(placement, 'b')) {
|
2003-03-28 17:19:49 +00:00
|
|
|
bottom = true;
|
|
|
|
}
|
2004-02-01 12:46:14 +00:00
|
|
|
if (contains(placement, 'p')) {
|
2003-03-28 17:19:49 +00:00
|
|
|
page = true;
|
|
|
|
}
|
2004-02-01 12:46:14 +00:00
|
|
|
if (contains(placement, 'h')) {
|
2003-03-28 17:19:49 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FloatPlacement::set(InsetFloatParams const & params)
|
|
|
|
{
|
|
|
|
set(params.placement);
|
|
|
|
|
|
|
|
if (params.wide) {
|
|
|
|
herepossiblyCB->setChecked(false);
|
2004-03-29 11:38:39 +00:00
|
|
|
heredefinitelyCB->setChecked(false);
|
2003-03-28 17:19:49 +00:00
|
|
|
bottomCB->setChecked(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
spanCB->setChecked(params.wide);
|
2004-03-29 11:38:39 +00:00
|
|
|
sidewaysCB->setChecked(params.sideways);
|
|
|
|
sidewaysCB->setEnabled(params.type == "figure"
|
|
|
|
|| params.type == "table");
|
2003-03-28 17:19:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-29 11:38:39 +00:00
|
|
|
string const FloatPlacement::get(bool & wide, bool & sideways) const
|
2003-03-28 17:19:49 +00:00
|
|
|
{
|
|
|
|
wide = spanCB->isChecked();
|
2004-03-29 11:38:39 +00:00
|
|
|
sideways = sidewaysCB->isChecked();
|
2003-03-28 17:19:49 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-01 16:06:34 +00:00
|
|
|
void FloatPlacement::defClicked()
|
|
|
|
{
|
|
|
|
checkAllowed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-28 17:19:49 +00:00
|
|
|
void FloatPlacement::tbhpClicked()
|
|
|
|
{
|
|
|
|
heredefinitelyCB->setChecked(false);
|
|
|
|
bool allow(topCB->isChecked());
|
|
|
|
allow |= bottomCB->isChecked();
|
|
|
|
allow |= pageCB->isChecked();
|
|
|
|
allow |= herepossiblyCB->isChecked();
|
|
|
|
ignoreCB->setEnabled(allow);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FloatPlacement::heredefinitelyClicked()
|
|
|
|
{
|
|
|
|
if (heredefinitelyCB->isChecked());
|
|
|
|
ignoreCB->setEnabled(false);
|
|
|
|
|
|
|
|
topCB->setChecked(false);
|
|
|
|
bottomCB->setChecked(false);
|
|
|
|
pageCB->setChecked(false);
|
|
|
|
herepossiblyCB->setChecked(false);
|
|
|
|
ignoreCB->setChecked(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FloatPlacement::spanClicked()
|
|
|
|
{
|
2004-04-01 16:06:34 +00:00
|
|
|
checkAllowed();
|
2003-03-28 17:19:49 +00:00
|
|
|
|
2004-04-01 16:06:34 +00:00
|
|
|
if (!spanCB->isChecked())
|
2003-03-28 17:19:49 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
herepossiblyCB->setChecked(false);
|
|
|
|
heredefinitelyCB->setChecked(false);
|
2004-03-29 11:38:39 +00:00
|
|
|
bottomCB->setChecked(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FloatPlacement::sidewaysClicked()
|
|
|
|
{
|
2004-04-01 16:06:34 +00:00
|
|
|
checkAllowed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FloatPlacement::checkAllowed()
|
|
|
|
{
|
2004-03-29 11:38:39 +00:00
|
|
|
bool const defaults(defaultsCB->isChecked());
|
|
|
|
bool ignore(topCB->isChecked());
|
|
|
|
ignore |= bottomCB->isChecked();
|
|
|
|
ignore |= pageCB->isChecked();
|
|
|
|
ignore |= herepossiblyCB->isChecked();
|
2004-04-01 16:06:34 +00:00
|
|
|
bool const span(spanCB->isChecked());
|
|
|
|
bool const sideways(sidewaysCB->isChecked());
|
2004-03-29 11:38:39 +00:00
|
|
|
|
|
|
|
defaultsCB->setEnabled(!sideways);
|
|
|
|
topCB->setEnabled(!sideways && !defaults);
|
2004-04-01 16:06:34 +00:00
|
|
|
bottomCB->setEnabled(!sideways && !defaults && !span);
|
2004-03-29 11:38:39 +00:00
|
|
|
pageCB->setEnabled(!sideways && !defaults);
|
|
|
|
ignoreCB->setEnabled(!sideways && !defaults && ignore);
|
2004-04-01 16:06:34 +00:00
|
|
|
herepossiblyCB->setEnabled(!sideways && !defaults && !span);
|
|
|
|
heredefinitelyCB->setEnabled(!sideways && !defaults && !span);
|
2003-03-28 17:19:49 +00:00
|
|
|
}
|