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(yearED, SIGNAL(textChanged(QString)),
40 this, SIGNAL(changed()));
41 connect(literalCB, SIGNAL(clicked()),
42 this, SIGNAL(changed()));
46 void GuiBibitem::paramsToDialog(Inset const * inset)
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);
68 labelED->setText(label);
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);
79 docstring GuiBibitem::dialogToParams() const
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));
93 bool GuiBibitem::checkWidgets(bool readonly) const
95 keyED->setReadOnly(readonly);
96 labelED->setReadOnly(readonly);
97 if (!InsetParamsWidget::checkWidgets())
99 return !keyED->text().isEmpty()
100 && (yearED->isHidden() || !yearED->text().isEmpty());
103 } // namespace frontend
106 #include "moc_GuiBibitem.cpp"