|
7 | 7 | #include <QApplication>
|
8 | 8 | #include <QMouseEvent>
|
9 | 9 | #include <QPainter>
|
| 10 | +#include <QMenu> |
10 | 11 | #include "StringUtil.h"
|
| 12 | +#include "Configuration.h" |
11 | 13 |
|
12 | 14 | //Hacky class that fixes a really annoying cursor problem
|
13 | 15 | class AbstractTableScrollBar : public QScrollBar
|
@@ -199,6 +201,82 @@ public slots:
|
199 | 201 | QColor separatorColor;
|
200 | 202 | QColor headerTextColor;
|
201 | 203 | QColor selectionColor;
|
| 204 | + |
| 205 | + //action helpers |
| 206 | +private: |
| 207 | + struct ActionShortcut |
| 208 | + { |
| 209 | + QAction* action; |
| 210 | + const char* shortcut; |
| 211 | + |
| 212 | + ActionShortcut(QAction* action, const char* shortcut) |
| 213 | + : action(action), |
| 214 | + shortcut(shortcut) |
| 215 | + { |
| 216 | + } |
| 217 | + }; |
| 218 | + |
| 219 | + std::vector<ActionShortcut> actionShortcutPairs; |
| 220 | + |
| 221 | + inline QAction* connectAction(QAction* action, const char* slot) |
| 222 | + { |
| 223 | + connect(action, SIGNAL(triggered(bool)), this, slot); |
| 224 | + addAction(action); |
| 225 | + return action; |
| 226 | + } |
| 227 | + |
| 228 | + inline QAction* connectShortcutAction(QAction* action, const char* shortcut) |
| 229 | + { |
| 230 | + actionShortcutPairs.push_back(ActionShortcut(action, shortcut)); |
| 231 | + action->setShortcut(ConfigShortcut(shortcut)); |
| 232 | + return action; |
| 233 | + } |
| 234 | + |
| 235 | + inline QAction* connectMenuAction(QMenu* menu, QAction* action) |
| 236 | + { |
| 237 | + return connectMenuAction(menu, action); |
| 238 | + } |
| 239 | + |
| 240 | +protected: |
| 241 | + inline QAction* makeAction(const QString & text, const char* slot) |
| 242 | + { |
| 243 | + return connectAction(new QAction(text, this), slot); |
| 244 | + } |
| 245 | + |
| 246 | + inline QAction* makeAction(const QIcon & icon, const QString & text, const char* slot) |
| 247 | + { |
| 248 | + return connectAction(new QAction(icon, text, this), slot); |
| 249 | + } |
| 250 | + |
| 251 | + inline QAction* makeShortcutAction(const QString & text, const char* slot, const char* shortcut) |
| 252 | + { |
| 253 | + return connectShortcutAction(makeAction(text, slot), shortcut); |
| 254 | + } |
| 255 | + |
| 256 | + inline QAction* makeShortcutAction(const QIcon & icon, const QString & text, const char* slot, const char* shortcut) |
| 257 | + { |
| 258 | + return connectShortcutAction(makeAction(icon, text, slot), shortcut); |
| 259 | + } |
| 260 | + |
| 261 | + inline QAction* makeMenuAction(QMenu* menu, const QString & text, const char* slot) |
| 262 | + { |
| 263 | + return connectMenuAction(menu, makeAction(text, slot)); |
| 264 | + } |
| 265 | + |
| 266 | + inline QAction* makeMenuAction(QMenu* menu, const QIcon & icon, const QString & text, const char* slot) |
| 267 | + { |
| 268 | + return connectMenuAction(menu, makeAction(icon, text, slot)); |
| 269 | + } |
| 270 | + |
| 271 | + inline QAction* makeMenuShortcutAction(QMenu* menu, const QString & text, const char* slot, const char* shortcut) |
| 272 | + { |
| 273 | + return connectShortcutAction(makeMenuAction(menu, text, slot), shortcut); |
| 274 | + } |
| 275 | + |
| 276 | + inline QAction* makeMenuShortcutAction(QMenu* menu, const QIcon & icon, const QString & text, const char* slot, const char* shortcut) |
| 277 | + { |
| 278 | + return connectShortcutAction(makeMenuAction(menu, icon, text, slot), shortcut); |
| 279 | + } |
202 | 280 | };
|
203 | 281 |
|
204 | 282 | #endif // ABSTRACTTABLEVIEW_H
|
0 commit comments