]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiIndex.cpp
2fcbbe57110ecc839ac07637ed164aa4c4ddba76
[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 GuiIndexDialogBase::GuiIndexDialogBase(LyXView & lv,
32                 docstring const & title, QString const & label)
33         : GuiDialog(lv, "index")
34 {
35         label_ = label;
36         setupUi(this);
37         setViewTitle(title);
38         setController(new ControlCommand(*this, "index", "index"));
39
40         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
41         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
42         connect(keywordED, SIGNAL(textChanged(const QString &)),
43                 this, SLOT(change_adaptor()));
44
45         setFocusProxy(keywordED);
46
47         keywordLA->setText(label_);
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         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
66         bc().setOK(okPB);
67         bc().setCancel(closePB);
68         bc().addReadOnly(keywordED);
69 }
70
71
72 ControlCommand & GuiIndexDialogBase::controller() const
73 {
74         return static_cast<ControlCommand &>(Dialog::controller());
75 }
76
77
78 void GuiIndexDialogBase::change_adaptor()
79 {
80         changed();
81 }
82
83
84 void GuiIndexDialogBase::reject()
85 {
86         slotClose();
87 }
88
89
90 void GuiIndexDialogBase::closeEvent(QCloseEvent * e)
91 {
92         slotWMHide();
93         e->accept();
94 }
95
96
97 void GuiIndexDialogBase::update_contents()
98 {
99         docstring const contents = controller().params()["name"];
100         keywordED->setText(toqstr(contents));
101         bc().setValid(!contents.empty());
102 }
103
104
105 void GuiIndexDialogBase::applyView()
106 {
107         controller().params()["name"] = qstring_to_ucs4(keywordED->text());
108 }
109
110
111 bool GuiIndexDialogBase::isValid()
112 {
113         return !keywordED->text().isEmpty();
114 }
115
116 } // namespace frontend
117 } // namespace lyx
118
119 #include "GuiIndex_moc.cpp"