]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiMathMatrix.cpp
Move the buffer related part from GuiView::renameBuffer to Buffer::saveAs.
[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                 switch (deco) {
109                         case 1: deco_name = "bmatrix";
110                                 break;
111                         case 2: deco_name = "pmatrix";
112                                 break;
113                         case 3: deco_name = "Bmatrix";
114                                 break;
115                         case 4: deco_name = "vmatrix";
116                                 break;
117                         case 5: deco_name = "Vmatrix";
118                                 break;
119                 }
120                 // only if a special alignment is set create a 1x1 AMS array in which
121                 // a normal array will be created, otherwise create just a normal AMS array
122                 if (sh.contains('l') > 0 || sh.contains('r') > 0) {
123                         string const str_ams = fromqstr(
124                                 QString("%1 %2 %3").arg(int(1)).arg(int(1)).arg(deco_name));
125                         dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
126                 } else {
127                         string const str_ams = fromqstr(
128                                 QString("%1 %2 %3").arg(nx).arg(ny).arg(deco_name));
129                         dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
130                         close();
131                         return;
132                 }
133         }
134         // create the normal array
135                 dispatch(FuncRequest(LFUN_MATH_MATRIX, str));
136         close();
137 }
138
139
140 void GuiMathMatrix::slotClose()
141 {
142         close();
143 }
144
145
146 Dialog * createGuiMathMatrix(GuiView & lv) { return new GuiMathMatrix(lv); }
147
148
149 } // namespace frontend
150 } // namespace lyx
151
152 #include "moc_GuiMathMatrix.cpp"