]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/BulletsModule.C
dont use pragma impementation and interface anymore
[lyx.git] / src / frontends / qt2 / BulletsModule.C
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  */
10
11 #include <config.h>
12 #include "qt_helpers.h"
13
14
15 #include <functional> // for operator %
16
17 #include <qinputdialog.h>
18 #include <qpopupmenu.h>
19 #include <qpixmap.h>
20 #include <qtoolbutton.h>
21 #include <qlistview.h>
22 #include <qcombobox.h>
23 #include <qlabel.h>
24 #include "BulletsModule.h"
25 #include "Bullet.h"
26 #include "ui/BulletsModuleBase.h"
27 #include "QBrowseBox.h"
28 #include "support/filetools.h"
29
30 BulletsModule::BulletsModule(QWidget * parent,  char const * name, WFlags fl)
31         : BulletsModuleBase(parent, name, fl)
32 {
33         for (int iter = 0; iter < 4; ++iter) {
34                 bullets_[iter] = ITEMIZE_DEFAULTS[iter];
35         }
36         
37         QPopupMenu * pm = new QPopupMenu(this);
38
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);
45
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);
52
53         pm1->insertItem(standard_);
54         pm2->insertItem(maths_);
55         pm3->insertItem(ding1_);
56         pm4->insertItem(ding2_);
57         pm5->insertItem(ding3_);
58         pm6->insertItem(ding4_);
59
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()));
67
68         setbulletTB->setPopup(pm);
69
70         // insert pixmaps
71         string bmfile;
72         bmfile = LibFileSearch("images", "standard", "xpm");
73         standard_->insertItem(QPixmap(toqstr(bmfile)));
74
75         bmfile = LibFileSearch("images", "amssymb", "xpm");
76         maths_->insertItem(QPixmap(toqstr(bmfile)));
77
78         bmfile = LibFileSearch("images", "psnfss1", "xpm");
79         ding1_->insertItem(QPixmap(toqstr(bmfile)));
80
81         bmfile = LibFileSearch("images", "psnfss2", "xpm");
82         ding2_->insertItem(QPixmap(toqstr(bmfile)));
83
84         bmfile = LibFileSearch("images", "psnfss3", "xpm");
85         ding3_->insertItem(QPixmap(toqstr(bmfile)));
86
87         bmfile = LibFileSearch("images", "psnfss4", "xpm");
88         ding4_->insertItem(QPixmap(toqstr(bmfile)));
89
90         connect(standard_, SIGNAL(selected(int, int)),
91                 this, SLOT(standard(int, int)));
92
93         connect(maths_, SIGNAL(selected(int, int)),
94                 this, SLOT(maths(int, int)));
95
96         connect(ding1_, SIGNAL(selected(int, int)),
97                 this, SLOT(ding1(int, int)));
98
99         connect(ding2_, SIGNAL(selected(int, int)),
100                 this, SLOT(ding2(int, int)));
101
102         connect(ding3_, SIGNAL(selected(int, int)),
103                 this, SLOT(ding3(int, int)));
104
105         connect(ding4_, SIGNAL(selected(int, int)),
106                 this, SLOT(ding4(int, int)));
107
108         // update the view
109         for (int iter = 0; iter < 4; ++iter) {
110                 setBullet(iter,bullets_[iter]);
111         }
112         activeitem_ = bulletsLV->firstChild();
113         activebullet_ = &bullets_[0];
114 }
115
116
117 BulletsModule::~BulletsModule()
118 {
119 }
120
121
122 QPixmap BulletsModule::getPixmap(int font, int character)
123 {
124         int col = character%6;
125         int row = (character - col)/6;
126         switch(font) {
127         case 0:
128                 return standard_->pixmap(row,col);
129         case 1:
130                 return maths_->pixmap(row,col);
131         case 2:
132                 return ding1_->pixmap(row,col);
133         case 3:
134                 return ding2_->pixmap(row,col);
135         case 4:
136                 return ding3_->pixmap(row,col);
137         case 5:
138                 return ding4_->pixmap(row,col);
139         default:
140                 return standard_->pixmap(row,col);
141         }
142 }
143
144
145 QListViewItem *  BulletsModule::getItem(int level)
146 {
147         QListViewItemIterator it(bulletsLV->firstChild());
148         for(int i=0; i<level; ++i) {
149                 ++it;
150         }
151         return it.current();
152 }
153
154
155 void BulletsModule::setActive(int level)
156 {
157         activeitem_ = getItem(level);
158         activebullet_ = &bullets_[level];
159 }
160
161
162 void BulletsModule::setActive(QListViewItem * item)
163 {
164         activeitem_ = item;
165         activebullet_ = &bullets_[item->depth()];
166 }
167
168
169 void BulletsModule::setBullet(int font, int character)
170 {
171         activeitem_->setText(0,"");
172         activeitem_->setPixmap(0,getPixmap(font,character));
173         
174         activebullet_->setFont(font);
175         activebullet_->setCharacter(character);
176 }
177
178
179 void BulletsModule::setBullet(string text)
180 {
181         activeitem_->setPixmap(0, QPixmap());
182         activeitem_->setText(0, toqstr(text));
183         
184         activebullet_->setText(text);
185 }
186
187
188 void BulletsModule::setBullet(int level, const Bullet & bullet)
189 {
190         setActive(level);
191         bullets_[level] = bullet;
192         // set size
193         setSize(bullet.getSize()+1);
194         // set pixmap
195         if (bullet.getFont()!=-1) {
196                 setBullet(bullet.getFont(),
197                           bullet.getCharacter());
198         } else {
199                 setBullet(bullet.getText());
200         }
201 }
202
203
204 Bullet BulletsModule::getBullet(int level)
205 {
206         return bullets_[level];
207 }
208
209
210 void BulletsModule::setSize(int size)
211 {
212         activeitem_->setText(1,bulletsizeCO->text(size));
213         activebullet_->setSize(size-1);
214 }
215
216
217 void BulletsModule::standard(int row, int col)
218 {
219         setBullet(0,6*row + col);
220 }
221
222 void BulletsModule::maths(int row, int col)
223 {
224         setBullet(1,6*row + col);
225 }
226
227
228 void BulletsModule::ding1(int row, int col)
229 {
230         setBullet(2,6*row + col);
231 }
232
233
234 void BulletsModule::ding2(int row, int col)
235 {
236         setBullet(3,6*row + col);
237 }
238
239
240 void BulletsModule::ding3(int row, int col)
241 {
242         setBullet(4,6*row + col);
243 }       
244
245
246 void BulletsModule::ding4(int row, int col)
247 {
248         setBullet(5,6*row + col);
249 }
250
251
252 void BulletsModule::setCustom()
253 {
254         bool ok = FALSE;
255         QString text = QInputDialog::getText(
256                 qt_( "Bullets" ),
257                 qt_( "Enter a custom bullet" ),
258                 QLineEdit::Normal,
259                 QString::null, &ok, this );
260
261         if (ok) {
262                 activeitem_->setPixmap(0,QPixmap());
263                 activeitem_->setText(0,text);
264                 activebullet_->setText(fromqstr(text));
265                 activebullet_->setFont(-1);
266         }
267 }