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