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(change_adaptor()));
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 int const nx = int(columnsSB->value());
70 halignED->setText(QString(nx, 'c'));
74 void GuiMathMatrix::decorationChanged(int deco)
76 // a matrix with a decoration cannot have a vertical alignment
78 valignCO->setEnabled(false);
79 valignCO->setCurrentIndex(1);
81 valignCO->setEnabled(true);
85 void GuiMathMatrix::change_adaptor()
87 // FIXME: We need a filter for the halign input
91 void GuiMathMatrix::slotOK()
93 int const nx = columnsSB->value();
94 int const ny = rowsSB->value();
95 // a matrix without a decoration is an array,
96 // otherwise it is an AMS matrix
97 // decorated matrices cannot have a vertical alignment
99 char v_align_c[] = "tcb";
100 char const c = v_align_c[valignCO->currentIndex()];
101 QString const sh = halignED->text();
102 string const str = fromqstr(
103 QString("%1 %2 %3 %4").arg(nx).arg(ny).arg(c).arg(sh));
105 if (decorationCO->currentIndex() != 0) {
106 int const deco = decorationCO->currentIndex();
109 case 1: deco_name = "bmatrix";
111 case 2: deco_name = "pmatrix";
113 case 3: deco_name = "Bmatrix";
115 case 4: deco_name = "vmatrix";
117 case 5: deco_name = "Vmatrix";
120 // only if a special alignment is set create a 1x1 AMS array in which
121 // a normal array will be created, otherwise create just a normal AMS array
122 if (sh.contains('l') > 0 || sh.contains('r') > 0) {
123 string const str_ams = fromqstr(
124 QString("%1 %2 %3").arg(int(1)).arg(int(1)).arg(deco_name));
125 dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
127 string const str_ams = fromqstr(
128 QString("%1 %2 %3").arg(nx).arg(ny).arg(deco_name));
129 dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
134 // create the normal array
135 dispatch(FuncRequest(LFUN_MATH_MATRIX, str));
140 void GuiMathMatrix::slotClose()
146 Dialog * createGuiMathMatrix(GuiView & lv) { return new GuiMathMatrix(lv); }
149 } // namespace frontend
152 #include "moc_GuiMathMatrix.cpp"