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"
21 #include <QCloseEvent>
23 #include <QPushButton>
29 GuiHyperlink::GuiHyperlink(GuiView & lv)
30 : GuiCommand(lv, "href",qt_("Hyperlink"))
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::closeEvent(QCloseEvent * e)
72 void GuiHyperlink::updateContents()
74 targetED->setText(toqstr(params_["target"]));
75 nameED->setText(toqstr(params_["name"]));
76 if (params_["type"] == "")
77 webRB->setChecked(true);
78 else if (params_["type"] == "mailto:")
79 emailRB->setChecked(true);
80 else if (params_["type"] == "file:")
81 fileRB->setChecked(true);
82 bc().setValid(isValid());
86 void GuiHyperlink::applyView()
88 params_["target"] = qstring_to_ucs4(targetED->text());
89 params_["name"] = qstring_to_ucs4(nameED->text());
90 if (webRB->isChecked())
91 params_["type"] = qstring_to_ucs4("");
92 else if (emailRB->isChecked())
93 params_["type"] = qstring_to_ucs4("mailto:");
94 else if (fileRB->isChecked())
95 params_["type"] = qstring_to_ucs4("file:");
96 params_.setCmdName("href");
100 bool GuiHyperlink::isValid()
102 QString const u = targetED->text();
103 QString const n = nameED->text();
105 return !u.isEmpty() || !n.isEmpty();
109 Dialog * createGuiHyperlink(GuiView & lv) { return new GuiHyperlink(lv); }
112 } // namespace frontend
116 #include "GuiHyperlink_moc.cpp"