]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiBibitem.cpp
Display full author list with Natbib (non-BibTeX) if requested
[lyx.git] / src / frontends / qt4 / GuiBibitem.cpp
1 /**
2  * \file GuiBibitem.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Jürgen Spitzmüller
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiBibitem.h"
15
16 #include "Buffer.h"
17 #include "BufferParams.h"
18
19 #include "qt_helpers.h"
20
21 #include "insets/InsetCommand.h"
22
23 #include <QLineEdit>
24 #include <QPushButton>
25
26
27 namespace lyx {
28 namespace frontend {
29
30
31 GuiBibitem::GuiBibitem(QWidget * parent) : InsetParamsWidget(parent)
32 {
33         setupUi(this);
34
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()));
45 }
46
47
48 void GuiBibitem::paramsToDialog(Inset const * inset)
49 {
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         BufferParams const bp = inset->buffer().masterParams();
56         if (bp.citeEngine() == "natbib" && bp.citeEngineType() == ENGINE_TYPE_AUTHORYEAR) {
57                 yearED->setHidden(false);
58                 yearLA->setHidden(false);
59                 allAuthorsED->setHidden(false);
60                 allAuthorsLA->setHidden(false);
61                 labelLA->setText(qt_("Author &Names:"));
62                 labelED->setToolTip(qt_("Insert the author name(s) for the author-year reference here. "
63                                         "If you use an abbreviated list (with 'et al.'), the full list can go below."));
64                 int const i = label.lastIndexOf("(");
65                 int const j = label.lastIndexOf(")");
66                 if (i != -1 && j != -1 && i < j) {
67                         // Split Author(s) and Year
68                         // Natbib syntax is "Jones et al.(1990)Jones, Baker, and Williams"
69                         // (full list is optional)
70                         QString const year = label.left(j).mid(i + 1);
71                         QString const author = label.left(i);
72                         QString const allauthors = label.mid(j + 1);
73                         labelED->setText(author);
74                         yearED->setText(year);
75                         allAuthorsED->setText(allauthors);
76                 } else
77                         labelED->setText(label);
78         } else {
79                 yearED->setHidden(true);
80                 yearLA->setHidden(true);
81                 allAuthorsED->setHidden(true);
82                 allAuthorsLA->setHidden(true);
83                 labelLA->setText(qt_("&Label:"));
84                 labelED->setToolTip(qt_("The label as it appears in the document"));
85                 labelED->setText(label);
86         }
87 }
88
89
90 docstring GuiBibitem::dialogToParams() const
91 {
92         InsetCommandParams params(insetCode());
93         QString label = labelED->text();
94         if (!yearED->isHidden())
95                 label += "(" + yearED->text() + ")" + allAuthorsED->text();
96         params["key"] = qstring_to_ucs4(keyED->text());
97         params["label"] = qstring_to_ucs4(label);
98         params["literal"] = literalCB->isChecked()
99                         ? from_ascii("true") : from_ascii("false");
100         return from_utf8(InsetCommand::params2string(params));
101 }
102
103
104 bool GuiBibitem::checkWidgets(bool readonly) const
105 {
106         keyED->setReadOnly(readonly);
107         labelED->setReadOnly(readonly);
108         if (!InsetParamsWidget::checkWidgets())
109                 return false;
110         return !keyED->text().isEmpty()
111                 && (yearED->isHidden() || !yearED->text().isEmpty());
112 }
113
114 } // namespace frontend
115 } // namespace lyx
116
117 #include "moc_GuiBibitem.cpp"