From afc787be7bf78961691db674dd45a6282bd43e6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sun, 17 Nov 2013 17:53:02 +0100 Subject: [PATCH] added comic vine pagination and sorting volumes by column --- YACReaderLibrary/comic_vine/comic_vine.pri | 8 +- .../comic_vine/comic_vine_client.cpp | 8 +- .../comic_vine/comic_vine_client.h | 2 +- .../comic_vine/comic_vine_dialog.cpp | 48 +++++++---- .../comic_vine/comic_vine_dialog.h | 6 +- .../comic_vine/model/response_parser.cpp | 23 +++++- .../comic_vine/model/response_parser.h | 4 + .../comic_vine/scraper_results_paginator.cpp | 75 ++++++++++++++++++ .../comic_vine/scraper_results_paginator.h | 34 ++++++++ .../comic_vine/scraper_selector.cpp | 25 ++++++ .../comic_vine/scraper_selector.h | 28 +++++++ .../comic_vine/scraper_tableview.cpp | 2 + YACReaderLibrary/comic_vine/select_comic.cpp | 16 +++- YACReaderLibrary/comic_vine/select_comic.h | 6 +- YACReaderLibrary/comic_vine/select_volume.cpp | 43 +++++++--- YACReaderLibrary/comic_vine/select_volume.h | 9 ++- YACReaderLibrary/images.qrc | 6 +- images/comic_vine/downArrow.png | Bin 0 -> 139 bytes images/comic_vine/nextPage.png | Bin 0 -> 166 bytes images/comic_vine/previousPage.png | Bin 0 -> 167 bytes images/comic_vine/upArrow.png | Bin 0 -> 140 bytes 21 files changed, 301 insertions(+), 42 deletions(-) create mode 100644 YACReaderLibrary/comic_vine/scraper_results_paginator.cpp create mode 100644 YACReaderLibrary/comic_vine/scraper_results_paginator.h create mode 100644 YACReaderLibrary/comic_vine/scraper_selector.cpp create mode 100644 YACReaderLibrary/comic_vine/scraper_selector.h create mode 100644 images/comic_vine/downArrow.png create mode 100644 images/comic_vine/nextPage.png create mode 100644 images/comic_vine/previousPage.png create mode 100644 images/comic_vine/upArrow.png diff --git a/YACReaderLibrary/comic_vine/comic_vine.pri b/YACReaderLibrary/comic_vine/comic_vine.pri index 17d7c328..823e536a 100644 --- a/YACReaderLibrary/comic_vine/comic_vine.pri +++ b/YACReaderLibrary/comic_vine/comic_vine.pri @@ -17,7 +17,9 @@ HEADERS += \ comic_vine/sort_volume_comics.h \ comic_vine/model/local_comic_list_model.h \ comic_vine/model/volume_comics_model.h \ - comic_vine/scraper_scroll_label.h + comic_vine/scraper_scroll_label.h \ + comic_vine/scraper_results_paginator.h \ + comic_vine/scraper_selector.h SOURCES += \ comic_vine/comic_vine_dialog.cpp \ @@ -37,4 +39,6 @@ SOURCES += \ comic_vine/sort_volume_comics.cpp \ comic_vine/model/local_comic_list_model.cpp \ comic_vine/model/volume_comics_model.cpp \ - comic_vine/scraper_scroll_label.cpp + comic_vine/scraper_scroll_label.cpp \ + comic_vine/scraper_results_paginator.cpp \ + comic_vine/scraper_selector.cpp diff --git a/YACReaderLibrary/comic_vine/comic_vine_client.cpp b/YACReaderLibrary/comic_vine/comic_vine_client.cpp index 86c1341a..81eee743 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_client.cpp +++ b/YACReaderLibrary/comic_vine/comic_vine_client.cpp @@ -19,7 +19,9 @@ static const QString CV_SERIES_DETAIL = CV_WEB_ADDRESS + "/volume/4050-%1/?api_k //gets info for comics in a volume id %1 static const QString CV_COMICS_INFO = CV_WEB_ADDRESS + "/issues/?api_key=" + CV_API_KEY + - "&format=json&field_list=name,issue_number,id,image&filter=volume:%1";//offset?? + "&format=json&field_list=name,issue_number,id,image&filter=volume:%1&offset=%2";//offset?? + +//"http://www.comicvine.com/api/issues/?api_key=46680bebb358f1de690a5a365e15d325f9649f91&format=json&field_list=name,issue_number,id,image&filter=volume:%1&page=%2 //gets id for comic number %2 in a volume id %1 static const QString CV_COMIC_ID = CV_WEB_ADDRESS + "/issues/?api_key=" + CV_API_KEY + @@ -99,9 +101,9 @@ void ComicVineClient::getSeriesCover(const QString & url) } //CV_COMIC_IDS -void ComicVineClient::getVolumeComicsInfo(const QString & idVolume) +void ComicVineClient::getVolumeComicsInfo(const QString & idVolume, int page) { - HttpWorker * search = new HttpWorker(CV_COMICS_INFO.arg(idVolume)); + HttpWorker * search = new HttpWorker(CV_COMICS_INFO.arg(idVolume).arg((page-1)*100)); //page on works for search, using offset instead connect(search,SIGNAL(dataReady(const QByteArray &)),this,SLOT(processVolumeComicsInfo(const QByteArray &))); connect(search,SIGNAL(timeout()),this,SIGNAL(timeOut())); //TODO connect(search,SIGNAL(finished()),search,SLOT(deleteLater())); diff --git a/YACReaderLibrary/comic_vine/comic_vine_client.h b/YACReaderLibrary/comic_vine/comic_vine_client.h index 1b017e84..6e1bc579 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_client.h +++ b/YACReaderLibrary/comic_vine/comic_vine_client.h @@ -24,7 +24,7 @@ public slots: void search(const QString & query, int page = 1); void getSeriesDetail(const QString & id); void getSeriesCover(const QString & url); - void getVolumeComicsInfo(const QString & idVolume); + void getVolumeComicsInfo(const QString & idVolume, int page=1); QByteArray getComicDetail(const QString & id, bool &outError, bool &outTimeout); void getComicCover(const QString & url); diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp index 9fb12967..20980fc3 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp @@ -106,6 +106,10 @@ void ComicVineDialog::doConnections() connect(backButton,SIGNAL(clicked()),this,SLOT(goBack())); connect(searchButton,SIGNAL(clicked()),this,SLOT(search())); connect(skipButton,SIGNAL(clicked()),this,SLOT(goToNextComic())); + + connect(selectVolumeWidget,SIGNAL(loadPage(QString,int)),this,SLOT(searchVolume(QString,int))); + + connect(selectComicWidget,SIGNAL(loadPage(QString,int)),this,SLOT(getVolumeComicsInfo(QString,int))); } void ComicVineDialog::goNext() @@ -141,18 +145,9 @@ void ComicVineDialog::goNext() } } else if (content->currentWidget() == selectVolumeWidget) { - showLoading(tr("Retrieving volume info...")); + currentVolumeId = selectVolumeWidget->getSelectedVolumeId(); + getVolumeComicsInfo(currentVolumeId); - status = GettingVolumeComics; - - ComicVineClient * comicVineClient = new ComicVineClient; - if(mode == Volume) - connect(comicVineClient,SIGNAL(volumeComicsInfo(QString)),this,SLOT(showSortVolumeComics(QString))); - else - connect(comicVineClient,SIGNAL(volumeComicsInfo(QString)),this,SLOT(showSelectComic(QString))); - connect(comicVineClient,SIGNAL(timeOut()),this,SLOT(queryTimeOut())); - connect(comicVineClient,SIGNAL(finished()),comicVineClient,SLOT(deleteLater())); - comicVineClient->getVolumeComicsInfo(selectVolumeWidget->getSelectedVolumeId()); } else if (content->currentWidget() == sortVolumeComicsWidget) { showLoading(); @@ -328,7 +323,7 @@ void ComicVineDialog::showSearchVolume() void ComicVineDialog::showSelectVolume(const QString & json) { showSelectVolume(); - selectVolumeWidget->load(json); + selectVolumeWidget->load(json,currentVolumeSearchString); } void ComicVineDialog::showSelectVolume() @@ -349,7 +344,7 @@ void ComicVineDialog::showSelectComic(const QString &json) status = SelectingComic; content->setCurrentWidget(selectComicWidget); - selectComicWidget->load(json); + selectComicWidget->load(json,currentVolumeId); backButton->setVisible(true); nextButton->setVisible(true); @@ -662,17 +657,40 @@ void ComicVineDialog::search() } } -void ComicVineDialog::searchVolume(const QString &v) +void ComicVineDialog::searchVolume(const QString &v, int page) { + showLoading(tr("Looking for volume...")); + + currentVolumeSearchString = v; + ComicVineClient * comicVineClient = new ComicVineClient; connect(comicVineClient,SIGNAL(searchResult(QString)),this,SLOT(debugClientResults(QString))); connect(comicVineClient,SIGNAL(timeOut()),this,SLOT(queryTimeOut())); connect(comicVineClient,SIGNAL(finished()),comicVineClient,SLOT(deleteLater())); - comicVineClient->search(v); + comicVineClient->search(v,page); status = SearchingVolume; } +void ComicVineDialog::getVolumeComicsInfo(const QString &vID, int page) +{ + showLoading(tr("Retrieving volume info...")); + + status = GettingVolumeComics; + + ComicVineClient * comicVineClient = new ComicVineClient; + if(mode == Volume) + connect(comicVineClient,SIGNAL(volumeComicsInfo(QString)),this,SLOT(showSortVolumeComics(QString))); + else + connect(comicVineClient,SIGNAL(volumeComicsInfo(QString)),this,SLOT(showSelectComic(QString))); + connect(comicVineClient,SIGNAL(timeOut()),this,SLOT(queryTimeOut())); + connect(comicVineClient,SIGNAL(finished()),comicVineClient,SLOT(deleteLater())); + + QLOG_TRACE() << vID; + + comicVineClient->getVolumeComicsInfo(vID,page); +} + void ComicVineDialog::launchSearchVolume() { showLoading(tr("Looking for volume...")); diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.h b/YACReaderLibrary/comic_vine/comic_vine_dialog.h index 7cc58986..6474afa1 100644 --- a/YACReaderLibrary/comic_vine/comic_vine_dialog.h +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.h @@ -47,7 +47,8 @@ protected slots: void showSearchVolume(); void showLoading(const QString & message = ""); void search(); - void searchVolume(const QString & v); + void searchVolume(const QString & v, int page = 1); + void getVolumeComicsInfo(const QString &vID, int page = 1); void launchSearchVolume(); void launchSearchComic(); void showSelectVolume(const QString & json); @@ -121,6 +122,9 @@ private: SelectVolume * selectVolumeWidget; SelectComic * selectComicWidget; SortVolumeComics * sortVolumeComicsWidget; + + QString currentVolumeSearchString; + QString currentVolumeId; }; #endif // COMIC_VINE_DIALOG_H diff --git a/YACReaderLibrary/comic_vine/model/response_parser.cpp b/YACReaderLibrary/comic_vine/model/response_parser.cpp index 759067a3..1901def6 100644 --- a/YACReaderLibrary/comic_vine/model/response_parser.cpp +++ b/YACReaderLibrary/comic_vine/model/response_parser.cpp @@ -4,7 +4,7 @@ #include ResponseParser::ResponseParser(QObject *parent) : - QObject(parent),error(false),numResults(-1) + QObject(parent),error(false),numResults(-1),currentPage(-1),totalPages(-1) { } @@ -18,6 +18,16 @@ qint32 ResponseParser::getNumResults() return numResults; } +qint32 ResponseParser::getCurrentPage() +{ + return currentPage; +} + +qint32 ResponseParser::getTotalPages() +{ + return totalPages; +} + void ResponseParser::loadJSONResponse(const QString &response) { QScriptEngine engine; @@ -36,5 +46,16 @@ void ResponseParser::loadJSONResponse(const QString &response) numResults = sc.property("number_of_total_results").toString().toInt();// sc.property("number_of_total_results").toInt32(); else qDebug() << sc.property("oops").toString(); + + int limit = sc.property("limit").toInt32(); + int offset = sc.property("offset").toInt32(); + int total = sc.property("number_of_total_results").toInt32(); + if(limit > 0) + { + totalPages = (total / limit) + (total%limit>0?1:0); + currentPage = (offset / limit) + 1; + } + else + totalPages = currentPage = 1; } } diff --git a/YACReaderLibrary/comic_vine/model/response_parser.h b/YACReaderLibrary/comic_vine/model/response_parser.h index 17775598..9d325edf 100644 --- a/YACReaderLibrary/comic_vine/model/response_parser.h +++ b/YACReaderLibrary/comic_vine/model/response_parser.h @@ -10,6 +10,8 @@ public: explicit ResponseParser(QObject *parent = 0); bool responseError(); qint32 getNumResults(); + qint32 getCurrentPage(); + qint32 getTotalPages(); signals: public slots: @@ -18,6 +20,8 @@ public slots: protected: bool error; qint32 numResults; + qint32 currentPage; + qint32 totalPages; }; #endif // RESPONSE_PARSER_H diff --git a/YACReaderLibrary/comic_vine/scraper_results_paginator.cpp b/YACReaderLibrary/comic_vine/scraper_results_paginator.cpp new file mode 100644 index 00000000..f627d315 --- /dev/null +++ b/YACReaderLibrary/comic_vine/scraper_results_paginator.cpp @@ -0,0 +1,75 @@ +#include "scraper_results_paginator.h" +#include "response_parser.h" + +#include +#include +#include +#include + + +ScraperResultsPaginator::ScraperResultsPaginator(QWidget *parent) : + QWidget(parent),customLabel("items") +{ + QHBoxLayout * pagesButtonsLayout = new QHBoxLayout; + + QString labelStylesheet = "QLabel {color:white; font-size:12px;font-family:Arial;}"; + + nextPage = new QToolButton; + nextPage->setStyleSheet("QToolButton {border:none;}"); + QPixmap np(":/images/comic_vine/nextPage.png"); + nextPage->setIconSize(np.size()); + nextPage->setIcon(np); + + previousPage = new QToolButton; + previousPage->setStyleSheet("QToolButton {border:none;}"); + QPixmap pp(":/images/comic_vine/previousPage.png"); + previousPage->setIconSize(pp.size()); + previousPage->setIcon(pp); + + connect(nextPage,SIGNAL(clicked()),this,SIGNAL(loadNextPage())); + connect(previousPage,SIGNAL(clicked()),this,SIGNAL(loadPreviousPage())); + + numElements = new QLabel(tr("Number of volumes found : %1")); + numElements->setStyleSheet(labelStylesheet); + numPages = new QLabel(tr("page %1 of %2")); + numPages->setStyleSheet(labelStylesheet); + + pagesButtonsLayout->addSpacing(15); + pagesButtonsLayout->addWidget(numElements); + pagesButtonsLayout->addStretch(); + pagesButtonsLayout->addWidget(numPages); + pagesButtonsLayout->addWidget(previousPage); + pagesButtonsLayout->addWidget(nextPage); + + setContentsMargins(0,0,0,0); + pagesButtonsLayout->setContentsMargins(0,0,0,0); + + setLayout(pagesButtonsLayout); +} + +void ScraperResultsPaginator::update(const QString &json) +{ + ResponseParser rp; + rp.loadJSONResponse(json); + + currentPage = rp.getCurrentPage(); + numElements->setText(tr("Number of %1 found : %2").arg(customLabel).arg(rp.getNumResults())); + numPages->setText(tr("page %1 of %2").arg(currentPage).arg(rp.getTotalPages())); + + previousPage->setDisabled(currentPage == 1); + nextPage->setDisabled(currentPage == rp.getTotalPages()); + + numPages->setHidden(rp.getTotalPages()==1); + previousPage->setHidden(rp.getTotalPages()==1); + nextPage->setHidden(rp.getTotalPages()==1); +} + +int ScraperResultsPaginator::getCurrentPage() +{ + return currentPage; +} + +void ScraperResultsPaginator::setCustomLabel(const QString &label) +{ + customLabel = label; +} diff --git a/YACReaderLibrary/comic_vine/scraper_results_paginator.h b/YACReaderLibrary/comic_vine/scraper_results_paginator.h new file mode 100644 index 00000000..c371b7af --- /dev/null +++ b/YACReaderLibrary/comic_vine/scraper_results_paginator.h @@ -0,0 +1,34 @@ +#ifndef SCRAPER_RESULTS_PAGINATOR_H +#define SCRAPER_RESULTS_PAGINATOR_H + +#include + +class QToolButton; +class QLabel; + +class ScraperResultsPaginator : public QWidget +{ + Q_OBJECT +public: + explicit ScraperResultsPaginator(QWidget *parent = 0); + void update(const QString & json); + int getCurrentPage(); + void setCustomLabel(const QString & label); +signals: + void loadNextPage(); + void loadPreviousPage(); + +public slots: + +private: + QToolButton * nextPage; + QToolButton * previousPage; + QLabel * numElements; + QLabel * numPages; + + int currentPage; + + QString customLabel; +}; + +#endif // SCRAPER_RESULTS_PAGINATOR_H diff --git a/YACReaderLibrary/comic_vine/scraper_selector.cpp b/YACReaderLibrary/comic_vine/scraper_selector.cpp new file mode 100644 index 00000000..e79117b9 --- /dev/null +++ b/YACReaderLibrary/comic_vine/scraper_selector.cpp @@ -0,0 +1,25 @@ +#include "scraper_selector.h" + +ScraperSelector::ScraperSelector(QWidget *parent) : + QWidget(parent) +{ + paginator = new ScraperResultsPaginator; + connect(paginator,SIGNAL(loadNextPage()),this,SLOT(loadNextPage())); + connect(paginator,SIGNAL(loadPreviousPage()),this,SLOT(loadPreviousPage())); +} + +void ScraperSelector::load(const QString &json, const QString &searchString) +{ + currentSearchString = searchString; + paginator->update(json); +} + +void ScraperSelector::loadNextPage() +{ + emit loadPage(currentSearchString,paginator->getCurrentPage()+1); +} + +void ScraperSelector::loadPreviousPage() +{ + emit loadPage(currentSearchString,paginator->getCurrentPage()-1); +} diff --git a/YACReaderLibrary/comic_vine/scraper_selector.h b/YACReaderLibrary/comic_vine/scraper_selector.h new file mode 100644 index 00000000..34ce409f --- /dev/null +++ b/YACReaderLibrary/comic_vine/scraper_selector.h @@ -0,0 +1,28 @@ +#ifndef SCRAPER_SELECTOR_H +#define SCRAPER_SELECTOR_H + +#include + +#include "scraper_results_paginator.h" + +class ScraperSelector : public QWidget +{ + Q_OBJECT +public: + explicit ScraperSelector(QWidget *parent = 0); + virtual void load(const QString & json, const QString & searchString); +public slots: + +signals: + void loadPage(QString,int); + +private slots: + void loadNextPage(); + void loadPreviousPage(); + +protected: + QString currentSearchString; + ScraperResultsPaginator * paginator; +}; + +#endif // SCRAPER_SELECTOR_H diff --git a/YACReaderLibrary/comic_vine/scraper_tableview.cpp b/YACReaderLibrary/comic_vine/scraper_tableview.cpp index 543146b5..22dbbed1 100644 --- a/YACReaderLibrary/comic_vine/scraper_tableview.cpp +++ b/YACReaderLibrary/comic_vine/scraper_tableview.cpp @@ -10,6 +10,8 @@ ScraperTableView::ScraperTableView(QWidget *parent) : "QTableView::item:selected {outline: 0px; background-color: #555555; }" "QHeaderView::section:horizontal {background-color:#292929; border-bottom:1px solid #1F1F1F; border-right:1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #292929, stop: 1 #1F1F1F); border-left:none; border-top:none; padding:4px; color:#ebebeb;}" "QHeaderView::section:vertical {border-bottom: 1px solid #DFDFDF;border-top: 1px solid #FEFEFE;}" + "QHeaderView::down-arrow {image: url(':/images/comic_vine/downArrow.png');}" + "QHeaderView::up-arrow {image: url(':/images/comic_vine/upArrow.png');}" "QScrollBar:vertical { border: none; background: #2B2B2B; width: 3px; margin: 0; }" "QScrollBar:horizontal { border: none; background: #2B2B2B; height: 3px; margin: 0; }" "QScrollBar::handle:vertical { background: #DDDDDD; width: 7px; min-height: 20px; }" diff --git a/YACReaderLibrary/comic_vine/select_comic.cpp b/YACReaderLibrary/comic_vine/select_comic.cpp index 872a8958..8105dfb1 100644 --- a/YACReaderLibrary/comic_vine/select_comic.cpp +++ b/YACReaderLibrary/comic_vine/select_comic.cpp @@ -10,7 +10,7 @@ #include SelectComic::SelectComic(QWidget *parent) - :QWidget(parent),model(0) + :ScraperSelector(parent),model(0) { QString labelStylesheet = "QLabel {color:white; font-size:12px;font-family:Arial;}"; @@ -20,8 +20,11 @@ SelectComic::SelectComic(QWidget *parent) QVBoxLayout * l = new QVBoxLayout; QWidget * leftWidget = new QWidget; QVBoxLayout * left = new QVBoxLayout; + QVBoxLayout * right = new QVBoxLayout; QHBoxLayout * content = new QHBoxLayout; + right->setContentsMargins(0,0,0,0); + //widgets cover = new QLabel(); cover->setScaledContents(true); @@ -34,6 +37,8 @@ SelectComic::SelectComic(QWidget *parent) //connections connect(tableComics,SIGNAL(clicked(QModelIndex)),this,SLOT(loadComicInfo(QModelIndex))); + paginator->setCustomLabel(tr("comics")); + left->addWidget(cover); left->addWidget(detailLabel,1); left->addStretch(); @@ -42,8 +47,11 @@ SelectComic::SelectComic(QWidget *parent) left->setContentsMargins(0,0,0,0); leftWidget->setContentsMargins(0,0,0,0); + right->addWidget(tableComics,0,Qt::AlignRight|Qt::AlignTop); + right->addWidget(paginator); + content->addWidget(leftWidget); - content->addWidget(tableComics,0,Qt::AlignRight|Qt::AlignTop); + content->addLayout(right); l->addSpacing(15); l->addWidget(label); @@ -56,7 +64,7 @@ SelectComic::SelectComic(QWidget *parent) setContentsMargins(0,0,0,0); } -void SelectComic::load(const QString &json) +void SelectComic::load(const QString &json, const QString & searchString) { VolumeComicsModel * tempM = new VolumeComicsModel(); tempM->load(json); @@ -76,6 +84,8 @@ void SelectComic::load(const QString &json) } tableComics->resizeColumnToContents(0); + + ScraperSelector::load(json,searchString); } SelectComic::~SelectComic() {} diff --git a/YACReaderLibrary/comic_vine/select_comic.h b/YACReaderLibrary/comic_vine/select_comic.h index d968b708..5d14a08b 100644 --- a/YACReaderLibrary/comic_vine/select_comic.h +++ b/YACReaderLibrary/comic_vine/select_comic.h @@ -1,7 +1,7 @@ #ifndef SELECT_COMIC_H #define SELECT_COMIC_H -#include +#include "scraper_selector.h" class QLabel; class VolumeComicsModel; @@ -10,12 +10,12 @@ class QModelIndex; class ScraperScrollLabel; class ScraperTableView; -class SelectComic : public QWidget +class SelectComic : public ScraperSelector { Q_OBJECT public: SelectComic(QWidget * parent = 0); - void load(const QString & json); + void load(const QString & json, const QString & searchString); virtual ~SelectComic(); public slots: diff --git a/YACReaderLibrary/comic_vine/select_volume.cpp b/YACReaderLibrary/comic_vine/select_volume.cpp index 2220d55b..3faa3309 100644 --- a/YACReaderLibrary/comic_vine/select_volume.cpp +++ b/YACReaderLibrary/comic_vine/select_volume.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "scraper_tableview.h" @@ -17,9 +18,14 @@ #include "comic_vine_client.h" #include "scraper_scroll_label.h" +#include "response_parser.h" +#include "scraper_results_paginator.h" + SelectVolume::SelectVolume(QWidget *parent) - :QWidget(parent),model(0) + :ScraperSelector(parent),model(0) { + proxyModel = new QSortFilterProxyModel; + QString labelStylesheet = "QLabel {color:white; font-size:12px;font-family:Arial;}"; QLabel * label = new QLabel(tr("Please, select the right series for your comic.")); @@ -28,8 +34,11 @@ SelectVolume::SelectVolume(QWidget *parent) QVBoxLayout * l = new QVBoxLayout; QWidget * leftWidget = new QWidget; QVBoxLayout * left = new QVBoxLayout; + QVBoxLayout * right = new QVBoxLayout; QHBoxLayout * content = new QHBoxLayout; + right->setContentsMargins(0,0,0,0); + //widgets cover = new QLabel(); cover->setScaledContents(true); @@ -39,9 +48,15 @@ SelectVolume::SelectVolume(QWidget *parent) detailLabel = new ScraperScrollLabel(this); tableVolumes = new ScraperTableView(this); + tableVolumes->setSortingEnabled(true); + tableVolumes->horizontalHeader()->setSectionsClickable(true); + //tableVolumes->horizontalHeader()->setSortIndicatorShown(false); + connect(tableVolumes->horizontalHeader(),SIGNAL(sectionClicked(int)), tableVolumes, SLOT(sortByColumn(int))); //connections connect(tableVolumes,SIGNAL(clicked(QModelIndex)),this,SLOT(loadVolumeInfo(QModelIndex))); + paginator->setCustomLabel(tr("volumes")); + left->addWidget(cover); left->addWidget(detailLabel,1); left->addStretch(); @@ -50,8 +65,11 @@ SelectVolume::SelectVolume(QWidget *parent) left->setContentsMargins(0,0,0,0); leftWidget->setContentsMargins(0,0,0,0); + right->addWidget(tableVolumes,0,Qt::AlignRight|Qt::AlignTop); + right->addWidget(paginator); + content->addWidget(leftWidget); - content->addWidget(tableVolumes,0,Qt::AlignRight|Qt::AlignTop); + content->addLayout(right); l->addSpacing(15); l->addWidget(label); @@ -64,12 +82,15 @@ SelectVolume::SelectVolume(QWidget *parent) setContentsMargins(0,0,0,0); } -void SelectVolume::load(const QString & json) +void SelectVolume::load(const QString & json, const QString & searchString) { VolumesModel * tempM = new VolumesModel(); tempM->load(json); - tableVolumes->setModel(tempM); + //tableVolumes->setModel(tempM); + proxyModel->setSourceModel( tempM ); + tableVolumes->setModel(proxyModel); + tableVolumes->sortByColumn(0,Qt::AscendingOrder); tableVolumes->resizeColumnsToContents(); tableVolumes->setFixedSize(619,341); @@ -82,16 +103,19 @@ void SelectVolume::load(const QString & json) if(model->rowCount()>0) { tableVolumes->selectRow(0); - loadVolumeInfo(model->index(0,0)); + loadVolumeInfo(proxyModel->index(0,0)); } tableVolumes->setColumnWidth(0,350); + + ScraperSelector::load(json,searchString); } SelectVolume::~SelectVolume() {} -void SelectVolume::loadVolumeInfo(const QModelIndex & mi) +void SelectVolume::loadVolumeInfo(const QModelIndex & omi) { + QModelIndex mi = proxyModel->mapToSource(omi); QString coverURL = model->getCoverURL(mi); QString id = model->getVolumeId(mi); @@ -146,16 +170,17 @@ void SelectVolume::setDescription(const QString & jsonDetail) QString SelectVolume::getSelectedVolumeId() { - return model->getVolumeId(tableVolumes->currentIndex()); + return model->getVolumeId(proxyModel->mapToSource(tableVolumes->currentIndex())); } int SelectVolume::getSelectedVolumeNumIssues() { - return model->getNumIssues(tableVolumes->currentIndex()); + return model->getNumIssues(proxyModel->mapToSource(tableVolumes->currentIndex())); } QString SelectVolume::getSelectedVolumePublisher() { - return model->getPublisher(tableVolumes->currentIndex()); + return model->getPublisher(proxyModel->mapToSource(tableVolumes->currentIndex())); } + diff --git a/YACReaderLibrary/comic_vine/select_volume.h b/YACReaderLibrary/comic_vine/select_volume.h index 8757c900..060933c2 100644 --- a/YACReaderLibrary/comic_vine/select_volume.h +++ b/YACReaderLibrary/comic_vine/select_volume.h @@ -1,21 +1,23 @@ #ifndef SELECT_VOLUME_H #define SELECT_VOLUME_H -#include +#include "scraper_selector.h" class QLabel; class VolumesModel; class QModelIndex; +class QToolButton; +class QSortFilterProxyModel; class ScraperScrollLabel; class ScraperTableView; -class SelectVolume : public QWidget +class SelectVolume : public ScraperSelector { Q_OBJECT public: SelectVolume(QWidget * parent = 0); - void load(const QString & json); + void load(const QString & json, const QString & searchString); virtual ~SelectVolume(); public slots: @@ -31,6 +33,7 @@ private: ScraperScrollLabel * detailLabel; ScraperTableView * tableVolumes; VolumesModel * model; + QSortFilterProxyModel * proxyModel; }; #endif // SELECT_VOLUME_H diff --git a/YACReaderLibrary/images.qrc b/YACReaderLibrary/images.qrc index 8f8f0e63..11902b02 100644 --- a/YACReaderLibrary/images.qrc +++ b/YACReaderLibrary/images.qrc @@ -79,7 +79,7 @@ ../images/main_toolbar/divider.png ../images/collapsed_branch_osx.png ../images/expanded_branch_osx.png - ../images/folder_macosx.png + ../images/folder_macosx.png ../images/libraryIconSelected.png ../images/libraryOptions.png ../images/branch-open.png @@ -94,6 +94,10 @@ ../images/comic_vine/radioUnchecked.png ../images/comic_vine/rowDown.png ../images/comic_vine/rowUp.png + ../images/comic_vine/previousPage.png + ../images/comic_vine/nextPage.png + ../images/comic_vine/downArrow.png + ../images/comic_vine/upArrow.png ../images/find_folder.png diff --git a/images/comic_vine/downArrow.png b/images/comic_vine/downArrow.png new file mode 100644 index 0000000000000000000000000000000000000000..ef5be7af84caf9a92bbf0abe81e722ec2cafde35 GIT binary patch literal 139 zcmeAS@N?(olHy`uVBq!ia0vp^tU%1d!3HGVjK4YnDajJoh?3y^w370~qErUQl>DSr z1<%~X^wgl##FWaylc_d9MY^6Yjv*Ddk`fLuNjyJ4zh2%$TcOi7fk~({gG+d(kgza6 jgQV~RCSiw~1_ovZDIU%&>v{bCK#dHZu6{1-oD!M<4AUbA literal 0 HcmV?d00001 diff --git a/images/comic_vine/nextPage.png b/images/comic_vine/nextPage.png new file mode 100644 index 0000000000000000000000000000000000000000..46aaa8c6274a0a1ed59aa9534d31719e87006cd2 GIT binary patch literal 166 zcmeAS@N?(olHy`uVBq!ia0vp^>_E)H!3HEvS)PI@$r9IylHmNblJdl&R0hYC{G?O` z&)mfH)S%SFl*+=BsWw1G9-c0aAr-fhDt>)=S))*vaDYjoQRx4|H>?hKG<0?UGR#(C z-ldc?$-tnolhIt@fLbL(hiv09wM`2+o8DM4h%?^WDK|Zwfr*D<^InCQ{AX8v1)9m= M>FVdQ&MBb@0R2TYn*aa+ literal 0 HcmV?d00001 diff --git a/images/comic_vine/previousPage.png b/images/comic_vine/previousPage.png new file mode 100644 index 0000000000000000000000000000000000000000..01365a899dbfa2536a0d7bdbe11ab58509acc284 GIT binary patch literal 167 zcmeAS@N?(olHy`uVBq!ia0vp^>_E)H!3HEvS)PI@$r9IylHmNblJdl&R0hYC{G?O` z&)mfH)S%SFl*+=BsWw1Go}Mm_Ar-fhQVuZ9v#Wi@u;fwX1s2hU5PJdkh95c}OJW(jm@UPGb(DAfQL5IN2U@_w;H~rBaf%nG%zqTu;q*Wjwspv3uq{V Mr>mdKI;Vst0Oz4J3jhEB literal 0 HcmV?d00001 diff --git a/images/comic_vine/upArrow.png b/images/comic_vine/upArrow.png new file mode 100644 index 0000000000000000000000000000000000000000..a0c1303de836d829af181c51a3a286bff6797450 GIT binary patch literal 140 zcmeAS@N?(olHy`uVBq!ia0vp^tU%1d!3HGVjK4YnDajJoh?3y^w370~qErUQl>DSr z1<%~X^wgl##FWaylc_d9MS7ktjv*Ddk`fLuNjM()^YgQGLx`<_xtf}qnE?|kPs5zg l9$dUL9k?!*oM-1SV5qsl8SpxOkqA&HgQu&X%Q~loCIGgDC