X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiDelimiter.cpp;h=0327fd48338bc82ff42bc4c13b8f538ade35a55a;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=91c79159819fe769039736ef60e6baf1d477e9d5;hpb=98eff22b9a1132ca1f9a9256a7959e9ac907255b;p=lyx.git diff --git a/src/frontends/qt4/GuiDelimiter.cpp b/src/frontends/qt4/GuiDelimiter.cpp index 91c7915981..0327fd4833 100644 --- a/src/frontends/qt4/GuiDelimiter.cpp +++ b/src/frontends/qt4/GuiDelimiter.cpp @@ -13,19 +13,30 @@ #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 #include #include -// Set to zero if unicode symbols are preferred. -#define USE_PIXMAP 1 +#include +#include + +using namespace std; -using std::string; +namespace lyx { +namespace frontend { + +namespace { static char const * latex_delimiters[] = { "(", ")", "{", "}", "[", "]", @@ -64,17 +75,96 @@ static QString fix_name(QString const & str, bool big) 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 math_symbols_; +/// Math-symbol / TeX-name map. +/// This one is for fast search, it contains the same data as +/// \c math_symbols_. +static map 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('('); + 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_["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_["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::const_iterator it = math_symbols_.begin(); + map::const_iterator end = math_symbols_.end(); + for (; it != end; ++it) + tex_names_[it->second.unicode] = it->first; +} -GuiDelimiterDialog::GuiDelimiterDialog(LyXView & lv) - : GuiDialog(lv, "mathdelimiter") +/// \return the math unicode symbol associated to a TeX name. +MathSymbol const & mathSymbol(string tex_name) +{ + map::const_iterator it = + math_symbols_.find(tex_name); + + static MathSymbol 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::const_iterator it = + tex_names_.find(math_symbol); + + static string 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")); - setController(new ControlMath(*this)); connect(closePB, SIGNAL(clicked()), this, SLOT(accept())); @@ -83,27 +173,28 @@ GuiDelimiterDialog::GuiDelimiterDialog(LyXView & lv) leftLW->setViewMode(QListView::IconMode); rightLW->setViewMode(QListView::IconMode); - typedef std::map ListItems; + initMathSymbols(); + + typedef map 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 = controller().mathSymbol(delim); + MathSymbol const & ms = mathSymbol(delim); 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); + lwi->setFont(frontend::getFont(lyxfont)); list_items[ms.unicode] = lwi; leftLW->addItem(lwi); } for (int i = 0; i != leftLW->count(); ++i) { - MathSymbol const & ms = controller().mathSymbol( + MathSymbol const & ms = mathSymbol( fromqstr(leftLW->item(i)->toolTip())); rightLW->addItem(list_items[doMatch(ms.unicode)]->clone()); } @@ -122,15 +213,9 @@ GuiDelimiterDialog::GuiDelimiterDialog(LyXView & lv) } -ControlMath & GuiDelimiterDialog::controller() +char_type GuiDelimiter::doMatch(char_type const symbol) { - return static_cast(GuiDialog::controller()); -} - - -char_type GuiDelimiterDialog::doMatch(char_type const symbol) -{ - string const & str = controller().texName(symbol); + string const & str = texName(symbol); string match; if (str == "(") match = ")"; else if (str == ")") match = "("; @@ -149,11 +234,11 @@ char_type GuiDelimiterDialog::doMatch(char_type const symbol) else if (str == "/") match = "backslash"; else return symbol; - return controller().mathSymbol(match).unicode; + return mathSymbol(match).unicode; } -void GuiDelimiterDialog::updateTeXCode(int size) +void GuiDelimiter::updateTeXCode(int size) { bool const bigsize = size != 0; @@ -191,39 +276,45 @@ void GuiDelimiterDialog::updateTeXCode(int size) } -void GuiDelimiterDialog::on_insertPB_clicked() +void GuiDelimiter::on_insertPB_clicked() { if (sizeCO->currentIndex() == 0) - controller().dispatchDelim(fromqstr(tex_code_)); + dispatch(FuncRequest(LFUN_MATH_DELIM, fromqstr(tex_code_))); else { QString command = '"' + tex_code_ + '"'; command.replace(' ', "\" \""); - controller().dispatchBigDelim(fromqstr(command)); + dispatch(FuncRequest(LFUN_MATH_BIGDELIM, fromqstr(command))); } } -void GuiDelimiterDialog::on_sizeCO_activated(int index) +void GuiDelimiter::on_sizeCO_activated(int index) { updateTeXCode(index); } -void GuiDelimiterDialog::on_leftLW_itemActivated(QListWidgetItem *) +void GuiDelimiter::on_leftLW_itemActivated(QListWidgetItem *) { + // do not auto-apply if !matchCB->isChecked() + if (!matchCB->isChecked()) + return; on_insertPB_clicked(); accept(); } -void GuiDelimiterDialog::on_rightLW_itemActivated(QListWidgetItem *) +void GuiDelimiter::on_rightLW_itemActivated(QListWidgetItem *) { + // do not auto-apply if !matchCB->isChecked() + if (!matchCB->isChecked()) + return; on_insertPB_clicked(); accept(); } -void GuiDelimiterDialog::on_leftLW_currentRowChanged(int item) +void GuiDelimiter::on_leftLW_currentRowChanged(int item) { if (matchCB->isChecked()) rightLW->setCurrentRow(item); @@ -232,7 +323,7 @@ void GuiDelimiterDialog::on_leftLW_currentRowChanged(int item) } -void GuiDelimiterDialog::on_rightLW_currentRowChanged(int item) +void GuiDelimiter::on_rightLW_currentRowChanged(int item) { if (matchCB->isChecked()) leftLW->setCurrentRow(item); @@ -241,7 +332,7 @@ void GuiDelimiterDialog::on_rightLW_currentRowChanged(int item) } -void GuiDelimiterDialog::on_matchCB_stateChanged(int state) +void GuiDelimiter::on_matchCB_stateChanged(int state) { if (state == Qt::Checked) on_leftLW_currentRowChanged(leftLW->currentRow()); @@ -250,7 +341,10 @@ void GuiDelimiterDialog::on_matchCB_stateChanged(int state) } +Dialog * createGuiDelimiter(GuiView & lv) { return new GuiDelimiter(lv); } + + } // namespace frontend } // namespace lyx -#include "GuiDelimiter_moc.cpp" +#include "moc_GuiDelimiter.cpp"