2 * \file BulletsModule.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
12 #include "qt_helpers.h"
15 #pragma implementation
18 #include <functional> // for operator %
20 #include <qinputdialog.h>
21 #include <qpopupmenu.h>
23 #include <qtoolbutton.h>
24 #include <qlistview.h>
25 #include <qcombobox.h>
27 #include "BulletsModule.h"
29 #include "ui/BulletsModuleBase.h"
30 #include "QBrowseBox.h"
31 #include "support/filetools.h"
33 BulletsModule::BulletsModule(QWidget * parent, char const * name, WFlags fl)
34 : BulletsModuleBase(parent, name, fl)
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("Standard", pm1);
64 pm->insertItem("Maths", pm2);
65 pm->insertItem("Ding 1",pm3);
66 pm->insertItem("Ding 2",pm4);
67 pm->insertItem("Ding 3",pm5);
68 pm->insertItem("Ding 4",pm6);
69 pm->insertItem("Custom...", this, SLOT(setCustom()));
71 setbulletTB->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)));
112 for (int iter = 0; iter < 4; ++iter) {
113 setBullet(iter,bullets_[iter]);
115 activeitem_ = bulletsLV->firstChild();
116 activebullet_ = &bullets_[0];
120 BulletsModule::~BulletsModule()
125 QPixmap BulletsModule::getPixmap(int font, int character)
127 int col = character%6;
128 int row = (character - col)/6;
131 return standard_->pixmap(row,col);
133 return maths_->pixmap(row,col);
135 return ding1_->pixmap(row,col);
137 return ding2_->pixmap(row,col);
139 return ding3_->pixmap(row,col);
141 return ding4_->pixmap(row,col);
143 return standard_->pixmap(row,col);
148 QListViewItem * BulletsModule::getItem(int level)
150 QListViewItemIterator it(bulletsLV->firstChild());
151 for(int i=0; i<level; ++i) {
158 void BulletsModule::setActive(int level)
160 activeitem_ = getItem(level);
161 activebullet_ = &bullets_[level];
165 void BulletsModule::setActive(QListViewItem * item)
168 activebullet_ = &bullets_[item->depth()];
172 void BulletsModule::setBullet(int font, int character)
174 activeitem_->setText(0,"");
175 activeitem_->setPixmap(0,getPixmap(font,character));
177 activebullet_->setFont(font);
178 activebullet_->setCharacter(character);
182 void BulletsModule::setBullet(string text)
184 activeitem_->setPixmap(0, QPixmap());
185 activeitem_->setText(0, toqstr(text));
187 activebullet_->setText(text);
191 void BulletsModule::setBullet(int level, const Bullet & bullet)
194 bullets_[level] = bullet;
196 setSize(bullet.getSize()+1);
198 if (bullet.getFont()!=-1) {
199 setBullet(bullet.getFont(),
200 bullet.getCharacter());
202 setBullet(bullet.getText());
207 Bullet BulletsModule::getBullet(int level)
209 return bullets_[level];
213 void BulletsModule::setSize(int size)
215 activeitem_->setText(1,bulletsizeCO->text(size));
216 activebullet_->setSize(size-1);
220 void BulletsModule::standard(int row, int col)
222 setBullet(0,6*row + col);
225 void BulletsModule::maths(int row, int col)
227 setBullet(1,6*row + col);
231 void BulletsModule::ding1(int row, int col)
233 setBullet(2,6*row + col);
237 void BulletsModule::ding2(int row, int col)
239 setBullet(3,6*row + col);
243 void BulletsModule::ding3(int row, int col)
245 setBullet(4,6*row + col);
249 void BulletsModule::ding4(int row, int col)
251 setBullet(5,6*row + col);
255 void BulletsModule::setCustom()
258 QString text = QInputDialog::getText(
260 qt_( "Enter a custom bullet" ),
262 QString::null, &ok, this );
265 activeitem_->setPixmap(0,QPixmap());
266 activeitem_->setText(0,text);
267 activebullet_->setText(fromqstr(text));
268 activebullet_->setFont(-1);