[multimedia/haruna] src: application: add isAltKeyPressed property set through an event filter
George Florea Bănuș <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 1dceb8c32480e193be3c336b457b545bc78cb354 by George Florea Bănuș.
Committed on 16/08/2026 at 16:25.
Pushed by georgefb into branch 'master'.
application: add isAltKeyPressed property set through an event filter
used to show tooltips even when disabled in settings
M +67 -23 src/application.cpp
M +9 -0 src/application.h
M +1 -0 src/qml/Main.qml
M +4 -1 src/qml/Settings/SettingsWindow.qml
https://invent.kde.org/multimedia/haruna/-/commit/1dceb8c32480e193be3c336b457b545bc78cb354
diff --git a/src/application.cpp b/src/application.cpp
index 5ecc7d11..1f749450 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -50,11 +50,29 @@ using namespace Qt::StringLiterals;
bool ApplicationEventFilter::eventFilter(QObject *obj, QEvent *event)
{
- if (event->type() == QEvent::Leave) {
- Q_EMIT applicationMouseLeave();
+ switch (event->type()) {
+ case QEvent::KeyPress: {
+ const auto *keyEvent = static_cast<QKeyEvent *>(event);
+ if (keyEvent->key() == Qt::Key_Alt) {
+ Q_EMIT altKeyPressed();
+ }
+ break;
+ }
+ case QEvent::KeyRelease: {
+ const auto *keyEvent = static_cast<QKeyEvent *>(event);
+ if (keyEvent->key() == Qt::Key_Alt) {
+ Q_EMIT altKeyReleased();
+ }
+ break;
}
- if (event->type() == QEvent::Enter) {
+ case QEvent::Leave:
+ Q_EMIT applicationMouseLeave();
+ break;
+ case QEvent::Enter:
Q_EMIT applicationMouseEnter();
+ break;
+ default:
+ break;
}
return QObject::eventFilter(obj, event);
}
@@ -71,32 +89,12 @@ Application *Application::create(QQmlEngine *, QJSEngine *)
return instance();
}
-bool Application::actionsEnabled()
-{
- return m_actionsEnabled;
-}
-
-void Application::setActionsEnabled(bool enable)
-{
- if (enable == actionsEnabled()) {
- return;
- }
- m_actionsEnabled = enable;
- Q_EMIT actionsEnabledChanged();
-}
-
Application::Application()
: QObject{nullptr}
, m_schemes(KColorSchemeManager::instance())
, m_systemDefaultStyle(QApplication::style()->objectName())
, m_appEventFilter{std::make_unique<ApplicationEventFilter>()}
{
- // used to hide playlist when mouse leaves the application
- // while moving between monitors while in fullscreen
- QApplication::instance()->installEventFilter(m_appEventFilter.get());
- QObject::connect(m_appEventFilter.get(), &ApplicationEventFilter::applicationMouseLeave, this, &Application::qmlApplicationMouseLeave);
- QObject::connect(m_appEventFilter.get(), &ApplicationEventFilter::applicationMouseEnter, this, &Application::qmlApplicationMouseEnter);
-
if (GeneralSettings::guiStyle() != u"System"_s) {
QApplication::setStyle(GeneralSettings::guiStyle());
}
@@ -113,6 +111,52 @@ Application::Application()
Application::~Application() = default;
+bool Application::actionsEnabled()
+{
+ return m_actionsEnabled;
+}
+
+void Application::setActionsEnabled(bool enable)
+{
+ if (enable == actionsEnabled()) {
+ return;
+ }
+ m_actionsEnabled = enable;
+ Q_EMIT actionsEnabledChanged();
+}
+
+bool Application::isAltKeyPressed() const
+{
+ return m_isAltKeyPressed;
+}
+
+void Application::setIsAltKeyPressed(bool newIsAltKeyPressed)
+{
+ if (m_isAltKeyPressed == newIsAltKeyPressed) {
+ return;
+ }
+ m_isAltKeyPressed = newIsAltKeyPressed;
+ Q_EMIT isAltKeyPressedChanged();
+}
+
+void Application::setupEventFilter(QObject *object)
+{
+ // used to hide playlist when mouse leaves the application
+ // while moving between monitors while in fullscreen
+ // and detecting if alt key is pressed to show tooltips even when they are disabled in settings
+ object->installEventFilter(m_appEventFilter.get());
+
+ QObject::connect(m_appEventFilter.get(), &ApplicationEventFilter::applicationMouseLeave, this, &Application::qmlApplicationMouseLeave);
+ QObject::connect(m_appEventFilter.get(), &ApplicationEventFilter::applicationMouseEnter, this, &Application::qmlApplicationMouseEnter);
+
+ QObject::connect(m_appEventFilter.get(), &ApplicationEventFilter::altKeyPressed, this, [this]() {
+ setIsAltKeyPressed(true);
+ });
+ QObject::connect(m_appEventFilter.get(), &ApplicationEventFilter::altKeyReleased, this, [this]() {
+ setIsAltKeyPressed(false);
+ });
+}
+
void Application::setupWorkerThread()
{
auto *worker = Worker::instance();
diff --git a/src/application.h b/src/application.h
index 81563049..0c78495a 100644
--- a/src/application.h
+++ b/src/application.h
@@ -30,6 +30,8 @@ class ApplicationEventFilter : public QObject
Q_SIGNALS:
void applicationMouseLeave();
void applicationMouseEnter();
+ void altKeyPressed();
+ void altKeyReleased();
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
@@ -51,6 +53,12 @@ public:
bool actionsEnabled();
void setActionsEnabled(bool enable);
+ Q_PROPERTY(bool isAltKeyPressed READ isAltKeyPressed WRITE setIsAltKeyPressed NOTIFY isAltKeyPressedChanged FINAL)
+ Q_SIGNAL void isAltKeyPressedChanged();
+ bool isAltKeyPressed() const;
+ void setIsAltKeyPressed(bool newIsAltKeyPressed);
+
+ Q_INVOKABLE void setupEventFilter(QObject *object);
Q_INVOKABLE QList<QUrl> urls();
Q_INVOKABLE QUrl url(uint index);
Q_INVOKABLE void addUrl(const QString &value);
@@ -96,6 +104,7 @@ private:
std::unique_ptr<ApplicationEventFilter> m_appEventFilter;
QQmlPropertyMap *m_actions{new QQmlPropertyMap};
bool m_actionsEnabled{true};
+ bool m_isAltKeyPressed;
};
#endif // APPLICATION_H
diff --git a/src/qml/Main.qml b/src/qml/Main.qml
index 41675e9d..a8a88e93 100644
--- a/src/qml/Main.qml
+++ b/src/qml/Main.qml
@@ -505,6 +505,7 @@ ApplicationWindow {
}
Component.onCompleted: {
+ HarunaApp.setupEventFilter(window)
HarunaApp.activateColorScheme(GeneralSettings.colorScheme)
const hasCommandLineFile = HarunaApp.url(0).toString() !== ""
diff --git a/src/qml/Settings/SettingsWindow.qml b/src/qml/Settings/SettingsWindow.qml
index b38fdc31..ce82e741 100644
--- a/src/qml/Settings/SettingsWindow.qml
+++ b/src/qml/Settings/SettingsWindow.qml
@@ -230,7 +230,10 @@ Loader {
onClosing: root.active = false
- Component.onCompleted: pageStack.columnView.columnWidth = Kirigami.Units.gridUnit * 15
+ Component.onCompleted: {
+ HarunaApp.setupEventFilter(settingsWindow)
+ pageStack.columnView.columnWidth = Kirigami.Units.gridUnit * 15
+ }
Shortcut {
sequence: "Esc"