From 802067ecdc8496b851b82d730775829f0c5ffccb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Uwe=20St=C3=B6hr?= Date: Sun, 12 Jul 2009 21:39:21 +0000 Subject: [PATCH] support for matrix decoration in the MathMatrix dialog; introduces a new LFUN and fixes #4620 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- src/FuncCode.h | 1 + src/LyXAction.cpp | 10 + src/Text3.cpp | 2 + src/frontends/qt4/GuiMathMatrix.cpp | 49 +++- src/frontends/qt4/GuiMathMatrix.h | 1 + src/frontends/qt4/ui/MathMatrixUi.ui | 328 +++++++++++++++------------ src/insets/InsetCollapsable.cpp | 1 + src/mathed/InsetMathAMSArray.h | 5 +- src/mathed/InsetMathNest.cpp | 18 ++ 9 files changed, 265 insertions(+), 150 deletions(-) diff --git a/src/FuncCode.h b/src/FuncCode.h index 682ed20e0b..3219bcb05c 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -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 }; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 6acb25a3ff..c3eb1dbd84 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -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 [] + * \li Params: : 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 diff --git a/src/Text3.cpp b/src/Text3.cpp index 29f1d2154f..2e99f936c5 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -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: diff --git a/src/frontends/qt4/GuiMathMatrix.cpp b/src/frontends/qt4/GuiMathMatrix.cpp index e74bd938c0..f87fa35b93 100644 --- a/src/frontends/qt4/GuiMathMatrix.cpp +++ b/src/frontends/qt4/GuiMathMatrix.cpp @@ -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(); } diff --git a/src/frontends/qt4/GuiMathMatrix.h b/src/frontends/qt4/GuiMathMatrix.h index 125af16a2f..8f3c624fc8 100644 --- a/src/frontends/qt4/GuiMathMatrix.h +++ b/src/frontends/qt4/GuiMathMatrix.h @@ -38,6 +38,7 @@ public Q_SLOTS: void slotClose(); void columnsChanged(int); void rowsChanged(int); + void decorationChanged(int); void change_adaptor(); }; diff --git a/src/frontends/qt4/ui/MathMatrixUi.ui b/src/frontends/qt4/ui/MathMatrixUi.ui index 0c578a6dea..fa35f8b18d 100644 --- a/src/frontends/qt4/ui/MathMatrixUi.ui +++ b/src/frontends/qt4/ui/MathMatrixUi.ui @@ -1,102 +1,96 @@ MathMatrixUi - - + + 0 0 - 248 - 371 + 347 + 372 - + - + true - - - 11 - - - 6 - - - - - 0 - - + + + + 6 + + 0 + - - + + Number of rows - + &Rows: - + rowsSB - - + + Number of rows - + QAbstractSpinBox::PlusMinus - - 511 - - + 1 + + 511 + - - + + Number of columns - + &Columns: - + columnsSB - - + + Number of columns - + QAbstractSpinBox::PlusMinus - - 511 - - + 1 + + 511 + - + Qt::Horizontal - + QSizePolicy::Expanding - + 20 20 @@ -106,15 +100,28 @@ - + + + + + 0 + 0 + + + + Resize this to the correct table dimensions + + + + - + Qt::Horizontal - + QSizePolicy::MinimumExpanding - + 20 20 @@ -122,70 +129,15 @@ - - - - - 5 - 5 - 0 - 0 - - - - Resize this to the correct table dimensions - - - - - - - 0 - - - 6 - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 20 - 20 - - - - - - - - &OK - - - - - - - Close - - - - - - + - + Qt::Vertical - + QSizePolicy::MinimumExpanding - + 20 20 @@ -193,74 +145,72 @@ - - - + + + Alignment - - + + 11 - + 6 - - - + + + Vertical alignment - + Top - + Middle - + Bottom - - - + + + &Vertical: - + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - + valignCO - - - - - 1 - 0 + + + + 0 0 - + Horizontal alignment per column (l,c,r) - - - + + + &Horizontal: - + halignED @@ -268,19 +218,112 @@ + + + + Decoration + + + + + + &Type: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + valignCO + + + + + + + decoration type / matrix border + + + + None + + + + + [x] + + + + + (x) + + + + + {x} + + + + + |x| + + + + + ||x|| + + + + + + + + + + + 6 + + + 0 + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 20 + 20 + + + + + + + + &OK + + + + + + + Close + + + + + - - - qt_i18n.h - EmptyTable QWidget
EmptyTable.h
- 0 -
@@ -291,6 +334,9 @@ okPB closePB + + qt_i18n.h +
diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index 2abe8a7f75..aca3757816 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -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: diff --git a/src/mathed/InsetMathAMSArray.h b/src/mathed/InsetMathAMSArray.h index 44c4b91c75..76c02f2452 100644 --- a/src/mathed/InsetMathAMSArray.h +++ b/src/mathed/InsetMathAMSArray.h @@ -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_; }; diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index e6c8f2eafc..99bfc5f46a 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -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; -- 2.39.2