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"
17 #include "FuncRequest.h"
18 #include "insets/InsetCommand.h"
22 #include <QPushButton>
24 #ifdef LYX_MERGED_BUILD
25 // GCC couldn't find operator==
27 bool operator==(lyx::docstring & d, char const * c);
29 bool operator==(lyx::docstring & d, char const * c);
38 GuiHyperlink::GuiHyperlink(GuiView & lv)
39 : GuiDialog(lv, "href", qt_("Hyperlink")),
40 params_(insetCode("href"))
44 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
45 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
46 connect(targetED, SIGNAL(textChanged(const QString &)),
47 this, SLOT(changed_adaptor()));
48 connect(nameED, SIGNAL(textChanged(const QString &)),
49 this, SLOT(changed_adaptor()));
50 connect(webRB, SIGNAL(clicked()),
51 this, SLOT(changed_adaptor()));
52 connect(emailRB, SIGNAL(clicked()),
53 this, SLOT(changed_adaptor()));
54 connect(fileRB, SIGNAL(clicked()),
55 this, SLOT(changed_adaptor()));
57 setFocusProxy(targetED);
59 bc().setPolicy(ButtonPolicy::OkCancelReadOnlyPolicy);
62 bc().setCancel(closePB);
63 bc().addReadOnly(targetED);
64 bc().addReadOnly(nameED);
65 bc().addReadOnly(webRB);
66 bc().addReadOnly(emailRB);
67 bc().addReadOnly(fileRB);
71 void GuiHyperlink::changed_adaptor()
77 void GuiHyperlink::paramsToDialog(InsetCommandParams const & /*icp*/)
79 targetED->setText(toqstr(params_["target"]));
80 nameED->setText(toqstr(params_["name"]));
81 if (params_["type"] == "")
82 webRB->setChecked(true);
83 else if (params_["type"] == "mailto:")
84 emailRB->setChecked(true);
85 else if (params_["type"] == "file:")
86 fileRB->setChecked(true);
87 bc().setValid(isValid());
91 void GuiHyperlink::applyView()
93 params_["target"] = qstring_to_ucs4(targetED->text());
94 params_["name"] = qstring_to_ucs4(nameED->text());
95 if (webRB->isChecked())
96 params_["type"] = qstring_to_ucs4("");
97 else if (emailRB->isChecked())
98 params_["type"] = qstring_to_ucs4("mailto:");
99 else if (fileRB->isChecked())
100 params_["type"] = qstring_to_ucs4("file:");
101 params_.setCmdName("href");
105 bool GuiHyperlink::isValid()
107 return !targetED->text().isEmpty() || !nameED->text().isEmpty();
111 bool GuiHyperlink::initialiseParams(std::string const & data)
113 // The name passed with LFUN_INSET_APPLY is also the name
114 // used to identify the mailer.
115 InsetCommand::string2params("href", data, params_);
116 paramsToDialog(params_);
121 void GuiHyperlink::dispatchParams()
123 std::string const lfun = InsetCommand::params2string("href", params_);
124 dispatch(FuncRequest(getLfun(), lfun));
128 Dialog * createGuiHyperlink(GuiView & lv) { return new GuiHyperlink(lv); }
131 } // namespace frontend
135 #include "moc_GuiHyperlink.cpp"