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"
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 using namespace lyx::support;
28 BulletsModule::BulletsModule(QWidget * parent, const char * name, WFlags fl)
29 : BulletsModuleBase(parent, name, fl), tmpbulletset(0)
31 for (int iter = 0; iter < 4; ++iter) {
32 bullets_[iter] = ITEMIZE_DEFAULTS[iter];
35 QPopupMenu * pm = new QPopupMenu(this);
37 QPopupMenu * pm1 = new QPopupMenu(pm);
38 QPopupMenu * pm2 = new QPopupMenu(pm);
39 QPopupMenu * pm3 = new QPopupMenu(pm);
40 QPopupMenu * pm4 = new QPopupMenu(pm);
41 QPopupMenu * pm5 = new QPopupMenu(pm);
42 QPopupMenu * pm6 = new QPopupMenu(pm);
44 standard_ = new QBrowseBox(6, 6, pm1);
45 maths_ = new QBrowseBox(6, 6, pm2);
46 ding1_ = new QBrowseBox(6, 6, pm3);
47 ding2_ = new QBrowseBox(6, 6, pm4);
48 ding3_ = new QBrowseBox(6, 6, pm5);
49 ding4_ = new QBrowseBox(6, 6, pm6);
51 pm1->insertItem(standard_);
52 pm2->insertItem(maths_);
53 pm3->insertItem(ding1_);
54 pm4->insertItem(ding2_);
55 pm5->insertItem(ding3_);
56 pm6->insertItem(ding4_);
58 pm->insertItem(qt_("&Standard"), pm1, 0);
59 pm->insertItem(qt_("&Maths"), pm2, 1);
60 pm->insertItem(qt_("Dings &1"), pm3, 2);
61 pm->insertItem(qt_("Dings &2"), pm4, 3);
62 pm->insertItem(qt_("Dings &3"), pm5, 4);
63 pm->insertItem(qt_("Dings &4"), pm6, 5);
64 pm->insertSeparator();
65 // FIXME: make this checkable
66 pm->insertItem(qt_("&Custom..."), this, SLOT(setCustom()), 0, 6);
68 bullet1PB->setPopup(pm);
69 bullet2PB->setPopup(pm);
70 bullet3PB->setPopup(pm);
71 bullet4PB->setPopup(pm);
75 bmfile = LibFileSearch("images", "standard", "xpm");
76 standard_->insertItem(QPixmap(toqstr(bmfile)));
78 bmfile = LibFileSearch("images", "amssymb", "xpm");
79 maths_->insertItem(QPixmap(toqstr(bmfile)));
81 bmfile = LibFileSearch("images", "psnfss1", "xpm");
82 ding1_->insertItem(QPixmap(toqstr(bmfile)));
84 bmfile = LibFileSearch("images", "psnfss2", "xpm");
85 ding2_->insertItem(QPixmap(toqstr(bmfile)));
87 bmfile = LibFileSearch("images", "psnfss3", "xpm");
88 ding3_->insertItem(QPixmap(toqstr(bmfile)));
90 bmfile = LibFileSearch("images", "psnfss4", "xpm");
91 ding4_->insertItem(QPixmap(toqstr(bmfile)));
93 connect(standard_, SIGNAL(selected(int, int)),
94 this, SLOT(standard(int, int)));
96 connect(maths_, SIGNAL(selected(int, int)),
97 this, SLOT(maths(int, int)));
99 connect(ding1_, SIGNAL(selected(int, int)),
100 this, SLOT(ding1(int, int)));
102 connect(ding2_, SIGNAL(selected(int, int)),
103 this, SLOT(ding2(int, int)));
105 connect(ding3_, SIGNAL(selected(int, int)),
106 this, SLOT(ding3(int, int)));
108 connect(ding4_, SIGNAL(selected(int, int)),
109 this, SLOT(ding4(int, int)));
111 connect(bullet1PB, SIGNAL(pressed()), this, SLOT(pressed1()));
112 connect(bullet2PB, SIGNAL(pressed()), this, SLOT(pressed2()));
113 connect(bullet3PB, SIGNAL(pressed()), this, SLOT(pressed3()));
114 connect(bullet4PB, SIGNAL(pressed()), this, SLOT(pressed4()));
115 connect(bulletsize1CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
116 connect(bulletsize2CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
117 connect(bulletsize3CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
118 connect(bulletsize4CO, SIGNAL(activated(int)), this, SLOT(updateSizes()));
121 for (int i = 0; i < 4; ++i)
122 setBullet(bullet1PB, bulletsize1CO, bullets_[i]);
126 BulletsModule::~BulletsModule()
131 void BulletsModule::updateSizes()
135 // -1 apparently means default...
136 bullets_[0].setSize(bulletsize1CO->currentItem() - 1);
137 bullets_[1].setSize(bulletsize2CO->currentItem() - 1);
138 bullets_[2].setSize(bulletsize3CO->currentItem() - 1);
139 bullets_[3].setSize(bulletsize4CO->currentItem() - 1);
143 // These arrive *after* the menus have done their work
144 void BulletsModule::pressed1()
148 tmpbulletset = false;
149 bullets_[0] = tmpbullet;
150 setBullet(bullet1PB, bulletsize1CO, bullets_[0]);
155 void BulletsModule::pressed2()
159 tmpbulletset = false;
160 bullets_[1] = tmpbullet;
161 setBullet(bullet2PB, bulletsize2CO, bullets_[1]);
166 void BulletsModule::pressed3()
170 tmpbulletset = false;
171 bullets_[2] = tmpbullet;
172 setBullet(bullet3PB, bulletsize3CO, bullets_[2]);
177 void BulletsModule::pressed4()
181 tmpbulletset = false;
182 bullets_[3] = tmpbullet;
183 setBullet(bullet4PB, bulletsize4CO, bullets_[3]);
188 QPixmap BulletsModule::getPixmap(int font, int character)
190 int col = character % 6;
191 int row = (character - col) / 6;
195 return standard_->pixmap(row,col);
197 return maths_->pixmap(row,col);
199 return ding1_->pixmap(row,col);
201 return ding2_->pixmap(row,col);
203 return ding3_->pixmap(row,col);
205 return ding4_->pixmap(row,col);
207 return standard_->pixmap(row,col);
212 void BulletsModule::setBullet(QPushButton * pb, QComboBox * co, Bullet const & b)
214 if (b.getFont() == -1) {
215 pb->setPixmap(QPixmap());
218 pb->setPixmap(getPixmap(b.getFont(), b.getCharacter()));
221 pb->setMinimumSize(QSize(50, 50));
223 co->setCurrentItem(b.getSize() + 1);
227 void BulletsModule::setBullet(int level, const Bullet & bullet)
229 bullets_[level] = bullet;
235 case 0: pb = bullet1PB; co = bulletsize1CO; break;
236 case 1: pb = bullet2PB; co = bulletsize2CO; break;
237 case 2: pb = bullet3PB; co = bulletsize3CO; break;
238 case 3: pb = bullet4PB; co = bulletsize4CO; break;
239 default: Assert(false); break;
242 setBullet(pb, co, bullet);
246 Bullet const BulletsModule::getBullet(int level)
248 return bullets_[level];
252 void BulletsModule::setCurrentBullet(int font, int character)
255 tmpbullet.setFont(font);
256 tmpbullet.setCharacter(character);
260 void BulletsModule::standard(int row, int col)
262 setCurrentBullet(0, 6 * row + col);
266 void BulletsModule::maths(int row, int col)
268 setCurrentBullet(1, 6 * row + col);
272 void BulletsModule::ding1(int row, int col)
274 setCurrentBullet(2, 6 * row + col);
278 void BulletsModule::ding2(int row, int col)
280 setCurrentBullet(3, 6 * row + col);
284 void BulletsModule::ding3(int row, int col)
286 setCurrentBullet(4, 6 * row + col);
290 void BulletsModule::ding4(int row, int col)
292 setCurrentBullet(5, 6 * row + col);
296 void BulletsModule::setCustom()
299 QString text = QInputDialog::getText(
301 qt_( "Enter a custom bullet" ),
303 QString::null, &ok, this );
309 tmpbullet.setText(fromqstr(text));
310 tmpbullet.setFont(-1);