]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiMathMatrix.cpp
the fun begins....
[lyx.git] / src / frontends / qt4 / GuiMathMatrix.cpp
1 /**
2  * \file GuiMathMatrix.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jürgen Spitzmüller
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "GuiMathMatrix.h"
14
15 #include "ControlMath.h"
16 #include "EmptyTable.h"
17 #include "qt_helpers.h"
18 #include "gettext.h"
19
20 #include <sstream>
21
22 #include <QLineEdit>
23 #include <QPushButton>
24 #include <QSpinBox>
25
26 using std::ostringstream;
27 using std::string;
28
29 namespace lyx {
30 namespace frontend {
31
32 GuiMathMatrixDialog::GuiMathMatrixDialog(LyXView & lv)
33         : GuiDialog(lv, "mathmatrix")
34 {
35         setupUi(this);
36         setViewTitle(_("Math Matrix"));
37         setController(new ControlMath(*this));
38
39         setWindowTitle(qt_("LyX: Insert Matrix"));
40
41         table->setMinimumSize(100, 100);
42         rowsSB->setValue(5);
43         columnsSB->setValue(5);
44         valignCO->setCurrentIndex(1);
45
46         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
47         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
48
49         connect(table, SIGNAL(rowsChanged(int)),
50                 rowsSB, SLOT(setValue(int)));
51         connect(table, SIGNAL(colsChanged(int)),
52                 columnsSB, SLOT(setValue(int)));
53         connect(rowsSB, SIGNAL(valueChanged(int)),
54                 table, SLOT(setNumberRows(int)));
55         connect(columnsSB, SIGNAL(valueChanged(int)),
56                 table, SLOT(setNumberColumns(int)));
57         connect(rowsSB, SIGNAL(valueChanged(int)),
58                 this, SLOT(rowsChanged(int)));
59         connect(columnsSB, SIGNAL(valueChanged(int)),
60                 this, SLOT(columnsChanged(int)) );
61         connect(valignCO, SIGNAL(highlighted(const QString&)),
62                 this, SLOT(change_adaptor()));
63         connect(halignED, SIGNAL(textChanged(const QString&)),
64                 this, SLOT(change_adaptor()));
65
66         bc().setPolicy(ButtonPolicy::IgnorantPolicy);
67 }
68
69
70 ControlMath & GuiMathMatrixDialog::controller() const
71 {
72         return static_cast<ControlMath &>(Dialog::controller());
73 }
74
75
76 void GuiMathMatrixDialog::columnsChanged(int)
77 {
78         char h_align_str[80] = "c";
79         int const nx = int(columnsSB->value());
80         for (int i = 0; i < nx; ++i)
81                 h_align_str[i] = 'c';
82
83         h_align_str[nx] = '\0';
84         halignED->setText(h_align_str);
85 }
86
87
88 void GuiMathMatrixDialog::rowsChanged(int)
89 {
90 }
91
92
93 void GuiMathMatrixDialog::change_adaptor()
94 {
95         // FIXME: We need a filter for the halign input
96 }
97
98
99 void GuiMathMatrixDialog::slotOK()
100 {
101         char v_align_c[] = "tcb";
102         char const c = v_align_c[valignCO->currentIndex()];
103         string const sh = fromqstr(halignED->text());
104         int const nx = int(columnsSB->value());
105         int const ny = int(rowsSB->value());
106
107         ostringstream os;
108         os << nx << ' ' << ny << ' ' << c << ' ' << sh;
109         controller().dispatchMatrix(os.str().c_str());
110
111         // close the dialog
112         close();
113 }
114
115
116 void GuiMathMatrixDialog::slotClose()
117 {
118         close();
119 }
120
121 } // namespace frontend
122 } // namespace lyx
123
124 #include "GuiMathMatrix_moc.cpp"