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); }
27 } // namespace frontend
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(literalCB, SIGNAL(clicked()),
44 this, SIGNAL(changed()));
45 connect(webRB, SIGNAL(clicked()),
46 this, SIGNAL(changed()));
47 connect(emailRB, SIGNAL(clicked()),
48 this, SIGNAL(changed()));
49 connect(fileRB, SIGNAL(clicked()),
50 this, SIGNAL(changed()));
52 setFocusProxy(targetED);
56 void GuiHyperlink::paramsToDialog(Inset const * inset)
58 InsetHyperlink const * hlink = static_cast<InsetHyperlink const *>(inset);
59 InsetCommandParams const & params = hlink->params();
61 targetED->setText(toqstr(params["target"]));
62 nameED->setText(toqstr(params["name"]));
63 literalCB->setChecked(params["literal"] == "true");
64 docstring const & type = params["type"];
66 webRB->setChecked(true);
67 else if (type == "mailto:")
68 emailRB->setChecked(true);
69 else if (type == "file:")
70 fileRB->setChecked(true);
74 bool GuiHyperlink::initialiseParams(std::string const & data)
76 InsetCommandParams params(insetCode());
77 if (!InsetCommand::string2params(data, params))
79 targetED->setText(toqstr(params["target"]));
80 nameED->setText(toqstr(params["name"]));
81 literalCB->setChecked(params["literal"] == "true");
82 if (params["type"] == from_utf8("mailto:"))
83 emailRB->setChecked(true);
84 else if (params["type"] == from_utf8("file:"))
85 fileRB->setChecked(true);
87 webRB->setChecked(true);
92 docstring GuiHyperlink::dialogToParams() const
94 InsetCommandParams params(insetCode());
96 params["target"] = qstring_to_ucs4(targetED->text());
97 params["name"] = qstring_to_ucs4(nameED->text());
98 if (webRB->isChecked())
99 params["type"] = from_utf8("");
100 else if (emailRB->isChecked())
101 params["type"] = from_utf8("mailto:");
102 else if (fileRB->isChecked())
103 params["type"] = from_utf8("file:");
104 params["literal"] = literalCB->isChecked()
105 ? from_ascii("true") : from_ascii("false");
106 params.setCmdName("href");
107 return from_utf8(InsetHyperlink::params2string(params));
111 bool GuiHyperlink::checkWidgets(bool readonly) const
113 targetED->setReadOnly(readonly);
114 nameED->setReadOnly(readonly);
115 typeGB->setEnabled(!readonly);
116 if (!InsetParamsWidget::checkWidgets())
118 return !targetED->text().isEmpty() || !nameED->text().isEmpty();
122 } // namespace frontend
126 #include "moc_GuiHyperlink.cpp"