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 <QScrollArea>
19 #include <QPushButton>
20 #include <QListWidget>
21 #include <QListWidgetItem>
24 #include "iconpalette.h"
25 #include "qt_helpers.h"
26 #include "controllers/ControlMath.h"
28 #include "support/filetools.h"
34 using support::FileName;
35 using support::libFileSearch;
42 char const ** panels[] = {
43 latex_bop, latex_varsz, latex_brel, latex_greek, latex_arrow,
44 latex_dots, latex_deco, latex_misc, latex_ams_ops,
45 latex_ams_rel, latex_ams_nrel, latex_ams_arrows,
49 int const nr_panels = sizeof(panels)/sizeof(panels[0]);
51 int panel_index[nr_panels];
56 QMathDialog::QMathDialog(QMath * form)
61 // enlarge the symbols ComboBox (no scrollbar)
62 //symbolsCO->setSizeLimit(13);
64 connect( tearoffPB, SIGNAL( clicked() ), this, SLOT( expandClicked() ) );
65 connect( closePB, SIGNAL( clicked() ), this, SLOT( accept() ) );
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 FileName icon_path = libFileSearch("images/math", "sqrt-square", "xpm");
75 sqrtPB->setIcon(QIcon(toqstr(icon_path.absFilename())));
76 icon_path = libFileSearch("images/math", "space", "xpm");
77 spacePB->setIcon(QIcon(toqstr(icon_path.absFilename())));
78 icon_path = libFileSearch("images/math", "style", "xpm");
79 stylePB->setIcon(QIcon(toqstr(icon_path.absFilename())));
80 icon_path = libFileSearch("images/math", "font", "xpm");
81 fontPB->setIcon(QIcon(toqstr(icon_path.absFilename())));
82 icon_path = libFileSearch("images/math", "equation", "xpm");
83 equationPB->setIcon(QIcon(toqstr(icon_path.absFilename())));
84 icon_path = libFileSearch("images/math", "frac-square", "xpm");
85 fracPB->setIcon(QIcon(toqstr(icon_path.absFilename())));
86 icon_path = libFileSearch("images/math", "sub", "xpm");
87 subscriptPB->setIcon(QIcon(toqstr(icon_path.absFilename())));
88 icon_path = libFileSearch("images/math", "super", "xpm");
89 superscriptPB->setIcon(QIcon(toqstr(icon_path.absFilename())));
90 icon_path = libFileSearch("images/math", "matrix", "xpm");
91 matrixPB->setIcon(QIcon(toqstr(icon_path.absFilename())));
92 icon_path = libFileSearch("images/math", "delim", "xpm");
93 delimitersPB->setIcon(QIcon(toqstr(icon_path.absFilename())));
96 for (int i = 0; *function_names[i]; ++i) {
97 functionsLW->addItem(function_names[i]);
99 //functionsLW->setFixedWidth(functionsLW->sizeHint().width());
101 // show first symbol panel
104 // add menu's to the buttons
105 QMenu * m = new QMenu(spacePB);
106 m->setTitle(qt_("LyX: Math Spacing"));
107 m->setTearOffEnabled(true);
108 addMenuItem(m, qt_("Thin space \\,"), ",");
109 addMenuItem(m, qt_("Medium space \\:"), ":");
110 addMenuItem(m, qt_("Thick space \\;"), ";");
111 addMenuItem(m, qt_("Quadratin space \\quad"), "quad");
112 addMenuItem(m, qt_("Double quadratin space \\qquad"), "qquad");
113 addMenuItem(m, qt_("Negative space \\!"), "!");
116 m = new QMenu(sqrtPB);
117 m->setTitle(qt_("LyX: Math Roots"));
118 m->setTearOffEnabled(true);
119 addMenuItem(m, qt_("Square root \\sqrt"), "sqrt");
120 QAction * ma = new QAction(qt_("Cube root \\root"), this);
121 connect(ma, SIGNAL(triggered()), this, SLOT(insertCubeRoot()));
123 addMenuItem(m, qt_("Other root \\root"), "root");
126 m = new QMenu(stylePB);
127 m->setTitle(qt_("LyX: Math Styles"));
128 m->setTearOffEnabled(true);
129 addMenuItem(m, qt_("Display style \\displaystyle"), "displaystyle");
130 addMenuItem(m, qt_("Normal text style \\textstyle"), "textstyle");
131 addMenuItem(m, qt_("Script (small) style \\scriptstyle"), "scriptstyle");
132 addMenuItem(m, qt_("Scriptscript (smaller) style \\scriptscriptstyle"), "scriptscriptstyle");
135 m = new QMenu(fracPB);
136 m->setTitle(qt_("LyX: Fractions"));
137 m->setTearOffEnabled(true);
138 addMenuItem(m, qt_("Standard \\frac"), "frac");
139 addMenuItem(m, qt_("No hor. line \\atop"), "atop");
140 addMenuItem(m, qt_("Nice \\nicefrac"), "nicefrac");
141 addMenuItem(m, qt_("Text frac (amsmath) \\tfrac"), "tfrac");
142 addMenuItem(m, qt_("Display frac (amsmath) \\dfrac"), "dfrac");
143 addMenuItem(m, qt_("Binomial \\choose"), "choose");
146 m = new QMenu(fontPB);
147 m->setTitle(qt_("LyX: Math Fonts"));
148 m->setTearOffEnabled(true);
149 addMenuItem(m, qt_("Roman \\mathrm"), "mathrm");
150 addMenuItem(m, qt_("Bold \\mathbf"), "mathbf");
151 addMenuItem(m, qt_("Bold symbol \\boldsymbol"), "boldsymbol");
152 addMenuItem(m, qt_("Sans serif \\mathsf"), "mathsf");
153 addMenuItem(m, qt_("Italic \\mathit"), "mathit");
154 addMenuItem(m, qt_("Typewriter \\mathtt"), "mathtt");
155 addMenuItem(m, qt_("Blackboard \\mathbb"), "mathbb");
156 addMenuItem(m, qt_("Fraktur \\mathfrak"), "mathfrak");
157 addMenuItem(m, qt_("Calligraphic \\mathcal"), "mathcal");
158 addMenuItem(m, qt_("Normal text mode \\textrm"), "textrm");
162 void QMathDialog::addMenuItem(QMenu * menu, const QString & label, const std::string & action)
164 QMAction * ma = new QMAction(label,action, this);
165 connect(ma, SIGNAL(action(const std::string &)), this, SLOT(symbol_clicked(const std::string &)));
169 void QMathDialog::showingPanel(int num)
171 if (!panel_index[num])
174 symbolWS->setCurrentIndex(panel_index[num]);
178 IconPalette * QMathDialog::makePanel(QWidget * parent, char const ** entries)
180 IconPalette * p = new IconPalette(parent, entries);
181 // Leave these std:: qualifications alone !
182 connect(p, SIGNAL(button_clicked(const std::string &)),
183 this, SLOT(symbol_clicked(const std::string &)));
189 void QMathDialog::addPanel(int num)
191 QScrollArea * sc = new QScrollArea(symbolWS);
192 IconPalette * p = makePanel(this, panels[num]);
194 panel_index[num] = symbolWS->addWidget(sc);
198 void QMathDialog::symbol_clicked(const string & str)
200 form_->controller().dispatchInsert(str);
204 void QMathDialog::delimiterClicked()
206 form_->controller().showDialog("mathdelimiter");
210 void QMathDialog::expandClicked()
212 int const id = symbolsCO->currentIndex();
213 IconPalette * p = makePanel(this, panels[id]);
215 s += fromqstr(symbolsCO->currentText());
216 p->setWindowTitle(toqstr(s));
217 p->setWindowFlags(Qt::Dialog);
222 void QMathDialog::functionSelected(QListWidgetItem * item)
224 form_->controller().dispatchInsert(fromqstr(item->text()));
228 void QMathDialog::matrixClicked()
230 form_->controller().showDialog("mathmatrix");
234 void QMathDialog::equationClicked()
236 form_->controller().dispatchToggleDisplay();
240 void QMathDialog::subscriptClicked()
242 form_->controller().dispatchSubscript();
246 void QMathDialog::superscriptClicked()
248 form_->controller().dispatchSuperscript();
252 void QMathDialog::insertCubeRoot()
254 form_->controller().dispatchCubeRoot();
258 } // namespace frontend
261 #include "QMathDialog_moc.cpp"