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
13 #include "qt_helpers.h"
15 #include "support/filetools.h"
16 #include "support/LAssert.h"
20 #include "ui/BulletsModuleBase.h"
21 #include "QBrowseBox.h"
22 #include "BulletsModule.h"
24 #include <qinputdialog.h>
25 #include <qpopupmenu.h>
27 #include <qpushbutton.h>
28 #include <qcombobox.h>
30 BulletsModule::BulletsModule(QWidget * parent, char const * name, WFlags fl)
31 : BulletsModuleBase(parent, name, fl), tmpbulletset(0)
33 for (int iter = 0; iter < 4; ++iter) {
34 bullets_[iter] = ITEMIZE_DEFAULTS[iter];
37 QPopupMenu * pm = new QPopupMenu(this);
39 QPopupMenu * pm1 = new QPopupMenu(pm);
40 QPopupMenu * pm2 = new QPopupMenu(pm);
41 QPopupMenu * pm3 = new QPopupMenu(pm);
42 QPopupMenu * pm4 = new QPopupMenu(pm);
43 QPopupMenu * pm5 = new QPopupMenu(pm);
44 QPopupMenu * pm6 = new QPopupMenu(pm);
46 standard_ = new QBrowseBox(6, 6, pm1);
47 maths_ = new QBrowseBox(6, 6, pm2);
48 ding1_ = new QBrowseBox(6, 6, pm3);
49 ding2_ = new QBrowseBox(6, 6, pm4);
50 ding3_ = new QBrowseBox(6, 6, pm5);
51 ding4_ = new QBrowseBox(6, 6, pm6);
53 pm1->insertItem(standard_);
54 pm2->insertItem(maths_);
55 pm3->insertItem(ding1_);
56 pm4->insertItem(ding2_);
57 pm5->insertItem(ding3_);
58 pm6->insertItem(ding4_);
60 pm->insertItem(qt_("&Standard"), pm1, 0);
61 pm->insertItem(qt_("&Maths"), pm2, 1);
62 pm->insertItem(qt_("Dings &1"), pm3, 2);
63 pm->insertItem(qt_("Dings &2"), pm4, 3);
64 pm->insertItem(qt_("Dings &3"), pm5, 4);
65 pm->insertItem(qt_("Dings &4"), pm6, 5);
66 pm->insertSeparator();
67 // FIXME: make this checkable
68 pm->insertItem(qt_("&Custom..."), this, SLOT(setCustom()), 0, 6);
70 bullet1PB->setPopup(pm);
71 bullet2PB->setPopup(pm);
72 bullet3PB->setPopup(pm);
73 bullet4PB->setPopup(pm);
77 bmfile = LibFileSearch("images", "standard", "xpm");
78 standard_->insertItem(QPixmap(toqstr(bmfile)));
80 bmfile = LibFileSearch("images", "amssymb", "xpm");
81 maths_->insertItem(QPixmap(toqstr(bmfile)));
83 bmfile = LibFileSearch("images", "psnfss1", "xpm");
84 ding1_->insertItem(QPixmap(toqstr(bmfile)));
86 bmfile = LibFileSearch("images", "psnfss2", "xpm");
87 ding2_->insertItem(QPixmap(toqstr(bmfile)));
89 bmfile = LibFileSearch("images", "psnfss3", "xpm");
90 ding3_->insertItem(QPixmap(toqstr(bmfile)));
92 bmfile = LibFileSearch("images", "psnfss4", "xpm");
93 ding4_->insertItem(QPixmap(toqstr(bmfile)));
95 connect(standard_, SIGNAL(selected(int, int)),
96 this, SLOT(standard(int, int)));
98 connect(maths_, SIGNAL(selected(int, int)),
99 this, SLOT(maths(int, int)));
101 connect(ding1_, SIGNAL(selected(int, int)),
102 this, SLOT(ding1(int, int)));
104 connect(ding2_, SIGNAL(selected(int, int)),
105 this, SLOT(ding2(int, int)));
107 connect(ding3_, SIGNAL(selected(int, int)),
108 this, SLOT(ding3(int, int)));
110 connect(ding4_, SIGNAL(selected(int, int)),
111 this, SLOT(ding4(int, int)));
113 connect(bullet1PB, SIGNAL(pressed()), this, SLOT(pressed1()));
114 connect(bullet2PB, SIGNAL(pressed()), this, SLOT(pressed2()));
115 connect(bullet3PB, SIGNAL(pressed()), this, SLOT(pressed3()));
116 connect(bullet4PB, SIGNAL(pressed()), this, SLOT(pressed4()));
117 connect(bulletsize1CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
118 connect(bulletsize2CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
119 connect(bulletsize3CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
120 connect(bulletsize4CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
123 for (int i = 0; i < 4; ++i)
124 setBullet(bullet1PB, bulletsize1CO, bullets_[i]);
128 BulletsModule::~BulletsModule()
133 void BulletsModule::updateSizes()
137 // -1 apparently means default...
138 bullets_[0].setSize(bulletsize1CO->currentItem() - 1);
139 bullets_[1].setSize(bulletsize2CO->currentItem() - 1);
140 bullets_[2].setSize(bulletsize3CO->currentItem() - 1);
141 bullets_[3].setSize(bulletsize4CO->currentItem() - 1);
145 // These arrive *after* the menus have done their work
146 void BulletsModule::pressed1()
150 tmpbulletset = false;
151 bullets_[0] = tmpbullet;
152 setBullet(bullet1PB, bulletsize1CO, bullets_[0]);
157 void BulletsModule::pressed2()
161 tmpbulletset = false;
162 bullets_[1] = tmpbullet;
163 setBullet(bullet2PB, bulletsize2CO, bullets_[1]);
168 void BulletsModule::pressed3()
172 tmpbulletset = false;
173 bullets_[2] = tmpbullet;
174 setBullet(bullet3PB, bulletsize3CO, bullets_[2]);
179 void BulletsModule::pressed4()
183 tmpbulletset = false;
184 bullets_[3] = tmpbullet;
185 setBullet(bullet4PB, bulletsize4CO, bullets_[3]);
190 QPixmap BulletsModule::getPixmap(int font, int character)
192 int col = character % 6;
193 int row = (character - col) / 6;
197 return standard_->pixmap(row,col);
199 return maths_->pixmap(row,col);
201 return ding1_->pixmap(row,col);
203 return ding2_->pixmap(row,col);
205 return ding3_->pixmap(row,col);
207 return ding4_->pixmap(row,col);
209 return standard_->pixmap(row,col);
214 void BulletsModule::setBullet(QPushButton * pb, QComboBox * co, Bullet const & b)
216 if (b.getFont() == -1) {
217 pb->setPixmap(QPixmap());
220 pb->setPixmap(getPixmap(b.getFont(), b.getCharacter()));
223 pb->setMinimumSize(QSize(50, 50));
225 co->setCurrentItem(b.getSize() + 1);
229 void BulletsModule::setBullet(int level, const Bullet & bullet)
231 bullets_[level] = bullet;
237 case 0: pb = bullet1PB; co = bulletsize1CO; break;
238 case 1: pb = bullet2PB; co = bulletsize2CO; break;
239 case 2: pb = bullet3PB; co = bulletsize3CO; break;
240 case 3: pb = bullet4PB; co = bulletsize4CO; break;
241 default: lyx::Assert(false); break;
244 setBullet(pb, co, bullet);
248 Bullet const BulletsModule::getBullet(int level)
250 return bullets_[level];
254 void BulletsModule::setCurrentBullet(int font, int character)
257 tmpbullet.setFont(font);
258 tmpbullet.setCharacter(character);
262 void BulletsModule::standard(int row, int col)
264 setCurrentBullet(0, 6 * row + col);
268 void BulletsModule::maths(int row, int col)
270 setCurrentBullet(1, 6 * row + col);
274 void BulletsModule::ding1(int row, int col)
276 setCurrentBullet(2, 6 * row + col);
280 void BulletsModule::ding2(int row, int col)
282 setCurrentBullet(3, 6 * row + col);
286 void BulletsModule::ding3(int row, int col)
288 setCurrentBullet(4, 6 * row + col);
292 void BulletsModule::ding4(int row, int col)
294 setCurrentBullet(5, 6 * row + col);
298 void BulletsModule::setCustom()
301 QString text = QInputDialog::getText(
303 qt_( "Enter a custom bullet" ),
305 QString::null, &ok, this );
311 tmpbullet.setText(fromqstr(text));
312 tmpbullet.setFont(-1);