]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWrap.cpp
rename a few view functions from foo() to fooView()
[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
18 #include "insets/InsetWrap.h"
19
20 #include "support/convert.h"
21 #include "support/lstrings.h"
22
23 #include <QLineEdit>
24 #include <QCloseEvent>
25 #include <QPushButton>
26
27
28 using std::string;
29
30 namespace lyx {
31 namespace frontend {
32
33 /////////////////////////////////////////////////////////////////////
34 //
35 // GuiWrapDialog
36 //
37 /////////////////////////////////////////////////////////////////////
38
39
40 GuiWrapDialog::GuiWrapDialog(GuiWrap * form)
41         : form_(form)
42 {
43         setupUi(this);
44
45         connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore()));
46         connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
47         connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
48         connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
49
50         connect(widthED, SIGNAL(textChanged(const QString &)),
51                 this, SLOT(change_adaptor()));
52         connect(unitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
53                 this, SLOT(change_adaptor()));
54         connect(valignCO, SIGNAL(highlighted(const QString &)),
55                 this, SLOT(change_adaptor()));
56 }
57
58
59 void GuiWrapDialog::closeEvent(QCloseEvent * e)
60 {
61         form_->slotWMHide();
62         e->accept();
63 }
64
65
66 void GuiWrapDialog::change_adaptor()
67 {
68         form_->changed();
69 }
70
71 /////////////////////////////////////////////////////////////////////
72 //
73 // GuiWrap
74 //
75 /////////////////////////////////////////////////////////////////////
76
77 GuiWrap::GuiWrap(GuiDialog & parent)
78         : GuiView<GuiWrapDialog>(parent, _("Text Wrap Settings"))
79 {
80 }
81
82
83 void GuiWrap::build_dialog()
84 {
85         dialog_.reset(new GuiWrapDialog(this));
86
87         bc().setRestore(dialog_->restorePB);
88         bc().setOK(dialog_->okPB);
89         bc().setApply(dialog_->applyPB);
90         bc().setCancel(dialog_->closePB);
91
92         bc().addReadOnly(dialog_->widthED);
93         bc().addReadOnly(dialog_->unitsLC);
94         bc().addReadOnly(dialog_->valignCO);
95 }
96
97
98 void GuiWrap::applyView()
99 {
100         double const value = convert<double>(fromqstr(dialog_->widthED->text()));
101         Length::UNIT unit = dialog_->unitsLC->currentLengthItem();
102         if (dialog_->widthED->text().isEmpty())
103                 unit = Length::UNIT_NONE;
104
105         InsetWrapParams & params = controller().params();
106
107         params.width = Length(value, unit);
108
109         switch (dialog_->valignCO->currentIndex()) {
110         case 0:
111                 params.placement.erase();
112                 break;
113         case 1:
114                 params.placement = "l";
115                 break;
116         case 2:
117                 params.placement = "r";
118                 break;
119         case 3:
120                 params.placement = "p";
121                 break;
122         }
123 }
124
125
126 static string const numtostr(double val)
127 {
128         string a = convert<string>(val);
129         // FIXME: Will this test ever trigger? (Lgb)
130         if (a == "0")
131                 a.erase();
132         return a;
133 }
134
135
136 void GuiWrap::update_contents()
137 {
138         InsetWrapParams & params = controller().params();
139
140         Length len(params.width);
141         dialog_->widthED->setText(toqstr(numtostr(len.value())));
142         dialog_->unitsLC->setCurrentItem(len.unit());
143
144         int item = 0;
145         if (params.placement == "l")
146                 item = 1;
147         else if (params.placement == "r")
148                 item = 2;
149         else if (params.placement == "p")
150                 item = 3;
151
152         dialog_->valignCO->setCurrentIndex(item);
153 }
154
155 } // namespace frontend
156 } // namespace lyx
157
158
159 #include "GuiWrap_moc.cpp"