]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiHyperlink.cpp
PrefShortcuts: ShortcutEdit, adapted from Edwin's patch
[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(urlED, SIGNAL(textChanged(const QString &)),
38                 this, SLOT(changed_adaptor()));
39         connect(nameED, SIGNAL(textChanged(const QString &)),
40                 this, SLOT(changed_adaptor()));
41
42         setFocusProxy(urlED);
43
44         bc().setOK(okPB);
45         bc().setCancel(closePB);
46         bc().addReadOnly(urlED);
47         bc().addReadOnly(nameED);
48 }
49
50
51 void GuiHyperlink::changed_adaptor()
52 {
53         changed();
54 }
55
56
57 void GuiHyperlink::closeEvent(QCloseEvent * e)
58 {
59         slotClose();
60         e->accept();
61 }
62
63
64 void GuiHyperlink::updateContents()
65 {
66         urlED->setText(toqstr(params_["target"]));
67         nameED->setText(toqstr(params_["name"]));
68         bc().setValid(isValid());
69 }
70
71
72 void GuiHyperlink::applyView()
73 {
74         params_["target"] = qstring_to_ucs4(urlED->text());
75         params_["name"] = qstring_to_ucs4(nameED->text());
76         params_.setCmdName("href");
77 }
78
79
80 bool GuiHyperlink::isValid()
81 {
82         QString const u = urlED->text();
83         QString const n = nameED->text();
84
85         return !u.isEmpty() || !n.isEmpty();
86 }
87
88
89 Dialog * createGuiHyperlink(LyXView & lv) { return new GuiHyperlink(lv); }
90
91
92 } // namespace frontend
93 } // namespace lyx
94
95
96 #include "GuiHyperlink_moc.cpp"