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 #include <functional> // for operator %
17 #include <qinputdialog.h>
18 #include <qpopupmenu.h>
20 #include <qtoolbutton.h>
21 #include <qlistview.h>
22 #include <qcombobox.h>
24 #include "BulletsModule.h"
26 #include "ui/BulletsModuleBase.h"
27 #include "QBrowseBox.h"
28 #include "support/filetools.h"
30 BulletsModule::BulletsModule(QWidget * parent, char const * name, WFlags fl)
31 : BulletsModuleBase(parent, name, fl)
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("Standard", pm1);
61 pm->insertItem("Maths", pm2);
62 pm->insertItem("Ding 1",pm3);
63 pm->insertItem("Ding 2",pm4);
64 pm->insertItem("Ding 3",pm5);
65 pm->insertItem("Ding 4",pm6);
66 pm->insertItem("Custom...", this, SLOT(setCustom()));
68 setbulletTB->setPopup(pm);
72 bmfile = LibFileSearch("images", "standard", "xpm");
73 standard_->insertItem(QPixmap(toqstr(bmfile)));
75 bmfile = LibFileSearch("images", "amssymb", "xpm");
76 maths_->insertItem(QPixmap(toqstr(bmfile)));
78 bmfile = LibFileSearch("images", "psnfss1", "xpm");
79 ding1_->insertItem(QPixmap(toqstr(bmfile)));
81 bmfile = LibFileSearch("images", "psnfss2", "xpm");
82 ding2_->insertItem(QPixmap(toqstr(bmfile)));
84 bmfile = LibFileSearch("images", "psnfss3", "xpm");
85 ding3_->insertItem(QPixmap(toqstr(bmfile)));
87 bmfile = LibFileSearch("images", "psnfss4", "xpm");
88 ding4_->insertItem(QPixmap(toqstr(bmfile)));
90 connect(standard_, SIGNAL(selected(int, int)),
91 this, SLOT(standard(int, int)));
93 connect(maths_, SIGNAL(selected(int, int)),
94 this, SLOT(maths(int, int)));
96 connect(ding1_, SIGNAL(selected(int, int)),
97 this, SLOT(ding1(int, int)));
99 connect(ding2_, SIGNAL(selected(int, int)),
100 this, SLOT(ding2(int, int)));
102 connect(ding3_, SIGNAL(selected(int, int)),
103 this, SLOT(ding3(int, int)));
105 connect(ding4_, SIGNAL(selected(int, int)),
106 this, SLOT(ding4(int, int)));
109 for (int iter = 0; iter < 4; ++iter) {
110 setBullet(iter,bullets_[iter]);
112 activeitem_ = bulletsLV->firstChild();
113 activebullet_ = &bullets_[0];
117 BulletsModule::~BulletsModule()
122 QPixmap BulletsModule::getPixmap(int font, int character)
124 int col = character%6;
125 int row = (character - col)/6;
128 return standard_->pixmap(row,col);
130 return maths_->pixmap(row,col);
132 return ding1_->pixmap(row,col);
134 return ding2_->pixmap(row,col);
136 return ding3_->pixmap(row,col);
138 return ding4_->pixmap(row,col);
140 return standard_->pixmap(row,col);
145 QListViewItem * BulletsModule::getItem(int level)
147 QListViewItemIterator it(bulletsLV->firstChild());
148 for(int i=0; i<level; ++i) {
155 void BulletsModule::setActive(int level)
157 activeitem_ = getItem(level);
158 activebullet_ = &bullets_[level];
162 void BulletsModule::setActive(QListViewItem * item)
165 activebullet_ = &bullets_[item->depth()];
169 void BulletsModule::setBullet(int font, int character)
171 activeitem_->setText(0,"");
172 activeitem_->setPixmap(0,getPixmap(font,character));
174 activebullet_->setFont(font);
175 activebullet_->setCharacter(character);
179 void BulletsModule::setBullet(string text)
181 activeitem_->setPixmap(0, QPixmap());
182 activeitem_->setText(0, toqstr(text));
184 activebullet_->setText(text);
188 void BulletsModule::setBullet(int level, const Bullet & bullet)
191 bullets_[level] = bullet;
193 setSize(bullet.getSize()+1);
195 if (bullet.getFont()!=-1) {
196 setBullet(bullet.getFont(),
197 bullet.getCharacter());
199 setBullet(bullet.getText());
204 Bullet BulletsModule::getBullet(int level)
206 return bullets_[level];
210 void BulletsModule::setSize(int size)
212 activeitem_->setText(1,bulletsizeCO->text(size));
213 activebullet_->setSize(size-1);
217 void BulletsModule::standard(int row, int col)
219 setBullet(0,6*row + col);
222 void BulletsModule::maths(int row, int col)
224 setBullet(1,6*row + col);
228 void BulletsModule::ding1(int row, int col)
230 setBullet(2,6*row + col);
234 void BulletsModule::ding2(int row, int col)
236 setBullet(3,6*row + col);
240 void BulletsModule::ding3(int row, int col)
242 setBullet(4,6*row + col);
246 void BulletsModule::ding4(int row, int col)
248 setBullet(5,6*row + col);
252 void BulletsModule::setCustom()
255 QString text = QInputDialog::getText(
257 qt_( "Enter a custom bullet" ),
259 QString::null, &ok, this );
262 activeitem_->setPixmap(0,QPixmap());
263 activeitem_->setText(0,text);
264 activebullet_->setText(fromqstr(text));
265 activebullet_->setFont(-1);