]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/BulletsModule.C
* src/frontends/qt4/BulletModule.C: remove unneeded debug include.
[lyx.git] / src / frontends / qt4 / 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
13 #include "BulletsModule.h"
14 #include "qt_helpers.h"
15
16 #include "support/filetools.h"
17
18 #include <QPixmap>
19 #include <QPainter>
20
21 #include <boost/assert.hpp>
22
23 namespace lyx {
24
25 using lyx::support::libFileSearch;
26
27 using std::string;
28
29 BulletsModule::BulletsModule(QWidget * , char const * , Qt::WFlags)
30 {
31         setupUi(this);
32
33         for (int iter = 0; iter < 4; ++iter) {
34                 bullets_[iter] = ITEMIZE_DEFAULTS[iter];
35         }
36         current_font_ = -1;
37         current_char_ = 0;
38
39         // add levels
40         levelLW->addItem("1");
41         levelLW->addItem("2");
42         levelLW->addItem("3");
43         levelLW->addItem("4");
44
45         // insert pixmaps
46         setupPanel(new QListWidget(bulletpaneSW), qt_("Standard"), "standard");
47         setupPanel(new QListWidget(bulletpaneSW), qt_("Maths"), "amssymb");
48         setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 1"), "psnfss1");
49         setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 2"), "psnfss2");
50         setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 3"), "psnfss3");
51         setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 4"), "psnfss4");
52
53         connect(levelLW, SIGNAL(currentRowChanged(int)), this, SLOT(showLevel(int)));
54         connect(bulletpaneCO, SIGNAL(activated(int)), bulletpaneSW, SLOT(setCurrentIndex(int)));
55 }
56
57
58 BulletsModule::~BulletsModule()
59 {
60 }
61
62
63 void BulletsModule::setupPanel(QListWidget * lw, QString panelname, std::string fname)
64 {
65         connect(lw, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
66                 this, SLOT(bulletSelected(QListWidgetItem *, QListWidgetItem*)));
67
68         // add panelname to combox
69         bulletpaneCO->addItem(panelname);
70
71         // get pixmap with bullets
72         QPixmap pixmap = QPixmap(toqstr(libFileSearch("images", fname, "xpm").absFilename()));
73
74         int const w = pixmap.width() / 6;
75         int const h = pixmap.height() / 6;
76
77         // apply setting to listwidget
78         lw->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
79         lw->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
80         lw->setViewMode(QListView::IconMode);
81         lw->setFlow(QListView::LeftToRight);
82         lw->setMovement(QListView::Static);
83         lw->setUniformItemSizes(true);
84         lw->setGridSize(QSize(w, h));
85         // the widening by 21 is needed to avoid wrapping
86         lw->resize(6 * w + 21, 6 * h);
87         bulletpaneSW->setMinimumSize(6 * w, 6 * h + 6);
88
89         // get individual bullets from pixmap
90         for (int row = 0; row < 6; ++row) {
91                 for (int col = 0; col < 6; ++col) {
92                         QPixmap small(w, h);
93                         small.fill();
94                         QPainter painter(&small);
95                         painter.drawPixmap(small.rect(), pixmap, QRect(col * w, row * h, w, h));
96                         new QListWidgetItem(QIcon(small), "" , lw, (6 * row + col));
97                 }
98         }
99
100         // add bulletpanel to stackedwidget
101         bulletpaneSW->addWidget(lw);
102 }
103
104
105 void BulletsModule::showLevel(int level)
106 {
107         // unselect previous item
108         selectItem(current_font_, current_char_, false);
109
110         current_font_ = bullets_[level].getFont();
111
112         if (bullets_[level].getFont() < 0) {
113                 customCB->setCheckState(Qt::Checked);
114                 customLE->setText(toqstr(bullets_[level].getText()));
115         } else {
116                 customCB->setCheckState(Qt::Unchecked);
117                 customLE->clear();
118                 current_char_ = bullets_[level].getCharacter();
119                 selectItem(current_font_, current_char_, true);
120                 bulletpaneCO->setCurrentIndex(current_font_);
121                 bulletpaneSW->setCurrentIndex(current_font_);
122         }
123         bulletsizeCO->setCurrentIndex(bullets_[level].getSize() + 1);
124 }
125
126
127 void BulletsModule::init()
128 {
129         levelLW->setCurrentRow(0);
130         showLevel(0);
131 }
132
133
134 void BulletsModule::bulletSelected(QListWidgetItem * item, QListWidgetItem *)
135 {
136         // unselect previous item
137         selectItem(current_font_, current_char_, false);
138
139         int const level = levelLW->currentRow();
140         bullets_[level].setCharacter(item->type());
141         bullets_[level].setFont(bulletpaneCO->currentIndex());
142         current_font_ = bulletpaneCO->currentIndex();
143         current_char_ = item->type();
144         changed();
145 }
146
147
148 void BulletsModule::on_customCB_clicked(bool custom)
149 {
150         if (!custom) {
151                 if (current_font_ < 0)
152                         current_font_ = bulletpaneCO->currentIndex();
153                 return;
154         }
155                 
156         // unselect previous item
157         selectItem(current_font_, current_char_, false);
158         current_font_ = -1;
159         changed();
160 }
161
162
163 void BulletsModule::selectItem(int font, int character, bool select)
164 {
165         if (font < 0)
166                 return;
167
168         QListWidget * lw = static_cast<QListWidget *>(bulletpaneSW->widget(font));
169         lw->setItemSelected(lw->item(character), select);
170 }
171
172
173 void BulletsModule::on_customLE_textEdited(const QString & text)
174 {
175         if (customCB->checkState() == Qt::Unchecked)
176                 return;
177
178         bullets_[levelLW->currentRow()].setFont(current_font_);
179         bullets_[levelLW->currentRow()].setText(qstring_to_ucs4(text));
180         changed();
181 }
182
183
184 void BulletsModule::on_bulletsizeCO_activated(int size)
185 {
186         // -1 apparently means default...
187         bullets_[levelLW->currentRow()].setSize(size - 1);
188 }
189
190
191 void BulletsModule::setBullet(int level, Bullet const & bullet)
192 {
193         bullets_[level] = bullet;
194 }
195
196
197 Bullet const & BulletsModule::getBullet(int level) const
198 {
199         return bullets_[level];
200 }
201
202
203 } // namespace lyx
204
205
206 #include "BulletsModule_moc.cpp"
207
208