lyx_mirror/src/frontends/qt4/FloatPlacement.C
Edwin Leuven e28114779b minimal effort implementation of:
* float widget as a .ui file
* floatplacement.[Ch] -> FloatPlacement.[Ch] 



git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14838 a592a061-630c-0410-9148-cb99ea01b6c8
2006-08-25 13:40:01 +00:00

242 lines
5.2 KiB
C

/**
* \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
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "FloatPlacement.h"
#include "qt_helpers.h"
#include "insets/insetfloat.h"
#include "support/lstrings.h"
using lyx::support::contains;
using std::string;
FloatPlacement::FloatPlacement(QWidget *)
{
setupUi(this);
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()));
spanCB->hide();
sidewaysCB->hide();
}
FloatPlacement::~FloatPlacement()
{
}
void FloatPlacement::useWide()
{
spanCB->show();
}
void FloatPlacement::useSideways()
{
sidewaysCB->show();
}
void FloatPlacement::changedSlot()
{
// emit signal
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;
} 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();
}
void FloatPlacement::set(InsetFloatParams const & params)
{
set(params.placement);
if (params.wide) {
herepossiblyCB->setChecked(false);
heredefinitelyCB->setChecked(false);
bottomCB->setChecked(false);
}
spanCB->setChecked(params.wide);
sidewaysCB->setChecked(params.sideways);
sidewaysCB->setEnabled(params.type == "figure"
|| params.type == "table");
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();
}
void FloatPlacement::on_heredefinitelyCB_clicked()
{
if (heredefinitelyCB->isChecked())
ignoreCB->setEnabled(false);
topCB->setChecked(false);
bottomCB->setChecked(false);
pageCB->setChecked(false);
herepossiblyCB->setChecked(false);
ignoreCB->setChecked(false);
}
void FloatPlacement::on_spanCB_clicked()
{
checkAllowed();
if (!spanCB->isChecked())
return;
herepossiblyCB->setChecked(false);
heredefinitelyCB->setChecked(false);
bottomCB->setChecked(false);
}
void FloatPlacement::on_sidewaysCB_clicked()
{
checkAllowed();
}
void FloatPlacement::checkAllowed()
{
bool const defaults(defaultsCB->isChecked());
bool ignore(topCB->isChecked());
ignore |= bottomCB->isChecked();
ignore |= pageCB->isChecked();
ignore |= herepossiblyCB->isChecked();
// float or document dialog?
if (spanCB->isVisible()) {
bool const span(spanCB->isChecked());
bool const sideways(sidewaysCB->isChecked());
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);
spanCB->setEnabled(!sideways);
} else {
topCB->setEnabled(!defaults);
bottomCB->setEnabled(!defaults);
pageCB->setEnabled(!defaults);
ignoreCB->setEnabled(!defaults && ignore);
herepossiblyCB->setEnabled(!defaults);
heredefinitelyCB->setEnabled(!defaults);
}
}
#include "FloatPlacement_moc.cpp"