]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWrap.cpp
getting rid of superfluous lyx::support:: statements.
[lyx.git] / src / frontends / qt4 / GuiWrap.cpp
1 /**
2  * \file GuiWrap.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jürgen Spitzmüller
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "GuiWrap.h"
14
15 #include "LengthCombo.h"
16 #include "qt_helpers.h"
17 #include "Validator.h"
18 #include "FuncRequest.h"
19
20 #include "insets/InsetWrap.h"
21
22 #include "support/lstrings.h"
23
24 #include <QLineEdit>
25 #include <QCloseEvent>
26 #include <QPushButton>
27
28 using namespace std;
29
30 namespace lyx {
31 namespace frontend {
32
33 GuiWrap::GuiWrap(GuiView & lv)
34         : GuiDialog(lv, "wrap")
35 {
36         setupUi(this);
37         setViewTitle(_("Wrap Float Settings"));
38
39         connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
40         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
41         connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
42         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
43
44         connect(widthED, SIGNAL(textChanged(QString)),
45                 this, SLOT(change_adaptor()));
46         connect(widthUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
47                 this, SLOT(change_adaptor()));
48         connect(valignCO, SIGNAL(highlighted(QString)),
49                 this, SLOT(change_adaptor()));
50         connect(overhangCB, SIGNAL(stateChanged(int)),
51                 this, SLOT(change_adaptor()));
52         connect(overhangED, SIGNAL(textChanged(QString)),
53                 this, SLOT(change_adaptor()));
54         connect(overhangUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
55                 this, SLOT(change_adaptor()));
56         connect(linesCB, SIGNAL(stateChanged(int)),
57                 this, SLOT(change_adaptor()));
58         connect(linesSB, SIGNAL(valueChanged(int)),
59                 this, SLOT(change_adaptor()));
60
61         widthED->setValidator(unsignedLengthValidator(widthED));
62         // FIXME:
63         // overhang can be negative, but the unsignedLengthValidator allows this
64         overhangED->setValidator(unsignedLengthValidator(overhangED));
65
66         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
67         bc().setRestore(restorePB);
68         bc().setOK(okPB);
69         bc().setApply(applyPB);
70         bc().setCancel(closePB);
71
72         bc().addReadOnly(widthED);
73         bc().addReadOnly(widthUnitLC);
74         bc().addReadOnly(valignCO);
75         bc().addReadOnly(overhangCB);
76         bc().addReadOnly(overhangED);
77         bc().addReadOnly(overhangUnitLC);
78         bc().addReadOnly(linesCB);
79         bc().addReadOnly(linesSB);
80
81         // initialize the length validator
82         bc().addCheckedLineEdit(widthED, widthLA);
83         bc().addCheckedLineEdit(overhangED, overhangCB);
84 }
85
86
87 void GuiWrap::closeEvent(QCloseEvent * e)
88 {
89         slotClose();
90         e->accept();
91 }
92
93
94 void GuiWrap::change_adaptor()
95 {
96         changed();
97 }
98
99
100 void GuiWrap::applyView()
101 {
102         double const width_value = widthED->text().toDouble();
103         Length::UNIT widthUnit = widthUnitLC->currentLengthItem();
104         if (widthED->text().isEmpty())
105                 widthUnit = Length::UNIT_NONE;
106         double const overhang_value = overhangED->text().toDouble();
107         Length::UNIT overhangUnit = overhangUnitLC->currentLengthItem();
108         if (overhangED->text().isEmpty())
109                 overhangUnit = Length::UNIT_NONE;
110         
111         params_.width = Length(width_value, widthUnit);
112
113         if (overhangCB->checkState() == Qt::Checked)
114                 params_.overhang = Length(overhang_value, overhangUnit);
115         else
116                 // when value is "0" the option is not set in the LaTeX-output
117                 // in InsetWrap.cpp
118                 params_.overhang = Length("0in");
119
120         if (linesCB->checkState() == Qt::Checked)
121                 params_.lines = linesSB->value();
122         else
123                 // when value is "0" the option is not set in the LaTeX-output
124                 // in InsetWrap.cpp
125                 params_.lines = 0;
126
127         switch (valignCO->currentIndex()) {
128         case 0:
129                 params_.placement = "o";
130                 break;
131         case 1:
132                 params_.placement = "i";
133                 break;
134         case 2:
135                 params_.placement = "l";
136                 break;
137         case 3:
138                 params_.placement = "r";
139                 break;
140         }
141 }
142
143
144 void GuiWrap::updateContents()
145 {
146         // 0pt is a legal width now, it yields a
147         // wrapfloat just wide enough for the contents.
148         Length len_w = params_.width;
149         widthED->setText(QString::number(len_w.value()));
150         widthUnitLC->setCurrentItem(len_w.unit());
151
152         Length len_o(params_.overhang);
153         overhangED->setText(QString::number(len_o.value()));
154         overhangUnitLC->setCurrentItem(len_o.unit());
155         if (len_o.value() == 0)
156                 overhangCB->setCheckState(Qt::Unchecked);
157         else
158                 overhangCB->setCheckState(Qt::Checked);
159
160         linesSB->setValue(params_.lines);
161         if (params_.lines == 0)
162                 linesCB->setCheckState(Qt::Unchecked);
163         else
164                 linesCB->setCheckState(Qt::Checked);
165
166         int item = 0;
167         if (params_.placement == "i")
168                 item = 1;
169         else if (params_.placement == "l")
170                 item = 2;
171         else if (params_.placement == "r")
172                 item = 3;
173
174         valignCO->setCurrentIndex(item);
175 }
176
177
178 bool GuiWrap::initialiseParams(string const & data)
179 {
180         InsetWrapMailer::string2params(data, params_);
181         return true;
182 }
183
184
185 void GuiWrap::clearParams()
186 {
187         params_ = InsetWrapParams();
188 }
189
190
191 void GuiWrap::dispatchParams()
192 {
193         string const lfun = InsetWrapMailer::params2string(params_);
194         dispatch(FuncRequest(getLfun(), lfun));
195 }
196
197
198 Dialog * createGuiWrap(GuiView & lv) { return new GuiWrap(lv); }
199
200
201 } // namespace frontend
202 } // namespace lyx
203
204
205 #include "GuiWrap_moc.cpp"