* 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:
Edwin Leuven 2006-08-14 15:07:13 +00:00
parent bd61a7a387
commit 5d28253e20
2 changed files with 26 additions and 35 deletions

View File

@ -30,6 +30,8 @@ BulletsModule::BulletsModule(QWidget * , char const * , Qt::WFlags)
for (int iter = 0; iter < 4; ++iter) { for (int iter = 0; iter < 4; ++iter) {
bullets_[iter] = ITEMIZE_DEFAULTS[iter]; bullets_[iter] = ITEMIZE_DEFAULTS[iter];
} }
current_font_ = -1;
current_char_ = 0;
// add levels // add levels
levelLW->addItem("1"); 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 row = 0; row < 6; ++row) {
for (int col = 0; col < 6; ++col) { for (int col = 0; col < 6; ++col) {
QPixmap small(w,h); QPixmap small(w,h);
// FIXME: how to get the good color? small.fill();
small.fill(QColor(Qt::white));
bitBlt(&small, 0, 0, &pixmap, col * w, row * h, w, h); bitBlt(&small, 0, 0, &pixmap, col * w, row * h, w, h);
new QListWidgetItem(QIcon(small), "" , lw, (6*row + col)); 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) void BulletsModule::showLevel(int level)
{ {
unselectPreviousItem(); // unselect previous item
selectItem(current_font_, current_char_, false);
current_font_ = bullets_[level].getFont(); current_font_ = bullets_[level].getFont();
if (bullets_[level].getFont()<0) { if (bullets_[level].getFont()<0) {
customCB->setCheckState(Qt::Checked); customCB->setCheckState(Qt::Checked);
customLE->setText(toqstr(bullets_[level].getText())); customLE->setText(toqstr(bullets_[level].getText()));
} else { } else {
selectBullet(level);
customCB->setCheckState(Qt::Unchecked); customCB->setCheckState(Qt::Unchecked);
customLE->clear(); customLE->clear();
current_char_ = bullets_[level].getCharacter();
selectItem(current_font_, current_char_, true);
bulletpaneCO->setCurrentIndex(current_font_); bulletpaneCO->setCurrentIndex(current_font_);
bulletpaneSW->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() void BulletsModule::init()
{ {
levelLW->setCurrentRow(0); levelLW->setCurrentRow(0);
@ -138,26 +127,18 @@ void BulletsModule::init()
void BulletsModule::bulletSelected(QListWidgetItem * item, QListWidgetItem *) void BulletsModule::bulletSelected(QListWidgetItem * item, QListWidgetItem *)
{ {
unselectPreviousItem(); // unselect previous item
selectItem(current_font_, current_char_, false);
int const level = levelLW->currentRow(); int const level = levelLW->currentRow();
bullets_[level].setCharacter(item->type()); bullets_[level].setCharacter(item->type());
bullets_[level].setFont(bulletpaneCO->currentIndex()); bullets_[level].setFont(bulletpaneCO->currentIndex());
current_font_ = bulletpaneCO->currentIndex(); current_font_ = bulletpaneCO->currentIndex();
current_item_ = item; current_char_ = item->type();
changed(); 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) void BulletsModule::on_customCB_toggled(bool custom)
{ {
if (!custom) { if (!custom) {
@ -166,12 +147,23 @@ void BulletsModule::on_customCB_toggled(bool custom)
return; return;
} }
unselectPreviousItem(); // unselect previous item
selectItem(current_font_, current_char_, false);
current_font_ = -1; current_font_ = -1;
changed(); 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) void BulletsModule::on_customLE_textEdited(const QString & text)
{ {
if (customCB->checkState() == Qt::Unchecked) if (customCB->checkState() == Qt::Unchecked)

View File

@ -46,14 +46,13 @@ protected Q_SLOTS:
void showLevel(int); void showLevel(int);
private: private:
void unselectPreviousItem(); void selectItem(int font, int character, bool select);
void setupPanel(QListWidget * lw, QString panelname, std::string fname); void setupPanel(QListWidget * lw, QString panelname, std::string fname);
void selectBullet(int level);
/// store results /// store results
boost::array<Bullet, 4> bullets_; boost::array<Bullet, 4> bullets_;
int current_font_; int current_font_;
QListWidgetItem * current_item_; int current_char_;
}; };
#endif // BULLETSMODULE_H #endif // BULLETSMODULE_H