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"
23 BulletsModule::BulletsModule(QWidget * parent)
28 for (int iter = 0; iter < 4; ++iter)
29 bullets_[iter] = ITEMIZE_DEFAULTS[iter];
35 levelLW->addItem("1");
36 levelLW->addItem("2");
37 levelLW->addItem("3");
38 levelLW->addItem("4");
41 setupPanel(new QListWidget(bulletpaneSW), qt_("Standard[[Bullets]]"), "standard");
42 setupPanel(new QListWidget(bulletpaneSW), qt_("Maths"), "amssymb");
43 setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 1"), "psnfss1");
44 setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 2"), "psnfss2");
45 setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 3"), "psnfss3");
46 setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 4"), "psnfss4");
48 connect(levelLW, SIGNAL(currentRowChanged(int)),
49 this, SLOT(showLevel(int)));
50 connect(bulletpaneCO, SIGNAL(activated(int)), bulletpaneSW,
51 SLOT(setCurrentIndex(int)));
55 void BulletsModule::setupPanel(QListWidget * lw, QString const & panelname,
58 connect(lw, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
59 this, SLOT(bulletSelected(QListWidgetItem *, QListWidgetItem*)));
61 // add panelname to combox
62 bulletpaneCO->addItem(panelname);
64 // get pixmap with bullets
65 QPixmap pixmap(":/images/" + toqstr(fname) + ".png");
67 int const w = pixmap.width() / 6;
68 int const h = pixmap.height() / 6;
70 // apply setting to listwidget
71 lw->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
72 lw->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
73 lw->setViewMode(QListView::IconMode);
74 lw->setFlow(QListView::LeftToRight);
75 lw->setMovement(QListView::Static);
76 lw->setUniformItemSizes(true);
77 lw->setGridSize(QSize(w, h));
78 // the widening by 21 is needed to avoid wrapping
79 lw->resize(6 * w + 21, 6 * h);
80 bulletpaneSW->setMinimumSize(6 * w + 5, 6 * h + 6);
82 // get individual bullets from pixmap
83 for (int row = 0; row < 6; ++row) {
84 for (int col = 0; col < 6; ++col) {
87 QPainter painter(&small);
88 painter.drawPixmap(small.rect(), pixmap, QRect(col * w, row * h, w, h));
89 new QListWidgetItem(QIcon(small), "" , lw, (6 * row + col));
93 // add bulletpanel to stackedwidget
94 bulletpaneSW->addWidget(lw);
98 void BulletsModule::showLevel(int level)
100 // unselect previous item
101 selectItem(current_font_, current_char_, false);
103 current_font_ = bullets_[level].getFont();
105 if (bullets_[level].getFont() < 0) {
106 customCB->setCheckState(Qt::Checked);
107 customLE->setText(toqstr(bullets_[level].getText()));
109 customCB->setCheckState(Qt::Unchecked);
111 current_char_ = bullets_[level].getCharacter();
112 selectItem(current_font_, current_char_, true);
113 bulletpaneCO->setCurrentIndex(current_font_);
114 bulletpaneSW->setCurrentIndex(current_font_);
116 bulletsizeCO->setCurrentIndex(bullets_[level].getSize() + 1);
120 void BulletsModule::init()
122 levelLW->setCurrentRow(0);
127 void BulletsModule::bulletSelected(QListWidgetItem * item, QListWidgetItem *)
129 // unselect previous item
130 selectItem(current_font_, current_char_, false);
132 int const level = levelLW->currentRow();
133 bullets_[level].setCharacter(item->type());
134 bullets_[level].setFont(bulletpaneCO->currentIndex());
135 current_font_ = bulletpaneCO->currentIndex();
136 current_char_ = item->type();
141 void BulletsModule::on_customCB_clicked(bool custom)
144 if (current_font_ < 0)
145 current_font_ = bulletpaneCO->currentIndex();
149 // unselect previous item
150 selectItem(current_font_, current_char_, false);
156 void BulletsModule::selectItem(int font, int character, bool select)
161 QListWidget * lw = static_cast<QListWidget *>(bulletpaneSW->widget(font));
162 lw->setItemSelected(lw->item(character), select);
166 void BulletsModule::on_customLE_textEdited(const QString & text)
168 if (customCB->checkState() == Qt::Unchecked)
171 bullets_[levelLW->currentRow()].setFont(current_font_);
172 bullets_[levelLW->currentRow()].setText(qstring_to_ucs4(text));
177 void BulletsModule::on_bulletsizeCO_activated(int size)
179 // -1 apparently means default...
180 bullets_[levelLW->currentRow()].setSize(size - 1);
184 void BulletsModule::setBullet(int level, Bullet const & bullet)
186 bullets_[level] = bullet;
190 Bullet const & BulletsModule::bullet(int level) const
192 return bullets_[level];
198 #include "moc_BulletsModule.cpp"