2010-02-15 23:17:45 +00:00
|
|
|
/**
|
|
|
|
* \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 <config.h>
|
|
|
|
|
|
|
|
#include "InsetParamsDialog.h"
|
|
|
|
|
|
|
|
#include "GuiBox.h"
|
2010-02-19 20:57:25 +00:00
|
|
|
#include "GuiBranch.h"
|
2010-02-23 21:24:24 +00:00
|
|
|
#include "GuiBibitem.h"
|
2010-02-15 23:17:45 +00:00
|
|
|
#include "GuiERT.h"
|
2010-10-27 20:01:49 +00:00
|
|
|
#include "GuiHSpace.h"
|
2010-10-27 17:02:42 +00:00
|
|
|
#include "GuiHyperlink.h"
|
2010-02-15 23:17:45 +00:00
|
|
|
#include "GuiInfo.h"
|
2010-10-27 17:25:55 +00:00
|
|
|
#include "GuiLabel.h"
|
2010-09-07 14:13:28 +00:00
|
|
|
#include "GuiLine.h"
|
2010-10-27 20:15:35 +00:00
|
|
|
#include "GuiNomenclature.h"
|
2010-10-30 20:14:57 +00:00
|
|
|
#include "GuiPrintNomencl.h"
|
2010-02-16 09:39:14 +00:00
|
|
|
#include "GuiTabular.h"
|
2010-02-15 23:17:45 +00:00
|
|
|
#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
|
|
|
|
{
|
2010-10-27 12:55:57 +00:00
|
|
|
Private() : widget_(0), inset_(0), changed_(false) {}
|
2010-02-15 23:17:45 +00:00
|
|
|
///
|
|
|
|
InsetParamsWidget * widget_;
|
2010-10-27 12:55:57 +00:00
|
|
|
/// 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_;
|
2010-02-15 23:17:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// 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);
|
2010-09-11 08:01:08 +00:00
|
|
|
setFocusProxy(widget);
|
2010-02-15 23:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InsetParamsDialog::~InsetParamsDialog()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-28 16:31:14 +00:00
|
|
|
bool InsetParamsDialog::initialiseParams(std::string const & data)
|
2010-02-19 11:17:00 +00:00
|
|
|
{
|
2010-10-28 16:31:14 +00:00
|
|
|
if (!d->widget_->initialiseParams(data))
|
|
|
|
on_restorePB_clicked();
|
2010-02-19 11:17:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-28 16:31:14 +00:00
|
|
|
|
2010-02-15 23:17:45 +00:00
|
|
|
void InsetParamsDialog::setInsetParamsWidget(InsetParamsWidget * widget)
|
|
|
|
{
|
|
|
|
d->widget_ = widget;
|
|
|
|
stackedWidget->addWidget(widget);
|
|
|
|
stackedWidget->setCurrentWidget(widget);
|
2010-02-16 10:50:06 +00:00
|
|
|
connect(d->widget_, SIGNAL(changed()), this, SLOT(onWidget_changed()));
|
2010-02-15 23:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetParamsDialog::on_restorePB_clicked()
|
|
|
|
{
|
2010-02-19 11:04:15 +00:00
|
|
|
updateView(true);
|
|
|
|
restorePB->setEnabled(false);
|
2010-10-27 12:55:57 +00:00
|
|
|
d->changed_ = false;
|
|
|
|
d->inset_ = inset(d->widget_->insetCode());
|
2010-02-15 23:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetParamsDialog::on_okPB_clicked()
|
|
|
|
{
|
2010-02-16 09:39:14 +00:00
|
|
|
Inset const * i = inset(d->widget_->insetCode());
|
|
|
|
if (i)
|
|
|
|
applyView();
|
|
|
|
else
|
|
|
|
newInset();
|
2010-02-15 23:17:45 +00:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-16 09:39:14 +00:00
|
|
|
void InsetParamsDialog::newInset()
|
|
|
|
{
|
|
|
|
docstring const argument = d->widget_->dialogToParams();
|
|
|
|
dispatch(FuncRequest(d->widget_->creationCode(), argument));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-19 20:44:59 +00:00
|
|
|
void InsetParamsDialog::on_newPB_clicked()
|
|
|
|
{
|
|
|
|
newInset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-15 23:17:45 +00:00
|
|
|
void InsetParamsDialog::on_applyPB_clicked()
|
|
|
|
{
|
2010-02-19 20:44:59 +00:00
|
|
|
applyView();
|
2010-02-15 23:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetParamsDialog::on_closePB_clicked()
|
|
|
|
{
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetParamsDialog::on_synchronizedViewCB_stateChanged(int state)
|
|
|
|
{
|
2010-02-19 20:44:59 +00:00
|
|
|
checkWidgets(state == Qt::Checked);
|
2010-02-15 23:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-16 10:50:06 +00:00
|
|
|
docstring InsetParamsDialog::checkWidgets(bool synchronized_view)
|
2010-02-15 23:17:45 +00:00
|
|
|
{
|
2010-02-16 10:50:06 +00:00
|
|
|
bool const widget_ok = d->widget_->checkWidgets();
|
|
|
|
Inset const * ins = inset(d->widget_->insetCode());
|
2010-02-15 23:17:45 +00:00
|
|
|
docstring const argument = d->widget_->dialogToParams();
|
2010-02-16 10:50:06 +00:00
|
|
|
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);
|
2010-10-27 12:55:57 +00:00
|
|
|
bool const can_be_restored = !synchronized_view && !read_only
|
|
|
|
&& ins && (ins != d->inset_ || d->changed_);
|
|
|
|
restorePB->setEnabled(can_be_restored);
|
2010-02-16 10:50:06 +00:00
|
|
|
applyPB->setEnabled(lfun_ok && widget_ok && !read_only && valid_argument);
|
|
|
|
d->widget_->setEnabled(!read_only);
|
|
|
|
return argument;
|
|
|
|
}
|
2010-02-15 23:17:45 +00:00
|
|
|
|
2010-02-16 10:50:06 +00:00
|
|
|
|
|
|
|
void InsetParamsDialog::onWidget_changed()
|
|
|
|
{
|
2010-10-27 12:55:57 +00:00
|
|
|
d->changed_ = true;
|
2010-02-16 10:50:06 +00:00
|
|
|
docstring const argument = checkWidgets(synchronizedViewCB->isChecked());
|
|
|
|
if (synchronizedViewCB->isChecked())
|
|
|
|
dispatch(FuncRequest(LFUN_INSET_MODIFY, argument));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetParamsDialog::applyView()
|
|
|
|
{
|
|
|
|
docstring const argument = checkWidgets(synchronizedViewCB->isChecked());
|
2010-02-15 23:17:45 +00:00
|
|
|
dispatch(FuncRequest(LFUN_INSET_MODIFY, argument));
|
2010-10-27 12:55:57 +00:00
|
|
|
d->changed_ = false;
|
|
|
|
d->inset_ = inset(d->widget_->insetCode());
|
|
|
|
updateView(true);
|
2010-02-15 23:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-19 11:04:15 +00:00
|
|
|
void InsetParamsDialog::updateView(bool update_widget)
|
2010-02-15 23:17:45 +00:00
|
|
|
{
|
2010-02-19 11:04:15 +00:00
|
|
|
if (update_widget) {
|
|
|
|
Inset const * i = inset(d->widget_->insetCode());
|
|
|
|
if (i) {
|
|
|
|
d->widget_->blockSignals(true);
|
|
|
|
d->widget_->paramsToDialog(i);
|
|
|
|
d->widget_->blockSignals(false);
|
|
|
|
}
|
2010-02-16 10:50:06 +00:00
|
|
|
}
|
|
|
|
checkWidgets(synchronizedViewCB->isChecked());
|
2010-02-15 23:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-19 11:04:15 +00:00
|
|
|
void InsetParamsDialog::updateView()
|
|
|
|
{
|
|
|
|
updateView(synchronizedViewCB->isChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-15 23:17:45 +00:00
|
|
|
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;
|
2010-02-23 21:24:24 +00:00
|
|
|
case BIBITEM_CODE:
|
|
|
|
widget = new GuiBibitem;
|
|
|
|
break;
|
2010-02-19 20:57:25 +00:00
|
|
|
case BRANCH_CODE:
|
|
|
|
widget = new GuiBranch;
|
|
|
|
break;
|
2010-02-15 23:17:45 +00:00
|
|
|
case BOX_CODE:
|
|
|
|
widget = new GuiBox;
|
|
|
|
break;
|
2010-10-27 17:02:42 +00:00
|
|
|
case HYPERLINK_CODE:
|
|
|
|
widget = new GuiHyperlink;
|
|
|
|
break;
|
2010-02-15 23:17:45 +00:00
|
|
|
case INFO_CODE:
|
|
|
|
widget = new GuiInfo;
|
|
|
|
break;
|
2010-10-27 17:25:55 +00:00
|
|
|
case LABEL_CODE:
|
|
|
|
widget = new GuiLabel;
|
|
|
|
break;
|
2010-09-07 14:13:28 +00:00
|
|
|
case LINE_CODE:
|
|
|
|
widget = new GuiLine;
|
|
|
|
break;
|
2010-02-21 09:28:33 +00:00
|
|
|
case MATH_SPACE_CODE:
|
|
|
|
widget = new GuiHSpace(true);
|
|
|
|
break;
|
2010-10-27 20:01:49 +00:00
|
|
|
case NOMENCL_CODE:
|
|
|
|
widget = new GuiNomenclature;
|
|
|
|
break;
|
2010-10-30 20:14:57 +00:00
|
|
|
case NOMENCL_PRINT_CODE:
|
|
|
|
widget = new GuiPrintNomencl;
|
|
|
|
break;
|
2010-02-21 09:28:33 +00:00
|
|
|
case SPACE_CODE:
|
|
|
|
widget = new GuiHSpace(false);
|
|
|
|
break;
|
2010-02-16 09:39:14 +00:00
|
|
|
case TABULAR_CODE:
|
|
|
|
widget = new GuiTabular;
|
|
|
|
break;
|
2010-02-15 23:17:45 +00:00
|
|
|
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"
|