]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/BulletsModule.C
34b17505bc74eed9efe406ccd1da8ceb2505c47d
[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  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13 #include "qt_helpers.h"
14
15 #include "support/filetools.h"
16 #include "support/LAssert.h"
17
18 #include "QBrowseBox.h"
19 #include "BulletsModule.h"
20
21 #include <qinputdialog.h>
22 #include <qpopupmenu.h>
23 #include <qpushbutton.h>
24 #include <qcombobox.h>
25
26 using namespace lyx::support;
27
28 BulletsModule::BulletsModule(QWidget * parent,  const char * name, WFlags fl)
29         : BulletsModuleBase(parent, name, fl), tmpbulletset(0)
30 {
31         for (int iter = 0; iter < 4; ++iter) {
32                 bullets_[iter] = ITEMIZE_DEFAULTS[iter];
33         }
34
35         QPopupMenu * pm = new QPopupMenu(this);
36
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);
43
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);
50
51         pm1->insertItem(standard_);
52         pm2->insertItem(maths_);
53         pm3->insertItem(ding1_);
54         pm4->insertItem(ding2_);
55         pm5->insertItem(ding3_);
56         pm6->insertItem(ding4_);
57
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);
67
68         bullet1PB->setPopup(pm);
69         bullet2PB->setPopup(pm);
70         bullet3PB->setPopup(pm);
71         bullet4PB->setPopup(pm);
72
73         // insert pixmaps
74         string bmfile;
75         bmfile = LibFileSearch("images", "standard", "xpm");
76         standard_->insertItem(QPixmap(toqstr(bmfile)));
77
78         bmfile = LibFileSearch("images", "amssymb", "xpm");
79         maths_->insertItem(QPixmap(toqstr(bmfile)));
80
81         bmfile = LibFileSearch("images", "psnfss1", "xpm");
82         ding1_->insertItem(QPixmap(toqstr(bmfile)));
83
84         bmfile = LibFileSearch("images", "psnfss2", "xpm");
85         ding2_->insertItem(QPixmap(toqstr(bmfile)));
86
87         bmfile = LibFileSearch("images", "psnfss3", "xpm");
88         ding3_->insertItem(QPixmap(toqstr(bmfile)));
89
90         bmfile = LibFileSearch("images", "psnfss4", "xpm");
91         ding4_->insertItem(QPixmap(toqstr(bmfile)));
92
93         connect(standard_, SIGNAL(selected(int, int)),
94                 this, SLOT(standard(int, int)));
95
96         connect(maths_, SIGNAL(selected(int, int)),
97                 this, SLOT(maths(int, int)));
98
99         connect(ding1_, SIGNAL(selected(int, int)),
100                 this, SLOT(ding1(int, int)));
101
102         connect(ding2_, SIGNAL(selected(int, int)),
103                 this, SLOT(ding2(int, int)));
104
105         connect(ding3_, SIGNAL(selected(int, int)),
106                 this, SLOT(ding3(int, int)));
107
108         connect(ding4_, SIGNAL(selected(int, int)),
109                 this, SLOT(ding4(int, int)));
110
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()));
119
120         // update the view
121         for (int i = 0; i < 4; ++i)
122                 setBullet(bullet1PB, bulletsize1CO, bullets_[i]);
123 }
124
125
126 BulletsModule::~BulletsModule()
127 {
128 }
129
130
131 void BulletsModule::updateSizes()
132 {
133         emit changed();
134
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);
140 }
141
142
143 // These arrive *after* the menus have done their work
144 void BulletsModule::pressed1()
145 {
146         if (!tmpbulletset)
147                 return;
148         tmpbulletset = false;
149         bullets_[0] = tmpbullet;
150         setBullet(bullet1PB, bulletsize1CO, bullets_[0]);
151         emit changed();
152 }
153
154
155 void BulletsModule::pressed2()
156 {
157         if (!tmpbulletset)
158                 return;
159         tmpbulletset = false;
160         bullets_[1] = tmpbullet;
161         setBullet(bullet2PB, bulletsize2CO, bullets_[1]);
162         emit changed();
163 }
164
165
166 void BulletsModule::pressed3()
167 {
168         if (!tmpbulletset)
169                 return;
170         tmpbulletset = false;
171         bullets_[2] = tmpbullet;
172         setBullet(bullet3PB, bulletsize3CO, bullets_[2]);
173         emit changed();
174 }
175
176
177 void BulletsModule::pressed4()
178 {
179         if (!tmpbulletset)
180                 return;
181         tmpbulletset = false;
182         bullets_[3] = tmpbullet;
183         setBullet(bullet4PB, bulletsize4CO, bullets_[3]);
184         emit changed();
185 }
186
187
188 QPixmap BulletsModule::getPixmap(int font, int character)
189 {
190         int col = character % 6;
191         int row = (character - col) / 6;
192
193         switch (font) {
194         case 0:
195                 return standard_->pixmap(row,col);
196         case 1:
197                 return maths_->pixmap(row,col);
198         case 2:
199                 return ding1_->pixmap(row,col);
200         case 3:
201                 return ding2_->pixmap(row,col);
202         case 4:
203                 return ding3_->pixmap(row,col);
204         case 5:
205                 return ding4_->pixmap(row,col);
206         default:
207                 return standard_->pixmap(row,col);
208         }
209 }
210
211
212 void BulletsModule::setBullet(QPushButton * pb, QComboBox * co, Bullet const & b)
213 {
214         if (b.getFont() == -1) {
215                 pb->setPixmap(QPixmap());
216                 pb->setText("...");
217         } else {
218                 pb->setPixmap(getPixmap(b.getFont(), b.getCharacter()));
219         }
220
221         pb->setMinimumSize(QSize(50, 50));
222
223         co->setCurrentItem(b.getSize() + 1);
224 }
225
226
227 void BulletsModule::setBullet(int level, const Bullet & bullet)
228 {
229         bullets_[level] = bullet;
230
231         QPushButton * pb;
232         QComboBox * co;
233
234         switch (level) {
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;
240         }
241
242         setBullet(pb, co, bullet);
243 }
244
245
246 Bullet const BulletsModule::getBullet(int level)
247 {
248         return bullets_[level];
249 }
250
251
252 void BulletsModule::setCurrentBullet(int font, int character)
253 {
254         tmpbulletset = true;
255         tmpbullet.setFont(font);
256         tmpbullet.setCharacter(character);
257 }
258
259
260 void BulletsModule::standard(int row, int col)
261 {
262         setCurrentBullet(0, 6 * row + col);
263 }
264
265
266 void BulletsModule::maths(int row, int col)
267 {
268         setCurrentBullet(1, 6 * row + col);
269 }
270
271
272 void BulletsModule::ding1(int row, int col)
273 {
274         setCurrentBullet(2, 6 * row + col);
275 }
276
277
278 void BulletsModule::ding2(int row, int col)
279 {
280         setCurrentBullet(3, 6 * row + col);
281 }
282
283
284 void BulletsModule::ding3(int row, int col)
285 {
286         setCurrentBullet(4, 6 * row + col);
287 }
288
289
290 void BulletsModule::ding4(int row, int col)
291 {
292         setCurrentBullet(5, 6 * row + col);
293 }
294
295
296 void BulletsModule::setCustom()
297 {
298         bool ok = FALSE;
299         QString text = QInputDialog::getText(
300                 qt_( "Bullets" ),
301                 qt_( "Enter a custom bullet" ),
302                 QLineEdit::Normal,
303                 QString::null, &ok, this );
304
305         if (!ok)
306                 return;
307
308         tmpbulletset = true;
309         tmpbullet.setText(fromqstr(text));
310         tmpbullet.setFont(-1);
311 }