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 * , char const * , Qt::WFlags)
27 for (int iter = 0; iter < 4; ++iter)
28 bullets_[iter] = ITEMIZE_DEFAULTS[iter];
34 levelLW->addItem("1");
35 levelLW->addItem("2");
36 levelLW->addItem("3");
37 levelLW->addItem("4");
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");
47 connect(levelLW, SIGNAL(currentRowChanged(int)),
48 this, SLOT(showLevel(int)));
49 connect(bulletpaneCO, SIGNAL(activated(int)), bulletpaneSW,
50 SLOT(setCurrentIndex(int)));
54 void BulletsModule::setupPanel(QListWidget * lw, QString const & panelname,
57 connect(lw, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
58 this, SLOT(bulletSelected(QListWidgetItem *, QListWidgetItem*)));
60 // add panelname to combox
61 bulletpaneCO->addItem(panelname);
63 // get pixmap with bullets
64 QPixmap pixmap(":/images/" + toqstr(fname) + ".png");
66 int const w = pixmap.width() / 6;
67 int const h = pixmap.height() / 6;
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);
81 // get individual bullets from pixmap
82 for (int row = 0; row < 6; ++row) {
83 for (int col = 0; col < 6; ++col) {
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));
92 // add bulletpanel to stackedwidget
93 bulletpaneSW->addWidget(lw);
97 void BulletsModule::showLevel(int level)
99 // unselect previous item
100 selectItem(current_font_, current_char_, false);
102 current_font_ = bullets_[level].getFont();
104 if (bullets_[level].getFont() < 0) {
105 customCB->setCheckState(Qt::Checked);
106 customLE->setText(toqstr(bullets_[level].getText()));
108 customCB->setCheckState(Qt::Unchecked);
110 current_char_ = bullets_[level].getCharacter();
111 selectItem(current_font_, current_char_, true);
112 bulletpaneCO->setCurrentIndex(current_font_);
113 bulletpaneSW->setCurrentIndex(current_font_);
115 bulletsizeCO->setCurrentIndex(bullets_[level].getSize() + 1);
119 void BulletsModule::init()
121 levelLW->setCurrentRow(0);
126 void BulletsModule::bulletSelected(QListWidgetItem * item, QListWidgetItem *)
128 // unselect previous item
129 selectItem(current_font_, current_char_, false);
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();
140 void BulletsModule::on_customCB_clicked(bool custom)
143 if (current_font_ < 0)
144 current_font_ = bulletpaneCO->currentIndex();
148 // unselect previous item
149 selectItem(current_font_, current_char_, false);
155 void BulletsModule::selectItem(int font, int character, bool select)
160 QListWidget * lw = static_cast<QListWidget *>(bulletpaneSW->widget(font));
161 lw->setItemSelected(lw->item(character), select);
165 void BulletsModule::on_customLE_textEdited(const QString & text)
167 if (customCB->checkState() == Qt::Unchecked)
170 bullets_[levelLW->currentRow()].setFont(current_font_);
171 bullets_[levelLW->currentRow()].setText(qstring_to_ucs4(text));
176 void BulletsModule::on_bulletsizeCO_activated(int size)
178 // -1 apparently means default...
179 bullets_[levelLW->currentRow()].setSize(size - 1);
183 void BulletsModule::setBullet(int level, Bullet const & bullet)
185 bullets_[level] = bullet;
189 Bullet const & BulletsModule::getBullet(int level) const
191 return bullets_[level];
197 #include "BulletsModule_moc.cpp"