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"
17 #include <QResizeEvent>
19 #include "iconpalette.h"
20 #include "qt_helpers.h"
22 #include "controllers/ControlMath.h"
24 #include "frontends/lyx_gui.h"
26 #include <q3widgetstack.h>
27 #include <qpushbutton.h>
28 #include <q3listbox.h>
29 #include <q3popupmenu.h>
36 class QScrollViewSingle : public Q3ScrollView {
38 QScrollViewSingle(QWidget * p)
39 : Q3ScrollView(p), w_(0) {
40 setResizePolicy(Manual);
41 setHScrollBarMode(AlwaysOff);
42 setVScrollBarMode(AlwaysOn);
43 setBackgroundMode(Qt::PaletteBackground);
44 viewport()->setBackgroundMode(Qt::PaletteBackground);
47 void setChild(QWidget * w) {
49 setMinimumWidth(verticalScrollBar()->width() + w_->width() + 4);
53 virtual void resizeEvent(QResizeEvent * e) {
54 Q3ScrollView::resizeEvent(e);
58 w_->resize(viewport()->width(), w_->height());
59 // force the resize to get accurate scrollbar
60 lyx_gui::sync_events();
61 resizeContents(w_->width(), w_->height());
69 char const ** panels[] = {
70 latex_bop, latex_varsz, latex_brel, latex_greek, latex_arrow,
71 latex_dots, latex_deco, latex_misc, latex_ams_ops,
72 latex_ams_rel, latex_ams_nrel, latex_ams_arrows,
76 int const nr_panels = sizeof(panels)/sizeof(panels[0]);
78 bool panel_initialised[nr_panels];
83 QMathDialog::QMathDialog(QMath * form)
88 // enlarge the symbols ComboBox (no scrollbar)
89 //symbolsCO->setSizeLimit(13);
91 connect(symbolsCO, SIGNAL(activated(int)), symbolsWS, SLOT(raiseWidget(int)));
93 connect( tearoffPB, SIGNAL( clicked() ), this, SLOT( expandClicked() ) );
94 connect( closePB, SIGNAL( clicked() ), this, SLOT( accept() ) );
95 connect( fracPB, SIGNAL( clicked() ), this, SLOT( fracClicked() ) );
96 connect( superscriptPB, SIGNAL( clicked() ), this, SLOT( superscriptClicked() ) );
97 connect( subscriptPB, SIGNAL( clicked() ), this, SLOT( subscriptClicked() ) );
98 connect( delimitersPB, SIGNAL( clicked() ), this, SLOT( delimiterClicked() ) );
99 connect( matrixPB, SIGNAL( clicked() ), this, SLOT( matrixClicked() ) );
100 connect( functionsLB, SIGNAL( selected(const QString&) ), this, SLOT( functionSelected(const QString &) ) );
101 connect( equationPB, SIGNAL( clicked() ), this, SLOT( equationClicked() ) );
103 for (int i = 0; *function_names[i]; ++i) {
104 functionsLB->insertItem(function_names[i]);
107 for (int i = 0; i < nr_panels; ++i) {
108 QScrollViewSingle * view = new QScrollViewSingle(symbolsWS);
109 symbolsWS->addWidget(view, i);
112 // aboutToShow() only fires when != 0 in Qt 2 !
113 symbolsWS->raiseWidget(0);
115 panel_initialised[0] = true;
117 connect(symbolsWS, SIGNAL(aboutToShow(int)), this, SLOT(showingPanel(int)));
119 Q3PopupMenu * m = new Q3PopupMenu(spacePB);
120 m->setCaption(qt_("LyX: Math Spacing"));
121 m->insertTearOffHandle();
122 m->insertItem(qt_("Thin space \\,"), 1);
123 m->insertItem(qt_("Medium space \\:"), 2);
124 m->insertItem(qt_("Thick space \\;"), 3);
125 m->insertItem(qt_("Quadratin space \\quad"), 4);
126 m->insertItem(qt_("Double quadratin space \\qquad"), 5);
127 m->insertItem(qt_("Negative space \\!"), 6);
128 connect(m, SIGNAL(activated(int)), this, SLOT(insertSpace(int)));
129 spacePB->setPopup(m);
131 m = new Q3PopupMenu(sqrtPB);
132 m->setCaption(qt_("LyX: Math Roots"));
133 m->insertTearOffHandle();
134 m->insertItem(qt_("Square root \\sqrt"), 1);
135 m->insertItem(qt_("Cube root \\root"), 2);
136 m->insertItem(qt_("Other root \\root"), 3);
137 connect(m, SIGNAL(activated(int)), this, SLOT(insertRoot(int)));
140 m = new Q3PopupMenu(stylePB);
141 m->setCaption(qt_("LyX: Math Styles"));
142 m->insertTearOffHandle();
143 m->insertItem(qt_("Display style \\displaystyle"), 1);
144 m->insertItem(qt_("Normal text style \\textstyle"), 2);
145 m->insertItem(qt_("Script (small) style \\scriptstyle"), 3);
146 m->insertItem(qt_("Scriptscript (smaller) style \\scriptscriptstyle"), 4);
147 connect(m, SIGNAL(activated(int)), this, SLOT(insertStyle(int)));
148 stylePB->setPopup(m);
150 m = new Q3PopupMenu(fontPB);
151 m->setCaption(qt_("LyX: Math Fonts"));
152 m->insertTearOffHandle();
153 m->insertItem(qt_("Roman \\mathrm"), 1);
154 m->insertItem(qt_("Bold \\mathbf"), 2);
155 m->insertItem(qt_("Bold symbol \\boldsymbol"), 3);
156 m->insertItem(qt_("Sans serif \\mathsf"), 4);
157 m->insertItem(qt_("Italic \\mathit"), 5);
158 m->insertItem(qt_("Typewriter \\mathtt"), 6);
159 m->insertItem(qt_("Blackboard \\mathbb"), 7);
160 m->insertItem(qt_("Fraktur \\mathfrak"), 8);
161 m->insertItem(qt_("Calligraphic \\mathcal"), 9);
162 m->insertItem(qt_("Normal text mode \\textrm"), 10);
163 connect(m, SIGNAL(activated(int)), this, SLOT(insertFont(int)));
168 void QMathDialog::showingPanel(int num)
170 if (panel_initialised[num])
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 p->add(QPixmap(toqstr(find_xpm(entries[i]))), entries[i], string("\\") + entries[i]);
185 // Leave these std:: qualifications alone !
186 connect(p, SIGNAL(button_clicked(const std::string &)),
187 this, SLOT(symbol_clicked(const std::string &)));
193 void QMathDialog::addPanel(int num)
195 QScrollViewSingle * view = static_cast<QScrollViewSingle*>(symbolsWS->widget(num));
196 IconPalette * p = makePanel(view->viewport(), panels[num]);
201 void QMathDialog::symbol_clicked(const string & str)
203 form_->controller().dispatchInsert(str);
207 void QMathDialog::fracClicked()
209 form_->controller().dispatchInsert("frac");
213 void QMathDialog::delimiterClicked()
215 form_->controller().showDialog("mathdelimiter");
219 void QMathDialog::expandClicked()
221 int const id = symbolsWS->id(symbolsWS->visibleWidget());
222 IconPalette * p = makePanel(0, panels[id]);
224 s += fromqstr(symbolsCO->text(id));
225 p->setCaption(toqstr(s));
226 p->resize(40 * 5, p->height());
228 p->setMaximumSize(p->width(), p->height());
232 void QMathDialog::functionSelected(const QString & str)
234 form_->controller().dispatchInsert(fromqstr(str));
238 void QMathDialog::matrixClicked()
240 form_->controller().showDialog("mathmatrix");
244 void QMathDialog::equationClicked()
246 form_->controller().dispatchToggleDisplay();
250 void QMathDialog::subscriptClicked()
252 form_->controller().dispatchSubscript();
256 void QMathDialog::superscriptClicked()
258 form_->controller().dispatchSuperscript();
262 void QMathDialog::insertSpace(int id)
266 case 1: str = ","; break;
267 case 2: str = ":"; break;
268 case 3: str = ";"; break;
269 case 4: str = "quad"; break;
270 case 5: str = "qquad"; break;
271 case 6: str = "!"; break;
274 form_->controller().dispatchInsert(str);
278 void QMathDialog::insertRoot(int id)
282 form_->controller().dispatchInsert("sqrt");
285 form_->controller().dispatchCubeRoot();
288 form_->controller().dispatchInsert("root");
294 void QMathDialog::insertStyle(int id)
298 case 1: str = "displaystyle"; break;
299 case 2: str = "textstyle"; break;
300 case 3: str = "scriptstyle"; break;
301 case 4: str = "scriptscriptstyle"; break;
304 form_->controller().dispatchInsert(str);
308 void QMathDialog::insertFont(int id)
312 case 1: str = "mathrm"; break;
313 case 2: str = "mathbf"; break;
314 case 3: str = "boldsymbol"; break;
315 case 4: str = "mathsf"; break;
316 case 5: str = "mathit"; break;
317 case 6: str = "mathtt"; break;
318 case 7: str = "mathbb"; break;
319 case 8: str = "mathfrak"; break;
320 case 9: str = "mathcal"; break;
321 case 10: str = "textrm"; break;
324 form_->controller().dispatchInsert(str);
327 } // namespace frontend