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 #if defined(LYX_MERGED_BUILD) && !defined(Q_CC_MSVC)
25 // GCC couldn't find operator==
27 bool operator==(lyx::docstring const & d, char const * c);
29 bool operator==(lyx::docstring const & d, char const * c)
30 { return lyx::operator ==(d, c); }
39 GuiHyperlink::GuiHyperlink(GuiView & lv)
40 : GuiDialog(lv, "href", qt_("Hyperlink")),
41 params_(insetCode("href"))
45 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
46 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
47 connect(targetED, SIGNAL(textChanged(const QString &)),
48 this, SLOT(changed_adaptor()));
49 connect(nameED, SIGNAL(textChanged(const QString &)),
50 this, SLOT(changed_adaptor()));
51 connect(webRB, SIGNAL(clicked()),
52 this, SLOT(changed_adaptor()));
53 connect(emailRB, SIGNAL(clicked()),
54 this, SLOT(changed_adaptor()));
55 connect(fileRB, SIGNAL(clicked()),
56 this, SLOT(changed_adaptor()));
58 setFocusProxy(targetED);
60 bc().setPolicy(ButtonPolicy::OkCancelReadOnlyPolicy);
63 bc().setCancel(closePB);
64 bc().addReadOnly(targetED);
65 bc().addReadOnly(nameED);
66 bc().addReadOnly(webRB);
67 bc().addReadOnly(emailRB);
68 bc().addReadOnly(fileRB);
72 void GuiHyperlink::changed_adaptor()
78 void GuiHyperlink::paramsToDialog(InsetCommandParams const & /*icp*/)
80 targetED->setText(toqstr(params_["target"]));
81 nameED->setText(toqstr(params_["name"]));
82 if (params_["type"] == "")
83 webRB->setChecked(true);
84 else if (params_["type"] == "mailto:")
85 emailRB->setChecked(true);
86 else if (params_["type"] == "file:")
87 fileRB->setChecked(true);
88 bc().setValid(isValid());
92 void GuiHyperlink::applyView()
94 params_["target"] = qstring_to_ucs4(targetED->text());
95 params_["name"] = qstring_to_ucs4(nameED->text());
96 if (webRB->isChecked())
97 params_["type"] = qstring_to_ucs4("");
98 else if (emailRB->isChecked())
99 params_["type"] = qstring_to_ucs4("mailto:");
100 else if (fileRB->isChecked())
101 params_["type"] = qstring_to_ucs4("file:");
102 params_.setCmdName("href");
106 bool GuiHyperlink::isValid()
108 return !targetED->text().isEmpty() || !nameED->text().isEmpty();
112 bool GuiHyperlink::initialiseParams(std::string const & data)
114 // The name passed with LFUN_INSET_APPLY is also the name
115 // used to identify the mailer.
116 InsetCommand::string2params("href", data, params_);
117 paramsToDialog(params_);
122 void GuiHyperlink::dispatchParams()
124 std::string const lfun = InsetCommand::params2string("href", params_);
125 dispatch(FuncRequest(getLfun(), lfun));
129 Dialog * createGuiHyperlink(GuiView & lv) { return new GuiHyperlink(lv); }
132 } // namespace frontend
136 #include "moc_GuiHyperlink.cpp"