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