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 "qt_helpers.h"
16 #include "support/filetools.h"
18 #include "QBrowseBox.h"
19 #include "BulletsModule.h"
21 #include <qinputdialog.h>
22 #include <qpopupmenu.h>
23 #include <qpushbutton.h>
24 #include <qcombobox.h>
26 #include <boost/assert.hpp>
28 using lyx::support::LibFileSearch;
33 BulletsModule::BulletsModule(QWidget * parent, const char * name, WFlags fl)
34 : 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 bullet1PB->setPopup(pm);
74 bullet2PB->setPopup(pm);
75 bullet3PB->setPopup(pm);
76 bullet4PB->setPopup(pm);
80 bmfile = LibFileSearch("images", "standard", "xpm");
81 standard_->insertItem(QPixmap(toqstr(bmfile)));
83 bmfile = LibFileSearch("images", "amssymb", "xpm");
84 maths_->insertItem(QPixmap(toqstr(bmfile)));
86 bmfile = LibFileSearch("images", "psnfss1", "xpm");
87 ding1_->insertItem(QPixmap(toqstr(bmfile)));
89 bmfile = LibFileSearch("images", "psnfss2", "xpm");
90 ding2_->insertItem(QPixmap(toqstr(bmfile)));
92 bmfile = LibFileSearch("images", "psnfss3", "xpm");
93 ding3_->insertItem(QPixmap(toqstr(bmfile)));
95 bmfile = LibFileSearch("images", "psnfss4", "xpm");
96 ding4_->insertItem(QPixmap(toqstr(bmfile)));
98 connect(standard_, SIGNAL(selected(int, int)),
99 this, SLOT(standard(int, int)));
101 connect(maths_, SIGNAL(selected(int, int)),
102 this, SLOT(maths(int, int)));
104 connect(ding1_, SIGNAL(selected(int, int)),
105 this, SLOT(ding1(int, int)));
107 connect(ding2_, SIGNAL(selected(int, int)),
108 this, SLOT(ding2(int, int)));
110 connect(ding3_, SIGNAL(selected(int, int)),
111 this, SLOT(ding3(int, int)));
113 connect(ding4_, SIGNAL(selected(int, int)),
114 this, SLOT(ding4(int, int)));
116 connect(bullet1PB, SIGNAL(pressed()), this, SLOT(pressed1()));
117 connect(bullet2PB, SIGNAL(pressed()), this, SLOT(pressed2()));
118 connect(bullet3PB, SIGNAL(pressed()), this, SLOT(pressed3()));
119 connect(bullet4PB, SIGNAL(pressed()), this, SLOT(pressed4()));
120 connect(bulletsize1CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
121 connect(bulletsize2CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
122 connect(bulletsize3CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
123 connect(bulletsize4CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
126 for (int i = 0; i < 4; ++i)
127 setBullet(bullet1PB, bulletsize1CO, bullets_[i]);
131 BulletsModule::~BulletsModule()
136 void BulletsModule::updateSizes()
140 // -1 apparently means default...
141 bullets_[0].setSize(bulletsize1CO->currentItem() - 1);
142 bullets_[1].setSize(bulletsize2CO->currentItem() - 1);
143 bullets_[2].setSize(bulletsize3CO->currentItem() - 1);
144 bullets_[3].setSize(bulletsize4CO->currentItem() - 1);
148 // These arrive *after* the menus have done their work
149 void BulletsModule::pressed1()
153 tmpbulletset = false;
154 bullets_[0] = tmpbullet;
155 setBullet(bullet1PB, bulletsize1CO, bullets_[0]);
160 void BulletsModule::pressed2()
164 tmpbulletset = false;
165 bullets_[1] = tmpbullet;
166 setBullet(bullet2PB, bulletsize2CO, bullets_[1]);
171 void BulletsModule::pressed3()
175 tmpbulletset = false;
176 bullets_[2] = tmpbullet;
177 setBullet(bullet3PB, bulletsize3CO, bullets_[2]);
182 void BulletsModule::pressed4()
186 tmpbulletset = false;
187 bullets_[3] = tmpbullet;
188 setBullet(bullet4PB, bulletsize4CO, bullets_[3]);
193 QPixmap BulletsModule::getPixmap(int font, int character)
195 int col = character % 6;
196 int row = (character - col) / 6;
200 return standard_->pixmap(row,col);
202 return maths_->pixmap(row,col);
204 return ding1_->pixmap(row,col);
206 return ding2_->pixmap(row,col);
208 return ding3_->pixmap(row,col);
210 return ding4_->pixmap(row,col);
212 return standard_->pixmap(row,col);
217 void BulletsModule::setBullet(QPushButton * pb, QComboBox * co, Bullet const & b)
219 if (b.getFont() == -1) {
220 pb->setPixmap(QPixmap());
223 pb->setPixmap(getPixmap(b.getFont(), b.getCharacter()));
226 pb->setMinimumSize(QSize(50, 50));
228 co->setCurrentItem(b.getSize() + 1);
232 void BulletsModule::setBullet(int level, const Bullet & bullet)
234 bullets_[level] = bullet;
240 case 0: pb = bullet1PB; co = bulletsize1CO; break;
241 case 1: pb = bullet2PB; co = bulletsize2CO; break;
242 case 2: pb = bullet3PB; co = bulletsize3CO; break;
243 case 3: pb = bullet4PB; co = bulletsize4CO; break;
244 default: BOOST_ASSERT(false); break;
247 setBullet(pb, co, bullet);
251 Bullet const BulletsModule::getBullet(int level)
253 return bullets_[level];
257 void BulletsModule::setCurrentBullet(int font, int character)
260 tmpbullet.setFont(font);
261 tmpbullet.setCharacter(character);
265 void BulletsModule::standard(int row, int col)
267 setCurrentBullet(0, 6 * row + col);
271 void BulletsModule::maths(int row, int col)
273 setCurrentBullet(1, 6 * row + col);
277 void BulletsModule::ding1(int row, int col)
279 setCurrentBullet(2, 6 * row + col);
283 void BulletsModule::ding2(int row, int col)
285 setCurrentBullet(3, 6 * row + col);
289 void BulletsModule::ding3(int row, int col)
291 setCurrentBullet(4, 6 * row + col);
295 void BulletsModule::ding4(int row, int col)
297 setCurrentBullet(5, 6 * row + col);
301 void BulletsModule::setCustom()
304 QString text = QInputDialog::getText(
306 qt_( "Enter a custom bullet" ),
308 QString::null, &ok, this );
314 tmpbullet.setText(fromqstr(text));
315 tmpbullet.setFont(-1);