2 * \file QMathMatrixDialog.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
8 * Full author contact details are available in file CREDITS.
13 #include "QMathMatrixDialog.h"
15 #include "EmptyTable.h"
16 #include "qt_helpers.h"
18 #include "controllers/ControlMath.h"
22 #include <qlineedit.h>
23 #include <qpushbutton.h>
28 using std::ostringstream;
36 char h_align_str[80] = "c";
37 char v_align_c[] = "tcb";
42 typedef QController<ControlMath, QView<QMathMatrixDialog> > matrix_base;
45 QMathMatrix::QMathMatrix(Dialog & parent)
46 : matrix_base(parent, _("Math Matrix"))
50 void QMathMatrix::build_dialog()
52 dialog_.reset(new QMathMatrixDialog(this));
56 QMathMatrixDialog::QMathMatrixDialog(QMathMatrix * form)
61 setWindowTitle(qt_("LyX: Insert Matrix"));
63 table->setMinimumSize(100, 100);
65 columnsSB->setValue(2);
66 valignCO->setCurrentIndex(1);
68 connect(okPB, SIGNAL(clicked()),
69 this, SLOT(slotOK()));
70 connect(closePB, SIGNAL(clicked()),
71 this, SLOT(slotClose()));
73 connect( table, SIGNAL( rowsChanged(int) ), rowsSB, SLOT( setValue(int) ) );
74 connect( table, SIGNAL( colsChanged(int) ), columnsSB, SLOT( setValue(int) ) );
75 connect( rowsSB, SIGNAL( valueChanged(int) ), table, SLOT( setNumberRows(int) ) );
76 connect( columnsSB, SIGNAL( valueChanged(int) ), table, SLOT( setNumberColumns(int) ) );
77 connect( rowsSB, SIGNAL( valueChanged(int) ), this, SLOT( rowsChanged(int) ) );
78 connect( columnsSB, SIGNAL( valueChanged(int) ), this, SLOT( columnsChanged(int) ) );
79 connect( valignCO, SIGNAL( highlighted(const QString&) ), this, SLOT( change_adaptor() ) );
80 connect( halignED, SIGNAL( textChanged(const QString&) ), this, SLOT( change_adaptor() ) );
84 void QMathMatrixDialog::columnsChanged(int)
86 int const nx = int(columnsSB->value());
87 for (int i = 0; i < nx; ++i)
90 h_align_str[nx] = '\0';
91 halignED->setText(h_align_str);
95 void QMathMatrixDialog::rowsChanged(int)
100 void QMathMatrixDialog::change_adaptor()
102 // FIXME: We need a filter for the halign input
106 void QMathMatrixDialog::slotOK()
108 char const c = v_align_c[valignCO->currentIndex()];
109 string const sh = fromqstr(halignED->text());
110 int const nx = int(columnsSB->value());
111 int const ny = int(rowsSB->value());
114 os << nx << ' ' << ny << ' ' << c << ' ' << sh;
115 form_->controller().dispatchMatrix(os.str().c_str());
122 void QMathMatrixDialog::slotClose()
127 } // namespace frontend
130 #include "QMathMatrixDialog_moc.cpp"