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();
108 // FIXME This is very dangerous way of coding.
109 // The order is defined in .ui file and anybody who will touch it
110 // will destroy the whole math decorations machinery.
111 // For better way look on MathDelimiter Size-combo solution and biggui[] array.
112 // Similarly for the v_align_c stuff -- at least we should push it into
113 // constructor and have it in one file...
115 case 1: deco_name = "bmatrix";
117 case 2: deco_name = "pmatrix";
119 case 3: deco_name = "Bmatrix";
121 case 4: deco_name = "vmatrix";
123 case 5: deco_name = "Vmatrix";
126 // only if a special alignment is set create a 1x1 AMS array in which
127 // a normal array will be created, otherwise create just a normal AMS array
128 if (sh.contains('l') > 0 || sh.contains('r') > 0) {
129 string const str_ams = fromqstr(
130 QString("%1 %2 %3").arg(int(1)).arg(int(1)).arg(deco_name));
131 dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
133 string const str_ams = fromqstr(
134 QString("%1 %2 %3").arg(nx).arg(ny).arg(deco_name));
135 dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
140 // create the normal array
141 dispatch(FuncRequest(LFUN_MATH_MATRIX, str));
146 void GuiMathMatrix::slotClose()
152 Dialog * createGuiMathMatrix(GuiView & lv) { return new GuiMathMatrix(lv); }
155 } // namespace frontend
158 #include "moc_GuiMathMatrix.cpp"