2 * \file BulletsModule.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "BulletsModule.h"
15 #include "QBrowseBox.h"
16 #include "qt_helpers.h"
18 #include "support/filetools.h"
20 #include <qinputdialog.h>
21 #include <qpopupmenu.h>
22 #include <qpushbutton.h>
23 #include <qcombobox.h>
25 #include <boost/assert.hpp>
27 using lyx::support::libFileSearch;
32 BulletsModule::BulletsModule(QWidget * parent, const char * name, WFlags fl)
33 : BulletsModuleBase(parent, name, fl), tmpbulletset(0),
36 for (int iter = 0; iter < 4; ++iter) {
37 bullets_[iter] = ITEMIZE_DEFAULTS[iter];
40 QPopupMenu * pm = new QPopupMenu(this);
42 QPopupMenu * pm1 = new QPopupMenu(pm);
43 QPopupMenu * pm2 = new QPopupMenu(pm);
44 QPopupMenu * pm3 = new QPopupMenu(pm);
45 QPopupMenu * pm4 = new QPopupMenu(pm);
46 QPopupMenu * pm5 = new QPopupMenu(pm);
47 QPopupMenu * pm6 = new QPopupMenu(pm);
49 standard_ = new QBrowseBox(6, 6, pm1);
50 maths_ = new QBrowseBox(6, 6, pm2);
51 ding1_ = new QBrowseBox(6, 6, pm3);
52 ding2_ = new QBrowseBox(6, 6, pm4);
53 ding3_ = new QBrowseBox(6, 6, pm5);
54 ding4_ = new QBrowseBox(6, 6, pm6);
56 pm1->insertItem(standard_);
57 pm2->insertItem(maths_);
58 pm3->insertItem(ding1_);
59 pm4->insertItem(ding2_);
60 pm5->insertItem(ding3_);
61 pm6->insertItem(ding4_);
63 pm->insertItem(qt_("&Standard"), pm1, 0);
64 pm->insertItem(qt_("&Maths"), pm2, 1);
65 pm->insertItem(qt_("Dings &1"), pm3, 2);
66 pm->insertItem(qt_("Dings &2"), pm4, 3);
67 pm->insertItem(qt_("Dings &3"), pm5, 4);
68 pm->insertItem(qt_("Dings &4"), pm6, 5);
69 pm->insertSeparator();
70 // FIXME: make this checkable
71 pm->insertItem(qt_("&Custom..."), this, SLOT(setCustom()), 0, 6);
73 connect(bullet1PB, SIGNAL(pressed()), this, SLOT(clicked1()));
74 bullet1PB->setPopup(pm);
76 connect(bullet2PB, SIGNAL(pressed()), this, SLOT(clicked2()));
77 bullet2PB->setPopup(pm);
79 connect(bullet3PB, SIGNAL(pressed()), this, SLOT(clicked3()));
80 bullet3PB->setPopup(pm);
82 connect(bullet4PB, SIGNAL(pressed()), this, SLOT(clicked4()));
83 bullet4PB->setPopup(pm);
87 bmfile = libFileSearch("images", "standard", "xpm");
88 standard_->insertItem(QPixmap(toqstr(bmfile)));
90 bmfile = libFileSearch("images", "amssymb", "xpm");
91 maths_->insertItem(QPixmap(toqstr(bmfile)));
93 bmfile = libFileSearch("images", "psnfss1", "xpm");
94 ding1_->insertItem(QPixmap(toqstr(bmfile)));
96 bmfile = libFileSearch("images", "psnfss2", "xpm");
97 ding2_->insertItem(QPixmap(toqstr(bmfile)));
99 bmfile = libFileSearch("images", "psnfss3", "xpm");
100 ding3_->insertItem(QPixmap(toqstr(bmfile)));
102 bmfile = libFileSearch("images", "psnfss4", "xpm");
103 ding4_->insertItem(QPixmap(toqstr(bmfile)));
105 connect(standard_, SIGNAL(selected(int, int)),
106 this, SLOT(standard(int, int)));
108 connect(maths_, SIGNAL(selected(int, int)),
109 this, SLOT(maths(int, int)));
111 connect(ding1_, SIGNAL(selected(int, int)),
112 this, SLOT(ding1(int, int)));
114 connect(ding2_, SIGNAL(selected(int, int)),
115 this, SLOT(ding2(int, int)));
117 connect(ding3_, SIGNAL(selected(int, int)),
118 this, SLOT(ding3(int, int)));
120 connect(ding4_, SIGNAL(selected(int, int)),
121 this, SLOT(ding4(int, int)));
123 connect(bullet1PB, SIGNAL(pressed()), this, SLOT(selected1()));
124 connect(bullet2PB, SIGNAL(pressed()), this, SLOT(selected2()));
125 connect(bullet3PB, SIGNAL(pressed()), this, SLOT(selected3()));
126 connect(bullet4PB, SIGNAL(pressed()), this, SLOT(selected4()));
127 connect(bulletsize1CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
128 connect(bulletsize2CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
129 connect(bulletsize3CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
130 connect(bulletsize4CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
133 for (int i = 0; i < 4; ++i)
134 setBullet(bullet1PB, bulletsize1CO, bullets_[i]);
138 BulletsModule::~BulletsModule()
143 void BulletsModule::updateSizes()
148 // -1 apparently means default...
149 bullets_[0].setSize(bulletsize1CO->currentItem() - 1);
150 bullets_[1].setSize(bulletsize2CO->currentItem() - 1);
151 bullets_[2].setSize(bulletsize3CO->currentItem() - 1);
152 bullets_[3].setSize(bulletsize4CO->currentItem() - 1);
156 // These arrive before the menus are launched.
157 void BulletsModule::clicked1()
159 bullet_pressed_ = &bullets_[0];
163 void BulletsModule::clicked2()
165 bullet_pressed_ = &bullets_[1];
169 void BulletsModule::clicked3()
171 bullet_pressed_ = &bullets_[2];
175 void BulletsModule::clicked4()
177 bullet_pressed_ = &bullets_[3];
181 // These arrive *after* the menus have done their work
182 void BulletsModule::selected1()
186 tmpbulletset = false;
187 bullets_[0] = tmpbullet;
188 setBullet(bullet1PB, bulletsize1CO, bullets_[0]);
194 void BulletsModule::selected2()
198 tmpbulletset = false;
199 bullets_[1] = tmpbullet;
200 setBullet(bullet2PB, bulletsize2CO, bullets_[1]);
206 void BulletsModule::selected3()
210 tmpbulletset = false;
211 bullets_[2] = tmpbullet;
212 setBullet(bullet3PB, bulletsize3CO, bullets_[2]);
218 void BulletsModule::selected4()
222 tmpbulletset = false;
223 bullets_[3] = tmpbullet;
224 setBullet(bullet4PB, bulletsize4CO, bullets_[3]);
230 QPixmap BulletsModule::getPixmap(int font, int character)
232 int col = character % 6;
233 int row = (character - col) / 6;
237 return standard_->pixmap(row,col);
239 return maths_->pixmap(row,col);
241 return ding1_->pixmap(row,col);
243 return ding2_->pixmap(row,col);
245 return ding3_->pixmap(row,col);
247 return ding4_->pixmap(row,col);
249 return standard_->pixmap(row,col);
254 void BulletsModule::setBullet(QPushButton * pb, QComboBox * co, Bullet const & b)
256 if (b.getFont() == -1) {
257 pb->setPixmap(QPixmap());
258 pb->setText(toqstr(b.getText()));
260 pb->setPixmap(getPixmap(b.getFont(), b.getCharacter()));
263 pb->setMinimumSize(QSize(50, 50));
265 co->setCurrentItem(b.getSize() + 1);
269 void BulletsModule::setBullet(int level, const Bullet & bullet)
271 bullets_[level] = bullet;
273 QPushButton * pb = 0;
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;
284 setBullet(pb, co, bullet);
288 Bullet const & BulletsModule::getBullet(int level) const
290 return bullets_[level];
294 void BulletsModule::setCurrentBullet(int font, int character)
297 tmpbullet.setFont(font);
298 tmpbullet.setCharacter(character);
302 void BulletsModule::standard(int row, int col)
304 setCurrentBullet(0, 6 * row + col);
308 void BulletsModule::maths(int row, int col)
310 setCurrentBullet(1, 6 * row + col);
314 void BulletsModule::ding1(int row, int col)
316 setCurrentBullet(2, 6 * row + col);
320 void BulletsModule::ding2(int row, int col)
322 setCurrentBullet(3, 6 * row + col);
326 void BulletsModule::ding3(int row, int col)
328 setCurrentBullet(4, 6 * row + col);
332 void BulletsModule::ding4(int row, int col)
334 setCurrentBullet(5, 6 * row + col);
338 void BulletsModule::setCustom()
340 QString const input = bullet_pressed_ ?
341 toqstr(bullet_pressed_->getText()) : QString::null;
344 QString text = QInputDialog::getText(
346 qt_( "Enter a custom bullet" ),
354 tmpbullet.setText(fromqstr(text));
355 tmpbullet.setFont(-1);