2006-03-05 17:24:44 +00:00
|
|
|
/**
|
|
|
|
* \file QDelimiterDialog.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "QDelimiterDialog.h"
|
2007-04-12 16:49:01 +00:00
|
|
|
|
|
|
|
#include "GuiApplication.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "QMath.h"
|
|
|
|
|
2006-08-16 14:22:47 +00:00
|
|
|
#include "qt_helpers.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "controllers/ControlMath.h"
|
|
|
|
|
2006-08-16 14:22:47 +00:00
|
|
|
#include "gettext.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-08-16 14:22:47 +00:00
|
|
|
#include <QPixmap>
|
|
|
|
#include <QCheckBox>
|
2007-04-05 12:12:07 +00:00
|
|
|
#include <QListWidgetItem>
|
2006-08-16 14:22:47 +00:00
|
|
|
|
|
|
|
#include <sstream>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-04-12 16:49:01 +00:00
|
|
|
// Set to zero if unicode symbols are preferred.
|
|
|
|
#define USE_PIXMAP 1
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
using std::string;
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2006-08-16 14:22:47 +00:00
|
|
|
char const * const bigleft[] = {"bigl", "Bigl", "biggl", "Biggl", ""};
|
|
|
|
|
|
|
|
|
|
|
|
char const * const bigright[] = {"bigr", "Bigr", "biggr", "Biggr", ""};
|
|
|
|
|
|
|
|
|
2006-11-05 17:38:58 +00:00
|
|
|
char const * const biggui[] = {N_("big[[delimiter size]]"), N_("Big[[delimiter size]]"),
|
|
|
|
N_("bigg[[delimiter size]]"), N_("Bigg[[delimiter size]]"), ""};
|
2006-08-16 14:22:47 +00:00
|
|
|
|
|
|
|
|
2007-04-06 15:57:32 +00:00
|
|
|
string fix_name(string const & str, bool big)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-04-06 15:57:32 +00:00
|
|
|
if (str.empty())
|
2006-03-05 17:24:44 +00:00
|
|
|
return ".";
|
2007-04-07 02:07:15 +00:00
|
|
|
if (!big || str == "(" || str == ")" || str == "[" || str == "]"
|
|
|
|
|| str == "|" || str == "/")
|
2007-04-06 15:57:32 +00:00
|
|
|
return str;
|
2006-08-16 14:22:47 +00:00
|
|
|
|
2007-04-11 00:27:35 +00:00
|
|
|
return "\\" + str;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2007-04-12 16:49:01 +00:00
|
|
|
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";
|
2007-04-14 16:19:05 +00:00
|
|
|
else if (str == "backslash") match = "/";
|
|
|
|
else if (str == "/") match = "backslash";
|
2007-04-12 16:49:01 +00:00
|
|
|
else return symbol;
|
|
|
|
|
|
|
|
return form_->controller().mathSymbol(match).unicode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
QDelimiterDialog::QDelimiterDialog(QMathDelimiter * form)
|
|
|
|
: form_(form)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
2006-08-16 14:22:47 +00:00
|
|
|
connect(closePB, SIGNAL(clicked()), this, SLOT(accept()));
|
|
|
|
connect(insertPB, SIGNAL(clicked()), this, SLOT(insertClicked()));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-08-17 08:52:59 +00:00
|
|
|
setWindowTitle(qt_("LyX: Delimiters"));
|
2007-04-05 12:12:07 +00:00
|
|
|
setFocusProxy(leftLW);
|
2007-04-06 15:57:32 +00:00
|
|
|
|
2007-04-12 16:49:01 +00:00
|
|
|
typedef std::map<char_type, QListWidgetItem *> ListItems;
|
|
|
|
ListItems list_items;
|
2007-04-05 09:26:09 +00:00
|
|
|
// The last element is the empty one.
|
2007-04-12 16:49:01 +00:00
|
|
|
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;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-04-12 16:49:01 +00:00
|
|
|
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.
|
2007-04-05 12:12:07 +00:00
|
|
|
leftLW->addItem(qt_("(None)"));
|
|
|
|
rightLW->addItem(qt_("(None)"));
|
2006-08-16 14:22:47 +00:00
|
|
|
|
2006-12-10 10:07:31 +00:00
|
|
|
sizeCO->addItem(qt_("Variable"));
|
2006-09-12 01:17:03 +00:00
|
|
|
|
2006-08-16 14:22:47 +00:00
|
|
|
for (int i = 0; *biggui[i]; ++i)
|
|
|
|
sizeCO->addItem(qt_(biggui[i]));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-04-05 12:12:07 +00:00
|
|
|
on_leftLW_currentRowChanged(0);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QDelimiterDialog::insertClicked()
|
|
|
|
{
|
2007-04-06 15:57:32 +00:00
|
|
|
string left_str;
|
|
|
|
string right_str;
|
|
|
|
if (leftLW->currentRow() < leftLW->count() - 1)
|
2007-04-12 16:49:01 +00:00
|
|
|
left_str = fromqstr(leftLW->currentItem()->toolTip());
|
2007-04-06 15:57:32 +00:00
|
|
|
if (rightLW->currentRow() < rightLW->count() - 1)
|
2007-04-12 16:49:01 +00:00
|
|
|
right_str = fromqstr(rightLW->currentItem()->toolTip());
|
2006-08-16 14:22:47 +00:00
|
|
|
|
2007-04-06 15:57:32 +00:00
|
|
|
int const size_ = sizeCO->currentIndex();
|
2006-08-16 14:22:47 +00:00
|
|
|
if (size_ == 0) {
|
|
|
|
form_->controller().dispatchDelim(
|
2007-04-06 15:57:32 +00:00
|
|
|
fix_name(left_str, false) + ' ' +
|
|
|
|
fix_name(right_str, false));
|
2006-08-16 14:22:47 +00:00
|
|
|
} else {
|
|
|
|
std::ostringstream os;
|
|
|
|
os << '"' << bigleft[size_ - 1] << "\" \""
|
2007-04-06 15:57:32 +00:00
|
|
|
<< fix_name(left_str, true) << "\" \""
|
2006-08-16 14:22:47 +00:00
|
|
|
<< bigright[size_ - 1] << "\" \""
|
2007-04-06 15:57:32 +00:00
|
|
|
<< fix_name(right_str, true) << '"';
|
2006-08-16 14:22:47 +00:00
|
|
|
form_->controller().dispatchBigDelim(os.str());
|
|
|
|
}
|
2007-04-05 12:12:07 +00:00
|
|
|
}
|
|
|
|
|
2006-08-16 14:22:47 +00:00
|
|
|
|
2007-04-05 12:12:07 +00:00
|
|
|
void QDelimiterDialog::on_leftLW_itemActivated(QListWidgetItem *)
|
|
|
|
{
|
2007-04-05 12:39:22 +00:00
|
|
|
insertClicked();
|
|
|
|
accept();
|
|
|
|
}
|
2007-04-05 12:12:07 +00:00
|
|
|
|
2007-04-05 12:39:22 +00:00
|
|
|
|
|
|
|
void QDelimiterDialog::on_rightLW_itemActivated(QListWidgetItem *)
|
|
|
|
{
|
2007-04-05 12:12:07 +00:00
|
|
|
insertClicked();
|
|
|
|
accept();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-05 12:12:07 +00:00
|
|
|
void QDelimiterDialog::on_leftLW_currentRowChanged(int item)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-04-05 12:12:07 +00:00
|
|
|
if (matchCB->isChecked())
|
|
|
|
rightLW->setCurrentRow(item);
|
2007-04-06 15:57:32 +00:00
|
|
|
|
|
|
|
// Display the associated TeX name.
|
|
|
|
if (leftLW->currentRow() == leftLW->count() - 1)
|
|
|
|
texCodeL->clear();
|
2007-04-12 16:49:01 +00:00
|
|
|
else
|
|
|
|
texCodeL->setText("TeX code: \\" + leftLW->currentItem()->toolTip());
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-05 12:12:07 +00:00
|
|
|
void QDelimiterDialog::on_rightLW_currentRowChanged(int item)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-04-05 12:12:07 +00:00
|
|
|
if (matchCB->isChecked())
|
|
|
|
leftLW->setCurrentRow(item);
|
2007-04-06 15:57:32 +00:00
|
|
|
|
|
|
|
// Display the associated TeX name.
|
|
|
|
if (rightLW->currentRow() == leftLW->count() - 1)
|
|
|
|
texCodeL->clear();
|
2007-04-12 16:49:01 +00:00
|
|
|
else
|
|
|
|
texCodeL->setText("TeX code: \\" + rightLW->currentItem()->toolTip());
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-16 14:22:47 +00:00
|
|
|
void QDelimiterDialog::on_matchCB_stateChanged(int state)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-08-16 14:22:47 +00:00
|
|
|
if (state == Qt::Checked)
|
2007-04-05 12:12:07 +00:00
|
|
|
on_leftLW_currentRowChanged(leftLW->currentRow());
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-08-16 14:22:47 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2006-05-18 08:51:12 +00:00
|
|
|
|
|
|
|
#include "QDelimiterDialog_moc.cpp"
|