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"
22 BulletsModule::BulletsModule(QWidget * , char const * , Qt::WFlags)
26 for (int iter = 0; iter < 4; ++iter)
27 bullets_[iter] = ITEMIZE_DEFAULTS[iter];
33 levelLW->addItem("1");
34 levelLW->addItem("2");
35 levelLW->addItem("3");
36 levelLW->addItem("4");
39 setupPanel(new QListWidget(bulletpaneSW), qt_("Standard[[Bullets]]"), "standard");
40 setupPanel(new QListWidget(bulletpaneSW), qt_("Maths"), "amssymb");
41 setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 1"), "psnfss1");
42 setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 2"), "psnfss2");
43 setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 3"), "psnfss3");
44 setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 4"), "psnfss4");
46 connect(levelLW, SIGNAL(currentRowChanged(int)),
47 this, SLOT(showLevel(int)));
48 connect(bulletpaneCO, SIGNAL(activated(int)), bulletpaneSW,
49 SLOT(setCurrentIndex(int)));
53 void BulletsModule::setupPanel(QListWidget * lw, QString const & panelname,
54 std::string const & fname)
56 connect(lw, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
57 this, SLOT(bulletSelected(QListWidgetItem *, QListWidgetItem*)));
59 // add panelname to combox
60 bulletpaneCO->addItem(panelname);
62 // get pixmap with bullets
63 QPixmap pixmap(":/images/" + toqstr(fname) + ".png");
65 int const w = pixmap.width() / 6;
66 int const h = pixmap.height() / 6;
68 // apply setting to listwidget
69 lw->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
70 lw->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
71 lw->setViewMode(QListView::IconMode);
72 lw->setFlow(QListView::LeftToRight);
73 lw->setMovement(QListView::Static);
74 lw->setUniformItemSizes(true);
75 lw->setGridSize(QSize(w, h));
76 // the widening by 21 is needed to avoid wrapping
77 lw->resize(6 * w + 21, 6 * h);
78 bulletpaneSW->setMinimumSize(6 * w, 6 * h + 6);
80 // get individual bullets from pixmap
81 for (int row = 0; row < 6; ++row) {
82 for (int col = 0; col < 6; ++col) {
85 QPainter painter(&small);
86 painter.drawPixmap(small.rect(), pixmap, QRect(col * w, row * h, w, h));
87 new QListWidgetItem(QIcon(small), "" , lw, (6 * row + col));
91 // add bulletpanel to stackedwidget
92 bulletpaneSW->addWidget(lw);
96 void BulletsModule::showLevel(int level)
98 // unselect previous item
99 selectItem(current_font_, current_char_, false);
101 current_font_ = bullets_[level].getFont();
103 if (bullets_[level].getFont() < 0) {
104 customCB->setCheckState(Qt::Checked);
105 customLE->setText(toqstr(bullets_[level].getText()));
107 customCB->setCheckState(Qt::Unchecked);
109 current_char_ = bullets_[level].getCharacter();
110 selectItem(current_font_, current_char_, true);
111 bulletpaneCO->setCurrentIndex(current_font_);
112 bulletpaneSW->setCurrentIndex(current_font_);
114 bulletsizeCO->setCurrentIndex(bullets_[level].getSize() + 1);
118 void BulletsModule::init()
120 levelLW->setCurrentRow(0);
125 void BulletsModule::bulletSelected(QListWidgetItem * item, QListWidgetItem *)
127 // unselect previous item
128 selectItem(current_font_, current_char_, false);
130 int const level = levelLW->currentRow();
131 bullets_[level].setCharacter(item->type());
132 bullets_[level].setFont(bulletpaneCO->currentIndex());
133 current_font_ = bulletpaneCO->currentIndex();
134 current_char_ = item->type();
139 void BulletsModule::on_customCB_clicked(bool custom)
142 if (current_font_ < 0)
143 current_font_ = bulletpaneCO->currentIndex();
147 // unselect previous item
148 selectItem(current_font_, current_char_, false);
154 void BulletsModule::selectItem(int font, int character, bool select)
159 QListWidget * lw = static_cast<QListWidget *>(bulletpaneSW->widget(font));
160 lw->setItemSelected(lw->item(character), select);
164 void BulletsModule::on_customLE_textEdited(const QString & text)
166 if (customCB->checkState() == Qt::Unchecked)
169 bullets_[levelLW->currentRow()].setFont(current_font_);
170 bullets_[levelLW->currentRow()].setText(qstring_to_ucs4(text));
175 void BulletsModule::on_bulletsizeCO_activated(int size)
177 // -1 apparently means default...
178 bullets_[levelLW->currentRow()].setSize(size - 1);
182 void BulletsModule::setBullet(int level, Bullet const & bullet)
184 bullets_[level] = bullet;
188 Bullet const & BulletsModule::getBullet(int level) const
190 return bullets_[level];
196 #include "BulletsModule_moc.cpp"