AddTagsCompletionBoxItem* AddTagsCompletionBox::Private::createItemForNewTag(const QString& newName, TAlbum* parent) { int parentTagId = parent ? parent->id() : 0; // If tag exists, do not add an entry to create it if (TagsCache::instance()->tagForName(newName, parentTagId)) { return 0; } AddTagsCompletionBoxItem* const item = new AddTagsCompletionBoxItem; if (parent) { item->setText(i18nc("Create New Tag <tag name> in <parent tag path>", "Create \"%1\" in %2", newName, parent->tagPath(false))); } else { item->setText(i18n("Create \"%1\"", newName)); } item->setData(Qt::DecorationRole, AlbumThumbnailLoader::instance()->getNewTagIcon()); item->setData(CompletionTextRole, newName); item->setAction(TaggingAction(newName, parentTagId)); return item; }
void AddTagsLineEdit::slotTextChanged(const QString& text) { if (text.isEmpty()) { d->currentTaggingAction = TaggingAction(); } }
TaggingAction AddTagsLineEdit::currentTaggingAction() const { if (d->currentTaggingAction.isValid()) { return d->currentTaggingAction; } else if (!text().isEmpty()) { return TaggingActionFactory::defaultTaggingAction(text(), d->parentTagId); } else { return TaggingAction(); } }
AddTagsCompletionBoxItem* AddTagsCompletionBox::Private::createItemForExistingTag(TAlbum* talbum, bool uniqueName) { if (!talbum || talbum->isRoot()) { return 0; } AddTagsCompletionBoxItem* const item = new AddTagsCompletionBoxItem; TAlbum* const parent = static_cast<TAlbum*>(talbum->parent()); if (parent->isRoot() || uniqueName) { item->setText(talbum->title()); } else { item->setText(i18nc("<tag name> in <tag path>", "%1 in %2", talbum->title(), parent->tagPath(false))); } if (model || filterModel) { QModelIndex index; if (filterModel) { index = filterModel->indexForAlbum(talbum); } else if (model) { index = model->indexForAlbum(talbum); } item->setData(Qt::DecorationRole, index.data(Qt::DecorationRole)); } item->setData(CompletionTextRole, talbum->title()); item->setAction(TaggingAction(talbum->id())); return item; }
void AddTagsLineEdit::slotEditingFinished() { d->currentTaggingAction = TaggingAction(); }
void AddTagsLineEdit::setCurrentTag(TAlbum* const album) { setCurrentTaggingAction(album ? TaggingAction(album->id()) : TaggingAction()); setText(album ? album->title() : QString()); }