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;
33 FormParagraph::FormParagraph(LyXView *v, Dialogs *d)
34 : dialog_(0), lv_(v), d_(d), h_(0)
36 // let the dialog be shown
37 // This is a permanent connection so we won't bother
38 // storing a copy because we won't be disconnecting.
39 d->showLayoutParagraph.connect(slot(this, &FormParagraph::show));
42 FormParagraph::~FormParagraph()
47 void FormParagraph::update(bool switched)
54 if (!lv_->view()->available())
57 Buffer *buf = lv_->view()->buffer();
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 // FIXME: ??? this breaks badly if we ever add non glue length vspace to a paragraph
82 // I need some help here ... it is silly anyway !
83 LyXGlueLength above(physpar->added_space_top.length().asString());
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 // FIXME: ??? this breaks badly if we ever add non glue length vspace to a paragraph
92 // I need some help here ... it is silly anyway !
93 LyXGlueLength below(physpar->added_space_bottom.length().asString());
94 lyxerr[Debug::GUI] << "Reading below space : \"" << physpar->added_space_bottom.length().asString() << "\"" << endl;
95 dialog_->setBelowLength(below.value(), below.plusValue(), below.minusValue(),
96 below.unit(), below.plusUnit(), below.minusUnit());
98 dialog_->setBelowLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
100 if (readonly!=buf->isReadonly()) {
101 readonly = buf->isReadonly();
102 dialog_->setReadOnly(readonly);
105 dialog_->setLabelWidth(text->cursor.par()->GetLabelWidthString().c_str());
106 dialog_->setAlign(align);
107 dialog_->setChecks(physpar->line_top, physpar->line_bottom,
108 physpar->pagebreak_top, physpar->pagebreak_bottom, physpar->noindent);
109 dialog_->setSpace(physpar->added_space_top.kind(), physpar->added_space_bottom.kind(),
110 physpar->added_space_top.keep(), physpar->added_space_bottom.keep());
112 // now the extras page
114 LyXLength extrawidth;
116 LyXLength::UNIT unit = LyXLength::CM;
118 if (isValidLength(par->pextra_width, &extrawidth)) {
119 lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
120 val = extrawidth.value();
121 unit = extrawidth.unit();
124 lyxerr[Debug::GUI] << "Reading widthp \"" << par->pextra_widthp << "\"" << endl;
126 dialog_->setExtra(val, unit, par->pextra_widthp,
127 par->pextra_alignment,
129 par->pextra_start_minipage,
130 static_cast<LyXParagraph::PEXTRA_TYPE>(par->pextra_type));
133 void FormParagraph::apply()
141 if (dialog_->getSpaceAboveKind()==VSpace::LENGTH)
142 spaceabove = VSpace(dialog_->getAboveLength());
144 spaceabove = VSpace(dialog_->getSpaceAboveKind());
146 if (dialog_->getSpaceBelowKind()==VSpace::LENGTH)
147 spacebelow = VSpace(dialog_->getBelowLength());
149 spacebelow = VSpace(dialog_->getSpaceBelowKind());
151 lyxerr[Debug::GUI] << "Setting above space \"" << LyXGlueLength(spaceabove.length().asString()).asString() << "\"" << endl;
152 lyxerr[Debug::GUI] << "Setting below space \"" << LyXGlueLength(spacebelow.length().asString()).asString() << "\"" << endl;
154 lv_->view()->text->SetParagraph(lv_->view(),
155 dialog_->getLineAbove(), dialog_->getLineBelow(),
156 dialog_->getPagebreakAbove(), dialog_->getPagebreakBelow(),
157 spaceabove, spacebelow, dialog_->getAlign(),
158 dialog_->getLabelWidth(), dialog_->getNoIndent());
165 LyXLength extrawidth(dialog_->getExtraWidth());
166 if (extrawidth.unit()==LyXLength::UNIT_NONE) {
167 widthp = dialog_->getExtraWidthPercent();
169 width = extrawidth.asString();
171 lyxerr[Debug::GUI] << "Setting extrawidth \"" << width << "\"" << endl;
172 lyxerr[Debug::GUI] << "Setting percent extrawidth \"" << widthp << "\"" << endl;
174 lv_->view()->text->SetParagraphExtraOpt(lv_->view(),
175 dialog_->getExtraType(), width, widthp,
176 dialog_->getExtraAlign(),
177 dialog_->getHfillBetween(),
178 dialog_->getStartNewMinipage());
181 void FormParagraph::show()
184 dialog_ = new ParaDialog(this, 0, _("LyX: Paragraph Options"), false);
186 if (!dialog_->isVisible())
187 h_ = d_->hideBufferDependent.connect(slot(this, &FormParagraph::hide));
190 dialog_->setActiveWindow();
196 void FormParagraph::close()
201 void FormParagraph::hide()