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