]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QMathMatrixDialog.cpp
Transfer Text::drawSelection() from InsetText::drawSelection() to InsetText::draw...
[lyx.git] / src / frontends / qt4 / QMathMatrixDialog.cpp
1 /**
2  * \file QMathMatrixDialog.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  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "QMathMatrixDialog.h"
14
15 #include "EmptyTable.h"
16 #include "qt_helpers.h"
17
18 #include "controllers/ControlMath.h"
19
20 #include <sstream>
21
22 #include <qlineedit.h>
23 #include <qpushbutton.h>
24 #include <qspinbox.h>
25
26 #include "gettext.h"
27
28 using std::ostringstream;
29 using std::string;
30
31 namespace lyx {
32 namespace frontend {
33
34 namespace {
35
36 char h_align_str[80] = "c";
37 char v_align_c[] = "tcb";
38
39 } // namespace anon
40
41
42 typedef QController<ControlMath, QView<QMathMatrixDialog> > matrix_base;
43
44
45 QMathMatrix::QMathMatrix(Dialog & parent)
46         : matrix_base(parent, _("Math Matrix"))
47 {}
48
49
50 void QMathMatrix::build_dialog()
51 {
52         dialog_.reset(new QMathMatrixDialog(this));
53 }
54
55
56 QMathMatrixDialog::QMathMatrixDialog(QMathMatrix * form)
57         : form_(form)
58 {
59         setupUi(this);
60
61         setWindowTitle(qt_("LyX: Insert Matrix"));
62
63         table->setMinimumSize(100, 100);
64         rowsSB->setValue(5);
65         columnsSB->setValue(5);
66         valignCO->setCurrentIndex(1);
67
68         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
69         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
70
71         connect(table, SIGNAL(rowsChanged(int)),
72                 rowsSB, SLOT(setValue(int)));
73         connect(table, SIGNAL(colsChanged(int)),
74                 columnsSB, SLOT(setValue(int)));
75         connect(rowsSB, SIGNAL(valueChanged(int)),
76                 table, SLOT(setNumberRows(int)));
77         connect(columnsSB, SIGNAL(valueChanged(int)),
78                 table, SLOT(setNumberColumns(int)));
79         connect(rowsSB, SIGNAL(valueChanged(int)),
80                 this, SLOT(rowsChanged(int)));
81         connect(columnsSB, SIGNAL(valueChanged(int)),
82                 this, SLOT(columnsChanged(int)) );
83         connect(valignCO, SIGNAL(highlighted(const QString&)),
84                 this, SLOT(change_adaptor()));
85         connect(halignED, SIGNAL(textChanged(const QString&)),
86                 this, SLOT(change_adaptor()));
87 }
88
89
90 void QMathMatrixDialog::columnsChanged(int)
91 {
92         int const nx = int(columnsSB->value());
93         for (int i = 0; i < nx; ++i)
94                 h_align_str[i] = 'c';
95
96         h_align_str[nx] = '\0';
97         halignED->setText(h_align_str);
98 }
99
100
101 void QMathMatrixDialog::rowsChanged(int)
102 {
103 }
104
105
106 void QMathMatrixDialog::change_adaptor()
107 {
108         // FIXME: We need a filter for the halign input
109 }
110
111
112 void QMathMatrixDialog::slotOK()
113 {
114         char const c = v_align_c[valignCO->currentIndex()];
115         string const sh = fromqstr(halignED->text());
116         int const nx = int(columnsSB->value());
117         int const ny = int(rowsSB->value());
118
119         ostringstream os;
120         os << nx << ' ' << ny << ' ' << c << ' ' << sh;
121         form_->controller().dispatchMatrix(os.str().c_str());
122
123         // close the dialog
124         close();
125 }
126
127
128 void QMathMatrixDialog::slotClose()
129 {
130         close();
131 }
132
133 } // namespace frontend
134 } // namespace lyx
135
136 #include "QMathMatrixDialog_moc.cpp"