]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiBibitem.cpp
Fix doxygen comment
[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(yearED, SIGNAL(textChanged(QString)),
40                 this, SIGNAL(changed()));
41         connect(literalCB, SIGNAL(clicked()),
42                 this, SIGNAL(changed()));
43 }
44
45
46 void GuiBibitem::paramsToDialog(Inset const * inset)
47 {
48         InsetCommand const * ic = static_cast<InsetCommand const *>(inset);
49         InsetCommandParams const & params = ic->params();
50         keyED->setText(toqstr(params["key"]));
51         literalCB->setChecked(params["literal"] == "true");
52         QString const label = toqstr(params["label"]);
53         BufferParams const bp = inset->buffer().masterParams();
54         if (bp.citeEngine() == "natbib" && bp.citeEngineType() == ENGINE_TYPE_AUTHORYEAR) {
55                 yearED->setHidden(false);
56                 yearLA->setHidden(false);
57                 labelLA->setText(qt_("Author &Name:"));
58                 labelED->setToolTip(qt_("Insert the author name(s) here. The year goes to the separate field."));
59                 int const i = label.lastIndexOf("(");
60                 int const j = label.lastIndexOf(")");
61                 if (i != -1 && j != -1 && i < j) {
62                         // Split Author(Year) to Author and Year
63                         QString const year = label.left(j).mid(i + 1);
64                         QString const author = label.left(i);
65                         labelED->setText(author);
66                         yearED->setText(year);
67                 } else
68                         labelED->setText(label);
69         } else {
70                 yearED->setHidden(true);
71                 yearLA->setHidden(true);
72                 labelLA->setText(qt_("&Label:"));
73                 labelED->setToolTip(qt_("The label as it appears in the document"));
74                 labelED->setText(label);
75         }
76 }
77
78
79 docstring GuiBibitem::dialogToParams() const
80 {
81         InsetCommandParams params(insetCode());
82         QString label = labelED->text();
83         if (!yearED->isHidden())
84                 label += "(" + yearED->text() + ")";
85         params["key"] = qstring_to_ucs4(keyED->text());
86         params["label"] = qstring_to_ucs4(label);
87         params["literal"] = literalCB->isChecked()
88                         ? from_ascii("true") : from_ascii("false");
89         return from_utf8(InsetCommand::params2string(params));
90 }
91
92
93 bool GuiBibitem::checkWidgets(bool readonly) const
94 {
95         keyED->setReadOnly(readonly);
96         labelED->setReadOnly(readonly);
97         if (!InsetParamsWidget::checkWidgets())
98                 return false;
99         return !keyED->text().isEmpty()
100                 && (yearED->isHidden() || !yearED->text().isEmpty());
101 }
102
103 } // namespace frontend
104 } // namespace lyx
105
106 #include "moc_GuiBibitem.cpp"