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"
19 #include "lyxtextclasslist.h"
22 #include "BufferView.h"
23 #include "ParagraphParameters.h"
26 using Liason::setMinibuffer;
30 QParagraph::QParagraph(LyXView *v, Dialogs *d)
31 : dialog_(0), lv_(v), d_(d), h_(0)
33 d->showParagraph.connect(slot(this, &QParagraph::show));
37 QParagraph::~QParagraph()
43 void QParagraph::update(bool switched)
50 if (!lv_->view()->available())
53 Buffer * buf = lv_->view()->buffer();
55 if (readonly!=buf->isReadonly()) {
56 readonly = buf->isReadonly();
57 dialog_->setReadOnly(readonly);
60 LyXText * text(lv_->view()->getLyXText());
61 Paragraph * par = text->cursor.par();
63 int align = par->getAlign();
65 if (align==LYX_ALIGN_LAYOUT)
66 align = textclasslist.Style(buf->params.textclass, par->getLayout()).align;
68 ParagraphParameters * params = &(par->params());
70 if (params->spaceTop().kind() == VSpace::LENGTH) {
71 LyXGlueLength above = params->spaceTop().length();
72 lyxerr[Debug::GUI] << "Reading above space : \"" << params->spaceTop().length().asString() << "\"" << endl;
73 dialog_->setAboveLength(above.len().value(), above.plus().value(), above.minus().value(),
74 above.len().unit(), above.plus().unit(), above.minus().unit());
76 dialog_->setAboveLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
78 if (params->spaceBottom().kind() == VSpace::LENGTH) {
79 LyXGlueLength below = params->spaceBottom().length();
80 lyxerr[Debug::GUI] << "Reading below space : \"" << params->spaceBottom().length().asString() << "\"" << endl;
81 dialog_->setBelowLength(below.len().value(), below.plus().value(), below.minus().value(),
82 below.len().unit(), below.plus().unit(), below.minus().unit());
84 dialog_->setBelowLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
86 dialog_->setLabelWidth(text->cursor.par()->getLabelWidthString().c_str());
87 dialog_->setAlign(align);
88 dialog_->setChecks(params->lineTop(), params->lineBottom(),
89 params->pagebreakTop(), params->pagebreakBottom(), params->noindent());
90 dialog_->setSpace(params->spaceTop().kind(), params->spaceBottom().kind(),
91 params->spaceTop().keep(), params->spaceBottom().keep());
93 // now the extras page
97 LyXLength::UNIT unit = LyXLength::CM;
98 params = &(par->params());
99 if (isValidLength(params->pextraWidth(), &extrawidth)) {
100 lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
101 val = extrawidth.value();
102 unit = extrawidth.unit();
105 lyxerr[Debug::GUI] << "Reading widthp \"" << params->pextraWidthp() << "\"" << endl;
107 dialog_->setExtra(val, unit, params->pextraWidthp(),
108 params->pextraAlignment(),
109 params->pextraHfill(),
110 params->pextraStartMinipage(),
111 static_cast<Paragraph::PEXTRA_TYPE>(params->pextraType()));
115 void QParagraph::apply()
123 if (dialog_->getSpaceAboveKind()==VSpace::LENGTH)
124 spaceabove = VSpace(dialog_->getAboveLength());
126 spaceabove = VSpace(dialog_->getSpaceAboveKind());
128 if (dialog_->getSpaceBelowKind()==VSpace::LENGTH)
129 spacebelow = VSpace(dialog_->getBelowLength());
131 spacebelow = VSpace(dialog_->getSpaceBelowKind());
133 spaceabove.setKeep(dialog_->getAboveKeep());
134 spacebelow.setKeep(dialog_->getBelowKeep());
136 lyxerr[Debug::GUI] << "Setting above space \"" << LyXGlueLength(spaceabove.length().asString()).asString() << "\"" << endl;
137 lyxerr[Debug::GUI] << "Setting below space \"" << LyXGlueLength(spacebelow.length().asString()).asString() << "\"" << endl;
139 LyXText * text(lv_->view()->getLyXText());
140 text->setParagraph(lv_->view(),
141 dialog_->getLineAbove(), dialog_->getLineBelow(),
142 dialog_->getPagebreakAbove(), dialog_->getPagebreakBelow(),
143 spaceabove, spacebelow, Spacing(), dialog_->getAlign(),
144 dialog_->getLabelWidth(), dialog_->getNoIndent());
151 LyXLength extrawidth(dialog_->getExtraWidth());
152 if (extrawidth.unit()==LyXLength::UNIT_NONE) {
153 widthp = dialog_->getExtraWidthPercent();
155 width = extrawidth.asString();
157 lyxerr[Debug::GUI] << "Setting extrawidth \"" << width << "\"" << endl;
158 lyxerr[Debug::GUI] << "Setting percent extrawidth \"" << widthp << "\"" << endl;
160 lv_->view()->update(text,
165 lv_->buffer()->markDirty();
166 setMinibuffer(lv_, _("Paragraph layout set"));
170 void QParagraph::show()
173 dialog_ = new QParagraphDialog(this, 0,
174 _("LyX: Paragraph Settings"),
177 if (!dialog_->isVisible())
178 h_ = d_->hideBufferDependent
179 .connect(slot(this, &QParagraph::hide));
182 dialog_->setActiveWindow();
189 void QParagraph::close()
195 void QParagraph::hide()