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