QtPass
2.0.0
Developer documentation
Toggle main menu visibility
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
13
class
QAction;
14
class
QKeyEvent;
15
class
QMainWindow;
16
29
class
MenuBarPeek
:
public
QObject {
30
Q_OBJECT
31
32
public
:
39
MenuBarPeek
(QMainWindow *window, QAction *toggle);
40
45
[[nodiscard]]
auto
isPeeking
()
const
-> bool;
46
47
protected
:
54
auto
eventFilter
(QObject *watched, QEvent *event) ->
bool
override
;
55
56
private
:
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
108
void
hideWhenNoMenuIsOpen
();
109
111
QMainWindow *
m_window
;
116
QAction *
m_toggle
;
118
bool
m_peeking
{
false
};
123
bool
m_altDown
{
false
};
128
bool
m_altAlone
{
false
};
133
bool
m_shownByThisPress
{
false
};
134
};
135
136
#endif
// SRC_MENUBARPEEK_H_
MenuBarPeek::onKeyRelease
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...
Definition
menubarpeek.cpp:81
MenuBarPeek::show
void show()
Show the menu bar and mark the peek as active.
Definition
menubarpeek.cpp:107
MenuBarPeek::m_peeking
bool m_peeking
true while the bar is shown because of Alt, not the toggle.
Definition
menubarpeek.h:118
MenuBarPeek::MenuBarPeek
MenuBarPeek(QMainWindow *window, QAction *toggle)
Watch window for Alt while its menu bar is hidden.
Definition
menubarpeek.cpp:17
MenuBarPeek::m_altDown
bool m_altDown
true between an Alt press in the window and its release (or the window losing activation); filters re...
Definition
menubarpeek.h:123
MenuBarPeek::m_shownByThisPress
bool m_shownByThisPress
true when the current Alt press is the one that showed the bar, so its release must not hide it again...
Definition
menubarpeek.h:133
MenuBarPeek::hideWhenNoMenuIsOpen
void hideWhenNoMenuIsOpen()
hide() on the next event-loop pass, and only if no popup is open and the bar has no active action....
Definition
menubarpeek.cpp:121
MenuBarPeek::m_window
QMainWindow * m_window
The main window whose menuBar() is shown and hidden; the parent.
Definition
menubarpeek.h:111
MenuBarPeek::eventFilter
auto eventFilter(QObject *watched, QEvent *event) -> bool override
Follows Alt, Escape, clicks and focus for the whole application.
Definition
menubarpeek.cpp:33
MenuBarPeek::onKeyPress
void onKeyPress(QObject *watched, const QKeyEvent *event)
Handle a key press seen by the application filter.
Definition
menubarpeek.cpp:61
MenuBarPeek::hide
void hide()
End the peek; hides the menu bar unless the "Show menu bar" toggle was checked in the meantime.
Definition
menubarpeek.cpp:112
MenuBarPeek::isPeeking
auto isPeeking() const -> bool
Whether the bar is up for a peek rather than by choice.
Definition
menubarpeek.cpp:31
MenuBarPeek::onMenuBar
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...
Definition
menubarpeek.cpp:101
MenuBarPeek::m_toggle
QAction * m_toggle
The window's "Show menu bar" action; while checked the bar is up by choice and the peek state is clea...
Definition
menubarpeek.h:116
MenuBarPeek::m_altAlone
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...
Definition
menubarpeek.h:128
MenuBarPeek::inWindow
auto inWindow(QObject *watched) const -> bool
Whether watched is a widget that belongs to the main window.
Definition
menubarpeek.cpp:96
src
menubarpeek.h
Generated by
1.18.0