mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 21:40:19 +00:00
* furter simplifications:
- simplify setting/unsetting of item - consolidate 2 methods that set bulletSelected - store character (int) instead of pointer to item git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14672 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
bd61a7a387
commit
5d28253e20
@ -30,6 +30,8 @@ BulletsModule::BulletsModule(QWidget * , char const * , Qt::WFlags)
|
||||
for (int iter = 0; iter < 4; ++iter) {
|
||||
bullets_[iter] = ITEMIZE_DEFAULTS[iter];
|
||||
}
|
||||
current_font_ = -1;
|
||||
current_char_ = 0;
|
||||
|
||||
// add levels
|
||||
levelLW->addItem("1");
|
||||
@ -83,8 +85,7 @@ void BulletsModule::setupPanel(QListWidget * lw, QString panelname, std::string
|
||||
for (int row = 0; row < 6; ++row) {
|
||||
for (int col = 0; col < 6; ++col) {
|
||||
QPixmap small(w,h);
|
||||
// FIXME: how to get the good color?
|
||||
small.fill(QColor(Qt::white));
|
||||
small.fill();
|
||||
bitBlt(&small, 0, 0, &pixmap, col * w, row * h, w, h);
|
||||
new QListWidgetItem(QIcon(small), "" , lw, (6*row + col));
|
||||
}
|
||||
@ -97,16 +98,19 @@ void BulletsModule::setupPanel(QListWidget * lw, QString panelname, std::string
|
||||
|
||||
void BulletsModule::showLevel(int level)
|
||||
{
|
||||
unselectPreviousItem();
|
||||
// unselect previous item
|
||||
selectItem(current_font_, current_char_, false);
|
||||
|
||||
current_font_ = bullets_[level].getFont();
|
||||
|
||||
if (bullets_[level].getFont()<0) {
|
||||
customCB->setCheckState(Qt::Checked);
|
||||
customLE->setText(toqstr(bullets_[level].getText()));
|
||||
} else {
|
||||
selectBullet(level);
|
||||
customCB->setCheckState(Qt::Unchecked);
|
||||
customLE->clear();
|
||||
current_char_ = bullets_[level].getCharacter();
|
||||
selectItem(current_font_, current_char_, true);
|
||||
bulletpaneCO->setCurrentIndex(current_font_);
|
||||
bulletpaneSW->setCurrentIndex(current_font_);
|
||||
}
|
||||
@ -114,21 +118,6 @@ void BulletsModule::showLevel(int level)
|
||||
}
|
||||
|
||||
|
||||
void BulletsModule::selectBullet(int level)
|
||||
{
|
||||
int const bullet = bullets_[level].getCharacter();
|
||||
QListWidget * lw = static_cast<QListWidget *>(bulletpaneSW->widget(current_font_));
|
||||
// get all items (FIXME: is there a better way? this looks too complicated)
|
||||
QList<QListWidgetItem *> items = lw->findItems("", Qt::MatchContains);
|
||||
for (int i = 0 ; i < items.size() ; ++i) {
|
||||
if (items.at(i)->type() == bullet) {
|
||||
current_item_ = items.at(i);
|
||||
lw->setItemSelected(current_item_, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BulletsModule::init()
|
||||
{
|
||||
levelLW->setCurrentRow(0);
|
||||
@ -138,26 +127,18 @@ void BulletsModule::init()
|
||||
|
||||
void BulletsModule::bulletSelected(QListWidgetItem * item, QListWidgetItem *)
|
||||
{
|
||||
unselectPreviousItem();
|
||||
// unselect previous item
|
||||
selectItem(current_font_, current_char_, false);
|
||||
|
||||
int const level = levelLW->currentRow();
|
||||
bullets_[level].setCharacter(item->type());
|
||||
bullets_[level].setFont(bulletpaneCO->currentIndex());
|
||||
current_font_ = bulletpaneCO->currentIndex();
|
||||
current_item_ = item;
|
||||
current_char_ = item->type();
|
||||
changed();
|
||||
}
|
||||
|
||||
|
||||
void BulletsModule::unselectPreviousItem()
|
||||
{
|
||||
if (current_font_<0)
|
||||
return;
|
||||
|
||||
QListWidget * lw = static_cast<QListWidget *>(bulletpaneSW->widget(current_font_));
|
||||
lw->setItemSelected(current_item_, false);
|
||||
}
|
||||
|
||||
|
||||
void BulletsModule::on_customCB_toggled(bool custom)
|
||||
{
|
||||
if (!custom) {
|
||||
@ -166,12 +147,23 @@ void BulletsModule::on_customCB_toggled(bool custom)
|
||||
return;
|
||||
}
|
||||
|
||||
unselectPreviousItem();
|
||||
// unselect previous item
|
||||
selectItem(current_font_, current_char_, false);
|
||||
current_font_ = -1;
|
||||
changed();
|
||||
}
|
||||
|
||||
|
||||
void BulletsModule::selectItem(int font, int character, bool select)
|
||||
{
|
||||
if (font<0)
|
||||
return;
|
||||
|
||||
QListWidget * lw = static_cast<QListWidget *>(bulletpaneSW->widget(font));
|
||||
lw->setItemSelected(lw->item(character), select);
|
||||
}
|
||||
|
||||
|
||||
void BulletsModule::on_customLE_textEdited(const QString & text)
|
||||
{
|
||||
if (customCB->checkState() == Qt::Unchecked)
|
||||
|
@ -46,14 +46,13 @@ protected Q_SLOTS:
|
||||
void showLevel(int);
|
||||
|
||||
private:
|
||||
void unselectPreviousItem();
|
||||
void selectItem(int font, int character, bool select);
|
||||
void setupPanel(QListWidget * lw, QString panelname, std::string fname);
|
||||
void selectBullet(int level);
|
||||
|
||||
/// store results
|
||||
boost::array<Bullet, 4> bullets_;
|
||||
int current_font_;
|
||||
QListWidgetItem * current_item_;
|
||||
int current_char_;
|
||||
};
|
||||
|
||||
#endif // BULLETSMODULE_H
|
||||
|
Loading…
Reference in New Issue
Block a user