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 #include "support/debug.h"
22 #if defined(LYX_MERGE_FILES) && !defined(Q_CC_MSVC)
23 // GCC couldn't find operator==
25 bool operator==(lyx::docstring const & d, char const * c);
27 bool operator==(lyx::docstring const & d, char const * c)
28 { return lyx::operator ==(d, c); }
29 } // namespace frontend
37 GuiHyperlink::GuiHyperlink(QWidget * parent) : InsetParamsWidget(parent)
41 connect(targetED, SIGNAL(textChanged(const QString &)),
42 this, SIGNAL(changed()));
43 connect(nameED, SIGNAL(textChanged(const QString &)),
44 this, SIGNAL(changed()));
45 connect(literalCB, SIGNAL(clicked()),
46 this, SIGNAL(changed()));
47 connect(webRB, SIGNAL(clicked()),
48 this, SIGNAL(changed()));
49 connect(emailRB, SIGNAL(clicked()),
50 this, SIGNAL(changed()));
51 connect(fileRB, SIGNAL(clicked()),
52 this, SIGNAL(changed()));
53 connect(noneRB, SIGNAL(clicked()),
54 this, SIGNAL(changed()));
56 setFocusProxy(targetED);
60 void GuiHyperlink::paramsToDialog(Inset const * inset)
62 InsetHyperlink const * hlink = static_cast<InsetHyperlink const *>(inset);
63 InsetCommandParams const & params = hlink->params();
65 targetED->setText(toqstr(params["target"]));
66 nameED->setText(toqstr(params["name"]));
67 literalCB->setChecked(params["literal"] == "true");
68 docstring const & type = params["type"];
70 webRB->setChecked(true);
71 else if (type == "mailto:")
72 emailRB->setChecked(true);
73 else if (type == "file:")
74 fileRB->setChecked(true);
75 else if (type == "other")
76 noneRB->setChecked(true);
78 LYXERR0("Unknown hyperlink type: " << type);
82 bool GuiHyperlink::initialiseParams(std::string const & sdata)
84 InsetCommandParams params(insetCode());
85 if (!InsetCommand::string2params(sdata, params))
87 targetED->setText(toqstr(params["target"]));
88 nameED->setText(toqstr(params["name"]));
89 literalCB->setChecked(params["literal"] == "true");
90 if (params["type"] == "mailto:")
91 emailRB->setChecked(true);
92 else if (params["type"] == "file:")
93 fileRB->setChecked(true);
94 else if (params["type"] == "other")
95 noneRB->setChecked(true);
97 webRB->setChecked(true);
102 docstring GuiHyperlink::dialogToParams() const
104 InsetCommandParams params(insetCode());
106 params["target"] = qstring_to_ucs4(targetED->text());
107 params["name"] = qstring_to_ucs4(nameED->text());
108 if (webRB->isChecked())
109 params["type"] = from_utf8("");
110 else if (emailRB->isChecked())
111 params["type"] = from_utf8("mailto:");
112 else if (fileRB->isChecked())
113 params["type"] = from_utf8("file:");
114 else if (noneRB->isChecked())
115 params["type"] = from_utf8("other");
116 params["literal"] = literalCB->isChecked()
117 ? from_ascii("true") : from_ascii("false");
118 params.setCmdName("href");
119 return from_utf8(InsetHyperlink::params2string(params));
123 bool GuiHyperlink::checkWidgets(bool readonly) const
125 targetED->setReadOnly(readonly);
126 nameED->setReadOnly(readonly);
127 typeGB->setEnabled(!readonly);
128 if (!InsetParamsWidget::checkWidgets())
130 return !targetED->text().isEmpty() || !nameED->text().isEmpty();
134 } // namespace frontend
138 #include "moc_GuiHyperlink.cpp"