]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QParagraph.C
some more random changes, added Timeout (make clean if LyX crashes !!)
[lyx.git] / src / frontends / qt2 / QParagraph.C
1 /**
2  * \file QParagraph.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 "QParagraphDialog.h"
12
13 #include "QParagraph.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 #include "BufferView.h"
22 #include "ParagraphParameters.h"
23
24 using SigC::slot;
25 using Liason::setMinibuffer;
26 using std::endl;
27
28
29 QParagraph::QParagraph(LyXView *v, Dialogs *d)
30         : dialog_(0), lv_(v), d_(d), h_(0)
31 {
32         d->showParagraph.connect(slot(this, &QParagraph::show));
33 }
34
35
36 QParagraph::~QParagraph()
37 {
38         delete dialog_;
39 }
40
41
42 void QParagraph::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         Paragraph * 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         ParagraphParameters * params = &(par->params());
75
76         if (params->spaceTop().kind() == VSpace::LENGTH) {
77                 LyXGlueLength above = params->spaceTop().length();
78                 lyxerr[Debug::GUI] << "Reading above space : \"" << params->spaceTop().length().asString() << "\"" << endl;
79                 dialog_->setAboveLength(above.value(), above.plusValue(), above.minusValue(),
80                         above.unit(), above.plusUnit(), above.minusUnit());
81         } else
82                 dialog_->setAboveLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
83
84         if (params->spaceBottom().kind() == VSpace::LENGTH) {
85                 LyXGlueLength below = params->spaceBottom().length();
86                 lyxerr[Debug::GUI] << "Reading below space : \"" << params->spaceBottom().length().asString() << "\"" << endl;
87                 dialog_->setBelowLength(below.value(), below.plusValue(), below.minusValue(),
88                         below.unit(), below.plusUnit(), below.minusUnit());
89         } else
90                 dialog_->setBelowLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
91
92         dialog_->setLabelWidth(text->cursor.par()->getLabelWidthString().c_str());
93         dialog_->setAlign(align);
94         dialog_->setChecks(params->lineTop(), params->lineBottom(),
95                 params->pagebreakTop(), params->pagebreakBottom(), params->noindent());
96         dialog_->setSpace(params->spaceTop().kind(), params->spaceBottom().kind(),
97                 params->spaceTop().keep(), params->spaceBottom().keep());
98
99         // now the extras page
100
101         LyXLength extrawidth;
102         float val = 0.0;
103         LyXLength::UNIT unit = LyXLength::CM;
104         params = &(par->params());
105         if (isValidLength(params->pextraWidth(), &extrawidth)) {
106                 lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
107                 val = extrawidth.value();
108                 unit = extrawidth.unit();
109         }
110
111         lyxerr[Debug::GUI] << "Reading widthp \"" << params->pextraWidthp() << "\"" << endl;
112
113         dialog_->setExtra(val, unit, params->pextraWidthp(),
114                 params->pextraAlignment(),
115                 params->pextraHfill(),
116                 params->pextraStartMinipage(),
117                 static_cast<Paragraph::PEXTRA_TYPE>(params->pextraType()));
118 }
119
120
121 void QParagraph::apply()
122 {
123         if (readonly)
124                 return;
125
126         VSpace spaceabove;
127         VSpace spacebelow;
128
129         if (dialog_->getSpaceAboveKind()==VSpace::LENGTH)
130                 spaceabove = VSpace(dialog_->getAboveLength());
131         else
132                 spaceabove = VSpace(dialog_->getSpaceAboveKind());
133
134         if (dialog_->getSpaceBelowKind()==VSpace::LENGTH)
135                 spacebelow = VSpace(dialog_->getBelowLength());
136         else
137                 spacebelow = VSpace(dialog_->getSpaceBelowKind());
138
139         spaceabove.setKeep(dialog_->getAboveKeep());
140         spacebelow.setKeep(dialog_->getBelowKeep());
141
142         lyxerr[Debug::GUI] << "Setting above space \"" << LyXGlueLength(spaceabove.length().asString()).asString() << "\"" << endl;
143         lyxerr[Debug::GUI] << "Setting below space \"" << LyXGlueLength(spacebelow.length().asString()).asString() << "\"" << endl;
144
145         lv_->view()->text->setParagraph(lv_->view(),
146                 dialog_->getLineAbove(), dialog_->getLineBelow(),
147                 dialog_->getPagebreakAbove(), dialog_->getPagebreakBelow(),
148                 spaceabove, spacebelow, Spacing(), dialog_->getAlign(),
149                 dialog_->getLabelWidth(), dialog_->getNoIndent());
150
151         // extra stuff
152
153         string width("");
154         string widthp("");
155
156         LyXLength extrawidth(dialog_->getExtraWidth());
157         if (extrawidth.unit()==LyXLength::UNIT_NONE) {
158                 widthp = dialog_->getExtraWidthPercent();
159         } else
160                 width = extrawidth.asString();
161
162         lyxerr[Debug::GUI] << "Setting extrawidth \"" << width << "\"" << endl;
163         lyxerr[Debug::GUI] << "Setting percent extrawidth \"" << widthp << "\"" << endl;
164
165         lv_->view()->update(lv_->view()->text,
166                             BufferView::SELECT |
167                             BufferView::FITCUR |
168                             BufferView::CHANGE);
169
170         lv_->buffer()->markDirty();
171         setMinibuffer(lv_, _("Paragraph layout set"));
172 }
173
174
175 void QParagraph::show()
176 {
177         if (!dialog_)
178                 dialog_ = new QParagraphDialog(this, 0,
179                                                _("LyX: Paragraph Settings"),
180                                                false);
181
182         if (!dialog_->isVisible())
183                 h_ = d_->hideBufferDependent
184                         .connect(slot(this, &QParagraph::hide));
185
186         dialog_->raise();
187         dialog_->setActiveWindow();
188         update();
189
190         dialog_->show();
191 }
192
193
194 void QParagraph::close()
195 {
196         h_.disconnect();
197 }
198
199
200 void QParagraph::hide()
201 {
202         dialog_->hide();
203         close();
204 }