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 using Liason::setMinibuffer;
25 FormParagraph::FormParagraph(LyXView *v, Dialogs *d)
26 : dialog_(0), lv_(v), d_(d), h_(0)
28 // let the dialog be shown
29 // This is a permanent connection so we won't bother
30 // storing a copy because we won't be disconnecting.
31 d->showLayoutParagraph.connect(slot(this, &FormParagraph::show));
34 FormParagraph::~FormParagraph()
39 void FormParagraph::update(bool switched)
46 if (!lv_->view()->available())
49 Buffer *buf = lv_->view()->buffer();
51 if (readonly!=buf->isReadonly()) {
52 readonly = buf->isReadonly();
53 dialog_->setReadOnly(readonly);
58 if (lv_->view()->theLockingInset())
59 text = lv_->view()->theLockingInset()->getLyXText(lv_->view());
62 text = lv_->view()->text;
64 LyXParagraph *par = text->cursor.par();
66 int align = par->GetAlign();
68 if (align==LYX_ALIGN_LAYOUT)
69 align = textclasslist.Style(buf->params.textclass, par->GetLayout()).align;
72 ParagraphParameters *params = &(par->FirstPhysicalPar()->params);
74 ParagraphParameters *params = &(par->params);
77 if (params->spaceTop().kind() == VSpace::LENGTH) {
78 LyXGlueLength above = params->spaceTop().length();
79 lyxerr[Debug::GUI] << "Reading above space : \"" << params->spaceTop().length().asString() << "\"" << endl;
80 dialog_->setAboveLength(above.value(), above.plusValue(), above.minusValue(),
81 above.unit(), above.plusUnit(), above.minusUnit());
83 dialog_->setAboveLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
85 if (params->spaceBottom().kind() == VSpace::LENGTH) {
86 LyXGlueLength below = params->spaceBottom().length();
87 lyxerr[Debug::GUI] << "Reading below space : \"" << params->spaceBottom().length().asString() << "\"" << endl;
88 dialog_->setBelowLength(below.value(), below.plusValue(), below.minusValue(),
89 below.unit(), below.plusUnit(), below.minusUnit());
91 dialog_->setBelowLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
93 dialog_->setLabelWidth(text->cursor.par()->GetLabelWidthString().c_str());
94 dialog_->setAlign(align);
95 dialog_->setChecks(params->lineTop(), params->lineBottom(),
96 params->pagebreakTop(), params->pagebreakBottom(), params->noindent());
97 dialog_->setSpace(params->spaceTop().kind(), params->spaceBottom().kind(),
98 params->spaceTop().keep(), params->spaceBottom().keep());
100 // now the extras page
102 LyXLength extrawidth;
104 LyXLength::UNIT unit = LyXLength::CM;
105 params = &(par->params);
107 if (isValidLength(params->pextraWidth(), &extrawidth)) {
108 lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
109 val = extrawidth.value();
110 unit = extrawidth.unit();
113 lyxerr[Debug::GUI] << "Reading widthp \"" << params->pextraWidthp() << "\"" << endl;
115 dialog_->setExtra(val, unit, params->pextraWidthp(),
116 params->pextraAlignment(),
117 params->pextraHfill(),
118 params->pextraStartMinipage(),
119 static_cast<LyXParagraph::PEXTRA_TYPE>(params->pextraType()));
122 void FormParagraph::apply()
130 if (dialog_->getSpaceAboveKind()==VSpace::LENGTH)
131 spaceabove = VSpace(dialog_->getAboveLength());
133 spaceabove = VSpace(dialog_->getSpaceAboveKind());
135 if (dialog_->getSpaceBelowKind()==VSpace::LENGTH)
136 spacebelow = VSpace(dialog_->getBelowLength());
138 spacebelow = VSpace(dialog_->getSpaceBelowKind());
140 spaceabove.setKeep(dialog_->getAboveKeep());
141 spacebelow.setKeep(dialog_->getBelowKeep());
143 lyxerr[Debug::GUI] << "Setting above space \"" << LyXGlueLength(spaceabove.length().asString()).asString() << "\"" << endl;
144 lyxerr[Debug::GUI] << "Setting below space \"" << LyXGlueLength(spacebelow.length().asString()).asString() << "\"" << endl;
146 lv_->view()->text->SetParagraph(lv_->view(),
147 dialog_->getLineAbove(), dialog_->getLineBelow(),
148 dialog_->getPagebreakAbove(), dialog_->getPagebreakBelow(),
149 spaceabove, spacebelow, dialog_->getAlign(),
150 dialog_->getLabelWidth(), dialog_->getNoIndent());
157 LyXLength extrawidth(dialog_->getExtraWidth());
158 if (extrawidth.unit()==LyXLength::UNIT_NONE) {
159 widthp = dialog_->getExtraWidthPercent();
161 width = extrawidth.asString();
163 lyxerr[Debug::GUI] << "Setting extrawidth \"" << width << "\"" << endl;
164 lyxerr[Debug::GUI] << "Setting percent extrawidth \"" << widthp << "\"" << endl;
166 lv_->view()->text->SetParagraphExtraOpt(lv_->view(),
167 dialog_->getExtraType(), width, widthp,
168 dialog_->getExtraAlign(),
169 dialog_->getHfillBetween(),
170 dialog_->getStartNewMinipage());
172 lv_->view()->update(lv_->view()->text,
177 lv_->buffer()->markDirty();
178 setMinibuffer(lv_, _("Paragraph layout set"));
181 void FormParagraph::show()
184 dialog_ = new ParagraphDlgImpl(this, 0, _("LyX: Paragraph Options"), false);
186 if (!dialog_->isVisible())
187 h_ = d_->hideBufferDependent.connect(slot(this, &FormParagraph::hide));
191 dialog_->setActiveWindow();
197 void FormParagraph::close()
202 void FormParagraph::hide()