]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiMathMatrix.cpp
Fix the tab ordering of GuiDocument components.
[lyx.git] / src / frontends / qt4 / GuiMathMatrix.cpp
index f87fa35b930c2f6358835ddc19e3118c8910cd0f..932ef71d8eea0d9286449d834f820d76f86a8900 100644 (file)
@@ -4,6 +4,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Jürgen Spitzmüller
+ * \author Uwe Stöhr
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -49,7 +50,7 @@ GuiMathMatrix::GuiMathMatrix(GuiView & lv)
        connect(columnsSB, SIGNAL(valueChanged(int)),
                table, SLOT(setNumberColumns(int)));
        connect(rowsSB, SIGNAL(valueChanged(int)),
-               this, SLOT(rowsChanged(int)));
+               this, SLOT(change_adaptor()));
        connect(columnsSB, SIGNAL(valueChanged(int)),
                this, SLOT(columnsChanged(int)) );
        connect(valignCO, SIGNAL(highlighted(QString)),
@@ -65,18 +66,8 @@ GuiMathMatrix::GuiMathMatrix(GuiView & lv)
 
 void GuiMathMatrix::columnsChanged(int)
 {
-       char h_align_str[80] = "c";
        int const nx = int(columnsSB->value());
-       for (int i = 0; i < nx; ++i)
-               h_align_str[i] = 'c';
-
-       h_align_str[nx] = '\0';
-       halignED->setText(h_align_str);
-}
-
-
-void GuiMathMatrix::rowsChanged(int)
-{
+       halignED->setText(QString(nx, 'c'));
 }
 
 
@@ -84,11 +75,10 @@ void GuiMathMatrix::decorationChanged(int deco)
 {
        // a matrix with a decoration cannot have a vertical alignment
        if (deco != 0) {
-               alignmentGB->setEnabled(false);
+               valignCO->setEnabled(false);
                valignCO->setCurrentIndex(1);
-               halignED->clear();
        } else
-               alignmentGB->setEnabled(true);
+               valignCO->setEnabled(true);
 }
 
 
@@ -103,17 +93,24 @@ 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 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 {
+       // otherwise it is an AMS matrix
+       // decorated matrices cannot have a vertical alignment
+       
+       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));
+
+       if (decorationCO->currentIndex() != 0) {
                int const deco = decorationCO->currentIndex();
                QString deco_name;
+               // FIXME This is very dangerous way of coding.
+               // The order is defined in .ui file and anybody who will touch it
+               // will destroy the whole math decorations machinery.
+               // For better way look on MathDelimiter Size-combo solution and biggui[] array.
+               // Similarly for the v_align_c stuff -- at least we should push it into
+               // constructor and have it in one file...
                switch (deco) {
                        case 1: deco_name = "bmatrix";
                                break;
@@ -126,10 +123,22 @@ void GuiMathMatrix::slotOK()
                        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));
+               // 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
+               if (sh.contains('l') > 0 || sh.contains('r') > 0) {
+                       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;
+               }
        }
+       // create the normal array
+               dispatch(FuncRequest(LFUN_MATH_MATRIX, str));
        close();
 }