2003-11-29 09:39:35 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file QVSpace.C
|
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
|
|
#include "QVSpace.h"
|
|
|
|
|
#include "QVSpaceDialog.h"
|
|
|
|
|
#include "Qt2BC.h"
|
2004-05-20 09:36:28 +00:00
|
|
|
|
|
2004-11-22 12:22:19 +00:00
|
|
|
|
#include "checkedwidgets.h"
|
2004-05-20 09:36:28 +00:00
|
|
|
|
#include "lengthcombo.h"
|
2003-11-29 09:39:35 +00:00
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
2004-05-20 09:36:28 +00:00
|
|
|
|
#include "lyxrc.h" // to set the default length values
|
2003-11-29 09:39:35 +00:00
|
|
|
|
#include "Spacing.h"
|
|
|
|
|
#include "vspace.h"
|
|
|
|
|
|
2004-05-20 09:36:28 +00:00
|
|
|
|
#include "controllers/ControlVSpace.h"
|
|
|
|
|
#include "controllers/helper_funcs.h"
|
|
|
|
|
|
2003-11-29 09:39:35 +00:00
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
#include "support/tostr.h"
|
|
|
|
|
|
|
|
|
|
#include <qcombobox.h>
|
|
|
|
|
#include <qlineedit.h>
|
|
|
|
|
#include <qcheckbox.h>
|
|
|
|
|
#include <qpushbutton.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
namespace frontend {
|
2003-11-29 09:39:35 +00:00
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
void setWidgetsFromVSpace(VSpace const & space,
|
|
|
|
|
QComboBox * spacing,
|
|
|
|
|
QLineEdit * value,
|
2003-11-29 17:25:31 +00:00
|
|
|
|
LengthCombo * unit,
|
|
|
|
|
QCheckBox * keep)
|
2003-11-29 09:39:35 +00:00
|
|
|
|
{
|
|
|
|
|
int item = 0;
|
|
|
|
|
switch (space.kind()) {
|
|
|
|
|
case VSpace::DEFSKIP:
|
2003-12-01 14:16:27 +00:00
|
|
|
|
item = 0;
|
2003-11-29 09:39:35 +00:00
|
|
|
|
break;
|
|
|
|
|
case VSpace::SMALLSKIP:
|
2003-12-01 14:16:27 +00:00
|
|
|
|
item = 1;
|
2003-11-29 09:39:35 +00:00
|
|
|
|
break;
|
|
|
|
|
case VSpace::MEDSKIP:
|
2003-12-01 14:16:27 +00:00
|
|
|
|
item = 2;
|
2003-11-29 09:39:35 +00:00
|
|
|
|
break;
|
|
|
|
|
case VSpace::BIGSKIP:
|
2003-12-01 14:16:27 +00:00
|
|
|
|
item = 3;
|
2003-11-29 09:39:35 +00:00
|
|
|
|
break;
|
|
|
|
|
case VSpace::VFILL:
|
2003-12-01 14:16:27 +00:00
|
|
|
|
item = 4;
|
2003-11-29 09:39:35 +00:00
|
|
|
|
break;
|
|
|
|
|
case VSpace::LENGTH:
|
2003-12-01 14:16:27 +00:00
|
|
|
|
item = 5;
|
2003-11-29 09:39:35 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
spacing->setCurrentItem(item);
|
|
|
|
|
keep->setChecked(space.keep());
|
2003-11-29 17:25:31 +00:00
|
|
|
|
|
|
|
|
|
LyXLength::UNIT default_unit =
|
|
|
|
|
(lyxrc.default_papersize > 3) ? LyXLength::CM : LyXLength::IN;
|
|
|
|
|
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);
|
|
|
|
|
}
|
2003-11-29 09:39:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VSpace setVSpaceFromWidgets(int spacing,
|
2003-11-29 17:25:31 +00:00
|
|
|
|
QLineEdit * value,
|
|
|
|
|
LengthCombo * unit,
|
2003-11-29 09:39:35 +00:00
|
|
|
|
bool keep)
|
|
|
|
|
{
|
2003-12-01 21:24:18 +00:00
|
|
|
|
VSpace space;
|
2003-11-29 09:39:35 +00:00
|
|
|
|
|
|
|
|
|
switch (spacing) {
|
|
|
|
|
case 0:
|
|
|
|
|
space = VSpace(VSpace::DEFSKIP);
|
|
|
|
|
break;
|
2003-12-01 14:16:27 +00:00
|
|
|
|
case 1:
|
2003-11-29 09:39:35 +00:00
|
|
|
|
space = VSpace(VSpace::SMALLSKIP);
|
|
|
|
|
break;
|
2003-12-01 14:16:27 +00:00
|
|
|
|
case 2:
|
2003-11-29 09:39:35 +00:00
|
|
|
|
space = VSpace(VSpace::MEDSKIP);
|
|
|
|
|
break;
|
2003-12-01 14:16:27 +00:00
|
|
|
|
case 3:
|
2003-11-29 09:39:35 +00:00
|
|
|
|
space = VSpace(VSpace::BIGSKIP);
|
|
|
|
|
break;
|
2003-12-01 14:16:27 +00:00
|
|
|
|
case 4:
|
2003-11-29 09:39:35 +00:00
|
|
|
|
space = VSpace(VSpace::VFILL);
|
|
|
|
|
break;
|
2003-12-01 14:16:27 +00:00
|
|
|
|
case 5:
|
2003-11-29 17:25:31 +00:00
|
|
|
|
space = VSpace(LyXGlueLength(
|
|
|
|
|
widgetsToLength(value, unit)));
|
2003-11-29 09:39:35 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
space.setKeep(keep);
|
|
|
|
|
return space;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef QController<ControlVSpace, QView<QVSpaceDialog> > base_class;
|
|
|
|
|
|
|
|
|
|
QVSpace::QVSpace(Dialog & parent)
|
2003-11-29 17:25:31 +00:00
|
|
|
|
: base_class(parent, _("LyX: Vertical Space Settings"))
|
2003-11-29 09:39:35 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QVSpace::build_dialog()
|
|
|
|
|
{
|
|
|
|
|
// the tabbed folder
|
|
|
|
|
dialog_.reset(new QVSpaceDialog(this));
|
|
|
|
|
|
|
|
|
|
// 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);
|
2003-11-29 17:25:31 +00:00
|
|
|
|
|
2004-11-22 12:22:19 +00:00
|
|
|
|
// initialize the length validator
|
|
|
|
|
addCheckedLineEdit(bcview(), dialog_->valueLE, dialog_->valueL);
|
|
|
|
|
|
2003-11-29 17:25:31 +00:00
|
|
|
|
// remove the %-items from the unit choice
|
2003-12-01 07:54:02 +00:00
|
|
|
|
dialog_->unitCO->noPercents();
|
2003-11-29 09:39:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QVSpace::apply()
|
|
|
|
|
{
|
|
|
|
|
// spacing
|
|
|
|
|
// If a vspace choice is "Length" but there's no text in
|
2003-12-01 14:16:27 +00:00
|
|
|
|
// the input field, do not insert a vspace at all.
|
2003-12-01 21:24:18 +00:00
|
|
|
|
if (dialog_->spacingCO->currentItem() == 5
|
2003-11-29 09:39:35 +00:00
|
|
|
|
&& dialog_->valueLE->text().isEmpty())
|
2003-12-01 14:16:27 +00:00
|
|
|
|
return;
|
2003-11-29 09:39:35 +00:00
|
|
|
|
|
|
|
|
|
VSpace const space =
|
|
|
|
|
setVSpaceFromWidgets(dialog_->spacingCO->currentItem(),
|
2003-11-29 17:25:31 +00:00
|
|
|
|
dialog_->valueLE,
|
|
|
|
|
dialog_->unitCO,
|
2003-11-29 09:39:35 +00:00
|
|
|
|
dialog_->keepCB->isChecked());
|
|
|
|
|
|
|
|
|
|
controller().params() = space;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QVSpace::update_contents()
|
|
|
|
|
{
|
|
|
|
|
setWidgetsFromVSpace(controller().params(),
|
|
|
|
|
dialog_->spacingCO,
|
|
|
|
|
dialog_->valueLE,
|
|
|
|
|
dialog_->unitCO,
|
2003-11-29 17:25:31 +00:00
|
|
|
|
dialog_->keepCB);
|
2003-11-29 09:39:35 +00:00
|
|
|
|
}
|
2004-05-19 15:11:37 +00:00
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
|
} // namespace lyx
|