Skip to content

Commit

Permalink
feat(qml): add page and image count at the bottom of the results
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed Apr 20, 2024
1 parent 952ca4b commit 9065111
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 19 deletions.
6 changes: 4 additions & 2 deletions src/gui-qml/src/components/GalleryScreen.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Page {
signal back()

property int page: 1
property string site
property var site
property var gallery
property bool infiniteScroll: gSettings.resultsInfiniteScroll.value
property var results
Expand All @@ -22,7 +22,7 @@ Page {
GallerySearchLoader {
id: galleryLoader

site: root.site
site: root.site.url
gallery: root.gallery.image
page: root.page
perPage: 20
Expand Down Expand Up @@ -116,6 +116,7 @@ Page {
enabled: query !== "" && page > 1
Layout.fillHeight: true
Material.elevation: 0
Material.roundedScale: Material.NotRounded

onClicked: {
page--
Expand All @@ -136,6 +137,7 @@ Page {
enabled: query !== ""
Layout.fillHeight: true
Material.elevation: 0
Material.roundedScale: Material.NotRounded

onClicked: {
page++
Expand Down
32 changes: 27 additions & 5 deletions src/gui-qml/src/components/SearchScreen.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Page {
signal openSources()

property int page: 1
property string site
property var site
property bool infiniteScroll: gSettings.resultsInfiniteScroll.value
property var results
property bool queryChanged: false
Expand All @@ -22,7 +22,7 @@ Page {
TagSearchLoader {
id: pageLoader

site: searchTab.site
site: searchTab.site.url
query: textFieldSearch.text
page: searchTab.page
perPage: 20
Expand Down Expand Up @@ -136,7 +136,7 @@ Page {
enabled: pageLoader.query !== ""
onClicked: isFavorited
? backend.removeFavorite(pageLoader.query)
: backend.addFavorite(pageLoader.query, searchTab.site)
: backend.addFavorite(pageLoader.query, searchTab.site.url)
}

Item {
Expand Down Expand Up @@ -179,6 +179,7 @@ Page {
spacing: 0
Layout.fillWidth: true
Layout.fillHeight: false
//Layout.preferredHeight: 40

Button {
id: prevButton
Expand All @@ -200,15 +201,36 @@ Page {
Button {
id: sourcesButton
background.anchors.fill: sourcesButton
text: qsTr("Sources")
Layout.fillWidth: true
implicitWidth: 50
icon.source: "file:///" + searchTab.site.icon
icon.color: "transparent"
leftPadding: 0
rightPadding: 0
Layout.fillHeight: true
Material.elevation: 0
Material.roundedScale: Material.NotRounded

onClicked: searchTab.openSources()
}

Rectangle {
Layout.fillWidth: true
Layout.fillHeight: true
color: sourcesButton.background.color

Text {
anchors.fill: parent
text: pageLoader.status == TagSearchLoader.Ready
? (results
? qsTr("Page %1 of %2\n(%3 of %4)").arg(page).arg(pageLoader.pageCount).arg(results.length).arg(pageLoader.imageCount)
: qsTr("No result"))
: ''
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
rightPadding: sourcesButton.width
}
}

Button {
id: nextButton
background.anchors.fill: nextButton
Expand Down
6 changes: 3 additions & 3 deletions src/gui-qml/src/components/SourcesScreen.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Page {
signal addSource()
signal editSource(var source)

property string currentSource
property string activeSource
property var sources

header: ToolBar {
Expand Down Expand Up @@ -52,7 +52,7 @@ Page {
property string url: modelData.url

width: parent.width
checked: modelData.url === currentSource
checked: modelData.url === activeSource
text: modelData.name || modelData.url
ButtonGroup.group: buttonGroup
height: 30 // from 40
Expand All @@ -65,7 +65,7 @@ Page {
size: 18 // from 28
}

onCheckedChanged: if (checked) currentSource = modelData.url
onCheckedChanged: if (checked) activeSource = modelData.url
}

ToolButton {
Expand Down
10 changes: 10 additions & 0 deletions src/gui-qml/src/loaders/search-loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ void SearchLoader::searchFinished(Page *page)
m_hasNext = pageCount > page->page() || page->imagesCount() == -1 || page->pagesCount() == -1 || (page->imagesCount() == 0 && page->pageImageCount() > 0);
emit hasNextChanged();

m_pageCount = page->pagesCount() > 0
? (page->pagesCount(false) == -1 ? "~" : QString()) + QString::number(page->pagesCount())
: (page->maxPagesCount() == -1 ? "?" : tr("max %1").arg(page->maxPagesCount()));
emit pageCountChanged();

m_imageCount = page->imagesCount() > 0
? (page->imagesCount(false) == -1 ? "~" : QString()) + QString::number(page->imagesCount())
: (page->maxImagesCount() == -1 ? "?" : tr("max %1").arg(page->maxImagesCount()));
emit imageCountChanged();

emit resultsChanged();
setStatus(Status::Ready);
}
9 changes: 9 additions & 0 deletions src/gui-qml/src/loaders/search-loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class SearchLoader : public Loader
Q_PROPERTY(QList<QmlImage*> results READ results NOTIFY resultsChanged)
Q_PROPERTY(bool hasPrev READ hasPrev NOTIFY hasPrevChanged)
Q_PROPERTY(bool hasNext READ hasNext NOTIFY hasNextChanged)
Q_PROPERTY(QString pageCount READ pageCount NOTIFY pageCountChanged)
Q_PROPERTY(QString imageCount READ imageCount NOTIFY imageCountChanged)

public:
explicit SearchLoader(QObject *parent = nullptr);
Expand All @@ -50,6 +52,9 @@ class SearchLoader : public Loader
bool hasPrev() const { return m_hasPrev; }
bool hasNext() const { return m_hasNext; }

QString pageCount() const { return m_pageCount; }
QString imageCount() const { return m_imageCount; }

protected slots:
void search(SearchQuery query);

Expand All @@ -65,6 +70,8 @@ class SearchLoader : public Loader
void profileChanged();
void hasPrevChanged();
void hasNextChanged();
void pageCountChanged();
void imageCountChanged();

private:
QString m_site;
Expand All @@ -76,6 +83,8 @@ class SearchLoader : public Loader
QList<QmlImage*> m_results;
bool m_hasPrev;
bool m_hasNext;
QString m_pageCount;
QString m_imageCount;
};

#endif // SEARCH_LOADER_H
3 changes: 2 additions & 1 deletion src/gui-qml/src/main-screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ void MainScreen::refreshSites()
m_sites.clear();

for (Site *site : m_profile->getSites().values()) {
m_sites.append(new QmlSite(site, this));
Source *source = m_profile->getSources().value(site->type());
m_sites.append(new QmlSite(site, source, this));
}

emit sitesChanged();
Expand Down
13 changes: 7 additions & 6 deletions src/gui-qml/src/main-screen.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ApplicationWindow {
title: "Grabber"

property string currentPage: "search"
property var activeSite: backend.sites.filter(site => site.url === gSettings.activeSource.value)[0]

Material.theme: gSettings.appearance_materialTheme.value
Material.primary: gSettings.appearance_materialPrimary.value
Expand Down Expand Up @@ -115,7 +116,7 @@ ApplicationWindow {
id: searchScreen
visible: currentPage == "search"
anchors.fill: parent
site: gSettings.activeSource.value
site: activeSite

onOpenSources: mainStackView.push(sourcesScreen)
}
Expand Down Expand Up @@ -163,7 +164,7 @@ ApplicationWindow {
GalleryScreen {
id: galleryScreen
visible: false
site: gSettings.activeSource.value
site: activeSite

onBack: mainStackView.pop()
}
Expand All @@ -172,12 +173,12 @@ ApplicationWindow {
id: sourcesScreen
visible: false
sources: backend.sites
currentSource: gSettings.activeSource.value
activeSource: gSettings.activeSource.value

onAccepted: { gSettings.activeSource.setValue(source); mainStackView.pop() }
onRejected: mainStackView.pop()
onActiveSourceChanged: { gSettings.activeSource.setValue(activeSource); }
onBack: mainStackView.pop()
onAddSource: mainStackView.push(addSourceScreen)
onEditSource: mainStackView.push(editSourceScreen, { site: source })
onEditSource: mainStackView.push(editSourceScreen, { site: activeSource })
}

AddSourceScreen {
Expand Down
8 changes: 6 additions & 2 deletions src/gui-qml/src/models/qml-site.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QObject>
#include "models/qml-auth.h"
#include "models/site.h"
#include "models/source.h"
#include "models/source-engine.h"
#include "settings.h"

Expand All @@ -14,12 +15,13 @@ class QmlSite : public QObject

Q_PROPERTY(QString url READ url CONSTANT)
Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(QString icon READ icon CONSTANT)
Q_PROPERTY(Settings * settings READ settings CONSTANT)
Q_PROPERTY(QList<QmlAuth*> authFields READ authFields CONSTANT)

public:
explicit QmlSite(Site *site, QObject *parent = nullptr)
: QObject(parent), m_site(site), m_settings(new Settings(site->settings(), this))
explicit QmlSite(Site *site, Source *source, QObject *parent = nullptr)
: QObject(parent), m_site(site), m_source(source), m_settings(new Settings(site->settings(), this))
{
auto auths = m_site->getSourceEngine()->getAuths();
for (auto it = auths.constBegin(); it != auths.constEnd(); ++it) {
Expand All @@ -29,13 +31,15 @@ class QmlSite : public QObject

QString url() const { return m_site->url(); }
QString name() const { return m_site->name(); }
QString icon() const { return m_source->getPath().readPath("icon.png"); }
Settings *settings() const { return m_settings; }
QList<QmlAuth*> authFields() const { return m_fields; }

Site *rawSite() const { return m_site; }

private:
Site *m_site;
Source *m_source;
Settings *m_settings;
QList<QmlAuth*> m_fields;
};
Expand Down

0 comments on commit 9065111

Please # to comment.