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