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 read_only = buffer().isReadonly();
170 bool const widget_ok = d->widget_->checkWidgets(read_only);
171 Inset const * ins = inset(d->widget_->insetCode());
172 docstring const argument = d->widget_->dialogToParams();
173 bool valid_argument = !argument.empty();
175 valid_argument &= ins->validateModifyArgument(argument);
176 FuncCode const code = immediate
177 ? d->widget_->creationCode() : LFUN_INSET_MODIFY;
178 bool const lfun_ok = lyx::getStatus(FuncRequest(code, argument)).enabled();
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(ins && !immediate && lfun_ok && widget_ok && !read_only && valid_argument);
185 newPB->setEnabled(widget_ok && !read_only && valid_argument);
186 synchronizedCB->setEnabled(!immediate);
191 void InsetParamsDialog::onWidget_changed()
194 docstring const argument = checkWidgets(immediateApplyCB->isChecked());
195 if (immediateApplyCB->isChecked()
196 && d->widget_->checkWidgets(buffer().isReadonly()))
197 dispatch(FuncRequest(LFUN_INSET_MODIFY, argument));
201 void InsetParamsDialog::applyView()
203 docstring const argument = checkWidgets(immediateApplyCB->isChecked());
204 dispatch(FuncRequest(LFUN_INSET_MODIFY, argument));
206 d->inset_ = inset(d->widget_->insetCode());
211 void InsetParamsDialog::updateView(bool update_widget)
214 Inset const * i = inset(d->widget_->insetCode());
216 d->widget_->blockSignals(true);
217 d->widget_->paramsToDialog(i);
218 d->widget_->blockSignals(false);
221 checkWidgets(immediateApplyCB->isChecked());
225 void InsetParamsDialog::updateView()
227 bool const update_widget =
228 (synchronizedCB->isChecked() || immediateApplyCB->isChecked());
229 updateView(update_widget);
233 Dialog * createDialog(GuiView & lv, InsetCode code)
235 InsetParamsWidget * widget;
241 widget = new FloatPlacement(true);
244 widget = new GuiBibitem;
247 widget = new GuiBranch;
253 widget = new GuiHyperlink;
256 widget = new GuiInfo;
259 widget = new GuiLabel;
262 widget = new GuiLine;
264 case MATH_SPACE_CODE:
265 widget = new GuiHSpace(true);
268 widget = new GuiNomenclature;
270 case NOMENCL_PRINT_CODE:
271 widget = new GuiPrintNomencl;
274 widget = new GuiHSpace(false);
277 widget = new GuiTabular;
280 widget = new GuiVSpace;
284 InsetParamsDialog * dialog = new InsetParamsDialog(lv, widget);
289 Dialog * createDialog(GuiView & lv, string const & name)
291 return createDialog(lv, insetCode(name));
294 } // namespace frontend
297 #include "moc_InsetParamsDialog.cpp"