4 * John Levon, moz@compsoc.man.ac.uk
7 /***************************************************************************
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
14 ***************************************************************************/
21 #include "FormParagraph.h"
25 #include "QtLyXView.h"
29 #ifdef CXX_WORKING_NAMESPACES
30 using Liason::setMinibuffer;
35 FormParagraph::FormParagraph(LyXView *v, Dialogs *d)
36 : dialog_(0), lv_(v), d_(d), h_(0)
38 // let the dialog be shown
39 // This is a permanent connection so we won't bother
40 // storing a copy because we won't be disconnecting.
41 d->showLayoutParagraph.connect(slot(this, &FormParagraph::show));
44 FormParagraph::~FormParagraph()
49 void FormParagraph::update(bool switched)
56 if (!lv_->view()->available())
59 Buffer *buf = lv_->view()->buffer();
63 if (lv_->view()->theLockingInset())
64 text = lv_->view()->theLockingInset()->getLyXText(lv_->view());
67 text = lv_->view()->text;
69 LyXParagraph *par = text->cursor.par();
71 int align = par->GetAlign();
73 if (align==LYX_ALIGN_LAYOUT)
74 align = textclasslist.Style(buf->params.textclass, par->GetLayout()).align;
77 LyXParagraph *physpar = par->FirstPhysicalPar();
79 LyXParagraph *physpar = par;
82 if (physpar->added_space_top.kind()==VSpace::LENGTH) {
83 LyXGlueLength above = physpar->added_space_top.length();
84 lyxerr[Debug::GUI] << "Reading above space : \"" << physpar->added_space_top.length().asString() << "\"" << endl;
85 dialog_->setAboveLength(above.value(), above.plusValue(), above.minusValue(),
86 above.unit(), above.plusUnit(), above.minusUnit());
88 dialog_->setAboveLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
90 if (physpar->added_space_bottom.kind()==VSpace::LENGTH) {
91 LyXGlueLength below = physpar->added_space_bottom.length();
92 lyxerr[Debug::GUI] << "Reading below space : \"" << physpar->added_space_bottom.length().asString() << "\"" << endl;
93 dialog_->setBelowLength(below.value(), below.plusValue(), below.minusValue(),
94 below.unit(), below.plusUnit(), below.minusUnit());
96 dialog_->setBelowLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
98 if (readonly!=buf->isReadonly()) {
99 readonly = buf->isReadonly();
100 dialog_->setReadOnly(readonly);
103 dialog_->setLabelWidth(text->cursor.par()->GetLabelWidthString().c_str());
104 dialog_->setAlign(align);
105 dialog_->setChecks(physpar->line_top, physpar->line_bottom,
106 physpar->pagebreak_top, physpar->pagebreak_bottom, physpar->noindent);
107 dialog_->setSpace(physpar->added_space_top.kind(), physpar->added_space_bottom.kind(),
108 physpar->added_space_top.keep(), physpar->added_space_bottom.keep());
110 // now the extras page
112 LyXLength extrawidth;
114 LyXLength::UNIT unit = LyXLength::CM;
116 if (isValidLength(par->pextra_width, &extrawidth)) {
117 lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
118 val = extrawidth.value();
119 unit = extrawidth.unit();
122 lyxerr[Debug::GUI] << "Reading widthp \"" << par->pextra_widthp << "\"" << endl;
124 dialog_->setExtra(val, unit, par->pextra_widthp,
125 par->pextra_alignment,
127 par->pextra_start_minipage,
128 static_cast<LyXParagraph::PEXTRA_TYPE>(par->pextra_type));
131 void FormParagraph::apply()
139 if (dialog_->getSpaceAboveKind()==VSpace::LENGTH)
140 spaceabove = VSpace(dialog_->getAboveLength());
142 spaceabove = VSpace(dialog_->getSpaceAboveKind());
144 if (dialog_->getSpaceBelowKind()==VSpace::LENGTH)
145 spacebelow = VSpace(dialog_->getBelowLength());
147 spacebelow = VSpace(dialog_->getSpaceBelowKind());
149 spaceabove.setKeep(dialog_->getAboveKeep());
150 spacebelow.setKeep(dialog_->getBelowKeep());
152 lyxerr[Debug::GUI] << "Setting above space \"" << LyXGlueLength(spaceabove.length().asString()).asString() << "\"" << endl;
153 lyxerr[Debug::GUI] << "Setting below space \"" << LyXGlueLength(spacebelow.length().asString()).asString() << "\"" << endl;
155 lv_->view()->text->SetParagraph(lv_->view(),
156 dialog_->getLineAbove(), dialog_->getLineBelow(),
157 dialog_->getPagebreakAbove(), dialog_->getPagebreakBelow(),
158 spaceabove, spacebelow, dialog_->getAlign(),
159 dialog_->getLabelWidth(), dialog_->getNoIndent());
166 LyXLength extrawidth(dialog_->getExtraWidth());
167 if (extrawidth.unit()==LyXLength::UNIT_NONE) {
168 widthp = dialog_->getExtraWidthPercent();
170 width = extrawidth.asString();
172 lyxerr[Debug::GUI] << "Setting extrawidth \"" << width << "\"" << endl;
173 lyxerr[Debug::GUI] << "Setting percent extrawidth \"" << widthp << "\"" << endl;
175 lv_->view()->text->SetParagraphExtraOpt(lv_->view(),
176 dialog_->getExtraType(), width, widthp,
177 dialog_->getExtraAlign(),
178 dialog_->getHfillBetween(),
179 dialog_->getStartNewMinipage());
181 lv_->view()->update(BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
182 lv_->buffer()->markDirty();
183 setMinibuffer(lv_, _("Paragraph layout set"));
186 void FormParagraph::show()
189 dialog_ = new ParaDialog(this, 0, _("LyX: Paragraph Options"), false);
191 if (!dialog_->isVisible())
192 h_ = d_->hideBufferDependent.connect(slot(this, &FormParagraph::hide));
195 dialog_->setActiveWindow();
201 void FormParagraph::close()
206 void FormParagraph::hide()