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(urlED, 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()));
51 bc().setCancel(closePB);
52 bc().addReadOnly(urlED);
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 urlED->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(urlED->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 = urlED->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"