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")));
73 int const w = pixmap.width() / 6;
74 int const h = pixmap.height() / 6;
76 // apply setting to listwidget
77 lw->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
78 lw->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
79 lw->setViewMode(QListView::IconMode);
80 lw->setFlow(QListView::LeftToRight);
81 lw->setMovement(QListView::Static);
82 lw->setUniformItemSizes(true);
83 lw->setGridSize( QSize(w , h) );
84 lw->resize( 6 * w + 6 , 6* h);
85 bulletpaneSW->setMinimumSize( 6 * w + 6 , 6 * h);
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_toggled(bool custom)
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];
204 #include "BulletsModule_moc.cpp"