]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/BulletsModule.C
remove preamble dialog from the qt frontend
[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 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include <functional> // for operator %
19
20 #include <qinputdialog.h>
21 #include <qpopupmenu.h>
22 #include <qpixmap.h>
23 #include <qtoolbutton.h>
24 #include <qlistview.h>
25 #include <qcombobox.h>
26 #include <qlabel.h>
27 #include "BulletsModule.h"
28 #include "Bullet.h"
29 #include "ui/BulletsModuleBase.h"
30 #include "QBrowseBox.h"
31 #include "support/filetools.h"
32
33 BulletsModule::BulletsModule(QWidget * parent,  char const * name, WFlags fl)
34         : BulletsModuleBase(parent, name, fl)
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("Standard", pm1);
64         pm->insertItem("Maths", pm2);
65         pm->insertItem("Ding 1",pm3);
66         pm->insertItem("Ding 2",pm4);
67         pm->insertItem("Ding 3",pm5);
68         pm->insertItem("Ding 4",pm6);
69         pm->insertItem("Custom...", this, SLOT(setCustom()));
70
71         setbulletTB->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         // update the view
112         for (int iter = 0; iter < 4; ++iter) {
113                 setBullet(iter,bullets_[iter]);
114         }
115         activeitem_ = bulletsLV->firstChild();
116         activebullet_ = &bullets_[0];
117 }
118
119
120 BulletsModule::~BulletsModule()
121 {
122 }
123
124
125 QPixmap BulletsModule::getPixmap(int font, int character)
126 {
127         int col = character%6;
128         int row = (character - col)/6;
129         switch(font) {
130         case 0:
131                 return standard_->pixmap(row,col);
132         case 1:
133                 return maths_->pixmap(row,col);
134         case 2:
135                 return ding1_->pixmap(row,col);
136         case 3:
137                 return ding2_->pixmap(row,col);
138         case 4:
139                 return ding3_->pixmap(row,col);
140         case 5:
141                 return ding4_->pixmap(row,col);
142         default:
143                 return standard_->pixmap(row,col);
144         }
145 }
146
147
148 QListViewItem *  BulletsModule::getItem(int level)
149 {
150         QListViewItemIterator it(bulletsLV->firstChild());
151         for(int i=0; i<level; ++i) {
152                 ++it;
153         }
154         return it.current();
155 }
156
157
158 void BulletsModule::setActive(int level)
159 {
160         activeitem_ = getItem(level);
161         activebullet_ = &bullets_[level];
162 }
163
164
165 void BulletsModule::setActive(QListViewItem * item)
166 {
167         activeitem_ = item;
168         activebullet_ = &bullets_[item->depth()];
169 }
170
171
172 void BulletsModule::setBullet(int font, int character)
173 {
174         activeitem_->setText(0,"");
175         activeitem_->setPixmap(0,getPixmap(font,character));
176         
177         activebullet_->setFont(font);
178         activebullet_->setCharacter(character);
179 }
180
181
182 void BulletsModule::setBullet(string text)
183 {
184         activeitem_->setPixmap(0, QPixmap());
185         activeitem_->setText(0, toqstr(text));
186         
187         activebullet_->setText(text);
188 }
189
190
191 void BulletsModule::setBullet(int level, const Bullet & bullet)
192 {
193         setActive(level);
194         bullets_[level] = bullet;
195         // set size
196         setSize(bullet.getSize()+1);
197         // set pixmap
198         if (bullet.getFont()!=-1) {
199                 setBullet(bullet.getFont(),
200                           bullet.getCharacter());
201         } else {
202                 setBullet(bullet.getText());
203         }
204 }
205
206
207 Bullet BulletsModule::getBullet(int level)
208 {
209         return bullets_[level];
210 }
211
212
213 void BulletsModule::setSize(int size)
214 {
215         activeitem_->setText(1,bulletsizeCO->text(size));
216         activebullet_->setSize(size-1);
217 }
218
219
220 void BulletsModule::standard(int row, int col)
221 {
222         setBullet(0,6*row + col);
223 }
224
225 void BulletsModule::maths(int row, int col)
226 {
227         setBullet(1,6*row + col);
228 }
229
230
231 void BulletsModule::ding1(int row, int col)
232 {
233         setBullet(2,6*row + col);
234 }
235
236
237 void BulletsModule::ding2(int row, int col)
238 {
239         setBullet(3,6*row + col);
240 }
241
242
243 void BulletsModule::ding3(int row, int col)
244 {
245         setBullet(4,6*row + col);
246 }       
247
248
249 void BulletsModule::ding4(int row, int col)
250 {
251         setBullet(5,6*row + col);
252 }
253
254
255 void BulletsModule::setCustom()
256 {
257         bool ok = FALSE;
258         QString text = QInputDialog::getText(
259                 qt_( "Bullets" ),
260                 qt_( "Enter a custom bullet" ),
261                 QLineEdit::Normal,
262                 QString::null, &ok, this );
263
264         if (ok) {
265                 activeitem_->setPixmap(0,QPixmap());
266                 activeitem_->setText(0,text);
267                 activebullet_->setText(fromqstr(text));
268                 activebullet_->setFont(-1);
269         }
270 }