2 * \file InsetParamsDialog.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Abdelrazak Younes
8 * Full author contact details are available in file CREDITS.
13 #include "InsetParamsDialog.h"
16 #include "GuiBranch.h"
17 #include "GuiBibitem.h"
19 #include "GuiHSpace.h"
20 #include "GuiHyperlink.h"
24 #include "GuiNomenclature.h"
25 #include "GuiPrintNomencl.h"
26 #include "GuiTabular.h"
27 #include "GuiVSpace.h"
28 #include "FloatPlacement.h"
30 #include "InsetParamsWidget.h"
31 #include "qt_helpers.h"
34 #include "buffer_funcs.h"
35 #include "BufferParams.h"
36 #include "BufferView.h"
38 #include "FuncRequest.h"
39 #include "FuncStatus.h"
42 #include "support/debug.h"
43 #include "support/lstrings.h"
46 using namespace lyx::support;
51 /////////////////////////////////////////////////////////////////
53 // InsetParamsDialog::Private
55 /////////////////////////////////////////////////////////////////
57 struct InsetParamsDialog::Private
59 Private() : widget_(0), inset_(0), changed_(false) {}
61 InsetParamsWidget * widget_;
62 /// The inset that was used at last Restore or Apply operation.
64 /// Set to true whenever the dialog is changed and set back to
65 /// false when the dialog is applied or restored.
69 /////////////////////////////////////////////////////////////////
73 /////////////////////////////////////////////////////////////////
75 InsetParamsDialog::InsetParamsDialog(GuiView & lv, InsetParamsWidget * widget)
76 : DialogView(lv, toqstr(insetName(widget->insetCode())),
77 toqstr(insetName(widget->insetCode()))), d(new Private)
80 setInsetParamsWidget(widget);
81 immediateApplyCB->setChecked(false);
82 synchronizedCB->setChecked(true);
83 on_immediateApplyCB_stateChanged(false);
84 setFocusProxy(widget);
87 InsetParamsDialog::~InsetParamsDialog()
93 bool InsetParamsDialog::initialiseParams(std::string const & data)
95 if (!d->widget_->initialiseParams(data))
96 on_restorePB_clicked();
101 void InsetParamsDialog::setInsetParamsWidget(InsetParamsWidget * widget)
104 stackedWidget->addWidget(widget);
105 stackedWidget->setCurrentWidget(widget);
106 connect(d->widget_, SIGNAL(changed()), this, SLOT(onWidget_changed()));
110 void InsetParamsDialog::on_restorePB_clicked()
113 restorePB->setEnabled(false);
115 d->inset_ = inset(d->widget_->insetCode());
119 void InsetParamsDialog::on_okPB_clicked()
121 Inset const * i = inset(d->widget_->insetCode());
130 void InsetParamsDialog::newInset()
132 docstring const argument = d->widget_->dialogToParams();
133 dispatch(FuncRequest(d->widget_->creationCode(), argument));
137 void InsetParamsDialog::on_newPB_clicked()
143 void InsetParamsDialog::on_applyPB_clicked()
149 void InsetParamsDialog::on_closePB_clicked()
155 void InsetParamsDialog::on_immediateApplyCB_stateChanged(int state)
157 checkWidgets(state == Qt::Checked);
161 void InsetParamsDialog::on_synchronizedCB_stateChanged(int)
167 docstring InsetParamsDialog::checkWidgets(bool immediate)
169 bool const widget_ok = d->widget_->checkWidgets();
170 Inset const * ins = inset(d->widget_->insetCode());
171 docstring const argument = d->widget_->dialogToParams();
172 bool valid_argument = !argument.empty();
174 valid_argument &= ins->validateModifyArgument(argument);
175 FuncCode const code = immediate
176 ? d->widget_->creationCode() : LFUN_INSET_MODIFY;
177 bool const lfun_ok = lyx::getStatus(FuncRequest(code, argument)).enabled();
178 bool const read_only = buffer().isReadonly();
180 okPB->setEnabled(!immediate && widget_ok && !read_only && valid_argument);
181 bool const can_be_restored = !immediate && !read_only
182 && ins && (ins != d->inset_ || d->changed_);
183 restorePB->setEnabled(can_be_restored);
184 applyPB->setEnabled(!immediate && lfun_ok && widget_ok && !read_only && valid_argument);
185 d->widget_->setEnabled(!read_only);
186 synchronizedCB->setEnabled(!immediate);
191 void InsetParamsDialog::onWidget_changed()
194 docstring const argument = checkWidgets(immediateApplyCB->isChecked());
195 if (immediateApplyCB->isChecked())
196 dispatch(FuncRequest(LFUN_INSET_MODIFY, argument));
200 void InsetParamsDialog::applyView()
202 docstring const argument = checkWidgets(immediateApplyCB->isChecked());
203 dispatch(FuncRequest(LFUN_INSET_MODIFY, argument));
205 d->inset_ = inset(d->widget_->insetCode());
210 void InsetParamsDialog::updateView(bool update_widget)
213 Inset const * i = inset(d->widget_->insetCode());
215 d->widget_->blockSignals(true);
216 d->widget_->paramsToDialog(i);
217 d->widget_->blockSignals(false);
220 checkWidgets(immediateApplyCB->isChecked());
224 void InsetParamsDialog::updateView()
226 bool const update_widget =
227 (synchronizedCB->isChecked() || immediateApplyCB->isChecked());
228 updateView(update_widget);
232 Dialog * createDialog(GuiView & lv, InsetCode code)
234 InsetParamsWidget * widget;
240 widget = new FloatPlacement(true);
243 widget = new GuiBibitem;
246 widget = new GuiBranch;
252 widget = new GuiHyperlink;
255 widget = new GuiInfo;
258 widget = new GuiLabel;
261 widget = new GuiLine;
263 case MATH_SPACE_CODE:
264 widget = new GuiHSpace(true);
267 widget = new GuiNomenclature;
269 case NOMENCL_PRINT_CODE:
270 widget = new GuiPrintNomencl;
273 widget = new GuiHSpace(false);
276 widget = new GuiTabular;
279 widget = new GuiVSpace;
283 InsetParamsDialog * dialog = new InsetParamsDialog(lv, widget);
288 Dialog * createDialog(GuiView & lv, string const & name)
290 return createDialog(lv, insetCode(name));
293 } // namespace frontend
296 #include "moc_InsetParamsDialog.cpp"