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>
28 GuiHyperlink::GuiHyperlink(GuiView & lv)
29 : GuiDialog(lv, "href", qt_("Hyperlink")),
30 params_(insetCode("href"))
34 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
35 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
36 connect(targetED, SIGNAL(textChanged(const QString &)),
37 this, SLOT(changed_adaptor()));
38 connect(nameED, SIGNAL(textChanged(const QString &)),
39 this, SLOT(changed_adaptor()));
40 connect(webRB, SIGNAL(clicked()),
41 this, SLOT(changed_adaptor()));
42 connect(emailRB, SIGNAL(clicked()),
43 this, SLOT(changed_adaptor()));
44 connect(fileRB, SIGNAL(clicked()),
45 this, SLOT(changed_adaptor()));
47 setFocusProxy(targetED);
50 bc().setCancel(closePB);
51 bc().addReadOnly(targetED);
52 bc().addReadOnly(nameED);
53 bc().addReadOnly(webRB);
54 bc().addReadOnly(emailRB);
55 bc().addReadOnly(fileRB);
59 void GuiHyperlink::changed_adaptor()
65 void GuiHyperlink::paramsToDialog(InsetCommandParams const & icp)
67 targetED->setText(toqstr(params_["target"]));
68 nameED->setText(toqstr(params_["name"]));
69 if (params_["type"] == "")
70 webRB->setChecked(true);
71 else if (params_["type"] == "mailto:")
72 emailRB->setChecked(true);
73 else if (params_["type"] == "file:")
74 fileRB->setChecked(true);
75 bc().setValid(isValid());
79 void GuiHyperlink::applyView()
81 params_["target"] = qstring_to_ucs4(targetED->text());
82 params_["name"] = qstring_to_ucs4(nameED->text());
83 if (webRB->isChecked())
84 params_["type"] = qstring_to_ucs4("");
85 else if (emailRB->isChecked())
86 params_["type"] = qstring_to_ucs4("mailto:");
87 else if (fileRB->isChecked())
88 params_["type"] = qstring_to_ucs4("file:");
89 params_.setCmdName("href");
93 bool GuiHyperlink::isValid()
95 return !targetED->text().isEmpty() || !nameED->text().isEmpty();
99 bool GuiHyperlink::initialiseParams(std::string const & data)
101 // The name passed with LFUN_INSET_APPLY is also the name
102 // used to identify the mailer.
103 InsetCommand::string2params("href", data, params_);
104 paramsToDialog(params_);
109 void GuiHyperlink::dispatchParams()
111 std::string const lfun = InsetCommand::params2string("href", params_);
112 dispatch(FuncRequest(getLfun(), lfun));
116 Dialog * createGuiHyperlink(GuiView & lv) { return new GuiHyperlink(lv); }
119 } // namespace frontend
123 #include "GuiHyperlink_moc.cpp"