mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
added shortcuts conflicts detection
This commit is contained in:
parent
2712ef89b2
commit
eb095bcdaf
@ -983,14 +983,20 @@ void MainWindowViewer::setUpShortcutsManagement()
|
|||||||
//actions holder
|
//actions holder
|
||||||
QObject * orphanActions = new QObject;
|
QObject * orphanActions = new QObject;
|
||||||
|
|
||||||
|
QList<QAction *> allActions;
|
||||||
|
QList<QAction *> tmpList;
|
||||||
|
|
||||||
|
|
||||||
editShortcutsDialog->addActionsGroup(tr("Comics"),QIcon(":/images/shortcuts_group_comics.png"),
|
editShortcutsDialog->addActionsGroup(tr("Comics"),QIcon(":/images/shortcuts_group_comics.png"),
|
||||||
QList<QAction *>()
|
tmpList = QList<QAction *>()
|
||||||
<< openAction
|
<< openAction
|
||||||
<< openFolderAction
|
<< openFolderAction
|
||||||
<< saveImageAction
|
<< saveImageAction
|
||||||
<< openPreviousComicAction
|
<< openPreviousComicAction
|
||||||
<< openNextComicAction);
|
<< openNextComicAction);
|
||||||
|
|
||||||
|
allActions << tmpList;
|
||||||
|
|
||||||
//keys without actions (General)
|
//keys without actions (General)
|
||||||
QAction * toggleFullScreenAction = new QAction(tr("Toggle fullscreen mode"),orphanActions);
|
QAction * toggleFullScreenAction = new QAction(tr("Toggle fullscreen mode"),orphanActions);
|
||||||
toggleFullScreenAction->setData(TOGGLE_FULL_SCREEN_ACTION_Y);
|
toggleFullScreenAction->setData(TOGGLE_FULL_SCREEN_ACTION_Y);
|
||||||
@ -1001,7 +1007,7 @@ void MainWindowViewer::setUpShortcutsManagement()
|
|||||||
toggleToolbarsAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(TOGGLE_TOOL_BARS_ACTION_Y));
|
toggleToolbarsAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(TOGGLE_TOOL_BARS_ACTION_Y));
|
||||||
|
|
||||||
editShortcutsDialog->addActionsGroup(tr("General"),QIcon(":/images/shortcuts_group_general.png"),
|
editShortcutsDialog->addActionsGroup(tr("General"),QIcon(":/images/shortcuts_group_general.png"),
|
||||||
QList<QAction *>()
|
tmpList = QList<QAction *>()
|
||||||
<< optionsAction
|
<< optionsAction
|
||||||
<< helpAboutAction
|
<< helpAboutAction
|
||||||
<< showShorcutsAction
|
<< showShorcutsAction
|
||||||
@ -1013,6 +1019,8 @@ void MainWindowViewer::setUpShortcutsManagement()
|
|||||||
<< toggleToolbarsAction
|
<< toggleToolbarsAction
|
||||||
<< showEditShortcutsAction);
|
<< showEditShortcutsAction);
|
||||||
|
|
||||||
|
allActions << tmpList;
|
||||||
|
|
||||||
//keys without actions (MGlass)
|
//keys without actions (MGlass)
|
||||||
QAction * sizeUpMglassAction = new QAction(tr("Size up magnifying glass"),orphanActions);
|
QAction * sizeUpMglassAction = new QAction(tr("Size up magnifying glass"),orphanActions);
|
||||||
sizeUpMglassAction->setData(SIZE_UP_MGLASS_ACTION_Y);
|
sizeUpMglassAction->setData(SIZE_UP_MGLASS_ACTION_Y);
|
||||||
@ -1031,20 +1039,22 @@ void MainWindowViewer::setUpShortcutsManagement()
|
|||||||
zoomOutMglassAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_OUT_MGLASS_ACTION_Y));
|
zoomOutMglassAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_OUT_MGLASS_ACTION_Y));
|
||||||
|
|
||||||
editShortcutsDialog->addActionsGroup(tr("Magnifiying glass"),QIcon(":/images/shortcuts_group_mglass.png"),
|
editShortcutsDialog->addActionsGroup(tr("Magnifiying glass"),QIcon(":/images/shortcuts_group_mglass.png"),
|
||||||
QList<QAction *>()
|
tmpList = QList<QAction *>()
|
||||||
<< showMagnifyingGlassAction
|
<< showMagnifyingGlassAction
|
||||||
<< sizeUpMglassAction
|
<< sizeUpMglassAction
|
||||||
<< sizeDownMglassAction
|
<< sizeDownMglassAction
|
||||||
<< zoomInMglassAction
|
<< zoomInMglassAction
|
||||||
<< zoomOutMglassAction);
|
<< zoomOutMglassAction);
|
||||||
|
|
||||||
|
allActions << tmpList;
|
||||||
|
|
||||||
//keys without actions
|
//keys without actions
|
||||||
QAction * toggleFitToScreenAction = new QAction(tr("Toggle between fit to width and fit to height"),orphanActions);
|
QAction * toggleFitToScreenAction = new QAction(tr("Toggle between fit to width and fit to height"),orphanActions);
|
||||||
toggleFitToScreenAction->setData(CHANGE_FIT_ACTION_Y);
|
toggleFitToScreenAction->setData(CHANGE_FIT_ACTION_Y);
|
||||||
toggleFitToScreenAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(CHANGE_FIT_ACTION_Y));
|
toggleFitToScreenAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(CHANGE_FIT_ACTION_Y));
|
||||||
|
|
||||||
editShortcutsDialog->addActionsGroup(tr("Page adjustement"),QIcon(":/images/shortcuts_group_page.png"),
|
editShortcutsDialog->addActionsGroup(tr("Page adjustement"),QIcon(":/images/shortcuts_group_page.png"),
|
||||||
QList<QAction *>()
|
tmpList = QList<QAction *>()
|
||||||
<< adjustHeightAction
|
<< adjustHeightAction
|
||||||
<< adjustWidthAction
|
<< adjustWidthAction
|
||||||
<< toggleFitToScreenAction
|
<< toggleFitToScreenAction
|
||||||
@ -1053,6 +1063,8 @@ void MainWindowViewer::setUpShortcutsManagement()
|
|||||||
<< doublePageAction
|
<< doublePageAction
|
||||||
<< adjustToFullSizeAction);
|
<< adjustToFullSizeAction);
|
||||||
|
|
||||||
|
allActions << tmpList;
|
||||||
|
|
||||||
QAction * autoScrollForwardAction = new QAction(tr("Autoscroll down"),orphanActions);
|
QAction * autoScrollForwardAction = new QAction(tr("Autoscroll down"),orphanActions);
|
||||||
autoScrollForwardAction->setData(AUTO_SCROLL_FORWARD_ACTION_Y);
|
autoScrollForwardAction->setData(AUTO_SCROLL_FORWARD_ACTION_Y);
|
||||||
autoScrollForwardAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(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));
|
goToLastPageAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(GO_TO_LAST_PAGE_ACTION_Y));
|
||||||
|
|
||||||
editShortcutsDialog->addActionsGroup(tr("Reading"),QIcon(":/images/shortcuts_group_reading.png"),
|
editShortcutsDialog->addActionsGroup(tr("Reading"),QIcon(":/images/shortcuts_group_reading.png"),
|
||||||
QList<QAction *>()
|
tmpList = QList<QAction *>()
|
||||||
<< nextAction
|
<< nextAction
|
||||||
<< prevAction
|
<< prevAction
|
||||||
<< setBookmarkAction
|
<< setBookmarkAction
|
||||||
@ -1101,6 +1113,10 @@ void MainWindowViewer::setUpShortcutsManagement()
|
|||||||
<< goToLastPageAction
|
<< goToLastPageAction
|
||||||
<< goToPageAction);
|
<< goToPageAction);
|
||||||
|
|
||||||
|
allActions << tmpList;
|
||||||
|
|
||||||
|
ShortcutsManager::getShortcutsManager().registerActions(allActions);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindowViewer::changeFit()
|
void MainWindowViewer::changeFit()
|
||||||
|
@ -298,8 +298,11 @@ void LibraryWindow::doDialogs()
|
|||||||
void LibraryWindow::setUpShortcutsManagement()
|
void LibraryWindow::setUpShortcutsManagement()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
QList<QAction *> allActions;
|
||||||
|
QList<QAction *> tmpList;
|
||||||
|
|
||||||
editShortcutsDialog->addActionsGroup("Comics",QIcon(":/images/shortcuts_group_comics.png"),
|
editShortcutsDialog->addActionsGroup("Comics",QIcon(":/images/shortcuts_group_comics.png"),
|
||||||
QList<QAction *>()
|
tmpList = QList<QAction *>()
|
||||||
<< openComicAction
|
<< openComicAction
|
||||||
<< setAsReadAction
|
<< setAsReadAction
|
||||||
<< setAsNonReadAction
|
<< setAsNonReadAction
|
||||||
@ -311,8 +314,10 @@ void LibraryWindow::setUpShortcutsManagement()
|
|||||||
<< deleteComicsAction
|
<< deleteComicsAction
|
||||||
<< getInfoAction);
|
<< getInfoAction);
|
||||||
|
|
||||||
|
allActions << tmpList;
|
||||||
|
|
||||||
editShortcutsDialog->addActionsGroup("Folders",QIcon(":/images/shortcuts_group_folders.png"),
|
editShortcutsDialog->addActionsGroup("Folders",QIcon(":/images/shortcuts_group_folders.png"),
|
||||||
QList<QAction *>()
|
tmpList = QList<QAction *>()
|
||||||
<< setRootIndexAction
|
<< setRootIndexAction
|
||||||
<< expandAllNodesAction
|
<< expandAllNodesAction
|
||||||
<< colapseAllNodesAction
|
<< colapseAllNodesAction
|
||||||
@ -321,9 +326,10 @@ void LibraryWindow::setUpShortcutsManagement()
|
|||||||
<< setFolderAsCompletedAction
|
<< setFolderAsCompletedAction
|
||||||
<< setFolderAsReadAction
|
<< setFolderAsReadAction
|
||||||
<< setFolderAsUnreadAction);
|
<< setFolderAsUnreadAction);
|
||||||
|
allActions << tmpList;
|
||||||
|
|
||||||
editShortcutsDialog->addActionsGroup("General",QIcon(":/images/shortcuts_group_general.png"),
|
editShortcutsDialog->addActionsGroup("General",QIcon(":/images/shortcuts_group_general.png"),
|
||||||
QList<QAction *>()
|
tmpList = QList<QAction *>()
|
||||||
<< backAction
|
<< backAction
|
||||||
<< forwardAction
|
<< forwardAction
|
||||||
<< helpAboutAction
|
<< helpAboutAction
|
||||||
@ -331,8 +337,10 @@ void LibraryWindow::setUpShortcutsManagement()
|
|||||||
<< serverConfigAction
|
<< serverConfigAction
|
||||||
<< showEditShortcutsAction);
|
<< showEditShortcutsAction);
|
||||||
|
|
||||||
|
allActions << tmpList;
|
||||||
|
|
||||||
editShortcutsDialog->addActionsGroup("Libraries",QIcon(":/images/shortcuts_group_libraries.png"),
|
editShortcutsDialog->addActionsGroup("Libraries",QIcon(":/images/shortcuts_group_libraries.png"),
|
||||||
QList<QAction *>()
|
tmpList = QList<QAction *>()
|
||||||
<< createLibraryAction
|
<< createLibraryAction
|
||||||
<< openLibraryAction
|
<< openLibraryAction
|
||||||
<< exportComicsInfoAction
|
<< exportComicsInfoAction
|
||||||
@ -343,13 +351,18 @@ void LibraryWindow::setUpShortcutsManagement()
|
|||||||
<< renameLibraryAction
|
<< renameLibraryAction
|
||||||
<< removeLibraryAction);
|
<< removeLibraryAction);
|
||||||
|
|
||||||
|
allActions << tmpList;
|
||||||
|
|
||||||
editShortcutsDialog->addActionsGroup("Visualization",QIcon(":/images/shortcuts_group_visualization.png"),
|
editShortcutsDialog->addActionsGroup("Visualization",QIcon(":/images/shortcuts_group_visualization.png"),
|
||||||
QList<QAction *>()
|
tmpList = QList<QAction *>()
|
||||||
<< showHideMarksAction
|
<< showHideMarksAction
|
||||||
<< toggleFullScreenAction
|
<< toggleFullScreenAction
|
||||||
<< toggleComicsViewAction
|
<< toggleComicsViewAction
|
||||||
<< hideComicViewAction);
|
<< hideComicViewAction);
|
||||||
|
|
||||||
|
allActions << tmpList;
|
||||||
|
|
||||||
|
ShortcutsManager::getShortcutsManager().registerActions(allActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibraryWindow::doModels()
|
void LibraryWindow::doModels()
|
||||||
|
@ -80,9 +80,15 @@ bool ActionsShortcutsModel::setData(const QModelIndex &index, const QVariant &va
|
|||||||
{
|
{
|
||||||
if(index.column() == KEYS)
|
if(index.column() == KEYS)
|
||||||
{
|
{
|
||||||
actions[index.row()]->setShortcut(value.toString());
|
ShortcutsManager sm = ShortcutsManager::getShortcutsManager();
|
||||||
ShortcutsManager::getShortcutsManager().saveShortcut(actions[index.row()]);
|
if(sm.checkConflicts(value.toString(), actions[index.row()]))
|
||||||
return true;
|
emit conflict(value.toString());
|
||||||
|
else
|
||||||
|
{
|
||||||
|
actions[index.row()]->setShortcut(value.toString());
|
||||||
|
ShortcutsManager::getShortcutsManager().saveShortcut(actions[index.row()]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ public:
|
|||||||
KEYS
|
KEYS
|
||||||
};
|
};
|
||||||
signals:
|
signals:
|
||||||
|
void conflict(QString);
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "QsLog.h"
|
#include "QsLog.h"
|
||||||
|
|
||||||
@ -59,6 +60,7 @@ EditShortcutsDialog::EditShortcutsDialog(QWidget *parent) :
|
|||||||
|
|
||||||
connect(resetButton,SIGNAL(clicked()),this,SLOT(resetToDefaults()));
|
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(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
|
#ifdef Q_OS_MAC
|
||||||
setFixedSize(760,500);
|
setFixedSize(760,500);
|
||||||
@ -86,3 +88,8 @@ void EditShortcutsDialog::loadShortcuts(const QModelIndex &mi,const QModelIndex
|
|||||||
{
|
{
|
||||||
actionsModel->addActions(groupsModel->getActions(mi));
|
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));
|
||||||
|
}
|
||||||
|
@ -21,6 +21,7 @@ signals:
|
|||||||
public slots:
|
public slots:
|
||||||
void resetToDefaults();
|
void resetToDefaults();
|
||||||
void loadShortcuts(const QModelIndex & mi,const QModelIndex &mi2);
|
void loadShortcuts(const QModelIndex & mi,const QModelIndex &mi2);
|
||||||
|
void processConflict(const QString & shortcutInConflict);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QListView * actionsGroupsListView;
|
QListView * actionsGroupsListView;
|
||||||
|
@ -93,3 +93,20 @@ void ShortcutsManager::saveShortcut(QAction *action)
|
|||||||
|
|
||||||
return s.setValue(action->data().toString() , action->shortcut().toString());
|
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;
|
||||||
|
}
|
||||||
|
@ -16,6 +16,8 @@ class ShortcutsManager
|
|||||||
private:
|
private:
|
||||||
ShortcutsManager();
|
ShortcutsManager();
|
||||||
QMap<QString,QKeySequence> defaultShorcuts;
|
QMap<QString,QKeySequence> defaultShorcuts;
|
||||||
|
QList<QAction *> actions; //all actions registered, used for checking conflicts
|
||||||
|
|
||||||
void initDefaultShorcuts();
|
void initDefaultShorcuts();
|
||||||
public:
|
public:
|
||||||
static ShortcutsManager & getShortcutsManager()
|
static ShortcutsManager & getShortcutsManager()
|
||||||
@ -27,6 +29,8 @@ public:
|
|||||||
void resetToDefaults();
|
void resetToDefaults();
|
||||||
QString getShortcut(const QString & name);
|
QString getShortcut(const QString & name);
|
||||||
void saveShortcut(QAction * action);
|
void saveShortcut(QAction * action);
|
||||||
|
void registerActions(const QList<QAction *> & actions);
|
||||||
|
bool checkConflicts(const QKeySequence &shortcut, const QAction *dest);
|
||||||
};
|
};
|
||||||
|
|
||||||
//ACTION NAMES YACReaderLibrary
|
//ACTION NAMES YACReaderLibrary
|
||||||
|
Loading…
x
Reference in New Issue
Block a user