diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index e77ded8e..3c16a805 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -983,14 +983,20 @@ void MainWindowViewer::setUpShortcutsManagement() //actions holder QObject * orphanActions = new QObject; + QList allActions; + QList tmpList; + + editShortcutsDialog->addActionsGroup(tr("Comics"),QIcon(":/images/shortcuts_group_comics.png"), - QList() + tmpList = QList() << openAction << openFolderAction << saveImageAction << openPreviousComicAction << openNextComicAction); + allActions << tmpList; + //keys without actions (General) QAction * toggleFullScreenAction = new QAction(tr("Toggle fullscreen mode"),orphanActions); toggleFullScreenAction->setData(TOGGLE_FULL_SCREEN_ACTION_Y); @@ -1001,7 +1007,7 @@ void MainWindowViewer::setUpShortcutsManagement() toggleToolbarsAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(TOGGLE_TOOL_BARS_ACTION_Y)); editShortcutsDialog->addActionsGroup(tr("General"),QIcon(":/images/shortcuts_group_general.png"), - QList() + tmpList = QList() << optionsAction << helpAboutAction << showShorcutsAction @@ -1013,6 +1019,8 @@ void MainWindowViewer::setUpShortcutsManagement() << toggleToolbarsAction << showEditShortcutsAction); + allActions << tmpList; + //keys without actions (MGlass) QAction * sizeUpMglassAction = new QAction(tr("Size up magnifying glass"),orphanActions); sizeUpMglassAction->setData(SIZE_UP_MGLASS_ACTION_Y); @@ -1031,20 +1039,22 @@ void MainWindowViewer::setUpShortcutsManagement() zoomOutMglassAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_OUT_MGLASS_ACTION_Y)); editShortcutsDialog->addActionsGroup(tr("Magnifiying glass"),QIcon(":/images/shortcuts_group_mglass.png"), - QList() + tmpList = QList() << showMagnifyingGlassAction << sizeUpMglassAction << sizeDownMglassAction << zoomInMglassAction << zoomOutMglassAction); + allActions << tmpList; + //keys without actions QAction * toggleFitToScreenAction = new QAction(tr("Toggle between fit to width and fit to height"),orphanActions); toggleFitToScreenAction->setData(CHANGE_FIT_ACTION_Y); toggleFitToScreenAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(CHANGE_FIT_ACTION_Y)); editShortcutsDialog->addActionsGroup(tr("Page adjustement"),QIcon(":/images/shortcuts_group_page.png"), - QList() + tmpList = QList() << adjustHeightAction << adjustWidthAction << toggleFitToScreenAction @@ -1053,6 +1063,8 @@ void MainWindowViewer::setUpShortcutsManagement() << doublePageAction << adjustToFullSizeAction); + allActions << tmpList; + QAction * autoScrollForwardAction = new QAction(tr("Autoscroll down"),orphanActions); autoScrollForwardAction->setData(AUTO_SCROLL_FORWARD_ACTION_Y); autoScrollForwardAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_FORWARD_ACTION_Y)); @@ -1086,7 +1098,7 @@ void MainWindowViewer::setUpShortcutsManagement() goToLastPageAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(GO_TO_LAST_PAGE_ACTION_Y)); editShortcutsDialog->addActionsGroup(tr("Reading"),QIcon(":/images/shortcuts_group_reading.png"), - QList() + tmpList = QList() << nextAction << prevAction << setBookmarkAction @@ -1101,6 +1113,10 @@ void MainWindowViewer::setUpShortcutsManagement() << goToLastPageAction << goToPageAction); + allActions << tmpList; + + ShortcutsManager::getShortcutsManager().registerActions(allActions); + } void MainWindowViewer::changeFit() diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index 0d2e9a42..dc4a8ea5 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -298,8 +298,11 @@ void LibraryWindow::doDialogs() void LibraryWindow::setUpShortcutsManagement() { + QList allActions; + QList tmpList; + editShortcutsDialog->addActionsGroup("Comics",QIcon(":/images/shortcuts_group_comics.png"), - QList() + tmpList = QList() << openComicAction << setAsReadAction << setAsNonReadAction @@ -311,8 +314,10 @@ void LibraryWindow::setUpShortcutsManagement() << deleteComicsAction << getInfoAction); + allActions << tmpList; + editShortcutsDialog->addActionsGroup("Folders",QIcon(":/images/shortcuts_group_folders.png"), - QList() + tmpList = QList() << setRootIndexAction << expandAllNodesAction << colapseAllNodesAction @@ -321,9 +326,10 @@ void LibraryWindow::setUpShortcutsManagement() << setFolderAsCompletedAction << setFolderAsReadAction << setFolderAsUnreadAction); + allActions << tmpList; editShortcutsDialog->addActionsGroup("General",QIcon(":/images/shortcuts_group_general.png"), - QList() + tmpList = QList() << backAction << forwardAction << helpAboutAction @@ -331,8 +337,10 @@ void LibraryWindow::setUpShortcutsManagement() << serverConfigAction << showEditShortcutsAction); + allActions << tmpList; + editShortcutsDialog->addActionsGroup("Libraries",QIcon(":/images/shortcuts_group_libraries.png"), - QList() + tmpList = QList() << createLibraryAction << openLibraryAction << exportComicsInfoAction @@ -343,13 +351,18 @@ void LibraryWindow::setUpShortcutsManagement() << renameLibraryAction << removeLibraryAction); + allActions << tmpList; + editShortcutsDialog->addActionsGroup("Visualization",QIcon(":/images/shortcuts_group_visualization.png"), - QList() + tmpList = QList() << showHideMarksAction << toggleFullScreenAction << toggleComicsViewAction << hideComicViewAction); + allActions << tmpList; + + ShortcutsManager::getShortcutsManager().registerActions(allActions); } void LibraryWindow::doModels() diff --git a/shortcuts_management/actions_shortcuts_model.cpp b/shortcuts_management/actions_shortcuts_model.cpp index 86c7d7ba..ba9b98bc 100644 --- a/shortcuts_management/actions_shortcuts_model.cpp +++ b/shortcuts_management/actions_shortcuts_model.cpp @@ -80,9 +80,15 @@ bool ActionsShortcutsModel::setData(const QModelIndex &index, const QVariant &va { if(index.column() == KEYS) { - actions[index.row()]->setShortcut(value.toString()); - ShortcutsManager::getShortcutsManager().saveShortcut(actions[index.row()]); - return true; + ShortcutsManager sm = ShortcutsManager::getShortcutsManager(); + if(sm.checkConflicts(value.toString(), actions[index.row()])) + emit conflict(value.toString()); + else + { + actions[index.row()]->setShortcut(value.toString()); + ShortcutsManager::getShortcutsManager().saveShortcut(actions[index.row()]); + return true; + } } return false; } diff --git a/shortcuts_management/actions_shortcuts_model.h b/shortcuts_management/actions_shortcuts_model.h index 58ea16f5..03e3bde6 100644 --- a/shortcuts_management/actions_shortcuts_model.h +++ b/shortcuts_management/actions_shortcuts_model.h @@ -28,7 +28,7 @@ public: KEYS }; signals: - + void conflict(QString); public slots: protected: diff --git a/shortcuts_management/edit_shortcuts_dialog.cpp b/shortcuts_management/edit_shortcuts_dialog.cpp index 5cfd9088..46dea7a6 100644 --- a/shortcuts_management/edit_shortcuts_dialog.cpp +++ b/shortcuts_management/edit_shortcuts_dialog.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "QsLog.h" @@ -59,6 +60,7 @@ EditShortcutsDialog::EditShortcutsDialog(QWidget *parent) : 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 + connect(actionsModel,SIGNAL(conflict(QString)),this,SLOT(processConflict(QString))); #ifdef Q_OS_MAC setFixedSize(760,500); @@ -86,3 +88,8 @@ void EditShortcutsDialog::loadShortcuts(const QModelIndex &mi,const QModelIndex { actionsModel->addActions(groupsModel->getActions(mi)); } + +void EditShortcutsDialog::processConflict(const QString &shortcutInConflict) +{ + QMessageBox::warning(this,tr("Shortcut in use"), QString(tr("The shortcut \"%1\" is already assigned to other function")).arg(shortcutInConflict)); +} diff --git a/shortcuts_management/edit_shortcuts_dialog.h b/shortcuts_management/edit_shortcuts_dialog.h index 0ba29413..e0debf98 100644 --- a/shortcuts_management/edit_shortcuts_dialog.h +++ b/shortcuts_management/edit_shortcuts_dialog.h @@ -21,6 +21,7 @@ signals: public slots: void resetToDefaults(); void loadShortcuts(const QModelIndex & mi,const QModelIndex &mi2); + void processConflict(const QString & shortcutInConflict); protected: QListView * actionsGroupsListView; diff --git a/shortcuts_management/shortcuts_manager.cpp b/shortcuts_management/shortcuts_manager.cpp index d7bb4375..df8d253d 100644 --- a/shortcuts_management/shortcuts_manager.cpp +++ b/shortcuts_management/shortcuts_manager.cpp @@ -93,3 +93,20 @@ void ShortcutsManager::saveShortcut(QAction *action) return s.setValue(action->data().toString() , action->shortcut().toString()); } + +void ShortcutsManager::registerActions(const QList &a) +{ + actions = a; +} + +bool ShortcutsManager::checkConflicts(const QKeySequence & shortcut, const QAction *dest) +{ + foreach(QAction * action, actions) + { + if(action != dest) //if the same shortcut is setted there is no conflict + if(action->shortcut() == shortcut) + return true; + } + + return false; +} diff --git a/shortcuts_management/shortcuts_manager.h b/shortcuts_management/shortcuts_manager.h index 6fd2f5c5..c6e3eae5 100644 --- a/shortcuts_management/shortcuts_manager.h +++ b/shortcuts_management/shortcuts_manager.h @@ -16,6 +16,8 @@ class ShortcutsManager private: ShortcutsManager(); QMap defaultShorcuts; + QList actions; //all actions registered, used for checking conflicts + void initDefaultShorcuts(); public: static ShortcutsManager & getShortcutsManager() @@ -27,6 +29,8 @@ public: void resetToDefaults(); QString getShortcut(const QString & name); void saveShortcut(QAction * action); + void registerActions(const QList & actions); + bool checkConflicts(const QKeySequence &shortcut, const QAction *dest); }; //ACTION NAMES YACReaderLibrary