support for matrix decoration in the MathMatrix dialog;

introduces a new LFUN and fixes #4620

This can in principle also go to branch when new LFUNs are there allowed, Jürgen?

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30523 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Uwe Stöhr 2009-07-12 21:39:21 +00:00
parent 1da9addbed
commit 802067ecdc
9 changed files with 270 additions and 155 deletions

View File

@ -439,6 +439,7 @@ enum FuncCode
LFUN_BRANCH_ADD_INSERT,
// 340
LFUN_BRANCHES_RENAME, // spitz 20090709
LFUN_MATH_AMS_MATRIX, // uwestoehr 12-07-2009
LFUN_LASTACTION // end of the table
};

View File

@ -1622,6 +1622,16 @@ void LyXAction::init()
* \endvar
*/
{ LFUN_MATH_MATRIX, "math-matrix", Noop, Math },
/*!
* \var lyx::FuncCode lyx::LFUN_MATH_AMS_MATRIX
* \li Action: Inserts a matrix.
* \li Syntax: math-matrix <COLS> <ROWS> [<DECORATION>]
* \li Params: <DECORATION>: Decoration determines the LaTeX name of the matrix
that should be created.
* \li Sample: math-ams-matrix 3 3 bmatrix
* \endvar
*/
{ LFUN_MATH_AMS_MATRIX, "math-ams-matrix", Noop, Math },
/*!
* \var lyx::FuncCode lyx::LFUN_MATH_MODE
* \li Action: In text mode enters math mode (i.e. puts math insets on the current

View File

@ -1751,6 +1751,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
break;
case LFUN_MATH_INSERT:
case LFUN_MATH_AMS_MATRIX:
case LFUN_MATH_MATRIX:
case LFUN_MATH_DELIM:
case LFUN_MATH_BIGDELIM: {
@ -2501,6 +2502,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
break;
case LFUN_MATH_INSERT:
case LFUN_MATH_AMS_MATRIX:
case LFUN_MATH_MATRIX:
case LFUN_MATH_DELIM:
case LFUN_MATH_BIGDELIM:

View File

@ -35,6 +35,7 @@ GuiMathMatrix::GuiMathMatrix(GuiView & lv)
rowsSB->setValue(5);
columnsSB->setValue(5);
valignCO->setCurrentIndex(1);
decorationCO->setCurrentIndex(0);
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
@ -55,6 +56,8 @@ GuiMathMatrix::GuiMathMatrix(GuiView & lv)
this, SLOT(change_adaptor()));
connect(halignED, SIGNAL(textChanged(QString)),
this, SLOT(change_adaptor()));
connect(decorationCO, SIGNAL(activated(int)),
this, SLOT(decorationChanged(int)));
bc().setPolicy(ButtonPolicy::IgnorantPolicy);
}
@ -77,6 +80,18 @@ void GuiMathMatrix::rowsChanged(int)
}
void GuiMathMatrix::decorationChanged(int deco)
{
// a matrix with a decoration cannot have a vertical alignment
if (deco != 0) {
alignmentGB->setEnabled(false);
valignCO->setCurrentIndex(1);
halignED->clear();
} else
alignmentGB->setEnabled(true);
}
void GuiMathMatrix::change_adaptor()
{
// FIXME: We need a filter for the halign input
@ -85,14 +100,36 @@ void GuiMathMatrix::change_adaptor()
void GuiMathMatrix::slotOK()
{
char v_align_c[] = "tcb";
char const c = v_align_c[valignCO->currentIndex()];
QString const sh = halignED->text();
int const nx = columnsSB->value();
int const ny = rowsSB->value();
string const str = fromqstr(
QString("%1 %2 %3 %4").arg(nx).arg(ny).arg(c).arg(sh));
dispatch(FuncRequest(LFUN_MATH_MATRIX, str));
// a matrix without a decoration is an array,
// otherwise it is an AMS matrix that cannot have a vertical alignment
if (decorationCO->currentIndex() == 0) {
char v_align_c[] = "tcb";
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));
dispatch(FuncRequest(LFUN_MATH_MATRIX, str));
} else {
int const deco = decorationCO->currentIndex();
QString deco_name;
switch (deco) {
case 1: deco_name = "bmatrix";
break;
case 2: deco_name = "pmatrix";
break;
case 3: deco_name = "Bmatrix";
break;
case 4: deco_name = "vmatrix";
break;
case 5: deco_name = "Vmatrix";
break;
}
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();
}

View File

@ -38,6 +38,7 @@ public Q_SLOTS:
void slotClose();
void columnsChanged(int);
void rowsChanged(int);
void decorationChanged(int);
void change_adaptor();
};

View File

@ -1,102 +1,96 @@
<ui version="4.0" >
<class>MathMatrixUi</class>
<widget class="QDialog" name="MathMatrixUi" >
<property name="geometry" >
<widget class="QDialog" name="MathMatrixUi">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>248</width>
<height>371</height>
<width>347</width>
<height>372</height>
</rect>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string/>
</property>
<property name="sizeGripEnabled" >
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>11</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="0" colspan="2" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="rowsL" >
<property name="toolTip" >
<widget class="QLabel" name="rowsL">
<property name="toolTip">
<string>Number of rows</string>
</property>
<property name="text" >
<property name="text">
<string>&amp;Rows:</string>
</property>
<property name="buddy" >
<property name="buddy">
<cstring>rowsSB</cstring>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="rowsSB" >
<property name="toolTip" >
<widget class="QSpinBox" name="rowsSB">
<property name="toolTip">
<string>Number of rows</string>
</property>
<property name="buttonSymbols" >
<property name="buttonSymbols">
<enum>QAbstractSpinBox::PlusMinus</enum>
</property>
<property name="maximum" >
<number>511</number>
</property>
<property name="minimum" >
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>511</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="columnsL" >
<property name="toolTip" >
<widget class="QLabel" name="columnsL">
<property name="toolTip">
<string>Number of columns</string>
</property>
<property name="text" >
<property name="text">
<string>&amp;Columns:</string>
</property>
<property name="buddy" >
<property name="buddy">
<cstring>columnsSB</cstring>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="columnsSB" >
<property name="toolTip" >
<widget class="QSpinBox" name="columnsSB">
<property name="toolTip">
<string>Number of columns</string>
</property>
<property name="buttonSymbols" >
<property name="buttonSymbols">
<enum>QAbstractSpinBox::PlusMinus</enum>
</property>
<property name="maximum" >
<number>511</number>
</property>
<property name="minimum" >
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>511</number>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
@ -106,86 +100,28 @@
</item>
</layout>
</item>
<item row="1" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" >
<widget class="EmptyTable" name="table" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>5</hsizetype>
<vsizetype>5</vsizetype>
<item row="1" column="0">
<widget class="EmptyTable" name="table" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<property name="toolTip">
<string>Resize this to the correct table dimensions</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okPB" >
<property name="text" >
<string>&amp;OK</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closePB" >
<property name="text" >
<string>Close</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0" >
<item row="1" column="1">
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
@ -193,74 +129,88 @@
</property>
</spacer>
</item>
<item row="3" column="0" colspan="2" >
<widget class="QGroupBox" name="alignmentG" >
<property name="title" >
<item row="2" column="0">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0" colspan="2">
<widget class="QGroupBox" name="alignmentGB">
<property name="title">
<string>Alignment</string>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<layout class="QGridLayout">
<property name="margin">
<number>11</number>
</property>
<property name="spacing" >
<property name="spacing">
<number>6</number>
</property>
<item row="1" column="0" >
<widget class="QComboBox" name="valignCO" >
<property name="toolTip" >
<item row="1" column="0">
<widget class="QComboBox" name="valignCO">
<property name="toolTip">
<string>Vertical alignment</string>
</property>
<item>
<property name="text" >
<property name="text">
<string>Top</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>Middle</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>Bottom</string>
</property>
</item>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="valignLA" >
<property name="text" >
<item row="0" column="0">
<widget class="QLabel" name="valignLA">
<property name="text">
<string>&amp;Vertical:</string>
</property>
<property name="alignment" >
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="buddy" >
<property name="buddy">
<cstring>valignCO</cstring>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QLineEdit" name="halignED" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>1</hsizetype>
<vsizetype>0</vsizetype>
<item row="1" column="1">
<widget class="QLineEdit" name="halignED">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<property name="toolTip">
<string>Horizontal alignment per column (l,c,r)</string>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QLabel" name="widthLA_2" >
<property name="text" >
<item row="0" column="1">
<widget class="QLabel" name="widthLA_2">
<property name="text">
<string>&amp;Horizontal:</string>
</property>
<property name="buddy" >
<property name="buddy">
<cstring>halignED</cstring>
</property>
</widget>
@ -268,19 +218,112 @@
</layout>
</widget>
</item>
<item row="3" column="2">
<widget class="QGroupBox" name="alignmentGB_2">
<property name="title">
<string>Decoration</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="typeLA">
<property name="text">
<string>&amp;Type:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>valignCO</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QComboBox" name="decorationCO">
<property name="toolTip">
<string>decoration type / matrix border</string>
</property>
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>[x]</string>
</property>
</item>
<item>
<property name="text">
<string>(x)</string>
</property>
</item>
<item>
<property name="text">
<string>{x}</string>
</property>
</item>
<item>
<property name="text">
<string>|x|</string>
</property>
</item>
<item>
<property name="text">
<string>||x||</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item row="4" column="0" colspan="2">
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okPB">
<property name="text">
<string>&amp;OK</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closePB">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<pixmapfunction></pixmapfunction>
<includes>
<include location="local" >qt_i18n.h</include>
</includes>
<customwidgets>
<customwidget>
<class>EmptyTable</class>
<extends>QWidget</extends>
<header>EmptyTable.h</header>
<container>0</container>
<pixmap></pixmap>
</customwidget>
</customwidgets>
<tabstops>
@ -291,6 +334,9 @@
<tabstop>okPB</tabstop>
<tabstop>closePB</tabstop>
</tabstops>
<includes>
<include location="local">qt_i18n.h</include>
</includes>
<resources/>
<connections/>
</ui>

View File

@ -782,6 +782,7 @@ bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_MARGINALNOTE_INSERT:
case LFUN_MATH_DISPLAY:
case LFUN_MATH_INSERT:
case LFUN_MATH_AMS_MATRIX:
case LFUN_MATH_MATRIX:
case LFUN_MATH_MODE:
case LFUN_MENU_OPEN:

View File

@ -21,9 +21,9 @@ namespace lyx {
class InsetMathAMSArray : public InsetMathGrid {
public:
///
InsetMathAMSArray(docstring const & name, int m, int n);
InsetMathAMSArray(docstring const &, int m, int n);
///
InsetMathAMSArray(docstring const & name);
InsetMathAMSArray(docstring const &);
///
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
@ -50,7 +50,6 @@ private:
char const * name_left() const;
///
char const * name_right() const;
///
docstring name_;
};

View File

@ -13,6 +13,7 @@
#include "InsetMathNest.h"
#include "InsetMathArray.h"
#include "InsetMathAMSArray.h"
#include "InsetMathBig.h"
#include "InsetMathBox.h"
#include "InsetMathBrace.h"
@ -1017,6 +1018,22 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
break;
}
case LFUN_MATH_AMS_MATRIX: {
cur.recordUndo();
unsigned int m = 1;
unsigned int n = 1;
docstring name;
idocstringstream is(cmd.argument());
is >> m >> n >> name;
if (m < 1)
m = 1;
if (n < 1)
n = 1;
cur.niceInsert(
MathAtom(new InsetMathAMSArray(name, m, n)));
break;
}
case LFUN_MATH_DELIM: {
docstring ls;
docstring rs = split(cmd.argument(), ls, ' ');
@ -1279,6 +1296,7 @@ bool InsetMathNest::getStatus(Cursor & cur, FuncRequest const & cmd,
flag.setEnabled(currentMode() != TEXT_MODE);
break;
case LFUN_MATH_AMS_MATRIX:
case LFUN_MATH_MATRIX:
flag.setEnabled(currentMode() == MATH_MODE);
break;