X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FInsetParamsDialog.cpp;h=44f49b5a44e01d74c1db0e2b2c7c0c9cf92fea5b;hb=161f7b7f62cb33dab681add6c5b5b68a887e2ea1;hp=7a8ab9c3295b9cff697c59b6e677b040e5071e48;hpb=85c782bde8b99402657ed7267b17dce30e24f69e;p=lyx.git diff --git a/src/frontends/qt4/InsetParamsDialog.cpp b/src/frontends/qt4/InsetParamsDialog.cpp index 7a8ab9c329..44f49b5a44 100644 --- a/src/frontends/qt4/InsetParamsDialog.cpp +++ b/src/frontends/qt4/InsetParamsDialog.cpp @@ -1,249 +1,297 @@ -/** - * \file InsetParamsDialog.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Abdelrazak Younes - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "InsetParamsDialog.h" - -#include "GuiBox.h" -#include "GuiBranch.h" -#include "GuiBibitem.h" -#include "GuiERT.h" -#include "GuiInfo.h" -#include "GuiHSpace.h" -#include "GuiTabular.h" -#include "GuiVSpace.h" -#include "FloatPlacement.h" - -#include "InsetParamsWidget.h" -#include "qt_helpers.h" - -#include "Buffer.h" -#include "buffer_funcs.h" -#include "BufferParams.h" -#include "BufferView.h" -#include "Cursor.h" -#include "FuncRequest.h" -#include "FuncStatus.h" -#include "LyX.h" - -#include "support/debug.h" -#include "support/lstrings.h" - -using namespace std; -using namespace lyx::support; - -namespace lyx { -namespace frontend { - -///////////////////////////////////////////////////////////////// -// -// InsetParamsDialog::Private -// -///////////////////////////////////////////////////////////////// - -struct InsetParamsDialog::Private -{ - /// - InsetParamsWidget * widget_; -}; - -///////////////////////////////////////////////////////////////// -// -// InsetParamsDialog -// -///////////////////////////////////////////////////////////////// - -InsetParamsDialog::InsetParamsDialog(GuiView & lv, InsetParamsWidget * widget) - : DialogView(lv, toqstr(insetName(widget->insetCode())), - toqstr(insetName(widget->insetCode()))), d(new Private) -{ - setupUi(this); - setInsetParamsWidget(widget); - synchronizedViewCB->setChecked(false); - on_synchronizedViewCB_stateChanged(false); -} - -InsetParamsDialog::~InsetParamsDialog() -{ - delete d; -} - - -bool InsetParamsDialog::initialiseParams(std::string const &) -{ - on_restorePB_clicked(); - return true; -} - -void InsetParamsDialog::setInsetParamsWidget(InsetParamsWidget * widget) -{ - d->widget_ = widget; - stackedWidget->addWidget(widget); - stackedWidget->setCurrentWidget(widget); - connect(d->widget_, SIGNAL(changed()), this, SLOT(onWidget_changed())); -} - - -void InsetParamsDialog::on_restorePB_clicked() -{ - updateView(true); - restorePB->setEnabled(false); -} - - -void InsetParamsDialog::on_okPB_clicked() -{ - Inset const * i = inset(d->widget_->insetCode()); - if (i) - applyView(); - else - newInset(); - hide(); -} - - -void InsetParamsDialog::newInset() -{ - docstring const argument = d->widget_->dialogToParams(); - dispatch(FuncRequest(d->widget_->creationCode(), argument)); -} - - -void InsetParamsDialog::on_newPB_clicked() -{ - newInset(); -} - - -void InsetParamsDialog::on_applyPB_clicked() -{ - applyView(); -} - - -void InsetParamsDialog::on_closePB_clicked() -{ - hide(); -} - - -void InsetParamsDialog::on_synchronizedViewCB_stateChanged(int state) -{ - checkWidgets(state == Qt::Checked); -} - - -docstring InsetParamsDialog::checkWidgets(bool synchronized_view) -{ - bool const widget_ok = d->widget_->checkWidgets(); - Inset const * ins = inset(d->widget_->insetCode()); - docstring const argument = d->widget_->dialogToParams(); - bool valid_argument = !argument.empty(); - if (ins) - valid_argument &= ins->validateModifyArgument(argument); - FuncCode const code = synchronized_view - ? d->widget_->creationCode() : LFUN_INSET_MODIFY; - bool const lfun_ok = lyx::getStatus(FuncRequest(code, argument)).enabled(); - bool const read_only = buffer().isReadonly(); - - okPB->setEnabled(!synchronized_view && widget_ok && !read_only && valid_argument); - restorePB->setEnabled(!synchronized_view && ins && !read_only); - applyPB->setEnabled(lfun_ok && widget_ok && !read_only && valid_argument); - d->widget_->setEnabled(!read_only); - return argument; -} - - -void InsetParamsDialog::onWidget_changed() -{ - docstring const argument = checkWidgets(synchronizedViewCB->isChecked()); - if (synchronizedViewCB->isChecked()) - dispatch(FuncRequest(LFUN_INSET_MODIFY, argument)); -} - - -void InsetParamsDialog::applyView() -{ - docstring const argument = checkWidgets(synchronizedViewCB->isChecked()); - dispatch(FuncRequest(LFUN_INSET_MODIFY, argument)); -} - - -void InsetParamsDialog::updateView(bool update_widget) -{ - if (update_widget) { - Inset const * i = inset(d->widget_->insetCode()); - if (i) { - d->widget_->blockSignals(true); - d->widget_->paramsToDialog(i); - d->widget_->blockSignals(false); - } - } - checkWidgets(synchronizedViewCB->isChecked()); -} - - -void InsetParamsDialog::updateView() -{ - updateView(synchronizedViewCB->isChecked()); -} - - -Dialog * createDialog(GuiView & lv, InsetCode code) -{ - InsetParamsWidget * widget; - switch (code) { - case ERT_CODE: - widget = new GuiERT; - break; - case FLOAT_CODE: - widget = new FloatPlacement(true); - break; - case BIBITEM_CODE: - widget = new GuiBibitem; - break; - case BRANCH_CODE: - widget = new GuiBranch; - break; - case BOX_CODE: - widget = new GuiBox; - break; - case INFO_CODE: - widget = new GuiInfo; - break; - case MATH_SPACE_CODE: - widget = new GuiHSpace(true); - break; - case SPACE_CODE: - widget = new GuiHSpace(false); - break; - case TABULAR_CODE: - widget = new GuiTabular; - break; - case VSPACE_CODE: - widget = new GuiVSpace; - break; - default: return 0; - } - InsetParamsDialog * dialog = new InsetParamsDialog(lv, widget); - return dialog; -} - - -Dialog * createDialog(GuiView & lv, string const & name) -{ - return createDialog(lv, insetCode(name)); -} - -} // namespace frontend -} // namespace lyx - -#include "moc_InsetParamsDialog.cpp" +/** + * \file InsetParamsDialog.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "InsetParamsDialog.h" + +#include "GuiBox.h" +#include "GuiBranch.h" +#include "GuiBibitem.h" +#include "GuiERT.h" +#include "GuiHSpace.h" +#include "GuiHyperlink.h" +#include "GuiInfo.h" +#include "GuiLabel.h" +#include "GuiLine.h" +#include "GuiNomenclature.h" +#include "GuiPrintNomencl.h" +#include "GuiTabular.h" +#include "GuiVSpace.h" +#include "FloatPlacement.h" + +#include "InsetParamsWidget.h" +#include "qt_helpers.h" + +#include "Buffer.h" +#include "buffer_funcs.h" +#include "BufferParams.h" +#include "BufferView.h" +#include "Cursor.h" +#include "FuncRequest.h" +#include "FuncStatus.h" +#include "LyX.h" + +#include "support/debug.h" +#include "support/lstrings.h" + +using namespace std; +using namespace lyx::support; + +namespace lyx { +namespace frontend { + +///////////////////////////////////////////////////////////////// +// +// InsetParamsDialog::Private +// +///////////////////////////////////////////////////////////////// + +struct InsetParamsDialog::Private +{ + Private() : widget_(0), inset_(0), changed_(false) {} + /// + InsetParamsWidget * widget_; + /// The inset that was used at last Restore or Apply operation. + Inset const * inset_; + /// Set to true whenever the dialog is changed and set back to + /// false when the dialog is applied or restored. + bool changed_; +}; + +///////////////////////////////////////////////////////////////// +// +// InsetParamsDialog +// +///////////////////////////////////////////////////////////////// + +InsetParamsDialog::InsetParamsDialog(GuiView & lv, InsetParamsWidget * widget) + : DialogView(lv, toqstr(insetName(widget->insetCode())), + widget->dialogTitle()), d(new Private) +{ + setupUi(this); + setInsetParamsWidget(widget); + immediateApplyCB->setChecked(false); + synchronizedCB->setChecked(true); + on_immediateApplyCB_stateChanged(false); + setFocusProxy(widget); +} + +InsetParamsDialog::~InsetParamsDialog() +{ + delete d; +} + + +bool InsetParamsDialog::initialiseParams(std::string const & data) +{ + if (!d->widget_->initialiseParams(data)) + on_restorePB_clicked(); + return true; +} + + +void InsetParamsDialog::setInsetParamsWidget(InsetParamsWidget * widget) +{ + d->widget_ = widget; + stackedWidget->addWidget(widget); + stackedWidget->setCurrentWidget(widget); + connect(d->widget_, SIGNAL(changed()), this, SLOT(onWidget_changed())); +} + + +void InsetParamsDialog::on_restorePB_clicked() +{ + updateView(true); + restorePB->setEnabled(false); + d->changed_ = false; + d->inset_ = inset(d->widget_->insetCode()); +} + + +void InsetParamsDialog::on_okPB_clicked() +{ + Inset const * i = inset(d->widget_->insetCode()); + if (i) + applyView(); + else + newInset(); + hide(); +} + + +void InsetParamsDialog::newInset() +{ + docstring const argument = d->widget_->dialogToParams(); + dispatch(FuncRequest(d->widget_->creationCode(), argument)); +} + + +void InsetParamsDialog::on_newPB_clicked() +{ + newInset(); +} + + +void InsetParamsDialog::on_applyPB_clicked() +{ + applyView(); +} + + +void InsetParamsDialog::on_closePB_clicked() +{ + hide(); +} + + +void InsetParamsDialog::on_immediateApplyCB_stateChanged(int state) +{ + checkWidgets(state == Qt::Checked); +} + + +void InsetParamsDialog::on_synchronizedCB_stateChanged(int) +{ + checkWidgets(false); +} + + +docstring InsetParamsDialog::checkWidgets(bool immediate) +{ + bool const read_only = buffer().isReadonly(); + bool const widget_ok = d->widget_->checkWidgets(read_only); + Inset const * ins = inset(d->widget_->insetCode()); + docstring const argument = d->widget_->dialogToParams(); + bool valid_argument = !argument.empty(); + if (ins) + valid_argument &= ins->validateModifyArgument(argument); + FuncCode const code = immediate + ? d->widget_->creationCode() : LFUN_INSET_MODIFY; + bool const lfun_ok = lyx::getStatus(FuncRequest(code, argument)).enabled(); + + okPB->setEnabled(!immediate && widget_ok && !read_only && valid_argument); + bool const can_be_restored = !immediate && !read_only + && ins && (ins != d->inset_ || d->changed_); + restorePB->setEnabled(can_be_restored); + applyPB->setEnabled(ins && !immediate && lfun_ok && widget_ok && !read_only && valid_argument); + newPB->setEnabled(widget_ok && !read_only && valid_argument); + synchronizedCB->setEnabled(!immediate); + return argument; +} + + +void InsetParamsDialog::onWidget_changed() +{ + d->changed_ = true; + docstring const argument = checkWidgets(immediateApplyCB->isChecked()); + if (immediateApplyCB->isChecked() + && d->widget_->checkWidgets(buffer().isReadonly())) + dispatch(FuncRequest(LFUN_INSET_MODIFY, argument)); +} + + +void InsetParamsDialog::applyView() +{ + docstring const argument = checkWidgets(immediateApplyCB->isChecked()); + dispatch(FuncRequest(LFUN_INSET_MODIFY, argument)); + d->changed_ = false; + d->inset_ = inset(d->widget_->insetCode()); + updateView(true); +} + + +void InsetParamsDialog::updateView(bool update_widget) +{ + if (update_widget) { + Inset const * i = inset(d->widget_->insetCode()); + if (i) { + d->widget_->blockSignals(true); + d->widget_->paramsToDialog(i); + d->widget_->blockSignals(false); + } + } + checkWidgets(immediateApplyCB->isChecked()); +} + + +void InsetParamsDialog::updateView() +{ + bool const update_widget = + (synchronizedCB->isChecked() || immediateApplyCB->isChecked()); + updateView(update_widget); +} + + +Dialog * createDialog(GuiView & lv, InsetCode code) +{ + InsetParamsWidget * widget; + switch (code) { + case ERT_CODE: + widget = new GuiERT; + break; + case FLOAT_CODE: + widget = new FloatPlacement(true); + break; + case BIBITEM_CODE: + widget = new GuiBibitem; + break; + case BRANCH_CODE: + widget = new GuiBranch; + break; + case BOX_CODE: + widget = new GuiBox; + break; + case HYPERLINK_CODE: + widget = new GuiHyperlink; + break; + case INFO_CODE: + widget = new GuiInfo; + break; + case LABEL_CODE: + widget = new GuiLabel; + break; + case LINE_CODE: + widget = new GuiLine; + break; + case MATH_SPACE_CODE: + widget = new GuiHSpace(true); + break; + case NOMENCL_CODE: + widget = new GuiNomenclature; + break; + case NOMENCL_PRINT_CODE: + widget = new GuiPrintNomencl; + break; + case SPACE_CODE: + widget = new GuiHSpace(false); + break; + case TABULAR_CODE: + widget = new GuiTabular; + break; + case VSPACE_CODE: + widget = new GuiVSpace; + break; + default: return 0; + } + InsetParamsDialog * dialog = new InsetParamsDialog(lv, widget); + return dialog; +} + + +Dialog * createDialog(GuiView & lv, string const & name) +{ + return createDialog(lv, insetCode(name)); +} + +} // namespace frontend +} // namespace lyx + +#include "moc_InsetParamsDialog.cpp"