]> git.lyx.org Git - lyx.git/blob - src/frontends/kde/FormParagraph.C
Move LaTeX and VC logs to GUI-I on xforms
[lyx.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         if (readonly!=buf->isReadonly()) {
62                 readonly = buf->isReadonly();
63                 dialog_->setReadOnly(readonly);
64         }
65
66         LyXText *text = 0;
67
68         if (lv_->view()->theLockingInset())
69                 text = lv_->view()->theLockingInset()->getLyXText(lv_->view());
70
71         if (!text)
72                 text = lv_->view()->text;
73
74         LyXParagraph *par = text->cursor.par();
75
76         int align = par->GetAlign();
77         
78         if (align==LYX_ALIGN_LAYOUT)
79                 align = textclasslist.Style(buf->params.textclass, par->GetLayout()).align;
80
81 #ifndef NEW_INSETS
82         LyXParagraph *physpar = par->FirstPhysicalPar();
83 #else
84         LyXParagraph *physpar = par;
85 #endif
86
87         if (physpar->added_space_top.kind()==VSpace::LENGTH) {
88                 LyXGlueLength above = physpar->added_space_top.length();
89                 lyxerr[Debug::GUI] << "Reading above space : \"" << physpar->added_space_top.length().asString() << "\"" << endl;
90                 dialog_->setAboveLength(above.value(), above.plusValue(), above.minusValue(),
91                         above.unit(), above.plusUnit(), above.minusUnit());
92         } else
93                 dialog_->setAboveLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
94
95         if (physpar->added_space_bottom.kind()==VSpace::LENGTH) {
96                 LyXGlueLength below = physpar->added_space_bottom.length();
97                 lyxerr[Debug::GUI] << "Reading below space : \"" << physpar->added_space_bottom.length().asString() << "\"" << endl;
98                 dialog_->setBelowLength(below.value(), below.plusValue(), below.minusValue(),
99                         below.unit(), below.plusUnit(), below.minusUnit());
100         } else
101                 dialog_->setBelowLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
102
103         dialog_->setLabelWidth(text->cursor.par()->GetLabelWidthString().c_str());
104         dialog_->setAlign(align);
105         dialog_->setChecks(physpar->line_top, physpar->line_bottom,
106                 physpar->pagebreak_top, physpar->pagebreak_bottom, physpar->noindent);
107         dialog_->setSpace(physpar->added_space_top.kind(), physpar->added_space_bottom.kind(),
108                 physpar->added_space_top.keep(), physpar->added_space_bottom.keep());
109
110         // now the extras page
111
112         LyXLength extrawidth;
113         float val = 0.0;
114         LyXLength::UNIT unit = LyXLength::CM;
115
116         if (isValidLength(par->pextra_width, &extrawidth)) {
117                 lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
118                 val = extrawidth.value();
119                 unit = extrawidth.unit();
120         }
121
122         lyxerr[Debug::GUI] << "Reading widthp \"" << par->pextra_widthp << "\"" << endl;
123
124         dialog_->setExtra(val, unit, par->pextra_widthp,
125                 par->pextra_alignment,
126                 par->pextra_hfill,
127                 par->pextra_start_minipage,
128                 static_cast<LyXParagraph::PEXTRA_TYPE>(par->pextra_type));
129 }
130
131 void FormParagraph::apply()
132 {
133         if (readonly)
134                 return;
135
136         VSpace spaceabove;
137         VSpace spacebelow;
138
139         if (dialog_->getSpaceAboveKind()==VSpace::LENGTH)
140                 spaceabove = VSpace(dialog_->getAboveLength());
141         else
142                 spaceabove = VSpace(dialog_->getSpaceAboveKind());
143
144         if (dialog_->getSpaceBelowKind()==VSpace::LENGTH)
145                 spacebelow = VSpace(dialog_->getBelowLength());
146         else
147                 spacebelow = VSpace(dialog_->getSpaceBelowKind());
148
149         spaceabove.setKeep(dialog_->getAboveKeep());
150         spacebelow.setKeep(dialog_->getBelowKeep());
151
152         lyxerr[Debug::GUI] << "Setting above space \"" << LyXGlueLength(spaceabove.length().asString()).asString() << "\"" << endl;
153         lyxerr[Debug::GUI] << "Setting below space \"" << LyXGlueLength(spacebelow.length().asString()).asString() << "\"" << endl;
154
155         lv_->view()->text->SetParagraph(lv_->view(),
156                 dialog_->getLineAbove(), dialog_->getLineBelow(),
157                 dialog_->getPagebreakAbove(), dialog_->getPagebreakBelow(),
158                 spaceabove, spacebelow, dialog_->getAlign(),
159                 dialog_->getLabelWidth(), dialog_->getNoIndent());
160
161         // extra stuff
162
163         string width("");
164         string widthp("");
165
166         LyXLength extrawidth(dialog_->getExtraWidth());
167         if (extrawidth.unit()==LyXLength::UNIT_NONE) {
168                 widthp = dialog_->getExtraWidthPercent();
169         } else
170                 width = extrawidth.asString();
171
172         lyxerr[Debug::GUI] << "Setting extrawidth \"" << width << "\"" << endl;
173         lyxerr[Debug::GUI] << "Setting percent extrawidth \"" << widthp << "\"" << endl;
174
175         lv_->view()->text->SetParagraphExtraOpt(lv_->view(),
176                 dialog_->getExtraType(), width, widthp,
177                 dialog_->getExtraAlign(),
178                 dialog_->getHfillBetween(),
179                 dialog_->getStartNewMinipage());
180
181         lv_->view()->update(BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
182         lv_->buffer()->markDirty();
183         setMinibuffer(lv_, _("Paragraph layout set"));
184 }
185
186 void FormParagraph::show()
187 {
188         if (!dialog_)
189                 dialog_ = new ParaDialog(this, 0, _("LyX: Paragraph Options"), false);
190
191         if (!dialog_->isVisible())
192                 h_ = d_->hideBufferDependent.connect(slot(this, &FormParagraph::hide));
193
194          
195         dialog_->raise();
196         dialog_->setActiveWindow();
197         update();
198          
199         dialog_->show();
200 }
201
202 void FormParagraph::close()
203 {
204         h_.disconnect();
205 }
206
207 void FormParagraph::hide()
208 {
209         dialog_->hide();
210         close();
211 }