]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiDelimiter.cpp
Fix bug #9990: Oversized & Incorrect Glyphs in Math Delimiter Dialog
[lyx.git] / src / frontends / qt4 / GuiDelimiter.cpp
index af4e609e2dafea9ab4bc1da0830e6eeb8a8fb9b8..31903fc8b46bc0e1a808ad4c9091b3b3844c925b 100644 (file)
@@ -41,6 +41,7 @@ namespace {
 static char const *  latex_delimiters[] = {
        "(", ")", "{", "}", "[", "]",
        "lceil", "rceil", "lfloor", "rfloor", "langle", "rangle",
+       "llbracket", "rrbracket",
        "uparrow", "updownarrow", "Uparrow", "Updownarrow", "downarrow", "Downarrow",
        "|", "Vert", "/", "backslash", ""
 };
@@ -99,14 +100,14 @@ void initMathSymbols()
        // defined with non-unicode ids for use within mathed.
        // FIXME 2: We should fill-in this map with the parsed "symbols"
        // file done in MathFactory.cpp.
-       math_symbols_["("] = MathSymbol('(');
-       math_symbols_[")"] = MathSymbol(')');
-       math_symbols_["{"] = MathSymbol('{');
-       math_symbols_["}"] = MathSymbol('}');
-       math_symbols_["["] = MathSymbol('[');
-       math_symbols_["]"] = MathSymbol(']');
-       math_symbols_["|"] = MathSymbol('|');
-       math_symbols_["/"] = MathSymbol('/', 54, CMSY_FAMILY);
+       math_symbols_["("] = MathSymbol('(', 40, CMR_FAMILY);
+       math_symbols_[")"] = MathSymbol(')', 41, CMR_FAMILY);
+       math_symbols_["{"] = MathSymbol('{', 102, CMSY_FAMILY);
+       math_symbols_["}"] = MathSymbol('}', 103, CMSY_FAMILY);
+       math_symbols_["["] = MathSymbol('[', 91, CMR_FAMILY);
+       math_symbols_["]"] = MathSymbol(']', 93, CMR_FAMILY);
+       math_symbols_["|"] = MathSymbol('|', 106, CMSY_FAMILY);
+       math_symbols_["/"] = MathSymbol('/', 47, CMR_FAMILY);
        math_symbols_["backslash"] = MathSymbol('\\', 110, CMSY_FAMILY);
        math_symbols_["lceil"] = MathSymbol(0x2308, 100, CMSY_FAMILY);
        math_symbols_["rceil"] = MathSymbol(0x2309, 101, CMSY_FAMILY);
@@ -114,6 +115,8 @@ void initMathSymbols()
        math_symbols_["rfloor"] = MathSymbol(0x230B, 99, CMSY_FAMILY);
        math_symbols_["langle"] = MathSymbol(0x2329, 104, CMSY_FAMILY);
        math_symbols_["rangle"] = MathSymbol(0x232A, 105, CMSY_FAMILY);
+       math_symbols_["llbracket"] = MathSymbol(0x27e6, 74, STMARY_FAMILY);
+       math_symbols_["rrbracket"] = MathSymbol(0x27e7, 75, STMARY_FAMILY);
        math_symbols_["uparrow"] = MathSymbol(0x2191, 34, CMSY_FAMILY);
        math_symbols_["Uparrow"] = MathSymbol(0x21D1, 42, CMSY_FAMILY);
        math_symbols_["updownarrow"] = MathSymbol(0x2195, 108, CMSY_FAMILY);
@@ -138,7 +141,7 @@ MathSymbol const & mathSymbol(string tex_name)
        map<string, MathSymbol>::const_iterator it =
                math_symbols_.find(tex_name);
 
-       static MathSymbol unknown_symbol;
+       static MathSymbol const unknown_symbol;
        if (it == math_symbols_.end())
                return unknown_symbol;
 
@@ -151,7 +154,7 @@ string const & texName(char_type math_symbol)
        map<char_type, string>::const_iterator it =
                tex_names_.find(math_symbol);
 
-       static string empty_string;
+       static string const empty_string;
        if (it == tex_names_.end())
                return empty_string;
 
@@ -173,6 +176,9 @@ GuiDelimiter::GuiDelimiter(GuiView & lv)
        leftLW->setViewMode(QListView::IconMode);
        rightLW->setViewMode(QListView::IconMode);
 
+       leftLW->setDragDropMode(QAbstractItemView::NoDragDrop);
+       rightLW->setDragDropMode(QAbstractItemView::NoDragDrop);
+
        initMathSymbols();
 
        typedef map<char_type, QListWidgetItem *> ListItems;
@@ -185,10 +191,11 @@ GuiDelimiter::GuiDelimiter(GuiView & lv)
                QString symbol(ms.fontcode?
                        QChar(ms.fontcode) : toqstr(docstring(1, ms.unicode)));
                QListWidgetItem * lwi = new QListWidgetItem(symbol);
-               lwi->setToolTip(toqstr(delim));
                FontInfo lyxfont;
                lyxfont.setFamily(ms.fontfamily);
-               lwi->setFont(frontend::getFont(lyxfont));
+               QFont font = frontend::getFont(lyxfont);
+               lwi->setFont(font);
+               lwi->setToolTip(toqstr(delim));
                list_items[ms.unicode] = lwi;
                leftLW->addItem(lwi);
        }
@@ -200,8 +207,10 @@ GuiDelimiter::GuiDelimiter(GuiView & lv)
        }
 
        // The last element is the empty one.
-       leftLW->addItem(qt_("(None)"));
-       rightLW->addItem(qt_("(None)"));
+       QListWidgetItem * lwi = new QListWidgetItem(qt_("(None)"));
+       QListWidgetItem * rwi = new QListWidgetItem(qt_("(None)"));
+       leftLW->addItem(lwi);
+       rightLW->addItem(rwi);
 
        sizeCO->addItem(qt_("Variable"));
 
@@ -230,6 +239,8 @@ char_type GuiDelimiter::doMatch(char_type const symbol)
        else if (str == "lfloor") match = "rfloor";
        else if (str == "rangle") match = "langle";
        else if (str == "langle") match = "rangle";
+       else if (str == "llbracket") match = "rrbracket";
+       else if (str == "rrbracket") match = "llbracket";
        else if (str == "backslash") match = "/";
        else if (str == "/") match = "backslash";
        else return symbol;
@@ -296,6 +307,9 @@ void GuiDelimiter::on_sizeCO_activated(int index)
 
 void GuiDelimiter::on_leftLW_itemActivated(QListWidgetItem *)
 {
+       // do not auto-apply if !matchCB->isChecked()
+       if (!matchCB->isChecked())
+               return;
        on_insertPB_clicked();
        accept();
 }
@@ -303,6 +317,9 @@ void GuiDelimiter::on_leftLW_itemActivated(QListWidgetItem *)
 
 void GuiDelimiter::on_rightLW_itemActivated(QListWidgetItem *)
 {
+       // do not auto-apply if !matchCB->isChecked()
+       if (!matchCB->isChecked())
+               return;
        on_insertPB_clicked();
        accept();
 }