]> git.lyx.org Git - lyx.git/blob - src/frontends/kde/FormParagraph.C
try this for distinguishing inner and outer tabs
[lyx.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 #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         d->showLayoutParagraph.connect(slot(this, &FormParagraph::show));
32 }
33
34
35 FormParagraph::~FormParagraph()
36 {
37         delete dialog_;
38 }
39
40
41 void FormParagraph::update(bool switched)
42 {
43         if (switched) {
44                 hide();
45                 return;
46         }
47
48         if (!lv_->view()->available())
49                 return;
50
51         Buffer *buf = lv_->view()->buffer();
52         
53         if (readonly != buf->isReadonly()) {
54                 readonly = buf->isReadonly();
55                 dialog_->setReadOnly(readonly);
56         }
57
58         LyXText * text = 0;
59
60         if (lv_->view()->theLockingInset())
61                 text = lv_->view()->theLockingInset()->getLyXText(lv_->view());
62
63         if (!text)
64                 text = lv_->view()->text;
65
66         LyXParagraph const * par = text->cursor.par();
67
68         int align = par->GetAlign();
69         
70         if (align==LYX_ALIGN_LAYOUT)
71                 align = textclasslist.Style(buf->params.textclass, par->GetLayout()).align;
72
73 #ifndef NEW_INSETS
74         LyXParagraph const * physpar = par->FirstPhysicalPar();
75 #else
76         LyXParagraph const * physpar = par;
77 #endif
78
79         if (physpar->added_space_top.kind() == VSpace::LENGTH) {
80                 LyXGlueLength above = physpar->added_space_top.length();
81                 lyxerr[Debug::GUI] << "Reading above space : \"" 
82                         << physpar->added_space_top.length().asString() << "\"" << endl;
83  
84                 dialog_->setAboveLength(above.value(), above.plusValue(), above.minusValue(),
85                         above.unit(), above.plusUnit(), above.minusUnit());
86         } else
87                 dialog_->setAboveLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
88
89         if (physpar->added_space_bottom.kind() == VSpace::LENGTH) {
90                 LyXGlueLength below = physpar->added_space_bottom.length();
91                 lyxerr[Debug::GUI] << "Reading below space : \"" 
92                         << physpar->added_space_bottom.length().asString() << "\"" << endl;
93
94                 dialog_->setBelowLength(below.value(), below.plusValue(), below.minusValue(),
95                         below.unit(), below.plusUnit(), below.minusUnit());
96         } else
97                 dialog_->setBelowLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
98
99         dialog_->setLabelWidth(text->cursor.par()->GetLabelWidthString().c_str());
100         dialog_->setAlign(align);
101
102         dialog_->setChecks(physpar->line_top, physpar->line_bottom,
103                 physpar->pagebreak_top, physpar->pagebreak_bottom, physpar->noindent);
104  
105         dialog_->setSpace(physpar->added_space_top.kind(), physpar->added_space_bottom.kind(),
106                 physpar->added_space_top.keep(), physpar->added_space_bottom.keep());
107
108         // now the extras page
109
110         LyXLength extrawidth;
111         float val = 0.0;
112         LyXLength::UNIT unit = LyXLength::CM;
113
114         if (isValidLength(par->pextra_width, &extrawidth)) {
115                 lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
116                 val = extrawidth.value();
117                 unit = extrawidth.unit();
118         }
119
120         lyxerr[Debug::GUI] << "Reading widthp \"" << par->pextra_widthp << "\"" << endl;
121
122         dialog_->setExtra(val, unit, par->pextra_widthp,
123                 par->pextra_alignment,
124                 par->pextra_hfill,
125                 par->pextra_start_minipage,
126                 static_cast<LyXParagraph::PEXTRA_TYPE>(par->pextra_type));
127 }
128
129
130 void FormParagraph::apply()
131 {
132         if (readonly)
133                 return;
134
135         VSpace spaceabove;
136         VSpace spacebelow;
137
138         if (dialog_->getSpaceAboveKind() == VSpace::LENGTH)
139                 spaceabove = VSpace(dialog_->getAboveLength());
140         else
141                 spaceabove = VSpace(dialog_->getSpaceAboveKind());
142
143         if (dialog_->getSpaceBelowKind() == VSpace::LENGTH)
144                 spacebelow = VSpace(dialog_->getBelowLength());
145         else
146                 spacebelow = VSpace(dialog_->getSpaceBelowKind());
147
148         spaceabove.setKeep(dialog_->getAboveKeep());
149         spacebelow.setKeep(dialog_->getBelowKeep());
150
151         lyxerr[Debug::GUI] << "Setting above space \"" 
152                 << LyXGlueLength(spaceabove.length().asString()).asString() << "\"" << endl;
153         lyxerr[Debug::GUI] << "Setting below space \"" 
154                 << 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         lv_->view()->update(BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
183         lv_->buffer()->markDirty();
184         setMinibuffer(lv_, _("Paragraph layout set"));
185 }
186
187
188 void FormParagraph::show()
189 {
190         if (!dialog_)
191                 dialog_ = new ParaDialog(this, 0, _("LyX: Paragraph Options"), false);
192
193         if (!dialog_->isVisible())
194                 h_ = d_->hideBufferDependent.connect(slot(this, &FormParagraph::hide));
195
196         dialog_->raise();
197         dialog_->setActiveWindow();
198         update();
199          
200         dialog_->show();
201 }
202
203
204 void FormParagraph::close()
205 {
206         h_.disconnect();
207 }
208
209
210 void FormParagraph::hide()
211 {
212         dialog_->hide();
213         close();
214 }