]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiHyperlink.cpp
* fix spelling in comments to please John.
[lyx.git] / src / frontends / qt4 / GuiHyperlink.cpp
1 /**
2  * \file GuiHyperlink.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiHyperlink.h"
15
16 #include "qt_helpers.h"
17 #include "FuncRequest.h"
18 #include "insets/InsetCommand.h"
19
20 #include <QCheckBox>
21 #include <QLineEdit>
22 #include <QPushButton>
23
24
25 namespace lyx {
26 namespace frontend {
27
28 GuiHyperlink::GuiHyperlink(GuiView & lv)
29         : GuiDialog(lv, "href", qt_("Hyperlink")),
30     params_(insetCode("href"))
31 {
32         setupUi(this);
33
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()));
46
47         setFocusProxy(targetED);
48
49         bc().setPolicy(ButtonPolicy::OkCancelReadOnlyPolicy);
50
51         bc().setOK(okPB);
52         bc().setCancel(closePB);
53         bc().addReadOnly(targetED);
54         bc().addReadOnly(nameED);
55         bc().addReadOnly(webRB);
56         bc().addReadOnly(emailRB);
57         bc().addReadOnly(fileRB);
58 }
59
60
61 void GuiHyperlink::changed_adaptor()
62 {
63         changed();
64 }
65
66
67 void GuiHyperlink::paramsToDialog(InsetCommandParams const & /*icp*/)
68 {
69         targetED->setText(toqstr(params_["target"]));
70         nameED->setText(toqstr(params_["name"]));
71         if (params_["type"] == "")
72                 webRB->setChecked(true);
73         else if (params_["type"] == "mailto:")
74                 emailRB->setChecked(true);
75         else if (params_["type"] == "file:")
76                 fileRB->setChecked(true);
77         bc().setValid(isValid());
78 }
79
80
81 void GuiHyperlink::applyView()
82 {
83         params_["target"] = qstring_to_ucs4(targetED->text());
84         params_["name"] = qstring_to_ucs4(nameED->text());
85         if (webRB->isChecked())
86                 params_["type"] = qstring_to_ucs4("");
87         else if (emailRB->isChecked())
88                 params_["type"] = qstring_to_ucs4("mailto:");
89         else if (fileRB->isChecked())
90                 params_["type"] = qstring_to_ucs4("file:");
91         params_.setCmdName("href");
92 }
93
94
95 bool GuiHyperlink::isValid()
96 {
97         return !targetED->text().isEmpty() || !nameED->text().isEmpty();
98 }
99
100
101 bool GuiHyperlink::initialiseParams(std::string const & data)
102 {
103         // The name passed with LFUN_INSET_APPLY is also the name
104         // used to identify the mailer.
105         InsetCommand::string2params("href", data, params_);
106         paramsToDialog(params_);
107         return true;
108 }
109
110
111 void GuiHyperlink::dispatchParams()
112 {
113         std::string const lfun = InsetCommand::params2string("href", params_);
114         dispatch(FuncRequest(getLfun(), lfun));
115 }
116
117
118 Dialog * createGuiHyperlink(GuiView & lv) { return new GuiHyperlink(lv); }
119
120
121 } // namespace frontend
122 } // namespace lyx
123
124
125 #include "moc_GuiHyperlink.cpp"