2 * \file GuiMathMatrix.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Jürgen Spitzmüller
8 * Full author contact details are available in file CREDITS.
13 #include "GuiMathMatrix.h"
15 #include "EmptyTable.h"
16 #include "qt_helpers.h"
18 #include "FuncRequest.h"
21 #include <QPushButton>
29 GuiMathMatrix::GuiMathMatrix(GuiView & lv)
30 : GuiDialog(lv, "mathmatrix", qt_("Math Matrix"))
34 table->setMinimumSize(100, 100);
36 columnsSB->setValue(5);
37 valignCO->setCurrentIndex(1);
38 decorationCO->setCurrentIndex(0);
40 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
41 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
43 connect(table, SIGNAL(rowsChanged(int)),
44 rowsSB, SLOT(setValue(int)));
45 connect(table, SIGNAL(colsChanged(int)),
46 columnsSB, SLOT(setValue(int)));
47 connect(rowsSB, SIGNAL(valueChanged(int)),
48 table, SLOT(setNumberRows(int)));
49 connect(columnsSB, SIGNAL(valueChanged(int)),
50 table, SLOT(setNumberColumns(int)));
51 connect(rowsSB, SIGNAL(valueChanged(int)),
52 this, SLOT(rowsChanged(int)));
53 connect(columnsSB, SIGNAL(valueChanged(int)),
54 this, SLOT(columnsChanged(int)) );
55 connect(valignCO, SIGNAL(highlighted(QString)),
56 this, SLOT(change_adaptor()));
57 connect(halignED, SIGNAL(textChanged(QString)),
58 this, SLOT(change_adaptor()));
59 connect(decorationCO, SIGNAL(activated(int)),
60 this, SLOT(decorationChanged(int)));
62 bc().setPolicy(ButtonPolicy::IgnorantPolicy);
66 void GuiMathMatrix::columnsChanged(int)
68 char h_align_str[80] = "c";
69 int const nx = int(columnsSB->value());
70 for (int i = 0; i < nx; ++i)
73 h_align_str[nx] = '\0';
74 halignED->setText(h_align_str);
78 void GuiMathMatrix::rowsChanged(int)
83 void GuiMathMatrix::decorationChanged(int deco)
85 // a matrix with a decoration cannot have a vertical alignment
87 alignmentGB->setEnabled(false);
88 valignCO->setCurrentIndex(1);
91 alignmentGB->setEnabled(true);
95 void GuiMathMatrix::change_adaptor()
97 // FIXME: We need a filter for the halign input
101 void GuiMathMatrix::slotOK()
103 int const nx = columnsSB->value();
104 int const ny = rowsSB->value();
105 // a matrix without a decoration is an array,
106 // otherwise it is an AMS matrix that cannot have a vertical alignment
107 if (decorationCO->currentIndex() == 0) {
108 char v_align_c[] = "tcb";
109 char const c = v_align_c[valignCO->currentIndex()];
110 QString const sh = halignED->text();
111 string const str = fromqstr(
112 QString("%1 %2 %3 %4").arg(nx).arg(ny).arg(c).arg(sh));
113 dispatch(FuncRequest(LFUN_MATH_MATRIX, str));
115 int const deco = decorationCO->currentIndex();
118 case 1: deco_name = "bmatrix";
120 case 2: deco_name = "pmatrix";
122 case 3: deco_name = "Bmatrix";
124 case 4: deco_name = "vmatrix";
126 case 5: deco_name = "Vmatrix";
129 string const str_ams = fromqstr(
130 QString("%1 %2 %3").arg(nx).arg(ny).arg(deco_name));
131 dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
137 void GuiMathMatrix::slotClose()
143 Dialog * createGuiMathMatrix(GuiView & lv) { return new GuiMathMatrix(lv); }
146 } // namespace frontend
149 #include "moc_GuiMathMatrix.cpp"