3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Jürgen Spitzmüller
8 * Full author contact details are available in file CREDITS.
15 #include "ControlWrap.h"
16 #include "LengthCombo.h"
17 #include "qt_helpers.h"
19 #include "insets/InsetWrap.h"
21 #include "support/convert.h"
22 #include "support/lstrings.h"
25 #include <QCloseEvent>
26 #include <QPushButton>
34 GuiWrapDialog::GuiWrapDialog(LyXView & lv)
35 : GuiDialog(lv, "wrap")
38 setViewTitle(_("Wrap Float Settings"));
39 setController(new ControlWrap(*this));
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()));
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()));
53 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
54 bc().setRestore(restorePB);
56 bc().setApply(applyPB);
57 bc().setCancel(closePB);
59 bc().addReadOnly(widthED);
60 bc().addReadOnly(unitsLC);
61 bc().addReadOnly(valignCO);
65 ControlWrap & GuiWrapDialog::controller() const
67 return static_cast<ControlWrap &>(Dialog::controller());
71 void GuiWrapDialog::closeEvent(QCloseEvent * e)
78 void GuiWrapDialog::change_adaptor()
84 void GuiWrapDialog::applyView()
86 double const value = widthED->text().toDouble();
87 Length::UNIT unit = unitsLC->currentLengthItem();
88 if (widthED->text().isEmpty())
89 unit = Length::UNIT_NONE;
91 InsetWrapParams & params = controller().params();
93 params.width = Length(value, unit);
95 switch (valignCO->currentIndex()) {
97 params.placement = "o";
100 params.placement = "i";
103 params.placement = "l";
106 params.placement = "r";
112 static string const numtostr(double val)
114 string a = convert<string>(val);
116 //0pt is a legal width now, it yields a
117 //wrapfloat just wide enough for the contents.
121 void GuiWrapDialog::update_contents()
123 InsetWrapParams & params = controller().params();
125 Length len(params.width);
126 widthED->setText(toqstr(numtostr(len.value())));
127 unitsLC->setCurrentItem(len.unit());
130 if (params.placement == "i")
132 else if (params.placement == "l")
134 else if (params.placement == "r")
137 valignCO->setCurrentIndex(item);
140 } // namespace frontend
144 #include "GuiWrap_moc.cpp"