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