]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiMathMatrix.cpp
Remove useless casts reported by GCC with -Wuseless-cast option
[lyx.git] / src / frontends / qt / 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 "support/gettext.h"
22
23 #include <QLineEdit>
24 #include <QPushButton>
25 #include <QSpinBox>
26
27 using namespace std;
28
29 namespace lyx {
30 namespace frontend {
31
32 static char const * const DecoChars[] = {
33         N_("None"),
34         N_("[x]"),
35         N_("(x)"),
36         N_("{x}"),
37         N_("|x|"),
38         N_("||x||"),
39         N_("small"),
40         ""
41 };
42
43 static char const * const DecoNames[] = {
44         N_("bmatrix"),
45         N_("pmatrix"),
46         N_("Bmatrix"),
47         N_("vmatrix"),
48         N_("Vmatrix"),
49         N_("smallmatrix"),
50         ""
51 };
52
53 static char const * const VertAligns[] = {
54         N_("Top"),
55         N_("Middle"),
56         N_("Bottom"),
57         ""
58 };
59
60 static char const v_align_c[] = "tcb";
61
62
63 GuiMathMatrix::GuiMathMatrix(GuiView & lv)
64         : GuiDialog(lv, "mathmatrix", qt_("Math Matrix"))
65 {
66         setupUi(this);
67
68         for (int i = 0; *VertAligns[i]; ++i)
69                 valignCO->addItem(qt_(VertAligns[i]));
70         for (int i = 0; *DecoChars[i]; ++i)
71                 decorationCO->addItem(qt_(DecoChars[i]));
72
73         table->setMinimumSize(100, 100);
74         rowsSB->setValue(5);
75         columnsSB->setValue(5);
76         valignCO->setCurrentIndex(1);
77         decorationCO->setCurrentIndex(0);
78
79         connect(table, SIGNAL(rowsChanged(int)),
80                 rowsSB, SLOT(setValue(int)));
81         connect(table, SIGNAL(colsChanged(int)),
82                 columnsSB, SLOT(setValue(int)));
83         connect(rowsSB, SIGNAL(valueChanged(int)),
84                 table, SLOT(setNumberRows(int)));
85         connect(columnsSB, SIGNAL(valueChanged(int)),
86                 table, SLOT(setNumberColumns(int)));
87         connect(rowsSB, SIGNAL(valueChanged(int)),
88                 this, SLOT(change_adaptor()));
89         connect(columnsSB, SIGNAL(valueChanged(int)),
90                 this, SLOT(columnsChanged(int)) );
91         connect(valignCO, SIGNAL(highlighted(QString)),
92                 this, SLOT(change_adaptor()));
93         connect(halignED, SIGNAL(textChanged(QString)),
94                 this, SLOT(change_adaptor()));
95         connect(decorationCO, SIGNAL(activated(int)),
96                 this, SLOT(decorationChanged(int)));
97
98         bc().setPolicy(ButtonPolicy::IgnorantPolicy);
99 }
100
101
102 void GuiMathMatrix::columnsChanged(int)
103 {
104         int const nx = columnsSB->value();
105         halignED->setText(QString(nx, 'c'));
106 }
107
108
109 void GuiMathMatrix::decorationChanged(int deco)
110 {
111         // a matrix with a decoration cannot have a vertical alignment
112         if (deco != 0) {
113                 valignCO->setEnabled(false);
114                 valignCO->setCurrentIndex(1);
115         } else
116                 valignCO->setEnabled(true);
117 }
118
119
120 void GuiMathMatrix::change_adaptor()
121 {
122         // FIXME: We need a filter for the halign input
123 }
124
125
126 void GuiMathMatrix::on_buttonBox_clicked(QAbstractButton * button)
127 {
128         switch (buttonBox->standardButton(button)) {
129         case QDialogButtonBox::Ok:
130                 slotOK();
131                 break;
132         case QDialogButtonBox::Cancel:
133                 slotClose();
134                 break;
135         default:
136                 break;
137         }
138 }
139
140
141 void GuiMathMatrix::slotOK()
142 {
143         int const nx = columnsSB->value();
144         int const ny = rowsSB->value();
145         // a matrix without a decoration is an array,
146         // otherwise it is an AMS matrix
147         // decorated matrices cannot have a vertical alignment or line
148
149         char const c = v_align_c[valignCO->currentIndex()];
150         QString const sh = halignED->text();
151         string const str = fromqstr(
152                 QString("%1 %2 %3 %4").arg(nx).arg(ny).arg(c).arg(sh));
153
154         if (decorationCO->currentIndex() != 0) {
155                 int const deco = decorationCO->currentIndex();
156                 QString deco_name = DecoNames[deco - 1];
157                 // if a vertical line or a special alignment is requested,
158                 // create a 1x1 AMS matrix containing a normal array,
159                 // otherwise create just a standard AMS matrix
160                 if (sh.contains('l') || sh.contains('r') || sh.contains('|')) {
161                         string const str_ams = fromqstr(
162                                 QString("%1 %2 %3").arg(1).arg(1).arg(deco_name));
163                         dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
164                 } else {
165                         string const str_ams = fromqstr(
166                                 QString("%1 %2 %3").arg(nx).arg(ny).arg(deco_name));
167                         dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
168                         close();
169                         return;
170                 }
171         }
172         // create the normal array
173                 dispatch(FuncRequest(LFUN_MATH_MATRIX, str));
174         close();
175 }
176
177
178 void GuiMathMatrix::slotClose()
179 {
180         close();
181 }
182
183
184 } // namespace frontend
185 } // namespace lyx
186
187 #include "moc_GuiMathMatrix.cpp"