2001-02-14 19:43:56 +00:00
|
|
|
/**
|
2001-08-19 13:25:15 +00:00
|
|
|
* \file QParagraph.C
|
2002-09-24 13:57:09 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2001-02-14 19:43:56 +00:00
|
|
|
*
|
2002-10-19 10:32:57 +00:00
|
|
|
* \author Edwin Leuven
|
2002-09-24 13:57:09 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2001-02-14 19:43:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2002-07-17 15:51:23 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
2001-02-14 19:43:56 +00:00
|
|
|
|
2002-07-17 15:51:23 +00:00
|
|
|
#include "ControlParagraph.h"
|
2001-08-19 13:25:15 +00:00
|
|
|
#include "QParagraph.h"
|
2002-07-17 15:51:23 +00:00
|
|
|
#include "QParagraphDialog.h"
|
|
|
|
#include "Qt2BC.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "ParagraphParameters.h"
|
2002-07-17 15:51:23 +00:00
|
|
|
#include "lyxrc.h" // to set the deafult length values
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "layout.h" // LyXAlignment
|
|
|
|
#include "helper_funcs.h"
|
|
|
|
#include "lyxgluelength.h"
|
|
|
|
#include "vspace.h"
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "support/LAssert.h"
|
|
|
|
|
|
|
|
#include <qcombobox.h>
|
|
|
|
#include <qlineedit.h>
|
|
|
|
#include <qcheckbox.h>
|
|
|
|
#include <qpushbutton.h>
|
|
|
|
#include <qtabwidget.h>
|
|
|
|
#include <qbuttongroup.h>
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
#include <functional>
|
|
|
|
|
2002-07-17 15:51:23 +00:00
|
|
|
using std::vector;
|
|
|
|
using std::bind2nd;
|
|
|
|
using std::remove_if;
|
|
|
|
|
|
|
|
typedef Qt2CB<ControlParagraph, Qt2DB<QParagraphDialog> > base_class;
|
2002-07-28 22:50:13 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-08-12 14:28:43 +00:00
|
|
|
QParagraph::QParagraph()
|
|
|
|
: base_class(_("Paragraph Layout"))
|
2002-07-17 15:51:23 +00:00
|
|
|
{}
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-07-17 15:51:23 +00:00
|
|
|
void QParagraph::build_dialog()
|
2001-02-14 19:43:56 +00:00
|
|
|
{
|
2002-07-17 15:51:23 +00:00
|
|
|
// the tabbed folder
|
|
|
|
dialog_.reset(new QParagraphDialog(this));
|
|
|
|
|
|
|
|
// Create the contents of the unit choices
|
|
|
|
// Don't include the "%" terms...
|
|
|
|
units_ = getLatexUnits();
|
2002-10-20 01:48:28 +00:00
|
|
|
vector<string>::iterator del =
|
|
|
|
remove_if(units_.begin(), units_.end(),
|
|
|
|
bind2nd(contains_functor(), "%"));
|
2002-07-17 15:51:23 +00:00
|
|
|
units_.erase(del, units_.end());
|
2002-07-28 22:50:13 +00:00
|
|
|
|
2002-07-17 15:51:23 +00:00
|
|
|
for (vector<string>::const_iterator it = units_.begin();
|
|
|
|
it != units_.end(); ++it) {
|
|
|
|
dialog_->unitAbove->insertItem(it->c_str());
|
|
|
|
dialog_->unitBelow->insertItem(it->c_str());
|
|
|
|
}
|
2002-07-28 22:50:13 +00:00
|
|
|
|
2002-07-17 15:51:23 +00:00
|
|
|
// Manage the ok, apply, restore and cancel/close buttons
|
|
|
|
bc().setOK(dialog_->okPB);
|
|
|
|
bc().setApply(dialog_->applyPB);
|
|
|
|
bc().setCancel(dialog_->closePB);
|
|
|
|
bc().setRestore(dialog_->restorePB);
|
|
|
|
bc().addReadOnly(dialog_->paragraphTab);
|
2001-02-14 19:43:56 +00:00
|
|
|
}
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-07-17 15:51:23 +00:00
|
|
|
namespace {
|
2001-05-09 09:14:50 +00:00
|
|
|
|
2002-07-17 15:51:23 +00:00
|
|
|
VSpace setVSpaceFromWidgets(int spacing,
|
|
|
|
string value,
|
|
|
|
string unit,
|
|
|
|
bool keep)
|
2001-02-14 19:43:56 +00:00
|
|
|
{
|
2002-07-17 15:51:23 +00:00
|
|
|
VSpace space;
|
|
|
|
|
|
|
|
switch (spacing) {
|
|
|
|
case 0:
|
|
|
|
space = VSpace(VSpace::NONE);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
space = VSpace(VSpace::DEFSKIP);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
space = VSpace(VSpace::SMALLSKIP);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
space = VSpace(VSpace::MEDSKIP);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
space = VSpace(VSpace::BIGSKIP);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
space = VSpace(VSpace::VFILL);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
string s;
|
2002-07-28 22:50:13 +00:00
|
|
|
string const length = trim(value);
|
2002-07-17 15:51:23 +00:00
|
|
|
if (isValidGlueLength(length)) {
|
|
|
|
s = length;
|
|
|
|
} else if (!length.empty()){
|
2002-07-28 22:50:13 +00:00
|
|
|
string u = trim(unit);
|
2002-07-17 15:51:23 +00:00
|
|
|
u = subst(u, "%%", "%");
|
|
|
|
s = length + u;
|
|
|
|
}
|
|
|
|
space = VSpace(LyXGlueLength(s));
|
|
|
|
break;
|
2001-02-14 19:43:56 +00:00
|
|
|
}
|
|
|
|
|
2002-07-17 15:51:23 +00:00
|
|
|
space.setKeep(keep);
|
2001-02-14 19:43:56 +00:00
|
|
|
|
2002-07-17 15:51:23 +00:00
|
|
|
return space;
|
2001-02-14 19:43:56 +00:00
|
|
|
}
|
|
|
|
|
2002-07-17 15:51:23 +00:00
|
|
|
} // namespace anon
|
2001-05-09 09:14:50 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
void QParagraph::apply()
|
2001-02-14 19:43:56 +00:00
|
|
|
{
|
2002-10-20 01:48:28 +00:00
|
|
|
ParagraphParameters & params = controller().params();
|
|
|
|
|
|
|
|
// SPACING ABOVE
|
2002-07-17 15:51:23 +00:00
|
|
|
// If a vspace kind is "Length" but there's no text in
|
|
|
|
// the input field, reset the kind to "None".
|
2002-10-20 01:48:28 +00:00
|
|
|
if (dialog_->spacingAbove->currentItem() == 5
|
2002-07-28 22:50:13 +00:00
|
|
|
&& dialog_->valueAbove->text().isEmpty())
|
2002-07-17 15:51:23 +00:00
|
|
|
dialog_->spacingAbove->setCurrentItem(0);
|
2002-07-28 22:50:13 +00:00
|
|
|
|
2002-07-17 15:51:23 +00:00
|
|
|
VSpace const space_top =
|
|
|
|
setVSpaceFromWidgets(dialog_->spacingAbove->currentItem(),
|
|
|
|
string(dialog_->valueAbove->text()),
|
|
|
|
string(dialog_->unitAbove->currentText()),
|
|
|
|
dialog_->keepAbove->isChecked());
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
params.spaceTop(space_top);
|
2002-07-28 22:50:13 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
// SPACING BELOW
|
|
|
|
if (dialog_->spacingBelow->currentItem() == 5
|
2002-07-28 22:50:13 +00:00
|
|
|
&& dialog_->valueBelow->text().isEmpty())
|
2002-07-17 15:51:23 +00:00
|
|
|
dialog_->spacingBelow->setCurrentItem(0);
|
|
|
|
|
|
|
|
VSpace const space_bottom =
|
|
|
|
setVSpaceFromWidgets(dialog_->spacingBelow->currentItem(),
|
|
|
|
string(dialog_->valueBelow->text()),
|
|
|
|
string(dialog_->unitBelow->currentText()),
|
|
|
|
dialog_->keepBelow->isChecked());
|
2002-07-28 22:50:13 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
params.spaceBottom(space_bottom);
|
2002-07-17 15:51:23 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
// alignment
|
2002-07-17 15:51:23 +00:00
|
|
|
LyXAlignment align;
|
|
|
|
switch (dialog_->align->currentItem()) {
|
|
|
|
case 0:
|
|
|
|
align = LYX_ALIGN_BLOCK;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
align = LYX_ALIGN_LEFT;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
align = LYX_ALIGN_RIGHT;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
align = LYX_ALIGN_CENTER;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
align = LYX_ALIGN_BLOCK;
|
|
|
|
}
|
2002-10-20 01:48:28 +00:00
|
|
|
params.align(align);
|
2002-07-28 22:50:13 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
// get spacing
|
2002-07-17 15:51:23 +00:00
|
|
|
Spacing::Space linespacing = Spacing::Default;
|
|
|
|
string other;
|
|
|
|
switch (dialog_->linespacing->currentItem()) {
|
|
|
|
case 0:
|
|
|
|
linespacing = Spacing::Default;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
linespacing = Spacing::Single;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
linespacing = Spacing::Onehalf;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
linespacing = Spacing::Double;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
linespacing = Spacing::Other;
|
|
|
|
other = dialog_->linespacingValue->text();
|
|
|
|
break;
|
|
|
|
}
|
2001-02-14 19:43:56 +00:00
|
|
|
|
2002-07-17 15:51:23 +00:00
|
|
|
Spacing const spacing(linespacing, other);
|
2002-10-20 01:48:28 +00:00
|
|
|
params.spacing(spacing);
|
|
|
|
|
|
|
|
// lines and pagebreaks
|
|
|
|
params.lineTop(dialog_->lineAbove->isChecked());
|
|
|
|
params.lineBottom(dialog_->lineBelow->isChecked());
|
|
|
|
params.pagebreakTop(dialog_->pagebreakAbove->isChecked());
|
|
|
|
params.pagebreakBottom(dialog_->pagebreakBelow->isChecked());
|
|
|
|
// label width
|
|
|
|
params.labelWidthString(string(dialog_->labelWidth->text()));
|
|
|
|
// indendation
|
|
|
|
params.noindent(dialog_->noindent->isChecked());
|
2001-03-23 06:31:30 +00:00
|
|
|
|
2001-02-14 19:43:56 +00:00
|
|
|
}
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-07-17 15:51:23 +00:00
|
|
|
namespace {
|
2001-05-09 09:14:50 +00:00
|
|
|
|
2002-07-17 15:51:23 +00:00
|
|
|
void setWidgetsFromVSpace(VSpace const & space,
|
|
|
|
QComboBox * spacing,
|
|
|
|
QLineEdit * value,
|
|
|
|
QComboBox * unit,
|
|
|
|
QCheckBox * keep, vector<string> units_)
|
2001-02-14 19:43:56 +00:00
|
|
|
{
|
2002-07-17 15:51:23 +00:00
|
|
|
value->setText("");
|
|
|
|
value->setEnabled(false);
|
|
|
|
unit->setEnabled(false);
|
|
|
|
|
2002-10-19 10:32:57 +00:00
|
|
|
int item = 0;
|
2002-07-17 15:51:23 +00:00
|
|
|
switch (space.kind()) {
|
|
|
|
case VSpace::NONE:
|
|
|
|
item = 0;
|
|
|
|
break;
|
|
|
|
case VSpace::DEFSKIP:
|
|
|
|
item = 1;
|
|
|
|
break;
|
|
|
|
case VSpace::SMALLSKIP:
|
|
|
|
item = 2;
|
|
|
|
break;
|
|
|
|
case VSpace::MEDSKIP:
|
|
|
|
item = 3;
|
|
|
|
break;
|
|
|
|
case VSpace::BIGSKIP:
|
|
|
|
item = 4;
|
|
|
|
break;
|
|
|
|
case VSpace::VFILL:
|
|
|
|
item = 5;
|
|
|
|
break;
|
2002-07-28 22:50:13 +00:00
|
|
|
case VSpace::LENGTH:
|
2002-07-17 15:51:23 +00:00
|
|
|
item = 6;
|
|
|
|
value->setEnabled(true);
|
|
|
|
unit->setEnabled(true);
|
|
|
|
string length = space.length().asString();
|
2002-10-20 01:48:28 +00:00
|
|
|
string const default_unit =
|
|
|
|
(lyxrc.default_papersize > 3) ? "cm" : "in";
|
2002-07-17 15:51:23 +00:00
|
|
|
string supplied_unit = default_unit;
|
|
|
|
LyXLength len(length);
|
2002-10-20 01:48:28 +00:00
|
|
|
if ((isValidLength(length)
|
|
|
|
|| isStrDbl(length)) && !len.zero()) {
|
2002-07-17 15:51:23 +00:00
|
|
|
ostringstream buffer;
|
|
|
|
buffer << len.value();
|
|
|
|
length = buffer.str();
|
2002-10-20 01:48:28 +00:00
|
|
|
supplied_unit = subst(stringFromUnit(len.unit()),
|
|
|
|
"%", "%%");
|
2002-07-17 15:51:23 +00:00
|
|
|
}
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-07-17 15:51:23 +00:00
|
|
|
int unit_item = 0;
|
|
|
|
int i = 0;
|
|
|
|
for (vector<string>::const_iterator it = units_.begin();
|
|
|
|
it != units_.end(); ++it) {
|
2002-10-20 01:48:28 +00:00
|
|
|
if (*it == default_unit) {
|
2002-07-17 15:51:23 +00:00
|
|
|
unit_item = i;
|
|
|
|
}
|
2002-10-20 01:48:28 +00:00
|
|
|
if (*it == supplied_unit) {
|
2002-07-17 15:51:23 +00:00
|
|
|
unit_item = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
value->setText(length.c_str());
|
|
|
|
unit->setCurrentItem(unit_item);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
spacing->setCurrentItem(item);
|
|
|
|
keep->setChecked(space.keep());
|
|
|
|
}
|
2001-02-14 19:43:56 +00:00
|
|
|
|
2002-07-17 15:51:23 +00:00
|
|
|
} // namespace anon
|
2001-03-23 06:31:30 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-07-17 15:51:23 +00:00
|
|
|
void QParagraph::update_contents()
|
|
|
|
{
|
2002-10-20 01:48:28 +00:00
|
|
|
ParagraphParameters const & params = controller().params();
|
|
|
|
|
|
|
|
// label width
|
|
|
|
string const & labelwidth = params.labelWidthString();
|
2002-07-17 15:51:23 +00:00
|
|
|
dialog_->labelWidth->setText(labelwidth.c_str());
|
|
|
|
dialog_->labelwidthGB->setEnabled(
|
|
|
|
labelwidth != _("Senseless with this layout!"));
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
// alignment
|
2002-07-17 15:51:23 +00:00
|
|
|
int i;
|
2002-10-20 01:48:28 +00:00
|
|
|
switch (params.align()) {
|
2002-07-17 15:51:23 +00:00
|
|
|
case LYX_ALIGN_LEFT:
|
|
|
|
i = 1;
|
|
|
|
break;
|
|
|
|
case LYX_ALIGN_RIGHT:
|
|
|
|
i = 2;
|
|
|
|
break;
|
|
|
|
case LYX_ALIGN_CENTER:
|
|
|
|
i = 3;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
i = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dialog_->align->setCurrentItem(i);
|
2002-07-28 22:50:13 +00:00
|
|
|
|
2002-07-17 15:51:23 +00:00
|
|
|
|
|
|
|
//LyXAlignment alignpos = controller().alignPossible();
|
|
|
|
|
|
|
|
// no inset-text-owned paragraph may have pagebreaks
|
|
|
|
bool ininset = controller().inInset();
|
|
|
|
dialog_->pagebreakAbove->setEnabled(!ininset);
|
|
|
|
dialog_->pagebreakBelow->setEnabled(!ininset);
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
// lines, pagebreaks and indent
|
|
|
|
dialog_->lineAbove->setChecked(params.lineTop());
|
|
|
|
dialog_->lineBelow->setChecked(params.lineBottom());
|
|
|
|
dialog_->pagebreakAbove->setChecked(params.pagebreakTop());
|
|
|
|
dialog_->pagebreakBelow->setChecked(params.pagebreakBottom());
|
|
|
|
dialog_->noindent->setChecked(params.noindent());
|
2002-07-17 15:51:23 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
// linespacing
|
2002-07-17 15:51:23 +00:00
|
|
|
int linespacing;
|
2002-10-20 01:48:28 +00:00
|
|
|
Spacing const & space = params.spacing();
|
2002-07-17 15:51:23 +00:00
|
|
|
switch (space.getSpace()) {
|
|
|
|
case Spacing::Single:
|
|
|
|
linespacing = 1;
|
|
|
|
break;
|
|
|
|
case Spacing::Onehalf:
|
|
|
|
linespacing = 2;
|
|
|
|
break;
|
|
|
|
case Spacing::Double:
|
|
|
|
linespacing = 3;
|
|
|
|
break;
|
|
|
|
case Spacing::Other:
|
|
|
|
linespacing = 4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
linespacing = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dialog_->linespacing->setCurrentItem(linespacing);
|
|
|
|
if (space.getSpace() == Spacing::Other) {
|
|
|
|
string const sp = tostr(space.getValue());
|
|
|
|
dialog_->linespacingValue->setText(sp.c_str());
|
|
|
|
dialog_->linespacingValue->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
dialog_->linespacingValue->setText("");
|
|
|
|
dialog_->linespacingValue->setEnabled(false);
|
|
|
|
}
|
2001-03-23 06:31:30 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
// vspace top
|
|
|
|
setWidgetsFromVSpace(params.spaceTop(),
|
2002-07-17 15:51:23 +00:00
|
|
|
dialog_->spacingAbove,
|
|
|
|
dialog_->valueAbove,
|
|
|
|
dialog_->unitAbove,
|
|
|
|
dialog_->keepAbove,units_);
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
// vspace bottom
|
|
|
|
setWidgetsFromVSpace(params.spaceBottom(),
|
2002-07-17 15:51:23 +00:00
|
|
|
dialog_->spacingBelow,
|
|
|
|
dialog_->valueBelow,
|
|
|
|
dialog_->unitBelow,
|
|
|
|
dialog_->keepBelow,units_);
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
// no indent
|
|
|
|
dialog_->noindent->setChecked(params.noindent());
|
2001-02-14 19:43:56 +00:00
|
|
|
}
|