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 "frontends/Application.h"
23 #include <qwidgetstack.h>
24 #include <qcombobox.h>
25 #include <qpushbutton.h>
27 #include <qpopupmenu.h>
34 class QScrollViewSingle : public QScrollView {
36 QScrollViewSingle(QWidget * p)
37 : QScrollView(p), w_(0) {
38 setResizePolicy(Manual);
39 setHScrollBarMode(AlwaysOff);
40 setVScrollBarMode(AlwaysOn);
41 setBackgroundMode(PaletteBackground);
42 viewport()->setBackgroundMode(PaletteBackground);
45 void setChild(QWidget * w) {
47 setMinimumWidth(verticalScrollBar()->width() + w_->width() + 4);
51 virtual void resizeEvent(QResizeEvent * e) {
52 QScrollView::resizeEvent(e);
56 w_->resize(viewport()->width(), w_->height());
57 // force the resize to get accurate scrollbar
59 resizeContents(w_->width(), w_->height());
67 char const ** panels[] = {
68 latex_bop, latex_varsz, latex_brel, latex_greek, latex_arrow,
69 latex_dots, latex_deco, latex_misc, latex_ams_ops,
70 latex_ams_rel, latex_ams_nrel, latex_ams_arrows,
74 int const nr_panels = sizeof(panels)/sizeof(panels[0]);
76 bool panel_initialised[nr_panels];
81 QMathDialog::QMathDialog(QMath * form)
82 : QMathDialogBase(0, 0, false, 0),
85 // enlarge the symbols ComboBox (no scrollbar)
86 symbolsCO->setSizeLimit(13);
88 connect(symbolsCO, SIGNAL(activated(int)), symbolsWS, SLOT(raiseWidget(int)));
90 for (int i = 0; *function_names[i]; ++i) {
91 functionsLB->insertItem(function_names[i]);
94 for (int i = 0; i < nr_panels; ++i) {
95 QScrollViewSingle * view = new QScrollViewSingle(symbolsWS);
96 symbolsWS->addWidget(view, i);
99 // aboutToShow() only fires when != 0 in Qt 2 !
100 symbolsWS->raiseWidget(0);
102 panel_initialised[0] = true;
104 connect(symbolsWS, SIGNAL(aboutToShow(int)), this, SLOT(showingPanel(int)));
106 QPopupMenu * m = new QPopupMenu(spacePB);
107 m->setCaption(qt_("LyX: Math Spacing"));
108 m->insertTearOffHandle();
109 m->insertItem(qt_("Thin space \\,"), 1);
110 m->insertItem(qt_("Medium space \\:"), 2);
111 m->insertItem(qt_("Thick space \\;"), 3);
112 m->insertItem(qt_("Quadratin space \\quad"), 4);
113 m->insertItem(qt_("Double quadratin space \\qquad"), 5);
114 m->insertItem(qt_("Negative space \\!"), 6);
115 connect(m, SIGNAL(activated(int)), this, SLOT(insertSpace(int)));
116 spacePB->setPopup(m);
118 m = new QPopupMenu(sqrtPB);
119 m->setCaption(qt_("LyX: Math Roots"));
120 m->insertTearOffHandle();
121 m->insertItem(qt_("Square root \\sqrt"), 1);
122 m->insertItem(qt_("Cube root \\root"), 2);
123 m->insertItem(qt_("Other root \\root"), 3);
124 connect(m, SIGNAL(activated(int)), this, SLOT(insertRoot(int)));
127 m = new QPopupMenu(fracPB);
128 m->setCaption(qt_("LyX: Fractions"));
129 m->insertTearOffHandle();
130 m->insertItem(qt_("Standard \\frac"), 1);
131 m->insertItem(qt_("No hor. line \\atop"), 2);
132 m->insertItem(qt_("Nice \\nicefrac"), 3);
133 m->insertItem(qt_("Text frac (amsmath) \\tfrac"), 4);
134 m->insertItem(qt_("Display frac (amsmath) \\dfrac"), 5);
135 m->insertItem(qt_("Binomial \\choose"), 6);
136 connect(m, SIGNAL(activated(int)), this, SLOT(fracClicked(int)));
139 m = new QPopupMenu(stylePB);
140 m->setCaption(qt_("LyX: Math Styles"));
141 m->insertTearOffHandle();
142 m->insertItem(qt_("Display style \\displaystyle"), 1);
143 m->insertItem(qt_("Normal text style \\textstyle"), 2);
144 m->insertItem(qt_("Script (small) style \\scriptstyle"), 3);
145 m->insertItem(qt_("Scriptscript (smaller) style \\scriptscriptstyle"), 4);
146 connect(m, SIGNAL(activated(int)), this, SLOT(insertStyle(int)));
147 stylePB->setPopup(m);
149 m = new QPopupMenu(fontPB);
150 m->setCaption(qt_("LyX: Math Fonts"));
151 m->insertTearOffHandle();
152 m->insertItem(qt_("Roman \\mathrm"), 1);
153 m->insertItem(qt_("Bold \\mathbf"), 2);
154 m->insertItem(qt_("Bold symbol \\boldsymbol"), 3);
155 m->insertItem(qt_("Sans serif \\mathsf"), 4);
156 m->insertItem(qt_("Italic \\mathit"), 5);
157 m->insertItem(qt_("Typewriter \\mathtt"), 6);
158 m->insertItem(qt_("Blackboard \\mathbb"), 7);
159 m->insertItem(qt_("Fraktur \\mathfrak"), 8);
160 m->insertItem(qt_("Calligraphic \\mathcal"), 9);
161 m->insertItem(qt_("Normal text mode \\textrm"), 10);
162 connect(m, SIGNAL(activated(int)), this, SLOT(insertFont(int)));
167 void QMathDialog::showingPanel(int num)
169 if (panel_initialised[num])
174 panel_initialised[num] = true;
178 IconPalette * QMathDialog::makePanel(QWidget * parent, char const ** entries)
180 IconPalette * p = new IconPalette(parent);
181 for (int i = 0; *entries[i]; ++i) {
182 p->add(QPixmap(toqstr(find_xpm(entries[i]))), entries[i], string("\\") + entries[i]);
184 // Leave these std:: qualifications alone !
185 connect(p, SIGNAL(button_clicked(const std::string &)),
186 this, SLOT(symbol_clicked(const std::string &)));
192 void QMathDialog::addPanel(int num)
194 QScrollViewSingle * view = static_cast<QScrollViewSingle*>(symbolsWS->widget(num));
195 IconPalette * p = makePanel(view->viewport(), panels[num]);
200 void QMathDialog::symbol_clicked(const string & str)
202 form_->controller().dispatchInsert(str);
206 void QMathDialog::fracClicked(int id)
210 case 1: str = "frac"; break;
211 case 2: str = "atop"; break;
212 case 3: str = "nicefrac"; break;
213 case 4: str = "tfrac"; break;
214 case 5: str = "dfrac"; break;
215 case 6: str = "choose"; break;
218 form_->controller().dispatchInsert(str);
222 void QMathDialog::delimiterClicked()
224 form_->controller().showDialog("mathdelimiter");
228 void QMathDialog::expandClicked()
230 int const id = symbolsWS->id(symbolsWS->visibleWidget());
231 IconPalette * p = makePanel(0, panels[id]);
233 s += fromqstr(symbolsCO->text(id));
234 p->setCaption(toqstr(s));
235 p->resize(40 * 5, p->height());
237 p->setMaximumSize(p->width(), p->height());
241 void QMathDialog::functionSelected(const QString & str)
243 form_->controller().dispatchInsert(fromqstr(str));
247 void QMathDialog::matrixClicked()
249 form_->controller().showDialog("mathmatrix");
253 void QMathDialog::equationClicked()
255 form_->controller().dispatchToggleDisplay();
259 void QMathDialog::subscriptClicked()
261 form_->controller().dispatchSubscript();
265 void QMathDialog::superscriptClicked()
267 form_->controller().dispatchSuperscript();
271 void QMathDialog::insertSpace(int id)
275 case 1: str = ","; break;
276 case 2: str = ":"; break;
277 case 3: str = ";"; break;
278 case 4: str = "quad"; break;
279 case 5: str = "qquad"; break;
280 case 6: str = "!"; break;
283 form_->controller().dispatchInsert(str);
287 void QMathDialog::insertRoot(int id)
291 form_->controller().dispatchInsert("sqrt");
294 form_->controller().dispatchCubeRoot();
297 form_->controller().dispatchInsert("root");
303 void QMathDialog::insertStyle(int id)
307 case 1: str = "displaystyle"; break;
308 case 2: str = "textstyle"; break;
309 case 3: str = "scriptstyle"; break;
310 case 4: str = "scriptscriptstyle"; break;
313 form_->controller().dispatchInsert(str);
317 void QMathDialog::insertFont(int id)
321 case 1: str = "mathrm"; break;
322 case 2: str = "mathbf"; break;
323 case 3: str = "boldsymbol"; break;
324 case 4: str = "mathsf"; break;
325 case 5: str = "mathit"; break;
326 case 6: str = "mathtt"; break;
327 case 7: str = "mathbb"; break;
328 case 8: str = "mathfrak"; break;
329 case 9: str = "mathcal"; break;
330 case 10: str = "textrm"; break;
333 form_->controller().dispatchInsert(str);
336 } // namespace frontend
339 #include "QMathDialog_moc.cpp"