2 * \file BulletsModule.C
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 lyx::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"), "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)), this, SLOT(showLevel(int)));
54 connect(bulletpaneCO, SIGNAL(activated(int)), bulletpaneSW, SLOT(setCurrentIndex(int)));
58 BulletsModule::~BulletsModule()
63 void BulletsModule::setupPanel(QListWidget * lw, QString panelname, std::string fname)
65 connect(lw, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
66 this, SLOT(bulletSelected(QListWidgetItem *, QListWidgetItem*)));
68 // add panelname to combox
69 bulletpaneCO->addItem(panelname);
71 // get pixmap with bullets
72 QPixmap pixmap = QPixmap(toqstr(libFileSearch("images", fname, "xpm").absFilename()));
74 int const w = pixmap.width() / 6;
75 int const h = pixmap.height() / 6;
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);
89 // get individual bullets from pixmap
90 for (int row = 0; row < 6; ++row) {
91 for (int col = 0; col < 6; ++col) {
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));
100 // add bulletpanel to stackedwidget
101 bulletpaneSW->addWidget(lw);
105 void BulletsModule::showLevel(int level)
107 // unselect previous item
108 selectItem(current_font_, current_char_, false);
110 current_font_ = bullets_[level].getFont();
112 if (bullets_[level].getFont() < 0) {
113 customCB->setCheckState(Qt::Checked);
114 customLE->setText(toqstr(bullets_[level].getText()));
116 customCB->setCheckState(Qt::Unchecked);
118 current_char_ = bullets_[level].getCharacter();
119 selectItem(current_font_, current_char_, true);
120 bulletpaneCO->setCurrentIndex(current_font_);
121 bulletpaneSW->setCurrentIndex(current_font_);
123 bulletsizeCO->setCurrentIndex(bullets_[level].getSize() + 1);
127 void BulletsModule::init()
129 levelLW->setCurrentRow(0);
134 void BulletsModule::bulletSelected(QListWidgetItem * item, QListWidgetItem *)
136 // unselect previous item
137 selectItem(current_font_, current_char_, false);
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();
148 void BulletsModule::on_customCB_clicked(bool custom)
151 if (current_font_ < 0)
152 current_font_ = bulletpaneCO->currentIndex();
156 // unselect previous item
157 selectItem(current_font_, current_char_, false);
163 void BulletsModule::selectItem(int font, int character, bool select)
168 QListWidget * lw = static_cast<QListWidget *>(bulletpaneSW->widget(font));
169 lw->setItemSelected(lw->item(character), select);
173 void BulletsModule::on_customLE_textEdited(const QString & text)
175 if (customCB->checkState() == Qt::Unchecked)
178 bullets_[levelLW->currentRow()].setFont(current_font_);
179 bullets_[levelLW->currentRow()].setText(qstring_to_ucs4(text));
184 void BulletsModule::on_bulletsizeCO_activated(int size)
186 // -1 apparently means default...
187 bullets_[levelLW->currentRow()].setSize(size - 1);
191 void BulletsModule::setBullet(int level, Bullet const & bullet)
193 bullets_[level] = bullet;
197 Bullet const & BulletsModule::getBullet(int level) const
199 return bullets_[level];
206 #include "BulletsModule_moc.cpp"