Skip to content

Commit

Permalink
feat: improve looks of the tag view of the QML version
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed Dec 30, 2022
1 parent c59ef31 commit 895e4ae
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 77 deletions.
79 changes: 2 additions & 77 deletions src/gui-qml/src/components/ImageScreen.qml
Original file line number Diff line number Diff line change
Expand Up @@ -162,83 +162,8 @@ Page {
}
}

Item {
id: tagView

Menu {
id: tagContextMenu
title: tagContextMenu.tag

property string tag

MenuItem {
text: "Search"
enabled: tagContextMenu.tag !== pageLoader.query

onTriggered: {
root.closed()
searchTab.load(tagContextMenu.tag)
}
}

MenuItem {
text: "Add to search"
enabled: pageLoader.query.split(' ').indexOf(tagContextMenu.tag) === -1

onTriggered: {
root.closed()
searchTab.load(pageLoader.query + ' ' + tagContextMenu.tag)
}
}

MenuItem {
text: "Remove from search"
enabled: pageLoader.query.split(' ').indexOf(tagContextMenu.tag) >= 0

onTriggered: {
root.closed()
searchTab.load(pageLoader.query.split(' ').filter(t => t !== tagContextMenu.tag).join(' '))
}
}

MenuItem {
text: "Copy"

onTriggered: {
backend.setClipboardText(tagContextMenu.tag)
}
}
}

ListView {
clip: true
anchors.fill: parent
anchors.margins: 8

model: Material.theme == Material.Dark ? modelData.tagsDark : modelData.tags

delegate: Label {
text: modelData
textFormat: Text.RichText

function getRawTag(html) {
return html.match(/href="(.+?)"/)[1]
}

MouseArea {
anchors.fill: parent

onClicked: {
root.closed()
searchTab.load(getRawTag(modelData))
}
onPressAndHold: {
tagContextMenu.tag = getRawTag(modelData)
tagContextMenu.popup()
}
}
}
}
TagView {
image: modelData
}

Component.onCompleted: modelData.loadTags()
Expand Down
101 changes: 101 additions & 0 deletions src/gui-qml/src/components/TagView.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import Grabber 1.0
import QtQuick 2.12
import QtQuick.Controls 2.5
import QtQuick.Controls.Material 2.12
import QtQuick.Layouts 1.12

Item {
id: tagView

property var image

Menu {
id: tagContextMenu
title: tagContextMenu.tag

property string tag

MenuItem {
property bool isFavorited: Array.prototype.indexOf.call(backend.favorites, tagContextMenu.tag) >= 0
text: isFavorited ? qsTr("Remove from favorites") : qsTr("Add to favorites")

onTriggered: {
if (isFavorited) {
backend.removeFavorite(tagContextMenu.tag)
} else {
backend.addFavorite(tagContextMenu.tag, searchTab.site)
}
}
}

MenuItem {
text: qsTr("Copy tag")

onTriggered: {
backend.setClipboardText(tagContextMenu.tag)
}
}
}

ListView {
clip: true
anchors.fill: parent
anchors.margins: 8

model: Material.theme == Material.Dark ? image.tagsDark : image.tags

delegate: RowLayout {
property string tag: decodeURIComponent(modelData.match(/href="(.+?)"/)[1])

width: parent.width
height: 34

Label {
text: modelData
textFormat: Text.RichText
Layout.fillHeight: true
Layout.fillWidth: true
topPadding: 5

MouseArea {
anchors.fill: parent

onClicked: {
root.closed()
searchTab.load(tag)
}
onPressAndHold: {
tagContextMenu.tag = tag
tagContextMenu.popup()
}
}
}

ToolButton {
icon.source: "/images/icons/" + (pageLoader.query.split(' ').indexOf(tag) === -1 ? "add" : "remove") + ".png"
Layout.fillHeight: true
Layout.preferredWidth: 34

onClicked: {
root.closed()
if (pageLoader.query.split(' ').indexOf(tag) === -1) {
searchTab.load(pageLoader.query + ' ' + tag)
} else {
searchTab.load(pageLoader.query.split(' ').filter(t => t !== tag).join(' '))
}
}
}

ToolButton {
icon.source: "/images/icons/menu.png"
Layout.fillHeight: true
Layout.preferredWidth: 34

onClicked: {
tagContextMenu.tag = tag
tagContextMenu.popup()
}
}
}
}
}
1 change: 1 addition & 0 deletions src/gui-qml/src/qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@
<file>components/InnerBorder.qml</file>
<file>components/Badge.qml</file>
<file>components/Loading.qml</file>
<file>components/TagView.qml</file>
</qresource>
</RCC>

0 comments on commit 895e4ae

Please sign in to comment.