2 * \file FormParagraph.C
3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
14 #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 d->showLayoutParagraph.connect(slot(this, &FormParagraph::show));
35 FormParagraph::~FormParagraph()
41 void FormParagraph::update(bool switched)
48 if (!lv_->view()->available())
51 Buffer *buf = lv_->view()->buffer();
53 if (readonly != buf->isReadonly()) {
54 readonly = buf->isReadonly();
55 dialog_->setReadOnly(readonly);
60 if (lv_->view()->theLockingInset())
61 text = lv_->view()->theLockingInset()->getLyXText(lv_->view());
64 text = lv_->view()->text;
66 LyXParagraph const * par = text->cursor.par();
68 int align = par->GetAlign();
70 if (align==LYX_ALIGN_LAYOUT)
71 align = textclasslist.Style(buf->params.textclass, par->GetLayout()).align;
74 LyXParagraph const * physpar = par->FirstPhysicalPar();
76 LyXParagraph const * physpar = par;
79 if (physpar->added_space_top.kind() == VSpace::LENGTH) {
80 LyXGlueLength above = physpar->added_space_top.length();
81 lyxerr[Debug::GUI] << "Reading above space : \""
82 << physpar->added_space_top.length().asString() << "\"" << endl;
84 dialog_->setAboveLength(above.value(), above.plusValue(), above.minusValue(),
85 above.unit(), above.plusUnit(), above.minusUnit());
87 dialog_->setAboveLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
89 if (physpar->added_space_bottom.kind() == VSpace::LENGTH) {
90 LyXGlueLength below = physpar->added_space_bottom.length();
91 lyxerr[Debug::GUI] << "Reading below space : \""
92 << physpar->added_space_bottom.length().asString() << "\"" << endl;
94 dialog_->setBelowLength(below.value(), below.plusValue(), below.minusValue(),
95 below.unit(), below.plusUnit(), below.minusUnit());
97 dialog_->setBelowLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
99 dialog_->setLabelWidth(text->cursor.par()->GetLabelWidthString().c_str());
100 dialog_->setAlign(align);
102 dialog_->setChecks(physpar->line_top, physpar->line_bottom,
103 physpar->pagebreak_top, physpar->pagebreak_bottom, physpar->noindent);
105 dialog_->setSpace(physpar->added_space_top.kind(), physpar->added_space_bottom.kind(),
106 physpar->added_space_top.keep(), physpar->added_space_bottom.keep());
108 // now the extras page
110 LyXLength extrawidth;
112 LyXLength::UNIT unit = LyXLength::CM;
114 if (isValidLength(par->pextra_width, &extrawidth)) {
115 lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
116 val = extrawidth.value();
117 unit = extrawidth.unit();
120 lyxerr[Debug::GUI] << "Reading widthp \"" << par->pextra_widthp << "\"" << endl;
122 dialog_->setExtra(val, unit, par->pextra_widthp,
123 par->pextra_alignment,
125 par->pextra_start_minipage,
126 static_cast<LyXParagraph::PEXTRA_TYPE>(par->pextra_type));
130 void FormParagraph::apply()
138 if (dialog_->getSpaceAboveKind() == VSpace::LENGTH)
139 spaceabove = VSpace(dialog_->getAboveLength());
141 spaceabove = VSpace(dialog_->getSpaceAboveKind());
143 if (dialog_->getSpaceBelowKind() == VSpace::LENGTH)
144 spacebelow = VSpace(dialog_->getBelowLength());
146 spacebelow = VSpace(dialog_->getSpaceBelowKind());
148 spaceabove.setKeep(dialog_->getAboveKeep());
149 spacebelow.setKeep(dialog_->getBelowKeep());
151 lyxerr[Debug::GUI] << "Setting above space \""
152 << LyXGlueLength(spaceabove.length().asString()).asString() << "\"" << endl;
153 lyxerr[Debug::GUI] << "Setting below space \""
154 << LyXGlueLength(spacebelow.length().asString()).asString() << "\"" << endl;
156 lv_->view()->text->SetParagraph(lv_->view(),
157 dialog_->getLineAbove(), dialog_->getLineBelow(),
158 dialog_->getPagebreakAbove(), dialog_->getPagebreakBelow(),
159 spaceabove, spacebelow, dialog_->getAlign(),
160 dialog_->getLabelWidth(), dialog_->getNoIndent());
167 LyXLength extrawidth(dialog_->getExtraWidth());
168 if (extrawidth.unit() == LyXLength::UNIT_NONE) {
169 widthp = dialog_->getExtraWidthPercent();
171 width = extrawidth.asString();
173 lyxerr[Debug::GUI] << "Setting extrawidth \"" << width << "\"" << endl;
174 lyxerr[Debug::GUI] << "Setting percent extrawidth \"" << widthp << "\"" << endl;
176 lv_->view()->text->SetParagraphExtraOpt(lv_->view(),
177 dialog_->getExtraType(), width, widthp,
178 dialog_->getExtraAlign(),
179 dialog_->getHfillBetween(),
180 dialog_->getStartNewMinipage());
182 lv_->view()->update(BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
183 lv_->buffer()->markDirty();
184 setMinibuffer(lv_, _("Paragraph layout set"));
188 void FormParagraph::show()
191 dialog_ = new ParaDialog(this, 0, _("LyX: Paragraph Options"), false);
193 if (!dialog_->isVisible())
194 h_ = d_->hideBufferDependent.connect(slot(this, &FormParagraph::hide));
197 dialog_->setActiveWindow();
204 void FormParagraph::close()
210 void FormParagraph::hide()