]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FormParagraph.C
try this for distinguishing inner and outer tabs
[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         LyXParagraph *physpar = par->FirstPhysicalPar();
76 #else
77         LyXParagraph *physpar = par;
78 #endif
79
80         if (physpar->added_space_top.kind()==VSpace::LENGTH) {
81                 LyXGlueLength above = physpar->added_space_top.length();
82                 lyxerr[Debug::GUI] << "Reading above space : \"" << physpar->added_space_top.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 (physpar->added_space_bottom.kind()==VSpace::LENGTH) {
89                 LyXGlueLength below = physpar->added_space_bottom.length();
90                 lyxerr[Debug::GUI] << "Reading below space : \"" << physpar->added_space_bottom.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(physpar->line_top, physpar->line_bottom,
99                 physpar->pagebreak_top, physpar->pagebreak_bottom, physpar->noindent);
100         dialog_->setSpace(physpar->added_space_top.kind(), physpar->added_space_bottom.kind(),
101                 physpar->added_space_top.keep(), physpar->added_space_bottom.keep());
102
103         // now the extras page
104
105         LyXLength extrawidth;
106         float val = 0.0;
107         LyXLength::UNIT unit = LyXLength::CM;
108
109         if (isValidLength(par->pextra_width, &extrawidth)) {
110                 lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
111                 val = extrawidth.value();
112                 unit = extrawidth.unit();
113         }
114
115         lyxerr[Debug::GUI] << "Reading widthp \"" << par->pextra_widthp << "\"" << endl;
116
117         dialog_->setExtra(val, unit, par->pextra_widthp,
118                 par->pextra_alignment,
119                 par->pextra_hfill,
120                 par->pextra_start_minipage,
121                 static_cast<LyXParagraph::PEXTRA_TYPE>(par->pextra_type));
122 }
123
124 void FormParagraph::apply()
125 {
126         if (readonly)
127                 return;
128
129         VSpace spaceabove;
130         VSpace spacebelow;
131
132         if (dialog_->getSpaceAboveKind()==VSpace::LENGTH)
133                 spaceabove = VSpace(dialog_->getAboveLength());
134         else
135                 spaceabove = VSpace(dialog_->getSpaceAboveKind());
136
137         if (dialog_->getSpaceBelowKind()==VSpace::LENGTH)
138                 spacebelow = VSpace(dialog_->getBelowLength());
139         else
140                 spacebelow = VSpace(dialog_->getSpaceBelowKind());
141
142         spaceabove.setKeep(dialog_->getAboveKeep());
143         spacebelow.setKeep(dialog_->getBelowKeep());
144
145         lyxerr[Debug::GUI] << "Setting above space \"" << LyXGlueLength(spaceabove.length().asString()).asString() << "\"" << endl;
146         lyxerr[Debug::GUI] << "Setting below space \"" << LyXGlueLength(spacebelow.length().asString()).asString() << "\"" << endl;
147
148         lv_->view()->text->SetParagraph(lv_->view(),
149                 dialog_->getLineAbove(), dialog_->getLineBelow(),
150                 dialog_->getPagebreakAbove(), dialog_->getPagebreakBelow(),
151                 spaceabove, spacebelow, dialog_->getAlign(),
152                 dialog_->getLabelWidth(), dialog_->getNoIndent());
153
154         // extra stuff
155
156         string width("");
157         string widthp("");
158
159         LyXLength extrawidth(dialog_->getExtraWidth());
160         if (extrawidth.unit()==LyXLength::UNIT_NONE) {
161                 widthp = dialog_->getExtraWidthPercent();
162         } else
163                 width = extrawidth.asString();
164
165         lyxerr[Debug::GUI] << "Setting extrawidth \"" << width << "\"" << endl;
166         lyxerr[Debug::GUI] << "Setting percent extrawidth \"" << widthp << "\"" << endl;
167
168         lv_->view()->text->SetParagraphExtraOpt(lv_->view(),
169                 dialog_->getExtraType(), width, widthp,
170                 dialog_->getExtraAlign(),
171                 dialog_->getHfillBetween(),
172                 dialog_->getStartNewMinipage());
173
174         lv_->view()->update(BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
175         lv_->buffer()->markDirty();
176         setMinibuffer(lv_, _("Paragraph layout set"));
177 }
178
179 void FormParagraph::show()
180 {
181         if (!dialog_)
182                 dialog_ = new ParagraphDlgImpl(this, 0, _("LyX: Paragraph Options"), false);
183
184         if (!dialog_->isVisible())
185                 h_ = d_->hideBufferDependent.connect(slot(this, &FormParagraph::hide));
186
187          
188         dialog_->raise();
189         dialog_->setActiveWindow();
190         update();
191          
192         dialog_->show();
193 }
194
195 void FormParagraph::close()
196 {
197         h_.disconnect();
198 }
199
200 void FormParagraph::hide()
201 {
202         dialog_->hide();
203         close();
204 }