]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QMathDialog.C
More fixes to math dialog
[lyx.git] / src / frontends / qt2 / QMathDialog.C
1 /**
2  * \file QMathDialog.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author John Levon <moz@compsoc.man.ac.uk>
7  */
8
9 #include <config.h>
10
11 #include "support/filetools.h"
12 #include "debug.h"
13  
14 #include "QMathDialog.h"
15 #include "QMath.h"
16
17 #include "ControlMath.h"
18 #include "iconpalette.h"
19  
20 #include <qwidgetstack.h>
21 #include <qcombobox.h>
22 #include <qlistbox.h>
23 #include <qpixmap.h>
24 #include <qscrollview.h>
25 #include <qlayout.h>
26  
27 using std::min;
28 using std::max;
29 using std::endl;
30  
31 class QScrollViewSingle : public QScrollView {
32 public:
33         QScrollViewSingle(QWidget * p)
34                 : QScrollView(p) {
35                 setResizePolicy(Manual);
36                 setHScrollBarMode(AlwaysOff);
37                 setVScrollBarMode(AlwaysOn);
38                 setMinimumHeight(200);
39         }
40  
41         void setChild(QWidget * w) {
42                 w_ = w; 
43                 setMinimumWidth(verticalScrollBar()->width() + w_->width() + 4);
44                 addChild(w_);
45         }
46
47 protected:
48         virtual void resizeEvent(QResizeEvent * e) {
49                 QScrollView::resizeEvent(e);
50                 if (!w_)
51                         return;
52  
53                 int h = max(w_->sizeHint().height(), e->size().height());
54                 w_->resize(viewport()->width(), h);
55                 resizeContents(w_->width(), w_->height());
56                 setMinimumHeight(200);
57         }
58
59 private:
60         QWidget * w_; 
61 };
62  
63  
64 QMathDialog::QMathDialog(QMath * form)
65         : QMathDialogBase(0, 0, false, 0),
66         form_(form)
67 {
68         connect(symbolsCO, SIGNAL(activated(int)), symbolsWS, SLOT(raiseWidget(int))); 
69
70         for (int i = 0; *function_names[i]; ++i) {
71                 functionsLB->insertItem(function_names[i]);
72         }
73  
74         addPanel("operators", latex_bop);
75         addPanel("bigoperators", latex_varsz);
76         addPanel("relations", latex_brel);
77         addPanel("greek", latex_greek);
78         addPanel("arrows", latex_arrow);
79         addPanel("dots", latex_dots);
80         addPanel("deco", latex_deco);
81         addPanel("misc", latex_misc);
82         addPanel("amsoperators", latex_ams_ops);
83         addPanel("amsrelations", latex_ams_rel);
84         addPanel("amsnegrelations", latex_ams_nrel);
85         addPanel("amsarrows", latex_ams_arrows);
86         addPanel("amsmisc", latex_ams_misc);
87         symbolsWS->raiseWidget(0);
88         symbolsWS->resize(symbolsWS->sizeHint());
89 }
90
91  
92 void QMathDialog::addPanel(string const & name, char const ** entries)
93 {
94         static int id = 0;
95  
96         QScrollViewSingle * view = new QScrollViewSingle(symbolsWS);
97         IconPalette * p = new IconPalette(view->viewport());
98  
99         for (int i = 0; *entries[i]; ++i) {
100                 string xpm_name = LibFileSearch("images/math/", entries[i], "xpm");
101                 p->add(QPixmap(xpm_name.c_str()), entries[i], string("\\") + entries[i]);
102         }
103         connect(p, SIGNAL(button_clicked(string)), this, SLOT(symbol_clicked(string)));
104  
105         view->setChild(p);
106         symbolsWS->addWidget(view, id++);
107 }
108
109  
110 void QMathDialog::symbol_clicked(string str)
111 {
112         form_->insert_symbol(str);
113 }
114
115  
116 void QMathDialog::fracClicked()
117 {
118         form_->insert_symbol("frac");
119 }
120  
121
122 void QMathDialog::sqrtClicked()
123 {
124         form_->insert_symbol("sqrt");
125 }
126
127  
128 void QMathDialog::delimiterClicked()
129 {
130 }
131
132  
133 void QMathDialog::expandClicked()
134 {
135 }
136
137  
138  
139 void QMathDialog::functionSelected(const QString & str)
140 {
141         form_->insert_symbol(str.latin1()); 
142 }
143
144  
145 void QMathDialog::matrixClicked()
146 {
147 }
148
149  
150 void QMathDialog::spaceClicked()
151 {
152 }
153
154  
155 void QMathDialog::styleClicked()
156 {
157 }
158
159  
160 void QMathDialog::subscriptClicked()
161 {
162         form_->subscript();
163 }
164
165  
166 void QMathDialog::superscriptClicked()
167 {
168         form_->superscript();
169 }