X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FBulletsModule.C;h=7704b80261c2a231affd23c6dc4a3202e5b4f7dd;hb=c6b932f4677029826468e65f63d8ed4660ef9296;hp=a106823e0e651664417674caf27f5a3ca8c14540;hpb=1a08a29b0ffdd8a2900597a73298a22ca18e64df;p=lyx.git diff --git a/src/frontends/qt4/BulletsModule.C b/src/frontends/qt4/BulletsModule.C index a106823e0e..7704b80261 100644 --- a/src/frontends/qt4/BulletsModule.C +++ b/src/frontends/qt4/BulletsModule.C @@ -16,10 +16,13 @@ #include "support/filetools.h" #include +#include #include -using lyx::support::libFileSearch; +namespace lyx { + +using support::libFileSearch; using std::string; @@ -27,9 +30,11 @@ BulletsModule::BulletsModule(QWidget * , char const * , Qt::WFlags) { setupUi(this); - for (int iter = 0; iter < 4; ++iter) { + for (int iter = 0; iter < 4; ++iter) bullets_[iter] = ITEMIZE_DEFAULTS[iter]; - } + + current_font_ = -1; + current_char_ = 0; // add levels levelLW->addItem("1"); @@ -45,17 +50,15 @@ BulletsModule::BulletsModule(QWidget * , char const * , Qt::WFlags) setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 3"), "psnfss3"); setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 4"), "psnfss4"); - connect(levelLW, SIGNAL(currentRowChanged(int)), this, SLOT(showLevel(int))); - connect(bulletpaneCO, SIGNAL(activated(int)), bulletpaneSW, SLOT(setCurrentIndex(int))); -} - - -BulletsModule::~BulletsModule() -{ + connect(levelLW, SIGNAL(currentRowChanged(int)), + this, SLOT(showLevel(int))); + connect(bulletpaneCO, SIGNAL(activated(int)), bulletpaneSW, + SLOT(setCurrentIndex(int))); } -void BulletsModule::setupPanel(QListWidget * lw, QString panelname, std::string fname) +void BulletsModule::setupPanel(QListWidget * lw, QString const & panelname, + std::string const & fname) { connect(lw, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(bulletSelected(QListWidgetItem *, QListWidgetItem*))); @@ -64,7 +67,8 @@ void BulletsModule::setupPanel(QListWidget * lw, QString panelname, std::string bulletpaneCO->addItem(panelname); // get pixmap with bullets - QPixmap pixmap = QPixmap(toqstr(libFileSearch("images", fname, "xpm"))); + QPixmap pixmap = QPixmap(toqstr(libFileSearch("images", fname, "xpm").absFilename())); + int const w = pixmap.width() / 6; int const h = pixmap.height() / 6; @@ -75,18 +79,19 @@ void BulletsModule::setupPanel(QListWidget * lw, QString panelname, std::string lw->setFlow(QListView::LeftToRight); lw->setMovement(QListView::Static); lw->setUniformItemSizes(true); - lw->setGridSize( QSize(w , h) ); - lw->resize( 6 * w + 6 , 6* h); - bulletpaneSW->setMinimumSize( 6 * w + 6 , 6 * h); + lw->setGridSize(QSize(w, h)); + // the widening by 21 is needed to avoid wrapping + lw->resize(6 * w + 21, 6 * h); + bulletpaneSW->setMinimumSize(6 * w, 6 * h + 6); // get individual bullets from pixmap 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)); - bitBlt(&small, 0, 0, &pixmap, col * w, row * h, w, h); - new QListWidgetItem(QIcon(small), "" , lw, (6*row + col)); + QPixmap small(w, h); + small.fill(); + QPainter painter(&small); + painter.drawPixmap(small.rect(), pixmap, QRect(col * w, row * h, w, h)); + new QListWidgetItem(QIcon(small), "" , lw, (6 * row + col)); } } @@ -97,16 +102,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) { + 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 +122,6 @@ void BulletsModule::showLevel(int level) } -void BulletsModule::selectBullet(int level) -{ - int const bullet = bullets_[level].getCharacter(); - QListWidget * lw = static_cast(bulletpaneSW->widget(current_font_)); - // get all items (FIXME: is there a better way? this looks too complicated) - QList 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,47 +131,50 @@ 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(bulletpaneSW->widget(current_font_)); - lw->setItemSelected(current_item_, false); -} - - -void BulletsModule::on_customCB_toggled(bool custom) +void BulletsModule::on_customCB_clicked(bool custom) { if (!custom) { - if (current_font_<0) + if (current_font_ < 0) current_font_ = bulletpaneCO->currentIndex(); 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(bulletpaneSW->widget(font)); + lw->setItemSelected(lw->item(character), select); +} + + void BulletsModule::on_customLE_textEdited(const QString & text) { if (customCB->checkState() == Qt::Unchecked) return; bullets_[levelLW->currentRow()].setFont(current_font_); - bullets_[levelLW->currentRow()].setText(fromqstr(text)); + bullets_[levelLW->currentRow()].setText(qstring_to_ucs4(text)); changed(); } @@ -201,5 +197,7 @@ Bullet const & BulletsModule::getBullet(int level) const return bullets_[level]; } +} // namespace lyx + #include "BulletsModule_moc.cpp"