]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWrap.cpp
ddbe458b1c48e420966401237618dad6c5d173ca
[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(overhangED, SIGNAL(textChanged(const QString &)),
53                 this, SLOT(change_adaptor()));
54         connect(overhangUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
55                 this, SLOT(change_adaptor()));
56         connect(linesSB, SIGNAL(valueChanged(int)),
57                 this, SLOT(change_adaptor()));
58
59         widthED->setValidator(unsignedLengthValidator(widthED));
60         // FIXME:
61         // overhang can be negative, but the unsignedLengthValidator allows this
62         overhangED->setValidator(unsignedLengthValidator(overhangED));
63
64         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
65         bc().setRestore(restorePB);
66         bc().setOK(okPB);
67         bc().setApply(applyPB);
68         bc().setCancel(closePB);
69
70         bc().addReadOnly(widthED);
71         bc().addReadOnly(widthUnitLC);
72         bc().addReadOnly(valignCO);
73         bc().addReadOnly(overhangED);
74         bc().addReadOnly(overhangUnitLC);
75         bc().addReadOnly(linesSB);
76
77         // initialize the length validator
78         bc().addCheckedLineEdit(widthED, widthLA);
79         bc().addCheckedLineEdit(overhangED, overhangLA);
80 }
81
82
83 ControlWrap & GuiWrapDialog::controller()
84 {
85         return static_cast<ControlWrap &>(GuiDialog::controller());
86 }
87
88
89 void GuiWrapDialog::closeEvent(QCloseEvent * e)
90 {
91         slotClose();
92         e->accept();
93 }
94
95
96 void GuiWrapDialog::change_adaptor()
97 {
98         changed();
99 }
100
101
102 void GuiWrapDialog::applyView()
103 {
104         double const width_value = widthED->text().toDouble();
105         Length::UNIT widthUnit = widthUnitLC->currentLengthItem();
106         if (widthED->text().isEmpty())
107                 widthUnit = Length::UNIT_NONE;
108         double const overhang_value = overhangED->text().toDouble();
109         Length::UNIT overhangUnit = overhangUnitLC->currentLengthItem();
110         if (overhangED->text().isEmpty())
111                 overhangUnit = Length::UNIT_NONE;
112         
113         InsetWrapParams & params = controller().params();
114
115         params.width = Length(width_value, widthUnit);
116         params.overhang = Length(overhang_value, overhangUnit);
117         params.lines = linesSB->value();
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 GuiWrapDialog::updateContents()
137 {
138         InsetWrapParams & params = controller().params();
139
140         //0pt is a legal width now, it yields a
141         //wrapfloat just wide enough for the contents.
142         Length len_w(params.width);
143         widthED->setText(QString::number(len_w.value()));
144         widthUnitLC->setCurrentItem(len_w.unit());
145         Length len_o(params.overhang);
146         overhangED->setText(QString::number(len_o.value()));
147         overhangUnitLC->setCurrentItem(len_o.unit());
148         linesSB->setValue(params.lines);
149
150         int item = 0;
151         if (params.placement == "i")
152                 item = 1;
153         else if (params.placement == "l")
154                 item = 2;
155         else if (params.placement == "r")
156                 item = 3;
157
158         valignCO->setCurrentIndex(item);
159 }
160
161 } // namespace frontend
162 } // namespace lyx
163
164
165 #include "GuiWrap_moc.cpp"