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)
28 { return lyx::operator ==(d, c); }
30 bool operator==(lyx::docstring & d, char const * c)
31 { return lyx::operator ==(d, c); }
40 GuiHyperlink::GuiHyperlink(GuiView & lv)
41 : GuiDialog(lv, "href", qt_("Hyperlink")),
42 params_(insetCode("href"))
46 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
47 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
48 connect(targetED, SIGNAL(textChanged(const QString &)),
49 this, SLOT(changed_adaptor()));
50 connect(nameED, SIGNAL(textChanged(const QString &)),
51 this, SLOT(changed_adaptor()));
52 connect(webRB, SIGNAL(clicked()),
53 this, SLOT(changed_adaptor()));
54 connect(emailRB, SIGNAL(clicked()),
55 this, SLOT(changed_adaptor()));
56 connect(fileRB, SIGNAL(clicked()),
57 this, SLOT(changed_adaptor()));
59 setFocusProxy(targetED);
61 bc().setPolicy(ButtonPolicy::OkCancelReadOnlyPolicy);
64 bc().setCancel(closePB);
65 bc().addReadOnly(targetED);
66 bc().addReadOnly(nameED);
67 bc().addReadOnly(webRB);
68 bc().addReadOnly(emailRB);
69 bc().addReadOnly(fileRB);
73 void GuiHyperlink::changed_adaptor()
79 void GuiHyperlink::paramsToDialog(InsetCommandParams const & /*icp*/)
81 targetED->setText(toqstr(params_["target"]));
82 nameED->setText(toqstr(params_["name"]));
83 if (params_["type"] == "")
84 webRB->setChecked(true);
85 else if (params_["type"] == "mailto:")
86 emailRB->setChecked(true);
87 else if (params_["type"] == "file:")
88 fileRB->setChecked(true);
89 bc().setValid(isValid());
93 void GuiHyperlink::applyView()
95 params_["target"] = qstring_to_ucs4(targetED->text());
96 params_["name"] = qstring_to_ucs4(nameED->text());
97 if (webRB->isChecked())
98 params_["type"] = qstring_to_ucs4("");
99 else if (emailRB->isChecked())
100 params_["type"] = qstring_to_ucs4("mailto:");
101 else if (fileRB->isChecked())
102 params_["type"] = qstring_to_ucs4("file:");
103 params_.setCmdName("href");
107 bool GuiHyperlink::isValid()
109 return !targetED->text().isEmpty() || !nameED->text().isEmpty();
113 bool GuiHyperlink::initialiseParams(std::string const & data)
115 // The name passed with LFUN_INSET_APPLY is also the name
116 // used to identify the mailer.
117 InsetCommand::string2params("href", data, params_);
118 paramsToDialog(params_);
123 void GuiHyperlink::dispatchParams()
125 std::string const lfun = InsetCommand::params2string("href", params_);
126 dispatch(FuncRequest(getLfun(), lfun));
130 Dialog * createGuiHyperlink(GuiView & lv) { return new GuiHyperlink(lv); }
133 } // namespace frontend
137 #include "moc_GuiHyperlink.cpp"