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"
20 #include "support/filetools.h"
22 #include <qinputdialog.h>
24 #include <qpushbutton.h>
27 #include <boost/assert.hpp>
29 using lyx::support::LibFileSearch;
34 BulletsModule::BulletsModule(QWidget * parent, const char * name, Qt::WFlags fl)
39 for (int iter = 0; iter < 4; ++iter) {
40 bullets_[iter] = ITEMIZE_DEFAULTS[iter];
43 QMenu * pm = new QMenu(this);
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);
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);
59 ///\todo See how to insert those BrowseBox:
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_);
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);
78 connect(bullet1PB, SIGNAL(pressed()), this, SLOT(clicked1()));
79 bullet1PB->setPopup(pm);
81 connect(bullet2PB, SIGNAL(pressed()), this, SLOT(clicked2()));
82 bullet2PB->setPopup(pm);
84 connect(bullet3PB, SIGNAL(pressed()), this, SLOT(clicked3()));
85 bullet3PB->setPopup(pm);
87 connect(bullet4PB, SIGNAL(pressed()), this, SLOT(clicked4()));
88 bullet4PB->setPopup(pm);
92 bmfile = LibFileSearch("images", "standard", "xpm");
93 standard_->insertItem(QPixmap(toqstr(bmfile)));
95 bmfile = LibFileSearch("images", "amssymb", "xpm");
96 maths_->insertItem(QPixmap(toqstr(bmfile)));
98 bmfile = LibFileSearch("images", "psnfss1", "xpm");
99 ding1_->insertItem(QPixmap(toqstr(bmfile)));
101 bmfile = LibFileSearch("images", "psnfss2", "xpm");
102 ding2_->insertItem(QPixmap(toqstr(bmfile)));
104 bmfile = LibFileSearch("images", "psnfss3", "xpm");
105 ding3_->insertItem(QPixmap(toqstr(bmfile)));
107 bmfile = LibFileSearch("images", "psnfss4", "xpm");
108 ding4_->insertItem(QPixmap(toqstr(bmfile)));
110 connect(standard_, SIGNAL(selected(int, int)),
111 this, SLOT(standard(int, int)));
113 connect(maths_, SIGNAL(selected(int, int)),
114 this, SLOT(maths(int, int)));
116 connect(ding1_, SIGNAL(selected(int, int)),
117 this, SLOT(ding1(int, int)));
119 connect(ding2_, SIGNAL(selected(int, int)),
120 this, SLOT(ding2(int, int)));
122 connect(ding3_, SIGNAL(selected(int, int)),
123 this, SLOT(ding3(int, int)));
125 connect(ding4_, SIGNAL(selected(int, int)),
126 this, SLOT(ding4(int, int)));
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()));
138 for (int i = 0; i < 4; ++i)
139 setBullet(bullet1PB, bulletsize1CO, bullets_[i]);
143 BulletsModule::~BulletsModule()
148 void BulletsModule::updateSizes()
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);
160 // These arrive before the menus are launched.
161 void BulletsModule::clicked1()
163 bullet_pressed_ = &bullets_[0];
167 void BulletsModule::clicked2()
169 bullet_pressed_ = &bullets_[1];
173 void BulletsModule::clicked3()
175 bullet_pressed_ = &bullets_[2];
179 void BulletsModule::clicked4()
181 bullet_pressed_ = &bullets_[3];
185 // These arrive *after* the menus have done their work
186 void BulletsModule::selected1()
190 tmpbulletset = false;
191 bullets_[0] = tmpbullet;
192 setBullet(bullet1PB, bulletsize1CO, bullets_[0]);
197 void BulletsModule::selected2()
201 tmpbulletset = false;
202 bullets_[1] = tmpbullet;
203 setBullet(bullet2PB, bulletsize2CO, bullets_[1]);
208 void BulletsModule::selected3()
212 tmpbulletset = false;
213 bullets_[2] = tmpbullet;
214 setBullet(bullet3PB, bulletsize3CO, bullets_[2]);
219 void BulletsModule::selected4()
223 tmpbulletset = false;
224 bullets_[3] = tmpbullet;
225 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);