]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiSymbols.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / GuiSymbols.cpp
index 145a2d20dd8397d09156611133f5d176a48f6a3d..ea863b49686fb03137119c61654346e836582305 100644 (file)
@@ -27,6 +27,8 @@
 #include "support/gettext.h"
 
 #include <QChar>
+#include <QDialogButtonBox>
+#include <QPushButton>
 #include <QString>
 
 #include <cstdio>
@@ -152,6 +154,7 @@ const int no_blocks = sizeof(unicode_blocks) / sizeof(UnicodeBlocks);
 QString getBlock(char_type c)
 {
        // store an educated guess for the next search
+       // 0 <= lastBlock < no_blocks
        // FIXME THREAD
        static int lastBlock = 0;
 
@@ -159,10 +162,6 @@ QString getBlock(char_type c)
        if (c < 0x7f)
                lastBlock = 0;
 
-       // off the end already
-       if (lastBlock == no_blocks)
-               return QString();
-
        // c falls into a covered area, and we can guess which
        if (c >= unicode_blocks[lastBlock].start
            && c <= unicode_blocks[lastBlock].end)
@@ -177,15 +176,25 @@ QString getBlock(char_type c)
        int i = 0;
        while (i < no_blocks && c > unicode_blocks[i].end)
                ++i;
-       if (i == no_blocks || c < unicode_blocks[i].start)
+
+       if (i == no_blocks)
+               return QString();
+
+       if (c < unicode_blocks[i].start) {
+               // 0 < i < no_blocks
+               // cache the previous block for guessing next time
+               lastBlock = i - 1;
                return QString();
+       }
+
+       // 0 <= i < no_blocks
        // cache the last block for guessing next time
        lastBlock = i;
        return unicode_blocks[lastBlock].qname;
 }
 
 
-} // namespace anon
+} // namespace
 
 
 /////////////////////////////////////////////////////////////////////
@@ -198,7 +207,7 @@ class GuiSymbols::Model : public QAbstractListModel
 {
 public:
        Model(GuiSymbols * parent)
-               : QAbstractListModel(parent)
+               : QAbstractListModel(parent), encoding_(0)
        {}
 
        QModelIndex index(int row, int column, QModelIndex const &) const
@@ -281,7 +290,7 @@ GuiSymbols::GuiSymbols(GuiView & lv)
 {
        setupUi(this);
 
-       //Translate names
+       // Translate names
        for (int i = 0 ; i < no_blocks; ++i)
                unicode_blocks[i].qname = qt_(unicode_blocks[i].name);
 
@@ -312,8 +321,8 @@ void GuiSymbols::updateView()
        chosenLE->clear();
 
        string new_encoding = bufferview()->cursor().getEncoding()->name();
-       if (buffer().params().inputenc != "auto" &&
-           buffer().params().inputenc != "default")
+       if (buffer().params().inputenc != "auto-legacy" &&
+           buffer().params().inputenc != "auto-legacy-plain")
                new_encoding = buffer().params().encoding().name();
        if (new_encoding == encoding_)
                // everything up to date
@@ -331,47 +340,58 @@ void GuiSymbols::updateView()
 void GuiSymbols::enableView(bool enable)
 {
        chosenLE->setEnabled(enable);
-       okPB->setEnabled(enable);
-       applyPB->setEnabled(enable);
+       buttonBox->button(QDialogButtonBox::Ok)->setEnabled(enable);
+       buttonBox->button(QDialogButtonBox::Apply)->setEnabled(enable);
+       if (enable)
+               buttonBox->button(QDialogButtonBox::Close)->setText(qt_("Cancel"));
+       else
+               buttonBox->button(QDialogButtonBox::Close)->setText(qt_("Close"));
 }
 
 
-void GuiSymbols::on_applyPB_clicked()
+void GuiSymbols::on_buttonBox_clicked(QAbstractButton * button)
 {
-       dispatchParams();
+       QDialogButtonBox * bbox = qobject_cast<QDialogButtonBox*>(sender());
+       switch (bbox->standardButton(button)) {
+       case QDialogButtonBox::Ok:
+               slotOK();
+               break;
+       case QDialogButtonBox::Apply:
+               dispatchParams();
+               break;
+       case QDialogButtonBox::Close:
+               hide();
+               break;
+       default:
+               break;
+       }
 }
 
 
-void GuiSymbols::on_okPB_clicked()
+void GuiSymbols::slotOK()
 {
        dispatchParams();
        hide();
 }
 
 
-void GuiSymbols::on_closePB_clicked()
-{
-       hide();
-}
-
-
 void GuiSymbols::on_symbolsLW_activated(QModelIndex const &)
 {
-       on_okPB_clicked();
+       slotOK();
 }
 
 
 void GuiSymbols::on_chosenLE_textChanged(QString const & text)
 {
        bool const empty_sel = text.isEmpty();
-       okPB->setEnabled(!empty_sel);
-       applyPB->setEnabled(!empty_sel);
+       buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!empty_sel);
+       buttonBox->button(QDialogButtonBox::Apply)->setEnabled(!empty_sel);
 }
 
 
 void GuiSymbols::on_chosenLE_returnPressed()
 {
-       on_okPB_clicked();
+       slotOK();
 }
 
 
@@ -477,7 +497,6 @@ void GuiSymbols::updateSymbolList(bool update_combo)
                // this happens when the encoding changes when moving the cursor
                categoryCO->setCurrentIndex(0);
                updateSymbolList(false);
-               return;
        }
 }