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
|
|
|
|
#include "Qt2BC.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 "controllers/ControlVSpace.h"
|
2007-04-25 17:53:54 +00:00
|
|
|
|
#include "controllers/frontend_helpers.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;
|
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
|
|
|
2007-04-24 12:02:27 +00:00
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
2007-08-31 05:53:55 +00:00
|
|
|
|
// GuiVSpaceDialog
|
2007-04-24 12:02:27 +00:00
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
GuiVSpaceDialog::GuiVSpaceDialog(GuiVSpace * form)
|
2007-04-24 12:02:27 +00:00
|
|
|
|
: form_(form)
|
|
|
|
|
{
|
|
|
|
|
setupUi(this);
|
|
|
|
|
|
|
|
|
|
connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
|
|
|
|
|
connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply()));
|
|
|
|
|
connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
|
|
|
|
|
|
|
|
|
|
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-08-31 05:53:55 +00:00
|
|
|
|
void GuiVSpaceDialog::closeEvent(QCloseEvent * e)
|
2007-04-24 12:02:27 +00:00
|
|
|
|
{
|
|
|
|
|
form_->slotWMHide();
|
|
|
|
|
e->accept();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
void GuiVSpaceDialog::change_adaptor()
|
2007-04-24 12:02:27 +00:00
|
|
|
|
{
|
|
|
|
|
form_->changed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
2007-08-31 05:53:55 +00:00
|
|
|
|
// GuiVSpace
|
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()) {
|
|
|
|
|
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-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,
|
2006-03-05 17:24:44 +00:00
|
|
|
|
QLineEdit * value,
|
|
|
|
|
LengthCombo * unit,
|
|
|
|
|
bool keep)
|
|
|
|
|
{
|
|
|
|
|
VSpace space;
|
|
|
|
|
|
|
|
|
|
switch (spacing) {
|
|
|
|
|
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:
|
2007-04-28 12:58:49 +00:00
|
|
|
|
space = VSpace(GlueLength(widgetsToLength(value, unit)));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
space.setKeep(keep);
|
|
|
|
|
return space;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
GuiVSpace::GuiVSpace(Dialog & parent)
|
2007-08-31 22:16:11 +00:00
|
|
|
|
: GuiView<GuiVSpaceDialog>(parent, _("Vertical Space Settings"))
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
void GuiVSpace::build_dialog()
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
// the tabbed folder
|
2007-08-31 05:53:55 +00:00
|
|
|
|
dialog_.reset(new GuiVSpaceDialog(this));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
// Manage the ok, apply, restore and cancel/close buttons
|
|
|
|
|
bcview().setOK(dialog_->okPB);
|
|
|
|
|
bcview().setApply(dialog_->applyPB);
|
|
|
|
|
bcview().setCancel(dialog_->closePB);
|
|
|
|
|
|
|
|
|
|
// disable for read-only documents
|
|
|
|
|
bcview().addReadOnly(dialog_->spacingCO);
|
|
|
|
|
bcview().addReadOnly(dialog_->valueLE);
|
|
|
|
|
bcview().addReadOnly(dialog_->unitCO);
|
|
|
|
|
bcview().addReadOnly(dialog_->keepCB);
|
|
|
|
|
|
|
|
|
|
// initialize the length validator
|
|
|
|
|
addCheckedLineEdit(bcview(), dialog_->valueLE, dialog_->valueL);
|
|
|
|
|
|
|
|
|
|
// remove the %-items from the unit choice
|
|
|
|
|
dialog_->unitCO->noPercents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
void GuiVSpace::apply()
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
// spacing
|
|
|
|
|
// If a vspace choice is "Length" but there's no text in
|
|
|
|
|
// the input field, do not insert a vspace at all.
|
2006-08-17 09:02:46 +00:00
|
|
|
|
if (dialog_->spacingCO->currentIndex() == 5
|
2006-03-05 17:24:44 +00:00
|
|
|
|
&& dialog_->valueLE->text().isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
VSpace const space =
|
2006-08-17 09:02:46 +00:00
|
|
|
|
setVSpaceFromWidgets(dialog_->spacingCO->currentIndex(),
|
2006-03-05 17:24:44 +00:00
|
|
|
|
dialog_->valueLE,
|
|
|
|
|
dialog_->unitCO,
|
|
|
|
|
dialog_->keepCB->isChecked());
|
|
|
|
|
|
|
|
|
|
controller().params() = space;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
void GuiVSpace::update_contents()
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
setWidgetsFromVSpace(controller().params(),
|
|
|
|
|
dialog_->spacingCO,
|
|
|
|
|
dialog_->valueLE,
|
|
|
|
|
dialog_->unitCO,
|
|
|
|
|
dialog_->keepCB);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
|
} // namespace lyx
|
2007-04-24 12:02:27 +00:00
|
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
#include "GuiVSpace_moc.cpp"
|