]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiSymbols.cpp
* fix spelling in comments to please John.
[lyx.git] / src / frontends / qt4 / GuiSymbols.cpp
index f2576a669d43b8ff93f169be3e2a58d4afec83c7..6bd5ba210a4bf1f9fcbed1c4751b482422dd8749 100644 (file)
@@ -3,7 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author Jürgen Spitzmüller
+ * \author Jürgen Spitzmüller
  *
  * Full author contact details are available in file CREDITS.
  */
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "BufferView.h"
+#include "Cursor.h"
 #include "Encoding.h"
 #include "FuncRequest.h"
 
+#include "support/debug.h"
 #include "support/gettext.h"
 
 #include <QChar>
@@ -29,6 +31,8 @@
 #include <QListWidgetItem>
 #include <QString>
 
+#include <cstdio>
+
 using namespace std;
 
 namespace lyx {
@@ -39,7 +43,7 @@ namespace {
 
 /// name of unicode block, start and end code point
 struct UnicodeBlocks {
-       QString name;
+       char const * name;
        char_type start;
        char_type end;
 };
@@ -139,8 +143,8 @@ UnicodeBlocks unicode_blocks[] = {
        { N_("CJK Compatibility Ideographs Supplement"), 0x2f800, 0x2fa1f },
        { N_("Tags"), 0xe0000, 0xe007f },
        { N_("Variation Selectors Supplement"), 0xe0100, 0xe01ef },
-       { N_("Supplementary Private Use Area-A"), 0xf0000, 0xe01ef },
-       { N_("Supplementary Private Use Area-B"), 0x100000, 0x10ffff }
+       { N_("Supplementary Private Use Area-A"), 0xf0000, 0xffffd },
+       { N_("Supplementary Private Use Area-B"), 0x100000, 0x10fffd }
 };
 
 const int no_blocks = sizeof(unicode_blocks) / sizeof(UnicodeBlocks);
@@ -148,12 +152,36 @@ const int no_blocks = sizeof(unicode_blocks) / sizeof(UnicodeBlocks);
 
 QString getBlock(char_type c)
 {
+       // store an educated guess for the next search
+       static int lastBlock = 0;
+
+       // "clever reset"
+       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)
+               return qt_(unicode_blocks[lastBlock].name);
+
+       // c falls into an uncovered area, but we can guess which       
+       if (c > unicode_blocks[lastBlock].end
+           && c < unicode_blocks[lastBlock + 1].start)
+               return QString();
+
+       // guessing was wrong so far. do a real search.
        int i = 0;
        while (c > unicode_blocks[i].end && i < no_blocks)
                ++i;
-       if (!unicode_blocks[i].name.isEmpty())
-               return unicode_blocks[i].name;
-       return QString();
+       if (i == no_blocks)
+               return QString();
+       lastBlock = i;
+       //LYXERR0("fail: " << int(c) << ' ' << lastBlock);
+       return qt_(unicode_blocks[lastBlock].name);
 }
 
 
@@ -218,7 +246,7 @@ public:
                return QVariant();
        }
 
-       void reset(QList<char_type> const & symbols)
+       void setSymbols(QList<char_type> const & symbols)
        {
                symbols_ = symbols;
                QAbstractItemModel::reset();
@@ -358,13 +386,14 @@ void GuiSymbols::on_categoryFilterCB_toggled(bool on)
 
 void GuiSymbols::scrollToItem(QString const & category)
 {
-       if (used_blocks.find(category) != used_blocks.end()) {
-               int row = used_blocks[category];
-               QModelIndex index = symbolsLW->model()->index(row, 0, QModelIndex());
-               symbolsLW->scrollTo(index, QAbstractItemView::PositionAtTop);
-       }
+       if (used_blocks.find(category) == used_blocks.end())
+               return;
+       int row = used_blocks[category];
+       QModelIndex index = symbolsLW->model()->index(row, 0, QModelIndex());
+       symbolsLW->scrollTo(index, QAbstractItemView::PositionAtTop);
 }
 
+
 void GuiSymbols::updateSymbolList(bool update_combo)
 {
        QString category = categoryCO->currentText();
@@ -379,11 +408,11 @@ void GuiSymbols::updateSymbolList(bool update_combo)
        bool const show_all = categoryFilterCB->isChecked();
 
        if (symbols_.empty() || update_combo)
-               symbols_ = encodings.getFromLyXName(encoding_)->getSymbolsList();
+               symbols_ = encodings.fromLyXName(encoding_)->symbolsList();
 
        if (!show_all) {
                for (int i = 0 ; i < no_blocks; ++i)
-                       if (unicode_blocks[i].name == category) {
+                       if (qt_(unicode_blocks[i].name) == category) {
                                range_start = unicode_blocks[i].start;
                                range_end = unicode_blocks[i].end;
                                break;
@@ -399,14 +428,13 @@ void GuiSymbols::updateSymbolList(bool update_combo)
 #if QT_VERSION >= 0x040300
                QChar::Category const cat = QChar::category(uint(c));
 #else
-               QChar const qc = uint(c);
-               QChar::Category const cat = qc.category();
+               QChar::Category const cat = QChar(uint(c)).category();
 #endif
                // we do not want control or space characters
                if (cat == QChar::Other_Control || cat == QChar::Separator_Space)
                        continue;
                ++numItem;
-               if (show_all || c >= range_start && c <= range_end)
+               if (show_all || (c >= range_start && c <= range_end))
                        s.append(c);
                if (update_combo) {
                        QString block = getBlock(c);
@@ -416,7 +444,7 @@ void GuiSymbols::updateSymbolList(bool update_combo)
                                used_blocks[block] = numItem;
                }
        }
-       model_->reset(s);
+       model_->setSymbols(s);
 
        if (update_combo) {
                // update category combo
@@ -451,4 +479,4 @@ Dialog * createGuiSymbols(GuiView & lv)
 } // namespace frontend
 } // namespace lyx
 
-#include "GuiSymbols_moc.cpp"
+#include "moc_GuiSymbols.cpp"