2 * \file BulletsModule.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "BulletsModule.h"
14 #include "qt_helpers.h"
16 #include "support/filetools.h"
21 #include <boost/assert.hpp>
25 using support::libFileSearch;
29 BulletsModule::BulletsModule(QWidget * , char const * , Qt::WFlags)
33 for (int iter = 0; iter < 4; ++iter)
34 bullets_[iter] = ITEMIZE_DEFAULTS[iter];
40 levelLW->addItem("1");
41 levelLW->addItem("2");
42 levelLW->addItem("3");
43 levelLW->addItem("4");
46 setupPanel(new QListWidget(bulletpaneSW), qt_("Standard[[Bullets]]"), "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");
53 connect(levelLW, SIGNAL(currentRowChanged(int)),
54 this, SLOT(showLevel(int)));
55 connect(bulletpaneCO, SIGNAL(activated(int)), bulletpaneSW,
56 SLOT(setCurrentIndex(int)));
60 void BulletsModule::setupPanel(QListWidget * lw, QString const & panelname,
61 std::string const & fname)
63 connect(lw, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
64 this, SLOT(bulletSelected(QListWidgetItem *, QListWidgetItem*)));
66 // add panelname to combox
67 bulletpaneCO->addItem(panelname);
69 // get pixmap with bullets
70 QPixmap pixmap = QPixmap(toqstr(libFileSearch("images", fname, "png").absFilename()));
72 int const w = pixmap.width() / 6;
73 int const h = pixmap.height() / 6;
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);
87 // get individual bullets from pixmap
88 for (int row = 0; row < 6; ++row) {
89 for (int col = 0; col < 6; ++col) {
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));
98 // add bulletpanel to stackedwidget
99 bulletpaneSW->addWidget(lw);
103 void BulletsModule::showLevel(int level)
105 // unselect previous item
106 selectItem(current_font_, current_char_, false);
108 current_font_ = bullets_[level].getFont();
110 if (bullets_[level].getFont() < 0) {
111 customCB->setCheckState(Qt::Checked);
112 customLE->setText(toqstr(bullets_[level].getText()));
114 customCB->setCheckState(Qt::Unchecked);
116 current_char_ = bullets_[level].getCharacter();
117 selectItem(current_font_, current_char_, true);
118 bulletpaneCO->setCurrentIndex(current_font_);
119 bulletpaneSW->setCurrentIndex(current_font_);
121 bulletsizeCO->setCurrentIndex(bullets_[level].getSize() + 1);
125 void BulletsModule::init()
127 levelLW->setCurrentRow(0);
132 void BulletsModule::bulletSelected(QListWidgetItem * item, QListWidgetItem *)
134 // unselect previous item
135 selectItem(current_font_, current_char_, false);
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();
146 void BulletsModule::on_customCB_clicked(bool custom)
149 if (current_font_ < 0)
150 current_font_ = bulletpaneCO->currentIndex();
154 // unselect previous item
155 selectItem(current_font_, current_char_, false);
161 void BulletsModule::selectItem(int font, int character, bool select)
166 QListWidget * lw = static_cast<QListWidget *>(bulletpaneSW->widget(font));
167 lw->setItemSelected(lw->item(character), select);
171 void BulletsModule::on_customLE_textEdited(const QString & text)
173 if (customCB->checkState() == Qt::Unchecked)
176 bullets_[levelLW->currentRow()].setFont(current_font_);
177 bullets_[levelLW->currentRow()].setText(qstring_to_ucs4(text));
182 void BulletsModule::on_bulletsizeCO_activated(int size)
184 // -1 apparently means default...
185 bullets_[levelLW->currentRow()].setSize(size - 1);
189 void BulletsModule::setBullet(int level, Bullet const & bullet)
191 bullets_[level] = bullet;
195 Bullet const & BulletsModule::getBullet(int level) const
197 return bullets_[level];
203 #include "BulletsModule_moc.cpp"