]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWrap.cpp
some remnaming
[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/lstrings.h"
22
23 #include <QLineEdit>
24 #include <QCloseEvent>
25 #include <QPushButton>
26
27 using std::string;
28
29
30 namespace lyx {
31 namespace frontend {
32
33 GuiWrapDialog::GuiWrapDialog(LyXView & lv)
34         : GuiDialog(lv, "wrap")
35 {
36         setupUi(this);
37         setViewTitle(_("Wrap Float Settings"));
38         setController(new ControlWrap(*this));
39
40         connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
41         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
42         connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
43         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
44
45         connect(widthED, SIGNAL(textChanged(const QString &)),
46                 this, SLOT(change_adaptor()));
47         connect(unitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
48                 this, SLOT(change_adaptor()));
49         connect(valignCO, SIGNAL(highlighted(const QString &)),
50                 this, SLOT(change_adaptor()));
51
52         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
53         bc().setRestore(restorePB);
54         bc().setOK(okPB);
55         bc().setApply(applyPB);
56         bc().setCancel(closePB);
57
58         bc().addReadOnly(widthED);
59         bc().addReadOnly(unitsLC);
60         bc().addReadOnly(valignCO);
61 }
62
63
64 ControlWrap & GuiWrapDialog::controller()
65 {
66         return static_cast<ControlWrap &>(GuiDialog::controller());
67 }
68
69
70 void GuiWrapDialog::closeEvent(QCloseEvent * e)
71 {
72         slotClose();
73         e->accept();
74 }
75
76
77 void GuiWrapDialog::change_adaptor()
78 {
79         changed();
80 }
81
82
83 void GuiWrapDialog::applyView()
84 {
85         double const value = widthED->text().toDouble();
86         Length::UNIT unit = unitsLC->currentLengthItem();
87         if (widthED->text().isEmpty())
88                 unit = Length::UNIT_NONE;
89
90         InsetWrapParams & params = controller().params();
91
92         params.width = Length(value, unit);
93
94         switch (valignCO->currentIndex()) {
95         case 0:
96                 params.placement = "o";
97                 break;
98         case 1:
99                 params.placement = "i";
100                 break;
101         case 2:
102                 params.placement = "l";
103                 break;
104         case 3:
105                 params.placement = "r";
106                 break;
107         }
108 }
109
110
111 void GuiWrapDialog::updateContents()
112 {
113         InsetWrapParams & params = controller().params();
114
115         Length len(params.width);
116         //0pt is a legal width now, it yields a
117         //wrapfloat just wide enough for the contents.
118         widthED->setText(QString::number(len.value()));
119         unitsLC->setCurrentItem(len.unit());
120
121         int item = 0;
122         if (params.placement == "i")
123                 item = 1;
124         else if (params.placement == "l")
125                 item = 2;
126         else if (params.placement == "r")
127                 item = 3;
128
129         valignCO->setCurrentIndex(item);
130 }
131
132 } // namespace frontend
133 } // namespace lyx
134
135
136 #include "GuiWrap_moc.cpp"