]> git.lyx.org Git - lyx.git/blob - src/frontends/kde/FormParagraph.C
More preference work from Angus
[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 FormParagraph::FormParagraph(LyXView *v, Dialogs *d)
34         : dialog_(0), lv_(v), d_(d), h_(0)
35 {
36         // let the dialog be shown
37         // This is a permanent connection so we won't bother
38         // storing a copy because we won't be disconnecting.
39         d->showLayoutParagraph.connect(slot(this, &FormParagraph::show));
40 }
41
42 FormParagraph::~FormParagraph()
43 {
44         delete dialog_;
45 }
46
47 void FormParagraph::update(bool switched)
48 {
49         if (switched) {
50                 hide();
51                 return;
52         }
53
54         if (!lv_->view()->available())
55                 return;
56
57         Buffer *buf = lv_->view()->buffer();
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                 // FIXME: ??? this breaks badly if we ever add non glue length vspace to a paragraph
82                 // I need some help here ... it is silly anyway !
83                 LyXGlueLength above(physpar->added_space_top.length().asString());
84                 lyxerr[Debug::GUI] << "Reading above space : \"" << physpar->added_space_top.length().asString() << "\"" << endl;
85                 dialog_->setAboveLength(above.value(), above.plusValue(), above.minusValue(),
86                         above.unit(), above.plusUnit(), above.minusUnit());
87         } else
88                 dialog_->setAboveLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
89
90         if (physpar->added_space_bottom.kind()==VSpace::LENGTH) {
91                 // FIXME: ??? this breaks badly if we ever add non glue length vspace to a paragraph
92                 // I need some help here ... it is silly anyway !
93                 LyXGlueLength below(physpar->added_space_bottom.length().asString());
94                 lyxerr[Debug::GUI] << "Reading below space : \"" << physpar->added_space_bottom.length().asString() << "\"" << endl;
95                 dialog_->setBelowLength(below.value(), below.plusValue(), below.minusValue(),
96                         below.unit(), below.plusUnit(), below.minusUnit());
97         } else
98                 dialog_->setBelowLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
99
100         if (readonly!=buf->isReadonly()) {
101                 readonly = buf->isReadonly();
102                 dialog_->setReadOnly(readonly);
103         }
104
105         dialog_->setLabelWidth(text->cursor.par()->GetLabelWidthString().c_str());
106         dialog_->setAlign(align);
107         dialog_->setChecks(physpar->line_top, physpar->line_bottom,
108                 physpar->pagebreak_top, physpar->pagebreak_bottom, physpar->noindent);
109         dialog_->setSpace(physpar->added_space_top.kind(), physpar->added_space_bottom.kind(),
110                 physpar->added_space_top.keep(), physpar->added_space_bottom.keep());
111
112         // now the extras page
113
114         LyXLength extrawidth;
115         float val = 0.0;
116         LyXLength::UNIT unit = LyXLength::CM;
117
118         if (isValidLength(par->pextra_width, &extrawidth)) {
119                 lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
120                 val = extrawidth.value();
121                 unit = extrawidth.unit();
122         }
123
124         lyxerr[Debug::GUI] << "Reading widthp \"" << par->pextra_widthp << "\"" << endl;
125
126         dialog_->setExtra(val, unit, par->pextra_widthp,
127                 par->pextra_alignment,
128                 par->pextra_hfill,
129                 par->pextra_start_minipage,
130                 static_cast<LyXParagraph::PEXTRA_TYPE>(par->pextra_type));
131 }
132
133 void FormParagraph::apply()
134 {
135         if (readonly)
136                 return;
137
138         VSpace spaceabove;
139         VSpace spacebelow;
140
141         if (dialog_->getSpaceAboveKind()==VSpace::LENGTH)
142                 spaceabove = VSpace(dialog_->getAboveLength());
143         else
144                 spaceabove = VSpace(dialog_->getSpaceAboveKind());
145
146         if (dialog_->getSpaceBelowKind()==VSpace::LENGTH)
147                 spacebelow = VSpace(dialog_->getBelowLength());
148         else
149                 spacebelow = VSpace(dialog_->getSpaceBelowKind());
150
151         lyxerr[Debug::GUI] << "Setting above space \"" << LyXGlueLength(spaceabove.length().asString()).asString() << "\"" << endl;
152         lyxerr[Debug::GUI] << "Setting below space \"" << LyXGlueLength(spacebelow.length().asString()).asString() << "\"" << endl;
153
154         lv_->view()->text->SetParagraph(lv_->view(),
155                 dialog_->getLineAbove(), dialog_->getLineBelow(),
156                 dialog_->getPagebreakAbove(), dialog_->getPagebreakBelow(),
157                 spaceabove, spacebelow, dialog_->getAlign(),
158                 dialog_->getLabelWidth(), dialog_->getNoIndent());
159
160         // extra stuff
161
162         string width("");
163         string widthp("");
164
165         LyXLength extrawidth(dialog_->getExtraWidth());
166         if (extrawidth.unit()==LyXLength::UNIT_NONE) {
167                 widthp = dialog_->getExtraWidthPercent();
168         } else
169                 width = extrawidth.asString();
170
171         lyxerr[Debug::GUI] << "Setting extrawidth \"" << width << "\"" << endl;
172         lyxerr[Debug::GUI] << "Setting percent extrawidth \"" << widthp << "\"" << endl;
173
174         lv_->view()->text->SetParagraphExtraOpt(lv_->view(),
175                 dialog_->getExtraType(), width, widthp,
176                 dialog_->getExtraAlign(),
177                 dialog_->getHfillBetween(),
178                 dialog_->getStartNewMinipage());
179 }
180
181 void FormParagraph::show()
182 {
183         if (!dialog_)
184                 dialog_ = new ParaDialog(this, 0, _("LyX: Paragraph Options"), false);
185
186         if (!dialog_->isVisible())
187                 h_ = d_->hideBufferDependent.connect(slot(this, &FormParagraph::hide));
188
189         dialog_->raise();
190         dialog_->setActiveWindow();
191
192         update();
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 }