]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QParagraph.C
fix typo that put too many include paths for most people
[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 "lyxtextclasslist.h"
20 #include "lyxtext.h"
21 #include "debug.h"
22 #include "BufferView.h"
23 #include "ParagraphParameters.h"
24
25 using SigC::slot;
26 using Liason::setMinibuffer;
27 using std::endl;
28
29
30 QParagraph::QParagraph(LyXView *v, Dialogs *d)
31         : dialog_(0), lv_(v), d_(d), h_(0)
32 {
33         d->showParagraph.connect(slot(this, &QParagraph::show));
34 }
35
36
37 QParagraph::~QParagraph()
38 {
39         delete dialog_;
40 }
41
42
43 void QParagraph::update(bool switched)
44 {
45         if (switched) {
46                 hide();
47                 return;
48         }
49
50         if (!lv_->view()->available())
51                 return;
52
53         Buffer * buf = lv_->view()->buffer();
54
55         if (readonly!=buf->isReadonly()) {
56                 readonly = buf->isReadonly();
57                 dialog_->setReadOnly(readonly);
58         }
59
60         LyXText * text(lv_->view()->getLyXText());
61         Paragraph * par = text->cursor.par();
62
63         int align = par->getAlign();
64
65         if (align==LYX_ALIGN_LAYOUT)
66                 align = textclasslist.Style(buf->params.textclass, par->getLayout()).align;
67
68         ParagraphParameters * params = &(par->params());
69
70         if (params->spaceTop().kind() == VSpace::LENGTH) {
71                 LyXGlueLength above = params->spaceTop().length();
72                 lyxerr[Debug::GUI] << "Reading above space : \"" << params->spaceTop().length().asString() << "\"" << endl;
73                 dialog_->setAboveLength(above.len().value(), above.plus().value(), above.minus().value(),
74                         above.len().unit(), above.plus().unit(), above.minus().unit());
75         } else
76                 dialog_->setAboveLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
77
78         if (params->spaceBottom().kind() == VSpace::LENGTH) {
79                 LyXGlueLength below = params->spaceBottom().length();
80                 lyxerr[Debug::GUI] << "Reading below space : \"" << params->spaceBottom().length().asString() << "\"" << endl;
81                 dialog_->setBelowLength(below.len().value(), below.plus().value(), below.minus().value(),
82                         below.len().unit(), below.plus().unit(), below.minus().unit());
83         } else
84                 dialog_->setBelowLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
85
86         dialog_->setLabelWidth(text->cursor.par()->getLabelWidthString().c_str());
87         dialog_->setAlign(align);
88         dialog_->setChecks(params->lineTop(), params->lineBottom(),
89                 params->pagebreakTop(), params->pagebreakBottom(), params->noindent());
90         dialog_->setSpace(params->spaceTop().kind(), params->spaceBottom().kind(),
91                 params->spaceTop().keep(), params->spaceBottom().keep());
92
93         // now the extras page
94
95         LyXLength extrawidth;
96         float val = 0.0;
97         LyXLength::UNIT unit = LyXLength::CM;
98         params = &(par->params());
99         if (isValidLength(params->pextraWidth(), &extrawidth)) {
100                 lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
101                 val = extrawidth.value();
102                 unit = extrawidth.unit();
103         }
104
105         lyxerr[Debug::GUI] << "Reading widthp \"" << params->pextraWidthp() << "\"" << endl;
106
107         dialog_->setExtra(val, unit, params->pextraWidthp(),
108                 params->pextraAlignment(),
109                 params->pextraHfill(),
110                 params->pextraStartMinipage(),
111                 static_cast<Paragraph::PEXTRA_TYPE>(params->pextraType()));
112 }
113
114
115 void QParagraph::apply()
116 {
117         if (readonly)
118                 return;
119
120         VSpace spaceabove;
121         VSpace spacebelow;
122
123         if (dialog_->getSpaceAboveKind()==VSpace::LENGTH)
124                 spaceabove = VSpace(dialog_->getAboveLength());
125         else
126                 spaceabove = VSpace(dialog_->getSpaceAboveKind());
127
128         if (dialog_->getSpaceBelowKind()==VSpace::LENGTH)
129                 spacebelow = VSpace(dialog_->getBelowLength());
130         else
131                 spacebelow = VSpace(dialog_->getSpaceBelowKind());
132
133         spaceabove.setKeep(dialog_->getAboveKeep());
134         spacebelow.setKeep(dialog_->getBelowKeep());
135
136         lyxerr[Debug::GUI] << "Setting above space \"" << LyXGlueLength(spaceabove.length().asString()).asString() << "\"" << endl;
137         lyxerr[Debug::GUI] << "Setting below space \"" << LyXGlueLength(spacebelow.length().asString()).asString() << "\"" << endl;
138
139         LyXText * text(lv_->view()->getLyXText());
140         text->setParagraph(lv_->view(),
141                            dialog_->getLineAbove(), dialog_->getLineBelow(),
142                            dialog_->getPagebreakAbove(), dialog_->getPagebreakBelow(),
143                            spaceabove, spacebelow, Spacing(), dialog_->getAlign(),
144                            dialog_->getLabelWidth(), dialog_->getNoIndent());
145
146         // extra stuff
147
148         string width("");
149         string widthp("");
150
151         LyXLength extrawidth(dialog_->getExtraWidth());
152         if (extrawidth.unit()==LyXLength::UNIT_NONE) {
153                 widthp = dialog_->getExtraWidthPercent();
154         } else
155                 width = extrawidth.asString();
156
157         lyxerr[Debug::GUI] << "Setting extrawidth \"" << width << "\"" << endl;
158         lyxerr[Debug::GUI] << "Setting percent extrawidth \"" << widthp << "\"" << endl;
159
160         lv_->view()->update(text,
161                             BufferView::SELECT |
162                             BufferView::FITCUR |
163                             BufferView::CHANGE);
164
165         lv_->buffer()->markDirty();
166         setMinibuffer(lv_, _("Paragraph layout set"));
167 }
168
169
170 void QParagraph::show()
171 {
172         if (!dialog_)
173                 dialog_ = new QParagraphDialog(this, 0,
174                                                _("LyX: Paragraph Settings"),
175                                                false);
176
177         if (!dialog_->isVisible())
178                 h_ = d_->hideBufferDependent
179                         .connect(slot(this, &QParagraph::hide));
180
181         dialog_->raise();
182         dialog_->setActiveWindow();
183         update();
184
185         dialog_->show();
186 }
187
188
189 void QParagraph::close()
190 {
191         h_.disconnect();
192 }
193
194
195 void QParagraph::hide()
196 {
197         dialog_->hide();
198         close();
199 }