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