3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
14 #pragma implementation
17 #include "support/filetools.h"
21 #include "QMathDialog.h"
24 #include "ControlMath.h"
25 #include "iconpalette.h"
26 #include "QDelimiterDialog.h"
27 #include "QMathMatrixDialog.h"
29 #include <qapplication.h>
30 #include <qwidgetstack.h>
31 #include <qcombobox.h>
32 #include <qpushbutton.h>
35 #include <qscrollview.h>
37 #include <qpopupmenu.h>
45 class QScrollViewSingle : public QScrollView {
47 QScrollViewSingle(QWidget * p)
48 : QScrollView(p), w_(0) {
49 setResizePolicy(Manual);
50 setHScrollBarMode(AlwaysOff);
51 setVScrollBarMode(AlwaysOn);
52 setBackgroundMode(PaletteBackground);
53 viewport()->setBackgroundMode(PaletteBackground);
56 void setChild(QWidget * w) {
58 setMinimumWidth(verticalScrollBar()->width() + w_->width() + 4);
62 virtual void resizeEvent(QResizeEvent * e) {
63 QScrollView::resizeEvent(e);
67 w_->resize(viewport()->width(), w_->height());
68 // force the resize to get accurate scrollbars
69 qApp->processEvents();
70 resizeContents(w_->width(), w_->height());
78 char const ** panels[] = {
79 latex_bop, latex_varsz, latex_brel, latex_greek, latex_arrow,
80 latex_dots, latex_deco, latex_misc, latex_ams_ops,
81 latex_ams_rel, latex_ams_nrel, latex_ams_arrows,
85 int const nr_panels = sizeof(panels)/sizeof(panels[0]);
87 bool panel_initialised[nr_panels];
92 QMathDialog::QMathDialog(QMath * form)
93 : QMathDialogBase(0, 0, false, 0),
96 // enlarge the symbols ComboBox (no scrollbar)
97 symbolsCO->setSizeLimit(13);
99 connect(symbolsCO, SIGNAL(activated(int)), symbolsWS, SLOT(raiseWidget(int)));
101 for (int i = 0; *function_names[i]; ++i) {
102 functionsLB->insertItem(function_names[i]);
105 for (int i = 0; i < nr_panels; ++i) {
106 QScrollViewSingle * view = new QScrollViewSingle(symbolsWS);
107 symbolsWS->addWidget(view, i);
110 // aboutToShow() only fires when != 0 in Qt 2 !
111 symbolsWS->raiseWidget(0);
113 panel_initialised[0] = true;
115 connect(symbolsWS, SIGNAL(aboutToShow(int)), this, SLOT(showingPanel(int)));
117 QPopupMenu * m = new QPopupMenu(spacePB);
118 m->setCaption(_("LyX: Insert space"));
119 m->insertTearOffHandle();
120 m->insertItem(_("Thin space \\,"), 1);
121 m->insertItem(_("Medium space \\:"), 2);
122 m->insertItem(_("Thick space \\;"), 3);
123 m->insertItem(_("Quadratin space \\quad"), 4);
124 m->insertItem(_("Double quadratin space \\qquad"), 5);
125 m->insertItem(_("Negative space \\!"), 6);
126 connect(m, SIGNAL(activated(int)), this, SLOT(insertSpace(int)));
127 spacePB->setPopup(m);
129 m = new QPopupMenu(sqrtPB);
130 m->setCaption(_("LyX: Insert root"));
131 m->insertTearOffHandle();
132 m->insertItem(_("Square root \\sqrt"), 1);
133 m->insertItem(_("Cube root \\root"), 2);
134 m->insertItem(_("Other root \\root"), 3);
135 connect(m, SIGNAL(activated(int)), this, SLOT(insertRoot(int)));
138 m = new QPopupMenu(stylePB);
139 m->setCaption(_("LyX: Set math style"));
140 m->insertTearOffHandle();
141 m->insertItem(_("Display style \\displaystyle"), 1);
142 m->insertItem(_("Normal text style \\textstyle"), 2);
143 m->insertItem(_("Script (small) style \\scriptstyle"), 3);
144 m->insertItem(_("Scriptscript (smaller) style \\scriptscriptstyle"), 4);
145 connect(m, SIGNAL(activated(int)), this, SLOT(insertStyle(int)));
146 stylePB->setPopup(m);
148 m = new QPopupMenu(fontPB);
149 m->setCaption(_("LyX: Set math font"));
150 m->insertTearOffHandle();
151 m->insertItem(_("Roman \\mathrm"), 1);
152 m->insertItem(_("Bold \\mathbf"), 2);
153 m->insertItem(_("San serif \\mathsf"), 3);
154 m->insertItem(_("Italic \\mathit"), 4);
155 m->insertItem(_("Typewriter \\mathtt"), 5);
156 m->insertItem(_("Blackboard \\mathbb"), 6);
157 m->insertItem(_("Fraktur \\mathfrak"), 7);
158 m->insertItem(_("Calligraphic \\mathcal"), 8);
159 m->insertItem(_("Normal text mode \\textrm"), 9);
160 connect(m, SIGNAL(activated(int)), this, SLOT(insertFont(int)));
165 void QMathDialog::showingPanel(int num)
167 if (panel_initialised[num])
172 // Qt needs to catch up. Dunno why.
173 qApp->processEvents();
175 panel_initialised[num] = true;
179 IconPalette * QMathDialog::makePanel(QWidget * parent, char const ** entries)
181 IconPalette * p = new IconPalette(parent);
182 for (int i = 0; *entries[i]; ++i) {
183 string xpm_name = LibFileSearch("images/math/", entries[i], "xpm");
184 p->add(QPixmap(xpm_name.c_str()), entries[i], string("\\") + entries[i]);
186 connect(p, SIGNAL(button_clicked(string const &)), this, SLOT(symbol_clicked(string const &)));
192 void QMathDialog::addPanel(int num)
194 QScrollViewSingle * view = static_cast<QScrollViewSingle*>(symbolsWS->visibleWidget());
195 IconPalette * p = makePanel(view->viewport(), panels[num]);
200 void QMathDialog::symbol_clicked(string const & str)
206 void QMathDialog::fracClicked()
208 form_->insert("frac");
212 void QMathDialog::delimiterClicked()
215 QDelimiterDialog * d = new QDelimiterDialog(form_);
220 void QMathDialog::expandClicked()
222 int const id = symbolsWS->id(symbolsWS->visibleWidget());
223 IconPalette * p = makePanel(0, panels[id]);
225 s += symbolsCO->text(id).latin1();
226 p->setCaption(s.c_str());
227 p->resize(40 * 5, p->height());
229 p->setMaximumSize(p->width(), p->height());
233 void QMathDialog::functionSelected(const QString & str)
235 form_->insert(str.latin1());
239 void QMathDialog::matrixClicked()
242 QMathMatrixDialog * d = new QMathMatrixDialog(form_);
247 void QMathDialog::equationClicked()
249 form_->toggleDisplay();
253 void QMathDialog::subscriptClicked()
259 void QMathDialog::superscriptClicked()
261 form_->superscript();
265 void QMathDialog::insertSpace(int id)
269 case 1: str = ","; break;
270 case 2: str = ":"; break;
271 case 3: str = ";"; break;
272 case 4: str = "quad"; break;
273 case 5: str = "qquad"; break;
274 case 6: str = "!"; break;
280 void QMathDialog::insertRoot(int id)
284 form_->insert("sqrt");
287 form_->insertCubeRoot();
290 form_->insert("root");
296 void QMathDialog::insertStyle(int id)
300 case 1: str = "displaystyle"; break;
301 case 2: str = "textstyle"; break;
302 case 3: str = "scriptstyle"; break;
303 case 4: str = "scriptscriptstyle"; break;
309 void QMathDialog::insertFont(int id)
313 case 1: str = "mathrm"; break;
314 case 2: str = "mathbf"; break;
315 case 3: str = "mathsf"; break;
316 case 4: str = "mathit"; break;
317 case 5: str = "mathtt"; break;
318 case 6: str = "mathbb"; break;
319 case 7: str = "mathfrak"; break;
320 case 8: str = "mathcal"; break;
321 case 9: str = "textrm"; break;