Make the delimiters dialog use true unicode symbols instead of pixmaps.

* ControlMath.[Ch]
  - mathSymbol(), texName(): new method for easy access of math symbols and associated TeX names
  - latex_delimiters: allowed delimiters transferred from QDelimiterDialog.C

* QDelimiterDialog.C:
  - makes use of the above.
  - display the TeX code in a label instead of beside the symbol.
 
* QDelimiterUi.ui
  - shrink it so that it could nicely fit in a DockWidget but this doesn't work, the dialog is too large!
  - texCodeL: new label.




git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17747 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-04-06 15:57:32 +00:00
parent d4e8fdd703
commit f9347bc672
4 changed files with 196 additions and 76 deletions

View File

@ -21,6 +21,7 @@
#include <functional>
using std::string;
using std::map;
namespace lyx {
@ -32,7 +33,50 @@ namespace frontend {
ControlMath::ControlMath(Dialog & dialog)
: Dialog::Controller(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<string, char_type>::const_iterator it = math_symbols_.begin();
std::map<string, char_type>::const_iterator end = math_symbols_.end();
for (; it != end; ++it)
tex_names_[it->second] = it->first;
}
void ControlMath::dispatchFunc(kb_action action, string const & arg) const
@ -97,6 +141,31 @@ void ControlMath::showDialog(string const & name) const
}
char_type ControlMath::mathSymbol(string tex_name) const
{
map<string, char_type>::const_iterator it =
math_symbols_.find(tex_name);
if (it == math_symbols_.end())
return '?';
return it->second;
}
std::string const & ControlMath::texName(char_type math_symbol) const
{
map<char_type, string>::const_iterator it =
tex_names_.find(math_symbol);
static string empty_string;
if (it == tex_names_.end())
return empty_string;
return it->second;
}
char const * function_names[] = {
"arccos", "arcsin", "arctan", "arg", "bmod",
"cos", "cosh", "cot", "coth", "csc", "deg",
@ -339,6 +408,16 @@ char const * latex_ams_ops[] = {
int const nr_latex_ams_ops = sizeof(latex_ams_ops) / sizeof(char const *);
char const * latex_delimiters[] = {
"(", ")", "{", "}", "[", "]",
"lceil", "rceil", "lfloor", "rfloor", "langle", "rangle",
"uparrow", "Uparrow", "downarrow", "Downarrow",
"|", "Vert", "/", "\\", ""
};
int const nr_latex_delimiters = sizeof(latex_delimiters) / sizeof(char const *);
namespace {
struct XPMmap {

View File

@ -18,6 +18,8 @@
#include "Dialog.h"
#include "lfuns.h" // for kb_action
#include <map>
namespace lyx {
namespace frontend {
@ -53,6 +55,19 @@ public:
* \param name the dialog identifier.
*/
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;
/// \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<std::string, char_type> math_symbols_;
/// Math-symbol / TeX-name map.
/// This one is for fast search, it contains the same data as
/// \c math_symbols_.
std::map<char_type, std::string> tex_names_;
};
@ -84,6 +99,8 @@ extern char const * latex_ams_nrel[];
extern int const nr_latex_ams_nrel;
extern char const * latex_ams_ops[];
extern int const nr_latex_ams_ops;
extern char const * latex_delimiters[];
extern int const nr_latex_delimiters;
/**
* Return the mangled XPM filename of the given

View File

@ -31,14 +31,6 @@ namespace frontend {
namespace {
string const delim[] = {
"(", ")", "{", "}", "[", "]",
"lceil", "rceil", "lfloor", "rfloor", "langle", "rangle",
"uparrow", "Uparrow", "downarrow", "Downarrow",
"|", "Vert", "slash", "backslash", ""
};
char const * const bigleft[] = {"bigl", "Bigl", "biggl", "Biggl", ""};
@ -49,7 +41,7 @@ char const * const biggui[] = {N_("big[[delimiter size]]"), N_("Big[[delimiter
N_("bigg[[delimiter size]]"), N_("Bigg[[delimiter size]]"), ""};
QString do_match(QString const & str)
string do_match(string const & str)
{
if (str == "(") return ")";
if (str == ")") return "(";
@ -64,24 +56,20 @@ QString do_match(QString const & str)
if (str == "lfloor") return "rfloor";
if (str == "rangle") return "langle";
if (str == "langle") return "rangle";
if (str == "backslash") return "slash";
if (str == "slash") return "backslash";
if (str == "\\") return "/";
if (str == "/") return "\\";
return str;
}
string fix_name(QString const & str, bool big)
string fix_name(string const & str, bool big)
{
if (str == "slash")
return "/";
if (str == "backslash")
return "\\";
if (str.isEmpty())
if (str.empty())
return ".";
if (!big || str == "(" || str == ")" || str == "[" || str == "]")
return fromqstr(str);
return str;
return "\\" + fromqstr(str);
return "\\" + str;
}
} // namespace anon
@ -97,20 +85,15 @@ QDelimiterDialog::QDelimiterDialog(QMathDelimiter * form)
setWindowTitle(qt_("LyX: Delimiters"));
setFocusProxy(leftLW);
// The last element is the empty one.
for (size_t i = 0; !delim[i].empty(); ++i) {
QString const left_d = toqstr(delim[i]);
QString const right_d = do_match(left_d);
if (left_d.size() == 1) {
leftLW->addItem(left_d);
rightLW->addItem(right_d);
} else {
QPixmap left_pm = QPixmap(toqstr(find_xpm(fromqstr(left_d))));
leftLW->addItem(new QListWidgetItem(QIcon(left_pm), left_d));
QPixmap right_pm = QPixmap(toqstr(find_xpm(fromqstr(right_d))));
rightLW->addItem(new QListWidgetItem(QIcon(right_pm), right_d));
}
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));
}
leftLW->addItem(qt_("(None)"));
@ -127,22 +110,24 @@ QDelimiterDialog::QDelimiterDialog(QMathDelimiter * form)
void QDelimiterDialog::insertClicked()
{
QString const left_ = (leftLW->currentRow() < leftLW->count() - 1)?
leftLW->currentItem()->text(): QString();
QString const right_ = (rightLW->currentRow() < rightLW->count() - 1)?
rightLW->currentItem()->text(): QString();
int const size_ = sizeCO->currentIndex();
string left_str;
string right_str;
if (leftLW->currentRow() < leftLW->count() - 1)
left_str = form_->controller().texName(qstring_to_ucs4(leftLW->currentItem()->text())[0]);
if (rightLW->currentRow() < rightLW->count() - 1)
right_str = form_->controller().texName(qstring_to_ucs4(rightLW->currentItem()->text())[0]);
int const size_ = sizeCO->currentIndex();
if (size_ == 0) {
form_->controller().dispatchDelim(
fix_name(left_, false) + ' ' +
fix_name(right_, false));
fix_name(left_str, false) + ' ' +
fix_name(right_str, false));
} else {
std::ostringstream os;
os << '"' << bigleft[size_ - 1] << "\" \""
<< fix_name(left_, true) << "\" \""
<< fix_name(left_str, true) << "\" \""
<< bigright[size_ - 1] << "\" \""
<< fix_name(right_, true) << '"';
<< fix_name(right_str, true) << '"';
form_->controller().dispatchBigDelim(os.str());
}
}
@ -166,6 +151,15 @@ void QDelimiterDialog::on_leftLW_currentRowChanged(int item)
{
if (matchCB->isChecked())
rightLW->setCurrentRow(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);
}
}
@ -173,6 +167,15 @@ void QDelimiterDialog::on_rightLW_currentRowChanged(int item)
{
if (matchCB->isChecked())
leftLW->setCurrentRow(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);
}
}

View File

@ -5,16 +5,30 @@
<rect>
<x>0</x>
<y>0</y>
<width>193</width>
<height>430</height>
<width>120</width>
<height>445</height>
</rect>
</property>
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>5</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>42</width>
<width>120</width>
<height>42</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>120</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle" >
<string/>
</property>
@ -28,31 +42,6 @@
<property name="spacing" >
<number>6</number>
</property>
<item row="2" column="1" >
<widget class="QComboBox" name="sizeCO" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2" >
<widget class="QCheckBox" name="matchCB" >
<property name="toolTip" >
<string>Match delimiter types</string>
</property>
<property name="text" >
<string>&amp;Keep matched</string>
</property>
<property name="checked" >
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2" >
<layout class="QHBoxLayout" >
<property name="margin" >
@ -73,7 +62,7 @@
</property>
<property name="maximumSize" >
<size>
<width>110</width>
<width>50</width>
<height>16777215</height>
</size>
</property>
@ -87,7 +76,7 @@
<enum>QListView::Adjust</enum>
</property>
<property name="spacing" >
<number>1</number>
<number>0</number>
</property>
<property name="currentRow" >
<number>-1</number>
@ -106,7 +95,7 @@
</property>
<property name="maximumSize" >
<size>
<width>110</width>
<width>50</width>
<height>16777215</height>
</size>
</property>
@ -117,13 +106,13 @@
</size>
</property>
<property name="spacing" >
<number>1</number>
<number>0</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0" >
<item row="3" column="0" >
<widget class="QLabel" name="label" >
<property name="text" >
<string>&amp;Size:</string>
@ -133,7 +122,7 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="2" >
<item row="4" column="0" colspan="2" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
@ -176,6 +165,38 @@
</item>
</layout>
</item>
<item row="2" column="0" colspan="2" >
<widget class="QCheckBox" name="matchCB" >
<property name="toolTip" >
<string>Match delimiter types</string>
</property>
<property name="text" >
<string>&amp;Keep matched</string>
</property>
<property name="checked" >
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="1" >
<widget class="QComboBox" name="sizeCO" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2" >
<widget class="QLabel" name="texCodeL" >
<property name="text" >
<string>TeX Code</string>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>