3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Jürgen Spitzmüller
9 * Full author contact details are available in file CREDITS.
14 #include "GuiBibitem.h"
17 #include "BufferParams.h"
19 #include "qt_helpers.h"
21 #include "insets/InsetCommand.h"
24 #include <QPushButton>
31 GuiBibitem::GuiBibitem(QWidget * parent) : InsetParamsWidget(parent)
35 connect(keyED, SIGNAL(textChanged(QString)),
36 this, SIGNAL(changed()));
37 connect(labelED, SIGNAL(textChanged(QString)),
38 this, SIGNAL(changed()));
39 connect(allAuthorsED, SIGNAL(textChanged(QString)),
40 this, SIGNAL(changed()));
41 connect(yearED, SIGNAL(textChanged(QString)),
42 this, SIGNAL(changed()));
43 connect(literalCB, SIGNAL(clicked()),
44 this, SIGNAL(changed()));
48 void GuiBibitem::paramsToDialog(Inset const * inset)
50 InsetCommand const * ic = static_cast<InsetCommand const *>(inset);
51 InsetCommandParams const & params = ic->params();
52 keyED->setText(toqstr(params["key"]));
53 literalCB->setChecked(params["literal"] == "true");
54 QString const label = toqstr(params["label"]);
55 if (inset->buffer().masterParams().citeEngine() == "natbib") {
56 yearED->setHidden(false);
57 yearLA->setHidden(false);
58 allAuthorsED->setHidden(false);
59 allAuthorsLA->setHidden(false);
60 labelLA->setText(qt_("Author &Names:"));
61 labelED->setToolTip(qt_("Insert the author name(s) for the author-year reference here. "
62 "If you use an abbreviated list (with 'et al.'), the full list can go below."));
63 int const i = label.lastIndexOf("(");
64 int const j = label.lastIndexOf(")");
65 if (i != -1 && j != -1 && i < j) {
66 // Split Author(s) and Year
67 // Natbib syntax is "Jones et al.(1990)Jones, Baker, and Williams"
68 // (full list is optional)
69 QString const year = label.left(j).mid(i + 1);
70 QString const author = label.left(i);
71 QString const allauthors = label.mid(j + 1);
72 labelED->setText(author);
73 yearED->setText(year);
74 allAuthorsED->setText(allauthors);
76 labelED->setText(label);
78 yearED->setHidden(true);
79 yearLA->setHidden(true);
80 allAuthorsED->setHidden(true);
81 allAuthorsLA->setHidden(true);
82 labelLA->setText(qt_("&Label:"));
83 labelED->setToolTip(qt_("The label as it appears in the document"));
84 labelED->setText(label);
89 docstring GuiBibitem::dialogToParams() const
91 InsetCommandParams params(insetCode());
92 QString label = labelED->text();
93 if (!yearED->isHidden())
94 label += "(" + yearED->text() + ")" + allAuthorsED->text();
95 params["key"] = qstring_to_ucs4(keyED->text());
96 params["label"] = qstring_to_ucs4(label);
97 params["literal"] = literalCB->isChecked()
98 ? from_ascii("true") : from_ascii("false");
99 return from_utf8(InsetCommand::params2string(params));
103 bool GuiBibitem::checkWidgets(bool readonly) const
105 keyED->setReadOnly(readonly);
106 labelED->setReadOnly(readonly);
107 if (!InsetParamsWidget::checkWidgets())
109 return !keyED->text().isEmpty()
110 && (yearED->isHidden() || !yearED->text().isEmpty());
113 } // namespace frontend
116 #include "moc_GuiBibitem.cpp"