]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiPrintindex.cpp
Make string-widget combination more l7n friendly
[lyx.git] / src / frontends / qt / GuiPrintindex.cpp
1 /**
2  * \file GuiPrintindex.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 "GuiPrintindex.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
24 #include "support/lstrings.h"
25
26 #include "insets/InsetCommand.h"
27
28 #include <QPushButton>
29
30 using namespace std;
31 using namespace lyx::support;
32
33 namespace lyx {
34 namespace frontend {
35
36 GuiPrintindex::GuiPrintindex(GuiView & lv)
37         : GuiDialog(lv, "index_print", qt_("Index Settings")),
38           params_(insetCode("index_print"))
39 {
40         setupUi(this);
41
42         connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
43                 this, SLOT(slotButtonBox(QAbstractButton *)));
44         connect(indicesCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
45         connect(subindexCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
46         connect(literalCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
47
48         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
49         bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
50         bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
51 }
52
53
54 void GuiPrintindex::change_adaptor()
55 {
56         changed();
57 }
58
59
60 void GuiPrintindex::updateContents()
61 {
62         typedef IndicesList::const_iterator const_iterator;
63
64         IndicesList const & indiceslist = buffer().params().indiceslist();
65         docstring const cur_index = suffixIs(params_.getCmdName(), '*') ?
66                 from_ascii("printall") : params_["type"];
67
68         indicesCO->clear();
69
70         indicesCO->addItem(qt_("<All indexes>"),
71                         QVariant(QString("printall")));
72
73         const_iterator const begin = indiceslist.begin();
74         const_iterator const end = indiceslist.end();
75         for (const_iterator it = begin; it != end; ++it)
76                 indicesCO->addItem(toqstr(it->index()),
77                         QVariant(toqstr(it->shortcut())));
78
79         int const pos = indicesCO->findData(toqstr(cur_index));
80         indicesCO->setCurrentIndex(pos);
81         subindexCB->setChecked(params_.getCmdName() == "printsubindex");
82         literalCB->setChecked(params_["literal"] == "true");
83 }
84
85
86 void GuiPrintindex::applyView()
87 {
88         QString const index = indicesCO->itemData(
89                 indicesCO->currentIndex()).toString();
90         string cmd = "printindex";
91         if (subindexCB->isChecked())
92                 cmd = "printsubindex";
93         if (index == QString("printall"))
94                 cmd += '*';
95         params_.setCmdName(cmd);
96         if (index == QString("printall"))
97                 params_["type"] = docstring();
98         else
99                 params_["type"] = qstring_to_ucs4(index);
100         params_["literal"] = literalCB->isChecked()
101                         ? from_ascii("true") : from_ascii("false");
102 }
103
104
105 void GuiPrintindex::paramsToDialog(InsetCommandParams const & /*icp*/)
106 {
107         int const pos = suffixIs(params_.getCmdName(), '*') ?
108                 indicesCO->findData(QString("printall")) :
109                 indicesCO->findData(toqstr(params_["type"]));
110         subindexCB->setChecked(params_.getCmdName() == "printsubindex");
111         indicesCO->setCurrentIndex(pos);
112         literalCB->setChecked(params_["literal"] == "true");
113         bc().setValid(isValid());
114 }
115
116
117 bool GuiPrintindex::initialiseParams(string const & sdata)
118 {
119         // The name passed with LFUN_INSET_APPLY is also the name
120         // used to identify the mailer.
121         InsetCommand::string2params(sdata, params_);
122         paramsToDialog(params_);
123         return true;
124 }
125
126
127 void GuiPrintindex::dispatchParams()
128 {
129         std::string const lfun = InsetCommand::params2string(params_);
130         dispatch(FuncRequest(getLfun(), lfun));
131 }
132
133
134 } // namespace frontend
135 } // namespace lyx
136
137 #include "moc_GuiPrintindex.cpp"