]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiURL.cpp
math stuff
[lyx.git] / src / frontends / qt4 / GuiURL.cpp
1 /**
2  * \file GuiURL.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 "GuiURL.h"
15
16 #include "GuiURL.h"
17 #include "qt_helpers.h"
18 #include "FuncRequest.h"
19 #include "insets/InsetCommand.h"
20
21 #include <QCheckBox>
22 #include <QCloseEvent>
23 #include <QLineEdit>
24 #include <QPushButton>
25
26
27 namespace lyx {
28 namespace frontend {
29
30 GuiURL::GuiURL(LyXView & lv)
31         : GuiCommand(lv, "url")
32 {
33         setupUi(this);
34         setViewTitle( _("URL"));
35
36         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
37         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
38         connect(urlED, SIGNAL(textChanged(const QString &)),
39                 this, SLOT(changed_adaptor()));
40         connect(hyperlinkCB, SIGNAL(clicked()),
41                 this, SLOT(changed_adaptor()));
42         connect(nameED, SIGNAL(textChanged(const QString &)),
43                 this, SLOT(changed_adaptor()));
44
45         setFocusProxy(urlED);
46
47         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
48         bc().setOK(okPB);
49         bc().setCancel(closePB);
50         bc().addReadOnly(urlED);
51         bc().addReadOnly(nameED);
52         bc().addReadOnly(hyperlinkCB);
53 }
54
55
56 void GuiURL::changed_adaptor()
57 {
58         changed();
59 }
60
61
62 void GuiURL::closeEvent(QCloseEvent * e)
63 {
64         slotClose();
65         e->accept();
66 }
67
68
69
70 void GuiURL::updateContents()
71 {
72         urlED->setText(toqstr(params_["target"]));
73         nameED->setText(toqstr(params_["name"]));
74         hyperlinkCB->setChecked(params_.getCmdName() != "url");
75
76         bc().setValid(isValid());
77 }
78
79
80 void GuiURL::applyView()
81 {
82         params_["target"] = qstring_to_ucs4(urlED->text());
83         params_["name"] = qstring_to_ucs4(nameED->text());
84
85         if (hyperlinkCB->isChecked())
86                 params_.setCmdName("htmlurl");
87         else
88                 params_.setCmdName("url");
89 }
90
91
92 bool GuiURL::isValid()
93 {
94         QString const u = urlED->text();
95         QString const n = nameED->text();
96
97         return !u.isEmpty() || !n.isEmpty();
98 }
99
100
101 Dialog * createGuiURL(LyXView & lv) { return new GuiURL(lv); }
102
103
104 } // namespace frontend
105 } // namespace lyx
106
107
108 #include "GuiURL_moc.cpp"