]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiIndex.cpp
fix memory leaks
[lyx.git] / src / frontends / qt4 / GuiIndex.cpp
1 /**
2  * \file GuiIndex.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 "GuiIndex.h"
14
15 #include "support/debug.h"
16 #include "qt_helpers.h"
17
18 #include <QLabel>
19 #include <QPushButton>
20 #include <QLineEdit>
21 #include <QCloseEvent>
22
23 using std::string;
24
25
26 namespace lyx {
27 namespace frontend {
28
29 /////////////////////////////////////////////////////////////////
30 //
31 // Base implementation
32 //
33 /////////////////////////////////////////////////////////////////
34
35 GuiIndexDialogBase::GuiIndexDialogBase(GuiView & lv,
36                 docstring const & title, QString const & label, std::string const & name)
37         : GuiCommand(lv, name)
38 {
39         label_ = label;
40         setupUi(this);
41         setViewTitle(title);
42
43         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
44         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
45         connect(keywordED, SIGNAL(textChanged(const QString &)),
46                 this, SLOT(change_adaptor()));
47
48         setFocusProxy(keywordED);
49
50         keywordLA->setText(label_);
51
52         keywordED->setWhatsThis( qt_(
53                 "The format of the entry in the index.\n"
54                 "\n"
55                 "An entry can be specified as a sub-entry of\n"
56                 "another with \"!\":\n"
57                 "\n"
58                 "cars!mileage\n"
59                 "\n"
60                 "You can cross-refer to another entry like so:\n"
61                 "\n"
62                 "cars!mileage|see{economy}\n"
63                 "\n"
64                 "For further details refer to the local LaTeX\n"
65                 "documentation.\n")
66         );
67
68         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
69         bc().setOK(okPB);
70         bc().setCancel(closePB);
71         bc().addReadOnly(keywordED);
72 }
73
74
75 void GuiIndexDialogBase::change_adaptor()
76 {
77         changed();
78 }
79
80
81 void GuiIndexDialogBase::reject()
82 {
83         slotClose();
84 }
85
86
87 void GuiIndexDialogBase::closeEvent(QCloseEvent * e)
88 {
89         slotClose();
90         e->accept();
91 }
92
93
94 void GuiIndexDialogBase::updateContents()
95 {
96         docstring const contents = params_["name"];
97         keywordED->setText(toqstr(contents));
98         bc().setValid(!contents.empty());
99 }
100
101
102 void GuiIndexDialogBase::applyView()
103 {
104         params_["name"] = qstring_to_ucs4(keywordED->text());
105 }
106
107
108 bool GuiIndexDialogBase::isValid()
109 {
110         return !keywordED->text().isEmpty();
111 }
112
113
114 /////////////////////////////////////////////////////////////////
115 //
116 // Index Dialog
117 //
118 /////////////////////////////////////////////////////////////////
119
120
121 GuiIndex::GuiIndex(GuiView & lv)
122         : GuiIndexDialogBase(lv, _("Index Entry"), qt_("&Keyword:"), "index") 
123 {
124         keywordED->setWhatsThis( qt_(
125                 "The format of the entry in the index.\n"
126                 "\n"
127                 "An entry can be specified as a sub-entry of\n"
128                 "another with \"!\":\n"
129                 "\n"
130                 "cars!mileage\n"
131                 "\n"
132                 "You can cross-refer to another entry like so:\n"
133                 "\n"
134                 "cars!mileage|see{economy}\n"
135                 "\n"
136                 "For further details refer to the local LaTeX\n"
137                 "documentation.\n")
138         );
139 }
140
141
142 Dialog * createGuiIndex(GuiView & lv) { return new GuiIndex(lv); }
143
144
145 /////////////////////////////////////////////////////////////////
146 //
147 // Label Dialog
148 //
149 /////////////////////////////////////////////////////////////////
150
151 GuiLabel::GuiLabel(GuiView & lv)
152         : GuiIndexDialogBase(lv, _("Label"), qt_("&Label:"), "label")
153 {}
154
155
156 Dialog * createGuiLabel(GuiView & lv) { return new GuiLabel(lv); }
157
158
159 } // namespace frontend
160 } // namespace lyx
161
162 #include "GuiIndex_moc.cpp"