2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-04-26 03:53:02 +00:00
|
|
|
* \file BulletsModule.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Edwin Leuven
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "BulletsModule.h"
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
2006-05-08 11:44:37 +00:00
|
|
|
#include <QPixmap>
|
2006-08-15 14:55:34 +00:00
|
|
|
#include <QPainter>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
using namespace std;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2008-09-20 11:47:38 +00:00
|
|
|
BulletsModule::BulletsModule(QWidget * parent)
|
|
|
|
: QWidget(parent)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
2007-04-25 16:39:21 +00:00
|
|
|
for (int iter = 0; iter < 4; ++iter)
|
2006-03-05 17:24:44 +00:00
|
|
|
bullets_[iter] = ITEMIZE_DEFAULTS[iter];
|
2007-04-25 16:39:21 +00:00
|
|
|
|
2006-08-14 15:07:13 +00:00
|
|
|
current_font_ = -1;
|
|
|
|
current_char_ = 0;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-08-13 15:44:05 +00:00
|
|
|
// add levels
|
|
|
|
levelLW->addItem("1");
|
|
|
|
levelLW->addItem("2");
|
|
|
|
levelLW->addItem("3");
|
|
|
|
levelLW->addItem("4");
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// insert pixmaps
|
2007-08-31 11:09:46 +00:00
|
|
|
setupPanel(new QListWidget(bulletpaneSW), qt_("Standard[[Bullets]]"), "standard");
|
2006-08-13 15:44:05 +00:00
|
|
|
setupPanel(new QListWidget(bulletpaneSW), qt_("Maths"), "amssymb");
|
|
|
|
setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 1"), "psnfss1");
|
|
|
|
setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 2"), "psnfss2");
|
|
|
|
setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 3"), "psnfss3");
|
|
|
|
setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 4"), "psnfss4");
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-04-25 16:39:21 +00:00
|
|
|
connect(levelLW, SIGNAL(currentRowChanged(int)),
|
|
|
|
this, SLOT(showLevel(int)));
|
|
|
|
connect(bulletpaneCO, SIGNAL(activated(int)), bulletpaneSW,
|
|
|
|
SLOT(setCurrentIndex(int)));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-25 16:39:21 +00:00
|
|
|
void BulletsModule::setupPanel(QListWidget * lw, QString const & panelname,
|
2007-12-12 19:28:07 +00:00
|
|
|
string const & fname)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-12-30 10:30:02 +00:00
|
|
|
connect(lw, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
|
|
|
|
this, SLOT(bulletSelected(QListWidgetItem *, QListWidgetItem*)));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-08-13 15:44:05 +00:00
|
|
|
// add panelname to combox
|
|
|
|
bulletpaneCO->addItem(panelname);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-08-13 15:44:05 +00:00
|
|
|
// get pixmap with bullets
|
2007-10-17 18:28:45 +00:00
|
|
|
QPixmap pixmap(":/images/" + toqstr(fname) + ".png");
|
2007-03-27 06:55:25 +00:00
|
|
|
|
2006-08-13 15:44:05 +00:00
|
|
|
int const w = pixmap.width() / 6;
|
|
|
|
int const h = pixmap.height() / 6;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-08-13 15:44:05 +00:00
|
|
|
// apply setting to listwidget
|
|
|
|
lw->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
lw->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
lw->setViewMode(QListView::IconMode);
|
|
|
|
lw->setFlow(QListView::LeftToRight);
|
|
|
|
lw->setMovement(QListView::Static);
|
|
|
|
lw->setUniformItemSizes(true);
|
2007-03-27 06:55:25 +00:00
|
|
|
lw->setGridSize(QSize(w, h));
|
|
|
|
// the widening by 21 is needed to avoid wrapping
|
|
|
|
lw->resize(6 * w + 21, 6 * h);
|
2009-08-17 14:22:40 +00:00
|
|
|
bulletpaneSW->setMinimumSize(6 * w + 5, 6 * h + 6);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-08-13 15:44:05 +00:00
|
|
|
// get individual bullets from pixmap
|
|
|
|
for (int row = 0; row < 6; ++row) {
|
|
|
|
for (int col = 0; col < 6; ++col) {
|
2006-11-10 17:00:21 +00:00
|
|
|
QPixmap small(w, h);
|
2006-08-14 15:07:13 +00:00
|
|
|
small.fill();
|
2006-08-15 14:55:34 +00:00
|
|
|
QPainter painter(&small);
|
|
|
|
painter.drawPixmap(small.rect(), pixmap, QRect(col * w, row * h, w, h));
|
2006-11-10 17:00:21 +00:00
|
|
|
new QListWidgetItem(QIcon(small), "" , lw, (6 * row + col));
|
2006-08-13 15:44:05 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-08-13 15:44:05 +00:00
|
|
|
// add bulletpanel to stackedwidget
|
|
|
|
bulletpaneSW->addWidget(lw);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-13 15:44:05 +00:00
|
|
|
void BulletsModule::showLevel(int level)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-08-14 15:07:13 +00:00
|
|
|
// unselect previous item
|
|
|
|
selectItem(current_font_, current_char_, false);
|
|
|
|
|
2006-08-13 15:44:05 +00:00
|
|
|
current_font_ = bullets_[level].getFont();
|
|
|
|
|
2006-11-10 17:00:21 +00:00
|
|
|
if (bullets_[level].getFont() < 0) {
|
2006-08-13 15:44:05 +00:00
|
|
|
customCB->setCheckState(Qt::Checked);
|
|
|
|
customLE->setText(toqstr(bullets_[level].getText()));
|
|
|
|
} else {
|
|
|
|
customCB->setCheckState(Qt::Unchecked);
|
|
|
|
customLE->clear();
|
2006-08-14 15:07:13 +00:00
|
|
|
current_char_ = bullets_[level].getCharacter();
|
|
|
|
selectItem(current_font_, current_char_, true);
|
2006-08-13 15:44:05 +00:00
|
|
|
bulletpaneCO->setCurrentIndex(current_font_);
|
|
|
|
bulletpaneSW->setCurrentIndex(current_font_);
|
|
|
|
}
|
|
|
|
bulletsizeCO->setCurrentIndex(bullets_[level].getSize() + 1);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-13 15:44:05 +00:00
|
|
|
void BulletsModule::init()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-08-13 15:44:05 +00:00
|
|
|
levelLW->setCurrentRow(0);
|
|
|
|
showLevel(0);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-13 15:44:05 +00:00
|
|
|
void BulletsModule::bulletSelected(QListWidgetItem * item, QListWidgetItem *)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-08-14 15:07:13 +00:00
|
|
|
// unselect previous item
|
|
|
|
selectItem(current_font_, current_char_, false);
|
|
|
|
|
2006-08-13 15:44:05 +00:00
|
|
|
int const level = levelLW->currentRow();
|
|
|
|
bullets_[level].setCharacter(item->type());
|
|
|
|
bullets_[level].setFont(bulletpaneCO->currentIndex());
|
|
|
|
current_font_ = bulletpaneCO->currentIndex();
|
2006-08-14 15:07:13 +00:00
|
|
|
current_char_ = item->type();
|
2006-06-30 14:11:50 +00:00
|
|
|
changed();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-17 13:06:16 +00:00
|
|
|
void BulletsModule::on_customCB_clicked(bool custom)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-08-13 15:44:05 +00:00
|
|
|
if (!custom) {
|
2006-11-10 17:00:21 +00:00
|
|
|
if (current_font_ < 0)
|
2006-08-13 15:44:05 +00:00
|
|
|
current_font_ = bulletpaneCO->currentIndex();
|
2006-03-05 17:24:44 +00:00
|
|
|
return;
|
2006-08-13 15:44:05 +00:00
|
|
|
}
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2006-08-14 15:07:13 +00:00
|
|
|
// unselect previous item
|
|
|
|
selectItem(current_font_, current_char_, false);
|
2006-08-13 15:44:05 +00:00
|
|
|
current_font_ = -1;
|
2006-06-30 14:11:50 +00:00
|
|
|
changed();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-14 15:07:13 +00:00
|
|
|
void BulletsModule::selectItem(int font, int character, bool select)
|
|
|
|
{
|
2006-11-10 17:00:21 +00:00
|
|
|
if (font < 0)
|
2006-08-14 15:07:13 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
QListWidget * lw = static_cast<QListWidget *>(bulletpaneSW->widget(font));
|
|
|
|
lw->setItemSelected(lw->item(character), select);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-13 15:44:05 +00:00
|
|
|
void BulletsModule::on_customLE_textEdited(const QString & text)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-08-13 15:44:05 +00:00
|
|
|
if (customCB->checkState() == Qt::Unchecked)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bullets_[levelLW->currentRow()].setFont(current_font_);
|
2006-10-20 19:26:23 +00:00
|
|
|
bullets_[levelLW->currentRow()].setText(qstring_to_ucs4(text));
|
2006-08-13 15:44:05 +00:00
|
|
|
changed();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-13 15:44:05 +00:00
|
|
|
void BulletsModule::on_bulletsizeCO_activated(int size)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-08-13 15:44:05 +00:00
|
|
|
// -1 apparently means default...
|
|
|
|
bullets_[levelLW->currentRow()].setSize(size - 1);
|
2011-06-04 12:50:39 +00:00
|
|
|
changed();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-13 15:44:05 +00:00
|
|
|
void BulletsModule::setBullet(int level, Bullet const & bullet)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
bullets_[level] = bullet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-20 11:47:38 +00:00
|
|
|
Bullet const & BulletsModule::bullet(int level) const
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
return bullets_[level];
|
|
|
|
}
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_BulletsModule.cpp"
|