#include "FontInfo.h"
#include "FuncRequest.h"
-#include "support/gettext.h"
+#include "support/debug.h"
#include "support/docstring.h"
+#include "support/gettext.h"
+#include "support/lstrings.h"
#include <QPixmap>
#include <QCheckBox>
#include <QListWidgetItem>
+#include <QScrollBar>
#include <map>
#include <string>
static int const nr_latex_delimiters =
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[] = {
N_("big[[delimiter size]]"),
// FIXME: It might be better to fix the big delim LFUN to not require
// additional '\' prefix.
-static QString fix_name(QString const & str, bool big)
+static docstring fix_name(string const & str, bool big)
{
- if (str.isEmpty())
- return ".";
+ if (str.empty())
+ return from_ascii(".");
if (!big || str == "(" || str == ")" || str == "[" || str == "]"
|| str == "|" || str == "/")
- return str;
+ return from_ascii(str);
- return "\\" + str;
+ return "\\" + from_ascii(str);
}
struct MathSymbol {
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
initMathSymbols();
+ FontInfo lyxfont;
+ lyxfont.setFamily(CMR_FAMILY);
+ QFontMetrics fm(frontend::getFont(lyxfont));
+ QSize item_size(fm.maxWidth(), fm.height() + 8);
+
+ leftLW->setMinimumWidth(5 * item_size.width());
+ rightLW->setMinimumWidth(5 * item_size.width());
+
typedef map<char_type, QListWidgetItem *> ListItems;
ListItems list_items;
// The last element is the empty one.
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.
-#if defined(Q_OS_WIN) || defined(Q_CYGWIN_WIN)
QString symbol(ms.fontcode?
QChar(ms.fontcode) : toqstr(docstring(1, ms.unicode)));
QListWidgetItem * lwi = new QListWidgetItem(symbol);
- FontInfo lyxfont;
lyxfont.setFamily(ms.fontfamily);
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);
+ setDelimiterName(lwi, delim);
lwi->setToolTip(toqstr(delim));
+ lwi->setSizeHint(item_size);
+ switch (ms.fontfamily) {
+ case CMSY_FAMILY:
+ case STMARY_FAMILY:
+ // Hack to work around the broken metrics of these fonts
+ // FIXME: Better fix the fonts or use fonts that are not broken
+ lwi->setTextAlignment(Qt::AlignTop | Qt::AlignHCenter);
+ break;
+ default:
+ lwi->setTextAlignment(Qt::AlignCenter);
+ }
list_items[ms.unicode] = lwi;
leftLW->addItem(lwi);
}
for (int i = 0; i != leftLW->count(); ++i) {
- MathSymbol const & ms = mathSymbol(
- fromqstr(leftLW->item(i)->toolTip()));
+ MathSymbol const & ms = mathSymbol(getDelimiterName(leftLW->item(i)));
rightLW->addItem(list_items[doMatch(ms.unicode)]->clone());
}
// The last element is the empty one.
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_(biggui[i]));
on_leftLW_currentRowChanged(0);
+ // synchronise the scroll bars
+ on_matchCB_stateChanged(matchCB->checkState());
bc().setPolicy(ButtonPolicy::IgnorantPolicy);
}
{
bool const bigsize = size != 0;
- QString left_str = fix_name(leftLW->currentItem()->toolTip(), bigsize);
- QString right_str = fix_name(rightLW->currentItem()->toolTip(), bigsize);
+ docstring left_str = fix_name(getDelimiterName(leftLW->currentItem()),
+ bigsize);
+ docstring right_str = fix_name(getDelimiterName(rightLW->currentItem()),
+ bigsize);
if (!bigsize)
tex_code_ = left_str + ' ' + right_str;
else {
- tex_code_ = bigleft[size] + ' '
+ tex_code_ = from_ascii(bigleft[size]) + ' '
+ left_str + ' '
- + bigright[size] + ' '
+ + from_ascii(bigright[size]) + ' '
+ right_str;
}
// FIXME: retrieve the LateX code directly from mathed.
// In all cases, we want the '\' prefix if needed, so we pass 'true'
// to fix_name.
- left_str = fix_name(leftLW->currentItem()->toolTip(), true);
- right_str = fix_name(rightLW->currentItem()->toolTip(), true);
- QString code_str;
+ left_str = fix_name(getDelimiterName(leftLW->currentItem()),
+ true);
+ right_str = fix_name(getDelimiterName(rightLW->currentItem()),
+ true);
+ docstring code_str;
if (!bigsize)
code_str = "\\left" + left_str + " \\right" + right_str;
else {
// There should be nothing in the TeX-code when the delimiter is "None".
if (left_str != ".")
- code_str = "\\" + bigleft[size] + left_str + ' ';
+ code_str = "\\" + from_ascii(bigleft[size]) + left_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()
{
if (sizeCO->currentIndex() == 0)
- dispatch(FuncRequest(LFUN_MATH_DELIM, fromqstr(tex_code_)));
+ dispatch(FuncRequest(LFUN_MATH_DELIM, tex_code_));
else {
- QString command = '"' + tex_code_ + '"';
- command.replace(' ', "\" \"");
- dispatch(FuncRequest(LFUN_MATH_BIGDELIM, fromqstr(command)));
+ docstring command = '"' + tex_code_ + '"';
+ command = support::subst(command, from_ascii(" "), from_ascii("\" \""));
+ dispatch(FuncRequest(LFUN_MATH_BIGDELIM, command));
}
- }
+}
void GuiDelimiter::on_sizeCO_activated(int index)
void GuiDelimiter::on_matchCB_stateChanged(int state)
{
- if (state == Qt::Checked)
+ // Synchronise the vertical scroll bars when checked
+ QScrollBar * ls = leftLW->verticalScrollBar();
+ QScrollBar * rs = rightLW->verticalScrollBar();
+
+ if (state == Qt::Checked) {
on_leftLW_currentRowChanged(leftLW->currentRow());
+ connect(ls, SIGNAL(valueChanged(int)), rs, SLOT(setValue(int)),
+ Qt::UniqueConnection);
+ connect(rs, SIGNAL(valueChanged(int)), ls, SLOT(setValue(int)),
+ Qt::UniqueConnection);
+ rs->setValue(ls->value());
+ } else {
+ ls->disconnect(rs);
+ rs->disconnect(ls);
+ }
+
updateTeXCode(sizeCO->currentIndex());
}