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, LFUN_BRANCH_ADD_INSERT,
// 340 // 340
LFUN_BRANCHES_RENAME, // spitz 20090709 LFUN_BRANCHES_RENAME, // spitz 20090709
LFUN_MATH_AMS_MATRIX, // uwestoehr 12-07-2009
LFUN_LASTACTION // end of the table LFUN_LASTACTION // end of the table
}; };

View File

@ -1622,6 +1622,16 @@ void LyXAction::init()
* \endvar * \endvar
*/ */
{ LFUN_MATH_MATRIX, "math-matrix", Noop, Math }, { 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 * \var lyx::FuncCode lyx::LFUN_MATH_MODE
* \li Action: In text mode enters math mode (i.e. puts math insets on the current * \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; break;
case LFUN_MATH_INSERT: case LFUN_MATH_INSERT:
case LFUN_MATH_AMS_MATRIX:
case LFUN_MATH_MATRIX: case LFUN_MATH_MATRIX:
case LFUN_MATH_DELIM: case LFUN_MATH_DELIM:
case LFUN_MATH_BIGDELIM: { case LFUN_MATH_BIGDELIM: {
@ -2501,6 +2502,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
break; break;
case LFUN_MATH_INSERT: case LFUN_MATH_INSERT:
case LFUN_MATH_AMS_MATRIX:
case LFUN_MATH_MATRIX: case LFUN_MATH_MATRIX:
case LFUN_MATH_DELIM: case LFUN_MATH_DELIM:
case LFUN_MATH_BIGDELIM: case LFUN_MATH_BIGDELIM:

View File

@ -35,6 +35,7 @@ GuiMathMatrix::GuiMathMatrix(GuiView & lv)
rowsSB->setValue(5); rowsSB->setValue(5);
columnsSB->setValue(5); columnsSB->setValue(5);
valignCO->setCurrentIndex(1); valignCO->setCurrentIndex(1);
decorationCO->setCurrentIndex(0);
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
@ -55,6 +56,8 @@ GuiMathMatrix::GuiMathMatrix(GuiView & lv)
this, SLOT(change_adaptor())); this, SLOT(change_adaptor()));
connect(halignED, SIGNAL(textChanged(QString)), connect(halignED, SIGNAL(textChanged(QString)),
this, SLOT(change_adaptor())); this, SLOT(change_adaptor()));
connect(decorationCO, SIGNAL(activated(int)),
this, SLOT(decorationChanged(int)));
bc().setPolicy(ButtonPolicy::IgnorantPolicy); 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() void GuiMathMatrix::change_adaptor()
{ {
// FIXME: We need a filter for the halign input // FIXME: We need a filter for the halign input
@ -85,14 +100,36 @@ void GuiMathMatrix::change_adaptor()
void GuiMathMatrix::slotOK() void GuiMathMatrix::slotOK()
{ {
int const nx = columnsSB->value();
int const ny = rowsSB->value();
// 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 v_align_c[] = "tcb";
char const c = v_align_c[valignCO->currentIndex()]; char const c = v_align_c[valignCO->currentIndex()];
QString const sh = halignED->text(); QString const sh = halignED->text();
int const nx = columnsSB->value();
int const ny = rowsSB->value();
string const str = fromqstr( string const str = fromqstr(
QString("%1 %2 %3 %4").arg(nx).arg(ny).arg(c).arg(sh)); QString("%1 %2 %3 %4").arg(nx).arg(ny).arg(c).arg(sh));
dispatch(FuncRequest(LFUN_MATH_MATRIX, str)); 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(); close();
} }

View File

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

View File

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

View File

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

View File

@ -21,9 +21,9 @@ namespace lyx {
class InsetMathAMSArray : public InsetMathGrid { class InsetMathAMSArray : public InsetMathGrid {
public: 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; void metrics(MetricsInfo & mi, Dimension & dim) const;
/// ///
@ -50,7 +50,6 @@ private:
char const * name_left() const; char const * name_left() const;
/// ///
char const * name_right() const; char const * name_right() const;
/// ///
docstring name_; docstring name_;
}; };

View File

@ -13,6 +13,7 @@
#include "InsetMathNest.h" #include "InsetMathNest.h"
#include "InsetMathArray.h" #include "InsetMathArray.h"
#include "InsetMathAMSArray.h"
#include "InsetMathBig.h" #include "InsetMathBig.h"
#include "InsetMathBox.h" #include "InsetMathBox.h"
#include "InsetMathBrace.h" #include "InsetMathBrace.h"
@ -1017,6 +1018,22 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
break; 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: { case LFUN_MATH_DELIM: {
docstring ls; docstring ls;
docstring rs = split(cmd.argument(), ls, ' '); docstring rs = split(cmd.argument(), ls, ' ');
@ -1279,6 +1296,7 @@ bool InsetMathNest::getStatus(Cursor & cur, FuncRequest const & cmd,
flag.setEnabled(currentMode() != TEXT_MODE); flag.setEnabled(currentMode() != TEXT_MODE);
break; break;
case LFUN_MATH_AMS_MATRIX:
case LFUN_MATH_MATRIX: case LFUN_MATH_MATRIX:
flag.setEnabled(currentMode() == MATH_MODE); flag.setEnabled(currentMode() == MATH_MODE);
break; break;