#include "GuiDelimiter.h"
#include "GuiApplication.h"
+#include "GuiFontLoader.h"
#include "GuiView.h"
-
#include "qt_helpers.h"
-#include "gettext.h"
+
+#include "FontEnums.h"
+#include "FontInfo.h"
+#include "FuncRequest.h"
+
+#include "support/gettext.h"
+#include "support/docstring.h"
#include <QPixmap>
#include <QCheckBox>
#include <QListWidgetItem>
-// Set to zero if unicode symbols are preferred.
-#define USE_PIXMAP 1
+#include <map>
+#include <string>
+
+using namespace std;
-using std::string;
+namespace lyx {
+namespace frontend {
+
+namespace {
static char const * latex_delimiters[] = {
"(", ")", "{", "}", "[", "]",
"lceil", "rceil", "lfloor", "rfloor", "langle", "rangle",
+ "llbracket", "rrbracket",
"uparrow", "updownarrow", "Uparrow", "Updownarrow", "downarrow", "Downarrow",
"|", "Vert", "/", "backslash", ""
};
return "\\" + str;
}
+struct MathSymbol {
+ MathSymbol(char_type uc = '?', unsigned char fc = 0,
+ FontFamily ff = SYMBOL_FAMILY)
+ : unicode(uc), fontcode(fc), fontfamily(ff)
+ {}
+ char_type unicode;
+ unsigned char fontcode;
+ FontFamily fontfamily;
+};
-namespace lyx {
-namespace frontend {
+/// TeX-name / Math-symbol map.
+static map<std::string, MathSymbol> math_symbols_;
+/// Math-symbol / TeX-name map.
+/// This one is for fast search, it contains the same data as
+/// \c math_symbols_.
+static map<char_type, string> tex_names_;
+void initMathSymbols()
+{
+ // FIXME: Ideally, those unicode codepoints would be defined
+ // in "lib/symbols". Unfortunately, some of those are already
+ // 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('(', 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);
+ math_symbols_["lfloor"] = MathSymbol(0x230A, 98, CMSY_FAMILY);
+ 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);
+ math_symbols_["Updownarrow"] = MathSymbol(0x21D5, 109, CMSY_FAMILY);
+ math_symbols_["downarrow"] = MathSymbol(0x2193, 35, CMSY_FAMILY);
+ math_symbols_["Downarrow"] = MathSymbol(0x21D3, 43, CMSY_FAMILY);
+ math_symbols_["downdownarrows"] = MathSymbol(0x21CA, 184, MSA_FAMILY);
+ math_symbols_["downharpoonleft"] = MathSymbol(0x21C3, 188, MSA_FAMILY);
+ math_symbols_["downharpoonright"] = MathSymbol(0x21C2, 186, MSA_FAMILY);
+ math_symbols_["vert"] = MathSymbol(0x007C, 106, CMSY_FAMILY);
+ math_symbols_["Vert"] = MathSymbol(0x2016, 107, CMSY_FAMILY);
+
+ map<string, MathSymbol>::const_iterator it = math_symbols_.begin();
+ map<string, MathSymbol>::const_iterator end = math_symbols_.end();
+ for (; it != end; ++it)
+ tex_names_[it->second.unicode] = it->first;
+}
-GuiDelimiter::GuiDelimiter(LyXView & lv)
- : GuiMath(lv, "mathdelimiter")
+/// \return the math unicode symbol associated to a TeX name.
+MathSymbol const & mathSymbol(string tex_name)
+{
+ map<string, MathSymbol>::const_iterator it =
+ math_symbols_.find(tex_name);
+
+ static MathSymbol const unknown_symbol;
+ if (it == math_symbols_.end())
+ return unknown_symbol;
+
+ return it->second;
+}
+
+/// \return the TeX name associated to a math unicode symbol.
+string const & texName(char_type math_symbol)
+{
+ map<char_type, string>::const_iterator it =
+ tex_names_.find(math_symbol);
+
+ static string const empty_string;
+ if (it == tex_names_.end())
+ return empty_string;
+
+ return it->second;
+}
+
+} // anon namespace
+
+
+GuiDelimiter::GuiDelimiter(GuiView & lv)
+ : GuiDialog(lv, "mathdelimiter", qt_("Math Delimiter"))
{
setupUi(this);
- setViewTitle(_("Math Delimiter"));
connect(closePB, SIGNAL(clicked()), this, SLOT(accept()));
leftLW->setViewMode(QListView::IconMode);
rightLW->setViewMode(QListView::IconMode);
- typedef std::map<char_type, QListWidgetItem *> ListItems;
+ leftLW->setDragDropMode(QAbstractItemView::NoDragDrop);
+ rightLW->setDragDropMode(QAbstractItemView::NoDragDrop);
+
+ initMathSymbols();
+
+ typedef map<char_type, QListWidgetItem *> ListItems;
ListItems list_items;
// The last element is the empty one.
int const end = nr_latex_delimiters - 1;
for (int i = 0; i < end; ++i) {
string const delim = latex_delimiters[i];
MathSymbol const & ms = mathSymbol(delim);
+// Due to a bug in Qt 4 on Windows, we need to use our math symbol font
+// on Windows (see #5760).
+// FIXME: Re-check after Windows has settled to Qt 5.
+// ATM, this doesn't work also with Qt 5.4.1 because of still missing
+// glyphs for \llbracket and \rrbracket. These last symbols are also
+// missing when compiling on cygwin using the X11 xcb backend.
+#if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
QString symbol(ms.fontcode?
QChar(ms.fontcode) : toqstr(docstring(1, ms.unicode)));
QListWidgetItem * lwi = new QListWidgetItem(symbol);
- lwi->setToolTip(toqstr(delim));
- Font lyxfont;
+ FontInfo lyxfont;
lyxfont.setFamily(ms.fontfamily);
- QFont const & symbol_font = guiApp->guiFontLoader().get(lyxfont);
- lwi->setFont(symbol_font);
+ QFont font = frontend::getFont(lyxfont);
+#else
+ QString symbol(QChar(ms.unicode));
+ QListWidgetItem * lwi = new QListWidgetItem(symbol);
+ QFont font = lwi->font();
+ font.setPointSize(2 * font.pointSize());
+#endif
+ lwi->setFont(font);
+ lwi->setToolTip(toqstr(delim));
list_items[ms.unicode] = lwi;
leftLW->addItem(lwi);
}
}
// 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)"));
+// See above comment.
+// FIXME: Re-check after Windows has settled to Qt 5.
+#if !defined(Q_OS_WIN) && !defined(Q_CYGWIN_WIN)
+ QFont font = lwi->font();
+ font.setPointSize(2 * font.pointSize());
+ lwi->setFont(font);
+ rwi->setFont(font);
+#endif
+ leftLW->addItem(lwi);
+ rightLW->addItem(rwi);
sizeCO->addItem(qt_("Variable"));
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;
void GuiDelimiter::on_insertPB_clicked()
{
if (sizeCO->currentIndex() == 0)
- dispatchDelim(fromqstr(tex_code_));
+ dispatch(FuncRequest(LFUN_MATH_DELIM, fromqstr(tex_code_)));
else {
QString command = '"' + tex_code_ + '"';
command.replace(' ', "\" \"");
- dispatchBigDelim(fromqstr(command));
+ dispatch(FuncRequest(LFUN_MATH_BIGDELIM, fromqstr(command)));
}
}
void GuiDelimiter::on_leftLW_itemActivated(QListWidgetItem *)
{
+ // do not auto-apply if !matchCB->isChecked()
+ if (!matchCB->isChecked())
+ return;
on_insertPB_clicked();
accept();
}
void GuiDelimiter::on_rightLW_itemActivated(QListWidgetItem *)
{
+ // do not auto-apply if !matchCB->isChecked()
+ if (!matchCB->isChecked())
+ return;
on_insertPB_clicked();
accept();
}
}
-Dialog * createGuiDelimiter(LyXView & lv) { return new GuiDelimiter(lv); }
+Dialog * createGuiDelimiter(GuiView & lv) { return new GuiDelimiter(lv); }
} // namespace frontend
} // namespace lyx
-#include "GuiDelimiter_moc.cpp"
+#include "moc_GuiDelimiter.cpp"