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.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
|
|
|
|
* \author Rob Lahaye
|
|
|
|
|
* \author Angus Leeming
|
|
|
|
|
* \author Edwin Leuven
|
|
|
|
|
* \author J<EFBFBD>rgen Spitzm<EFBFBD>ller
|
|
|
|
|
*
|
|
|
|
|
* 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-09-05 20:33:29 +00:00
|
|
|
|
#include "ControlVSpace.h"
|
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
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "LyXRC.h" // to set the default length values
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include "Spacing.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "VSpace.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
|
|
|
|
#include <QCheckBox>
|
2007-04-24 12:02:27 +00:00
|
|
|
|
#include <QCloseEvent>
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
namespace frontend {
|
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
GuiVSpaceDialog::GuiVSpaceDialog(LyXView & lv)
|
|
|
|
|
: GuiDialog(lv, "vspace")
|
2007-04-24 12:02:27 +00:00
|
|
|
|
{
|
|
|
|
|
setupUi(this);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
setViewTitle(_("Vertical Space Settings"));
|
|
|
|
|
setController(new ControlVSpace(*this));
|
2007-04-24 12:02:27 +00:00
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
|
|
|
|
|
connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
|
|
|
|
|
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
|
2007-04-24 12:02:27 +00:00
|
|
|
|
|
|
|
|
|
connect(spacingCO, SIGNAL(highlighted(const QString &)),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
connect(valueLE, SIGNAL(textChanged(const QString &)),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
connect(spacingCO, SIGNAL(activated(int)),
|
|
|
|
|
this, SLOT(enableCustom(int)));
|
|
|
|
|
connect(keepCB, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
2007-04-28 12:58:49 +00:00
|
|
|
|
connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
|
2007-04-24 12:02:27 +00:00
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
|
|
|
|
|
valueLE->setValidator(unsignedLengthValidator(valueLE));
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
|
|
// Manage the ok, apply, restore and cancel/close buttons
|
|
|
|
|
bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
|
|
|
|
|
bc().setOK(okPB);
|
|
|
|
|
bc().setApply(applyPB);
|
|
|
|
|
bc().setCancel(closePB);
|
|
|
|
|
|
|
|
|
|
// disable for read-only documents
|
|
|
|
|
bc().addReadOnly(spacingCO);
|
|
|
|
|
bc().addReadOnly(valueLE);
|
|
|
|
|
bc().addReadOnly(unitCO);
|
|
|
|
|
bc().addReadOnly(keepCB);
|
|
|
|
|
|
|
|
|
|
// initialize the length validator
|
|
|
|
|
bc().addCheckedLineEdit(valueLE, valueL);
|
|
|
|
|
|
|
|
|
|
// remove the %-items from the unit choice
|
|
|
|
|
unitCO->noPercents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-11 18:33:42 +00:00
|
|
|
|
ControlVSpace & GuiVSpaceDialog::controller()
|
2007-09-05 20:33:29 +00:00
|
|
|
|
{
|
2007-09-10 22:32:59 +00:00
|
|
|
|
return static_cast<ControlVSpace &>(GuiDialog::controller());
|
2007-04-24 12:02:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
void GuiVSpaceDialog::closeEvent(QCloseEvent * e)
|
2007-04-24 12:02:27 +00:00
|
|
|
|
{
|
2007-09-11 17:06:15 +00:00
|
|
|
|
slotClose();
|
2007-04-24 12:02:27 +00:00
|
|
|
|
e->accept();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
void GuiVSpaceDialog::change_adaptor()
|
2007-04-24 12:02:27 +00:00
|
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
|
changed();
|
2007-04-24 12:02:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
void GuiVSpaceDialog::enableCustom(int selection)
|
2007-04-24 12:02:27 +00:00
|
|
|
|
{
|
|
|
|
|
bool const enable = selection == 5;
|
|
|
|
|
valueLE->setEnabled(enable);
|
|
|
|
|
unitCO->setEnabled(enable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
|
Length::UNIT default_unit =
|
|
|
|
|
(lyxrc.default_papersize > 3) ? Length::CM : Length::IN;
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
void GuiVSpaceDialog::applyView()
|
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())
|
2006-03-05 17:24:44 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
VSpace const space = setVSpaceFromWidgets(spacingCO->currentIndex(),
|
|
|
|
|
valueLE, unitCO, keepCB->isChecked());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
controller().params() = space;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-11 18:33:42 +00:00
|
|
|
|
void GuiVSpaceDialog::updateContents()
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
setWidgetsFromVSpace(controller().params(),
|
2007-09-05 20:33:29 +00:00
|
|
|
|
spacingCO, valueLE, unitCO, keepCB);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
|
} // namespace lyx
|
2007-04-24 12:02:27 +00:00
|
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
#include "GuiVSpace_moc.cpp"
|