]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QURL.C
reverse last change
[lyx.git] / src / frontends / qt2 / QURL.C
1 /**
2  * \file QURL.C
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 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "ControlUrl.h"
18 #include "debug.h"
19 #include "qt_helpers.h"
20
21 #include "QURL.h"
22 #include "QURLDialog.h"
23 #include "Qt2BC.h"
24
25 #include <qcheckbox.h>
26 #include <qpushbutton.h>
27 #include <qlineedit.h>
28
29 typedef Qt2CB<ControlUrl, Qt2DB<QURLDialog> > base_class;
30
31
32 QURL::QURL()
33         : base_class(qt_("URL"))
34 {
35 }
36
37
38 void QURL::build_dialog()
39 {
40         dialog_.reset(new QURLDialog(this));
41
42         bc().setOK(dialog_->okPB);
43         bc().setCancel(dialog_->closePB);
44         bc().addReadOnly(dialog_->urlED);
45         bc().addReadOnly(dialog_->nameED);
46         bc().addReadOnly(dialog_->hyperlinkCB);
47 }
48
49
50 void QURL::update_contents()
51 {
52         InsetCommandParams const & params = controller().params();
53
54         dialog_->urlED->setText(toqstr(params.getContents()));
55         dialog_->nameED->setText(toqstr(params.getOptions()));
56         dialog_->hyperlinkCB->setChecked(params.getCmdName() != "url");
57         
58         bc().valid(isValid());
59 }
60
61
62 void QURL::apply()
63 {
64         InsetCommandParams & params = controller().params();
65
66         params.setContents(fromqstr(dialog_->urlED->text()));
67         params.setOptions(fromqstr(dialog_->nameED->text()));
68
69         if (dialog_->hyperlinkCB->isChecked())
70                 params.setCmdName("htmlurl");
71         else
72                 params.setCmdName("url");
73 }
74
75
76 bool QURL::isValid()
77 {
78         string const u(fromqstr(dialog_->urlED->text()));
79         string const n(fromqstr(dialog_->nameED->text()));
80
81         return !u.empty() || !n.empty();
82 }