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