]> git.lyx.org Git - features.git/blob - src/frontends/kde/FormParagraph.C
c957a0baf7d5983d604d657085d3c720b5447b4c
[features.git] / src / frontends / kde / FormParagraph.C
1 /*
2  * FormParagraph.C
3  * (C) 2000 LyX Team
4  * John Levon, moz@compsoc.man.ac.uk
5  */
6
7 /***************************************************************************
8  *                                                                         *
9  *   This program is free software; you can redistribute it and/or modify  *
10  *   it under the terms of the GNU General Public License as published by  *
11  *   the Free Software Foundation; either version 2 of the License, or     *
12  *   (at your option) any later version.                                   *
13  *                                                                         *
14  ***************************************************************************/
15
16 #include <config.h>
17
18 #include "paradlg.h"
19
20 #include "Dialogs.h"
21 #include "FormParagraph.h"
22 #include "Liason.h"
23 #include "gettext.h"
24 #include "buffer.h"
25 #include "QtLyXView.h"
26 #include "lyxtext.h"
27 #include "debug.h"
28
29 #ifdef CXX_WORKING_NAMESPACES
30 using Liason::setMinibuffer;
31 #endif
32
33 using std::endl;
34
35 FormParagraph::FormParagraph(LyXView *v, Dialogs *d)
36         : dialog_(0), lv_(v), d_(d), h_(0)
37 {
38         // let the dialog be shown
39         // This is a permanent connection so we won't bother
40         // storing a copy because we won't be disconnecting.
41         d->showLayoutParagraph.connect(slot(this, &FormParagraph::show));
42 }
43
44 FormParagraph::~FormParagraph()
45 {
46         delete dialog_;
47 }
48
49 void FormParagraph::update(bool switched)
50 {
51         if (switched) {
52                 hide();
53                 return;
54         }
55
56         if (!lv_->view()->available())
57                 return;
58
59         Buffer *buf = lv_->view()->buffer();
60         
61         LyXText *text = 0;
62
63         if (lv_->view()->theLockingInset())
64                 text = lv_->view()->theLockingInset()->getLyXText(lv_->view());
65
66         if (!text)
67                 text = lv_->view()->text;
68
69         LyXParagraph *par = text->cursor.par();
70
71         int align = par->GetAlign();
72         
73         if (align==LYX_ALIGN_LAYOUT)
74                 align = textclasslist.Style(buf->params.textclass, par->GetLayout()).align;
75
76 #ifndef NEW_INSETS
77         LyXParagraph *physpar = par->FirstPhysicalPar();
78 #else
79         LyXParagraph *physpar = par;
80 #endif
81
82         if (physpar->added_space_top.kind()==VSpace::LENGTH) {
83                 // FIXME: ??? this breaks badly if we ever add non glue length vspace to a paragraph
84                 // I need some help here ... it is silly anyway !
85                 LyXGlueLength above(physpar->added_space_top.length().asString());
86                 lyxerr[Debug::GUI] << "Reading above space : \"" << physpar->added_space_top.length().asString() << "\"" << endl;
87                 dialog_->setAboveLength(above.value(), above.plusValue(), above.minusValue(),
88                         above.unit(), above.plusUnit(), above.minusUnit());
89         } else
90                 dialog_->setAboveLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
91
92         if (physpar->added_space_bottom.kind()==VSpace::LENGTH) {
93                 // FIXME: ??? this breaks badly if we ever add non glue length vspace to a paragraph
94                 // I need some help here ... it is silly anyway !
95                 LyXGlueLength below(physpar->added_space_bottom.length().asString());
96                 lyxerr[Debug::GUI] << "Reading below space : \"" << physpar->added_space_bottom.length().asString() << "\"" << endl;
97                 dialog_->setBelowLength(below.value(), below.plusValue(), below.minusValue(),
98                         below.unit(), below.plusUnit(), below.minusUnit());
99         } else
100                 dialog_->setBelowLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
101
102         if (readonly!=buf->isReadonly()) {
103                 readonly = buf->isReadonly();
104                 dialog_->setReadOnly(readonly);
105         }
106
107         dialog_->setLabelWidth(text->cursor.par()->GetLabelWidthString().c_str());
108         dialog_->setAlign(align);
109         dialog_->setChecks(physpar->line_top, physpar->line_bottom,
110                 physpar->pagebreak_top, physpar->pagebreak_bottom, physpar->noindent);
111         dialog_->setSpace(physpar->added_space_top.kind(), physpar->added_space_bottom.kind(),
112                 physpar->added_space_top.keep(), physpar->added_space_bottom.keep());
113
114         // now the extras page
115
116         LyXLength extrawidth;
117         float val = 0.0;
118         LyXLength::UNIT unit = LyXLength::CM;
119
120         if (isValidLength(par->pextra_width, &extrawidth)) {
121                 lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
122                 val = extrawidth.value();
123                 unit = extrawidth.unit();
124         }
125
126         lyxerr[Debug::GUI] << "Reading widthp \"" << par->pextra_widthp << "\"" << endl;
127
128         dialog_->setExtra(val, unit, par->pextra_widthp,
129                 par->pextra_alignment,
130                 par->pextra_hfill,
131                 par->pextra_start_minipage,
132                 static_cast<LyXParagraph::PEXTRA_TYPE>(par->pextra_type));
133 }
134
135 void FormParagraph::apply()
136 {
137         if (readonly)
138                 return;
139
140         VSpace spaceabove;
141         VSpace spacebelow;
142
143         if (dialog_->getSpaceAboveKind()==VSpace::LENGTH)
144                 spaceabove = VSpace(dialog_->getAboveLength());
145         else
146                 spaceabove = VSpace(dialog_->getSpaceAboveKind());
147
148         if (dialog_->getSpaceBelowKind()==VSpace::LENGTH)
149                 spacebelow = VSpace(dialog_->getBelowLength());
150         else
151                 spacebelow = VSpace(dialog_->getSpaceBelowKind());
152
153         lyxerr[Debug::GUI] << "Setting above space \"" << LyXGlueLength(spaceabove.length().asString()).asString() << "\"" << endl;
154         lyxerr[Debug::GUI] << "Setting below space \"" << LyXGlueLength(spacebelow.length().asString()).asString() << "\"" << endl;
155
156         lv_->view()->text->SetParagraph(lv_->view(),
157                 dialog_->getLineAbove(), dialog_->getLineBelow(),
158                 dialog_->getPagebreakAbove(), dialog_->getPagebreakBelow(),
159                 spaceabove, spacebelow, dialog_->getAlign(),
160                 dialog_->getLabelWidth(), dialog_->getNoIndent());
161
162         // extra stuff
163
164         string width("");
165         string widthp("");
166
167         LyXLength extrawidth(dialog_->getExtraWidth());
168         if (extrawidth.unit()==LyXLength::UNIT_NONE) {
169                 widthp = dialog_->getExtraWidthPercent();
170         } else
171                 width = extrawidth.asString();
172
173         lyxerr[Debug::GUI] << "Setting extrawidth \"" << width << "\"" << endl;
174         lyxerr[Debug::GUI] << "Setting percent extrawidth \"" << widthp << "\"" << endl;
175
176         lv_->view()->text->SetParagraphExtraOpt(lv_->view(),
177                 dialog_->getExtraType(), width, widthp,
178                 dialog_->getExtraAlign(),
179                 dialog_->getHfillBetween(),
180                 dialog_->getStartNewMinipage());
181 }
182
183 void FormParagraph::show()
184 {
185         if (!dialog_)
186                 dialog_ = new ParaDialog(this, 0, _("LyX: Paragraph Options"), false);
187
188         if (!dialog_->isVisible())
189                 h_ = d_->hideBufferDependent.connect(slot(this, &FormParagraph::hide));
190
191         dialog_->raise();
192         dialog_->setActiveWindow();
193
194         update();
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 }