This commit was manufactured by cvs2svn to create tag 'lyx-1_3_7'.
[lyx.git] / src / frontends / qt2 / BulletsModule.C
blobaaf7973adc7ca5105299a6a376ddcd9e86f7a49f
1 /**
2  * \file BulletsModule.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  *
8  * Full author contact details are available in file CREDITS
9  */
11 #include <config.h>
12 #include "qt_helpers.h"
14 #include <functional> // for operator %
16 #include <qinputdialog.h>
17 #include <qpopupmenu.h>
18 #include <qpixmap.h>
19 #include <qtoolbutton.h>
20 #include <qlistview.h>
21 #include <qcombobox.h>
22 #include <qlabel.h>
23 #include "BulletsModule.h"
24 #include "Bullet.h"
25 #include "ui/BulletsModuleBase.h"
26 #include "QBrowseBox.h"
27 #include "support/filetools.h"
29 BulletsModule::BulletsModule(QWidget * parent,  char const * name, WFlags fl)
30         : BulletsModuleBase(parent, name, fl)
32         for (int iter = 0; iter < 4; ++iter) {
33                 bullets_[iter] = ITEMIZE_DEFAULTS[iter];
34         }
35         
36         QPopupMenu * pm = new QPopupMenu(this);
38         QPopupMenu * pm1 = new QPopupMenu(pm);
39         QPopupMenu * pm2 = new QPopupMenu(pm);
40         QPopupMenu * pm3 = new QPopupMenu(pm);
41         QPopupMenu * pm4 = new QPopupMenu(pm);
42         QPopupMenu * pm5 = new QPopupMenu(pm);
43         QPopupMenu * pm6 = new QPopupMenu(pm);
45         standard_ = new QBrowseBox(6, 6, pm1);
46         maths_ = new QBrowseBox(6, 6, pm2);
47         ding1_ = new QBrowseBox(6, 6, pm3);
48         ding2_ = new QBrowseBox(6, 6, pm4);
49         ding3_ = new QBrowseBox(6, 6, pm5);
50         ding4_ = new QBrowseBox(6, 6, pm6);
52         pm1->insertItem(standard_);
53         pm2->insertItem(maths_);
54         pm3->insertItem(ding1_);
55         pm4->insertItem(ding2_);
56         pm5->insertItem(ding3_);
57         pm6->insertItem(ding4_);
59         pm->insertItem("Standard", pm1);
60         pm->insertItem("Maths", pm2);
61         pm->insertItem("Ding 1",pm3);
62         pm->insertItem("Ding 2",pm4);
63         pm->insertItem("Ding 3",pm5);
64         pm->insertItem("Ding 4",pm6);
65         pm->insertItem("Custom...", this, SLOT(setCustom()));
67         setbulletTB->setPopup(pm);
69         // insert pixmaps
70         string bmfile;
71         bmfile = LibFileSearch("images", "standard", "xpm");
72         standard_->insertItem(QPixmap(toqstr(bmfile)));
74         bmfile = LibFileSearch("images", "amssymb", "xpm");
75         maths_->insertItem(QPixmap(toqstr(bmfile)));
77         bmfile = LibFileSearch("images", "psnfss1", "xpm");
78         ding1_->insertItem(QPixmap(toqstr(bmfile)));
80         bmfile = LibFileSearch("images", "psnfss2", "xpm");
81         ding2_->insertItem(QPixmap(toqstr(bmfile)));
83         bmfile = LibFileSearch("images", "psnfss3", "xpm");
84         ding3_->insertItem(QPixmap(toqstr(bmfile)));
86         bmfile = LibFileSearch("images", "psnfss4", "xpm");
87         ding4_->insertItem(QPixmap(toqstr(bmfile)));
89         connect(standard_, SIGNAL(selected(int, int)),
90                 this, SLOT(standard(int, int)));
92         connect(maths_, SIGNAL(selected(int, int)),
93                 this, SLOT(maths(int, int)));
95         connect(ding1_, SIGNAL(selected(int, int)),
96                 this, SLOT(ding1(int, int)));
98         connect(ding2_, SIGNAL(selected(int, int)),
99                 this, SLOT(ding2(int, int)));
101         connect(ding3_, SIGNAL(selected(int, int)),
102                 this, SLOT(ding3(int, int)));
104         connect(ding4_, SIGNAL(selected(int, int)),
105                 this, SLOT(ding4(int, int)));
107         // update the view
108         for (int iter = 0; iter < 4; ++iter) {
109                 setBullet(iter,bullets_[iter]);
110         }
111         activeitem_ = bulletsLV->firstChild();
112         activebullet_ = &bullets_[0];
116 BulletsModule::~BulletsModule()
121 QPixmap BulletsModule::getPixmap(int font, int character)
123         int col = character%6;
124         int row = (character - col)/6;
125         switch(font) {
126         case 0:
127                 return standard_->pixmap(row,col);
128         case 1:
129                 return maths_->pixmap(row,col);
130         case 2:
131                 return ding1_->pixmap(row,col);
132         case 3:
133                 return ding2_->pixmap(row,col);
134         case 4:
135                 return ding3_->pixmap(row,col);
136         case 5:
137                 return ding4_->pixmap(row,col);
138         default:
139                 return standard_->pixmap(row,col);
140         }
144 QListViewItem *  BulletsModule::getItem(int level)
146         QListViewItemIterator it(bulletsLV->firstChild());
147         for(int i=0; i<level; ++i) {
148                 ++it;
149         }
150         return it.current();
154 void BulletsModule::setActive(int level)
156         activeitem_ = getItem(level);
157         activebullet_ = &bullets_[level];
161 void BulletsModule::setActive(QListViewItem * item)
163         activeitem_ = item;
164         activebullet_ = &bullets_[item->depth()];
168 void BulletsModule::setBullet(int font, int character)
170         activeitem_->setText(0,"");
171         activeitem_->setPixmap(0,getPixmap(font,character));
172         
173         activebullet_->setFont(font);
174         activebullet_->setCharacter(character);
178 void BulletsModule::setBullet(string text)
180         activeitem_->setPixmap(0, QPixmap());
181         activeitem_->setText(0, toqstr(text));
182         
183         activebullet_->setText(text);
187 void BulletsModule::setBullet(int level, const Bullet & bullet)
189         setActive(level);
190         bullets_[level] = bullet;
191         // set size
192         setSize(bullet.getSize()+1);
193         // set pixmap
194         if (bullet.getFont()!=-1) {
195                 setBullet(bullet.getFont(),
196                           bullet.getCharacter());
197         } else {
198                 setBullet(bullet.getText());
199         }
203 Bullet BulletsModule::getBullet(int level)
205         return bullets_[level];
209 void BulletsModule::setSize(int size)
211         activeitem_->setText(1,bulletsizeCO->text(size));
212         activebullet_->setSize(size-1);
216 void BulletsModule::standard(int row, int col)
218         setBullet(0,6*row + col);
221 void BulletsModule::maths(int row, int col)
223         setBullet(1,6*row + col);
227 void BulletsModule::ding1(int row, int col)
229         setBullet(2,6*row + col);
233 void BulletsModule::ding2(int row, int col)
235         setBullet(3,6*row + col);
239 void BulletsModule::ding3(int row, int col)
241         setBullet(4,6*row + col);
242 }       
245 void BulletsModule::ding4(int row, int col)
247         setBullet(5,6*row + col);
251 void BulletsModule::setCustom()
253         bool ok = FALSE;
254         QString text = QInputDialog::getText(
255                 qt_( "Bullets" ),
256                 qt_( "Enter a custom bullet" ),
257                 QLineEdit::Normal,
258                 QString::null, &ok, this );
260         if (ok) {
261                 activeitem_->setPixmap(0,QPixmap());
262                 activeitem_->setText(0,text);
263                 activebullet_->setText(fromqstr(text));
264                 activebullet_->setFont(-1);
265         }