void ScriptDelegate::updateItemWidgets(const QList< QWidget* > widgets, const QStyleOptionViewItem& option, const QPersistentModelIndex& index) const { QCheckBox* check_box = static_cast<QCheckBox*>(widgets[0]); check_box->resize(check_box->sizeHint()); int x = MARGIN; check_box->move(x, option.rect.height() / 2 - check_box->sizeHint().height() / 2); QPushButton* about_button = static_cast<QPushButton*>(widgets[2]); QSize about_size_hint = about_button->sizeHint(); about_button->resize(about_size_hint); x = option.rect.width() - MARGIN - about_size_hint.width(); about_button->move(x, option.rect.height() / 2 - about_size_hint.height() / 2); QPushButton* configure_button = static_cast<QPushButton*>(widgets[1]); QSize configure_size_hint = configure_button->sizeHint(); configure_button->resize(configure_size_hint); x = option.rect.width() - MARGIN * 2 - configure_size_hint.width() - about_size_hint.width(); configure_button->move(x, option.rect.height() / 2 - configure_size_hint.height() / 2); if (!index.isValid()) { check_box->setVisible(false); about_button->setVisible(false); configure_button->setVisible(false); } else { check_box->setChecked(index.model()->data(index, Qt::CheckStateRole).toBool()); check_box->setEnabled(true); configure_button->setVisible(true); configure_button->setEnabled(index.model()->data(index, ScriptModel::ConfigurableRole).toBool()); } }
void MicroblogDelegate::updateItemWidgets( const QList<QWidget*> widgets, const QStyleOptionViewItem &option, const QPersistentModelIndex &index ) const { Q_UNUSED( option ); if ( !index.isValid() ) { return; } const BlogModel* model = static_cast<const BlogModel*>( index.model() ); int row = index.row(); QWebView *edit = static_cast<QWebView*>( widgets[0] ); edit->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks ); edit->move( 5, 5 ); edit->resize( 400,200 ); QString text; text.append( "<table><tr><td><img src=\"" + this->getData( model, row, BlogModel::Picture ).toString() + "\"></td>" ); text.append( "<td>" + getData( model, row, BlogModel::Date ).toString() ); text.append( "<Br>" + getData( model, row, BlogModel::User ).toString() ); text.append( "</td></tr></table>" ); text.append( "<Br>" + getData( model, row, BlogModel::Text ).toString() ); //kDebug() << text; edit->setHtml( text ); }
void MainWindow::slotAltitudeRequestsReady(const QList<int>& readyRequests) { qDebug() << readyRequests.count() << " items ready!"; LookupAltitude* const myAltitudeLookup = qobject_cast<LookupAltitude*>(sender()); if (!myAltitudeLookup) { return; } for (int i = 0; i < readyRequests.count(); ++i) { const GeoIface::LookupAltitude::Request& myLookup = myAltitudeLookup->getRequest(readyRequests.at(i)); const QPersistentModelIndex markerIndex = myLookup.data.value<QPersistentModelIndex>(); if (!markerIndex.isValid()) { continue; } /// @todo Why does the index return a const model??? const QAbstractItemModel* const itemModel = markerIndex.model(); const_cast<QAbstractItemModel*>(itemModel)->setData(markerIndex, QVariant::fromValue(myLookup.coordinates), RoleCoordinates); } }
MsgPartNetworkReply::MsgPartNetworkReply(MsgPartNetAccessManager *parent, const QPersistentModelIndex &part): QNetworkReply(parent), part(part) { QUrl url; url.setScheme(QStringLiteral("trojita-imap")); url.setHost(QStringLiteral("msg")); url.setPath(part.data(Imap::Mailbox::RolePartPathToPart).toString()); setUrl(url); setOpenMode(QIODevice::ReadOnly | QIODevice::Unbuffered); Q_ASSERT(part.isValid()); connect(part.model(), &QAbstractItemModel::dataChanged, this, &MsgPartNetworkReply::slotModelDataChanged); // We have to ask for contents before we check whether it's already fetched part.data(Imap::Mailbox::RolePartData); // The part data might be already unavailable or already fetched QTimer::singleShot(0, this, SLOT(slotMyDataChanged())); QByteArray* bufferPtr = part.data(Imap::Mailbox::RolePartBufferPtr).value<QByteArray*>(); Q_ASSERT(bufferPtr); buffer.setBuffer(bufferPtr); buffer.open(QIODevice::ReadOnly); }
QPixmap KipiImageModel::getPixmapForIndex(const QPersistentModelIndex& itemIndex, const int size) { if (itemIndex.isValid()) { Q_ASSERT(itemIndex.model()==this); } // TODO: should we cache the pixmap on our own here or does the interface usually cache it for us? // TODO: do we need to make sure we do not request the same pixmap twice in a row? // construct the key under which we stored the pixmap in the cache: KipiImageItem* const imageItem = itemFromIndex(itemIndex); if (!imageItem) return QPixmap(); const QString itemKeyString = CacheKeyFromSizeAndUrl(size, imageItem->url()); QPixmap thumbnailPixmap; const bool havePixmapInCache = d->pixmapCache->find(itemKeyString, thumbnailPixmap); // kDebug()<<imageItem->url()<<size<<havePixmapInCache<<d->pixmapCache->isEnabled(); if (havePixmapInCache) return thumbnailPixmap; // did we already request this pixmap at this size? for (int i=0; i<d->requestedPixmaps.count(); ++i) { if (d->requestedPixmaps.at(i).first==itemIndex) { if (d->requestedPixmaps.at(i).second==size) { // the pixmap has already been requested, at this size return QPixmap(); } } } // remember at which size the pixmap was ordered: d->requestedPixmaps << QPair<QPersistentModelIndex, int>(itemIndex, size); // TODO: what about raw images? The old version of the plugin had a special loading mechanism for those if (d->interface) { d->interface->thumbnails(KUrl::List()<<imageItem->url(), size); } else { // KIO::PreviewJob *job = KIO::filePreview(urls, DEFAULTSIZE); // // connect(job, SIGNAL(gotPreview(KFileItem,QPixmap)), // this, SLOT(slotKDEPreview(KFileItem,QPixmap))); // // connect(job, SIGNAL(failed(KFileItem)), // this, SLOT(slotKDEPreviewFailed(KFileItem))); } return QPixmap(); }
void GPSSyncKGeoMapModelHelper::onIndicesMoved(const QList<QPersistentModelIndex>& movedMarkers, const GeoCoordinates& targetCoordinates, const QPersistentModelIndex& targetSnapIndex) { if (targetSnapIndex.isValid()) { const QAbstractItemModel* const targetModel = targetSnapIndex.model(); for (int i=0; i<d->ungroupedModelHelpers.count(); ++i) { ModelHelper* const ungroupedHelper = d->ungroupedModelHelpers.at(i); if (ungroupedHelper->model()==targetModel) { QList<QModelIndex> iMovedMarkers; for (int i=0; i<movedMarkers.count(); ++i) { iMovedMarkers << movedMarkers.at(i); } ungroupedHelper->snapItemsTo(targetSnapIndex, iMovedMarkers); return; } } } GPSUndoCommand* const undoCommand = new GPSUndoCommand(); for (int i=0; i<movedMarkers.count(); ++i) { const QPersistentModelIndex itemIndex = movedMarkers.at(i); KipiImageItem* const item = static_cast<KipiImageItem*>(d->model->itemFromIndex(itemIndex)); GPSUndoCommand::UndoInfo undoInfo(itemIndex); undoInfo.readOldDataFromItem(item); GPSDataContainer newData; newData.setCoordinates(targetCoordinates); item->setGPSData(newData); undoInfo.readNewDataFromItem(item); undoCommand->addUndoInfo(undoInfo); } undoCommand->setText(i18np("1 image moved", "%1 images moved", movedMarkers.count())); emit(signalUndoCommand(undoCommand)); }
void PluginListWidgetItemDelegate::updateItemWidgets(const QList<QWidget *> widgets, const QStyleOptionViewItem &option, const QPersistentModelIndex &index) const { auto checkBox = static_cast<QCheckBox*>(widgets[0]); checkBox->resize(checkBox->sizeHint()); checkBox->move(m_pluginSelector->dependantLayoutValue(MARGIN, checkBox->sizeHint().width(), option.rect.width()), option.rect.height() / 2 - checkBox->sizeHint().height() / 2); auto aboutPushButton = static_cast<QPushButton*>(widgets[1]); auto aboutPushButtonSizeHint = aboutPushButton->sizeHint(); aboutPushButton->resize(aboutPushButtonSizeHint); aboutPushButton->move(m_pluginSelector->dependantLayoutValue(option.rect.width() - MARGIN - aboutPushButtonSizeHint.width(), aboutPushButtonSizeHint.width(), option.rect.width()), option.rect.height() / 2 - aboutPushButtonSizeHint.height() / 2); if (!index.isValid() || !index.internalPointer()) { checkBox->setVisible(false); aboutPushButton->setVisible(false); } else checkBox->setChecked(index.model()->data(index, Qt::CheckStateRole).toBool()); }
void ServiceItemDelegate::updateItemWidgets(const QList<QWidget*> widgets, const QStyleOptionViewItem& option, const QPersistentModelIndex& index) const { QCheckBox* checkBox = static_cast<QCheckBox*>(widgets[0]); KPushButton *configureButton = static_cast<KPushButton*>(widgets[1]); const int itemHeight = sizeHint(option, index).height(); // Update the checkbox showing the service name and icon const QAbstractItemModel* model = index.model(); checkBox->setText(model->data(index).toString()); const QString iconName = model->data(index, Qt::DecorationRole).toString(); if (!iconName.isEmpty()) { checkBox->setIcon(KIcon(iconName)); } checkBox->setChecked(model->data(index, Qt::CheckStateRole).toBool()); const bool configurable = model->data(index, ServiceModel::ConfigurableRole).toBool(); int checkBoxWidth = option.rect.width(); if (configurable) { checkBoxWidth -= configureButton->sizeHint().width(); } checkBox->resize(checkBoxWidth, checkBox->sizeHint().height()); checkBox->move(0, (itemHeight - checkBox->height()) / 2); // Update the configuration button if (configurable) { configureButton->setEnabled(checkBox->isChecked()); configureButton->setIcon(KIcon("configure")); configureButton->resize(configureButton->sizeHint()); configureButton->move(option.rect.right() - configureButton->width(), (itemHeight - configureButton->height()) / 2); } configureButton->setVisible(configurable); }
QPixmap GPSImageModel::getPixmapForIndex(const QPersistentModelIndex& itemIndex, const int size) { if (itemIndex.isValid()) { Q_ASSERT(itemIndex.model() == this); } // TODO: should we cache the pixmap on our own here or does the interface usually cache it for us? // TODO: do we need to make sure we do not request the same pixmap twice in a row? // construct the key under which we stored the pixmap in the cache: GPSImageItem* const imageItem = itemFromIndex(itemIndex); if (!imageItem) return QPixmap(); QPixmap thumbnail; if (d->thumbnailLoadThread->find(ThumbnailIdentifier(imageItem->url().toLocalFile()), thumbnail, size)) { return thumbnail.copy(1, 1, thumbnail.size().width()-2, thumbnail.size().height()-2); } return QPixmap(); }
void ItemsViewDelegate::updateItemWidgets( const QList<QWidget*> widgets, const QStyleOptionViewItem& option, const QPersistentModelIndex& index ) const { const GluonPlayer::GameItemsModel* model = qobject_cast<const GluonPlayer::GameItemsModel*>( index.model() ); if( !model ) { kDebug() << "Warning - Invalid Model!"; return; } // setup the install button int margin = option.fontMetrics.height() / 2; int right = option.rect.width(); const_cast<QSize&>( m_buttonSize ) = QSize( 32, 32 ); KPushButton* playButton = qobject_cast<KPushButton*>( widgets.at( DelegatePlayButton ) ); if( playButton ) { playButton->setIcon( KIcon( "media-playback-start" ) ); playButton->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::MinimumExpanding ); playButton->resize( m_buttonSize ); playButton->move( right - playButton->width() - margin, option.fontMetrics.height() + playButton->height() * 0.5 ); } GameTextLabel* gameName = qobject_cast<GameTextLabel*>( widgets.at( DelegateGameName ) ); // gameName->setWordWrap(true); if( gameName ) { gameName->move( margin + m_buttonSize.width() * 3, option.fontMetrics.height() ); gameName->resize( QSize( option.rect.width() - ( margin * 4 ) - m_buttonSize.width() * 4, option.fontMetrics.height() * 2 ) ); gameName->setText( index.data( GluonPlayer::GameItemsModel::GameNameRole ).toString() ); } GameTextLabel* gameDescription = qobject_cast<GameTextLabel*>( widgets.at( DelegateGameDescription ) ); // gameName->setWordWrap(true); if( gameDescription ) { gameDescription->move( margin + m_buttonSize.width() * 3, option.fontMetrics.height() * 1 + gameName->size().height() ); gameDescription->resize( QSize( option.rect.width() - ( margin * 4 ) - m_buttonSize.width() * 4, option.fontMetrics.height() * 2 ) ); gameDescription->setText( index.data( GluonPlayer::GameItemsModel::GameDescriptionRole ).toString() ); } }
void ItemsViewDelegate::updateItemWidgets(const QList<QWidget*> widgets, const QStyleOptionViewItem &option, const QPersistentModelIndex &index) const { const QSortFilterProxyModel * model = qobject_cast<const QSortFilterProxyModel*>(index.model()); if (model == NULL) { return; } const ItemsModel * realmodel = qobject_cast<const ItemsModel*>(model->sourceModel()); if (realmodel == NULL || !index.isValid()) { return; } // setup the install button int margin = option.fontMetrics.height() / 2; int right = option.rect.width(); //int bottom = option.rect.height(); QSize size(option.fontMetrics.height() * 7, widgets.at(kInstall)->sizeHint().height()); QLabel * infoLabel = qobject_cast<QLabel*>(widgets.at(kLabel)); infoLabel->setWordWrap(true); if (infoLabel != NULL) { if (realmodel->hasPreviewImages()) { // move the text right by kPreviewWidth + margin pixels to fit the preview infoLabel->move(kPreviewWidth + margin * 2, 0); infoLabel->resize(QSize(option.rect.width() - kPreviewWidth - (margin * 6) - size.width(), option.fontMetrics.height() * 7)); } else { infoLabel->move(margin, 0); infoLabel->resize(QSize(option.rect.width() - (margin * 4) - size.width(), option.fontMetrics.height() * 7)); } QString text = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">p, li { white-space: pre-wrap; margin:0 0 0 0;}\n" "</style></head><body><p><b>" + index.data(ItemsModel::kNameRole).toString() + "</b></p>\n"; QString summary = "<p>" + option.fontMetrics.elidedText(index.data(ItemsModel::kSummary).toString(), Qt::ElideRight, infoLabel->width() * 3) + "</p>\n"; text += summary; QString authorName = index.data(ItemsModel::kAuthorName).toString(); QString email = index.data(ItemsModel::kAuthorEmail).toString(); if (!authorName.isEmpty()) { if (email.isEmpty()) { text += "<p><i>" + authorName + "</i></p>\n"; } else { text += "<p><i>" + authorName + "</i> <a href=\"mailto:" + email + "\">" + email + "</a></p>\n"; } } unsigned int downloads = index.data(ItemsModel::kDownloads).toUInt(); text += downloads == 0 ? i18n("<p>No Downloads</p>") : i18n("<p>Downloads: %1</p>\n", downloads); text += "</body></html>"; text.replace("[b]", "<b>"); text.replace("[/b]", "</b>"); text.replace("[i]", "<i>"); text.replace("[/i]", "</i>"); text.replace("[u]", "<i>"); text.replace("[/u]", "</i>"); text.remove("[url]"); text.remove("[/url]"); text.replace("\\\'", "\'"); infoLabel->setText(text.simplified()); } QToolButton * button = qobject_cast<QToolButton*>(widgets.at(kInstall)); if (button != NULL) { Entry::Status status = Entry::Status(model->data(index, ItemsModel::kStatus).toUInt()); //if (!button->menu()) { // button->setMenu(InstallMenu(button, status)); // button->setIconSize(QSize(16, 16)); button->resize(size); //} button->move(right - button->width() - margin, option.rect.height() / 2 - button->height()); button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); //button->setPopupMode(QToolButton::MenuButtonPopup); // validate our assumptions //Q_ASSERT(button->menu()); //Q_ASSERT(button->menu()->actions().count() == 2); // get the two actions //QAction * action_install = button->menu()->actions()[0]; //QAction * action_uninstall = button->menu()->actions()[1]; switch (status) { case Entry::Installed: button->setText(i18n("Uninstall")); //action_install->setVisible(false); //action_uninstall->setVisible(true); button->setIcon(QIcon(m_statusicons[Entry::Deleted])); break; case Entry::Updateable: button->setText(i18n("Update")); //action_uninstall->setVisible(false); //action_install->setText(i18n("Update")); //action_install->setVisible(true); //action_install->setIcon(QIcon(m_statusicons[Entry::Updateable])); button->setIcon(QIcon(m_statusicons[Entry::Updateable])); break; case Entry::Deleted: /// @todo Set different button text when string freeze is over? "Install again" button->setText(i18n("Install")); //action_uninstall->setVisible(false); //action_install->setText(i18n("Install")); //action_install->setVisible(true); //action_install->setIcon(QIcon(m_statusicons[Entry::Installed])); button->setIcon(QIcon(m_statusicons[Entry::Installed])); break; default: button->setText(i18n("Install")); //action_uninstall->setVisible(false); //action_install->setVisible(true); //action_install->setIcon(QIcon(m_statusicons[Entry::Installed])); button->setIcon(QIcon(m_statusicons[Entry::Installed])); } } QLabel * ratingLabel = qobject_cast<QLabel*>(widgets.at(kRating)); if (ratingLabel != NULL) { ratingLabel->setText(i18n("Rating: %1", model->data(index, ItemsModel::kRating).toString())); // put the rating label below the install button ratingLabel->move(right - button->width() - margin, option.rect.height() / 2 + button->height()/2); ratingLabel->resize(size); } }
void CommentItemsViewDelegate::updateItemWidgets( const QList<QWidget*> widgets, const QStyleOptionViewItem& option, const QPersistentModelIndex& index ) const { const GluonPlayer::CommentItemsModel* model = qobject_cast<const GluonPlayer::CommentItemsModel*>( index.model() ); if( !model ) { kDebug() << "Warning - Invalid Model!"; return; } // setup the install button int margin = option.fontMetrics.height() / 2; int right = option.rect.width(); int bottom = option.rect.height(); const_cast<QSize&>( m_buttonSize ) = QSize( 32, 32 ); KPushButton* replyButton = qobject_cast<KPushButton*>( widgets.at( DelegateCommentReplyButton ) ); if( replyButton ) { replyButton->setVisible( const_cast<GluonPlayer::CommentItemsModel*>( model )->isOnline() ); replyButton->setIcon( KIcon( "edit-undo" ) ); replyButton->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::MinimumExpanding ); replyButton->resize( m_buttonSize ); replyButton->move( right - replyButton->width() - margin, bottom - m_buttonSize.height() * 1.5 ); } KSqueezedTextLabel* author = qobject_cast<KSqueezedTextLabel*>( widgets.at( DelegateCommentAuthor ) ); if( author ) { author->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::MinimumExpanding ); author->resize( right / 5, m_buttonSize.height() ); author->move( margin, option.fontMetrics.height() ); author->setText( index.data( GluonPlayer::CommentItemsModel::AuthorRole ).toString() ); } KSqueezedTextLabel* dateTime = qobject_cast<KSqueezedTextLabel*>( widgets.at( DelegateCommentDateTime ) ); if( dateTime ) { dateTime->resize( author->size().width(), author->size().height() ); dateTime->move( author->x() + author->size().width(), author->y() ); dateTime->setText( index.data( GluonPlayer::CommentItemsModel::DateTimeRole ).toString() ); } KSqueezedTextLabel* title = qobject_cast<KSqueezedTextLabel*>( widgets.at( DelegateCommentTitle ) ); if( title ) { title->resize( dateTime->size().width(), dateTime->size().height() ); title->move( dateTime->x() + dateTime->size().width(), dateTime->y() ); title->setText( index.data( GluonPlayer::CommentItemsModel::TitleRole ).toString() ); } KSqueezedTextLabel* rating = qobject_cast<KSqueezedTextLabel*>( widgets.at( DelegateCommentRating ) ); if( rating ) { rating->resize( title->size().width(), title->size().height() ); rating->move( title->x() + title->size().width(), title->y() ); rating->setText( index.data( GluonPlayer::CommentItemsModel::RatingRole ).toString() ); } KSqueezedTextLabel* body = qobject_cast<KSqueezedTextLabel*>( widgets.at( DelegateCommentBody ) ); if( body ) { body->resize( right - 2 * margin, bottom - author->size().height() - 2 * margin ); body->move( margin, option.fontMetrics.height() + author->size().height() ); body->setText( index.data( GluonPlayer::CommentItemsModel::BodyRole ).toString() ); } }
void ProgressListDelegate::updateItemWidgets(const QList<QWidget*> widgets, const QStyleOptionViewItem &option, const QPersistentModelIndex &index) const { if (!index.isValid()) { return; } QPushButton *pauseResumeButton = static_cast<QPushButton*>(widgets[0]); QPushButton *cancelButton = static_cast<QPushButton*>(widgets[1]); cancelButton->setToolTip(i18n("Cancel")); QProgressBar *progressBar = static_cast<QProgressBar*>(widgets[2]); QPushButton *clearButton = static_cast<QPushButton*>(widgets[3]); int percent = d->getPercent(index); cancelButton->setVisible(percent < 100); pauseResumeButton->setVisible(percent < 100); clearButton->setVisible(percent > 99); KJob::Capabilities capabilities = (KJob::Capabilities) index.model()->data(index, JobView::Capabilities).toInt(); cancelButton->setEnabled(capabilities & KJob::Killable); pauseResumeButton->setEnabled(capabilities & KJob::Suspendable); JobView::JobState state = (JobView::JobState) index.model()->data(index, JobView::State).toInt(); switch (state) { case JobView::Running: pauseResumeButton->setToolTip(i18n("Pause")); pauseResumeButton->setIcon(QIcon::fromTheme(QStringLiteral("media-playback-pause"))); break; case JobView::Suspended: pauseResumeButton->setToolTip(i18n("Resume")); pauseResumeButton->setIcon(QIcon::fromTheme(QStringLiteral("media-playback-start"))); break; default: Q_ASSERT(0); break; } QSize progressBarButtonSizeHint; if (percent < 100) { QSize cancelButtonSizeHint = cancelButton->sizeHint(); cancelButton->move(option.rect.width() - d->separatorPixels - cancelButtonSizeHint.width(), option.rect.height() - d->separatorPixels - cancelButtonSizeHint.height()); QSize pauseResumeButtonSizeHint = pauseResumeButton->sizeHint(); pauseResumeButton->move(option.rect.width() - d->separatorPixels * 2 - pauseResumeButtonSizeHint.width() - cancelButtonSizeHint.width(), option.rect.height() - d->separatorPixels - pauseResumeButtonSizeHint.height()); progressBarButtonSizeHint = pauseResumeButtonSizeHint; } else { progressBarButtonSizeHint = clearButton->sizeHint(); clearButton->resize(progressBarButtonSizeHint); clearButton->move(option.rect.width() - d->separatorPixels - progressBarButtonSizeHint.width(), option.rect.height() - d->separatorPixels - progressBarButtonSizeHint.height()); } progressBar->setValue(percent); QFontMetrics fm(QApplication::font()); QSize progressBarSizeHint = progressBar->sizeHint(); progressBar->resize(QSize(option.rect.width() - d->getCurrentLeftMargin(fm.height()) - d->rightMargin, progressBarSizeHint.height())); progressBar->move(d->getCurrentLeftMargin(fm.height()), option.rect.height() - d->separatorPixels * 2 - progressBarButtonSizeHint.height() - progressBarSizeHint.height()); }
void ItemsViewDelegate::updateItemWidgets(const QList<QWidget *> widgets, const QStyleOptionViewItem &option, const QPersistentModelIndex &index) const { const KNSCore::ItemsModel *model = qobject_cast<const KNSCore::ItemsModel *>(index.model()); if (!model) { qCDebug(KNEWSTUFF) << "WARNING - INVALID MODEL!"; return; } KNSCore::EntryInternal entry = index.data(Qt::UserRole).value<KNSCore::EntryInternal>(); // setup the install button int margin = option.fontMetrics.height() / 2; int right = option.rect.width(); QToolButton *installButton = qobject_cast<QToolButton *>(widgets.at(DelegateInstallButton)); if (installButton != 0) { if (installButton->menu()) { QMenu *buttonMenu = installButton->menu(); buttonMenu->clear(); installButton->setMenu(0); buttonMenu->deleteLater(); } bool installable = false; bool enabled = true; QString text; QIcon icon; switch (entry.status()) { case Entry::Installed: text = i18n("Uninstall"); icon = m_iconDelete; break; case Entry::Updateable: text = i18n("Update"); icon = m_iconUpdate; installable = true; break; case Entry::Installing: text = i18n("Installing"); enabled = false; icon = m_iconUpdate; break; case Entry::Updating: text = i18n("Updating"); enabled = false; icon = m_iconUpdate; break; case Entry::Downloadable: text = i18n("Install"); icon = m_iconInstall; installable = true; break; case Entry::Deleted: text = i18n("Install Again"); icon = m_iconInstall; installable = true; break; default: text = i18n("Install"); } installButton->setText(text); installButton->setEnabled(enabled); installButton->setIcon(icon); if (installable && entry.downloadLinkCount() > 1) { QMenu *installMenu = new QMenu(installButton); foreach (const KNSCore::EntryInternal::DownloadLinkInformation &info, entry.downloadLinkInformationList()) { QString text = info.name; if (!info.distributionType.trimmed().isEmpty()) { text + " (" + info.distributionType.trimmed() + ')'; } QAction *installAction = installMenu->addAction(m_iconInstall, text); installAction->setData(QPoint(index.row(), info.id)); } installButton->setMenu(installMenu); } }