]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiMathMatrix.cpp
Migrate GuiLine to InsetParamsWidget.
[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         int const nx = int(columnsSB->value());
70         halignED->setText(QString(nx, 'c'));
71 }
72
73
74 void GuiMathMatrix::rowsChanged(int)
75 {
76 }
77
78
79 void GuiMathMatrix::decorationChanged(int deco)
80 {
81         // a matrix with a decoration cannot have a vertical alignment
82         if (deco != 0) {
83                 alignmentGB->setEnabled(false);
84                 valignCO->setCurrentIndex(1);
85                 halignED->clear();
86         } else
87                 alignmentGB->setEnabled(true);
88 }
89
90
91 void GuiMathMatrix::change_adaptor()
92 {
93         // FIXME: We need a filter for the halign input
94 }
95
96
97 void GuiMathMatrix::slotOK()
98 {
99         int const nx = columnsSB->value();
100         int const ny = rowsSB->value();
101         // a matrix without a decoration is an array,
102         // otherwise it is an AMS matrix that cannot have a vertical alignment
103         if (decorationCO->currentIndex() == 0) {
104                 char v_align_c[] = "tcb";
105                 char const c = v_align_c[valignCO->currentIndex()];
106                 QString const sh = halignED->text();
107                 string const str = fromqstr(
108                         QString("%1 %2 %3 %4").arg(nx).arg(ny).arg(c).arg(sh));
109                 dispatch(FuncRequest(LFUN_MATH_MATRIX, str));
110         } else {
111                 int const deco = decorationCO->currentIndex();
112                 QString deco_name;
113                 switch (deco) {
114                         case 1: deco_name = "bmatrix";
115                                 break;
116                         case 2: deco_name = "pmatrix";
117                                 break;
118                         case 3: deco_name = "Bmatrix";
119                                 break;
120                         case 4: deco_name = "vmatrix";
121                                 break;
122                         case 5: deco_name = "Vmatrix";
123                                 break;
124                 }
125                 string const str_ams = fromqstr(
126                         QString("%1 %2 %3").arg(nx).arg(ny).arg(deco_name));
127                 dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
128         }
129         close();
130 }
131
132
133 void GuiMathMatrix::slotClose()
134 {
135         close();
136 }
137
138
139 Dialog * createGuiMathMatrix(GuiView & lv) { return new GuiMathMatrix(lv); }
140
141
142 } // namespace frontend
143 } // namespace lyx
144
145 #include "moc_GuiMathMatrix.cpp"