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*/,
34 char const * /*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 // FIXME: Need to verify that this does not leak memory.
46 /*QMenu * pm1 =*/ new QMenu(pm);
47 /*QMenu * pm2 =*/ new QMenu(pm);
48 /*QMenu * pm3 =*/ new QMenu(pm);
49 /*QMenu * pm4 =*/ new QMenu(pm);
50 /*QMenu * pm5 =*/ new QMenu(pm);
51 /*QMenu * pm6 =*/ new QMenu(pm);
53 // FIXME: We need a Qt4 compatible browsebox type widget
54 // which can act as a popup to a toolbutton
56 standard_ = new QBrowseBox(6, 6, pm1);
57 maths_ = new QBrowseBox(6, 6, pm2);
58 ding1_ = new QBrowseBox(6, 6, pm3);
59 ding2_ = new QBrowseBox(6, 6, pm4);
60 ding3_ = new QBrowseBox(6, 6, pm5);
61 ding4_ = new QBrowseBox(6, 6, pm6);
63 ///\todo See how to insert those BrowseBox:
64 pm1->addMenu((QMenu*) standard_);
65 pm2->addMenu((QMenu*)maths_);
66 pm3->addMenu((QMenu*)ding1_);
67 pm4->addMenu((QMenu*)ding2_);
68 pm5->addMenu((QMenu*)ding3_);
69 pm6->addMenu((QMenu*)ding4_);
71 pm->insertItem(qt_("&Standard"), pm1, 0);
72 pm->insertItem(qt_("&Maths"), pm2, 1);
73 pm->insertItem(qt_("Dings &1"), pm3, 2);
74 pm->insertItem(qt_("Dings &2"), pm4, 3);
75 pm->insertItem(qt_("Dings &3"), pm5, 4);
76 pm->insertItem(qt_("Dings &4"), pm6, 5);
77 pm->insertSeparator();
78 // FIXME: make this checkable
79 pm->insertItem(qt_("&Custom..."), this, SLOT(setCustom()), 0, 6);
81 connect(bullet1PB, SIGNAL(pressed()), this, SLOT(clicked1()));
82 bullet1PB->setPopup(pm);
84 connect(bullet2PB, SIGNAL(pressed()), this, SLOT(clicked2()));
85 bullet2PB->setPopup(pm);
87 connect(bullet3PB, SIGNAL(pressed()), this, SLOT(clicked3()));
88 bullet3PB->setPopup(pm);
90 connect(bullet4PB, SIGNAL(pressed()), this, SLOT(clicked4()));
91 bullet4PB->setPopup(pm);
95 bmfile = libFileSearch("images", "standard", "xpm");
96 standard_->insertItem(QPixmap(toqstr(bmfile)));
98 bmfile = libFileSearch("images", "amssymb", "xpm");
99 maths_->insertItem(QPixmap(toqstr(bmfile)));
101 bmfile = libFileSearch("images", "psnfss1", "xpm");
102 ding1_->insertItem(QPixmap(toqstr(bmfile)));
104 bmfile = libFileSearch("images", "psnfss2", "xpm");
105 ding2_->insertItem(QPixmap(toqstr(bmfile)));
107 bmfile = libFileSearch("images", "psnfss3", "xpm");
108 ding3_->insertItem(QPixmap(toqstr(bmfile)));
110 bmfile = libFileSearch("images", "psnfss4", "xpm");
111 ding4_->insertItem(QPixmap(toqstr(bmfile)));
113 connect(standard_, SIGNAL(selected(int, int)),
114 this, SLOT(standard(int, int)));
116 connect(maths_, SIGNAL(selected(int, int)),
117 this, SLOT(maths(int, int)));
119 connect(ding1_, SIGNAL(selected(int, int)),
120 this, SLOT(ding1(int, int)));
122 connect(ding2_, SIGNAL(selected(int, int)),
123 this, SLOT(ding2(int, int)));
125 connect(ding3_, SIGNAL(selected(int, int)),
126 this, SLOT(ding3(int, int)));
128 connect(ding4_, SIGNAL(selected(int, int)),
129 this, SLOT(ding4(int, int)));
131 connect(bullet1PB, SIGNAL(pressed()), this, SLOT(selected1()));
132 connect(bullet2PB, SIGNAL(pressed()), this, SLOT(selected2()));
133 connect(bullet3PB, SIGNAL(pressed()), this, SLOT(selected3()));
134 connect(bullet4PB, SIGNAL(pressed()), this, SLOT(selected4()));
135 connect(bulletsize1CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
136 connect(bulletsize2CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
137 connect(bulletsize3CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
138 connect(bulletsize4CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
141 for (int i = 0; i < 4; ++i)
142 setBullet(bullet1PB, bulletsize1CO, bullets_[i]);
147 BulletsModule::~BulletsModule()
152 void BulletsModule::updateSizes()
157 // -1 apparently means default...
158 bullets_[0].setSize(bulletsize1CO->currentItem() - 1);
159 bullets_[1].setSize(bulletsize2CO->currentItem() - 1);
160 bullets_[2].setSize(bulletsize3CO->currentItem() - 1);
161 bullets_[3].setSize(bulletsize4CO->currentItem() - 1);
165 // These arrive before the menus are launched.
166 void BulletsModule::clicked1()
168 bullet_pressed_ = &bullets_[0];
172 void BulletsModule::clicked2()
174 bullet_pressed_ = &bullets_[1];
178 void BulletsModule::clicked3()
180 bullet_pressed_ = &bullets_[2];
184 void BulletsModule::clicked4()
186 bullet_pressed_ = &bullets_[3];
190 // These arrive *after* the menus have done their work
191 void BulletsModule::selected1()
195 tmpbulletset = false;
196 bullets_[0] = tmpbullet;
197 setBullet(bullet1PB, bulletsize1CO, bullets_[0]);
203 void BulletsModule::selected2()
207 tmpbulletset = false;
208 bullets_[1] = tmpbullet;
209 setBullet(bullet2PB, bulletsize2CO, bullets_[1]);
215 void BulletsModule::selected3()
219 tmpbulletset = false;
220 bullets_[2] = tmpbullet;
221 setBullet(bullet3PB, bulletsize3CO, bullets_[2]);
227 void BulletsModule::selected4()
231 tmpbulletset = false;
232 bullets_[3] = tmpbullet;
233 setBullet(bullet4PB, bulletsize4CO, bullets_[3]);
239 QPixmap BulletsModule::getPixmap(int /*font*/, int /*character*/)
241 //int col = character % 6;
242 //int row = (character - col) / 6;
246 return standard_->pixmap(row,col);
248 return maths_->pixmap(row,col);
250 return ding1_->pixmap(row,col);
252 return ding2_->pixmap(row,col);
254 return ding3_->pixmap(row,col);
256 return ding4_->pixmap(row,col);
258 return standard_->pixmap(row,col);
260 // make qt4 frontend at least compilable now.
265 void BulletsModule::setBullet(QPushButton * pb, QComboBox * co, Bullet const & b)
267 if (b.getFont() == -1) {
268 pb->setPixmap(QPixmap());
269 pb->setText(toqstr(b.getText()));
271 pb->setPixmap(getPixmap(b.getFont(), b.getCharacter()));
274 pb->setMinimumSize(QSize(50, 50));
276 co->setCurrentItem(b.getSize() + 1);
280 void BulletsModule::setBullet(int level, const Bullet & bullet)
282 bullets_[level] = bullet;
283 // FIXME: backout until we fixed the browsebox
286 QPushButton * pb = 0;
290 case 0: pb = bullet1PB; co = bulletsize1CO; break;
291 case 1: pb = bullet2PB; co = bulletsize2CO; break;
292 case 2: pb = bullet3PB; co = bulletsize3CO; break;
293 case 3: pb = bullet4PB; co = bulletsize4CO; break;
294 default: BOOST_ASSERT(false); break;
297 setBullet(pb, co, bullet);
301 Bullet const & BulletsModule::getBullet(int level) const
303 return bullets_[level];
307 void BulletsModule::setCurrentBullet(int font, int character)
310 tmpbullet.setFont(font);
311 tmpbullet.setCharacter(character);
315 void BulletsModule::standard(int row, int col)
317 setCurrentBullet(0, 6 * row + col);
321 void BulletsModule::maths(int row, int col)
323 setCurrentBullet(1, 6 * row + col);
327 void BulletsModule::ding1(int row, int col)
329 setCurrentBullet(2, 6 * row + col);
333 void BulletsModule::ding2(int row, int col)
335 setCurrentBullet(3, 6 * row + col);
339 void BulletsModule::ding3(int row, int col)
341 setCurrentBullet(4, 6 * row + col);
345 void BulletsModule::ding4(int row, int col)
347 setCurrentBullet(5, 6 * row + col);
351 void BulletsModule::setCustom()
353 QString const input = bullet_pressed_ ?
354 toqstr(bullet_pressed_->getText()) : QString::null;
357 QString text = QInputDialog::getText(
359 qt_( "Enter a custom bullet" ),
367 tmpbullet.setText(fromqstr(text));
368 tmpbullet.setFont(-1);
371 #include "BulletsModule_moc.cpp"