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(LyXView & lv)
30 : GuiCommand(lv, "href")
33 setViewTitle( _("Hyperlink"));
35 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
36 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
37 connect(targetED, SIGNAL(textChanged(const QString &)),
38 this, SLOT(changed_adaptor()));
39 connect(nameED, SIGNAL(textChanged(const QString &)),
40 this, SLOT(changed_adaptor()));
41 connect(webRB, SIGNAL(clicked()),
42 this, SLOT(changed_adaptor()));
43 connect(emailRB, SIGNAL(clicked()),
44 this, SLOT(changed_adaptor()));
45 connect(fileRB, SIGNAL(clicked()),
46 this, SLOT(changed_adaptor()));
48 setFocusProxy(targetED);
51 bc().setCancel(closePB);
52 bc().addReadOnly(targetED);
53 bc().addReadOnly(nameED);
54 bc().addReadOnly(webRB);
55 bc().addReadOnly(emailRB);
56 bc().addReadOnly(fileRB);
60 void GuiHyperlink::changed_adaptor()
66 void GuiHyperlink::closeEvent(QCloseEvent * e)
73 void GuiHyperlink::updateContents()
75 targetED->setText(toqstr(params_["target"]));
76 nameED->setText(toqstr(params_["name"]));
77 if (params_["type"] == "")
78 webRB->setChecked(true);
79 else if (params_["type"] == "mailto:")
80 emailRB->setChecked(true);
81 else if (params_["type"] == "file:")
82 fileRB->setChecked(true);
83 bc().setValid(isValid());
87 void GuiHyperlink::applyView()
89 params_["target"] = qstring_to_ucs4(targetED->text());
90 params_["name"] = qstring_to_ucs4(nameED->text());
91 if (webRB->isChecked())
92 params_["type"] = qstring_to_ucs4("");
93 else if (emailRB->isChecked())
94 params_["type"] = qstring_to_ucs4("mailto:");
95 else if (fileRB->isChecked())
96 params_["type"] = qstring_to_ucs4("file:");
97 params_.setCmdName("href");
101 bool GuiHyperlink::isValid()
103 QString const u = targetED->text();
104 QString const n = nameED->text();
106 return !u.isEmpty() || !n.isEmpty();
110 Dialog * createGuiHyperlink(LyXView & lv) { return new GuiHyperlink(lv); }
113 } // namespace frontend
117 #include "GuiHyperlink_moc.cpp"