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/lstrings.h"
45 using namespace lyx::support;
50 /////////////////////////////////////////////////////////////////
52 // InsetParamsDialog::Private
54 /////////////////////////////////////////////////////////////////
56 struct InsetParamsDialog::Private
58 Private() : widget_(0), inset_(0), changed_(false) {}
60 InsetParamsWidget * widget_;
61 /// The inset that was used at last Restore or Apply operation.
63 /// Set to true whenever the dialog is changed and set back to
64 /// false when the dialog is applied or restored.
68 /////////////////////////////////////////////////////////////////
72 /////////////////////////////////////////////////////////////////
74 InsetParamsDialog::InsetParamsDialog(GuiView & lv, InsetParamsWidget * widget)
75 : DialogView(lv, toqstr(insetName(widget->insetCode())),
76 toqstr(insetName(widget->insetCode()))), d(new Private)
79 setInsetParamsWidget(widget);
80 immediateApplyCB->setChecked(false);
81 synchronizedCB->setChecked(true);
82 on_immediateApplyCB_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_immediateApplyCB_stateChanged(int state)
156 checkWidgets(state == Qt::Checked);
160 void InsetParamsDialog::on_synchronizedCB_stateChanged(int)
166 docstring InsetParamsDialog::checkWidgets(bool immediate)
168 bool const widget_ok = d->widget_->checkWidgets();
169 Inset const * ins = inset(d->widget_->insetCode());
170 docstring const argument = d->widget_->dialogToParams();
171 bool valid_argument = !argument.empty();
173 valid_argument &= ins->validateModifyArgument(argument);
174 FuncCode const code = immediate
175 ? d->widget_->creationCode() : LFUN_INSET_MODIFY;
176 bool const lfun_ok = lyx::getStatus(FuncRequest(code, argument)).enabled();
177 bool const read_only = buffer().isReadonly();
179 okPB->setEnabled(!immediate && widget_ok && !read_only && valid_argument);
180 bool const can_be_restored = !immediate && !read_only
181 && ins && (ins != d->inset_ || d->changed_);
182 restorePB->setEnabled(can_be_restored);
183 applyPB->setEnabled(!immediate && lfun_ok && widget_ok && !read_only && valid_argument);
184 d->widget_->setEnabled(!read_only);
185 synchronizedCB->setEnabled(!immediate);
190 void InsetParamsDialog::onWidget_changed()
193 docstring const argument = checkWidgets(immediateApplyCB->isChecked());
194 if (immediateApplyCB->isChecked())
195 dispatch(FuncRequest(LFUN_INSET_MODIFY, argument));
199 void InsetParamsDialog::applyView()
201 docstring const argument = checkWidgets(immediateApplyCB->isChecked());
202 dispatch(FuncRequest(LFUN_INSET_MODIFY, argument));
204 d->inset_ = inset(d->widget_->insetCode());
209 void InsetParamsDialog::updateView(bool update_widget)
212 Inset const * i = inset(d->widget_->insetCode());
214 d->widget_->blockSignals(true);
215 d->widget_->paramsToDialog(i);
216 d->widget_->blockSignals(false);
219 checkWidgets(immediateApplyCB->isChecked());
223 void InsetParamsDialog::updateView()
225 bool const update_widget =
226 (synchronizedCB->isChecked() || immediateApplyCB->isChecked());
227 updateView(update_widget);
231 Dialog * createDialog(GuiView & lv, InsetCode code)
233 InsetParamsWidget * widget;
239 widget = new FloatPlacement(true);
242 widget = new GuiBibitem;
245 widget = new GuiBranch;
251 widget = new GuiHyperlink;
254 widget = new GuiInfo;
257 widget = new GuiLabel;
260 widget = new GuiLine;
262 case MATH_SPACE_CODE:
263 widget = new GuiHSpace(true);
266 widget = new GuiNomenclature;
268 case NOMENCL_PRINT_CODE:
269 widget = new GuiPrintNomencl;
272 widget = new GuiHSpace(false);
275 widget = new GuiTabular;
278 widget = new GuiVSpace;
282 InsetParamsDialog * dialog = new InsetParamsDialog(lv, widget);
287 Dialog * createDialog(GuiView & lv, string const & name)
289 return createDialog(lv, insetCode(name));
292 } // namespace frontend
295 #include "moc_InsetParamsDialog.cpp"