]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiLabel.cpp
8a4a7c26fa99ba6e774c6da49ff9d64b9fa5f2a4
[lyx.git] / src / frontends / qt4 / GuiLabel.cpp
1 /**
2  * \file GuiLabel.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 "GuiLabel.h"
14
15 #include "FuncRequest.h"
16 #include "qt_helpers.h"
17
18 #include "support/debug.h"
19 #include "insets/InsetCommand.h"
20
21 #include <QLabel>
22 #include <QPushButton>
23 #include <QLineEdit>
24
25 using namespace std;
26
27 namespace lyx {
28 namespace frontend {
29
30 /////////////////////////////////////////////////////////////////
31 //
32 // GuiLabel
33 //
34 /////////////////////////////////////////////////////////////////
35
36 GuiLabel::GuiLabel(GuiView & lv)
37         : GuiDialog(lv, "label", qt_("Label")),
38           params_(insetCode("label"))
39 {
40         setupUi(this);
41
42         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
43         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
44         connect(keywordED, SIGNAL(textChanged(const QString &)),
45                 this, SLOT(change_adaptor()));
46
47         setFocusProxy(keywordED);
48
49         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
50         bc().setOK(okPB);
51         bc().setCancel(closePB);
52         bc().addReadOnly(keywordED);
53 }
54
55
56 void GuiLabel::change_adaptor()
57 {
58         changed();
59 }
60
61
62 void GuiLabel::reject()
63 {
64         slotClose();
65 }
66
67
68 void GuiLabel::updateContents()
69 {
70         docstring const contents = params_["name"];
71         keywordED->setText(toqstr(contents));
72         bc().setValid(!contents.empty());
73 }
74
75
76 void GuiLabel::applyView()
77 {
78         params_["name"] = qstring_to_ucs4(keywordED->text());
79 }
80
81
82 bool GuiLabel::isValid()
83 {
84         return !keywordED->text().isEmpty();
85 }
86
87
88 bool GuiLabel::initialiseParams(std::string const & data)
89 {
90         InsetCommand::string2params("label", data, params_);
91         return true;
92 }
93
94
95 void GuiLabel::dispatchParams()
96 {
97         std::string const lfun = InsetCommand::params2string("label", params_);
98         dispatch(FuncRequest(getLfun(), lfun));
99 }
100
101
102 Dialog * createGuiLabel(GuiView & lv) { return new GuiLabel(lv); }
103
104
105 } // namespace frontend
106 } // namespace lyx
107
108 #include "moc_GuiLabel.cpp"