]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QMathMatrixDialog.cpp
* src/frontends/qt4/ui/TextLayoutUi.ui:
[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()),
69                 this, SLOT(slotOK()));
70         connect(closePB, SIGNAL(clicked()),
71                 this, SLOT(slotClose()));
72
73     connect( table, SIGNAL( rowsChanged(int) ), rowsSB, SLOT( setValue(int) ) );
74     connect( table, SIGNAL( colsChanged(int) ), columnsSB, SLOT( setValue(int) ) );
75     connect( rowsSB, SIGNAL( valueChanged(int) ), table, SLOT( setNumberRows(int) ) );
76     connect( columnsSB, SIGNAL( valueChanged(int) ), table, SLOT( setNumberColumns(int) ) );
77     connect( rowsSB, SIGNAL( valueChanged(int) ), this, SLOT( rowsChanged(int) ) );
78     connect( columnsSB, SIGNAL( valueChanged(int) ), this, SLOT( columnsChanged(int) ) );
79     connect( valignCO, SIGNAL( highlighted(const QString&) ), this, SLOT( change_adaptor() ) );
80     connect( halignED, SIGNAL( textChanged(const QString&) ), this, SLOT( change_adaptor() ) );
81 }
82
83
84 void QMathMatrixDialog::columnsChanged(int)
85 {
86         int const nx = int(columnsSB->value());
87         for (int i = 0; i < nx; ++i)
88                 h_align_str[i] = 'c';
89
90         h_align_str[nx] = '\0';
91         halignED->setText(h_align_str);
92 }
93
94
95 void QMathMatrixDialog::rowsChanged(int)
96 {
97 }
98
99
100 void QMathMatrixDialog::change_adaptor()
101 {
102         // FIXME: We need a filter for the halign input
103 }
104
105
106 void QMathMatrixDialog::slotOK()
107 {
108         char const c = v_align_c[valignCO->currentIndex()];
109         string const sh = fromqstr(halignED->text());
110         int const nx = int(columnsSB->value());
111         int const ny = int(rowsSB->value());
112
113         ostringstream os;
114         os << nx << ' ' << ny << ' ' << c << ' ' << sh;
115         form_->controller().dispatchMatrix(os.str().c_str());
116
117         // close the dialog
118         close();
119 }
120
121
122 void QMathMatrixDialog::slotClose()
123 {
124         close();
125 }
126
127 } // namespace frontend
128 } // namespace lyx
129
130 #include "QMathMatrixDialog_moc.cpp"