2006-03-05 17:24:44 +00:00
|
|
|
/**
|
|
|
|
* \file QMathDialog.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 "QMathDialog.h"
|
|
|
|
#include "QMath.h"
|
2006-04-05 15:10:34 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QPixmap>
|
|
|
|
#include <QResizeEvent>
|
2006-04-05 15:10:34 +00:00
|
|
|
#include <QScrollArea>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QListWidget>
|
|
|
|
#include <QListWidgetItem>
|
|
|
|
#include <QIcon>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
#include "iconpalette.h"
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
#include "controllers/ControlMath.h"
|
|
|
|
#include "frontends/lyx_gui.h"
|
2006-04-09 21:14:58 +00:00
|
|
|
#include "support/filetools.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
2006-04-09 21:24:01 +00:00
|
|
|
using lyx::support::libFileSearch;
|
2006-04-09 21:14:58 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
char const ** panels[] = {
|
|
|
|
latex_bop, latex_varsz, latex_brel, latex_greek, latex_arrow,
|
|
|
|
latex_dots, latex_deco, latex_misc, latex_ams_ops,
|
|
|
|
latex_ams_rel, latex_ams_nrel, latex_ams_arrows,
|
|
|
|
latex_ams_misc
|
|
|
|
};
|
|
|
|
|
|
|
|
int const nr_panels = sizeof(panels)/sizeof(panels[0]);
|
|
|
|
|
|
|
|
bool panel_initialised[nr_panels];
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
|
QMathDialog::QMathDialog(QMath * form)
|
|
|
|
: form_(form)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
|
|
|
// enlarge the symbols ComboBox (no scrollbar)
|
|
|
|
//symbolsCO->setSizeLimit(13);
|
|
|
|
|
2006-04-05 15:10:34 +00:00
|
|
|
connect( tearoffPB, SIGNAL( clicked() ), this, SLOT( expandClicked() ) );
|
|
|
|
connect( closePB, SIGNAL( clicked() ), this, SLOT( accept() ) );
|
|
|
|
connect( fracPB, SIGNAL( clicked() ), this, SLOT( fracClicked() ) );
|
|
|
|
connect( superscriptPB, SIGNAL( clicked() ), this, SLOT( superscriptClicked() ) );
|
|
|
|
connect( subscriptPB, SIGNAL( clicked() ), this, SLOT( subscriptClicked() ) );
|
|
|
|
connect( delimitersPB, SIGNAL( clicked() ), this, SLOT( delimiterClicked() ) );
|
|
|
|
connect( matrixPB, SIGNAL( clicked() ), this, SLOT( matrixClicked() ) );
|
|
|
|
connect( functionsLW, SIGNAL( itemActivated(QListWidgetItem *) ), this, SLOT( functionSelected(QListWidgetItem *) ) );
|
|
|
|
connect( equationPB, SIGNAL( clicked() ), this, SLOT( equationClicked() ) );
|
|
|
|
connect( symbolsCO, SIGNAL(activated(int)), this, SLOT(showingPanel(int)));
|
|
|
|
|
2006-04-09 21:24:01 +00:00
|
|
|
string icon_path = libFileSearch("images/math", "sqrt-square", "xpm");
|
2006-04-09 21:14:58 +00:00
|
|
|
sqrtPB->setIcon(QIcon(toqstr(icon_path)));
|
2006-04-09 21:24:01 +00:00
|
|
|
icon_path = libFileSearch("images/math", "space", "xpm");
|
2006-04-09 21:14:58 +00:00
|
|
|
spacePB->setIcon(QIcon(toqstr(icon_path)));
|
2006-04-09 21:24:01 +00:00
|
|
|
icon_path = libFileSearch("images/math", "style", "xpm");
|
2006-04-09 21:14:58 +00:00
|
|
|
stylePB->setIcon(QIcon(toqstr(icon_path)));
|
2006-04-09 21:24:01 +00:00
|
|
|
icon_path = libFileSearch("images/math", "font", "xpm");
|
2006-04-09 21:14:58 +00:00
|
|
|
fontPB->setIcon(QIcon(toqstr(icon_path)));
|
2006-04-09 21:24:01 +00:00
|
|
|
icon_path = libFileSearch("images/math", "equation", "xpm");
|
2006-04-09 21:14:58 +00:00
|
|
|
equationPB->setIcon(QIcon(toqstr(icon_path)));
|
2006-04-09 21:24:01 +00:00
|
|
|
icon_path = libFileSearch("images/math", "frac-square", "xpm");
|
2006-04-09 21:14:58 +00:00
|
|
|
fracPB->setIcon(QIcon(toqstr(icon_path)));
|
2006-04-09 21:24:01 +00:00
|
|
|
icon_path = libFileSearch("images/math", "sub", "xpm");
|
2006-04-09 21:14:58 +00:00
|
|
|
subscriptPB->setIcon(QIcon(toqstr(icon_path)));
|
2006-04-09 21:24:01 +00:00
|
|
|
icon_path = libFileSearch("images/math", "super", "xpm");
|
2006-04-09 21:14:58 +00:00
|
|
|
superscriptPB->setIcon(QIcon(toqstr(icon_path)));
|
2006-04-09 21:24:01 +00:00
|
|
|
icon_path = libFileSearch("images/math", "matrix", "xpm");
|
2006-04-09 21:14:58 +00:00
|
|
|
matrixPB->setIcon(QIcon(toqstr(icon_path)));
|
2006-04-09 21:24:01 +00:00
|
|
|
icon_path = libFileSearch("images/math", "delim", "xpm");
|
2006-04-09 21:14:58 +00:00
|
|
|
delimitersPB->setIcon(QIcon(toqstr(icon_path)));
|
|
|
|
|
2006-04-05 15:10:34 +00:00
|
|
|
// function list
|
2006-03-05 17:24:44 +00:00
|
|
|
for (int i = 0; *function_names[i]; ++i) {
|
2006-04-05 15:10:34 +00:00
|
|
|
functionsLW->addItem(function_names[i]);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
2006-04-06 15:08:48 +00:00
|
|
|
//functionsLW->setFixedWidth(functionsLW->sizeHint().width());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-05 15:10:34 +00:00
|
|
|
// add first symbol panel
|
2006-03-05 17:24:44 +00:00
|
|
|
addPanel(0);
|
2006-04-05 15:10:34 +00:00
|
|
|
showingPanel(0);
|
|
|
|
// 5 buttons + 2 margins + 1 scrollbar
|
|
|
|
symbolWS->setFixedWidth(5*40 + 2*10 + 15 );
|
|
|
|
|
|
|
|
// add menu's to the buttons
|
|
|
|
QMenu * m = new QMenu(spacePB);
|
|
|
|
m->setTitle(qt_("LyX: Math Spacing"));
|
|
|
|
m->setTearOffEnabled(true);
|
|
|
|
addMenuItem(m, qt_("Thin space \\,"), ",");
|
|
|
|
addMenuItem(m, qt_("Medium space \\:"), ":");
|
|
|
|
addMenuItem(m, qt_("Thick space \\;"), ";");
|
|
|
|
addMenuItem(m, qt_("Quadratin space \\quad"), "quad");
|
|
|
|
addMenuItem(m, qt_("Double quadratin space \\qquad"), "qquad");
|
|
|
|
addMenuItem(m, qt_("Negative space \\!"), "!");
|
|
|
|
spacePB->setMenu(m);
|
|
|
|
|
|
|
|
m = new QMenu(sqrtPB);
|
|
|
|
m->setTitle(qt_("LyX: Math Roots"));
|
|
|
|
m->setTearOffEnabled(true);
|
|
|
|
addMenuItem(m, qt_("Square root \\sqrt"), "sqrt");
|
|
|
|
QAction * ma = new QAction(qt_("Cube root \\root"), this);
|
|
|
|
connect(ma, SIGNAL(triggered()), this, SLOT(insertCubeRoot()));
|
|
|
|
m->addAction(ma);
|
|
|
|
addMenuItem(m, qt_("Other root \\root"), "root");
|
2006-03-05 17:24:44 +00:00
|
|
|
sqrtPB->setPopup(m);
|
|
|
|
|
2006-04-05 15:10:34 +00:00
|
|
|
m = new QMenu(stylePB);
|
|
|
|
m->setTitle(qt_("LyX: Math Styles"));
|
|
|
|
m->setTearOffEnabled(true);
|
|
|
|
addMenuItem(m, qt_("Display style \\displaystyle"), "displaystyle");
|
|
|
|
addMenuItem(m, qt_("Normal text style \\textstyle"), "textstyle");
|
|
|
|
addMenuItem(m, qt_("Script (small) style \\scriptstyle"), "scriptstyle");
|
|
|
|
addMenuItem(m, qt_("Scriptscript (smaller) style \\scriptscriptstyle"), "scriptscriptstyle");
|
2006-03-05 17:24:44 +00:00
|
|
|
stylePB->setPopup(m);
|
|
|
|
|
2006-04-05 15:10:34 +00:00
|
|
|
m = new QMenu(fontPB);
|
|
|
|
m->setTitle(qt_("LyX: Math Fonts"));
|
|
|
|
m->setTearOffEnabled(true);
|
|
|
|
addMenuItem(m, qt_("Roman \\mathrm"), "mathrm");
|
|
|
|
addMenuItem(m, qt_("Bold \\mathbf"), "mathbf");
|
|
|
|
addMenuItem(m, qt_("Bold symbol \\boldsymbol"), "boldsymbol");
|
|
|
|
addMenuItem(m, qt_("Sans serif \\mathsf"), "mathsf");
|
|
|
|
addMenuItem(m, qt_("Italic \\mathit"), "mathit");
|
|
|
|
addMenuItem(m, qt_("Typewriter \\mathtt"), "mathtt");
|
|
|
|
addMenuItem(m, qt_("Blackboard \\mathbb"), "mathbb");
|
|
|
|
addMenuItem(m, qt_("Fraktur \\mathfrak"), "mathfrak");
|
|
|
|
addMenuItem(m, qt_("Calligraphic \\mathcal"), "mathcal");
|
|
|
|
addMenuItem(m, qt_("Normal text mode \\textrm"), "textrm");
|
2006-03-05 17:24:44 +00:00
|
|
|
fontPB->setPopup(m);
|
|
|
|
}
|
|
|
|
|
2006-04-05 15:10:34 +00:00
|
|
|
void QMathDialog::addMenuItem(QMenu * menu, const QString & label, const std::string & action)
|
|
|
|
{
|
|
|
|
QMAction * ma = new QMAction(label,action, this);
|
|
|
|
connect(ma, SIGNAL(action(const std::string &)), this, SLOT(symbol_clicked(const std::string &)));
|
|
|
|
menu->addAction(ma);
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
void QMathDialog::showingPanel(int num)
|
|
|
|
{
|
2006-04-05 15:10:34 +00:00
|
|
|
if (!panel_initialised[num])
|
|
|
|
addPanel(num);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-05 15:10:34 +00:00
|
|
|
symbolWS->setCurrentIndex(num);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IconPalette * QMathDialog::makePanel(QWidget * parent, char const ** entries)
|
|
|
|
{
|
|
|
|
IconPalette * p = new IconPalette(parent);
|
|
|
|
for (int i = 0; *entries[i]; ++i) {
|
|
|
|
p->add(QPixmap(toqstr(find_xpm(entries[i]))), entries[i], string("\\") + entries[i]);
|
|
|
|
}
|
|
|
|
// Leave these std:: qualifications alone !
|
|
|
|
connect(p, SIGNAL(button_clicked(const std::string &)),
|
|
|
|
this, SLOT(symbol_clicked(const std::string &)));
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMathDialog::addPanel(int num)
|
|
|
|
{
|
2006-04-05 15:10:34 +00:00
|
|
|
QScrollArea * sc = new QScrollArea(symbolWS);
|
|
|
|
IconPalette * p = makePanel(this, panels[num]);
|
|
|
|
p->resize(40 * 5, p->height());
|
|
|
|
sc->setWidget(p);
|
|
|
|
symbolWS->insertWidget(num,sc);
|
|
|
|
panel_initialised[num] = true;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMathDialog::symbol_clicked(const string & str)
|
|
|
|
{
|
|
|
|
form_->controller().dispatchInsert(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMathDialog::fracClicked()
|
|
|
|
{
|
|
|
|
form_->controller().dispatchInsert("frac");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMathDialog::delimiterClicked()
|
|
|
|
{
|
|
|
|
form_->controller().showDialog("mathdelimiter");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMathDialog::expandClicked()
|
|
|
|
{
|
2006-04-05 15:10:34 +00:00
|
|
|
int const id = symbolsCO->currentIndex();
|
2006-03-05 17:24:44 +00:00
|
|
|
IconPalette * p = makePanel(0, panels[id]);
|
|
|
|
string s = "LyX: ";
|
2006-04-05 15:10:34 +00:00
|
|
|
s += fromqstr(symbolsCO->currentText());
|
2006-03-05 17:24:44 +00:00
|
|
|
p->setCaption(toqstr(s));
|
|
|
|
p->resize(40 * 5, p->height());
|
|
|
|
p->show();
|
|
|
|
p->setMaximumSize(p->width(), p->height());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-05 15:10:34 +00:00
|
|
|
void QMathDialog::functionSelected(QListWidgetItem * item)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-04-05 15:10:34 +00:00
|
|
|
form_->controller().dispatchInsert(fromqstr(item->text()));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMathDialog::matrixClicked()
|
|
|
|
{
|
|
|
|
form_->controller().showDialog("mathmatrix");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMathDialog::equationClicked()
|
|
|
|
{
|
|
|
|
form_->controller().dispatchToggleDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMathDialog::subscriptClicked()
|
|
|
|
{
|
|
|
|
form_->controller().dispatchSubscript();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMathDialog::superscriptClicked()
|
|
|
|
{
|
|
|
|
form_->controller().dispatchSuperscript();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-05 15:10:34 +00:00
|
|
|
void QMathDialog::insertCubeRoot()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-04-05 15:10:34 +00:00
|
|
|
form_->controller().dispatchCubeRoot();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|