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