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 bool GuiHyperlink::initialiseParams(std::string const & data)
73 InsetCommandParams params(insetCode());
74 if (!InsetCommand::string2params(data, params))
76 targetED->setText(toqstr(params["target"]));
77 nameED->setText(toqstr(params["name"]));
78 if (params["type"] == from_utf8("mailto:"))
79 emailRB->setChecked(true);
80 else if (params["type"] == from_utf8("file:"))
81 fileRB->setChecked(true);
83 webRB->setChecked(true);
88 docstring GuiHyperlink::dialogToParams() const
90 InsetCommandParams params(insetCode());
92 params["target"] = qstring_to_ucs4(targetED->text());
93 params["name"] = qstring_to_ucs4(nameED->text());
94 if (webRB->isChecked())
95 params["type"] = from_utf8("");
96 else if (emailRB->isChecked())
97 params["type"] = from_utf8("mailto:");
98 else if (fileRB->isChecked())
99 params["type"] = from_utf8("file:");
100 params.setCmdName("href");
101 return from_utf8(InsetHyperlink::params2string(params));
105 bool GuiHyperlink::checkWidgets(bool readonly) const
107 targetED->setReadOnly(readonly);
108 nameED->setReadOnly(readonly);
109 typeGB->setEnabled(!readonly);
110 if (!InsetParamsWidget::checkWidgets())
112 return !targetED->text().isEmpty() || !nameED->text().isEmpty();
116 } // namespace frontend
120 #include "moc_GuiHyperlink.cpp"