2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiVSpace.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 André Pönitz
|
|
|
|
* \author Jürgen Vigna
|
2006-03-05 17:24:44 +00:00
|
|
|
* \author Rob Lahaye
|
|
|
|
* \author Angus Leeming
|
|
|
|
* \author Edwin Leuven
|
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 "GuiVSpace.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-04-26 03:53:02 +00:00
|
|
|
#include "Validator.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2010-02-15 23:17:45 +00:00
|
|
|
#include "Spacing.h"
|
|
|
|
#include "VSpace.h"
|
2008-03-27 00:21:35 +00:00
|
|
|
|
2007-10-05 22:27:04 +00:00
|
|
|
#include "insets/InsetVSpace.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 <QCheckBox>
|
2007-04-24 12:02:27 +00:00
|
|
|
#include <QLineEdit>
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QPushButton>
|
2007-04-24 12:02:27 +00:00
|
|
|
#include <QValidator>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
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 {
|
|
|
|
|
2010-02-15 23:17:45 +00:00
|
|
|
GuiVSpace::GuiVSpace(QWidget * parent) : InsetParamsWidget(parent)
|
2007-04-24 12:02:27 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
2007-10-09 21:21:01 +00:00
|
|
|
connect(valueLE, SIGNAL(textChanged(QString)),
|
2010-02-15 23:17:45 +00:00
|
|
|
this, SIGNAL(changed()));
|
2007-04-24 12:02:27 +00:00
|
|
|
connect(keepCB, SIGNAL(clicked()),
|
2010-02-15 23:17:45 +00:00
|
|
|
this, SIGNAL(changed()));
|
2007-04-28 12:58:49 +00:00
|
|
|
connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
|
2010-02-15 23:17:45 +00:00
|
|
|
this, SIGNAL(changed()));
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2010-02-15 23:17:45 +00:00
|
|
|
connect(spacingCO, SIGNAL(activated(int)),
|
|
|
|
this, SLOT(enableCustom(int)));
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2010-02-15 23:17:45 +00:00
|
|
|
valueLE->setValidator(unsignedGlueLengthValidator(valueLE));
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
// initialize the length validator
|
2010-02-15 23:17:45 +00:00
|
|
|
addCheckedWidget(valueLE, valueL);
|
2013-11-14 09:42:24 +00:00
|
|
|
enableCustom(spacingCO->currentIndex());
|
2007-04-24 12:02:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 22:27:04 +00:00
|
|
|
void GuiVSpace::enableCustom(int selection)
|
2007-04-24 12:02:27 +00:00
|
|
|
{
|
|
|
|
bool const enable = selection == 5;
|
|
|
|
valueLE->setEnabled(enable);
|
2013-11-15 06:03:14 +00:00
|
|
|
if (enable)
|
|
|
|
valueLE->setFocus();
|
2013-11-14 09:42:24 +00:00
|
|
|
valueL->setEnabled(enable);
|
2007-04-24 12:02:27 +00:00
|
|
|
unitCO->setEnabled(enable);
|
2013-11-14 09:42:24 +00:00
|
|
|
changed();
|
2007-04-24 12:02:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void setWidgetsFromVSpace(VSpace const & space,
|
2006-03-05 17:24:44 +00:00
|
|
|
QComboBox * spacing,
|
|
|
|
QLineEdit * value,
|
|
|
|
LengthCombo * unit,
|
|
|
|
QCheckBox * keep)
|
|
|
|
{
|
|
|
|
int item = 0;
|
|
|
|
switch (space.kind()) {
|
2007-09-05 20:33:29 +00:00
|
|
|
case VSpace::DEFSKIP: item = 0; break;
|
|
|
|
case VSpace::SMALLSKIP: item = 1; break;
|
|
|
|
case VSpace::MEDSKIP: item = 2; break;
|
|
|
|
case VSpace::BIGSKIP: item = 3; break;
|
|
|
|
case VSpace::VFILL: item = 4; break;
|
|
|
|
case VSpace::LENGTH: item = 5; break;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
2006-08-17 09:02:46 +00:00
|
|
|
spacing->setCurrentIndex(item);
|
2006-03-05 17:24:44 +00:00
|
|
|
keep->setChecked(space.keep());
|
|
|
|
|
2009-02-06 21:24:13 +00:00
|
|
|
Length::UNIT const default_unit = Length::defaultUnit();
|
2006-03-05 17:24:44 +00:00
|
|
|
bool const custom_vspace = space.kind() == VSpace::LENGTH;
|
|
|
|
if (custom_vspace) {
|
|
|
|
value->setEnabled(true);
|
|
|
|
unit->setEnabled(true);
|
|
|
|
string length = space.length().asString();
|
|
|
|
lengthToWidgets(value, unit, length, default_unit);
|
|
|
|
} else {
|
|
|
|
lengthToWidgets(value, unit, "", default_unit);
|
|
|
|
value->setEnabled(false);
|
|
|
|
unit->setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-24 12:02:27 +00:00
|
|
|
static VSpace setVSpaceFromWidgets(int spacing,
|
2007-09-05 20:33:29 +00:00
|
|
|
QLineEdit * value, LengthCombo * unit, bool keep)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
VSpace space;
|
|
|
|
|
|
|
|
switch (spacing) {
|
2007-09-05 20:33:29 +00:00
|
|
|
case 0: space = VSpace(VSpace::DEFSKIP); break;
|
|
|
|
case 1: space = VSpace(VSpace::SMALLSKIP); break;
|
|
|
|
case 2: space = VSpace(VSpace::MEDSKIP); break;
|
|
|
|
case 3: space = VSpace(VSpace::BIGSKIP); break;
|
|
|
|
case 4: space = VSpace(VSpace::VFILL); break;
|
|
|
|
case 5: space = VSpace(GlueLength(widgetsToLength(value, unit))); break;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
space.setKeep(keep);
|
|
|
|
return space;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-15 23:17:45 +00:00
|
|
|
docstring GuiVSpace::dialogToParams() const
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
// If a vspace choice is "Length" but there's no text in
|
|
|
|
// the input field, do not insert a vspace at all.
|
2007-09-05 20:33:29 +00:00
|
|
|
if (spacingCO->currentIndex() == 5 && valueLE->text().isEmpty())
|
2010-02-15 23:17:45 +00:00
|
|
|
return docstring();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2010-02-15 23:17:45 +00:00
|
|
|
VSpace const params = setVSpaceFromWidgets(spacingCO->currentIndex(),
|
|
|
|
valueLE, unitCO, keepCB->isChecked());
|
|
|
|
return from_ascii(InsetVSpace::params2string(params));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-15 23:17:45 +00:00
|
|
|
void GuiVSpace::paramsToDialog(Inset const * inset)
|
2007-10-05 22:27:04 +00:00
|
|
|
{
|
2010-02-15 23:17:45 +00:00
|
|
|
InsetVSpace const * vs = static_cast<InsetVSpace const *>(inset);
|
|
|
|
VSpace const & params = vs->space();
|
|
|
|
setWidgetsFromVSpace(params, spacingCO, valueLE, unitCO, keepCB);
|
2013-11-15 18:29:15 +00:00
|
|
|
enableCustom(spacingCO->currentIndex());
|
2007-10-05 22:27:04 +00:00
|
|
|
}
|
|
|
|
|
2015-04-02 15:03:08 +00:00
|
|
|
|
|
|
|
bool GuiVSpace::checkWidgets(bool readonly) const
|
|
|
|
{
|
|
|
|
valueLE->setReadOnly(readonly);
|
|
|
|
keepCB->setEnabled(!readonly);
|
|
|
|
|
2015-05-11 09:35:02 +00:00
|
|
|
if (readonly) {
|
|
|
|
spacingCO->setEnabled(false);
|
|
|
|
unitCO->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
bool const enable = (spacingCO->currentIndex() == 5);
|
|
|
|
valueLE->setEnabled(enable);
|
|
|
|
valueL->setEnabled(enable);
|
|
|
|
unitCO->setEnabled(enable);
|
|
|
|
}
|
|
|
|
|
2015-04-02 15:03:08 +00:00
|
|
|
return InsetParamsWidget::checkWidgets();
|
|
|
|
}
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-04-24 12:02:27 +00:00
|
|
|
|
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiVSpace.cpp"
|