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"
24 #include <QPushButton>
32 static char const * const DecoChars[] = {
43 static char const * const DecoNames[] = {
53 static char const * const VertAligns[] = {
60 static char const v_align_c[] = "tcb";
63 GuiMathMatrix::GuiMathMatrix(GuiView & lv)
64 : GuiDialog(lv, "mathmatrix", qt_("Math Matrix"))
68 for (int i = 0; *VertAligns[i]; ++i)
69 valignCO->addItem(qt_(VertAligns[i]));
70 for (int i = 0; *DecoChars[i]; ++i)
71 decorationCO->addItem(qt_(DecoChars[i]));
73 table->setMinimumSize(100, 100);
75 columnsSB->setValue(5);
76 valignCO->setCurrentIndex(1);
77 decorationCO->setCurrentIndex(0);
79 connect(table, SIGNAL(rowsChanged(int)),
80 rowsSB, SLOT(setValue(int)));
81 connect(table, SIGNAL(colsChanged(int)),
82 columnsSB, SLOT(setValue(int)));
83 connect(rowsSB, SIGNAL(valueChanged(int)),
84 table, SLOT(setNumberRows(int)));
85 connect(columnsSB, SIGNAL(valueChanged(int)),
86 table, SLOT(setNumberColumns(int)));
87 connect(rowsSB, SIGNAL(valueChanged(int)),
88 this, SLOT(change_adaptor()));
89 connect(columnsSB, SIGNAL(valueChanged(int)),
90 this, SLOT(columnsChanged(int)) );
91 connect(valignCO, SIGNAL(highlighted(QString)),
92 this, SLOT(change_adaptor()));
93 connect(halignED, SIGNAL(textChanged(QString)),
94 this, SLOT(change_adaptor()));
95 connect(decorationCO, SIGNAL(activated(int)),
96 this, SLOT(decorationChanged(int)));
98 bc().setPolicy(ButtonPolicy::IgnorantPolicy);
102 void GuiMathMatrix::columnsChanged(int)
104 int const nx = int(columnsSB->value());
105 halignED->setText(QString(nx, 'c'));
109 void GuiMathMatrix::decorationChanged(int deco)
111 // a matrix with a decoration cannot have a vertical alignment
113 valignCO->setEnabled(false);
114 valignCO->setCurrentIndex(1);
116 valignCO->setEnabled(true);
120 void GuiMathMatrix::change_adaptor()
122 // FIXME: We need a filter for the halign input
126 void GuiMathMatrix::on_buttonBox_clicked(QAbstractButton * button)
128 switch (buttonBox->standardButton(button)) {
129 case QDialogButtonBox::Ok:
132 case QDialogButtonBox::Cancel:
141 void GuiMathMatrix::slotOK()
143 int const nx = columnsSB->value();
144 int const ny = rowsSB->value();
145 // a matrix without a decoration is an array,
146 // otherwise it is an AMS matrix
147 // decorated matrices cannot have a vertical alignment
149 char const c = v_align_c[valignCO->currentIndex()];
150 QString const sh = halignED->text();
151 string const str = fromqstr(
152 QString("%1 %2 %3 %4").arg(nx).arg(ny).arg(c).arg(sh));
154 if (decorationCO->currentIndex() != 0) {
155 int const deco = decorationCO->currentIndex();
156 QString deco_name = DecoNames[deco - 1];
157 // only if a special alignment is set create a 1x1 AMS array in which
158 // a normal array will be created, otherwise create just a normal AMS array
159 if (sh.contains('l') || sh.contains('r')) {
160 string const str_ams = fromqstr(
161 QString("%1 %2 %3").arg(int(1)).arg(int(1)).arg(deco_name));
162 dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
164 string const str_ams = fromqstr(
165 QString("%1 %2 %3").arg(nx).arg(ny).arg(deco_name));
166 dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
171 // create the normal array
172 dispatch(FuncRequest(LFUN_MATH_MATRIX, str));
177 void GuiMathMatrix::slotClose()
183 Dialog * createGuiMathMatrix(GuiView & lv) { return new GuiMathMatrix(lv); }
186 } // namespace frontend
189 #include "moc_GuiMathMatrix.cpp"