]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt/GuiIndex.cpp
Make code a bit easier to read
[lyx.git] / src / frontends / qt / GuiIndex.cpp
index a59ac3953f27222cda4b910d5ac717a7a55330fb..5e145808e6d0091970d7423665452518ab3e5f66 100644 (file)
@@ -20,6 +20,7 @@
 #include "BufferParams.h"
 #include "FuncRequest.h"
 #include "IndicesList.h"
+#include "insets/InsetIndex.h"
 
 #include <QPushButton>
 
@@ -37,6 +38,18 @@ GuiIndex::GuiIndex(GuiView & lv)
                this, SLOT(slotButtonBox(QAbstractButton *)));
        connect(indicesCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
 
+       rangeCO->addItem(qt_("None"), InsetIndexParams::None);
+       rangeCO->addItem(qt_("Start"), InsetIndexParams::Start);
+       rangeCO->addItem(qt_("End"), InsetIndexParams::End);
+       connect(rangeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
+
+       pageFormatCO->addItem(qt_("Default"), toqstr("default"));
+       pageFormatCO->addItem(qt_("Bold"), toqstr("textbf"));
+       pageFormatCO->addItem(qt_("Italic"), toqstr("textit"));
+       pageFormatCO->addItem(qt_("Emphasized"), toqstr("emph"));
+       pageFormatCO->addItem(qt_("Custom"), toqstr("custom"));
+       connect(pageFormatCO, SIGNAL(activated(int)), this, SLOT(pageFormatChanged(int)));
+
        bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
        bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
        bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
@@ -49,11 +62,26 @@ void GuiIndex::change_adaptor()
 }
 
 
+void GuiIndex::pageFormatChanged(int i)
+{
+       QString const pf = pageFormatCO->itemData(i).toString();
+       pageFormatLE->setEnabled(pf == "custom");
+       change_adaptor();
+}
+
+
 void GuiIndex::updateContents()
 {
        typedef IndicesList::const_iterator const_iterator;
 
-       IndicesList const & indiceslist = buffer().params().indiceslist();
+       BufferParams const & bp = buffer().masterBuffer()->params();
+       indicesGB->setEnabled(bp.use_indices);
+
+       QString const pf = pageFormatCO->itemData(
+               pageFormatCO->currentIndex()).toString();
+       pageFormatLE->setEnabled(pf == "custom");
+
+       IndicesList const & indiceslist = bp.indiceslist();
        docstring const cur_index = params_.index;
 
        indicesCO->clear();
@@ -64,8 +92,19 @@ void GuiIndex::updateContents()
                indicesCO->addItem(toqstr(it->index()),
                        QVariant(toqstr(it->shortcut())));
 
-       int const pos = indicesCO->findData(toqstr(cur_index));
+       int pos = indicesCO->findData(toqstr(cur_index));
        indicesCO->setCurrentIndex(pos);
+
+       pos = pageFormatCO->findData(toqstr(params_.pagefmt));
+       if (pos == -1) {
+               pos = pageFormatCO->findData("custom");
+               pageFormatLE->setText(toqstr(params_.pagefmt));
+       } else
+               pageFormatLE->clear();
+       pageFormatCO->setCurrentIndex(pos);
+
+       pos = rangeCO->findData(params_.range);
+       rangeCO->setCurrentIndex(pos);
 }
 
 
@@ -73,7 +112,15 @@ void GuiIndex::applyView()
 {
        QString const index = indicesCO->itemData(
                indicesCO->currentIndex()).toString();
+       int const range = rangeCO->itemData(
+               rangeCO->currentIndex()).toInt();
+       QString const pagefmt = pageFormatCO->itemData(
+               pageFormatCO->currentIndex()).toString();
        params_.index = qstring_to_ucs4(index);
+       params_.range = InsetIndexParams::PageRange(range);
+       params_.pagefmt = (pagefmt == "custom") 
+                       ? fromqstr(pageFormatLE->text())
+                       : fromqstr(pagefmt);
 }
 
 
@@ -96,9 +143,6 @@ void GuiIndex::dispatchParams()
 }
 
 
-Dialog * createGuiIndex(GuiView & lv) { return new GuiIndex(lv); }
-
-
 } // namespace frontend
 } // namespace lyx