added shortcuts conflicts detection

This commit is contained in:
Luis Ángel San Martín 2014-07-22 22:02:06 +02:00
parent 2712ef89b2
commit eb095bcdaf
8 changed files with 78 additions and 14 deletions

View File

@ -983,14 +983,20 @@ void MainWindowViewer::setUpShortcutsManagement()
//actions holder
QObject * orphanActions = new QObject;
QList<QAction *> allActions;
QList<QAction *> tmpList;
editShortcutsDialog->addActionsGroup(tr("Comics"),QIcon(":/images/shortcuts_group_comics.png"),
QList<QAction *>()
tmpList = QList<QAction *>()
<< 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<QAction *>()
tmpList = QList<QAction *>()
<< 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<QAction *>()
tmpList = QList<QAction *>()
<< 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<QAction *>()
tmpList = QList<QAction *>()
<< 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<QAction *>()
tmpList = QList<QAction *>()
<< nextAction
<< prevAction
<< setBookmarkAction
@ -1101,6 +1113,10 @@ void MainWindowViewer::setUpShortcutsManagement()
<< goToLastPageAction
<< goToPageAction);
allActions << tmpList;
ShortcutsManager::getShortcutsManager().registerActions(allActions);
}
void MainWindowViewer::changeFit()

View File

@ -298,8 +298,11 @@ void LibraryWindow::doDialogs()
void LibraryWindow::setUpShortcutsManagement()
{
QList<QAction *> allActions;
QList<QAction *> tmpList;
editShortcutsDialog->addActionsGroup("Comics",QIcon(":/images/shortcuts_group_comics.png"),
QList<QAction *>()
tmpList = QList<QAction *>()
<< openComicAction
<< setAsReadAction
<< setAsNonReadAction
@ -311,8 +314,10 @@ void LibraryWindow::setUpShortcutsManagement()
<< deleteComicsAction
<< getInfoAction);
allActions << tmpList;
editShortcutsDialog->addActionsGroup("Folders",QIcon(":/images/shortcuts_group_folders.png"),
QList<QAction *>()
tmpList = QList<QAction *>()
<< 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<QAction *>()
tmpList = QList<QAction *>()
<< backAction
<< forwardAction
<< helpAboutAction
@ -331,8 +337,10 @@ void LibraryWindow::setUpShortcutsManagement()
<< serverConfigAction
<< showEditShortcutsAction);
allActions << tmpList;
editShortcutsDialog->addActionsGroup("Libraries",QIcon(":/images/shortcuts_group_libraries.png"),
QList<QAction *>()
tmpList = QList<QAction *>()
<< createLibraryAction
<< openLibraryAction
<< exportComicsInfoAction
@ -343,13 +351,18 @@ void LibraryWindow::setUpShortcutsManagement()
<< renameLibraryAction
<< removeLibraryAction);
allActions << tmpList;
editShortcutsDialog->addActionsGroup("Visualization",QIcon(":/images/shortcuts_group_visualization.png"),
QList<QAction *>()
tmpList = QList<QAction *>()
<< showHideMarksAction
<< toggleFullScreenAction
<< toggleComicsViewAction
<< hideComicViewAction);
allActions << tmpList;
ShortcutsManager::getShortcutsManager().registerActions(allActions);
}
void LibraryWindow::doModels()

View File

@ -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;
}

View File

@ -28,7 +28,7 @@ public:
KEYS
};
signals:
void conflict(QString);
public slots:
protected:

View File

@ -11,6 +11,7 @@
#include <QPushButton>
#include <QHeaderView>
#include <QLabel>
#include <QMessageBox>
#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));
}

View File

@ -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;

View File

@ -93,3 +93,20 @@ void ShortcutsManager::saveShortcut(QAction *action)
return s.setValue(action->data().toString() , action->shortcut().toString());
}
void ShortcutsManager::registerActions(const QList<QAction *> &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;
}

View File

@ -16,6 +16,8 @@ class ShortcutsManager
private:
ShortcutsManager();
QMap<QString,QKeySequence> defaultShorcuts;
QList<QAction *> 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<QAction *> & actions);
bool checkConflicts(const QKeySequence &shortcut, const QAction *dest);
};
//ACTION NAMES YACReaderLibrary