|
QtPass 2.0.0
Developer documentation
|
Shows a hidden menu bar while Alt is used, as browsers and file managers do. More...
#include <menubarpeek.h>
Public Member Functions | |
| MenuBarPeek (QMainWindow *window, QAction *toggle) | |
Watch window for Alt while its menu bar is hidden. | |
| auto | isPeeking () const -> bool |
| Whether the bar is up for a peek rather than by choice. | |
Protected Member Functions | |
| auto | eventFilter (QObject *watched, QEvent *event) -> bool override |
| Follows Alt, Escape, clicks and focus for the whole application. | |
Private Member Functions | |
| void | onKeyPress (QObject *watched, const QKeyEvent *event) |
| Handle a key press seen by the application filter. | |
| void | onKeyRelease (const QKeyEvent *event) |
| Handle the release of Alt: a second lone tap hides the bar, an Alt+key chord that did not open a menu hides it once no menu is open, and the tap that showed it leaves it up. | |
| auto | inWindow (QObject *watched) const -> bool |
Whether watched is a widget that belongs to the main window. | |
| auto | onMenuBar (QObject *watched) const -> bool |
Whether watched is the menu bar itself or one of its children, so a click there must not end the peek. | |
| void | show () |
| Show the menu bar and mark the peek as active. | |
| void | hide () |
| End the peek; hides the menu bar unless the "Show menu bar" toggle was checked in the meantime. | |
| void | hideWhenNoMenuIsOpen () |
| hide() on the next event-loop pass, and only if no popup is open and the bar has no active action. Deferred because a menu's aboutToHide also fires when the pointer moves on to the next menu, and Escape is seen before the bar leaves keyboard mode. | |
Private Attributes | |
| QMainWindow * | m_window |
| The main window whose menuBar() is shown and hidden; the parent. | |
| QAction * | m_toggle |
| The window's "Show menu bar" action; while checked the bar is up by choice and the peek state is cleared. | |
| bool | m_peeking {false} |
| true while the bar is shown because of Alt, not the toggle. | |
| bool | m_altDown {false} |
| true between an Alt press in the window and its release (or the window losing activation); filters repeats and propagated copies. | |
| bool | m_altAlone {false} |
| true while no other key has been pressed since Alt went down, i.e. the release will be a lone tap rather than a chord. | |
| bool | m_shownByThisPress {false} |
| true when the current Alt press is the one that showed the bar, so its release must not hide it again. | |
Shows a hidden menu bar while Alt is used, as browsers and file managers do.
Pressing Alt in the window shows the bar, so Alt+F and the other mnemonics open their menus. A lone tap leaves it up until Alt is tapped again, Escape is pressed, the window is clicked or loses focus; after a menu closes, or after an Alt shortcut that was not a menu, it goes again. The stored "Show menu bar" choice is never touched: checking it during a peek keeps the bar.
Definition at line 29 of file menubarpeek.h.
| MenuBarPeek::MenuBarPeek | ( | QMainWindow * | window, |
| QAction * | toggle ) |
Watch window for Alt while its menu bar is hidden.
| window | The main window whose menuBar() is shown; also the parent. |
| toggle | The window's "Show menu bar" action. While it is checked the bar is simply there and Alt does nothing extra. |
Definition at line 17 of file menubarpeek.cpp.
|
overrideprotected |
Follows Alt, Escape, clicks and focus for the whole application.
| watched | The object the event is for. |
| event | The event; never consumed. |
Definition at line 33 of file menubarpeek.cpp.
|
private |
End the peek; hides the menu bar unless the "Show menu bar" toggle was checked in the meantime.
Definition at line 112 of file menubarpeek.cpp.
|
private |
hide() on the next event-loop pass, and only if no popup is open and the bar has no active action. Deferred because a menu's aboutToHide also fires when the pointer moves on to the next menu, and Escape is seen before the bar leaves keyboard mode.
Definition at line 121 of file menubarpeek.cpp.
|
nodiscardprivate |
Whether watched is a widget that belongs to the main window.
| watched | The object an event was sent to. |
Definition at line 96 of file menubarpeek.cpp.
|
nodiscard |
Whether the bar is up for a peek rather than by choice.
Definition at line 31 of file menubarpeek.cpp.
|
private |
Handle a key press seen by the application filter.
A first, non-repeated Alt press inside the window shows the bar when it is hidden; any other key marks the press as "Alt plus something", and Escape during a peek hides the bar. A key event reaches the filter once for every widget it propagates to and again as auto-repeat; m_altDown makes the second sighting a no-op.
| watched | The object the event was sent to. |
| event | The key press. |
Definition at line 61 of file menubarpeek.cpp.
|
private |
Handle the release of Alt: a second lone tap hides the bar, an Alt+key chord that did not open a menu hides it once no menu is open, and the tap that showed it leaves it up.
| event | The key release; anything but a tracked Alt is ignored. |
Definition at line 81 of file menubarpeek.cpp.
|
nodiscardprivate |
Whether watched is the menu bar itself or one of its children, so a click there must not end the peek.
| watched | The object a mouse press was sent to. |
Definition at line 101 of file menubarpeek.cpp.
|
private |
Show the menu bar and mark the peek as active.
Definition at line 107 of file menubarpeek.cpp.
|
private |
true while no other key has been pressed since Alt went down, i.e. the release will be a lone tap rather than a chord.
Definition at line 128 of file menubarpeek.h.
|
private |
true between an Alt press in the window and its release (or the window losing activation); filters repeats and propagated copies.
Definition at line 123 of file menubarpeek.h.
|
private |
true while the bar is shown because of Alt, not the toggle.
Definition at line 118 of file menubarpeek.h.
|
private |
true when the current Alt press is the one that showed the bar, so its release must not hide it again.
Definition at line 133 of file menubarpeek.h.
|
private |
The window's "Show menu bar" action; while checked the bar is up by choice and the peek state is cleared.
Definition at line 116 of file menubarpeek.h.
|
private |
The main window whose menuBar() is shown and hidden; the parent.
Definition at line 111 of file menubarpeek.h.