2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiWrap.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.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Jürgen Spitzmüller
|
2006-03-05 17:24:44 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiWrap.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-04-26 03:53:02 +00:00
|
|
|
#include "LengthCombo.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
2007-09-24 13:43:58 +00:00
|
|
|
#include "Validator.h"
|
2007-10-05 20:16:05 +00:00
|
|
|
#include "FuncRequest.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-02-05 12:43:19 +00:00
|
|
|
#include "support/gettext.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
GuiWrap::GuiWrap(GuiView & lv)
|
2008-02-05 12:43:19 +00:00
|
|
|
: GuiDialog(lv, "wrap", qt_("Wrap Float Settings"))
|
2007-04-24 14:59:51 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
|
|
|
|
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
|
|
|
|
connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
|
|
|
|
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
|
2007-04-24 14:59:51 +00:00
|
|
|
|
2008-03-02 17:12:22 +00:00
|
|
|
connect(valignCO, SIGNAL(highlighted(QString)),
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
connect(floatCB, SIGNAL(stateChanged(int)),
|
|
|
|
this, SLOT(change_adaptor()));
|
2007-10-05 20:16:05 +00:00
|
|
|
connect(widthED, SIGNAL(textChanged(QString)),
|
2007-04-24 14:59:51 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
2007-09-24 13:43:58 +00:00
|
|
|
connect(widthUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
|
2007-04-24 14:59:51 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
2007-09-24 22:35:00 +00:00
|
|
|
connect(overhangCB, SIGNAL(stateChanged(int)),
|
|
|
|
this, SLOT(change_adaptor()));
|
2007-10-05 20:16:05 +00:00
|
|
|
connect(overhangED, SIGNAL(textChanged(QString)),
|
2007-09-24 13:43:58 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
connect(overhangUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
|
|
|
|
this, SLOT(change_adaptor()));
|
2007-09-24 22:35:00 +00:00
|
|
|
connect(linesCB, SIGNAL(stateChanged(int)),
|
|
|
|
this, SLOT(change_adaptor()));
|
2007-09-24 13:43:58 +00:00
|
|
|
connect(linesSB, SIGNAL(valueChanged(int)),
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
|
|
|
widthED->setValidator(unsignedLengthValidator(widthED));
|
|
|
|
// FIXME:
|
|
|
|
// overhang can be negative, but the unsignedLengthValidator allows this
|
|
|
|
overhangED->setValidator(unsignedLengthValidator(overhangED));
|
2007-04-24 14:59:51 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
|
|
|
|
bc().setRestore(restorePB);
|
|
|
|
bc().setOK(okPB);
|
|
|
|
bc().setApply(applyPB);
|
|
|
|
bc().setCancel(closePB);
|
2007-04-24 14:59:51 +00:00
|
|
|
|
2008-03-02 17:12:22 +00:00
|
|
|
bc().addReadOnly(valignCO);
|
|
|
|
bc().addReadOnly(floatCB);
|
2007-09-05 20:33:29 +00:00
|
|
|
bc().addReadOnly(widthED);
|
2007-09-24 13:43:58 +00:00
|
|
|
bc().addReadOnly(widthUnitLC);
|
2007-09-24 22:35:00 +00:00
|
|
|
bc().addReadOnly(overhangCB);
|
2007-09-27 21:05:36 +00:00
|
|
|
bc().addReadOnly(overhangED);
|
|
|
|
bc().addReadOnly(overhangUnitLC);
|
2007-09-24 22:35:00 +00:00
|
|
|
bc().addReadOnly(linesCB);
|
2007-09-27 21:05:36 +00:00
|
|
|
bc().addReadOnly(linesSB);
|
2007-09-24 13:43:58 +00:00
|
|
|
|
|
|
|
// initialize the length validator
|
|
|
|
bc().addCheckedLineEdit(widthED, widthLA);
|
2007-09-24 22:35:00 +00:00
|
|
|
bc().addCheckedLineEdit(overhangED, overhangCB);
|
2007-04-24 14:59:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 20:16:05 +00:00
|
|
|
void GuiWrap::change_adaptor()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 20:16:05 +00:00
|
|
|
void GuiWrap::applyView()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-24 13:43:58 +00:00
|
|
|
double const width_value = widthED->text().toDouble();
|
|
|
|
Length::UNIT widthUnit = widthUnitLC->currentLengthItem();
|
2007-09-05 20:33:29 +00:00
|
|
|
if (widthED->text().isEmpty())
|
2007-09-24 13:43:58 +00:00
|
|
|
widthUnit = Length::UNIT_NONE;
|
|
|
|
double const overhang_value = overhangED->text().toDouble();
|
|
|
|
Length::UNIT overhangUnit = overhangUnitLC->currentLengthItem();
|
|
|
|
if (overhangED->text().isEmpty())
|
|
|
|
overhangUnit = Length::UNIT_NONE;
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2007-10-05 20:16:05 +00:00
|
|
|
params_.width = Length(width_value, widthUnit);
|
2007-09-24 22:35:00 +00:00
|
|
|
|
|
|
|
if (overhangCB->checkState() == Qt::Checked)
|
2007-10-05 20:16:05 +00:00
|
|
|
params_.overhang = Length(overhang_value, overhangUnit);
|
2007-09-24 22:35:00 +00:00
|
|
|
else
|
|
|
|
// when value is "0" the option is not set in the LaTeX-output
|
|
|
|
// in InsetWrap.cpp
|
2007-10-05 20:16:05 +00:00
|
|
|
params_.overhang = Length("0in");
|
2007-09-24 22:35:00 +00:00
|
|
|
|
|
|
|
if (linesCB->checkState() == Qt::Checked)
|
2007-10-05 20:16:05 +00:00
|
|
|
params_.lines = linesSB->value();
|
2007-09-24 22:35:00 +00:00
|
|
|
else
|
|
|
|
// when value is "0" the option is not set in the LaTeX-output
|
|
|
|
// in InsetWrap.cpp
|
2007-10-05 20:16:05 +00:00
|
|
|
params_.lines = 0;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-03-02 17:12:22 +00:00
|
|
|
bool floatOn = false;
|
|
|
|
if (floatCB->checkState() == Qt::Checked)
|
|
|
|
floatOn = true;
|
2007-09-05 20:33:29 +00:00
|
|
|
switch (valignCO->currentIndex()) {
|
2006-03-05 17:24:44 +00:00
|
|
|
case 0:
|
2008-03-02 17:12:22 +00:00
|
|
|
if (floatOn)
|
|
|
|
params_.placement = "O";
|
|
|
|
else
|
|
|
|
params_.placement = "o";
|
2006-03-05 17:24:44 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2008-03-02 17:12:22 +00:00
|
|
|
if (floatOn)
|
|
|
|
params_.placement = "I";
|
|
|
|
else
|
|
|
|
params_.placement = "i";
|
2006-03-05 17:24:44 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2008-03-02 17:12:22 +00:00
|
|
|
if (floatOn)
|
|
|
|
params_.placement = "L";
|
|
|
|
else
|
|
|
|
params_.placement = "l";
|
2006-03-05 17:24:44 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2008-03-02 17:12:22 +00:00
|
|
|
if (floatOn)
|
|
|
|
params_.placement = "R";
|
|
|
|
else
|
|
|
|
params_.placement = "r";
|
2006-03-05 17:24:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-06 14:53:54 +00:00
|
|
|
void GuiWrap::paramsToDialog(InsetWrapParams const & params)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-10-05 20:16:05 +00:00
|
|
|
// 0pt is a legal width now, it yields a
|
|
|
|
// wrapfloat just wide enough for the contents.
|
2008-05-06 14:53:54 +00:00
|
|
|
Length len_w = params.width;
|
2007-09-24 13:43:58 +00:00
|
|
|
widthED->setText(QString::number(len_w.value()));
|
|
|
|
widthUnitLC->setCurrentItem(len_w.unit());
|
2007-10-03 09:57:51 +00:00
|
|
|
|
2008-05-06 14:53:54 +00:00
|
|
|
Length len_o(params.overhang);
|
2007-09-24 13:43:58 +00:00
|
|
|
overhangED->setText(QString::number(len_o.value()));
|
|
|
|
overhangUnitLC->setCurrentItem(len_o.unit());
|
2007-10-03 09:57:51 +00:00
|
|
|
if (len_o.value() == 0)
|
|
|
|
overhangCB->setCheckState(Qt::Unchecked);
|
|
|
|
else
|
|
|
|
overhangCB->setCheckState(Qt::Checked);
|
|
|
|
|
2008-05-06 14:53:54 +00:00
|
|
|
linesSB->setValue(params.lines);
|
|
|
|
if (params.lines == 0)
|
2007-10-03 09:57:51 +00:00
|
|
|
linesCB->setCheckState(Qt::Unchecked);
|
|
|
|
else
|
|
|
|
linesCB->setCheckState(Qt::Checked);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
int item = 0;
|
2008-05-06 14:53:54 +00:00
|
|
|
if (params.placement == "i" || params.placement == "I")
|
2006-03-05 17:24:44 +00:00
|
|
|
item = 1;
|
2008-05-06 14:53:54 +00:00
|
|
|
else if (params.placement == "l" || params.placement == "L")
|
2006-03-05 17:24:44 +00:00
|
|
|
item = 2;
|
2008-05-06 14:53:54 +00:00
|
|
|
else if (params.placement == "r" || params.placement == "R")
|
2006-03-05 17:24:44 +00:00
|
|
|
item = 3;
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
valignCO->setCurrentIndex(item);
|
2008-03-02 17:12:22 +00:00
|
|
|
|
2008-05-06 14:53:54 +00:00
|
|
|
if (params.placement == "O" || params.placement == "I"
|
|
|
|
|| params.placement == "L" || params.placement == "R")
|
2008-03-02 17:12:22 +00:00
|
|
|
floatCB->setCheckState(Qt::Checked);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-10-05 20:16:05 +00:00
|
|
|
|
|
|
|
bool GuiWrap::initialiseParams(string const & data)
|
|
|
|
{
|
2008-03-27 00:07:54 +00:00
|
|
|
InsetWrap::string2params(data, params_);
|
2008-05-06 14:53:54 +00:00
|
|
|
paramsToDialog(params_);
|
2007-10-05 20:16:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiWrap::clearParams()
|
|
|
|
{
|
|
|
|
params_ = InsetWrapParams();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiWrap::dispatchParams()
|
|
|
|
{
|
2008-03-27 00:07:54 +00:00
|
|
|
string const lfun = InsetWrap::params2string(params_);
|
2007-10-05 20:16:05 +00:00
|
|
|
dispatch(FuncRequest(getLfun(), lfun));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiWrap(GuiView & lv) { return new GuiWrap(lv); }
|
2007-10-05 20:16:05 +00:00
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-04-24 14:59:51 +00:00
|
|
|
|
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiWrap.cpp"
|