]> git.lyx.org Git - features.git/blob - src/frontends/qt4/GuiHyperlink.cpp
cmake: remove recursive call, even if it breaks merged builds with GCC
[features.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 #ifdef LYX_MERGED_BUILD
25 // GCC couldn't find operator==
26 namespace lyx {
27         bool operator==(lyx::docstring & d, char const * c);
28         namespace frontend {
29                 bool operator==(lyx::docstring & d, char const * c);
30         }
31 }
32 #endif
33
34
35 namespace lyx {
36 namespace frontend {
37
38 GuiHyperlink::GuiHyperlink(GuiView & lv)
39         : GuiDialog(lv, "href", qt_("Hyperlink")),
40     params_(insetCode("href"))
41 {
42         setupUi(this);
43
44         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
45         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
46         connect(targetED, SIGNAL(textChanged(const QString &)),
47                 this, SLOT(changed_adaptor()));
48         connect(nameED, SIGNAL(textChanged(const QString &)),
49                 this, SLOT(changed_adaptor()));
50         connect(webRB, SIGNAL(clicked()),
51                 this, SLOT(changed_adaptor()));
52         connect(emailRB, SIGNAL(clicked()),
53                 this, SLOT(changed_adaptor()));
54         connect(fileRB, SIGNAL(clicked()),
55                 this, SLOT(changed_adaptor()));
56
57         setFocusProxy(targetED);
58
59         bc().setPolicy(ButtonPolicy::OkCancelReadOnlyPolicy);
60
61         bc().setOK(okPB);
62         bc().setCancel(closePB);
63         bc().addReadOnly(targetED);
64         bc().addReadOnly(nameED);
65         bc().addReadOnly(webRB);
66         bc().addReadOnly(emailRB);
67         bc().addReadOnly(fileRB);
68 }
69
70
71 void GuiHyperlink::changed_adaptor()
72 {
73         changed();
74 }
75
76
77 void GuiHyperlink::paramsToDialog(InsetCommandParams const & /*icp*/)
78 {
79         targetED->setText(toqstr(params_["target"]));
80         nameED->setText(toqstr(params_["name"]));
81         if (params_["type"] == "")
82                 webRB->setChecked(true);
83         else if (params_["type"] == "mailto:")
84                 emailRB->setChecked(true);
85         else if (params_["type"] == "file:")
86                 fileRB->setChecked(true);
87         bc().setValid(isValid());
88 }
89
90
91 void GuiHyperlink::applyView()
92 {
93         params_["target"] = qstring_to_ucs4(targetED->text());
94         params_["name"] = qstring_to_ucs4(nameED->text());
95         if (webRB->isChecked())
96                 params_["type"] = qstring_to_ucs4("");
97         else if (emailRB->isChecked())
98                 params_["type"] = qstring_to_ucs4("mailto:");
99         else if (fileRB->isChecked())
100                 params_["type"] = qstring_to_ucs4("file:");
101         params_.setCmdName("href");
102 }
103
104
105 bool GuiHyperlink::isValid()
106 {
107         return !targetED->text().isEmpty() || !nameED->text().isEmpty();
108 }
109
110
111 bool GuiHyperlink::initialiseParams(std::string const & data)
112 {
113         // The name passed with LFUN_INSET_APPLY is also the name
114         // used to identify the mailer.
115         InsetCommand::string2params("href", data, params_);
116         paramsToDialog(params_);
117         return true;
118 }
119
120
121 void GuiHyperlink::dispatchParams()
122 {
123         std::string const lfun = InsetCommand::params2string("href", params_);
124         dispatch(FuncRequest(getLfun(), lfun));
125 }
126
127
128 Dialog * createGuiHyperlink(GuiView & lv) { return new GuiHyperlink(lv); }
129
130
131 } // namespace frontend
132 } // namespace lyx
133
134
135 #include "moc_GuiHyperlink.cpp"