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
9 * Full author contact details are available in file CREDITS.
14 #include "GuiMathMatrix.h"
16 #include "EmptyTable.h"
17 #include "qt_helpers.h"
19 #include "FuncRequest.h"
22 #include <QPushButton>
30 GuiMathMatrix::GuiMathMatrix(GuiView & lv)
31 : GuiDialog(lv, "mathmatrix", qt_("Math Matrix"))
35 table->setMinimumSize(100, 100);
37 columnsSB->setValue(5);
38 valignCO->setCurrentIndex(1);
39 decorationCO->setCurrentIndex(0);
41 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
42 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
44 connect(table, SIGNAL(rowsChanged(int)),
45 rowsSB, SLOT(setValue(int)));
46 connect(table, SIGNAL(colsChanged(int)),
47 columnsSB, SLOT(setValue(int)));
48 connect(rowsSB, SIGNAL(valueChanged(int)),
49 table, SLOT(setNumberRows(int)));
50 connect(columnsSB, SIGNAL(valueChanged(int)),
51 table, SLOT(setNumberColumns(int)));
52 connect(rowsSB, SIGNAL(valueChanged(int)),
53 this, SLOT(rowsChanged(int)));
54 connect(columnsSB, SIGNAL(valueChanged(int)),
55 this, SLOT(columnsChanged(int)) );
56 connect(valignCO, SIGNAL(highlighted(QString)),
57 this, SLOT(change_adaptor()));
58 connect(halignED, SIGNAL(textChanged(QString)),
59 this, SLOT(change_adaptor()));
60 connect(decorationCO, SIGNAL(activated(int)),
61 this, SLOT(decorationChanged(int)));
63 bc().setPolicy(ButtonPolicy::IgnorantPolicy);
67 void GuiMathMatrix::columnsChanged(int)
69 char h_align_str[80] = "c";
70 int const nx = int(columnsSB->value());
71 for (int i = 0; i < nx; ++i)
74 h_align_str[nx] = '\0';
75 halignED->setText(h_align_str);
79 void GuiMathMatrix::rowsChanged(int)
84 void GuiMathMatrix::decorationChanged(int deco)
86 // a matrix with a decoration cannot have a vertical alignment
88 alignmentGB->setEnabled(false);
89 valignCO->setCurrentIndex(1);
92 alignmentGB->setEnabled(true);
96 void GuiMathMatrix::change_adaptor()
98 // FIXME: We need a filter for the halign input
102 void GuiMathMatrix::slotOK()
104 int const nx = columnsSB->value();
105 int const ny = rowsSB->value();
106 // a matrix without a decoration is an array,
107 // otherwise it is an AMS matrix that cannot have a vertical alignment
108 if (decorationCO->currentIndex() == 0) {
109 char v_align_c[] = "tcb";
110 char const c = v_align_c[valignCO->currentIndex()];
111 QString const sh = halignED->text();
112 string const str = fromqstr(
113 QString("%1 %2 %3 %4").arg(nx).arg(ny).arg(c).arg(sh));
114 dispatch(FuncRequest(LFUN_MATH_MATRIX, str));
116 int const deco = decorationCO->currentIndex();
119 case 1: deco_name = "bmatrix";
121 case 2: deco_name = "pmatrix";
123 case 3: deco_name = "Bmatrix";
125 case 4: deco_name = "vmatrix";
127 case 5: deco_name = "Vmatrix";
130 string const str_ams = fromqstr(
131 QString("%1 %2 %3").arg(nx).arg(ny).arg(deco_name));
132 dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
138 void GuiMathMatrix::slotClose()
144 Dialog * createGuiMathMatrix(GuiView & lv) { return new GuiMathMatrix(lv); }
147 } // namespace frontend
150 #include "moc_GuiMathMatrix.cpp"