2 * \file GuiHyperlink.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS.
14 #include "GuiHyperlink.h"
16 #include "qt_helpers.h"
18 #include "insets/InsetHyperlink.h"
20 #if defined(LYX_MERGE_FILES) && !defined(Q_CC_MSVC)
21 // GCC couldn't find operator==
23 bool operator==(lyx::docstring const & d, char const * c);
25 bool operator==(lyx::docstring const & d, char const * c)
26 { return lyx::operator ==(d, c); }
35 GuiHyperlink::GuiHyperlink(QWidget * parent) : InsetParamsWidget(parent)
39 connect(targetED, SIGNAL(textChanged(const QString &)),
40 this, SIGNAL(changed()));
41 connect(nameED, SIGNAL(textChanged(const QString &)),
42 this, SIGNAL(changed()));
43 connect(webRB, SIGNAL(clicked()),
44 this, SIGNAL(changed()));
45 connect(emailRB, SIGNAL(clicked()),
46 this, SIGNAL(changed()));
47 connect(fileRB, SIGNAL(clicked()),
48 this, SIGNAL(changed()));
50 setFocusProxy(targetED);
54 void GuiHyperlink::paramsToDialog(Inset const * inset)
56 InsetHyperlink const * hlink = static_cast<InsetHyperlink const *>(inset);
57 InsetCommandParams const & params = hlink->params();
59 targetED->setText(toqstr(params["target"]));
60 nameED->setText(toqstr(params["name"]));
61 docstring const & type = params["type"];
63 webRB->setChecked(true);
64 else if (type == "mailto:")
65 emailRB->setChecked(true);
66 else if (type == "file:")
67 fileRB->setChecked(true);
71 docstring GuiHyperlink::dialogToParams() const
73 InsetCommandParams params(insetCode());
75 params["target"] = qstring_to_ucs4(targetED->text());
76 params["name"] = qstring_to_ucs4(nameED->text());
77 if (webRB->isChecked())
78 params["type"] = qstring_to_ucs4("");
79 else if (emailRB->isChecked())
80 params["type"] = qstring_to_ucs4("mailto:");
81 else if (fileRB->isChecked())
82 params["type"] = qstring_to_ucs4("file:");
83 params.setCmdName("href");
84 return from_utf8(InsetHyperlink::params2string(params));
88 bool GuiHyperlink::checkWidgets() const
90 if (!InsetParamsWidget::checkWidgets())
92 return !targetED->text().isEmpty() || !nameED->text().isEmpty();
96 } // namespace frontend
100 #include "moc_GuiHyperlink.cpp"