From 4d9c1bc29685055ce7e43396c2c33e2fd42afcd0 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Thu, 12 Apr 2007 16:49:01 +0000 Subject: [PATCH] Fix bug 3450: http://bugzilla.lyx.org/show_bug.cgi?id=3450 * ControlMath - new MathSymbol struct that summarize the symbol attributes (including font and fontcode) * QDelimiterDialog: - make use of the new MathSymbol for the ListWidget. - store the latex name in the tooltip instead of lookup for it. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17786 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/controllers/ControlMath.C | 77 +++++++++---------- src/frontends/controllers/ControlMath.h | 15 +++- src/frontends/qt4/QDelimiterDialog.C | 98 +++++++++++++++---------- src/frontends/qt4/QDelimiterDialog.h | 2 + 4 files changed, 109 insertions(+), 83 deletions(-) diff --git a/src/frontends/controllers/ControlMath.C b/src/frontends/controllers/ControlMath.C index 5eb662dc55..f80d41214c 100644 --- a/src/frontends/controllers/ControlMath.C +++ b/src/frontends/controllers/ControlMath.C @@ -37,45 +37,39 @@ ControlMath::ControlMath(Dialog & dialog) // 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. - math_symbols_["("] = '('; - math_symbols_[")"] = ')'; - math_symbols_["{"] = '{'; - math_symbols_["}"] = '}'; - math_symbols_["["] = '['; - math_symbols_["]"] = ']'; - math_symbols_["|"] = '|'; - math_symbols_["/"] = '/'; - math_symbols_["\\"] = '\\'; - math_symbols_["lceil"] = 0x2308; - math_symbols_["rceil"] = 0x2309; - math_symbols_["lfloor"] = 0x230A; - math_symbols_["rfloor"] = 0x230B; - math_symbols_["langle"] = 0x2329; - math_symbols_["rangle"] = 0x232A; - math_symbols_["uparrow"] = 0x2191; - math_symbols_["Uparrow"] = 0x21D1; - math_symbols_["UpArrow"] = 0x2191; - math_symbols_["UpArrowBar"] = 0x2912; - math_symbols_["UpArrowDownArrow"] = 0x21C5; - math_symbols_["updownarrow"] = 0x2195; - math_symbols_["Updownarrow"] = 0x21D5; - math_symbols_["UpDownArrow"] = 0x2195; - math_symbols_["downarrow"] = 0x2193; - math_symbols_["Downarrow"] = 0x21D3; - math_symbols_["DownArrow"] = 0x2193; - math_symbols_["DownArrowBar"] = 0x2913; - math_symbols_["DownArrowUpArrow"] = 0x21F5; - math_symbols_["downdownarrows"] = 0x21CA; - math_symbols_["downharpoonleft"] = 0x21C3; - math_symbols_["downharpoonright"] = 0x21C2; - math_symbols_["vert"] = 0x007C; - math_symbols_["Vert"] = 0x2016; - math_symbols_["Backslash"] = 0x2216; - - std::map::const_iterator it = math_symbols_.begin(); - std::map::const_iterator end = math_symbols_.end(); + // FIXME 2: We should fill-in this map with the parsed "symbols" + // file done in MathFactory.C. + math_symbols_["("] = MathSymbol('('); + math_symbols_[")"] = MathSymbol(')'); + math_symbols_["{"] = MathSymbol('{'); + math_symbols_["}"] = MathSymbol('}'); + math_symbols_["["] = MathSymbol('['); + math_symbols_["]"] = MathSymbol(']'); + math_symbols_["|"] = MathSymbol('|'); + math_symbols_["/"] = MathSymbol('/'); + math_symbols_["\\"] = MathSymbol('\\', 110, LyXFont::CMSY_FAMILY); + math_symbols_["lceil"] = MathSymbol(0x2308, 100, LyXFont::CMSY_FAMILY); + math_symbols_["rceil"] = MathSymbol(0x2309, 101, LyXFont::CMSY_FAMILY); + math_symbols_["lfloor"] = MathSymbol(0x230A, 98, LyXFont::CMSY_FAMILY); + math_symbols_["rfloor"] = MathSymbol(0x230B, 99, LyXFont::CMSY_FAMILY); + math_symbols_["langle"] = MathSymbol(0x2329, 104, LyXFont::CMSY_FAMILY); + math_symbols_["rangle"] = MathSymbol(0x232A, 105, LyXFont::CMSY_FAMILY); + math_symbols_["uparrow"] = MathSymbol(0x2191, 34, LyXFont::CMSY_FAMILY); + math_symbols_["Uparrow"] = MathSymbol(0x21D1, 42, LyXFont::CMSY_FAMILY); + math_symbols_["updownarrow"] = MathSymbol(0x2195, 108, LyXFont::CMSY_FAMILY); + math_symbols_["Updownarrow"] = MathSymbol(0x21D5, 109, LyXFont::CMSY_FAMILY); + math_symbols_["downarrow"] = MathSymbol(0x2193, 35, LyXFont::CMSY_FAMILY); + math_symbols_["Downarrow"] = MathSymbol(0x21D3, 43, LyXFont::CMSY_FAMILY); + math_symbols_["downdownarrows"] = MathSymbol(0x21CA, 184, LyXFont::MSA_FAMILY); + math_symbols_["downharpoonleft"] = MathSymbol(0x21C3, 188, LyXFont::MSA_FAMILY); + math_symbols_["downharpoonright"] = MathSymbol(0x21C2, 186, LyXFont::MSA_FAMILY); + math_symbols_["vert"] = MathSymbol(0x007C, 106, LyXFont::CMSY_FAMILY); + math_symbols_["Vert"] = MathSymbol(0x2016, 107, LyXFont::CMSY_FAMILY); + + std::map::const_iterator it = math_symbols_.begin(); + std::map::const_iterator end = math_symbols_.end(); for (; it != end; ++it) - tex_names_[it->second] = it->first; + tex_names_[it->second.unicode] = it->first; } @@ -141,13 +135,14 @@ void ControlMath::showDialog(string const & name) const } -char_type ControlMath::mathSymbol(string tex_name) const +MathSymbol const & ControlMath::mathSymbol(string tex_name) const { - map::const_iterator it = + map::const_iterator it = math_symbols_.find(tex_name); + static MathSymbol unknown_symbol; if (it == math_symbols_.end()) - return '?'; + return unknown_symbol; return it->second; } diff --git a/src/frontends/controllers/ControlMath.h b/src/frontends/controllers/ControlMath.h index c408ddb20b..30319c7bcb 100644 --- a/src/frontends/controllers/ControlMath.h +++ b/src/frontends/controllers/ControlMath.h @@ -17,12 +17,23 @@ #include "Dialog.h" #include "lfuns.h" // for kb_action +#include "lyxfont.h" #include namespace lyx { namespace frontend { +struct MathSymbol { + MathSymbol(char_type uc = '?', unsigned char fc = 0, + LyXFont::FONT_FAMILY ff = LyXFont::SYMBOL_FAMILY) + : unicode(uc), fontcode(fc), fontfamily(ff) + {} + char_type unicode; + unsigned char fontcode; + LyXFont::FONT_FAMILY fontfamily; +}; + class ControlMath : public Dialog::Controller { public: ControlMath(Dialog &); @@ -57,13 +68,13 @@ public: void showDialog(std::string const & name) const; /// \return the math unicode symbol associated to a TeX name. - char_type mathSymbol(std::string tex_name) const; + MathSymbol const & mathSymbol(std::string tex_name) const; /// \return the TeX name associated to a math unicode symbol. std::string const & texName(char_type math_symbol) const; private: /// TeX-name / Math-symbol map. - std::map math_symbols_; + std::map math_symbols_; /// Math-symbol / TeX-name map. /// This one is for fast search, it contains the same data as /// \c math_symbols_. diff --git a/src/frontends/qt4/QDelimiterDialog.C b/src/frontends/qt4/QDelimiterDialog.C index 302c1a273a..809c5d4f53 100644 --- a/src/frontends/qt4/QDelimiterDialog.C +++ b/src/frontends/qt4/QDelimiterDialog.C @@ -11,6 +11,8 @@ #include #include "QDelimiterDialog.h" + +#include "GuiApplication.h" #include "QMath.h" #include "qt_helpers.h" @@ -24,6 +26,9 @@ #include +// Set to zero if unicode symbols are preferred. +#define USE_PIXMAP 1 + using std::string; namespace lyx { @@ -41,27 +46,6 @@ char const * const biggui[] = {N_("big[[delimiter size]]"), N_("Big[[delimiter N_("bigg[[delimiter size]]"), N_("Bigg[[delimiter size]]"), ""}; -string do_match(string const & str) -{ - if (str == "(") return ")"; - if (str == ")") return "("; - if (str == "[") return "]"; - if (str == "]") return "["; - if (str == "{") return "}"; - if (str == "}") return "{"; - if (str == "l") return "r"; - if (str == "rceil") return "lceil"; - if (str == "lceil") return "rceil"; - if (str == "rfloor") return "lfloor"; - if (str == "lfloor") return "rfloor"; - if (str == "rangle") return "langle"; - if (str == "langle") return "rangle"; - if (str == "\\") return "/"; - if (str == "/") return "\\"; - return str; -} - - string fix_name(string const & str, bool big) { if (str.empty()) @@ -76,6 +60,31 @@ string fix_name(string const & str, bool big) } // namespace anon +char_type QDelimiterDialog::doMatch(char_type const symbol) const +{ + string const & str = form_->controller().texName(symbol); + string match; + if (str == "(") match = ")"; + else if (str == ")") match = "("; + else if (str == "[") match = "]"; + else if (str == "]") match = "["; + else if (str == "{") match = "}"; + else if (str == "}") match = "{"; + else if (str == "l") match = "r"; + else if (str == "rceil") match = "lceil"; + else if (str == "lceil") match = "rceil"; + else if (str == "rfloor") match = "lfloor"; + else if (str == "lfloor") match = "rfloor"; + else if (str == "rangle") match = "langle"; + else if (str == "langle") match = "rangle"; + else if (str == "\\") match = "/"; + else if (str == "/") match = "\\"; + else return symbol; + + return form_->controller().mathSymbol(match).unicode; +} + + QDelimiterDialog::QDelimiterDialog(QMathDelimiter * form) : form_(form) { @@ -87,16 +96,31 @@ QDelimiterDialog::QDelimiterDialog(QMathDelimiter * form) setWindowTitle(qt_("LyX: Delimiters")); setFocusProxy(leftLW); + typedef std::map ListItems; + ListItems list_items; // The last element is the empty one. - for (int i = 0; i < nr_latex_delimiters - 1; ++i) { - docstring const left_d(1, - form_->controller().mathSymbol(latex_delimiters[i])); - docstring const right_d(1, - form_->controller().mathSymbol(do_match(latex_delimiters[i]))); - leftLW->addItem(toqstr(left_d)); - rightLW->addItem(toqstr(right_d)); + int const end = nr_latex_delimiters - 1; + for (int i = 0; i < end; ++i) { + string const delim = latex_delimiters[i]; + MathSymbol const & ms = form_->controller().mathSymbol(delim); + QString symbol(ms.fontcode? + QChar(ms.fontcode) : toqstr(docstring(1, ms.unicode))); + QListWidgetItem * lwi = new QListWidgetItem(symbol); + lwi->setToolTip(toqstr(delim)); + LyXFont lyxfont; + lyxfont.setFamily(ms.fontfamily); + QFont const & symbol_font = guiApp->guiFontLoader().get(lyxfont); + lwi->setFont(symbol_font); + list_items[ms.unicode] = lwi; } + ListItems::const_iterator it = list_items.begin(); + ListItems::const_iterator it_end = list_items.end(); + for (; it != it_end; ++it) { + leftLW->addItem(it->second); + rightLW->addItem(list_items[doMatch(it->first)]->clone()); + } + // The last element is the empty one. leftLW->addItem(qt_("(None)")); rightLW->addItem(qt_("(None)")); @@ -114,9 +138,9 @@ void QDelimiterDialog::insertClicked() string left_str; string right_str; if (leftLW->currentRow() < leftLW->count() - 1) - left_str = form_->controller().texName(qstring_to_ucs4(leftLW->currentItem()->text())[0]); + left_str = fromqstr(leftLW->currentItem()->toolTip()); if (rightLW->currentRow() < rightLW->count() - 1) - right_str = form_->controller().texName(qstring_to_ucs4(rightLW->currentItem()->text())[0]); + right_str = fromqstr(rightLW->currentItem()->toolTip()); int const size_ = sizeCO->currentIndex(); if (size_ == 0) { @@ -156,11 +180,8 @@ void QDelimiterDialog::on_leftLW_currentRowChanged(int item) // Display the associated TeX name. if (leftLW->currentRow() == leftLW->count() - 1) texCodeL->clear(); - else { - QString const str = toqstr(form_->controller().texName( - qstring_to_ucs4(leftLW->currentItem()->text())[0])); - texCodeL->setText("TeX code: \\" + str); - } + else + texCodeL->setText("TeX code: \\" + leftLW->currentItem()->toolTip()); } @@ -172,11 +193,8 @@ void QDelimiterDialog::on_rightLW_currentRowChanged(int item) // Display the associated TeX name. if (rightLW->currentRow() == leftLW->count() - 1) texCodeL->clear(); - else { - QString const str = toqstr(form_->controller().texName( - qstring_to_ucs4(rightLW->currentItem()->text())[0])); - texCodeL->setText("TeX code: \\" + str); - } + else + texCodeL->setText("TeX code: \\" + rightLW->currentItem()->toolTip()); } diff --git a/src/frontends/qt4/QDelimiterDialog.h b/src/frontends/qt4/QDelimiterDialog.h index 515ff84a41..ac8258f5b0 100644 --- a/src/frontends/qt4/QDelimiterDialog.h +++ b/src/frontends/qt4/QDelimiterDialog.h @@ -35,6 +35,8 @@ public Q_SLOTS: void on_matchCB_stateChanged(int); void insertClicked(); private: + /// + char_type doMatch(char_type const symbol) const; /// owning form QMathDelimiter * form_; }; -- 2.39.2