]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWrap.cpp
943c7c5aac8139941d000743b1c1d6f44d83044c
[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(_("Text Wrap 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() const
66 {
67         return static_cast<ControlWrap &>(Dialog::controller());
68 }
69
70
71 void GuiWrapDialog::closeEvent(QCloseEvent * e)
72 {
73         slotWMHide();
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.erase();
98                 break;
99         case 1:
100                 params.placement = "l";
101                 break;
102         case 2:
103                 params.placement = "r";
104                 break;
105         case 3:
106                 params.placement = "p";
107                 break;
108         }
109 }
110
111
112 static string const numtostr(double val)
113 {
114         string a = convert<string>(val);
115         // FIXME: Will this test ever trigger? (Lgb)
116         if (a == "0")
117                 a.erase();
118         return a;
119 }
120
121
122 void GuiWrapDialog::update_contents()
123 {
124         InsetWrapParams & params = controller().params();
125
126         Length len(params.width);
127         widthED->setText(toqstr(numtostr(len.value())));
128         unitsLC->setCurrentItem(len.unit());
129
130         int item = 0;
131         if (params.placement == "l")
132                 item = 1;
133         else if (params.placement == "r")
134                 item = 2;
135         else if (params.placement == "p")
136                 item = 3;
137
138         valignCO->setCurrentIndex(item);
139 }
140
141 } // namespace frontend
142 } // namespace lyx
143
144
145 #include "GuiWrap_moc.cpp"