]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiMathMatrix.cpp
move Controller inheritance further up the tree
[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 "EmptyTable.h"
16 #include "qt_helpers.h"
17 #include "gettext.h"
18
19 #include <sstream>
20
21 #include <QLineEdit>
22 #include <QPushButton>
23 #include <QSpinBox>
24
25 using std::ostringstream;
26 using std::string;
27
28 namespace lyx {
29 namespace frontend {
30
31 GuiMathMatrix::GuiMathMatrix(LyXView & lv)
32         : GuiMath(lv, "mathmatrix")
33 {
34         setupUi(this);
35         setViewTitle(_("Math Matrix"));
36
37         table->setMinimumSize(100, 100);
38         rowsSB->setValue(5);
39         columnsSB->setValue(5);
40         valignCO->setCurrentIndex(1);
41
42         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
43         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
44
45         connect(table, SIGNAL(rowsChanged(int)),
46                 rowsSB, SLOT(setValue(int)));
47         connect(table, SIGNAL(colsChanged(int)),
48                 columnsSB, SLOT(setValue(int)));
49         connect(rowsSB, SIGNAL(valueChanged(int)),
50                 table, SLOT(setNumberRows(int)));
51         connect(columnsSB, SIGNAL(valueChanged(int)),
52                 table, SLOT(setNumberColumns(int)));
53         connect(rowsSB, SIGNAL(valueChanged(int)),
54                 this, SLOT(rowsChanged(int)));
55         connect(columnsSB, SIGNAL(valueChanged(int)),
56                 this, SLOT(columnsChanged(int)) );
57         connect(valignCO, SIGNAL(highlighted(const QString&)),
58                 this, SLOT(change_adaptor()));
59         connect(halignED, SIGNAL(textChanged(const QString&)),
60                 this, SLOT(change_adaptor()));
61
62         bc().setPolicy(ButtonPolicy::IgnorantPolicy);
63 }
64
65
66 void GuiMathMatrix::columnsChanged(int)
67 {
68         char h_align_str[80] = "c";
69         int const nx = int(columnsSB->value());
70         for (int i = 0; i < nx; ++i)
71                 h_align_str[i] = 'c';
72
73         h_align_str[nx] = '\0';
74         halignED->setText(h_align_str);
75 }
76
77
78 void GuiMathMatrix::rowsChanged(int)
79 {
80 }
81
82
83 void GuiMathMatrix::change_adaptor()
84 {
85         // FIXME: We need a filter for the halign input
86 }
87
88
89 void GuiMathMatrix::slotOK()
90 {
91         char v_align_c[] = "tcb";
92         char const c = v_align_c[valignCO->currentIndex()];
93         string const sh = fromqstr(halignED->text());
94         int const nx = int(columnsSB->value());
95         int const ny = int(rowsSB->value());
96
97         ostringstream os;
98         os << nx << ' ' << ny << ' ' << c << ' ' << sh;
99         dispatchMatrix(os.str().c_str());
100
101         // close the dialog
102         close();
103 }
104
105
106 void GuiMathMatrix::slotClose()
107 {
108         close();
109 }
110
111
112 Dialog * createGuiMathMatrix(LyXView & lv) { return new GuiMathMatrix(lv); }
113
114
115 } // namespace frontend
116 } // namespace lyx
117
118 #include "GuiMathMatrix_moc.cpp"