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"
21 #include "BufferView.h"
22 #include "ParagraphParameters.h"
25 using Liason::setMinibuffer;
29 FormParagraph::FormParagraph(LyXView *v, Dialogs *d)
30 : dialog_(0), lv_(v), d_(d), h_(0)
32 // let the dialog be shown
33 // This is a permanent connection so we won't bother
34 // storing a copy because we won't be disconnecting.
35 d->showParagraph.connect(slot(this, &FormParagraph::show));
39 FormParagraph::~FormParagraph()
45 void FormParagraph::update(bool switched)
52 if (!lv_->view()->available())
55 Buffer * buf = lv_->view()->buffer();
57 if (readonly!=buf->isReadonly()) {
58 readonly = buf->isReadonly();
59 dialog_->setReadOnly(readonly);
64 if (lv_->view()->theLockingInset())
65 text = lv_->view()->theLockingInset()->getLyXText(lv_->view());
68 text = lv_->view()->text;
70 Paragraph * par = text->cursor.par();
72 int align = par->getAlign();
74 if (align==LYX_ALIGN_LAYOUT)
75 align = textclasslist.Style(buf->params.textclass, par->getLayout()).align;
77 ParagraphParameters * params = &(par->params());
79 if (params->spaceTop().kind() == VSpace::LENGTH) {
80 LyXGlueLength above = params->spaceTop().length();
81 lyxerr[Debug::GUI] << "Reading above space : \"" << params->spaceTop().length().asString() << "\"" << endl;
82 dialog_->setAboveLength(above.value(), above.plusValue(), above.minusValue(),
83 above.unit(), above.plusUnit(), above.minusUnit());
85 dialog_->setAboveLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
87 if (params->spaceBottom().kind() == VSpace::LENGTH) {
88 LyXGlueLength below = params->spaceBottom().length();
89 lyxerr[Debug::GUI] << "Reading below space : \"" << params->spaceBottom().length().asString() << "\"" << endl;
90 dialog_->setBelowLength(below.value(), below.plusValue(), below.minusValue(),
91 below.unit(), below.plusUnit(), below.minusUnit());
93 dialog_->setBelowLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
95 dialog_->setLabelWidth(text->cursor.par()->getLabelWidthString().c_str());
96 dialog_->setAlign(align);
97 dialog_->setChecks(params->lineTop(), params->lineBottom(),
98 params->pagebreakTop(), params->pagebreakBottom(), params->noindent());
99 dialog_->setSpace(params->spaceTop().kind(), params->spaceBottom().kind(),
100 params->spaceTop().keep(), params->spaceBottom().keep());
102 // now the extras page
104 LyXLength extrawidth;
106 LyXLength::UNIT unit = LyXLength::CM;
107 params = &(par->params());
108 if (isValidLength(params->pextraWidth(), &extrawidth)) {
109 lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
110 val = extrawidth.value();
111 unit = extrawidth.unit();
114 lyxerr[Debug::GUI] << "Reading widthp \"" << params->pextraWidthp() << "\"" << endl;
116 dialog_->setExtra(val, unit, params->pextraWidthp(),
117 params->pextraAlignment(),
118 params->pextraHfill(),
119 params->pextraStartMinipage(),
120 static_cast<Paragraph::PEXTRA_TYPE>(params->pextraType()));
124 void FormParagraph::apply()
132 if (dialog_->getSpaceAboveKind()==VSpace::LENGTH)
133 spaceabove = VSpace(dialog_->getAboveLength());
135 spaceabove = VSpace(dialog_->getSpaceAboveKind());
137 if (dialog_->getSpaceBelowKind()==VSpace::LENGTH)
138 spacebelow = VSpace(dialog_->getBelowLength());
140 spacebelow = VSpace(dialog_->getSpaceBelowKind());
142 spaceabove.setKeep(dialog_->getAboveKeep());
143 spacebelow.setKeep(dialog_->getBelowKeep());
145 lyxerr[Debug::GUI] << "Setting above space \"" << LyXGlueLength(spaceabove.length().asString()).asString() << "\"" << endl;
146 lyxerr[Debug::GUI] << "Setting below space \"" << LyXGlueLength(spacebelow.length().asString()).asString() << "\"" << endl;
148 lv_->view()->text->SetParagraph(lv_->view(),
149 dialog_->getLineAbove(), dialog_->getLineBelow(),
150 dialog_->getPagebreakAbove(), dialog_->getPagebreakBelow(),
151 spaceabove, spacebelow, dialog_->getAlign(),
152 dialog_->getLabelWidth(), dialog_->getNoIndent());
159 LyXLength extrawidth(dialog_->getExtraWidth());
160 if (extrawidth.unit()==LyXLength::UNIT_NONE) {
161 widthp = dialog_->getExtraWidthPercent();
163 width = extrawidth.asString();
165 lyxerr[Debug::GUI] << "Setting extrawidth \"" << width << "\"" << endl;
166 lyxerr[Debug::GUI] << "Setting percent extrawidth \"" << widthp << "\"" << endl;
168 lv_->view()->update(lv_->view()->text,
173 lv_->buffer()->markDirty();
174 setMinibuffer(lv_, _("Paragraph layout set"));
178 void FormParagraph::show()
181 dialog_ = new ParagraphDlgImpl(this, 0,
182 _("LyX: Paragraph Options"),
185 if (!dialog_->isVisible())
186 h_ = d_->hideBufferDependent
187 .connect(slot(this, &FormParagraph::hide));
190 dialog_->setActiveWindow();
197 void FormParagraph::close()
203 void FormParagraph::hide()