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