]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiURL.cpp
This is the last of a series of patches that merges the layout modules development...
[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 John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "GuiURL.h"
14
15 #include "ControlCommand.h"
16 #include "qt_helpers.h"
17
18 #include <QCheckBox>
19 #include <QCloseEvent>
20 #include <QLineEdit>
21 #include <QPushButton>
22
23
24 namespace lyx {
25 namespace frontend {
26
27 GuiURLDialog::GuiURLDialog(LyXView & lv)
28         : GuiDialog(lv, "url")
29 {
30         setupUi(this);
31         setViewTitle( _("URL"));
32         setController(new ControlCommand(*this, "url", "url"));
33
34         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
35         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
36         connect(urlED, SIGNAL(textChanged(const QString &)),
37                 this, SLOT(changed_adaptor()));
38         connect(hyperlinkCB, SIGNAL(clicked()),
39                 this, SLOT(changed_adaptor()));
40         connect(nameED, SIGNAL(textChanged(const QString &)),
41                 this, SLOT(changed_adaptor()));
42
43         setFocusProxy(urlED);
44
45         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
46         bc().setOK(okPB);
47         bc().setCancel(closePB);
48         bc().addReadOnly(urlED);
49         bc().addReadOnly(nameED);
50         bc().addReadOnly(hyperlinkCB);
51 }
52
53
54 ControlCommand & GuiURLDialog::controller()
55 {
56         return static_cast<ControlCommand &>(GuiDialog::controller());
57 }
58
59
60 void GuiURLDialog::changed_adaptor()
61 {
62         changed();
63 }
64
65
66 void GuiURLDialog::closeEvent(QCloseEvent * e)
67 {
68         slotClose();
69         e->accept();
70 }
71
72
73
74 void GuiURLDialog::updateContents()
75 {
76         InsetCommandParams const & params = controller().params();
77
78         urlED->setText(toqstr(params["target"]));
79         nameED->setText(toqstr(params["name"]));
80         hyperlinkCB->setChecked(params.getCmdName() != "url");
81
82         bc().setValid(isValid());
83 }
84
85
86 void GuiURLDialog::applyView()
87 {
88         InsetCommandParams & params = controller().params();
89
90         params["target"] = qstring_to_ucs4(urlED->text());
91         params["name"] = qstring_to_ucs4(nameED->text());
92
93         if (hyperlinkCB->isChecked())
94                 params.setCmdName("htmlurl");
95         else
96                 params.setCmdName("url");
97 }
98
99
100 bool GuiURLDialog::isValid()
101 {
102         QString const u = urlED->text();
103         QString const n = nameED->text();
104
105         return !u.isEmpty() || !n.isEmpty();
106 }
107
108 } // namespace frontend
109 } // namespace lyx
110
111
112 #include "GuiURL_moc.cpp"