From 50c8eca7c4440af43782dde012241ab84dcf4158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Thu, 17 Jul 2014 22:30:03 +0200 Subject: [PATCH] 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...) --- YACReaderLibrary/YACReaderLibrary.pro | 1 + YACReaderLibrary/images.qrc | 2 + YACReaderLibrary/library_window.cpp | 226 ++++++++++++++---- YACReaderLibrary/library_window.h | 17 +- YACReaderLibrary/options_dialog.cpp | 64 +++-- YACReaderLibrary/options_dialog.h | 2 + images/accept_shortcut.png | Bin 0 -> 239 bytes images/clear_shortcut.png | Bin 0 -> 201 bytes shortcuts_management/actions_groups_model.cpp | 80 +++++++ shortcuts_management/actions_groups_model.h | 44 ++++ .../actions_shortcuts_model.cpp | 92 +++++++ .../actions_shortcuts_model.h | 38 +++ .../edit_shortcut_item_delegate.cpp | 145 +++++++++++ .../edit_shortcut_item_delegate.h | 48 ++++ shortcuts_management/shortcuts_dialog.cpp | 82 +++++++ shortcuts_management/shortcuts_dialog.h | 32 +++ shortcuts_management/shortcuts_management.pri | 16 ++ shortcuts_management/shortcuts_manager.cpp | 49 ++++ shortcuts_management/shortcuts_manager.h | 73 ++++++ 19 files changed, 933 insertions(+), 78 deletions(-) create mode 100644 images/accept_shortcut.png create mode 100644 images/clear_shortcut.png create mode 100644 shortcuts_management/actions_groups_model.cpp create mode 100644 shortcuts_management/actions_groups_model.h create mode 100644 shortcuts_management/actions_shortcuts_model.cpp create mode 100644 shortcuts_management/actions_shortcuts_model.h create mode 100644 shortcuts_management/edit_shortcut_item_delegate.cpp create mode 100644 shortcuts_management/edit_shortcut_item_delegate.h create mode 100644 shortcuts_management/shortcuts_dialog.cpp create mode 100644 shortcuts_management/shortcuts_dialog.h create mode 100644 shortcuts_management/shortcuts_management.pri create mode 100644 shortcuts_management/shortcuts_manager.cpp create mode 100644 shortcuts_management/shortcuts_manager.h diff --git a/YACReaderLibrary/YACReaderLibrary.pro b/YACReaderLibrary/YACReaderLibrary.pro index 3523e1ec..88275787 100644 --- a/YACReaderLibrary/YACReaderLibrary.pro +++ b/YACReaderLibrary/YACReaderLibrary.pro @@ -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 diff --git a/YACReaderLibrary/images.qrc b/YACReaderLibrary/images.qrc index fb527aa9..d6551235 100644 --- a/YACReaderLibrary/images.qrc +++ b/YACReaderLibrary/images.qrc @@ -100,6 +100,8 @@ ../images/comic_vine/downArrow.png ../images/comic_vine/upArrow.png ../images/find_folder.png + ../images/clear_shortcut.png + ../images/accept_shortcut.png diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index fe8621dc..d61d796a 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -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() + << openComicAction + << setAsReadAction + << setAsNonReadAction + << openContainingFolderComicAction + << resetComicRatingAction + << selectAllComicsAction + << editSelectedComicsAction + << asignOrderAction + << deleteComicsAction + << getInfoAction); + + shortcutsDialog->addActionsGroup("Folders",QIcon(), + QList() + << setRootIndexAction + << expandAllNodesAction + << colapseAllNodesAction + << openContainingFolderAction + << setFolderAsNotCompletedAction + << setFolderAsCompletedAction + << setFolderAsReadAction + << setFolderAsUnreadAction); + + shortcutsDialog->addActionsGroup("General",QIcon(), + QList() + << backAction + << forwardAction + << helpAboutAction + << optionsAction + << serverConfigAction); + + shortcutsDialog->addActionsGroup("Libraries",QIcon(), + QList() + << createLibraryAction + << openLibraryAction + << exportComicsInfoAction + << importComicsInfoAction + << exportLibraryAction + << importLibraryAction + << updateLibraryAction + << renameLibraryAction + << removeLibraryAction); + + shortcutsDialog->addActionsGroup("Visualization",QIcon(), + QList() + << 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); diff --git a/YACReaderLibrary/library_window.h b/YACReaderLibrary/library_window.h index 8092a774..d44ec840 100644 --- a/YACReaderLibrary/library_window.h +++ b/YACReaderLibrary/library_window.h @@ -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(); diff --git a/YACReaderLibrary/options_dialog.cpp b/YACReaderLibrary/options_dialog.cpp index d8b15a92..2ab02678 100644 --- a/YACReaderLibrary/options_dialog.cpp +++ b/YACReaderLibrary/options_dialog.cpp @@ -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())); } + diff --git a/YACReaderLibrary/options_dialog.h b/YACReaderLibrary/options_dialog.h index d42a9ead..d597f686 100644 --- a/YACReaderLibrary/options_dialog.h +++ b/YACReaderLibrary/options_dialog.h @@ -12,6 +12,8 @@ class OptionsDialog : public YACReaderOptionsDialog Q_OBJECT public: OptionsDialog(QWidget * parent = 0); +signals: + void editShortcuts(); }; diff --git a/images/accept_shortcut.png b/images/accept_shortcut.png new file mode 100644 index 0000000000000000000000000000000000000000..4d2b852dbb11826d538a648f3f54978f42a34aa2 GIT binary patch literal 239 zcmeAS@N?(olHy`uVBq!ia0vp^{2desrQkZrc3qwyCW}}k0)(F2aY-^wQW4T&dvJw=O(A{p<9+w;u_(-I j@a2;<=8HJSz+u1;{43|ILXVFL&~Xf&u6{1-oD!M<=Sfdc literal 0 HcmV?d00001 diff --git a/images/clear_shortcut.png b/images/clear_shortcut.png new file mode 100644 index 0000000000000000000000000000000000000000..e7d2102090a0163f4d43f534146efb288749987e GIT binary patch literal 201 zcmeAS@N?(olHy`uVBq!ia0vp^{2}1{rUgjo_S{j>+FR3_;{%avpQ9##6^Uda62oW zNGrK>{q}EpdHFWU#B;}zr1coeS%oJ(@KM^!6@J`fD+9CD+y$Nv>c)p|`0$7@sMRc6 xeAy*)*@-ZAh#RIKn@O1TaS?83{1OR@5MT-Cc literal 0 HcmV?d00001 diff --git a/shortcuts_management/actions_groups_model.cpp b/shortcuts_management/actions_groups_model.cpp new file mode 100644 index 00000000..47ba2e91 --- /dev/null +++ b/shortcuts_management/actions_groups_model.cpp @@ -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 ActionsGroupsModel::getActions(const QModelIndex &mi) +{ + if(mi.isValid()) + return groups[mi.row()].getActions(); + return QList(); +} + +//------------------------------------------------------------------- + +ActionsGroup::ActionsGroup(const QString &name, const QIcon &icon, QList &actions) + :name(name), icon(icon), actions(actions) +{ + +} + +QString ActionsGroup::getName() const +{ + return name; +} + +QIcon ActionsGroup::getIcon() const +{ + return icon; +} + +QList ActionsGroup::getActions() const +{ + return actions; +} diff --git a/shortcuts_management/actions_groups_model.h b/shortcuts_management/actions_groups_model.h new file mode 100644 index 00000000..91fb5a7c --- /dev/null +++ b/shortcuts_management/actions_groups_model.h @@ -0,0 +1,44 @@ +#ifndef ACTIONS_GROUPS_MODEL_H +#define ACTIONS_GROUPS_MODEL_H + +#include +#include + +class QAction; + +class ActionsGroup +{ +public: + ActionsGroup(const QString & name, const QIcon & icon, QList & actions); + QString getName() const; + QIcon getIcon() const; + QList getActions() const; +protected: + QString name; + QIcon icon; + QList 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 getActions(const QModelIndex & mi); +signals: + +public slots: + +protected: + QList groups; +}; + +#endif // ACTIONS_GROUPS_MODEL_H diff --git a/shortcuts_management/actions_shortcuts_model.cpp b/shortcuts_management/actions_shortcuts_model.cpp new file mode 100644 index 00000000..0a9760d1 --- /dev/null +++ b/shortcuts_management/actions_shortcuts_model.cpp @@ -0,0 +1,92 @@ +#include "actions_shortcuts_model.h" +#include "shortcuts_manager.h" + +#include + +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 actions) +{ + beginResetModel(); + this->actions = actions; + endResetModel(); +} diff --git a/shortcuts_management/actions_shortcuts_model.h b/shortcuts_management/actions_shortcuts_model.h new file mode 100644 index 00000000..58ea16f5 --- /dev/null +++ b/shortcuts_management/actions_shortcuts_model.h @@ -0,0 +1,38 @@ +#ifndef ACTIONS_SHORTCUTS_MODEL_H +#define ACTIONS_SHORTCUTS_MODEL_H + +#include + +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 actions); + Qt::ItemFlags flags(const QModelIndex &index) const; + + + enum Columns { + ICON = 0, + NAME, + KEYS + }; +signals: + +public slots: + +protected: + QList actions; +}; + +#endif // ACTIONS_SHORTCUTS_MODEL_H diff --git a/shortcuts_management/edit_shortcut_item_delegate.cpp b/shortcuts_management/edit_shortcut_item_delegate.cpp new file mode 100644 index 00000000..5b7d3627 --- /dev/null +++ b/shortcuts_management/edit_shortcut_item_delegate.cpp @@ -0,0 +1,145 @@ +#include "edit_shortcut_item_delegate.h" + +#include + +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(editor); + lineEdit->setText(value); +} + +void EditShortcutItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const +{ + KeySequenceLineEdit *lineEdit = static_cast(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(sender())); + emit closeEditor(static_cast(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; +} + diff --git a/shortcuts_management/edit_shortcut_item_delegate.h b/shortcuts_management/edit_shortcut_item_delegate.h new file mode 100644 index 00000000..7cc1e4e8 --- /dev/null +++ b/shortcuts_management/edit_shortcut_item_delegate.h @@ -0,0 +1,48 @@ +#ifndef EDIT_SHORTCUT_ITEM_DELEGATE_H +#define EDIT_SHORTCUT_ITEM_DELEGATE_H + +#include +#include +#include +#include +#include + +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 diff --git a/shortcuts_management/shortcuts_dialog.cpp b/shortcuts_management/shortcuts_dialog.cpp new file mode 100644 index 00000000..d48c87d8 --- /dev/null +++ b/shortcuts_management/shortcuts_dialog.cpp @@ -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 +#include +#include +#include +#include +#include +#include + +#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() << 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 &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)); +} diff --git a/shortcuts_management/shortcuts_dialog.h b/shortcuts_management/shortcuts_dialog.h new file mode 100644 index 00000000..d63c9bcd --- /dev/null +++ b/shortcuts_management/shortcuts_dialog.h @@ -0,0 +1,32 @@ +#ifndef SHORTCUTS_DIALOG_H +#define SHORTCUTS_DIALOG_H + +#include +#include + +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 & 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 diff --git a/shortcuts_management/shortcuts_management.pri b/shortcuts_management/shortcuts_management.pri new file mode 100644 index 00000000..e85a6912 --- /dev/null +++ b/shortcuts_management/shortcuts_management.pri @@ -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 diff --git a/shortcuts_management/shortcuts_manager.cpp b/shortcuts_management/shortcuts_manager.cpp new file mode 100644 index 00000000..eca6e45b --- /dev/null +++ b/shortcuts_management/shortcuts_manager.cpp @@ -0,0 +1,49 @@ +#include "shortcuts_manager.h" + +#include +#include +#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()); +} diff --git a/shortcuts_management/shortcuts_manager.h b/shortcuts_management/shortcuts_manager.h new file mode 100644 index 00000000..d8cf0c69 --- /dev/null +++ b/shortcuts_management/shortcuts_manager.h @@ -0,0 +1,73 @@ +#ifndef SHORTCUTS_MANAGER_H +#define SHORTCUTS_MANAGER_H + +#include +#include +#include +#include + + +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 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