]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiIndex.cpp
cebac4debdeab5068809c3fa7430221cc72ed156
[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 "debug.h"
14 #include "qt_helpers.h"
15
16 #include "GuiIndex.h"
17 #include "Qt2BC.h"
18 #include "ButtonController.h"
19
20 #include <QLabel>
21 #include <QPushButton>
22 #include <QLineEdit>
23 #include <QCloseEvent>
24
25
26 using std::string;
27
28 /////////////////////////////////////////////////////////////////////
29 //
30 // GuiIndexDialog
31 //
32 /////////////////////////////////////////////////////////////////////
33
34 namespace lyx {
35 namespace frontend {
36
37 GuiIndexDialog::GuiIndexDialog(GuiIndex * form)
38         : form_(form)
39 {
40         setupUi(this);
41
42         connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
43         connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
44         connect(keywordED, SIGNAL(textChanged(const QString &)),
45                 this, SLOT(change_adaptor()));
46
47         setFocusProxy(keywordED);
48
49         keywordED->setWhatsThis( qt_(
50                 "The format of the entry in the index.\n"
51                 "\n"
52                 "An entry can be specified as a sub-entry of\n"
53                 "another with \"!\":\n"
54                 "\n"
55                 "cars!mileage\n"
56                 "\n"
57                 "You can cross-refer to another entry like so:\n"
58                 "\n"
59                 "cars!mileage|see{economy}\n"
60                 "\n"
61                 "For further details refer to the local LaTeX\n"
62                 "documentation.\n")
63         );
64 }
65
66
67 void GuiIndexDialog::change_adaptor()
68 {
69         form_->changed();
70 }
71
72
73 void GuiIndexDialog::reject()
74 {
75         form_->slotClose();
76 }
77
78
79 void GuiIndexDialog::closeEvent(QCloseEvent * e)
80 {
81         form_->slotWMHide();
82         e->accept();
83 }
84
85
86 /////////////////////////////////////////////////////////////////////
87 //
88 // GuiIndex
89 //
90 /////////////////////////////////////////////////////////////////////
91
92
93 GuiIndex::GuiIndex(Dialog & parent, docstring const & title, QString const & label)
94         : GuiView<GuiIndexDialog>(parent, title), label_(label)
95 {
96 }
97
98
99 void GuiIndex::build_dialog()
100 {
101         dialog_.reset(new GuiIndexDialog(this));
102
103         dialog_->keywordLA->setText(label_);
104
105         bcview().setOK(dialog_->okPB);
106         bcview().setCancel(dialog_->closePB);
107         bcview().addReadOnly(dialog_->keywordED);
108 }
109
110
111 void GuiIndex::update_contents()
112 {
113         docstring const contents = controller().params()["name"];
114         dialog_->keywordED->setText(toqstr(contents));
115
116         bc().valid(!contents.empty());
117 }
118
119
120 void GuiIndex::apply()
121 {
122         controller().params()["name"] = qstring_to_ucs4(dialog_->keywordED->text());
123 }
124
125
126 bool GuiIndex::isValid()
127 {
128         return !dialog_->keywordED->text().isEmpty();
129 }
130
131 } // namespace frontend
132 } // namespace lyx
133
134 #include "GuiIndex_moc.cpp"