LogViewer
A modern log viewer with AI-assisted analysis (Qt 6)
Loading...
Searching...
No Matches
KeyboardNavigationManager.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <QObject>
4#include <QKeySequence>
5#include <functional>
6#include <map>
7
8class QWidget;
9class QKeyEvent;
10
11namespace ui::qt::utils
12{
13
25{
26 Q_OBJECT
27
28 public:
29 explicit KeyboardNavigationManager(QWidget* mainWindow);
30
32 void registerShortcut(const QKeySequence& key, const QString& description,
33 std::function<void()> handler);
34
36 bool handleKeyPress(QKeyEvent* event);
37
40
43
45 void navigateDown();
46
48 void navigateUp();
49
51 void navigateLeft();
52
54 void navigateRight();
55
57 void jumpToFirst();
58
60 void jumpToLast();
61
63 void jumpToRow(int row);
64
66 void setVimKeybindingsEnabled(bool enabled) { m_vimKeybindingsEnabled = enabled; }
68
70 const std::map<QString, QString>& shortcuts() const { return m_shortcutDescriptions; }
71
72 private:
74 bool handleVimBindings(QKeyEvent* event);
75 bool handleStandardBindings(QKeyEvent* event);
76
78 std::map<int, std::function<void()>> m_shortcuts; // Qt key code -> handler
79 std::map<QString, QString> m_shortcutDescriptions; // Key -> description
81 bool m_vimGGPressed {false}; // Track G key for GG binding
82};
83
84} // namespace ui::qt::utils
Manages keyboard navigation and shortcuts throughout the application.
Definition KeyboardNavigationManager.hpp:25
void registerShortcut(const QKeySequence &key, const QString &description, std::function< void()> handler)
Register a keyboard shortcut with a handler.
Definition KeyboardNavigationManager.cpp:48
QWidget * m_mainWindow
Definition KeyboardNavigationManager.hpp:77
void navigateRight()
Navigate right in table (Right arrow or L)
Definition KeyboardNavigationManager.cpp:246
void navigateToNextPanel()
Navigate to next panel (Ctrl+Tab)
Definition KeyboardNavigationManager.cpp:143
std::map< int, std::function< void()> > m_shortcuts
Definition KeyboardNavigationManager.hpp:78
bool handleKeyPress(QKeyEvent *event)
Handle key press event.
Definition KeyboardNavigationManager.cpp:59
void jumpToFirst()
Jump to first row (Home or G+G)
Definition KeyboardNavigationManager.cpp:263
void navigateDown()
Navigate down in table (Down arrow or J)
Definition KeyboardNavigationManager.cpp:195
std::map< QString, QString > m_shortcutDescriptions
Definition KeyboardNavigationManager.hpp:79
void jumpToRow(int row)
Jump to row by number (: followed by number)
Definition KeyboardNavigationManager.cpp:302
void setupDefaultShortcuts()
Definition KeyboardNavigationManager.cpp:20
void setVimKeybindingsEnabled(bool enabled)
Enable/disable Vim-like keybindings.
Definition KeyboardNavigationManager.hpp:66
const std::map< QString, QString > & shortcuts() const
Get all registered shortcuts.
Definition KeyboardNavigationManager.hpp:70
void navigateUp()
Navigate up in table (Up arrow or K)
Definition KeyboardNavigationManager.cpp:212
void jumpToLast()
Jump to last row (End)
Definition KeyboardNavigationManager.cpp:282
void navigateToPreviousPanel()
Navigate to previous panel (Ctrl+Shift+Tab)
Definition KeyboardNavigationManager.cpp:170
void navigateLeft()
Navigate left in table (Left arrow or H)
Definition KeyboardNavigationManager.cpp:229
bool handleStandardBindings(QKeyEvent *event)
Definition KeyboardNavigationManager.cpp:125
bool m_vimGGPressed
Definition KeyboardNavigationManager.hpp:81
bool handleVimBindings(QKeyEvent *event)
Definition KeyboardNavigationManager.cpp:73
bool areVimKeybindingsEnabled() const
Definition KeyboardNavigationManager.hpp:67
bool m_vimKeybindingsEnabled
Definition KeyboardNavigationManager.hpp:80
Definition AppDataDir.hpp:14