2 * \file InsetParamsDialog.cpp
\r
3 * This file is part of LyX, the document processor.
\r
4 * Licence details can be found in the file COPYING.
\r
6 * \author Abdelrazak Younes
\r
8 * Full author contact details are available in file CREDITS.
\r
13 #include "InsetParamsDialog.h"
\r
16 #include "GuiBranch.h"
\r
17 #include "GuiBibitem.h"
\r
19 #include "GuiHSpace.h"
\r
20 #include "GuiHyperlink.h"
\r
21 #include "GuiInfo.h"
\r
22 #include "GuiLabel.h"
\r
23 #include "GuiLine.h"
\r
24 #include "GuiNomenclature.h"
\r
25 #include "GuiPrintNomencl.h"
\r
26 #include "GuiTabular.h"
\r
27 #include "GuiVSpace.h"
\r
28 #include "FloatPlacement.h"
\r
30 #include "InsetParamsWidget.h"
\r
31 #include "qt_helpers.h"
\r
34 #include "buffer_funcs.h"
\r
35 #include "BufferParams.h"
\r
36 #include "BufferView.h"
\r
38 #include "FuncRequest.h"
\r
39 #include "FuncStatus.h"
\r
42 #include "support/debug.h"
\r
43 #include "support/lstrings.h"
\r
45 using namespace std;
\r
46 using namespace lyx::support;
\r
49 namespace frontend {
\r
51 /////////////////////////////////////////////////////////////////
\r
53 // InsetParamsDialog::Private
\r
55 /////////////////////////////////////////////////////////////////
\r
57 struct InsetParamsDialog::Private
\r
59 Private() : widget_(0), inset_(0), changed_(false) {}
\r
61 InsetParamsWidget * widget_;
\r
62 /// The inset that was used at last Restore or Apply operation.
\r
63 Inset const * inset_;
\r
64 /// Set to true whenever the dialog is changed and set back to
\r
65 /// false when the dialog is applied or restored.
\r
69 /////////////////////////////////////////////////////////////////
\r
71 // InsetParamsDialog
\r
73 /////////////////////////////////////////////////////////////////
\r
75 InsetParamsDialog::InsetParamsDialog(GuiView & lv, InsetParamsWidget * widget)
\r
76 : DialogView(lv, toqstr(insetName(widget->insetCode())),
\r
77 toqstr(insetName(widget->insetCode()))), d(new Private)
\r
80 setInsetParamsWidget(widget);
\r
81 synchronizedViewCB->setChecked(false);
\r
82 on_synchronizedViewCB_stateChanged(false);
\r
83 setFocusProxy(widget);
\r
86 InsetParamsDialog::~InsetParamsDialog()
\r
92 bool InsetParamsDialog::initialiseParams(std::string const & data)
\r
94 if (!d->widget_->initialiseParams(data))
\r
95 on_restorePB_clicked();
\r
100 void InsetParamsDialog::setInsetParamsWidget(InsetParamsWidget * widget)
\r
102 d->widget_ = widget;
\r
103 stackedWidget->addWidget(widget);
\r
104 stackedWidget->setCurrentWidget(widget);
\r
105 connect(d->widget_, SIGNAL(changed()), this, SLOT(onWidget_changed()));
\r
109 void InsetParamsDialog::on_restorePB_clicked()
\r
112 restorePB->setEnabled(false);
\r
113 d->changed_ = false;
\r
114 d->inset_ = inset(d->widget_->insetCode());
\r
118 void InsetParamsDialog::on_okPB_clicked()
\r
120 Inset const * i = inset(d->widget_->insetCode());
\r
129 void InsetParamsDialog::newInset()
\r
131 docstring const argument = d->widget_->dialogToParams();
\r
132 dispatch(FuncRequest(d->widget_->creationCode(), argument));
\r
136 void InsetParamsDialog::on_newPB_clicked()
\r
142 void InsetParamsDialog::on_applyPB_clicked()
\r
148 void InsetParamsDialog::on_closePB_clicked()
\r
154 void InsetParamsDialog::on_synchronizedViewCB_stateChanged(int state)
\r
156 checkWidgets(state == Qt::Checked);
\r
160 docstring InsetParamsDialog::checkWidgets(bool synchronized_view)
\r
162 bool const widget_ok = d->widget_->checkWidgets();
\r
163 Inset const * ins = inset(d->widget_->insetCode());
\r
164 docstring const argument = d->widget_->dialogToParams();
\r
165 bool valid_argument = !argument.empty();
\r
167 valid_argument &= ins->validateModifyArgument(argument);
\r
168 FuncCode const code = synchronized_view
\r
169 ? d->widget_->creationCode() : LFUN_INSET_MODIFY;
\r
170 bool const lfun_ok = lyx::getStatus(FuncRequest(code, argument)).enabled();
\r
171 bool const read_only = buffer().isReadonly();
\r
173 okPB->setEnabled(!synchronized_view && widget_ok && !read_only && valid_argument);
\r
174 bool const can_be_restored = !synchronized_view && !read_only
\r
175 && ins && (ins != d->inset_ || d->changed_);
\r
176 restorePB->setEnabled(can_be_restored);
\r
177 applyPB->setEnabled(lfun_ok && widget_ok && !read_only && valid_argument);
\r
178 d->widget_->setEnabled(!read_only);
\r
183 void InsetParamsDialog::onWidget_changed()
\r
185 d->changed_ = true;
\r
186 docstring const argument = checkWidgets(synchronizedViewCB->isChecked());
\r
187 if (synchronizedViewCB->isChecked())
\r
188 dispatch(FuncRequest(LFUN_INSET_MODIFY, argument));
\r
192 void InsetParamsDialog::applyView()
\r
194 docstring const argument = checkWidgets(synchronizedViewCB->isChecked());
\r
195 dispatch(FuncRequest(LFUN_INSET_MODIFY, argument));
\r
196 d->changed_ = false;
\r
197 d->inset_ = inset(d->widget_->insetCode());
\r
202 void InsetParamsDialog::updateView(bool update_widget)
\r
204 if (update_widget) {
\r
205 Inset const * i = inset(d->widget_->insetCode());
\r
207 d->widget_->blockSignals(true);
\r
208 d->widget_->paramsToDialog(i);
\r
209 d->widget_->blockSignals(false);
\r
212 checkWidgets(synchronizedViewCB->isChecked());
\r
216 void InsetParamsDialog::updateView()
\r
218 updateView(synchronizedViewCB->isChecked());
\r
222 Dialog * createDialog(GuiView & lv, InsetCode code)
\r
224 InsetParamsWidget * widget;
\r
227 widget = new GuiERT;
\r
230 widget = new FloatPlacement(true);
\r
233 widget = new GuiBibitem;
\r
236 widget = new GuiBranch;
\r
239 widget = new GuiBox;
\r
241 case HYPERLINK_CODE:
\r
242 widget = new GuiHyperlink;
\r
245 widget = new GuiInfo;
\r
248 widget = new GuiLabel;
\r
251 widget = new GuiLine;
\r
253 case MATH_SPACE_CODE:
\r
254 widget = new GuiHSpace(true);
\r
257 widget = new GuiNomenclature;
\r
259 case NOMENCL_PRINT_CODE:
\r
260 widget = new GuiPrintNomencl;
\r
263 widget = new GuiHSpace(false);
\r
266 widget = new GuiTabular;
\r
269 widget = new GuiVSpace;
\r
273 InsetParamsDialog * dialog = new InsetParamsDialog(lv, widget);
\r
278 Dialog * createDialog(GuiView & lv, string const & name)
\r
280 return createDialog(lv, insetCode(name));
\r
283 } // namespace frontend
\r
286 #include "moc_InsetParamsDialog.cpp"
\r