Skip to content

Commit

Permalink
feat: add new option to context menu to get tags with namespaces (fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed Apr 7, 2024
1 parent add5c8d commit 19e196e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/gui/src/image-context-menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ImageContextMenu::ImageContextMenu(QSettings *settings, QSharedPointer<Image> im

// Copy
addAction(QIcon(":/images/icons/copy.png"), tr("Copy all tags"), this, SLOT(copyAllTagsToClipboard()));
addAction(QIcon(":/images/icons/copy.png"), tr("Copy all tags (with namespaces)"), this, SLOT(copyAllTagsWithNamespacesToClipboard()));
addSeparator();

// Open image in browser
Expand All @@ -45,6 +46,11 @@ void ImageContextMenu::copyAllTagsToClipboard()
QApplication::clipboard()->setText(m_image->tagsString().join(' '));
}

void ImageContextMenu::copyAllTagsWithNamespacesToClipboard()
{
QApplication::clipboard()->setText(m_image->tagsString(true).join(' '));
}

void ImageContextMenu::openInBrowser()
{
QDesktopServices::openUrl(m_image->pageUrl());
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/image-context-menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ImageContextMenu : public QMenu

protected slots:
void copyAllTagsToClipboard();
void copyAllTagsWithNamespacesToClipboard();
void openInBrowser();
void searchMd5();
void reverseImageSearch(int i);
Expand Down
12 changes: 12 additions & 0 deletions src/gui/src/tag-context-menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ TagContextMenu::TagContextMenu(QString tag, QList<Tag> allTags, QUrl browserUrl,
addAction(QIcon(":/images/icons/copy.png"), tr("Copy tag"), this, SLOT(copyTagToClipboard()));
if (!allTags.isEmpty()) {
addAction(QIcon(":/images/icons/copy.png"), tr("Copy all tags"), this, SLOT(copyAllTagsToClipboard()));
addAction(QIcon(":/images/icons/copy.png"), tr("Copy all tags (with namespaces)"), this, SLOT(copyAllTagsWithNamespacesToClipboard()));
}
addSeparator();

Expand Down Expand Up @@ -145,3 +146,14 @@ void TagContextMenu::copyAllTagsToClipboard()

QApplication::clipboard()->setText(tags.join(' '));
}
void TagContextMenu::copyAllTagsWithNamespacesToClipboard()
{
QStringList tags;
tags.reserve(m_allTags.count());
for (const Tag &tag : qAsConst(m_allTags)) {
const QString nspace = !tag.type().isUnknown() ? tag.type().name() + ":" : QString();
tags.append(nspace + tag.text());
}

QApplication::clipboard()->setText(tags.join(' '));
}
1 change: 1 addition & 0 deletions src/gui/src/tag-context-menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class TagContextMenu : public QMenu
void openInBrowser();
void copyTagToClipboard();
void copyAllTagsToClipboard();
void copyAllTagsWithNamespacesToClipboard();

signals:
void setFavoriteImage();
Expand Down
5 changes: 3 additions & 2 deletions src/lib/src/models/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,12 +932,13 @@ Image::Size Image::preferredDisplaySize() const
: Size::Full;
}

QStringList Image::tagsString() const
QStringList Image::tagsString(bool namespaces) const
{
QStringList tags;
tags.reserve(m_tags.count());
for (const Tag &tag : m_tags) {
tags.append(tag.text());
const QString nspace = namespaces && !tag.type().isUnknown() ? tag.type().name() + ":" : QString();
tags.append(nspace + tag.text());
}
return tags;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/src/models/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Image : public QObject, public Downloadable
int value() const;
QString md5() const;
const QList<Tag> &tags() const;
QStringList tagsString() const;
QStringList tagsString(bool namespaces = false) const;
const QList<Pool> &pools() const;
qulonglong id() const;
QVariantMap identity() const;
Expand Down

0 comments on commit 19e196e

Please sign in to comment.