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