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