2002-08-30 16:20:27 +00:00
|
|
|
/**
|
|
|
|
* \file QMathDialog.C
|
|
|
|
* Copyright 2001 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
|
|
|
* \author John Levon <moz@compsoc.man.ac.uk>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "support/filetools.h"
|
2002-09-14 01:44:58 +00:00
|
|
|
#include "gettext.h"
|
2002-09-06 01:44:02 +00:00
|
|
|
#include "debug.h"
|
2002-08-30 16:20:27 +00:00
|
|
|
|
|
|
|
#include "QMathDialog.h"
|
|
|
|
#include "QMath.h"
|
|
|
|
|
|
|
|
#include "ControlMath.h"
|
|
|
|
#include "iconpalette.h"
|
|
|
|
|
2002-09-12 00:25:59 +00:00
|
|
|
#include <qapplication.h>
|
2002-08-30 16:20:27 +00:00
|
|
|
#include <qwidgetstack.h>
|
|
|
|
#include <qcombobox.h>
|
2002-09-14 01:44:58 +00:00
|
|
|
#include <qpushbutton.h>
|
2002-08-30 16:20:27 +00:00
|
|
|
#include <qlistbox.h>
|
|
|
|
#include <qpixmap.h>
|
2002-09-06 01:44:02 +00:00
|
|
|
#include <qscrollview.h>
|
|
|
|
#include <qlayout.h>
|
2002-09-14 01:44:58 +00:00
|
|
|
#include <qpopupmenu.h>
|
|
|
|
#include <qcursor.h>
|
2002-08-30 16:20:27 +00:00
|
|
|
|
2002-09-08 01:14:08 +00:00
|
|
|
using std::min;
|
|
|
|
using std::max;
|
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
class QScrollViewSingle : public QScrollView {
|
|
|
|
public:
|
|
|
|
QScrollViewSingle(QWidget * p)
|
2002-09-12 00:56:53 +00:00
|
|
|
: QScrollView(p), w_(0) {
|
2002-09-08 01:14:08 +00:00
|
|
|
setResizePolicy(Manual);
|
|
|
|
setHScrollBarMode(AlwaysOff);
|
|
|
|
setVScrollBarMode(AlwaysOn);
|
2002-09-08 02:37:57 +00:00
|
|
|
setBackgroundMode(PaletteBackground);
|
|
|
|
viewport()->setBackgroundMode(PaletteBackground);
|
2002-09-08 01:14:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2002-09-08 02:37:57 +00:00
|
|
|
w_->resize(viewport()->width(), w_->height());
|
2002-09-12 00:25:59 +00:00
|
|
|
// force the resize to get accurate scrollbars
|
|
|
|
qApp->processEvents();
|
2002-09-08 01:14:08 +00:00
|
|
|
resizeContents(w_->width(), w_->height());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QWidget * w_;
|
|
|
|
};
|
|
|
|
|
2002-09-08 02:57:10 +00:00
|
|
|
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]);
|
2002-09-12 00:56:53 +00:00
|
|
|
|
|
|
|
bool panel_initialised[nr_panels];
|
2002-09-08 02:57:10 +00:00
|
|
|
}
|
|
|
|
|
2002-09-08 01:14:08 +00:00
|
|
|
|
2002-08-30 16:20:27 +00:00
|
|
|
QMathDialog::QMathDialog(QMath * form)
|
|
|
|
: QMathDialogBase(0, 0, false, 0),
|
|
|
|
form_(form)
|
|
|
|
{
|
|
|
|
connect(symbolsCO, SIGNAL(activated(int)), symbolsWS, SLOT(raiseWidget(int)));
|
|
|
|
|
|
|
|
for (int i = 0; *function_names[i]; ++i) {
|
|
|
|
functionsLB->insertItem(function_names[i]);
|
|
|
|
}
|
|
|
|
|
2002-09-12 00:56:53 +00:00
|
|
|
for (int i = 0; i < nr_panels; ++i) {
|
|
|
|
QScrollViewSingle * view = new QScrollViewSingle(symbolsWS);
|
|
|
|
symbolsWS->addWidget(view, i);
|
2002-09-08 02:57:10 +00:00
|
|
|
}
|
2002-09-12 00:56:53 +00:00
|
|
|
|
|
|
|
// aboutToShow() only fires when != 0 in Qt 2 !
|
2002-08-30 16:20:27 +00:00
|
|
|
symbolsWS->raiseWidget(0);
|
2002-09-12 00:56:53 +00:00
|
|
|
addPanel(0);
|
|
|
|
panel_initialised[0] = true;
|
|
|
|
|
|
|
|
connect(symbolsWS, SIGNAL(aboutToShow(int)), this, SLOT(showingPanel(int)));
|
2002-09-14 01:44:58 +00:00
|
|
|
|
|
|
|
space_menu_ = new QPopupMenu(spacePB);
|
|
|
|
space_menu_->insertItem(_("Thin space \\,"), 1);
|
|
|
|
space_menu_->insertItem(_("Medium space \\:"), 2);
|
|
|
|
space_menu_->insertItem(_("Thick space \\;"), 3);
|
|
|
|
space_menu_->insertItem(_("Quadratin space \\quad"), 4);
|
|
|
|
space_menu_->insertItem(_("Double quadratin space \\qquad"), 5);
|
|
|
|
space_menu_->insertItem(_("Negative space \\!"), 6);
|
|
|
|
connect(space_menu_, SIGNAL(activated(int)), this, SLOT(insertSpace(int)));
|
2002-09-12 00:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMathDialog::showingPanel(int num)
|
|
|
|
{
|
|
|
|
if (panel_initialised[num])
|
|
|
|
return;
|
|
|
|
|
|
|
|
addPanel(num);
|
2002-09-12 01:04:39 +00:00
|
|
|
|
|
|
|
// Qt needs to catch up. Dunno why.
|
|
|
|
qApp->processEvents();
|
|
|
|
|
2002-09-12 00:56:53 +00:00
|
|
|
panel_initialised[num] = true;
|
2002-08-30 16:20:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-08 02:57:10 +00:00
|
|
|
IconPalette * QMathDialog::makePanel(QWidget * parent, char const ** entries)
|
2002-08-30 16:20:27 +00:00
|
|
|
{
|
2002-09-08 02:57:10 +00:00
|
|
|
IconPalette * p = new IconPalette(parent);
|
2002-08-30 16:20:27 +00:00
|
|
|
for (int i = 0; *entries[i]; ++i) {
|
|
|
|
string xpm_name = LibFileSearch("images/math/", entries[i], "xpm");
|
|
|
|
p->add(QPixmap(xpm_name.c_str()), entries[i], string("\\") + entries[i]);
|
|
|
|
}
|
|
|
|
connect(p, SIGNAL(button_clicked(string)), this, SLOT(symbol_clicked(string)));
|
2002-09-12 00:25:59 +00:00
|
|
|
|
2002-09-08 02:57:10 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2002-09-06 01:44:02 +00:00
|
|
|
|
2002-09-12 00:56:53 +00:00
|
|
|
void QMathDialog::addPanel(int num)
|
2002-09-08 02:57:10 +00:00
|
|
|
{
|
2002-09-12 00:56:53 +00:00
|
|
|
QScrollViewSingle * view = static_cast<QScrollViewSingle*>(symbolsWS->visibleWidget());
|
|
|
|
IconPalette * p = makePanel(view->viewport(), panels[num]);
|
2002-09-08 01:14:08 +00:00
|
|
|
view->setChild(p);
|
2002-08-30 16:20:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-14 01:44:58 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
form_->insert_symbol(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-30 16:20:27 +00:00
|
|
|
void QMathDialog::symbol_clicked(string str)
|
|
|
|
{
|
|
|
|
form_->insert_symbol(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMathDialog::fracClicked()
|
|
|
|
{
|
|
|
|
form_->insert_symbol("frac");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMathDialog::sqrtClicked()
|
|
|
|
{
|
|
|
|
form_->insert_symbol("sqrt");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMathDialog::delimiterClicked()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMathDialog::expandClicked()
|
|
|
|
{
|
2002-09-08 02:57:10 +00:00
|
|
|
int const id = symbolsWS->id(symbolsWS->visibleWidget());
|
|
|
|
IconPalette * p = makePanel(0, panels[id]);
|
2002-09-08 05:00:37 +00:00
|
|
|
string s = "LyX: ";
|
|
|
|
s += symbolsCO->text(id).latin1();
|
|
|
|
p->setCaption(s.c_str());
|
|
|
|
p->resize(40 * 5, p->height());
|
2002-09-08 02:57:10 +00:00
|
|
|
p->show();
|
2002-09-08 05:00:37 +00:00
|
|
|
p->setMaximumSize(p->width(), p->height());
|
2002-08-30 16:20:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMathDialog::functionSelected(const QString & str)
|
|
|
|
{
|
|
|
|
form_->insert_symbol(str.latin1());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMathDialog::matrixClicked()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMathDialog::spaceClicked()
|
|
|
|
{
|
2002-09-14 01:44:58 +00:00
|
|
|
space_menu_->exec(QCursor::pos());
|
2002-08-30 16:20:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMathDialog::styleClicked()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMathDialog::subscriptClicked()
|
|
|
|
{
|
2002-09-06 01:44:02 +00:00
|
|
|
form_->subscript();
|
2002-08-30 16:20:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QMathDialog::superscriptClicked()
|
|
|
|
{
|
2002-09-06 01:44:02 +00:00
|
|
|
form_->superscript();
|
2002-08-30 16:20:27 +00:00
|
|
|
}
|