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