mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
moved history navigation to its own class
This commit is contained in:
parent
ab81cebf92
commit
3b08d75d15
@ -125,7 +125,8 @@ HEADERS += comic_flow.h \
|
|||||||
db/reading_list_item.h \
|
db/reading_list_item.h \
|
||||||
yacreader_folders_view.h \
|
yacreader_folders_view.h \
|
||||||
yacreader_reading_lists_view.h \
|
yacreader_reading_lists_view.h \
|
||||||
add_label_dialog.h
|
add_label_dialog.h \
|
||||||
|
yacreader_history_controller.h
|
||||||
|
|
||||||
|
|
||||||
SOURCES += comic_flow.cpp \
|
SOURCES += comic_flow.cpp \
|
||||||
@ -179,7 +180,8 @@ SOURCES += comic_flow.cpp \
|
|||||||
db/reading_list_item.cpp \
|
db/reading_list_item.cpp \
|
||||||
yacreader_folders_view.cpp \
|
yacreader_folders_view.cpp \
|
||||||
yacreader_reading_lists_view.cpp \
|
yacreader_reading_lists_view.cpp \
|
||||||
add_label_dialog.cpp
|
add_label_dialog.cpp \
|
||||||
|
yacreader_history_controller.cpp
|
||||||
|
|
||||||
|
|
||||||
include(./server/server.pri)
|
include(./server/server.pri)
|
||||||
|
@ -77,6 +77,8 @@
|
|||||||
#include "yacreader_reading_lists_view.h"
|
#include "yacreader_reading_lists_view.h"
|
||||||
#include "add_label_dialog.h"
|
#include "add_label_dialog.h"
|
||||||
|
|
||||||
|
#include "yacreader_history_controller.h"
|
||||||
|
|
||||||
#include "QsLog.h"
|
#include "QsLog.h"
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
@ -116,6 +118,8 @@ void LibraryWindow::setupUI()
|
|||||||
settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creación del fichero de config con el servidor
|
settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creación del fichero de config con el servidor
|
||||||
settings->beginGroup("libraryConfig");
|
settings->beginGroup("libraryConfig");
|
||||||
|
|
||||||
|
historyController = new YACReaderHistoryController(this);
|
||||||
|
|
||||||
createActions();
|
createActions();
|
||||||
doModels();
|
doModels();
|
||||||
|
|
||||||
@ -1016,8 +1020,14 @@ void LibraryWindow::createMenus()
|
|||||||
void LibraryWindow::createConnections()
|
void LibraryWindow::createConnections()
|
||||||
{
|
{
|
||||||
//history navigation
|
//history navigation
|
||||||
connect(backAction,SIGNAL(triggered()),this,SLOT(backward()));
|
connect(backAction,SIGNAL(triggered()),historyController,SLOT(backward()));
|
||||||
connect(forwardAction,SIGNAL(triggered()),this,SLOT(forward()));
|
connect(forwardAction,SIGNAL(triggered()),historyController,SLOT(forward()));
|
||||||
|
//--
|
||||||
|
connect(historyController,SIGNAL(enabledBackward(bool)),backAction,SLOT(setEnabled(bool)));
|
||||||
|
connect(historyController,SIGNAL(enabledForward(bool)),forwardAction,SLOT(setEnabled(bool)));
|
||||||
|
connect(historyController,SIGNAL(modelIndexSelected(QModelIndex)),this,SLOT(loadCovers(QModelIndex)));
|
||||||
|
connect(historyController,SIGNAL(modelIndexSelected(QModelIndex)),foldersView,SLOT(setCurrentIndex(QModelIndex)));
|
||||||
|
connect(foldersView, SIGNAL(clicked(QModelIndex)), historyController, SLOT(updateHistory(QModelIndex)));
|
||||||
|
|
||||||
//libraryCreator connections
|
//libraryCreator connections
|
||||||
connect(createLibraryDialog,SIGNAL(createLibrary(QString,QString,QString)),this,SLOT(create(QString,QString,QString)));
|
connect(createLibraryDialog,SIGNAL(createLibrary(QString,QString,QString)),this,SLOT(create(QString,QString,QString)));
|
||||||
@ -1065,8 +1075,7 @@ void LibraryWindow::createConnections()
|
|||||||
|
|
||||||
//navigations between view modes (tree,list and flow)
|
//navigations between view modes (tree,list and flow)
|
||||||
connect(foldersView, SIGNAL(pressed(QModelIndex)), this, SLOT(updateFoldersViewConextMenu(QModelIndex)));
|
connect(foldersView, SIGNAL(pressed(QModelIndex)), this, SLOT(updateFoldersViewConextMenu(QModelIndex)));
|
||||||
connect(foldersView, SIGNAL(clicked(QModelIndex)), this, SLOT(loadCovers(QModelIndex)));
|
connect(foldersView, SIGNAL(clicked(QModelIndex)), this, SLOT(loadCovers(QModelIndex)));
|
||||||
connect(foldersView, SIGNAL(clicked(QModelIndex)), this, SLOT(updateHistory(QModelIndex)));
|
|
||||||
|
|
||||||
//drops in folders view
|
//drops in folders view
|
||||||
connect(foldersView, SIGNAL(copyComicsToFolder(QList<QPair<QString,QString> >,QModelIndex)), this, SLOT(copyAndImportComicsToFolder(QList<QPair<QString,QString> >,QModelIndex)));
|
connect(foldersView, SIGNAL(copyComicsToFolder(QList<QPair<QString,QString> >,QModelIndex)), this, SLOT(copyAndImportComicsToFolder(QList<QPair<QString,QString> >,QModelIndex)));
|
||||||
@ -1170,11 +1179,7 @@ void LibraryWindow::loadLibrary(const QString & name)
|
|||||||
{
|
{
|
||||||
if(!libraries.isEmpty()) //si hay bibliotecas...
|
if(!libraries.isEmpty()) //si hay bibliotecas...
|
||||||
{
|
{
|
||||||
currentFolderNavigation=0;
|
historyController->clear();
|
||||||
backAction->setDisabled(true);
|
|
||||||
forwardAction->setDisabled(true);
|
|
||||||
history.clear();
|
|
||||||
history.append(QModelIndex());
|
|
||||||
|
|
||||||
showRootWidget();
|
showRootWidget();
|
||||||
QString path=libraries.getPath(name)+"/.yacreaderlibrary";
|
QString path=libraries.getPath(name)+"/.yacreaderlibrary";
|
||||||
@ -1700,7 +1705,7 @@ void LibraryWindow::selectSubfolder(const QModelIndex &mi, int child)
|
|||||||
{
|
{
|
||||||
QModelIndex dest = foldersModel->index(child,0,mi);
|
QModelIndex dest = foldersModel->index(child,0,mi);
|
||||||
foldersView->setCurrentIndex(dest);
|
foldersView->setCurrentIndex(dest);
|
||||||
updateHistory(dest);
|
historyController->updateHistory(dest);
|
||||||
loadCovers(dest);
|
loadCovers(dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2001,8 +2006,7 @@ void LibraryWindow::setRootIndex()
|
|||||||
if(d.exists(path))
|
if(d.exists(path))
|
||||||
{
|
{
|
||||||
loadCovers(QModelIndex());
|
loadCovers(QModelIndex());
|
||||||
if(history.count()>1)
|
historyController->updateHistory(QModelIndex());
|
||||||
updateHistory(QModelIndex());
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2071,7 +2075,7 @@ void LibraryWindow::setSearchFilter(const YACReader::SearchModifiers modifier, Q
|
|||||||
{
|
{
|
||||||
QModelIndex mi = foldersModel->indexFromItem(index,column);
|
QModelIndex mi = foldersModel->indexFromItem(index,column);
|
||||||
foldersView->scrollTo(mi,QAbstractItemView::PositionAtTop);
|
foldersView->scrollTo(mi,QAbstractItemView::PositionAtTop);
|
||||||
updateHistory(mi);
|
historyController->updateHistory(mi);
|
||||||
foldersView->setCurrentIndex(mi);
|
foldersView->setCurrentIndex(mi);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -2535,59 +2539,6 @@ void LibraryWindow::showSocial()
|
|||||||
socialDialog->setHidden(false);
|
socialDialog->setHidden(false);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
void LibraryWindow::backward()
|
|
||||||
{
|
|
||||||
if(currentFolderNavigation>0)
|
|
||||||
{
|
|
||||||
currentFolderNavigation--;
|
|
||||||
loadCovers(history.at(currentFolderNavigation));
|
|
||||||
foldersView->setCurrentIndex(history.at(currentFolderNavigation));
|
|
||||||
forwardAction->setEnabled(true);
|
|
||||||
}
|
|
||||||
if(currentFolderNavigation==0)
|
|
||||||
{
|
|
||||||
backAction->setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LibraryWindow::forward()
|
|
||||||
{
|
|
||||||
if(currentFolderNavigation<history.count()-1)
|
|
||||||
{
|
|
||||||
currentFolderNavigation++;
|
|
||||||
loadCovers(history.at(currentFolderNavigation));
|
|
||||||
foldersView->setCurrentIndex(history.at(currentFolderNavigation));
|
|
||||||
backAction->setEnabled(true);
|
|
||||||
}
|
|
||||||
if(currentFolderNavigation==history.count()-1)
|
|
||||||
{
|
|
||||||
forwardAction->setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LibraryWindow::updateHistory(const QModelIndex &mi)
|
|
||||||
{
|
|
||||||
//remove history from current index
|
|
||||||
if(!mi.isValid())
|
|
||||||
return;
|
|
||||||
int numElementsToRemove = history.count() - (currentFolderNavigation+1);
|
|
||||||
while(numElementsToRemove>0)
|
|
||||||
{
|
|
||||||
numElementsToRemove--;
|
|
||||||
history.removeLast();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(mi!=history.at(currentFolderNavigation))
|
|
||||||
{
|
|
||||||
history.append(mi);
|
|
||||||
|
|
||||||
backAction->setEnabled(true);
|
|
||||||
currentFolderNavigation++;
|
|
||||||
}
|
|
||||||
|
|
||||||
forwardAction->setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LibraryWindow::updateFoldersViewConextMenu(const QModelIndex &mi)
|
void LibraryWindow::updateFoldersViewConextMenu(const QModelIndex &mi)
|
||||||
{
|
{
|
||||||
if(!mi.isValid())
|
if(!mi.isValid())
|
||||||
|
@ -64,6 +64,7 @@ class ComicFilesManager;
|
|||||||
class QProgressDialog;
|
class QProgressDialog;
|
||||||
class ReadingListModel;
|
class ReadingListModel;
|
||||||
class YACReaderReadingListsView;
|
class YACReaderReadingListsView;
|
||||||
|
class YACReaderHistoryController;
|
||||||
|
|
||||||
#include "comic_db.h"
|
#include "comic_db.h"
|
||||||
|
|
||||||
@ -265,8 +266,7 @@ private:
|
|||||||
QSettings * settings;
|
QSettings * settings;
|
||||||
|
|
||||||
//navigation backward and forward
|
//navigation backward and forward
|
||||||
int currentFolderNavigation;
|
YACReaderHistoryController * historyController;
|
||||||
QList<QModelIndex> history;
|
|
||||||
|
|
||||||
bool removeError;
|
bool removeError;
|
||||||
|
|
||||||
@ -331,9 +331,6 @@ public slots:
|
|||||||
QModelIndexList getSelectedComics();
|
QModelIndexList getSelectedComics();
|
||||||
void deleteComics();
|
void deleteComics();
|
||||||
//void showSocial();
|
//void showSocial();
|
||||||
void backward();
|
|
||||||
void forward();
|
|
||||||
void updateHistory(const QModelIndex & mi);
|
|
||||||
void updateFoldersViewConextMenu(const QModelIndex & mi);
|
void updateFoldersViewConextMenu(const QModelIndex & mi);
|
||||||
void libraryAlreadyExists(const QString & name);
|
void libraryAlreadyExists(const QString & name);
|
||||||
void importLibraryPackage();
|
void importLibraryPackage();
|
||||||
|
66
YACReaderLibrary/yacreader_history_controller.cpp
Normal file
66
YACReaderLibrary/yacreader_history_controller.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#include "yacreader_history_controller.h"
|
||||||
|
|
||||||
|
YACReaderHistoryController::YACReaderHistoryController(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void YACReaderHistoryController::clear()
|
||||||
|
{
|
||||||
|
currentFolderNavigation = 0;
|
||||||
|
history.clear();
|
||||||
|
history.append(QModelIndex()); //root folder is always the first item
|
||||||
|
|
||||||
|
emit(enabledBackward(false));
|
||||||
|
emit(enabledForward(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
void YACReaderHistoryController::backward()
|
||||||
|
{
|
||||||
|
if(currentFolderNavigation>0)
|
||||||
|
{
|
||||||
|
currentFolderNavigation--;
|
||||||
|
emit(modelIndexSelected(history.at(currentFolderNavigation)));
|
||||||
|
emit(enabledForward(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(currentFolderNavigation==0)
|
||||||
|
emit(enabledBackward(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
void YACReaderHistoryController::forward()
|
||||||
|
{
|
||||||
|
if(currentFolderNavigation<history.count()-1)
|
||||||
|
{
|
||||||
|
currentFolderNavigation++;
|
||||||
|
emit(modelIndexSelected(history.at(currentFolderNavigation)));
|
||||||
|
emit(enabledBackward(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(currentFolderNavigation==history.count()-1)
|
||||||
|
emit(enabledForward(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
void YACReaderHistoryController::updateHistory(const QModelIndex &mi)
|
||||||
|
{
|
||||||
|
//remove history from current index
|
||||||
|
if(!mi.isValid() && history.count() == 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int numElementsToRemove = history.count() - (currentFolderNavigation+1);
|
||||||
|
while(numElementsToRemove>0)
|
||||||
|
{
|
||||||
|
numElementsToRemove--;
|
||||||
|
history.removeLast();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mi!=history.at(currentFolderNavigation))
|
||||||
|
{
|
||||||
|
history.append(mi);
|
||||||
|
|
||||||
|
emit(enabledBackward(true));
|
||||||
|
currentFolderNavigation++;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit(enabledForward(false));
|
||||||
|
}
|
31
YACReaderLibrary/yacreader_history_controller.h
Normal file
31
YACReaderLibrary/yacreader_history_controller.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef YACREADER_HISTORY_CONTROLLER_H
|
||||||
|
#define YACREADER_HISTORY_CONTROLLER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#include <QModelIndex>
|
||||||
|
|
||||||
|
class YACReaderHistoryController : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit YACReaderHistoryController(QObject *parent = 0);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void enabledForward(bool enabled);
|
||||||
|
void enabledBackward(bool enabled);
|
||||||
|
void modelIndexSelected(QModelIndex mi);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void clear();
|
||||||
|
void backward();
|
||||||
|
void forward();
|
||||||
|
void updateHistory(const QModelIndex & mi);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int currentFolderNavigation;
|
||||||
|
QList<QModelIndex> history;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // YACREADER_HISTORY_CONTROLLER_H
|
Loading…
x
Reference in New Issue
Block a user