KoResourcePopupAction::KoResourcePopupAction(QSharedPointer<KoAbstractResourceServerAdapter>resourceAdapter, QObject *parent) : KAction(parent) , d(new Private()) { Q_ASSERT(resourceAdapter); d->menu = new QMenu(); QWidget *widget = new QWidget(d->menu); QWidgetAction *wdgAction = new QWidgetAction(widget); d->resourceList = new KoResourceItemView(widget); d->resourceList->setModel(new KoResourceModel(resourceAdapter, widget)); d->resourceList->setItemDelegate(new KoResourceItemDelegate(widget)); KoResourceModel * resourceModel = qobject_cast<KoResourceModel*>(d->resourceList->model()); if (resourceModel) { resourceModel->setColumnCount(1); } KoResource *resource = 0; if (resourceAdapter->resources().count() > 0) { resource = resourceAdapter->resources().at(0); } KoAbstractGradient *gradient = dynamic_cast<KoAbstractGradient*>(resource); KoPattern *pattern = dynamic_cast<KoPattern*>(resource); if (gradient) { QGradient *qg = gradient->toQGradient(); qg->setCoordinateMode(QGradient::ObjectBoundingMode); d->background = QSharedPointer<KoShapeBackground>(new KoGradientBackground(qg)); } else if (pattern) { KoImageCollection *collection = new KoImageCollection(); d->background = QSharedPointer<KoShapeBackground>(new KoPatternBackground(collection)); static_cast<KoPatternBackground*>(d->background.data())->setPattern(pattern->pattern()); } QHBoxLayout *layout = new QHBoxLayout(widget); layout->addWidget(d->resourceList); widget->setLayout(layout); wdgAction->setDefaultWidget(widget); d->menu->addAction(wdgAction); setMenu(d->menu); new QHBoxLayout(d->menu); d->menu->layout()->addWidget(widget); d->menu->layout()->setMargin(0); connect(d->resourceList, SIGNAL(clicked(QModelIndex)), this, SLOT(indexChanged(QModelIndex))); updateIcon(); }
void updateIndex( KoResourceSelector * me ) { KoResourceModel * resourceModel = qobject_cast<KoResourceModel*>(me->model()); if (!resourceModel) return; if (!resourceModel->rowCount()) return; int currentIndex = me->currentIndex(); QModelIndex currentModelIndex = me->view()->currentIndex(); if (currentIndex < 0 || !currentModelIndex.isValid()) { me->blockSignals(true); me->view()->setCurrentIndex( resourceModel->index( 0, 0 ) ); me->setCurrentIndex(0); me->blockSignals(false); me->update(); } }
void KoResourceSelector::setColumnCount( int columnCount ) { KoResourceModel * resourceModel = qobject_cast<KoResourceModel*>(model()); if (resourceModel) resourceModel->setColumnCount( columnCount ); }