]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/BulletsModule.C
delete some emits that I missed, add comments about emitting signals
[lyx.git] / src / frontends / qt4 / BulletsModule.C
1 /**
2  * \file BulletsModule.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "BulletsModule.h"
15 // #include "QBrowseBox.h"
16 #include "qt_helpers.h"
17
18 #include "support/filetools.h"
19
20 #include <QInputDialog>
21 #include <QMenu>
22 #include <QPushButton>
23 #include <QComboBox>
24 #include <QPixmap>
25
26 #include <boost/assert.hpp>
27
28 using lyx::support::libFileSearch;
29
30 using std::string;
31
32
33 BulletsModule::BulletsModule(QWidget * parent,  const char * name, Qt::WFlags fl)
34         : bullet_pressed_(0)
35 {
36         setupUi(this);
37
38         for (int iter = 0; iter < 4; ++iter) {
39                 bullets_[iter] = ITEMIZE_DEFAULTS[iter];
40         }
41
42         QMenu * pm = new QMenu(this);
43
44         QMenu * pm1 = new QMenu(pm);
45         QMenu * pm2 = new QMenu(pm);
46         QMenu * pm3 = new QMenu(pm);
47         QMenu * pm4 = new QMenu(pm);
48         QMenu * pm5 = new QMenu(pm);
49         QMenu * pm6 = new QMenu(pm);
50
51 // FIXME: We need a Qt4 compatible browsebox type widget
52 // which can act as a popup to a toolbutton
53 /*
54         standard_ = new QBrowseBox(6, 6, pm1);
55         maths_ = new QBrowseBox(6, 6, pm2);
56         ding1_ = new QBrowseBox(6, 6, pm3);
57         ding2_ = new QBrowseBox(6, 6, pm4);
58         ding3_ = new QBrowseBox(6, 6, pm5);
59         ding4_ = new QBrowseBox(6, 6, pm6);
60
61         ///\todo See how to insert those BrowseBox:
62         pm1->addMenu((QMenu*) standard_);
63         pm2->addMenu((QMenu*)maths_);
64         pm3->addMenu((QMenu*)ding1_);
65         pm4->addMenu((QMenu*)ding2_);
66         pm5->addMenu((QMenu*)ding3_);
67         pm6->addMenu((QMenu*)ding4_);
68
69         pm->insertItem(qt_("&Standard"), pm1, 0);
70         pm->insertItem(qt_("&Maths"), pm2, 1);
71         pm->insertItem(qt_("Dings &1"), pm3, 2);
72         pm->insertItem(qt_("Dings &2"), pm4, 3);
73         pm->insertItem(qt_("Dings &3"), pm5, 4);
74         pm->insertItem(qt_("Dings &4"), pm6, 5);
75         pm->insertSeparator();
76         // FIXME: make this checkable
77         pm->insertItem(qt_("&Custom..."), this, SLOT(setCustom()), 0, 6);
78
79         connect(bullet1PB, SIGNAL(pressed()), this, SLOT(clicked1()));
80         bullet1PB->setPopup(pm);
81
82         connect(bullet2PB, SIGNAL(pressed()), this, SLOT(clicked2()));
83         bullet2PB->setPopup(pm);
84
85         connect(bullet3PB, SIGNAL(pressed()), this, SLOT(clicked3()));
86         bullet3PB->setPopup(pm);
87
88         connect(bullet4PB, SIGNAL(pressed()), this, SLOT(clicked4()));
89         bullet4PB->setPopup(pm);
90
91         // insert pixmaps
92         string bmfile;
93         bmfile = libFileSearch("images", "standard", "xpm");
94         standard_->insertItem(QPixmap(toqstr(bmfile)));
95
96         bmfile = libFileSearch("images", "amssymb", "xpm");
97         maths_->insertItem(QPixmap(toqstr(bmfile)));
98
99         bmfile = libFileSearch("images", "psnfss1", "xpm");
100         ding1_->insertItem(QPixmap(toqstr(bmfile)));
101
102         bmfile = libFileSearch("images", "psnfss2", "xpm");
103         ding2_->insertItem(QPixmap(toqstr(bmfile)));
104
105         bmfile = libFileSearch("images", "psnfss3", "xpm");
106         ding3_->insertItem(QPixmap(toqstr(bmfile)));
107
108         bmfile = libFileSearch("images", "psnfss4", "xpm");
109         ding4_->insertItem(QPixmap(toqstr(bmfile)));
110
111         connect(standard_, SIGNAL(selected(int, int)),
112                 this, SLOT(standard(int, int)));
113
114         connect(maths_, SIGNAL(selected(int, int)),
115                 this, SLOT(maths(int, int)));
116
117         connect(ding1_, SIGNAL(selected(int, int)),
118                 this, SLOT(ding1(int, int)));
119
120         connect(ding2_, SIGNAL(selected(int, int)),
121                 this, SLOT(ding2(int, int)));
122
123         connect(ding3_, SIGNAL(selected(int, int)),
124                 this, SLOT(ding3(int, int)));
125
126         connect(ding4_, SIGNAL(selected(int, int)),
127                 this, SLOT(ding4(int, int)));
128
129         connect(bullet1PB, SIGNAL(pressed()), this, SLOT(selected1()));
130         connect(bullet2PB, SIGNAL(pressed()), this, SLOT(selected2()));
131         connect(bullet3PB, SIGNAL(pressed()), this, SLOT(selected3()));
132         connect(bullet4PB, SIGNAL(pressed()), this, SLOT(selected4()));
133         connect(bulletsize1CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
134         connect(bulletsize2CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
135         connect(bulletsize3CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
136         connect(bulletsize4CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
137
138         // update the view
139         for (int i = 0; i < 4; ++i)
140                 setBullet(bullet1PB, bulletsize1CO, bullets_[i]);
141 */
142 }
143
144
145 BulletsModule::~BulletsModule()
146 {
147 }
148
149
150 void BulletsModule::updateSizes()
151 {
152         // emit signal
153         changed();
154
155         // -1 apparently means default...
156         bullets_[0].setSize(bulletsize1CO->currentItem() - 1);
157         bullets_[1].setSize(bulletsize2CO->currentItem() - 1);
158         bullets_[2].setSize(bulletsize3CO->currentItem() - 1);
159         bullets_[3].setSize(bulletsize4CO->currentItem() - 1);
160 }
161
162
163 // These arrive before the menus are launched.
164 void BulletsModule::clicked1()
165 {
166         bullet_pressed_ = &bullets_[0];
167 }
168
169
170 void BulletsModule::clicked2()
171 {
172         bullet_pressed_ = &bullets_[1];
173 }
174
175
176 void BulletsModule::clicked3()
177 {
178         bullet_pressed_ = &bullets_[2];
179 }
180
181
182 void BulletsModule::clicked4()
183 {
184         bullet_pressed_ = &bullets_[3];
185 }
186
187
188 // These arrive *after* the menus have done their work
189 void BulletsModule::selected1()
190 {
191         if (!tmpbulletset)
192                 return;
193         tmpbulletset = false;
194         bullets_[0] = tmpbullet;
195         setBullet(bullet1PB, bulletsize1CO, bullets_[0]);
196         // emit signal
197         changed();
198 }
199
200
201 void BulletsModule::selected2()
202 {
203         if (!tmpbulletset)
204                 return;
205         tmpbulletset = false;
206         bullets_[1] = tmpbullet;
207         setBullet(bullet2PB, bulletsize2CO, bullets_[1]);
208         // emit signal
209         changed();
210 }
211
212
213 void BulletsModule::selected3()
214 {
215         if (!tmpbulletset)
216                 return;
217         tmpbulletset = false;
218         bullets_[2] = tmpbullet;
219         setBullet(bullet3PB, bulletsize3CO, bullets_[2]);
220         // emit signal
221         changed();
222 }
223
224
225 void BulletsModule::selected4()
226 {
227         if (!tmpbulletset)
228                 return;
229         tmpbulletset = false;
230         bullets_[3] = tmpbullet;
231         setBullet(bullet4PB, bulletsize4CO, bullets_[3]);
232         // emit signal
233         changed();
234 }
235
236
237 QPixmap BulletsModule::getPixmap(int font, int character)
238 {
239         int col = character % 6;
240         int row = (character - col) / 6;
241
242 /*      switch (font) {
243         case 0:
244                 return standard_->pixmap(row,col);
245         case 1:
246                 return maths_->pixmap(row,col);
247         case 2:
248                 return ding1_->pixmap(row,col);
249         case 3:
250                 return ding2_->pixmap(row,col);
251         case 4:
252                 return ding3_->pixmap(row,col);
253         case 5:
254                 return ding4_->pixmap(row,col);
255         default:
256                 return standard_->pixmap(row,col);
257         }*/
258         // make qt4 frontend at least compilable now.
259         return QPixmap();
260 }
261
262
263 void BulletsModule::setBullet(QPushButton * pb, QComboBox * co, Bullet const & b)
264 {
265         if (b.getFont() == -1) {
266                 pb->setPixmap(QPixmap());
267                 pb->setText(toqstr(b.getText()));
268         } else {
269                 pb->setPixmap(getPixmap(b.getFont(), b.getCharacter()));
270         }
271
272         pb->setMinimumSize(QSize(50, 50));
273
274         co->setCurrentItem(b.getSize() + 1);
275 }
276
277
278 void BulletsModule::setBullet(int level, const Bullet & bullet)
279 {
280         bullets_[level] = bullet;
281         // FIXME: backout until we fixed the browsebox
282         return;
283
284         QPushButton * pb = 0;
285         QComboBox * co = 0;
286
287         switch (level) {
288                 case 0: pb = bullet1PB; co = bulletsize1CO; break;
289                 case 1: pb = bullet2PB; co = bulletsize2CO; break;
290                 case 2: pb = bullet3PB; co = bulletsize3CO; break;
291                 case 3: pb = bullet4PB; co = bulletsize4CO; break;
292                 default: BOOST_ASSERT(false); break;
293         }
294
295         setBullet(pb, co, bullet);
296 }
297
298
299 Bullet const & BulletsModule::getBullet(int level) const
300 {
301         return bullets_[level];
302 }
303
304
305 void BulletsModule::setCurrentBullet(int font, int character)
306 {
307         tmpbulletset = true;
308         tmpbullet.setFont(font);
309         tmpbullet.setCharacter(character);
310 }
311
312
313 void BulletsModule::standard(int row, int col)
314 {
315         setCurrentBullet(0, 6 * row + col);
316 }
317
318
319 void BulletsModule::maths(int row, int col)
320 {
321         setCurrentBullet(1, 6 * row + col);
322 }
323
324
325 void BulletsModule::ding1(int row, int col)
326 {
327         setCurrentBullet(2, 6 * row + col);
328 }
329
330
331 void BulletsModule::ding2(int row, int col)
332 {
333         setCurrentBullet(3, 6 * row + col);
334 }
335
336
337 void BulletsModule::ding3(int row, int col)
338 {
339         setCurrentBullet(4, 6 * row + col);
340 }
341
342
343 void BulletsModule::ding4(int row, int col)
344 {
345         setCurrentBullet(5, 6 * row + col);
346 }
347
348
349 void BulletsModule::setCustom()
350 {
351         QString const input = bullet_pressed_ ?
352                 toqstr(bullet_pressed_->getText()) : QString::null;
353
354         bool ok = false;
355         QString text = QInputDialog::getText(
356                 qt_( "Bullets" ),
357                 qt_( "Enter a custom bullet" ),
358                 QLineEdit::Normal,
359                 input, &ok, this );
360
361         if (!ok)
362                 return;
363
364         tmpbulletset = true;
365         tmpbullet.setText(fromqstr(text));
366         tmpbullet.setFont(-1);
367 }
368
369 #include "BulletsModule_moc.cpp"