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:51:10 +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 16:27:22 +02:00
|
|
|
connect(allAuthorsED, SIGNAL(textChanged(QString)),
|
|
|
|
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"]);
|
2019-04-19 09:53:42 +02:00
|
|
|
if (inset->buffer().masterParams().citeEngine() == "natbib") {
|
2019-04-18 14:48:01 +02:00
|
|
|
yearED->setHidden(false);
|
|
|
|
yearLA->setHidden(false);
|
2019-04-18 16:27:22 +02:00
|
|
|
allAuthorsED->setHidden(false);
|
|
|
|
allAuthorsLA->setHidden(false);
|
|
|
|
labelLA->setText(qt_("Author &Names:"));
|
2019-04-19 11:27:54 +02:00
|
|
|
labelLA->setMaximumWidth(labelLA->sizeHint().width());
|
2019-04-18 16:27:22 +02:00
|
|
|
labelED->setToolTip(qt_("Insert the author name(s) for the author-year reference here. "
|
|
|
|
"If you use an abbreviated list (with 'et al.'), the full list can go below."));
|
2019-04-19 11:27:54 +02:00
|
|
|
allAuthorsLA->setText(qt_("A&ll Author Names:"));
|
|
|
|
allAuthorsLA->setMaximumWidth(allAuthorsLA->sizeHint().width());
|
2019-04-19 13:43:33 +02:00
|
|
|
literalCB->setToolTip(qt_("Pass content of the `Author', `Year' and `All Authors' fields literally to LaTeX. "
|
2019-04-19 11:27:54 +02:00
|
|
|
"Check this if you want to enter LaTeX code."));
|
2019-04-18 14:48:01 +02:00
|
|
|
int const i = label.lastIndexOf("(");
|
|
|
|
int const j = label.lastIndexOf(")");
|
|
|
|
if (i != -1 && j != -1 && i < j) {
|
2019-04-19 09:33:31 +02:00
|
|
|
// Split Author(s) and Year
|
|
|
|
// Natbib syntax is "Jones et al.(1990)Jones, Baker, and Williams"
|
|
|
|
// (full list is optional)
|
2019-04-18 14:48:01 +02:00
|
|
|
QString const year = label.left(j).mid(i + 1);
|
|
|
|
QString const author = label.left(i);
|
2019-04-18 16:27:22 +02:00
|
|
|
QString const allauthors = label.mid(j + 1);
|
2019-04-18 14:48:01 +02:00
|
|
|
labelED->setText(author);
|
|
|
|
yearED->setText(year);
|
2019-04-18 16:27:22 +02:00
|
|
|
allAuthorsED->setText(allauthors);
|
2019-04-18 14:48:01 +02:00
|
|
|
} else
|
|
|
|
labelED->setText(label);
|
|
|
|
} else {
|
|
|
|
yearED->setHidden(true);
|
|
|
|
yearLA->setHidden(true);
|
2019-04-18 16:27:22 +02:00
|
|
|
allAuthorsED->setHidden(true);
|
|
|
|
allAuthorsLA->setHidden(true);
|
2019-04-19 11:27:54 +02:00
|
|
|
allAuthorsLA->setText(qt_("&Label:"));
|
|
|
|
allAuthorsLA->setMaximumWidth(allAuthorsLA->sizeHint().width());
|
2019-04-18 14:48:01 +02:00
|
|
|
labelLA->setText(qt_("&Label:"));
|
2019-04-19 11:27:54 +02:00
|
|
|
labelLA->setMaximumWidth(labelLA->sizeHint().width());
|
2019-04-18 14:48:01 +02:00
|
|
|
labelED->setToolTip(qt_("The label as it appears in the document"));
|
|
|
|
labelED->setText(label);
|
2019-04-19 11:27:54 +02:00
|
|
|
literalCB->setToolTip(qt_("Pass content of the `Label' field literally to LaTeX. "
|
|
|
|
"Check this if you want to enter LaTeX code."));
|
2019-04-18 14:48:01 +02:00
|
|
|
}
|
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())
|
2019-04-18 16:27:22 +02:00
|
|
|
label += "(" + yearED->text() + ")" + allAuthorsED->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"
|