]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiMathMatrix.cpp
Fix the tab ordering of GuiDocument components.
[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(change_adaptor()));
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::decorationChanged(int deco)
75 {
76         // a matrix with a decoration cannot have a vertical alignment
77         if (deco != 0) {
78                 valignCO->setEnabled(false);
79                 valignCO->setCurrentIndex(1);
80         } else
81                 valignCO->setEnabled(true);
82 }
83
84
85 void GuiMathMatrix::change_adaptor()
86 {
87         // FIXME: We need a filter for the halign input
88 }
89
90
91 void GuiMathMatrix::slotOK()
92 {
93         int const nx = columnsSB->value();
94         int const ny = rowsSB->value();
95         // a matrix without a decoration is an array,
96         // otherwise it is an AMS matrix
97         // decorated matrices cannot have a vertical alignment
98         
99         char v_align_c[] = "tcb";
100         char const c = v_align_c[valignCO->currentIndex()];
101         QString const sh = halignED->text();
102         string const str = fromqstr(
103                 QString("%1 %2 %3 %4").arg(nx).arg(ny).arg(c).arg(sh));
104
105         if (decorationCO->currentIndex() != 0) {
106                 int const deco = decorationCO->currentIndex();
107                 QString deco_name;
108                 // FIXME This is very dangerous way of coding.
109                 // The order is defined in .ui file and anybody who will touch it
110                 // will destroy the whole math decorations machinery.
111                 // For better way look on MathDelimiter Size-combo solution and biggui[] array.
112                 // Similarly for the v_align_c stuff -- at least we should push it into
113                 // constructor and have it in one file...
114                 switch (deco) {
115                         case 1: deco_name = "bmatrix";
116                                 break;
117                         case 2: deco_name = "pmatrix";
118                                 break;
119                         case 3: deco_name = "Bmatrix";
120                                 break;
121                         case 4: deco_name = "vmatrix";
122                                 break;
123                         case 5: deco_name = "Vmatrix";
124                                 break;
125                 }
126                 // only if a special alignment is set create a 1x1 AMS array in which
127                 // a normal array will be created, otherwise create just a normal AMS array
128                 if (sh.contains('l') > 0 || sh.contains('r') > 0) {
129                         string const str_ams = fromqstr(
130                                 QString("%1 %2 %3").arg(int(1)).arg(int(1)).arg(deco_name));
131                         dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
132                 } else {
133                         string const str_ams = fromqstr(
134                                 QString("%1 %2 %3").arg(nx).arg(ny).arg(deco_name));
135                         dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
136                         close();
137                         return;
138                 }
139         }
140         // create the normal array
141                 dispatch(FuncRequest(LFUN_MATH_MATRIX, str));
142         close();
143 }
144
145
146 void GuiMathMatrix::slotClose()
147 {
148         close();
149 }
150
151
152 Dialog * createGuiMathMatrix(GuiView & lv) { return new GuiMathMatrix(lv); }
153
154
155 } // namespace frontend
156 } // namespace lyx
157
158 #include "moc_GuiMathMatrix.cpp"