]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/UrlView.C
enable Font cache only for MacOSX and inline width() for other platform.
[lyx.git] / src / frontends / qt4 / UrlView.C
1 /**
2  * \file UrlView.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 #include "UrlView.h"
14 #include "QURLDialog.h"
15 #include "Qt2BC.h"
16 #include "qt_helpers.h"
17
18 #include "controllers/ButtonController.h"
19 #include "controllers/ControlCommand.h"
20
21 #include <QCheckBox>
22 #include <QLineEdit>
23 #include <QPushButton>
24
25 using std::string;
26
27 namespace lyx {
28 namespace frontend {
29
30 typedef QController< ControlCommand, QView<QURLDialog> > base_class;
31
32 UrlView::UrlView(Dialog & parent)
33         : base_class(parent, lyx::to_utf8(_("URL")))
34 {
35 }
36
37
38 void UrlView::build_dialog()
39 {
40         dialog_.reset(new QURLDialog(this));
41
42         bcview().setOK(dialog_->okPB);
43         bcview().setCancel(dialog_->closePB);
44         bcview().addReadOnly(dialog_->urlED);
45         bcview().addReadOnly(dialog_->nameED);
46         bcview().addReadOnly(dialog_->hyperlinkCB);
47 }
48
49
50 void UrlView::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 UrlView::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 UrlView::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 }
83
84 } // namespace frontend
85 } // namespace lyx