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 LyXParagraph *physpar = par->FirstPhysicalPar();
77 LyXParagraph *physpar = par;
80 if (physpar->added_space_top.kind()==VSpace::LENGTH) {
81 LyXGlueLength above = physpar->added_space_top.length();
82 lyxerr[Debug::GUI] << "Reading above space : \"" << physpar->added_space_top.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 (physpar->added_space_bottom.kind()==VSpace::LENGTH) {
89 LyXGlueLength below = physpar->added_space_bottom.length();
90 lyxerr[Debug::GUI] << "Reading below space : \"" << physpar->added_space_bottom.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(physpar->line_top, physpar->line_bottom,
99 physpar->pagebreak_top, physpar->pagebreak_bottom, physpar->noindent);
100 dialog_->setSpace(physpar->added_space_top.kind(), physpar->added_space_bottom.kind(),
101 physpar->added_space_top.keep(), physpar->added_space_bottom.keep());
103 // now the extras page
105 LyXLength extrawidth;
107 LyXLength::UNIT unit = LyXLength::CM;
109 if (isValidLength(par->pextra_width, &extrawidth)) {
110 lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
111 val = extrawidth.value();
112 unit = extrawidth.unit();
115 lyxerr[Debug::GUI] << "Reading widthp \"" << par->pextra_widthp << "\"" << endl;
117 dialog_->setExtra(val, unit, par->pextra_widthp,
118 par->pextra_alignment,
120 par->pextra_start_minipage,
121 static_cast<LyXParagraph::PEXTRA_TYPE>(par->pextra_type));
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()->text->SetParagraphExtraOpt(lv_->view(),
169 dialog_->getExtraType(), width, widthp,
170 dialog_->getExtraAlign(),
171 dialog_->getHfillBetween(),
172 dialog_->getStartNewMinipage());
174 lv_->view()->update(lv_->view()->text,
179 lv_->buffer()->markDirty();
180 setMinibuffer(lv_, _("Paragraph layout set"));
183 void FormParagraph::show()
186 dialog_ = new ParagraphDlgImpl(this, 0, _("LyX: Paragraph Options"), false);
188 if (!dialog_->isVisible())
189 h_ = d_->hideBufferDependent.connect(slot(this, &FormParagraph::hide));
193 dialog_->setActiveWindow();
199 void FormParagraph::close()
204 void FormParagraph::hide()