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.
13 #include "QMathDialog.h"
16 #include "iconpalette.h"
17 #include "qt_helpers.h"
19 #include "controllers/ControlMath.h"
21 #include <qwidgetstack.h>
22 #include <qcombobox.h>
23 #include <qpushbutton.h>
25 #include <qpopupmenu.h>
32 class QScrollViewSingle : public QScrollView {
34 QScrollViewSingle(QWidget * p)
35 : QScrollView(p), w_(0) {
36 setResizePolicy(Manual);
37 setHScrollBarMode(AlwaysOff);
38 setVScrollBarMode(AlwaysOn);
39 setBackgroundMode(PaletteBackground);
40 viewport()->setBackgroundMode(PaletteBackground);
43 void setChild(QWidget * w) {
45 setMinimumWidth(verticalScrollBar()->width() + w_->width() + 4);
49 virtual void resizeEvent(QResizeEvent * e) {
50 QScrollView::resizeEvent(e);
54 w_->resize(viewport()->width(), w_->height());
55 // force the resize to get accurate scrollbars
56 qApp->processEvents();
57 resizeContents(w_->width(), w_->height());
65 char const ** panels[] = {
66 latex_bop, latex_varsz, latex_brel, latex_greek, latex_arrow,
67 latex_dots, latex_deco, latex_misc, latex_ams_ops,
68 latex_ams_rel, latex_ams_nrel, latex_ams_arrows,
72 int const nr_panels = sizeof(panels)/sizeof(panels[0]);
74 bool panel_initialised[nr_panels];
79 QMathDialog::QMathDialog(QMath * form)
80 : QMathDialogBase(0, 0, false, 0),
83 // enlarge the symbols ComboBox (no scrollbar)
84 symbolsCO->setSizeLimit(13);
86 connect(symbolsCO, SIGNAL(activated(int)), symbolsWS, SLOT(raiseWidget(int)));
88 for (int i = 0; *function_names[i]; ++i) {
89 functionsLB->insertItem(function_names[i]);
92 for (int i = 0; i < nr_panels; ++i) {
93 QScrollViewSingle * view = new QScrollViewSingle(symbolsWS);
94 symbolsWS->addWidget(view, i);
97 // aboutToShow() only fires when != 0 in Qt 2 !
98 symbolsWS->raiseWidget(0);
100 panel_initialised[0] = true;
102 connect(symbolsWS, SIGNAL(aboutToShow(int)), this, SLOT(showingPanel(int)));
104 QPopupMenu * m = new QPopupMenu(spacePB);
105 m->setCaption(qt_("LyX: Insert space"));
106 m->insertTearOffHandle();
107 m->insertItem(qt_("Thin space \\,"), 1);
108 m->insertItem(qt_("Medium space \\:"), 2);
109 m->insertItem(qt_("Thick space \\;"), 3);
110 m->insertItem(qt_("Quadratin space \\quad"), 4);
111 m->insertItem(qt_("Double quadratin space \\qquad"), 5);
112 m->insertItem(qt_("Negative space \\!"), 6);
113 connect(m, SIGNAL(activated(int)), this, SLOT(insertSpace(int)));
114 spacePB->setPopup(m);
116 m = new QPopupMenu(sqrtPB);
117 m->setCaption(qt_("LyX: Insert root"));
118 m->insertTearOffHandle();
119 m->insertItem(qt_("Square root \\sqrt"), 1);
120 m->insertItem(qt_("Cube root \\root"), 2);
121 m->insertItem(qt_("Other root \\root"), 3);
122 connect(m, SIGNAL(activated(int)), this, SLOT(insertRoot(int)));
125 m = new QPopupMenu(stylePB);
126 m->setCaption(qt_("LyX: Set math style"));
127 m->insertTearOffHandle();
128 m->insertItem(qt_("Display style \\displaystyle"), 1);
129 m->insertItem(qt_("Normal text style \\textstyle"), 2);
130 m->insertItem(qt_("Script (small) style \\scriptstyle"), 3);
131 m->insertItem(qt_("Scriptscript (smaller) style \\scriptscriptstyle"), 4);
132 connect(m, SIGNAL(activated(int)), this, SLOT(insertStyle(int)));
133 stylePB->setPopup(m);
135 m = new QPopupMenu(fontPB);
136 m->setCaption(qt_("LyX: Set math font"));
137 m->insertTearOffHandle();
138 m->insertItem(qt_("Roman \\mathrm"), 1);
139 m->insertItem(qt_("Bold \\mathbf"), 2);
140 m->insertItem(qt_("Sans serif \\mathsf"), 3);
141 m->insertItem(qt_("Italic \\mathit"), 4);
142 m->insertItem(qt_("Typewriter \\mathtt"), 5);
143 m->insertItem(qt_("Blackboard \\mathbb"), 6);
144 m->insertItem(qt_("Fraktur \\mathfrak"), 7);
145 m->insertItem(qt_("Calligraphic \\mathcal"), 8);
146 m->insertItem(qt_("Normal text mode \\textrm"), 9);
147 connect(m, SIGNAL(activated(int)), this, SLOT(insertFont(int)));
152 void QMathDialog::showingPanel(int num)
154 if (panel_initialised[num])
159 // Qt needs to catch up. Dunno why.
160 qApp->processEvents();
162 panel_initialised[num] = true;
166 IconPalette * QMathDialog::makePanel(QWidget * parent, char const ** entries)
168 IconPalette * p = new IconPalette(parent);
169 for (int i = 0; *entries[i]; ++i) {
170 p->add(QPixmap(toqstr(find_xpm(entries[i]))), entries[i], string("\\") + entries[i]);
172 // Leave these std:: qualifications alone !
173 connect(p, SIGNAL(button_clicked(const std::string &)),
174 this, SLOT(symbol_clicked(const std::string &)));
180 void QMathDialog::addPanel(int num)
182 QScrollViewSingle * view = static_cast<QScrollViewSingle*>(symbolsWS->widget(num));
183 IconPalette * p = makePanel(view->viewport(), panels[num]);
188 void QMathDialog::symbol_clicked(const string & str)
190 form_->controller().dispatchInsert(str);
194 void QMathDialog::fracClicked()
196 form_->controller().dispatchInsert("frac");
200 void QMathDialog::delimiterClicked()
202 form_->controller().showDialog("mathdelimiter");
206 void QMathDialog::expandClicked()
208 int const id = symbolsWS->id(symbolsWS->visibleWidget());
209 IconPalette * p = makePanel(0, panels[id]);
211 s += fromqstr(symbolsCO->text(id));
212 p->setCaption(toqstr(s));
213 p->resize(40 * 5, p->height());
215 p->setMaximumSize(p->width(), p->height());
219 void QMathDialog::functionSelected(const QString & str)
221 form_->controller().dispatchInsert(fromqstr(str));
225 void QMathDialog::matrixClicked()
227 form_->controller().showDialog("mathmatrix");
231 void QMathDialog::equationClicked()
233 form_->controller().dispatchToggleDisplay();
237 void QMathDialog::subscriptClicked()
239 form_->controller().dispatchSubscript();
243 void QMathDialog::superscriptClicked()
245 form_->controller().dispatchSuperscript();
249 void QMathDialog::insertSpace(int id)
253 case 1: str = ","; break;
254 case 2: str = ":"; break;
255 case 3: str = ";"; break;
256 case 4: str = "quad"; break;
257 case 5: str = "qquad"; break;
258 case 6: str = "!"; break;
261 form_->controller().dispatchInsert(str);
265 void QMathDialog::insertRoot(int id)
269 form_->controller().dispatchInsert("sqrt");
272 form_->controller().dispatchCubeRoot();
275 form_->controller().dispatchInsert("root");
281 void QMathDialog::insertStyle(int id)
285 case 1: str = "displaystyle"; break;
286 case 2: str = "textstyle"; break;
287 case 3: str = "scriptstyle"; break;
288 case 4: str = "scriptscriptstyle"; break;
291 form_->controller().dispatchInsert(str);
295 void QMathDialog::insertFont(int id)
299 case 1: str = "mathrm"; break;
300 case 2: str = "mathbf"; break;
301 case 3: str = "mathsf"; break;
302 case 4: str = "mathit"; break;
303 case 5: str = "mathtt"; break;
304 case 6: str = "mathbb"; break;
305 case 7: str = "mathfrak"; break;
306 case 8: str = "mathcal"; break;
307 case 9: str = "textrm"; break;
310 form_->controller().dispatchInsert(str);
313 } // namespace frontend