mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-11 13:46:43 +00:00
d66fbd6442
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5719 a592a061-630c-0410-9148-cb99ea01b6c8
328 lines
7.2 KiB
C
328 lines
7.2 KiB
C
/**
|
|
* \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>
|
|
|
|
#ifdef __GNUG__
|
|
#pragma implementation
|
|
#endif
|
|
|
|
#include "support/filetools.h"
|
|
#include "gettext.h"
|
|
#include "debug.h"
|
|
|
|
#include "ControlMath.h"
|
|
|
|
#include "QMathDialog.h"
|
|
#include "QMath.h"
|
|
|
|
#include "iconpalette.h"
|
|
#include "QDelimiterDialog.h"
|
|
#include "QMathMatrixDialog.h"
|
|
|
|
#include <qapplication.h>
|
|
#include <qwidgetstack.h>
|
|
#include <qcombobox.h>
|
|
#include <qpushbutton.h>
|
|
#include <qlistbox.h>
|
|
#include <qpixmap.h>
|
|
#include <qscrollview.h>
|
|
#include <qlayout.h>
|
|
#include <qpopupmenu.h>
|
|
#include <qcursor.h>
|
|
|
|
using std::min;
|
|
using std::max;
|
|
using std::endl;
|
|
|
|
|
|
class QScrollViewSingle : public QScrollView {
|
|
public:
|
|
QScrollViewSingle(QWidget * p)
|
|
: QScrollView(p), w_(0) {
|
|
setResizePolicy(Manual);
|
|
setHScrollBarMode(AlwaysOff);
|
|
setVScrollBarMode(AlwaysOn);
|
|
setBackgroundMode(PaletteBackground);
|
|
viewport()->setBackgroundMode(PaletteBackground);
|
|
}
|
|
|
|
void setChild(QWidget * w) {
|
|
w_ = w;
|
|
setMinimumWidth(verticalScrollBar()->width() + w_->width() + 4);
|
|
addChild(w_);
|
|
}
|
|
protected:
|
|
virtual void resizeEvent(QResizeEvent * e) {
|
|
QScrollView::resizeEvent(e);
|
|
if (!w_)
|
|
return;
|
|
|
|
w_->resize(viewport()->width(), w_->height());
|
|
// force the resize to get accurate scrollbars
|
|
qApp->processEvents();
|
|
resizeContents(w_->width(), w_->height());
|
|
}
|
|
private:
|
|
QWidget * w_;
|
|
};
|
|
|
|
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)
|
|
: QMathDialogBase(0, 0, false, 0),
|
|
form_(form)
|
|
{
|
|
// enlarge the symbols ComboBox (no scrollbar)
|
|
symbolsCO->setSizeLimit(13);
|
|
|
|
connect(symbolsCO, SIGNAL(activated(int)), symbolsWS, SLOT(raiseWidget(int)));
|
|
|
|
for (int i = 0; *function_names[i]; ++i) {
|
|
functionsLB->insertItem(function_names[i]);
|
|
}
|
|
|
|
for (int i = 0; i < nr_panels; ++i) {
|
|
QScrollViewSingle * view = new QScrollViewSingle(symbolsWS);
|
|
symbolsWS->addWidget(view, i);
|
|
}
|
|
|
|
// aboutToShow() only fires when != 0 in Qt 2 !
|
|
symbolsWS->raiseWidget(0);
|
|
addPanel(0);
|
|
panel_initialised[0] = true;
|
|
|
|
connect(symbolsWS, SIGNAL(aboutToShow(int)), this, SLOT(showingPanel(int)));
|
|
|
|
QPopupMenu * m = new QPopupMenu(spacePB);
|
|
m->setCaption(_("LyX: Insert space"));
|
|
m->insertTearOffHandle();
|
|
m->insertItem(_("Thin space \\,"), 1);
|
|
m->insertItem(_("Medium space \\:"), 2);
|
|
m->insertItem(_("Thick space \\;"), 3);
|
|
m->insertItem(_("Quadratin space \\quad"), 4);
|
|
m->insertItem(_("Double quadratin space \\qquad"), 5);
|
|
m->insertItem(_("Negative space \\!"), 6);
|
|
connect(m, SIGNAL(activated(int)), this, SLOT(insertSpace(int)));
|
|
spacePB->setPopup(m);
|
|
|
|
m = new QPopupMenu(sqrtPB);
|
|
m->setCaption(_("LyX: Insert root"));
|
|
m->insertTearOffHandle();
|
|
m->insertItem(_("Square root \\sqrt"), 1);
|
|
m->insertItem(_("Cube root \\root"), 2);
|
|
m->insertItem(_("Other root \\root"), 3);
|
|
connect(m, SIGNAL(activated(int)), this, SLOT(insertRoot(int)));
|
|
sqrtPB->setPopup(m);
|
|
|
|
m = new QPopupMenu(stylePB);
|
|
m->setCaption(_("LyX: Set math style"));
|
|
m->insertTearOffHandle();
|
|
m->insertItem(_("Display style \\displaystyle"), 1);
|
|
m->insertItem(_("Normal text style \\textstyle"), 2);
|
|
m->insertItem(_("Script (small) style \\scriptstyle"), 3);
|
|
m->insertItem(_("Scriptscript (smaller) style \\scriptscriptstyle"), 4);
|
|
connect(m, SIGNAL(activated(int)), this, SLOT(insertStyle(int)));
|
|
stylePB->setPopup(m);
|
|
|
|
m = new QPopupMenu(fontPB);
|
|
m->setCaption(_("LyX: Set math font"));
|
|
m->insertTearOffHandle();
|
|
m->insertItem(_("Roman \\mathrm"), 1);
|
|
m->insertItem(_("Bold \\mathbf"), 2);
|
|
m->insertItem(_("San serif \\mathsf"), 3);
|
|
m->insertItem(_("Italic \\mathit"), 4);
|
|
m->insertItem(_("Typewriter \\mathtt"), 5);
|
|
m->insertItem(_("Blackboard \\mathbb"), 6);
|
|
m->insertItem(_("Fraktur \\mathfrak"), 7);
|
|
m->insertItem(_("Calligraphic \\mathcal"), 8);
|
|
m->insertItem(_("Normal text mode \\textrm"), 9);
|
|
connect(m, SIGNAL(activated(int)), this, SLOT(insertFont(int)));
|
|
fontPB->setPopup(m);
|
|
}
|
|
|
|
|
|
void QMathDialog::showingPanel(int num)
|
|
{
|
|
if (panel_initialised[num])
|
|
return;
|
|
|
|
addPanel(num);
|
|
|
|
// Qt needs to catch up. Dunno why.
|
|
qApp->processEvents();
|
|
|
|
panel_initialised[num] = true;
|
|
}
|
|
|
|
|
|
IconPalette * QMathDialog::makePanel(QWidget * parent, char const ** entries)
|
|
{
|
|
IconPalette * p = new IconPalette(parent);
|
|
for (int i = 0; *entries[i]; ++i) {
|
|
p->add(QPixmap(find_xpm(entries[i]).c_str()), entries[i], string("\\") + entries[i]);
|
|
}
|
|
connect(p, SIGNAL(button_clicked(string const &)), this, SLOT(symbol_clicked(string const &)));
|
|
|
|
return p;
|
|
}
|
|
|
|
|
|
void QMathDialog::addPanel(int num)
|
|
{
|
|
QScrollViewSingle * view = static_cast<QScrollViewSingle*>(symbolsWS->visibleWidget());
|
|
IconPalette * p = makePanel(view->viewport(), panels[num]);
|
|
view->setChild(p);
|
|
}
|
|
|
|
|
|
void QMathDialog::symbol_clicked(string const & str)
|
|
{
|
|
form_->insert(str);
|
|
}
|
|
|
|
|
|
void QMathDialog::fracClicked()
|
|
{
|
|
form_->insert("frac");
|
|
}
|
|
|
|
|
|
void QMathDialog::delimiterClicked()
|
|
{
|
|
// FIXME: leak
|
|
QDelimiterDialog * d = new QDelimiterDialog(form_);
|
|
d->show();
|
|
}
|
|
|
|
|
|
void QMathDialog::expandClicked()
|
|
{
|
|
int const id = symbolsWS->id(symbolsWS->visibleWidget());
|
|
IconPalette * p = makePanel(0, panels[id]);
|
|
string s = "LyX: ";
|
|
s += symbolsCO->text(id).latin1();
|
|
p->setCaption(s.c_str());
|
|
p->resize(40 * 5, p->height());
|
|
p->show();
|
|
p->setMaximumSize(p->width(), p->height());
|
|
}
|
|
|
|
|
|
void QMathDialog::functionSelected(const QString & str)
|
|
{
|
|
form_->insert(str.latin1());
|
|
}
|
|
|
|
|
|
void QMathDialog::matrixClicked()
|
|
{
|
|
// FIXME: leak?
|
|
QMathMatrixDialog * d = new QMathMatrixDialog(form_);
|
|
d->show();
|
|
}
|
|
|
|
|
|
void QMathDialog::equationClicked()
|
|
{
|
|
form_->toggleDisplay();
|
|
}
|
|
|
|
|
|
void QMathDialog::subscriptClicked()
|
|
{
|
|
form_->subscript();
|
|
}
|
|
|
|
|
|
void QMathDialog::superscriptClicked()
|
|
{
|
|
form_->superscript();
|
|
}
|
|
|
|
|
|
void QMathDialog::insertSpace(int id)
|
|
{
|
|
string str;
|
|
switch (id) {
|
|
case 1: str = ","; break;
|
|
case 2: str = ":"; break;
|
|
case 3: str = ";"; break;
|
|
case 4: str = "quad"; break;
|
|
case 5: str = "qquad"; break;
|
|
case 6: str = "!"; break;
|
|
default: return;
|
|
}
|
|
form_->insert(str);
|
|
}
|
|
|
|
|
|
void QMathDialog::insertRoot(int id)
|
|
{
|
|
switch (id) {
|
|
case 1:
|
|
form_->insert("sqrt");
|
|
break;
|
|
case 2:
|
|
form_->insertCubeRoot();
|
|
break;
|
|
case 3:
|
|
form_->insert("root");
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
void QMathDialog::insertStyle(int id)
|
|
{
|
|
string str;
|
|
switch (id) {
|
|
case 1: str = "displaystyle"; break;
|
|
case 2: str = "textstyle"; break;
|
|
case 3: str = "scriptstyle"; break;
|
|
case 4: str = "scriptscriptstyle"; break;
|
|
default: return;
|
|
}
|
|
form_->insert(str);
|
|
}
|
|
|
|
|
|
void QMathDialog::insertFont(int id)
|
|
{
|
|
string str;
|
|
switch (id) {
|
|
case 1: str = "mathrm"; break;
|
|
case 2: str = "mathbf"; break;
|
|
case 3: str = "mathsf"; break;
|
|
case 4: str = "mathit"; break;
|
|
case 5: str = "mathtt"; break;
|
|
case 6: str = "mathbb"; break;
|
|
case 7: str = "mathfrak"; break;
|
|
case 8: str = "mathcal"; break;
|
|
case 9: str = "textrm"; break;
|
|
default: return;
|
|
}
|
|
form_->insert(str);
|
|
}
|