]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWrap.cpp
This is the last of the commits that hopes to enforce the distinction between "layout...
[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/gettext.h"
23 #include "support/lstrings.h"
24
25 #include <QLineEdit>
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", qt_("Wrap Float Settings"))
35 {
36         setupUi(this);
37
38         connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
39         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
40         connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
41         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
42
43         connect(widthED, SIGNAL(textChanged(QString)),
44                 this, SLOT(change_adaptor()));
45         connect(widthUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
46                 this, SLOT(change_adaptor()));
47         connect(valignCO, SIGNAL(highlighted(QString)),
48                 this, SLOT(change_adaptor()));
49         connect(overhangCB, SIGNAL(stateChanged(int)),
50                 this, SLOT(change_adaptor()));
51         connect(overhangED, SIGNAL(textChanged(QString)),
52                 this, SLOT(change_adaptor()));
53         connect(overhangUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
54                 this, SLOT(change_adaptor()));
55         connect(linesCB, SIGNAL(stateChanged(int)),
56                 this, SLOT(change_adaptor()));
57         connect(linesSB, SIGNAL(valueChanged(int)),
58                 this, SLOT(change_adaptor()));
59
60         widthED->setValidator(unsignedLengthValidator(widthED));
61         // FIXME:
62         // overhang can be negative, but the unsignedLengthValidator allows this
63         overhangED->setValidator(unsignedLengthValidator(overhangED));
64
65         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
66         bc().setRestore(restorePB);
67         bc().setOK(okPB);
68         bc().setApply(applyPB);
69         bc().setCancel(closePB);
70
71         bc().addReadOnly(widthED);
72         bc().addReadOnly(widthUnitLC);
73         bc().addReadOnly(valignCO);
74         bc().addReadOnly(overhangCB);
75         bc().addReadOnly(overhangED);
76         bc().addReadOnly(overhangUnitLC);
77         bc().addReadOnly(linesCB);
78         bc().addReadOnly(linesSB);
79
80         // initialize the length validator
81         bc().addCheckedLineEdit(widthED, widthLA);
82         bc().addCheckedLineEdit(overhangED, overhangCB);
83 }
84
85
86 void GuiWrap::change_adaptor()
87 {
88         changed();
89 }
90
91
92 void GuiWrap::applyView()
93 {
94         double const width_value = widthED->text().toDouble();
95         Length::UNIT widthUnit = widthUnitLC->currentLengthItem();
96         if (widthED->text().isEmpty())
97                 widthUnit = Length::UNIT_NONE;
98         double const overhang_value = overhangED->text().toDouble();
99         Length::UNIT overhangUnit = overhangUnitLC->currentLengthItem();
100         if (overhangED->text().isEmpty())
101                 overhangUnit = Length::UNIT_NONE;
102         
103         params_.width = Length(width_value, widthUnit);
104
105         if (overhangCB->checkState() == Qt::Checked)
106                 params_.overhang = Length(overhang_value, overhangUnit);
107         else
108                 // when value is "0" the option is not set in the LaTeX-output
109                 // in InsetWrap.cpp
110                 params_.overhang = Length("0in");
111
112         if (linesCB->checkState() == Qt::Checked)
113                 params_.lines = linesSB->value();
114         else
115                 // when value is "0" the option is not set in the LaTeX-output
116                 // in InsetWrap.cpp
117                 params_.lines = 0;
118
119         switch (valignCO->currentIndex()) {
120         case 0:
121                 params_.placement = "o";
122                 break;
123         case 1:
124                 params_.placement = "i";
125                 break;
126         case 2:
127                 params_.placement = "l";
128                 break;
129         case 3:
130                 params_.placement = "r";
131                 break;
132         }
133 }
134
135
136 void GuiWrap::updateContents()
137 {
138         // 0pt is a legal width now, it yields a
139         // wrapfloat just wide enough for the contents.
140         Length len_w = params_.width;
141         widthED->setText(QString::number(len_w.value()));
142         widthUnitLC->setCurrentItem(len_w.unit());
143
144         Length len_o(params_.overhang);
145         overhangED->setText(QString::number(len_o.value()));
146         overhangUnitLC->setCurrentItem(len_o.unit());
147         if (len_o.value() == 0)
148                 overhangCB->setCheckState(Qt::Unchecked);
149         else
150                 overhangCB->setCheckState(Qt::Checked);
151
152         linesSB->setValue(params_.lines);
153         if (params_.lines == 0)
154                 linesCB->setCheckState(Qt::Unchecked);
155         else
156                 linesCB->setCheckState(Qt::Checked);
157
158         int item = 0;
159         if (params_.placement == "i")
160                 item = 1;
161         else if (params_.placement == "l")
162                 item = 2;
163         else if (params_.placement == "r")
164                 item = 3;
165
166         valignCO->setCurrentIndex(item);
167 }
168
169
170 bool GuiWrap::initialiseParams(string const & data)
171 {
172         InsetWrapMailer::string2params(data, params_);
173         return true;
174 }
175
176
177 void GuiWrap::clearParams()
178 {
179         params_ = InsetWrapParams();
180 }
181
182
183 void GuiWrap::dispatchParams()
184 {
185         string const lfun = InsetWrapMailer::params2string(params_);
186         dispatch(FuncRequest(getLfun(), lfun));
187 }
188
189
190 Dialog * createGuiWrap(GuiView & lv) { return new GuiWrap(lv); }
191
192
193 } // namespace frontend
194 } // namespace lyx
195
196
197 #include "GuiWrap_moc.cpp"