mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Do not rely on toolTip() to generate LaTeX code
This commit is contained in:
parent
b692e3a484
commit
2a4538ad56
@ -24,6 +24,7 @@
|
|||||||
#include "support/debug.h"
|
#include "support/debug.h"
|
||||||
#include "support/docstring.h"
|
#include "support/docstring.h"
|
||||||
#include "support/gettext.h"
|
#include "support/gettext.h"
|
||||||
|
#include "support/lstrings.h"
|
||||||
|
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
@ -51,9 +52,9 @@ static char const * latex_delimiters[] = {
|
|||||||
static int const nr_latex_delimiters =
|
static int const nr_latex_delimiters =
|
||||||
sizeof(latex_delimiters) / sizeof(char const *);
|
sizeof(latex_delimiters) / sizeof(char const *);
|
||||||
|
|
||||||
static QString const bigleft[] = {"", "bigl", "Bigl", "biggl", "Biggl"};
|
static string const bigleft[] = {"", "bigl", "Bigl", "biggl", "Biggl"};
|
||||||
|
|
||||||
static QString const bigright[] = {"", "bigr", "Bigr", "biggr", "Biggr"};
|
static string const bigright[] = {"", "bigr", "Bigr", "biggr", "Biggr"};
|
||||||
|
|
||||||
static char const * const biggui[] = {
|
static char const * const biggui[] = {
|
||||||
N_("big[[delimiter size]]"),
|
N_("big[[delimiter size]]"),
|
||||||
@ -66,15 +67,15 @@ static char const * const biggui[] = {
|
|||||||
|
|
||||||
// FIXME: It might be better to fix the big delim LFUN to not require
|
// FIXME: It might be better to fix the big delim LFUN to not require
|
||||||
// additional '\' prefix.
|
// additional '\' prefix.
|
||||||
static QString fix_name(QString const & str, bool big)
|
static docstring fix_name(string const & str, bool big)
|
||||||
{
|
{
|
||||||
if (str.isEmpty())
|
if (str.empty())
|
||||||
return ".";
|
return from_ascii(".");
|
||||||
if (!big || str == "(" || str == ")" || str == "[" || str == "]"
|
if (!big || str == "(" || str == ")" || str == "[" || str == "]"
|
||||||
|| str == "|" || str == "/")
|
|| str == "|" || str == "/")
|
||||||
return str;
|
return from_ascii(str);
|
||||||
|
|
||||||
return "\\" + str;
|
return "\\" + from_ascii(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MathSymbol {
|
struct MathSymbol {
|
||||||
@ -162,6 +163,19 @@ string const & texName(char_type math_symbol)
|
|||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void setDelimiterName(QListWidgetItem * lwi, string const & name)
|
||||||
|
{
|
||||||
|
lwi->setData(Qt::UserRole, toqstr(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
string getDelimiterName(QListWidgetItem const * lwi)
|
||||||
|
{
|
||||||
|
return fromqstr(lwi->data(Qt::UserRole).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // anon namespace
|
} // anon namespace
|
||||||
|
|
||||||
|
|
||||||
@ -200,6 +214,7 @@ GuiDelimiter::GuiDelimiter(GuiView & lv)
|
|||||||
lyxfont.setFamily(ms.fontfamily);
|
lyxfont.setFamily(ms.fontfamily);
|
||||||
QFont font = frontend::getFont(lyxfont);
|
QFont font = frontend::getFont(lyxfont);
|
||||||
lwi->setFont(font);
|
lwi->setFont(font);
|
||||||
|
setDelimiterName(lwi, delim);
|
||||||
lwi->setToolTip(toqstr(delim));
|
lwi->setToolTip(toqstr(delim));
|
||||||
lwi->setSizeHint(item_size);
|
lwi->setSizeHint(item_size);
|
||||||
switch (ms.fontfamily) {
|
switch (ms.fontfamily) {
|
||||||
@ -217,8 +232,7 @@ GuiDelimiter::GuiDelimiter(GuiView & lv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i != leftLW->count(); ++i) {
|
for (int i = 0; i != leftLW->count(); ++i) {
|
||||||
MathSymbol const & ms = mathSymbol(
|
MathSymbol const & ms = mathSymbol(getDelimiterName(leftLW->item(i)));
|
||||||
fromqstr(leftLW->item(i)->toolTip()));
|
|
||||||
rightLW->addItem(list_items[doMatch(ms.unicode)]->clone());
|
rightLW->addItem(list_items[doMatch(ms.unicode)]->clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,15 +283,17 @@ void GuiDelimiter::updateTeXCode(int size)
|
|||||||
{
|
{
|
||||||
bool const bigsize = size != 0;
|
bool const bigsize = size != 0;
|
||||||
|
|
||||||
QString left_str = fix_name(leftLW->currentItem()->toolTip(), bigsize);
|
docstring left_str = fix_name(getDelimiterName(leftLW->currentItem()),
|
||||||
QString right_str = fix_name(rightLW->currentItem()->toolTip(), bigsize);
|
bigsize);
|
||||||
|
docstring right_str = fix_name(getDelimiterName(rightLW->currentItem()),
|
||||||
|
bigsize);
|
||||||
|
|
||||||
if (!bigsize)
|
if (!bigsize)
|
||||||
tex_code_ = left_str + ' ' + right_str;
|
tex_code_ = left_str + ' ' + right_str;
|
||||||
else {
|
else {
|
||||||
tex_code_ = bigleft[size] + ' '
|
tex_code_ = from_ascii(bigleft[size]) + ' '
|
||||||
+ left_str + ' '
|
+ left_str + ' '
|
||||||
+ bigright[size] + ' '
|
+ from_ascii(bigright[size]) + ' '
|
||||||
+ right_str;
|
+ right_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,33 +302,35 @@ void GuiDelimiter::updateTeXCode(int size)
|
|||||||
// FIXME: retrieve the LateX code directly from mathed.
|
// FIXME: retrieve the LateX code directly from mathed.
|
||||||
// In all cases, we want the '\' prefix if needed, so we pass 'true'
|
// In all cases, we want the '\' prefix if needed, so we pass 'true'
|
||||||
// to fix_name.
|
// to fix_name.
|
||||||
left_str = fix_name(leftLW->currentItem()->toolTip(), true);
|
left_str = fix_name(getDelimiterName(leftLW->currentItem()),
|
||||||
right_str = fix_name(rightLW->currentItem()->toolTip(), true);
|
true);
|
||||||
QString code_str;
|
right_str = fix_name(getDelimiterName(rightLW->currentItem()),
|
||||||
|
true);
|
||||||
|
docstring code_str;
|
||||||
if (!bigsize)
|
if (!bigsize)
|
||||||
code_str = "\\left" + left_str + " \\right" + right_str;
|
code_str = "\\left" + left_str + " \\right" + right_str;
|
||||||
else {
|
else {
|
||||||
// There should be nothing in the TeX-code when the delimiter is "None".
|
// There should be nothing in the TeX-code when the delimiter is "None".
|
||||||
if (left_str != ".")
|
if (left_str != ".")
|
||||||
code_str = "\\" + bigleft[size] + left_str + ' ';
|
code_str = "\\" + from_ascii(bigleft[size]) + left_str + ' ';
|
||||||
if (right_str != ".")
|
if (right_str != ".")
|
||||||
code_str += "\\" + bigright[size] + right_str;
|
code_str += "\\" + from_ascii(bigright[size]) + right_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
texCodeL->setText(qt_("TeX Code: ") + code_str);
|
texCodeL->setText(qt_("TeX Code: ") + toqstr(code_str));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiDelimiter::on_insertPB_clicked()
|
void GuiDelimiter::on_insertPB_clicked()
|
||||||
{
|
{
|
||||||
if (sizeCO->currentIndex() == 0)
|
if (sizeCO->currentIndex() == 0)
|
||||||
dispatch(FuncRequest(LFUN_MATH_DELIM, fromqstr(tex_code_)));
|
dispatch(FuncRequest(LFUN_MATH_DELIM, tex_code_));
|
||||||
else {
|
else {
|
||||||
QString command = '"' + tex_code_ + '"';
|
docstring command = '"' + tex_code_ + '"';
|
||||||
command.replace(' ', "\" \"");
|
command = support::subst(command, from_ascii(" "), from_ascii("\" \""));
|
||||||
dispatch(FuncRequest(LFUN_MATH_BIGDELIM, fromqstr(command)));
|
dispatch(FuncRequest(LFUN_MATH_BIGDELIM, command));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiDelimiter::on_sizeCO_activated(int index)
|
void GuiDelimiter::on_sizeCO_activated(int index)
|
||||||
|
@ -49,7 +49,7 @@ private:
|
|||||||
void updateTeXCode(int size);
|
void updateTeXCode(int size);
|
||||||
|
|
||||||
/// TeX code that will be inserted.
|
/// TeX code that will be inserted.
|
||||||
QString tex_code_;
|
docstring tex_code_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
|
Loading…
Reference in New Issue
Block a user