1 #include "shortcuts_manager.h"
2
3 #include <QSettings>
4 #include <QAction>
5 #include "yacreader_global.h"
6
ShortcutsManager()7 ShortcutsManager::ShortcutsManager()
8 {
9 initDefaultShorcuts();
10 }
11
initDefaultShorcuts()12 void ShortcutsManager::initDefaultShorcuts()
13 {
14 #ifdef YACREADER_LIBRARY
15 //ACTIONS
16 defaultShorcuts.insert(FOCUS_SEARCH_LINE_ACTION_YL, Qt::CTRL | Qt::Key_F);
17 defaultShorcuts.insert(CREATE_LIBRARY_ACTION_YL, Qt::Key_A);
18 defaultShorcuts.insert(OPEN_LIBRARY_ACTION_YL, Qt::Key_O);
19 defaultShorcuts.insert(UPDATE_LIBRARY_ACTION_YL, Qt::Key_U);
20 defaultShorcuts.insert(RENAME_LIBRARY_ACTION_YL, Qt::Key_R);
21 defaultShorcuts.insert(OPEN_COMIC_ACTION_YL, Qt::Key_Return);
22 defaultShorcuts.insert(SHOW_HIDE_MARKS_ACTION_YL, Qt::Key_M);
23 defaultShorcuts.insert(TOGGLE_FULL_SCREEN_ACTION_YL, Qt::Key_F);
24 defaultShorcuts.insert(HELP_ABOUT_ACTION_YL, Qt::Key_F1);
25 defaultShorcuts.insert(SET_ROOT_INDEX_ACTION_YL, Qt::Key_0);
26 defaultShorcuts.insert(EXPAND_ALL_NODES_ACTION_YL, Qt::Key_Plus);
27 defaultShorcuts.insert(COLAPSE_ALL_NODES_ACTION_YL, Qt::Key_Minus);
28 defaultShorcuts.insert(OPTIONS_ACTION_YL, Qt::Key_C);
29 defaultShorcuts.insert(SERVER_CONFIG_ACTION_YL, Qt::Key_S);
30 defaultShorcuts.insert(QUIT_ACTION_YL, Qt::CTRL | Qt::Key_Q);
31 defaultShorcuts.insert(TOGGLE_COMICS_VIEW_ACTION_YL, Qt::Key_V);
32
33 //COMMANDS (used in keypressevent)
34 #else
35 defaultShorcuts.insert(OPEN_ACTION_Y, Qt::Key_O);
36 defaultShorcuts.insert(OPEN_LATEST_COMIC_Y, Qt::CTRL | Qt::Key_R);
37 defaultShorcuts.insert(OPEN_FOLDER_ACTION_Y, Qt::CTRL | Qt::Key_O);
38 defaultShorcuts.insert(OPEN_PREVIOUS_COMIC_ACTION_Y, Qt::CTRL | Qt::Key_Left);
39 defaultShorcuts.insert(OPEN_NEXT_COMIC_ACTION_Y, Qt::CTRL | Qt::Key_Right);
40 defaultShorcuts.insert(PREV_ACTION_Y, Qt::Key_Left);
41 defaultShorcuts.insert(NEXT_ACTION_Y, Qt::Key_Right);
42 defaultShorcuts.insert(LEFT_ROTATION_ACTION_Y, Qt::Key_L);
43 defaultShorcuts.insert(RIGHT_ROTATION_ACTION_Y, Qt::Key_R);
44 defaultShorcuts.insert(DOUBLE_PAGE_ACTION_Y, Qt::Key_D);
45 defaultShorcuts.insert(DOUBLE_MANGA_PAGE_ACTION_Y, Qt::Key_J);
46 defaultShorcuts.insert(GO_TO_PAGE_ACTION_Y, Qt::Key_G);
47 defaultShorcuts.insert(OPTIONS_ACTION_Y, Qt::Key_C);
48 defaultShorcuts.insert(HELP_ABOUT_ACTION_Y, Qt::Key_F1);
49 defaultShorcuts.insert(SHOW_MAGNIFYING_GLASS_ACTION_Y, Qt::Key_Z);
50 defaultShorcuts.insert(SET_BOOKMARK_ACTION_Y, Qt::CTRL | Qt::Key_M);
51 defaultShorcuts.insert(SHOW_BOOKMARKS_ACTION_Y, Qt::Key_M);
52 defaultShorcuts.insert(SHOW_INFO_ACTION_Y, Qt::Key_I);
53 defaultShorcuts.insert(CLOSE_ACTION_Y, Qt::Key_Escape);
54 defaultShorcuts.insert(SHOW_DICTIONARY_ACTION_Y, Qt::Key_T);
55 defaultShorcuts.insert(ALWAYS_ON_TOP_ACTION_Y, Qt::Key_Q); //deprecated
56 defaultShorcuts.insert(ADJUST_TO_FULL_SIZE_ACTION_Y, Qt::Key_W);
57 defaultShorcuts.insert(SHOW_FLOW_ACTION_Y, Qt::Key_S);
58 defaultShorcuts.insert(ZOOM_PLUS_ACTION_Y, Qt::Key_Plus);
59 defaultShorcuts.insert(ZOOM_MINUS_ACTION_Y, Qt::Key_Minus);
60 defaultShorcuts.insert(RESET_ZOOM_ACTION_Y, Qt::CTRL | Qt::Key_0);
61
62 //main_window_viewer
63 defaultShorcuts.insert(TOGGLE_FULL_SCREEN_ACTION_Y, Qt::Key_F);
64 defaultShorcuts.insert(TOGGLE_TOOL_BARS_ACTION_Y, Qt::Key_H);
65 defaultShorcuts.insert(CHANGE_FIT_ACTION_Y, Qt::Key_A);
66 //viewer
67 defaultShorcuts.insert(AUTO_SCROLL_FORWARD_ACTION_Y, Qt::Key_Space);
68 defaultShorcuts.insert(AUTO_SCROLL_BACKWARD_ACTION_Y, Qt::Key_B);
69 defaultShorcuts.insert(MOVE_DOWN_ACTION_Y, Qt::Key_Down);
70 defaultShorcuts.insert(MOVE_UP_ACTION_Y, Qt::Key_Up);
71 defaultShorcuts.insert(GO_TO_FIRST_PAGE_ACTION_Y, Qt::Key_Home);
72 defaultShorcuts.insert(GO_TO_LAST_PAGE_ACTION_Y, Qt::Key_End);
73 //mglass
74 defaultShorcuts.insert(SIZE_UP_MGLASS_ACTION_Y, Qt::Key_Plus);
75 defaultShorcuts.insert(SIZE_DOWN_MGLASS_ACTION_Y, Qt::Key_Minus);
76 defaultShorcuts.insert(ZOOM_IN_MGLASS_ACTION_Y, Qt::Key_Asterisk);
77 defaultShorcuts.insert(ZOOM_OUT_MGLASS_ACTION_Y, Qt::Key_Underscore);
78
79 #ifdef Q_OS_MAC
80 defaultShorcuts.insert(NEW_INSTANCE_ACTION_Y, Qt::Key_N);
81 #endif
82
83 #endif
84 }
85
resetToDefaults()86 void ShortcutsManager::resetToDefaults()
87 {
88 //TODO reset to defaults
89 }
90
getShortcut(const QString & name)91 QString ShortcutsManager::getShortcut(const QString &name)
92 {
93 #ifdef YACREADER
94 QString filePath = "/YACReader.ini";
95 #else
96 QString filePath = "/YACReaderLibrary.ini";
97 #endif
98 QSettings s(YACReader::getSettingsPath() + filePath, QSettings::IniFormat);
99 s.beginGroup("shortcuts");
100
101 return s.value(name, defaultShorcuts.value(name)).toString();
102 }
103
saveShortcut(QAction * action)104 void ShortcutsManager::saveShortcut(QAction *action)
105 {
106 #ifdef YACREADER
107 QString filePath = "/YACReader.ini";
108 #else
109 QString filePath = "/YACReaderLibrary.ini";
110 #endif
111 QSettings s(YACReader::getSettingsPath() + filePath, QSettings::IniFormat);
112 s.beginGroup("shortcuts");
113
114 return s.setValue(action->data().toString(), action->shortcut().toString());
115 }
116
registerActions(const QList<QAction * > & a)117 void ShortcutsManager::registerActions(const QList<QAction *> &a)
118 {
119 actions = a;
120 }
121
checkConflicts(const QKeySequence & shortcut,const QAction * dest)122 bool ShortcutsManager::checkConflicts(const QKeySequence &shortcut, const QAction *dest)
123 {
124 if (shortcut.isEmpty())
125 return false;
126
127 foreach (QAction *action, actions) {
128 if (action != dest) //if the same shortcut is setted there is no conflict
129 if (action->shortcut() == shortcut)
130 return true;
131 }
132
133 return false;
134 }
135