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"
21 #include "support/gettext.h"
22 #include "support/docstring.h"
25 #include <QPushButton>
33 static char const * const DecoChars[] = {
43 static char const * const DecoNames[] = {
52 static char const * const VertAligns[] = {
59 static char const v_align_c[] = "tcb";
62 GuiMathMatrix::GuiMathMatrix(GuiView & lv)
63 : GuiDialog(lv, "mathmatrix", qt_("Math Matrix"))
67 table->setMinimumSize(100, 100);
69 columnsSB->setValue(5);
70 valignCO->setCurrentIndex(1);
71 decorationCO->setCurrentIndex(0);
73 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
74 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
76 connect(table, SIGNAL(rowsChanged(int)),
77 rowsSB, SLOT(setValue(int)));
78 connect(table, SIGNAL(colsChanged(int)),
79 columnsSB, SLOT(setValue(int)));
80 connect(rowsSB, SIGNAL(valueChanged(int)),
81 table, SLOT(setNumberRows(int)));
82 connect(columnsSB, SIGNAL(valueChanged(int)),
83 table, SLOT(setNumberColumns(int)));
84 connect(rowsSB, SIGNAL(valueChanged(int)),
85 this, SLOT(change_adaptor()));
86 connect(columnsSB, SIGNAL(valueChanged(int)),
87 this, SLOT(columnsChanged(int)) );
88 connect(valignCO, SIGNAL(highlighted(QString)),
89 this, SLOT(change_adaptor()));
90 connect(halignED, SIGNAL(textChanged(QString)),
91 this, SLOT(change_adaptor()));
92 connect(decorationCO, SIGNAL(activated(int)),
93 this, SLOT(decorationChanged(int)));
95 for (int i = 0; *VertAligns[i]; ++i)
96 valignCO->addItem(qt_(VertAligns[i]));
97 for (int i = 0; *DecoChars[i]; ++i)
98 decorationCO->addItem(qt_(DecoChars[i]));
100 bc().setPolicy(ButtonPolicy::IgnorantPolicy);
104 void GuiMathMatrix::columnsChanged(int)
106 int const nx = int(columnsSB->value());
107 halignED->setText(QString(nx, 'c'));
111 void GuiMathMatrix::decorationChanged(int deco)
113 // a matrix with a decoration cannot have a vertical alignment
115 valignCO->setEnabled(false);
116 valignCO->setCurrentIndex(1);
118 valignCO->setEnabled(true);
122 void GuiMathMatrix::change_adaptor()
124 // FIXME: We need a filter for the halign input
128 void GuiMathMatrix::slotOK()
130 int const nx = columnsSB->value();
131 int const ny = rowsSB->value();
132 // a matrix without a decoration is an array,
133 // otherwise it is an AMS matrix
134 // decorated matrices cannot have a vertical alignment
136 char const c = v_align_c[valignCO->currentIndex()];
137 QString const sh = halignED->text();
138 string const str = fromqstr(
139 QString("%1 %2 %3 %4").arg(nx).arg(ny).arg(c).arg(sh));
141 if (decorationCO->currentIndex() != 0) {
142 int const deco = decorationCO->currentIndex();
143 QString deco_name = DecoNames[deco - 1];
144 // only if a special alignment is set create a 1x1 AMS array in which
145 // a normal array will be created, otherwise create just a normal AMS array
146 if (sh.contains('l') || sh.contains('r')) {
147 string const str_ams = fromqstr(
148 QString("%1 %2 %3").arg(int(1)).arg(int(1)).arg(deco_name));
149 dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
151 string const str_ams = fromqstr(
152 QString("%1 %2 %3").arg(nx).arg(ny).arg(deco_name));
153 dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
158 // create the normal array
159 dispatch(FuncRequest(LFUN_MATH_MATRIX, str));
164 void GuiMathMatrix::slotClose()
170 Dialog * createGuiMathMatrix(GuiView & lv) { return new GuiMathMatrix(lv); }
173 } // namespace frontend
176 #include "moc_GuiMathMatrix.cpp"