]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiMathMatrix.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / GuiMathMatrix.cpp
index 25555f7b01d76a2a740598d4467b264dc0181ab9..3a9768b0943bd4491baa21a3b27b9fa63971deb8 100644 (file)
@@ -18,6 +18,8 @@
 
 #include "FuncRequest.h"
 
+#include "support/gettext.h"
+
 #include <QLineEdit>
 #include <QPushButton>
 #include <QSpinBox>
@@ -27,20 +29,51 @@ using namespace std;
 namespace lyx {
 namespace frontend {
 
+static char const * const DecoChars[] = {
+       N_("None"),
+       N_("[x]"),
+       N_("(x)"),
+       N_("{x}"),
+       N_("|x|"),
+       N_("||x||"),
+       ""
+};
+
+static char const * const DecoNames[] = {
+       N_("bmatrix"),
+       N_("pmatrix"),
+       N_("Bmatrix"),
+       N_("vmatrix"),
+       N_("Vmatrix"),
+       ""
+};
+
+static char const * const VertAligns[] = {
+       N_("Top"),
+       N_("Middle"),
+       N_("Bottom"),
+       ""
+};
+
+static char const v_align_c[] = "tcb";
+
+
 GuiMathMatrix::GuiMathMatrix(GuiView & lv)
        : GuiDialog(lv, "mathmatrix", qt_("Math Matrix"))
 {
        setupUi(this);
 
+       for (int i = 0; *VertAligns[i]; ++i)
+               valignCO->addItem(qt_(VertAligns[i]));
+       for (int i = 0; *DecoChars[i]; ++i)
+               decorationCO->addItem(qt_(DecoChars[i]));
+
        table->setMinimumSize(100, 100);
        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()));
-
        connect(table, SIGNAL(rowsChanged(int)),
                rowsSB, SLOT(setValue(int)));
        connect(table, SIGNAL(colsChanged(int)),
@@ -50,7 +83,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)),
@@ -66,18 +99,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'));
 }
 
 
@@ -85,11 +108,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);
 }
 
 
@@ -99,38 +121,53 @@ void GuiMathMatrix::change_adaptor()
 }
 
 
+void GuiMathMatrix::on_buttonBox_clicked(QAbstractButton * button)
+{
+       switch (buttonBox->standardButton(button)) {
+       case QDialogButtonBox::Ok:
+               slotOK();
+               break;
+       case QDialogButtonBox::Cancel:
+               slotClose();
+               break;
+       default:
+               break;
+       }
+}
+
+
 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 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;
-               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;
+               QString deco_name = DecoNames[deco - 1];
+               // 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') || sh.contains('r')) {
+                       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;
                }
-               string const str_ams = fromqstr(
-                       QString("%1 %2 %3").arg(nx).arg(ny).arg(deco_name));
-               dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
        }
+       // create the normal array
+               dispatch(FuncRequest(LFUN_MATH_MATRIX, str));
        close();
 }