3 * Copyright 2001 LyX Team
6 * \author John Levon, moz@compsoc.man.ac.uk
11 #include "QParagraphDialog.h"
13 #include "QParagraph.h"
17 #include "QtLyXView.h"
18 #include "lyxtextclasslist.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);
59 LyXText * text(lv_->view()->getLyXText());
60 Paragraph * par = text->cursor.par();
62 int align = par->getAlign();
64 if (align==LYX_ALIGN_LAYOUT)
65 align = textclasslist.Style(buf->params.textclass, par->getLayout()).align;
67 ParagraphParameters * params = &(par->params());
69 if (params->spaceTop().kind() == VSpace::LENGTH) {
70 LyXGlueLength above = params->spaceTop().length();
71 lyxerr[Debug::GUI] << "Reading above space : \"" << params->spaceTop().length().asString() << "\"" << endl;
72 dialog_->setAboveLength(above.len().value(), above.plus().value(), above.minus().value(),
73 above.len().unit(), above.plus().unit(), above.minus().unit());
75 dialog_->setAboveLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
77 if (params->spaceBottom().kind() == VSpace::LENGTH) {
78 LyXGlueLength below = params->spaceBottom().length();
79 lyxerr[Debug::GUI] << "Reading below space : \"" << params->spaceBottom().length().asString() << "\"" << endl;
80 dialog_->setBelowLength(below.len().value(), below.plus().value(), below.minus().value(),
81 below.len().unit(), below.plus().unit(), below.minus().unit());
83 dialog_->setBelowLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
85 dialog_->setLabelWidth(text->cursor.par()->getLabelWidthString().c_str());
86 dialog_->setAlign(align);
87 dialog_->setChecks(params->lineTop(), params->lineBottom(),
88 params->pagebreakTop(), params->pagebreakBottom(), params->noindent());
89 dialog_->setSpace(params->spaceTop().kind(), params->spaceBottom().kind(),
90 params->spaceTop().keep(), params->spaceBottom().keep());
92 // now the extras page
96 LyXLength::UNIT unit = LyXLength::CM;
97 params = &(par->params());
98 if (isValidLength(params->pextraWidth(), &extrawidth)) {
99 lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
100 val = extrawidth.value();
101 unit = extrawidth.unit();
104 lyxerr[Debug::GUI] << "Reading widthp \"" << params->pextraWidthp() << "\"" << endl;
106 dialog_->setExtra(val, unit, params->pextraWidthp(),
107 params->pextraAlignment(),
108 params->pextraHfill(),
109 params->pextraStartMinipage(),
110 static_cast<Paragraph::PEXTRA_TYPE>(params->pextraType()));
114 void QParagraph::apply()
122 if (dialog_->getSpaceAboveKind()==VSpace::LENGTH)
123 spaceabove = VSpace(dialog_->getAboveLength());
125 spaceabove = VSpace(dialog_->getSpaceAboveKind());
127 if (dialog_->getSpaceBelowKind()==VSpace::LENGTH)
128 spacebelow = VSpace(dialog_->getBelowLength());
130 spacebelow = VSpace(dialog_->getSpaceBelowKind());
132 spaceabove.setKeep(dialog_->getAboveKeep());
133 spacebelow.setKeep(dialog_->getBelowKeep());
135 lyxerr[Debug::GUI] << "Setting above space \"" << LyXGlueLength(spaceabove.length().asString()).asString() << "\"" << endl;
136 lyxerr[Debug::GUI] << "Setting below space \"" << LyXGlueLength(spacebelow.length().asString()).asString() << "\"" << endl;
138 LyXText * text(lv_->view()->getLyXText());
139 text->setParagraph(lv_->view(),
140 dialog_->getLineAbove(), dialog_->getLineBelow(),
141 dialog_->getPagebreakAbove(), dialog_->getPagebreakBelow(),
142 spaceabove, spacebelow, Spacing(), dialog_->getAlign(),
143 dialog_->getLabelWidth(), dialog_->getNoIndent());
150 LyXLength extrawidth(dialog_->getExtraWidth());
151 if (extrawidth.unit()==LyXLength::UNIT_NONE) {
152 widthp = dialog_->getExtraWidthPercent();
154 width = extrawidth.asString();
156 lyxerr[Debug::GUI] << "Setting extrawidth \"" << width << "\"" << endl;
157 lyxerr[Debug::GUI] << "Setting percent extrawidth \"" << widthp << "\"" << endl;
159 lv_->view()->update(text,
164 lv_->buffer()->markDirty();
165 setMinibuffer(lv_, _("Paragraph layout set"));
169 void QParagraph::show()
172 dialog_ = new QParagraphDialog(this, 0,
173 _("LyX: Paragraph Settings"),
176 if (!dialog_->isVisible())
177 h_ = d_->hideBufferDependent
178 .connect(slot(this, &QParagraph::hide));
181 dialog_->setActiveWindow();
188 void QParagraph::close()
194 void QParagraph::hide()