]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QParagraph.C
Yet more (minor) compilation fixes.
[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 "Liason.h"
15 #include "gettext.h"
16 #include "buffer.h"
17 #include "QtLyXView.h"
18 #include "lyxtextclasslist.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(lv_->view()->getLyXText());
60         Paragraph * par = text->cursor.par();
61
62         int align = par->getAlign();
63
64         if (align==LYX_ALIGN_LAYOUT)
65                 align = textclasslist.Style(buf->params.textclass, par->getLayout()).align;
66
67         ParagraphParameters * params = &(par->params());
68
69         if (params->spaceTop().kind() == VSpace::LENGTH) {
70                 LyXGlueLength above = params->spaceTop().length();
71                 lyxerr[Debug::GUI] << "Reading above space : \"" << params->spaceTop().length().asString() << "\"" << endl;
72                 dialog_->setAboveLength(above.len().value(), above.plus().value(), above.minus().value(),
73                         above.len().unit(), above.plus().unit(), above.minus().unit());
74         } else
75                 dialog_->setAboveLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
76
77         if (params->spaceBottom().kind() == VSpace::LENGTH) {
78                 LyXGlueLength below = params->spaceBottom().length();
79                 lyxerr[Debug::GUI] << "Reading below space : \"" << params->spaceBottom().length().asString() << "\"" << endl;
80                 dialog_->setBelowLength(below.len().value(), below.plus().value(), below.minus().value(),
81                         below.len().unit(), below.plus().unit(), below.minus().unit());
82         } else
83                 dialog_->setBelowLength(0.0, 0.0, 0.0, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE, LyXLength::UNIT_NONE);
84
85         dialog_->setLabelWidth(text->cursor.par()->getLabelWidthString().c_str());
86         dialog_->setAlign(align);
87         dialog_->setChecks(params->lineTop(), params->lineBottom(),
88                 params->pagebreakTop(), params->pagebreakBottom(), params->noindent());
89         dialog_->setSpace(params->spaceTop().kind(), params->spaceBottom().kind(),
90                 params->spaceTop().keep(), params->spaceBottom().keep());
91
92         // now the extras page
93
94         LyXLength extrawidth;
95         float val = 0.0;
96         LyXLength::UNIT unit = LyXLength::CM;
97         params = &(par->params());
98         if (isValidLength(params->pextraWidth(), &extrawidth)) {
99                 lyxerr[Debug::GUI] << "Reading extra width \"" << extrawidth.asString() << "\"" << endl;
100                 val = extrawidth.value();
101                 unit = extrawidth.unit();
102         }
103
104         lyxerr[Debug::GUI] << "Reading widthp \"" << params->pextraWidthp() << "\"" << endl;
105
106         dialog_->setExtra(val, unit, params->pextraWidthp(),
107                 params->pextraAlignment(),
108                 params->pextraHfill(),
109                 params->pextraStartMinipage(),
110                 static_cast<Paragraph::PEXTRA_TYPE>(params->pextraType()));
111 }
112
113
114 void QParagraph::apply()
115 {
116         if (readonly)
117                 return;
118
119         VSpace spaceabove;
120         VSpace spacebelow;
121
122         if (dialog_->getSpaceAboveKind()==VSpace::LENGTH)
123                 spaceabove = VSpace(dialog_->getAboveLength());
124         else
125                 spaceabove = VSpace(dialog_->getSpaceAboveKind());
126
127         if (dialog_->getSpaceBelowKind()==VSpace::LENGTH)
128                 spacebelow = VSpace(dialog_->getBelowLength());
129         else
130                 spacebelow = VSpace(dialog_->getSpaceBelowKind());
131
132         spaceabove.setKeep(dialog_->getAboveKeep());
133         spacebelow.setKeep(dialog_->getBelowKeep());
134
135         lyxerr[Debug::GUI] << "Setting above space \"" << LyXGlueLength(spaceabove.length().asString()).asString() << "\"" << endl;
136         lyxerr[Debug::GUI] << "Setting below space \"" << LyXGlueLength(spacebelow.length().asString()).asString() << "\"" << endl;
137
138         LyXText * text(lv_->view()->getLyXText());
139         text->setParagraph(lv_->view(),
140                            dialog_->getLineAbove(), dialog_->getLineBelow(),
141                            dialog_->getPagebreakAbove(), dialog_->getPagebreakBelow(),
142                            spaceabove, spacebelow, Spacing(), dialog_->getAlign(),
143                            dialog_->getLabelWidth(), dialog_->getNoIndent());
144
145         // extra stuff
146
147         string width("");
148         string widthp("");
149
150         LyXLength extrawidth(dialog_->getExtraWidth());
151         if (extrawidth.unit()==LyXLength::UNIT_NONE) {
152                 widthp = dialog_->getExtraWidthPercent();
153         } else
154                 width = extrawidth.asString();
155
156         lyxerr[Debug::GUI] << "Setting extrawidth \"" << width << "\"" << endl;
157         lyxerr[Debug::GUI] << "Setting percent extrawidth \"" << widthp << "\"" << endl;
158
159         lv_->view()->update(text,
160                             BufferView::SELECT |
161                             BufferView::FITCUR |
162                             BufferView::CHANGE);
163
164         lv_->buffer()->markDirty();
165         setMinibuffer(lv_, _("Paragraph layout set"));
166 }
167
168
169 void QParagraph::show()
170 {
171         if (!dialog_)
172                 dialog_ = new QParagraphDialog(this, 0,
173                                                _("LyX: Paragraph Settings"),
174                                                false);
175
176         if (!dialog_->isVisible())
177                 h_ = d_->hideBufferDependent
178                         .connect(slot(this, &QParagraph::hide));
179
180         dialog_->raise();
181         dialog_->setActiveWindow();
182         update();
183
184         dialog_->show();
185 }
186
187
188 void QParagraph::close()
189 {
190         h_.disconnect();
191 }
192
193
194 void QParagraph::hide()
195 {
196         dialog_->hide();
197         close();
198 }