Add paragraph dialog to qt2 frontend. First commit, I am sure it can be done better but it works.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4683 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Edwin Leuven 2002-07-17 15:51:23 +00:00
parent 6b03e0d948
commit 9a4842fc84
10 changed files with 1032 additions and 2461 deletions

View File

@ -1,3 +1,12 @@
2002-07-07 Edwin Leuven <leuven@fee.uva.nl>
* QParagraph.[Ch]: Add paragraph dialog
* QParagraphDialog.[Ch]:
* ui/QParagraphDialog.[Ch]:
* Makefile.am:
* Makefile.dialogs:
* guiapi.C:
2002-07-17 John Levon <moz@compsoc.man.ac.uk>
* QtView.C: basic statusbar show

View File

@ -3,8 +3,7 @@ include $(top_srcdir)/config/common.am
SUBDIRS = ui moc
EXTRA_DIST = Makefile.dialogs QDocument.C QDocument.h \
QDocumentDialog.C QDocumentDialog.h QParagraph.h QParagraph.C \
QParagraphDialog.h QParagraphDialog.C
QDocumentDialog.C QDocumentDialog.h
noinst_LTLIBRARIES = libqt2.la

View File

@ -16,6 +16,7 @@ DIALOGS = \
QIndex \
QLog \
QMinipage \
QParagraph \
QPreamble \
QPrint \
QRef \
@ -58,6 +59,8 @@ DIALOGSOURCES = \
QLog.C QLogDialog.C \
QMinipage.h QMinipageDialog.h \
QMinipage.C QMinipageDialog.C \
QParagraph.h QParagraphDialog.h \
QParagraph.C QParagraphDialog.C \
QPreamble.h QPreambleDialog.h \
QPreamble.C QPreambleDialog.C \
QPrint.h QPrintDialog.h \
@ -98,6 +101,7 @@ MOCDIALOGS = \
QIndexDialog_moc.C \
QLogDialog_moc.C \
QMinipageDialog_moc.C \
QParagraphDialog_moc.C \
QPreambleDialog_moc.C \
QPrintDialog_moc.C \
QRefDialog_moc.C \
@ -142,6 +146,8 @@ UIDIALOGS = \
QLogDialogBase.C \
QMinipageDialogBase.h \
QMinipageDialogBase.C \
QParagraphDialogBase.h \
QParagraphDialogBase.C \
QPreambleDialogBase.h \
QPreambleDialogBase.C \
QPrintDialogBase.h \
@ -183,6 +189,7 @@ UIMOCDIALOGS = \
QIndexDialogBase_moc.C \
QLogDialogBase_moc.C \
QMinipageDialogBase_moc.C \
QParagraphDialogBase_moc.C \
QPreambleDialogBase_moc.C \
QPrintDialogBase_moc.C \
QRefDialogBase_moc.C \

View File

@ -60,7 +60,7 @@ Image::FormatList QLImage::loadableFormats()
QStrListIterator it(qt_formats);
for (; it.current(); ++it) {
lyxerr[Debug::GRAPHICS] << it.current() << endl;
lyxerr[Debug::GRAPHICS] << it.current() << std::endl;
string ext = lowercase(it.current());

View File

@ -1,198 +1,372 @@
/**
* \file QParagraph.C
* Copyright 2001 LyX Team
* see the file COPYING
* Copyright 2000-2001 The LyX Team.
* See the file COPYING.
*
* \author John Levon, moz@compsoc.man.ac.uk
* \author Edwin Leuven <leuven@fee.uva.nl>
*/
#include <config.h>
#include "QParagraphDialog.h"
#ifdef __GNUG__
#pragma implementation
#endif
#include "ControlParagraph.h"
#include "QParagraph.h"
#include "Liason.h"
#include "gettext.h"
#include "buffer.h"
#include "QtLyXView.h"
#include "lyxtextclasslist.h"
#include "lyxtext.h"
#include "debug.h"
#include "BufferView.h"
#include "QParagraphDialog.h"
#include "Qt2BC.h"
#include "ParagraphParameters.h"
#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"
using SigC::slot;
using Liason::setMinibuffer;
using std::endl;
#include "support/lstrings.h"
#include "support/LAssert.h"
#include <functional>
QParagraph::QParagraph(LyXView *v, Dialogs *d)
: dialog_(0), lv_(v), d_(d), h_(0)
#include <qcombobox.h>
#include <qlineedit.h>
#include <qcheckbox.h>
#include <qpushbutton.h>
#include <qtabwidget.h>
#include <qbuttongroup.h>
using std::vector;
using std::bind2nd;
using std::remove_if;
typedef Qt2CB<ControlParagraph, Qt2DB<QParagraphDialog> > base_class;
QParagraph::QParagraph(ControlParagraph & c, Dialogs &)
: base_class(c, _("Paragraph Layout"))
{}
void QParagraph::build_dialog()
{
d->showParagraph.connect(slot(this, &QParagraph::show));
// the tabbed folder
dialog_.reset(new QParagraphDialog(this));
// Create the contents of the unit choices
// Don't include the "%" terms...
units_ = getLatexUnits();
vector<string>::iterator del = remove_if(units_.begin(), units_.end(),
bind2nd(contains_functor(), "%"));
units_.erase(del, units_.end());
for (vector<string>::const_iterator it = units_.begin();
it != units_.end(); ++it) {
dialog_->unitAbove->insertItem(it->c_str());
dialog_->unitBelow->insertItem(it->c_str());
}
// 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);
}
namespace {
QParagraph::~QParagraph()
VSpace setVSpaceFromWidgets(int spacing,
string value,
string unit,
bool keep)
{
delete dialog_;
}
void QParagraph::update(bool switched)
{
if (switched) {
hide();
return;
}
if (!lv_->view()->available())
return;
Buffer * buf = lv_->view()->buffer();
if (readonly!=buf->isReadonly()) {
readonly = buf->isReadonly();
dialog_->setReadOnly(readonly);
}
LyXText * text(lv_->view()->getLyXText());
Paragraph * par = text->cursor.par();
int align = par->getAlign();
if (align==LYX_ALIGN_LAYOUT)
align = textclasslist.Style(buf->params.textclass, par->getLayout()).align;
ParagraphParameters * params = &(par->params());
if (params->spaceTop().kind() == VSpace::LENGTH) {
LyXGlueLength above = params->spaceTop().length();
lyxerr[Debug::GUI] << "Reading above space : \"" << params->spaceTop().length().asString() << "\"" << endl;
dialog_->setAboveLength(above.len().value(), above.plus().value(), above.minus().value(),
above.len().unit(), above.plus().unit(), above.minus().unit());
} else
dialog_->setAboveLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
if (params->spaceBottom().kind() == VSpace::LENGTH) {
LyXGlueLength below = params->spaceBottom().length();
lyxerr[Debug::GUI] << "Reading below space : \"" << params->spaceBottom().length().asString() << "\"" << endl;
dialog_->setBelowLength(below.len().value(), below.plus().value(), below.minus().value(),
below.len().unit(), below.plus().unit(), below.minus().unit());
} else
dialog_->setBelowLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
dialog_->setLabelWidth(text->cursor.par()->getLabelWidthString().c_str());
dialog_->setAlign(align);
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());
// now the extras page
LyXLength extrawidth;
float val = 0.0;
LyXLength::UNIT unit = LyXLength::CM;
params = &(par->params());
if (isValidLength(params->pextraWidth(), &extrawidth)) {
lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
val = extrawidth.value();
unit = extrawidth.unit();
}
lyxerr[Debug::GUI] << "Reading widthp \"" << params->pextraWidthp() << "\"" << endl;
dialog_->setExtra(val, unit, params->pextraWidthp(),
params->pextraAlignment(),
params->pextraHfill(),
params->pextraStartMinipage(),
static_cast<Paragraph::PEXTRA_TYPE>(params->pextraType()));
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;
string const length = strip(frontStrip(value));
if (isValidGlueLength(length)) {
s = length;
} else if (!length.empty()){
string u = strip(frontStrip(unit));
u = subst(u, "%%", "%");
s = length + u;
}
space = VSpace(LyXGlueLength(s));
break;
}
space.setKeep(keep);
return space;
}
} // namespace anon
void QParagraph::apply()
{
if (readonly)
return;
/* SPACING ABOVE */
// If a vspace kind is "Length" but there's no text in
// the input field, reset the kind to "None".
if (dialog_->spacingAbove->currentItem()==5
&& dialog_->valueAbove->text().isEmpty())
dialog_->spacingAbove->setCurrentItem(0);
VSpace const space_top =
setVSpaceFromWidgets(dialog_->spacingAbove->currentItem(),
string(dialog_->valueAbove->text()),
string(dialog_->unitAbove->currentText()),
dialog_->keepAbove->isChecked());
VSpace spaceabove;
VSpace spacebelow;
controller().params().spaceTop(space_top);
if (dialog_->getSpaceAboveKind()==VSpace::LENGTH)
spaceabove = VSpace(dialog_->getAboveLength());
else
spaceabove = VSpace(dialog_->getSpaceAboveKind());
/* SPACING BELOW */
if (dialog_->spacingBelow->currentItem()==5
&& dialog_->valueBelow->text().isEmpty())
dialog_->spacingBelow->setCurrentItem(0);
if (dialog_->getSpaceBelowKind()==VSpace::LENGTH)
spacebelow = VSpace(dialog_->getBelowLength());
else
spacebelow = VSpace(dialog_->getSpaceBelowKind());
VSpace const space_bottom =
setVSpaceFromWidgets(dialog_->spacingBelow->currentItem(),
string(dialog_->valueBelow->text()),
string(dialog_->unitBelow->currentText()),
dialog_->keepBelow->isChecked());
controller().params().spaceBottom(space_bottom);
spaceabove.setKeep(dialog_->getAboveKeep());
spacebelow.setKeep(dialog_->getBelowKeep());
/* alignment */
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;
}
controller().params().align(align);
/* get spacing */
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;
}
lyxerr[Debug::GUI] << "Setting above space \"" << LyXGlueLength(spaceabove.length().asString()).asString() << "\"" << endl;
lyxerr[Debug::GUI] << "Setting below space \"" << LyXGlueLength(spacebelow.length().asString()).asString() << "\"" << endl;
Spacing const spacing(linespacing, other);
controller().params().spacing(spacing);
/* lines and pagebreaks */
controller().params().lineTop(dialog_->lineAbove->isChecked());
controller().params().lineBottom(dialog_->lineBelow->isChecked());
controller().params().pagebreakTop(dialog_->pagebreakAbove->isChecked());
controller().params().pagebreakBottom(dialog_->pagebreakBelow->isChecked());
/* label width */
controller().params().labelWidthString(string(dialog_->labelWidth->text()));
/* indendation */
controller().params().noindent(dialog_->noindent->isChecked());
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());
// 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;
lv_->view()->update(text,
BufferView::SELECT |
BufferView::FITCUR |
BufferView::CHANGE);
lv_->buffer()->markDirty();
setMinibuffer(lv_, _("Paragraph layout set"));
}
namespace {
void QParagraph::show()
void setWidgetsFromVSpace(VSpace const & space,
QComboBox * spacing,
QLineEdit * value,
QComboBox * unit,
QCheckBox * keep, vector<string> units_)
{
if (!dialog_)
dialog_ = new QParagraphDialog(this, 0,
_("LyX: Paragraph Settings"),
false);
value->setText("");
value->setEnabled(false);
unit->setEnabled(false);
if (!dialog_->isVisible())
h_ = d_->hideBufferDependent
.connect(slot(this, &QParagraph::hide));
dialog_->raise();
dialog_->setActiveWindow();
update();
dialog_->show();
int item;
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;
case VSpace::LENGTH:
item = 6;
value->setEnabled(true);
unit->setEnabled(true);
string length = space.length().asString();
string const default_unit = (lyxrc.default_papersize>3) ? "cm" : "in";
string supplied_unit = default_unit;
LyXLength len(length);
if ((isValidLength(length) || isStrDbl(length)) && !len.zero()) {
ostringstream buffer;
buffer << len.value();
length = buffer.str();
supplied_unit = subst(stringFromUnit(len.unit()),"%","%%");
}
int unit_item = 0;
int i = 0;
for (vector<string>::const_iterator it = units_.begin();
it != units_.end(); ++it) {
if (*it==default_unit) {
unit_item = i;
}
if (*it==supplied_unit) {
unit_item = i;
break;
}
i += 1;
}
value->setText(length.c_str());
unit->setCurrentItem(unit_item);
break;
}
spacing->setCurrentItem(item);
keep->setChecked(space.keep());
}
} // namespace anon
void QParagraph::close()
void QParagraph::update_contents()
{
h_.disconnect();
/* label width */
string labelwidth = controller().params().labelWidthString();
dialog_->labelWidth->setText(labelwidth.c_str());
dialog_->labelwidthGB->setEnabled(
labelwidth != _("Senseless with this layout!"));
/* alignment */
int i;
switch (controller().params().align()) {
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);
//LyXAlignment alignpos = controller().alignPossible();
// no inset-text-owned paragraph may have pagebreaks
bool ininset = controller().inInset();
dialog_->pagebreakAbove->setEnabled(!ininset);
dialog_->pagebreakBelow->setEnabled(!ininset);
/* lines, pagebreaks and indent */
dialog_->lineAbove->setChecked(controller().params().lineTop());
dialog_->lineBelow->setChecked(controller().params().lineBottom());
dialog_->pagebreakAbove->setChecked(controller().params().pagebreakTop());
dialog_->pagebreakBelow->setChecked(controller().params().pagebreakBottom());
dialog_->noindent->setChecked(controller().params().noindent());
/* linespacing */
int linespacing;
Spacing const space = controller().params().spacing();
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);
}
/* vspace top */
setWidgetsFromVSpace(controller().params().spaceTop(),
dialog_->spacingAbove,
dialog_->valueAbove,
dialog_->unitAbove,
dialog_->keepAbove,units_);
/* vspace bottom */
setWidgetsFromVSpace(controller().params().spaceBottom(),
dialog_->spacingBelow,
dialog_->valueBelow,
dialog_->unitBelow,
dialog_->keepBelow,units_);
/* no indent */
dialog_->noindent->setChecked(controller().params().noindent());
}
void QParagraph::hide()
{
dialog_->hide();
close();
}

View File

@ -4,52 +4,37 @@
* Copyright 2001 LyX Team
* see the file COPYING
*
* \author John Levon, moz@compsoc.man.ac.uk
* \author Edwin Leuven <leuven@fee.uva.nl>
* \author John Levon <moz@compsoc.man.ac.uk>
*/
#ifndef QPARAGRAPH_H
#define QPARAGRAPH_H
#include "DialogBase.h"
#include "LString.h"
#include "boost/utility.hpp"
#include <config.h>
#include "Qt2Base.h"
class Dialogs;
class LyXView;
class ControlParagraph;
class QParagraphDialog;
class Dialogs;
class QParagraph :
public Qt2CB<ControlParagraph, Qt2DB<QParagraphDialog> >
{
friend class QParagraphDialog;
class QParagraph : public DialogBase {
public:
QParagraph(LyXView *, Dialogs *);
~QParagraph();
/// Apply changes
void apply();
/// Update the dialog.
void update(bool switched = false);
/// Close the connections
void close();
QParagraph(ControlParagraph &, Dialogs &);
private:
/// Create the dialog if necessary, update it and display it.
void show();
/// Hide the dialog.
void hide();
/// Real GUI implementation.
QParagraphDialog * dialog_;
/// the LyXView we belong to
LyXView * lv_;
/// Used so we can get at the signals we have to connect to.
Dialogs * d_;
/// Hide connection.
SigC::Connection h_;
/// readonly file or not
bool readonly;
/// Apply changes
virtual void apply();
/// update
virtual void update_contents();
/// build the dialog
virtual void build_dialog();
std::vector<string> units_;
};
#endif // QPARAGRAPH_H

View File

@ -7,532 +7,66 @@
* \author Edwin Leuven, leuven@fee.uva.nl
*/
#include <config.h>
#include <gettext.h>
#include <string>
#include "QParagraphDialog.h"
#include "QParagraph.h"
#include "support/lstrings.h"
#include "debug.h"
#include <qlineedit.h>
#include <qcombobox.h>
#include <qcheckbox.h>
#include <qpushbutton.h>
#include <qtabwidget.h>
#include <qlabel.h>
#include <qgroupbox.h>
#include <qvalidator.h>
using std::endl;
#include "helper_funcs.h"
QParagraphDialog::QParagraphDialog(QParagraph * form, QWidget * parent,
char const * name, bool modal, WFlags fl)
: QParagraphDialogBase(parent, name, modal, fl),
form_(form)
using std::vector;
QParagraphDialog::QParagraphDialog(QParagraph * form)
: QParagraphDialogBase(0, 0, false, 0),
form_(form)
{
setCaption(name);
connect(okPB, SIGNAL(clicked()),
form_, SLOT(slotOK()));
connect(applyPB, SIGNAL(clicked()),
form_, SLOT(slotApply()));
connect(closePB, SIGNAL(clicked()),
form_, SLOT(slotClose()));
linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
valueAbove->setValidator(new QDoubleValidator(valueAbove));
valueBelow->setValidator(new QDoubleValidator(valueBelow));
}
QParagraphDialog::~QParagraphDialog()
{
}
void QParagraphDialog::setReadOnly(bool readonly)
{
TabsParagraph->setEnabled(!readonly);
okPB->setEnabled(!readonly);
applyPB->setEnabled(!readonly);
defaultsPB->setEnabled(!readonly);
cancelPB->setText(readonly ? _("&Close") : _("&Cancel"));
}
void QParagraphDialog::setLabelWidth(char const * text)
{
// FIXME: should be cleverer here
if (!strcmp(_("Senseless with this layout!"),text)) {
listOptions->setEnabled(false);
labelWidth->setText("");
} else {
listOptions->setEnabled(true);
labelWidth->setText(text);
}
}
void QParagraphDialog::setAlign(int type)
{
int item = 0;
switch (type) {
case LYX_ALIGN_BLOCK: item = 0; break;
case LYX_ALIGN_LEFT: item = 1; break;
case LYX_ALIGN_RIGHT: item = 2; break;
case LYX_ALIGN_CENTER: item = 3; break;
default:
item = 0;
break;
}
alignment->setCurrentItem(item);
}
void QParagraphDialog::setChecks(bool labove, bool lbelow, bool pabove,
bool pbelow, bool noindent)
{
lineAbove->setChecked(labove);
lineBelow->setChecked(lbelow);
pagebreakAbove->setChecked(pabove);
pagebreakBelow->setChecked(pbelow);
noIndent->setChecked(noindent);
}
void QParagraphDialog::setSpace(VSpace::vspace_kind kindabove,
VSpace::vspace_kind kindbelow,
bool keepabove, bool keepbelow)
{
int item = 0;
switch (kindabove) {
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;
case VSpace::LENGTH: item = 6; break;
}
spacingAbove->setCurrentItem(item);
switch (kindbelow) {
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;
case VSpace::LENGTH: item = 6; break;
}
spacingBelow->setCurrentItem(item);
spacingAboveValue->setEnabled(kindabove == VSpace::LENGTH);
spacingAbovePlus->setEnabled(kindabove == VSpace::LENGTH);
spacingAboveMinus->setEnabled(kindabove == VSpace::LENGTH);
spacingBelowValue->setEnabled(kindbelow == VSpace::LENGTH);
spacingBelowPlus->setEnabled(kindbelow == VSpace::LENGTH);
spacingBelowMinus->setEnabled(kindbelow == VSpace::LENGTH);
spacingAboveKeep->setChecked(keepabove);
spacingBelowKeep->setChecked(keepbelow);
}
void QParagraphDialog::setAboveLength(float val, float plus, float minus,
LyXLength::UNIT vunit,
LyXLength::UNIT punit,
LyXLength::UNIT munit)
{
if (vunit == LyXLength::UNIT_NONE) {
spacingAboveValue->setText("");
spacingAbovePlus->setText("");
spacingAboveMinus->setText("");
} else {
spacingAboveValue->setText(tostr(val).c_str());
spacingAbovePlus->setText(tostr(plus).c_str());
spacingAboveMinus->setText(tostr(minus).c_str());
}
spacingAboveValueUnit->setCurrentItem(getItem(vunit));
spacingAbovePlusUnit->setCurrentItem(getItem(punit));
spacingAboveMinusUnit->setCurrentItem(getItem(munit));
}
void QParagraphDialog::setBelowLength(float val, float plus, float minus,
LyXLength::UNIT vunit,
LyXLength::UNIT punit,
LyXLength::UNIT munit)
{
if (vunit == LyXLength::UNIT_NONE) {
spacingBelowValue->setText("");
spacingBelowPlus->setText("");
spacingBelowMinus->setText("");
} else {
spacingBelowValue->setText(tostr(val).c_str());
spacingBelowPlus->setText(tostr(plus).c_str());
spacingBelowMinus->setText(tostr(minus).c_str());
}
spacingBelowValueUnit->setCurrentItem(getItem(vunit));
spacingBelowPlusUnit->setCurrentItem(getItem(punit));
spacingBelowMinusUnit->setCurrentItem(getItem(munit));
}
void QParagraphDialog::setExtra(float widthval, LyXLength::UNIT units,
string const & percent, int align,
bool hfill, bool startminipage,
Paragraph::PEXTRA_TYPE type)
{
if (type != Paragraph::PEXTRA_NONE) {
lyxerr[Debug::GUI] << "percent : $" << percent << "$ widthval "
<< widthval << " unit " << long(units)
<< endl;
if (percent != "") {
extraWidth->setText(percent.c_str());
extraUnit->setCurrentItem(11);
} else {
extraWidth->setText(tostr(widthval).c_str());
extraUnit->setCurrentItem(getItem(units));
}
} else
extraWidth->setText("");
switch (type) {
case Paragraph::PEXTRA_NONE:
extraType->setCurrentItem(0);
break;
case Paragraph::PEXTRA_MINIPAGE:
extraType->setCurrentItem(1);
enable_extraOptions(1);
enable_minipageOptions(1);
break;
case Paragraph::PEXTRA_FLOATFLT:
extraType->setCurrentItem(2);
enable_extraOptions(2);
break;
case Paragraph::PEXTRA_INDENT:
extraType->setCurrentItem(3);
enable_extraOptions(3);
break;
}
switch (align) {
case Paragraph::MINIPAGE_ALIGN_TOP:
minipageValign->setCurrentItem(0);
break;
case Paragraph::MINIPAGE_ALIGN_MIDDLE:
minipageValign->setCurrentItem(1);
break;
case Paragraph::MINIPAGE_ALIGN_BOTTOM:
minipageValign->setCurrentItem(2);
break;
}
minipageHfill->setChecked(hfill);
minipageStart->setChecked(startminipage);
}
LyXGlueLength QParagraphDialog::getAboveLength() const
{
LyXGlueLength len(
LyXLength(spacingAboveValue->text().toFloat(),
getLyXLength(spacingAboveValueUnit->currentItem())),
LyXLength(spacingAbovePlus->text().toFloat(),
getLyXLength(spacingAbovePlusUnit->currentItem())),
LyXLength(spacingAboveMinus->text().toFloat(),
getLyXLength(spacingAboveMinusUnit->currentItem()))
);
return len;
}
LyXGlueLength QParagraphDialog::getBelowLength() const
{
LyXGlueLength len(
LyXLength(spacingBelowValue->text().toFloat(),
getLyXLength(spacingBelowValueUnit->currentItem())),
LyXLength(spacingBelowPlus->text().toFloat(),
getLyXLength(spacingBelowPlusUnit->currentItem())),
LyXLength(spacingBelowMinus->text().toFloat(),
getLyXLength(spacingBelowMinusUnit->currentItem()))
);
return len;
}
LyXLength QParagraphDialog::getExtraWidth() const
{
if (extraUnit->currentItem() != 11) {
LyXLength len(
(extraWidth->text()).toDouble(),
getLyXLength(extraUnit->currentItem())
);
return len;
} else {
LyXLength len(0.0, LyXLength::UNIT_NONE);
return len;
}
}
string QParagraphDialog::getExtraWidthPercent() const
{
double val = (extraWidth->text()).toDouble();
if (val > 100.0)
val = 100.0;
if (val < 0.0)
val = 0.0;
return tostr(val);
}
char const * QParagraphDialog::getLabelWidth() const
{
return labelWidth->text();
}
LyXAlignment QParagraphDialog::getAlign() const
{
switch (alignment->currentItem()) {
case 0: return LYX_ALIGN_BLOCK;
case 1: return LYX_ALIGN_LEFT;
case 2: return LYX_ALIGN_RIGHT;
case 3: return LYX_ALIGN_CENTER;
default: return LYX_ALIGN_CENTER;
}
}
bool QParagraphDialog::getAboveKeep() const
{
return spacingAboveKeep->isChecked();
}
bool QParagraphDialog::getBelowKeep() const
{
return spacingBelowKeep->isChecked();
}
bool QParagraphDialog::getLineAbove() const
{
return lineAbove->isChecked();
}
bool QParagraphDialog::getLineBelow() const
{
return lineBelow->isChecked();
}
bool QParagraphDialog::getPagebreakAbove() const
{
return pagebreakAbove->isChecked();
}
bool QParagraphDialog::getPagebreakBelow() const
{
return pagebreakBelow->isChecked();
}
bool QParagraphDialog::getNoIndent() const
{
return noIndent->isChecked();
}
VSpace::vspace_kind QParagraphDialog::getSpaceAboveKind() const
{
return getSpaceKind(spacingAbove->currentItem());
}
VSpace::vspace_kind QParagraphDialog::getSpaceBelowKind() const
{
return getSpaceKind(spacingBelow->currentItem());
}
Paragraph::PEXTRA_TYPE QParagraphDialog::getExtraType() const
{
switch (extraType->currentItem()) {
case 0: return Paragraph::PEXTRA_NONE;
case 1: return Paragraph::PEXTRA_MINIPAGE;
case 2: return Paragraph::PEXTRA_FLOATFLT;
case 3: return Paragraph::PEXTRA_INDENT;
}
return Paragraph::PEXTRA_NONE;
}
Paragraph::MINIPAGE_ALIGNMENT QParagraphDialog::getExtraAlign() const
{
switch (minipageValign->currentItem()) {
case 0: return Paragraph::MINIPAGE_ALIGN_TOP;
case 1: return Paragraph::MINIPAGE_ALIGN_MIDDLE;
case 2: return Paragraph::MINIPAGE_ALIGN_BOTTOM;
default: return Paragraph::MINIPAGE_ALIGN_BOTTOM;
}
}
bool QParagraphDialog::getHfillBetween() const
{
return minipageHfill->isChecked();
}
bool QParagraphDialog::getStartNewMinipage() const
{
return minipageStart->isChecked();
}
VSpace::vspace_kind QParagraphDialog::getSpaceKind(int val) const
{
switch (val) {
case 0: return VSpace::NONE;
case 1: return VSpace::DEFSKIP;
case 2: return VSpace::SMALLSKIP;
case 3: return VSpace::MEDSKIP;
case 4: return VSpace::BIGSKIP;
case 5: return VSpace::VFILL;
case 6: return VSpace::LENGTH;
default:
lyxerr[Debug::GUI] << "Unknown kind combo entry "
<< val << std::endl;
}
return VSpace::NONE;
}
LyXLength::UNIT QParagraphDialog::getLyXLength(int val) const
{
switch (val) {
case 0: return LyXLength::CM;
case 1: return LyXLength::IN;
case 2: return LyXLength::PT;
case 3: return LyXLength::MM;
case 4: return LyXLength::PC;
case 5: return LyXLength::EX;
case 6: return LyXLength::EM;
case 7: return LyXLength::SP;
case 8: return LyXLength::BP;
case 9: return LyXLength::DD;
case 10: return LyXLength::CC;
default:
lyxerr[Debug::GUI] << "Unknown kind combo entry "
<< val << std::endl;
}
return LyXLength::UNIT_NONE;
}
int QParagraphDialog::getItem(LyXLength::UNIT unit) const
{
int item = 0;
switch (unit) {
case LyXLength::CM: item = 0; break;
case LyXLength::IN: item = 1; break;
case LyXLength::PT: item = 2; break;
case LyXLength::MM: item = 3; break;
case LyXLength::PC: item = 4; break;
case LyXLength::EX: item = 5; break;
case LyXLength::EM: item = 6; break;
case LyXLength::SP: item = 7; break;
case LyXLength::BP: item = 8; break;
case LyXLength::DD: item = 9; break;
case LyXLength::CC: item = 10; break;
case LyXLength::MU: item = 0; break;
case LyXLength::UNIT_NONE: item = 0; break;
default:
lyxerr[Debug::GUI] << "Unknown unit " << long(unit)
<< endl;
}
return item;
}
void QParagraphDialog::enable_extraOptions(int item)
{
bool const enable = (item != 0);
extraWidth->setEnabled(enable);
extraWidthL->setEnabled(enable);
extraUnit->setEnabled(enable);
extraUnitL->setEnabled(enable);
}
void QParagraphDialog::enable_minipageOptions(int item)
{
minipageOptions->setEnabled( item == 1 );
}
void QParagraphDialog::enable_spacingAbove(int item)
{
bool const enable = (item == 6);
spacingAboveValue->setEnabled(enable);
spacingAbovePlus->setEnabled(enable);
spacingAboveMinus->setEnabled(enable);
spacingAboveValueUnit->setEnabled(enable);
spacingAbovePlusUnit->setEnabled(enable);
spacingAboveMinusUnit->setEnabled(enable);
spacingAboveUnitsL->setEnabled(enable);
bool const enablel = ( (item == 6) || (item != 6 && spacingBelow->currentItem() == 6) );
spacingValueL->setEnabled(enablel);
spacingPlusL->setEnabled(enablel);
spacingMinusL->setEnabled(enablel);
}
void QParagraphDialog::enable_spacingBelow(int item)
{
bool const enable = (item == 6);
spacingBelowValue->setEnabled(enable);
spacingBelowPlus->setEnabled(enable);
spacingBelowMinus->setEnabled(enable);
spacingBelowValueUnit->setEnabled(enable);
spacingBelowPlusUnit->setEnabled(enable);
spacingBelowMinusUnit->setEnabled(enable);
spacingBelowUnitsL->setEnabled(enable);
bool const enablel = ( (item == 6) || (item!=6 && spacingAbove->currentItem() == 6) );
spacingValueL->setEnabled(enablel);
spacingPlusL->setEnabled(enablel);
spacingMinusL->setEnabled(enablel);
}
void QParagraphDialog::closeEvent(QCloseEvent * e)
{
form_->close();
form_->slotWMHide();
e->accept();
}
void QParagraphDialog::apply_adaptor()
void QParagraphDialog::change_adaptor()
{
form_->apply();
form_->changed();
}
void QParagraphDialog::enableAbove(int)
{
bool const enable = spacingAbove->currentItem()==6;
valueAbove->setEnabled(enable);
unitAbove->setEnabled(enable);
}
void QParagraphDialog::enableBelow(int)
{
bool const enable = spacingBelow->currentItem()==6;
valueBelow->setEnabled(enable);
unitBelow->setEnabled(enable);
}
void QParagraphDialog::enableLinespacingValue(int)
{
bool const enable = linespacing->currentItem()==4;
linespacingValue->setEnabled(enable);
}
void QParagraphDialog::cancel_adaptor()
{
form_->close();
hide();
}
void QParagraphDialog::ok_adaptor()
{
apply_adaptor();
form_->close();
hide();
}
void QParagraphDialog::restore_adaptor()
{
form_->update();
}

View File

@ -13,71 +13,27 @@
#include <config.h>
#include "QParagraph.h"
#include "ui/QParagraphDialogBase.h"
#include "vspace.h"
#include "paragraph.h"
#include "layout.h"
#include "lyxgluelength.h"
class QParagraph;
#include <qevent.h>
class QParagraphDialog : public QParagraphDialogBase
{ Q_OBJECT
{
Q_OBJECT
public:
QParagraphDialog(QParagraph * form, QWidget * parent = 0,
char const * name = 0, bool modal = FALSE,
WFlags fl = 0);
~QParagraphDialog();
QParagraphDialog(QParagraph * form);
void setReadOnly(bool);
void setLabelWidth(char const *);
void setAlign(int);
void setChecks(bool, bool, bool, bool, bool);
void setSpace(VSpace::vspace_kind, VSpace::vspace_kind, bool, bool);
void setAboveLength(float, float, float,
LyXLength::UNIT, LyXLength::UNIT, LyXLength::UNIT);
void setBelowLength(float, float, float,
LyXLength::UNIT, LyXLength::UNIT, LyXLength::UNIT);
void setExtra(float, LyXLength::UNIT,
string const &, int, bool, bool, Paragraph::PEXTRA_TYPE);
LyXGlueLength getAboveLength() const;
LyXGlueLength getBelowLength() const;
LyXLength getExtraWidth() const;
string getExtraWidthPercent() const;
// FIXME: return a std::string !
char const * getLabelWidth() const;
LyXAlignment getAlign() const;
bool getAboveKeep() const;
bool getBelowKeep() const;
bool getLineAbove() const;
bool getLineBelow() const;
bool getPagebreakAbove() const;
bool getPagebreakBelow() const;
bool getNoIndent() const;
VSpace::vspace_kind getSpaceAboveKind() const;
VSpace::vspace_kind getSpaceBelowKind() const;
Paragraph::PEXTRA_TYPE getExtraType() const;
Paragraph::MINIPAGE_ALIGNMENT getExtraAlign() const;
bool getHfillBetween() const;
bool getStartNewMinipage() const;
protected:
void closeEvent (QCloseEvent * e);
private:
QParagraph * form_;
VSpace::vspace_kind getSpaceKind(int val) const;
LyXLength::UNIT getLyXLength(int val) const;
int getItem(LyXLength::UNIT unit) const;
protected slots:
void apply_adaptor();
void cancel_adaptor();
void enable_extraOptions(int);
void enable_minipageOptions(int);
void enable_spacingAbove(int);
void enable_spacingBelow(int);
void ok_adaptor();
void restore_adaptor();
void change_adaptor();
void enableAbove(int);
void enableBelow(int);
void enableLinespacingValue(int);
};
#endif // QPARAGRAPHDIALOG_H

View File

@ -44,7 +44,8 @@
#include "QLogDialog.h"
#include "QMinipage.h"
#include "QMinipageDialog.h"
//#include "QParagraph.h"
#include "QParagraph.h"
#include "QParagraphDialog.h"
#include "QPreamble.h"
#include "QPreambleDialog.h"
//#include "QPreferences.h"
@ -150,6 +151,10 @@ GUISingleton<GUI<ControlMinipage, QMinipage,
NoRepeatedApplyReadOnlyPolicy, Qt2BC> >
controlMinipageSingleton;
GUISingleton<GUI<ControlParagraph, QParagraph,
OkApplyCancelReadOnlyPolicy, Qt2BC> >
controlParagraphSingleton;
//GUISingleton<QPreferences> formPreferencesSingleton;
GUISingleton<GUI<ControlRef, QRef,
@ -344,6 +349,7 @@ extern "C" {
void gui_ShowParagraph(LyXView & lv, Dialogs & d)
{
controlParagraphSingleton.get(lv, d).show();
#if 0
static GUI<ControlParagraph, QParagraph,
OkApplyCancelReadOnlyPolicy, Qt2BC> cp(lv, d);

File diff suppressed because it is too large Load Diff