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>
22 #include <QPushButton>
26 #include <boost/assert.hpp>
28 using lyx::support::libFileSearch;
33 BulletsModule::BulletsModule(QWidget * parent, const char * name, Qt::WFlags fl)
38 for (int iter = 0; iter < 4; ++iter) {
39 bullets_[iter] = ITEMIZE_DEFAULTS[iter];
42 QMenu * pm = new QMenu(this);
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);
51 // FIXME: We need a Qt4 compatible browsebox type widget
52 // which can act as a popup to a toolbutton
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);
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_);
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);
79 connect(bullet1PB, SIGNAL(pressed()), this, SLOT(clicked1()));
80 bullet1PB->setPopup(pm);
82 connect(bullet2PB, SIGNAL(pressed()), this, SLOT(clicked2()));
83 bullet2PB->setPopup(pm);
85 connect(bullet3PB, SIGNAL(pressed()), this, SLOT(clicked3()));
86 bullet3PB->setPopup(pm);
88 connect(bullet4PB, SIGNAL(pressed()), this, SLOT(clicked4()));
89 bullet4PB->setPopup(pm);
93 bmfile = libFileSearch("images", "standard", "xpm");
94 standard_->insertItem(QPixmap(toqstr(bmfile)));
96 bmfile = libFileSearch("images", "amssymb", "xpm");
97 maths_->insertItem(QPixmap(toqstr(bmfile)));
99 bmfile = libFileSearch("images", "psnfss1", "xpm");
100 ding1_->insertItem(QPixmap(toqstr(bmfile)));
102 bmfile = libFileSearch("images", "psnfss2", "xpm");
103 ding2_->insertItem(QPixmap(toqstr(bmfile)));
105 bmfile = libFileSearch("images", "psnfss3", "xpm");
106 ding3_->insertItem(QPixmap(toqstr(bmfile)));
108 bmfile = libFileSearch("images", "psnfss4", "xpm");
109 ding4_->insertItem(QPixmap(toqstr(bmfile)));
111 connect(standard_, SIGNAL(selected(int, int)),
112 this, SLOT(standard(int, int)));
114 connect(maths_, SIGNAL(selected(int, int)),
115 this, SLOT(maths(int, int)));
117 connect(ding1_, SIGNAL(selected(int, int)),
118 this, SLOT(ding1(int, int)));
120 connect(ding2_, SIGNAL(selected(int, int)),
121 this, SLOT(ding2(int, int)));
123 connect(ding3_, SIGNAL(selected(int, int)),
124 this, SLOT(ding3(int, int)));
126 connect(ding4_, SIGNAL(selected(int, int)),
127 this, SLOT(ding4(int, int)));
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()));
139 for (int i = 0; i < 4; ++i)
140 setBullet(bullet1PB, bulletsize1CO, bullets_[i]);
145 BulletsModule::~BulletsModule()
150 void BulletsModule::updateSizes()
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);
162 // These arrive before the menus are launched.
163 void BulletsModule::clicked1()
165 bullet_pressed_ = &bullets_[0];
169 void BulletsModule::clicked2()
171 bullet_pressed_ = &bullets_[1];
175 void BulletsModule::clicked3()
177 bullet_pressed_ = &bullets_[2];
181 void BulletsModule::clicked4()
183 bullet_pressed_ = &bullets_[3];
187 // These arrive *after* the menus have done their work
188 void BulletsModule::selected1()
192 tmpbulletset = false;
193 bullets_[0] = tmpbullet;
194 setBullet(bullet1PB, bulletsize1CO, bullets_[0]);
199 void BulletsModule::selected2()
203 tmpbulletset = false;
204 bullets_[1] = tmpbullet;
205 setBullet(bullet2PB, bulletsize2CO, bullets_[1]);
210 void BulletsModule::selected3()
214 tmpbulletset = false;
215 bullets_[2] = tmpbullet;
216 setBullet(bullet3PB, bulletsize3CO, bullets_[2]);
221 void BulletsModule::selected4()
225 tmpbulletset = false;
226 bullets_[3] = tmpbullet;
227 setBullet(bullet4PB, bulletsize4CO, bullets_[3]);
232 QPixmap BulletsModule::getPixmap(int font, int character)
234 int col = character % 6;
235 int row = (character - col) / 6;
239 return standard_->pixmap(row,col);
241 return maths_->pixmap(row,col);
243 return ding1_->pixmap(row,col);
245 return ding2_->pixmap(row,col);
247 return ding3_->pixmap(row,col);
249 return ding4_->pixmap(row,col);
251 return standard_->pixmap(row,col);
253 // make qt4 frontend at least compilable now.
258 void BulletsModule::setBullet(QPushButton * pb, QComboBox * co, Bullet const & b)
260 if (b.getFont() == -1) {
261 pb->setPixmap(QPixmap());
262 pb->setText(toqstr(b.getText()));
264 pb->setPixmap(getPixmap(b.getFont(), b.getCharacter()));
267 pb->setMinimumSize(QSize(50, 50));
269 co->setCurrentItem(b.getSize() + 1);
273 void BulletsModule::setBullet(int level, const Bullet & bullet)
275 bullets_[level] = bullet;
276 // FIXME: backout until we fixed the browsebox
279 QPushButton * pb = 0;
283 case 0: pb = bullet1PB; co = bulletsize1CO; break;
284 case 1: pb = bullet2PB; co = bulletsize2CO; break;
285 case 2: pb = bullet3PB; co = bulletsize3CO; break;
286 case 3: pb = bullet4PB; co = bulletsize4CO; break;
287 default: BOOST_ASSERT(false); break;
290 setBullet(pb, co, bullet);
294 Bullet const & BulletsModule::getBullet(int level) const
296 return bullets_[level];
300 void BulletsModule::setCurrentBullet(int font, int character)
303 tmpbullet.setFont(font);
304 tmpbullet.setCharacter(character);
308 void BulletsModule::standard(int row, int col)
310 setCurrentBullet(0, 6 * row + col);
314 void BulletsModule::maths(int row, int col)
316 setCurrentBullet(1, 6 * row + col);
320 void BulletsModule::ding1(int row, int col)
322 setCurrentBullet(2, 6 * row + col);
326 void BulletsModule::ding2(int row, int col)
328 setCurrentBullet(3, 6 * row + col);
332 void BulletsModule::ding3(int row, int col)
334 setCurrentBullet(4, 6 * row + col);
338 void BulletsModule::ding4(int row, int col)
340 setCurrentBullet(5, 6 * row + col);
344 void BulletsModule::setCustom()
346 QString const input = bullet_pressed_ ?
347 toqstr(bullet_pressed_->getText()) : QString::null;
350 QString text = QInputDialog::getText(
352 qt_( "Enter a custom bullet" ),
360 tmpbullet.setText(fromqstr(text));
361 tmpbullet.setFont(-1);
364 #include "BulletsModule_moc.cpp"