]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/BulletsModule.C
Get rid of the static_casts.
[lyx.git] / src / frontends / qt2 / 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 #include "qt_helpers.h"
14
15 #include "support/filetools.h"
16 #include "support/LAssert.h"
17 #include "debug.h"
18
19 #include "Bullet.h"
20 #include "ui/BulletsModuleBase.h"
21 #include "QBrowseBox.h"
22 #include "BulletsModule.h"
23
24 #include <qinputdialog.h>
25 #include <qpopupmenu.h>
26 #include <qpixmap.h>
27 #include <qpushbutton.h>
28 #include <qcombobox.h>
29
30 BulletsModule::BulletsModule(QWidget * parent,  char const * name, WFlags fl)
31         : BulletsModuleBase(parent, name, fl), tmpbulletset(0)
32 {
33         for (int iter = 0; iter < 4; ++iter) {
34                 bullets_[iter] = ITEMIZE_DEFAULTS[iter];
35         }
36
37         QPopupMenu * pm = new QPopupMenu(this);
38
39         QPopupMenu * pm1 = new QPopupMenu(pm);
40         QPopupMenu * pm2 = new QPopupMenu(pm);
41         QPopupMenu * pm3 = new QPopupMenu(pm);
42         QPopupMenu * pm4 = new QPopupMenu(pm);
43         QPopupMenu * pm5 = new QPopupMenu(pm);
44         QPopupMenu * pm6 = new QPopupMenu(pm);
45
46         standard_ = new QBrowseBox(6, 6, pm1);
47         maths_ = new QBrowseBox(6, 6, pm2);
48         ding1_ = new QBrowseBox(6, 6, pm3);
49         ding2_ = new QBrowseBox(6, 6, pm4);
50         ding3_ = new QBrowseBox(6, 6, pm5);
51         ding4_ = new QBrowseBox(6, 6, pm6);
52
53         pm1->insertItem(standard_);
54         pm2->insertItem(maths_);
55         pm3->insertItem(ding1_);
56         pm4->insertItem(ding2_);
57         pm5->insertItem(ding3_);
58         pm6->insertItem(ding4_);
59
60         pm->insertItem(qt_("&Standard"), pm1, 0);
61         pm->insertItem(qt_("&Maths"), pm2, 1);
62         pm->insertItem(qt_("Dings &1"), pm3, 2);
63         pm->insertItem(qt_("Dings &2"), pm4, 3);
64         pm->insertItem(qt_("Dings &3"), pm5, 4);
65         pm->insertItem(qt_("Dings &4"), pm6, 5);
66         pm->insertSeparator();
67         // FIXME: make this checkable
68         pm->insertItem(qt_("&Custom..."), this, SLOT(setCustom()), 0, 6);
69
70         bullet1PB->setPopup(pm);
71         bullet2PB->setPopup(pm);
72         bullet3PB->setPopup(pm);
73         bullet4PB->setPopup(pm);
74
75         // insert pixmaps
76         string bmfile;
77         bmfile = LibFileSearch("images", "standard", "xpm");
78         standard_->insertItem(QPixmap(toqstr(bmfile)));
79
80         bmfile = LibFileSearch("images", "amssymb", "xpm");
81         maths_->insertItem(QPixmap(toqstr(bmfile)));
82
83         bmfile = LibFileSearch("images", "psnfss1", "xpm");
84         ding1_->insertItem(QPixmap(toqstr(bmfile)));
85
86         bmfile = LibFileSearch("images", "psnfss2", "xpm");
87         ding2_->insertItem(QPixmap(toqstr(bmfile)));
88
89         bmfile = LibFileSearch("images", "psnfss3", "xpm");
90         ding3_->insertItem(QPixmap(toqstr(bmfile)));
91
92         bmfile = LibFileSearch("images", "psnfss4", "xpm");
93         ding4_->insertItem(QPixmap(toqstr(bmfile)));
94
95         connect(standard_, SIGNAL(selected(int, int)),
96                 this, SLOT(standard(int, int)));
97
98         connect(maths_, SIGNAL(selected(int, int)),
99                 this, SLOT(maths(int, int)));
100
101         connect(ding1_, SIGNAL(selected(int, int)),
102                 this, SLOT(ding1(int, int)));
103
104         connect(ding2_, SIGNAL(selected(int, int)),
105                 this, SLOT(ding2(int, int)));
106
107         connect(ding3_, SIGNAL(selected(int, int)),
108                 this, SLOT(ding3(int, int)));
109
110         connect(ding4_, SIGNAL(selected(int, int)),
111                 this, SLOT(ding4(int, int)));
112
113         connect(bullet1PB, SIGNAL(pressed()), this, SLOT(pressed1()));
114         connect(bullet2PB, SIGNAL(pressed()), this, SLOT(pressed2()));
115         connect(bullet3PB, SIGNAL(pressed()), this, SLOT(pressed3()));
116         connect(bullet4PB, SIGNAL(pressed()), this, SLOT(pressed4()));
117         connect(bulletsize1CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
118         connect(bulletsize2CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
119         connect(bulletsize3CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
120         connect(bulletsize4CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
121
122         // update the view
123         for (int i = 0; i < 4; ++i)
124                 setBullet(bullet1PB, bulletsize1CO, bullets_[i]);
125 }
126
127
128 BulletsModule::~BulletsModule()
129 {
130 }
131
132
133 void BulletsModule::updateSizes()
134 {
135         emit changed();
136
137         // -1 apparently means default...
138         bullets_[0].setSize(bulletsize1CO->currentItem() - 1);
139         bullets_[1].setSize(bulletsize2CO->currentItem() - 1);
140         bullets_[2].setSize(bulletsize3CO->currentItem() - 1);
141         bullets_[3].setSize(bulletsize4CO->currentItem() - 1);
142 }
143
144
145 // These arrive *after* the menus have done their work
146 void BulletsModule::pressed1()
147 {
148         if (!tmpbulletset)
149                 return;
150         tmpbulletset = false;
151         bullets_[0] = tmpbullet;
152         setBullet(bullet1PB, bulletsize1CO, bullets_[0]);
153         emit changed();
154 }
155
156
157 void BulletsModule::pressed2()
158 {
159         if (!tmpbulletset)
160                 return;
161         tmpbulletset = false;
162         bullets_[1] = tmpbullet;
163         setBullet(bullet2PB, bulletsize2CO, bullets_[1]);
164         emit changed();
165 }
166
167
168 void BulletsModule::pressed3()
169 {
170         if (!tmpbulletset)
171                 return;
172         tmpbulletset = false;
173         bullets_[2] = tmpbullet;
174         setBullet(bullet3PB, bulletsize3CO, bullets_[2]);
175         emit changed();
176 }
177
178
179 void BulletsModule::pressed4()
180 {
181         if (!tmpbulletset)
182                 return;
183         tmpbulletset = false;
184         bullets_[3] = tmpbullet;
185         setBullet(bullet4PB, bulletsize4CO, bullets_[3]);
186         emit changed();
187 }
188
189
190 QPixmap BulletsModule::getPixmap(int font, int character)
191 {
192         int col = character % 6;
193         int row = (character - col) / 6;
194
195         switch (font) {
196         case 0:
197                 return standard_->pixmap(row,col);
198         case 1:
199                 return maths_->pixmap(row,col);
200         case 2:
201                 return ding1_->pixmap(row,col);
202         case 3:
203                 return ding2_->pixmap(row,col);
204         case 4:
205                 return ding3_->pixmap(row,col);
206         case 5:
207                 return ding4_->pixmap(row,col);
208         default:
209                 return standard_->pixmap(row,col);
210         }
211 }
212
213
214 void BulletsModule::setBullet(QPushButton * pb, QComboBox * co, Bullet const & b)
215 {
216         if (b.getFont() == -1) {
217                 pb->setPixmap(QPixmap());
218                 pb->setText("...");
219         } else {
220                 pb->setPixmap(getPixmap(b.getFont(), b.getCharacter()));
221         }
222
223         pb->setMinimumSize(QSize(50, 50));
224
225         co->setCurrentItem(b.getSize() + 1);
226 }
227
228
229 void BulletsModule::setBullet(int level, const Bullet & bullet)
230 {
231         bullets_[level] = bullet;
232
233         QPushButton * pb;
234         QComboBox * co;
235
236         switch (level) {
237                 case 0: pb = bullet1PB; co = bulletsize1CO; break;
238                 case 1: pb = bullet2PB; co = bulletsize2CO; break;
239                 case 2: pb = bullet3PB; co = bulletsize3CO; break;
240                 case 3: pb = bullet4PB; co = bulletsize4CO; break;
241                 default: lyx::Assert(false); break;
242         }
243
244         setBullet(pb, co, bullet);
245 }
246
247
248 Bullet const BulletsModule::getBullet(int level)
249 {
250         return bullets_[level];
251 }
252
253
254 void BulletsModule::setCurrentBullet(int font, int character)
255 {
256         tmpbulletset = true;
257         tmpbullet.setFont(font);
258         tmpbullet.setCharacter(character);
259 }
260
261
262 void BulletsModule::standard(int row, int col)
263 {
264         setCurrentBullet(0, 6 * row + col);
265 }
266
267
268 void BulletsModule::maths(int row, int col)
269 {
270         setCurrentBullet(1, 6 * row + col);
271 }
272
273
274 void BulletsModule::ding1(int row, int col)
275 {
276         setCurrentBullet(2, 6 * row + col);
277 }
278
279
280 void BulletsModule::ding2(int row, int col)
281 {
282         setCurrentBullet(3, 6 * row + col);
283 }
284
285
286 void BulletsModule::ding3(int row, int col)
287 {
288         setCurrentBullet(4, 6 * row + col);
289 }
290
291
292 void BulletsModule::ding4(int row, int col)
293 {
294         setCurrentBullet(5, 6 * row + col);
295 }
296
297
298 void BulletsModule::setCustom()
299 {
300         bool ok = FALSE;
301         QString text = QInputDialog::getText(
302                 qt_( "Bullets" ),
303                 qt_( "Enter a custom bullet" ),
304                 QLineEdit::Normal,
305                 QString::null, &ok, this );
306
307         if (!ok)
308                 return;
309
310         tmpbulletset = true;
311         tmpbullet.setText(fromqstr(text));
312         tmpbullet.setFont(-1);
313 }