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