2001-02-14 19:43:56 +00:00
|
|
|
/**
|
2001-08-19 13:25:15 +00:00
|
|
|
* \file QParagraph.C
|
2001-02-14 19:43:56 +00:00
|
|
|
* Copyright 2001 LyX Team
|
|
|
|
* see the file COPYING
|
|
|
|
*
|
|
|
|
* \author John Levon, moz@compsoc.man.ac.uk
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
#include "QParagraphDialog.h"
|
2001-02-14 19:43:56 +00:00
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
#include "QParagraph.h"
|
2001-02-14 19:43:56 +00:00
|
|
|
#include "Liason.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "QtLyXView.h"
|
2002-01-04 03:21:47 +00:00
|
|
|
#include "lyxtextclasslist.h"
|
2001-02-14 19:43:56 +00:00
|
|
|
#include "lyxtext.h"
|
|
|
|
#include "debug.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "BufferView.h"
|
|
|
|
#include "ParagraphParameters.h"
|
2001-02-14 19:43:56 +00:00
|
|
|
|
2001-03-26 19:34:45 +00:00
|
|
|
using SigC::slot;
|
2001-02-14 19:43:56 +00:00
|
|
|
using Liason::setMinibuffer;
|
|
|
|
using std::endl;
|
|
|
|
|
2001-05-09 09:14:50 +00:00
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
QParagraph::QParagraph(LyXView *v, Dialogs *d)
|
2001-02-14 19:43:56 +00:00
|
|
|
: dialog_(0), lv_(v), d_(d), h_(0)
|
|
|
|
{
|
2001-08-19 13:25:15 +00:00
|
|
|
d->showParagraph.connect(slot(this, &QParagraph::show));
|
2001-02-14 19:43:56 +00:00
|
|
|
}
|
|
|
|
|
2001-05-09 09:14:50 +00:00
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
QParagraph::~QParagraph()
|
2001-02-14 19:43:56 +00:00
|
|
|
{
|
|
|
|
delete dialog_;
|
|
|
|
}
|
|
|
|
|
2001-05-09 09:14:50 +00:00
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
void QParagraph::update(bool switched)
|
2001-02-14 19:43:56 +00:00
|
|
|
{
|
|
|
|
if (switched) {
|
|
|
|
hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lv_->view()->available())
|
|
|
|
return;
|
|
|
|
|
2001-05-09 09:14:50 +00:00
|
|
|
Buffer * buf = lv_->view()->buffer();
|
2001-03-23 06:31:30 +00:00
|
|
|
|
2001-02-14 19:43:56 +00:00
|
|
|
if (readonly!=buf->isReadonly()) {
|
|
|
|
readonly = buf->isReadonly();
|
|
|
|
dialog_->setReadOnly(readonly);
|
|
|
|
}
|
|
|
|
|
2001-12-05 05:53:01 +00:00
|
|
|
LyXText * text(lv_->view()->getLyXText());
|
2001-06-25 00:06:33 +00:00
|
|
|
Paragraph * par = text->cursor.par();
|
2001-02-14 19:43:56 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
int align = par->getAlign();
|
2001-03-23 06:31:30 +00:00
|
|
|
|
2001-02-14 19:43:56 +00:00
|
|
|
if (align==LYX_ALIGN_LAYOUT)
|
2001-06-25 00:06:33 +00:00
|
|
|
align = textclasslist.Style(buf->params.textclass, par->getLayout()).align;
|
2001-02-14 19:43:56 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
ParagraphParameters * params = &(par->params());
|
2001-03-23 06:31:30 +00:00
|
|
|
|
2001-03-12 11:22:26 +00:00
|
|
|
if (params->spaceTop().kind() == VSpace::LENGTH) {
|
|
|
|
LyXGlueLength above = params->spaceTop().length();
|
|
|
|
lyxerr[Debug::GUI] << "Reading above space : \"" << params->spaceTop().length().asString() << "\"" << endl;
|
2001-12-05 18:32:49 +00:00
|
|
|
dialog_->setAboveLength(above.len().value(), above.plus().value(), above.minus().value(),
|
|
|
|
above.len().unit(), above.plus().unit(), above.minus().unit());
|
2001-02-14 19:43:56 +00:00
|
|
|
} else
|
|
|
|
dialog_->setAboveLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
|
|
|
|
|
2001-03-12 11:22:26 +00:00
|
|
|
if (params->spaceBottom().kind() == VSpace::LENGTH) {
|
|
|
|
LyXGlueLength below = params->spaceBottom().length();
|
|
|
|
lyxerr[Debug::GUI] << "Reading below space : \"" << params->spaceBottom().length().asString() << "\"" << endl;
|
2001-12-05 18:32:49 +00:00
|
|
|
dialog_->setBelowLength(below.len().value(), below.plus().value(), below.minus().value(),
|
|
|
|
below.len().unit(), below.plus().unit(), below.minus().unit());
|
2001-02-14 19:43:56 +00:00
|
|
|
} else
|
|
|
|
dialog_->setBelowLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
dialog_->setLabelWidth(text->cursor.par()->getLabelWidthString().c_str());
|
2001-02-14 19:43:56 +00:00
|
|
|
dialog_->setAlign(align);
|
2001-03-12 11:22:26 +00:00
|
|
|
dialog_->setChecks(params->lineTop(), params->lineBottom(),
|
|
|
|
params->pagebreakTop(), params->pagebreakBottom(), params->noindent());
|
|
|
|
dialog_->setSpace(params->spaceTop().kind(), params->spaceBottom().kind(),
|
|
|
|
params->spaceTop().keep(), params->spaceBottom().keep());
|
2001-02-14 19:43:56 +00:00
|
|
|
|
|
|
|
// now the extras page
|
|
|
|
|
|
|
|
LyXLength extrawidth;
|
|
|
|
float val = 0.0;
|
|
|
|
LyXLength::UNIT unit = LyXLength::CM;
|
2001-06-25 00:06:33 +00:00
|
|
|
params = &(par->params());
|
2001-03-12 11:22:26 +00:00
|
|
|
if (isValidLength(params->pextraWidth(), &extrawidth)) {
|
2001-02-14 19:43:56 +00:00
|
|
|
lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
|
|
|
|
val = extrawidth.value();
|
|
|
|
unit = extrawidth.unit();
|
|
|
|
}
|
|
|
|
|
2001-03-12 11:22:26 +00:00
|
|
|
lyxerr[Debug::GUI] << "Reading widthp \"" << params->pextraWidthp() << "\"" << endl;
|
2001-02-14 19:43:56 +00:00
|
|
|
|
2001-03-12 11:22:26 +00:00
|
|
|
dialog_->setExtra(val, unit, params->pextraWidthp(),
|
|
|
|
params->pextraAlignment(),
|
|
|
|
params->pextraHfill(),
|
|
|
|
params->pextraStartMinipage(),
|
2001-06-25 00:06:33 +00:00
|
|
|
static_cast<Paragraph::PEXTRA_TYPE>(params->pextraType()));
|
2001-02-14 19:43:56 +00:00
|
|
|
}
|
|
|
|
|
2001-05-09 09:14:50 +00:00
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
void QParagraph::apply()
|
2001-02-14 19:43:56 +00:00
|
|
|
{
|
|
|
|
if (readonly)
|
|
|
|
return;
|
|
|
|
|
|
|
|
VSpace spaceabove;
|
|
|
|
VSpace spacebelow;
|
|
|
|
|
|
|
|
if (dialog_->getSpaceAboveKind()==VSpace::LENGTH)
|
|
|
|
spaceabove = VSpace(dialog_->getAboveLength());
|
|
|
|
else
|
|
|
|
spaceabove = VSpace(dialog_->getSpaceAboveKind());
|
|
|
|
|
|
|
|
if (dialog_->getSpaceBelowKind()==VSpace::LENGTH)
|
|
|
|
spacebelow = VSpace(dialog_->getBelowLength());
|
|
|
|
else
|
|
|
|
spacebelow = VSpace(dialog_->getSpaceBelowKind());
|
|
|
|
|
|
|
|
spaceabove.setKeep(dialog_->getAboveKeep());
|
|
|
|
spacebelow.setKeep(dialog_->getBelowKeep());
|
|
|
|
|
|
|
|
lyxerr[Debug::GUI] << "Setting above space \"" << LyXGlueLength(spaceabove.length().asString()).asString() << "\"" << endl;
|
|
|
|
lyxerr[Debug::GUI] << "Setting below space \"" << LyXGlueLength(spacebelow.length().asString()).asString() << "\"" << endl;
|
|
|
|
|
2001-12-05 05:53:01 +00:00
|
|
|
LyXText * text(lv_->view()->getLyXText());
|
|
|
|
text->setParagraph(lv_->view(),
|
|
|
|
dialog_->getLineAbove(), dialog_->getLineBelow(),
|
|
|
|
dialog_->getPagebreakAbove(), dialog_->getPagebreakBelow(),
|
|
|
|
spaceabove, spacebelow, Spacing(), dialog_->getAlign(),
|
|
|
|
dialog_->getLabelWidth(), dialog_->getNoIndent());
|
2001-02-14 19:43:56 +00:00
|
|
|
|
|
|
|
// extra stuff
|
|
|
|
|
|
|
|
string width("");
|
|
|
|
string widthp("");
|
|
|
|
|
|
|
|
LyXLength extrawidth(dialog_->getExtraWidth());
|
|
|
|
if (extrawidth.unit()==LyXLength::UNIT_NONE) {
|
|
|
|
widthp = dialog_->getExtraWidthPercent();
|
|
|
|
} else
|
|
|
|
width = extrawidth.asString();
|
|
|
|
|
|
|
|
lyxerr[Debug::GUI] << "Setting extrawidth \"" << width << "\"" << endl;
|
|
|
|
lyxerr[Debug::GUI] << "Setting percent extrawidth \"" << widthp << "\"" << endl;
|
|
|
|
|
2001-12-05 05:53:01 +00:00
|
|
|
lv_->view()->update(text,
|
2001-02-23 16:19:54 +00:00
|
|
|
BufferView::SELECT |
|
|
|
|
BufferView::FITCUR |
|
|
|
|
BufferView::CHANGE);
|
2001-03-23 06:31:30 +00:00
|
|
|
|
2001-02-14 19:43:56 +00:00
|
|
|
lv_->buffer()->markDirty();
|
|
|
|
setMinibuffer(lv_, _("Paragraph layout set"));
|
|
|
|
}
|
|
|
|
|
2001-05-09 09:14:50 +00:00
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
void QParagraph::show()
|
2001-02-14 19:43:56 +00:00
|
|
|
{
|
|
|
|
if (!dialog_)
|
2001-08-19 13:25:15 +00:00
|
|
|
dialog_ = new QParagraphDialog(this, 0,
|
|
|
|
_("LyX: Paragraph Settings"),
|
2001-05-09 09:14:50 +00:00
|
|
|
false);
|
2001-02-14 19:43:56 +00:00
|
|
|
|
|
|
|
if (!dialog_->isVisible())
|
2001-05-09 09:14:50 +00:00
|
|
|
h_ = d_->hideBufferDependent
|
2001-08-19 13:25:15 +00:00
|
|
|
.connect(slot(this, &QParagraph::hide));
|
2001-03-23 06:31:30 +00:00
|
|
|
|
2001-02-14 19:43:56 +00:00
|
|
|
dialog_->raise();
|
|
|
|
dialog_->setActiveWindow();
|
|
|
|
update();
|
2001-03-23 06:31:30 +00:00
|
|
|
|
2001-02-14 19:43:56 +00:00
|
|
|
dialog_->show();
|
|
|
|
}
|
|
|
|
|
2001-05-09 09:14:50 +00:00
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
void QParagraph::close()
|
2001-02-14 19:43:56 +00:00
|
|
|
{
|
|
|
|
h_.disconnect();
|
|
|
|
}
|
|
|
|
|
2001-05-09 09:14:50 +00:00
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
void QParagraph::hide()
|
2001-02-14 19:43:56 +00:00
|
|
|
{
|
|
|
|
dialog_->hide();
|
|
|
|
close();
|
|
|
|
}
|