WImage *WItemDelegate::iconWidget(WidgetRef& w, bool autoCreate) { WImage *image = dynamic_cast<WImage *>(w.w->find("i")); if (image || !autoCreate) return image; WContainerWidget *wc = dynamic_cast<WContainerWidget *>(w.w->find("a")); if (!wc) wc = dynamic_cast<WContainerWidget *>(w.w->find("o")); if (!wc) { wc = new WContainerWidget(); wc->setObjectName("o"); wc->addWidget(w.w); w.w = wc; } image = new WImage(); image->setObjectName("i"); image->setStyleClass("icon"); wc->insertWidget(wc->count() - 1, image); // IE does not want to center vertically without this: if (wApp->environment().agentIsIE()) { WImage *inv = new WImage(wApp->onePixelGifUrl()); inv->setStyleClass("rh w0 icon"); inv->resize(0, WLength::Auto); wc->insertWidget(wc->count() -1, inv); } return image; }
IndexCheckBox *WItemDelegate::checkBox(WidgetRef& w, const WModelIndex& index, bool autoCreate, bool triState) { IndexCheckBox *checkBox = dynamic_cast<IndexCheckBox *>(w.w->find("c")); if (!checkBox) { if (autoCreate) { IndexCheckBox * const result = checkBox = new IndexCheckBox(index); checkBox->setObjectName("c"); checkBox->clicked().preventPropagation(); WContainerWidget *wc = dynamic_cast<WContainerWidget *>(w.w->find("o")); if (!wc) { wc = new WContainerWidget(); wc->setObjectName("o"); w.w->setInline(true); w.w->setStyleClass(WString::Empty); /* We first remove to avoid reparenting warnings */ WContainerWidget *p = dynamic_cast<WContainerWidget *>(w.w->parent()); if (p) p->removeWidget(w.w); wc->addWidget(w.w); w.w = wc; } wc->insertWidget(0, checkBox); checkBox->changed().connect (boost::bind(&WItemDelegate::onCheckedChange, this, result)); } else return 0; } checkBox->setTristate(triState); return checkBox; }