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->setText(tr("Set as uncompleted"));
setFolderAsNotCompletedAction->setVisible(false);
setFolderAsNotCompletedAction->setData(SET_FOLDER_AS_NOT_COMPLETED_ACTION_YL);
setFolderAsNotCompletedAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_FOLDER_AS_NOT_COMPLETED_ACTION_YL));
setFolderAsCompletedAction = new QAction(this);
setFolderAsCompletedAction->setText(tr("Set as completed"));
setFolderAsCompletedAction->setVisible(false);
setFolderAsCompletedAction->setData(SET_FOLDER_AS_COMPLETED_ACTION_YL);
setFolderAsCompletedAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_FOLDER_AS_COMPLETED_ACTION_YL));
setFolderAsReadAction = new QAction(this);
setFolderAsReadAction->setText(tr("Set as read"));
setFolderAsReadAction->setVisible(false);
setFolderAsReadAction->setData(SET_FOLDER_AS_READ_ACTION_YL);
setFolderAsReadAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_FOLDER_AS_READ_ACTION_YL));
setFolderAsUnreadAction = new QAction(this);
setFolderAsUnreadAction->setText(tr("Set as unread"));
setFolderAsUnreadAction->setVisible(false);
setFolderAsUnreadAction->setData(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);
updateFolderAction->setDisabled(disabled);
if(disabled == false)
{
setFolderAsNotCompletedAction->setVisible(false);
setFolderAsCompletedAction->setVisible(false);
setFolderAsReadAction->setVisible(false);
setFolderAsUnreadAction->setVisible(false);
}
}
void LibraryWindow::disableAllActions()
@ -1111,6 +1099,7 @@ void LibraryWindow::createConnections()
//drops in folders view
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(customContextMenuRequested(QPoint)), this, SLOT(showFoldersContextMenu(QPoint)));
//actions
connect(createLibraryAction,SIGNAL(triggered()),this,SLOT(createLibrary()));
@ -1978,11 +1967,6 @@ void LibraryWindow::setRootIndex()
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)
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);
}*/
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)
{
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();
void deleteComics();
//void showSocial();
void updateFoldersViewConextMenu(const QModelIndex & mi);
void showFoldersContextMenu(const QPoint & point);
void libraryAlreadyExists(const QString & name);
void importLibraryPackage();
void updateComicsView(quint64 libraryId, const ComicDB & comic);

View File

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

View File

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