]> git.lyx.org Git - features.git/commitdiff
support for matrix decoration in the MathMatrix dialog;
authorUwe Stöhr <uwestoehr@web.de>
Sun, 12 Jul 2009 21:39:21 +0000 (21:39 +0000)
committerUwe Stöhr <uwestoehr@web.de>
Sun, 12 Jul 2009 21:39:21 +0000 (21:39 +0000)
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

src/FuncCode.h
src/LyXAction.cpp
src/Text3.cpp
src/frontends/qt4/GuiMathMatrix.cpp
src/frontends/qt4/GuiMathMatrix.h
src/frontends/qt4/ui/MathMatrixUi.ui
src/insets/InsetCollapsable.cpp
src/mathed/InsetMathAMSArray.h
src/mathed/InsetMathNest.cpp

index 682ed20e0b1482486583472c73af2b89d05313ff..3219bcb05c3b2fbec3437fc064e60ca5159838c0 100644 (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
 };
index 6acb25a3ff38b6c8fc696e8aba8b7da7d6e1c67e..c3eb1dbd84e25972cdb69e4c2a8ad39113a5917f 100644 (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
index 29f1d2154f79d64cbd0e66cf156ddce4e29dce37..2e99f936c566630da02dfd708e462f526af0e26e 100644 (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:
index e74bd938c0d634c15a4ccae39c1f44b0efb6b2f7..f87fa35b930c2f6358835ddc19e3118c8910cd0f 100644 (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();
 }
 
index 125af16a2f77bc96cc01dc032aef5ca30b43f3fd..8f3c624fc84db5a5f3e9c10835102754f7a37144 100644 (file)
@@ -38,6 +38,7 @@ public Q_SLOTS:
        void slotClose();
        void columnsChanged(int);
        void rowsChanged(int);
+       void decorationChanged(int);
        void change_adaptor();
 };
 
index 0c578a6dea1ee7322c80d99d1096dd15e735e74a..fa35f8b18d1525eef2f82eea2b947f0d84dccd95 100644 (file)
 <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>
      </item>
     </layout>
    </item>
-   <item row="1" column="1" >
+   <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">
+      <string>Resize this to the correct table dimensions</string>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="1">
     <spacer>
-     <property name="orientation" >
+     <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>
      </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>
-       <verstretch>0</verstretch>
-      </sizepolicy>
-     </property>
-     <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="2" column="0">
     <spacer>
-     <property name="orientation" >
+     <property name="orientation">
       <enum>Qt::Vertical</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>
      </property>
     </spacer>
    </item>
-   <item row="3" column="0" colspan="2" >
-    <widget class="QGroupBox" name="alignmentG>
-     <property name="title" >
+   <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>
      </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>
   <tabstop>okPB</tabstop>
   <tabstop>closePB</tabstop>
  </tabstops>
+ <includes>
+  <include location="local">qt_i18n.h</include>
+ </includes>
  <resources/>
  <connections/>
 </ui>
index 2abe8a7f752df2c516d76969208d264bdd681938..aca37578168cece9de0004095370575322699b48 100644 (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:
index 44c4b91c75d60ca5e6c5d112935f9a9e19ca5ce5..76c02f245297da64349562a9f4949f38080c9d73 100644 (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_;
 };
index e6c8f2eafc7a03d8496c7c48be3c188e0a10b406..99bfc5f46aa6e47326e936689722f00682c6d88f 100644 (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;