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 // FIXME: ??? this breaks badly if we ever add non glue length vspace to a paragraph
84 // I need some help here ... it is silly anyway !
85 LyXGlueLength above(physpar->added_space_top.length().asString());
86 lyxerr[Debug::GUI] << "Reading above space : \"" << physpar->added_space_top.length().asString() << "\"" << endl;
87 dialog_->setAboveLength(above.value(), above.plusValue(), above.minusValue(),
88 above.unit(), above.plusUnit(), above.minusUnit());
90 dialog_->setAboveLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
92 if (physpar->added_space_bottom.kind()==VSpace::LENGTH) {
93 // FIXME: ??? this breaks badly if we ever add non glue length vspace to a paragraph
94 // I need some help here ... it is silly anyway !
95 LyXGlueLength below(physpar->added_space_bottom.length().asString());
96 lyxerr[Debug::GUI] << "Reading below space : \"" << physpar->added_space_bottom.length().asString() << "\"" << endl;
97 dialog_->setBelowLength(below.value(), below.plusValue(), below.minusValue(),
98 below.unit(), below.plusUnit(), below.minusUnit());
100 dialog_->setBelowLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
102 if (readonly!=buf->isReadonly()) {
103 readonly = buf->isReadonly();
104 dialog_->setReadOnly(readonly);
107 dialog_->setLabelWidth(text->cursor.par()->GetLabelWidthString().c_str());
108 dialog_->setAlign(align);
109 dialog_->setChecks(physpar->line_top, physpar->line_bottom,
110 physpar->pagebreak_top, physpar->pagebreak_bottom, physpar->noindent);
111 dialog_->setSpace(physpar->added_space_top.kind(), physpar->added_space_bottom.kind(),
112 physpar->added_space_top.keep(), physpar->added_space_bottom.keep());
114 // now the extras page
116 LyXLength extrawidth;
118 LyXLength::UNIT unit = LyXLength::CM;
120 if (isValidLength(par->pextra_width, &extrawidth)) {
121 lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
122 val = extrawidth.value();
123 unit = extrawidth.unit();
126 lyxerr[Debug::GUI] << "Reading widthp \"" << par->pextra_widthp << "\"" << endl;
128 dialog_->setExtra(val, unit, par->pextra_widthp,
129 par->pextra_alignment,
131 par->pextra_start_minipage,
132 static_cast<LyXParagraph::PEXTRA_TYPE>(par->pextra_type));
135 void FormParagraph::apply()
143 if (dialog_->getSpaceAboveKind()==VSpace::LENGTH)
144 spaceabove = VSpace(dialog_->getAboveLength());
146 spaceabove = VSpace(dialog_->getSpaceAboveKind());
148 if (dialog_->getSpaceBelowKind()==VSpace::LENGTH)
149 spacebelow = VSpace(dialog_->getBelowLength());
151 spacebelow = VSpace(dialog_->getSpaceBelowKind());
153 lyxerr[Debug::GUI] << "Setting above space \"" << LyXGlueLength(spaceabove.length().asString()).asString() << "\"" << endl;
154 lyxerr[Debug::GUI] << "Setting below space \"" << 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());
183 void FormParagraph::show()
186 dialog_ = new ParaDialog(this, 0, _("LyX: Paragraph Options"), false);
188 if (!dialog_->isVisible())
189 h_ = d_->hideBufferDependent.connect(slot(this, &FormParagraph::hide));
192 dialog_->setActiveWindow();
198 void FormParagraph::close()
203 void FormParagraph::hide()