added shortcuts management support

TODO: integrate it in YACReader
TODO: add icons for groups
TODO: add conflicts detection
TODO: fix any shortcut used in keyPressEvent
TODO: choose new default shortcuts (F5 update, F11 fullscreen, etc...)
This commit is contained in:
Luis Ángel San Martín 2014-07-17 22:30:03 +02:00
parent 3c18599496
commit 50c8eca7c4
19 changed files with 933 additions and 78 deletions

View File

@ -174,6 +174,7 @@ include(../custom_widgets/custom_widgets_yacreaderlibrary.pri)
include(../compressed_archive/wrapper.pri)
include(./comic_vine/comic_vine.pri)
include(../QsLog/QsLog.pri)
include(../shortcuts_management/shortcuts_management.pri)
RESOURCES += images.qrc files.qrc
win32:RESOURCES += images_win.qrc

View File

@ -100,6 +100,8 @@
<file>../images/comic_vine/downArrow.png</file>
<file>../images/comic_vine/upArrow.png</file>
<file>../images/find_folder.png</file>
<file>../images/clear_shortcut.png</file>
<file>../images/accept_shortcut.png</file>
<!--<file>../images/busy_background.png</file>-->
</qresource>
</RCC>

View File

@ -65,6 +65,9 @@
#include "comics_view_transition.h"
#include "empty_folder_widget.h"
#include "shortcuts_dialog.h"
#include "shortcuts_manager.h"
#include "QsLog.h"
#ifdef Q_OS_WIN
@ -270,6 +273,9 @@ void LibraryWindow::doDialogs()
optionsDialog = new OptionsDialog(this);
optionsDialog->restoreOptions(settings);
shortcutsDialog = new ShortcutsDialog(this);
setUpShortcutsManagement();
#ifdef SERVER_RELEASE
serverConfigDialog = new ServerConfigDialog(this);
#endif
@ -289,6 +295,61 @@ void LibraryWindow::doDialogs()
}
void LibraryWindow::setUpShortcutsManagement()
{
shortcutsDialog->addActionsGroup("Comics",QIcon(":/images/openInYACReader.png"),
QList<QAction *>()
<< openComicAction
<< setAsReadAction
<< setAsNonReadAction
<< openContainingFolderComicAction
<< resetComicRatingAction
<< selectAllComicsAction
<< editSelectedComicsAction
<< asignOrderAction
<< deleteComicsAction
<< getInfoAction);
shortcutsDialog->addActionsGroup("Folders",QIcon(),
QList<QAction *>()
<< setRootIndexAction
<< expandAllNodesAction
<< colapseAllNodesAction
<< openContainingFolderAction
<< setFolderAsNotCompletedAction
<< setFolderAsCompletedAction
<< setFolderAsReadAction
<< setFolderAsUnreadAction);
shortcutsDialog->addActionsGroup("General",QIcon(),
QList<QAction *>()
<< backAction
<< forwardAction
<< helpAboutAction
<< optionsAction
<< serverConfigAction);
shortcutsDialog->addActionsGroup("Libraries",QIcon(),
QList<QAction *>()
<< createLibraryAction
<< openLibraryAction
<< exportComicsInfoAction
<< importComicsInfoAction
<< exportLibraryAction
<< importLibraryAction
<< updateLibraryAction
<< renameLibraryAction
<< removeLibraryAction);
shortcutsDialog->addActionsGroup("Visualization",QIcon(),
QList<QAction *>()
<< showHideMarksAction
<< toggleFullScreenAction
<< toggleComicsViewAction
<< hideComicViewAction);
}
void LibraryWindow::doModels()
{
//folders
@ -323,67 +384,90 @@ void LibraryWindow::createActions()
QIcon icoBackButton;
icoBackButton.addPixmap(QPixmap(":/images/main_toolbar/back.png"), QIcon::Normal);
//icoBackButton.addPixmap(QPixmap(":/images/main_toolbar/back_disabled.png"), QIcon::Disabled);
backAction->setIcon(icoBackButton);
backAction->setData(BACK_ACTION_YL);
backAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(BACK_ACTION_YL));
backAction->setIcon(icoBackButton);
backAction->setDisabled(true);
forwardAction = new QAction(this);
QIcon icoFordwardButton;
icoFordwardButton.addPixmap(QPixmap(":/images/main_toolbar/forward.png"), QIcon::Normal);
//icoFordwardButton.addPixmap(QPixmap(":/images/main_toolbar/forward_disabled.png"), QIcon::Disabled);
forwardAction->setData(FORWARD_ACTION_YL);
forwardAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(FORWARD_ACTION_YL));
forwardAction->setIcon(icoFordwardButton);
forwardAction->setDisabled(true);
createLibraryAction = new QAction(this);
createLibraryAction->setToolTip(tr("Create a new library"));
createLibraryAction->setShortcut(Qt::Key_A);
createLibraryAction->setData(CREATE_LIBRARY_ACTION_YL);
createLibraryAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(CREATE_LIBRARY_ACTION_YL));
createLibraryAction->setIcon(QIcon(":/images/newLibraryIcon.png"));
openLibraryAction = new QAction(this);
openLibraryAction->setToolTip(tr("Open an existing library"));
openLibraryAction->setShortcut(Qt::Key_O);
openLibraryAction->setData(OPEN_LIBRARY_ACTION_YL);
openLibraryAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPEN_LIBRARY_ACTION_YL));
openLibraryAction->setIcon(QIcon(":/images/openLibraryIcon.png"));
exportComicsInfo = new QAction(tr("Export comics info"),this);
exportComicsInfo->setToolTip(tr("Export comics info"));
exportComicsInfo->setIcon(QIcon(":/images/exportComicsInfoIcon.png"));
exportComicsInfoAction = new QAction(tr("Export comics info"),this);
exportComicsInfoAction->setToolTip(tr("Export comics info"));
exportComicsInfoAction->setData(EXPORT_COMICS_INFO_YL);
exportComicsInfoAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(EXPORT_COMICS_INFO_YL));
exportComicsInfoAction->setIcon(QIcon(":/images/exportComicsInfoIcon.png"));
importComicsInfo = new QAction(tr("Import comics info"),this);
importComicsInfo->setToolTip(tr("Import comics info"));
importComicsInfo->setIcon(QIcon(":/images/importComicsInfoIcon.png"));
importComicsInfoAction = new QAction(tr("Import comics info"),this);
importComicsInfoAction->setToolTip(tr("Import comics info"));
importComicsInfoAction->setData(IMPORT_COMICS_INFO_YL);
importComicsInfoAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(IMPORT_COMICS_INFO_YL));
importComicsInfoAction->setIcon(QIcon(":/images/importComicsInfoIcon.png"));
exportLibraryAction = new QAction(tr("Pack covers"),this);
exportLibraryAction->setToolTip(tr("Pack the covers of the selected library"));
exportLibraryAction->setData(EXPORT_LIBRARY_ACTION_YL);
exportLibraryAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(EXPORT_LIBRARY_ACTION_YL));
exportLibraryAction->setIcon(QIcon(":/images/exportLibraryIcon.png"));
importLibraryAction = new QAction(tr("Unpack covers"),this);
importLibraryAction->setToolTip(tr("Unpack a catalog"));
importLibraryAction->setData(IMPORT_LIBRARY_ACTION_YL);
importLibraryAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(IMPORT_LIBRARY_ACTION_YL));
importLibraryAction->setIcon(QIcon(":/images/importLibraryIcon.png"));
updateLibraryAction = new QAction(tr("Update library"),this);
updateLibraryAction->setToolTip(tr("Update current library"));
updateLibraryAction->setShortcut(Qt::Key_U);
updateLibraryAction->setData(UPDATE_LIBRARY_ACTION_YL);
updateLibraryAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(UPDATE_LIBRARY_ACTION_YL));
updateLibraryAction->setIcon(QIcon(":/images/updateLibraryIcon.png"));
renameLibraryAction = new QAction(tr("Rename library"),this);
renameLibraryAction->setToolTip(tr("Rename current library"));
renameLibraryAction->setShortcut(Qt::Key_R);
renameLibraryAction->setData(RENAME_LIBRARY_ACTION_YL);
renameLibraryAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(RENAME_LIBRARY_ACTION_YL));
renameLibraryAction->setIcon(QIcon(":/images/editIcon.png"));
removeLibraryAction = new QAction(tr("Remove library"),this);
removeLibraryAction->setToolTip(tr("Remove current library from your collection"));
removeLibraryAction->setData(REMOVE_LIBRARY_ACTION_YL);
removeLibraryAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(REMOVE_LIBRARY_ACTION_YL));
removeLibraryAction->setIcon(QIcon(":/images/removeLibraryIcon.png"));
openComicAction = new QAction(tr("Open current comic"),this);
openComicAction->setToolTip(tr("Open current comic on YACReader"));
openComicAction->setShortcut(Qt::Key_Return);
openComicAction->setData(OPEN_COMIC_ACTION_YL);
openComicAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPEN_COMIC_ACTION_YL));
openComicAction->setIcon(QIcon(":/images/openInYACReader.png"));
setAsReadAction = new QAction(tr("Set as read"),this);
setAsReadAction->setToolTip(tr("Set comic as read"));
setAsReadAction->setData(SET_AS_READ_ACTION_YL);
setAsReadAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_AS_READ_ACTION_YL));
setAsReadAction->setIcon(QIcon(":/images/setReadButton.png"));
setAsNonReadAction = new QAction(tr("Set as unread"),this);
setAsNonReadAction->setToolTip(tr("Set comic as unread"));
setAsNonReadAction->setData(SET_AS_NON_READ_ACTION_YL);
setAsNonReadAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_AS_NON_READ_ACTION_YL));
setAsNonReadAction->setIcon(QIcon(":/images/setUnread.png"));
/*setAllAsReadAction = new QAction(tr("Set all as read"),this);
@ -396,120 +480,157 @@ void LibraryWindow::createActions()
showHideMarksAction = new QAction(tr("Show/Hide marks"),this);
showHideMarksAction->setToolTip(tr("Show or hide readed marks"));
showHideMarksAction->setShortcut(Qt::Key_M);
showHideMarksAction->setData(SHOW_HIDE_MARKS_ACTION_YL);
showHideMarksAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SHOW_HIDE_MARKS_ACTION_YL));
showHideMarksAction->setCheckable(true);
showHideMarksAction->setIcon(QIcon(":/images/showMarks.png"));
showHideMarksAction->setChecked(true);
toggleFullScreenAction = new QAction(tr("Fullscreen mode on/off"),this);
toggleFullScreenAction->setToolTip(tr("Fullscreen mode on/off (F)"));
toggleFullScreenAction->setShortcut(Qt::Key_F);
toggleFullScreenAction->setToolTip(tr("Fullscreen mode on/off"));
toggleFullScreenAction->setData(TOGGLE_FULL_SCREEN_ACTION_YL);
toggleFullScreenAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(TOGGLE_FULL_SCREEN_ACTION_YL));
QIcon icoFullscreenButton;
icoFullscreenButton.addPixmap(QPixmap(":/images/main_toolbar/fullscreen.png"), QIcon::Normal);
toggleFullScreenAction->setIcon(icoFullscreenButton);
helpAboutAction = new QAction(this);
helpAboutAction->setToolTip(tr("Help, About YACReader"));
helpAboutAction->setShortcut(Qt::Key_F1);
helpAboutAction->setData(HELP_ABOUT_ACTION_YL);
helpAboutAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(HELP_ABOUT_ACTION_YL));
QIcon icoHelpButton;
icoHelpButton.addPixmap(QPixmap(":/images/main_toolbar/help.png"), QIcon::Normal);
helpAboutAction->setIcon(icoHelpButton);
setRootIndexAction = new QAction(this);
setRootIndexAction->setShortcut(Qt::Key_0);
setRootIndexAction->setData(SET_ROOT_INDEX_ACTION_YL);
setRootIndexAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_ROOT_INDEX_ACTION_YL));
setRootIndexAction->setToolTip(tr("Select root node"));
setRootIndexAction->setIcon(QIcon(":/images/setRoot.png"));
expandAllNodesAction = new QAction(this);
expandAllNodesAction->setShortcut(tr("+"));
expandAllNodesAction->setToolTip(tr("Expand all nodes"));
expandAllNodesAction->setData(EXPAND_ALL_NODES_ACTION_YL);
expandAllNodesAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(EXPAND_ALL_NODES_ACTION_YL));
expandAllNodesAction->setIcon(QIcon(":/images/expand.png"));
colapseAllNodesAction = new QAction(this);
colapseAllNodesAction->setShortcut(tr("-"));
colapseAllNodesAction->setToolTip(tr("Colapse all nodes"));
colapseAllNodesAction->setData(COLAPSE_ALL_NODES_ACTION_YL);
colapseAllNodesAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(COLAPSE_ALL_NODES_ACTION_YL));
colapseAllNodesAction->setIcon(QIcon(":/images/colapse.png"));
optionsAction = new QAction(this);
optionsAction->setShortcut(Qt::Key_C);
optionsAction->setToolTip(tr("Show options dialog"));
optionsAction->setData(OPTIONS_ACTION_YL);
optionsAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPTIONS_ACTION_YL));
QIcon icoSettingsButton;
icoSettingsButton.addPixmap(QPixmap(":/images/main_toolbar/settings.png"), QIcon::Normal);
optionsAction->setIcon(icoSettingsButton);
serverConfigAction = new QAction(this);
serverConfigAction->setShortcut(Qt::Key_S);
serverConfigAction->setToolTip(tr("Show comics server options dialog"));
serverConfigAction->setData(SERVER_CONFIG_ACTION_YL);
serverConfigAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SERVER_CONFIG_ACTION_YL));
QIcon icoServerButton;
icoServerButton.addPixmap(QPixmap(":/images/main_toolbar/server.png"), QIcon::Normal);
serverConfigAction->setIcon(icoServerButton);
toggleComicsViewAction = new QAction(tr("Change between comics views"),this);
toggleComicsViewAction->setShortcut(Qt::Key_V);
toggleComicsViewAction->setToolTip(tr("Change between comics views"));
QIcon icoViewsButton;
if(!settings->contains(COMICS_VIEW_STATUS) || settings->value(COMICS_VIEW_STATUS) == Flow)
icoViewsButton.addPixmap(QPixmap(":/images/main_toolbar/grid.png"), QIcon::Normal);
else
icoViewsButton.addPixmap(QPixmap(":/images/main_toolbar/flow.png"), QIcon::Normal);
toggleComicsViewAction->setData(TOGGLE_COMICS_VIEW_ACTION_YL);
toggleComicsViewAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(TOGGLE_COMICS_VIEW_ACTION_YL));
toggleComicsViewAction->setIcon(icoViewsButton);
//socialAction = new QAction(this);
openContainingFolderAction = new QAction(this);
openContainingFolderAction->setText(tr("Open folder..."));
openContainingFolderAction->setData(OPEN_CONTAINING_FOLDER_ACTION_YL);
openContainingFolderAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPEN_CONTAINING_FOLDER_ACTION_YL));
openContainingFolderAction->setIcon(QIcon(":/images/open.png"));
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));
setFolderAsFinishedAction = new QAction(this);
setFolderAsFinishedAction->setText(tr("Set as read"));
setFolderAsFinishedAction->setVisible(false);
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));
setFolderAsNotFinishedAction = new QAction(this);
setFolderAsNotFinishedAction->setText(tr("Set as unread"));
setFolderAsNotFinishedAction->setVisible(false);
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));
openContainingFolderComicAction = new QAction(this);
openContainingFolderComicAction->setText(tr("Open containing folder..."));
openContainingFolderComicAction->setData(OPEN_CONTAINING_FOLDER_COMIC_ACTION_YL);
openContainingFolderComicAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPEN_CONTAINING_FOLDER_COMIC_ACTION_YL));
openContainingFolderComicAction->setIcon(QIcon(":/images/open.png"));
resetComicRatingAction = new QAction(this);
resetComicRatingAction->setText(tr("Reset comic rating"));
resetComicRatingAction->setData(RESET_COMIC_RATING_ACTION_YL);
resetComicRatingAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(RESET_COMIC_RATING_ACTION_YL));
//Edit comics actions------------------------------------------------------
selectAllComicsAction = new QAction(this);
selectAllComicsAction->setText(tr("Select all comics"));
selectAllComicsAction->setIcon(QIcon(":/images/selectAll.png"));
selectAllComicsAction->setData(SELECT_ALL_COMICS_ACTION_YL);
selectAllComicsAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SELECT_ALL_COMICS_ACTION_YL));
selectAllComicsAction->setIcon(QIcon(":/images/selectAll.png"));
editSelectedComicsAction = new QAction(this);
editSelectedComicsAction->setText(tr("Edit"));
editSelectedComicsAction->setData(EDIT_SELECTED_COMICS_ACTION_YL);
editSelectedComicsAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(EDIT_SELECTED_COMICS_ACTION_YL));
editSelectedComicsAction->setIcon(QIcon(":/images/editComic.png"));
asignOrderAction = new QAction(this);
asignOrderAction->setText(tr("Asign current order to comics"));
asignOrderAction->setData(ASIGN_ORDER_ACTION_YL);
asignOrderAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ASIGN_ORDER_ACTION_YL));
asignOrderAction->setIcon(QIcon(":/images/asignNumber.png"));
forceConverExtractedAction = new QAction(this);
forceConverExtractedAction->setText(tr("Update cover"));
forceConverExtractedAction->setIcon(QIcon(":/images/importCover.png"));
forceCoverExtractedAction = new QAction(this);
forceCoverExtractedAction->setText(tr("Update cover"));
forceCoverExtractedAction->setData(FORCE_COVER_EXTRACTED_ACTION_YL);
forceCoverExtractedAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(FORCE_COVER_EXTRACTED_ACTION_YL));
forceCoverExtractedAction->setIcon(QIcon(":/images/importCover.png"));
deleteComicsAction = new QAction(this);
deleteComicsAction->setText(tr("Delete selected comics"));
deleteComicsAction->setData(DELETE_COMICS_ACTION_YL);
deleteComicsAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(DELETE_COMICS_ACTION_YL));
deleteComicsAction->setIcon(QIcon(":/images/trash.png"));
hideComicViewAction = new QAction(this);
hideComicViewAction->setText(tr("Hide comic flow"));
hideComicViewAction->setData(HIDE_COMIC_VIEW_ACTION_YL);
hideComicViewAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(HIDE_COMIC_VIEW_ACTION_YL));
hideComicViewAction->setIcon(QIcon(":/images/hideComicFlow.png"));
hideComicViewAction->setCheckable(true);
hideComicViewAction->setChecked(false);
getInfoAction = new QAction(this);
getInfoAction->setData(GET_INFO_ACTION_YL);
getInfoAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(GET_INFO_ACTION_YL));
getInfoAction->setText(tr("Download tags from Comic Vine"));
getInfoAction->setIcon(QIcon(":/images/getInfo.png"));
//-------------------------------------------------------------------------
@ -545,8 +666,8 @@ void LibraryWindow::disableLibrariesActions(bool disabled)
updateLibraryAction->setDisabled(disabled);
renameLibraryAction->setDisabled(disabled);
removeLibraryAction->setDisabled(disabled);
exportComicsInfo->setDisabled(disabled);
importComicsInfo->setDisabled(disabled);
exportComicsInfoAction->setDisabled(disabled);
importComicsInfoAction->setDisabled(disabled);
exportLibraryAction->setDisabled(disabled);
//importLibraryAction->setDisabled(disabled);
}
@ -554,8 +675,8 @@ void LibraryWindow::disableLibrariesActions(bool disabled)
void LibraryWindow::disableNoUpdatedLibrariesActions(bool disabled)
{
updateLibraryAction->setDisabled(disabled);
exportComicsInfo->setDisabled(disabled);
importComicsInfo->setDisabled(disabled);
exportComicsInfoAction->setDisabled(disabled);
importComicsInfoAction->setDisabled(disabled);
exportLibraryAction->setDisabled(disabled);
}
@ -571,8 +692,8 @@ void LibraryWindow::disableFoldersActions(bool disabled)
{
setFolderAsNotCompletedAction->setVisible(false);
setFolderAsCompletedAction->setVisible(false);
setFolderAsFinishedAction->setVisible(false);
setFolderAsNotFinishedAction->setVisible(false);
setFolderAsReadAction->setVisible(false);
setFolderAsUnreadAction->setVisible(false);
}
}
@ -699,16 +820,16 @@ void LibraryWindow::createMenus()
foldersView->addAction(setFolderAsCompletedAction);
YACReader::addSperator(foldersView);
foldersView->addAction(setFolderAsFinishedAction);
foldersView->addAction(setFolderAsNotFinishedAction);
foldersView->addAction(setFolderAsReadAction);
foldersView->addAction(setFolderAsUnreadAction);
selectedLibrary->addAction(updateLibraryAction);
selectedLibrary->addAction(renameLibraryAction);
selectedLibrary->addAction(removeLibraryAction);
YACReader::addSperator(selectedLibrary);
selectedLibrary->addAction(exportComicsInfo);
selectedLibrary->addAction(importComicsInfo);
selectedLibrary->addAction(exportComicsInfoAction);
selectedLibrary->addAction(importComicsInfoAction);
YACReader::addSperator(selectedLibrary);
selectedLibrary->addAction(exportLibraryAction);
@ -827,8 +948,8 @@ void LibraryWindow::createConnections()
//comicsInfoManagement
connect(exportComicsInfo,SIGNAL(triggered()),this,SLOT(showExportComicsInfo()));
connect(importComicsInfo,SIGNAL(triggered()),this,SLOT(showImportComicsInfo()));
connect(exportComicsInfoAction,SIGNAL(triggered()),this,SLOT(showExportComicsInfo()));
connect(importComicsInfoAction,SIGNAL(triggered()),this,SLOT(showImportComicsInfo()));
//properties & config
connect(propertiesDialog,SIGNAL(accepted()),this,SLOT(reloadCovers()));
@ -852,6 +973,7 @@ void LibraryWindow::createConnections()
connect(serverConfigAction, SIGNAL(triggered()), serverConfigDialog, SLOT(show()));
#endif
connect(optionsDialog, SIGNAL(optionsChanged()),this,SLOT(reloadOptions()));
connect(optionsDialog, SIGNAL(editShortcuts()),shortcutsDialog,SLOT(show()));
//Folders filter
//connect(clearFoldersFilter,SIGNAL(clicked()),foldersFilter,SLOT(clear()));
@ -862,8 +984,8 @@ void LibraryWindow::createConnections()
connect(openContainingFolderComicAction,SIGNAL(triggered()),this,SLOT(openContainingFolderComic()));
connect(setFolderAsNotCompletedAction,SIGNAL(triggered()),this,SLOT(setFolderAsNotCompleted()));
connect(setFolderAsCompletedAction,SIGNAL(triggered()),this,SLOT(setFolderAsCompleted()));
connect(setFolderAsFinishedAction,SIGNAL(triggered()),this,SLOT(setFolderAsFinished()));
connect(setFolderAsNotFinishedAction,SIGNAL(triggered()),this,SLOT(setFolderAsNotFinished()));
connect(setFolderAsReadAction,SIGNAL(triggered()),this,SLOT(setFolderAsRead()));
connect(setFolderAsUnreadAction,SIGNAL(triggered()),this,SLOT(setFolderAsUnread()));
connect(openContainingFolderAction,SIGNAL(triggered()),this,SLOT(openContainingFolder()));
connect(resetComicRatingAction,SIGNAL(triggered()),this,SLOT(resetComicRating()));
@ -1387,8 +1509,8 @@ void LibraryWindow::setRootIndex()
setFolderAsNotCompletedAction->setVisible(false);
setFolderAsCompletedAction->setVisible(false);
setFolderAsFinishedAction->setVisible(false);
setFolderAsNotFinishedAction->setVisible(false);
setFolderAsReadAction->setVisible(false);
setFolderAsUnreadAction->setVisible(false);
}
@ -1650,12 +1772,12 @@ void LibraryWindow::setFolderAsCompleted()
dm->updateFolderCompletedStatus(foldersView->selectionModel()->selectedRows(),true);
}
void LibraryWindow::setFolderAsFinished()
void LibraryWindow::setFolderAsRead()
{
dm->updateFolderFinishedStatus(foldersView->selectionModel()->selectedRows(),true);
}
void LibraryWindow::setFolderAsNotFinished()
void LibraryWindow::setFolderAsUnread()
{
dm->updateFolderFinishedStatus(foldersView->selectionModel()->selectedRows(),false);
}
@ -1907,8 +2029,8 @@ void LibraryWindow::updateFoldersViewConextMenu(const QModelIndex &mi)
bool isFinished = item->data(TreeModel::Finished).toBool();
bool isCompleted = item->data(TreeModel::Completed).toBool();
setFolderAsFinishedAction->setVisible(!isFinished);
setFolderAsNotFinishedAction->setVisible(isFinished);
setFolderAsReadAction->setVisible(!isFinished);
setFolderAsUnreadAction->setVisible(isFinished);
setFolderAsCompletedAction->setVisible(!isCompleted);
setFolderAsNotCompletedAction->setVisible(isCompleted);

View File

@ -54,6 +54,7 @@ class ClassicComicsView;
class GridComicsView;
class ComicsViewTransition;
class EmptyFolderWidget;
class ShortcutsDialog;
#include "comic_db.h"
@ -76,6 +77,7 @@ private:
RenameLibraryDialog * renameLibraryDialog;
PropertiesDialog * propertiesDialog;
ComicVineDialog * comicVineDialog;
ShortcutsDialog * shortcutsDialog;
//YACReaderSocialDialog * socialDialog;
bool fullscreen;
bool importedCovers; //if true, the library is read only (not updates,open comic or properties)
@ -125,8 +127,8 @@ private:
QAction * createLibraryAction;
QAction * openLibraryAction;
QAction * exportComicsInfo;
QAction * importComicsInfo;
QAction * exportComicsInfoAction;
QAction * importComicsInfoAction;
QAction * exportLibraryAction;
QAction * importLibraryAction;
@ -151,8 +153,8 @@ private:
QAction * setFolderAsNotCompletedAction;
QAction * setFolderAsCompletedAction;
//--
QAction * setFolderAsFinishedAction;
QAction * setFolderAsNotFinishedAction;
QAction * setFolderAsReadAction;
QAction * setFolderAsUnreadAction;
QAction * openContainingFolderComicAction;
QAction * setAsReadAction;
@ -167,7 +169,7 @@ private:
QAction * selectAllComicsAction;
QAction * editSelectedComicsAction;
QAction * asignOrderAction;
QAction * forceConverExtractedAction;
QAction * forceCoverExtractedAction;
QAction * deleteComicsAction;
QAction * hideComicViewAction;
@ -204,6 +206,7 @@ private:
void createConnections();
void doLayout();
void doDialogs();
void setUpShortcutsManagement();
void doModels();
void disconnectComicsViewConnections(ComicsView * widget);
void doComicsViewConnections();
@ -258,8 +261,8 @@ public slots:
void openContainingFolder();
void setFolderAsNotCompleted();
void setFolderAsCompleted();
void setFolderAsFinished();
void setFolderAsNotFinished();
void setFolderAsRead();
void setFolderAsUnread();
void openContainingFolderComic();
void deleteCurrentLibrary();
void removeLibrary();

View File

@ -20,33 +20,59 @@ FlowType flowType = Strip;
OptionsDialog::OptionsDialog(QWidget * parent)
:YACReaderOptionsDialog(parent)
{
QVBoxLayout * layout = new QVBoxLayout;
QTabWidget * tabWidget = new QTabWidget();
QHBoxLayout * switchFlowType = new QHBoxLayout;
switchFlowType->addStretch();
switchFlowType->addWidget(useGL);
QVBoxLayout * layout = new QVBoxLayout(this);
QVBoxLayout * flowLayout = new QVBoxLayout;
QVBoxLayout * generalLayout = new QVBoxLayout();
QHBoxLayout * switchFlowType = new QHBoxLayout;
switchFlowType->addStretch();
switchFlowType->addWidget(useGL);
QHBoxLayout * buttons = new QHBoxLayout();
buttons->addStretch();
buttons->addWidget(accept);
buttons->addWidget(cancel);
flowLayout->addWidget(sw);
flowLayout->addWidget(gl);
flowLayout->addLayout(switchFlowType);
QVBoxLayout * shortcutsLayout = new QVBoxLayout();
QPushButton * shortcutsButton = new QPushButton(tr("Edit shortcuts"));
shortcutsLayout->addWidget(shortcutsButton);
sw->hide();
QHBoxLayout * buttons = new QHBoxLayout();
buttons->addStretch();
buttons->addWidget(accept);
buttons->addWidget(cancel);
QWidget * comicFlowW = new QWidget;
comicFlowW->setLayout(flowLayout);
layout->addWidget(sw);
layout->addWidget(gl);
layout->addLayout(switchFlowType);
layout->addLayout(buttons);
QGroupBox *generalBox = new QGroupBox(tr("Shortcuts"));
generalBox->setLayout(shortcutsLayout);
generalLayout->addWidget(generalBox);
generalLayout->addStretch();
sw->hide();
QWidget * generalW = new QWidget;
generalW->setLayout(generalLayout);
setLayout(layout);
//restoreOptions(settings); //load options
//resize(200,0);
setModal (true);
setWindowTitle(tr("Options"));
tabWidget->addTab(comicFlowW,tr("Comic Flow"));
tabWidget->addTab(generalW,tr("General"));
this->layout()->setSizeConstraint(QLayout::SetFixedSize);
layout->addWidget(tabWidget);
layout->addLayout(buttons);
setLayout(layout);
//restoreOptions(settings); //load options
//resize(200,0);
setModal (true);
setWindowTitle(tr("Options"));
this->layout()->setSizeConstraint(QLayout::SetFixedSize);
connect(shortcutsButton,SIGNAL(clicked()),this,SIGNAL(editShortcuts()));
}

View File

@ -12,6 +12,8 @@ class OptionsDialog : public YACReaderOptionsDialog
Q_OBJECT
public:
OptionsDialog(QWidget * parent = 0);
signals:
void editShortcuts();
};

BIN
images/accept_shortcut.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

BIN
images/clear_shortcut.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

View File

@ -0,0 +1,80 @@
#include "actions_groups_model.h"
ActionsGroupsModel::ActionsGroupsModel(QObject *parent) :
QAbstractItemModel(parent)
{
}
int ActionsGroupsModel::rowCount(const QModelIndex &parent) const
{
return groups.length();
}
int ActionsGroupsModel::columnCount(const QModelIndex &parent) const
{
return 1;
}
QModelIndex ActionsGroupsModel::index(int row, int column, const QModelIndex &parent) const
{
if (!hasIndex(row, column, parent))
return QModelIndex();
return createIndex(row, column, &groups.at(row).getActions());
}
QVariant ActionsGroupsModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::DecorationRole)
return QVariant(groups.at(index.row()).getIcon());
if (role != Qt::DisplayRole)
return QVariant();
return QVariant(groups[index.row()].getName());
}
QModelIndex ActionsGroupsModel::parent(const QModelIndex &index) const
{
return QModelIndex();
}
void ActionsGroupsModel::addActionsGroup(const ActionsGroup &group)
{
beginInsertRows(QModelIndex(),groups.length()-1,groups.length());
groups.push_back(group);
endInsertRows();
}
QList<QAction *> ActionsGroupsModel::getActions(const QModelIndex &mi)
{
if(mi.isValid())
return groups[mi.row()].getActions();
return QList<QAction *>();
}
//-------------------------------------------------------------------
ActionsGroup::ActionsGroup(const QString &name, const QIcon &icon, QList<QAction *> &actions)
:name(name), icon(icon), actions(actions)
{
}
QString ActionsGroup::getName() const
{
return name;
}
QIcon ActionsGroup::getIcon() const
{
return icon;
}
QList<QAction *> ActionsGroup::getActions() const
{
return actions;
}

View File

@ -0,0 +1,44 @@
#ifndef ACTIONS_GROUPS_MODEL_H
#define ACTIONS_GROUPS_MODEL_H
#include <QAbstractItemModel>
#include <QIcon>
class QAction;
class ActionsGroup
{
public:
ActionsGroup(const QString & name, const QIcon & icon, QList<QAction *> & actions);
QString getName() const;
QIcon getIcon() const;
QList<QAction *> getActions() const;
protected:
QString name;
QIcon icon;
QList<QAction *> actions;
};
class ActionsGroupsModel : public QAbstractItemModel
{
Q_OBJECT
public:
explicit ActionsGroupsModel(QObject *parent = 0);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
QModelIndex parent(const QModelIndex &index) const;
void addActionsGroup(const ActionsGroup & group);
QList<QAction *> getActions(const QModelIndex & mi);
signals:
public slots:
protected:
QList<ActionsGroup> groups;
};
#endif // ACTIONS_GROUPS_MODEL_H

View File

@ -0,0 +1,92 @@
#include "actions_shortcuts_model.h"
#include "shortcuts_manager.h"
#include <QAction>
ActionsShortcutsModel::ActionsShortcutsModel(QObject *parent) :
QAbstractItemModel(parent)
{
}
int ActionsShortcutsModel::rowCount(const QModelIndex &parent) const
{
return actions.length();
}
int ActionsShortcutsModel::columnCount(const QModelIndex &parent) const
{
return 3;
}
QModelIndex ActionsShortcutsModel::index(int row, int column, const QModelIndex &parent) const
{
if (!hasIndex(row, column, parent))
return QModelIndex();
return createIndex(row, column, actions[row]);
}
Qt::ItemFlags ActionsShortcutsModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return 0;
if(index.column() == KEYS)
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
QVariant ActionsShortcutsModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::DecorationRole && index.column() == ICON)
return QVariant(actions[index.row()]->icon());
if (role == Qt::TextAlignmentRole)
{
switch(index.column())
{
case ICON:
return QVariant(Qt::AlignHCenter | Qt::AlignVCenter);
case NAME:
return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
case KEYS:
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
}
}
if (role != Qt::DisplayRole)
return QVariant();
if (index.column() == NAME)
return QVariant(actions[index.row()]->toolTip());
if (index.column() == KEYS)
return QVariant(actions[index.row()]->shortcut().toString());
return QVariant();
}
bool ActionsShortcutsModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if(index.column() == KEYS)
{
actions[index.row()]->setShortcut(value.toString());
ShortcutsManager::getShortcutsManager().saveShortcut(actions[index.row()]);
return true;
}
return false;
}
QModelIndex ActionsShortcutsModel::parent(const QModelIndex &index) const
{
return QModelIndex();
}
void ActionsShortcutsModel::addActions(const QList<QAction *> actions)
{
beginResetModel();
this->actions = actions;
endResetModel();
}

View File

@ -0,0 +1,38 @@
#ifndef ACTIONS_SHORTCUTS_MODEL_H
#define ACTIONS_SHORTCUTS_MODEL_H
#include <QAbstractItemModel>
class QAction;
class ActionsShortcutsModel : public QAbstractItemModel
{
Q_OBJECT
public:
explicit ActionsShortcutsModel(QObject *parent = 0);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
bool setData(const QModelIndex &index, const QVariant &value, int role);
QModelIndex parent(const QModelIndex &index) const;
void addActions(const QList<QAction *> actions);
Qt::ItemFlags flags(const QModelIndex &index) const;
enum Columns {
ICON = 0,
NAME,
KEYS
};
signals:
public slots:
protected:
QList<QAction *> actions;
};
#endif // ACTIONS_SHORTCUTS_MODEL_H

View File

@ -0,0 +1,145 @@
#include "edit_shortcut_item_delegate.h"
#include <QAction>
EditShortcutItemDelegate::EditShortcutItemDelegate(QObject *parent) :
QItemDelegate(parent)
{
}
QWidget *EditShortcutItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
KeySequenceLineEdit * editor = new KeySequenceLineEdit(parent);
connect(editor,SIGNAL(editingFinished()),this,SLOT(closeShortcutEditor()));
return editor;
}
void EditShortcutItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
QString value = index.model()->data(index, Qt::DisplayRole).toString();
KeySequenceLineEdit * lineEdit = static_cast<KeySequenceLineEdit*>(editor);
lineEdit->setText(value);
}
void EditShortcutItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
KeySequenceLineEdit *lineEdit = static_cast<KeySequenceLineEdit*>(editor);
model->setData(index, lineEdit->text(), Qt::EditRole);
}
void EditShortcutItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &mi) const
{
editor->setGeometry(option.rect);
}
bool EditShortcutItemDelegate::eventFilter(QObject* editor, QEvent* event)
{
if(event->type()==QEvent::KeyPress)
return false;
return QItemDelegate::eventFilter(editor, event);
}
void EditShortcutItemDelegate::closeShortcutEditor()
{
emit commitData(static_cast<QWidget *>(sender()));
emit closeEditor(static_cast<QWidget *>(sender()),QAbstractItemDelegate::NoHint);
}
//TODO uncoment commented code for enabling concatenated shortcuts
KeySequenceLineEdit::KeySequenceLineEdit(QWidget *parent)
:QLineEdit(parent)//,numKeys(0)
{
//keys[0] = keys[1] = keys[2] = keys[3] = 0;
setAlignment(Qt::AlignRight);
QPixmap clearPixmap(":/images/clear_shortcut.png");
QPixmap acceptPixmap(":/images/accept_shortcut.png");
clearButton = new QToolButton(this);
acceptButton = new QToolButton(this);
QString buttonsStyle = "QToolButton { border: none; padding: 0px; }";
clearButton->setIcon(QIcon(clearPixmap));
clearButton->setIconSize(clearPixmap.size());
clearButton->setCursor(Qt::ArrowCursor);
clearButton->setStyleSheet(buttonsStyle);
acceptButton->setIcon(QIcon(acceptPixmap));
acceptButton->setIconSize(acceptPixmap.size());
acceptButton->setCursor(Qt::ArrowCursor);
acceptButton->setStyleSheet(buttonsStyle);
connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
connect(acceptButton, SIGNAL(clicked()), this, SIGNAL(editingFinished()));
}
void KeySequenceLineEdit::resizeEvent(QResizeEvent *)
{
QSize szClear = clearButton->sizeHint();
//int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
int leftMargin = style()->pixelMetric(QStyle::PM_LayoutLeftMargin);
int topMargin = style()->pixelMetric(QStyle::PM_LayoutTopMargin);
clearButton->move(0 + leftMargin,topMargin-4);
acceptButton->move( leftMargin + szClear.width(),topMargin-4);
}
void KeySequenceLineEdit::keyPressEvent(QKeyEvent * e)
{
int key = e->key();
//if ( numKeys > 3 ||
if ( key == Qt::Key_Control ||
key == Qt::Key_Shift ||
key == Qt::Key_Meta ||
key == Qt::Key_Alt )
return;
key |= translateModifiers(e->modifiers(), e->text());
/*switch (numKeys) {
case 0:
keys[0] = nextKey;
break;
case 1:
keys[1] = nextKey;
break;
case 2:
keys[2] = nextKey;
break;
case 3:
keys[3] = nextKey;
break;
default:
break;
}*/
//numKeys++;
QKeySequence keySequence = QKeySequence(key);
setText(keySequence.toString(QKeySequence::NativeText));
e->accept();
}
int KeySequenceLineEdit::translateModifiers(Qt::KeyboardModifiers state,
const QString &text)
{
int result = 0;
// The shift modifier only counts when it is not used to type a symbol
// that is only reachable using the shift key anyway
if ((state & Qt::ShiftModifier) && (text.size() == 0
|| !text.at(0).isPrint()
|| text.at(0).isLetterOrNumber()
|| text.at(0).isSpace()))
result |= Qt::SHIFT;
if (state & Qt::ControlModifier)
result |= Qt::CTRL;
if (state & Qt::MetaModifier)
result |= Qt::META;
if (state & Qt::AltModifier)
result |= Qt::ALT;
return result;
}

View File

@ -0,0 +1,48 @@
#ifndef EDIT_SHORTCUT_ITEM_DELEGATE_H
#define EDIT_SHORTCUT_ITEM_DELEGATE_H
#include <QItemDelegate>
#include <QLineEdit>
#include <QKeyEvent>
#include <QKeySequence>
#include <QToolButton>
class KeySequenceLineEdit : public QLineEdit
{
Q_OBJECT
public:
explicit KeySequenceLineEdit(QWidget *parent = 0);
protected:
//int numKeys;
//int keys[4];
void keyPressEvent(QKeyEvent *);
int translateModifiers(Qt::KeyboardModifiers state, const QString &text);
void resizeEvent(QResizeEvent *);
private:
QToolButton *clearButton;
QToolButton *acceptButton;
};
class EditShortcutItemDelegate : public QItemDelegate
{
Q_OBJECT
public:
explicit EditShortcutItemDelegate(QObject *parent = 0);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex & mi) const;
bool eventFilter(QObject *editor, QEvent *event);
signals:
public slots:
void closeShortcutEditor();
};
#endif // EDIT_SHORTCUT_ITEM_DELEGATE_H

View File

@ -0,0 +1,82 @@
#include "shortcuts_dialog.h"
#include "actions_groups_model.h"
#include "actions_shortcuts_model.h"
#include "edit_shortcut_item_delegate.h"
#include <QVBoxLayout>
#include <QSplitter>
#include <QListView>
#include <QTableView>
#include <QPushButton>
#include <QHeaderView>
#include <QLabel>
#include "QsLog.h"
ShortcutsDialog::ShortcutsDialog(QWidget *parent) :
QDialog(parent)
{
QPushButton * resetButton = new QPushButton(tr("Restore defaults"),this);
QLabel * infoLabel = new QLabel(tr("To change a shortcut, select it, click in the key combination and type the new keys."));
QVBoxLayout * layout = new QVBoxLayout(this);
QSplitter * splitter = new QSplitter(this);
actionsGroupsListView = new QListView(this);
actionsTableView = new QTableView(this);
actionsTableView->verticalHeader()->setHidden(true);
actionsTableView->horizontalHeader()->setHidden(true);
splitter->addWidget(actionsGroupsListView);
splitter->addWidget(actionsTableView);
splitter->setStretchFactor(1,1);
splitter->setSizes(QList<int>() << 200 << 400);
layout->addWidget(infoLabel,0);
layout->addWidget(splitter,1);
layout->addWidget(resetButton,0,Qt::AlignRight);
setLayout(layout);
groupsModel = new ActionsGroupsModel();
actionsModel = new ActionsShortcutsModel();
actionsGroupsListView->setModel(groupsModel);
actionsTableView->setModel(actionsModel);
actionsTableView->setColumnWidth(0,30);
actionsTableView->setColumnWidth(1,270);
actionsTableView->horizontalHeader()->setStretchLastSection(true);
actionsTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
actionsTableView->setShowGrid(false);
actionsTableView->setItemDelegateForColumn(ActionsShortcutsModel::KEYS,new EditShortcutItemDelegate(this));
actionsTableView->installEventFilter(this);
/*actionsTableView->setStyleSheet("QTableView {outline: 0px;}"
"QTableView::item {outline: 0px;}");
"QTableView {border:0px;}"
"QTableView::item:selected {outline: 0px; border: 0px;}"
"");*/
connect(resetButton,SIGNAL(clicked()),this,SLOT(resetToDefaults()));
connect(actionsGroupsListView->selectionModel(),SIGNAL(currentChanged(QModelIndex,QModelIndex)),this,SLOT(loadShortcuts(QModelIndex,QModelIndex))); //clicked(QModelIndex) doesn't work :S
setFixedSize(640,480);
setWindowTitle(tr("Shortcuts settings"));
setModal(true);
}
void ShortcutsDialog::addActionsGroup(const QString &name, const QIcon &ico, QList<QAction *> &group)
{
//TODO
//groups model add
groupsModel->addActionsGroup(ActionsGroup(name,ico,group));
}
void ShortcutsDialog::resetToDefaults()
{
}
void ShortcutsDialog::loadShortcuts(const QModelIndex &mi,const QModelIndex &mi2)
{
actionsModel->addActions(groupsModel->getActions(mi));
}

View File

@ -0,0 +1,32 @@
#ifndef SHORTCUTS_DIALOG_H
#define SHORTCUTS_DIALOG_H
#include <QDialog>
#include <QModelIndex>
class QListView;
class QTableView;
class ActionsGroupsModel;
class ActionsShortcutsModel;
class ShortcutsDialog : public QDialog
{
Q_OBJECT
public:
explicit ShortcutsDialog(QWidget * parent = 0);
void addActionsGroup(const QString & name, const QIcon & ico, QList<QAction *> & group);
signals:
public slots:
void resetToDefaults();
void loadShortcuts(const QModelIndex & mi,const QModelIndex &mi2);
protected:
QListView * actionsGroupsListView;
QTableView * actionsTableView;
ActionsGroupsModel * groupsModel;
ActionsShortcutsModel * actionsModel;
};
#endif // SHORTCUTS_DIALOG_H

View File

@ -0,0 +1,16 @@
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD
HEADERS += \
$$PWD/shortcuts_dialog.h \
$$PWD/actions_groups_model.h \
$$PWD/actions_shortcuts_model.h \
$$PWD/edit_shortcut_item_delegate.h \
$$PWD/shortcuts_manager.h
SOURCES += \
$$PWD/shortcuts_dialog.cpp \
$$PWD/actions_groups_model.cpp \
$$PWD/actions_shortcuts_model.cpp \
$$PWD/edit_shortcut_item_delegate.cpp \
$$PWD/shortcuts_manager.cpp

View File

@ -0,0 +1,49 @@
#include "shortcuts_manager.h"
#include <QSettings>
#include <QAction>
#include "yacreader_global.h"
ShortcutsManager::ShortcutsManager()
{
initDefaultShorcuts();
}
void ShortcutsManager::initDefaultShorcuts()
{
defaultShorcuts.insert(CREATE_LIBRARY_ACTION_YL,Qt::Key_A);
defaultShorcuts.insert(OPEN_LIBRARY_ACTION_YL,Qt::Key_O);
defaultShorcuts.insert(UPDATE_LIBRARY_ACTION_YL,Qt::Key_U);
defaultShorcuts.insert(RENAME_LIBRARY_ACTION_YL,Qt::Key_R);
defaultShorcuts.insert(OPEN_COMIC_ACTION_YL,Qt::Key_Return);
defaultShorcuts.insert(SHOW_HIDE_MARKS_ACTION_YL,Qt::Key_M);
defaultShorcuts.insert(TOGGLE_FULL_SCREEN_ACTION_YL,Qt::Key_F);
defaultShorcuts.insert(HELP_ABOUT_ACTION_YL,Qt::Key_F1);
defaultShorcuts.insert(SET_ROOT_INDEX_ACTION_YL,Qt::Key_0);
defaultShorcuts.insert(EXPAND_ALL_NODES_ACTION_YL,Qt::Key_Plus);
defaultShorcuts.insert(COLAPSE_ALL_NODES_ACTION_YL,Qt::Key_Minus);
defaultShorcuts.insert(OPTIONS_ACTION_YL,Qt::Key_C);
defaultShorcuts.insert(SERVER_CONFIG_ACTION_YL,Qt::Key_S);
defaultShorcuts.insert(TOGGLE_COMICS_VIEW_ACTION_YL,Qt::Key_V);
}
void ShortcutsManager::resetToDefaults()
{
//TODO reset to defaults
}
QString ShortcutsManager::getShortcut(const QString &name)
{
QSettings s(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat);
s.beginGroup("shortcuts");
return s.value(name,defaultShorcuts.value(name)).toString();
}
void ShortcutsManager::saveShortcut(QAction *action)
{
QSettings s(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat);
s.beginGroup("shortcuts");
return s.setValue(action->data().toString() , action->shortcut().toString());
}

View File

@ -0,0 +1,73 @@
#ifndef SHORTCUTS_MANAGER_H
#define SHORTCUTS_MANAGER_H
#include <QObject>
#include <QKeySequence>
#include <QString>
#include <QMap>
class QAction;
//QAction: used setData() and data() for storing (userData) an identifier for each QAction. This value is ussed in QSettings
class ShortcutsManager
{
private:
ShortcutsManager();
QMap<QString,QKeySequence> defaultShorcuts;
void initDefaultShorcuts();
public:
static ShortcutsManager & getShortcutsManager()
{
static ShortcutsManager manager;
return manager;
}
void resetToDefaults();
QString getShortcut(const QString & name);
void saveShortcut(QAction * action);
};
//ACTION NAMES YACReaderLibrary
#define BACK_ACTION_YL "BACK_ACTION_YL"
#define FORWARD_ACTION_YL "FORWARD_ACTION_YL"
#define CREATE_LIBRARY_ACTION_YL "CREATE_LIBRARY_ACTION_YL"
#define OPEN_LIBRARY_ACTION_YL "OPEN_LIBRARY_ACTION_YL"
#define EXPORT_COMICS_INFO_YL "EXPORT_COMICS_INFO_YL"
#define IMPORT_COMICS_INFO_YL "IMPORT_COMICS_INFO_YL"
#define EXPORT_LIBRARY_ACTION_YL "EXPORT_LIBRARY_ACTION_YL"
#define IMPORT_LIBRARY_ACTION_YL "IMPORT_LIBRARY_ACTION_YL"
#define UPDATE_LIBRARY_ACTION_YL "UPDATE_LIBRARY_ACTION_YL"
#define RENAME_LIBRARY_ACTION_YL "RENAME_LIBRARY_ACTION_YL"
#define REMOVE_LIBRARY_ACTION_YL "REMOVE_LIBRARY_ACTION_YL"
#define OPEN_COMIC_ACTION_YL "OPEN_COMIC_ACTION_YL"
#define SET_AS_READ_ACTION_YL "SET_AS_READ_ACTION_YL"
#define SET_AS_NON_READ_ACTION_YL "SET_AS_NON_READ_ACTION_YL"
#define SHOW_HIDE_MARKS_ACTION_YL "SHOW_HIDE_MARKS_ACTION_YL"
#define TOGGLE_FULL_SCREEN_ACTION_YL "TOGGLE_FULL_SCREEN_ACTION_YL"
#define HELP_ABOUT_ACTION_YL "HELP_ABOUT_ACTION_YL"
#define SET_ROOT_INDEX_ACTION_YL "SET_ROOT_INDEX_ACTION_YL"
#define EXPAND_ALL_NODES_ACTION_YL "EXPAND_ALL_NODES_ACTION_YL"
#define COLAPSE_ALL_NODES_ACTION_YL "COLAPSE_ALL_NODES_ACTION_YL"
#define OPTIONS_ACTION_YL "OPTIONS_ACTION_YL"
#define SERVER_CONFIG_ACTION_YL "SERVER_CONFIG_ACTION_YL"
#define TOGGLE_COMICS_VIEW_ACTION_YL "TOGGLE_COMICS_VIEW_ACTION_YL"
#define OPEN_CONTAINING_FOLDER_ACTION_YL "OPEN_CONTAINING_FOLDER_ACTION_YL"
#define SET_FOLDER_AS_NOT_COMPLETED_ACTION_YL "SET_FOLDER_AS_NOT_COMPLETED_ACTION_YL"
#define SET_FOLDER_AS_COMPLETED_ACTION_YL "SET_FOLDER_AS_COMPLETED_ACTION_YL"
#define SET_FOLDER_AS_READ_ACTION_YL "SET_FOLDER_AS_READ_ACTION_YL"
#define SET_FOLDER_AS_UNREAD_ACTION_YL "SET_FOLDER_AS_UNREAD_ACTION_YL"
#define OPEN_CONTAINING_FOLDER_COMIC_ACTION_YL "OPEN_CONTAINING_FOLDER_COMIC_ACTION_YL"
#define RESET_COMIC_RATING_ACTION_YL "RESET_COMIC_RATING_ACTION_YL"
#define SELECT_ALL_COMICS_ACTION_YL "SELECT_ALL_COMICS_ACTION_YL"
#define EDIT_SELECTED_COMICS_ACTION_YL "EDIT_SELECTED_COMICS_ACTION_YL"
#define ASIGN_ORDER_ACTION_YL "ASIGN_ORDER_ACTION_YL"
#define FORCE_COVER_EXTRACTED_ACTION_YL "FORCE_COVER_EXTRACTED_ACTION_YL"
#define DELETE_COMICS_ACTION_YL "DELETE_COMICS_ACTION_YL"
#define HIDE_COMIC_VIEW_ACTION_YL "HIDE_COMIC_VIEW_ACTION_YL"
#define GET_INFO_ACTION_YL "GET_INFO_ACTION_YL"
#endif // SHORTCUTS_MANAGER_H