]> git.lyx.org Git - features.git/blob - src/frontends/qt2/FormParagraph.C
dc62aedf549af6dbfc79f724730fcfa76bcb9bcf
[features.git] / src / frontends / qt2 / FormParagraph.C
1 /**
2  * \file FormParagraph.C
3  * Copyright 2001 LyX Team
4  * see the file COPYING
5  *
6  * \author John Levon, moz@compsoc.man.ac.uk
7  */
8
9 #include <config.h>
10
11 #include "paragraphdlgimpl.h"
12
13 #include "FormParagraph.h"
14 #include "Dialogs.h"
15 #include "Liason.h"
16 #include "gettext.h"
17 #include "buffer.h"
18 #include "QtLyXView.h"
19 #include "lyxtext.h"
20 #include "debug.h"
21 #include "BufferView.h"
22 #include "ParagraphParameters.h"
23
24 using SigC::slot;
25 using Liason::setMinibuffer;
26 using std::endl;
27
28
29 FormParagraph::FormParagraph(LyXView *v, Dialogs *d)
30         : dialog_(0), lv_(v), d_(d), h_(0)
31 {
32         // let the dialog be shown
33         // This is a permanent connection so we won't bother
34         // storing a copy because we won't be disconnecting.
35         d->showParagraph.connect(slot(this, &FormParagraph::show));
36 }
37
38
39 FormParagraph::~FormParagraph()
40 {
41         delete dialog_;
42 }
43
44
45 void FormParagraph::update(bool switched)
46 {
47         if (switched) {
48                 hide();
49                 return;
50         }
51
52         if (!lv_->view()->available())
53                 return;
54
55         Buffer * buf = lv_->view()->buffer();
56
57         if (readonly!=buf->isReadonly()) {
58                 readonly = buf->isReadonly();
59                 dialog_->setReadOnly(readonly);
60         }
61
62         LyXText * text = 0;
63
64         if (lv_->view()->theLockingInset())
65                 text = lv_->view()->theLockingInset()->getLyXText(lv_->view());
66
67         if (!text)
68                 text = lv_->view()->text;
69
70         Paragraph * par = text->cursor.par();
71
72         int align = par->getAlign();
73
74         if (align==LYX_ALIGN_LAYOUT)
75                 align = textclasslist.Style(buf->params.textclass, par->getLayout()).align;
76
77         ParagraphParameters * params = &(par->params());
78
79         if (params->spaceTop().kind() == VSpace::LENGTH) {
80                 LyXGlueLength above = params->spaceTop().length();
81                 lyxerr[Debug::GUI] << "Reading above space : \"" << params->spaceTop().length().asString() << "\"" << endl;
82                 dialog_->setAboveLength(above.value(), above.plusValue(), above.minusValue(),
83                         above.unit(), above.plusUnit(), above.minusUnit());
84         } else
85                 dialog_->setAboveLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
86
87         if (params->spaceBottom().kind() == VSpace::LENGTH) {
88                 LyXGlueLength below = params->spaceBottom().length();
89                 lyxerr[Debug::GUI] << "Reading below space : \"" << params->spaceBottom().length().asString() << "\"" << endl;
90                 dialog_->setBelowLength(below.value(), below.plusValue(), below.minusValue(),
91                         below.unit(), below.plusUnit(), below.minusUnit());
92         } else
93                 dialog_->setBelowLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
94
95         dialog_->setLabelWidth(text->cursor.par()->getLabelWidthString().c_str());
96         dialog_->setAlign(align);
97         dialog_->setChecks(params->lineTop(), params->lineBottom(),
98                 params->pagebreakTop(), params->pagebreakBottom(), params->noindent());
99         dialog_->setSpace(params->spaceTop().kind(), params->spaceBottom().kind(),
100                 params->spaceTop().keep(), params->spaceBottom().keep());
101
102         // now the extras page
103
104         LyXLength extrawidth;
105         float val = 0.0;
106         LyXLength::UNIT unit = LyXLength::CM;
107         params = &(par->params());
108         if (isValidLength(params->pextraWidth(), &extrawidth)) {
109                 lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
110                 val = extrawidth.value();
111                 unit = extrawidth.unit();
112         }
113
114         lyxerr[Debug::GUI] << "Reading widthp \"" << params->pextraWidthp() << "\"" << endl;
115
116         dialog_->setExtra(val, unit, params->pextraWidthp(),
117                 params->pextraAlignment(),
118                 params->pextraHfill(),
119                 params->pextraStartMinipage(),
120                 static_cast<Paragraph::PEXTRA_TYPE>(params->pextraType()));
121 }
122
123
124 void FormParagraph::apply()
125 {
126         if (readonly)
127                 return;
128
129         VSpace spaceabove;
130         VSpace spacebelow;
131
132         if (dialog_->getSpaceAboveKind()==VSpace::LENGTH)
133                 spaceabove = VSpace(dialog_->getAboveLength());
134         else
135                 spaceabove = VSpace(dialog_->getSpaceAboveKind());
136
137         if (dialog_->getSpaceBelowKind()==VSpace::LENGTH)
138                 spacebelow = VSpace(dialog_->getBelowLength());
139         else
140                 spacebelow = VSpace(dialog_->getSpaceBelowKind());
141
142         spaceabove.setKeep(dialog_->getAboveKeep());
143         spacebelow.setKeep(dialog_->getBelowKeep());
144
145         lyxerr[Debug::GUI] << "Setting above space \"" << LyXGlueLength(spaceabove.length().asString()).asString() << "\"" << endl;
146         lyxerr[Debug::GUI] << "Setting below space \"" << LyXGlueLength(spacebelow.length().asString()).asString() << "\"" << endl;
147
148         lv_->view()->text->setParagraph(lv_->view(),
149                 dialog_->getLineAbove(), dialog_->getLineBelow(),
150                 dialog_->getPagebreakAbove(), dialog_->getPagebreakBelow(),
151                 spaceabove, spacebelow, dialog_->getAlign(),
152                 dialog_->getLabelWidth(), dialog_->getNoIndent());
153
154         // extra stuff
155
156         string width("");
157         string widthp("");
158
159         LyXLength extrawidth(dialog_->getExtraWidth());
160         if (extrawidth.unit()==LyXLength::UNIT_NONE) {
161                 widthp = dialog_->getExtraWidthPercent();
162         } else
163                 width = extrawidth.asString();
164
165         lyxerr[Debug::GUI] << "Setting extrawidth \"" << width << "\"" << endl;
166         lyxerr[Debug::GUI] << "Setting percent extrawidth \"" << widthp << "\"" << endl;
167
168         lv_->view()->update(lv_->view()->text,
169                             BufferView::SELECT |
170                             BufferView::FITCUR |
171                             BufferView::CHANGE);
172
173         lv_->buffer()->markDirty();
174         setMinibuffer(lv_, _("Paragraph layout set"));
175 }
176
177
178 void FormParagraph::show()
179 {
180         if (!dialog_)
181                 dialog_ = new ParagraphDlgImpl(this, 0,
182                                                _("LyX: Paragraph Options"),
183                                                false);
184
185         if (!dialog_->isVisible())
186                 h_ = d_->hideBufferDependent
187                         .connect(slot(this, &FormParagraph::hide));
188
189         dialog_->raise();
190         dialog_->setActiveWindow();
191         update();
192
193         dialog_->show();
194 }
195
196
197 void FormParagraph::close()
198 {
199         h_.disconnect();
200 }
201
202
203 void FormParagraph::hide()
204 {
205         dialog_->hide();
206         close();
207 }