]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiMathMatrix.cpp
support for matrix decoration in the MathMatrix dialog;
[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
18 #include "FuncRequest.h"
19
20 #include <QLineEdit>
21 #include <QPushButton>
22 #include <QSpinBox>
23
24 using namespace std;
25
26 namespace lyx {
27 namespace frontend {
28
29 GuiMathMatrix::GuiMathMatrix(GuiView & lv)
30         : GuiDialog(lv, "mathmatrix", qt_("Math Matrix"))
31 {
32         setupUi(this);
33
34         table->setMinimumSize(100, 100);
35         rowsSB->setValue(5);
36         columnsSB->setValue(5);
37         valignCO->setCurrentIndex(1);
38         decorationCO->setCurrentIndex(0);
39
40         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
41         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
42
43         connect(table, SIGNAL(rowsChanged(int)),
44                 rowsSB, SLOT(setValue(int)));
45         connect(table, SIGNAL(colsChanged(int)),
46                 columnsSB, SLOT(setValue(int)));
47         connect(rowsSB, SIGNAL(valueChanged(int)),
48                 table, SLOT(setNumberRows(int)));
49         connect(columnsSB, SIGNAL(valueChanged(int)),
50                 table, SLOT(setNumberColumns(int)));
51         connect(rowsSB, SIGNAL(valueChanged(int)),
52                 this, SLOT(rowsChanged(int)));
53         connect(columnsSB, SIGNAL(valueChanged(int)),
54                 this, SLOT(columnsChanged(int)) );
55         connect(valignCO, SIGNAL(highlighted(QString)),
56                 this, SLOT(change_adaptor()));
57         connect(halignED, SIGNAL(textChanged(QString)),
58                 this, SLOT(change_adaptor()));
59         connect(decorationCO, SIGNAL(activated(int)),
60                 this, SLOT(decorationChanged(int)));
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::decorationChanged(int deco)
84 {
85         // a matrix with a decoration cannot have a vertical alignment
86         if (deco != 0) {
87                 alignmentGB->setEnabled(false);
88                 valignCO->setCurrentIndex(1);
89                 halignED->clear();
90         } else
91                 alignmentGB->setEnabled(true);
92 }
93
94
95 void GuiMathMatrix::change_adaptor()
96 {
97         // FIXME: We need a filter for the halign input
98 }
99
100
101 void GuiMathMatrix::slotOK()
102 {
103         int const nx = columnsSB->value();
104         int const ny = rowsSB->value();
105         // a matrix without a decoration is an array,
106         // otherwise it is an AMS matrix that cannot have a vertical alignment
107         if (decorationCO->currentIndex() == 0) {
108                 char v_align_c[] = "tcb";
109                 char const c = v_align_c[valignCO->currentIndex()];
110                 QString const sh = halignED->text();
111                 string const str = fromqstr(
112                         QString("%1 %2 %3 %4").arg(nx).arg(ny).arg(c).arg(sh));
113                 dispatch(FuncRequest(LFUN_MATH_MATRIX, str));
114         } else {
115                 int const deco = decorationCO->currentIndex();
116                 QString deco_name;
117                 switch (deco) {
118                         case 1: deco_name = "bmatrix";
119                                 break;
120                         case 2: deco_name = "pmatrix";
121                                 break;
122                         case 3: deco_name = "Bmatrix";
123                                 break;
124                         case 4: deco_name = "vmatrix";
125                                 break;
126                         case 5: deco_name = "Vmatrix";
127                                 break;
128                 }
129                 string const str_ams = fromqstr(
130                         QString("%1 %2 %3").arg(nx).arg(ny).arg(deco_name));
131                 dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
132         }
133         close();
134 }
135
136
137 void GuiMathMatrix::slotClose()
138 {
139         close();
140 }
141
142
143 Dialog * createGuiMathMatrix(GuiView & lv) { return new GuiMathMatrix(lv); }
144
145
146 } // namespace frontend
147 } // namespace lyx
148
149 #include "moc_GuiMathMatrix.cpp"