]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiHyperlink.cpp
063bce724ee924c493fa2f9baaef349b4e3d927a
[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 <QCloseEvent>
22 #include <QLineEdit>
23 #include <QPushButton>
24
25
26 namespace lyx {
27 namespace frontend {
28
29 GuiHyperlink::GuiHyperlink(GuiView & lv)
30         : GuiCommand(lv, "href",qt_("Hyperlink"))
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().setOK(okPB);
50         bc().setCancel(closePB);
51         bc().addReadOnly(targetED);
52         bc().addReadOnly(nameED);
53         bc().addReadOnly(webRB);
54         bc().addReadOnly(emailRB);
55         bc().addReadOnly(fileRB);
56 }
57
58
59 void GuiHyperlink::changed_adaptor()
60 {
61         changed();
62 }
63
64
65 void GuiHyperlink::updateContents()
66 {
67         targetED->setText(toqstr(params_["target"]));
68         nameED->setText(toqstr(params_["name"]));
69         if (params_["type"] == "")
70                 webRB->setChecked(true);
71         else if (params_["type"] == "mailto:")
72                 emailRB->setChecked(true);
73         else if (params_["type"] == "file:")
74                 fileRB->setChecked(true);
75         bc().setValid(isValid());
76 }
77
78
79 void GuiHyperlink::applyView()
80 {
81         params_["target"] = qstring_to_ucs4(targetED->text());
82         params_["name"] = qstring_to_ucs4(nameED->text());
83         if (webRB->isChecked())
84                 params_["type"] = qstring_to_ucs4("");
85         else if (emailRB->isChecked())
86                 params_["type"] = qstring_to_ucs4("mailto:");
87         else if (fileRB->isChecked())
88                 params_["type"] = qstring_to_ucs4("file:");
89         params_.setCmdName("href");
90 }
91
92
93 bool GuiHyperlink::isValid()
94 {
95         QString const u = targetED->text();
96         QString const n = nameED->text();
97
98         return !u.isEmpty() || !n.isEmpty();
99 }
100
101
102 Dialog * createGuiHyperlink(GuiView & lv) { return new GuiHyperlink(lv); }
103
104
105 } // namespace frontend
106 } // namespace lyx
107
108
109 #include "GuiHyperlink_moc.cpp"