]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiBibitem.cpp
Remove obsolete (and false) comment.
[lyx.git] / src / frontends / qt / 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         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                 labelLA->setMaximumWidth(labelLA->sizeHint().width());
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                 allAuthorsLA->setText(qt_("A&ll Author Names:"));
65                 allAuthorsLA->setMaximumWidth(allAuthorsLA->sizeHint().width());
66                 literalCB->setToolTip(qt_("Pass content of the `Author', `Year' and `All Authors' fields literally to LaTeX. "
67                                           "Check this if you want to enter LaTeX code."));
68                 int const i = label.lastIndexOf("(");
69                 int const j = label.lastIndexOf(")");
70                 if (i != -1 && j != -1 && i < j) {
71                         // Split Author(s) and Year
72                         // Natbib syntax is "Jones et al.(1990)Jones, Baker, and Williams"
73                         // (full list is optional)
74                         QString const year = label.left(j).mid(i + 1);
75                         QString const author = label.left(i);
76                         QString const allauthors = label.mid(j + 1);
77                         labelED->setText(author);
78                         yearED->setText(year);
79                         allAuthorsED->setText(allauthors);
80                 } else
81                         labelED->setText(label);
82         } else {
83                 yearED->setHidden(true);
84                 yearLA->setHidden(true);
85                 allAuthorsED->setHidden(true);
86                 allAuthorsLA->setHidden(true);
87                 allAuthorsLA->setText(qt_("&Label:"));
88                 allAuthorsLA->setMaximumWidth(allAuthorsLA->sizeHint().width());
89                 labelLA->setText(qt_("&Label:"));
90                 labelLA->setMaximumWidth(labelLA->sizeHint().width());
91                 labelED->setToolTip(qt_("The label as it appears in the document"));
92                 labelED->setText(label);
93                 literalCB->setToolTip(qt_("Pass content of the `Label' field literally to LaTeX. "
94                                           "Check this if you want to enter LaTeX code."));
95         }
96 }
97
98
99 docstring GuiBibitem::dialogToParams() const
100 {
101         InsetCommandParams params(insetCode());
102         QString label = labelED->text();
103         if (!yearED->isHidden())
104                 label += "(" + yearED->text() + ")" + allAuthorsED->text();
105         params["key"] = qstring_to_ucs4(keyED->text());
106         params["label"] = qstring_to_ucs4(label);
107         params["literal"] = literalCB->isChecked()
108                         ? from_ascii("true") : from_ascii("false");
109         return from_utf8(InsetCommand::params2string(params));
110 }
111
112
113 bool GuiBibitem::checkWidgets(bool readonly) const
114 {
115         keyED->setReadOnly(readonly);
116         labelED->setReadOnly(readonly);
117         if (!InsetParamsWidget::checkWidgets())
118                 return false;
119         return !keyED->text().isEmpty()
120                 && (yearED->isHidden() || !yearED->text().isEmpty());
121 }
122
123 } // namespace frontend
124 } // namespace lyx
125
126 #include "moc_GuiBibitem.cpp"