]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiSymbols.cpp
On Linux show in crash message box the backtrace
[lyx.git] / src / frontends / qt4 / GuiSymbols.cpp
index 8029265286dd925a624a1dc4cf9dbe202f4f935b..1e7e7891bf2f73ac49ece06350475d533669cb5f 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.
  */
@@ -19,6 +19,7 @@
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "BufferView.h"
+#include "Cursor.h"
 #include "Encoding.h"
 #include "FuncRequest.h"
 
@@ -30,6 +31,8 @@
 #include <QListWidgetItem>
 #include <QString>
 
+#include <cstdio>
+
 using namespace std;
 
 namespace lyx {
@@ -40,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;
 };
@@ -150,6 +153,7 @@ const int no_blocks = sizeof(unicode_blocks) / sizeof(UnicodeBlocks);
 QString getBlock(char_type c)
 {
        // store an educated guess for the next search
+       // FIXME THREAD
        static int lastBlock = 0;
 
        // "clever reset"
@@ -163,7 +167,7 @@ QString getBlock(char_type c)
        // c falls into a covered area, and we can guess which
        if (c >= unicode_blocks[lastBlock].start
            && c <= unicode_blocks[lastBlock].end)
-               return unicode_blocks[lastBlock].name;
+               return qt_(unicode_blocks[lastBlock].name);
 
        // c falls into an uncovered area, but we can guess which       
        if (c > unicode_blocks[lastBlock].end
@@ -178,7 +182,7 @@ QString getBlock(char_type c)
                return QString();
        lastBlock = i;
        //LYXERR0("fail: " << int(c) << ' ' << lastBlock);
-       return unicode_blocks[lastBlock].name;
+       return qt_(unicode_blocks[lastBlock].name);
 }
 
 
@@ -195,7 +199,7 @@ class GuiSymbols::Model : public QAbstractItemModel
 {
 public:
        Model(GuiSymbols * parent)
-               : QAbstractItemModel(parent), parent_(parent)
+               : QAbstractItemModel(parent)
        {}
 
        QModelIndex index(int row, int column, QModelIndex const &) const
@@ -223,6 +227,7 @@ public:
                static QString const strCharacter = qt_("Character: ");
                static QString const strCodePoint = qt_("Code Point: ");
 
+               // FIXME THREAD
                static char codeName[10];
 
                char_type c = symbols_.at(index.row()); 
@@ -245,14 +250,14 @@ public:
 
        void setSymbols(QList<char_type> const & symbols)
        {
+               QAbstractItemModel::beginResetModel();
                symbols_ = symbols;
-               QAbstractItemModel::reset();
+               QAbstractItemModel::endResetModel();
        }
 
 private:
        friend class GuiSymbols;
-       GuiSymbols * parent_;
-       
+
        QList<char_type> symbols_;
 };
 
@@ -272,12 +277,17 @@ GuiSymbols::GuiSymbols(GuiView & lv)
        setFocusProxy(symbolsLW);
 
        symbolsLW->setViewMode(QListView::IconMode);
-       symbolsLW->setUniformItemSizes(true);
        // increase the display size of the symbols a bit
-       QFont font= symbolsLW->font();
-       int size = font.pointSize() + 3;
+       QFont font = symbolsLW->font();
+       const int size = font.pointSize() + 3;
        font.setPointSize(size);
        symbolsLW->setFont(font);
+       QFontMetrics fm(font);
+       const int cellHeight = fm.height() + 2;
+       // FIXME: using at least cellHeight because of
+       // QFontMetrics::maxWidth() is returning 0 with Qt/Cocoa on Mac OS
+       const int cellWidth = max(cellHeight, fm.maxWidth() + 2);
+       symbolsLW->setGridSize(QSize(cellWidth, cellHeight));
        symbolsLW->setModel(model_);
 }
 
@@ -383,13 +393,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();
@@ -408,7 +419,7 @@ void GuiSymbols::updateSymbolList(bool update_combo)
 
        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;
@@ -421,17 +432,12 @@ void GuiSymbols::updateSymbolList(bool update_combo)
                char_type c = *it;
                if (!update_combo && !show_all && (c <= range_start || c >= range_end))
                        continue;
-#if QT_VERSION >= 0x040300
                QChar::Category const cat = QChar::category(uint(c));
-#else
-               QChar const qc = uint(c);
-               QChar::Category const cat = qc.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);
@@ -476,4 +482,4 @@ Dialog * createGuiSymbols(GuiView & lv)
 } // namespace frontend
 } // namespace lyx
 
-#include "GuiSymbols_moc.cpp"
+#include "moc_GuiSymbols.cpp"