3 * Copyright 2001 LyX Team
6 * \author John Levon, moz@compsoc.man.ac.uk
11 #include "QParagraphDialog.h"
13 #include "QParagraph.h"
18 #include "QtLyXView.h"
21 #include "BufferView.h"
22 #include "ParagraphParameters.h"
25 using Liason::setMinibuffer;
29 QParagraph::QParagraph(LyXView *v, Dialogs *d)
30 : dialog_(0), lv_(v), d_(d), h_(0)
32 d->showParagraph.connect(slot(this, &QParagraph::show));
36 QParagraph::~QParagraph()
42 void QParagraph::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 Paragraph * 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;
74 ParagraphParameters * params = &(par->params());
76 if (params->spaceTop().kind() == VSpace::LENGTH) {
77 LyXGlueLength above = params->spaceTop().length();
78 lyxerr[Debug::GUI] << "Reading above space : \"" << params->spaceTop().length().asString() << "\"" << endl;
79 dialog_->setAboveLength(above.value(), above.plusValue(), above.minusValue(),
80 above.unit(), above.plusUnit(), above.minusUnit());
82 dialog_->setAboveLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
84 if (params->spaceBottom().kind() == VSpace::LENGTH) {
85 LyXGlueLength below = params->spaceBottom().length();
86 lyxerr[Debug::GUI] << "Reading below space : \"" << params->spaceBottom().length().asString() << "\"" << endl;
87 dialog_->setBelowLength(below.value(), below.plusValue(), below.minusValue(),
88 below.unit(), below.plusUnit(), below.minusUnit());
90 dialog_->setBelowLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
92 dialog_->setLabelWidth(text->cursor.par()->getLabelWidthString().c_str());
93 dialog_->setAlign(align);
94 dialog_->setChecks(params->lineTop(), params->lineBottom(),
95 params->pagebreakTop(), params->pagebreakBottom(), params->noindent());
96 dialog_->setSpace(params->spaceTop().kind(), params->spaceBottom().kind(),
97 params->spaceTop().keep(), params->spaceBottom().keep());
99 // now the extras page
101 LyXLength extrawidth;
103 LyXLength::UNIT unit = LyXLength::CM;
104 params = &(par->params());
105 if (isValidLength(params->pextraWidth(), &extrawidth)) {
106 lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
107 val = extrawidth.value();
108 unit = extrawidth.unit();
111 lyxerr[Debug::GUI] << "Reading widthp \"" << params->pextraWidthp() << "\"" << endl;
113 dialog_->setExtra(val, unit, params->pextraWidthp(),
114 params->pextraAlignment(),
115 params->pextraHfill(),
116 params->pextraStartMinipage(),
117 static_cast<Paragraph::PEXTRA_TYPE>(params->pextraType()));
121 void QParagraph::apply()
129 if (dialog_->getSpaceAboveKind()==VSpace::LENGTH)
130 spaceabove = VSpace(dialog_->getAboveLength());
132 spaceabove = VSpace(dialog_->getSpaceAboveKind());
134 if (dialog_->getSpaceBelowKind()==VSpace::LENGTH)
135 spacebelow = VSpace(dialog_->getBelowLength());
137 spacebelow = VSpace(dialog_->getSpaceBelowKind());
139 spaceabove.setKeep(dialog_->getAboveKeep());
140 spacebelow.setKeep(dialog_->getBelowKeep());
142 lyxerr[Debug::GUI] << "Setting above space \"" << LyXGlueLength(spaceabove.length().asString()).asString() << "\"" << endl;
143 lyxerr[Debug::GUI] << "Setting below space \"" << LyXGlueLength(spacebelow.length().asString()).asString() << "\"" << endl;
145 lv_->view()->text->setParagraph(lv_->view(),
146 dialog_->getLineAbove(), dialog_->getLineBelow(),
147 dialog_->getPagebreakAbove(), dialog_->getPagebreakBelow(),
148 spaceabove, spacebelow, Spacing(), dialog_->getAlign(),
149 dialog_->getLabelWidth(), dialog_->getNoIndent());
156 LyXLength extrawidth(dialog_->getExtraWidth());
157 if (extrawidth.unit()==LyXLength::UNIT_NONE) {
158 widthp = dialog_->getExtraWidthPercent();
160 width = extrawidth.asString();
162 lyxerr[Debug::GUI] << "Setting extrawidth \"" << width << "\"" << endl;
163 lyxerr[Debug::GUI] << "Setting percent extrawidth \"" << widthp << "\"" << endl;
165 lv_->view()->update(lv_->view()->text,
170 lv_->buffer()->markDirty();
171 setMinibuffer(lv_, _("Paragraph layout set"));
175 void QParagraph::show()
178 dialog_ = new QParagraphDialog(this, 0,
179 _("LyX: Paragraph Settings"),
182 if (!dialog_->isVisible())
183 h_ = d_->hideBufferDependent
184 .connect(slot(this, &QParagraph::hide));
187 dialog_->setActiveWindow();
194 void QParagraph::close()
200 void QParagraph::hide()