/**
* \file QParagraph.C
- * Copyright 2001 LyX Team
- * see the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * \author John Levon, moz@compsoc.man.ac.uk
+ * \author Edwin Leuven
+ *
+ * Full author contact details are available in file CREDITS.
*/
#include <config.h>
-#include "QParagraphDialog.h"
-
-#include "QParagraph.h"
-#include "Dialogs.h"
-#include "Liason.h"
-#include "gettext.h"
-#include "buffer.h"
-#include "QtLyXView.h"
-#include "lyxtext.h"
#include "debug.h"
-#include "BufferView.h"
+#include "ControlParagraph.h"
+#include "QParagraph.h"
+#include "QParagraphDialog.h"
+#include "Qt2BC.h"
#include "ParagraphParameters.h"
+#include "lyxrc.h" // to set the deafult length values
+#include "qt_helpers.h"
+#include "helper_funcs.h"
-using SigC::slot;
-using Liason::setMinibuffer;
-using std::endl;
-
-
-QParagraph::QParagraph(LyXView *v, Dialogs *d)
- : dialog_(0), lv_(v), d_(d), h_(0)
-{
- d->showParagraph.connect(slot(this, &QParagraph::show));
-}
-
+#include "Spacing.h"
+#include "vspace.h"
-QParagraph::~QParagraph()
-{
- delete dialog_;
-}
+#include "support/lstrings.h"
+#include "support/tostr.h"
+#include <qcombobox.h>
+#include <qlineedit.h>
+#include <qcheckbox.h>
+#include <qpushbutton.h>
+#include <qtabwidget.h>
+#include <qbuttongroup.h>
-void QParagraph::update(bool switched)
-{
- if (switched) {
- hide();
- return;
- }
+using lyx::support::contains_functor;
+using lyx::support::isStrDbl;
+using lyx::support::subst;
+using lyx::support::trim;
- if (!lv_->view()->available())
- return;
+using std::bind2nd;
+using std::remove_if;
+using std::string;
+using std::vector;
- Buffer * buf = lv_->view()->buffer();
- if (readonly!=buf->isReadonly()) {
- readonly = buf->isReadonly();
- dialog_->setReadOnly(readonly);
- }
+typedef QController<ControlParagraph, QView<QParagraphDialog> > base_class;
- 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.value(), above.plusValue(), above.minusValue(),
- above.unit(), above.plusUnit(), above.minusUnit());
- } 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.value(), below.plusValue(), below.minusValue(),
- below.unit(), below.plusUnit(), below.minusUnit());
- } 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()));
-}
+QParagraph::QParagraph(Dialog & parent)
+ : base_class(parent, _("LyX: Paragraph Settings"))
+{}
-void QParagraph::apply()
+void QParagraph::build_dialog()
{
- 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;
-
- 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"));
+ // 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());
+
+ // Manage the ok, apply, restore and cancel/close buttons
+ bcview().setOK(dialog_->okPB);
+ bcview().setApply(dialog_->applyPB);
+ bcview().setCancel(dialog_->closePB);
+ bcview().setRestore(dialog_->restorePB);
}
-void QParagraph::show()
+void QParagraph::apply()
{
- if (!dialog_)
- dialog_ = new QParagraphDialog(this, 0,
- _("LyX: Paragraph Settings"),
- false);
-
- if (!dialog_->isVisible())
- h_ = d_->hideBufferDependent
- .connect(slot(this, &QParagraph::hide));
+ ParagraphParameters & params = controller().params();
+
+ // 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;
+ }
+ 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 = fromqstr(dialog_->linespacingValue->text());
+ break;
+ }
- dialog_->raise();
- dialog_->setActiveWindow();
- update();
+ Spacing const spacing(linespacing, other);
+ params.spacing(spacing);
- dialog_->show();
+ // label width
+ params.labelWidthString(fromqstr(dialog_->labelWidth->text()));
+ // indendation
+ params.noindent(!dialog_->indentCB->isChecked());
}
-void QParagraph::close()
+void QParagraph::update_contents()
{
- h_.disconnect();
-}
-
+ ParagraphParameters const & params = controller().params();
+
+ // label width
+ string const & labelwidth = params.labelWidthString();
+ // _() is correct here (this is stupid though !)
+ if (labelwidth != _("Senseless with this layout!")) {
+ dialog_->labelwidthGB->setEnabled(true);
+ dialog_->labelWidth->setText(toqstr(labelwidth));
+ } else {
+ dialog_->labelwidthGB->setEnabled(false);
+ dialog_->labelWidth->setText("");
+ }
-void QParagraph::hide()
-{
- dialog_->hide();
- close();
+ // alignment
+ int i;
+ switch (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();
+
+ dialog_->indentCB->setChecked(!params.noindent());
+
+ // linespacing
+ int linespacing;
+ Spacing const & space = 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(toqstr(sp));
+ dialog_->linespacingValue->setEnabled(true);
+ } else {
+ dialog_->linespacingValue->setText("");
+ dialog_->linespacingValue->setEnabled(false);
+ }
}