2 * \file FormParagraph.C
3 * Copyright 2001 LyX Team
6 * \author John Levon, moz@compsoc.man.ac.uk
11 #include "paragraphdlgimpl.h"
13 #include "FormParagraph.h"
18 #include "QtLyXView.h"
22 #ifdef CXX_WORKING_NAMESPACES
23 using Liason::setMinibuffer;
28 FormParagraph::FormParagraph(LyXView *v, Dialogs *d)
29 : dialog_(0), lv_(v), d_(d), h_(0)
31 // let the dialog be shown
32 // This is a permanent connection so we won't bother
33 // storing a copy because we won't be disconnecting.
34 d->showLayoutParagraph.connect(slot(this, &FormParagraph::show));
37 FormParagraph::~FormParagraph()
42 void FormParagraph::update(bool switched)
49 if (!lv_->view()->available())
52 Buffer *buf = lv_->view()->buffer();
54 if (readonly!=buf->isReadonly()) {
55 readonly = buf->isReadonly();
56 dialog_->setReadOnly(readonly);
61 if (lv_->view()->theLockingInset())
62 text = lv_->view()->theLockingInset()->getLyXText(lv_->view());
65 text = lv_->view()->text;
67 LyXParagraph *par = text->cursor.par();
69 int align = par->GetAlign();
71 if (align==LYX_ALIGN_LAYOUT)
72 align = textclasslist.Style(buf->params.textclass, par->GetLayout()).align;
75 ParagraphParameters *params = &(par->FirstPhysicalPar()->params);
77 ParagraphParameters *params = &(par->params);
80 if (params->spaceTop().kind() == VSpace::LENGTH) {
81 LyXGlueLength above = params->spaceTop().length();
82 lyxerr[Debug::GUI] << "Reading above space : \"" << params->spaceTop().length().asString() << "\"" << endl;
83 dialog_->setAboveLength(above.value(), above.plusValue(), above.minusValue(),
84 above.unit(), above.plusUnit(), above.minusUnit());
86 dialog_->setAboveLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
88 if (params->spaceBottom().kind() == VSpace::LENGTH) {
89 LyXGlueLength below = params->spaceBottom().length();
90 lyxerr[Debug::GUI] << "Reading below space : \"" << params->spaceBottom().length().asString() << "\"" << endl;
91 dialog_->setBelowLength(below.value(), below.plusValue(), below.minusValue(),
92 below.unit(), below.plusUnit(), below.minusUnit());
94 dialog_->setBelowLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
96 dialog_->setLabelWidth(text->cursor.par()->GetLabelWidthString().c_str());
97 dialog_->setAlign(align);
98 dialog_->setChecks(params->lineTop(), params->lineBottom(),
99 params->pagebreakTop(), params->pagebreakBottom(), params->noindent());
100 dialog_->setSpace(params->spaceTop().kind(), params->spaceBottom().kind(),
101 params->spaceTop().keep(), params->spaceBottom().keep());
103 // now the extras page
105 LyXLength extrawidth;
107 LyXLength::UNIT unit = LyXLength::CM;
108 params = &(par->params);
110 if (isValidLength(params->pextraWidth(), &extrawidth)) {
111 lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
112 val = extrawidth.value();
113 unit = extrawidth.unit();
116 lyxerr[Debug::GUI] << "Reading widthp \"" << params->pextraWidthp() << "\"" << endl;
118 dialog_->setExtra(val, unit, params->pextraWidthp(),
119 params->pextraAlignment(),
120 params->pextraHfill(),
121 params->pextraStartMinipage(),
122 static_cast<LyXParagraph::PEXTRA_TYPE>(params->pextraType()));
125 void FormParagraph::apply()
133 if (dialog_->getSpaceAboveKind()==VSpace::LENGTH)
134 spaceabove = VSpace(dialog_->getAboveLength());
136 spaceabove = VSpace(dialog_->getSpaceAboveKind());
138 if (dialog_->getSpaceBelowKind()==VSpace::LENGTH)
139 spacebelow = VSpace(dialog_->getBelowLength());
141 spacebelow = VSpace(dialog_->getSpaceBelowKind());
143 spaceabove.setKeep(dialog_->getAboveKeep());
144 spacebelow.setKeep(dialog_->getBelowKeep());
146 lyxerr[Debug::GUI] << "Setting above space \"" << LyXGlueLength(spaceabove.length().asString()).asString() << "\"" << endl;
147 lyxerr[Debug::GUI] << "Setting below space \"" << LyXGlueLength(spacebelow.length().asString()).asString() << "\"" << endl;
149 lv_->view()->text->SetParagraph(lv_->view(),
150 dialog_->getLineAbove(), dialog_->getLineBelow(),
151 dialog_->getPagebreakAbove(), dialog_->getPagebreakBelow(),
152 spaceabove, spacebelow, dialog_->getAlign(),
153 dialog_->getLabelWidth(), dialog_->getNoIndent());
160 LyXLength extrawidth(dialog_->getExtraWidth());
161 if (extrawidth.unit()==LyXLength::UNIT_NONE) {
162 widthp = dialog_->getExtraWidthPercent();
164 width = extrawidth.asString();
166 lyxerr[Debug::GUI] << "Setting extrawidth \"" << width << "\"" << endl;
167 lyxerr[Debug::GUI] << "Setting percent extrawidth \"" << widthp << "\"" << endl;
169 lv_->view()->text->SetParagraphExtraOpt(lv_->view(),
170 dialog_->getExtraType(), width, widthp,
171 dialog_->getExtraAlign(),
172 dialog_->getHfillBetween(),
173 dialog_->getStartNewMinipage());
175 lv_->view()->update(lv_->view()->text,
180 lv_->buffer()->markDirty();
181 setMinibuffer(lv_, _("Paragraph layout set"));
184 void FormParagraph::show()
187 dialog_ = new ParagraphDlgImpl(this, 0, _("LyX: Paragraph Options"), false);
189 if (!dialog_->isVisible())
190 h_ = d_->hideBufferDependent.connect(slot(this, &FormParagraph::hide));
194 dialog_->setActiveWindow();
200 void FormParagraph::close()
205 void FormParagraph::hide()