]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QMathDialog.C
fix mathed scrollbars
[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 <qapplication.h>
21 #include <qwidgetstack.h>
22 #include <qcombobox.h>
23 #include <qlistbox.h>
24 #include <qpixmap.h>
25 #include <qscrollview.h>
26 #include <qlayout.h>
27  
28 using std::min;
29 using std::max;
30 using std::endl;
31  
32 class QScrollViewSingle : public QScrollView {
33 public:
34         QScrollViewSingle(QWidget * p)
35                 : QScrollView(p) {
36                 setResizePolicy(Manual);
37                 setHScrollBarMode(AlwaysOff);
38                 setVScrollBarMode(AlwaysOn);
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                 // force the resize to get accurate scrollbars
57                 qApp->processEvents();
58                 resizeContents(w_->width(), w_->height());
59         }
60
61 private:
62         QWidget * w_; 
63 };
64  
65 namespace { 
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,
70                 latex_ams_misc
71         };
72         int const nr_panels = sizeof(panels)/sizeof(panels[0]);
73 }
74  
75  
76 QMathDialog::QMathDialog(QMath * form)
77         : QMathDialogBase(0, 0, false, 0),
78         form_(form)
79 {
80         connect(symbolsCO, SIGNAL(activated(int)), symbolsWS, SLOT(raiseWidget(int))); 
81
82         for (int i = 0; *function_names[i]; ++i) {
83                 functionsLB->insertItem(function_names[i]);
84         }
85  
86         for (int i = 0; i < nr_panels; ++i) {
87                 addPanel(panels[i]);
88         }
89         symbolsWS->raiseWidget(0);
90         symbolsWS->resize(symbolsWS->sizeHint());
91 }
92
93  
94 IconPalette * QMathDialog::makePanel(QWidget * parent, char const ** entries)
95 {
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]);
100         }
101         connect(p, SIGNAL(button_clicked(string)), this, SLOT(symbol_clicked(string)));
102  
103         return p;
104 }
105
106  
107 void QMathDialog::addPanel(char const ** entries)
108 {
109         static int id = 0;
110  
111         QScrollViewSingle * view = new QScrollViewSingle(symbolsWS);
112  
113         IconPalette * p = makePanel(view->viewport(), entries);
114         view->setChild(p);
115         symbolsWS->addWidget(view, id++);
116 }
117
118  
119 void QMathDialog::symbol_clicked(string str)
120 {
121         form_->insert_symbol(str);
122 }
123
124  
125 void QMathDialog::fracClicked()
126 {
127         form_->insert_symbol("frac");
128 }
129  
130
131 void QMathDialog::sqrtClicked()
132 {
133         form_->insert_symbol("sqrt");
134 }
135
136  
137 void QMathDialog::delimiterClicked()
138 {
139 }
140
141  
142 void QMathDialog::expandClicked()
143 {
144         int const id = symbolsWS->id(symbolsWS->visibleWidget());
145         IconPalette * p = makePanel(0, panels[id]);
146         string s = "LyX: "; 
147         s += symbolsCO->text(id).latin1();
148         p->setCaption(s.c_str());
149         p->resize(40 * 5, p->height());
150         p->show();
151         p->setMaximumSize(p->width(), p->height());
152 }
153  
154  
155 void QMathDialog::functionSelected(const QString & str)
156 {
157         form_->insert_symbol(str.latin1()); 
158 }
159
160  
161 void QMathDialog::matrixClicked()
162 {
163 }
164
165  
166 void QMathDialog::spaceClicked()
167 {
168 }
169
170  
171 void QMathDialog::styleClicked()
172 {
173 }
174
175  
176 void QMathDialog::subscriptClicked()
177 {
178         form_->subscript();
179 }
180
181  
182 void QMathDialog::superscriptClicked()
183 {
184         form_->superscript();
185 }