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 synchronizedViewCB->setChecked(false);
82 on_synchronizedViewCB_stateChanged(false);
83 setFocusProxy(widget);
86 InsetParamsDialog::~InsetParamsDialog()
92 bool InsetParamsDialog::initialiseParams(std::string const & data)
94 if (!d->widget_->initialiseParams(data))
95 on_restorePB_clicked();
100 void InsetParamsDialog::setInsetParamsWidget(InsetParamsWidget * widget)
103 stackedWidget->addWidget(widget);
104 stackedWidget->setCurrentWidget(widget);
105 connect(d->widget_, SIGNAL(changed()), this, SLOT(onWidget_changed()));
109 void InsetParamsDialog::on_restorePB_clicked()
112 restorePB->setEnabled(false);
114 d->inset_ = inset(d->widget_->insetCode());
118 void InsetParamsDialog::on_okPB_clicked()
120 Inset const * i = inset(d->widget_->insetCode());
129 void InsetParamsDialog::newInset()
131 docstring const argument = d->widget_->dialogToParams();
132 dispatch(FuncRequest(d->widget_->creationCode(), argument));
136 void InsetParamsDialog::on_newPB_clicked()
142 void InsetParamsDialog::on_applyPB_clicked()
148 void InsetParamsDialog::on_closePB_clicked()
154 void InsetParamsDialog::on_synchronizedViewCB_stateChanged(int state)
156 checkWidgets(state == Qt::Checked);
160 docstring InsetParamsDialog::checkWidgets(bool synchronized_view)
162 bool const widget_ok = d->widget_->checkWidgets();
163 Inset const * ins = inset(d->widget_->insetCode());
164 docstring const argument = d->widget_->dialogToParams();
165 bool valid_argument = !argument.empty();
167 valid_argument &= ins->validateModifyArgument(argument);
168 FuncCode const code = synchronized_view
169 ? d->widget_->creationCode() : LFUN_INSET_MODIFY;
170 bool const lfun_ok = lyx::getStatus(FuncRequest(code, argument)).enabled();
171 bool const read_only = buffer().isReadonly();
173 okPB->setEnabled(!synchronized_view && widget_ok && !read_only && valid_argument);
174 bool const can_be_restored = !synchronized_view && !read_only
175 && ins && (ins != d->inset_ || d->changed_);
176 restorePB->setEnabled(can_be_restored);
177 applyPB->setEnabled(lfun_ok && widget_ok && !read_only && valid_argument);
178 d->widget_->setEnabled(!read_only);
183 void InsetParamsDialog::onWidget_changed()
186 docstring const argument = checkWidgets(synchronizedViewCB->isChecked());
187 if (synchronizedViewCB->isChecked())
188 dispatch(FuncRequest(LFUN_INSET_MODIFY, argument));
192 void InsetParamsDialog::applyView()
194 docstring const argument = checkWidgets(synchronizedViewCB->isChecked());
195 dispatch(FuncRequest(LFUN_INSET_MODIFY, argument));
197 d->inset_ = inset(d->widget_->insetCode());
202 void InsetParamsDialog::updateView(bool update_widget)
205 Inset const * i = inset(d->widget_->insetCode());
207 d->widget_->blockSignals(true);
208 d->widget_->paramsToDialog(i);
209 d->widget_->blockSignals(false);
212 checkWidgets(synchronizedViewCB->isChecked());
216 void InsetParamsDialog::updateView()
218 updateView(synchronizedViewCB->isChecked());
222 Dialog * createDialog(GuiView & lv, InsetCode code)
224 InsetParamsWidget * widget;
230 widget = new FloatPlacement(true);
233 widget = new GuiBibitem;
236 widget = new GuiBranch;
242 widget = new GuiHyperlink;
245 widget = new GuiInfo;
248 widget = new GuiLabel;
251 widget = new GuiLine;
253 case MATH_SPACE_CODE:
254 widget = new GuiHSpace(true);
257 widget = new GuiNomenclature;
259 case NOMENCL_PRINT_CODE:
260 widget = new GuiPrintNomencl;
263 widget = new GuiHSpace(false);
266 widget = new GuiTabular;
269 widget = new GuiVSpace;
273 InsetParamsDialog * dialog = new InsetParamsDialog(lv, widget);
278 Dialog * createDialog(GuiView & lv, string const & name)
280 return createDialog(lv, insetCode(name));
283 } // namespace frontend
286 #include "moc_InsetParamsDialog.cpp"