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>
18 #include <QScrollArea>
20 #include <QPushButton>
21 #include <QListWidget>
22 #include <QListWidgetItem>
25 #include "iconpalette.h"
26 #include "qt_helpers.h"
27 #include "controllers/ControlMath.h"
28 #include "frontends/lyx_gui.h"
29 #include "support/filetools.h"
33 using lyx::support::libFileSearch;
41 char const ** panels[] = {
42 latex_bop, latex_varsz, latex_brel, latex_greek, latex_arrow,
43 latex_dots, latex_deco, latex_misc, latex_ams_ops,
44 latex_ams_rel, latex_ams_nrel, latex_ams_arrows,
48 int const nr_panels = sizeof(panels)/sizeof(panels[0]);
50 bool panel_initialised[nr_panels];
55 QMathDialog::QMathDialog(QMath * form)
60 // enlarge the symbols ComboBox (no scrollbar)
61 //symbolsCO->setSizeLimit(13);
63 connect( tearoffPB, SIGNAL( clicked() ), this, SLOT( expandClicked() ) );
64 connect( closePB, SIGNAL( clicked() ), this, SLOT( accept() ) );
65 connect( fracPB, SIGNAL( clicked() ), this, SLOT( fracClicked() ) );
66 connect( superscriptPB, SIGNAL( clicked() ), this, SLOT( superscriptClicked() ) );
67 connect( subscriptPB, SIGNAL( clicked() ), this, SLOT( subscriptClicked() ) );
68 connect( delimitersPB, SIGNAL( clicked() ), this, SLOT( delimiterClicked() ) );
69 connect( matrixPB, SIGNAL( clicked() ), this, SLOT( matrixClicked() ) );
70 connect( functionsLW, SIGNAL( itemActivated(QListWidgetItem *) ), this, SLOT( functionSelected(QListWidgetItem *) ) );
71 connect( equationPB, SIGNAL( clicked() ), this, SLOT( equationClicked() ) );
72 connect( symbolsCO, SIGNAL(activated(int)), this, SLOT(showingPanel(int)));
74 string icon_path = libFileSearch("images/math", "sqrt-square", "xpm");
75 sqrtPB->setIcon(QIcon(toqstr(icon_path)));
76 icon_path = libFileSearch("images/math", "space", "xpm");
77 spacePB->setIcon(QIcon(toqstr(icon_path)));
78 icon_path = libFileSearch("images/math", "style", "xpm");
79 stylePB->setIcon(QIcon(toqstr(icon_path)));
80 icon_path = libFileSearch("images/math", "font", "xpm");
81 fontPB->setIcon(QIcon(toqstr(icon_path)));
82 icon_path = libFileSearch("images/math", "equation", "xpm");
83 equationPB->setIcon(QIcon(toqstr(icon_path)));
84 icon_path = libFileSearch("images/math", "frac-square", "xpm");
85 fracPB->setIcon(QIcon(toqstr(icon_path)));
86 icon_path = libFileSearch("images/math", "sub", "xpm");
87 subscriptPB->setIcon(QIcon(toqstr(icon_path)));
88 icon_path = libFileSearch("images/math", "super", "xpm");
89 superscriptPB->setIcon(QIcon(toqstr(icon_path)));
90 icon_path = libFileSearch("images/math", "matrix", "xpm");
91 matrixPB->setIcon(QIcon(toqstr(icon_path)));
92 icon_path = libFileSearch("images/math", "delim", "xpm");
93 delimitersPB->setIcon(QIcon(toqstr(icon_path)));
96 for (int i = 0; *function_names[i]; ++i) {
97 functionsLW->addItem(function_names[i]);
99 //functionsLW->setFixedWidth(functionsLW->sizeHint().width());
101 // add first symbol panel
104 // 5 buttons + 2 margins + 1 scrollbar
105 symbolWS->setFixedWidth(5*40 + 2*10 + 15 );
107 // add menu's to the buttons
108 QMenu * m = new QMenu(spacePB);
109 m->setTitle(qt_("LyX: Math Spacing"));
110 m->setTearOffEnabled(true);
111 addMenuItem(m, qt_("Thin space \\,"), ",");
112 addMenuItem(m, qt_("Medium space \\:"), ":");
113 addMenuItem(m, qt_("Thick space \\;"), ";");
114 addMenuItem(m, qt_("Quadratin space \\quad"), "quad");
115 addMenuItem(m, qt_("Double quadratin space \\qquad"), "qquad");
116 addMenuItem(m, qt_("Negative space \\!"), "!");
119 m = new QMenu(sqrtPB);
120 m->setTitle(qt_("LyX: Math Roots"));
121 m->setTearOffEnabled(true);
122 addMenuItem(m, qt_("Square root \\sqrt"), "sqrt");
123 QAction * ma = new QAction(qt_("Cube root \\root"), this);
124 connect(ma, SIGNAL(triggered()), this, SLOT(insertCubeRoot()));
126 addMenuItem(m, qt_("Other root \\root"), "root");
129 m = new QMenu(stylePB);
130 m->setTitle(qt_("LyX: Math Styles"));
131 m->setTearOffEnabled(true);
132 addMenuItem(m, qt_("Display style \\displaystyle"), "displaystyle");
133 addMenuItem(m, qt_("Normal text style \\textstyle"), "textstyle");
134 addMenuItem(m, qt_("Script (small) style \\scriptstyle"), "scriptstyle");
135 addMenuItem(m, qt_("Scriptscript (smaller) style \\scriptscriptstyle"), "scriptscriptstyle");
136 stylePB->setPopup(m);
138 m = new QMenu(fontPB);
139 m->setTitle(qt_("LyX: Math Fonts"));
140 m->setTearOffEnabled(true);
141 addMenuItem(m, qt_("Roman \\mathrm"), "mathrm");
142 addMenuItem(m, qt_("Bold \\mathbf"), "mathbf");
143 addMenuItem(m, qt_("Bold symbol \\boldsymbol"), "boldsymbol");
144 addMenuItem(m, qt_("Sans serif \\mathsf"), "mathsf");
145 addMenuItem(m, qt_("Italic \\mathit"), "mathit");
146 addMenuItem(m, qt_("Typewriter \\mathtt"), "mathtt");
147 addMenuItem(m, qt_("Blackboard \\mathbb"), "mathbb");
148 addMenuItem(m, qt_("Fraktur \\mathfrak"), "mathfrak");
149 addMenuItem(m, qt_("Calligraphic \\mathcal"), "mathcal");
150 addMenuItem(m, qt_("Normal text mode \\textrm"), "textrm");
154 void QMathDialog::addMenuItem(QMenu * menu, const QString & label, const std::string & action)
156 QMAction * ma = new QMAction(label,action, this);
157 connect(ma, SIGNAL(action(const std::string &)), this, SLOT(symbol_clicked(const std::string &)));
161 void QMathDialog::showingPanel(int num)
163 if (!panel_initialised[num])
166 symbolWS->setCurrentIndex(num);
170 IconPalette * QMathDialog::makePanel(QWidget * parent, char const ** entries)
172 IconPalette * p = new IconPalette(parent);
173 for (int i = 0; *entries[i]; ++i) {
174 p->add(QPixmap(toqstr(find_xpm(entries[i]))), entries[i], string("\\") + entries[i]);
176 // Leave these std:: qualifications alone !
177 connect(p, SIGNAL(button_clicked(const std::string &)),
178 this, SLOT(symbol_clicked(const std::string &)));
184 void QMathDialog::addPanel(int num)
186 QScrollArea * sc = new QScrollArea(symbolWS);
187 IconPalette * p = makePanel(this, panels[num]);
188 p->resize(40 * 5, p->height());
190 symbolWS->insertWidget(num,sc);
191 panel_initialised[num] = true;
195 void QMathDialog::symbol_clicked(const string & str)
197 form_->controller().dispatchInsert(str);
201 void QMathDialog::fracClicked()
203 form_->controller().dispatchInsert("frac");
207 void QMathDialog::delimiterClicked()
209 form_->controller().showDialog("mathdelimiter");
213 void QMathDialog::expandClicked()
215 int const id = symbolsCO->currentIndex();
216 IconPalette * p = makePanel(0, panels[id]);
218 s += fromqstr(symbolsCO->currentText());
219 p->setCaption(toqstr(s));
220 p->resize(40 * 5, p->height());
222 p->setMaximumSize(p->width(), p->height());
226 void QMathDialog::functionSelected(QListWidgetItem * item)
228 form_->controller().dispatchInsert(fromqstr(item->text()));
232 void QMathDialog::matrixClicked()
234 form_->controller().showDialog("mathmatrix");
238 void QMathDialog::equationClicked()
240 form_->controller().dispatchToggleDisplay();
244 void QMathDialog::subscriptClicked()
246 form_->controller().dispatchSubscript();
250 void QMathDialog::superscriptClicked()
252 form_->controller().dispatchSuperscript();
256 void QMathDialog::insertCubeRoot()
258 form_->controller().dispatchCubeRoot();
262 } // namespace frontend
265 #include "QMathDialog_moc.cpp"