]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/BulletsModule.C
code cosmetics whitespace, unneeded lyx:: qualification, indentation, unneeded destru...
[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 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)),
54                 this, SLOT(showLevel(int)));
55         connect(bulletpaneCO, SIGNAL(activated(int)), bulletpaneSW,
56                 SLOT(setCurrentIndex(int)));
57 }
58
59
60 void BulletsModule::setupPanel(QListWidget * lw, QString const & panelname,
61         std::string const & fname)
62 {
63         connect(lw, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
64                 this, SLOT(bulletSelected(QListWidgetItem *, QListWidgetItem*)));
65
66         // add panelname to combox
67         bulletpaneCO->addItem(panelname);
68
69         // get pixmap with bullets
70         QPixmap pixmap = QPixmap(toqstr(libFileSearch("images", fname, "xpm").absFilename()));
71
72         int const w = pixmap.width() / 6;
73         int const h = pixmap.height() / 6;
74
75         // apply setting to listwidget
76         lw->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
77         lw->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
78         lw->setViewMode(QListView::IconMode);
79         lw->setFlow(QListView::LeftToRight);
80         lw->setMovement(QListView::Static);
81         lw->setUniformItemSizes(true);
82         lw->setGridSize(QSize(w, h));
83         // the widening by 21 is needed to avoid wrapping
84         lw->resize(6 * w + 21, 6 * h);
85         bulletpaneSW->setMinimumSize(6 * w, 6 * h + 6);
86
87         // get individual bullets from pixmap
88         for (int row = 0; row < 6; ++row) {
89                 for (int col = 0; col < 6; ++col) {
90                         QPixmap small(w, h);
91                         small.fill();
92                         QPainter painter(&small);
93                         painter.drawPixmap(small.rect(), pixmap, QRect(col * w, row * h, w, h));
94                         new QListWidgetItem(QIcon(small), "" , lw, (6 * row + col));
95                 }
96         }
97
98         // add bulletpanel to stackedwidget
99         bulletpaneSW->addWidget(lw);
100 }
101
102
103 void BulletsModule::showLevel(int level)
104 {
105         // unselect previous item
106         selectItem(current_font_, current_char_, false);
107
108         current_font_ = bullets_[level].getFont();
109
110         if (bullets_[level].getFont() < 0) {
111                 customCB->setCheckState(Qt::Checked);
112                 customLE->setText(toqstr(bullets_[level].getText()));
113         } else {
114                 customCB->setCheckState(Qt::Unchecked);
115                 customLE->clear();
116                 current_char_ = bullets_[level].getCharacter();
117                 selectItem(current_font_, current_char_, true);
118                 bulletpaneCO->setCurrentIndex(current_font_);
119                 bulletpaneSW->setCurrentIndex(current_font_);
120         }
121         bulletsizeCO->setCurrentIndex(bullets_[level].getSize() + 1);
122 }
123
124
125 void BulletsModule::init()
126 {
127         levelLW->setCurrentRow(0);
128         showLevel(0);
129 }
130
131
132 void BulletsModule::bulletSelected(QListWidgetItem * item, QListWidgetItem *)
133 {
134         // unselect previous item
135         selectItem(current_font_, current_char_, false);
136
137         int const level = levelLW->currentRow();
138         bullets_[level].setCharacter(item->type());
139         bullets_[level].setFont(bulletpaneCO->currentIndex());
140         current_font_ = bulletpaneCO->currentIndex();
141         current_char_ = item->type();
142         changed();
143 }
144
145
146 void BulletsModule::on_customCB_clicked(bool custom)
147 {
148         if (!custom) {
149                 if (current_font_ < 0)
150                         current_font_ = bulletpaneCO->currentIndex();
151                 return;
152         }
153                 
154         // unselect previous item
155         selectItem(current_font_, current_char_, false);
156         current_font_ = -1;
157         changed();
158 }
159
160
161 void BulletsModule::selectItem(int font, int character, bool select)
162 {
163         if (font < 0)
164                 return;
165
166         QListWidget * lw = static_cast<QListWidget *>(bulletpaneSW->widget(font));
167         lw->setItemSelected(lw->item(character), select);
168 }
169
170
171 void BulletsModule::on_customLE_textEdited(const QString & text)
172 {
173         if (customCB->checkState() == Qt::Unchecked)
174                 return;
175
176         bullets_[levelLW->currentRow()].setFont(current_font_);
177         bullets_[levelLW->currentRow()].setText(qstring_to_ucs4(text));
178         changed();
179 }
180
181
182 void BulletsModule::on_bulletsizeCO_activated(int size)
183 {
184         // -1 apparently means default...
185         bullets_[levelLW->currentRow()].setSize(size - 1);
186 }
187
188
189 void BulletsModule::setBullet(int level, Bullet const & bullet)
190 {
191         bullets_[level] = bullet;
192 }
193
194
195 Bullet const & BulletsModule::getBullet(int level) const
196 {
197         return bullets_[level];
198 }
199
200 } // namespace lyx
201
202
203 #include "BulletsModule_moc.cpp"