QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
MenuBarPeek Class Reference

Shows a hidden menu bar while Alt is used, as browsers and file managers do. More...

#include <menubarpeek.h>

Inheritance diagram for MenuBarPeek:
Collaboration diagram for MenuBarPeek:

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.

Detailed Description

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.

Constructor & Destructor Documentation

◆ MenuBarPeek()

MenuBarPeek::MenuBarPeek ( QMainWindow * window,
QAction * toggle )

Watch window for Alt while its menu bar is hidden.

Parameters
windowThe main window whose menuBar() is shown; also the parent.
toggleThe 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.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ eventFilter()

auto MenuBarPeek::eventFilter ( QObject * watched,
QEvent * event ) -> bool
overrideprotected

Follows Alt, Escape, clicks and focus for the whole application.

Parameters
watchedThe object the event is for.
eventThe event; never consumed.
Returns
Always false.

Definition at line 33 of file menubarpeek.cpp.

Here is the call graph for this function:

◆ hide()

void MenuBarPeek::hide ( )
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.

Here is the caller graph for this function:

◆ hideWhenNoMenuIsOpen()

void MenuBarPeek::hideWhenNoMenuIsOpen ( )
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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ inWindow()

auto MenuBarPeek::inWindow ( QObject * watched) const -> bool
nodiscardprivate

Whether watched is a widget that belongs to the main window.

Parameters
watchedThe object an event was sent to.
Returns
true if it is a widget whose top-level window is m_window.

Definition at line 96 of file menubarpeek.cpp.

Here is the caller graph for this function:

◆ isPeeking()

auto MenuBarPeek::isPeeking ( ) const -> bool
nodiscard

Whether the bar is up for a peek rather than by choice.

Returns
true between the Alt press that showed it and its hiding.

Definition at line 31 of file menubarpeek.cpp.

◆ onKeyPress()

void MenuBarPeek::onKeyPress ( QObject * watched,
const QKeyEvent * event )
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.

Parameters
watchedThe object the event was sent to.
eventThe key press.

Definition at line 61 of file menubarpeek.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onKeyRelease()

void MenuBarPeek::onKeyRelease ( const QKeyEvent * event)
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.

Parameters
eventThe key release; anything but a tracked Alt is ignored.

Definition at line 81 of file menubarpeek.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onMenuBar()

auto MenuBarPeek::onMenuBar ( QObject * watched) const -> bool
nodiscardprivate

Whether watched is the menu bar itself or one of its children, so a click there must not end the peek.

Parameters
watchedThe object a mouse press was sent to.
Returns
true for the menu bar or a descendant of it.

Definition at line 101 of file menubarpeek.cpp.

Here is the caller graph for this function:

◆ show()

void MenuBarPeek::show ( )
private

Show the menu bar and mark the peek as active.

Definition at line 107 of file menubarpeek.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ m_altAlone

bool MenuBarPeek::m_altAlone {false}
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.

◆ m_altDown

bool MenuBarPeek::m_altDown {false}
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.

◆ m_peeking

bool MenuBarPeek::m_peeking {false}
private

true while the bar is shown because of Alt, not the toggle.

Definition at line 118 of file menubarpeek.h.

◆ m_shownByThisPress

bool MenuBarPeek::m_shownByThisPress {false}
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.

◆ m_toggle

QAction* MenuBarPeek::m_toggle
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.

◆ m_window

QMainWindow* MenuBarPeek::m_window
private

The main window whose menuBar() is shown and hidden; the parent.

Definition at line 111 of file menubarpeek.h.


The documentation for this class was generated from the following files: