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