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()
147 // -1 apparently means default...
148 bullets_[0].setSize(bulletsize1CO->currentItem() - 1);
149 bullets_[1].setSize(bulletsize2CO->currentItem() - 1);
150 bullets_[2].setSize(bulletsize3CO->currentItem() - 1);
151 bullets_[3].setSize(bulletsize4CO->currentItem() - 1);
155 // These arrive before the menus are launched.
156 void BulletsModule::clicked1()
158 bullet_pressed_ = &bullets_[0];
162 void BulletsModule::clicked2()
164 bullet_pressed_ = &bullets_[1];
168 void BulletsModule::clicked3()
170 bullet_pressed_ = &bullets_[2];
174 void BulletsModule::clicked4()
176 bullet_pressed_ = &bullets_[3];
180 // These arrive *after* the menus have done their work
181 void BulletsModule::selected1()
185 tmpbulletset = false;
186 bullets_[0] = tmpbullet;
187 setBullet(bullet1PB, bulletsize1CO, bullets_[0]);
192 void BulletsModule::selected2()
196 tmpbulletset = false;
197 bullets_[1] = tmpbullet;
198 setBullet(bullet2PB, bulletsize2CO, bullets_[1]);
203 void BulletsModule::selected3()
207 tmpbulletset = false;
208 bullets_[2] = tmpbullet;
209 setBullet(bullet3PB, bulletsize3CO, bullets_[2]);
214 void BulletsModule::selected4()
218 tmpbulletset = false;
219 bullets_[3] = tmpbullet;
220 setBullet(bullet4PB, bulletsize4CO, bullets_[3]);
225 QPixmap BulletsModule::getPixmap(int font, int character)
227 int col = character % 6;
228 int row = (character - col) / 6;
232 return standard_->pixmap(row,col);
234 return maths_->pixmap(row,col);
236 return ding1_->pixmap(row,col);
238 return ding2_->pixmap(row,col);
240 return ding3_->pixmap(row,col);
242 return ding4_->pixmap(row,col);
244 return standard_->pixmap(row,col);
249 void BulletsModule::setBullet(QPushButton * pb, QComboBox * co, Bullet const & b)
251 if (b.getFont() == -1) {
252 pb->setPixmap(QPixmap());
253 pb->setText(toqstr(b.getText()));
255 pb->setPixmap(getPixmap(b.getFont(), b.getCharacter()));
258 pb->setMinimumSize(QSize(50, 50));
260 co->setCurrentItem(b.getSize() + 1);
264 void BulletsModule::setBullet(int level, const Bullet & bullet)
266 bullets_[level] = bullet;
268 QPushButton * pb = 0;
272 case 0: pb = bullet1PB; co = bulletsize1CO; break;
273 case 1: pb = bullet2PB; co = bulletsize2CO; break;
274 case 2: pb = bullet3PB; co = bulletsize3CO; break;
275 case 3: pb = bullet4PB; co = bulletsize4CO; break;
276 default: BOOST_ASSERT(false); break;
279 setBullet(pb, co, bullet);
283 Bullet const & BulletsModule::getBullet(int level) const
285 return bullets_[level];
289 void BulletsModule::setCurrentBullet(int font, int character)
292 tmpbullet.setFont(font);
293 tmpbullet.setCharacter(character);
297 void BulletsModule::standard(int row, int col)
299 setCurrentBullet(0, 6 * row + col);
303 void BulletsModule::maths(int row, int col)
305 setCurrentBullet(1, 6 * row + col);
309 void BulletsModule::ding1(int row, int col)
311 setCurrentBullet(2, 6 * row + col);
315 void BulletsModule::ding2(int row, int col)
317 setCurrentBullet(3, 6 * row + col);
321 void BulletsModule::ding3(int row, int col)
323 setCurrentBullet(4, 6 * row + col);
327 void BulletsModule::ding4(int row, int col)
329 setCurrentBullet(5, 6 * row + col);
333 void BulletsModule::setCustom()
335 QString const input = bullet_pressed_ ?
336 toqstr(bullet_pressed_->getText()) : QString::null;
339 QString text = QInputDialog::getText(
341 qt_( "Enter a custom bullet" ),
349 tmpbullet.setText(fromqstr(text));
350 tmpbullet.setFont(-1);