3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
6 * \author John Levon <moz@compsoc.man.ac.uk>
11 #include "support/filetools.h"
14 #include "QMathDialog.h"
17 #include "ControlMath.h"
18 #include "iconpalette.h"
20 #include <qapplication.h>
21 #include <qwidgetstack.h>
22 #include <qcombobox.h>
25 #include <qscrollview.h>
32 class QScrollViewSingle : public QScrollView {
34 QScrollViewSingle(QWidget * p)
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);
50 virtual void resizeEvent(QResizeEvent * e) {
51 QScrollView::resizeEvent(e);
55 w_->resize(viewport()->width(), w_->height());
56 // force the resize to get accurate scrollbars
57 qApp->processEvents();
58 resizeContents(w_->width(), w_->height());
66 char const ** panels[] = {
67 latex_bop, latex_varsz, latex_brel, latex_greek, latex_arrow,
68 latex_dots, latex_deco, latex_misc, latex_ams_ops,
69 latex_ams_rel, latex_ams_nrel, latex_ams_arrows,
72 int const nr_panels = sizeof(panels)/sizeof(panels[0]);
76 QMathDialog::QMathDialog(QMath * form)
77 : QMathDialogBase(0, 0, false, 0),
80 connect(symbolsCO, SIGNAL(activated(int)), symbolsWS, SLOT(raiseWidget(int)));
82 for (int i = 0; *function_names[i]; ++i) {
83 functionsLB->insertItem(function_names[i]);
86 for (int i = 0; i < nr_panels; ++i) {
89 symbolsWS->raiseWidget(0);
90 symbolsWS->resize(symbolsWS->sizeHint());
94 IconPalette * QMathDialog::makePanel(QWidget * parent, char const ** entries)
96 IconPalette * p = new IconPalette(parent);
97 for (int i = 0; *entries[i]; ++i) {
98 string xpm_name = LibFileSearch("images/math/", entries[i], "xpm");
99 p->add(QPixmap(xpm_name.c_str()), entries[i], string("\\") + entries[i]);
101 connect(p, SIGNAL(button_clicked(string)), this, SLOT(symbol_clicked(string)));
107 void QMathDialog::addPanel(char const ** entries)
111 QScrollViewSingle * view = new QScrollViewSingle(symbolsWS);
113 IconPalette * p = makePanel(view->viewport(), entries);
115 symbolsWS->addWidget(view, id++);
119 void QMathDialog::symbol_clicked(string str)
121 form_->insert_symbol(str);
125 void QMathDialog::fracClicked()
127 form_->insert_symbol("frac");
131 void QMathDialog::sqrtClicked()
133 form_->insert_symbol("sqrt");
137 void QMathDialog::delimiterClicked()
142 void QMathDialog::expandClicked()
144 int const id = symbolsWS->id(symbolsWS->visibleWidget());
145 IconPalette * p = makePanel(0, panels[id]);
147 s += symbolsCO->text(id).latin1();
148 p->setCaption(s.c_str());
149 p->resize(40 * 5, p->height());
151 p->setMaximumSize(p->width(), p->height());
155 void QMathDialog::functionSelected(const QString & str)
157 form_->insert_symbol(str.latin1());
161 void QMathDialog::matrixClicked()
166 void QMathDialog::spaceClicked()
171 void QMathDialog::styleClicked()
176 void QMathDialog::subscriptClicked()
182 void QMathDialog::superscriptClicked()
184 form_->superscript();