]> git.lyx.org Git - features.git/blob - src/frontends/qt4/GuiURL.cpp
518987cfa1a58a98b1c3bd3f0a2c621b3c725b73
[features.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 #include "Qt2BC.h"
15 #include "qt_helpers.h"
16 #include "ButtonController.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(UrlView * form)
28         : form_(form)
29 {
30         setupUi(this);
31
32         connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
33         connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
34         connect(urlED, SIGNAL(textChanged(const QString &)),
35                 this, SLOT(changed_adaptor()));
36         connect(hyperlinkCB, SIGNAL(clicked()),
37                 this, SLOT(changed_adaptor()));
38         connect(nameED, SIGNAL(textChanged(const QString &)),
39                 this, SLOT(changed_adaptor()));
40
41         setFocusProxy(urlED);
42 }
43
44
45 void GuiURLDialog::changed_adaptor()
46 {
47         form_->changed();
48 }
49
50
51 void GuiURLDialog::closeEvent(QCloseEvent * e)
52 {
53         form_->slotWMHide();
54         e->accept();
55 }
56
57
58
59 UrlView::UrlView(Dialog & parent)
60         : GuiView<GuiURLDialog>(parent, _("URL"))
61 {
62 }
63
64
65 void UrlView::build_dialog()
66 {
67         dialog_.reset(new GuiURLDialog(this));
68
69         bcview().setOK(dialog_->okPB);
70         bcview().setCancel(dialog_->closePB);
71         bcview().addReadOnly(dialog_->urlED);
72         bcview().addReadOnly(dialog_->nameED);
73         bcview().addReadOnly(dialog_->hyperlinkCB);
74 }
75
76
77 void UrlView::update_contents()
78 {
79         InsetCommandParams const & params = controller().params();
80
81         dialog_->urlED->setText(toqstr(params["target"]));
82         dialog_->nameED->setText(toqstr(params["name"]));
83         dialog_->hyperlinkCB->setChecked(params.getCmdName() != "url");
84
85         bc().valid(isValid());
86 }
87
88
89 void UrlView::apply()
90 {
91         InsetCommandParams & params = controller().params();
92
93         params["target"] = qstring_to_ucs4(dialog_->urlED->text());
94         params["name"] = qstring_to_ucs4(dialog_->nameED->text());
95
96         if (dialog_->hyperlinkCB->isChecked())
97                 params.setCmdName("htmlurl");
98         else
99                 params.setCmdName("url");
100 }
101
102
103 bool UrlView::isValid()
104 {
105         QString const u = dialog_->urlED->text();
106         QString const n = dialog_->nameED->text();
107
108         return !u.isEmpty() || !n.isEmpty();
109 }
110
111 } // namespace frontend
112 } // namespace lyx
113
114
115 #include "GuiURL_moc.cpp"