]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWrap.cpp
21122c3b3489deb7f89c5cf970b3510e05ea5c60
[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
19 #include "insets/InsetWrap.h"
20
21 #include "support/convert.h"
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(unitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
49                 this, SLOT(change_adaptor()));
50         connect(valignCO, SIGNAL(highlighted(const QString &)),
51                 this, SLOT(change_adaptor()));
52
53         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
54         bc().setRestore(restorePB);
55         bc().setOK(okPB);
56         bc().setApply(applyPB);
57         bc().setCancel(closePB);
58
59         bc().addReadOnly(widthED);
60         bc().addReadOnly(unitsLC);
61         bc().addReadOnly(valignCO);
62 }
63
64
65 ControlWrap & GuiWrapDialog::controller()
66 {
67         return static_cast<ControlWrap &>(GuiDialog::controller());
68 }
69
70
71 void GuiWrapDialog::closeEvent(QCloseEvent * e)
72 {
73         slotClose();
74         e->accept();
75 }
76
77
78 void GuiWrapDialog::change_adaptor()
79 {
80         changed();
81 }
82
83
84 void GuiWrapDialog::applyView()
85 {
86         double const value = widthED->text().toDouble();
87         Length::UNIT unit = unitsLC->currentLengthItem();
88         if (widthED->text().isEmpty())
89                 unit = Length::UNIT_NONE;
90
91         InsetWrapParams & params = controller().params();
92
93         params.width = Length(value, unit);
94
95         switch (valignCO->currentIndex()) {
96         case 0:
97                 params.placement = "o";
98                 break;
99         case 1:
100                 params.placement = "i";
101                 break;
102         case 2:
103                 params.placement = "l";
104                 break;
105         case 3:
106                 params.placement = "r";
107                 break;
108         }
109 }
110
111
112 static string const numtostr(double val)
113 {
114         string a = convert<string>(val);
115         return a;
116         //0pt is a legal width now, it yields a
117         //wrapfloat just wide enough for the contents.
118 }
119
120
121 void GuiWrapDialog::updateContents()
122 {
123         InsetWrapParams & params = controller().params();
124
125         Length len(params.width);
126         widthED->setText(toqstr(numtostr(len.value())));
127         unitsLC->setCurrentItem(len.unit());
128
129         int item = 0;
130         if (params.placement == "i")
131                 item = 1;
132         else if (params.placement == "l")
133                 item = 2;
134         else if (params.placement == "r")
135                 item = 3;
136
137         valignCO->setCurrentIndex(item);
138 }
139
140 } // namespace frontend
141 } // namespace lyx
142
143
144 #include "GuiWrap_moc.cpp"