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