]> git.lyx.org Git - features.git/blob - src/frontends/qt/GuiIndex.cpp
Fix broken Apple speller interface
[features.git] / src / frontends / qt / 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 Angus Leeming
7  * \author Martin Vermeer
8  * \author Jürgen Spitzmüller
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "GuiIndex.h"
16
17 #include "qt_helpers.h"
18
19 #include "Buffer.h"
20 #include "BufferParams.h"
21 #include "FuncRequest.h"
22 #include "IndicesList.h"
23 #include "insets/InsetIndex.h"
24
25 #include <QPushButton>
26
27 using namespace std;
28
29 namespace lyx {
30 namespace frontend {
31
32 GuiIndex::GuiIndex(GuiView & lv)
33         : GuiDialog(lv, "index", qt_("Index Entry Settings"))
34 {
35         setupUi(this);
36
37         connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
38                 this, SLOT(slotButtonBox(QAbstractButton *)));
39         connect(indicesCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
40
41         rangeCO->addItem(qt_("None"), InsetIndexParams::None);
42         rangeCO->addItem(qt_("Start"), InsetIndexParams::Start);
43         rangeCO->addItem(qt_("End"), InsetIndexParams::End);
44         connect(rangeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
45
46         pageFormatCO->addItem(qt_("Default"), toqstr("default"));
47         pageFormatCO->addItem(qt_("Bold"), toqstr("textbf"));
48         pageFormatCO->addItem(qt_("Italic"), toqstr("textit"));
49         pageFormatCO->addItem(qt_("Emphasized"), toqstr("emph"));
50         pageFormatCO->addItem(qt_("Custom"), toqstr("custom"));
51         connect(pageFormatCO, SIGNAL(activated(int)), this, SLOT(pageFormatChanged(int)));
52
53         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
54         bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
55         bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
56 }
57
58
59 void GuiIndex::change_adaptor()
60 {
61         changed();
62 }
63
64
65 void GuiIndex::pageFormatChanged(int i)
66 {
67         QString const pf = pageFormatCO->itemData(i).toString();
68         pageFormatLE->setEnabled(pf == "custom");
69         change_adaptor();
70 }
71
72
73 void GuiIndex::updateContents()
74 {
75         typedef IndicesList::const_iterator const_iterator;
76
77         BufferParams const & bp = buffer().masterBuffer()->params();
78         indicesGB->setEnabled(bp.use_indices);
79
80         QString const pf = pageFormatCO->itemData(
81                 pageFormatCO->currentIndex()).toString();
82         pageFormatLE->setEnabled(pf == "custom");
83
84         IndicesList const & indiceslist = bp.indiceslist();
85         docstring const cur_index = params_.index;
86
87         indicesCO->clear();
88
89         const_iterator const begin = indiceslist.begin();
90         const_iterator const end = indiceslist.end();
91         for (const_iterator it = begin; it != end; ++it)
92                 indicesCO->addItem(toqstr(it->index()),
93                         QVariant(toqstr(it->shortcut())));
94
95         int pos = indicesCO->findData(toqstr(cur_index));
96         indicesCO->setCurrentIndex(pos);
97
98         pos = pageFormatCO->findData(toqstr(params_.pagefmt));
99         if (pos == -1) {
100                 pos = pageFormatCO->findData("custom");
101                 pageFormatLE->setText(toqstr(params_.pagefmt));
102         } else
103                 pageFormatLE->clear();
104         pageFormatCO->setCurrentIndex(pos);
105
106         pos = rangeCO->findData(params_.range);
107         rangeCO->setCurrentIndex(pos);
108 }
109
110
111 void GuiIndex::applyView()
112 {
113         QString const index = indicesCO->itemData(
114                 indicesCO->currentIndex()).toString();
115         int const range = rangeCO->itemData(
116                 rangeCO->currentIndex()).toInt();
117         QString const pagefmt = pageFormatCO->itemData(
118                 pageFormatCO->currentIndex()).toString();
119         params_.index = qstring_to_ucs4(index);
120         params_.range = InsetIndexParams::PageRange(range);
121         params_.pagefmt = (pagefmt == "custom") 
122                         ? fromqstr(pageFormatLE->text())
123                         : fromqstr(pagefmt);
124 }
125
126
127 bool GuiIndex::initialiseParams(string const & sdata)
128 {
129         InsetIndex::string2params(sdata, params_);
130         return true;
131 }
132
133
134 void GuiIndex::clearParams()
135 {
136         params_ = InsetIndexParams();
137 }
138
139
140 void GuiIndex::dispatchParams()
141 {
142         dispatch(FuncRequest(getLfun(), InsetIndex::params2string(params_)));
143 }
144
145
146 } // namespace frontend
147 } // namespace lyx
148
149 #include "moc_GuiIndex.cpp"