QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
menubarpeek.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
8#ifndef SRC_MENUBARPEEK_H_
9#define SRC_MENUBARPEEK_H_
10
11#include <QObject>
12
13class QAction;
14class QKeyEvent;
15class QMainWindow;
16
29class MenuBarPeek : public QObject {
30 Q_OBJECT
31
32public:
39 MenuBarPeek(QMainWindow *window, QAction *toggle);
40
45 [[nodiscard]] auto isPeeking() const -> bool;
46
47protected:
54 auto eventFilter(QObject *watched, QEvent *event) -> bool override;
55
56private:
68 void onKeyPress(QObject *watched, const QKeyEvent *event);
69
76 void onKeyRelease(const QKeyEvent *event);
77
83 [[nodiscard]] auto inWindow(QObject *watched) const -> bool;
84
91 [[nodiscard]] auto onMenuBar(QObject *watched) const -> bool;
92
94 void show();
95
100 void hide();
101
109
111 QMainWindow *m_window;
116 QAction *m_toggle;
118 bool m_peeking{false};
123 bool m_altDown{false};
128 bool m_altAlone{false};
134};
135
136#endif // SRC_MENUBARPEEK_H_
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...
void show()
Show the menu bar and mark the peek as active.
bool m_peeking
true while the bar is shown because of Alt, not the toggle.
MenuBarPeek(QMainWindow *window, QAction *toggle)
Watch window for Alt while its menu bar is hidden.
bool m_altDown
true between an Alt press in the window and its release (or the window losing activation); filters re...
bool m_shownByThisPress
true when the current Alt press is the one that showed the bar, so its release must not hide it again...
void hideWhenNoMenuIsOpen()
hide() on the next event-loop pass, and only if no popup is open and the bar has no active action....
QMainWindow * m_window
The main window whose menuBar() is shown and hidden; the parent.
auto eventFilter(QObject *watched, QEvent *event) -> bool override
Follows Alt, Escape, clicks and focus for the whole application.
void onKeyPress(QObject *watched, const QKeyEvent *event)
Handle a key press seen by the application filter.
void hide()
End the peek; hides the menu bar unless the "Show menu bar" toggle was checked in the meantime.
auto isPeeking() const -> bool
Whether the bar is up for a peek rather than by choice.
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...
QAction * m_toggle
The window's "Show menu bar" action; while checked the bar is up by choice and the peek state is clea...
bool m_altAlone
true while no other key has been pressed since Alt went down, i.e. the release will be a lone tap rat...
auto inWindow(QObject *watched) const -> bool
Whether watched is a widget that belongs to the main window.