]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QMathDialog.C
relayout on resize for the icon palette
[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  
65 QMathDialog::QMathDialog(QMath * form)
66         : QMathDialogBase(0, 0, false, 0),
67         form_(form)
68 {
69         connect(symbolsCO, SIGNAL(activated(int)), symbolsWS, SLOT(raiseWidget(int))); 
70
71         for (int i = 0; *function_names[i]; ++i) {
72                 functionsLB->insertItem(function_names[i]);
73         }
74  
75         addPanel("operators", latex_bop);
76         addPanel("bigoperators", latex_varsz);
77         addPanel("relations", latex_brel);
78         addPanel("greek", latex_greek);
79         addPanel("arrows", latex_arrow);
80         addPanel("dots", latex_dots);
81         addPanel("deco", latex_deco);
82         addPanel("misc", latex_misc);
83         addPanel("amsoperators", latex_ams_ops);
84         addPanel("amsrelations", latex_ams_rel);
85         addPanel("amsnegrelations", latex_ams_nrel);
86         addPanel("amsarrows", latex_ams_arrows);
87         addPanel("amsmisc", latex_ams_misc);
88         symbolsWS->raiseWidget(0);
89         symbolsWS->resize(symbolsWS->sizeHint());
90 }
91
92  
93 void QMathDialog::addPanel(string const & name, char const ** entries)
94 {
95         static int id = 0;
96  
97         QScrollViewSingle * view = new QScrollViewSingle(symbolsWS);
98         IconPalette * p = new IconPalette(view->viewport());
99  
100         for (int i = 0; *entries[i]; ++i) {
101                 string xpm_name = LibFileSearch("images/math/", entries[i], "xpm");
102                 p->add(QPixmap(xpm_name.c_str()), entries[i], string("\\") + entries[i]);
103         }
104         connect(p, SIGNAL(button_clicked(string)), this, SLOT(symbol_clicked(string)));
105  
106         view->setChild(p);
107         symbolsWS->addWidget(view, id++);
108 }
109
110  
111 void QMathDialog::symbol_clicked(string str)
112 {
113         form_->insert_symbol(str);
114 }
115
116  
117 void QMathDialog::fracClicked()
118 {
119         form_->insert_symbol("frac");
120 }
121  
122
123 void QMathDialog::sqrtClicked()
124 {
125         form_->insert_symbol("sqrt");
126 }
127
128  
129 void QMathDialog::delimiterClicked()
130 {
131 }
132
133  
134 void QMathDialog::expandClicked()
135 {
136 }
137
138  
139  
140 void QMathDialog::functionSelected(const QString & str)
141 {
142         form_->insert_symbol(str.latin1()); 
143 }
144
145  
146 void QMathDialog::matrixClicked()
147 {
148 }
149
150  
151 void QMathDialog::spaceClicked()
152 {
153 }
154
155  
156 void QMathDialog::styleClicked()
157 {
158 }
159
160  
161 void QMathDialog::subscriptClicked()
162 {
163         form_->subscript();
164 }
165
166  
167 void QMathDialog::superscriptClicked()
168 {
169         form_->superscript();
170 }