]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiHyperlink.cpp
Complete the removal of the embedding stuff. Maybe. It's hard to be sure we got every...
[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         : GuiCommand(lv, "href",qt_("Hyperlink"))
30 {
31         setupUi(this);
32
33         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
34         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
35         connect(targetED, SIGNAL(textChanged(const QString &)),
36                 this, SLOT(changed_adaptor()));
37         connect(nameED, SIGNAL(textChanged(const QString &)),
38                 this, SLOT(changed_adaptor()));
39         connect(webRB, SIGNAL(clicked()),
40                 this, SLOT(changed_adaptor()));
41         connect(emailRB, SIGNAL(clicked()),
42                 this, SLOT(changed_adaptor()));
43         connect(fileRB, SIGNAL(clicked()),
44                 this, SLOT(changed_adaptor()));
45
46         setFocusProxy(targetED);
47
48         bc().setOK(okPB);
49         bc().setCancel(closePB);
50         bc().addReadOnly(targetED);
51         bc().addReadOnly(nameED);
52         bc().addReadOnly(webRB);
53         bc().addReadOnly(emailRB);
54         bc().addReadOnly(fileRB);
55 }
56
57
58 void GuiHyperlink::changed_adaptor()
59 {
60         changed();
61 }
62
63
64 void GuiHyperlink::updateContents()
65 {
66         targetED->setText(toqstr(params_["target"]));
67         nameED->setText(toqstr(params_["name"]));
68         if (params_["type"] == "")
69                 webRB->setChecked(true);
70         else if (params_["type"] == "mailto:")
71                 emailRB->setChecked(true);
72         else if (params_["type"] == "file:")
73                 fileRB->setChecked(true);
74         bc().setValid(isValid());
75 }
76
77
78 void GuiHyperlink::applyView()
79 {
80         params_["target"] = qstring_to_ucs4(targetED->text());
81         params_["name"] = qstring_to_ucs4(nameED->text());
82         if (webRB->isChecked())
83                 params_["type"] = qstring_to_ucs4("");
84         else if (emailRB->isChecked())
85                 params_["type"] = qstring_to_ucs4("mailto:");
86         else if (fileRB->isChecked())
87                 params_["type"] = qstring_to_ucs4("file:");
88         params_.setCmdName("href");
89 }
90
91
92 bool GuiHyperlink::isValid()
93 {
94         QString const u = targetED->text();
95         QString const n = nameED->text();
96
97         return !u.isEmpty() || !n.isEmpty();
98 }
99
100
101 Dialog * createGuiHyperlink(GuiView & lv) { return new GuiHyperlink(lv); }
102
103
104 } // namespace frontend
105 } // namespace lyx
106
107
108 #include "GuiHyperlink_moc.cpp"