2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 22:37:05 +00:00
|
|
|
* \file GuiMathMatrix.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Jürgen Spitzmüller
|
2009-07-13 23:25:47 +00:00
|
|
|
* \author Uwe Stöhr
|
2006-03-05 17:24:44 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-08-31 22:37:05 +00:00
|
|
|
#include "GuiMathMatrix.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-04-26 03:53:02 +00:00
|
|
|
#include "EmptyTable.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
2008-06-02 10:05:29 +00:00
|
|
|
#include "FuncRequest.h"
|
|
|
|
|
2013-05-14 00:19:43 +00:00
|
|
|
#include "support/gettext.h"
|
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QSpinBox>
|
2007-04-19 21:42:42 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2013-05-14 00:19:43 +00:00
|
|
|
static char const * const DecoChars[] = {
|
|
|
|
N_("None"),
|
|
|
|
N_("[x]"),
|
|
|
|
N_("(x)"),
|
|
|
|
N_("{x}"),
|
|
|
|
N_("|x|"),
|
|
|
|
N_("||x||"),
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
|
|
|
static char const * const DecoNames[] = {
|
|
|
|
N_("bmatrix"),
|
|
|
|
N_("pmatrix"),
|
|
|
|
N_("Bmatrix"),
|
|
|
|
N_("vmatrix"),
|
|
|
|
N_("Vmatrix"),
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
|
|
|
static char const * const VertAligns[] = {
|
|
|
|
N_("Top"),
|
|
|
|
N_("Middle"),
|
|
|
|
N_("Bottom"),
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
|
|
|
static char const v_align_c[] = "tcb";
|
|
|
|
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
GuiMathMatrix::GuiMathMatrix(GuiView & lv)
|
2008-06-02 10:05:29 +00:00
|
|
|
: GuiDialog(lv, "mathmatrix", qt_("Math Matrix"))
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
2014-06-06 14:14:24 +00:00
|
|
|
for (int i = 0; *VertAligns[i]; ++i)
|
|
|
|
valignCO->addItem(qt_(VertAligns[i]));
|
|
|
|
for (int i = 0; *DecoChars[i]; ++i)
|
|
|
|
decorationCO->addItem(qt_(DecoChars[i]));
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
table->setMinimumSize(100, 100);
|
2007-05-07 18:30:41 +00:00
|
|
|
rowsSB->setValue(5);
|
|
|
|
columnsSB->setValue(5);
|
2006-08-17 08:57:44 +00:00
|
|
|
valignCO->setCurrentIndex(1);
|
2009-07-12 21:39:21 +00:00
|
|
|
decorationCO->setCurrentIndex(0);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-08-12 12:44:42 +00:00
|
|
|
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
|
|
|
|
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
|
|
|
|
|
|
|
|
connect(table, SIGNAL(rowsChanged(int)),
|
|
|
|
rowsSB, SLOT(setValue(int)));
|
|
|
|
connect(table, SIGNAL(colsChanged(int)),
|
|
|
|
columnsSB, SLOT(setValue(int)));
|
|
|
|
connect(rowsSB, SIGNAL(valueChanged(int)),
|
|
|
|
table, SLOT(setNumberRows(int)));
|
|
|
|
connect(columnsSB, SIGNAL(valueChanged(int)),
|
|
|
|
table, SLOT(setNumberColumns(int)));
|
|
|
|
connect(rowsSB, SIGNAL(valueChanged(int)),
|
2010-09-24 03:44:34 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
2007-08-12 12:44:42 +00:00
|
|
|
connect(columnsSB, SIGNAL(valueChanged(int)),
|
|
|
|
this, SLOT(columnsChanged(int)) );
|
2008-04-20 21:05:35 +00:00
|
|
|
connect(valignCO, SIGNAL(highlighted(QString)),
|
2007-08-12 12:44:42 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
2008-04-20 21:05:35 +00:00
|
|
|
connect(halignED, SIGNAL(textChanged(QString)),
|
2007-08-12 12:44:42 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
2009-07-12 21:39:21 +00:00
|
|
|
connect(decorationCO, SIGNAL(activated(int)),
|
|
|
|
this, SLOT(decorationChanged(int)));
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
bc().setPolicy(ButtonPolicy::IgnorantPolicy);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 20:34:09 +00:00
|
|
|
void GuiMathMatrix::columnsChanged(int)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
int const nx = int(columnsSB->value());
|
2010-03-06 14:57:16 +00:00
|
|
|
halignED->setText(QString(nx, 'c'));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-12 21:39:21 +00:00
|
|
|
void GuiMathMatrix::decorationChanged(int deco)
|
|
|
|
{
|
|
|
|
// a matrix with a decoration cannot have a vertical alignment
|
|
|
|
if (deco != 0) {
|
2010-09-24 03:44:34 +00:00
|
|
|
valignCO->setEnabled(false);
|
2009-07-12 21:39:21 +00:00
|
|
|
valignCO->setCurrentIndex(1);
|
|
|
|
} else
|
2010-09-24 03:44:34 +00:00
|
|
|
valignCO->setEnabled(true);
|
2009-07-12 21:39:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 20:34:09 +00:00
|
|
|
void GuiMathMatrix::change_adaptor()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
// FIXME: We need a filter for the halign input
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 20:34:09 +00:00
|
|
|
void GuiMathMatrix::slotOK()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2008-04-20 21:05:35 +00:00
|
|
|
int const nx = columnsSB->value();
|
|
|
|
int const ny = rowsSB->value();
|
2009-07-12 21:39:21 +00:00
|
|
|
// a matrix without a decoration is an array,
|
2010-09-24 03:44:34 +00:00
|
|
|
// otherwise it is an AMS matrix
|
|
|
|
// decorated matrices cannot have a vertical alignment
|
|
|
|
|
|
|
|
char const c = v_align_c[valignCO->currentIndex()];
|
|
|
|
QString const sh = halignED->text();
|
|
|
|
string const str = fromqstr(
|
|
|
|
QString("%1 %2 %3 %4").arg(nx).arg(ny).arg(c).arg(sh));
|
|
|
|
|
|
|
|
if (decorationCO->currentIndex() != 0) {
|
2009-07-12 21:39:21 +00:00
|
|
|
int const deco = decorationCO->currentIndex();
|
2013-05-14 00:19:43 +00:00
|
|
|
QString deco_name = DecoNames[deco - 1];
|
2010-09-24 03:44:34 +00:00
|
|
|
// only if a special alignment is set create a 1x1 AMS array in which
|
|
|
|
// a normal array will be created, otherwise create just a normal AMS array
|
2013-05-10 11:13:20 +00:00
|
|
|
if (sh.contains('l') || sh.contains('r')) {
|
2010-09-24 03:44:34 +00:00
|
|
|
string const str_ams = fromqstr(
|
|
|
|
QString("%1 %2 %3").arg(int(1)).arg(int(1)).arg(deco_name));
|
|
|
|
dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
|
|
|
|
} else {
|
|
|
|
string const str_ams = fromqstr(
|
|
|
|
QString("%1 %2 %3").arg(nx).arg(ny).arg(deco_name));
|
|
|
|
dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
|
|
|
|
close();
|
|
|
|
return;
|
|
|
|
}
|
2009-07-12 21:39:21 +00:00
|
|
|
}
|
2010-09-24 03:44:34 +00:00
|
|
|
// create the normal array
|
|
|
|
dispatch(FuncRequest(LFUN_MATH_MATRIX, str));
|
2006-03-05 17:24:44 +00:00
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 20:34:09 +00:00
|
|
|
void GuiMathMatrix::slotClose()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
2007-10-07 20:34:09 +00:00
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiMathMatrix(GuiView & lv) { return new GuiMathMatrix(lv); }
|
2007-10-07 20:34:09 +00:00
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2006-05-18 08:51:12 +00:00
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiMathMatrix.cpp"
|