Skip to content

Commit

Permalink
Add support for post-filters in QML UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed Nov 7, 2020
1 parent 7354614 commit ffe63f0
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 28 deletions.
Binary file added src/gui-qml/resources/images/icons/remove.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/gui-qml/resources/images/icons/remove@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/gui-qml/resources/images/icons/remove@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/gui-qml/resources/images/icons/remove@4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/gui-qml/resources/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,9 @@
<file>images/icons/cloud@2x.png</file>
<file>images/icons/cloud@3x.png</file>
<file>images/icons/cloud@4x.png</file>
<file>images/icons/remove.png</file>
<file>images/icons/remove@2x.png</file>
<file>images/icons/remove@3x.png</file>
<file>images/icons/remove@4x.png</file>
</qresource>
</RCC>
36 changes: 36 additions & 0 deletions src/gui-qml/src/components/SearchEdit.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Grabber 1.0
import QtQuick 2.12
import QtQuick.Controls 2.5

TextEdit {
id: root

signal enterPressed()
property alias placeholderText: placeholder.text

verticalAlignment: Text.AlignVCenter
font.pixelSize: 14

Keys.onEnterPressed: {
root.enterPressed()
event.accepted = true
}
Keys.onReturnPressed: {
root.enterPressed()
event.accepted = true
}

Text {
id: placeholder

anchors.fill: parent
verticalAlignment: Text.AlignVCenter
visible: !(parent.text.length || parent.inputMethodComposing)
font: parent.font
color: "#666"
}

SyntaxHighlighterHelper {
quickDocument: root.textDocument
}
}
38 changes: 14 additions & 24 deletions src/gui-qml/src/components/SearchField.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ FocusScope {

signal enterPressed()
property alias text: textInput.text
property alias placeholderText: placeholder.text
property alias placeholderText: textInput.placeholderText
property bool isOpen: false

activeFocusOnTab: true

Expand All @@ -20,39 +21,28 @@ FocusScope {
color: Qt.rgba(1, 1, 1, 0.6)
radius: 12

TextEdit {
SearchEdit {
id: textInput

anchors.fill: parent
clip: true
anchors.leftMargin: 12
anchors.rightMargin: 12
verticalAlignment: Text.AlignVCenter
font.pixelSize: 14
focus: true

Keys.onEnterPressed: {
root.enterPressed()
event.accepted = true
}
Keys.onReturnPressed: {
root.enterPressed()
event.accepted = true
}

Text {
id: placeholder

anchors.fill: parent
verticalAlignment: Text.AlignVCenter
visible: !(parent.text.length || textInput.inputMethodComposing)
font: parent.font
color: "#666"
}
onEnterPressed: root.enterPressed()
}

SyntaxHighlighterHelper {
quickDocument: textInput.textDocument
ToolButton {
icon.source: root.isOpen
? "/images/icons/remove.png"
: "/images/icons/add.png"
onClicked: root.isOpen = !root.isOpen
flat: true
height: 34
width: 34
anchors.right: editbg.right
anchors.verticalCenter: editbg.verticalCenter
}
}
}
19 changes: 18 additions & 1 deletion src/gui-qml/src/components/SearchScreen.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Page {
if (tag) {
textFieldSearch.text = tag
}
backend.search(site, textFieldSearch.text, page)
backend.search(site, textFieldSearch.text, page, textFieldPostFiltering.text)
}

header: ToolBar {
Expand Down Expand Up @@ -66,6 +66,23 @@ Page {
spacing: 0
anchors.fill: parent

Rectangle {
Layout.fillWidth: true
border.width: 1
border.color: "#666"
height: 40
visible: textFieldSearch.isOpen

SearchEdit {
id: textFieldPostFiltering
placeholderText: "Post-filters"
anchors.fill: parent
anchors.margins: 8

onEnterPressed: searchTab.load()
}
}

ResultsView {
results: searchTab.results
thumbnailHeightToWidthRatio: gSettings.resultsLayoutType.value === "flow" ? 0 : gSettings.resultsHeightToWidthRatio.value
Expand Down
4 changes: 2 additions & 2 deletions src/gui-qml/src/main-screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ void MainScreen::refreshSources()
emit sourcesChanged();
}

void MainScreen::search(const QString &siteUrl, const QString &query, int pageNumber)
void MainScreen::search(const QString &siteUrl, const QString &query, int pageNumber, const QString &postFilter)
{
m_query = query;
emit queryChanged();

Site *site = m_profile->getSites().value(siteUrl);
Page *page = new Page(m_profile, site, m_profile->getSites().values(), query.split(' '), pageNumber, IMAGES_PER_PAGE, {}, false, this);
Page *page = new Page(m_profile, site, m_profile->getSites().values(), query.split(' '), pageNumber, IMAGES_PER_PAGE, postFilter.split(' '), false, this);

QEventLoop loop;
QObject::connect(page, &Page::finishedLoading, &loop, &QEventLoop::quit);
Expand Down
2 changes: 1 addition & 1 deletion src/gui-qml/src/main-screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MainScreen : public QObject
QString settingsFileName() const;

public slots:
void search(const QString &site, const QString &query, int page);
void search(const QString &site, const QString &query, int page, const QString &postFilter);
void newLog(const QString &message);
void downloadImage(const QSharedPointer<Image> &image);
QString addSite(const QString &type, const QString &host, bool https);
Expand Down
1 change: 1 addition & 0 deletions src/gui-qml/src/qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@
<file>components/settings/items/RadioSetting.qml</file>
<file>components/ResultsView.qml</file>
<file>components/settings/pages/SourcesSettingsPage.qml</file>
<file>components/SearchEdit.qml</file>
</qresource>
</RCC>

0 comments on commit ffe63f0

Please sign in to comment.