2010-09-07 00:41:00 +00:00
|
|
|
/**
|
|
|
|
* \file GuiLine.cpp
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2010-09-17 01:32:23 +00:00
|
|
|
* \author Abdelrazak Younes
|
2010-09-07 00:41:00 +00:00
|
|
|
* \author Uwe Stöhr
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "GuiLine.h"
|
|
|
|
|
|
|
|
#include "LengthCombo.h"
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
#include "Validator.h"
|
|
|
|
|
|
|
|
#include "FuncRequest.h"
|
|
|
|
|
|
|
|
#include "insets/InsetLine.h"
|
|
|
|
|
2012-06-28 18:52:20 +00:00
|
|
|
#include "support/debug.h"
|
2010-09-07 00:41:00 +00:00
|
|
|
#include "support/gettext.h"
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QValidator>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2010-09-07 14:13:28 +00:00
|
|
|
GuiLine::GuiLine(QWidget * parent) : InsetParamsWidget(parent)
|
2010-09-07 00:41:00 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
|
|
|
connect(OffsetLE, SIGNAL(textChanged(QString)),
|
2010-09-07 14:13:28 +00:00
|
|
|
this, SIGNAL(changed()));
|
2010-09-07 00:41:00 +00:00
|
|
|
connect(OffsetUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
|
2010-09-07 14:13:28 +00:00
|
|
|
this, SIGNAL(changed()));
|
2010-09-07 00:41:00 +00:00
|
|
|
connect(WidthLE, SIGNAL(textChanged(QString)),
|
2010-09-07 14:13:28 +00:00
|
|
|
this, SIGNAL(changed()));
|
2010-09-07 00:41:00 +00:00
|
|
|
connect(WidthUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
|
2010-09-07 14:13:28 +00:00
|
|
|
this, SIGNAL(changed()));
|
2010-09-07 00:41:00 +00:00
|
|
|
connect(HeightLE, SIGNAL(textChanged(QString)),
|
2010-09-07 14:13:28 +00:00
|
|
|
this, SIGNAL(changed()));
|
2010-09-07 00:41:00 +00:00
|
|
|
connect(HeightUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
|
2010-09-07 14:13:28 +00:00
|
|
|
this, SIGNAL(changed()));
|
2010-09-07 00:41:00 +00:00
|
|
|
|
|
|
|
// initialize the length validator
|
2010-09-07 14:13:28 +00:00
|
|
|
addCheckedWidget(OffsetLE, OffsetValueL);
|
|
|
|
addCheckedWidget(WidthLE, WidthValueL);
|
|
|
|
addCheckedWidget(HeightLE, HeightValueL);
|
2010-09-07 00:41:00 +00:00
|
|
|
|
|
|
|
OffsetLE->setValidator(unsignedGlueLengthValidator(OffsetLE));
|
|
|
|
WidthLE->setValidator(unsignedGlueLengthValidator(WidthLE));
|
|
|
|
HeightLE->setValidator(unsignedGlueLengthValidator(HeightLE));
|
2010-09-11 07:52:06 +00:00
|
|
|
|
2010-09-11 16:19:24 +00:00
|
|
|
OffsetLE->setText("0.5");
|
|
|
|
OffsetUnitCO->setCurrentItem(Length::EX);
|
2010-09-11 07:52:06 +00:00
|
|
|
WidthLE->setText("100");
|
2010-09-11 16:19:24 +00:00
|
|
|
WidthUnitCO->setCurrentItem(Length::PCW);
|
|
|
|
HeightLE->setText("1");
|
|
|
|
HeightUnitCO->setCurrentItem(Length::PT);
|
2010-09-11 07:52:06 +00:00
|
|
|
setFocusProxy(WidthLE);
|
2010-09-07 00:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-07 14:13:28 +00:00
|
|
|
docstring GuiLine::dialogToParams() const
|
2010-09-07 00:41:00 +00:00
|
|
|
{
|
2010-09-07 14:13:28 +00:00
|
|
|
InsetCommandParams params(insetCode());
|
2010-12-21 15:28:55 +00:00
|
|
|
params["offset"] = from_utf8(widgetsToLength(OffsetLE, OffsetUnitCO));
|
2010-09-11 07:52:06 +00:00
|
|
|
params["width"] = from_utf8(widgetsToLength(WidthLE, WidthUnitCO));
|
|
|
|
params["height"] = from_utf8(widgetsToLength(HeightLE, HeightUnitCO));
|
2010-09-07 14:13:28 +00:00
|
|
|
params.setCmdName("rule");
|
2010-10-29 00:25:28 +00:00
|
|
|
return from_ascii(InsetLine::params2string(params));
|
2010-09-07 00:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-07 14:13:28 +00:00
|
|
|
void GuiLine::paramsToDialog(Inset const * inset)
|
2010-09-07 00:41:00 +00:00
|
|
|
{
|
2010-09-07 14:13:28 +00:00
|
|
|
InsetLine const * line = static_cast<InsetLine const *>(inset);
|
|
|
|
InsetCommandParams const & params = line->params();
|
|
|
|
lengthToWidgets(OffsetLE,
|
|
|
|
OffsetUnitCO,
|
|
|
|
params["offset"],
|
|
|
|
Length::defaultUnit());
|
|
|
|
lengthToWidgets(WidthLE,
|
|
|
|
WidthUnitCO,
|
|
|
|
params["width"],
|
|
|
|
Length::defaultUnit());
|
|
|
|
lengthToWidgets(HeightLE,
|
|
|
|
HeightUnitCO,
|
|
|
|
params["height"],
|
|
|
|
Length::defaultUnit());
|
2010-09-07 00:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-30 12:44:11 +00:00
|
|
|
bool GuiLine::checkWidgets(bool readonly) const
|
2010-09-07 00:41:00 +00:00
|
|
|
{
|
2015-03-30 12:44:11 +00:00
|
|
|
WidthLE->setReadOnly(readonly);
|
|
|
|
HeightLE->setReadOnly(readonly);
|
|
|
|
OffsetLE->setReadOnly(readonly);
|
|
|
|
OffsetUnitCO->setEnabled(!readonly);
|
|
|
|
HeightUnitCO->setEnabled(!readonly);
|
|
|
|
WidthUnitCO->setEnabled(!readonly);
|
2010-09-07 14:13:28 +00:00
|
|
|
if (!InsetParamsWidget::checkWidgets())
|
|
|
|
return false;
|
2010-09-11 07:52:06 +00:00
|
|
|
// FIXME: this should be handled in unsignedGlueLengthValidator!
|
|
|
|
if (WidthLE->text().startsWith('-'))
|
|
|
|
return false;
|
|
|
|
// FIXME: this should be handled in unsignedGlueLengthValidator!
|
|
|
|
if (HeightLE->text().startsWith('-'))
|
|
|
|
return false;
|
2010-09-07 00:41:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
|
|
|
|
#include "moc_GuiLine.cpp"
|