added custom context menu to folders view

This commit is contained in:
Luis Ángel San Martín 2014-11-28 13:27:17 +01:00
parent b0711bec86
commit 1ca994451c
4 changed files with 32 additions and 37 deletions

View File

@ -644,25 +644,21 @@ void LibraryWindow::createActions()
setFolderAsNotCompletedAction = new QAction(this); setFolderAsNotCompletedAction = new QAction(this);
setFolderAsNotCompletedAction->setText(tr("Set as uncompleted")); setFolderAsNotCompletedAction->setText(tr("Set as uncompleted"));
setFolderAsNotCompletedAction->setVisible(false);
setFolderAsNotCompletedAction->setData(SET_FOLDER_AS_NOT_COMPLETED_ACTION_YL); setFolderAsNotCompletedAction->setData(SET_FOLDER_AS_NOT_COMPLETED_ACTION_YL);
setFolderAsNotCompletedAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_FOLDER_AS_NOT_COMPLETED_ACTION_YL)); setFolderAsNotCompletedAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_FOLDER_AS_NOT_COMPLETED_ACTION_YL));
setFolderAsCompletedAction = new QAction(this); setFolderAsCompletedAction = new QAction(this);
setFolderAsCompletedAction->setText(tr("Set as completed")); setFolderAsCompletedAction->setText(tr("Set as completed"));
setFolderAsCompletedAction->setVisible(false);
setFolderAsCompletedAction->setData(SET_FOLDER_AS_COMPLETED_ACTION_YL); setFolderAsCompletedAction->setData(SET_FOLDER_AS_COMPLETED_ACTION_YL);
setFolderAsCompletedAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_FOLDER_AS_COMPLETED_ACTION_YL)); setFolderAsCompletedAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_FOLDER_AS_COMPLETED_ACTION_YL));
setFolderAsReadAction = new QAction(this); setFolderAsReadAction = new QAction(this);
setFolderAsReadAction->setText(tr("Set as read")); setFolderAsReadAction->setText(tr("Set as read"));
setFolderAsReadAction->setVisible(false);
setFolderAsReadAction->setData(SET_FOLDER_AS_READ_ACTION_YL); setFolderAsReadAction->setData(SET_FOLDER_AS_READ_ACTION_YL);
setFolderAsReadAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_FOLDER_AS_READ_ACTION_YL)); setFolderAsReadAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_FOLDER_AS_READ_ACTION_YL));
setFolderAsUnreadAction = new QAction(this); setFolderAsUnreadAction = new QAction(this);
setFolderAsUnreadAction->setText(tr("Set as unread")); setFolderAsUnreadAction->setText(tr("Set as unread"));
setFolderAsUnreadAction->setVisible(false);
setFolderAsUnreadAction->setData(SET_FOLDER_AS_UNREAD_ACTION_YL); setFolderAsUnreadAction->setData(SET_FOLDER_AS_UNREAD_ACTION_YL);
setFolderAsUnreadAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_FOLDER_AS_UNREAD_ACTION_YL)); setFolderAsUnreadAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_FOLDER_AS_UNREAD_ACTION_YL));
@ -831,14 +827,6 @@ void LibraryWindow::disableFoldersActions(bool disabled)
openContainingFolderAction->setDisabled(disabled); openContainingFolderAction->setDisabled(disabled);
updateFolderAction->setDisabled(disabled); updateFolderAction->setDisabled(disabled);
if(disabled == false)
{
setFolderAsNotCompletedAction->setVisible(false);
setFolderAsCompletedAction->setVisible(false);
setFolderAsReadAction->setVisible(false);
setFolderAsUnreadAction->setVisible(false);
}
} }
void LibraryWindow::disableAllActions() void LibraryWindow::disableAllActions()
@ -1111,6 +1099,7 @@ void LibraryWindow::createConnections()
//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)));
connect(foldersView, SIGNAL(moveComicsToFolder(QList<QPair<QString,QString> >,QModelIndex)), this, SLOT(moveAndImportComicsToFolder(QList<QPair<QString,QString> >,QModelIndex))); connect(foldersView, SIGNAL(moveComicsToFolder(QList<QPair<QString,QString> >,QModelIndex)), this, SLOT(moveAndImportComicsToFolder(QList<QPair<QString,QString> >,QModelIndex)));
connect(foldersView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showFoldersContextMenu(QPoint)));
//actions //actions
connect(createLibraryAction,SIGNAL(triggered()),this,SLOT(createLibrary())); connect(createLibraryAction,SIGNAL(triggered()),this,SLOT(createLibrary()));
@ -1978,11 +1967,6 @@ void LibraryWindow::setRootIndex()
foldersView->selectionModel()->clear(); foldersView->selectionModel()->clear();
} }
setFolderAsNotCompletedAction->setVisible(false);
setFolderAsCompletedAction->setVisible(false);
setFolderAsReadAction->setVisible(false);
setFolderAsUnreadAction->setVisible(false);
} }
@ -2520,7 +2504,33 @@ void LibraryWindow::deleteComics()
if(thread != NULL) if(thread != NULL)
thread->start(); thread->start();
} }
}
void LibraryWindow::showFoldersContextMenu(const QPoint &point)
{
QModelIndex sourceMI = foldersModelProxy->mapToSource(foldersView->indexAt(point));
bool isCompleted = sourceMI.data(FolderModel::CompletedRole).toBool();
bool isRead = sourceMI.data(FolderModel::FinishedRole).toBool();
QMenu menu;
//QMenu * folderMenu = new QMenu(tr("Folder"));
menu.addAction(openContainingFolderAction);
menu.addAction(updateFolderAction);
menu.addSeparator();//-------------------------------
if(isCompleted)
menu.addAction(setFolderAsNotCompletedAction);
else
menu.addAction(setFolderAsCompletedAction);
menu.addSeparator();//-------------------------------
if(isRead)
menu.addAction(setFolderAsUnreadAction);
else
menu.addAction(setFolderAsReadAction);
menu.exec(foldersView->mapToGlobal(point));
} }
/* /*
@ -2536,21 +2546,6 @@ void LibraryWindow::showSocial()
socialDialog->setHidden(false); socialDialog->setHidden(false);
}*/ }*/
void LibraryWindow::updateFoldersViewConextMenu(const QModelIndex &mi)
{
if(!mi.isValid())
return;
bool isFinished = mi.data(FolderModel::FinishedRole).toBool();
bool isCompleted = mi.data(FolderModel::CompletedRole).toBool();
setFolderAsReadAction->setVisible(!isFinished);
setFolderAsUnreadAction->setVisible(isFinished);
setFolderAsCompletedAction->setVisible(!isCompleted);
setFolderAsNotCompletedAction->setVisible(isCompleted);
}
void LibraryWindow::libraryAlreadyExists(const QString & name) void LibraryWindow::libraryAlreadyExists(const QString & name)
{ {
QMessageBox::information(this,tr("Library name already exists"),tr("There is another library with the name '%1'.").arg(name)); QMessageBox::information(this,tr("Library name already exists"),tr("There is another library with the name '%1'.").arg(name));

View File

@ -350,7 +350,7 @@ public slots:
QModelIndexList getSelectedComics(); QModelIndexList getSelectedComics();
void deleteComics(); void deleteComics();
//void showSocial(); //void showSocial();
void updateFoldersViewConextMenu(const QModelIndex & mi); void showFoldersContextMenu(const QPoint & point);
void libraryAlreadyExists(const QString & name); void libraryAlreadyExists(const QString & name);
void importLibraryPackage(); void importLibraryPackage();
void updateComicsView(quint64 libraryId, const ComicDB & comic); void updateComicsView(quint64 libraryId, const ComicDB & comic);

View File

@ -73,7 +73,7 @@ void YACReaderNavigationController::loadFolderInfo(const QModelIndex &modelIndex
libraryWindow->disableComicsActions(true); libraryWindow->disableComicsActions(true);
} }
libraryWindow->updateFoldersViewConextMenu(modelIndex); //libraryWindow->updateFoldersViewConextMenu(modelIndex);
//if a folder is selected, listsView selection must be cleared //if a folder is selected, listsView selection must be cleared
libraryWindow->listsView->clearSelection(); libraryWindow->listsView->clearSelection();

View File

@ -11,8 +11,8 @@ YACReaderTreeView::YACReaderTreeView(QWidget *parent) :
/*viewport()->setAcceptDrops(true); /*viewport()->setAcceptDrops(true);
setDropIndicatorShown(true);*/ setDropIndicatorShown(true);*/
setContextMenuPolicy(Qt::ActionsContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
setContextMenuPolicy(Qt::ActionsContextMenu);
header()->hide(); header()->hide();
setUniformRowHeights(true); setUniformRowHeights(true);
setSelectionBehavior(QAbstractItemView::SelectRows); setSelectionBehavior(QAbstractItemView::SelectRows);