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