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)
35 for (int iter = 0; iter < 4; ++iter) {
36 bullets_[iter] = ITEMIZE_DEFAULTS[iter];
39 QPopupMenu * pm = new QPopupMenu(this);
41 QPopupMenu * pm1 = new QPopupMenu(pm);
42 QPopupMenu * pm2 = new QPopupMenu(pm);
43 QPopupMenu * pm3 = new QPopupMenu(pm);
44 QPopupMenu * pm4 = new QPopupMenu(pm);
45 QPopupMenu * pm5 = new QPopupMenu(pm);
46 QPopupMenu * pm6 = new QPopupMenu(pm);
48 standard_ = new QBrowseBox(6, 6, pm1);
49 maths_ = new QBrowseBox(6, 6, pm2);
50 ding1_ = new QBrowseBox(6, 6, pm3);
51 ding2_ = new QBrowseBox(6, 6, pm4);
52 ding3_ = new QBrowseBox(6, 6, pm5);
53 ding4_ = new QBrowseBox(6, 6, pm6);
55 pm1->insertItem(standard_);
56 pm2->insertItem(maths_);
57 pm3->insertItem(ding1_);
58 pm4->insertItem(ding2_);
59 pm5->insertItem(ding3_);
60 pm6->insertItem(ding4_);
62 pm->insertItem(qt_("&Standard"), pm1, 0);
63 pm->insertItem(qt_("&Maths"), pm2, 1);
64 pm->insertItem(qt_("Dings &1"), pm3, 2);
65 pm->insertItem(qt_("Dings &2"), pm4, 3);
66 pm->insertItem(qt_("Dings &3"), pm5, 4);
67 pm->insertItem(qt_("Dings &4"), pm6, 5);
68 pm->insertSeparator();
69 // FIXME: make this checkable
70 pm->insertItem(qt_("&Custom..."), this, SLOT(setCustom()), 0, 6);
72 bullet1PB->setPopup(pm);
73 bullet2PB->setPopup(pm);
74 bullet3PB->setPopup(pm);
75 bullet4PB->setPopup(pm);
79 bmfile = LibFileSearch("images", "standard", "xpm");
80 standard_->insertItem(QPixmap(toqstr(bmfile)));
82 bmfile = LibFileSearch("images", "amssymb", "xpm");
83 maths_->insertItem(QPixmap(toqstr(bmfile)));
85 bmfile = LibFileSearch("images", "psnfss1", "xpm");
86 ding1_->insertItem(QPixmap(toqstr(bmfile)));
88 bmfile = LibFileSearch("images", "psnfss2", "xpm");
89 ding2_->insertItem(QPixmap(toqstr(bmfile)));
91 bmfile = LibFileSearch("images", "psnfss3", "xpm");
92 ding3_->insertItem(QPixmap(toqstr(bmfile)));
94 bmfile = LibFileSearch("images", "psnfss4", "xpm");
95 ding4_->insertItem(QPixmap(toqstr(bmfile)));
97 connect(standard_, SIGNAL(selected(int, int)),
98 this, SLOT(standard(int, int)));
100 connect(maths_, SIGNAL(selected(int, int)),
101 this, SLOT(maths(int, int)));
103 connect(ding1_, SIGNAL(selected(int, int)),
104 this, SLOT(ding1(int, int)));
106 connect(ding2_, SIGNAL(selected(int, int)),
107 this, SLOT(ding2(int, int)));
109 connect(ding3_, SIGNAL(selected(int, int)),
110 this, SLOT(ding3(int, int)));
112 connect(ding4_, SIGNAL(selected(int, int)),
113 this, SLOT(ding4(int, int)));
115 connect(bullet1PB, SIGNAL(pressed()), this, SLOT(pressed1()));
116 connect(bullet2PB, SIGNAL(pressed()), this, SLOT(pressed2()));
117 connect(bullet3PB, SIGNAL(pressed()), this, SLOT(pressed3()));
118 connect(bullet4PB, SIGNAL(pressed()), this, SLOT(pressed4()));
119 connect(bulletsize1CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
120 connect(bulletsize2CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
121 connect(bulletsize3CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
122 connect(bulletsize4CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
125 for (int i = 0; i < 4; ++i)
126 setBullet(bullet1PB, bulletsize1CO, bullets_[i]);
130 BulletsModule::~BulletsModule()
135 void BulletsModule::updateSizes()
139 // -1 apparently means default...
140 bullets_[0].setSize(bulletsize1CO->currentItem() - 1);
141 bullets_[1].setSize(bulletsize2CO->currentItem() - 1);
142 bullets_[2].setSize(bulletsize3CO->currentItem() - 1);
143 bullets_[3].setSize(bulletsize4CO->currentItem() - 1);
147 // These arrive *after* the menus have done their work
148 void BulletsModule::pressed1()
152 tmpbulletset = false;
153 bullets_[0] = tmpbullet;
154 setBullet(bullet1PB, bulletsize1CO, bullets_[0]);
159 void BulletsModule::pressed2()
163 tmpbulletset = false;
164 bullets_[1] = tmpbullet;
165 setBullet(bullet2PB, bulletsize2CO, bullets_[1]);
170 void BulletsModule::pressed3()
174 tmpbulletset = false;
175 bullets_[2] = tmpbullet;
176 setBullet(bullet3PB, bulletsize3CO, bullets_[2]);
181 void BulletsModule::pressed4()
185 tmpbulletset = false;
186 bullets_[3] = tmpbullet;
187 setBullet(bullet4PB, bulletsize4CO, bullets_[3]);
192 QPixmap BulletsModule::getPixmap(int font, int character)
194 int col = character % 6;
195 int row = (character - col) / 6;
199 return standard_->pixmap(row,col);
201 return maths_->pixmap(row,col);
203 return ding1_->pixmap(row,col);
205 return ding2_->pixmap(row,col);
207 return ding3_->pixmap(row,col);
209 return ding4_->pixmap(row,col);
211 return standard_->pixmap(row,col);
216 void BulletsModule::setBullet(QPushButton * pb, QComboBox * co, Bullet const & b)
218 if (b.getFont() == -1) {
219 pb->setPixmap(QPixmap());
220 pb->setText(toqstr(b.getText()));
222 pb->setPixmap(getPixmap(b.getFont(), b.getCharacter()));
225 pb->setMinimumSize(QSize(50, 50));
227 co->setCurrentItem(b.getSize() + 1);
231 void BulletsModule::setBullet(int level, const Bullet & bullet)
233 bullets_[level] = bullet;
235 QPushButton * pb = 0;
239 case 0: pb = bullet1PB; co = bulletsize1CO; break;
240 case 1: pb = bullet2PB; co = bulletsize2CO; break;
241 case 2: pb = bullet3PB; co = bulletsize3CO; break;
242 case 3: pb = bullet4PB; co = bulletsize4CO; break;
243 default: BOOST_ASSERT(false); break;
246 setBullet(pb, co, bullet);
250 Bullet const BulletsModule::getBullet(int level)
252 return bullets_[level];
256 void BulletsModule::setCurrentBullet(int font, int character)
259 tmpbullet.setFont(font);
260 tmpbullet.setCharacter(character);
264 void BulletsModule::standard(int row, int col)
266 setCurrentBullet(0, 6 * row + col);
270 void BulletsModule::maths(int row, int col)
272 setCurrentBullet(1, 6 * row + col);
276 void BulletsModule::ding1(int row, int col)
278 setCurrentBullet(2, 6 * row + col);
282 void BulletsModule::ding2(int row, int col)
284 setCurrentBullet(3, 6 * row + col);
288 void BulletsModule::ding3(int row, int col)
290 setCurrentBullet(4, 6 * row + col);
294 void BulletsModule::ding4(int row, int col)
296 setCurrentBullet(5, 6 * row + col);
300 void BulletsModule::setCustom()
303 QString text = QInputDialog::getText(
305 qt_( "Enter a custom bullet" ),
307 QString::null, &ok, this );
313 tmpbullet.setText(fromqstr(text));
314 tmpbullet.setFont(-1);