]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QMathDialog.C
first cut of detachable icon menus. Buggy.
[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                 setBackgroundMode(PaletteBackground);
40                 viewport()->setBackgroundMode(PaletteBackground);
41         }
42  
43         void setChild(QWidget * w) {
44                 w_ = w; 
45                 setMinimumWidth(verticalScrollBar()->width() + w_->width() + 4);
46                 addChild(w_);
47         }
48
49 protected:
50         virtual void resizeEvent(QResizeEvent * e) {
51                 QScrollView::resizeEvent(e);
52                 if (!w_)
53                         return;
54  
55                 w_->resize(viewport()->width(), w_->height());
56                 resizeContents(w_->width(), w_->height());
57                 setMinimumHeight(200);
58         }
59
60 private:
61         QWidget * w_; 
62 };
63  
64 namespace { 
65         char const ** panels[] = {
66                 latex_bop, latex_varsz, latex_brel, latex_greek, latex_arrow,
67                 latex_dots, latex_deco, latex_misc, latex_ams_ops,
68                 latex_ams_rel, latex_ams_nrel, latex_ams_arrows,
69                 latex_ams_misc
70         };
71         int const nr_panels = sizeof(panels)/sizeof(panels[0]);
72 }
73  
74  
75 QMathDialog::QMathDialog(QMath * form)
76         : QMathDialogBase(0, 0, false, 0),
77         form_(form)
78 {
79         connect(symbolsCO, SIGNAL(activated(int)), symbolsWS, SLOT(raiseWidget(int))); 
80
81         for (int i = 0; *function_names[i]; ++i) {
82                 functionsLB->insertItem(function_names[i]);
83         }
84  
85         for (int i = 0; i < nr_panels; ++i) {
86                 addPanel(panels[i]);
87         }
88         symbolsWS->raiseWidget(0);
89         symbolsWS->resize(symbolsWS->sizeHint());
90 }
91
92  
93 IconPalette * QMathDialog::makePanel(QWidget * parent, char const ** entries)
94 {
95         IconPalette * p = new IconPalette(parent);
96         for (int i = 0; *entries[i]; ++i) {
97                 string xpm_name = LibFileSearch("images/math/", entries[i], "xpm");
98                 p->add(QPixmap(xpm_name.c_str()), entries[i], string("\\") + entries[i]);
99         }
100         connect(p, SIGNAL(button_clicked(string)), this, SLOT(symbol_clicked(string)));
101         return p;
102 }
103
104  
105 void QMathDialog::addPanel(char const ** entries)
106 {
107         static int id = 0;
108  
109         QScrollViewSingle * view = new QScrollViewSingle(symbolsWS);
110         IconPalette * p = makePanel(view->viewport(), entries);
111         view->setChild(p);
112         symbolsWS->addWidget(view, id++);
113 }
114
115  
116 void QMathDialog::symbol_clicked(string str)
117 {
118         form_->insert_symbol(str);
119 }
120
121  
122 void QMathDialog::fracClicked()
123 {
124         form_->insert_symbol("frac");
125 }
126  
127
128 void QMathDialog::sqrtClicked()
129 {
130         form_->insert_symbol("sqrt");
131 }
132
133  
134 void QMathDialog::delimiterClicked()
135 {
136 }
137
138  
139 void QMathDialog::expandClicked()
140 {
141         int const id = symbolsWS->id(symbolsWS->visibleWidget());
142         IconPalette * p = makePanel(0, panels[id]);
143         p->show();
144 }
145  
146  
147 void QMathDialog::functionSelected(const QString & str)
148 {
149         form_->insert_symbol(str.latin1()); 
150 }
151
152  
153 void QMathDialog::matrixClicked()
154 {
155 }
156
157  
158 void QMathDialog::spaceClicked()
159 {
160 }
161
162  
163 void QMathDialog::styleClicked()
164 {
165 }
166
167  
168 void QMathDialog::subscriptClicked()
169 {
170         form_->subscript();
171 }
172
173  
174 void QMathDialog::superscriptClicked()
175 {
176         form_->superscript();
177 }