]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/BulletsModule.C
Qt4 compilation speedup patch by Bo Peng and me.
[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 changed();
153
154         // -1 apparently means default...
155         bullets_[0].setSize(bulletsize1CO->currentItem() - 1);
156         bullets_[1].setSize(bulletsize2CO->currentItem() - 1);
157         bullets_[2].setSize(bulletsize3CO->currentItem() - 1);
158         bullets_[3].setSize(bulletsize4CO->currentItem() - 1);
159 }
160
161
162 // These arrive before the menus are launched.
163 void BulletsModule::clicked1()
164 {
165         bullet_pressed_ = &bullets_[0];
166 }
167
168
169 void BulletsModule::clicked2()
170 {
171         bullet_pressed_ = &bullets_[1];
172 }
173
174
175 void BulletsModule::clicked3()
176 {
177         bullet_pressed_ = &bullets_[2];
178 }
179
180
181 void BulletsModule::clicked4()
182 {
183         bullet_pressed_ = &bullets_[3];
184 }
185
186
187 // These arrive *after* the menus have done their work
188 void BulletsModule::selected1()
189 {
190         if (!tmpbulletset)
191                 return;
192         tmpbulletset = false;
193         bullets_[0] = tmpbullet;
194         setBullet(bullet1PB, bulletsize1CO, bullets_[0]);
195         emit changed();
196 }
197
198
199 void BulletsModule::selected2()
200 {
201         if (!tmpbulletset)
202                 return;
203         tmpbulletset = false;
204         bullets_[1] = tmpbullet;
205         setBullet(bullet2PB, bulletsize2CO, bullets_[1]);
206         emit changed();
207 }
208
209
210 void BulletsModule::selected3()
211 {
212         if (!tmpbulletset)
213                 return;
214         tmpbulletset = false;
215         bullets_[2] = tmpbullet;
216         setBullet(bullet3PB, bulletsize3CO, bullets_[2]);
217         emit changed();
218 }
219
220
221 void BulletsModule::selected4()
222 {
223         if (!tmpbulletset)
224                 return;
225         tmpbulletset = false;
226         bullets_[3] = tmpbullet;
227         setBullet(bullet4PB, bulletsize4CO, bullets_[3]);
228         emit changed();
229 }
230
231
232 QPixmap BulletsModule::getPixmap(int font, int character)
233 {
234         int col = character % 6;
235         int row = (character - col) / 6;
236
237 /*      switch (font) {
238         case 0:
239                 return standard_->pixmap(row,col);
240         case 1:
241                 return maths_->pixmap(row,col);
242         case 2:
243                 return ding1_->pixmap(row,col);
244         case 3:
245                 return ding2_->pixmap(row,col);
246         case 4:
247                 return ding3_->pixmap(row,col);
248         case 5:
249                 return ding4_->pixmap(row,col);
250         default:
251                 return standard_->pixmap(row,col);
252         }*/
253 }
254
255
256 void BulletsModule::setBullet(QPushButton * pb, QComboBox * co, Bullet const & b)
257 {
258         if (b.getFont() == -1) {
259                 pb->setPixmap(QPixmap());
260                 pb->setText(toqstr(b.getText()));
261         } else {
262                 pb->setPixmap(getPixmap(b.getFont(), b.getCharacter()));
263         }
264
265         pb->setMinimumSize(QSize(50, 50));
266
267         co->setCurrentItem(b.getSize() + 1);
268 }
269
270
271 void BulletsModule::setBullet(int level, const Bullet & bullet)
272 {
273         bullets_[level] = bullet;
274         // FIXME: backout until we fixed the browsebox
275         return;
276
277         QPushButton * pb = 0;
278         QComboBox * co = 0;
279
280         switch (level) {
281                 case 0: pb = bullet1PB; co = bulletsize1CO; break;
282                 case 1: pb = bullet2PB; co = bulletsize2CO; break;
283                 case 2: pb = bullet3PB; co = bulletsize3CO; break;
284                 case 3: pb = bullet4PB; co = bulletsize4CO; break;
285                 default: BOOST_ASSERT(false); break;
286         }
287
288         setBullet(pb, co, bullet);
289 }
290
291
292 Bullet const & BulletsModule::getBullet(int level) const
293 {
294         return bullets_[level];
295 }
296
297
298 void BulletsModule::setCurrentBullet(int font, int character)
299 {
300         tmpbulletset = true;
301         tmpbullet.setFont(font);
302         tmpbullet.setCharacter(character);
303 }
304
305
306 void BulletsModule::standard(int row, int col)
307 {
308         setCurrentBullet(0, 6 * row + col);
309 }
310
311
312 void BulletsModule::maths(int row, int col)
313 {
314         setCurrentBullet(1, 6 * row + col);
315 }
316
317
318 void BulletsModule::ding1(int row, int col)
319 {
320         setCurrentBullet(2, 6 * row + col);
321 }
322
323
324 void BulletsModule::ding2(int row, int col)
325 {
326         setCurrentBullet(3, 6 * row + col);
327 }
328
329
330 void BulletsModule::ding3(int row, int col)
331 {
332         setCurrentBullet(4, 6 * row + col);
333 }
334
335
336 void BulletsModule::ding4(int row, int col)
337 {
338         setCurrentBullet(5, 6 * row + col);
339 }
340
341
342 void BulletsModule::setCustom()
343 {
344         QString const input = bullet_pressed_ ?
345                 toqstr(bullet_pressed_->getText()) : QString::null;
346
347         bool ok = false;
348         QString text = QInputDialog::getText(
349                 qt_( "Bullets" ),
350                 qt_( "Enter a custom bullet" ),
351                 QLineEdit::Normal,
352                 input, &ok, this );
353
354         if (!ok)
355                 return;
356
357         tmpbulletset = true;
358         tmpbullet.setText(fromqstr(text));
359         tmpbullet.setFont(-1);
360 }
361
362 #include "BulletsModule_moc.cpp"