2006-03-05 17:24:44 +00:00
|
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
|
* \file GuiBibitem.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author John Levon
|
2019-04-18 14:48:01 +02:00
|
|
|
|
* \¸author Jürgen Spitzmüller
|
2006-03-05 17:24:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
#include "GuiBibitem.h"
|
2010-02-23 21:24:24 +00:00
|
|
|
|
|
2019-04-18 14:48:01 +02:00
|
|
|
|
#include "Buffer.h"
|
|
|
|
|
#include "BufferParams.h"
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include "qt_helpers.h"
|
2007-10-07 10:31:37 +00:00
|
|
|
|
|
2008-04-20 08:19:26 +00:00
|
|
|
|
#include "insets/InsetCommand.h"
|
|
|
|
|
|
2007-04-25 08:42:22 +00:00
|
|
|
|
#include <QLineEdit>
|
|
|
|
|
#include <QPushButton>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
namespace frontend {
|
|
|
|
|
|
2007-04-25 08:42:22 +00:00
|
|
|
|
|
2010-02-23 21:24:24 +00:00
|
|
|
|
GuiBibitem::GuiBibitem(QWidget * parent) : InsetParamsWidget(parent)
|
2007-04-25 08:42:22 +00:00
|
|
|
|
{
|
|
|
|
|
setupUi(this);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
2007-10-07 10:31:37 +00:00
|
|
|
|
connect(keyED, SIGNAL(textChanged(QString)),
|
2010-02-23 21:24:24 +00:00
|
|
|
|
this, SIGNAL(changed()));
|
2007-10-07 10:31:37 +00:00
|
|
|
|
connect(labelED, SIGNAL(textChanged(QString)),
|
2010-02-23 21:24:24 +00:00
|
|
|
|
this, SIGNAL(changed()));
|
2019-04-18 14:48:01 +02:00
|
|
|
|
connect(yearED, SIGNAL(textChanged(QString)),
|
|
|
|
|
this, SIGNAL(changed()));
|
2017-01-30 07:44:55 +01:00
|
|
|
|
connect(literalCB, SIGNAL(clicked()),
|
|
|
|
|
this, SIGNAL(changed()));
|
2007-04-25 08:42:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-02-23 21:24:24 +00:00
|
|
|
|
void GuiBibitem::paramsToDialog(Inset const * inset)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2010-02-23 21:24:24 +00:00
|
|
|
|
InsetCommand const * ic = static_cast<InsetCommand const *>(inset);
|
|
|
|
|
InsetCommandParams const & params = ic->params();
|
|
|
|
|
keyED->setText(toqstr(params["key"]));
|
2017-01-30 07:44:55 +01:00
|
|
|
|
literalCB->setChecked(params["literal"] == "true");
|
2019-04-18 14:48:01 +02:00
|
|
|
|
QString const label = toqstr(params["label"]);
|
|
|
|
|
BufferParams const bp = inset->buffer().masterParams();
|
|
|
|
|
if (bp.citeEngine() == "natbib" && bp.citeEngineType() == ENGINE_TYPE_AUTHORYEAR) {
|
|
|
|
|
yearED->setHidden(false);
|
|
|
|
|
yearLA->setHidden(false);
|
|
|
|
|
labelLA->setText(qt_("Author &Name:"));
|
|
|
|
|
labelED->setToolTip(qt_("Insert the author name(s) here. The year goes to the separate field."));
|
|
|
|
|
int const i = label.lastIndexOf("(");
|
|
|
|
|
int const j = label.lastIndexOf(")");
|
|
|
|
|
if (i != -1 && j != -1 && i < j) {
|
|
|
|
|
// Split Author(Year) to Author and Year
|
|
|
|
|
QString const year = label.left(j).mid(i + 1);
|
|
|
|
|
QString const author = label.left(i);
|
|
|
|
|
labelED->setText(author);
|
|
|
|
|
yearED->setText(year);
|
|
|
|
|
} else
|
|
|
|
|
labelED->setText(label);
|
|
|
|
|
} else {
|
|
|
|
|
yearED->setHidden(true);
|
|
|
|
|
yearLA->setHidden(true);
|
|
|
|
|
labelLA->setText(qt_("&Label:"));
|
|
|
|
|
labelED->setToolTip(qt_("The label as it appears in the document"));
|
|
|
|
|
labelED->setText(label);
|
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-02-23 21:24:24 +00:00
|
|
|
|
docstring GuiBibitem::dialogToParams() const
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2010-02-23 21:24:24 +00:00
|
|
|
|
InsetCommandParams params(insetCode());
|
2019-04-18 14:48:01 +02:00
|
|
|
|
QString label = labelED->text();
|
|
|
|
|
if (!yearED->isHidden())
|
|
|
|
|
label += "(" + yearED->text() + ")";
|
2010-02-23 21:24:24 +00:00
|
|
|
|
params["key"] = qstring_to_ucs4(keyED->text());
|
2019-04-18 14:48:01 +02:00
|
|
|
|
params["label"] = qstring_to_ucs4(label);
|
2017-01-30 07:44:55 +01:00
|
|
|
|
params["literal"] = literalCB->isChecked()
|
|
|
|
|
? from_ascii("true") : from_ascii("false");
|
2010-10-29 00:25:28 +00:00
|
|
|
|
return from_utf8(InsetCommand::params2string(params));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-03-30 14:44:11 +02:00
|
|
|
|
bool GuiBibitem::checkWidgets(bool readonly) const
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2015-03-30 14:44:11 +02:00
|
|
|
|
keyED->setReadOnly(readonly);
|
|
|
|
|
labelED->setReadOnly(readonly);
|
2010-02-23 21:24:24 +00:00
|
|
|
|
if (!InsetParamsWidget::checkWidgets())
|
|
|
|
|
return false;
|
2019-04-18 14:48:01 +02:00
|
|
|
|
return !keyED->text().isEmpty()
|
|
|
|
|
&& (yearED->isHidden() || !yearED->text().isEmpty());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
|
} // namespace lyx
|
2007-04-25 08:42:22 +00:00
|
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
|
#include "moc_GuiBibitem.cpp"
|