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.
16 #include "LengthCombo.h"
17 #include "qt_helpers.h"
19 #include "controllers/ControlWrap.h"
21 #include "insets/InsetWrap.h"
23 #include "support/convert.h"
24 #include "support/lstrings.h"
27 #include <QCloseEvent>
28 #include <QPushButton>
36 /////////////////////////////////////////////////////////////////////
40 /////////////////////////////////////////////////////////////////////
43 GuiWrapDialog::GuiWrapDialog(GuiWrap * form)
48 connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore()));
49 connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
50 connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
51 connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
53 connect(widthED, SIGNAL(textChanged(const QString &)),
54 this, SLOT(change_adaptor()));
55 connect(unitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
56 this, SLOT(change_adaptor()));
57 connect(valignCO, SIGNAL(highlighted(const QString &)),
58 this, SLOT(change_adaptor()));
62 void GuiWrapDialog::closeEvent(QCloseEvent * e)
69 void GuiWrapDialog::change_adaptor()
74 /////////////////////////////////////////////////////////////////////
78 /////////////////////////////////////////////////////////////////////
80 typedef QController<ControlWrap, GuiView<GuiWrapDialog> > wrap_base_class;
82 GuiWrap::GuiWrap(Dialog & parent)
83 : wrap_base_class(parent, _("Text Wrap Settings"))
88 void GuiWrap::build_dialog()
90 dialog_.reset(new GuiWrapDialog(this));
92 bcview().setRestore(dialog_->restorePB);
93 bcview().setOK(dialog_->okPB);
94 bcview().setApply(dialog_->applyPB);
95 bcview().setCancel(dialog_->closePB);
97 bcview().addReadOnly(dialog_->widthED);
98 bcview().addReadOnly(dialog_->unitsLC);
99 bcview().addReadOnly(dialog_->valignCO);
103 void GuiWrap::apply()
105 double const value = convert<double>(fromqstr(dialog_->widthED->text()));
106 Length::UNIT unit = dialog_->unitsLC->currentLengthItem();
107 if (dialog_->widthED->text().isEmpty())
108 unit = Length::UNIT_NONE;
110 InsetWrapParams & params = controller().params();
112 params.width = Length(value, unit);
114 switch (dialog_->valignCO->currentIndex()) {
116 params.placement.erase();
119 params.placement = "l";
122 params.placement = "r";
125 params.placement = "p";
131 static string const numtostr(double val)
133 string a = convert<string>(val);
134 // FIXME: Will this test ever trigger? (Lgb)
141 void GuiWrap::update_contents()
143 InsetWrapParams & params = controller().params();
145 Length len(params.width);
146 dialog_->widthED->setText(toqstr(numtostr(len.value())));
147 dialog_->unitsLC->setCurrentItem(len.unit());
150 if (params.placement == "l")
152 else if (params.placement == "r")
154 else if (params.placement == "p")
157 dialog_->valignCO->setCurrentIndex(item);
160 } // namespace frontend
164 #include "GuiWrap_moc.cpp"