mirror of
https://github.com/YACReader/yacreader
synced 2025-07-18 13:04:28 -04:00
added new history navigation for supporting different source containers
This commit is contained in:
@ -9,7 +9,7 @@ void YACReaderHistoryController::clear()
|
|||||||
{
|
{
|
||||||
currentFolderNavigation = 0;
|
currentFolderNavigation = 0;
|
||||||
history.clear();
|
history.clear();
|
||||||
history.append(QModelIndex()); //root folder is always the first item
|
history.append(YACReaderLibrarySourceContainer(QModelIndex(),YACReaderLibrarySourceContainer::Folder)); //root folder is always the first item
|
||||||
|
|
||||||
emit(enabledBackward(false));
|
emit(enabledBackward(false));
|
||||||
emit(enabledForward(false));
|
emit(enabledForward(false));
|
||||||
@ -41,10 +41,10 @@ void YACReaderHistoryController::forward()
|
|||||||
emit(enabledForward(false));
|
emit(enabledForward(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
void YACReaderHistoryController::updateHistory(const QModelIndex &mi)
|
void YACReaderHistoryController::updateHistory(const YACReaderLibrarySourceContainer &source)
|
||||||
{
|
{
|
||||||
//remove history from current index
|
//remove history from current index
|
||||||
if(!mi.isValid() && history.count() == 1)
|
if(!source.sourceModelIndex.isValid() && history.count() == 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int numElementsToRemove = history.count() - (currentFolderNavigation+1);
|
int numElementsToRemove = history.count() - (currentFolderNavigation+1);
|
||||||
@ -54,9 +54,9 @@ void YACReaderHistoryController::updateHistory(const QModelIndex &mi)
|
|||||||
history.removeLast();
|
history.removeLast();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mi!=history.at(currentFolderNavigation))
|
if(source!=history.at(currentFolderNavigation))
|
||||||
{
|
{
|
||||||
history.append(mi);
|
history.append(source);
|
||||||
|
|
||||||
emit(enabledBackward(true));
|
emit(enabledBackward(true));
|
||||||
currentFolderNavigation++;
|
currentFolderNavigation++;
|
||||||
@ -65,12 +65,44 @@ void YACReaderHistoryController::updateHistory(const QModelIndex &mi)
|
|||||||
emit(enabledForward(false));
|
emit(enabledForward(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex YACReaderHistoryController::lastIndex()
|
YACReaderLibrarySourceContainer YACReaderHistoryController::lastSourceContainer()
|
||||||
{
|
{
|
||||||
return history.last();
|
return history.last();
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex YACReaderHistoryController::currentIndex()
|
YACReaderLibrarySourceContainer YACReaderHistoryController::currentSourceContainer()
|
||||||
{
|
{
|
||||||
return history.at(currentFolderNavigation);
|
return history.at(currentFolderNavigation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
YACReaderLibrarySourceContainer::YACReaderLibrarySourceContainer()
|
||||||
|
:sourceModelIndex(QModelIndex()),type(None)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
YACReaderLibrarySourceContainer::YACReaderLibrarySourceContainer(const QModelIndex &sourceModelIndex, YACReaderLibrarySourceContainer::SourceType type)
|
||||||
|
:sourceModelIndex(sourceModelIndex),type(type)
|
||||||
|
{}
|
||||||
|
|
||||||
|
QModelIndex YACReaderLibrarySourceContainer::getSourceModelIndex() const
|
||||||
|
{
|
||||||
|
return sourceModelIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
YACReaderLibrarySourceContainer::SourceType YACReaderLibrarySourceContainer::getType() const
|
||||||
|
{
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool YACReaderLibrarySourceContainer::operator==(const YACReaderLibrarySourceContainer &other) const
|
||||||
|
{
|
||||||
|
return sourceModelIndex == other.sourceModelIndex && type == other.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool YACReaderLibrarySourceContainer::operator!=(const YACReaderLibrarySourceContainer &other) const
|
||||||
|
{
|
||||||
|
return !(*this == other);
|
||||||
|
}
|
||||||
|
@ -5,6 +5,35 @@
|
|||||||
|
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
|
|
||||||
|
class YACReaderHistoryController;
|
||||||
|
|
||||||
|
class YACReaderLibrarySourceContainer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum SourceType {
|
||||||
|
None,
|
||||||
|
Folder,
|
||||||
|
List
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit YACReaderLibrarySourceContainer();
|
||||||
|
explicit YACReaderLibrarySourceContainer(const QModelIndex & sourceModelIndex, YACReaderLibrarySourceContainer::SourceType type);
|
||||||
|
QModelIndex getSourceModelIndex() const;
|
||||||
|
YACReaderLibrarySourceContainer::SourceType getType() const;
|
||||||
|
|
||||||
|
bool operator==(const YACReaderLibrarySourceContainer& other) const;
|
||||||
|
bool operator!=(const YACReaderLibrarySourceContainer& other) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QModelIndex sourceModelIndex;
|
||||||
|
YACReaderLibrarySourceContainer::SourceType type;
|
||||||
|
|
||||||
|
friend class YACReaderHistoryController;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(YACReaderLibrarySourceContainer)
|
||||||
|
|
||||||
class YACReaderHistoryController : public QObject
|
class YACReaderHistoryController : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -14,19 +43,19 @@ public:
|
|||||||
signals:
|
signals:
|
||||||
void enabledForward(bool enabled);
|
void enabledForward(bool enabled);
|
||||||
void enabledBackward(bool enabled);
|
void enabledBackward(bool enabled);
|
||||||
void modelIndexSelected(QModelIndex mi);
|
void modelIndexSelected(YACReaderLibrarySourceContainer);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void clear();
|
void clear();
|
||||||
void backward();
|
void backward();
|
||||||
void forward();
|
void forward();
|
||||||
void updateHistory(const QModelIndex & mi);
|
void updateHistory(const YACReaderLibrarySourceContainer & source);
|
||||||
QModelIndex lastIndex();
|
YACReaderLibrarySourceContainer lastSourceContainer();
|
||||||
QModelIndex currentIndex();
|
YACReaderLibrarySourceContainer currentSourceContainer();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int currentFolderNavigation;
|
int currentFolderNavigation;
|
||||||
QList<QModelIndex> history;
|
QList<YACReaderLibrarySourceContainer> history;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ void YACReaderNavigationController::selectedFolder(const QModelIndex &mi)
|
|||||||
QModelIndex modelIndex = libraryWindow->foldersModelProxy->mapToSource(mi);
|
QModelIndex modelIndex = libraryWindow->foldersModelProxy->mapToSource(mi);
|
||||||
|
|
||||||
//update history
|
//update history
|
||||||
libraryWindow->historyController->updateHistory(modelIndex);
|
libraryWindow->historyController->updateHistory(YACReaderLibrarySourceContainer(modelIndex, YACReaderLibrarySourceContainer::Folder));
|
||||||
|
|
||||||
if(libraryWindow->status == LibraryWindow::Searching)
|
if(libraryWindow->status == LibraryWindow::Searching)
|
||||||
{
|
{
|
||||||
@ -173,7 +173,7 @@ void YACReaderNavigationController::selectedList(const QModelIndex &mi)
|
|||||||
QModelIndex modelIndex = libraryWindow->listsModelProxy->mapToSource(mi);
|
QModelIndex modelIndex = libraryWindow->listsModelProxy->mapToSource(mi);
|
||||||
|
|
||||||
//update history
|
//update history
|
||||||
libraryWindow->historyController->updateHistory(modelIndex);
|
libraryWindow->historyController->updateHistory(YACReaderLibrarySourceContainer(modelIndex,YACReaderLibrarySourceContainer::List));
|
||||||
|
|
||||||
if(libraryWindow->status == LibraryWindow::Searching)
|
if(libraryWindow->status == LibraryWindow::Searching)
|
||||||
{
|
{
|
||||||
@ -195,7 +195,7 @@ void YACReaderNavigationController::reselectCurrentList()
|
|||||||
selectedList(libraryWindow->listsView->currentIndex());
|
selectedList(libraryWindow->listsView->currentIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
void YACReaderNavigationController::selectedIndexFromHistory(const QModelIndex &sourceMI)
|
void YACReaderNavigationController::selectedIndexFromHistory(const YACReaderLibrarySourceContainer &sourceContainer)
|
||||||
{
|
{
|
||||||
//TODO NO searching allowed, just disable backward/forward actions in searching mode
|
//TODO NO searching allowed, just disable backward/forward actions in searching mode
|
||||||
if(libraryWindow->status == LibraryWindow::Searching)
|
if(libraryWindow->status == LibraryWindow::Searching)
|
||||||
@ -206,17 +206,38 @@ void YACReaderNavigationController::selectedIndexFromHistory(const QModelIndex &
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO more info about mi is needed (folder, lists...)
|
//TODO more info about mi is needed (folder, lists...)
|
||||||
QModelIndex mi = libraryWindow->foldersModelProxy->mapFromSource(sourceMI);
|
loadIndexFromHistory(sourceContainer);
|
||||||
libraryWindow->foldersView->scrollTo(mi,QAbstractItemView::PositionAtTop);
|
}
|
||||||
libraryWindow->foldersView->setCurrentIndex(mi);
|
|
||||||
loadFolderInfo(sourceMI);
|
void YACReaderNavigationController::loadIndexFromHistory(const YACReaderLibrarySourceContainer &sourceContainer)
|
||||||
|
{
|
||||||
|
QModelIndex sourceMI = sourceContainer.getSourceModelIndex();
|
||||||
|
switch(sourceContainer.getType())
|
||||||
|
{
|
||||||
|
case YACReaderLibrarySourceContainer::Folder:
|
||||||
|
{
|
||||||
|
QModelIndex mi = libraryWindow->foldersModelProxy->mapFromSource(sourceMI);
|
||||||
|
libraryWindow->foldersView->scrollTo(mi,QAbstractItemView::PositionAtTop);
|
||||||
|
libraryWindow->foldersView->setCurrentIndex(mi);
|
||||||
|
loadFolderInfo(sourceMI);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case YACReaderLibrarySourceContainer::List:
|
||||||
|
{
|
||||||
|
QModelIndex mi = libraryWindow->listsModelProxy->mapFromSource(sourceMI);
|
||||||
|
libraryWindow->listsView->scrollTo(mi,QAbstractItemView::PositionAtTop);
|
||||||
|
libraryWindow->listsView->setCurrentIndex(mi);
|
||||||
|
loadListInfo(sourceMI);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void YACReaderNavigationController::selectSubfolder(const QModelIndex &sourceMIParent, int child)
|
void YACReaderNavigationController::selectSubfolder(const QModelIndex &sourceMIParent, int child)
|
||||||
{
|
{
|
||||||
QModelIndex dest = libraryWindow->foldersModel->index(child,0,sourceMIParent);
|
QModelIndex dest = libraryWindow->foldersModel->index(child,0,sourceMIParent);
|
||||||
libraryWindow->foldersView->setCurrentIndex(libraryWindow->foldersModelProxy->mapFromSource(dest));
|
libraryWindow->foldersView->setCurrentIndex(libraryWindow->foldersModelProxy->mapFromSource(dest));
|
||||||
libraryWindow->historyController->updateHistory(dest);
|
libraryWindow->historyController->updateHistory(YACReaderLibrarySourceContainer(dest,YACReaderLibrarySourceContainer::Folder));
|
||||||
loadFolderInfo(dest);
|
loadFolderInfo(dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,18 +250,15 @@ void YACReaderNavigationController::loadEmptyFolderInfo(const QModelIndex &model
|
|||||||
|
|
||||||
void YACReaderNavigationController::loadPreviousStatus()
|
void YACReaderNavigationController::loadPreviousStatus()
|
||||||
{
|
{
|
||||||
QModelIndex sourceMI = libraryWindow->historyController->currentIndex();
|
YACReaderLibrarySourceContainer sourceContainer = libraryWindow->historyController->currentSourceContainer();
|
||||||
QModelIndex mi = libraryWindow->foldersModelProxy->mapFromSource(sourceMI);
|
loadIndexFromHistory(sourceContainer);
|
||||||
libraryWindow->foldersView->scrollTo(mi,QAbstractItemView::PositionAtTop);
|
|
||||||
libraryWindow->foldersView->setCurrentIndex(mi);
|
|
||||||
loadFolderInfo(sourceMI);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void YACReaderNavigationController::setupConnections()
|
void YACReaderNavigationController::setupConnections()
|
||||||
{
|
{
|
||||||
connect(libraryWindow->foldersView,SIGNAL(clicked(QModelIndex)),this,SLOT(selectedFolder(QModelIndex)));
|
connect(libraryWindow->foldersView,SIGNAL(clicked(QModelIndex)),this,SLOT(selectedFolder(QModelIndex)));
|
||||||
connect(libraryWindow->listsView,SIGNAL(clicked(QModelIndex)),this,SLOT(selectedList(QModelIndex)));
|
connect(libraryWindow->listsView,SIGNAL(clicked(QModelIndex)),this,SLOT(selectedList(QModelIndex)));
|
||||||
connect(libraryWindow->historyController,SIGNAL(modelIndexSelected(QModelIndex)),this,SLOT(selectedIndexFromHistory(QModelIndex)));
|
connect(libraryWindow->historyController,SIGNAL(modelIndexSelected(YACReaderLibrarySourceContainer)),this,SLOT(selectedIndexFromHistory(YACReaderLibrarySourceContainer)));
|
||||||
connect(libraryWindow->emptyFolderWidget,SIGNAL(subfolderSelected(QModelIndex,int)),this,SLOT(selectSubfolder(QModelIndex,int)));
|
connect(libraryWindow->emptyFolderWidget,SIGNAL(subfolderSelected(QModelIndex,int)),this,SLOT(selectSubfolder(QModelIndex,int)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
class LibraryWindow;
|
class LibraryWindow;
|
||||||
|
class YACReaderLibrarySourceContainer;
|
||||||
|
|
||||||
class YACReaderNavigationController : public QObject
|
class YACReaderNavigationController : public QObject
|
||||||
{
|
{
|
||||||
@ -23,7 +23,8 @@ public slots:
|
|||||||
void selectedList(const QModelIndex & mi);
|
void selectedList(const QModelIndex & mi);
|
||||||
void reselectCurrentList();
|
void reselectCurrentList();
|
||||||
//history navigation
|
//history navigation
|
||||||
void selectedIndexFromHistory(const QModelIndex & mi);
|
void selectedIndexFromHistory(const YACReaderLibrarySourceContainer &sourceContainer);
|
||||||
|
void loadIndexFromHistory(const YACReaderLibrarySourceContainer &sourceContainer);
|
||||||
//empty subfolder
|
//empty subfolder
|
||||||
void selectSubfolder(const QModelIndex &sourceMI, int child);
|
void selectSubfolder(const QModelIndex &sourceMI, int child);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user